如何解决我需要帮助使用变量来引用类中的函数
我有一些代码想要工作。所以基本上我在这些类中有多个类和多个函数。用户输入类的名称和其中的函数,但我不知道如何使其工作。
这是我的代码:
Class = #The Users Input
Function = #The users Input
Class.Function # So I want to reference the function with the users input
出现语法错误。
解决方法
创建类:
class A:
def __init__(self):
#this function will be called everytime whenever the class is called
def func1(self):
#first function
def func2(self):
#second function
class B:
def __init__(self):
#this function will be called everytime whenever the class is called
def func1(self):
#first function
def func2(self):
#second function
调用类:
try1=A()
try2=B()
#calling function1 of the first class
a=try1.func1()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。