Python 中 raw_input() 可以填充的最大字符数
对于 InterviewStreet 挑战,我们必须能够容纳从键盘输入的 10,000 个字符串,但是当我将 10k 长的单词复制/粘贴到本地测试中时,它会在 1000 个左右被截断。
Python 的官方限制是多少?有没有办法改变这一点?
谢谢大家
,这是挑战:
http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4edb8abd7cacd
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确定您的 10k 长单词不包含换行符吗?
raw_input
返回的缓冲区没有最大限制(在 python 中),并且当我测试了 stdin 的一些大长度输入时,我无法重现您的结果。我尝试在网上搜索有关此问题的信息,但没有找到任何可以帮助我回答您的问题的信息。我的测试
Are you sure of the fact that your 10k long word doesn't contain newlines?
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
我也有同样的经历,并且发现如果不导入 readline 模块,Python 就会限制 raw_input 的输入长度。一旦我导入了 readline 模块,它就解除了限制(或者至少将其显着提高到我使用的文本工作得很好的程度)。这是在我的 Mac 上使用 Python
2.7.15
进行的。此外,已确认至少可在3.9.5
上运行。I had this same experience, and found python limits the length of input to
raw_input
if you do not import thereadline
module. Once I imported thereadline
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 Python2.7.15
. Additionally, it’s been confirmed working on at least3.9.5
.我想这是挑战的一部分。 常见问题解答表明 raw_input() 可能不是最佳方法:
确实有Python 标准模块可以帮助处理系统输入/输出。
I guess this is part of the challenges. The faq suggest raw_input() might not be the optimal approach:
There are indeed Python standard modules helping to handle system input/output.