Re: Better way to do this?

2008-02-11 Thread imho
PRC ha scritto: > Hi folks, > > I have a tuple of tuples, in the form--> ((code1, 'string1'),(code2, > 'string2'),(code3, 'string3'),) > > Codes are unique. A dict would probably be the best approach but this > is beyond my control. > > Here is an example: pets = ((0,'cat'),(1,'dog'),(2,'mo

Re: a trick with lists ?

2008-02-07 Thread imho
Steve Holden ha scritto: >>> What I do not fully understand is the line "self.tasks[:] = tasks". >>> Why does the guy who coded this did not write it as "self.tasks = >>> tasks"? What is the use of the "[:]" trick ? >> >> It changes the list in-place. If it has been given to other objects, >> i

Re: How to Split a String

2007-11-29 Thread imho
Grant Edwards ha scritto: >> One solution: >> > s = '(a, b, "c", d, "e")' > print [x.strip('" ') for x in s.strip('()').split(',')] >> ['a', 'b', 'c', 'd', 'e'] > > That fails when a quoted string contains commas: > s = '(a, b, "c", d, "e,f,g")' print [x.strip('" ') for x in s.

Re: How to Split a String

2007-11-29 Thread imho
Siah ha scritto: > Hi, > > I need to convert the string: '(a, b, "c", d, "e")' into the following > list ['a', 'b', 'c', 'd', 'e']. Much like a csv reader does. I usually > use the split function, but this mini-monster wouldn't properly get > split up due to those random quotations postgresql retu

Re: Accessing function in a module by name

2007-06-06 Thread imho
Tobiah ha scritto: > Is there a way to call function in an imported > module having only the name? > > > func_name = 'doit' > > real_func = foo.some_magic(func_name) > > #Now call it > real_func(args) > > > I'm trying to set up a function dispatcher for a > SOAP server. > > Thanks, > > Tobi

Re: How to recognise "generator functions" ?

2006-07-19 Thread imho
Georg Brandl ha scritto: f.func_code.co_flags > 67 g.func_code.co_flags > 99 > > => 32 (CO_GENERATOR in compiler.consts) is the flag that indicates a > generator code object. > > Georg What a fast reply! Thank You very much! :-) -- http://mail.python.org/mailman/listinfo/python-list

How to recognise "generator functions" ?

2006-07-19 Thread imho
Hi all. Is there a way to know if a function object is actually a "generator function" or not ? e.g.: def f(): pass def g(): yield None f.__class__ is the same as g.__class__ , i.e. "function" type. But i "know" that the second, when invoked, returns a generator object, becaus

Re: mapping None values to ''

2006-06-19 Thread imho
Roberto Bonvallet ha scritto: > imho <[EMAIL PROTECTED]>: >> map(lambda x:"" , [i for i in [a,b,c] if i in ("None",None) ]) > > You don't need map when using list comprehensions: > >["" for i in [a, b, c] if i in ("None&quo

Re: mapping None values to ''

2006-06-18 Thread imho
[EMAIL PROTECTED] ha scritto: > hi > i wish to map None or "None" values to "". > eg > a = None > b = None > c = "None" > > map( , [i for i in [a,b,c] if i in ("None",None) ]) > > I can't seem to find a way to put all values to "". Can anyone help? > thanks > You already filtered [a,b,c] in

Re: package search

2006-06-11 Thread imho
boris ha scritto: > > COOL! You just saved me an awful lot of work. > > Thanks, Diego! > > Boris > ;-) Bye -- http://mail.python.org/mailman/listinfo/python-list

Re: package search

2006-06-11 Thread imho
boris ha scritto: > I have two directories, lib1 and lib2, that both contain the package > foo, one with the submodule mod1 > and the other with the submodule mod2: > [...] > Now this script: > > import sys > sys.path.append("lib1") > sys.path.append("lib2") > import foo.mod1 > > will find the mo