ちょっとした修正.
@@ -4,123 +4,73 @@ | ||
4 | 4 | Python インタプリタを使う |
5 | 5 | ************************* |
6 | 6 | |
7 | -.. % Using the Python Interpreter | |
8 | - | |
9 | - | |
10 | 7 | .. _tut-invoking: |
11 | 8 | |
12 | 9 | インタプリタを起動する |
13 | 10 | ====================== |
14 | 11 | |
15 | -Python が使える計算機なら、インタプリタはたいてい :file:`/usr/local/bin/python` にインストールされています。Unix シェ | |
16 | -ルのサーチパスに :file:`/usr/local/bin` を入れれば、シェルで | |
12 | +Python が使える計算機なら、インタプリタは大抵 :file:`/usr/local/bin/python` | |
13 | +にインストールされています。Unix シェルの検索パスに :file:`/usr/local/bin` | |
14 | +を入れれば、シェルで | |
17 | 15 | |
18 | -.. % Invoking the Interpreter | |
19 | -.. % % The Python interpreter is usually installed as | |
20 | -.. % % \file{/usr/local/bin/python} on those machines where it is available; | |
21 | -.. % % putting \file{/usr/local/bin} in your \UNIX{} shell's search path | |
22 | -.. % % makes it possible to start it by typing the command | |
23 | - | |
24 | -Windows マシンの場合には、Pythonは大抵の場合 :file:`C:\Python26` にインストールされますが、インストーラ実行時に変更すること | |
25 | -ができます。このディレクトリをあなたのパスに追加するには、以下のコマンドをコマンドプロンプトで実行してください:: | |
26 | - | |
27 | - set path=%path%;C:\python26 | |
28 | - | |
29 | 16 | :: |
30 | 17 | |
31 | 18 | python |
32 | 19 | |
33 | -とコマンドを入力すれば使えるようになります。インストールする際にどのディレクトリに Python インタプリタを入れるかをオプションで指定できるので、 | |
34 | -インタプリタは他のディレクトリにあるかもしれません; 身近な Python の導師 (guru) か、システム管理者に聞いてみてください。(例えば、その他の場 | |
35 | -所としては :file:`/usr/local/python` が一般的です。) | |
20 | +とコマンドを入力すれば使えるようになります。 | |
21 | +インストールする際にどのディレクトリに Python インタプリタを入れるかを | |
22 | +オプションで指定できるので、インタプリタは他のディレクトリにあるかも | |
23 | +しれません; 身近な Python の導師 (guru) か、システム管理者に聞いてみてください。 | |
24 | +(例えば、その他の場所としては :file:`/usr/local/python` が一般的です。) | |
36 | 25 | |
37 | -.. % % to the shell. Since the choice of the directory where the interpreter | |
38 | -.. % % lives is an installation option, other places are possible; check with | |
39 | -.. % % your local Python guru or system administrator. (E.g., | |
40 | -.. % % \file{/usr/local/python} is a popular alternative location.) | |
26 | +Windows マシンの場合には、Pythonは大抵の場合 :file:`C:\\Python26` | |
27 | +にインストールされますが、インストーラ実行時に変更することができます。 | |
28 | +このディレクトリをあなたのパスに追加するには、以下のコマンドをコマンドプロンプトで実行してください:: | |
41 | 29 | |
30 | + set path=%path%;C:\python26 | |
31 | + | |
42 | 32 | ファイル終端文字 (Unixでは :kbd:`Control-D` 、DOS や Windows では :kbd:`Control-Z`) を一次プロンプト |
43 | 33 | (primary prompt) に入力すると、インタプリタが終了状態ゼロで終了します。もしこの操作がうまく働かないなら、コマンド: ``import |
44 | 34 | sys; sys.exit()`` と入力すればインタプリタを終了できます。 |
45 | 35 | |
46 | -.. % % Typing an end-of-file character (\kbd{Control-D} on \UNIX, | |
47 | -.. % % \kbd{Control-Z} on DOS or Windows) at the primary prompt causes the | |
48 | -.. % % interpreter to exit with a zero exit status. If that doesn't work, | |
49 | -.. % % you can exit the interpreter by typing the following commands: | |
50 | -.. % % \samp{import sys; sys.exit()}. | |
51 | - | |
52 | -通常、インタプリタの行編集機能は、あまり洗練されたものではありません。 Unixシステムでは、インタプリタをインストールした誰かが GNU readline | |
36 | +通常、インタプリタの行編集機能は、あまり洗練されたものではありません。 | |
37 | +Unixシステムでは、インタプリタをインストールした誰かが GNU readline | |
53 | 38 | ライブラリのサポートを有効にしていれば、洗練された対話的行編集やヒストリ機能が追加されます。 |
54 | -コマンドライン編集機能がサポートされているかを最も手っ取り早く調べる方法は、おそらく最初に表示された Python プロンプトに Control-P を入力し | |
55 | -てみることでしょう。ビープ音が鳴るなら、コマンドライン編集機能があります。編集キーについての解説は付録 :ref:`tut-interacting` | |
56 | -を参照してください。何も起こらないように見えるか、 ``^P`` がエコーバックされるなら、コ | |
57 | -マンドライン編集機能は利用できません。この場合、現在編集中の行から文字を削除するにはバックスペースを使うしかありません。 | |
39 | +コマンドライン編集機能がサポートされているかを最も手っ取り早く調べる方法は、 | |
40 | +おそらく最初に表示された Python プロンプトに Control-P を入力してみることでしょう。 | |
41 | +ビープ音が鳴るなら、コマンドライン編集機能があります。編集キーについての解説は付録 :ref:`tut-interacting` | |
42 | +を参照してください。何も起こらないように見えるか、 ``^P`` がエコーバックされるなら、 | |
43 | +コマンドライン編集機能は利用できません。 | |
44 | +この場合、現在編集中の行から文字を削除するにはバックスペースを使うしかありません。 | |
58 | 45 | |
59 | -.. % % The interpreter's line-editing features usually aren't very | |
60 | -.. % % sophisticated. On \UNIX, whoever installed the interpreter may have | |
61 | -.. % % enabled support for the GNU readline library, which adds more | |
62 | -.. % % elaborate interactive editing and history features. Perhaps the | |
63 | -.. % % quickest check to see whether command line editing is supported is | |
64 | -.. % % typing Control-P to the first Python prompt you get. If it beeps, you | |
65 | -.. % % have command line editing; see Appendix \ref{interacting} for an | |
66 | -.. % % introduction to the keys. If nothing appears to happen, or if | |
67 | -.. % % \code{\^P} is echoed, command line editing isn't available; you'll | |
68 | -.. % % only be able to use backspace to remove characters from the current | |
69 | -.. % % line. | |
46 | +インタプリタはさながら Unix シェルのように働きます。 | |
47 | +標準入力が端末に接続された状態で呼び出されると、コマンドを対話的に読み込んで実行します。 | |
48 | +ファイル名を引数にしたり、標準入力からファイルを入力すると、インタプリタはファイルから | |
49 | +*スクリプト* を読み込んで実行します。 | |
70 | 50 | |
71 | -インタプリタはさながら Unix シェルのように働きます。標準入力が端末に接続された状態で呼び出されると、コマンドを対話的に読み込んで実行しま | |
72 | -す。ファイル名を引数にしたり、標準入力からファイルを入力すると、インタプリタはファイルから *スクリプト* を読み込んで実行します。 | |
51 | +インタプリタを起動する第二の方法は ``python -c command [arg] ...`` です。 | |
52 | +この形式では、シェルの :option:`-c` オプションと同じように、 *command* | |
53 | +に指定した文を実行します。 | |
54 | +Python 文には、スペースなどのシェルにとって特殊な意味をもつ文字がしばしば | |
55 | +含まれるので、 *command* 全体を二重引用符を囲っておいたほうが良いでしょう。 | |
73 | 56 | |
74 | -.. % % The interpreter operates somewhat like the \UNIX{} shell: when called | |
75 | -.. % % with standard input connected to a tty device, it reads and executes | |
76 | -.. % % commands interactively; when called with a file name argument or with | |
77 | -.. % % a file as standard input, it reads and executes a \emph{script} from | |
78 | -.. % % that file. | |
57 | +Python のモジュールには、スクリプトとしても便利に使えるものがあります。 | |
58 | +``python -m module [arg] ...`` のようにすると、 *module* のソースファイルを、 | |
59 | +フルパスを指定して起動したかのように実行できます。 | |
79 | 60 | |
80 | -インタプリタを起動する第二の方法は ``python -c command [arg] ...`` です。この形式では、シェルの :option:`-c` | |
81 | -オプションと同じように、 *command* に指定した文を実行します。Python 文には、スペースなどの | |
82 | -シェルにとって特殊な意味をもつ文字がしばしば含まれるので、 *command* 全体を二重引用符を囲っておいたほうが良いでしょう。 | |
61 | +``python file`` と ``python <file`` の違いに注意してください。 | |
62 | +後者の場合、プログラム内で :func:`input` や :func:`raw_input` が呼び出され、 | |
63 | +ユーザからの入力が必要な場合、入力は *ファイル* から取り込まれます。 | |
64 | +この場合、パーザはプログラムの実行を開始される前にファイルを終端まで | |
65 | +読み込んでおくので、プログラムはすぐに入力の終わりまで到達してしまいます。 | |
66 | +前者の場合 (大抵はこちらの方が望ましい動作です)、入力には Python | |
67 | +インタプリタの標準入力に接続された何らかのファイルまたはデバイスが充てられます。 | |
83 | 68 | |
84 | -.. % % A second way of starting the interpreter is | |
85 | -.. % % \samp{\program{python} \programopt{-c} \var{command} [arg] ...}, which | |
86 | -.. % % executes the statement(s) in \var{command}, analogous to the shell's | |
87 | -.. % % \programopt{-c} option. Since Python statements often contain spaces | |
88 | -.. % % or other characters that are special to the shell, it is best to quote | |
89 | -.. % % \var{command} in its entirety with double quotes. | |
69 | +スクリプトファイルが使われた場合、スクリプトを走らせて、そのまま対話モードに | |
70 | +入れると便利なことがあります。これには :option:`-i` をスクリプトの前に追加します。 | |
71 | +(前の段落で述べたのと同じ理由から、スクリプトを標準入力から読み込んだ場合には、このオプションはうまく働きません。) | |
90 | 72 | |
91 | -Python のモジュールには、スクリプトとしても便利に使えるものがあります。 ``python -m module [arg] ...`` のようにすると、 | |
92 | -*module* のソースファイルを、フルパスを指定して起動したかのように実行できます。 | |
93 | 73 | |
94 | -.. % +Some Python modules are also useful as scripts. These can be invoked using | |
95 | -.. % +\samp{\program{python} \programopt{-m} \var{module} [arg] ...}, which | |
96 | -.. % +executes the source file for \var{module} as if you had spelled out its | |
97 | -.. % +full name on the command line. | |
98 | - | |
99 | -``python file`` と ``python <file`` の違いに注意してください。後者の場合、プログラム内で :func:`input` や | |
100 | -:func:`raw_input` が呼び出され、ユーザからの入力が必要な場合、入力は *ファイル* から | |
101 | -取り込まれます。この場合、パーザはプログラムの実行を開始される前にファイルを終端まで読み込んでおくので、プログラムはすぐに入力の終わりまで到 | |
102 | -達してしまいます。前者の場合 (大抵はこちらの方が望ましい動作です)、入力には Python インタプリタの標準入力に接続された何らかのファイルまたは | |
103 | -デバイスが充てられます。 | |
104 | - | |
105 | -.. % % Note that there is a difference between \samp{python file} and | |
106 | -.. % % \samp{python <file}. In the latter case, input requests from the | |
107 | -.. % % program, such as calls to \code{input()} and \code{raw_input()}, are | |
108 | -.. % % satisfied from \emph{file}. Since this file has already been read | |
109 | -.. % % until the end by the parser before the program starts executing, the | |
110 | -.. % % program will encounter end-of-file immediately. In the former case | |
111 | -.. % % (which is usually what you want) they are satisfied from whatever file | |
112 | -.. % % or device is connected to standard input of the Python interpreter. | |
113 | - | |
114 | -スクリプトファイルが使われた場合、スクリプトを走らせて、そのまま対話モードに入れると便利なことがあります。これには :option:`-i` をスク | |
115 | -リプトの前に追加します。(前の段落で述べたのと同じ理由から、スクリプトを標準入力から読み込んだ場合には、このオプションはうまく働きません。) | |
116 | - | |
117 | -.. % % When a script file is used, it is sometimes useful to be able to run | |
118 | -.. % % the script and enter interactive mode afterwards. This can be done by | |
119 | -.. % % passing \programopt{-i} before the script. (This does not work if the | |
120 | -.. % % script is read from standard input, for the same reason as explained | |
121 | -.. % % in the previous paragraph.) | |
122 | - | |
123 | - | |
124 | 74 | .. _tut-argpassing: |
125 | 75 | |
126 | 76 | 引数の受け渡し |