更新时间:2021-12-16 06:29:07
字符串是可迭代的(就像列表一样).
Strings are iterable (just like a list).
我是在解释您确实想要像这样的东西:
I'm interpreting that you really want something like:
fd = open(filename,'rU')
chars = []
for line in fd:
for c in line:
chars.append(c)
或
fd = open(filename, 'rU')
chars = []
for line in fd:
chars.extend(line)
或
chars = []
with open(filename, 'rU') as fd:
map(chars.extend, fd)
字符将包含文件中的所有字符.
chars would contain all of the characters in the file.