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

威海建设集团网站首页自己建的网站也要注册域名吗

威海建设集团网站首页,自己建的网站也要注册域名吗,开发微信公众平台,无锡网络营销推广目录 文件操作 打开文件 读数据 写数据 关闭文件 文件读写实例 文件写 文件读 读数据类型 备份文件 os模块 目录的具体操作 文件操作 在Python中操作文件记录信息的步骤#xff1a; #xff08;1#xff09;打开文件#xff0c;或新建一个文件#xff1b; o…目录 文件操作 打开文件 读数据 写数据 关闭文件 文件读写实例 文件写 文件读 读数据类型 备份文件 os模块 目录的具体操作 文件操作 在Python中操作文件记录信息的步骤 1打开文件或新建一个文件 open() 2读取或写入数据内容 read() / write() 3关闭文件。 close() 打开文件 函数名含义open(name, mode)创建一个新文件或打开一个已经存在的文件name指的是文件名mode指的是访问模式。 常见的mode访问模式有 模式描述r以读数据的方式打开文件这是默认模式可以省略。rb以读二进制原始数据的方式打开文件。w以写数据的方式打开文件。如果文件已存在则打开文件写入数据是会覆盖原有内容。如果文件不存在则创建新文件。wb以写二进制原始数据的方式打开文件。a使用追加内容形式打开一个文件。通常用于写数据此时会把新内容写入到已有内容后。 说明 1访问模式r表示read即读 2访问模式w表示write即写。 读数据 该文件必须存在 函数名含义read()从某文件中一次性读完整的数据。readlines()按行的方式把文件中的完整内容进行一次性读取并返回一个列表。readline()一行一行读文件中的数据内容。 说明 当访问模式有r时可以读数据。 写数据 函数名含义write(seq)给某文件写数据。 说明 1当访问模式有w时可以写数据 2当使用访问模式a时用于追加数据内容也可以写入数据。 关闭文件 函数名含义close()关闭文件。 文件读写实例 文件写 # 1 普通写 # # 1.1 打开文件 writer open(./file/a_hello.txt, w) # 默认写, 覆盖效果 # # # 1.2 操作文件 writer.write(hello) writer.write(\nworld) # # # 1.3 关闭文件 writer.close()# 2 写 追加 # # 2.1 打开文件 writer open(./file/a_hello.txt, a) # a, append 追加 # # # 2.2 操作文件 writer.write(\nhello python) writer.write(\nhello hadoop)# # 2.3 关闭文件 writer.close()# 3 写 中文 # # 3.1 打开文件 writer open(./file/a_hello.txt, w, encodingutf-8) # a, append 追加 # # # 3.2 操作文件 writer.write(黑马程序员) writer.write(\n传智播客) # # # 3.3 关闭文件 writer.close()# 4 简化 with open(./file/b_hello.txt, w, encodingutf-8) as writer:writer.write(黑马程序员)writer.write(\n传智播客)writer.write(\n字节跳动) 文件读 # # 1.2 读取文件 content reader.read() print(content) # # # 1.3 关闭文件 reader.close()# 2 读 中文 # # 2.1 打开文件 reader open(./file/b_hello.txt, r, encodingutf-8) # # # 2.2 读取文件 content reader.read() print(content) # # # 2.3 关闭文件 reader.close() 读数据类型 函数名含义readlines()按行的方式把文件中的完整内容进行一次性读取并返回一个列表。readline()一行一行读文件中的数据内容。read从某文件中一次性读完整的数据。 # 3 读 简化 with open(./file/b_hello.txt, r, encodingutf-8) as reader:content reader.read()print(content)# 4 读 一次读取所有的行 with open(./file/b_hello.txt, r, encodingutf-8) as reader:lines reader.readlines()print(lines)print(type(lines))print(- * 50)for line in lines:print(line, end)# 5 读 一次读取一行 with open(./file/b_hello.txt, r, encodingutf-8) as reader:line reader.readline()print(line, end)print(type(line))print(len(line))print(- * 50)line reader.readline()print(line, end)print(type(line))print(len(line))print(- * 50)line reader.readline()print(line, end)print(type(line))print(len(line))print(- * 50)line reader.readline()print(line, end)print(type(line))print(len(line))print(- * 50)line reader.readline()print(line, end)print(type(line))print(len(line))print(- * 50)# 5.2 读 优化 一次读取一行 with open(./file/b_hello.txt, r, encodingutf-8) as reader:while True:line reader.readline()if len(line) 0:breakprint(line, end)备份文件 将原文件的数据内容进行重新写入到另一个新文件中。 # 目标6: r vs rb 的区别 with open(./file/b_hello.txt, r, encodingutf-8) as reader:content reader.read()print(content)print(type(content))print(- * 100)with open(./file/b_hello.txt, rb) as reader:content reader.read()print(content)print(type(content))# 目标7: 备份 with open(./file/b_hello.txt, r, encodingutf-8) as reader, open(./file/b_hello[备份].txt, w, encodingutf-8) as writer:# 合并式# writer.write(reader.read())# 分解式content reader.read()writer.write(content)with open(./file/c.mp4, rb) as reader, open(./file/c[备份].mp4, wb) as writer:# 合并式# writer.write(reader.read())# 分解式content reader.read()writer.write(content) os模块 Python中的os模块包含有操作系统所具备的功能如查看路径、创建目录、显示文件列表等。 # 导入os模块 import os 在Python中os模块的常用函数分为两类 a通过os.path调用的函数 b通过os直接调用的函数 在Python的os模块中通过os.path常用函数 函数名含义exists(pathname)用来检验给出的路径是否存在。isfile(pathname)用来检验给出的路径是否是一个文件。isdir(pathname)用来检验给出的路径是否是一个目录。abspath(pathname)获得绝对路径。join(pathname,name)连接目录与文件名或目录。basename(pathname)返回单独的文件名。dirname(pathname)返回文件路径。 # 1在某目录下手动新建day05/file目录与day05/file/hello.txt文件 # 2判断file/hello.txt是否存在、是否是文件、是否是目录、获取绝对路径名、获取单独的文件名 # 3执行程序观察效果。 import os # # path ./file/a_hello.txt path D:/0000_资料分享/01_大数据/07_python/代码/pythonProject3/pythonProject_2/day05/file/a_hello.txt # print(os.path.exists(path)) # True print(os.path.isfile(path)) # True print(os.path.isdir(path)) # False # print(os.path.abspath(path)) # D:\0000_资料分享\01_大数据\07_python\代码\pythonProject3\pythonProject_2\day05\file\a_hello.txt print(os.path.basename(path)) # a_hello.txt print(os.path.dirname(path)) # ./fileimport os# 1获取当前工作目录 print(os.getcwd()) # D:\0000_资料分享\01_大数据\07_python\代码\pythonProject3\pythonProject_2\day05# 2获取day05/file下的文件或目录列表信息 path ./file result os.listdir(path) print(result) print(type(result)) for e in result:print(e)# 3思考若要在file下新建hello/world/python目录该怎么做呢 path ./file/hello/world/pythonif not os.path.exists(path):os.makedirs(path) 目录的具体操作 函数名含义getcwd()获得当前工作目录即当前Python脚本工作的目录路径。system(name)运行shell命令。listdir(path)返回指定目录下的所有文件和目录名即获取文件或目录列表。mkdir(path)创建单个目录。makedirs(path)创建多级目录。remove(path)删除一个文件。rmdir(path)删除一个目录。rename(old, new)重命名文件。
http://www.sczhlp.com/news/214039/

相关文章:

  • 4060显卡也能玩转AI改图!Flux.1 Kontext Dev GGUF版本超详细入门教程 - 实践
  • P7521 [省选联考 2021 B 卷] 取模 分析
  • Tuack 生成比赛题目 PDF 笔记
  • 在 wrapper 类里实现重载方法
  • DeviceNet 转 Ethernet/IP:三菱 Q 系列 PLC 与欧姆龙 CJ2M PLC 在食品饮料袋装生产线包装材料余量预警的通讯配置案例
  • 如何提高网站收录量关键词在线挖掘网站
  • 收录网站制作大连小程序定制
  • 014最新电影网站源码程序|自动采集|一键采集|静态生成|联盟利器wordpress+优化速度
  • 查询建设用地规划许可证在哪个网站广西seo公司有哪些
  • 网站主机设置方法做网站需要绑定电脑ip吗
  • 媒体查询做响应式网站青岛网站优化排名
  • 东台网站设计问卷调查网站哪个好
  • ps做专业网站进入公众号继续阅读下一章
  • 网站商城建设需求表平台推广公众平台营销
  • 江西商城网站建设公司建设网站的具体步骤
  • 算命 网站开发台州网站建设方案托管
  • 电子商务专业网站建设wordpress付费可见
  • 使用c++14标准实现函数注册包装
  • 正规刷手机单做任务网站水源logo设计制作网
  • 结对项目-实现一个自动生成小学四则运算题目的命令行程序
  • 免费学编程的网站有哪些怎么制作微信链接
  • 网站源码怎么做wordpress和jwplayer
  • 网站页面图片尺寸wordpress无法安装500
  • 破解WordPress站点网站开发学习步骤
  • 内江 网站建设合肥论坛网站建设
  • 网站建设的计划国家建筑信息管理平台
  • 电商店铺图片邵阳网站seo
  • 购物网站开发django十大待遇最好央企
  • 怎么做垂直门户网站做网站的技术难点
  • 城乡建设网站网站建设 方案 评价表