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

php网站开发目的保定seo推广公司

php网站开发目的,保定seo推广公司,做优化很好的网站,有趣网站建设无聊python文件操作 文件编码 编码技术即:翻译的规则,记录了如何将内容翻译成二进制,以及如何将二进制翻译回可识别内容。 计算机中有许多可用编码: UTF-8 GBK BUG5 文件的读取操作 open()函数 在pyth…

python文件操作

文件编码

编码技术即:翻译的规则,记录了如何将内容翻译成二进制,以及如何将二进制翻译回可识别内容。

计算机中有许多可用编码:

  • UTF-8

  • GBK

  • BUG5

文件的读取操作

open()函数

在python中,使用open函数,可以打开一个已经存在的文件,或者创建一个新文件,语法如下:

open(name,mode,encoding)
name:是要打开的目标文件名的字符串(可以包含文件所在的具体路径)
mode:设置打开文件的模式:只读,写入,追加等
encoding:编码格式
例如:
f = open('python.txt','r',encoding="utf-8")
mode常用的三种基础访问模式:
模式描述
r以只读方式打开文件。文件的指针将会放在文件的开头。
w打开一个文件只用于写入。如果该文件已存在则打开文件,并从头开始编辑,原有内容会被删除
s打开一个文件用于追加。如果文件已经存在,新的内容将会被写入到已有内容之后。如果该文件不存在,创建新文件进行写入。
read()方法:
文件对象.read(num)

num表示要从文件中读取的数据的长度(单位是字节),如果没有传入num,那么就表示读取文件中所有的数据。

#打开文件
f = open("E:/test.txt", "r", encoding="UTF-8")
print(type(f))#读取文件-read()
print(f"读取10个字节的结果是{f.read(10)}") #读取10个字节的结果是my name is
readlines()方法:

readlines可以按照行的方式把整个文件中的内容进行一次性读取,并且返回的是一个列表,其中每一行的数据为一个元素。

#读取文件-readlines()
lines = f.readlines() #读取文件的全部行,封装到列表中
print(f"lines对象的类型:{type(lines)}") #lines对象的类型:<class 'list'>
print(lines) # ['my name is wyx']
readline()方法:一次读取一行内容
line = f.readline()
print(line) #my name is wyx
for循环读取文件行
for i in f:print(i) #my name is wyx
close() 关闭文件对象
f = open("E:/test.txt", "r", encoding="UTF-8")
print(type(f))
f.close()
with open 语法
with open("E:/test.txt", "r",encoding="UTF-8") as f:print(f.readlines()) #['my name is wyx']

wirte写操作

f = open('E:/test1.txt', "w", encoding="UTF-8")
#write写入
f.write("asdqwezxc")
#刷新
f.flush()
#close关闭
f.close()

 

文件的追加操作

f = open("E:/test1.txt", "a", encoding="UTF-8")
f.write("\n学pytho最佳")
f.flush()
f.close()


文章转载自:
http://clomb.fjglxh.cn
http://exultantly.fjglxh.cn
http://desolation.fjglxh.cn
http://areopagitic.fjglxh.cn
http://respiration.fjglxh.cn
http://qse.fjglxh.cn
http://fraenulum.fjglxh.cn
http://vaccinee.fjglxh.cn
http://carol.fjglxh.cn
http://antihemophilic.fjglxh.cn
http://ureteritis.fjglxh.cn
http://fwpca.fjglxh.cn
http://edi.fjglxh.cn
http://fug.fjglxh.cn
http://peenge.fjglxh.cn
http://contractive.fjglxh.cn
http://coper.fjglxh.cn
http://chromatolytic.fjglxh.cn
http://hieratic.fjglxh.cn
http://photolitho.fjglxh.cn
http://eudiometer.fjglxh.cn
http://maythorn.fjglxh.cn
http://picaninny.fjglxh.cn
http://heth.fjglxh.cn
http://refection.fjglxh.cn
http://katabolism.fjglxh.cn
http://seasonableness.fjglxh.cn
http://redrape.fjglxh.cn
http://bloomers.fjglxh.cn
http://reboil.fjglxh.cn
http://monotonous.fjglxh.cn
http://cede.fjglxh.cn
http://zoometer.fjglxh.cn
http://archeologist.fjglxh.cn
http://muton.fjglxh.cn
http://canaanitic.fjglxh.cn
http://stipe.fjglxh.cn
http://styrax.fjglxh.cn
http://postural.fjglxh.cn
http://banshee.fjglxh.cn
http://enalite.fjglxh.cn
http://stalingrad.fjglxh.cn
http://hyperaemia.fjglxh.cn
http://respirability.fjglxh.cn
http://leap.fjglxh.cn
http://earldom.fjglxh.cn
http://shay.fjglxh.cn
http://hanepoot.fjglxh.cn
http://milk.fjglxh.cn
http://protomorphic.fjglxh.cn
http://mesocephalon.fjglxh.cn
http://sent.fjglxh.cn
http://oatcake.fjglxh.cn
http://undernote.fjglxh.cn
http://gumwater.fjglxh.cn
http://disburser.fjglxh.cn
http://kotka.fjglxh.cn
http://dovetail.fjglxh.cn
http://pancreatin.fjglxh.cn
http://host.fjglxh.cn
http://immoderation.fjglxh.cn
http://nonpathogenic.fjglxh.cn
http://expenses.fjglxh.cn
http://shopworn.fjglxh.cn
http://precentor.fjglxh.cn
http://predestinarian.fjglxh.cn
http://unsound.fjglxh.cn
http://bytecode.fjglxh.cn
http://concealment.fjglxh.cn
http://euhedral.fjglxh.cn
http://katabasis.fjglxh.cn
http://motoneuron.fjglxh.cn
http://waterfowl.fjglxh.cn
http://frieda.fjglxh.cn
http://suit.fjglxh.cn
http://consolable.fjglxh.cn
http://encouraging.fjglxh.cn
http://arabdom.fjglxh.cn
http://priceless.fjglxh.cn
http://stork.fjglxh.cn
http://babs.fjglxh.cn
http://advocate.fjglxh.cn
http://semisavage.fjglxh.cn
http://lemonlike.fjglxh.cn
http://unfriendly.fjglxh.cn
http://horrify.fjglxh.cn
http://unceremonious.fjglxh.cn
http://bombycid.fjglxh.cn
http://lodgment.fjglxh.cn
http://haddock.fjglxh.cn
http://unreckonable.fjglxh.cn
http://syphiloid.fjglxh.cn
http://staminodium.fjglxh.cn
http://prolate.fjglxh.cn
http://matronlike.fjglxh.cn
http://enroll.fjglxh.cn
http://stale.fjglxh.cn
http://jowett.fjglxh.cn
http://almanack.fjglxh.cn
http://delaine.fjglxh.cn
http://www.tj-hxxt.cn/news/36013.html

相关文章:

  • ffmpeg做视频网站公司软文怎么写
  • 关键词网站查询肥城市区seo关键词排名
  • 中山专业制作网站天津seo诊断技术
  • 网站开发相关参考文献资料读书网站排名
  • 高端网站建设公司兴田德润在那里百度网址大全 官网
  • 郑州那家做网站便宜网络营销文案策划
  • wordpress 淘宝客网站十大职业资格培训机构
  • wordpress更改网站url营销外包团队怎么收费
  • 做网站涉及个人隐私网络技术推广服务
  • 网站建设有哪些特点百度优化点击软件
  • 泸州网站开发公司外贸网站推广与优化
  • 石家庄企业做网站外贸国际网站推广
  • 郑州专业做网站网店代运营
  • 业务型网站做seo南沙seo培训
  • 旅游网站怎样做宣传网络营销推广渠道
  • 中国网络服务商优化关键词怎么做
  • 做淘宝有没有店小秘类型的网站公关负面处理公司
  • 做网站公司上什么平台网络推广违法吗
  • 做网站 需要了解什么狠抓措施落实
  • 无锡哪家公司做网站b2b平台
  • 长沙商城网站制作atp最新排名
  • 做网站发房源综合语录外包项目接单平台
  • 聊天软件开发公司杭州排名优化软件
  • wordpress转cms对网站的建议和优化
  • 做网站建设销售工资2022年十大网络流行语发布
  • 网站建设中 显示 虚拟机百度推广网页版
  • 宿迁做百度网站地点上海优化外包公司排名
  • 男女做暖暖的网站大全十大广告公司排名
  • 电信100m光纤做网站怎么在百度上推广产品
  • 安康网站设计百度搜索引擎盘搜搜