【发布时间】:2016-01-31 08:19:34
【问题描述】:
对于这样的项目结构:
/tumblr
/tumblr
/module_foo
__init__.py
submodule_foo.py
/module_bar
__init__.py
submodule_bar.py
__init__.py
bot.py
我正在做类似的事情:
import sys
sys.path.append('C:\\repos\\bot\\tumblr\\tumblr')
from tumblr.bot import Bot
class SubmoduleFoo(Bot):
def __init__(self):
super().__init__()
# ...
# ...
if __name__ == "__main__":
SubmoduleFoo()
bot.py 只定义了一个带有一些初始化的空类:
import sys
sys.path.append('C:\\repos\\bot\\tumblr\\tumblr')
class Bot:
def __init__(self):
self.settings = dict()
# ...
如果我从命令行调用这些脚本,它们就可以工作:
python C:\path\to\submodule_foo.py
如果我双击我的 python submodule_foo.py "script" 它不起作用。
我认为问题是由继承引起的,并调用父 init
但由于我只是双击它,我不知道如何正确调试它。
我试图包含一个:
with open('codes.txt', 'a') as file:
file.write("It Works \n")
就在if __name__ == "__main__": 语句之后并且不起作用:$
我的 PATH 变量(在 Windows 10 中)包括 c:\python34 和 c:\python34\scripts
我还有一个PYHOME env 变量指向c:\python34
我已经尝试过这个解决方案:Python scripts stopped running on double-click in Windows 但它对我不起作用。
我还尝试通过 python 解释器创建这些类。并且导入到 tumblr.bot.Bot() 正在工作
我的想法快用完了。
【问题讨论】:
标签: python windows inheritance scripting