问题
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?
回答1:
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:
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).
来源:https://stackoverflow.com/questions/7357007/python-raw-input-limit-with-mac-os-x-terminal