Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String from input is limited?

I'm taking user input from the console but it will only accept 4096 bytes (4kb) of input. Since that is such a specific number is it something that is built into the language/is there a way around it?

The code I'm using:

message = input("Enter Message: ")
like image 457
noviceOne Avatar asked May 19 '15 02:05

noviceOne


People also ask

How do you limit input strings?

Complete HTML/CSS Course 2022 The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively.

How do you limit a string input in python?

To limit user input length: Use a while loop to iterate until the user enters a string of the specified length. Check if the user entered a message of the given length. If the condition is met, break out of the loop.

How do you change the length of an input in python?

you can use getkey() or getstr(). but using getstr() is simpler, and it give the user choice to enter less than 5 char if he want, but no more than 5.


2 Answers

is it something that is built into the language

No, the limitation is not part of Python, it's a limitation of the console shell.

is there a way around it?

That depends on your operating system. See this answer for how to enter more than 4096 characters at the console on Linux:

Linux terminal input: reading user input from terminal truncating lines at 4095 character limit

like image 198
samgak Avatar answered Oct 06 '22 00:10

samgak


4096 is 2^12

If you want larger input, please consider reading the message from a file instead.

with open('myfile.txt', 'r') as f:
    text = f.read()

Now, text will be a string which is all the text in the file. You can also do:

text = text.split('\n')

Now, text is a list of the lines in your text file

like image 30
sshashank124 Avatar answered Oct 05 '22 23:10

sshashank124