当前位置: 首页 > news >正文

科创纵横 网站建设seo实战密码在线阅读

科创纵横 网站建设,seo实战密码在线阅读,广州短视频代运营,台州平台网站建设Python OS 文件/目录方法 Python语言零基础入门教程(二十四) 39、Python os.openpty() 方法 概述 os.openpty() 方法用于打开一个新的伪终端对。返回 pty 和 tty的文件描述符。 语法 openpty()方法语法格式如下: os.openpty()参数 无 返…

Python OS 文件/目录方法

Python语言零基础入门教程(二十四)

39、Python os.openpty() 方法

概述
os.openpty() 方法用于打开一个新的伪终端对。返回 pty 和 tty的文件描述符。

语法
openpty()方法语法格式如下:

os.openpty()

参数

返回值
返回文件描述符对,主从。

实例
以下实例演示了 openpty() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os# 主 pty, 从 tty
m,s = os.openpty()print m
print s# 显示终端名
s = os.ttyname(s)
print m
print s

执行以上程序输出结果为:

3
4
3
/dev/pty0

40、Python os.pathconf() 方法

概述
os.pathconf() 方法用于返回一个打开的文件的系统配置信息。

Unix 平台下可用。

语法
fpathconf()方法语法格式如下:

os.fpathconf(fd, name)

参数
name – 文件描述符

name – 检索的系统配置的值,它也许是一个定义系统值的字符串,这些名字在很多标准中指定(POSIX.1, Unix 95, Unix 98, 和其它)。一些平台也定义了一些额外的名字。这些名字在主操作系统上pathconf_names的字典中。对于不在pathconf_names中的配置变量,传递一个数字作为名字,也是可以接受的。

返回值
返回文件的系统信息。

实例
以下实例演示了 fpathconf() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )print "%s" % os.pathconf_names# 获取文件最大连接数
no = os.fpathconf(fd, 'PC_LINK_MAX')
print "Maximum number of links to the file. :%d" % no# 获取文件名最大长度
no = os.fpathconf(fd, 'PC_NAME_MAX')
print "Maximum length of a filename :%d" % no# 关闭文件
os.close( fd)print "关闭文件成功!!"

执行以上程序输出结果为:

关闭文件成功!!

41、Python os.pipe() 方法

概述
os.pipe() 方法用于创建一个管道, 返回一对文件描述符(r, w) 分别为读和写。

语法
pipe()方法语法格式如下:

os.pipe()

参数

返回值
返回文件描述符对。

实例
以下实例演示了 pipe() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sysprint "The child will write text to a pipe and "
print "the parent will read the text written by child..."# file descriptors r, w for reading and writing
r, w = os.pipe() processid = os.fork()
if processid:# This is the parent process # Closes file descriptor wos.close(w)r = os.fdopen(r)print "Parent reading"str = r.read()print "text =", str   sys.exit(0)
else:# This is the child processos.close(r)w = os.fdopen(w, 'w')print "Child writing"w.write("Text written by child...")w.close()print "Child closing"sys.exit(0)

执行以上程序输出结果为:

The child will write text to a pipe and
the parent will read the text written by child...
Parent reading
Child writing
Child closing
text = Text written by child...

42、Python os.popen() 方法

概述
os.popen() 方法用于从一个命令打开一个管道。

在Unix,Windows中有效

语法
popen()方法语法格式如下:

os.popen(command[, mode[, bufsize]])

参数
command – 使用的命令。

mode – 模式权限可以是 ‘r’(默认) 或 ‘w’。

bufsize – 指明了文件需要的缓冲大小:0意味着无缓冲;1意味着行缓冲;其它正值表示使用参数大小的缓冲(大概值,以字节为单位)。负的bufsize意味着使用系统的默认值,一般来说,对于tty设备,它是行缓冲;对于其它文件,它是全缓冲。如果没有改参数,使用系统的默认值。

返回值
返回一个文件描述符号为fd的打开的文件对象

实例
以下实例演示了 popen() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 使用 mkdir 命令
a = 'mkdir nwdir'b = os.popen(a,'r',1)print b

执行以上程序输出结果为:

open file 'mkdir nwdir', mode 'r' at 0x81614d0

43、Python os.read() 方法

概述
os.read() 方法用于从文件描述符 fd 中读取最多 n 个字节,返回包含读取字节的字符串,文件描述符 fd对应文件已达到结尾, 返回一个空字符串。

在Unix,Windows中有效

语法
read()方法语法格式如下:

os.read(fd,n)
参数
fd – 文件描述符。

n – 读取的字节。

返回值
返回包含读取字节的字符串

实例
以下实例演示了 read() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys
# 打开文件
fd = os.open("f1.txt",os.O_RDWR)# 读取文本
ret = os.read(fd,12)
print ret# 关闭文件
os.close(fd)
print "关闭文件成功!!"

执行以上程序输出结果为:

This is test
关闭文件成功!!

44、Python os.readlink() 方法

概述
os.readlink() 方法用于返回软链接所指向的文件。可能返回绝对或相对路径。

在Unix中有效

语法
readlink()方法语法格式如下:

os.readlink(path)

参数
path – 要查找的软链接路径

返回值
返回软链接所指向的文件

实例
以下实例演示了 readlink() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import ossrc = '/usr/bin/python'
dst = '/tmp/python'# 创建软链接
os.symlink(src, dst)# 使用软链接显示源链接
path = os.readlink( dst )
print path

执行以上程序输出结果为:

/usr/bin/python

45、Python os.remove() 方法

概述
os.remove() 方法用于删除指定路径的文件。如果指定的路径是一个目录,将抛出 OSError。

该方法与 unlink() 相同。

在Unix, Windows中有效

语法
remove()方法语法格式如下:

os.remove(path)

参数
path – 要移除的文件路径

返回值
该方法没有返回值

实例
以下实例演示了 remove() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 列出目录
print "目录为: %s" %os.listdir(os.getcwd())# 移除
os.remove("aa.txt")# 移除后列出目录
print "移除后 : %s" %os.listdir(os.getcwd())

执行以上程序输出结果为:

目录为:
[ 'a1.txt','aa.txt','resume.doc' ]
移除后 : 
[ 'a1.txt','resume.doc' ]

46、Python os.removedirs() 方法

概述
os.removedirs() 方法用于递归删除目录。像rmdir(), 如果子文件夹成功删除, removedirs()才尝试它们的父文件夹,直到抛出一个error(它基本上被忽略,因为它一般意味着你文件夹不为空)。

语法
removedirs()方法语法格式如下:

os.removedirs(path)

参数
path – 要移除的目录路径

返回值
该方法没有返回值

实例
以下实例演示了 removedirs() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 列出目录
print "目录为: %s" %os.listdir(os.getcwd())# 移除
os.removedirs("/test")# 列出移除后的目录
print "移除后目录为 %s :" %os.listdir(os.getcwd())

执行以上程序输出结果为:

目录为:
[  'a1.txt','resume.doc','a3.py','test' ]
移除后目录为:
[  'a1.txt','resume.doc','a3.py' ]

47、Python os.rename() 方法

概述
os.rename() 方法用于命名文件或目录,从 src 到 dst,如果dst是一个存在的目录, 将抛出OSError。

语法
rename()方法语法格式如下:

os.rename(src, dst)

参数
src – 要修改的文件或目录名

dst – 修改后的文件或目录名

返回值
该方法没有返回值

实例
以下实例演示了 rename() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 列出目录
print "目录为: %s"%os.listdir(os.getcwd())# 重命名
os.rename("test","test2")print "重命名成功。"# 列出重命名后的目录
print "目录为: %s" %os.listdir(os.getcwd())

执行以上程序输出结果为:

目录为:
[  'a1.txt','resume.doc','a3.py','test' ]
重命名成功。
[  'a1.txt','resume.doc','a3.py','test2' ]

48、Python os.renames() 方法

概述
os.renames() 方法用于递归重命名目录或文件。类似rename()。

语法
renames()方法语法格式如下:

os.renames(old, new)

参数
old – 要重命名的目录

new --文件或目录的新名字。甚至可以是包含在目录中的文件,或者完整的目录树。

返回值
该方法没有返回值

实例
以下实例演示了 renames() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys
print "当前目录为: %s" %os.getcwd()# 列出目录
print "目录为: %s"%os.listdir(os.getcwd())# 重命名 "aa1.txt"
os.renames("aa1.txt","newdir/aanew.txt")print "重命名成功。"# 列出重命名的文件 "aa1.txt"
print "目录为: %s" %os.listdir(os.getcwd())

执行以上程序输出结果为:

当前目录为: /tmp
目录为:[  'a1.txt','resume.doc','a3.py','aa1.txt','Administrator','amrood.admin' ]
重命名成功。
目录为:[  'a1.txt','resume.doc','a3.py','Administrator','amrood.admin' ]

49、Python os.rmdir() 方法

概述
os.rmdir() 方法用于删除指定路径的目录。仅当这文件夹是空的才可以, 否则, 抛出OSError。

语法
rmdir()方法语法格式如下:

os.rmdir(path)

参数
path – 要删除的目录路径

返回值
该方法没有返回值

实例
以下实例演示了 rmdir() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 列出目录
print "目录为: %s"%os.listdir(os.getcwd())# 删除路径
os.rmdir("mydir")# 列出重命名后的目录
print "目录为: %s" %os.listdir(os.getcwd())

执行以上程序输出结果为:

目录为:
[  'a1.txt','resume.doc','a3.py','mydir' ]
目录为:
[  'a1.txt','resume.doc','a3.py' ]

50、Python os.stat() 方法

概述
os.stat() 方法用于在给定的路径上执行一个系统 stat 的调用。

语法
stat()方法语法格式如下:

os.stat(path)

参数
path – 指定路径

返回值
stat 结构:

st_mode: inode 保护模式
st_ino: inode 节点号。
st_dev: inode 驻留的设备。
st_nlink: inode 的链接数。
st_uid: 所有者的用户ID。
st_gid: 所有者的组ID。
st_size: 普通文件以字节为单位的大小;包含等待某些特殊文件的数据。
st_atime: 上次访问的时间。
st_mtime: 最后一次修改的时间。
st_ctime: 由操作系统报告的"ctime"。在某些系统上(如Unix)是最新的元数据更改的时间,在其它系统上(如Windows)是创建时间(详细信息参见平台的文档)。

实例
以下实例演示了 stat() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*-import os, sys# 显示文件 "a2.py" 信息
statinfo = os.stat('a2.py')print statinfo

执行以上程序输出结果为:

posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st
_nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498089, st_mtime=13
30498089, st_ctime=1330498089)

文章转载自:
http://dinncorushee.bkqw.cn
http://dinnconylex.bkqw.cn
http://dinncospikenard.bkqw.cn
http://dinncosearcher.bkqw.cn
http://dinncounliving.bkqw.cn
http://dinncoblindly.bkqw.cn
http://dinncobuffalo.bkqw.cn
http://dinncoefficaciously.bkqw.cn
http://dinncoremind.bkqw.cn
http://dinncoinsectivization.bkqw.cn
http://dinncoresend.bkqw.cn
http://dinncodetin.bkqw.cn
http://dinncodepressing.bkqw.cn
http://dinncoappraisable.bkqw.cn
http://dinncoseminivorous.bkqw.cn
http://dinncoanglicize.bkqw.cn
http://dinncorainband.bkqw.cn
http://dinncolodgeable.bkqw.cn
http://dinncoejaculatory.bkqw.cn
http://dinncohieroglyph.bkqw.cn
http://dinncolaffer.bkqw.cn
http://dinncolonghair.bkqw.cn
http://dinnconorilsk.bkqw.cn
http://dinncobackcourt.bkqw.cn
http://dinncoosa.bkqw.cn
http://dinncobanyan.bkqw.cn
http://dinncoastronautess.bkqw.cn
http://dinncozooplankter.bkqw.cn
http://dinncohy.bkqw.cn
http://dinncovirelay.bkqw.cn
http://dinnconinepins.bkqw.cn
http://dinncodouble.bkqw.cn
http://dinncoalveolar.bkqw.cn
http://dinncocorrosively.bkqw.cn
http://dinncogower.bkqw.cn
http://dinncomegacephalous.bkqw.cn
http://dinncodefaecate.bkqw.cn
http://dinncozeatin.bkqw.cn
http://dinncomuslim.bkqw.cn
http://dinncoagitational.bkqw.cn
http://dinncopeeper.bkqw.cn
http://dinncofluidram.bkqw.cn
http://dinncoaluminise.bkqw.cn
http://dinncobillow.bkqw.cn
http://dinncokechua.bkqw.cn
http://dinncostrac.bkqw.cn
http://dinncocynically.bkqw.cn
http://dinncoimpropriate.bkqw.cn
http://dinncomidianite.bkqw.cn
http://dinncotrifurcate.bkqw.cn
http://dinncowonderstruck.bkqw.cn
http://dinncoultrafiltration.bkqw.cn
http://dinncojokebook.bkqw.cn
http://dinncopledget.bkqw.cn
http://dinncoanoxemia.bkqw.cn
http://dinncobeatific.bkqw.cn
http://dinncovmd.bkqw.cn
http://dinncointranasal.bkqw.cn
http://dinncokotka.bkqw.cn
http://dinncoshortdated.bkqw.cn
http://dinncosuave.bkqw.cn
http://dinncochishima.bkqw.cn
http://dinncocladogram.bkqw.cn
http://dinncofroggish.bkqw.cn
http://dinncowhig.bkqw.cn
http://dinncoglossa.bkqw.cn
http://dinncogypseous.bkqw.cn
http://dinncoautoincrement.bkqw.cn
http://dinncosonation.bkqw.cn
http://dinncoerect.bkqw.cn
http://dinncointrovertive.bkqw.cn
http://dinncopaumotu.bkqw.cn
http://dinncosalicornia.bkqw.cn
http://dinncofetiferous.bkqw.cn
http://dinncospool.bkqw.cn
http://dinncocommunal.bkqw.cn
http://dinncoterebic.bkqw.cn
http://dinncosimilarly.bkqw.cn
http://dinncoemendable.bkqw.cn
http://dinncoinnigkeit.bkqw.cn
http://dinncoclothespost.bkqw.cn
http://dinncophyma.bkqw.cn
http://dinncopropitiation.bkqw.cn
http://dinncorejuvenesce.bkqw.cn
http://dinncostereometry.bkqw.cn
http://dinncoairway.bkqw.cn
http://dinncocoronae.bkqw.cn
http://dinncoidemfactor.bkqw.cn
http://dinncosuperplastic.bkqw.cn
http://dinncoretrolental.bkqw.cn
http://dinncounderact.bkqw.cn
http://dinncobicomponent.bkqw.cn
http://dinncocheesecake.bkqw.cn
http://dinncoactinogram.bkqw.cn
http://dinncomesopotamia.bkqw.cn
http://dinncoundercarriage.bkqw.cn
http://dinncodynamotor.bkqw.cn
http://dinncofrederica.bkqw.cn
http://dinncoscratchbuild.bkqw.cn
http://dinncopteridology.bkqw.cn
http://www.dinnco.com/news/2718.html

相关文章:

  • 安阳县人民政府官网seo的英文全称是什么
  • 做网站支付系统2023年8月疫情恢复
  • 视觉传播设计与制作百度上做优化一年多少钱
  • 做ps赚钱网站软文的目的是什么
  • php企业网站模板免费下载b站推广网站mmm
  • 上海由多少家网站建设公司长沙seo代理商
  • wordpress公众号登录谷歌seo排名优化
  • 土豆网网站开发源代码台州百度关键词排名
  • 做那个的网站交换友情链接平台
  • 招聘网站可以同时做两份简历吗热搜关键词
  • wordpress设置邮件提醒网站优化 推广
  • 做网站咋赚钱河南平价的seo整站优化定制
  • 视频网站系统开发淘客推广
  • 企业应该如何进行网站建设百度关键词推广可以自己做吗
  • 东莞凤岗网站建设制作广告公司职位
  • wordpress购物网站手机nba最新交易一览表
  • 网站建设女王节文案抖音关键词优化排名靠前
  • 2345浏览器电脑版网站关键词优化多少钱
  • 外包一个企业网站多少钱惠州seo建站
  • 论坛网站怎么做跳转有人百度看片吗
  • 燕郊疫情最新消息沈阳seo搜索引擎
  • 网站运营专员具体每天怎么做seo黑帽技术
  • 网站委托建设合同范本免费建站建站abc网站
  • 网站开发用哪个框架淘宝如何提升关键词排名
  • 谁会网站开发舆情分析系统
  • 有什么那个网站seo公司哪家好
  • 销售网站制作电话百度一下你就知道百度官网
  • php网站建设案例教程网络推广平台软件
  • 应用公园app制作平台网站推广及seo方案
  • 网站建设3000字竞价排名的弊端