9

I wrote a python script and have been running it in terminal on Mac OS X snow leopard using python2.6. I used raw_input() to import text in several places, but I seem to reach a limit where it will no longer accept any more characters.

Is this a limit in python raw_input() or is this something to do with Terminal or Mac OSX?

Is there a better way to have the user input larger amounts of text in python?

4
  • 1
    Try testing Python raw_limit versus cat > file.txt in the shell. If both have problems, then it's a problem with the terminal. Commented Sep 9, 2011 at 4:00
  • It might help if you described the amount of text and generally what you're trying to have happen. If you're essentially writing a macro, then it makes more sense to operate on files IMHO. Commented Sep 9, 2011 at 4:01
  • An interesting update. If I call raw_input from python running in terminal, I can add as much text as I want. But within my script, when I add more than about a paragraph of text, the script locks up. What I thought was a limit on raw_input is actually the terminal window locking up or crashing I think. Commented Sep 9, 2011 at 4:19
  • 1
    fwiw, the max characters allowed are 1024 Commented Dec 14, 2017 at 19:53

2 Answers 2

22

I had this same experience, and found python limits the length of input to raw_input if you do not import the readline module. Once I imported the readline module, it lifted the limit (or at least raised it significantly enough to where the text I was using worked just fine).

Sign up to request clarification or add additional context in comments.

2 Comments

Obscure, but worked for me too (using py3's input)
Also worked for me. One of the most weird bug/solution combos I have ever seen!
4

I'd say it's a limitation/bug with the OSX Terminal - try running the script with input via IDLE and see whether you still hit the same problem.

As for better ways of dealing with large input - it totally depends on your requirements but some ways could be:

  • Import text from a file
  • Create some kind of GUI/frontend to handle text input via more user friendly controls

2 Comments

I haven't used IDLE much, but it doesn't seem to be allowing me to paste input into IDLE.
@Thursdays: You won't be able to use your right-click context menu, but you can just choose "Paste" from the "Edit" menu or use the OSX paste shortcut (Cmd+V if I remember correctly)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.