首页 / PYTHON / Python 常用模块
Python 常用模块
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python 常用模块,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1988字,纯文字阅读大概需要3分钟。
内容图文
![Python 常用模块](/upload/InfoBanner/zyjiaocheng/791/e48ad82a029348f4be854223a3448f80.jpg)
os模块
提供了非常丰富的方法用来处理文件和目录。
os.getcwd() 返回当前工作目录
os.getegid() 得到有效组id os.getgid() 得到组id
os.geteuid() 得到有效用户id os.getuid()
os.chdir(dir) 更改当前目录 os.chdir('d:\\outlook')
os.system(cmd) 利用系统调用,运行cmd命令
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 切换到 "/var/www/html" 目录 os.chdir("/var/www/html" ) # 打印当前目录 print "当前工作目录 : %s" % os.getcwd() # 打开 "/tmp" fd = os.open( "/tmp", os.O_RDONLY ) # 使用 os.fchdir() 方法修改目录 os.fchdir(fd) # 打印当前目录 print "当前工作目录 : %s" % os.getcwd() # 关闭文件 os.close( fd ) -------------------------------- 当前工作目录 : /var/www/html 当前工作目录 : /tmp
--------------------------------
- all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.
- os.path is one of the modules posixpath, or ntpath
- os.name is 'posix', 'nt', 'os2', '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.)
sys模块
from...import 语句
python的from语句让你从模块中导入一个指定的部分到当前命名空间中。
from modname import name1[,name2[, ... nameN]] 例如:要导入模块fib的fibonacci函数,使用如下语句 from fib import fibonacci
from...import * 语句
把一个模块的所有内容完全都导入到当前的命名空间也是可行的,只需要使用如下声明:
from modname import * 这提供了一个简单的方法来导入一个模块中的所有项目。然而这种声明不该被过多地使用。 例如我们想一次性引入math模块中的所有东西,语句如下: form math import *
内容总结
以上是互联网集市为您收集整理的Python 常用模块全部内容,希望文章能够帮你解决Python 常用模块所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。