Re: How can I verify if the content of a variable is a list or a string?

2012-02-01 Thread Rainer Grimm
You can do it more concise. >>> def isListOrString(p): ...return any((isinstance(p,list),isinstance(p,str))) ... >>> listOrString("string") True >>> listOrString([1,2,3]) True >>> listOrString(2) False >>> listOrString(False) False Rainer -- http://mail.python.org/mailman/listinfo/python-lis

Re: Scope of variable inside list comprehensions?

2011-12-05 Thread Rainer Grimm
Hello, > try: > songs = [Song(id) for id in song_ids] > except Song.DoesNotExist: > print "unknown song id (%d)" % id that's is a bad programming style. So it will be forbidden with python 3. The reason is that list comprehension is a construct from the functional world.

Aw: Re: Aw: Functional style programming in python: what will you talk about if you have an hour on this topic?

2011-07-16 Thread Rainer Grimm
Am Samstag, 16. Juli 2011 08:46:42 UTC+2 schrieb Steven D'Aprano: > Rainer Grimm wrote: > > > I think it's relatively difficult to get a feeling what a are the key > > points behind functional programming. So I think you should start > > explaining the concept

Aw: Functional style programming in python: what will you talk about if you have an hour on this topic?

2011-07-15 Thread Rainer Grimm
Hello, > > (My post did not appear in the mailing list, so this is my second try. > > Apology if it ends up posted twice) > > > > Hi, all, > > > > If you have read my previous posts to the group, you probably have some > > idea why I asked this question. > > > > I am giving a few presentations

Re: What is a list compression in Python?

2010-01-19 Thread Rainer Grimm
Hallo, you can also look at list comprehension as syntactic sugar for the functions map and filter. The two functions from the functional world can be expressed in a comprehensive way with list comprehension. >>> [x**2 for x in range(10) ] == map ( lambda x: x*x, range(10)) True >>> [ x for x in ra

Re: multivariable assignment

2010-01-01 Thread Rainer Grimm
On Dec 31 2009, 5:13 pm, davidj411 wrote: > I am not sure why this behavior is this way. > at beginning of script, i want to create a bunch of empty lists and > use each one for its own purpose. > however, updating one list seems to update the others. > > >>> a = b = c = [] > >>> a.append('1') > >

Re: How do I begin debugging a python memory leak?

2009-09-18 Thread Rainer Grimm
On Sep 18, 5:42 pm, Paul Rubin <http://phr...@nospam.invalid> wrote: > Rainer Grimm writes: > > have a look at valgrind. > > Have you actually used that on Python? Not with python as far I can remember. But often with C++ executables, as i mentioned it. I you look at htt

Re: How do I begin debugging a python memory leak?

2009-09-18 Thread Rainer Grimm
On 17 Sep., 02:10, Matthew Wilson wrote: > I have a web app based on TurboGears 1.0.  In the last few days, as > traffic and usage has picked up, I noticed that the app went from using > 4% of my total memory all the way up to 50%. > > I suspect I'm loading data from the database and somehow preve

Re: invoke method on many instances

2009-07-19 Thread Rainer Grimm
Hallo Alan, > def apply2(itr, methodname, *args, **kwargs): >     f = operator.methodcaller(methodname, *args, **kwargs) >     for item in itr: >         f(item) you can do it in a functional way. >>> class A(object): ... def hello(self): return "hello: " + str ( self.__class__.__name__ ) ... >>

Re: Beginner question: module organisation

2007-05-19 Thread Rainer Grimm
ts => strategy pattern override the steps of the processing in subclasses => template method Regards, Rainer -- _creating IT solutions Rainer Grimm scVENUS Schulungsleiter science + computing ag phone +49(0)7071 9457-253

Re: a better solution for GUI in python

2007-03-17 Thread Rainer Grimm
ce wrote: > Hi, > > My company is using python currently for our website. We need to > develop a GUI front-end for our ERP that would be portable (Windows > and Linux). > > My question is which solution would be better for the GUI (and easier > to implement)? I knew there are something like wxidg