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
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
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.
"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
> [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
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
> 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
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
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
"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.
> > [...] 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
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
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) :
>
13 matches
Mail list logo