scriptpath = "../Test/"
# Add the directory containing your module to the Python path (wants absolute paths)sys.path.append(os.path.abspath(scriptpath))
# Do the importimport MyModule
class secretclass:def secretmessage(cls, myarg):return myarg + " is if.. up in the sky, the sky"secretmessage = classmethod( secretmessage )
def skycake(cls):return "cookie and sky pie people can't go up and "skycake = classmethod( skycake )
将此代码放入您的main.py(可以在任何地方):
import usermsg = "The only way skycake tates good"msg = user.secretclass.secretmessage(msg)msg += user.secretclass.skycake()print(msg + " have the sky pie! SKYCAKE!")
运行它,你应该得到这个:
$ python main.pyThe only way skycake tates good is if.. up in the sky,the skycookie and sky pie people can't go up and have the sky pie!SKYCAKE!
如果您在此处收到错误:ModuleNotFoundError: No module named 'user',则表示您使用的是python3,默认情况下会禁用startuphooks。