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

不改域名和空间 只改网站类型万网官网登陆

不改域名和空间 只改网站类型,万网官网登陆,网站建设高端网站,app开发和网站建设区别目录 基本步骤 常用函数 open()函数 close()函数 read()函数 readlines()函数 readline()函数 write()函数 writelines()函数 with语句 读写操作的应用#xff1a; 拷贝文件 with 语句的嵌套 逐行拷贝 基本步骤 1. 打开文件#xff1a;open(filepath, mode, en…目录 基本步骤 常用函数 open()函数 close()函数 read()函数 readlines()函数 readline()函数 write()函数 writelines()函数 with语句 读写操作的应用 拷贝文件 with 语句的嵌套 逐行拷贝 基本步骤 1. 打开文件open(filepath, mode, encoding) 2. 读写文件read() / write() 3. 关闭文件close() python读取文件操作实例 f open(filename.txt, r, encodingutf-8) f.read() f.close() 常用函数 open()函数 open(file, moder, buffering-1, encodingNone, errorsNone, newlineNone, closefdTrue, openerNone) file是要打开的文件moder是打开文件的模式encoding是编码格式 文件的打开模式有以下字符表示 r       open for reading (default)     w       open for writing, truncating the file first     x       create a new file and open it for writing     a       open for writing, appending to the end of the file if it exists     b       binary mode     t       text mode (default)           open a disk file for updating (reading and writing) 打开模式还能连用 The default mode is rt (open for reading text). For binary random  access, the mode wb opens and truncates the file to 0 bytes, while rb opens the file without truncation. The x mode implies w and raises an FileExistsError if the file already exists. close()函数 close() method of _io.TextIOWrapper instance     Flush and close the IO object. This method has no effect if the file is already closed 打开文件必须有对应的关闭否则该未关闭的文件不能被其它的应用操作。 read()函数 read(size-1, /) method of _io.TextIOWrapper instance     Read at most size characters from stream. Read from underlying buffer until we have size characters or we hit EOF.     If size is negative or omitted, read until EOF. read()可选参数size可以用于读取“size”大小的数据返回的是字符串或字节对象若是size的值没有填写或者是个负值那么read()函数将读取文件的所有内容这也是用python开发pc软件中“复制黏贴”的功能比较常用的函数。 readlines()函数 Help on built-in function readlines: readlines(hint-1, /) method of _io.TextIOWrapper instance     Return a list of lines from the stream. hint can be specified to control the number of lines read: no more     lines will be read if the total size (in bytes/characters) of all     lines so far exceeds hint. readlines()函数是将文件当中的所有行一行一行地读取并逐一写入一个列表list内最终返回这个列表。 readline()函数 Help on built-in function readline: readline(size-1, /) method of _io.TextIOWrapper instance     Read until newline or EOF. Return an empty string if EOF is hit immediately.     If size is specified, at most size characters will be read. readline()函数就是读取一行数据用法除了size参数之外就跟read()差不多也是open()打开文件readline()读取数据close()关闭文件 write()函数 write(text, /) method of _io.TextIOWrapper instance     Write string s to stream. Return the number of characters written     (which is always equal to the length of the string). writelines()函数 writelines(lines, /) method of _io.TextIOWrapper instance     Write a list of lines to stream. Line separators are not added, so it is usual for each of the     lines provided to have a line separator at the end. with语句 通过with语句不管读取还是写入文件操作都不用写对应的close()函数语句块结束系统会自动关闭文件。 with open(filename.txt, r, encodingurf-8) as f:f.read() 读写操作的应用 拷贝文件 # 打开源文件以读取内容 with open(source.txt, r) as source_file: source_content source_file.read() # 打开目标文件以写入内容 with open(destination.txt, w) as destination_file: destination_file.write(source_content) with 语句的嵌套 以上两个with语句块还能嵌套写在一起 # 打开源文件以读取内容并同时打开目标文件以写入内容 with open(source.txt, r) as source_file: with open(destination.txt, w) as destination_file: # 读取源文件的内容 source_content source_file.read() # 将读取的内容写入到目标文件中 destination_file.write(source_content) 可以写在同一行 # 打开源文件以读取内容并同时打开目标文件以写入内容 with open(source.txt, r) as source_file, open(destination.txt, w) as destination_file: # 读取源文件的内容 source_content source_file.read() # 将读取的内容写入到目标文件中 destination_file.write(source_content) 逐行拷贝 如果源文件很大使用read()方法一次性读取所有内容可能会消耗较多的内存。对于大文件更推荐的做法是使用文件对象的迭代器逐行读取和写入这样可以减少内存的使用。 with open(source.txt, r) as source_file, open(destination.txt, w) as destination_file: # 逐行读取源文件并写入目标文件 for line in source_file: destination_file.write(line) 完
http://www.pierceye.com/news/883957/

相关文章:

  • 做网站用什么语音网站开发绪论
  • 中国建设银行徐州分行网站网站如何做视频教程
  • 烟台建站服务荥阳市建设局 网站
  • 网站备案登记推广网站案例
  • 企业网站设计论文摘要怎么写网络广告是什么意思
  • 自建站服务快应用 小程序
  • 上海网站建设过程邯郸网站建设推荐咨询
  • 公司有网站域名 如何做网站wordpress 字段
  • 做网站的类型东莞网页设计制作公司
  • 有品质的网站推广公司网站建设彩铃语
  • wordpress提示更新网站页面seo
  • 建设全国科技中心网站郑州百姓网官网
  • 漂亮网站wordpress 文章统计
  • 广西建设厅培训中心兰州seo网站排名
  • 布吉医院网站建设鞍山市网络销售平台
  • 开发一个网站系统报价wordpress文章摘要
  • 做脚本从网站引流外贸网站建设不可缺少的灵活性
  • 网站开发用linux好吗网站公司网站搭建
  • 网站数据库如何导入全自动引流推广软件app
  • 企业微网站案例响应式模板
  • 网站优化排名如何做网站纯色背景图怎么做
  • 医院网站设计方案长沙企业网站
  • 多页网站模板淘宝官网首页登录账号
  • 建设人员变更是哪个网站网络广告方案怎么写
  • 宠物网站 html模板长春城乡建设部网站首页
  • 电商网站设计线路图景县网站建设
  • 中级建设消防员证书查询网站昆明百度搜索排名优化
  • 网站广告是内容营销吗四川鸿业建设集团网站
  • 企业网站管理系统 aspwordpress幻灯片简码
  • 深圳建设银行官方网站上海搜索引擎优化1