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
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,20 +57,21 @@ Các tập lệnh (scripts) tiện ích phổ biến thường cần xử lý c
57
57
58
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).
59
59
60
-
### 10.4. Error Output Redirection and Program Termination
60
+
### 10.4. Lỗi chuyển hướng đầu ra và kết thúc chương trình (Error Output Redirection and Program Termination)
61
+
62
+
Mô-đun [`sys`](https://docs.python.org/3/library/sys.html#module-sys) cũng có các thuộc tính cho _stdin_, _stdout_, and _stderr_. Cái sau cùng hữu ích khi phát ra các cảnh báo và thông báo lỗi để hiển thị chúng ngay cả khi _stdout_ đã được chuyển hướng:>>>
61
63
62
-
The [`sys`](https://docs.python.org/3/library/sys.html#module-sys) module also has attributes for _stdin_, _stdout_, and _stderr_. The latter is useful for emitting warnings and error messages to make them visible even when _stdout_ has been redirected:>>>
63
64
64
65
```text
65
66
>>> sys.stderr.write('Warning, log file not found starting a new one\n')
66
67
Warning, log file not found starting a new one
67
68
```
68
69
69
-
The most direct way to terminate a script is to use`sys.exit()`.
70
+
Cách trực tiếp nhất để chấm dứt tập lệnh là sử dụng`sys.exit()`.
70
71
71
-
### 10.5. String Pattern Matching
72
+
### 10.5. So khớp mẫu chuỗi (String Pattern Matching)
72
73
73
-
The[`re`](https://docs.python.org/3/library/re.html#module-re)module provides regular expression tools for advanced string processing. For complex matching and manipulation, regular expressions offer succinct, optimized solutions:>>>
74
+
Mô-đun[`re`](https://docs.python.org/3/library/re.html#module-re)cung cấp các công cụ biểu thức chính quy để xử lý chuỗi nâng cao. Để đối sánh và thao tác phức tạp, biểu thức chính quy cung cấp các giải pháp gọn gàng, được tối ưu hóa:>>>
74
75
75
76
```text
76
77
>>> import re
@@ -80,27 +81,27 @@ The [`re`](https://docs.python.org/3/library/re.html#module-re) module provides
80
81
'cat in the hat'
81
82
```
82
83
83
-
When only simple capabilities are needed, string methods are preferred because they are easier to read and debug:>>>
84
+
Khi chỉ có các khả năng đơn giản là cần thiết, các phương thức chuỗi được ưa thích vì chúng dễ đọc và gỡ lỗi hơn:>>>
84
85
85
86
```text
86
87
>>> 'tea for too'.replace('too', 'two')
87
88
'tea for two'
88
89
```
89
90
90
-
### 10.6. Mathematics
91
+
### 10.6. Toán học (Mathematics)
91
92
92
93
The [`math`](https://docs.python.org/3/library/math.html#module-math) module gives access to the underlying C library functions for floating point math:>>>
93
94
95
+
Mô-đun [`math`](https://docs.python.org/3/library/math.html#module-math) cho phép truy cập vào các hàm thư viện C bên dưới cho phép toán trên số thực (floating point math):>>>
96
+
94
97
```text
95
98
>>> import math
96
99
>>> math.cos(math.pi / 4)
97
100
0.70710678118654757
98
101
>>> math.log(1024, 2)
99
102
10.0
100
103
```
101
-
102
-
The [`random`](https://docs.python.org/3/library/random.html#module-random) module provides tools for making random selections:>>>
103
-
104
+
Mô-đun [`random`](https://docs.python.org/3/library/random.html#module-random) cung cấp các công cụ để thực hiện các lựa chọn ngẫu nhiên:>>>
104
105
```text
105
106
>>> import random
106
107
>>> random.choice(['apple', 'pear', 'banana'])
@@ -113,8 +114,7 @@ The [`random`](https://docs.python.org/3/library/random.html#module-random) modu
113
114
4
114
115
```
115
116
116
-
The [`statistics`](https://docs.python.org/3/library/statistics.html#module-statistics) module calculates basic statistical properties \(the mean, median, variance, etc.\) of numeric data:>>>
117
-
117
+
Mô-đun [`statistics`](https://docs.python.org/3/library/statistics.html#module-statistics) tính toán các thuộc tính thông kê cơ bản \(the mean, median, variance, etc.\) của dữ liệu số:>>>
118
118
```text
119
119
>>> import statistics
120
120
>>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]
@@ -126,11 +126,11 @@ The [`statistics`](https://docs.python.org/3/library/statistics.html#module-stat
126
126
1.3720238095238095
127
127
```
128
128
129
-
The SciPy project <[https://scipy.org](https://scipy.org/)>has many other modules for numerical computations.
130
-
131
-
### 10.7. Internet Access
129
+
Dự án SciPy <[https://scipy.org](https://scipy.org/)>có nhiều mô-đun khác để tính toán số.
130
+
131
+
### 10.7. Truy cập Internet (Internet Access)
132
132
133
-
There are a number of modules for accessing the internet and processing internet protocols. Two of the simplest are [`urllib.request`](https://docs.python.org/3/library/urllib.request.html#module-urllib.request)for retrieving data from URLs and[`smtplib`](https://docs.python.org/3/library/smtplib.html#module-smtplib)for sending mail:>>>
133
+
Có một số mô-đun để truy cập internet và xử lý các giao thức internet. Hai trong số mô-đun đơn giản nhất là [`urllib.request`](https://docs.python.org/3/library/urllib.request.html#module-urllib.request)để truy xuất dữ liệu từ các URLs và[`smtplib`](https://docs.python.org/3/library/smtplib.html#module-smtplib)để gửi thư:>>>
134
134
135
135
```text
136
136
>>> from urllib.request import urlopen
@@ -155,6 +155,8 @@ There are a number of modules for accessing the internet and processing internet
155
155
156
156
\(Note that the second example needs a mailserver running on localhost.\)
157
157
158
+
\(Lưu ý rằng ví dụ thứ hai cần một máy chủ thư (mailserver) chạy trên máy chủ cục bộ (localhost).\)
159
+
158
160
### 10.8. Dates and Times
159
161
160
162
The [`datetime`](https://docs.python.org/3/library/datetime.html#module-datetime) module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the focus of the implementation is on efficient member extraction for output formatting and manipulation. The module also supports objects that are timezone aware.>>>
0 commit comments