3

我在 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' ''] 
4

1 回答 1

1

这是 numpy 的数组表示的设置,要让它整行,你必须datum自己打印每个str.join.

于 2013-03-09T15:11:56.450 回答