class func & var name overlap

Changsen Xu xu.20 at nd.edu
Fri Mar 9 23:34:10 EST 2001


hi all,

I just now tried function name and variable name overlaping
in Python's script (1) and (2):

(1)
class x:
        x = 3
        def x(self): return 5
y=x()
print y.x


(2)
class x:
        x = 3
        def x(self): return 5
        x = 6
y=x()
print y.x


Then if I run 1), I got screen echo as
        <method x.x of x instance at 80e17d4>
while for 2), I got
        6

I'm here curious why Python doesn't even report an error
for this obvious mistake ?




More information about the Python-list mailing list