Skip to content

Commit a4f36f3

Browse files
committed
Update2.1
Bản thô
1 parent 5004040 commit a4f36f3

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

2.-using-the-python-interpreter.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22

33

44

5-
### 2.1. Invoking the Interpreter
5+
### 2.1. Gọi tới trình thông dịch
66

7-
The Python interpreter is usually installed as `/usr/local/bin/python3.6` on those machines where it is available; putting `/usr/local/bin` in your Unix shell’s search path makes it possible to start it by typing the command:
7+
Trình thông dịch Python thường được cài đặt tại địa chỉ `/usr/local/bin/python3.6` trên những máy có sẵn; hãy dẫn Unix shell của bạn tới `/usr/local/bin` và khởi động nó bằng cách nhập:
88

99
```text
1010
python3.6
1111
```
1212

13-
to the shell. [\[1\]](https://docs.python.org/3/tutorial/interpreter.html#id2) Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local Python guru or system administrator. \(E.g., `/usr/local/python` is a popular alternative location.\)
13+
vào shell. [\[1\]](https://docs.python.org/3/tutorial/interpreter.html#id2) Vì địa chỉ có thể tùy chỉnh trong quá trình cài đặt nên để biết chính xác đường dẫn tới trình biên dịch hãy hỏi quản trị viên hoặc người dạy của bạn \(v.d., `/usr/local/python` là một đường dẫn phổ biến.\)
1414

15-
On Windows machines, the Python installation is usually placed in `C:\Python36`, though you can change this when you’re running the installer. To add this directory to your path, you can type the following command into the command prompt in a DOS box:
15+
Trên các máy Windows, cài đặt Python thường được đặt tại `C:\Python36`, mặc dù vậy bạn cũng có thể thay đổi nó trong quá trình cài đặt. Để thêm đường đẫn của mình, bạn có thể nhập lệnh sau vào hộp lệnh DOS:
1616

1717
```text
1818
set path=%path%;C:\python36
1919
```
2020

21-
Typing an end-of-file character \(Control-D on Unix, Control-Z on Windows\) at the primary prompt causes the interpreter to exit with a zero exit status. If that doesn’t work, you can exit the interpreter by typing the following command: `quit()`.
21+
Tại ký tự cuối file \(Control-D trên Unix, Control-Z trên Windows\) để thoát khỏi trình thông dịch. Nếu không được, bạn có thể thoát bằng câu lệnh: `quit()`.
2222

23-
The interpreter’s line-editing features include interactive editing, history substitution and code completion on systems that support readline. Perhaps the quickest check to see whether command line editing is supported is typing Control-P to the first Python prompt you get. If it beeps, you have command line editing; see Appendix [Interactive Input Editing and History Substitution](https://docs.python.org/3/tutorial/interactive.html#tut-interacting) for an introduction to the keys. If nothing appears to happen, or if `^P` is echoed, command line editing isn’t available; you’ll only be able to use backspace to remove characters from the current line.
23+
Các tính năng line-editing của trình thông dịch bao gồm chỉnh sửa tương tác \(interactive editing\), lịch sử thay thế và hoàn thành code trên các hệ thống hỗ trợ readline. Phải chăng cách nhanh nhất để kiểm tra xem việc chỉnh sửa có được hỗ trợ hay không là nhấn tổ hợp Control-P vào dấu nhắc đầu tiên mà bạn nhận được. Nếu nó kêu beeps, bạn có thể chỉnh sửa dòng lệnh; xem Appendix [Interactive Input Editing and History Substitution](https://docs.python.org/3/tutorial/interactive.html#tut-interacting) để đọc giới thiệu về các phím. Nếu không có gì xuất hiện, hoặc nếu `^P` được in ra, dòng lệnh chỉnh sửa không có hiệu lực; bạn chỉ có khả năng sử dụng phím backspace để xóa các ký tự ở dòng hiện tại.
2424

25-
The interpreter operates somewhat like the Unix shell: when called with standard input connected to a tty device, it reads and executes commands interactively; when called with a file name argument or with a file as standard input, it reads and executes a _script_ from that file.
25+
Trình thông dịch hoạt động có phần giống với Unix shell: khi được gọi với standard input kết nối với một thiết bị tty, nó đọc và thực thi các lệnh tương tác; khi được gọi với một đối số là tên tệp hay với tệp như một standard input, nó đọc và thực thi một _script_ từ các file ấy.
2626

27-
A second way of starting the interpreter is `python -c command [arg] ...`, which executes the statement\(s\) in _command_, analogous to the shell’s [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c) option. Since Python statements often contain spaces or other characters that are special to the shell, it is usually advised to quote _command_ in its entirety with single quotes.
27+
Cách thứ hai để bắt đầu với trình thông dịch là sử dụng lệnh `python -c command [arg] ...`, các lệnh sẽ được thực thi trong _command_, tương tự với thiết đặt [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c) của shell. Vì các câu lệnh của Python thường chứa nhiều khoảng trống hoặc các ký tự đặc biệt, nên có một lời khuyện là trích dẫn toàn bộ các _command_ với dấu nháy đơn.
2828

29-
Some Python modules are also useful as scripts. These can be invoked using `python -m module [arg] ...`, which executes the source file for _module_ as if you had spelled out its full name on the command line.
29+
Một vài modules Python cũng được sử dụng như các scipts. Chúng có thể được gọi bằng câu lệnh `python -m module [arg] ...`, nó sẽ thực thi tệp nguồn của _module_ như thể bạn đã viết đầy đủ tên nó lên dòng lệnh.
3030

31-
When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing [`-i`](https://docs.python.org/3/using/cmdline.html#cmdoption-i) before the script.
31+
Khi một tệp script được sử dụng, đôi khi rất hữu ích nếu chạy và truy cập vào chế độ tương tác ngay sau đó. Nó có thể làm được bằng lệnh [`-i`](https://docs.python.org/3/using/cmdline.html#cmdoption-i) đặt trước script.
3232

33-
All command line options are described in [Command line and environment](https://docs.python.org/3/using/cmdline.html#using-on-general).
33+
Tất cả các thiết đặt dòng lệnh được mô tả trong [Command line and environment](https://docs.python.org/3/using/cmdline.html#using-on-general).
3434

35-
#### 2.1.1. Argument Passing
35+
#### 2.1.1. Truyền đối số
3636

37-
When known to the interpreter, the script name and additional arguments thereafter are turned into a list of strings and assigned to the `argv` variable in the `sys` module. You can access this list by executing `import sys`. The length of the list is at least one; when no script and no arguments are given, `sys.argv[0]` is an empty string. When the script name is given as `'-'` \(meaning standard input\), `sys.argv[0]` is set to `'-'`. When [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c)_command_ is used, `sys.argv[0]` is set to `'-c'`. When [`-m`](https://docs.python.org/3/using/cmdline.html#cmdoption-m) _module_ is used, `sys.argv[0]` is set to the full name of the located module. Options found after [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c) _command_ or [`-m`](https://docs.python.org/3/using/cmdline.html#cmdoption-m) _module_ are not consumed by the Python interpreter’s option processing but left in `sys.argv` for the command or module to handle.
37+
Khi được trình thông dịch biết đến, tên script và các đối số bổ sung được chuyển thành một danh sách các chuỗi và được gán cho biến `argv` trong module `sys`. Bạn có thể truy cập danh sách này bằng cách import modules sys này `import sys`. Độ dài tối thiểu của một list; khi không có script và các đối số được truyền, `sys.argv[0]`là một chuỗi trống. Khi tên của script `'-'` \(\), `sys.argv[0]` sẽ trở thành `'-'`. Khi sử dụng _command_ [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c), `sys.argv[0]` được đặt là `'-c'`. Khi _module_ [`-m`](https://docs.python.org/3/using/cmdline.html#cmdoption-m) được sử dụng, `sys.argv[0]` được đặt thành tên vị trí đầy đủ của modules. Các thiết đặt được tìm thấy sau _lệnh_ [`-c`](https://docs.python.org/3/using/cmdline.html#cmdoption-c) hoặc _module_ [`-m`](https://docs.python.org/3/using/cmdline.html#cmdoption-m) không được trình thông dịch Python xử lý nhưng còn lại trong`sys.argv` thì được lệnh hoặc modules xử lý.
3838

39-
#### 2.1.2. Interactive Mode
39+
#### 2.1.2. Chế độ tương tác
4040

41-
When commands are read from a tty, the interpreter is said to be in _interactive mode_. In this mode it prompts for the next command with the _primary prompt_, usually three greater-than signs \(`>>>`\); for continuation lines it prompts with the _secondary prompt_, by default three dots \(`...`\). The interpreter prints a welcome message stating its version number and a copyright notice before printing the first prompt:
41+
Khi các câu lệnh được đọc từ một tty, trình thông dịch sẽ chuyển sang chế độ tương tác _interactive mode_. Trong chế độ này, các dấu nhắc cho câu lệnh tiếp theo là _primary prompt_, thường là 3 dấu lớn hơn \(`>>>`\); các dòng tiếp theo bắt đầu bằng dấu _secondary prompt_, mặc định là 3 chấm thế này \(`...`\). Trước khi xuất hiện dấu nhắc đầu tiên, trình thông dịch in ra một dòng thông báo chào mừng bắt đầu là số hiệu phiên bản và chứng chỉ bản quyền :
4242

4343
```text
4444
$ python3.6
@@ -48,7 +48,7 @@ Type "help", "copyright", "credits" or "license" for more information.
4848
>>>
4949
```
5050

51-
Continuation lines are needed when entering a multi-line construct. As an example, take a look at this [`if`](https://docs.python.org/3/reference/compound_stmts.html#if)statement:>>>
51+
Các dòng cần được viết liên tục khi bạn muốn thực hiện một cấu trúc gồm nhiều dòng. Ví dụ về cầu lệnh rẽ nhánh [`if`](https://docs.python.org/3/reference/compound_stmts.html#if):
5252

5353
```text
5454
>>> the_world_is_flat = True
@@ -58,38 +58,38 @@ Continuation lines are needed when entering a multi-line construct. As an exampl
5858
Be careful not to fall off!
5959
```
6060

61-
For more on interactive mode, see [Interactive Mode](https://docs.python.org/3/tutorial/appendix.html#tut-interac).
61+
Để xem nhiều hơn về chế độ này, xem [Interactive Mode](https://docs.python.org/3/tutorial/appendix.html#tut-interac).
6262

63-
### 2.2. The Interpreter and Its Environment
63+
### 2.2. Trình thông dịch và môi trường
6464

65-
#### 2.2.1. Source Code Encoding
65+
#### 2.2.1. Mã hóa Source Code
6666

67-
By default, Python source files are treated as encoded in UTF-8. In that encoding, characters of most languages in the world can be used simultaneously in string literals, identifiers and comments — although the standard library only uses ASCII characters for identifiers, a convention that any portable code should follow. To display all these characters properly, your editor must recognize that the file is UTF-8, and it must use a font that supports all the characters in the file.
67+
Mặc định, các tệp nguồn Python được định dạng mã hóa UTF-8. Trong mã hóa này, các ký tự của hầu hết ngôn ngữ trên thế giới có thể được sử dụng đồng thời trong chuỗi ký tự, định danh và comments — mặc dù thư viện chuẩn chỉ sử dụng các ký tự ASCII cho các định danh, một quy ước mà bất kỳ portable code nào cũng phải tuân thủ. Để hiển thị đúng tất cả các ký tự, trình soạn thảo của bạn phải nhận ra được các file đó là UTF-8, và nó phải sử dụng phông chữ hỗ trợ tất cả các ký tự trong file.
6868

69-
To declare an encoding other than the default one, a special comment line should be added as the _first_ line of the file. The syntax is as follows:
69+
Để khai báo một mã hóa khác với kiểu mặc định, một comment đặc biệt phải được thêm vào dòng _đầu tiên_ của file. Cú pháp:
7070

7171
```text
7272
# -*- coding: encoding -*-
7373
```
7474

75-
where _encoding_ is one of the valid [`codecs`](https://docs.python.org/3/library/codecs.html#module-codecs) supported by Python.
75+
Trong đó _encoding_ là một trong các [`codecs`](https://docs.python.org/3/library/codecs.html#module-codecs) được Python hỗ trợ.
7676

77-
For example, to declare that Windows-1252 encoding is to be used, the first line of your source code file should be:
77+
Ví dụ, để khai báo mã hóa Windows-1252, dòng đầu tiên trong mã nguồn sẽ là:
7878

7979
```text
8080
# -*- coding: cp1252 -*-
8181
```
8282

83-
One exception to the _first line_ rule is when the source code starts with a [UNIX “shebang” line](https://docs.python.org/3/tutorial/appendix.html#tut-scripts). In this case, the encoding declaration should be added as the second line of the file. For example:
83+
Một ngoại lệ _first line_ là khi mã nguồn bắt đầu bằng dòng chứa ký tự `#!`\([UNIX “shebang” line](https://docs.python.org/3/tutorial/appendix.html#tut-scripts)\). Trong trường hợp này, dòng khai báo được đặt ở dòng thứ 2. Ví dụ:
8484

8585
```text
8686
#!/usr/bin/env python3
8787
# -*- coding: cp1252 -*-
8888
```
8989

90-
Footnotes
90+
Chú thích
9191

92-
| [\[1\]](https://docs.python.org/3/tutorial/interpreter.html#id1) | On Unix, the Python 3.x interpreter is by default not installed with the executable named `python`, so that it does not conflict with a simultaneously installed Python 2.x executable. |
92+
| [\[1\]](https://docs.python.org/3/tutorial/interpreter.html#id1) | Trên Unix, mặc định trình thông dịch Python 3.x không được cài đặt với tệp thực thi có tên là `python`, làm vậy để nó không xung đột với Python 2.x đã được cài đặt. |
9393
| --- |
9494

9595

0 commit comments

Comments
 (0)