导航
×
   ❮   
HTML CSS JavaScript PHP Python C C++ Go Sass W3C Colors TypeScript ECMS

Python 教程

Python 简介 Python 历史 Python 下载安装配置 Python 入门 Python 语法 Python 语句 Python 输出 Python 注释 Python 变量 Python 数据类型 Python 数值类型 Python 类型转换 Python 字符串 Python 布尔值 Python 运算符 Python 列表 Python 元组 Python 集合 Python 字典 Python If...Else Python While 循环 Python For 循环 Python 函数 Python Range Python 数组 Python 类和对象 Python 继承 Python 迭代 Python 模块 Python 日期时间 Python 数学运算 Python JSON Python 正则表达式 Python PIP Python Try...Except Python 用户输入 Python 字符串格式化

Python 文件处理

Python 文件处理 Python 打开文件 Python 创建/写入文件 Python 删除文件

Python NumPy

NumPy 简介 NumPy 入门 NumPy 创建数组 NumPy 数组索引 NumPy 数组裁切 NumPy 数据类型 NumPy 副本 vs 视图 NumPy 数组形状 NumPy 数组重塑 NumPy 数组迭代 NumPy 数组连接 NumPy 数组拆分 NumPy 数组搜索 NumPy 数组排序 NumPy 数组过滤 NumPy 随机数 NumPy ufunc 通用函数

Python SciPy

SciPy 简介 SciPy 入门 SciPy 常量 SciPy 优化器 SciPy 稀疏数据 SciPy 图表 SciPy 空间数据 SciPy Matlab 数组 SciPy 插值 SciPy 统计显着性检验

Python 机器学习

Machine 机器学习入门 Machine 平均中位数模式 Machine 标准差 Machine 百分位数 Machine 数据分布 Machine 正态数据分布 Machine 散点图 Machine 线性回归 Machine 多项式回归 Machine 多元回归 Machine 缩放 Machine 训练/测试 Machine 决策树

Python MySQL

MySQL 入门 MySQL Create Database MySQL Create Table MySQL Insert MySQL Select MySQL Where MySQL Order By MySQL Delete MySQL Drop Table MySQL Update MySQL Limit MySQL Join

Python MongoDB

MongoDB 入门 MongoDB 创建数据库 MongoDB 创建集合 MongoDB 插入 MongoDB 查找 MongoDB 查询 MongoDB 排序 MongoDB 删除 MongoDB 删除集合 MongoDB 更新 MongoDB 限制

Python 参考手册

Python 参考手册 Python 内置函数 Python 字符串方法 Python 列表/数组方法 Python 字典方法 Python 元组方法 Python 集合方法 Python 文件方法 Python 关键字 Python 内置异常 Python 词汇表
Python 词汇表 Indentation Multi Line Comments Creating Variables Variable Names Output Variables String Concatenation Global Variables Built-In Data Types Getting Data Type Setting Data Type Numbers Int Float Complex Random Number Specify a Variable Type String Literals Assigning a String to a Variable Multiline Strings Strings are Arrays Slicing a String Negative Indexing on a String String Length Check In String Format String Escape Characters Evaluate Booleans Return Boolean Value Comparison Operators Identity Operators Access List Items Change List Item Loop Through List Items Check if List Item Exists List Length Add List Items Remove List Items Copy a List Join Two Lists Access Tuple Items Change Tuple Item Loop List Items Check if Tuple Item Exists Tuple Length Tuple With One Item Remove Tuple Items Join Two Tuples 访问集合项 添加集合项目 Loop Set Items 检查集合项是否存在 集合长度 删除集合项 连接两个集合 Access Dictionary Items Change Dictionary Item Loop Dictionary Items Check if Dictionary Item Exists Dictionary Length Add Dictionary Item Remove Dictionary Items Copy Dictionary Nested Dictionaries If Statement If 缩进 Elif Else 简写 If Else If AND If OR 嵌套 If If中的pass关键字 While While Break While Continue While Else Loop Through a String For Break For Continue Looping Through a rangee For Else Nested Loops For pass Call a Function *args Keyword Arguments *kwargs Default Parameter Value Passing a List as an Argument Function Return Value The pass Statement i Functions Function Recursion Why Use Lambda Functions Array What is an Array Array Length Looping Array Elements Add Array Element Remove Array Element Array Methods Class Create Class The Class __init__() Function Object Methods self Modify Object Properties Delete Object Properties Delete Object Class pass Statement Create Parent Class Create Child Class Create the __init__() Function Add Class Properties Add Class Methods Iterator vs Iterable Loop Through an Iterator Create an Iterator StopIteration Global Scope Global Keyword Create a Module Variables in Modules Renaming a Module Built-in Modules Using the dir() Function Import From Module Date Output Create a Date Object The strftime Method Date Format Codes Parse JSON Convert into JSON Format JSON Sort JSON RegEx Functions Metacharacters in RegEx RegEx Special Sequences RegEx Sets RegEx Match Object Install PIP PIP Packages PIP Remove Package Error Handling Try Else Try Finally raise Comments Assign Values to Multiple Variables Type Conversion Boolean Values Operators Arithmetic Operators Assignment Operators Logical Operators 成员运算符 Bitwise Operators Lists Tuple 集合 Dictionary 简写 If For Function Function Arguments Lambda Function super Function Iterators Datetime Module JSON RegEx Module Handle Many Exceptions Access Arrays

Python 模块参考

Python 内置模块 Python random 随机模块 Python requests 请求模块 Python statistics 统计模块 Python math 数学模块 Python cMath 模块

Python 如何使用

Python 删除列表重复项 Python 反转字符串 Python 添加两个数字

Python 实例

Python 实例 Python 测验

Python os 模块


实例

打印操作系统名称(稳定输出):

import os

print(os.name)
亲自试一试 »

os 模块提供了一种可移植的方式来使用操作系统相关的功能。

使用它来操作文件系统、环境变量、进程等等。


成员

备注:

[Windows] = 仅适用于 Windows 系统。

[Unix] = 适用于 POSIX 系统(Linux、macOS 等)。

[Linux] = 仅适用于 Linux 系统。

某些功能在多个平台上都存在,但可能存在功能限制(会在描述中注明)。

成员 描述
access() 检查用户对路径的权限。
add_dll_directory() [Windows] 将路径添加到 DLL 搜索路径。
chdir() 更改当前工作目录。
chmod() 更改路径的权限。
chown() [Unix] 更改路径的所有者和组。
close() 关闭文件描述符。
closerange() 关闭一系列文件描述符。
cpu_count() 返回系统中的 CPU 数量(可能为 None)。
ctermid() [Unix] 返回控制终端的文件名。
devnull 空设备的路径。
device_encoding() 返回文件描述符的编码,如果是则返回 None。
dup() 复制文件描述符。
dup2() 将文件描述符复制到指定的文件描述符。
dup3() 将文件描述符复制到指定的文件描述符(带标志)。
environ 表示进程环境的映射对象。
execl() 执行一个新程序(可变参数形式)。
execle() 执行一个带有环境变量(可变参数)的新程序。
execlp() 执行一个新程序,并在 PATH 环境变量中搜索(可变参数)。
execlpe() 执行一个带有环境变量(可变参数)的新程序,并在 PATH 环境变量中搜索。
execv() 执行一个新程序,并替换当前进程。
execve() 使用环境变量(底层)执行新程序。
execvp() 执行程序,并在 PATH 环境变量中搜索。
execvpe() 执行程序,并在 PATH 环境变量中搜索。
extsep 操作系统扩展名分隔符。
fchdir() [Unix] 将当前工作目录更改为已打开文件描述符指定的目录。
fchmod() [Unix] 更改文件描述符指定的文件的权限。
fchown() [Unix] 更改文件描述符指定的文件的所有者和组。
fdopen() 返回一个已打开并连接到文件描述符的文件对象。
fork() [Unix] 创建一个子进程。
fsdecode() 将路径对象或字节对象解码为字符串。
fsencode() 将路径对象或字符串对象编码为字节。
fspath() 返回路径对象的文件系统表示形式。
fstat() 对已打开的文件描述符执行状态查询。
ftruncate() 将文件截断为指定长度。
get_blocking() 获取文件描述符的阻塞模式。
getcwd() 以字符串形式返回当前工作目录。
getcwdb() 以字节形式返回当前工作目录。
getegid() [Unix] 返回有效组 ID。
geteuid() [Unix] 返回有效用户 ID。
get_exec_path() 返回用于搜索可执行文件的目录序列。
getgid() [Unix] 返回实际的组 ID。
getgrouplist() [Unix] 返回用户所属的组 ID 列表。
get_inheritable() 获取文件描述符的可继承标志。
getlogin() [Unix] 返回在控制终端上登录的用户名。
getpgid() [Unix] 返回进程的进程组 ID。
getpgrp() [Unix] 返回当前进程的进程组 ID。
getpid() 返回当前进程 ID。
getppid() 返回父进程 ID。
getpriority() [Unix] 获取进程调度优先级。
getsid() [Unix] 返回进程的会话 ID。
get_terminal_size() 返回终端窗口的大小(以列和行为单位)。
getuid() [Unix] 返回真实用户 ID。
isatty() 如果文件描述符已打开并连接到 tty 设备,则返回 True。
kill() [Windows 系统限制] 向进程发送信号。
killpg() [Unix] 向进程组发送信号。
linesep 用于分隔(或终止)当前平台上的行的字符串。
link() 创建指向路径的硬链接。
listdir() 返回目录中的条目列表。
lseek() 设置文件描述符的位置。
lstat() 类似于 stat(),但不跟踪符号链接。
makedirs() 递归创建目录。
memfd_create() [Linux] 创建匿名内存文件。
mkdir() 创建目录。
mkfifo() [Unix] 创建 FIFO(命名管道)。
mknod() [Unix] 创建一个文件系统节点。
name 导入的操作系统相关模块的名称。
open() 底层操作系统打开函数;返回一个文件描述符。
openpty() [Unix] 打开一个新的伪终端对。
path 用于路径名操作的子模块。
pathsep 用于分隔搜索路径组成部分的字符串(例如,Windows 系统中的";")。
pipe() 创建一个管道,返回一对文件描述符(r,w)。
pipe2() [Unix] 创建一个带有标志的管道。
posix_spawn() [Unix] 生成一个进程(POSIX,高效)。
posix_spawnp() [Unix] 启动一个在 PATH 环境变量中搜索的进程(POSIX)。
pread() [Unix] 从文件描述符的指定位置读取数据。
pwrite() [Unix] 向文件描述符的指定位置写入数据。
putenv() 设置环境变量的值。
read() 从文件描述符读取数据。
readlink() 返回符号链接指向的路径。
readv() [Unix] 从文件描述符读取数据到多个缓冲区。
register_at_fork() [Unix] 注册要在进程 fork 时执行的可调用对象。
remove() 删除文件。
rename() 重命名文件或目录。
renames() 递归重命名文件或目录。
rmdir() 删除目录。
scandir() 返回 DirEntry 对象的迭代器。
sched_getaffinity() [Unix] 获取 CPU 亲和性掩码。
sched_setaffinity() [Unix] 设置 CPU 亲和性掩码。
sched_yield() [Unix] 让出处理器。
sep 当前平台的路径分隔符。
set_blocking() 设置文件描述符的阻塞模式。
setegid() [Unix] 设置有效组 ID。
setenv() 设置环境变量(如果可用)。
seteuid() [Unix] 设置有效用户 ID。
setgid() [Unix] 设置实际组 ID。
setgroups() [Unix] 设置当前进程的组 ID 列表。
set_handle_inheritable() [Windows] 设置句柄可继承标志。
set_inheritable() 设置文件描述符的可继承标志。
setpgid() [Unix] 设置进程组 ID。
setpgrp() [Unix] 将当前进程设为会话领导者。
setpriority() [Unix] 设置进程调度优先级。
setregid() [Unix] 设置真实组 ID 和有效组 ID。
setreuid() [Unix] 设置真实用户 ID 和有效用户 ID。
setsid() [Unix] 启动一个新会话。
setuid() [Unix] 设置真实用户 ID。
spawnl() 使用路径(可变参数)启动一个进程。
spawnle() 使用路径和环境变量(可变参数)启动一个进程。
spawnlp() 在 PATH 环境变量(可变参数)下启动一个进程。
spawnlpe() 使用环境变量(可变参数)在 PATH 中搜索并生成一个进程。
spawnv() 使用路径(向量参数)生成一个进程。
spawnve() 使用路径和环境变量(向量参数)生成一个进程。
spawnvp() 使用环境变量(向量参数)在 PATH 中搜索并生成一个进程。
spawnvpe() 使用环境变量(向量参数)在 PATH 中搜索并生成一个进程。
startfile() [Windows] 使用关联的应用程序打开文件。
stat() 对路径执行 stat 系统调用。
statvfs() [Unix] 返回文件系统统计信息。
strerror() 返回与 errno 值对应的错误消息。
supports_bytes_environ 如果 environ 接受字节键/值,则返回 True。
supports_dir_fd 如果函数接受 dir_fd 参数,则为 True。
supports_effective_ids 如果函数支持有效 ID,则为 True。
supports_fd 如果函数接受文件描述符,则为 True。
supports_follow_symlinks 如果函数支持 follow_symlinks 参数,则为 True。
symlink() 创建符号链接。在 Windows 系统中,需要开发者模式或管理员权限。
sync() [Unix] 刷新文件系统缓冲区。
system() 在子 shell 中执行命令(字符串)。
times() 返回进程运行时间。
truncate() 将文件截断至指定长度。
umask() 设置进程 umask 并返回先前的值。
uname() [Unix] 返回操作系统标识。
unlink() 删除文件。
urandom() 返回用于加密的随机字节。
utime() 设置访问时间和修改时间。
wait() [Unix] 等待子进程完成。
wait3() [Unix] 等待子进程,并返回资源使用情况。
wait4() [Unix] 等待带有 rusage 的子进程。
waitpid() [Unix] 等待指定的子进程完成。
walk() 通过遍历目录树生成文件名。
write() 写入文件描述符。
writev() [Unix] 从多个缓冲区写入文件描述符。

Copyright ©2026 蒙ICP备2026009383号 All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。