posix — The most common POSIX system calls¶
Цей модуль забезпечує доступ до функціональних можливостей операційної системи, стандартизованих стандартом C і стандартом POSIX (тонко замаскований інтерфейс Unix).
Availability: Unix.
Do not import this module directly. Instead, import the module os,
which provides a portable version of this interface. On Unix, the os
module provides a superset of the posix interface. On non-Unix operating
systems the posix module is not available, but a subset is always
available through the os interface. Once os is imported, there is
no performance penalty in using it instead of posix. In addition,
os provides some additional functionality, such as automatically calling
putenv() when an entry in os.environ is changed.
Помилки повідомляються як винятки; звичайні винятки надаються для помилок типу, тоді як помилки, про які повідомляють системні виклики, викликають OSError.
Підтримка великих файлів¶
Several operating systems (including AIX and Solaris) provide support for files that are larger than 2 GiB from a C programming model where int and long are 32-bit values. This is typically accomplished by defining the relevant size and offset types as 64-bit values. Such files are sometimes referred to as large files.
Large file support is enabled in Python when the size of an off_t is
larger than a long and the long long is at least as large
as an off_t.
It may be necessary to configure and compile Python with certain compiler flags
to enable this mode. For example, with Solaris 2.6 and 2.7 you need to do
something like:
CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
./configure
У системах Linux із підтримкою великих файлів це може працювати:
CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
./configure
Важливий зміст модуля¶
In addition to many functions described in the os module documentation,
posix defines the following data item:
- posix.environ¶
Словник, що представляє середовище рядків на момент запуску інтерпретатора. Ключі та значення є байтами в Unix і str у Windows. Наприклад,
environ[b'HOME'](environ['HOME']у Windows) — це шлях до вашого домашнього каталогу, еквівалентнийgetenv("HOME")у C .Зміна цього словника не впливає на середовище рядків, яке передається
execv(),popen()абоsystem(); якщо вам потрібно змінити середовище, передайтеenvironдоexecve()або додайте призначення змінних і оператори експорту до командного рядка дляsystem()абоpopen().Змінено в версії 3.2: В Unix ключі та значення є байтами.
Примітка
The
osmodule provides an alternate implementation ofenvironwhich updates the environment on modification. Note also that updatingos.environwill render this dictionary obsolete. Use of theosmodule version of this is recommended over direct access to theposixmodule.