[Tutor] Option of passing sequences are arguments
Kalle Svensson
kalle@gnupung.net
Sat, 16 Jun 2001 01:31:11 +0200
Sez Phil Bertram:
> I would like to define a class so that it can be called as follows
>
> m = MyObject(arg1,arg2,arg3)
>
> or
>
> args=(arg1,arg2,arg3)
> x=MyObject(args)
Python 2.1 (#1, Jun 15 2001, 00:08:24)
[GCC 2.95.4 20010604 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> def f(*args):
... print args
...
>>> args = (1,2,3)
>>> f(1,2,3)
(1, 2, 3)
>>> f(args)
((1, 2, 3),)
>>> f(*args) # This only works in 2.1 (2.0?) and later
(1, 2, 3)
>>> apply(f, args)
(1, 2, 3)
>>>
Peace,
Kalle
--
Email: kalle@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. ]