'Python: How do I remove the input character length limit?

Recently, while trying to input a 5944 characters long string to my Python program, I noticed that only 4095 characters were being stored in the variable:

# file.py
var = input("Enter: ") # Input 4095+ characters long string.
print(len(var)) # Outputs 4095.

I tried doing the same in REPL and surprisingly, all the characters were stored in the variable!

>>> var = input("Enter: ") # Input 4095+ characters long string.
Enter: <6016 characters long string>
>>> len(var)
6016

So I have two questions:

  • Why is there a limit of 4095 input characters when taking it from a .py file but not in REPL?
  • Is there a way I can remove the input limit in the file as well?

I do plan on implementing a feature to let the user pass a file with their input instead, but I am curious about the answers to the above questions.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source