This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available
sys. abiflagsOn POSIX systems where Python was built with the standard configure
script, this contains the ABI flags as specified by PEP 3149
Changed in version 3. 8. Default flags became an empty string [m
flag for pymalloc has been removed].
New in version 3. 2
sys. addaudithook[hook]Append the callable hook to the list of active auditing hooks for the current [sub]interpreter
When an auditing event is raised through the function, each hook will be called in the order it was added with the event name and the tuple of arguments. Native hooks added by are called first, followed by hooks added in the current [sub]interpreter. Hooks can then log the event, raise an exception to abort the operation, or terminate the process entirely
Note that audit hooks are primarily for collecting information about internal or otherwise unobservable actions, whether by Python or libraries written in Python. They are not suitable for implementing a “sandbox”. In particular, malicious code can trivially disable or bypass hooks added using this function. At a minimum, any security-sensitive hooks must be added using the C API before initialising the runtime, and any modules allowing arbitrary memory modification [such as ] should be completely removed or closely monitored
Calling will itself raise an auditing event named
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'4 with no arguments. If any existing hooks raise an exception derived from , the new hook will not be added and the exception suppressed. As a result, callers cannot assume that their hook has been added unless they control all existing hooks
See the for all events raised by CPython, and PEP 578 for the original design discussion
New in version 3. 8
Changed in version 3. 8. 1. Exceptions derived from but not are no longer suppressed.
CPython implementation detail. When tracing is enabled [see ], Python hooks are only traced if the callable has a
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'9 member that is set to a true value. Otherwise, trace functions will skip the hooksys. argv
The list of command line arguments passed to a Python script.
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'0 is the script name [it is operating system dependent whether this is a full pathname or not]. If the command was executed using the command line option to the interpreter,
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'0 is set to the string
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'3. If no script name was passed to the Python interpreter,
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'0 is the empty string
To loop over the standard input, or the list of files given on the command line, see the module
See also
Note
On Unix, command line arguments are passed by bytes from OS. Python decodes them with filesystem encoding and “surrogateescape” error handler. When you need original bytes, you can get it by
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'7sys. audit[event , *args]
Raise an auditing event and trigger any active auditing hooks. event is a string identifying the event, and args may contain optional arguments with more information about the event. The number and types of arguments for a given event are considered a public and stable API and should not be modified between releases
For example, one auditing event is named
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'8. This event has one argument called path that will contain the requested new working directory
sẽ gọi các móc kiểm tra hiện có, chuyển tên sự kiện và đối số, đồng thời sẽ đưa ra lại ngoại lệ đầu tiên từ bất kỳ móc nào. In general, if an exception is raised, it should not be handled and the process should be terminated as quickly as possible. This allows hook implementations to decide how to respond to particular events. họ chỉ có thể ghi lại sự kiện hoặc hủy bỏ hoạt động bằng cách đưa ra một ngoại lệ
Hooks are added using the or functions
The native equivalent of this function is . Using the native function is preferred when possible
See the for all events raised by CPython
New in version 3. 8
sys. base_exec_prefixSet during Python startup, before
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...3 is run, to the same value as . Nếu không chạy trong a , các giá trị sẽ giữ nguyên;
Mới trong phiên bản 3. 3
sys. base_prefixSet during Python startup, before
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...3 is run, to the same value as . Nếu không chạy trong a , các giá trị sẽ giữ nguyên;
Mới trong phiên bản 3. 3
sys. byteorderMột chỉ báo về thứ tự byte gốc. Điều này sẽ có giá trị
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...7 trên nền tảng big-endian [byte quan trọng nhất đầu tiên] và
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...8 trên nền tảng little-endian [byte ít quan trọng nhất đầu tiên]sys. builtin_module_names
Một bộ chuỗi chứa tên của tất cả các mô-đun được biên dịch thành trình thông dịch Python này. [Thông tin này không có sẵn theo bất kỳ cách nào khác —
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...9 chỉ liệt kê các mô-đun đã nhập. ]
Xem thêm danh sách
sys. call_tracing[func , args]Gọi
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}1, trong khi theo dõi được kích hoạt. Trạng thái theo dõi được lưu và khôi phục sau đó. Điều này dự định được gọi từ trình gỡ lỗi từ một điểm kiểm tra, để gỡ lỗi đệ quy một số mã khácsys. copyright
A string containing the copyright pertaining to the Python interpreter
sys. _clear_type_cache[]Clear the internal type cache. The type cache is used to speed up attribute and method lookups. Use the function only to drop unnecessary references during reference leak debugging
This function should be used for internal and specialized purposes only
sys. _current_frames[]Return a dictionary mapping each thread’s identifier to the topmost stack frame currently active in that thread at the time the function is called. Note that functions in the module can build the call stack given such a frame
This is most useful for debugging deadlock. this function does not require the deadlocked threads’ cooperation, and such threads’ call stacks are frozen for as long as they remain deadlocked. The frame returned for a non-deadlocked thread may bear no relationship to that thread’s current activity by the time calling code examines the frame
This function should be used for internal and specialized purposes only
Raises an
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}3 with no argumentssys. _current_exceptions[]
Return a dictionary mapping each thread’s identifier to the topmost exception currently active in that thread at the time the function is called. If a thread is not currently handling an exception, it is not included in the result dictionary
This is most useful for statistical profiling
This function should be used for internal and specialized purposes only
Raises an
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}4 with no argumentssys. breakpointhook[]
This hook function is called by built-in . By default, it drops you into the debugger, but it can be set to any other function so that you can choose which debugger gets used
The signature of this function is dependent on what it calls. For example, the default binding [e. g.
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}7] expects no arguments, but you might bind it to a function that expects additional arguments [positional and/or keyword]. The built-in
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}5 function passes its
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}9 and
sys
0 straight through. Whatever sys
1 returns is returned from $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}5
Việc triển khai mặc định trước tiên sẽ tham khảo biến môi trường. Nếu điều đó được đặt thành sys
4 thì hàm này sẽ trả về ngay lập tức; . e. nó là một no-op. Nếu biến môi trường không được đặt hoặc được đặt thành chuỗi trống, thì
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}7 được gọi. Mặt khác, biến này nên đặt tên cho một hàm để chạy, sử dụng danh pháp nhập dấu chấm của Python, e. g.
sys
6. Trong trường hợp này, sys
7 sẽ được nhập và mô-đun kết quả phải có tên gọi là sys
8. Điều này được chạy, chuyển vào $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}9 và
sys
0, và bất kỳ giá trị nào mà ____309_______8 trả về, ______307_______2 trả về hàm tích hợpLưu ý rằng nếu có bất kỳ sự cố nào xảy ra trong khi nhập tên có thể gọi được theo , thì a sẽ được báo cáo và điểm ngắt bị bỏ qua
Cũng lưu ý rằng nếu configure
2 bị ghi đè theo chương trình, sẽ không được tư vấn
Mới trong phiên bản 3. 7
sys. _debugmallocstats[]In thông tin cấp thấp tới thiết bị lỗi chuẩn về trạng thái cấp phát bộ nhớ của CPython
Nếu Python là [], thì nó cũng thực hiện một số kiểm tra tính nhất quán nội bộ đắt tiền
Mới trong phiên bản 3. 3
Chi tiết triển khai CPython. Hàm này dành riêng cho CPython. Định dạng đầu ra chính xác không được xác định ở đây và có thể thay đổi
sys. dllhandleSố nguyên chỉ định phần xử lý của Python DLL
các cửa sổ
sys. displayhook[value]Nếu giá trị không phải là configure
9, hàm này sẽ in m
0 thành m
1 và lưu giá trị trong m
2. Nếu không thể mã hóa m
0 thành m
4 với trình xử lý lỗi m
5 [có thể là m
6], hãy mã hóa nó thành m
4 với trình xử lý lỗi m
8
m
9 được gọi dựa trên kết quả đánh giá một mục đã nhập trong phiên Python tương tác. Việc hiển thị các giá trị này có thể được tùy chỉnh bằng cách gán một hàm một đối số khác cho m
9
mã giả
def displayhook[value]: if value is None: return # Set '_' to None to avoid recursion builtins._ = None text = repr[value] try: sys.stdout.write[text] except UnicodeEncodeError: bytes = text.encode[sys.stdout.encoding, 'backslashreplace'] if hasattr[sys.stdout, 'buffer']: sys.stdout.buffer.write[bytes] else: text = bytes.decode[sys.stdout.encoding, 'strict'] sys.stdout.write[text] sys.stdout.write["\n"] builtins._ = value
Đã thay đổi trong phiên bản 3. 2. Sử dụng trình xử lý lỗi m
8 trên.
Nếu điều này là đúng, Python sẽ không cố ghi các tệp sys.audit[]
3 khi nhập các mô-đun nguồn. Giá trị này ban đầu được đặt thành sys.audit[]
4 hoặc sys.audit[]
5 tùy thuộc vào tùy chọn dòng lệnh và biến môi trường, nhưng bạn có thể tự đặt giá trị này để kiểm soát việc tạo tệp mã byte
Thông tin lưu giữ về môi trường trên nền tảng wasm32-emscripten. Tuple được đặt tên là tạm thời và có thể thay đổi trong tương lai
Thuộc tính
Giải trình
sys.audit[]
8
Phiên bản mô tả dưới dạng bộ dữ liệu ints [chính, phụ, vi mô], e. g. sys.audit[]
9
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'00
Chuỗi thời gian chạy, e. g. tác nhân người dùng trình duyệt,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'01 hoặc
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'02
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'03
sys.audit[]
4 nếu Python được biên dịch với sự hỗ trợ của Emscripten pthreads
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'05
sys.audit[]
4 nếu Python được biên dịch với hỗ trợ bộ nhớ dùng chung
Emscripten
Mới trong phiên bản 3. 11
sys. pycache_prefixNếu điều này được đặt [không phải configure
9], Python sẽ ghi các tệp bytecode-cache sys.audit[]
3 vào [và đọc chúng từ] một cây thư mục song song bắt nguồn từ thư mục này, thay vì từ các thư mục
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'09 trong cây mã nguồn. Mọi thư mục
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'09 trong cây mã nguồn sẽ bị bỏ qua và các tệp
sys.audit[]
3 mới được ghi trong tiền tố pycache. Vì vậy, nếu bạn sử dụng như một bước xây dựng trước, bạn phải đảm bảo rằng bạn chạy nó với cùng một tiền tố pycache [nếu có] mà bạn sẽ sử dụng trong thời gian chạyMột đường dẫn tương đối được giải thích liên quan đến thư mục làm việc hiện tại
Giá trị này ban đầu được đặt dựa trên giá trị của tùy chọn dòng lệnh
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'14 hoặc biến môi trường [dòng lệnh được ưu tiên]. Nếu không được đặt, nó là
configure
9New in version 3. 8
sys. excepthook[type , value , traceback]Hàm này in ra một truy nguyên đã cho và ngoại lệ đối với
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'17
Khi một ngoại lệ được đưa ra và chưa được xử lý, trình thông dịch gọi ____________18 với ba đối số, lớp ngoại lệ, thể hiện ngoại lệ và một đối tượng truy nguyên. Trong một phiên tương tác, điều này xảy ra ngay trước khi quyền điều khiển được đưa trở lại dấu nhắc; . Việc xử lý các ngoại lệ cấp cao nhất như vậy có thể được tùy chỉnh bằng cách gán một hàm ba đối số khác cho
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'18
Đưa ra một sự kiện kiểm tra
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'18 với các đối số
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'21,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'22,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'23,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}2 khi một ngoại lệ chưa được phát hiện xảy ra. Nếu chưa đặt móc,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'21 có thể là
configure
9. Nếu bất kỳ hook nào đưa ra một ngoại lệ bắt nguồn từ lệnh gọi hook sẽ bị chặn. Nếu không, ngoại lệ móc kiểm tra sẽ được báo cáo là không thể phát hiện được và >>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'18 sẽ được gọi
Xem thêm
Hàm xử lý các ngoại lệ không thể kích hoạt và hàm xử lý ngoại lệ được đưa ra bởi
sys. __breakpointhook__sys. __displayhook__sys. __excepthook__sys. __unraisablehook__Các đối tượng này chứa các giá trị ban đầu của
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'32,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'33,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'34 và
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'35 khi bắt đầu chương trình. Chúng được lưu để có thể khôi phục lại
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'32,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'33 và
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'34,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'35 trong trường hợp chúng tình cờ được thay thế bằng các đồ vật bị hỏng hoặc thay thế
Mới trong phiên bản 3. 7. __breakpointhook__
Mới trong phiên bản 3. 8. __unraisablehook__
sys. exception[]Hàm này, khi được gọi trong khi trình xử lý ngoại lệ đang thực thi [chẳng hạn như mệnh đề
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'40 hoặc
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'41], trả về trường hợp ngoại lệ đã bị trình xử lý này bắt. Khi các trình xử lý ngoại lệ được lồng vào nhau, chỉ có thể truy cập được ngoại lệ được xử lý bởi trình xử lý trong cùng
Nếu không có trình xử lý ngoại lệ nào đang thực thi, hàm này sẽ trả về configure
9
Mới trong phiên bản 3. 11
sys. exc_info[]Hàm này trả về biểu diễn kiểu cũ của ngoại lệ được xử lý. Nếu một ngoại lệ
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'43 hiện đang được xử lý [vì vậy sẽ trả về
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'43], trả về bộ dữ liệu
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'47. Nghĩa là, một bộ chứa loại ngoại lệ [một lớp con của ], bản thân ngoại lệ đó và một thường đóng gói ngăn xếp cuộc gọi tại điểm xảy ra ngoại lệ lần cuối
Nếu không có ngoại lệ nào được xử lý ở bất kỳ đâu trên ngăn xếp, thì hàm này trả về một bộ chứa ba giá trị configure
9
Đã thay đổi trong phiên bản 3. 11. Các trường
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'22 và
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}2 hiện được lấy từ
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'23 [trường hợp ngoại lệ], do đó, khi một ngoại lệ được sửa đổi trong khi nó đang được xử lý, những thay đổi đó sẽ được phản ánh trong kết quả của các lệnh gọi tiếp theo tới. sys. exec_prefix
Một chuỗi cung cấp tiền tố thư mục dành riêng cho trang nơi các tệp Python phụ thuộc vào nền tảng được cài đặt; . Điều này có thể được đặt tại thời điểm xây dựng với đối số
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'55 cho tập lệnh cấu hình. Cụ thể, tất cả các tệp cấu hình [e. g. tệp tiêu đề
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'56] được cài đặt trong thư mục
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'57 và các mô-đun thư viện dùng chung được cài đặt trong
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'58, trong đó X. Y là số phiên bản của Python, ví dụ
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'59
Note
Nếu a có hiệu lực, giá trị này sẽ được thay đổi trong
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...3 để trỏ đến môi trường ảo. Giá trị cho bản cài đặt Python sẽ vẫn khả dụng, thông quasys. executable
Một chuỗi cung cấp đường dẫn tuyệt đối của tệp nhị phân thực thi cho trình thông dịch Python, trên các hệ thống mà điều này hợp lý. Nếu Python không thể truy xuất đường dẫn thực đến tệp thực thi của nó, thì sẽ là một chuỗi trống hoặc configure
9
Đưa ra một ngoại lệ, báo hiệu ý định thoát khỏi trình thông dịch
Đối số tùy chọn arg có thể là một số nguyên cho biết trạng thái thoát [mặc định là 0] hoặc một loại đối tượng khác. Nếu nó là một số nguyên, số 0 được coi là "kết thúc thành công" và bất kỳ giá trị khác không nào được coi là "kết thúc bất thường" bởi shell và những thứ tương tự. Hầu hết các hệ thống yêu cầu nó nằm trong phạm vi 0–127 và nếu không thì sẽ tạo ra kết quả không xác định. Một số hệ thống có quy ước gán ý nghĩa cụ thể cho các mã thoát cụ thể, nhưng chúng thường kém phát triển; . Nếu một loại đối tượng khác được truyền, thì configure
9 tương đương với việc truyền số 0 và bất kỳ đối tượng nào khác được in ra và dẫn đến mã thoát là 1. Đặc biệt,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'67 là cách nhanh chóng để thoát khỏi chương trình khi xảy ra lỗi
Vì cuối cùng "chỉ" đưa ra một ngoại lệ, nó sẽ chỉ thoát khỏi quy trình khi được gọi từ luồng chính và ngoại lệ không bị chặn. Các hành động dọn dẹp được chỉ định bởi các mệnh đề cuối cùng của câu lệnh được tôn trọng và có thể chặn nỗ lực thoát ở cấp độ bên ngoài
Đã thay đổi trong phiên bản 3. 6. Nếu xảy ra lỗi trong quá trình dọn dẹp sau khi trình thông dịch Python bắt lỗi [chẳng hạn như lỗi xóa dữ liệu được lưu trong bộ đệm trong luồng tiêu chuẩn], thì trạng thái thoát sẽ được thay đổi thành 120.
sys. flagsCác cờ hiển thị trạng thái của các cờ dòng lệnh. Các thuộc tính chỉ được đọc
thuộc tính
lá cờ
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'71
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'75
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'77
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'79
or
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'84
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'86
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'88
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'90
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'92
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'94
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'96
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'98
[]
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'00
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'02
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'04
[]
Đã thay đổi trong phiên bản 3. 2. Đã thêm thuộc tính
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'94 cho cờ mới.
Mới trong phiên bản 3. 2. 3. Thuộc tính
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'96.
Đã thay đổi trong phiên bản 3. 3. Đã xóa thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'09 lỗi thời.
Đã thay đổi trong phiên bản 3. 4. Đã thêm thuộc tính
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'77 cho cờ
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'77.
Đã thay đổi trong phiên bản 3. 7. Đã thêm thuộc tính
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'98 cho cờ mới và thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'00 cho cờ
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'16 mới.
Đã thay đổi trong phiên bản 3. 11. Đã thêm thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'02 cho tùy chọn.
Đã thay đổi trong phiên bản 3. 11. Đã thêm thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'04. sys. float_info
Một thông tin đang lưu giữ về kiểu float. Nó chứa thông tin cấp thấp về độ chính xác và biểu diễn bên trong. Các giá trị tương ứng với các hằng số dấu phẩy động khác nhau được xác định trong tệp tiêu đề tiêu chuẩn
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'20 cho ngôn ngữ lập trình 'C'; . 2. 4. 2. 2 của tiêu chuẩn ISO/IEC C năm 1999, 'Đặc điểm của các loại nổi', để biết chi tiết
thuộc tính
trôi nổi. h vĩ mô
giải trình
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'21
DBL_EPSILON
sự khác biệt giữa 1. 0 và giá trị nhỏ nhất lớn hơn 1. 0 có thể biểu diễn dưới dạng float
See also
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'23
DBL_DIG
số chữ số thập phân tối đa có thể được biểu diễn trung thực trong một số float;
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'24
DBL_MANT_DIG
phao chính xác. số cơ sở-
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'25 chữ số trong ý nghĩa của một số thực
DBL_MAX
số float hữu hạn dương có thể biểu diễn lớn nhất
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'27
DBL_MAX_EXP
số nguyên tối đa e sao cho
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'28 là số float hữu hạn có thể biểu diễn
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'29
DBL_MAX_10_EXP
số nguyên tối đa e sao cho
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'30 nằm trong phạm vi số float hữu hạn có thể biểu diễn
DBL_MIN
float chuẩn hóa dương tối thiểu có thể đại diện
Sử dụng để có được số float có thể biểu diễn không chuẩn hóa dương nhỏ nhất
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'33
DBL_MIN_EXP
số nguyên e nhỏ nhất sao cho
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'28 là số float chuẩn hóa
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'35
DBL_MIN_10_EXP
số nguyên e nhỏ nhất sao cho
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'30 là số float chuẩn hóa
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'25
FLT_RADIX
cơ số biểu diễn số mũ
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'38
FLT_ROUNDS
hằng số nguyên đại diện cho chế độ làm tròn được sử dụng cho các phép toán số học. Điều này phản ánh giá trị của macro FLT_ROUNDS hệ thống tại thời điểm khởi động trình thông dịch. Xem phần 5. 2. 4. 2. 2 của tiêu chuẩn C99 để giải thích về các giá trị có thể có và ý nghĩa của chúng
Thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'39 cần được giải thích thêm. Nếu
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'40 là bất kỳ chuỗi nào đại diện cho một số thập phân có nhiều nhất là
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'39 chữ số có nghĩa, thì việc chuyển đổi
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'40 thành một số thực và ngược lại sẽ phục hồi một chuỗi đại diện cho cùng một giá trị thập phân
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'
Nhưng đối với các chuỗi có hơn
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'39 chữ số có nghĩa, điều này không phải lúc nào cũng đúng
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'sys. float_repr_style
Một chuỗi cho biết cách hoạt động của hàm đối với số float. Nếu chuỗi có giá trị
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'45 thì đối với số float hữu hạn
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'46,
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'47 nhằm mục đích tạo ra một chuỗi ngắn có thuộc tính
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'48. Đây là hành vi thông thường trong Python 3. 1 trở lên. Mặt khác,
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'49 có giá trị
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'50 và
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'47 hoạt động giống như trong các phiên bản Python trước 3. 1
Mới trong phiên bản 3. 1
sys. getallocatedblocks[]Trả về số khối bộ nhớ hiện được cấp phát bởi trình thông dịch, bất kể kích thước của chúng. Chức năng này chủ yếu hữu ích để theo dõi và gỡ lỗi rò rỉ bộ nhớ. Do bộ đệm bên trong của trình thông dịch, kết quả có thể khác nhau giữa các cuộc gọi;
Nếu bản dựng hoặc triển khai Python không thể tính toán thông tin này một cách hợp lý, thay vào đó được phép trả về 0
Mới trong phiên bản 3. 4
sys. getandroidapilevel[]Trả lại phiên bản API thời gian xây dựng của Android dưới dạng số nguyên
Android
Mới trong phiên bản 3. 7
sys. getdefaultencoding[]Trả về tên của mã hóa chuỗi mặc định hiện tại được triển khai Unicode sử dụng
sys. getdlopenflags[]Trả về giá trị hiện tại của cờ được sử dụng cho cuộc gọi
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'55. Có thể tìm thấy tên tượng trưng cho các giá trị cờ trong mô-đun [_______2_______57 hằng số, e. g. ]
Unix
sys. getfilesystemencoding[]Nhận được. mã hóa được sử dụng để chuyển đổi giữa tên tệp Unicode và tên tệp byte. Trình xử lý lỗi hệ thống tập tin được trả về từ
Để có khả năng tương thích tốt nhất, nên sử dụng str cho tên tệp trong mọi trường hợp, mặc dù việc biểu thị tên tệp dưới dạng byte cũng được hỗ trợ. Các chức năng chấp nhận hoặc trả về tên tệp phải hỗ trợ str hoặc byte và chuyển đổi nội bộ thành biểu diễn ưu tiên của hệ thống
và nên được sử dụng để đảm bảo rằng chế độ lỗi và mã hóa chính xác được sử dụng
Được cấu hình khi khởi động Python bằng hàm
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'62. xem và các thành viên của
Đã thay đổi trong phiên bản 3. 2. kết quả không thể là configure
9 nữa.
Đã thay đổi trong phiên bản 3. 6. Windows không còn được bảo đảm sẽ trả về
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'68. Xem PEP 529 và để biết thêm thông tin.
Đã thay đổi trong phiên bản 3. 7. Trả lại
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'70 nếu được bật. sys. getfilesystemencodeerrors[]
Nhận được. trình xử lý lỗi được sử dụng để chuyển đổi giữa tên tệp Unicode và tên tệp byte. Mã hóa hệ thống tập tin được trả về từ
và nên được sử dụng để đảm bảo rằng chế độ lỗi và mã hóa chính xác được sử dụng
Được cấu hình khi khởi động Python bằng hàm
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'62. xem và các thành viên của
Mới trong phiên bản 3. 6
sys. get_int_max_str_digits[]Trả về giá trị hiện tại cho. Xem thêm
Mới trong phiên bản 3. 11
sys. getrefcount[object]Trả về số tham chiếu của đối tượng. Số đếm được trả về thường cao hơn một số so với bạn mong đợi, bởi vì nó bao gồm tham chiếu [tạm thời] làm đối số cho
sys. getrecursionlimit[]Trả về giá trị hiện tại của giới hạn đệ quy, độ sâu tối đa của ngăn xếp trình thông dịch Python. Giới hạn này ngăn đệ quy vô hạn gây tràn ngăn xếp C và làm sập Python. Nó có thể được thiết lập bởi
sys. getsizeof[object[ , default]]Trả về kích thước của một đối tượng theo byte. Đối tượng có thể là bất kỳ loại đối tượng nào. Tất cả các đối tượng tích hợp sẽ trả về kết quả chính xác, nhưng điều này không nhất thiết phải đúng với các tiện ích mở rộng của bên thứ ba vì nó được triển khai cụ thể
Chỉ tính mức tiêu thụ bộ nhớ được gán trực tiếp cho đối tượng, không phải mức tiêu thụ bộ nhớ của các đối tượng mà nó đề cập đến
Nếu được cung cấp, giá trị mặc định sẽ được trả về nếu đối tượng không cung cấp phương tiện để lấy kích thước. Nếu không a sẽ được nâng lên
gọi phương thức
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'83 của đối tượng và thêm một bộ thu gom rác bổ sung nếu đối tượng được quản lý bởi bộ thu gom rác
Xem công thức sizeof đệ quy để biết ví dụ về cách sử dụng đệ quy để tìm kích thước của vùng chứa và tất cả nội dung của chúng
sys. getswitchinterval[]Trả về "khoảng thời gian chuyển đổi chủ đề" của trình thông dịch;
New in version 3. 2
sys. _getframe[[depth]]Trả về một đối tượng khung từ ngăn xếp cuộc gọi. Nếu độ sâu số nguyên tùy chọn được cung cấp, hãy trả về đối tượng khung có nhiều lệnh gọi bên dưới đỉnh ngăn xếp. Nếu đó là sâu hơn ngăn xếp cuộc gọi, được nâng lên. Độ sâu mặc định bằng 0, trả về khung ở đầu ngăn xếp cuộc gọi
Đưa ra một
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'87 với đối số
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'88
Chi tiết triển khai CPython. Chức năng này chỉ nên được sử dụng cho mục đích nội bộ và chuyên biệt. Nó không được đảm bảo tồn tại trong tất cả các triển khai của Python
sys. getprofile[]Nhận chức năng hồ sơ như được thiết lập bởi
sys. gettrace[]Nhận chức năng theo dõi như được thiết lập bởi
Chi tiết triển khai CPython. Chức năng này chỉ dành cho việc triển khai trình gỡ lỗi, trình lược tả, công cụ bảo hiểm và những thứ tương tự. Hành vi của nó là một phần của nền tảng triển khai, chứ không phải là một phần của định nghĩa ngôn ngữ và do đó có thể không có sẵn trong tất cả các triển khai Python
sys. getwindowsversion[]Trả về một bộ có tên mô tả phiên bản Windows hiện đang chạy. Các phần tử được đặt tên là chính, phụ, xây dựng, nền tảng, service_pack, service_pack_minor, service_pack_major, suite_mask, product_type và platform_version. service_pack chứa một chuỗi, platform_version là 3-tuple và tất cả các giá trị khác là số nguyên. Các thành phần cũng có thể được truy cập theo tên, vì vậy
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'92 tương đương với
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'93. Để tương thích với các phiên bản trước, chỉ 5 phần tử đầu tiên có thể truy xuất được bằng cách lập chỉ mục
nền tảng sẽ là
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'94
product_type có thể là một trong các giá trị sau
Hằng số
Nghĩa
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'95
Hệ thống là một máy trạm
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'96
Hệ thống là một bộ điều khiển miền
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'97
Hệ thống là một máy chủ, nhưng không phải là bộ điều khiển miền
Chức năng này bao bọc chức năng Win32
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'98;
platform_version trả về phiên bản chính, phiên bản phụ và số bản dựng của hệ điều hành hiện tại, thay vì phiên bản đang được mô phỏng cho quy trình. Nó được thiết kế để sử dụng trong ghi nhật ký hơn là để phát hiện tính năng
Note
platform_version lấy phiên bản từ kernel32. dll có thể là phiên bản khác với phiên bản hệ điều hành. Vui lòng sử dụng mô-đun để đạt được phiên bản hệ điều hành chính xác
các cửa sổ
Đã thay đổi trong phiên bản 3. 2. Đã thay đổi thành một bộ được đặt tên và thêm service_pack_minor, service_pack_major, suite_mask và product_type.
Đã thay đổi trong phiên bản 3. 6. Đã thêm platform_version
sys. get_asyncgen_hooks[]Trả về một đối tượng asyncgen_hooks, tương tự như đối tượng có dạng
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...02, trong đó hàm đầu tiên và hàm hoàn thiện dự kiến sẽ là
configure
9 hoặc các hàm lấy một đối số làm đối số và được sử dụng để lên lịch hoàn thiện trình tạo không đồng bộ bằng một vòng lặp sự kiệnMới trong phiên bản 3. 6. Xem PEP 525 để biết thêm chi tiết.
Note
Chức năng này đã được thêm vào trên cơ sở tạm thời [xem PEP 411 để biết chi tiết. ]
sys. get_coroutine_origin_tracking_depth[]Nhận độ sâu theo dõi nguồn gốc coroutine hiện tại, như được đặt bởi
Mới trong phiên bản 3. 7
Note
Chức năng này đã được thêm vào trên cơ sở tạm thời [xem PEP 411 để biết chi tiết. ] Chỉ sử dụng nó cho mục đích gỡ lỗi
sys. hash_infoMột tham số đưa ra của việc thực hiện hàm băm số. Để biết thêm chi tiết về băm các loại số, xem
thuộc tính
giải trình
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...05
chiều rộng tính bằng bit được sử dụng cho giá trị băm
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...06
mô đun nguyên tố P được sử dụng cho sơ đồ băm số
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...07
giá trị băm được trả về cho một vô cực dương
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...08
[thuộc tính này không còn được sử dụng]
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...09
số nhân được sử dụng cho phần ảo của một số phức
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...10
tên của thuật toán để băm str, byte và memoryview
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...11
kích thước đầu ra bên trong của thuật toán băm
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...12
kích thước của khóa hạt giống của thuật toán băm
New in version 3. 2
Đã thay đổi trong phiên bản 3. 4. Đã thêm thuật toán, hash_bits và seed_bits
sys. hexversionSố phiên bản được mã hóa dưới dạng một số nguyên. Điều này được đảm bảo tăng theo từng phiên bản, bao gồm hỗ trợ thích hợp cho các bản phát hành phi sản xuất. Ví dụ: để kiểm tra trình thông dịch Python ít nhất là phiên bản 1. 5. 2, sử dụng
________số 8_______
Cái này được gọi là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...13 vì nó chỉ thực sự có ý nghĩa khi được xem là kết quả của việc chuyển nó sang hàm tích hợp. Có thể được sử dụng để mã hóa cùng một thông tin thân thiện với con người hơn
Thông tin chi tiết về
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...13 có thể được tìm thấy tạisys. implementation
Một đối tượng chứa thông tin về việc triển khai trình thông dịch Python hiện đang chạy. Các thuộc tính sau được yêu cầu tồn tại trong tất cả các triển khai Python
tên là định danh của việc triển khai, e. g.
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...17. Chuỗi thực tế được xác định bằng cách triển khai Python, nhưng nó được đảm bảo là chữ thường
phiên bản là một tuple được đặt tên, có cùng định dạng với. Nó đại diện cho phiên bản triển khai Python. Điều này có ý nghĩa khác biệt với phiên bản cụ thể của ngôn ngữ Python mà trình thông dịch hiện đang chạy tuân theo, mà
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...15 đại diện. Ví dụ: đối với PyPy 1. 8
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...20 có thể là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...21, trong khi đó
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...15 sẽ là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...23. Đối với CPython, chúng có cùng giá trị, vì đó là triển khai tham chiếu
hexversion là phiên bản triển khai ở định dạng thập lục phân, như
cache_tag là thẻ được máy móc nhập khẩu sử dụng trong tên tệp của các mô-đun được lưu trong bộ nhớ cache. Theo quy ước, nó sẽ là sự kết hợp của tên và phiên bản triển khai, chẳng hạn như
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...25. Tuy nhiên, việc triển khai Python có thể sử dụng một số giá trị khác nếu thích hợp. Nếu
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...26 được đặt thành
configure
9, điều đó cho biết rằng bộ nhớ đệm mô-đun sẽ bị tắtcó thể chứa các thuộc tính bổ sung dành riêng cho việc triển khai Python. Các thuộc tính không chuẩn này phải bắt đầu bằng dấu gạch dưới và không được mô tả ở đây. Bất kể nội dung của nó là gì, sẽ không thay đổi trong quá trình chạy trình thông dịch, cũng như giữa các phiên bản triển khai. [Tuy nhiên, nó có thể thay đổi giữa các phiên bản ngôn ngữ Python. ] Xem PEP 421 để biết thêm thông tin
Mới trong phiên bản 3. 3
Note
Việc bổ sung các thuộc tính bắt buộc mới phải trải qua quy trình PEP thông thường. Xem PEP 421 để biết thêm thông tin
sys. int_infoA chứa thông tin về biểu diễn số nguyên bên trong của Python. Các thuộc tính chỉ được đọc
Thuộc tính
Giải trình
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...30
số bit được giữ trong mỗi chữ số. Số nguyên Python được lưu trữ nội bộ trong cơ sở
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...31
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...32
kích thước tính bằng byte của loại C được sử dụng để biểu thị một chữ số
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...33
giá trị mặc định khi nó không được cấu hình rõ ràng
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...35
giá trị khác không nhỏ nhất cho , , hoặc
Mới trong phiên bản 3. 1
Đã thay đổi trong phiên bản 3. 11. Đã thêm
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...33 và
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...35. sys. __interactivehook__
Khi thuộc tính này tồn tại, giá trị của nó sẽ tự động được gọi [không có đối số] khi trình thông dịch được khởi chạy trong. Điều này được thực hiện sau khi tệp được đọc, để bạn có thể đặt móc này ở đó. mô-đun
Tăng một
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...43 với đối tượng hook làm đối số khi hook được gọi khi khởi động
Mới trong phiên bản 3. 4
sys. intern[string]Nhập chuỗi vào bảng các chuỗi “đã được nhập” và trả về chuỗi đã được nhập – là chính chuỗi đó hoặc một bản sao. Việc thực tập các chuỗi rất hữu ích để đạt được một chút hiệu suất khi tra cứu từ điển - nếu các khóa trong từ điển được thực tập và khóa tra cứu được thực tập, thì việc so sánh khóa [sau khi băm] có thể được thực hiện bằng cách so sánh con trỏ thay vì so sánh chuỗi. Thông thường, các tên được sử dụng trong các chương trình Python được tự động thực hiện và các từ điển được sử dụng để giữ các thuộc tính mô-đun, lớp hoặc cá thể có các khóa được thực tập
Chuỗi liên kết không phải là bất tử;
sys. is_finalizing[]Quay lại nếu trình thông dịch Python là , ngược lại
Mới trong phiên bản 3. 5
sys. last_typesys. last_valuesys. last_tracebackBa biến này không phải lúc nào cũng được xác định; . Mục đích sử dụng của chúng là cho phép người dùng tương tác nhập mô-đun trình gỡ lỗi và tham gia vào quá trình gỡ lỗi sau khi kiểm tra mà không phải thực hiện lại lệnh gây ra lỗi. [Sử dụng điển hình là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...47 để vào trình gỡ lỗi sau khi chết; xem mô-đun để biết thêm thông tin. ]
Ý nghĩa của các biến giống như ý nghĩa của các giá trị trả về ở trên
sys. maxsizeMột số nguyên cho giá trị lớn nhất mà một biến kiểu có thể nhận. Nó thường là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...51 trên nền tảng 32-bit và
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...52 trên nền tảng 64-bitsys. maxunicode
Một số nguyên cho giá trị của điểm mã Unicode lớn nhất, i. e.
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...53 [_______8_______54 ở hệ thập lục phân]
Đã thay đổi trong phiên bản 3. 3. Trước PEP 393,
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...55 từng là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...56 hoặc
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...54, tùy thuộc vào tùy chọn cấu hình chỉ định liệu các ký tự Unicode được lưu dưới dạng UCS-2 hay UCS-4. sys. meta_path
Một danh sách các đối tượng có các phương thức được gọi để xem liệu một trong các đối tượng có thể tìm thấy mô-đun được nhập hay không. Theo mặc định, nó chứa các mục triển khai ngữ nghĩa nhập mặc định của Python. Phương thức được gọi với ít nhất tên tuyệt đối của mô-đun được nhập. Nếu mô-đun được nhập nằm trong một gói, thì thuộc tính của gói gốc được chuyển vào dưới dạng đối số thứ hai. Phương thức trả về a , hoặc configure
9 nếu không tìm thấy mô-đun
Xem thêm
Lớp cơ sở trừu tượng xác định giao diện của các đối tượng tìm kiếm trên
Lớp cụ thể sẽ trả về các phiên bản của
Đã thay đổi trong phiên bản 3. 4. đã được giới thiệu trong Python 3. 4, bởi PEP 451. Các phiên bản trước của Python đã tìm kiếm một phương thức gọi là. Điều này vẫn được gọi là dự phòng nếu một mục không có phương thức.
sys. modulesĐây là từ điển ánh xạ tên mô-đun tới các mô-đun đã được tải. Điều này có thể được thao tác để buộc tải lại các mô-đun và các thủ thuật khác. Tuy nhiên, việc thay thế từ điển sẽ không nhất thiết hoạt động như mong đợi và việc xóa các mục thiết yếu khỏi từ điển có thể khiến Python bị lỗi. Nếu bạn muốn lặp lại từ điển toàn cầu này, hãy luôn sử dụng
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...69 hoặc
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...70 để tránh các ngoại lệ vì kích thước của nó có thể thay đổi trong quá trình lặp lại do tác dụng phụ của mã hoặc hoạt động trong các luồng khácsys. orig_argv
Danh sách các đối số dòng lệnh ban đầu được chuyển đến tệp thực thi Python
See also
Mới trong phiên bản 3. 10
sys. pathDanh sách các chuỗi chỉ định đường dẫn tìm kiếm cho các mô-đun. Được khởi tạo từ biến môi trường, cộng với mặc định phụ thuộc vào cài đặt
Theo mặc định, như được khởi tạo khi khởi động chương trình, một đường dẫn không an toàn tiềm tàng được thêm vào trước [trước các mục nhập do kết quả của ]
Dòng lệnh
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...
75. thêm vào thư mục làm việc hiện tạiif sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...
76 dòng lệnh. thêm vào trước thư mục của tập lệnh. Nếu đó là một liên kết tượng trưng, hãy giải quyết các liên kết tượng trưngDòng lệnh
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...
77 vàif sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...
78 [REPL]. thêm vào trước một chuỗi rỗng, có nghĩa là thư mục làm việc hiện tại
Để không thêm đường dẫn có thể không an toàn này vào trước, hãy sử dụng tùy chọn dòng lệnh hoặc biến môi trường
Một chương trình được tự do sửa đổi danh sách này cho các mục đích riêng của nó. Chỉ nên thêm các chuỗi vào ;
Xem thêm
Mô-đun Phần này mô tả cách sử dụng. tập tin pth để mở rộng
Một danh sách các hàm có thể gọi lấy một đối số đường dẫn để cố gắng tạo một đường dẫn cho. Nếu một công cụ tìm có thể được tạo, nó sẽ được trả về bởi khả năng gọi được, nếu không thì hãy tăng
Ban đầu được chỉ định trong PEP 302
sys. path_importer_cacheMột từ điển hoạt động như một bộ đệm cho các đối tượng. Các khóa là các đường dẫn đã được chuyển đến và các giá trị là các công cụ tìm được tìm thấy. Nếu một đường dẫn là một đường dẫn hệ thống tệp hợp lệ nhưng không tìm thấy công cụ tìm nào thì configure
9 được lưu trữ
Ban đầu được chỉ định trong PEP 302
Đã thay đổi trong phiên bản 3. 3. ______307_______9 được lưu trữ thay vì khi không tìm thấy công cụ tìm.
sys. platformVí dụ: chuỗi này chứa mã định danh nền tảng có thể được sử dụng để nối thêm các thành phần dành riêng cho nền tảng
Đối với các hệ thống Unix, ngoại trừ trên Linux và AIX, đây là tên hệ điều hành viết thường được trả về bởi
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...91 với phần đầu tiên của phiên bản được trả về bởi
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...92 được thêm vào, e. g.
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...93 hoặc
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...94, vào thời điểm Python được xây dựng. Trừ khi bạn muốn kiểm tra một phiên bản hệ thống cụ thể, do đó, nên sử dụng thành ngữ sau
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
Đối với các hệ thống khác, các giá trị là
Hệ thống
Giá trị
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...00
AIX
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...96
Emscripten
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...97
Linux
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...98
LÀ TÔI
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...99
các cửa sổ
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...00
Windows/Cygwin
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...01
hệ điều hành Mac
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...02
Đã thay đổi trong phiên bản 3. 3. Trên Linux, không chứa phiên bản chính nữa. Nó luôn là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...98, thay vì
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...05 hoặc
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...06. Vì các phiên bản Python cũ hơn bao gồm số phiên bản, nên luôn sử dụng thành ngữ
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...07 được trình bày ở trên.
Đã thay đổi trong phiên bản 3. 8. Trên AIX, không chứa phiên bản chính nữa. Nó luôn là
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...96, thay vì
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...10 hoặc
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...11. Vì các phiên bản Python cũ hơn bao gồm số phiên bản, nên luôn sử dụng thành ngữ
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...07 được trình bày ở trên.
Xem thêm
có độ chi tiết thô hơn. cung cấp thông tin phiên bản phụ thuộc vào hệ thống
Mô-đun này cung cấp các kiểm tra chi tiết về danh tính của hệ thống
sys. platlibdirTên của thư mục thư viện dành riêng cho nền tảng. Nó được sử dụng để xây dựng đường dẫn của thư viện chuẩn và đường dẫn của các mô-đun mở rộng đã cài đặt
Nó bằng với
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...16 trên hầu hết các nền tảng. Trên Fedora và SuSE, nó bằng với
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...17 trên nền tảng 64-bit cung cấp các đường dẫn ____8_______73 sau [trong đó ____12_______19 là phiên bản Python ____12_______20]
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
21. Thư viện tiêu chuẩn [nhưif sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
22 của mô-đun]if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
24. Các mô-đun mở rộng C của thư viện chuẩn [như mô-đun, tên tệp chính xác là dành riêng cho nền tảng]if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
26 [luôn luôn sử dụngif sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
27, không phải ]. Mô-đun của bên thứ baif sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...
29. Các mô-đun mở rộng C của gói bên thứ ba
Mới trong phiên bản 3. 9
sys. prefixMột chuỗi cung cấp tiền tố thư mục dành riêng cho trang nơi các tệp Python độc lập với nền tảng được cài đặt; . Điều này có thể được đặt tại thời điểm xây dựng với đối số
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...31 cho tập lệnh cấu hình. Xem các đường dẫn xuất phát
Note
Nếu a có hiệu lực, giá trị này sẽ được thay đổi trong
if sys.hexversion >= 0x010502F0: # use some advanced feature ... else: # use an alternative implementation or warn the user ...3 để trỏ đến môi trường ảo. Giá trị cho bản cài đặt Python sẽ vẫn khả dụng, thông quasys. ps1sys. ps2
Các chuỗi chỉ định dấu nhắc chính và dấu nhắc phụ của trình thông dịch. Chúng chỉ được xác định nếu trình thông dịch ở chế độ tương tác. Giá trị ban đầu của chúng trong trường hợp này là
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...34 và
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...35. Nếu một đối tượng không phải chuỗi được gán cho một trong hai biến, thì đối tượng đó sẽ được đánh giá lại mỗi khi trình thông dịch chuẩn bị đọc một lệnh tương tác mới; sys. setdlopenflags[n]
Đặt các cờ được trình thông dịch sử dụng cho cuộc gọi
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'55, chẳng hạn như khi trình thông dịch tải các mô-đun mở rộng. Trong số những thứ khác, điều này sẽ cho phép giải quyết chậm các ký hiệu khi nhập mô-đun, nếu được gọi là
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...38. Để chia sẻ các biểu tượng trên các mô-đun mở rộng, hãy gọi là
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...39. Có thể tìm thấy tên tượng trưng cho các giá trị cờ trong mô-đun [_______2_______57 hằng số, e. g. ]
Unix
sys. set_int_max_str_digits[maxdigits]Đặt được sử dụng bởi trình thông dịch này. Xem thêm
Mới trong phiên bản 3. 11
sys. setprofile[profilefunc]Đặt chức năng cấu hình của hệ thống, cho phép bạn triển khai trình lược tả mã nguồn Python trong Python. Xem chương để biết thêm thông tin về Python profiler. Chức năng hồ sơ của hệ thống được gọi tương tự như chức năng theo dõi của hệ thống [xem ], nhưng nó được gọi với các sự kiện khác nhau, ví dụ: nó không được gọi cho mỗi dòng mã được thực thi [chỉ khi gọi và trả về, nhưng sự kiện trả về được báo cáo . Chức năng này dành riêng cho luồng, nhưng không có cách nào để trình lược tả biết về các chuyển đổi ngữ cảnh giữa các luồng, vì vậy sẽ không hợp lý khi sử dụng chức năng này khi có nhiều luồng. Ngoài ra, giá trị trả về của nó không được sử dụng, vì vậy nó có thể chỉ cần trả về configure
9. Lỗi chức năng profile sẽ tự unset
Các chức năng hồ sơ nên có ba đối số. khung, sự kiện và arg. khung là khung ngăn xếp hiện tại. sự kiện là một chuỗi.
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...46,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...47,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...48,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...49, hoặc
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...50. arg phụ thuộc vào loại sự kiện
Tăng một
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...51 mà không có đối số
Các sự kiện có ý nghĩa như sau
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...46
Một chức năng được gọi [hoặc một số khối mã khác được nhập]. Hàm hồ sơ được gọi;
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...47
Một chức năng [hoặc khối mã khác] sắp trở lại. Hàm hồ sơ được gọi;
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...48
Hàm C sắp được gọi. Đây có thể là chức năng mở rộng hoặc tích hợp sẵn. arg là đối tượng hàm C
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...49
Một chức năng C đã trở lại. arg là đối tượng hàm C
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...50
Hàm C đã đưa ra một ngoại lệ. arg là đối tượng hàm C
sys. setrecursionlimit[limit]Đặt độ sâu tối đa của ngăn xếp trình thông dịch Python thành giới hạn. Giới hạn này ngăn đệ quy vô hạn gây tràn ngăn xếp C và làm sập Python
Giới hạn cao nhất có thể phụ thuộc vào nền tảng. Người dùng có thể cần đặt giới hạn cao hơn khi họ có chương trình yêu cầu đệ quy sâu và nền tảng hỗ trợ giới hạn cao hơn. Điều này nên được thực hiện cẩn thận, vì giới hạn quá cao có thể dẫn đến sự cố
If the new limit is too low at the current recursion depth, a exception is raised
Changed in version 3. 5. 1. A exception is now raised if the new limit is too low at the current recursion depth.
sys. setswitchinterval[interval]Set the interpreter’s thread switch interval [in seconds]. This floating-point value determines the ideal duration of the “timeslices” allocated to concurrently running Python threads. Please note that the actual value can be higher, especially if long-running internal functions or methods are used. Also, which thread becomes scheduled at the end of the interval is the operating system’s decision. The interpreter doesn’t have its own scheduler
New in version 3. 2
sys. settrace[tracefunc]Set the system’s trace function, which allows you to implement a Python source code debugger in Python. The function is thread-specific; for a debugger to support multiple threads, it must register a trace function using for each thread being debugged or use
Trace functions should have three arguments. frame, event, and arg. frame is the current stack frame. event is a string.
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...46,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...64,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...47,
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...66 or
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...67. arg depends on the event type
The trace function is invoked [with event set to
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...46] whenever a new local scope is entered; it should return a reference to a local trace function to be used for the new scope, or
configure
9 if the scope shouldn’t be tracedThe local trace function should return a reference to itself [or to another function for further tracing in that scope], or configure
9 to turn off tracing in that scope
If there is any error occurred in the trace function, it will be unset, just like
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...71 is called
Các sự kiện có ý nghĩa như sau
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...46
A function is called [or some other code block entered]. The global trace function is called; arg is configure
9; the return value specifies the local trace function
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...64
The interpreter is about to execute a new line of code or re-execute the condition of a loop. The local trace function is called; arg is configure
9; the return value specifies the new local trace function. See
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...76 for a detailed explanation of how this works. Per-line events may be disabled for a frame by setting
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...77 to on that frame
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...47
A function [or other code block] is about to return. The local trace function is called; arg is the value that will be returned, or configure
9 if the event is caused by an exception being raised. The trace function’s return value is ignored
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...66
An exception has occurred. The local trace function is called; arg is a tuple
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...82; the return value specifies the new local trace function
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...67
The interpreter is about to execute a new opcode [see for opcode details]. The local trace function is called; arg is configure
9; the return value specifies the new local trace function. Per-opcode events are not emitted by default. they must be explicitly requested by setting
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...86 to on the frame
Note that as an exception is propagated down the chain of callers, an
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...66 event is generated at each level
For more fine-grained usage, it’s possible to set a trace function by assigning
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...89 explicitly, rather than relying on it being set indirectly via the return value from an already installed trace function. This is also required for activating the trace function on the current frame, which doesn’t do. Note that in order for this to work, a global tracing function must have been installed with in order to enable the runtime tracing machinery, but it doesn’t need to be the same tracing function [e. g. it could be a low overhead tracing function that simply returns
configure
9 to disable itself immediately on each frame]For more information on code and frame objects, refer to
Raises an
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...93 with no arguments
Chi tiết triển khai CPython. Chức năng này chỉ dành cho việc triển khai trình gỡ lỗi, trình lược tả, công cụ bảo hiểm và những thứ tương tự. Hành vi của nó là một phần của nền tảng triển khai, chứ không phải là một phần của định nghĩa ngôn ngữ và do đó có thể không có sẵn trong tất cả các triển khai Python
Changed in version 3. 7.
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...67 event type added;
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...77 and
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...86 attributes added to framessys. set_asyncgen_hooks[firstiter , finalizer]
Accepts two optional keyword arguments which are callables that accept an as an argument. The firstiter callable will be called when an asynchronous generator is iterated for the first time. The finalizer will be called when an asynchronous generator is about to be garbage collected
Raises an
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...98 with no arguments
Raises an
if sys.platform.startswith['freebsd']: # FreeBSD-specific code here... elif sys.platform.startswith['linux']: # Linux-specific code here... elif sys.platform.startswith['aix']: # AIX-specific code here...99 with no arguments
Two auditing events are raised because the underlying API consists of two calls, each of which must raise its own event
New in version 3. 6. See PEP 525 for more details, and for a reference example of a finalizer method see the implementation of
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}00 in Lib/asyncio/base_events. py
Note
Chức năng này đã được thêm vào trên cơ sở tạm thời [xem PEP 411 để biết chi tiết. ]
sys. set_coroutine_origin_tracking_depth[depth]Allows enabling or disabling coroutine origin tracking. When enabled, the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}01 attribute on coroutine objects will contain a tuple of [filename, line number, function name] tuples describing the traceback where the coroutine object was created, with the most recent call first. When disabled,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}01 will be None
To enable, pass a depth value greater than zero; this sets the number of frames whose information will be captured. To disable, pass set depth to zero
This setting is thread-specific
Mới trong phiên bản 3. 7
Note
Chức năng này đã được thêm vào trên cơ sở tạm thời [xem PEP 411 để biết chi tiết. ] Chỉ sử dụng nó cho mục đích gỡ lỗi
sys. _enablelegacywindowsfsencoding[]Changes the to ‘mbcs’ and ‘replace’ respectively, for consistency with versions of Python prior to 3. 6
This is equivalent to defining the environment variable before launching Python
See also and
các cửa sổ
New in version 3. 6. See PEP 529 for more details.
sys. stdinsys. stdoutsys. stderrused by the interpreter for standard input, output and errors
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
06 is used for all interactive input [including calls to ];$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
08 is used for the output of and statements and for the prompts of ;The interpreter’s own prompts and its error messages go to
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'
66
These streams are regular like those returned by the function. Their parameters are chosen as follows
The encoding and error handling are is initialized from and
On Windows, UTF-8 is used for the console device. Non-character devices such as disk files and pipes use the system locale encoding [i. e. the ANSI codepage]. Non-console character devices such as NUL [i. e. where
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
15 returnssys.audit[]
4] use the value of the console input and output codepages at startup, respectively for stdin and stdout/stderr. This defaults to the system if the process is not initially attached to a consoleThe special behaviour of the console can be overridden by setting the environment variable PYTHONLEGACYWINDOWSSTDIO before starting Python. In that case, the console codepages are used as for any other character device
Under all platforms, you can override the character encoding by setting the environment variable before starting Python or by using the new
>>> s = '9876543211234567' # 16 significant digits is too many! >>> format[float[s], '.16g'] # conversion changes value '9876543211234568'
16 command line option and environment variable. However, for the Windows console, this only applies when is also setWhen interactive, the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
08 stream is line-buffered. Otherwise, it is block-buffered like regular text files. The>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'
66 stream is line-buffered in both cases. You can make both streams unbuffered by passing the command-line option or setting the environment variable
Changed in version 3. 9. Non-interactive
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'66 is now line-buffered instead of fully buffered.
Note
To write or read binary data from/to the standard streams, use the underlying binary object. For example, to write bytes to , use
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}29
However, if you are writing a library [and do not control in which context its code will be executed], be aware that the standard streams may be replaced with file-like objects like which do not support the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}27 attributesys. __stdin__sys. __stdout__sys. __stderr__
These objects contain the original values of
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}06,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'66 and
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}08 at the start of the program. They are used during finalization, and could be useful to print to the actual standard stream no matter if the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}35 object has been redirected
Nó cũng có thể được sử dụng để khôi phục các tệp thực tế thành các đối tượng tệp đang hoạt động đã biết trong trường hợp chúng bị ghi đè bằng một đối tượng bị hỏng. Tuy nhiên, cách ưu tiên để thực hiện việc này là lưu rõ ràng luồng trước đó trước khi thay thế luồng đó và khôi phục đối tượng đã lưu
Note
Trong một số điều kiện
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}06,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}08 và
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'66 cũng như các giá trị ban đầu
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}39,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}40 và
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}41 có thể là
configure
9. Trường hợp này thường xảy ra đối với các ứng dụng Windows GUI không được kết nối với bảng điều khiển và các ứng dụng Python bắt đầu bằng pythonwsys. stdlib_module_namesMột tập hợp các chuỗi cố định chứa tên của các mô-đun thư viện tiêu chuẩn
Nó giống nhau trên tất cả các nền tảng. Modules which are not available on some platforms and modules disabled at Python build are also listed. All module kinds are listed. pure Python, built-in, frozen and extension modules. Test modules are excluded
For packages, only the main package is listed. sub-packages and sub-modules are not listed. For example, the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}43 package is listed, but the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}44 sub-package and the
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}45 sub-module are not listed
Xem thêm danh sách
Mới trong phiên bản 3. 10
sys. thread_infoA holding information about the thread implementation
Thuộc tính
Giải trình
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}47
Name of the thread implementation
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}48. Windows threads $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}49. POSIX threads $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}50. stub POSIX threads [on WebAssembly platforms without threading support] $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}51. Solaris threads
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}52
Name of the lock implementation
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}53. a lock uses a semaphore $ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}54. a lock uses a mutex and a condition variable
configure
9 if this information is unknown
Name and version of the thread library. It is a string, or configure
9 if this information is unknown
Mới trong phiên bản 3. 3
sys. tracebacklimitWhen this variable is set to an integer value, it determines the maximum number of levels of traceback information printed when an unhandled exception occurs. The default is
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}58. When set to
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}59 or less, all traceback information is suppressed and only the exception type and value are printedsys. unraisablehook[unraisable , /]
Handle an unraisable exception
Called when an exception has occurred but there is no way for Python to handle it. For example, when a destructor raises an exception or during garbage collection []
The unraisable argument has the following attributes
exc_type. Exception type
exc_value. Exception value, can be
configure
9exc_traceback. Exception traceback, can be
configure
9err_msg. Error message, can be
configure
9object. Object causing the exception, can be
configure
9
The default hook formats err_msg and object as.
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}65; use “Exception ignored in” error message if err_msg is
configure
9can be overridden to control how unraisable exceptions are handled
Storing exc_value using a custom hook can create a reference cycle. It should be cleared explicitly to break the reference cycle when the exception is no longer needed
Storing object using a custom hook can resurrect it if it is set to an object which is being finalized. Avoid storing object after the custom hook completes to avoid resurrecting objects
See also which handles uncaught exceptions
Raise an auditing event
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}69 with arguments
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'21,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}71 when an exception that cannot be handled occurs. The
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}71 object is the same as what will be passed to the hook. If no hook has been set,
>>> import sys >>> sys.float_info.dig 15 >>> s = '3.14159265358979' # decimal string with 15 significant digits >>> format[float[s], '.15g'] # convert to float and back -> same value '3.14159265358979'21 may be
configure
9New in version 3. 8
sys. versionA string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use and the functions provided by the module
sys. api_versionThe C API version for this interpreter. Programmers may find this useful when debugging version conflicts between Python and extension modules
sys. version_infoA tuple containing the five components of the version number. major, minor, micro, releaselevel, and serial. All values except releaselevel are integers; the release level is
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}77,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}78,
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}79, or
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}80. The
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}75 value corresponding to the Python version 2. 0 is
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}82. The components can also be accessed by name, so
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}83 is equivalent to
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}84 and so on
Changed in version 3. 1. Added named component attributes.
sys. warnoptionsThis is an implementation detail of the warnings framework; do not modify this value. Refer to the module for more information on the warnings framework
sys. winverThe version number used to form registry keys on Windows platforms. This is stored as string resource 1000 in the Python DLL. The value is normally the major and minor versions of the running Python interpreter. It is provided in the module for informational purposes; modifying this value has no effect on the registry keys used by Python
các cửa sổ
sys. _xoptionsA dictionary of the various implementation-specific flags passed through the command-line option. Option names are either mapped to their values, if given explicitly, or to . Example
$ ./python -Xa=b -Xc Python 3.2a3+ [py3k, Oct 16 2010, 20:14:50] [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys._xoptions {'a': 'b', 'c': True}
CPython implementation detail. This is a CPython-specific way of accessing options passed through . Other implementations may export them through other means, or not at all
New in version 3. 2
Citations
ISO/IEC 9899. 1999. “Programming languages – C. ” A public draft of this standard is available at https. //www. open-std. org/jtc1/sc22/wg14/www/docs/n1256. pdf