我在Python中遇到了一些项目问题。这是参考Qn 48的Learn Python the Hard Way。如何在Python项目中正确组织文件
测试仪lexicon_tests.py
那的投掷了一个问题行:
from ex48 import lexicon
我看到的错误是:
ImportError: no module named ex48
我不知道这是因为我还没有安排我的文件正确地在项目文件夹内:我有一个名为ex48
的文件夹,其子文件夹包括tests
和lexicon
。在lexicon
之内,我有文件lexicon.py
。在tests
之内,我有文件lexicon_tests.py
在上述组织中是否有错误?
编辑:张贴在这里的代码 -
在/ ex48,我有setup.py
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'description': 'My Project',
'author': 'MyName',
'url': 'URL to get it at.',
'download_url': 'Where to download it.',
'author_email': 'My email.',
'version': '0.1',
'install_requires': ['nose'],
'packages': ['ex48'],
'scripts': [],
'name': 'projectname'
}
setup(**config)
在/ ex48 /词库,我有lexicon.py
class lexicon:
@staticmethod
def scan(string):
direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']
verbs = ['go','stop','kill','eat']
stop = ['the','in', 'of', 'from', 'at','it']
nouns = ['door', 'bear', 'princess', 'cabinet']
words = string.split()
result = []
for word in words:
if word in direction:
result.append(('direction',word))
和等等。 。 。与return result
在最后。所有环境变量都已正确添加。我看到的错误是ImportError
,名称词汇。
学习Python硬盘的方式:'帮助( '进口')'。 ':D' – Droogans 2012-02-14 11:49:25