Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 December 29th, 2012, 07:53 AM
slidon slidon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 slidon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 20 sec
Reputation Power: 0
Append() and raw_input()

Hi, I have not been doing python for that long so please bear with me. Here is an example of the problem I am having:

list = []
input = raw_input()
list.append(input)
print list


when I print "list" I get the individual letters I typed when assigning "input" like this:

['i, n, p, u, t']

why isn't is giving me the whole word?

thanks in advance

Reply With Quote
  #2  
Old December 29th, 2012, 09:19 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
I've put your program into file p.py, and on the command line I execute, `hmmph' my input is shown

$ python p.py
hmmph
['hmmph']
$

I don't comprehend the problem. raw_input returns the keyboard input without the new line as a string.


1) Hiding the names of builtin functions is usually bad practice. You hid both `input' and `list'.

2) If still confused please show the input you provide and the output you expect. I think explaining what you think python does is counterproductive, because it's not yet correct.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 29th, 2012, 10:21 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 480 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 57 sec
Reputation Power: 63
Getting ['i, n, p, u, t'] doesn't make any sense, unless
you entered the string i, n, p, u, t

Avoid using Python function names as variable names.
When in doubt prefix with my like this:
Code:
mylist = []
myinput = raw_input()
mylist.append(myinput)
print mylist
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Last edited by Dietrich : December 29th, 2012 at 11:21 AM.

Reply With Quote
  #4  
Old December 29th, 2012, 11:05 AM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 74 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 37 sec
Reputation Power: 2
This looks like the result of using extend() instead of append(). Is the code you wrote here copied verbatim from what you actually ran?

Reply With Quote
  #5  
Old December 29th, 2012, 11:25 AM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 480 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 8 m 57 sec
Reputation Power: 63
Quote:
Originally Posted by Nyktos
This looks like the result of using extend() instead of append(). Is the code you wrote here copied verbatim from what you actually ran?


Sharp mind Nyktos!
Code:
mylist = []
myinput = raw_input()
mylist.extend(myinput)
print mylist

''' result typing in the word input -->
['i', 'n', 'p', 'u', 't']
'''

Reply With Quote
  #6  
Old December 30th, 2012, 06:26 AM
slidon slidon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 slidon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 32 m 20 sec
Reputation Power: 0
sorry, when I was messing around with something else I must have tried extend() and not changed it. I have changed it now and it works, thanks for the help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Append() and raw_input()

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap