[英]Python read file line by line and print for debug
我正在嘗試逐行讀取文件。 該文件有很多行。
每行的格式如下:
data:otherdata1
data:someotherdata2
但是出於調試目的,我使用了幾行相同格式的文件。
我正在嘗試打印這些數據。
但是我得到了錯誤:
print data.split(':')
^
SyntaxError: invalid syntax
怎么了? 我真的迷失了。
def process(data):
print data.split(':') #printing for debug purposes
return data
file = open("list.txt")
for line in file:
process(line)
是的,我添加了import fileinput
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.