免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2897 | 回复: 0
打印 上一主题 下一主题

os模块1 [Python] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-05 21:14 |只看该作者 |倒序浏览
常用的os模块工具

Tasks
tools
Shell variables
os.environ
Running programs
os.system
os.popen
os.popen2/3/4
os.startfile
Spawning processes
os.fork
os.pipe
os.exec
os.waitpid
os.kill
Descriptor files, locks
os. open
os.read
os.write
File processing
os.remove
os.rename
os.mkfifo
os.mkidr
os.rmdir
Administrative tools
os.getcwd
os.chdir
os.chmod
os.getpid
os.listdir
Portability tools
os.sep
os.pathsep
os.curdir
os.path.split
os.path.join
Pathname tools
os.path.exisets('path')
os.path.isdir('path')
os.path.getsize('path')

os模块的方法和属性是比较多的,而且在不同的平台下,也不尽相同.

Linux


[root@lvdbing ~]# python
Python 2.5.2 (r252:60911, Sep 26 2008, 01:57:27)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> dir(os)
['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR',  ... ... ... 'umask',  'write']
>>> len(dir(os))
213
WindowsXP
Python 2.5.2 (r252:60911, Mar 27 2008, 17:57:18) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> dir(os)
['F_OK', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', ... ... ... , 'write']
>>> len(dir(os))
122
可以看到Linux和WindowsXP是不同的.
如何才能知道模块提供的工具如何使用呢,Python使用help()函数可以实时查看帮助文档.
>>> help(os)
Help on module os:
NAME
    os - OS routines for Mac, NT, or Posix depending on what system we're on.
FILE
    /usr/local/python25/lib/python2.5/os.py
MODULE DOCS
    http://www.python.org/doc/current/lib/module-os.html
DESCRIPTION
    This exports:
      - all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc.
      - os.path is one of the modules posixpath, ntpath, or macpath
      - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
      - os.curdir is a string representing the current directory ('.' or ':')
      - os.pardir is a string representing the parent directory ('..' or '::')
      - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
      - os.extsep is the extension separator ('.' or '/')
      - os.altsep is the alternate pathname separator (None or '/')
      - os.pathsep is the component separator used in $PATH etc
      - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
      - os.defpath is the default search path for executables
      - os.devnull is the file path of the null device ('/dev/null', etc.)
   
    Programs that import and use 'os


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20294/showart_1273127.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP