我(尝试)解析我的研究小组使用的软件的输出,到目前为止,我能够逐行迭代我需要的列表(好吧,这有点烦人的空在循环结束时列出[])。当我尝试将每次迭代中的列表附加到一个大列表(列表列表)时,真正的问题就开始了,所以我可以在循环之外使用它。
到目前为止,这是代码:
vdf_file_path = "/home/henrique/Coding/Python/VEDA2XLSX/nq1a.vdf"
vdf_big_list = []
vdf_s_lines_string = """ """
with open(vdf_file_path, "r") as vdf_all_input_lines:
for vdf_line in vdf_all_input_lines.readlines()[4:]:
if "Frequencies" in vdf_line:
break
else:
vdf_s_line_fixed = vdf_line.strip()
vdf_s_lines_list = list(filter(None,vdf_s_line_fixed.split(" ")))
vdf_big_list = vdf_big_list.append(vdf_s_lines_list)
(请原谅我乱糟糟的代码,我还在学习)
然后我收到错误:
Traceback (most recent call last):
File "/home/henrique/Coding/Python/VEDA2XLSX/importvdf.py", line 12, in <module>
vdf_big_list = vdf_big_list.append(vdf_s_lines_list)
AttributeError: 'NoneType' object has no attribute 'append'
尽管阅读了here提供的答案并尝试了几种方法,但我仍然无法理解问题是什么并修复它。
有任何建议吗?
数据样本:
abbreviation of: e:\documents\yyyy\yyyyyy-yyyyyy\camb3lyp\dmso\veda\nq1a.ved
IR spectrum from file: e:\Documents\yyyyyyy\yyyyyyyyy-yyyyyyyy\CAMB3LYP\dmso\Veda\nq1a.out
diagonality factor = 53.06 <EPm> = 49.71
IR RAMAN CM-1
245.54 730.41 3538.10 s1 100
3.93 204.17 3237.13 s6 93
11.13 477.42 3233.43 s3 14 s5 76
3.44 136.83 3229.53 s3 -78 s5 15
262.17 212.10 1672.05 s16 61
117.64 169.79 1669.31 s17 -64 s41 14
9.66 60.78 1657.86 s19 -59 s44 10
981.59 1079.26 1642.51 s18 -56
1030.99 315.40 1578.03 s37 40 s42 10
185.95 27.40 1559.81 s37 20 s42 -37
55.61 10.42 1535.81 s39 -53 s63 14
4.91 5.16 1507.94 s20 -37 s40 44
59.12 24.29 1504.96 s47 69 s76 -23
14.09 29.85 1492.35 s46 -71 s75 22
19.97 9.49 1487.58 s48 86
17.93 4.37 1469.24 s21 -39 s43 -27
答案 0 :(得分:2)
append
不会返回任何内容。最后一行应该是:
vdf_big_list.append(vdf_s_lines_list)
答案 1 :(得分:2)
这种情况正在发生,因为vdf_big_list
的返回为无。
第一次追加时,vdf_big_list.append(vdf_s_lines_list)
被指定为无。
将代码更改为
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home//venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/app/management/commands/index_users.py", line 19, in handle
bulk_indexing(User)
File "/home/uapp/management/commands/index_users.py", line 12, in bulk_indexing
bulk(client=es, actions=(m.indexing() for m in model.objects.all()))
File "/home/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 257, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/home//venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 180, in streaming_bulk
client.transport.serializer):
File "/home/venv/local/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 58, in _chunk_actions
for action, data in actions:
File "/home/app/management/commands/index_users.py", line 12, in <genexpr>
bulk(client=es, actions=(m.indexing() for m in model.objects.all().iterator()))
File "/home/app/models.py", line 137, in indexing
obj.save(index="users")
File "/home/venv/local/lib/python2.7/site-packages/elasticsearch_dsl/document.py", line 418, in save
return meta['created']
KeyError: 'created'