Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write lines longer than 80 chars in output file [Python]

I've got a pretty basic question. I'm using Python to calculate an n×12 vector

y = numpy.array([V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12])

which I append after each loop calculation.

My problem is that when I try to save it to a file or print it Python automatically breaks the result in three lines as my output usually exceeds 200 chars. Is there a way to supress this 80 char/line behavior? Many thanks in advance.

like image 706
Saki Avatar asked Nov 26 '10 15:11

Saki


People also ask

How do you print a long text in Python?

Use a backslash ( \ ) as a line continuation character In Python, a backslash ( \ ) is a line continuation character. If a backslash is placed at the end of a line, it is considered that the line is continued on the next line.

How do you shorten long lines of code in Python?

Summary. If you have a very long line of code in Python and you'd like to break it up over over multiple lines, if you're inside parentheses, square brackets, or curly braces you can put line breaks wherever you'd like because Python allows for implicit line continuation.

How do you print multiple lines on one line in Python?

To print multiple expressions to the same line, you can end the print statement in Python 2 with a comma ( , ). You can set the end argument to a whitespace character string to print to the same line in Python 3.


1 Answers

You can use numpy.savetxt() to save an array to a text file while controlling the formatting. To print it to the screen, you have different options to control the linewidth. One would be to call

numpy.set_printoptions(linewidth=200)

to set the linewidth to a higher value.

like image 70
Sven Marnach Avatar answered Sep 24 '22 09:09

Sven Marnach