Python GUI 开发的最佳实践与技巧
1. 摆脱 Eclipse PYTHONPATH 依赖
在 Python 开发中,我们有时会遇到依赖特定 IDE 配置的问题,比如 Eclipse 的 PYTHONPATH 变量。以下代码展示了如何摆脱这种依赖:
from pprint import pprint
#=======================================================
# Required setup for the PYTONPATH in order to find
# all package folders
#=======================================================
from site import addsitedir
from os import getcwd, chdir, pardir
for _ in range(10):
curFull = getcwd()
curDir = curFull.split('\\')[-1]
if 'B04829_Ch11_Code' == curDir:
addsitedir(curFull)
addsitedir(curFull + '\\Folder1\\Folder2\\Folder3\\')
break
chdir(pardir)
pprint(path)
运行这段代码后,我们可以在不依赖 Eclipse 的 PYTHONPATH 变量的情况下运行 GUI
超级会员免费看
订阅专栏 解锁全文
1358

被折叠的 条评论
为什么被折叠?



