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-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,20 +155,21 @@ Có một số mô-đun để truy cập internet và xử lý các giao thức
155
155
156
156
\(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).\)
157
157
158
-
### 10.8. Dates and Times
159
158
160
-
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.>>>
159
+
### 10.8. Ngày và giờ (Dates and Times)
160
+
161
+
Mô-đun [`datetime`] (https://docs.python.org/3/library/datetime.html#module-datetime) cung cấp các lớp (classes) để thao tác ngày tháng và thời gian theo cả hai cách đơn giản và phức tạp. Trong khi ngày giờ số học được hỗ trợ, trọng tâm của việc thực hiện (implementation) là trích xuất thành viên hiệu quả cho định dạng đầu ra và thao tác. Mô-đun này cũng hỗ trợ các đối tượng nhận biết múi giờ. >>>
161
162
162
163
```text
163
-
>>> # dates are easily constructed and formatted
164
+
>>> # ngày giờ được xây dựng và định dạng dễ dàng
164
165
>>> from datetime import date
165
166
>>> now = date.today()
166
167
>>> now
167
168
datetime.date(2003, 12, 2)
168
169
>>> now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
169
170
'12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.'
170
171
171
-
>>> # dates support calendar arithmetic
172
+
>>> # ngày hỗ trợ số học lịch (calender)
172
173
>>> birthday = date(1964, 7, 31)
173
174
>>> age = now - birthday
174
175
>>> age.days
@@ -177,7 +178,7 @@ datetime.date(2003, 12, 2)
177
178
178
179
### 10.9. Data Compression
179
180
180
-
Common data archiving and compression formats are directly supported by modules including: [`zlib`](https://docs.python.org/3/library/zlib.html#module-zlib), [`gzip`](https://docs.python.org/3/library/gzip.html#module-gzip), [`bz2`](https://docs.python.org/3/library/bz2.html#module-bz2), [`lzma`](https://docs.python.org/3/library/lzma.html#module-lzma), [`zipfile`](https://docs.python.org/3/library/zipfile.html#module-zipfile) and [`tarfile`](https://docs.python.org/3/library/tarfile.html#module-tarfile).>>>
181
+
Các định dạng nén và lưu trữ dữ liệu được hỗ trợ trực tiếp bởi các mô-đun bao gồm: [`zlib`](https://docs.python.org/3/library/zlib.html#module-zlib), [`gzip`](https://docs.python.org/3/library/gzip.html#module-gzip), [`bz2`](https://docs.python.org/3/library/bz2.html#module-bz2), [`lzma`](https://docs.python.org/3/library/lzma.html#module-lzma), [`zipfile`](https://docs.python.org/3/library/zipfile.html#module-zipfile) and [`tarfile`](https://docs.python.org/3/library/tarfile.html#module-tarfile).>>>
181
182
182
183
```text
183
184
>>> import zlib
@@ -195,10 +196,12 @@ b'witch which has which witches wrist watch'
195
196
196
197
### 10.10. Performance Measurement
197
198
198
-
Some Python users develop a deep interest in knowing the relative performance of different approaches to the same problem. Python provides a measurement tool that answers those questions immediately.
199
+
Một số người dùng Python phát triển một sự quan tâm sâu sắc trong việc biết hiệu suất tương đối của các cách tiếp cận khác nhau cho cùng một vấn đề. Python cung cấp một công cụ đo lường để trả lời các câu hỏi đó ngay lập tức.
199
200
200
201
For example, it may be tempting to use the tuple packing and unpacking feature instead of the traditional approach to swapping arguments. The [`timeit`](https://docs.python.org/3/library/timeit.html#module-timeit) module quickly demonstrates a modest performance advantage:>>>
201
202
203
+
Ví dụ, nó có thể hấp dẫn để sử dụng tính năng đóng gói và giải nén tuple thay vì cách tiếp cận truyền thống để hoán đổi đối số. Mô-đun [`timeit`](https://docs.python.org/3/library/timeit.html#module-timeit) chứng tỏ một cách nhanh chóng về lợi thế hiệu suất: >>>
204
+
202
205
```text
203
206
>>> from timeit import Timer
204
207
>>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()
@@ -207,13 +210,14 @@ For example, it may be tempting to use the tuple packing and unpacking feature i
207
210
0.54962537085770791
208
211
```
209
212
210
-
In contrast to [`timeit`](https://docs.python.org/3/library/timeit.html#module-timeit)’s fine level of granularity, the [`profile`](https://docs.python.org/3/library/profile.html#module-profile)and[`pstats`](https://docs.python.org/3/library/profile.html#module-pstats)modules provide tools for identifying time critical sections in larger blocks of code.
213
+
Ngược lại với mức độ chi tiết của [`timeit`](https://docs.python.org/3/library/timeit.html#module-timeit), các mô-đun [`profile`](https://docs.python.org/3/library/profile.html#module-profile)và[`pstats`](https://docs.python.org/3/library/profile.html#module-pstats)cung cấp các công cụ cho việc xác định các phần thời gian quan trọng trong các khối mã (code) lớn hơn.
211
214
212
215
### 10.11. Quality Control
213
216
214
-
One approach for developing high quality software is to write tests for each function as it is developed and to run those tests frequently during the development process.
215
217
216
-
The [`doctest`](https://docs.python.org/3/library/doctest.html#module-doctest) module provides a tool for scanning a module and validating tests embedded in a program’s docstrings. Test construction is as simple as cutting-and-pasting a typical call along with its results into the docstring. This improves the documentation by providing the user with an example and it allows the doctest module to make sure the code remains true to the documentation:
218
+
Một cách tiếp cận để phát triển phần mềm chất lượng cao là viết các bài kiểm thử (tests) cho từng chức năng khi nó được phát triển và chạy các bài kiểm thử đó thường xuyên trong quá trình phát triển.
219
+
220
+
Mô-đun [`doctest`](https://docs.python.org/3/library/doctest.html#module-doctest) cung cấp công cụ để quét mô-đun và xác thực các bài kiểm thử được nhúng trong tài liệu của chương trình. Việc xây dựng kiểm thử đơn giản như việc cắt và dán thông thường cùng với các kết quả của nó vào trong tài liệu (docstring). Điều này cải thiện tài liệu bằng cách cung cấp cho người dùng một ví dụ và nó cho phép mô-đun *doctest* đảm bảo mã (code) vẫn đúng với tài liệu:
217
221
218
222
```text
219
223
def average(values):
@@ -228,7 +232,7 @@ import doctest
228
232
doctest.testmod() # automatically validate the embedded tests
229
233
```
230
234
231
-
The[`unittest`](https://docs.python.org/3/library/unittest.html#module-unittest)module is not as effortless as the [`doctest`](https://docs.python.org/3/library/doctest.html#module-doctest) module, but it allows a more comprehensive set of tests to be maintained in a separate file:
235
+
Mô-đun[`unittest`](https://docs.python.org/3/library/unittest.html#module-unittest)không dễ dàng như mô-đun [`doctest`](https://docs.python.org/3/library/doctest.html#module-doctest), nhưng nó cho phép kiểm tra toàn diện hơn được duy trì trong một tệp riêng biệt:
232
236
233
237
```text
234
238
import unittest
@@ -243,8 +247,7 @@ class TestStatisticalFunctions(unittest.TestCase):
243
247
with self.assertRaises(TypeError):
244
248
average(20, 30, 70)
245
249
246
-
unittest.main() # Calling from the command line invokes all tests
247
-
```
250
+
unittest.main() # Gọi từ dòng lệnh kích hoạt tất cả các trường hợp kiểm thử
0 commit comments