2013-03-09 20 views
3

我在OS X 10.8终端中运行以下Python脚本,其行长度大约为200个字符。但脚本的输出大约在80行。 如何使输出线持续到控制台的长度?Python输出行包装

这里是我的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' ''] 
+1

这绝对是您需要设置的终端参数。 Python不关心你的终端窗口的宽度。它只是打印。 – 2013-03-09 15:03:21

+3

这是一个numpy的'array'表示的设置,让整行只用'str.join'来打印每个“datum”。 – Gandaro 2013-03-09 15:05:15

+0

@TimPietzcker:不,它不是。由于某些终端设置,终端不打印阵列。 – Gandaro 2013-03-09 15:06:09

回答

1

这是numpy的字节数组表示的设置,把它整条生产线,你就必须请用str.join自行打印每datum