$PYTHONSTARTUP with python 2.7 and python 3.2

五迷三道 提交于 2019-12-05 00:24:49
Ned Batchelder

If you use Python 2 for some projects and Python 3 for others, then change the environment variable when you change projects.

Or, have your startup script look like this:

import sys
if sys.version_info[0] == 2:
    import startup2
else:
    import startup3

and split your real startup code into startup2.py and startup3.py

Set your $PYTHONSTARTUP to point to a script like this, which checks the version of Python being used, and then delegates to another startup script:

import sys
if sys.version_info[0]==2:
    from startup2k import *
elif sys.version_info[0]==3:
    from startup3k import *
else:
    # logging.warn('Unsupported version of Python')
    pass

Define an alias for one of the python versions. In the alias, reset PYTHONSTARTUP as appropriate for that python version:

alias py3='PYTHONSTARTUP=/path/to/startup.py /other/path/to/python3.2'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!