annoying behavior

Elbert Lev elbertlev at hotmail.com
Tue Sep 28 18:56:13 CEST 2004


# here is the problem I ran into:

class foo:
    def __init__(self, host):
        self.f()
        self.r = True
    
    def f(self):
        if self.r:
            #<do something>
            pass
        else:
            #<do something else>
            pass

f = foo("1234")

#here is the output:

#Traceback (most recent call last):
#  File "G:\MyProjects\Python\Little\inconv.py", line 16, in ?
#    f = foo("1234")
#  File "G:\MyProjects\Python\Little\inconv.py", line 5, in __init__
#    self.f()
#  File "G:\MyProjects\Python\Little\inconv.py", line 9, in f
#    if self.r:
#AttributeError: foo instance has no attribute 'r'

# I understand why does this happen, but, to tell the truth,
# this feature is very annoying. 
# Are there any plans to relax this restriction? 
# In 3.0 :)?



More information about the Python-list mailing list