__module__,__class__

目录

# lib/aa.py
class C:
    def __init__(self):
        self.name = 'SB'
# index.py

from lib.aa import C

obj = C()

__module__

  • __module__ 表示当前操作的对象在那个模块
print(obj.__module__)  # 输出 lib.aa,即:输出模块

__class__

  • __class__表示当前操作的对象的类是什么
print(obj.__class__)  # 输出 lib.aa.C,即:输出类

猜你喜欢

转载自www.cnblogs.com/nickchen121/p/10991513.html
今日推荐