Results 1 to 5 of 5

Thread: input() problem, Python

  1. #1
    Join Date
    Aug 2009
    Beans
    37

    Cool input() problem, Python

    Hello all,

    I have written a simple program in python:

    Code:
    x = raw_input("Enter anything: ")
    
    print x
    Doesn't get much simpler. It runs fine, but the arrow keys don't work properly:

    Code:
    dara@dara-laptop:~/autotxt$ python aaa.py 
    Enter anything: Hello there^[[D^[[D^[[D^[[Deheje!!
    Hello teheje!!
    Is there a workaround?

    Thank you

  2. #2
    Join Date
    Jan 2009
    Beans
    111

    Re: input() problem, Python

    You could parse ^[[D or whatever it was as a right arrow key I guess? What did you expect the arrow keys' output to be?


    If you want to use arrow keys you should use something like Pygame, or Tkinter I think.


  3. #3
    Join Date
    Aug 2009
    Beans
    37

    Re: input() problem, Python

    Quote Originally Posted by nice_like_rice View Post
    You could parse ^[[D or whatever it was as a right arrow key I guess? What did you expect the arrow keys' output to be?


    If you want to use arrow keys you should use something like Pygame, or Tkinter I think.

    I need the file to be run from a command line. I would expect the following:

    Code:
                                v------Cursor
    Enter something: Hello There
    
    *left arrow pressed a few times*
                            
                             v------------Cursor
    Enter something: Hello There
    
    *something typed in*
    
    Enter something: Hello Theeeeeere
    Do you know what I mean?

  4. #4
    Join Date
    Jan 2009
    Beans
    111

    Re: input() problem, Python

    Yes I know what you mean, and I solved it (woop woop)!

    Try this:

    Code:
    import readline
    
    test = raw_input("type something in:")
    
    print test
    Works fine for me. See the man page for raw_input, that's where I figured it out from.

    David

  5. #5
    Join Date
    Aug 2009
    Beans
    37

    Re: input() problem, Python

    Quote Originally Posted by nice_like_rice View Post
    Yes I know what you mean, and I solved it (woop woop)!

    Try this:

    Code:
    import readline
    
    test = raw_input("type something in:")
    
    print test
    Works fine for me. See the man page for raw_input, that's where I figured it out from.

    David
    WAHOO! Thanks a million!
    Last edited by Dara Javaherian; January 3rd, 2011 at 02:20 AM. Reason: typo

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •