简体   繁体   English

从文件中部分读取一行

[英]Reading a line partially from a file

I have a file in which data is stored in 4 columns such as:我有一个文件,其中数据存储在 4 列中,例如:

MOORE 0.312 5.312 9

Now I just want to read the name from the line and store in a list, but i am not able to figure out how to do it.现在我只想从行中读取名称并将其存储在列表中,但我不知道该怎么做。

Try this:尝试这个:

text = open('file.txt').readlines()

for line in text:
    print line.split(' ')[0]

不是 Python,但它不会变得更容易。

$ cut -d" " -f 1 < file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM