我从上到下搜索了这个网站,但还没有找到一种方法来真正实现我想要的Python3x.这是一个简单的玩具应用程序,所以我想我可以在asserts中编写一些简单的测试用例,并就此结束.它确实会生成报告,所以我希望确保我的代码在发生更改时不会做任何不可靠的事情.
我目前的目录 struct 是:(仅包含相关部分)
project
-model
__init__.py
my_file.py
-test
my_file_test.py
我在拿我的测试文件时非常痛苦.py导入我的_文件.皮耶.
就像我说的.我从上到下搜索了这个网站,没有找到有效的解决方案.我的Python版本是3.2.3,运行在Fedora 17上.
Previously tried attempts: https://stackoverflow.com/questions/5078590/dynamic-imports-relative-imports-in-python-3 Importing modules from parent folder Can anyone explain python's relative imports? How to accomplish relative import in python
几乎在每次try 中,我都会遇到以下错误:
ImportError:没有名为*
这是怎么回事.我已经在网上试过了所有被接受的答案.不是在这里做什么花哨的事,而是作为一个.NET/Java/Ruby程序员这被证明是直觉的绝对定义.
编辑:如果重要的话,我try 在REPL中加载我试图导入的类,我得到以下结果:
>>> import datafileclass
>>> datafileclass.methods
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
>>> x = datafileclass('sample_data/sample_input.csv')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
如果重要的话...我知道类中的功能可以正常工作,但我无法导入它,这导致现在无法进行测试.future 肯定会引发整合问题.(改名保护无辜)