How to access args as a list?

Andreas Waldenburger usenot at geekmail.INVALID
Sat Apr 3 20:16:13 EDT 2010


On Sat, 3 Apr 2010 22:58:43 +0000 (UTC) kj <no.email at please.post> wrote:

> The best I have managed looks like this:
> 
> class _Spam(object):
>     def __init__(self, x, y, z): 
>         self.__dict__ = OrderedDict(())
>         for p in inspect.getargspec(_Spam.__init__).args[1:]:
>             self.__dict__[p] = locals()[p]
> 
>     def __iter__(self):
>         return iter(self.__dict__.values())

Looks like you're trying to be lazy by doing extra hard work. Anything
wrong with this (?):

class Spam(object):
    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z
        self.arguments = (x, y, z)

    def __iter__(self):
        return iter(self.arguments)  # iter(...) kinda optional

With what little I know about your use case, that's how I would do it.

/W


-- 
INVALID? DE!




More information about the Python-list mailing list