# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#python之模块 osimport os
'''
FUNCTIONSabort(...)#暂不了解abort() -> does not return!Abort the interpreter immediately.  This 'dumps core' or otherwise failsin the hardest way possible on the hosting operating system.access(...)#暂不了解access(path, mode) -> True if granted, False otherwiseUse the real uid/gid to test for access to a path.  Note that mostoperations will use the effective uid/gid, therefore this routine canbe used in a suid/sgid environment to test if the invoking user has thespecified access to the path.  The mode argument can be F_OK to testexistence, or the inclusive-OR of R_OK, W_OK, and X_OK.chdir(...)#改变当前工作目录,改变工作目录到dirname,相当于shell下cdchdir(path)Change the current working directory to the specified path.chmod(...)chmod(path, mode)Change the access permissions of a file.close(...)close(fd)Close a file descriptor (for low level IO).closerange(...)closerange(fd_low, fd_high)Closes all file descriptors in [fd_low, fd_high), ignoring errors.dup(...)dup(fd) -> fd2Return a duplicate of a file descriptor.dup2(...)dup2(old_fd, new_fd)Duplicate file descriptor.execl(file, *args)execl(file, *args)Execute the executable file with argument list args, replacing thecurrent process.execle(file, *args)execle(file, *args, env)Execute the executable file with argument list args andenvironment env, replacing the current process.execlp(file, *args)execlp(file, *args)Execute the executable file (which is searched for along $PATH)with argument list args, replacing the current process.execlpe(file, *args)execlpe(file, *args, env)Execute the executable file (which is searched for along $PATH)with argument list args and environment env, replacing the currentprocess.execv(...)execv(path, args)Execute an executable path with arguments, replacing current process.path: path of executable fileargs: tuple or list of stringsexecve(...)execve(path, args, env)Execute a path with arguments and environment, replacing current process.path: path of executable fileargs: tuple or list of argumentsenv: dictionary of strings mapping to stringsexecvp(file, args)execvp(file, args)Execute the executable file (which is searched for along $PATH)with argument list args, replacing the current process.args may be a list or tuple of strings.execvpe(file, args, env)execvpe(file, args, env)Execute the executable file (which is searched for along $PATH)with argument list args and environment env , replacing thecurrent process.args may be a list or tuple of strings.fdopen(...)fdopen(fd [, mode='r' [, bufsize]]) -> file_objectReturn an open file object connected to a file descriptor.fstat(...)fstat(fd) -> stat resultLike stat(), but for an open file descriptor.fsync(...)fsync(fildes)force write of file with filedescriptor to disk.getcwd(...)#获取当前目录getcwd() -> pathReturn a string representing the current working directory.getcwdu(...)getcwdu() -> pathReturn a unicode string representing the current working directory.getenv(key, default=None)Get an environment variable, return None if it doesn't exist.The optional second argument can specify an alternate default.getpid(...)getpid() -> pidReturn the current process idisatty(...)isatty(fd) -> boolReturn True if the file descriptor 'fd' is an open file descriptorconnected to the slave end of a terminal.kill(...)kill(pid, sig)Kill a process with a signal.listdir(...)#获取目录内容,其结果为list类型listdir(path) -> list_of_stringsReturn a list containing the names of the entries in the directory.path: path of directory to listThe list is in arbitrary order.  It does not include the specialentries '.' and '..' even if they are present in the directory.lseek(...)lseek(fd, pos, how) -> newposSet the current position of a file descriptor.Return the new cursor position in bytes, starting from the beginning.lstat(...)lstat(path) -> stat resultLike stat(path), but do not follow symbolic links.makedirs(name, mode=511)#递归文件夹创建函数,#os.makedirs('dirname1/dirname2') 可生成多层递归目录makedirs(path [, mode=0777])Super-mkdir; create a leaf directory and all intermediate ones.Works like mkdir, except that any intermediate path segment (notjust the rightmost) will be created if it does not exist.  This isrecursive.mkdir(...)#创建一个新的目录,目录已存在会报错,WindowsError: [Error 183] : '1'mkdir(path [, mode=0777])Create a directory.open(...)open(filename, flag [, mode=0777]) -> fdOpen a file (for low level IO).pipe(...)pipe() -> (read_end, write_end)Create a pipe.popen(...)popen(command [, mode='r' [, bufsize]]) -> pipeOpen a pipe to/from a command returning a file object.popen2(...)popen3(...)popen4(...)putenv(...)putenv(key, value)Change or add an environment variable.read(...)read(fd, buffersize) -> stringRead a file descriptor.remove(...)#删除文件,参数可根绝对路径remove(path)Remove a file (same as unlink(path)).removedirs(name)#递归删除目录在os模块中使用removedirs方法时,要想把a目录和a目录下的b目录同时删除,代码os.removedirs(r'D:\a\b'),只有符合以下条件时,a和b两个目录才会被同时删除。1)a目录下只有b目录2)b目录中必须是一个空目录两者缺一不可removedirs(path)Super-rmdir; remove a leaf directory and all empty intermediateones.  Works like rmdir except that, if the leaf directory issuccessfully removed, directories corresponding to rightmost pathsegments will be pruned away until either the whole path isconsumed or an error occurs.  Errors during this latter phase areignored -- they generally mean that a directory was not empty.rename(...)#文件重命名rename(old, new)Rename a file or directory.renames(old, new)#递归重命名文件夹或者文件,暂不知道怎么使用renames(old, new)Super-rename; create directories as necessary and delete any leftempty.  Works like rename, except creation of any intermediatedirectories needed to make the new pathname good is attemptedfirst.  After the rename, directories corresponding to rightmostpath segments of the old name will be pruned until either thewhole path is consumed or a nonempty directory is found.Note: this function can fail with the new directory structure madeif you lack permissions needed to unlink the leaf directory orfile.rmdir(...)#删除空目录,如果目录非空报错,WindowsError: [Error 145] : '1'rmdir(path)Remove a directory.spawnl(mode, file, *args)spawnl(mode, file, *args) -> integerExecute file with arguments from args in a subprocess.If mode == P_NOWAIT return the pid of the process.If mode == P_WAIT return the process's exit code if it exits normally;otherwise return -SIG, where SIG is the signal that killed it.spawnle(mode, file, *args)spawnle(mode, file, *args, env) -> integerExecute file with arguments from args in a subprocess with thesupplied environment.If mode == P_NOWAIT return the pid of the process.If mode == P_WAIT return the process's exit code if it exits normally;otherwise return -SIG, where SIG is the signal that killed it.spawnv(...)spawnv(mode, path, args)Execute the program 'path' in a new process.mode: mode of process creationpath: path of executable fileargs: tuple or list of stringsspawnve(...)spawnve(mode, path, args, env)Execute the program 'path' in a new process.mode: mode of process creationpath: path of executable fileargs: tuple or list of argumentsenv: dictionary of strings mapping to stringsstartfile(...)startfile(filepath [, operation]) - Start a file with its associatedapplication.When "operation" is not specified or "open", this acts likedouble-clicking the file in Explorer, or giving the file name as anargument to the DOS "start" command: the file is opened with whateverapplication (if any) its extension is associated.When another "operation" is given, it specifies what should be done withthe file.  A typical operation is "print".startfile returns as soon as the associated application is launched.There is no option to wait for the application to close, and no wayto retrieve the application's exit status.The filepath is relative to the current directory.  If you want to usean absolute path, make sure the first character is not a slash ("/");the underlying Win32 ShellExecute function doesn't work if it is.stat(...)#os.stat('path/filename') 获取文件/目录信息stat(path) -> stat resultPerform a stat system call on the given path.stat_float_times(...)stat_float_times([newval]) -> oldvalDetermine whether os.[lf]stat represents time stamps as float objects.If newval is True, future calls to stat() return floats, if it is False,future calls return ints. If newval is omitted, return the current setting.strerror(...)strerror(code) -> stringTranslate an error code to a message string.system(...)#运行shell命令#os.system('cmd') #启动dos#启动cmd命令符Execute the command (a string) in a subshell.tempnam(...)tempnam([dir[, prefix]]) -> stringReturn a unique name for a temporary file.The directory and a prefix may be specified as strings; they may be omittedor None if not needed.times(...)times() -> (utime, stime, cutime, cstime, elapsed_time)Return a tuple of floating point numbers indicating process times.tmpfile(...)tmpfile() -> file objectCreate a temporary file with no directory entries.tmpnam(...)tmpnam() -> stringReturn a unique name for a temporary file.umask(...)umask(new_mask) -> old_maskSet the current numeric umask and return the previous umask.unlink(...)unlink(path)Remove a file (same as remove(path)).urandom(...)urandom(n) -> strReturn n random bytes suitable for cryptographic use.utime(...)utime(path, (atime, mtime))utime(path, None)Set the access and modified time of the file to the given values.  If thesecond form is used, set the access and modified times to the current time.waitpid(...)waitpid(pid, options) -> (pid, status << 8)Wait for completion of a given process.  options is ignored on Windows.walk(top, topdown=True, οnerrοr=None, followlinks=False)#目录遍历Directory tree generator.For each directory in the directory tree rooted at top (including topitself, but excluding '.' and '..'), yields a 3-tupleWindowsError: [Error 183] : '1'dirpath, dirnames, filenamesExample:import osfrom os.path import join, getsizefor root, dirs, files in os.walk('python/Lib/email'):print root, "consumes",print sum([getsize(join(root, name)) for name in files]),print "bytes in", len(files), "non-directory files"if 'CVS' in dirs:dirs.remove('CVS')  # don't visit CVS directorieswrite(...)write(fd, string) -> byteswrittenWrite a string to a file descriptor.DATA:os.name#输出字符串指示正在使用的平台。如果是window 则用'nt'表示,对于Linux/Unix用户,它是'posixos.linesep字符串给出当前平台使用的行终止符 '\r\n'            #Windows使用'\r\n',Linux使用'\n'而Mac使用'\r'。os.curdir 返回当前目录: ('.')os.pardir 获取当前目录的父目录字符串名:('..')os.environ 获取系统环境变量>>>
'''

转载于:https://www.cnblogs.com/dengyg200891/p/4986236.html

python之模块 os相关推荐

  1. python标准模块--os

    目录 1.介绍2.常用函数 1.介绍 os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问题,就可以在L ...

  2. python标准模块os

    os模块为平台特定的模块(posix.nt和mac)提供了一个包装器.所有平台上函数的API都是相同的,所以使用os模块可以提供一定的可移植性.不过,并不是所有函数在每一个平台上都可用,许多进程管理函 ...

  3. Python常用模块os——与操作系统交互

    os.getcwd() 返回当前工作目录绝对路径 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit ...

  4. Python常用模块——目录

    Python常用模块学习 Python模块和包 Python常用模块time & datetime &random 模块 Python常用模块os & sys & sh ...

  5. python模块os测试文件是否存在及基础原信息获取

    python模块os测试文件是否存在及基础原信息获取 在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路 ...

  6. python里的os模块_python中os模块再回顾

    先看下我的文件目录结构 F:\PYTHON项目\ATM购物车\7月28 在此目录下的文件如下: 封装.py 模块os.sys复习.py 运行当前的文件是模块os.sys复习.py 1.获取当前文件所在 ...

  7. Python教程:os 与 sys 模块详细用法

    os 模块 os 模块主要用来进行与操作系统进行交互,它的导入方式为: import os os 模块主要涉及文件操作.文件夹操作.路径操作和其他操作四个方面. 文件操作 通过 os 模块对文件直接进 ...

  8. Python:目录和文件的操作模块os.path和OS常用方法

    1.目录和文件的操作模块os.path,在使用之前要先导入:import os.path.它主要有以下几个重要的功能函数: #!/user/bin/python #coding= utf-8impor ...

  9. Python第二十二天 stat模块 os.chmod方法 os.stat方法 pwd grp模块

    Python第二十二天   stat模块  os.chmod方法  os.stat方法  pwd  grp模块 stat模块描述了os.stat(filename)返回的文件属性列表中各值的意义,根据 ...

  10. python中的os模块

    os模块 os模块的作用: os,语义为操作系统,所以肯定就是操作系统相关的功能了,可以处理文件和目录这些我们日常手动需要做的操作,就比如说:显示当前目录下所有文件/删除某个文件/获取文件大小-- 另 ...

最新文章

  1. Java:Linux上java -jar xxx.jar命令执行jar包时出现Error: Invalid or corrupt jarfile xxx.jar解决方案...
  2. SQL Server优化50法
  3. hadoop3伪分布式安装
  4. sql 合并行内容_SAS高级编程公开课之一SQL
  5. 风能matlab仿真_发现潜力:使用计算机视觉对可再生风能发电场的主要区域进行分类(第1部分)
  6. 错过了面试,公司招满人了_您可能错过了Google令人赞叹的AI公告。
  7. 95-140-114-源码-transform-算子project
  8. 【自由随想录(三)】
  9. JavaScript prompt函数
  10. C++杂记之this指针
  11. ThreadPoolExecutor线程池源码(二) - 核心源码
  12. [2022-06-21 完美解决]MacBookPro 2020 M1 开启2k HIDPI
  13. Ant Design Vue 表格行内编辑!!!
  14. Course Z6110X0035 CC Lab 2
  15. 2019年年末给我自己的一个总结---发现自己其实外表平静,内心狂野哈哈哈哈哈
  16. java求数组的平均值_Java中数组求平均值,最大值,最小值。
  17. 搭建直播平台什么样的服务器最合适?
  18. 关于 退步编程 和 退步看书的思考
  19. Web代理(HTTP代理)
  20. 生信工作流框架搭建 | 02-nextflow 实战

热门文章

  1. 7-17 mmh学长的三色灯 (20分)
  2. golang 生成定单号
  3. Zookeeper 概述与安装、配置参数、数据结构、选举机制、客户端命令
  4. Java 序列化与主流编解码技术框架介绍
  5. 阶段3 2.Spring_02.程序间耦合_1 编写jdbc的工程代码用于分析程序的耦合
  6. 多用类型常量,少用#define预处理指令
  7. linux 单机跨进程通信
  8. 类序列化之后保存在COOKIES里
  9. 手机验证码免费10条\java、C#、html....
  10. mysql中XtraBackup备份工作机制