if line and not line[0].isdigit() and line != '\n':
のコードは、プロジェクトの中と外で動作が異なるのはなぜですか? 私はライン88での私のプロジェクトmeltsubtitlesから次のコード抜粋があります:私はプロジェクトからコードを抽出し、text.txt
でそれを実行したときにプリントアウトし、Pythonの `if`文は、どこで実行するかによって動作が異なりますか?
with open('test.txt', 'r', encoding='utf-8') as finput:
for line in finput:
if line and not line[0].isdigit() and line != '\n':
pass
else:
print(line)
を:
1
00:00:03,940 --> 00:00:07,550
2
00:00:09,280 --> 00:00:10,650
が、私を私のプロジェクトに同様のコードを入れて、最初のline '1\n'
は印刷されません。出力は次のとおりです。
00:00:03,940 --> 00:00:07,550
2
00:00:09,280 --> 00:00:10,650
私は何を期待することは次のとおりです、私はデバッグにpycharmを使用し、臨界線if line and not line[0].isdigit() and line != '\n':
にステップしているline = '1\n'
1
00:00:03,940 --> 00:00:07,550
2
00:00:09,280 --> 00:00:10,650
、if
while文にそれが妙実行それはではありませんが、コードを抽出すると、if
の文には反映されません。
test.txt
ファイル
1
00:00:03,940 --> 00:00:07,550
Horsin' Around is filmed before a live studio audience.
2
00:00:09,280 --> 00:00:10,650
Mondays.
私のプロジェクトはgithubの中に88 meltsubtitlesラインです私は、Python 3.5を実行しているし、勝利10
なぜdownvote? – EvanL00