python - list.append() 不向列表添加任何值

标签 python

我想打开一个 pdb 文件并提取其序列,但是 list.append() 没有将任何对象添加到我的列表中并显示 [ ] 作为输出。我尝试了所有可能的替代方案,但这根本不起作用。

  file=open("c:/pdb/1ana.pdb")
  for lines in file:
      list1=lines.split()
      id=list1[0]
      list=[]
      if id=='ATOM':
          if list1[2]=='C4':
              list.append(list1[3])
 print(list)

最佳答案

list=[] 位于 for 循环内,它将在每次迭代中重置 list

此外,避免使用 list 作为变量名,因为 list 是 python 中的关键字

关于python - list.append() 不向列表添加任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44538056/

相关文章:

python - 为什么在使用 dask 时 zarr 的性能比 Parquet 好得多?

python - "import ... from ..."有性能优势吗?

python - 使用 Python Flask 上传 CSV 文件并进行处理

python - 数据帧列表理解 "zip(...)": loop through chosen df columns efficiently with just a list of column name strings

python - SQLalchemy 基于Mixin列的联合继承查询

php - 如何结合 Prestashop (PHP) 和 DjangoCMS (Python)

python - 在Python中处理二维列表边界检查的最佳方法?

python - 数组与散列键搜索

python - 在 Visual Studio Express 2013 中自动生成 python 文档字符串

python - 使用 Pandas 在数据框中创建带有整数的字符串