如果我有這樣的Python腳本:從類中找到的類的實例的名稱
class my_class(object):
def __init__(self):
pass
def get_name(self):
return [name of self]
this_is_the_name_im_looking_for = my_class()
print ('the name is: ' + this_is_the_name_im_looking_for.get_name())
我會有什麼才能具備的功能,以取代[個體經營的名稱]get_name返回'this_is_the_name_im_looking_for'?
我需要這個,因爲我創建一個Python模塊,並希望回饋他們使用
類的單個實例可被綁定到多個可變名稱:'this_name = my_class(); other_name = this_name; this_name is other_name == True' –
@ali_m我假設這不是這種情況,但這是一個有用的評論,儘管如此 –
或者,它可能根本沒有任何名稱:'mylist.append(my_class( ))'。 –