Reputation: 4084
On Windows, interactive Python sys.stdin.readline()
truncates Ctrl+V pastes to 512 characters.
How do I extend this limit? I need large pastes for prototyping.
Tried the fdopen()
trick and it didn't work.
The buffer seems to be 1024 on macOS.
UPD: Looks like the buffer size is a compile-time constant.
In C, it is possible to expand buffer with setvbuf()
, but this function is not wrapped by Python, which is sad. I guess I'll try to call it in MSVCRT.DLL
with ctypes
.
Upvotes: 3
Views: 732
Reputation: 2722
(On Mac OS)
Adding import readline
to your python script will extend the limit of input()
from https://docs.python.org/3/library/readline.html
The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. This module can be used directly, or via the rlcompleter module, which supports completion of Python identifiers at the interactive prompt. Settings made using this module affect the behaviour of both the interpreter’s interactive prompt and the prompts offered by the built-in input() function.
example
import readline
data = input()
print(data)
Upvotes: 1
Reputation: 4084
This is a bug: https://bugs.python.org/issue41849
sys.stdin.readline()
has 512-character buffer, indeedinput()
has 16K-character bufferSo currently input()
can be used as a workaround.
Upvotes: 0