我仍然在學習並喜歡構建將來最終會定期完成的任務,以便更好地理解x如何執行此操作。在Python中通過多個類返回時遇到問題
我還沒有學到很多關於班級如何完全工作的知識,但是我建立了一個會經過多個班級的調用。
getattr(monster, monster_class.str().lower())(1)
調用該:
class monster:
def vampire(x):
monster_loot = {'Gold':75, 'Sword':50.3, 'Good Sword':40.5, 'Blood':100.0, 'Ore':.05}
if x == 1:
loot_table.all_loot(monster_loot)
進而調用這個...
然後,最後,到達最後一堂課。
class drop_chance:
def chance(loot_list):
loot_gained = []
for i in loot_list:
x = random.uniform(0.0,100.0)
if loot_list[i] >= x:
loot_gained.append(i)
return loot_gained
這一切都有效,除非它沒有返回loot_gained。我假設它只是返回到loot_table類,我不知道如何繞過它一路回到第一行發佈。我能得到一些見解嗎?
我需要在每個類定義中定義loot_gained嗎? – user2609785
呃,不......你只需要繼續使用'return'。 –
我剛剛開始把自己與我所做的所有編碼混淆起來......對此抱歉。我忘了設置getattr來打印,並按照您的建議進行。但是,我得到了loot_table位置的回報。 「0x000000000340B3C8」下的<__ main __。loot_table對象>「 – user2609785