Gal*_*hok 0 python python-3.x python-requests
如果使用Python 3.7中的条件,如何仅使用单个if条件而不是两个来重写下面的代码?
with open('demo.csv', 'r') as f, open("Result_csv.csv", 'w+') as out:
for line in f:
if '/tcp' in line:
print(line)
out.write(line)
if '/udp' in line:
print(line)
out.write(line)
Run Code Online (Sandbox Code Playgroud)
with open('demo.csv', 'r') as f, open("Result_csv.csv", 'w+') as out:
for line in f:
if '/tcp' in line or '/udp' in line:
print(line)
out.write(line)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |