[英]An error occured when reading lines by readlines() method
The following function is defined to read the content of the .csv file and store it into lists: 定义以下功能以读取.csv文件的内容并将其存储到列表中:
def _read_txt_file(self):
self.img_paths = []
self.labels = []
with open(self.txt_file, 'r') as f:
lines = f.readlines()
for line in lines:
items = line.split(',') # .csv
self.img_paths.append(items[0])
self.labels.append(int(items[1]))
Something wrong has happened in line 6. The PyCharm debugger shows normal values of variable lines
, ie '../ZP_45151/0.bin,0\\n'
, '../ZP_45151/0.bin,1\\n'
and so forth. 一些错误的管线6发生的PyCharm调试器显示可变的正常值
lines
,即'../ZP_45151/0.bin,0\\n'
, '../ZP_45151/0.bin,1\\n'
等向前。 But the line
variable displays a weird value, that is, ',\\n'
, which is obviously that something has been lost. 但是
line
变量显示一个奇怪的值,即',\\n'
,这显然是丢失了一些东西。 Does anyone have an idea that why the operation is not going through the complete content? 有谁知道为什么操作没有遍历全部内容?
Well, I checked my reading .csv file and found that there are plenty of blank lines expressed as ',\\n'
in string format. 好吧,我检查了读取的.csv文件,发现有很多空白行以字符串格式表示为
',\\n'
。 The issue has been settled. 该问题已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.