OS模块的常用内置方法

chdir修改当前工作目录到指定目录

Change the current working directory to the specified path.

chmod修改一个文件的访问权限

Change the access permissions of a file.

chown把一个目录的属主和属组修改成另一个数字的属主和属组

Change the owner and group id of path to the numeric uid and gid

chroot修改根目录(在liunx下使用)

Change root directory to path.

ctermid返回一个进程的控制台的名字

Return the name of the controlling terminal for this process.

getcwd以字符串格式显示当前工作目录(python解释器的工作目录)

Return a unicode string representing the current working directory.

getegid获取当前进程的有效组ID

Return the current process's effective group id.

getenv获取系统的环境变量,环境变量不存在时返回None

Get an environment variable, return None if it doesn't exist.

geteuid获取当前进程的有效用户ID

Return the current process's effective user id.

getgid获取当彰进程的组ID

Return the current process's group id.

getgrouplist返回指定用户的基本组的列表

getgrouplist(user, group) -> list of groups to which a user belongs

Returns a list of groups to which a user belongs.

getgroups获取一个进程的附加组ID的列表

Return list of supplemental group IDs for the process.

getloadavg返回当前一个由系统1分钟,5分钟和15分钟的平均负载使用率组成的元组

Return average recent system load information.

Return the number of processes in the system run queue averaged over

the last 1, 5, and 15 minutes as a tuple of three floats.

Raises OSError if the load average was unobtainable.

getlogin返回当前系统的实际登陆的用户名

Return the actual login name.

getpid返回当前的进程ID号

Return the current process id.

getppid返回当前进程的父进程的ID号

Return the parent's process id.

getuid返回当前进程的用户ID

Return the current process's user id.

kill结束一个进程

Kill a process with a signal.

killpg结束掉一个进程组

Kill a process group with a signal.

listdir返回指定路径下由所有所有文件的名字组成的列表,未指定路径则默认为当前路径

Return a list containing the names of the files in the directory.

path can be specified as either str or bytes. If path is bytes,

the filenames returned will also be bytes; in all other circumstances

the filenames returned will be str.

If path is None, uses the path='.'.

lseek设置并返回指定文件的指针的位置,

Set the position of a file descriptor. Return the new position.

Return the new cursor position in number of bytes

relative to the beginning of the file.

major获取一个设备文件的主设备号

Extracts a device major number from a raw device number.

makedev在系统上创建一个新的设备文件

Composes a raw device number from the major and minor device numbers.

makedirs递归创建多层目录,如果目标目录已经存在,则报错

Super-mkdir; create a leaf directory and all intermediate ones. Works like

mkdir, except that any intermediate path segment (not just the rightmost)

will be created if it does not exist. If the target directory already

exists, raise an OSError if exist_ok is False. Otherwise no exception is

raised. This is recursive.

minor获取一个设备文件的次设备号

Extracts a device minor number from a raw device number.

mkdir创建一个目录

Create a directory.

mkfifo创建一个管道文件

If dir_fd is not None, it should be a file descriptor open to a directory,

and path should be relative; path will then be relative to that directory.

dir_fd may not be implemented on your platform.

If it is unavailable, using it will raise a NotImplementedError.

nice为一个进程增加属性,也即修改一个进程的nice值

Add increment to the priority of process and return the new priority.

open在硬件层面打开文件,返回一个整型的文件描述符

Open a file for low level IO. Returns a file descriptor (integer).

putenv修改或增加一个环境变量

Change or add an environment variable.

read读取指定文件的文件描述符,返回字节对象

Read from a file descriptor. Returns a bytes object.

remove删除指定文件

Remove a file (same as unlink()).

removedirs删除多层目录,

Super-rmdir; remove a leaf directory and all empty intermediate

ones. Works like rmdir except that, if the leaf directory is

successfully removed, directories corresponding to rightmost path

segments will be pruned away until either the whole path is

consumed or an error occurs. Errors during this latter phase are

ignored -- they generally mean that a directory was not empty.

rename为一个文件或目录重命名

Rename a file or directory.

rmdir删除一个目录

Remove a directory.

setegid设置当前进程的有效组ID

Set the current process's effective group id.

seteuid设置当前进程的有效用户ID

Set the current process's effective user id.

setgid设置当前进程的组ID

Set the current process's group id.

setuid为当前进程设置用户ID

Set the current process's user id.

stat显示指定路径的详细信息

Perform a stat system call on the given path.

strerror把错误号码转换成信息字符串

Translate an error code to a message string.

symlink为指定目录创建软链接

symlink(src, dst, target_is_directory=False, *, dir_fd=None)

Create a symbolic link pointing to src named dst.

sync强制写入内容到磁盘中

Force write of everything to disk.

system在子shell中执行系统命令

Execute the command in a subshell.

times返回系统时间信息的集合

Return a collection containing process timing information.

umask

为文件或目录设置并返回新权限模式

Set the current numeric umask and return the previous umask.

uname返回当前操作系统的内核信息

Return an object identifying the current operating system.

unlink删除一个软链接

unlink(path, *, dir_fd=None)

Remove a file (same as remove()).

unsetenv删除一个环境变量

Delete an environment variable.

utime为指定路径设置最后访问时间和最后修改时间

utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)

Set the access and modified time of path.

walk给定目录名,返回一个由当前目录名,当前目录的子目录以及当前目录下的普通文件组成的元组

Directory tree generator.

For each directory in the directory tree rooted at top (including top

itself, but excluding '.' and '..'), yields a 3-tuple

dirpath, dirnames, filenames

dirpath is a string, the path to the directory. dirnames is a list of

the names of the subdirectories in dirpath (excluding '.' and '..').

filenames is a list of the names of the non-directory files in dirpath.

Note that the names in the lists are just names, with no path components.

To get a full path (which begins with top) to a file or directory in

dirpath, do os.path.join(dirpath, name).

python常用内置模块-Python之OS模块常用内置方法汇总相关推荐

  1. Python 入门 —— Python 面向对象:类的创建及其基本内置方法的使用

    Python 面向对象:类的创建及其基本内置方法的使用 首先了解一下什么是面向对象 面向过程: 就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了. ...

  2. python 内置模块 增加_模块的内置方法--Python提高班

    这期的话题有点简单, 整理下常见的模块内置方法 刚开始学Python的时候, 看到if __name__ == '__main__': main()就不明觉厉了, 一直好奇__name__这货到底是个 ...

  3. Python入门学习 DAY 05 字符串,列表的内置方法

    Python入门 DAY 05 本篇文章主要介绍字符串类型及内置方法,列表类型及内置方法 1.字符串类型及内置方法 (1)字符串定义       1.字符串中的字符是有序的          可以通过 ...

  4. python基础30个常用代码大全-Python3列表内置方法大全及示例代码小结

    Python中的列表是简直可说是有容乃大,虽然看似类似C中的数组,但是Python列表可以接受任意的对象元素,比如,字符串,数字,布尔值,甚至列表,字典等等,自由度提升到一个新的高度,而Python也 ...

  5. python系统-Python OS模块常用功能 中文图文详解

    一.Python OS模块介绍 OS模块简单的来说它是一个Python的系统编程的操作模块,可以处理文件和目录这些我们日常手动需要做的操作. 可以查看OS模块的帮助文档: >>> i ...

  6. python os模块 常用命令

    os 模块用法示例 python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关.以下列举常用的命令 1. os.name()--判断现在正在实用 ...

  7. Python 之 os 模块常用操作

    我们知道,使用 Python 内置的库函数, open() 函数可以对文本文件进行读写操作,那么这是在文件层面上的操作,如果说我们想对文件夹进行增.删.改.查时,又该如何去做呢? Python 拥有强 ...

  8. python常用内置模块-Python基础-22常用内置模块

    22. 常用内置模块 22.1 random模块 随机数据可以用于数学.测试.安全.算法等领域中.内置random模块,可用于生成伪随机数. 真正意义上的随机数或随机事件是在某次产生过程中是按照实验过 ...

  9. Python初级第2课——os模块(只读课堂)

    欢迎来到"只读课堂"! 这个模块和文件操作一样,使用它,可以与我们当前的系统进行交互. OS模块简单介绍 os模块主要有以下几种:posix(适用于unix操作系统) nt(win ...

最新文章

  1. 基于android的记账本论文,(毕业论文)基于安卓的记账本.doc
  2. mcrypt_module_open php,求PHP7.1 加密函数mcrypt_module_open()替换方案
  3. python制作工资计算器-Python实现扣除个人税后的工资计算器示例
  4. 原生js写三级联动 java_原生js三级联动的简单实现代码
  5. “中国好创意” CCF全国青年大数据创新大赛启动仪式 暨大数据大师论坛议程...
  6. 苏宁启动30周年庆:联合近300个品牌启动“超级品牌季”
  7. 消息中间件学习总结(18)——MQ常见面试题总结
  8. Mysql学习总结(71)——MySQL 重复记录查询与删除总结
  9. 电脑剪贴板在哪里打开_如何把在公司电脑上复制的内容,粘贴到家里的电脑?超好用!...
  10. 代码走查与代码审查区别
  11. es分词查询与模糊查询
  12. DDD-领域驱动设计
  13. 数据结构——拓扑排序算法理解和实现
  14. Java毕业设计-资产管理系统
  15. MATLAB-插值算法汇总
  16. 笔记本电脑更换固态硬盘教程(联想ThinkPadE455)
  17. Linux下打包压缩war和解压war包 zip和jar
  18. C语言编程>第二十一周 ⑥ 请补充main函数,该函数的功能是:从键盘输入一个字符串,即一个指定,然后把这个字符及其后面的所有字符全部删除,结果仍然保存在原串中。
  19. Linux——SAMBA文件共享
  20. 腾讯云服务器完全卸载mysql

热门文章

  1. Oracle单表备份三种方案
  2. 源码分析(一) 进程cleos的命令解析
  3. Redis - 事务
  4. 聊聊大麦网UWP版的首页顶部图片联动效果的实现方法
  5. 栏目信息开源 免费 java CMS - FreeCMS1.3 标签 infoList
  6. Maven笔记(2)-- 常用命令和标准的Maven项目结构
  7. Activity查看数据与文本框反回数据
  8. Asp.net与SQL一起打包部署安装
  9. Silverlight 全屏模式
  10. 搭建无人值守安装服务器(CentOS)