且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将字符串分解为Python中的字符列表

更新时间: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.