我试图从excel表中导入数据到RPG游戏的类实例列表中。目前我正在尝试使用Pandas,下面是我一直在使用的代码:python3.7.2import pandas as pd
class potion(object):
def __init__(self, name, types, effects, value, weight):
self.name = name
self.types = types
self.effects = effects
self.value = value
self.weight = weight
df = pd.read_excel('Data/potions.xlsx', sheet_name='None')
potions = df.values.tolist()
print(potions)
输出为:
^{pr2}$
我要找的一个例子是要存储的数据,这样每一行都是实例列表的索引:potions = [potion('Crude Hp Potion', 'Hp Potion', 10, 10, 0.5),
potion('Hp Potion', ' hp Potion', 25, 50, 1.0)]
为了达到这个目的,我尝试:for i in potions[0]:
potions.append([potion(i)])
print(potions[0].name)
给了我:TypeError: __init__() missing 4 required positio