swf format verification?

2007-02-14 Thread akonsu
hello, can someone recommend a good library to verify whether a file
is in swf format (and ideally flv as well)? i need it to enable file
uploading on to my web site.

thanks
konstantin

-- 
http://mail.python.org/mailman/listinfo/python-list


how to add property "dynamically"?

2008-08-16 Thread akonsu
hello,

i need to add properties to instances dynamically during run time.
this is because their names are determined by the database contents.
so far i found a way to add methods on demand:

class A(object) :
def __getattr__(self, name) :
if name == 'test' :
def f() : return 'test'
setattr(self, name, f)
return f
else :
raise AttributeError("'%s' object has no attribute '%s'" %
(self.__class__.__name__, name))

this seems to work and i can invoke method test() on an object. it
would be nice to have it as property though. so i tried:

class A(object) :
def __getattr__(self, name) :
if name == 'test' :
def f() : return 'test'
setattr(self, name, property(f))
return f
else :
raise AttributeError("'%s' object has no attribute '%s'" %
(self.__class__.__name__, name))

but this does not work, instance.test returns a callable but does not
call it.

i am not an expert in python, would someone please tell me what i am
doing wrong?

thanks
konstantin
--
http://mail.python.org/mailman/listinfo/python-list


Re: nested structure with "internal references"

2009-09-25 Thread akonsu
On Sep 25, 1:11 pm, Torsten Mohr  wrote:
> Hi,
>
> sorry for posting in german before, that was a mistake.
>
> I'd like to use a nested structure in memory that consists
> of dict()s and list()s, list entries can be dict()s, other list()s,
> dict entries can be list()s or other dict()s.
>
> The lists and dicts can also contain int, float, string, ...
>
> But i'd also like to have something like a "reference" to another
> entry.
> I'd like to refer to another entry and not copy that entry, i need to
> know later that this is a reference to another entry, i need to find
> also access that entry then.
>
> Is something like this possible in Python?
>
> The references only need to refer to entries in this structure.
> The lists may change at runtime (entries removed / added), so
> storing the index may not help.
>
> Thanks for any hints,
> Torsten.

hello,

maybe i know less python than you do, but i am talking from the point
of view of my common sense and experience. if you store an object in a
list more than once, i doubt that python creates a duplicate. unless
the object is a value type. thus you have a reference to this object
in both elements. and then if you are asking this question, maybe your
design is not good enough? would you explain the problem?
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nested structure with "internal references"

2009-09-25 Thread akonsu
put a (name, value) pair in each list element instead of just value
and reference them by name, you can use uuid to generate names

konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


module path?

2009-09-28 Thread akonsu
hello,

is there a way to determine the file location of a loaded module?
assuming it is not built in.

import settings
print settings

produces: 

i would like to get to this path somehow other than by parsing the
string representation of the module. is there a property on
types.ModuleType? i could not find anything...

thanks
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: module path?

2009-09-28 Thread akonsu
On Sep 28, 7:51 pm, Steven D'Aprano  wrote:
> On Mon, 28 Sep 2009 16:41:36 -0700, akonsu wrote:
> > hello,
>
> > is there a way to determine the file location of a loaded module?
> > assuming it is not built in.
>
> > import settings
> > print settings
>
> > produces: 
>
> > i would like to get to this path somehow other than by parsing the
> > string representation of the module. is there a property on
> > types.ModuleType? i could not find anything...
>
> Did you look at dir(settings) for a list of method and attribute names?
>
> Look at module.__file__. But be careful because some modules are "built
> in", that is, they don't actually exist as a separate file and are part
> of the Python compiler. E.g.:
>
> >>> import sys
> >>> sys.__file__
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'module' object has no attribute '__file__'>>> sys
>
> 
>
> --
> Steven

thanks! i did not know about dir() method.
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


something like perl's Mail::GPG ?

2009-08-13 Thread akonsu
hello,

i am looking for a module with functionality similar to that of the
Perl's Mail::GPG package. I need to verify multipart emails that are
PGP-signed.

thanks for any advice
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: coding for multiple versions of python

2009-08-13 Thread akonsu
On Aug 13, 12:57 pm, "Tim Arnold"  wrote:
> Hi,
> I've got a python based system that has to run on hp unix and red hat linux.
> The Python version on the HP is 2.4 and the version on the Linux box is 2.6.
> There's nothing I can do about that.
>
> I think that means I must have two different libraries since the pyc files
> are not cross-version compatible. No problem for the libs like PIL or lxml.
> But for the part of the system I actually code every day, I'd rather not do
> dual maintenance, having two copies of my code for each platform/version.
>
> I'm guessing I need to configure cvs to copy files to both locations
> whenever I commit. Does that sound right? Is there a better way I'm not
> thinking of?
>
> thanks,
> --Tim

hello,

why would you need to maintain pyc files at all? is having just source
files enough? or am i missing something?

konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


cleanup in sys.excepthook?

2009-09-23 Thread akonsu
hello,

my script creates files that i need to delete if an exception is
thrown.

is this a good pythonic style to do this kind of cleanup in
sys.excepthook instead of inside except clause of a try block?

konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very simple finite automaton (?)

2009-09-23 Thread akonsu
On Sep 23, 1:24 am, kpp9c  wrote:
> Very simple finite automaton (?)
>
> 1 --> 2 5
> 2 --> 1 4
> 3 --> 3
> 4 --> 1
> 5 --> 4 3
>

hello,
this is a graph and you are doing depth first search.
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Very simple finite automaton (?)

2009-09-23 Thread akonsu
On Sep 23, 11:49 am, akonsu  wrote:
> On Sep 23, 1:24 am, kpp9c  wrote:
>
> > Very simple finite automaton (?)
>
> > 1 --> 2 5
> > 2 --> 1 4
> > 3 --> 3
> > 4 --> 1
> > 5 --> 4 3
>
> hello,
> this is a graph and you are doing depth first search.
> konstantin

BREADTH first. sorry :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cleanup in sys.excepthook?

2009-09-23 Thread akonsu
On Sep 23, 11:57 am, Jean-Michel Pichavant 
wrote:
> akonsu wrote:
> > hello,
>
> > my script creates files that i need to delete if an exception is
> > thrown.
>
> > is this a good pythonic style to do this kind of cleanup in
> > sys.excepthook instead of inside except clause of a try block?
>
> > konstantin
>
> def doIt():
>     pass
>
> try:
>     doIt()
> except Exception, exc:
>     #cleaning up files
>
> I mean, what is the problem with try except ? It's pythonic. If you tell
> us what wrong with it in your case, we may spend time on hacking
> sys.excepthook.
>
> Jean-Michel

thanks. nothing is wrong with try/except. i just already have an
excepthook handler that uses logger to send emails if a critical error
occurs, so i was just thinking that maybe i can add cleanup there. i
agree, try/except makes more sense.

konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Idiom for "last word in a string"

2009-09-23 Thread akonsu
On Sep 23, 2:47 pm, Grant Edwards  wrote:
> I recently ran across this construct for grabbing the last
> (whitespace delimited) word in a string:
>
>    s.rsplit(None,1)[1]
>
> It was somewhat obvious from the context what it was supposed
> to do, but it took a bit of Googling to figure out exactly what
> was going on.
>
> When I want the last word in a string, I've always done this:
>
>    s.split()[-1]
>
> I was wondering what the advantage of the rsplit(None,1)[1]
> approach would be other than inducing people to learn about the
> maxsplit argument that is accepted by the split() methods?
>
> --
> Grant Edwards                   grante             Yow! I want a VEGETARIAN
>                                   at               BURRITO to go ... with
>                                visi.com            EXTRA MSG!!

hello,
perhaps rsplit generates as many elements in the list as absolutely
necesary compared to the whole list returned by split()?
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list


logging.handlers.SMTPHandler question

2009-09-23 Thread akonsu
hello,

SMTPHAndler seems to email every single record separately. is there a
way to collect all log output and then send it in a single email
message? or do i have to do it manually?

thanks
konstantin
-- 
http://mail.python.org/mailman/listinfo/python-list