Search code examples
pythonpython-3.xstartupscript

$PYTHONSTARTUP with python 2.7 and python 3.2


I finally started using python 3 alongside python 2.7 on Linux.

I setup my python shell using a startup-script defined by $PYTHONSTARTUP. Due to incompatibilities I am unable to use the same script for both versions.

What is the easiest way to get one script for python 2.7, and another for python 3.2?


Solution

  • 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