[Tutor] IDLE Caching

Luke Paireepinart rabidpoobear at gmail.com
Mon Jul 24 11:38:39 CEST 2006


[snip code]
> look at this code. Edit this code with IDLE. For example change one of 
> the 'self' statement
> in the code. For instance change self => slf then save the file and 
> press F5(Run Module)
> It doesn't complain about the code !!! this is my problem.
>
I think maybe you're just confused about what 'self' is.
'self' is not a reserved keyword that's used for the name of class 
instances.
for example:
#-----start code-------

class Foo(object):
    def __init__(abracadabra):
       print 'BAR!'
       print abracadabra
       abracadabra.random_variable = 42

#make an instance of Foo and call its __init__
x = Foo()
#print the value of random_variable
print x.random_variable

#----end code-----
#---start output----

BAR!
<__main__.Foo object at 0x00F0C930>
42

#---end output----

does this clear anything up for you?
There's no reason to name your first arguments of
methods of class instances 'self' other than
readability and tradition.  To the compiler
it makes no difference.

Do you still think it's a problem with IDLE?


More information about the Tutor mailing list