Bug in pythpn 1.5.2. for Win32
Kalle Svensson
kalle at gnupung.net
Tue May 8 17:56:46 EDT 2001
Sez Pavel Khmelinsky:
> Hi!
>
> Ok, lets try this source code:
> -------------------
> def f(m):
> for i in m:
> print i
>
> m1 = range(5,10)
> f(m1)
> ------------------
>
> The output is:
> ------------------
> 5
> 6
> 7
> 8
> 9
> ------------------
>
> All right, but lets try few differ source code:
> ------------------
> class cl:
> def f(m):
> for i in m:
> print i
>
> c=cl()
> m1 = range(5,10)
> c.f(m1)
> -----------------
>
> And python interpretator returns me this error message:
> -----------------
> Traceback (innermost last):
> File "test3.py", line 11, in ?
> c.f(m1)
> TypeError: too many arguments; expected 1, got 2
> -----------------
>
> Not working!
> Why? I think that is it must working!
> I send just one argument to function.
> But is not working....
> Please help me. May be you have solution of this problem.
This is not a bug, this is documented behavior. The first argument to
instance methods is the instance, it is automatically passed to the method
when it is invoked.
Try:
class cl:
def f(self, m):
print self
for i in m:
print i
c=cl()
m1 = range(5,10)
c.f(m1)
Peace,
Kalle
--
Email: kalle at gnupung.net | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
[ Not signed due to lossage. Blame Microsoft Outlook Express. ]
More information about the Python-list
mailing list