我想在一个类中导入一些功能,而无需导入整个类。
我的课如下
class MyClass:
def __init__(self):
pass #Some init stuff
def some_funcs(self):
pass #Some other funcs
@staticmethod
def desired_func():
pass #The func i want to import
Run Code Online (Sandbox Code Playgroud)
from MyClassFile import MyClass.desired_func
Run Code Online (Sandbox Code Playgroud)
要么
from MyClassFile.MyClass import desired_func
Run Code Online (Sandbox Code Playgroud)
我试图以这种方式导入,但无法正常工作,有什么办法可以做到吗?