Python逐行读取文件并将每行的内容存入列表list中?

Python按行读取文件

How do I read every line of a file in Python and store each line as an element in a list?
I want to read the file line by line and append each line to the end of the list.

with open(fname) as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content] 

I’m guessing that you meant and not array.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

76 + = 83