Answers for "call class function by string python"

0

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"))
Posted by: Guest on February-18-2021
0

call class function by string python

import foo
method_to_call = getattr(foo, 'bar')
result = method_to_call()
Posted by: Guest on June-29-2021
0

call class function by string python

result = getattr(foo, 'bar')()
Posted by: Guest on June-29-2021

Code answers related to "call class function by string python"

Python Answers by Framework

Browse Popular Code Answers by Language