Raw_input...

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 28
Reputation: Your_mum is an unknown quantity at this point 
Solved Threads: 0
Your_mum Your_mum is offline Offline
Light Poster

Raw_input...

 
0
  #1
Jul 19th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 231
Reputation: sravan953 has a little shameless behaviour in the past 
Solved Threads: 28
sravan953's Avatar
sravan953 sravan953 is offline Offline
Posting Whiz in Training

Re: Raw_input...

 
0
  #2
Jul 19th, 2009
What do you mean 'pass it to a class'? Can you post some code and pin-point your problem please?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 162
Reputation: snippsat is an unknown quantity at this point 
Solved Threads: 49
snippsat snippsat is online now Online
Junior Poster

Re: Raw_input...

 
0
  #3
Jul 19th, 2009
You can pass value in as argument.
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 106
Reputation: zachabesh is an unknown quantity at this point 
Solved Threads: 16
zachabesh's Avatar
zachabesh zachabesh is offline Offline
Junior Poster

Re: Raw_input...

 
0
  #4
Jul 20th, 2009
Not really recommended, since you don't really always want to pause your code but I think you want this:

  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:

  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)
-Zac
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 28
Reputation: Your_mum is an unknown quantity at this point 
Solved Threads: 0
Your_mum Your_mum is offline Offline
Light Poster

Re: Raw_input...

 
0
  #5
Jul 21st, 2009
Thanks, I can't see why I couldn't work that out!
neway, problem solved.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC