Newbie: Functions and class
KefX
keflimarcusx at aol.comNOSPAM
Thu Oct 30 16:13:27 EST 2003
>class hittable(object):
> def __init__(self):
> self = [[], [], [], []]
Assignment to 'self' is never all that useful. You're just rebinding a
temporary object; this function is basically a no-op because the assignment to
'self' is discarded once the function exits. I know it's kind of confusing, but
you'll get used to the name binding rules before too long.
If you don't understand, it's the same reason this doesn't work:
x = 2
y = x
x = 3
if x == y:
print 'Hewwo world'
# Why doesn't this print?
The answer is that rebinding x doesn't rebind y, which is clearly a Good Thing
in genera as you can see by the example.
- Kef
More information about the Python-list
mailing list