如何从 python 包中导出自身文件?

2016-06-02 20:19:01 +08:00
 zeroten

有包 testcli, testcli 中有文件 b.py等 ,如何把这个文件导出或者说复制出来?

具体场景是通过

entry_points={
        'console_scripts':[
            'testcli= testcli.cli:main'
        ]

设定命令行工具入口,现在进入了 testcli.cli:main 函数,在这个 main 函数中,怎么写才能把包 a 中的所有文件导出来呢?

3148 次点击
所在节点    Python
3 条回复
xiaket
2016-06-02 20:28:38 +08:00
你试试 from testcli import a 后 print dir(a)看下?
NxnXgpuPSfsIT
2016-06-03 08:58:58 +08:00
@zeroten 包 a 是哪个?
目录结构是下面这样么?
testcli/
__init__.py
b.py
cli.py
a/
__init__.py
Pythagodzilla
2016-06-03 11:11:47 +08:00
import module
print module.__file__

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/283077

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX