Pythonは、オブジェクトまたはクラス名を渡すことができる関数dirを提供し、このクラスのすべてのメンバーを出力できます。
print("Test Class")
class Video(object):
# 构造函数
def __init__(self):
print("Create Video")
# 析构函数
def __del__(self):
print("Delete Video")
# <class '__main__.Video'> 其中的这个__main__是入口模块名称
video1 = Video()
print(Video)
print(video1)
print(dir(video1))
print("end")
プログラム出力:
Test Class
Create Video
Delete Video
<class '__main__.Video'>
<__main__.Video object at 0x000001E5ADF2CA58>
['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
end
<クラスのメイン.Video '>
モジュールの名前にこの__main__対応し、我々はPythonプログラムであるため、将来的には、複数のファイルをファイルごとに一つのモジュールが参加する、複数のファイルとプログラムを書くと、複数ますファイルの場合、実行を開始するファイルを知っている必要があるため、エントリファイルが必要です。Pythonでは、エントリは__main__モジュールであるモジュールであるため、このモジュールの下のクラスはすべて__main__。クラス名です。