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

大连网站设计培训班杭州有哪些网络公司

大连网站设计培训班,杭州有哪些网络公司,学生做网站,绍兴易网网站开发#f open(raaa/a.txt,modert) # f的值是一种变量#xff0c;占用的是应用程序的内存空间,此时牵扯的是两个方面的资源#print(f)##2.操作文件#xff1a;读/写文件,应用程序对文件的读写请求都是向操作系统调用#xff0c;然后由操作系统控制把硬盘把输入读入内存…#f open(raaa/a.txt,modert) # f的值是一种变量占用的是应用程序的内存空间,此时牵扯的是两个方面的资源#print(f)##2.操作文件读/写文件,应用程序对文件的读写请求都是向操作系统调用然后由操作系统控制把硬盘把输入读入内存或者写入硬盘#resf.read()#print(res)#关闭文件 z#f.close()回收操作系统资源f 还存在#f变量还存在但是不能再读了#del f 回收应用程序程序资源#文件对象又称为文件句柄# with open(a.txt,modert) as f1:# resf1.read()# print(res)# with open(a.txt,modert) as f1,open(b.txt,modert) as f2:# res1f1.read()# res2f2.read()# print(res1)# print(res2)指定字符编码t 文本(默认的模式)1。 读写都是以str (unicode)为单位的2。文本文件3。必须指定encodingutf-8# 没有指定encoding 参数操作系统会使用自己的默认的编码# Linux 和mac 默认使用utf-8# Windows默认gbk# with open (c.txt,modert,encodingutf-8) as f:# resf.read() #t模式会将f.read()读出来的结果解码成unicode# print(res,type(res))##内存utf-8格式的二进制----解码---unicode#硬盘(c.txt 内容 utf-8格式的二进制)#以t 模式为基础进行内存操作##1.rt在本python文件的目录下创建一个name.txt的文本文件izhan:1005inp_username input(please input your name:).strip()inp_password input(please input your password:).strip()with open(name.txt,modert,encodingutf-8) as f:resf.read()print(res)username,passwordres.split(:)print(username)print(password)print(inp_username)print(inp_password)if inp_username username and inp_password password:print(congratulations! you can login)else:print(sorry! the password is wrong or has no this user)please input your name:izhanplease input your password:1005izhan1005izhan1005congratulations! you can login随便输入看看please input your name:dandanplease input your password:0711izhan1005dandan0711sorry! the password is wrong or has no this userProcess finished with exit code 0再创建一个name.txt 文件izhan:1005lili:1111dandan:0711另外python spit 的学习https://www.cnblogs.com/clairedandan/p/10926173.htmlinp_username input(please input your name:).strip()inp_password input(please input your password:).strip()with open(name.txt,modert,encodingutf-8) as f:for line in f:print(line,end) # 没有end,结果就会一行一行中间有一行空的。username,passwordline.strip().split(:)# print(username)# print(password)if inp_username username and inp_password password:print(login successfully)breakelse:print(账号错误)please input your name:liliplease input your password:0711izhan:1005lili:1111dandan:0711账号错误Process finished with exit code 0please input your name:izhanplease input your password:1005izhan:1005login successfullyProcess finished with exit code 0w:只写模式当文件不存在时会创造空文件当文件存在时会清空文件# with open(d.txt,modewt,encodingutf-8) as f:# # f.read()报错不可读# f.write(hahaha\n)# f.write(hello\n)# f.write(wwwwww\n)##如果重新打开文件则会清空之前的内容如果连续write则会连续写的3.a 只追加写# with open(a.txt,modeat,encodingutf-8) as f:# # f.read() 不能读# f.write(hahahahah\n)# f.write(enenenenen\n)# f.write(oooooo\n)a 重新打开文件不会清空文件内容会将文件指针直接移动到末尾a 文件一直用作记录日志注册功能a 模式注册功能# nameinput(please input your name:)# pwdinput(please input your password:)# with open(db.txt,modeat,encodingutf-8) as f:# f.write({}:{}\n.format(name,pwd))w 可以用做文本文件的copywith open(e.txt,modert,encodingutf8)as f1,\open(f.txt,modewt,encodingutf-8)as f2:resf1.read()f2.write(res)src_fileinput(源文件文件)dst_fileinput(目标文件)with open(r{}.format(src_file),modert,encodingutf8)as f1,\open(r{}.format(dst_file),modewt,encodingutf-8)as f2:resf1.read()f2.write(res)/usr/local/bin/python3.8 /Users/futantan/PycharmProjects/S14/文件知识/文件处理.py源文件文件/Users/futantan/PycharmProjects/S14/文件知识/a.txt目标文件/Users/futantan/PycharmProjects/S14/a_copy.txtProcess finished with exit code 0此时就可以发现有一个copy的文件了标签txt,python,res,--,详解,mode,print,input,password来源 https://www.cnblogs.com/clairedandan/p/14105609.html
http://www.yutouwan.com/news/52949/

相关文章:

  • 廉江手机网站建设公司开发公司清除地上树木侵犯了谁的权利
  • 设计参考图哪个网站好怎样制作静态网站
  • 电商初学者wordpress seo插件哪个好
  • 手机网站建设哪家好wordpress 清除
  • 生物科技公司网站模板flash网站源文件下载
  • 做网站运营需要学什么条件如何网上销售自己的产品
  • 网站发展趋势和前景wordpress 医院主题
  • 网站开发心得做网站服务器什么配置
  • 佛山公司网站设计需要网站建设
  • 网站建设的公司系统规划哈尔滨seo优化客户
  • 重庆市公路建设网站怎么上百度推广产品
  • 开设类似于京东商城这类购物网站安卓手机下载app的软件
  • 珠海医疗网站建设公司排名wordpress js在哪
  • 凡科轻站小程序制作平台开发公司质量管理制度体系的情况说明
  • 黄冈网站建设哪家好gooood设计网
  • 有没有专门做渔具的网站做淘宝网站多少钱
  • 网站维护工作内容始兴县建设局网站
  • 免费做电子邀请涵的网站南京网站开发公司哪家好
  • 做网站和c 哪个好甘肃省住房和城乡建设部网站首页
  • 网站建设需要编程吗网页版聊天软件
  • 自建站怎么搭建线上广告平台
  • 线圈 东莞网站建设wordpress如何设置友情链接
  • 信息图表设计网站网页设计排版布局图片
  • 建站教程新手怎么做网站phpwordpress怎么在首页添加友情链接
  • 南通网站建设方案书英文网站建设运营
  • 贵港网站建设代理网站免费观看永久视频下载
  • 使用ftp修改网站图片成都网络营销精英
  • 西安网站免费制作廊坊营销型网站建设
  • 河北平台网站建设价位织梦做的网站_别人提交给我留的言我去哪里看
  • 如何设置免费网站域名买了怎么做网站