943,840 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 884
  • Python RSS
Jul 19th, 2009
0

Raw_input...

Expand Post »
Say I have a variable, 'New', who's value is Raw_input("Enter name: ") How could I take this variable and pass it into a class?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Your_mum is offline Offline
30 posts
since Jun 2009
Jul 19th, 2009
0

Re: Raw_input...

What do you mean 'pass it to a class'? Can you post some code and pin-point your problem please?
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Jul 19th, 2009
0

Re: Raw_input...

You can pass value in as argument.
python Syntax (Toggle Plain Text)
  1. new = raw_input('Enter name: ')
  2.  
  3. class Test(object):
  4. def __init__(self,value):
  5. self.value = value
  6.  
  7. x = Test(new)
  8. print x.value
  9.  
  10. '''
  11. output-->
  12. Enter name: hi
  13. hi
  14. '''
Last edited by snippsat; Jul 19th, 2009 at 12:02 pm.
Reputation Points: 280
Solved Threads: 278
Master Poster
snippsat is offline Offline
770 posts
since Aug 2008
Jul 20th, 2009
0

Re: Raw_input...

Not really recommended, since you don't really always want to pause your code but I think you want this:

python Syntax (Toggle Plain Text)
  1. class Name:
  2. def __init__(self):
  3. self.name = raw_input("Name: ")

However, I'd have to agree that snippsat's solution is a better written class, because if neccessary you could use it on names that you don't get through raw_input like...a list! For example:

python Syntax (Toggle Plain Text)
  1. #snippseat's class
  2. class Test(object):
  3. def __init__(self,value):
  4. self.value = value
  5.  
  6. for name in namelist:
  7. test = Test(name)
Reputation Points: 16
Solved Threads: 17
Junior Poster
zachabesh is offline Offline
106 posts
since Jun 2008
Jul 21st, 2009
0

Re: Raw_input...

Thanks, I can't see why I couldn't work that out!
neway, problem solved.
Reputation Points: 10
Solved Threads: 0
Light Poster
Your_mum is offline Offline
30 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: wxpython GUI error....
Next Thread in Python Forum Timeline: Incrementing loops within loops





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC