You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 10.-brief-tour-of-the-standard-library.md
+15-17Lines changed: 15 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,21 @@
1
-
# 10. Brief Tour of the Standard Library
1
+
# 10. Giới thiệu sơ lược về Thư viện chuẩn
2
2
3
3
4
+
### 10.1. Giao diện hệ điều hành
4
5
5
-
### 10.1. Operating System Interface
6
-
7
-
The [`os`](https://docs.python.org/3/library/os.html#module-os) module provides dozens of functions for interacting with the operating system:>>>
8
-
6
+
Mô-đun [`os`](https://docs.python.org/3/library/os.html#module-os) (os là viết tắt của operating system) cung cấp hàng tá chức năng để tương tác với hệ điều hành:
9
7
```text
10
8
>>> import os
11
-
>>> os.getcwd() # Return the current working directory
9
+
>>> os.getcwd() # Quay về thư mục làm việc hiện tại
12
10
'C:\\Python36'
13
-
>>> os.chdir('/server/accesslogs') # Change current working directory
14
-
>>> os.system('mkdir today') # Run the command mkdir in the system shell
11
+
>>> os.chdir('/server/accesslogs') # Thay đổi thư mục làm việc hiện tại
12
+
>>> os.system('mkdir today') # Chạy lệnh mkdir trong thông dịch dòng lệnh hệ thống (the system shell)
15
13
0
16
14
```
17
15
18
-
Be sure to use the `import os`style instead of `from os import *`. This will keep [`os.open()`](https://docs.python.org/3/library/os.html#os.open)from shadowing the built-in [`open()`](https://docs.python.org/3/library/functions.html#open)function which operates much differently.
16
+
Hãy dùng `import os`thay vì `from os import *`. Điều này giữ cho [`os.open()`](https://docs.python.org/3/library/os.html#os.open)khỏi việc che mờ hàm được dựng sẵn [`open()`](https://docs.python.org/3/library/functions.html#open)khiến các hoạt động sai khác đáng kể.
19
17
20
-
The built-in [`dir()`](https://docs.python.org/3/library/functions.html#dir)and[`help()`](https://docs.python.org/3/library/functions.html#help)functions are useful as interactive aids for working with large modules like [`os`](https://docs.python.org/3/library/os.html#module-os):>>>
18
+
Các hàm dựng sẵn [`dir()`](https://docs.python.org/3/library/functions.html#dir)và[`help()`](https://docs.python.org/3/library/functions.html#help)hữu ích giống như những hỗ trợ tương tác để làm việc với các mô đun (modules) lớn như [`os`](https://docs.python.org/3/library/os.html#module-os):
21
19
22
20
```text
23
21
>>> import os
@@ -26,8 +24,7 @@ The built-in [`dir()`](https://docs.python.org/3/library/functions.html#dir) and
26
24
>>> help(os)
27
25
<returns an extensive manual page created from the module's docstrings>
28
26
```
29
-
30
-
For daily file and directory management tasks, the [`shutil`](https://docs.python.org/3/library/shutil.html#module-shutil) module provides a higher level interface that is easier to use:>>>
27
+
Đối với các tác vụ quản lý thư mục và tệp hàng ngày, mô-đun [`shutil`](https://docs.python.org/3/library/shutil.html#module-shutil) cung cấp giao diện cấp cao hơn dễ sử dụng hơn:
31
28
32
29
```text
33
30
>>> import shutil
@@ -37,27 +34,28 @@ For daily file and directory management tasks, the [`shutil`](https://docs.pytho
37
34
'installdir'
38
35
```
39
36
40
-
### 10.2. File Wildcards
37
+
### 10.2. Tệp ký tự đại diện (File Wildcards)
38
+
41
39
42
-
The[`glob`](https://docs.python.org/3/library/glob.html#module-glob)module provides a function for making file lists from directory wildcard searches:>>>
40
+
Mô-đun[`glob`](https://docs.python.org/3/library/glob.html#module-glob)cung cấp một hàm để tạo danh sách tệp từ các tìm kiếm theo ký tự đại diện:
43
41
44
42
```text
45
43
>>> import glob
46
44
>>> glob.glob('*.py')
47
45
['primes.py', 'random.py', 'quote.py']
48
46
```
49
47
50
-
### 10.3. Command Line Arguments
48
+
### 10.3. Đối số dòng lệnh (Command Line Arguments)
51
49
52
-
Common utility scripts often need to process command line arguments. These arguments are stored in the [`sys`](https://docs.python.org/3/library/sys.html#module-sys)module’s _argv_ attribute as a list. For instance the following output results from running `python demo.py one twothree` at the command line:>>>
50
+
Các tập lệnh (scripts) tiện ích phổ biến thường cần xử lý các đối số dòng lệnh. Các đối số này được lưu trữ trong thuộc tính *argv* của mô-đun (module) [`sys`](https://docs.python.org/3/library/sys.html#module-sys) dưới dạng danh sách. Ví dụ kết quả đầu ra sau đây từ chạy `python demo.py one two three` tại dòng lệnh:
53
51
54
52
```text
55
53
>>> import sys
56
54
>>> print(sys.argv)
57
55
['demo.py', 'one', 'two', 'three']
58
56
```
59
57
60
-
The[`getopt`](https://docs.python.org/3/library/getopt.html#module-getopt)module processes_sys.argv_using the conventions of the Unix [`getopt()`](https://docs.python.org/3/library/getopt.html#module-getopt) function. More powerful and flexible command line processing is provided by the [`argparse`](https://docs.python.org/3/library/argparse.html#module-argparse) module.
58
+
Mô-đun[`getopt`](https://docs.python.org/3/library/getopt.html#module-getopt)xử lý_sys.argv_bằng cách sử dụng các quy ước của hàm [`getopt()`](https://docs.python.org/3/library/getopt.html#module-getopt)trên Unix. Xử lý dòng lệnh mạnh mẽ và linh hoạt hơn được cung cấp bởi mô-đun [`argparse`](https://docs.python.org/3/library/argparse.html#module-argparse).
61
59
62
60
### 10.4. Error Output Redirection and Program Termination
0 commit comments