Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to check if a variable holds a class reference in python

#how to check if a variable holds a class reference, if it is an instance
#or a function or a method in python
import inspect
class cls:
  pass

print(inspect.isclass(cls))
>True
instance = cls()
print(issinstance(instance, cls))
>True
print(inspect.isclass(instance))
>False

#you can also use
#inspect.isfunction(function_name)
#inspect.ismethod(method_name)
Comment

PREVIOUS NEXT
Code Example
Python :: how to use django-rest-framework-datatables 
Python :: how to check if string is in byte formate pythin 
Python :: how to convert string to integer in python 
Python :: django cleanup 
Python :: matrix diagonal sum leetcode in java 
Python :: python enumerate 
Python :: numpy copy a array vertical 
Python :: appending items to a tuple python 
Python :: flask app with spark 
Python :: argparse accept only few options 
Python :: how to get the length of a string in python 
Python :: access column pandas 
Python :: Converting objects into integers in python 
Python :: loads function in json python 
Python :: string list to int list python 
Python :: django admin readonly models 
Python :: keyboard python 
Python :: python concatenate strings 
Python :: python not equal to symbol 
Python :: django model query join 
Python :: qt setfocus 
Python :: pytorch dill model save 
Python :: change column names pandas 
Python :: how to configure a button in python tkinter 
Python :: create_polygon tkinter 
Python :: array creation in numpy 
Python :: removing duplicates using json python 
Python :: print all variables jupyter notebook 
Python :: how to add zeros in front of numbers in pandas 
Python :: difference between set and list in python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =