Fungsi panggilan python dari modul yang sama

Modul ini menyediakan akses ke beberapa variabel yang digunakan atau dikelola oleh juru bahasa dan ke fungsi yang berinteraksi kuat dengan juru bahasa. It is always available

sys. abiflags

On 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(kait)

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 hook

sys. 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'
7

sys. 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. Acara ini memiliki satu argumen yang disebut jalur yang akan berisi direktori kerja baru yang diminta

akan memanggil kait audit yang ada, meneruskan nama acara dan argumen, dan akan memunculkan kembali pengecualian pertama dari kait apa pun. Secara umum, jika pengecualian muncul, itu tidak boleh ditangani dan prosesnya harus dihentikan secepat mungkin. Hal ini memungkinkan implementasi pengait untuk memutuskan bagaimana menanggapi peristiwa tertentu. mereka hanya dapat mencatat peristiwa atau membatalkan operasi dengan mengajukan pengecualian

Pengait ditambahkan menggunakan fungsi atau

Padanan asli dari fungsi ini adalah. Menggunakan fungsi asli lebih disukai jika memungkinkan

Lihat untuk semua acara yang diangkat oleh CPython

New in version 3. 8

sys. base_exec_prefix

Setel selama startup Python, sebelum

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_3 dijalankan, dengan nilai yang sama dengan. Jika tidak dijalankan dalam a , nilainya akan tetap sama;

Baru di versi 3. 3

sys. base_prefix

Setel selama startup Python, sebelum

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_3 dijalankan, dengan nilai yang sama dengan. Jika tidak dijalankan dalam a , nilainya akan tetap sama;

Baru di versi 3. 3

sys. byteorder

Indikator urutan byte asli. Ini akan memiliki nilai

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 pada platform big-endian (most-significant byte first), dan
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 pada platform little-endian (least-significant byte first)

sys. builtin_module_names

A tuple of strings containing the names of all modules that are compiled into this Python interpreter. (This information is not available in any other way —

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 only lists the imported modules. )

See also the list

sys. call_tracing(func , args)

Call

$ ./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, while tracing is enabled. The tracing state is saved, and restored afterwards. This is intended to be called from a debugger from a checkpoint, to recursively debug some other code

sys. 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()

Mengembalikan kamus yang memetakan setiap pengidentifikasi utas ke bingkai tumpukan paling atas yang saat ini aktif di utas tersebut pada saat fungsi dipanggil. Perhatikan bahwa fungsi dalam modul dapat membangun tumpukan panggilan yang diberi bingkai seperti itu

Ini paling berguna untuk men-debug kebuntuan. fungsi ini tidak memerlukan kerja sama utas yang menemui jalan buntu, dan tumpukan panggilan utas tersebut dibekukan selama mereka tetap menemui jalan buntu. Bingkai yang dikembalikan untuk utas yang tidak menemui jalan buntu mungkin tidak memiliki hubungan dengan aktivitas utas saat ini pada saat kode pemanggil memeriksa bingkai

This function should be used for internal and specialized purposes only

Memunculkan

$ ./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 tanpa argumen

sys. _current_exceptions()

Mengembalikan kamus yang memetakan setiap pengidentifikasi utas ke pengecualian paling atas yang saat ini aktif di utas tersebut pada saat fungsi dipanggil. Jika utas saat ini tidak menangani pengecualian, utas tidak disertakan dalam kamus hasil

Ini paling berguna untuk pembuatan profil statistik

This function should be used for internal and specialized purposes only

Memunculkan

$ ./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 tanpa argumen

sys. breakpointhook()

Fungsi hook ini disebut dengan built-in. Secara default, itu memasukkan Anda ke dalam debugger, tetapi dapat diatur ke fungsi lain apa pun sehingga Anda dapat memilih debugger mana yang akan digunakan

Tanda tangan dari fungsi ini tergantung pada apa yang dipanggilnya. Misalnya, pengikatan default (mis. 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) tidak mengharapkan argumen, tetapi Anda dapat mengikatnya ke fungsi yang mengharapkan argumen tambahan (posisional dan/atau kata kunci). Fungsi
$ ./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 bawaan melewati
$ ./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 dan sys0 langsung melalui. Apapun sys_1 pengembalian dikembalikan dari
$ ./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

Implementasi default pertama-tama berkonsultasi dengan variabel lingkungan. Jika itu disetel ke sys4 maka fungsi ini segera kembali; . e. itu adalah tanpa operasi. Jika variabel lingkungan tidak disetel, atau disetel ke string kosong,

$ ./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 dipanggil. Kalau tidak, variabel ini harus memberi nama fungsi untuk dijalankan, menggunakan nomenklatur dotted-import Python, mis. g. sys6. Dalam hal ini, sys_7 akan diimpor dan modul yang dihasilkan harus memiliki nama panggilan sys8. Ini dijalankan, meneruskan
$ ./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 dan sys0, dan apa pun yang dikembalikan sys8, configure2 kembali ke fungsi bawaan

Perhatikan bahwa jika terjadi kesalahan saat mengimpor callable bernama by , a dilaporkan dan breakpoint diabaikan

Perhatikan juga bahwa jika configure_2 diganti secara terprogram, tidak dikonsultasikan

Baru di versi 3. 7

sys. _debugmallocstats()

Cetak informasi tingkat rendah ke stderr tentang status pengalokasi memori CPython

Jika Python adalah (), itu juga melakukan beberapa pemeriksaan konsistensi internal yang mahal

Baru di versi 3. 3

Detail implementasi CPython. Fungsi ini khusus untuk CPython. Format keluaran yang tepat tidak ditentukan di sini, dan dapat berubah

sys. dllhandle

Bilangan bulat yang menentukan pegangan Python DLL

Windows

sys. displayhook(value)

Jika nilai bukan configure_9, fungsi ini mencetak m0 ke m1, dan menyimpan nilai di m2. Jika m_0 tidak dapat disandikan ke m4 dengan penangan kesalahan m5 (yang mungkin m6), enkodekan ke penangan kesalahan m4 dengan penangan kesalahan m8

m_9 dipanggil pada hasil evaluasi yang dimasukkan dalam sesi Python interaktif. Tampilan nilai-nilai ini dapat disesuaikan dengan menugaskan fungsi satu argumen lainnya ke m9

Kode semu

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

Berubah di versi 3. 2. Gunakan penangan kesalahan m8 di.

sys. dont_write_bytecode

Jika ini benar, Python tidak akan mencoba menulis sys.audit()3 file pada impor modul sumber. Nilai ini awalnya disetel ke sys.audit()_4 atau sys.audit()5 bergantung pada opsi baris perintah dan variabel lingkungan, tetapi Anda dapat menyetelnya sendiri untuk mengontrol pembuatan file bytecode

sys. _emscripten_info

Tempat menyimpan informasi tentang lingkungan pada platform wasm32-emscripten. Tuple bernama bersifat sementara dan dapat berubah di masa mendatang

Atribut

Penjelasan

sys.audit()_8

Versi emscripten sebagai tupel int (mayor, minor, mikro), 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

String runtime, mis. g. agen pengguna browser,

>>> 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, atau
>>> 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 jika Python dikompilasi dengan dukungan 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 jika Python dikompilasi dengan dukungan memori bersama

Emscripten

Baru di versi 3. 11

sys. pycache_prefix

Jika ini disetel (bukan configure_9), Python akan menulis file bytecode-cache sys.audit()3 ke (dan membacanya dari) pohon direktori paralel yang berakar pada direktori ini, bukan dari direktori

>>> 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 di pohon kode sumber. Any
>>> 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 directories in the source code tree will be ignored and new sys.audit()3 files written within the pycache prefix. Jadi jika Anda menggunakan sebagai langkah pra-bangun, Anda harus memastikan Anda menjalankannya dengan awalan pycache yang sama (jika ada) yang akan Anda gunakan saat runtime

Jalur relatif ditafsirkan relatif terhadap direktori kerja saat ini

Nilai ini awalnya ditetapkan berdasarkan nilai opsi baris perintah

>>> 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 atau variabel lingkungan (baris perintah diutamakan). Jika tidak ada yang disetel, itu adalah ________307______9

New in version 3. 8

sys. excepthook(type , value , traceback)

Fungsi ini mencetak traceback dan pengecualian yang diberikan ke

>>> 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

Saat pengecualian muncul dan tidak tertangkap, juru bahasa memanggil

>>> 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 dengan tiga argumen, kelas pengecualian, instance pengecualian, dan objek traceback. Dalam sesi interaktif ini terjadi sebelum kontrol dikembalikan ke prompt; . Penanganan pengecualian tingkat atas tersebut dapat disesuaikan dengan menugaskan fungsi tiga argumen lainnya ke
>>> 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

Mengangkat acara audit

>>> 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 dengan argumen
>>> 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 saat terjadi pengecualian yang tidak tertangkap. Jika tidak ada pengait yang dipasang,
>>> 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 mungkin configure9. Jika ada hook yang memunculkan eksepsi yang berasal dari panggilan ke hook akan ditekan. Jika tidak, pengecualian kaitan audit akan dilaporkan sebagai tidak dapat diajukan dan
>>> 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 akan dipanggil

See also

Fungsi menangani pengecualian yang tidak dapat dimunculkan dan fungsi menangani pengecualian yang diajukan oleh

sys. __breakpointhook__sys. __displayhook__sys. __excepthook__sys. __unraisablehook__

These objects contain the original values of

>>> 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, and
>>> 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 at the start of the program. They are saved so that
>>> 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 and
>>> 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 can be restored in case they happen to get replaced with broken or alternative objects

New in version 3. 7. __breakpointhook__

New in version 3. 8. __unraisablehook__

sys. exception()

This function, when called while an exception handler is executing (such as an

>>> 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 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'
41 clause), returns the exception instance that was caught by this handler. When exception handlers are nested within one another, only the exception handled by the innermost handler is accessible

If no exception handler is executing, this function returns configure9

Baru di versi 3. 11

sys. exc_info()

This function returns the old-style representation of the handled exception. If an exception

>>> 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 is currently handled (so would return
>>> 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), returns the tuple
>>> 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. That is, a tuple containing the type of the exception (a subclass of ), the exception itself, and a which typically encapsulates the call stack at the point where the exception last occurred

If no exception is being handled anywhere on the stack, this function return a tuple containing three configure9 values

Changed in version 3. 11. Kolom

>>> 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 dan
$ ./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 sekarang diturunkan dari
>>> 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 (instance pengecualian), jadi saat pengecualian diubah saat sedang ditangani, perubahan tersebut tercermin dalam hasil panggilan berikutnya ke.

sys. exec_prefix

Sebuah string yang memberikan awalan direktori khusus situs tempat file Python yang bergantung pada platform diinstal; . Ini dapat diatur pada waktu pembuatan dengan argumen

>>> 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 ke skrip configure. Secara khusus, semua file konfigurasi (mis. g. file header
>>> 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) dipasang di direktori
>>> 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, dan modul pustaka bersama dipasang di
>>> 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, di mana X. Y adalah nomor versi Python, misalnya
>>> 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

Jika a berlaku, nilai ini akan diubah di

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
3 untuk menunjuk ke lingkungan virtual. Nilai untuk instalasi Python akan tetap tersedia, via

sys. executable

Sebuah string yang memberikan jalur absolut dari biner yang dapat dieksekusi untuk juru bahasa Python, pada sistem yang masuk akal. Jika Python tidak dapat mengambil jalur sebenarnya ke yang dapat dieksekusi, akan menjadi string kosong atau configure9

sys. exit([arg])

Ajukan pengecualian, menandakan niat untuk keluar dari penerjemah

Argumen opsional arg dapat berupa bilangan bulat yang memberikan status keluar (default ke nol), atau jenis objek lainnya. Jika bilangan bulat, nol dianggap sebagai "penghentian yang berhasil" dan nilai bukan nol apa pun dianggap sebagai "penghentian abnormal" oleh shell dan sejenisnya. Sebagian besar sistem mengharuskannya berada dalam kisaran 0–127, dan sebaliknya menghasilkan hasil yang tidak terdefinisi. Beberapa sistem memiliki konvensi untuk memberikan arti khusus pada kode keluar tertentu, tetapi ini umumnya kurang berkembang; . Jika jenis objek lain dilewatkan, configure9 setara dengan melewati nol, dan objek lainnya dicetak ke dan menghasilkan kode keluar 1. Secara khusus,

>>> 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 adalah cara cepat untuk keluar dari program saat terjadi kesalahan

Karena pada akhirnya "hanya" memunculkan pengecualian, itu hanya akan keluar dari proses saat dipanggil dari utas utama, dan pengecualian tidak dicegat. Tindakan pembersihan ditentukan oleh akhirnya klausa pernyataan dihormati, dan dimungkinkan untuk mencegat upaya keluar di tingkat luar

Berubah di versi 3. 6. Jika terjadi kesalahan dalam pembersihan setelah juru bahasa Python menangkap (seperti kesalahan membilas data buffer di aliran standar), status keluar diubah menjadi 120.

sys. flags

Bendera memperlihatkan status bendera baris perintah. Atribut hanya bisa dibaca

atribut

bendera

>>> 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

atau

>>> 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

()

Berubah di versi 3. 2. Menambahkan atribut

>>> 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 untuk bendera baru.

Baru di versi 3. 2. 3. Atribut

>>> 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.

Berubah di versi 3. 3. Menghapus atribut

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
09 usang.

Berubah di versi 3. 4. Menambahkan atribut

>>> 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 untuk bendera
>>> 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.

Berubah di versi 3. 7. Menambahkan atribut

>>> 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 untuk yang baru dan atribut
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
00 untuk bendera
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
16 yang baru.

Berubah di versi 3. 11. Menambahkan atribut

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
02 untuk opsi.

Berubah di versi 3. 11. Menambahkan atribut

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
04.

sys. float_info

Informasi holding tentang tipe float. Ini berisi informasi tingkat rendah tentang presisi dan representasi internal. Nilai sesuai dengan berbagai konstanta floating-point yang didefinisikan dalam file header standar

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
20 untuk bahasa pemrograman 'C'; . 2. 4. 2. 2 dari standar ISO/IEC C 1999, 'Karakteristik tipe mengambang', untuk detail

atribut

mengambang. h makro

penjelasan

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
_21

DBL_EPSILON

perbedaan antara 1. 0 dan nilai terkecil lebih besar dari 1. 0 that is representable as a float

See also

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
23

DBL_DIG

maximum number of decimal digits that can be faithfully represented in a float; see below

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
24

DBL_MANT_DIG

float precision. the number of base-

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
25 digits in the significand of a float

DBL_MAX

maximum representable positive finite float

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
27

DBL_MAX_EXP

maximum integer e such that

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
28 is a representable finite float

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
29

DBL_MAX_10_EXP

maximum integer e such that

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
30 is in the range of representable finite floats

DBL_MIN

minimum representable positive normalized float

Use to get the smallest positive denormalized representable float

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
33

DBL_MIN_EXP

minimum integer e such that

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
28 is a normalized float

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
35

DBL_MIN_10_EXP

minimum integer e such that

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
30 is a normalized float

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
25

FLT_RADIX

radix of exponent representation

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
38

FLT_ROUNDS

integer constant representing the rounding mode used for arithmetic operations. This reflects the value of the system FLT_ROUNDS macro at interpreter startup time. See section 5. 2. 4. 2. 2 of the C99 standard for an explanation of the possible values and their meanings

The attribute

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
39 needs further explanation. If
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
40 is any string representing a decimal number with at most
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
39 significant digits, then converting
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
40 to a float and back again will recover a string representing the same decimal value

>>> 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'

But for strings with more than

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
39 significant digits, this isn’t always true

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'

sys. float_repr_style

A string indicating how the function behaves for floats. If the string has value

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
45 then for a finite float
>>> 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 aims to produce a short string with the property that
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
48. This is the usual behaviour in Python 3. 1 and later. Otherwise,
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
49 has value
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
50 and
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
47 behaves in the same way as it did in versions of Python prior to 3. 1

New in version 3. 1

sys. getallocatedblocks()

Kembalikan jumlah blok memori yang saat ini dialokasikan oleh juru bahasa, terlepas dari ukurannya. This function is mainly useful for tracking and debugging memory leaks. Because of the interpreter’s internal caches, the result can vary from call to call; you may have to call and to get more predictable results

If a Python build or implementation cannot reasonably compute this information, is allowed to return 0 instead

New in version 3. 4

sys. getandroidapilevel()

Return the build time API version of Android as an integer

Android

Baru di versi 3. 7

sys. getdefaultencoding()

Return the name of the current default string encoding used by the Unicode implementation

sys. getdlopenflags()

Return the current value of the flags that are used for

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
55 calls. Symbolic names for the flag values can be found in the module (
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
57 constants, e. g. )

Unix

sys. getfilesystemencoding()

Get the . the encoding used with the to convert between Unicode filenames and bytes filenames. The filesystem error handler is returned from

For best compatibility, str should be used for filenames in all cases, although representing filenames as bytes is also supported. Functions accepting or returning filenames should support either str or bytes and internally convert to the system’s preferred representation

and should be used to ensure that the correct encoding and errors mode are used

The are configured at Python startup by the

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
62 function. see and members of

Changed in version 3. 2. result cannot be configure9 anymore.

Changed in version 3. 6. Windows is no longer guaranteed to return

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
68. See PEP 529 and for more information.

Changed in version 3. 7. Return

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
70 if the is enabled.

sys. getfilesystemencodeerrors()

Get the . the error handler used with the to convert between Unicode filenames and bytes filenames. The filesystem encoding is returned from

and should be used to ensure that the correct encoding and errors mode are used

The are configured at Python startup by the

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
62 function. see and members of

New in version 3. 6

sys. get_int_max_str_digits()

Returns the current value for the . See also

Baru di versi 3. 11

sys. getrefcount(object)

Return the reference count of the object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to

sys. getrecursionlimit()

Return the current value of the recursion limit, the maximum depth of the Python interpreter stack. This limit prevents infinite recursion from causing an overflow of the C stack and crashing Python. It can be set by

sys. getsizeof(object[ , default])

Return the size of an object in bytes. Objeknya bisa berupa jenis objek apa saja. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific

Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to

If given, default will be returned if the object does not provide means to retrieve the size. Otherwise a will be raised

calls the object’s

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
83 method and adds an additional garbage collector overhead if the object is managed by the garbage collector

See recursive sizeof recipe for an example of using recursively to find the size of containers and all their contents

sys. getswitchinterval()

Return the interpreter’s “thread switch interval”; see

New in version 3. 2

sys. _getframe([depth])

Return a frame object from the call stack. If optional integer depth is given, return the frame object that many calls below the top of the stack. If that is deeper than the call stack, is raised. The default for depth is zero, returning the frame at the top of the call stack

Raises an

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
87 with argument
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
88

CPython implementation detail. This function should be used for internal and specialized purposes only. It is not guaranteed to exist in all implementations of Python

sys. getprofile()

Get the profiler function as set by

sys. gettrace()

Get the trace function as set by

CPython implementation detail. The function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations

sys. getwindowsversion()

Return a named tuple describing the Windows version currently running. The named elements are major, minor, build, platform, service_pack, service_pack_minor, service_pack_major, suite_mask, product_type and platform_version. service_pack contains a string, platform_version a 3-tuple and all other values are integers. The components can also be accessed by name, so

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
92 is equivalent to
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
93. For compatibility with prior versions, only the first 5 elements are retrievable by indexing

platform will be

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
94

product_type may be one of the following values

Constant

Meaning

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
95

The system is a workstation

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
96

The system is a domain controller

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
97

The system is a server, but not a domain controller

This function wraps the Win32

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
98 function; see the Microsoft documentation on
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
99 for more information about these fields

platform_version returns the major version, minor version and build number of the current operating system, rather than the version that is being emulated for the process. It is intended for use in logging rather than for feature detection

Note

platform_version derives the version from kernel32. dll which can be of a different version than the OS version. Please use module for achieving accurate OS version

Windows

Changed in version 3. 2. Changed to a named tuple and added service_pack_minor, service_pack_major, suite_mask, and product_type.

Changed in version 3. 6. Added platform_version

sys. get_asyncgen_hooks()

Returns an asyncgen_hooks object, which is similar to a of the form

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
02, where firstiter and finalizer are expected to be either configure9 or functions which take an as an argument, and are used to schedule finalization of an asynchronous generator by an event loop

New in version 3. 6. See PEP 525 for more details.

Note

This function has been added on a provisional basis (see PEP 411 for details. )

sys. get_coroutine_origin_tracking_depth()

Get the current coroutine origin tracking depth, as set by

Baru di versi 3. 7

Note

This function has been added on a provisional basis (see PEP 411 for details. ) Use it only for debugging purposes

sys. hash_info

A giving parameters of the numeric hash implementation. For more details about hashing of numeric types, see

atribut

penjelasan

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
05

width in bits used for hash values

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
06

prime modulus P used for numeric hash scheme

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
07

hash value returned for a positive infinity

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
08

(this attribute is no longer used)

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
09

multiplier used for the imaginary part of a complex number

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
10

name of the algorithm for hashing of str, bytes, and memoryview

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
11

internal output size of the hash algorithm

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
12

size of the seed key of the hash algorithm

New in version 3. 2

Changed in version 3. 4. Added algorithm, hash_bits and seed_bits

sys. hexversion

The version number encoded as a single integer. This is guaranteed to increase with each version, including proper support for non-production releases. For example, to test that the Python interpreter is at least version 1. 5. 2, use

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...

This is called

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
13 since it only really looks meaningful when viewed as the result of passing it to the built-in function. The may be used for a more human-friendly encoding of the same information

More details of

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
13 can be found at

sys. implementation

An object containing information about the implementation of the currently running Python interpreter. The following attributes are required to exist in all Python implementations

name is the implementation’s identifier, e. g.

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
17. The actual string is defined by the Python implementation, but it is guaranteed to be lower case

version is a named tuple, in the same format as . It represents the version of the Python implementation. This has a distinct meaning from the specific version of the Python language to which the currently running interpreter conforms, which

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
15 represents. For example, for PyPy 1. 8
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
20 might be
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
21, whereas
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
15 would be
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
23. For CPython they are the same value, since it is the reference implementation

hexversion is the implementation version in hexadecimal format, like

cache_tag is the tag used by the import machinery in the filenames of cached modules. By convention, it would be a composite of the implementation’s name and version, like

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
25. However, a Python implementation may use some other value if appropriate. If
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
26 is set to configure9, it indicates that module caching should be disabled

may contain additional attributes specific to the Python implementation. These non-standard attributes must start with an underscore, and are not described here. Regardless of its contents, will not change during a run of the interpreter, nor between implementation versions. (It may change between Python language versions, however. ) See PEP 421 for more information

Baru di versi 3. 3

Note

The addition of new required attributes must go through the normal PEP process. See PEP 421 for more information

sys. int_info

A that holds information about Python’s internal representation of integers. The attributes are read only

Atribut

Penjelasan

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
30

number of bits held in each digit. Bilangan bulat Python disimpan secara internal di basis

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

ukuran dalam byte tipe C yang digunakan untuk mewakili digit

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_33

nilai default ketika tidak dikonfigurasi secara eksplisit

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_35

nilai non-nol minimum untuk , , atau

New in version 3. 1

Berubah di versi 3. 11. Menambahkan

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
33 dan
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
35.

sys. __interactivehook__

Saat atribut ini ada, nilainya secara otomatis dipanggil (tanpa argumen) saat penerjemah diluncurkan. Ini dilakukan setelah file dibaca, sehingga Anda dapat mengatur pengait ini di sana. Modul

Memunculkan

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_43 dengan objek hook sebagai argumen saat hook dipanggil saat startup

New in version 3. 4

sys. magang(string)

Masukkan string dalam tabel string "diinternir" dan kembalikan string yang diinternir - yang merupakan string itu sendiri atau salinannya. String magang berguna untuk mendapatkan sedikit kinerja pada pencarian kamus - jika kunci dalam kamus diinternir, dan kunci pencarian diinternir, perbandingan kunci (setelah hashing) dapat dilakukan dengan perbandingan penunjuk alih-alih perbandingan string. Biasanya, nama yang digunakan dalam program Python secara otomatis diinternir, dan kamus yang digunakan untuk menyimpan atribut modul, kelas, atau instance memiliki kunci yang diinternir.

String yang diinternir tidak abadi;

sys. sedang_menyelesaikan()

Kembalikan jika juru bahasa Python adalah , jika tidak

Baru di versi 3. 5

sys. last_typesys. last_valuesys. last_traceback

Ketiga variabel ini tidak selalu didefinisikan; . Penggunaan yang dimaksudkan adalah untuk memungkinkan pengguna interaktif mengimpor modul debugger dan terlibat dalam debugging post-mortem tanpa harus menjalankan kembali perintah yang menyebabkan kesalahan. (Penggunaan umum adalah

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_47 untuk memasukkan debugger post-mortem; lihat modul untuk informasi lebih lanjut. )

Arti dari variabel sama dengan nilai kembalian dari atas

sys. maxsize

Bilangan bulat yang memberikan nilai maksimum yang dapat diambil oleh variabel bertipe. Biasanya

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_51 pada platform 32-bit dan
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
52 pada platform 64-bit

sys. maxunicode

Bilangan bulat yang memberikan nilai titik kode Unicode terbesar, i. e.

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_53 (
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
54 dalam heksadesimal)

Berubah di versi 3. 3. Sebelum PEP 393,

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
55 dulunya adalah
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
56 atau
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
54, bergantung pada opsi konfigurasi yang menentukan apakah karakter Unicode disimpan sebagai UCS-2 atau UCS-4.

sys. meta_path

Daftar objek yang metodenya dipanggil untuk melihat apakah salah satu objek dapat menemukan modul yang akan diimpor. Secara default, ini menyimpan entri yang mengimplementasikan semantik impor default Python. Metode dipanggil dengan setidaknya nama absolut dari modul yang diimpor. Jika modul yang akan diimpor terdapat dalam sebuah paket, maka atribut paket induk diteruskan sebagai argumen kedua. Metode mengembalikan a , atau ________307______9 jika modul tidak dapat ditemukan

See also

Kelas dasar abstrak yang mendefinisikan antarmuka objek finder

Kelas konkret yang harus mengembalikan instance

Changed in version 3. 4. diperkenalkan dengan Python 3. 4, oleh PEP 451. Versi Python sebelumnya mencari metode yang disebut. Ini masih disebut fallback jika entri tidak memiliki metode.

sys. modules

Ini adalah kamus yang memetakan nama modul ke modul yang telah dimuat. Ini dapat dimanipulasi untuk memaksa memuat ulang modul dan trik lainnya. Namun, mengganti kamus belum tentu berfungsi seperti yang diharapkan dan menghapus item penting dari kamus dapat menyebabkan Python gagal. Jika Anda ingin mengulangi kamus global ini selalu gunakan

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
69 atau
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
70 untuk menghindari pengecualian karena ukurannya dapat berubah selama iterasi sebagai efek samping dari kode atau aktivitas di utas lainnya

sys. orig_argv

Daftar argumen baris perintah asli diteruskan ke Python yang dapat dieksekusi

See also

Baru di versi 3. 10

sys. path

Daftar string yang menentukan jalur pencarian untuk modul. Diinisialisasi dari variabel lingkungan , ditambah default yang bergantung pada penginstalan

By default, as initialized upon program startup, a potentially unsafe path is prepended to (before the entries inserted as a result of )

  • if sys.hexversion >= 0x010502F0:
        # use some advanced feature
        ...
    else:
        # use an alternative implementation or warn the user
        ...
    
    _75 baris perintah. tambahkan direktori kerja saat ini

  • if sys.hexversion >= 0x010502F0:
        # use some advanced feature
        ...
    else:
        # use an alternative implementation or warn the user
        ...
    
    _76 baris perintah. tambahkan direktori skrip. Jika itu adalah tautan simbolik, selesaikan tautan simbolik

  • if sys.hexversion >= 0x010502F0:
        # use some advanced feature
        ...
    else:
        # use an alternative implementation or warn the user
        ...
    
    77 dan
    if sys.hexversion >= 0x010502F0:
        # use some advanced feature
        ...
    else:
        # use an alternative implementation or warn the user
        ...
    
    78 (REPL) baris perintah. tambahkan string kosong, yang berarti direktori kerja saat ini

Untuk tidak menambahkan jalur yang berpotensi tidak aman ini, gunakan opsi baris perintah atau variabel lingkungan

Sebuah program bebas untuk memodifikasi daftar ini untuk tujuannya sendiri. Hanya string yang harus ditambahkan ke ;

See also

  • Modul Ini menjelaskan cara menggunakan. file pth untuk memperpanjang

sys. path_hooks

Daftar callable yang mengambil argumen path untuk mencoba membuat path. Jika finder dapat dibuat, itu akan dikembalikan oleh callable, jika tidak naikkan

Awalnya ditentukan dalam PEP 302

sys. path_importer_cache

Kamus bertindak sebagai cache untuk objek. Kuncinya adalah jalur yang telah dilewati dan nilainya adalah pencari yang ditemukan. If a path is a valid file system path but no finder is found on then configure9 is stored

Awalnya ditentukan dalam PEP 302

Changed in version 3. 3. configure9 disimpan alih-alih saat tidak ditemukan pencari.

sys. platform

This string contains a platform identifier that can be used to append platform-specific components to , for instance

For Unix systems, except on Linux and AIX, this is the lowercased OS name as returned by

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
91 with the first part of the version as returned by
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
92 appended, e. g.
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
93 or
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
94, at the time when Python was built. Unless you want to test for a specific system version, it is therefore recommended to use the following idiom

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...

For other systems, the values are

System

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
00 value

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

WASI

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_99

Windows

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

macOS

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

Berubah di versi 3. 3. Di Linux, tidak lagi berisi versi utama. Itu selalu

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_98, bukan
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 atau
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. Karena versi Python yang lebih lama menyertakan nomor versi, disarankan untuk selalu menggunakan idiom
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 yang disajikan di atas.

Berubah di versi 3. 8. Di AIX, tidak lagi berisi versi utama. Itu selalu

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
_96, bukan
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 atau
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. Karena versi Python yang lebih lama menyertakan nomor versi, disarankan untuk selalu menggunakan idiom
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 yang disajikan di atas.

See also

memiliki granularitas yang lebih kasar. memberikan informasi versi yang bergantung pada sistem

Modul ini memberikan pemeriksaan terperinci untuk identitas sistem

sys. platlibdir

Nama direktori perpustakaan khusus platform. Ini digunakan untuk membangun jalur pustaka standar dan jalur modul ekstensi yang diinstal

Itu sama dengan

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 di sebagian besar platform. Di Fedora dan SuSE, ini sama dengan
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 pada platform 64-bit yang memberikan jalur
if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
73 berikut (di mana
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...
19 adalah versi Python
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...
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. Pustaka standar (seperti
    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 modul)

  • 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. Modul ekstensi C dari perpustakaan standar (seperti modul, nama file yang tepat adalah khusus platform)

  • 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 (selalu gunakan ________12______27, bukan ). Modul pihak ketiga

  • 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...
    
    _29. Modul ekstensi C dari paket pihak ketiga

Baru di versi 3. 9

sys. prefix

Sebuah string yang memberikan awalan direktori khusus situs tempat file Python independen platform diinstal; . Ini dapat diatur pada waktu pembuatan dengan argumen

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 ke skrip configure. Lihat untuk jalur turunan

Note

Jika a berlaku, nilai ini akan diubah di

if sys.hexversion >= 0x010502F0:
    # use some advanced feature
    ...
else:
    # use an alternative implementation or warn the user
    ...
3 untuk menunjuk ke lingkungan virtual. Nilai untuk instalasi Python akan tetap tersedia, via

sys. ps1sys. ps2

String yang menentukan perintah utama dan sekunder dari juru bahasa. Ini hanya ditentukan jika juru bahasa dalam mode interaktif. Their initial values in this case are

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 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...
35. Jika objek non-string ditugaskan ke salah satu variabel, itu dievaluasi ulang setiap kali juru bahasa bersiap untuk membaca perintah interaktif baru;

sys. setdlopenflags(n)

Tetapkan tanda yang digunakan oleh juru bahasa untuk panggilan

>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
55, seperti saat juru bahasa memuat modul ekstensi. Antara lain, ini akan mengaktifkan penyelesaian simbol yang malas saat mengimpor modul, jika disebut sebagai
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. Untuk berbagi simbol di seluruh modul ekstensi, panggil sebagai
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. Nama simbolik untuk nilai bendera dapat ditemukan di modul (
>>> s = '9876543211234567'    # 16 significant digits is too many!
>>> format(float(s), '.16g')  # conversion changes value
'9876543211234568'
57 konstanta, e. g. )

Unix

sys. set_int_max_str_digits(maxdigits)

Setel yang digunakan oleh juru bahasa ini. Lihat juga

Baru di versi 3. 11

sys. setprofile(profilefunc)

Setel fungsi profil sistem, yang memungkinkan Anda mengimplementasikan profiler kode sumber Python dengan Python. Lihat bab untuk informasi lebih lanjut tentang profiler Python. Fungsi profil sistem dipanggil mirip dengan fungsi pelacakan sistem (lihat ), tetapi dipanggil dengan peristiwa yang berbeda, misalnya tidak dipanggil untuk setiap baris kode yang dieksekusi (hanya pada panggilan dan pengembalian, tetapi peristiwa pengembalian dilaporkan . Fungsi ini spesifik untuk utas, tetapi tidak ada cara bagi pembuat profil untuk mengetahui tentang peralihan konteks di antara utas, jadi tidak masuk akal untuk menggunakan ini di hadapan banyak utas. Selain itu, nilai pengembaliannya tidak digunakan, jadi cukup mengembalikan configure9. Kesalahan dalam fungsi profil akan menyebabkan dirinya tidak disetel

Fungsi profil harus memiliki tiga argumen. bingkai, acara, dan arg. frame adalah frame tumpukan saat ini. acara adalah 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...
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, atau
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 tergantung pada jenis acara

Memunculkan

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 tanpa argumen

Peristiwa tersebut memiliki arti sebagai berikut

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

Suatu fungsi dipanggil (atau beberapa blok kode lain dimasukkan). Fungsi profil disebut;

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

Sebuah fungsi (atau blok kode lainnya) akan kembali. Fungsi profil disebut;

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

Fungsi C akan segera dipanggil. Ini mungkin merupakan fungsi ekstensi atau built-in. arg adalah objek fungsi 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

Fungsi AC telah kembali. arg adalah objek fungsi 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

Fungsi C telah memunculkan pengecualian. arg adalah objek fungsi C

sys. setrecursionlimit(limit)

Setel kedalaman maksimum tumpukan juru bahasa Python ke batas. Batasan ini mencegah rekursi tak terbatas yang menyebabkan meluapnya tumpukan C dan menabrak Python

Batas tertinggi yang mungkin bergantung pada platform. Pengguna mungkin perlu menyetel batas lebih tinggi saat mereka memiliki program yang memerlukan rekursi mendalam dan platform yang mendukung batas lebih tinggi. Ini harus dilakukan dengan hati-hati, karena batas yang terlalu tinggi dapat menyebabkan crash

Jika batas baru terlalu rendah pada kedalaman rekursi saat ini, pengecualian akan dimunculkan

Berubah di versi 3. 5. 1. Pengecualian sekarang dimunculkan jika batas baru terlalu rendah pada kedalaman rekursi saat ini.

sys. setswitchinterval(interval)

Tetapkan interval peralihan utas juru bahasa (dalam detik). Nilai floating-point ini menentukan durasi ideal dari "timeslices" yang dialokasikan untuk menjalankan thread Python secara bersamaan. Harap perhatikan bahwa nilai sebenarnya bisa lebih tinggi, terutama jika fungsi atau metode internal yang berjalan lama digunakan. Juga, utas mana yang dijadwalkan pada akhir interval adalah keputusan sistem operasi. Penerjemah tidak memiliki penjadwal sendiri

New in version 3. 2

sys. settrace(tracefunc)

Setel fungsi pelacakan sistem, yang memungkinkan Anda menerapkan debugger kode sumber Python di Python. Fungsinya khusus untuk utas;

Fungsi pelacakan harus memiliki tiga argumen. bingkai, acara, dan arg. frame adalah frame tumpukan saat ini. acara adalah 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 atau
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 tergantung pada jenis acara

Fungsi pelacakan dipanggil (dengan peristiwa diatur ke

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) setiap kali cakupan lokal baru dimasukkan;

Fungsi pelacakan lokal harus mengembalikan referensi ke dirinya sendiri (atau ke fungsi lain untuk pelacakan lebih lanjut dalam cakupan tersebut), atau configure9 untuk menonaktifkan pelacakan dalam cakupan tersebut

Jika ada kesalahan yang terjadi dalam fungsi pelacakan, itu akan dibatalkan, seperti

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 dipanggil

Peristiwa tersebut memiliki arti sebagai berikut

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

Suatu fungsi dipanggil (atau beberapa blok kode lain dimasukkan). Fungsi pelacakan global disebut;

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

Penerjemah akan mengeksekusi baris kode baru atau mengeksekusi ulang kondisi loop. Fungsi jejak lokal disebut; . Lihat

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 untuk penjelasan rinci tentang cara kerjanya. Peristiwa per baris dapat dinonaktifkan untuk suatu bingkai dengan menyetel
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 ke bingkai itu

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

Sebuah fungsi (atau blok kode lainnya) akan kembali. Fungsi jejak lokal disebut; . Nilai pengembalian fungsi pelacakan diabaikan

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

Pengecualian telah terjadi. Fungsi jejak lokal disebut;

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

Penerjemah akan mengeksekusi opcode baru (lihat detail opcode). Fungsi jejak lokal disebut; . Acara per-opcode tidak dipancarkan secara default. mereka harus diminta secara eksplisit dengan menyetel ________12______86 ke pada bingkai

Perhatikan bahwa saat pengecualian disebarkan ke rantai pemanggil, peristiwa

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 dihasilkan di setiap level

Untuk penggunaan yang lebih mendetail, menyetel fungsi pelacakan dengan menetapkan

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 secara eksplisit dapat dilakukan, daripada mengandalkan penyetelan secara tidak langsung melalui nilai pengembalian dari fungsi pelacakan yang sudah diinstal. Ini juga diperlukan untuk mengaktifkan fungsi jejak pada bingkai saat ini, yang tidak berfungsi. Perhatikan bahwa agar ini berfungsi, fungsi pelacakan global harus diinstal untuk mengaktifkan mesin pelacakan waktu proses, tetapi fungsi pelacakan tidak harus sama (mis. g. itu bisa menjadi fungsi pelacakan overhead rendah yang hanya mengembalikan configure9 untuk menonaktifkan dirinya sendiri segera di setiap frame)

Untuk informasi lebih lanjut tentang objek kode dan bingkai, lihat

Memunculkan

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 tanpa argumen

CPython implementation detail. The function is intended only for implementing debuggers, profilers, coverage tools and the like. Its behavior is part of the implementation platform, rather than part of the language definition, and thus may not be available in all Python implementations

Berubah di versi 3. 7. ________12______67 jenis acara ditambahkan;

sys. set_asyncgen_hooks(firstiter , finalizer)

Menerima dua argumen kata kunci opsional yang dapat dipanggil yang menerima sebagai argumen. Firstiter callable akan dipanggil saat generator asinkron diiterasi untuk pertama kali. Finalizer akan dipanggil saat generator asinkron akan dikumpulkan sampahnya

Memunculkan

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 tanpa argumen

Memunculkan

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 tanpa argumen

Dua kejadian audit dimunculkan karena API yang mendasarinya terdiri dari dua panggilan, yang masing-masing harus memunculkan kejadiannya sendiri

Baru di versi 3. 6. Lihat PEP 525 untuk detail lebih lanjut, dan untuk contoh referensi metode finalizer lihat implementasi

$ ./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 di Lib/asyncio/base_events. pi

Note

This function has been added on a provisional basis (see PEP 411 for details. )

sys. set_coroutine_origin_tracking_depth(depth)

Allows enabling or disabling coroutine origin tracking. Saat diaktifkan, atribut

$ ./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 pada objek coroutine akan berisi tuple (nama file, nomor baris, nama fungsi) tupel yang menjelaskan traceback tempat objek coroutine dibuat, dengan panggilan terbaru terlebih dahulu. Saat dinonaktifkan,
$ ./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 akan menjadi Tidak ada

Untuk mengaktifkan, berikan nilai kedalaman yang lebih besar dari nol; . Untuk menonaktifkan, berikan kedalaman setel ke nol

Pengaturan ini khusus untuk utas

Baru di versi 3. 7

Note

This function has been added on a provisional basis (see PEP 411 for details. ) Use it only for debugging purposes

sys. _enablelegacywindowsfsencoding()

Mengubah masing-masing menjadi 'mbcs' dan 'replace', untuk konsistensi dengan versi Python sebelum 3. 6

Ini sama dengan mendefinisikan variabel lingkungan sebelum meluncurkan Python

Lihat juga dan

Windows

Baru di versi 3. 6. Lihat PEP 529 untuk detail lebih lanjut.

sys. stdinsys. stdoutsys. stderr

digunakan oleh juru bahasa untuk input, output, dan kesalahan standar

  • $ ./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 digunakan untuk semua input interaktif (termasuk panggilan ke );

  • $ ./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 digunakan untuk keluaran dari dan pernyataan dan untuk prompt dari ;

  • Permintaan juru bahasa itu sendiri dan pesan kesalahannya masuk ke

    >>> 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

Aliran ini teratur seperti yang dikembalikan oleh fungsi. Parameter mereka dipilih sebagai berikut

  • Pengodean dan penanganan kesalahan diinisialisasi dari dan

    Di Windows, UTF-8 digunakan untuk perangkat konsol. Perangkat non-karakter seperti file disk dan pipa menggunakan pengkodean lokal sistem (mis. e. halaman kode ANSI). Perangkat karakter non-konsol seperti NUL (i. e. di mana

    $ ./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 mengembalikan sys.audit()4) gunakan nilai halaman kode input dan output konsol saat startup, masing-masing untuk stdin dan stdout/stderr. Ini default ke sistem jika proses awalnya tidak terpasang ke konsol

    Perilaku khusus konsol dapat diganti dengan menyetel variabel lingkungan PYTHONLEGACYWINDOWSSTDIO sebelum memulai Python. Dalam hal ini, halaman kode konsol digunakan untuk perangkat karakter lainnya

    Di bawah semua platform, Anda dapat mengganti pengkodean karakter dengan menyetel variabel lingkungan sebelum memulai Python atau dengan menggunakan opsi baris perintah

    >>> s = '9876543211234567'    # 16 significant digits is too many!
    >>> format(float(s), '.16g')  # conversion changes value
    '9876543211234568'
    
    _16 baru dan variabel lingkungan. Namun, untuk konsol Windows, ini hanya berlaku bila juga disetel

  • Saat interaktif, aliran

    $ ./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 di-buffer baris. Kalau tidak, itu adalah blok-buffer seperti file teks biasa. Aliran
    >>> 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 adalah buffer garis dalam kedua kasus. Anda dapat membuat kedua aliran tanpa buffer dengan meneruskan opsi baris perintah atau menyetel variabel lingkungan

Berubah di versi 3. 9. Non-interaktif

>>> 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 sekarang di-buffer baris, bukan di-buffer sepenuhnya.

Note

Untuk menulis atau membaca data biner dari/ke aliran standar, gunakan objek biner yang mendasarinya. Misalnya, untuk menulis byte ke , gunakan

$ ./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

Namun, jika Anda menulis perpustakaan (dan tidak mengontrol dalam konteks mana kodenya akan dieksekusi), ketahuilah bahwa aliran standar dapat diganti dengan objek seperti file yang tidak mendukung atribut

$ ./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

sys. __stdin__sys. __stdout__sys. __stderr__

Objek ini berisi nilai asli

$ ./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 dan
$ ./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 di awal program. Mereka digunakan selama finalisasi, dan dapat berguna untuk mencetak ke aliran standar aktual tidak peduli jika objek
$ ./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 telah dialihkan

Itu juga dapat digunakan untuk memulihkan file aktual ke objek file yang berfungsi diketahui jika telah ditimpa dengan objek yang rusak. Namun, cara yang lebih disukai untuk melakukannya adalah dengan menyimpan aliran sebelumnya secara eksplisit sebelum menggantinya, dan memulihkan objek yang disimpan

Note

Dalam beberapa kondisi

$ ./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 dan
>>> 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 serta nilai asli
$ ./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 dan
$ ./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 dapat menjadi configure9. Biasanya aplikasi Windows GUI yang tidak terhubung ke konsol dan aplikasi Python dimulai dengan pythonw

sys. stdlib_module_names

Kumpulan string beku yang berisi nama-nama modul perpustakaan standar

Itu sama di semua platform. Modul yang tidak tersedia pada beberapa platform dan modul yang dinonaktifkan pada pembangunan Python juga dicantumkan. Semua jenis modul terdaftar. pure Python, built-in, frozen and extension modules. Modul uji dikecualikan

Untuk paket, hanya paket utama yang dicantumkan. sub-paket dan sub-modul tidak terdaftar. Misalnya, paket

$ ./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 terdaftar, tetapi sub-paket ________15______44 dan sub-modul
$ ./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 tidak terdaftar

See also the list

Baru di versi 3. 10

sys. thread_info

Informasi holding tentang implementasi thread

Atribut

Penjelasan

$ ./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

Nama implementasi utas

  • $ ./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. Utas jendela

  • $ ./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. utas POSIX

  • $ ./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. rintisan utas POSIX (pada platform WebAssembly tanpa dukungan threading)

  • $ ./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. Benang Solaris

$ ./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

Nama implementasi kunci

  • $ ./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. kunci menggunakan 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. kunci menggunakan mutex dan variabel kondisi

  • configure_9 jika informasi ini tidak diketahui

Nama dan versi pustaka utas. Ini adalah string, atau configure9 jika informasi ini tidak diketahui

Baru di versi 3. 3

sys. tracebacklimit

Ketika variabel ini diatur ke nilai integer, itu menentukan jumlah maksimum tingkat informasi traceback yang dicetak ketika terjadi pengecualian yang tidak tertangani. Standarnya adalah

$ ./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. Bila diatur ke
$ ./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 atau kurang, semua informasi traceback ditekan dan hanya jenis dan nilai pengecualian yang dicetak

sys. unraisablehook(unraisable , /)

Tangani pengecualian yang tidak dapat dimunculkan

Dipanggil saat pengecualian terjadi tetapi tidak ada cara bagi Python untuk menanganinya. Misalnya, saat destruktor memunculkan pengecualian atau selama pengumpulan sampah ()

Argumen unraisable memiliki atribut berikut

  • exc_type. Jenis pengecualian

  • exc_value. Nilai pengecualian, bisa configure_9

  • exc_traceback. Pengecualian traceback, bisa configure9

  • err_msg. Pesan kesalahan, bisa configure_9

  • obyek. Objek yang menyebabkan pengecualian, dapat berupa configure9

Kait default memformat err_msg dan objek sebagai.

$ ./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;

dapat diganti untuk mengontrol bagaimana penanganan pengecualian yang tidak dapat dilakukan

Menyimpan exc_value menggunakan pengait khusus dapat membuat siklus referensi. Itu harus dibersihkan secara eksplisit untuk memutus siklus referensi ketika pengecualian tidak lagi diperlukan

Menyimpan objek menggunakan pengait khusus dapat menghidupkannya kembali jika disetel ke objek yang sedang diselesaikan. Hindari menyimpan objek setelah pengait khusus selesai untuk menghindari kebangkitan objek

Lihat juga yang menangani pengecualian yang tidak tertangkap

Mengangkat acara audit

$ ./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 dengan argumen
>>> 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 ketika pengecualian yang tidak dapat ditangani terjadi. Objek
$ ./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 sama dengan apa yang akan diteruskan ke hook. Jika tidak ada pengait yang dipasang,
>>> 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 mungkin configure9

New in version 3. 8

sys. version

Sebuah string yang berisi nomor versi juru bahasa Python ditambah informasi tambahan tentang nomor build dan kompiler yang digunakan. String ini ditampilkan saat interpreter interaktif dimulai. Jangan mengekstrak informasi versi darinya, melainkan gunakan dan fungsi yang disediakan oleh modul

sys. api_version

Versi C API untuk juru bahasa ini. Pemrogram mungkin menganggap ini berguna saat men-debug konflik versi antara Python dan modul ekstensi

sys. version_info

Tuple yang berisi lima komponen nomor versi. mayor, minor, mikro, level rilis, dan serial. Semua nilai kecuali tingkat rilis adalah bilangan bulat; . Nilai

$ ./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 sesuai dengan Python versi 2. 0 adalah
$ ./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. Komponen juga dapat diakses dengan nama, jadi
$ ./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 setara dengan
$ ./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 dan seterusnya

Berubah di versi 3. 1. Menambahkan atribut komponen bernama.

sys. warnoptions

Ini adalah detail implementasi kerangka peringatan; . Lihat modul untuk informasi lebih lanjut tentang kerangka peringatan

sys. winver

Nomor versi yang digunakan untuk membentuk kunci registri pada platform Windows. Ini disimpan sebagai sumber daya string 1000 di Python DLL. Nilainya biasanya adalah versi mayor dan minor dari interpreter Python yang sedang berjalan. Ini disediakan dalam modul untuk tujuan informasi;

Windows

sys. _xoptions

Kamus dari berbagai flag khusus implementasi melewati opsi baris perintah. Nama opsi dipetakan ke nilainya, jika diberikan secara eksplisit, atau ke. Contoh

$ ./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}

Detail implementasi CPython. Ini adalah cara khusus CPython untuk mengakses opsi yang dilewati. Implementasi lain dapat mengekspornya melalui cara lain, atau tidak sama sekali

New in version 3. 2

Kutipan

ISO/IEC 9899. 1999. “Bahasa Pemrograman – C. Draf publik dari standar ini tersedia di https. // www. buka-std. org/jtc1/sc22/wg14/www/docs/n1256. pdf

Bagaimana Anda memanggil fungsi dari modul dengan Python?

Anda perlu menggunakan kata kunci impor bersama dengan nama modul yang diinginkan. Saat juru bahasa menemukan pernyataan impor, ia mengimpor modul ke program Anda saat ini. Anda dapat menggunakan fungsi di dalam modul dengan menggunakan titik(. ) operator beserta nama modul .

Bagaimana Anda memanggil fungsi dari modul?

Anda dapat memanggil modul fungsi dari program ABAP apa pun dengan menggunakan pernyataan ABAP berikut
CALL FUNCTION .
[IMPOR f1 = a1. fn = sebuah]
[MENGGANTI f1 = a1. fn = sebuah]
[TABEL t1 = itab1. tn = itabn]
[PENGECUALIAN e1 = r1. id = rn]
[ERROR_MESSAGE = rE]
[LAINNYA = ro]]

Bisakah Anda memanggil fungsi dalam fungsi yang sama Python?

Jika Anda terbiasa dengan fungsi di Python, maka Anda tahu bahwa sangat umum bagi satu fungsi untuk memanggil fungsi lainnya . Di Python, fungsi juga bisa memanggil dirinya sendiri. Sebuah fungsi yang memanggil dirinya sendiri disebut rekursif, dan teknik menggunakan fungsi rekursif disebut rekursif.

How do you call a function in the same class in Python?

Metode instance adalah fungsi yang dibangun ke dalam definisi kelas dari suatu objek dan memerlukan instance dari kelas tersebut untuk dipanggil. Untuk memanggil metode, Anda perlu memenuhi fungsi dengan self . . Misalnya, di kelas yang berisi fungsi first() dan second(), first() dapat memanggil second().