<p>我正在逐行阅读一个文件,假设除了“如果”文件的这一行包含一个大写字母,我什么都不关心。因为如果是的话,我想用它。我不想使用文件的此行,如果它没有。在</p>
<p>我可以用if语句吗?或者我必须使用for循环。我已经有两个嵌套语句了。在</p>
<p>我的代码:</p>
<pre><code>with open(var) as config_file: #open file
for line in config_file: #line by line reading of file
#if "description" and capital letter is contain in line:
line = line.replace('\n' , '').replace('"' , '').replace(']' , '') #removes all extra characters
i = "| except " + (line.split("description ", 1)[1]) + " " #split the line and save last index (cust name)
cus_str+=i #<a href="https://www.cnpython.com/list/append" class="inner-link">append</a> to string
config_file.close()
</code></pre>