我在python上非常新,并且收到此错误。
Traceback (most recent call last):
File "C:\Users\kzul\Documents\Stigma-demo-game-master\testw32\testing.py", line 44, in <module>
dam = test().getClass('hello', 'dam')
File "C:\Users\kzul\Documents\Stigma-demo-game-master\testw32\testing.py", line 40, in getClass
objmod = self._impoter(modules, klass)
File "C:\Users\kzul\Documents\Stigma-demo-game-master\testw32\testing.py", line 24, in _impoter
fp, pathname, description = imp.find_module(pathmod)
ImportError: No module named hello\dam
我不知道为什么wndows中的python给了我这个错误,但在我的Linux中运行顺利。它说没有模块 hello \ dam :(
这是关于dam文件的目录
C:\Users\kzul\Documents\Stigma-demo-game-master\testw32\hello\dam.py
这是我在cmd上运行的代码
C:\Users\kzul\Documents\Stigma-demo-game-master\testw32>python testing.py
testw32 \ testing.py
中的代码import sys, imp
from os import path
from hello.dam import dam
class test:
def _impoter(self, instance, substance):
pathmod = path.join(instance, substance)
try:
return sys.modules[pathmod]
except KeyError:
pass
fp, pathname, description = imp.find_module(pathmod)
try:
return imp.load_module(pathmod, fp, pathname, description)
finally:
if fp:
fp.close()
def getClass(self, modules, klass):
objmod = self._impoter(modules, klass)
klass = getattr(objmod, klass)
return klass()
dam = test().getClass('hello', 'dam')
dam().hello()
文件中的代码 testw32 \ hello \ dam.py
class dam:
def hello(self):
print 'you did it'
我在windows中的environtment变量上设置了 PYTHONPATH , PYTHONHOME 和 PATH 但仍无法正常工作:(