> **Источник:** https://python-all.ru/3.1/library/allos.html
>
> «Документация Python на русском» – неофициальный перевод официальной документации Python: версии от 2.6 до 3.16, полнотекстовый поиск, английский оригинал рядом с переводом. Эта Markdown-версия страницы предназначена для работы с LLM: вставьте её в ChatGPT, Claude или Cursor.

---

# 15. Общие службы операционной системы

Модули, описанные в этой главе, предоставляют интерфейсы к возможностям операционной системы, доступным (почти) во всех ОС, таким как файлы и часы. Интерфейсы в основном смоделированы по образцу Unix- или C-интерфейсов, но они также доступны и в большинстве других систем. Вот обзор:

- [15.1. `os` – Разные интерфейсы операционной системы](https://python-all.ru/3.1/library/os.html)

  - [15.1.1. Имена файлов, аргументы командной строки и переменные окружения](https://python-all.ru/3.1/library/os.html#file-names-command-line-arguments-and-environment-variables)
  - [15.1.2. Параметры процесса](https://python-all.ru/3.1/library/os.html#process-parameters)
  - [15.1.3. Создание файловых объектов](https://python-all.ru/3.1/library/os.html#file-object-creation)
  - [15.1.4. Операции с файловыми дескрипторами](https://python-all.ru/3.1/library/os.html#file-descriptor-operations)

    - [15.1.4.1. Константы флагов `open()`](https://python-all.ru/3.1/library/os.html#open-flag-constants)
  - [15.1.5. Файлы и каталоги](https://python-all.ru/3.1/library/os.html#files-and-directories)
  - [15.1.6. Управление процессами](https://python-all.ru/3.1/library/os.html#process-management)
  - [15.1.7. Разная системная информация](https://python-all.ru/3.1/library/os.html#miscellaneous-system-information)
  - [15.1.8. Разные функции](https://python-all.ru/3.1/library/os.html#miscellaneous-functions)
- [15.2. `io` – Основные средства для работы с потоками](https://python-all.ru/3.1/library/io.html)

  - [15.2.1. Обзор](https://python-all.ru/3.1/library/io.html#overview)

    - [15.2.1.1. Текстовый ввод-вывод](https://python-all.ru/3.1/library/io.html#text-i-o)
    - [15.2.1.2. Двоичный ввод-вывод](https://python-all.ru/3.1/library/io.html#binary-i-o)
    - [15.2.1.3. Сырой I/O](https://python-all.ru/3.1/library/io.html#raw-i-o)
  - [15.2.2. Интерфейс модуля высокого уровня](https://python-all.ru/3.1/library/io.html#high-level-module-interface)

    - [15.2.2.1. Потоки в памяти](https://python-all.ru/3.1/library/io.html#in-memory-streams)
  - [15.2.3. Иерархия классов](https://python-all.ru/3.1/library/io.html#class-hierarchy)

    - [15.2.3.1. Базовые классы ввода-вывода](https://python-all.ru/3.1/library/io.html#i-o-base-classes)
    - [15.2.3.2. Сырой файловый I/O](https://python-all.ru/3.1/library/io.html#raw-file-i-o)
    - [15.2.3.3. Буферизованные потоки](https://python-all.ru/3.1/library/io.html#buffered-streams)
    - [15.2.3.4. Текстовый ввод-вывод](https://python-all.ru/3.1/library/io.html#id1)
  - [15.2.4. Продвинутые темы](https://python-all.ru/3.1/library/io.html#advanced-topics)

    - [15.2.4.1. Производительность](https://python-all.ru/3.1/library/io.html#performance)

      - [15.2.4.1.1. Двоичный ввод-вывод](https://python-all.ru/3.1/library/io.html#id2)
      - [15.2.4.1.2. Текстовый ввод-вывод](https://python-all.ru/3.1/library/io.html#id3)
    - [15.2.4.2. Многопоточность](https://python-all.ru/3.1/library/io.html#multi-threading)
    - [15.2.4.3. Реентерабельность](https://python-all.ru/3.1/library/io.html#reentrancy)
- [15.3. `time` – Доступ ко времени и преобразования](https://python-all.ru/3.1/library/time.html)
- [15.4. `optparse` – более мощный анализатор параметров командной строки](https://python-all.ru/3.1/library/optparse.html)

  - [15.4.1. Предыстория](https://python-all.ru/3.1/library/optparse.html#background)

    - [15.4.1.1. Терминология](https://python-all.ru/3.1/library/optparse.html#terminology)
    - [15.4.1.2. Для чего нужны параметры?](https://python-all.ru/3.1/library/optparse.html#what-are-options-for)
    - [15.4.1.3. Для чего нужны позиционные аргументы?](https://python-all.ru/3.1/library/optparse.html#what-are-positional-arguments-for)
  - [15.4.2. Учебное пособие](https://python-all.ru/3.1/library/optparse.html#tutorial)

    - [15.4.2.1. Понимание действий параметров](https://python-all.ru/3.1/library/optparse.html#understanding-option-actions)
    - [15.4.2.2. Действие store](https://python-all.ru/3.1/library/optparse.html#the-store-action)
    - [15.4.2.3. Обработка булевых (флаговых) параметров](https://python-all.ru/3.1/library/optparse.html#handling-boolean-flag-options)
    - [15.4.2.4. Другие действия](https://python-all.ru/3.1/library/optparse.html#other-actions)
    - [15.4.2.5. Значения по умолчанию](https://python-all.ru/3.1/library/optparse.html#default-values)
    - [15.4.2.6. Генерация справки](https://python-all.ru/3.1/library/optparse.html#generating-help)

      - [15.4.2.6.1. Группировка параметров](https://python-all.ru/3.1/library/optparse.html#grouping-options)
    - [15.4.2.7. Вывод строки версии](https://python-all.ru/3.1/library/optparse.html#printing-a-version-string)
    - [15.4.2.8. Как `optparse` обрабатывает ошибки](https://python-all.ru/3.1/library/optparse.html#how-optparse-handles-errors)
    - [15.4.2.9. Собираем всё вместе](https://python-all.ru/3.1/library/optparse.html#putting-it-all-together)
  - [15.4.3. Справочное руководство](https://python-all.ru/3.1/library/optparse.html#reference-guide)

    - [15.4.3.1. Создание анализатора](https://python-all.ru/3.1/library/optparse.html#creating-the-parser)
    - [15.4.3.2. Наполнение анализатора](https://python-all.ru/3.1/library/optparse.html#populating-the-parser)
    - [15.4.3.3. Определение параметров](https://python-all.ru/3.1/library/optparse.html#defining-options)
    - [15.4.3.4. Атрибуты параметров](https://python-all.ru/3.1/library/optparse.html#option-attributes)
    - [15.4.3.5. Стандартные действия параметров](https://python-all.ru/3.1/library/optparse.html#standard-option-actions)
    - [15.4.3.6. Стандартные типы параметров](https://python-all.ru/3.1/library/optparse.html#standard-option-types)
    - [15.4.3.7. Разбор аргументов](https://python-all.ru/3.1/library/optparse.html#parsing-arguments)
    - [15.4.3.8. Запросы и управление анализатором параметров](https://python-all.ru/3.1/library/optparse.html#querying-and-manipulating-your-option-parser)
    - [15.4.3.9. Конфликты между параметрами](https://python-all.ru/3.1/library/optparse.html#conflicts-between-options)
    - [15.4.3.10. Очистка](https://python-all.ru/3.1/library/optparse.html#cleanup)
    - [15.4.3.11. Другие методы](https://python-all.ru/3.1/library/optparse.html#other-methods)
  - [15.4.4. Колбэки опций](https://python-all.ru/3.1/library/optparse.html#option-callbacks)

    - [15.4.4.1. Определение опции с колбэком](https://python-all.ru/3.1/library/optparse.html#defining-a-callback-option)
    - [15.4.4.2. Как вызываются колбэки](https://python-all.ru/3.1/library/optparse.html#how-callbacks-are-called)
    - [15.4.4.3. Возбуждение ошибок в колбэке](https://python-all.ru/3.1/library/optparse.html#raising-errors-in-a-callback)
    - [15.4.4.4. Пример колбэка 1: простой колбэк](https://python-all.ru/3.1/library/optparse.html#callback-example-1-trivial-callback)
    - [15.4.4.5. Пример колбэка 2: проверка порядка опций](https://python-all.ru/3.1/library/optparse.html#callback-example-2-check-option-order)
    - [15.4.4.6. Пример колбэка 3: проверка порядка опций (обобщённая)](https://python-all.ru/3.1/library/optparse.html#callback-example-3-check-option-order-generalized)
    - [15.4.4.7. Пример колбэка 4: проверка произвольного условия](https://python-all.ru/3.1/library/optparse.html#callback-example-4-check-arbitrary-condition)
    - [15.4.4.8. Пример колбэка 5: фиксированные аргументы](https://python-all.ru/3.1/library/optparse.html#callback-example-5-fixed-arguments)
    - [15.4.4.9. Пример колбэка 6: переменное число аргументов](https://python-all.ru/3.1/library/optparse.html#callback-example-6-variable-arguments)
  - [15.4.5. Расширение `optparse`](https://python-all.ru/3.1/library/optparse.html#extending-optparse)

    - [15.4.5.1. Добавление новых типов](https://python-all.ru/3.1/library/optparse.html#adding-new-types)
    - [15.4.5.2. Добавление новых действий](https://python-all.ru/3.1/library/optparse.html#adding-new-actions)
- [15.5. `getopt` – Парсер параметров командной строки](https://python-all.ru/3.1/library/getopt.html)
- [15.6. `logging` – Средство журналирования для Python](https://python-all.ru/3.1/library/logging.html)

  - [15.6.1. Учебное пособие по logging](https://python-all.ru/3.1/library/logging.html#logging-tutorial)

    - [15.6.1.1. Простые примеры](https://python-all.ru/3.1/library/logging.html#simple-examples)
    - [15.6.1.2. Логгеры](https://python-all.ru/3.1/library/logging.html#loggers)
    - [15.6.1.3. Обработчики](https://python-all.ru/3.1/library/logging.html#handlers)
    - [15.6.1.4. Форматировщики](https://python-all.ru/3.1/library/logging.html#formatters)
    - [15.6.1.5. Настройка журналирования](https://python-all.ru/3.1/library/logging.html#configuring-logging)
    - [15.6.1.6. Настройка журналирования для библиотеки](https://python-all.ru/3.1/library/logging.html#configuring-logging-for-a-library)
  - [15.6.2. Уровни журналирования](https://python-all.ru/3.1/library/logging.html#logging-levels)
  - [15.6.3. Полезные обработчики](https://python-all.ru/3.1/library/logging.html#module-logging.handlers)
  - [15.6.4. Функции уровня модуля](https://python-all.ru/3.1/library/logging.html#module-level-functions)
  - [15.6.5. Объекты логгера](https://python-all.ru/3.1/library/logging.html#logger-objects)
  - [15.6.6. Базовый пример](https://python-all.ru/3.1/library/logging.html#basic-example)
  - [15.6.7. Журналирование в несколько мест назначения](https://python-all.ru/3.1/library/logging.html#logging-to-multiple-destinations)
  - [15.6.8. Исключения, возникающие при журналировании](https://python-all.ru/3.1/library/logging.html#exceptions-raised-during-logging)
  - [15.6.9. Добавление контекстной информации в вывод журнала](https://python-all.ru/3.1/library/logging.html#adding-contextual-information-to-your-logging-output)

    - [15.6.9.1. Использование LoggerAdapter для передачи контекстной информации](https://python-all.ru/3.1/library/logging.html#using-loggeradapters-to-impart-contextual-information)
    - [15.6.9.2. Использование фильтров для передачи контекстной информации](https://python-all.ru/3.1/library/logging.html#using-filters-to-impart-contextual-information)
  - [15.6.10. Логирование в один файл из нескольких процессов](https://python-all.ru/3.1/library/logging.html#logging-to-a-single-file-from-multiple-processes)
  - [15.6.11. Отправка и получение событий логирования по сети](https://python-all.ru/3.1/library/logging.html#sending-and-receiving-logging-events-across-a-network)
  - [15.6.12. Использование произвольных объектов в качестве сообщений](https://python-all.ru/3.1/library/logging.html#using-arbitrary-objects-as-messages)
  - [15.6.13. Оптимизация](https://python-all.ru/3.1/library/logging.html#optimization)
  - [15.6.14. Объекты-обработчики](https://python-all.ru/3.1/library/logging.html#handler-objects)

    - [15.6.14.1. StreamHandler](https://python-all.ru/3.1/library/logging.html#streamhandler)
    - [15.6.14.2. FileHandler](https://python-all.ru/3.1/library/logging.html#filehandler)
    - [15.6.14.3. NullHandler](https://python-all.ru/3.1/library/logging.html#nullhandler)
    - [15.6.14.4. WatchedFileHandler](https://python-all.ru/3.1/library/logging.html#watchedfilehandler)
    - [15.6.14.5. RotatingFileHandler](https://python-all.ru/3.1/library/logging.html#rotatingfilehandler)
    - [15.6.14.6. TimedRotatingFileHandler](https://python-all.ru/3.1/library/logging.html#timedrotatingfilehandler)
    - [15.6.14.7. SocketHandler](https://python-all.ru/3.1/library/logging.html#sockethandler)
    - [15.6.14.8. DatagramHandler](https://python-all.ru/3.1/library/logging.html#datagramhandler)
    - [15.6.14.9. SysLogHandler](https://python-all.ru/3.1/library/logging.html#sysloghandler)
    - [15.6.14.10. NTEventLogHandler](https://python-all.ru/3.1/library/logging.html#nteventloghandler)
    - [15.6.14.11. SMTPHandler](https://python-all.ru/3.1/library/logging.html#smtphandler)
    - [15.6.14.12. MemoryHandler](https://python-all.ru/3.1/library/logging.html#memoryhandler)
    - [15.6.14.13. HTTPHandler](https://python-all.ru/3.1/library/logging.html#httphandler)
  - [15.6.15. Объекты-форматеры](https://python-all.ru/3.1/library/logging.html#formatter-objects)
  - [15.6.16. Объекты-фильтры](https://python-all.ru/3.1/library/logging.html#filter-objects)
  - [15.6.17. Объекты LogRecord](https://python-all.ru/3.1/library/logging.html#logrecord-objects)
  - [15.6.18. Объекты LoggerAdapter](https://python-all.ru/3.1/library/logging.html#loggeradapter-objects)
  - [15.6.19. Потокобезопасность](https://python-all.ru/3.1/library/logging.html#thread-safety)
  - [15.6.20. Конфигурация](https://python-all.ru/3.1/library/logging.html#configuration)

    - [15.6.20.1. Функции конфигурации](https://python-all.ru/3.1/library/logging.html#configuration-functions)
    - [15.6.20.2. Формат конфигурационного файла](https://python-all.ru/3.1/library/logging.html#configuration-file-format)
    - [15.6.20.3. Пример сервера конфигурации](https://python-all.ru/3.1/library/logging.html#configuration-server-example)
  - [15.6.21. Дополнительные примеры](https://python-all.ru/3.1/library/logging.html#more-examples)

    - [15.6.21.1. Несколько обработчиков и форматеров](https://python-all.ru/3.1/library/logging.html#multiple-handlers-and-formatters)
    - [15.6.21.2. Использование логирования в нескольких модулях](https://python-all.ru/3.1/library/logging.html#using-logging-in-multiple-modules)
- [15.7. `getpass` – Переносимый ввод пароля](https://python-all.ru/3.1/library/getpass.html)
- [15.8. `curses` – Управление терминалом для символьных дисплеев](https://python-all.ru/3.1/library/curses.html)

  - [15.8.1. Функции](https://python-all.ru/3.1/library/curses.html#functions)
  - [15.8.2. Объекты окон](https://python-all.ru/3.1/library/curses.html#window-objects)
  - [15.8.3. Константы](https://python-all.ru/3.1/library/curses.html#constants)
- [15.9. `curses.textpad` – Виджет ввода текста для программ curses](https://python-all.ru/3.1/library/curses.html#module-curses.textpad)

  - [15.9.1. Объекты Textbox](https://python-all.ru/3.1/library/curses.html#textbox-objects)
- [15.10. `curses.wrapper` – Обработчик терминала для программ curses](https://python-all.ru/3.1/library/curses.html#module-curses.wrapper)
- [15.11. `curses.ascii` – Утилиты для работы с ASCII-символами](https://python-all.ru/3.1/library/curses.ascii.html)
- [15.12. `curses.panel` – Расширение стека панелей для curses](https://python-all.ru/3.1/library/curses.panel.html)

  - [15.12.1. Функции](https://python-all.ru/3.1/library/curses.panel.html#functions)
  - [15.12.2. Объекты панелей](https://python-all.ru/3.1/library/curses.panel.html#panel-objects)
- [15.13. `platform` – Доступ к идентификационным данным базовой платформы](https://python-all.ru/3.1/library/platform.html)

  - [15.13.1. Кросс-платформенные](https://python-all.ru/3.1/library/platform.html#cross-platform)
  - [15.13.2. Платформа Java](https://python-all.ru/3.1/library/platform.html#java-platform)
  - [15.13.3. Платформа Windows](https://python-all.ru/3.1/library/platform.html#windows-platform)

    - [15.13.3.1. Специфичное для Win95/98](https://python-all.ru/3.1/library/platform.html#win95-98-specific)
  - [15.13.4. Платформа Mac OS](https://python-all.ru/3.1/library/platform.html#mac-os-platform)
  - [15.13.5. Платформы Unix](https://python-all.ru/3.1/library/platform.html#unix-platforms)
- [15.14. `errno` – Стандартные системные символы errno](https://python-all.ru/3.1/library/errno.html)
- [15.15. `ctypes` – Библиотека для вызова внешних функций в Python](https://python-all.ru/3.1/library/ctypes.html)

  - [15.15.1. Учебник по ctypes](https://python-all.ru/3.1/library/ctypes.html#ctypes-tutorial)

    - [15.15.1.1. Загрузка динамически подключаемых библиотек](https://python-all.ru/3.1/library/ctypes.html#loading-dynamic-link-libraries)
    - [15.15.1.2. Доступ к функциям из загруженных DLL](https://python-all.ru/3.1/library/ctypes.html#accessing-functions-from-loaded-dlls)
    - [15.15.1.3. Вызов функций](https://python-all.ru/3.1/library/ctypes.html#calling-functions)
    - [15.15.1.4. Базовые типы данных](https://python-all.ru/3.1/library/ctypes.html#fundamental-data-types)
    - [15.15.1.5. Вызов функций (продолжение)](https://python-all.ru/3.1/library/ctypes.html#calling-functions-continued)
    - [15.15.1.6. Вызов функций с пользовательскими типами данных](https://python-all.ru/3.1/library/ctypes.html#calling-functions-with-your-own-custom-data-types)
    - [15.15.1.7. Указание требуемых типов аргументов (прототипы функций)](https://python-all.ru/3.1/library/ctypes.html#specifying-the-required-argument-types-function-prototypes)
    - [15.15.1.8. Типы возвращаемых значений](https://python-all.ru/3.1/library/ctypes.html#return-types)
    - [15.15.1.9. Передача указателей (или: передача параметров по ссылке)](https://python-all.ru/3.1/library/ctypes.html#passing-pointers-or-passing-parameters-by-reference)
    - [15.15.1.10. Структуры и объединения](https://python-all.ru/3.1/library/ctypes.html#structures-and-unions)
    - [15.15.1.11. Выравнивание структур и объединений и порядок байтов](https://python-all.ru/3.1/library/ctypes.html#structure-union-alignment-and-byte-order)
    - [15.15.1.12. Битовые поля в структурах и объединениях](https://python-all.ru/3.1/library/ctypes.html#bit-fields-in-structures-and-unions)
    - [15.15.1.13. Массивы](https://python-all.ru/3.1/library/ctypes.html#arrays)
    - [15.15.1.14. Указатели](https://python-all.ru/3.1/library/ctypes.html#pointers)
    - [15.15.1.15. Преобразования типов](https://python-all.ru/3.1/library/ctypes.html#type-conversions)
    - [15.15.1.16. Неполные типы](https://python-all.ru/3.1/library/ctypes.html#incomplete-types)
    - [15.15.1.17. Функции обратного вызова](https://python-all.ru/3.1/library/ctypes.html#callback-functions)
    - [15.15.1.18. Доступ к значениям, экспортируемым из DLL](https://python-all.ru/3.1/library/ctypes.html#accessing-values-exported-from-dlls)
    - [15.15.1.19. Сюрпризы](https://python-all.ru/3.1/library/ctypes.html#surprises)
    - [15.15.1.20. Типы данных переменного размера](https://python-all.ru/3.1/library/ctypes.html#variable-sized-data-types)
  - [15.15.2. Справочник по ctypes](https://python-all.ru/3.1/library/ctypes.html#ctypes-reference)

    - [15.15.2.1. Поиск разделяемых библиотек](https://python-all.ru/3.1/library/ctypes.html#finding-shared-libraries)
    - [15.15.2.2. Загрузка разделяемых библиотек](https://python-all.ru/3.1/library/ctypes.html#loading-shared-libraries)
    - [15.15.2.3. Внешние функции](https://python-all.ru/3.1/library/ctypes.html#foreign-functions)
    - [15.15.2.4. Прототипы функций](https://python-all.ru/3.1/library/ctypes.html#function-prototypes)
    - [15.15.2.5. Вспомогательные функции](https://python-all.ru/3.1/library/ctypes.html#utility-functions)
    - [15.15.2.6. Типы данных](https://python-all.ru/3.1/library/ctypes.html#data-types)
    - [15.15.2.7. Базовые типы данных](https://python-all.ru/3.1/library/ctypes.html#ctypes-fundamental-data-types-2)
    - [15.15.2.8. Структурированные типы данных](https://python-all.ru/3.1/library/ctypes.html#structured-data-types)
    - [15.15.2.9. Массивы и указатели](https://python-all.ru/3.1/library/ctypes.html#arrays-and-pointers)
