#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Raw_input not outputting my question txt


    hi peeps my problem is when i use raw_input for example
    " name = raw_input("whats your name? ")"
    i dont get the prompt just a blank and nobody can see the question. Any ideas why.? im using learn python the hard way
    on excersise16. Ive even tried just copying and pasting the short script but i dont get the output any help would be much appreciated thanx.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    I suppose you're using a version 2 python.
    raw_input works. Start your python interpreter and try it like this:

    >>> raw_input('?')
    ?

    To diagnose exactly what's causing the symptoms you report you need to explain what modules you imported, your operating system, how you started python, the exact statement that failed by copy-n-paste of the session.

    That which you posted is erroneous in two interpretations:
    Code:
    >>> " name = raw_input("whats your name? ")"
      File "<stdin>", line 1
        " name = raw_input("whats your name? ")"
                                ^
    SyntaxError: invalid syntax
    >>>
    Code:
    >>>  name = raw_input("whats your name? ")
      File "<stdin>", line 1
        name = raw_input("whats your name? ")
        ^
    IndentationError: unexpected indent
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    sorry i didnt explain very well im using windows 7 with Python 2.7.4. Im currently working through the learn python the hard way web site which seems pretty good but when i got to exercise 16 my program worked but did not display the prompts which should have appeared I guessed i had made a typo but on cutting and pasting the example script i found it did just the same. Im quite a newby at programming in python so im not sure of which (if any) modules im using. The actual script is.

    from sys import argv

    script, filename = argv

    print "We're going to erase %r." % filename
    print "If you don't want that, hit CTRL-C (^C)."
    print "If you do want that, hit RETURN."

    raw_input("?") # I thought this should display a ? (Dave)

    print "Opening the file..."
    target = open(filename, 'w')

    print "Truncating the file. Goodbye!"
    target.truncate()

    print "Now I'm going to ask you for three lines."

    line1 = raw_input("line 1: ")# These are just blank
    line2 = raw_input("line 2: ")# and this
    line3 = raw_input("line 3: ")# and this

    print "I'm going to write these to the file."

    target.write(line1)
    target.write("\n")
    target.write(line2)
    target.write("\n")
    target.write(line3)
    target.write("\n")

    print "And finally, we close it."
    target.close()

    I run it from the conmmandline with the name of a test file in the arguments

    ive played around with the raw_input statement and it seem to work ok in other programs so i cant really figure it out

    thanks again...
    Dave
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    I tried the program in a cmd window on Windows NT 32 bit system. The prompts do display. When I run the program on same system in an xemacs shell buffer the prompts do not display. The program always works as I'd expect on my linux system. Sorry.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    ok thanks for trying i have laptops running linux mint and ubuntu ill carry on from one of those, thanks for trying mate.
    Dave
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65
    Your problem could be your IDE, not all of them handle input() well.
    Generally IDLE has no problems.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

IMN logo majestic logo threadwatch logo seochat tools logo