在输出文件中写入长度超过80个字符的行[Python] [英] Write lines longer than 80 chars in output file [Python]

查看:497
本文介绍了在输出文件中写入长度超过80个字符的行[Python]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题。我使用Python来计算一个n×12的向量

pre $ y $ n $ p $ ,V5,V6,V7,V8,V9,V10,V11,V12])

我的问题是,当我试图将其保存到一个文件或打印
Python自动将结果分成三行,作为我的
的输出通常超过200个字符。有没有办法来抑制这个80字符/行的
?非常感谢。

解决方案

您可以使用 numpy.savetxt() 将数组保存到文本文件格式化。要将其打印到屏幕上,您有不同的选项来控制线宽。其中一个是
pre $ numpy.set_printoptions(linewidth = 200)

将线宽设置为更高的值。


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.

解决方案

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.

这篇关于在输出文件中写入长度超过80个字符的行[Python]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆