3

For an InterviewStreet challenge, we have to be able to accomodate for a 10,000 character String input from the keyboard, but when I copy/paste a 10k long word into my local testing, it cuts off at a thousand or so.

What's the official limit in Python? And is there a way to change this?

Thanks guys

Here's the challenge by-the-by:

http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4edb8abd7cacd

Srini Kadamati
  • 609
  • 1
  • 6
  • 13

3 Answers3

8

Are you sure of the fact that your 10k long word doesn't contain newlines?


raw_input([prompt])

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.

...

If the readline module was loaded, then raw_input() will use it to provide elaborate line editing and history features.

There is no maximum limit (in python) of the buffer returned by raw_input, and as I tested some big length of input to stdin I could not reproduce your result. I tried to search the web for information regarding this but came up with nothing that would help me answer your question.

my tests

  :/tmp% python -c 'print "A"*1000000' | python -c 'print len (raw_input ())';
  1000000
  :/tmp% python -c 'print "A"*210012300' | python -c 'print len (raw_input ())';
  210012300
  :/tmp% python -c 'print "A"*100+"\n"+"B"*100' | python -c 'print len (raw_input ())'; 
  100
Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
6

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). This was on my Mac with Python 2.7.15. Additionally, it’s been confirmed working on at least 3.9.5.

Eric Ferreira
  • 1,811
  • 18
  • 20
0

I guess this is part of the challenges. The faq suggest raw_input() might not be the optimal approach:

The most common (possibly naive) methods are listed below. (...)

There are indeed Python standard modules helping to handle system input/output.