如標題所示,如何在另一個程序的類中調用函數?調用另一個程序的類中的函數 - Python
Class.py
class Object:
def __init__(self, mood):
self.__mood = mood
def set_mood(self, mood):
self.__mood = mood
def check_mood(self):
if random.randint(1, 3) == 1:
self.__mood = 'happy'
elif random.randint(1, 3) == 2:
self.__mood = 'hungry'
elif random.randint(1, 3) == 3:
self.__mood = 'sleepy'
def get_mood(self):
return self.__mood
Generator.py
from test import Object
import test
mood = 'happy'
ani = Object.test(mood)
print("This is your mood: " + get_mood())
情緒被設置爲 「幸福」 的默認值。我需要以使顯示的心情時,它並不總是顯示爲「幸福」
你能更清楚嗎?你不能只用check_mood方法來改變心情嗎? –
這個代碼是非常不一致的,至少可以說。 – Manhattan
什麼是Object.test()? – Dannnno