class variable declarations...
Lee John Moore
leej at dsl.pipex.com
Mon Jun 16 17:41:26 CEST 2003
One may as well begin with Peter Hansen's letter to comp.lang.python:
>> class SpeedTouchComm:
>> "Interface with the SpeedTouch router"
>> def __init__(self, connect, uid, pwd, rtuid, rtpwd):
>> self.connect = connect
>> self.uid = uid
>> self.pwd = pwd
>> self.rtuid = rtuid
>> self.rtpwd = rtpwd
I've left the example in for reference. :-)
> Not sure what you mean here. "Class attributes" would
> normally mean attributes that are shared by all instances of a
> class, as if you were to do "SpeedTouchComm.rtuid = rtuid" in
> the above, instead of using "self" which refers to an
> *instance*, not the class.
I know. I'm referring to connect, uid, pwd, etc. as attributes
of the SpeedTouchComm class. I referred to them as variables in
a previous post (simply because I would refer to them as
declared variables in a similar OP or C++ class), but I was told
I should be calling them attributes. So that's where that came
> Also, what do you mean by "against the law"?
I'm trying and failing at being humorous. ;-) What didn't 'feel'
like good code is compounded by my difficulty in coming to terms
with a language that doesn't require me to declare everything.
The above example just doesn't feel very clean (to me), but then
you consider it good coding style so I'm clearly just having
difficulty adapting. ;-)
> to be exactly how *all* Python code works, where you pass
> values in to the __init__ method and it dutifully assigns them
> to various names in self. I don't think you're being clear,
> Maybe the short answer will do: there's nothing wrong with the
> above. It even exhibits good coding style! :-)
Phew. You're clearer and more concise than I'll ever be. Thank
ye kindly for saying that. Did I mention that I love Python?
And I've only been studying it on and off for ten days. Even my
cron jobs have been ported just for the hell of it. ;-)
"However far you may travel in this world, you
will still occupy the same volume of space."
- Traditional Ur-Bororo saying
More information about the Python-list