我有两个python文件:main.py和imported.py。我想将imported.py导入main.py但我想访问import.py文件中的main.py路径。那就是我想要访问导入模块的路径。例如:
#main.py
import imp
imported = imp.load_source('imported', "/absolute/path/to/imported.py")
#imported.py
pathToImportingModule=os.path.???
doSomethingWithPath(pathToImportingModule)
答案 0 :(得分:0)
来自ekhumoro的评论中收到的解决方案:
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table
doc = SimpleDocTemplate("example.pdf", pagesize=letter)
data = [
['aaq', '56.18%', 'CC'],
['jasl', '0.00%', 'JO'],
['arw', '1.74%', 'AS'],
['vcf', '1.07%', 'DA'],
['hsw', '0.00%', 'LO'],
['wey', '41.01%', 'IS'],
['fol', '0.00%', 'MO'],
['aaw', '0.00%', 'AP'],
['sta', '0.00%', 'TT'],
]
doc.build([Table(data)])