我在 OS X 10.8 终端中运行以下 Python 脚本,行长约为 200 个字符。然而,脚本的输出在第 80 行左右被换行。 我怎样才能使输出行持续到控制台的长度?
这是我的 Python 脚本:
import csv as csv
import numpy as np
#Open up the csv file in to a Python object
csv_file_object = csv.reader(open('./data/train.csv', 'rb'))
header = csv_file_object.next() #The next() command just skips the
#first line which is a header
data=[] #Create a variable called 'data'
for row in csv_file_object: #Run through each row in the csv file
data.append(row) #adding each row to the data variable
data = np.array(data) #Then convert from a list to an array
#Be aware that each item is currently a string in this format
for datum in data:
print datum[0:10]
我得到的输出是这样的:
['1' '3' 'Najib, Miss. Adele Kiamie "Jane"' 'female' '15' '0' '0' '2667'
'7.225' '']
['0' '3' 'Gustafsson, Mr. Alfred Ossian' 'male' '20' '0' '0' '7534'
'9.8458' '']
最佳答案
这是 numpy 数组表示的设置,要让它整行,你必须自己用 str.join
打印每个 datum
。
关于Python 输出换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15312113/