Passing options to Python executable in non-interactive mode

后端 未结 4 915
故里飘歌
故里飘歌 2021-01-21 04:09

I would like to pass some options to Python (version 2.6) every time, not just in interactive mode. Is there a file I can put such commands in?

EDIT: Specifically, I\'m

4条回答
  •  再見小時候
    2021-01-21 04:39

    Most of the options can be passed in as environment variables -- do python -h to see the list:

    $ py26 -h|grep PYTH
    -B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
    -d     : debug output from parser; also PYTHONDEBUG=x
    -E     : ignore PYTHON* environment variables (such as PYTHONPATH)
             if stdin does not appear to be a terminal; also PYTHONINSPECT=x
    -O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
    -s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
    -u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
    -v     : verbose (trace import statements); also PYTHONVERBOSE=x
    PYTHONSTARTUP: file executed on interactive startup (no default)
    PYTHONPATH   : ':'-separated list of directories prefixed to the
    PYTHONHOME   : alternate  directory (or :).
    PYTHONCASEOK : ignore case in 'import' statements (Windows).
    PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
    

    Are you concerned with other flags that can't be set via environment variables?

    PS the PYTHONINSPECT=x is the equivalent of -i (the grep cut that info because it comes on the immediately previous line;-).

提交回复
热议问题