8

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?

Thursdays Coming
  • 1,002
  • 13
  • 28
  • 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. – Dietrich Epp Sep 09 '11 at 04: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. – fncomp Sep 09 '11 at 04: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. – Thursdays Coming Sep 09 '11 at 04:19
  • 1
    fwiw, the max characters allowed are 1024 – sbru Dec 14 '17 at 19:53

2 Answers2

16

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).

Eric Ferreira
  • 1,811
  • 18
  • 20
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
mal-wan
  • 4,391
  • 4
  • 26
  • 37
  • I haven't used IDLE much, but it doesn't seem to be allowing me to paste input into IDLE. – Thursdays Coming Sep 09 '11 at 04:26
  • @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) – mal-wan Sep 09 '11 at 04:37