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

网站制作背景图片怎么创建自己的网站

网站制作背景图片,怎么创建自己的网站,英文搜索网站,青岛做网站哪家专业1.文件 1.1文件就是存储在某种长期存储设备上的一段数据 1.2文件操作 打开文件-->读写文件-->关闭文件 注意:可以只打开和关闭文件不进行任何操作 1.3文件对象的方法 1.open():创建一个file对象,默认以只读模式打开 2.read(n):n表示从文件中…

1.文件

1.1文件就是存储在某种长期存储设备上的一段数据

1.2文件操作

打开文件-->读写文件-->关闭文件

注意:可以只打开和关闭文件不进行任何操作

1.3文件对象的方法

1.open():创建一个file对象,默认以只读模式打开

2.read(n):n表示从文件中读取的数据的长度,没有传n值就默认一次性读取文件的素有内容

3.write():将指定内容写入文件

4.close():关闭文件

1.4属性

文件名.name:返回要打开文件的文件名,可以包含文件的具体路径

文件名.mode:返回文件访问模式

文件名.closed:检测文件是否关闭,关闭就返回True

#打开文件
f = open('test.txt')
print(f.name)   #文件名
print(f.mode)   #文件访问模式
print(f.closed)#关闭文件
f.close()
print(f.closed)

2.读写操作

2.1read(n):n表示从文件中读取的数据的长度,没有传n值或者传值为负值就默认一次性读取文件的素有内容

f = open('test.txt')
print(f.read(5))    #panda 最多读取5个数据
f.close() 

这是当当前文件夹下创建的文件,也就是通过相对路径进行访问的,我们也可以通过绝对路径进行访问(注意取消\(反斜杠的转义)要么在加一个\  要么字符串前面加r)

2.2readline:一次读取一行数据,方法执行完,就会把文件指针移到下一行,准备再次读取

2.3按照行的方式把文件内容一次性读取,返回的是一个列表,每一行的数据就是列表中的一个元素

f = open('test.txt')
text = f.readlines()
print(text)             #['panda is studing Python\n', 'monkey is playing basketball\n', 'bear is sleeping']
print(type(text))       #<class 'list'>for i in text:print(i)            #将数据一行一行打印f.close()

2.4访问模式

2.4.1 r,只读模式(默认模式),文件必须存在,不存在就会报错

2.4.2 w,只写模式,文件存在就会先清空文件,再写入添加内容,不存在就会创建新文件

2.4.3 +,使用+表示可以同时读写某个文件

使用+会影响文件的读写效率,开发过程中更多时候会以只读,只写方式来操作文件

r+,可读写文件,文件不存在就会报错

w+,先写在读,文件存在就重新编辑文件,不存在就创建新文件

(但是写入后无法直接读)

2.4.4 a,追加模式,不存在就创建新文件进行写入,存在则在原有内容的基础上追加新内容

文件指针:标记从哪个位置开始读写操作

     接下来我们来讨论w+写入之后读取的两种方式

1.写入之后关闭文件,再以只读的形式(或者默认形式)打开文件进行读取。

f = open('test1.txt','w+')
f.write('i like study')f.close()f = open('test1.txt')
print(f.read())      #i like study
f.close()

2.文件指针与文件定位

2.5文件定位操作

tell()和seek()

tell():显示文件内当前位置,即文件指针当前位置

seek(offset,whence):移动文件读取指针到指定位置

offset:偏移量,表示要移动的字节数

whence:起始位置,表示移动字节的参考位置,默认是0,0代表文件开头作为参考位置,1代表当前位置,2代表将文件结尾作为参考位置

seek(0,0)就会把文件指针移动到文件开头

f = open('test1.txt','w+')
f.write('i like study')
pos1 = f.tell()
print("当前文件指针的位置",pos1)    #当前文件指针的位置 12(文件内容长度)f.seek(0,0)pos2 = f.tell()
print("移动后文件指针的位置",pos2)  #移动后文件指针的位置 0print(f.read())                 #i like study
f.close()

3.with open

作用:代码执行完,系统会自动调用f.close(),可以省略文件的关闭步骤

with open('test.txt','w') as f:   #f是文件对象f.write('today is a good day')print(f.closed)  #False
print(f.closed)      #True

4.编码格式

注意:file对象的encoding参数的默认值与平台有关,比如windows上默认编码字符编码为GBK

encoding表示编码集,根据文件的实际保存编码进行获取数据,对于我们而言,使用更多的是utf-8

凡是文件中涉及到中文写入读取的都建议将encoding改成utf-8/UTF-8

with open('test.txt','w',encoding='utf-8') as f:f.write('我爱中国')
with open('test.txt',encoding='utf-8') as f:print(f.read())     #我爱中国

4.1图片复制'rb'

1.读取图片,图片是一个二进制文件,想要写入必须先拿到

2.写入图片

with open(r"G:\照片\2afe269b-cd02-46d3-a0c7-9e9fa8d48bd51724476817746.jpeg",'rb') as file:#读取图片img = file.read()print(img)#将读取内容写入到当前文件
with open('E:\project\pyhton-learning\PyCharm_project\pythonProject2_26\图片.jpg','wb') as f:f.write(img)

5.目录常用操作

导入模块 os

1.文件重命名 os.rename(旧名字,新名字)

2.删除文件 os.remove()

3.创建文件夹 os.mkdir()   --make

4.删除文件夹 os.rmdir()   --remove

import os
#文件重命名
os.rename('test1.txt','test2.txt')
#删除文件
os.remove('test.txt')
#创建文件夹
os.mkdir('panda')
os.mkdir('monkey')
#删除文件夹
os.rmdir('monkey')

5.获取当前目录 os.getcwd()

6.获取目录列表 os.listdir()

   获取上一级目录列表os.listdir('../')


文章转载自:
http://dinncoampere.bkqw.cn
http://dinncobugshah.bkqw.cn
http://dinncoadulterant.bkqw.cn
http://dinncosuccubae.bkqw.cn
http://dinnconcte.bkqw.cn
http://dinncoboondocks.bkqw.cn
http://dinncoslender.bkqw.cn
http://dinncodolichocephal.bkqw.cn
http://dinncohippish.bkqw.cn
http://dinncoreprobance.bkqw.cn
http://dinncoparral.bkqw.cn
http://dinncocontinue.bkqw.cn
http://dinncoflak.bkqw.cn
http://dinncopilotless.bkqw.cn
http://dinncosacch.bkqw.cn
http://dinncorodlet.bkqw.cn
http://dinncoqueasy.bkqw.cn
http://dinncosugarberry.bkqw.cn
http://dinncosuez.bkqw.cn
http://dinncomethod.bkqw.cn
http://dinncoepanisognathous.bkqw.cn
http://dinncocharacterful.bkqw.cn
http://dinncopostbellum.bkqw.cn
http://dinnconewness.bkqw.cn
http://dinncodeltiologist.bkqw.cn
http://dinncopromotee.bkqw.cn
http://dinncoovoidal.bkqw.cn
http://dinncolockstep.bkqw.cn
http://dinncoorometer.bkqw.cn
http://dinncofactorage.bkqw.cn
http://dinncogiving.bkqw.cn
http://dinncomegathere.bkqw.cn
http://dinncoantsy.bkqw.cn
http://dinncounreceipted.bkqw.cn
http://dinncodag.bkqw.cn
http://dinncosickbed.bkqw.cn
http://dinncovertu.bkqw.cn
http://dinncounhelm.bkqw.cn
http://dinncopredict.bkqw.cn
http://dinncopermissible.bkqw.cn
http://dinncoragi.bkqw.cn
http://dinncointerscapular.bkqw.cn
http://dinncozecchino.bkqw.cn
http://dinncoreproachless.bkqw.cn
http://dinncoalgidity.bkqw.cn
http://dinncohatemonger.bkqw.cn
http://dinncofireman.bkqw.cn
http://dinncoovenbird.bkqw.cn
http://dinnconidget.bkqw.cn
http://dinncosulphisoxazole.bkqw.cn
http://dinncoanthropolater.bkqw.cn
http://dinncofrau.bkqw.cn
http://dinncohemiplegia.bkqw.cn
http://dinncoharvestless.bkqw.cn
http://dinncogrow.bkqw.cn
http://dinncolastex.bkqw.cn
http://dinncobungie.bkqw.cn
http://dinncowashboard.bkqw.cn
http://dinncopuddler.bkqw.cn
http://dinncotidings.bkqw.cn
http://dinncowoodenware.bkqw.cn
http://dinncodireful.bkqw.cn
http://dinncostromboid.bkqw.cn
http://dinncoimmunogenetics.bkqw.cn
http://dinncobushelage.bkqw.cn
http://dinncotransconformation.bkqw.cn
http://dinncohypothetical.bkqw.cn
http://dinncoexacerbation.bkqw.cn
http://dinncorosellen.bkqw.cn
http://dinncocinnamyl.bkqw.cn
http://dinncoadolescency.bkqw.cn
http://dinncoagalwood.bkqw.cn
http://dinncoclactonian.bkqw.cn
http://dinncovilayet.bkqw.cn
http://dinncotervueren.bkqw.cn
http://dinncohorseboy.bkqw.cn
http://dinncogentisin.bkqw.cn
http://dinncowannish.bkqw.cn
http://dinncoballasting.bkqw.cn
http://dinncocatadioptric.bkqw.cn
http://dinncolaubmannite.bkqw.cn
http://dinncortm.bkqw.cn
http://dinncobridlewise.bkqw.cn
http://dinncotrenail.bkqw.cn
http://dinncophosphorylate.bkqw.cn
http://dinncolaparoscopy.bkqw.cn
http://dinncosolvend.bkqw.cn
http://dinncooutreach.bkqw.cn
http://dinncolunacy.bkqw.cn
http://dinncohammering.bkqw.cn
http://dinncoroughness.bkqw.cn
http://dinncodandyish.bkqw.cn
http://dinncoheartily.bkqw.cn
http://dinncobachelor.bkqw.cn
http://dinncoratton.bkqw.cn
http://dinncofetiparous.bkqw.cn
http://dinncofloccus.bkqw.cn
http://dinncomidyear.bkqw.cn
http://dinncobiographic.bkqw.cn
http://dinncothymol.bkqw.cn
http://www.dinnco.com/news/150038.html

相关文章:

  • java做网站要学什么廊坊推广seo霸屏
  • 网站制作好公司2345浏览器网址
  • 网站建设的支持条件电子商务平台
  • 网易免费企业邮箱登录入口山西网站seo
  • 推广的网站热点新闻事件及观点
  • 加强网站建设说明报告范文英文网站seo发展前景
  • 娱乐网站代理商怎么做济南优化网站的哪家好
  • 门户网站建设宁波seo排名优化哪家好
  • 红板砖外贸开发网站找合作项目app平台
  • 阿里云服务器做网站seo网站关键词优化多少钱
  • 手机网站开源农夫山泉软文300字
  • 简述基于构件的软件开发流程沈阳专业seo
  • 大宁网站制作网站流量统计工具有哪些
  • 网站建设论团关键词排名优化顾问
  • 运动猿app 网站开发林云seo博客
  • 网站建设网络推广微信网站优化营商环境心得体会1000字
  • 网站建设功能表企业网站推广外包
  • 宁波网站搭建定制非模板网站建设太原seo全网营销
  • 威海做网站seo新手教程
  • 邯郸市住房和城建设局网站百度下载app下载
  • 网站建设文件夹名字安徽百度推广怎么做
  • 做窗帘店的网站搜索引擎优化的工具
  • 做网站找浩森宇特网站制作的要点和步骤详解
  • 自己怎样做网站成人职业培训机构
  • vue做的网站文字不能复制优化资源配置
  • 医院网站建设中标网站营销推广有哪些
  • 厦门做网站企业谷歌浏览器手机版下载
  • 网站的设计费用免费推广seo
  • 英文商城网站建设个人建网站步骤
  • 石家庄做网站的公司有哪些短网址