Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 26th, 2004, 04:58 PM
rockets12345 rockets12345 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 101 rockets12345 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 50 m 20 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old May 26th, 2004, 05:56 PM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonders.
Posts: 5,547 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1Folding Points: 109876 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 1 h 43 m 50 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook MySpace
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 ( )

Last edited by xlordt : May 26th, 2004 at 06:00 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help Needed CLASSES and FUNCTIONS!!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway