我的 Spyder ide 中有以下设置:
此程序显示以下异常:
runfile('C:/Users/pc/source/repos/python_package_and_module_test/main.py', wdir='C:/Users/pc/source/repos/python_package_and_module_test')
Reloaded modules: jupyter_client.session, zmq.eventloop, zmq.eventloop.ioloop, tornado.platform, tornado.platform.asyncio, tornado.gen, zmq.eventloop.zmqstream, jupyter_client.jsonutil, jupyter_client.adapter, spyder, spyder.pil_patch, PIL, PIL._version, PIL.Image, PIL.ImageMode, PIL.TiffTags, PIL._binary, PIL._util, PIL._imaging, cffi, cffi.api, cffi.lock, cffi.error, cffi.model
Traceback (most recent call last):
File "C:\Users\pc\source\repos\python_package_and_module_test\main.py", line 1, in <module>
import token.factoryclass as a
ModuleNotFoundError: No module named 'token.factoryclass'; 'token' is not a package
我该如何解决这个问题?
源代码:
我的文件如下:
import token.factoryclass as a
var = a.factoryclass();
var.print();
class factoryclass(object):
def print(object):
print("factoryclass")
class tokenclass(object):
def print(object):
print("tokenclass")
class factoryclass(object):
def print(object):
print("factory.factoryclass")
class tokenclass(object):
def print(object):
print("factory.tokenclass")
class factoryclass(object):
def print(object):
print("token.factoryclass")
class tokenclass(object):
def print(object):
print("token.tokenclass")
然而,相同的包和模块结构在 repl.it 中工作: