gpt4 book ai didi

python - 错误: TypeError: can't multiply sequence by non-int of type 'list'

转载 作者:行者123 更新时间:2023-12-03 08:02:40 26 4
gpt4 key购买 nike

我只是从python开始,并针对此错误。有谁知道为什么以及是否将数据保存为整数或如何做到这一点?

Traceback (most recent call last):
File "C:\Users\Gabriela Lammoglia\AppData\Local\Programs\Python\Python37-32\open.py", line 34, in <module>
latt2=mult*lattice

码:
from csv import reader
from collections import defaultdict
from ast import literal_eval
from pprint import pprint

data = defaultdict(list)
with open('crystal.csv') as f:
csv_reader = reader(f)

current_header = None
for line in csv_reader:

# We found a header
if len(line) == 1 and all(item.isalpha() or item.isspace() for item in line[0]):
current_header = line[0]

# Otherwise normal line with ints and floats
else:
data[current_header].append(list(map(literal_eval, line)))

pprint(data)

mult=data['multiplicty']
lattice=data['lattice parameters']
occup=data['occupancy']
sites=data['atom sites']

print(mult)
print(lattice)
print(occup)
print(sites)

import numpy as np
latt2=mult*lattice

最佳答案

latt2=int(mult)*lattice
您需要将多值设为整数。现在,您尝试使用多个字符串和列表,这是个坏主意。

关于python - 错误: TypeError: can't multiply sequence by non-int of type 'list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53552895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com