2 回答
TA贡献1795条经验 获得超7个赞
解决方法如下:
import pandas as pd
df = pd.read_excel('stock.xlsx')
inventory_code = df['code'].tolist()
inventory_name= df['name'].tolist()
inventory_amount = df['amount'].tolist()
inventory_unit = df["birim"].tolist()
inventory_location=df["location"].tolist()
class Inventory:
def __init__(self,i_code,i_amount,i_unit,i_location):
self.i_code=i_code
self.i_amount=i_amount
self.i_unit=i_unit
self.i_location=i_location
def info(self):
print("Product code:", self.i_code, "Amount:", self.i_amount, "Unit:", self.i_unit, "Place:", self.i_location)
def add(self, add_amount):
self.i_amount += add_amount
def update(self):
for i in range(0, len(inventory_name)):
if inventory_code[i] == self.i_code:
mylist2.append(self.i_amount)
else:
mylist2.append(inventory_amount[i])
for i in range(0,len(inventory_name)):
globals()[inventory_name[i]]=Inventory(inventory_code[i],inventory_amount[i],inventory_unit[i],inventory_location[i])
mylist2=[]
folyo.info()
folyo.add(4000)
folyo.update()
folyo.info()
print(mylist2)
print(len(inventory_amount))
print(len(mylist2))
TA贡献1853条经验 获得超9个赞
解决方法如下:
import pandas as pd
df = pd.read_excel('stock.xlsx')
inventory_code = df['code'].tolist()
inventory_name= df['name'].tolist()
inventory_amount = df['amount'].tolist()
inventory_unit = df["birim"].tolist()
inventory_location=df["location"].tolist()
class Inventory:
def __init__(self,i_code,i_amount,i_unit,i_location):
self.i_code=i_code
self.i_amount=i_amount
self.i_unit=i_unit
self.i_location=i_location
def info(self):
print("Product code:", self.i_code, "Amount:", self.i_amount, "Unit:", self.i_unit, "Place:", self.i_location)
def add(self, add_amount):
self.i_amount += add_amount
def update(self):
for i in range(0, len(inventory_name)):
if inventory_code[i] == self.i_code:
mylist2.append(self.i_amount)
else:
mylist2.append(inventory_amount[i])
for i in range(0,len(inventory_name)):
globals()[inventory_name[i]]=Inventory(inventory_code[i],inventory_amount[i],inventory_unit[i],inventory_location[i])
mylist2=[]
folyo.info()
folyo.add(4000)
folyo.update()
folyo.info()
print(mylist2)
print(len(inventory_amount))
print(len(mylist2))
添加回答
举报