読者です 読者をやめる 読者になる 読者になる

牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

Python Quick Referenceをゆっくり参照してみた 01 起動オプション

Python

以下を参照。

Invocation Options 起動オプション

(シェルで実行。>>>の表示はインタプリタ起動中。)

### -d

Output parser debugging information (also PYTHONDEBUG=x)

G5:~ username$ python -d
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 



### -E

Ignore environment variables (such as PYTHONPATH)

G5:~ username$ python -E
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 



### -h

Print a help message and exit (formerly -?)

G5:~ username$ python -h
usage: /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser (also PYTHONDEBUG=x)
-E     : ignore environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script, (also PYTHONINSPECT=x)
         and force prompts, even if stdin does not appear to be a terminal
-m mod : run library module as a script (terminates option list)
-O     : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)
-OO    : remove doc-strings in addition to the -O optimizations
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
-S     : don't imply 'import site' on initialization
-t     : issue warnings about inconsistent tab usage (-tt: issue errors)
-u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
         see man page for details on internal buffering relating to '-u'
-v     : verbose (trace import statements) (also PYTHONVERBOSE=x)
-V     : print the Python version number and exit (also --version)
-W arg : warning control (arg is action:message:category:module:lineno)
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ':'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>:<exec_prefix>).
               The default module search path uses <prefix>/pythonX.X.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
### -i

Inspect interactively after running script (also PYTHONINSPECT=x) and force prompts, even if stdin appears not to be a terminal.
下準備として、ファイルprint.pyを作成して「print "I love Python!"」と書いて保存しておく。(現在作業中のディレクトリに)

G5:~ username$ python -i
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
G5:~ username$ python -i print.py
I love Python!
>>>
### -m module

Search for module on sys.path and runs the module as a script. (Implementation improved in 2.5: module runpy)

G5:~ username$ python -m print
I love Python!
### -O

Optimize generated bytecode (also PYTHONOPTIMIZE=x). Asserts are suppressed.
保留(´・ω・`)

### -OO

Remove doc-strings in addition to the -O optimizations.
保留(´・ω・`)

### -Q arg

Division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
保留(´・ω・`)

### -S

Don't perform import site on initialization.
保留(´・ω・`)

### -t

Issue warnings about inconsistent tab usage (-tt: issue errors).
保留(´・ω・`)

### -u

Unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x).
保留(´・ω・`)

### -U

Force Python to interpret all string literals as Unicode literals.
保留(´・ω・`)

### -v

Verbose (trace import statements) (also PYTHONVERBOSE=x).

# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.pyc has bad magic
import site # from /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.py

:
長いので略
:

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so
>>>
### -V

Print the Python version number and exit.

G5:~ username$ python -V
Python 2.5.1
### -W arg

Warning control (arg is action:message:category:module:lineno)
保留(´・ω・`)

### -x

Skip first line of source, allowing use of non-unix Forms of #!cmd
保留(´・ω・`)

### -c command

Specify the command to execute (see next section). This terminates the option list (following options are passed as arguments to the command).
保留(´・ω・`)

### scriptFile

The name of a python file (.py) to execute. Read from stdin.

G5:~ username$ python print.py
I love Python!
### -

Program read from stdin (default; interactive mode if a tty).
保留(´・ω・`)

### args

Passed to script or command (in sys.argv[1:])
下準備として現在作業中のディレクトリにargv_hoge.pyファイルを作成し以下を書き込む。

import sys
for i in sys.argv[1:]:
    print i

実行と結果

G5:~ username$ python argv_hoge.py 1 2 3
1
2
3
G5:~ username$ python argv_hoge.py "a" "b" "c"
a
b
c
###

If no scriptFile or command, Python enters interactive mode.

G5:~ username$ python
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) 
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
補足

というか言い訳。
起動オプションなんて普段使わないから、よくわからず保留多し(´・ω・`)。そのうち...