python - Python 中 raw_input() 可以填充的最大字符数

标签 python raw-input

对于 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/

相关文章:

python - 有什么方法可以使 matplotlib 的 Nbagg 后端更快,或者 Inline 后端更高分辨率?

Python 2 原始输入(): EOFError when reading a line in WINDOWS 7 command prompt

python - 如何从 python 中的 raw_input 制作列表?

Python 通过写入 stdin 取消 raw_input/input?

python - 当用户决定是否在 raw_input 中写入任何内容时如何做其他事情?

c++ - 在 Windows 上模拟原始输入

Python:带有 2 个样本的二维 Kolmogorov-Smirnov

python - 数据帧行的快速笛卡尔求和

python - 将本地时间转换为 UNIX 时间

python lxml 在 windows 和 linux 上的不同结果