我正在使用ReportLab生成pdf。但是当我试图在其中附加图像时,它会给出错误。如果我不包括图片,那么一切都很好。代码成功运行。I/O错误:无法打开资源,同时从不同目录导入python文件
我有以下目录结构。
parentDir\
main.py
childDir\
__init__.py
first.py
second.py
image.jpg
main.py
from childDir.first import methodOfFirst
#using methodOfFirst
first.py
from second import methodOfSecond
#using methodOfSecond
second.py
#this second.py file have **ReportLab** Code
.............
canvas.drawImage('image.jpg', 0.2*inch, 11.12*inch, width=w*scale, height=h*scale)
.............
这是我的代码的基本骨架。但是,当我执行,它会产生错误:
raise IOError('Cannot open resource "%s"' % name)
IOError: Cannot open resource "tjsservices.jpg"
handle_pageBegin args=()
我是新来的Python和ReportLab的所以不知道什么是进口这样一种层次结构的正确途径。如果所有文件都在同一个目录中,那么它工作正常。但是当我使用这种目录结构时,它失败了。
只是为了简单起见,我提供了这个骨架。让我知道是否需要更多的代码。
所以问题是。为什么我得到这个错误以及如何解决它?这是ReportLab的问题(即reportLab不支持这种导入)或者我错误地导入文件? 任何帮助将不胜感激。
这样一个准确的答案非常感谢你。 – 2012-03-22 10:38:36