Does python print function have a line length limit that it can print?

I am trying to print a large line, and it is in the size of 100 MB, and this needs to be done in one shot. It seems to be truncating.

+6
source share
2 answers

although this does not answer your question, to move data with print data is probably a bad idea: print is for short information printouts. it provides functions that are usually not needed when moving big data, such as formatting and adding EOL.

Instead, use something lower level, like write in the sys.stdout file sys.stdout (or some other file descriptor, this makes it easy to write to the file instead of stdout)

  out=sys.stdout out.write(largedata) 

you also probably want to re-delete the data before output:

  # this is just pseudocode: for chunk in largedata: out.write(chunk) 

.write does not add an EOL symbol, so outputting multiple pieces will be practically indistinguishable from outputting all in one big move. but you have the advantage of not overlapping any buffers.

+3
source

About the maximum size of your line that you can print to stdout using the print function, since you need to pass your text as a python object to the print function, and since the maximum size of your variable depends on your platform, it can be 2 31 - 1 per 32-bit platform and 2 63 - 1 on a 64-bit platform.

You can also use sys.maxsize to get the maximum size of your variables:

sys.maxsize

An integer giving the maximum value can take a variable of type Py_ssize_t. Its usually 2 ** 31 - 1 on a 32-bit platform and 2 ** 63 - 1 on a 64-bit platform.

+1
source

All Articles