Re: how can I use a callable object as a method

2008-09-18 Thread Marco Wahl
Piotr Sobolewski <[EMAIL PROTECTED]> writes: > I would like to use a callable object as a method of a class. So, when I > have such normal class: > > I want to change it to something like that: > > class add: > def __call__(self, another_self): > return another_self.version

Re: Explanation about pickle module

2007-01-30 Thread Marco Wahl
n(c__main__\nFoo\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'bar'\np6\nI1\nsb.") >>> b.bar 1 >>> b <__main__.Foo object at 0x402ae68c> >>> There is also pickle.dumps and pickle.loads to work directly with files. Further there is module cpickle which

Re: Class and instance question

2006-12-17 Thread Marco Wahl
rzed <[EMAIL PROTECTED]> writes: To simplify take > class T(object): > def __new__(self): > self.a = 1 and t = T() and then you get >>> print t.a > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'NoneType' object has no attribute 'a' While T.a is 1.

Re: unit test for a printing method

2006-08-29 Thread Marco Wahl
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: >>> >>> why are you trying to reinvent doctest ? >> >> The OP asked for unit test. This could be read that >> the OP wants to use module unittest. > > http://docs.python.org/lib/doctest-unittest-api.html Ahh, that's good to know that doctests can be

Re: unit test for a printing method

2006-08-28 Thread Marco Wahl
> [OP] What is the proper way to test (using unit test) a method that print > information? > [...] Fredrik Lundh <[EMAIL PROTECTED]> writes: > > Scott David Daniels wrote: > >> For silly module myprog.py: >> def A(s): >> print '---'+s+'---' >> in test_myprog.py: >> import unitte

Re: dicts vs classes

2006-07-25 Thread Marco Wahl
usage point of view? I recommend you to measure the time and memory usage for the two alternatives. That could give you the answer you want. HTH -- Marco Wahl http://visenso.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Detupleize a tuple for argument list

2006-07-05 Thread Marco Wahl
> Marco Wahl enlightened us with: > > >>> foo(t) > > Traceback (most recent call last): > >File "", line 1, in ? > > TypeError: foo() takes exactly 2 arguments (1 given) > > Call foo(*t) Thank you very much Luke Plant, Steven D&#x

Detupleize a tuple for argument list

2006-07-05 Thread Marco Wahl
e is that I take the functions from a library that I cannot modify. On the other side in my code I use the tuples. Best wishes -- Marco Wahl http://visenso.com -- http://mail.python.org/mailman/listinfo/python-list

Re: a class variable question

2006-06-27 Thread Marco Wahl
Hi, just some lines added below. hth [EMAIL PROTECTED] wrote: > hi > i have define a class like this > > class A: > _var1 = 0 > def __init__(self): > ## some initialization > self.func1() > > def func1(): se

Re: global name is not defined - error

2006-06-27 Thread Marco Wahl
"a" <[EMAIL PROTECTED]> writes: > What I want > --- > I want to create a list of items from a function operating on an array > of strings Ok. > What I did > - > list=["s0","s1","s2"] > l=len(list) > for i in range(l): > d_list[i]=f.

Re: Where is documentation for +=

2006-06-14 Thread Marco Wahl
> > [...] I can't find any documentation for +=. > > Any hints? > http://docs.python.org/ref/augassign.html That's it. Thank you very much. -- http://mail.python.org/mailman/listinfo/python-list

Where is documentation for +=

2006-06-14 Thread Marco Wahl
Hello, by accident I found that += exists in python. E.g. >>> a = 0 >>> a += 42 >>> a 42 >>> a += 0.42 >>> a 42.422 >>> But I can't find any documentation for +=. Any hints? Best wishes -- http://mail.python.org/mailman/listinfo/python-list

Re: a question on re

2006-03-31 Thread Marco Wahl
Hi, > i tried to search 2 patterns > > pat1 = re.compile("blah") > pat2 = re.compile("blah2") > > > if i do > if re.findall(pat1,something) and re.findall(pat2,something): >do something > > if does not work > > but when i do a nest if, > > if re.findall(pat1,something) : >