Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python call function in class

#------------------------------------
#CLASS
#------------------------------------
class Student:
  def __init__(self):
    self.name = None
    
  def set_name(self, word):
    self.name = word
    return self.get_name()
    
  def get_name(self):
    return self.name
  
#------------------------------------
# USAGE:
#------------------------------------

a = Student()
print(a.set_name("Hello"))
Comment

how to run class.function from name python

class A:
    def __init__(self):
        pass

    def sampleFunc(self, arg):
        print('you called sampleFunc({})'.format(arg))

m = globals()['A']()
func = getattr(m, 'sampleFunc')
func('sample arg')

# Sample, all on one line
getattr(globals()['A'](), 'sampleFunc')('sample arg')
Comment

PREVIOUS NEXT
Code Example
Python :: print python reverse list 
Python :: python compiler online 
Python :: post from postman and receive in python 
Python :: assignment operators in python 
Python :: implement stack using list in python 
Python :: how to add axis labels to a plotly barchart 
Python :: python debugging 
Python :: .translate python 
Python :: how to print random in python 
Python :: python numpy how to empty array cycle 
Python :: How to add all the numbers of a list using python? 
Python :: deleting key from dictionary 
Python :: python index for all matches 
Python :: how to sum all the values in a list in python 
Python :: Python NumPy insert Function Example Working with arrays 
Python :: tree in python 
Python :: python foreach 2d array 
Python :: Implement a binary search of a sorted array of integers Using pseudo-code. 
Python :: class decorator python 
Python :: pd.cut in pandas 
Python :: what is django python 
Python :: python list remove() 
Python :: remove timezone from a datetime object? 
Python :: simple python program for beginners 
Python :: insert in python 
Python :: string slicing python 
Python :: kwargs in python 
Python :: numpy datatime to string 
Python :: watershed segmentation 
Python :: Syntax of Python Frozenset 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =