Is there is some python rule that says declare/define all global variable in the "init" method? Why would python allow this?
for example, see the following code:
class Myclass():
def __init__(self,input):
self.input = input
def a_method(self):
self.sneaky = {}
local_var = 'a var'
return local_var
def another_method(self):
print self.input
print self.sneaky, ', O sneaky you bad var'
return
If my class had many methods the variable 'self.sneaky' would have been hard to spot. And "a_method" has to be called first other wise AttributeError is raised when "another_method" is called. I just spotted it in somebody's code and want to know if it is common practice.