Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个文件,每行由两个由变量空间分隔的字符串组成,如下所示:
"Doe, Mary" "W 135"
如何将其解析为字符串对["Doe, Mary", "W 135"]?
["Doe, Mary", "W 135"]
with open('file.txt') as f: pairs = csv.reader(f, delimiter=' ', skipinitialspace=True)
现在您可以创建一个列表pairs,在 for 循环中对其进行迭代,等等。
pairs