【Python】—— 动态获取类的名称
核心语句:type(self).__name__实现:#!/usr/bin/python# -*- coding: utf-8 -*-# @File: class_name.py# @Time: 2019/3/25 22:55# @Author: MaiXiaochai# @Site: https://github.com/MaiXiaoch...
·
核心语句:
type(self).__name__
实现:
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @File : class_name.py
# @Time : 2019/3/25 22:55
# @Author : MaiXiaochai
# @Site : https://github.com/MaiXiaochai
class ShowHello:
def __init__(self, name):
self.name = name
def my_name(self):
print("class_name: {}".format(type(self).__name__))
if __name__ == "__main__":
hello = ShowHello('Python')
hello.my_name()
结果:
# class_name: ShowHello
The end.
更多推荐



所有评论(0)