我有一个非常简单的 python 脚本,它读入一个文件,并逐行解析它。
它似乎无法识别我行首的“//”。如果我将其更改为在行首查找“#”,它也找不到这些行。我只是误解了这一点吗?
line = fIn.readline()
while line:
print "line is", line
line = line.strip()
if line.startswith('//'):
print "winner"
line = fIn.readline()
我正在阅读的文件如下所示:
// Feedback
"Feedback" = "Feedback";
// New strings
"File URL not reachable." = "File URL not reachable.";
打印出来的调试行看起来很合适:
line is // Feedback
line is "Feedback" = "Feedback";
line is
line is // New strings
line is "File URL not reachable." = "File URL not reachable.";
line is