擅长:python、mysql、java
<p>你有没有试过拆分成一个列表,然后删除空白元素??你知道吗</p>
<pre><code>f = open('file.txt', 'rb')
raw_str = str(f.read())
full_list = raw_str.split(';')
templist = list(filter(None, full_list))
</code></pre>
<p>通过打印templast,它给出了所有元素的列表。您可以根据需要使用for循环对其执行任何操作,如再次转换为字符串。输出就像-
<a href="https://i.stack.imgur.com/aa4QT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aa4QT.png" alt="enter image description here"/></a></p>