Skip to content Skip to sidebar Skip to footer

How To Input() Value Longer Than 4095 Characters?

I'm trying to input() a string containing a large paste of JSON. (Why I'm pasting a large blob of json is outside the scope of my question, but please believe me when I say I have

Solution 1:

Python has to follow the terminal rules. But you could use a system call from python to change terminal behaviour and change it back (Linux):

import subprocess,json

subprocess.check_call(["stty","-icanon"])
result = json.loads(input())
subprocess.check_call(["stty","icanon"])

Alternately, consider trying to get an indented json dump from your provider that you can read line by line, then decode.

data = "".join(sys.stdin.readlines())
result = json.loads(data)

Post a Comment for "How To Input() Value Longer Than 4095 Characters?"