对于 InterviewStreet 挑战,我们必须能够从键盘输入 10,000 个字符的字符串,但是当我将 10k 长的单词复制/粘贴到我的本地测试中时,它会在 1000 左右截断。
Python 的官方限制是什么?有没有办法改变这种情况?
谢谢大家
下面是挑战:
http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4edb8abd7cacd
最佳答案
您确定您的 10k 长单词不包含换行符吗?
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.
raw_input
返回的缓冲区没有最大限制(在 python 中),并且当我测试了一些输入到 stdin 的大长度时,我无法重现您的结果.我试图在网上搜索有关这方面的信息,但没有找到任何可以帮助我回答您的问题的信息。
我的测试
:/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
关于python - Python 中 raw_input() 可以填充的最大字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8469122/