Python 输出换行

标签 python osx-mountain-lion

我在 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/

相关文章:

python - 无法将文件上传到 Google 云端硬盘

python - 在 debian 上打包使用 perl 和 python 的应用程序

ios - Xcode 4 ios模拟器权限问题

python - 如何将csv读入多维数组

python - 如何在 Telegram bot (Python) 中使用 inline_keyboard 代替键盘?

Python 捕获自定义异常

homebrew - OSX Mountain Lion Homebrew doctor 导入 cdo 时出错

cron - 如何检查Macbook Lid是否通过终端关闭?

objective-c - 使应用程序在全屏应用程序上弹出

macos - 查找当前桌面图片的路径