|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help Needed CLASSES and FUNCTIONS!!!
hi,
I have a small problem I think the following code explains what I am trying to do: ***************************************** class TEST: def __init__ (self): print "INSTANCE" def A (self): self.a = 'AZ' def B (self): print self.a if __name__ == '__main__': test = TEST() test.B() ****************************************** I am trying to get the value of self.a in def B() though it is being declared in def A(). Currently it doesn't work and gets an error: AttributeError: Azeem instance has no attribute 'a' Now is there a way to get the value of self.a in def B() without declaring self.a in __init__() i.e. any way to get to that value using any class reference or anything. What I want to do is that create multiple lists at runtime in different methods. I am not sure ahead how many lists I need to create as it all depends on the data in the input-file. I have different methods that populate the relevant lists. That's a small picture of the code I am working. Any help is appreciated. Thanks |
|
#2
|
||||
|
||||
|
This could work for ya
Code:
class TEST:
def __init__ ( self ):
print "INSTANCE"
self.A ( " " )
def A ( self, var ):
self.var = 'AZ'
def B ( self ):
print self.var
if __name__ == '__main__':
test = TEST ( )
test.B ( )
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev Last edited by xlordt : May 26th, 2004 at 06:00 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Help Needed CLASSES and FUNCTIONS!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|