這樣:我怎樣才能使實例名稱的列表,然後可以例如做成一個類的實例
class Recipe:
def __init__(self, *args):
#does something with args
list = [schnitzel, goulash] #list of instance names
datalist =[[['chicken',2],['breadcrumbs', 100],['flour', 100]],[['beef', 500],['paprika powder', 100]] #these are the args which are in the same index as as its name in list.
for i in list:
i = Recipe(datalist[list.index(i)])
從這個
現在我要土豆燒牛肉和炸肉排,成爲一個實例。然而,問題在於燉牛肉和炸肉排都是未定義的變量,所以當我嘗試列表時會失敗。我嘗試將名稱變爲字符串:
list = ['schnitzel', 'goulash']
但它仍然無法工作。
任何想法我可以做到這一點?謝謝!
我不認爲這是OP要求... – TerryA
因爲他的問題與他的名單有關:「問題是燉牛肉和炸肉排都是未定義的變量,所以當我嘗試列表時失敗」 – TerryA