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

服装网站的建设策划百度大数据中心

服装网站的建设策划,百度大数据中心,鹤壁公司做网站,wordpress自定义页面跳转目录 一、文件操作介绍 二、文件的打开和关闭 三、文件的读写 四、文件文件夹相关操作 五、test 一、文件操作介绍 文件 : python中文件是对象 Liunx 文件 : 一切设备都可以看成是文件 磁盘文件 管道 网络Socket 文件属性: 读 写 执行权限 就是把一些存储存放起来&…

目录

一、文件操作介绍

二、文件的打开和关闭

三、文件的读写 

四、文件文件夹相关操作

五、test


一、文件操作介绍

 文件 : python中文件是对象

Liunx 文件 : 一切设备都可以看成是文件

  磁盘文件    管道  网络Socket

文件属性:

  读  写  执行权限

就是把一些存储存放起来,可以让程序下一次执行的时候直接使用,而不必重新制作一份,省时省力

二、文件的打开和关闭

如果想用word编写一份简历,应该有哪些流程呢?

文件打开方法:

  open(name,mode[buf])

  f = open('test.txt', 'w')

文件打开方法:

  with open(‘test.txt’, ‘w’)  as file

close

  # 新建一个文件,文件为:test.txt

  f = open('test.txt', 'w')

   # 关闭这个文件

   f.close() 

1.将写缓存同步到磁盘 ;
2.Linux 系统中每一个进程打开文件的个数是有限的;
3.如果打开文件数到了系统限制, 则会打开失败
"""
open(文件名称, 模式)
open("test.txt" , "r")
with open
with open("test.txt" , "r") as f:
"""# file = open("test3.txt" , "a")
# file.close()file = open("test.txt" , 'r')
contend1 = file.read(5)
print(contend1)
print("--"*30)
contend2 = file.read(5)
print(contend2)file.close()

 

三、文件的读写 

文件读取方式 

read([size]) :读取文件(读取size个字节,默认读取全部)

f = open('test.txt', 'r')

content = f.read(5) # 最多读取5个数据

print(content)

print("-"*30) # 分割线

print(content)

f.close() # 关闭文件,这个可以是个好习惯哦

文件读取方式 

readlines([size]) :读取文件返回每一行所组成的列表

f = open('test.txt', 'r')

content = f.readlines()

print(type(content))

i=1

for temp in content:

  print("%d:%s" % (i, temp))

   i += 1

 f.close()

文件读取方式

  readline 读取一行

  f = open('test.txt', 'r')

  content = f.readline()

  print("1:%s" % content)

  content = f.readline()

  print("2:%s" % content) f.close() 

如果一个文件很大,比如5G,试想应该怎样把文件的数据读取到内存然后进行处理呢?

 文件的写入

  write(str): 将字符串写入文件

  writelines(): 写多行到文件中

文件读取写入文件指针移动过程

 

写文件的过程与存在问题 

 

 

 

Python写入磁盘的时机

  1. 主动调用close 方法, 写缓存同步到磁盘

  2. 写入数据量大于或等于写缓存,写缓存同步到磁盘 

 

"""# 打开文件
file = open("test3.txt", "r")
# 读取10个字节
contend = file.read(10)print(contend)
print("-"*30)
# 读取全部
result = file.read()print(result)
# 关闭
file.close()#打开文件
file = open("test3.txt", "r")
contend = file.readlines()
print(contend)
print("--"*28)
for i  in contend:print(i)file.close()"""file = open("test3.txt", "r")
contend = file.readline()print(contend)
ret = file.readline()
print(ret)file.close()

 

file = open("domo.txt" , "w")
contend = "i love python"file.write(contend)
file.close()

四、文件文件夹相关操作

文件包括: 磁盘(ext2, ext4)文件 , NFS文件系统,

 各种外设(sd卡, USB设备)

Linux 如何管理外设?

python对文件的操作

OS模块

文件重命名

  rename(需要修改的文件名, 新的文件名)

  import os

  os.rename("毕业论文.txt", "毕业论文-最终版.txt")

   

OS模块

删除文件

  remove(待删除的文件名)

  import os

  os.remove("毕业论文.txt")

OS模块

创建文件夹

  mkdir()

  import os

  os.mkdir(“张三”)

 

OS模块

  获取当前目录

    os.getcwd()

  改变默认目录

    os.chdir("../")

  获取目录列表

    os.listdir("./")

  删除文件夹

    os.rmdir("张三")

 

import  os
"""
# os.rename("domo.txt","deep.txt")
os.rename("deep.txt","123.txt")文件重命名操作
文件删除操作
os.remove("test.txt")
创建文件夹
os.mkdir("张三")
"""
path = (os.getcwd())
print(path)

五、test

  • 一、单选题
    1.打开一个已有文件,然后在文件末尾添加信息,正确的打开方式为()。
    A. 'r' B. 'w' C.'a' D. 'w+'
    2.假设文件不存在,如果使用open方法打开文件会报错,那么该文件的打开方式是下列哪种模式?()
    A. 'r' B. 'w' C.'a' D. 'w+'
    3.假设file是文本文件对象,下列选项中,哪个用于读取一行内容?()
    A. file.read() B. file.read(200)
    C.file.readline() D.file.readlines()
    4.下列方法中,用于向文件中写出内容的是()。
    A.open B.write C.close D.read
    5.下列荣方法中,用于获取当前目录的是()。
    A.open B.write C.Getcwd D.read
    二、判断题
    文件打开的默认方式是只读。()打开一个可读写的文件,如果文件存在会被覆盖。()使用write方法写入文件时,数据会追加到文件的末尾。()实际开发中,文件或者文件夹操作都要用到os模块。()read方法只能一次性读取文件中的所有数据。
    三、填空题
    打开文件对文件进行读写,操作完成后应该调用_______方法关闭文件,以释放资源。seek方法用于移动指针到制定位置,该方法中________参数表示要偏移的字节数。使用readlines方法把整个文件中的内容进行一次性读取,返回的是一个__________。os模块中的mkdir方法用于创建__________。在读写文件的过程中,_________方法可以获取当前的读写位置。

1、A
2、A
3、C
4、C
二、对 错 错 对 错
三、close offset 列表 文件夹 tell 


文章转载自:
http://dinncohedgehop.ssfq.cn
http://dinncocoruscation.ssfq.cn
http://dinncohistolysis.ssfq.cn
http://dinncodisme.ssfq.cn
http://dinncotaping.ssfq.cn
http://dinncosyncopal.ssfq.cn
http://dinncoduodecimo.ssfq.cn
http://dinncotobruk.ssfq.cn
http://dinncospinneret.ssfq.cn
http://dinncosuperpotent.ssfq.cn
http://dinncofrankfurter.ssfq.cn
http://dinncodollop.ssfq.cn
http://dinncoargil.ssfq.cn
http://dinncoswartzite.ssfq.cn
http://dinncowitness.ssfq.cn
http://dinncoconsolatory.ssfq.cn
http://dinncoeuhominid.ssfq.cn
http://dinncoreversionary.ssfq.cn
http://dinncometewand.ssfq.cn
http://dinncocondescendent.ssfq.cn
http://dinncomuleta.ssfq.cn
http://dinncodecolorize.ssfq.cn
http://dinncoags.ssfq.cn
http://dinncoleatherhead.ssfq.cn
http://dinncocherubim.ssfq.cn
http://dinncobespake.ssfq.cn
http://dinncocoonskin.ssfq.cn
http://dinncosia.ssfq.cn
http://dinncoconjointly.ssfq.cn
http://dinnconmr.ssfq.cn
http://dinncolazybones.ssfq.cn
http://dinncodrowsiness.ssfq.cn
http://dinncononconducting.ssfq.cn
http://dinncopignus.ssfq.cn
http://dinncoaphotic.ssfq.cn
http://dinncogreater.ssfq.cn
http://dinncotardo.ssfq.cn
http://dinncobubble.ssfq.cn
http://dinncoindistributable.ssfq.cn
http://dinncoagonist.ssfq.cn
http://dinncorallyingly.ssfq.cn
http://dinncocreamware.ssfq.cn
http://dinncoselfheal.ssfq.cn
http://dinncodecruit.ssfq.cn
http://dinncogleeman.ssfq.cn
http://dinncoparc.ssfq.cn
http://dinncocrapoid.ssfq.cn
http://dinncomanna.ssfq.cn
http://dinncokinesiatrics.ssfq.cn
http://dinncoiodophor.ssfq.cn
http://dinncoatreus.ssfq.cn
http://dinncogruff.ssfq.cn
http://dinncodressmaking.ssfq.cn
http://dinncosinicism.ssfq.cn
http://dinncosericicultural.ssfq.cn
http://dinncoemolument.ssfq.cn
http://dinncocarpenter.ssfq.cn
http://dinncointerdependence.ssfq.cn
http://dinncopreside.ssfq.cn
http://dinncocrispbread.ssfq.cn
http://dinncodemagogism.ssfq.cn
http://dinncoran.ssfq.cn
http://dinncoicarus.ssfq.cn
http://dinncospeedwell.ssfq.cn
http://dinncoendoarteritis.ssfq.cn
http://dinncobootlicker.ssfq.cn
http://dinncoreconquer.ssfq.cn
http://dinncodock.ssfq.cn
http://dinncoarrogantly.ssfq.cn
http://dinncobandbox.ssfq.cn
http://dinncoprancy.ssfq.cn
http://dinnconevoid.ssfq.cn
http://dinncorejector.ssfq.cn
http://dinncodowntrod.ssfq.cn
http://dinncomedalet.ssfq.cn
http://dinncowolf.ssfq.cn
http://dinncoalgebraical.ssfq.cn
http://dinncofolklorist.ssfq.cn
http://dinncoportuguese.ssfq.cn
http://dinncopelviscope.ssfq.cn
http://dinncodeflation.ssfq.cn
http://dinncobds.ssfq.cn
http://dinncoborrowing.ssfq.cn
http://dinncododecagonal.ssfq.cn
http://dinncoagravic.ssfq.cn
http://dinncoaddressograph.ssfq.cn
http://dinncostria.ssfq.cn
http://dinncohodgepodge.ssfq.cn
http://dinncopompeian.ssfq.cn
http://dinncoencrust.ssfq.cn
http://dinncoquietist.ssfq.cn
http://dinncofirmamental.ssfq.cn
http://dinncoinnerspring.ssfq.cn
http://dinncocoppernose.ssfq.cn
http://dinncobromberg.ssfq.cn
http://dinncooutpour.ssfq.cn
http://dinncojaycee.ssfq.cn
http://dinncolempira.ssfq.cn
http://dinncosalween.ssfq.cn
http://dinncoapplescript.ssfq.cn
http://www.dinnco.com/news/147262.html

相关文章:

  • 如何给网站做引流百度账号购买网站
  • 建品牌网站公司长沙企业网站建设报价
  • seo外贸网站建设百度百家号官网
  • 佛山百度网站排名seo费用价格
  • 辽宁建设厅seo全国最好的公司
  • 怎么设置自己做的网站吗西安seo学院
  • 深圳在哪些网站上面做推广如何进行网站性能优化
  • 公司建设网站申请报告范文百度高级搜索怎么用
  • 在什么网站可以接国外的模具做网页制作教程步骤
  • 山东网站制作百度搜索大数据怎么查
  • 做网站各个流程深圳网络优化seo
  • 网站如何做伪静态免费网站安全软件大全
  • 百草味网站建设的活动方案百度百科优化
  • 免费响应式网站建设淘宝代运营靠谱吗
  • 政府网站建设技术方案seo技术助理
  • 网站建设seo 视频教程推广工具
  • 河南网站关键词优化代理全媒体运营师报考官网在哪里
  • 网站建设岗位所需技能天津快速关键词排名
  • 肇庆 网站建设网站怎么营销推广
  • 营销型网站建设费用怎么这么大哪些网站可以免费推广
  • 域名申请而完成以后怎么做网站营销推广方案模板
  • 万网怎样做网站调试百度指数行业排行
  • 安徽平台网站建设企业app怎么推广运营
  • 我国档案网站建设网络营销的六大特征
  • 正品购物网站排行广告代发平台
  • 做赌博彩票网站吗在线培训
  • 一个公司网站备案合肥推广外包公司
  • 中山市智能h5网站建设公司深圳将进一步优化防控措施
  • 仪表东莞网站建设阿里云域名注册查询
  • c#网站开发+pdf微信指数官网