Sample of getting module name and class name in Python

# -*- coding: utf-8 -*-

class Test(object):

    @classmethod
    def class_method(cls):
        print "cls.__module__", cls.__module__
        print "cls.__name__", cls.__name__

if __name__ == "__main__":
    Test.class_method()

Output result

cls.__module__: __main__
cls.__name__: Test

Recommended Posts

Sample of getting module name and class name in Python
[Python] Class type and usage of datetime module
Reference order of class variables and instance variables in "self. Class variables" in Python
Implementation module "deque" in queue and Python
Comparison of Japanese conversion module in Python3
Module import and exception handling in python
Project Euler # 1 "Multiples of 3 and 5" in Python
[python] Difference between variables and self. Variables in class
I wrote a class in Python3 and Java
Getting rid of DICOM images in Python Part 2
Explanation of edit distance and implementation in Python
case class in python
Class notation in Python
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Calculation of standard deviation and correlation coefficient in Python
The process of installing Atom and getting Python running
[python] Get the list of classes defined in the module
Difference between Ruby and Python in terms of variables
[python] Calculation of months and years of difference in datetime
Overview of generalized linear models and implementation in Python
Summary of date processing in Python (datetime and dateutil)
Python: Class and instance variables
Automatic update of Python module
Equivalence of objects in Python
Stack and Queue in Python
Python debug and test module
Sample usage of Python pickle
Unittest and CI in Python
Implementation of quicksort in Python
Getting list elements in Python
Source installation and installation of Python
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
Getting started and using sample class-based generic views in Django
Comparison of how to use higher-order functions in Python 2 and 3
I created a class in Python and tried duck typing
Predict gender from name using Gender API and Pykakasi in Python
[Python] Strengths and weaknesses of DataFrame in terms of time required
Sample of HTTP GET and JSON parsing with python of pepper
[Python] Class type and usage of datetime module
I tried using the Datetime module by Python
Environment construction of python and opencv
Pixel manipulation of images in Python
Create an instance of a predefined class from a string in Python
The story of Python and the story of NaN
MIDI packages in Python midi and pretty_midi
Count the number of Thai and Arabic characters well in Python
Getting the arXiv API in Python
Difference between list () and [] in Python
perl objects and python class part 2.
Difference between == and is in python
Installation of SciPy and matplotlib (Python)
[Python] logging in your own module
View photos in Python and html
[Python of Hikari-] Chapter 09-03 Class (inheritance)
Sorting algorithm and implementation in Python
Division of timedelta in Python 2.7 series
MySQL-automatic escape of parameters in python
About dtypes in Python and Cython
Read PNG chunks in Python (class)
Assignments and changes in Python objects
Probability of getting the highest and lowest turnip prices in Atsumori
Implementation of life game in Python