to thine own SELF be true...
Duncan Booth
duncan.booth at invalid.invalid
Fri May 5 13:40:08 EDT 2006
Mark Harrison wrote:
> For example, in my brain I'm thinking:
>
> optc,args=getopt.getopt(args,cmdopts[cmd][0], cmdopts[cmd][1])
>
> but I'm having to type:
>
> self.optc,self.args=getopt.getopt(self.args,self.cmdopts[self.c
> md][0],
>
> self.cmdopts[self.cmd][1])
>
>
> Is there a way to get rid of those the "self." references, or is this
> just something I need to get my brain to accept?
>
I would wonder why it is that all of those need to be attributes on self.
Are you sure you aren't storing too many things as attributes?
Trying to guess some context around that code, I would expect something
like:
def docommand(self, cmd, args):
opts, longopts = self.cmdopts[cmd]
optc, args = getopt.getopt(args, opts, longopts)
return self.getAction(cmd)(optc, args)
or in other words a lot fewer uses of self.
More information about the Python-list
mailing list