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

游戏网站开发名字百度搜索简洁版网址

游戏网站开发名字,百度搜索简洁版网址,怎么样百度搜到自己的网站,自己做微网站制作教程path方法常常用来访问一个文件所在的地址,然后将地址储存在变量中。然后有不同的方法将文件内容进行处理,还可以将文件进行创建。 from pathlib import Path pathPath(xxxxxxx) 1.文件读取操作 (1)txt文件 常用read_text()读取文件内容, …

path方法常常用来访问一个文件所在的地址,然后将地址储存在变量中。然后有不同的方法将文件内容进行处理,还可以将文件进行创建。

from pathlib import Path
path=Path('xxxxxxx')

1.文件读取操作

(1)txt文件

常用read_text()读取文件内容,

from pathlib import Path
path=Path('xxxxxx')
contexts=path.read_text()

读取内容后使用splitlines()方法获取文件的各行,返回的是一个包含文件各行的列表

from pathlib import Path
path=Path('xxxxxx')#txt文件存储位置
contexts=path.read_text()
lines=contexts.splitlines()

(2)json文件 

对于文件后缀为json文件(可以理解成加密的txt文件),读取时候我们Path进行文件地址访问,然后使用read_text()进行文件内容获取,然后将文件内容使用json.load()函数进行解析加载到内存中,方便我们访问内容(相当于文件解密),这样python就可以访问内容了。

from pathlib import Path
import json
path=Path('xxxxxx')#是json文件存储地址
contexts=path.read_text()
contents=json.load(contexts)

(3)csv文件 

对于一种特殊文件格式csv,文件阅读较为困难,使用机器进行阅读较为方便。因此,需要我们进行导入文件内容。文件打开同样使用Path方法,read_text()将文件读取,然后使用csv.reader()解析文件的各行,返回的各行的列表,对列表调用函数next()获取文件的下一行(相当于将列表文件从头开始进行按顺序检索)。

from pathlib import Path
import csv
path=Path('xxxxxx')#csv文件存储位置
contexts=path.read_text()
reader=csv.reader(contexts)
print(next(reader))

csv有种特殊的形式将每一行内容头打印出来,并加上索引。使用函数enumerate()处理将返回一个字典,索引和每一行的头。

from pathlib import Path
import csv
path=Path('xxxxxx')#csv文件存储位置
contexts=path.read_text()
reader=csv.reader(contexts)
for key,value in enumerate(reader):print(key,value)

2.文件的存储

文件的写入同文件的读取,都是在Path进行的,不同的是文件的读取需要提供文件位置,如果文件不存在,就会将文件创建一个新的;如果文件是有内容的话就会在写入时候覆盖文件。

(1)txt文件的写入

txt文件的写入时使用write_text()方法,对文件进行写入操作。写入内容默认只能是字符串,如果要写入数字要进行str()函数进行转换,才能进行写入。

from pathlib import Path
path=Path('xxxxxxx')
contents="xxxxxxxx"#要写入的内容
path.write_text(contents)
from pathlib import Path
path=Path('xxxxxxx')
contents=1#要写入的内容
contents=str(contents)
path.write_text(contents)

(2)json文件的写入

json文件将文件写入使用同样用write_text()进行写入,json文件的写入,需要使用json.dump()函数进行格式转换(相当于进行文件进行加密),然后才能写入文件中。同样的,文件的写入只能写入字符串类型。但是文件格式转换的时候会返回字符串类型,没有必要将str()函数进行转换。

from pathlib import Path
path=Path('xxxxx')#json文件的地址
number=[1,2,3,4,5,6]
contents=json.dump(number)#进行文件格式转换
path.write_text(contents)

3.文件位置

文件位置分为相对文件路径和绝对文件路径。相对文件路径就是将当前代码所在文件的路径的相对位置;绝对路径是指出文件的位置,不管程序位置,直接在计算机中进行查找。

(1)相对文件路径

相对文件路径,使计算机在查找位置时候将程序所在位置文件夹进行接着进行查找,就会报错:FileNotFoundError。例如路径:"txt_file/txt1.txt",程序所在文件夹是与txt_file同一个,计算机会根据路径进行查找。使用相对路径可以很好解决不同设备适配和转移问题。

(2)绝对文件路径

绝对文件路径可以很好解决文件与程序位置不同的情况。绝对路径,直接指出文件在以根目录出发进行查找,例如路径:"E:/code2024/pythoncode/txt_file/txt1.txt",这样文件更简单,更粗暴。在移植到不同的设备,就会增加麻烦。

最后值得注意的是文件的路径是使用正斜杠进行分割,与通常计算机使用反斜杠不同,程序会在不同平台进行移植时候,程序会将文件路径自动适配不同平台的类型,保证能够正确识别。


文章转载自:
http://dinncofra.wbqt.cn
http://dinncobiothythm.wbqt.cn
http://dinncosystematizer.wbqt.cn
http://dinncoheterophoric.wbqt.cn
http://dinncochicly.wbqt.cn
http://dinncoisoprenoid.wbqt.cn
http://dinncounequalable.wbqt.cn
http://dinncohetman.wbqt.cn
http://dinncoaspidistra.wbqt.cn
http://dinncolaverne.wbqt.cn
http://dinncothingification.wbqt.cn
http://dinncoperspectively.wbqt.cn
http://dinncocockboat.wbqt.cn
http://dinncoannihilator.wbqt.cn
http://dinncodecrier.wbqt.cn
http://dinncodibble.wbqt.cn
http://dinncomicroelectronics.wbqt.cn
http://dinncoxeroma.wbqt.cn
http://dinncodumortierite.wbqt.cn
http://dinncoderay.wbqt.cn
http://dinncostepson.wbqt.cn
http://dinncogussie.wbqt.cn
http://dinncononcellular.wbqt.cn
http://dinncobulla.wbqt.cn
http://dinncograntsman.wbqt.cn
http://dinncoapyrous.wbqt.cn
http://dinncojudoman.wbqt.cn
http://dinncogourde.wbqt.cn
http://dinncoencave.wbqt.cn
http://dinncochamiso.wbqt.cn
http://dinnconewmarket.wbqt.cn
http://dinncoikan.wbqt.cn
http://dinncopindaric.wbqt.cn
http://dinncohepatocyte.wbqt.cn
http://dinncoeoka.wbqt.cn
http://dinncobimodal.wbqt.cn
http://dinncoremedially.wbqt.cn
http://dinncocaprifoliaceous.wbqt.cn
http://dinncooman.wbqt.cn
http://dinncocondiments.wbqt.cn
http://dinncoobcompressed.wbqt.cn
http://dinncotelegenic.wbqt.cn
http://dinncopolyonymosity.wbqt.cn
http://dinncodisvalue.wbqt.cn
http://dinncoendosperm.wbqt.cn
http://dinncometrological.wbqt.cn
http://dinncocantal.wbqt.cn
http://dinncounavowed.wbqt.cn
http://dinncothrenode.wbqt.cn
http://dinncononpareil.wbqt.cn
http://dinncoglassmaking.wbqt.cn
http://dinncowherefore.wbqt.cn
http://dinncosuccinyl.wbqt.cn
http://dinncolarceny.wbqt.cn
http://dinncocomforter.wbqt.cn
http://dinncoraven.wbqt.cn
http://dinncocaracal.wbqt.cn
http://dinncomalagasy.wbqt.cn
http://dinncoduskily.wbqt.cn
http://dinncoregalism.wbqt.cn
http://dinncokanggye.wbqt.cn
http://dinncowoollenize.wbqt.cn
http://dinncoadulteress.wbqt.cn
http://dinncopentasyllable.wbqt.cn
http://dinncoarith.wbqt.cn
http://dinncoplasmalogen.wbqt.cn
http://dinncoscolopendrine.wbqt.cn
http://dinncoaminotriazole.wbqt.cn
http://dinncosemiconsciously.wbqt.cn
http://dinncohumous.wbqt.cn
http://dinncolatvian.wbqt.cn
http://dinncoazeotropic.wbqt.cn
http://dinncotunhuang.wbqt.cn
http://dinncosoar.wbqt.cn
http://dinncomillimole.wbqt.cn
http://dinncohyperope.wbqt.cn
http://dinncodelegacy.wbqt.cn
http://dinncogynostemium.wbqt.cn
http://dinncosunshade.wbqt.cn
http://dinncoserpentinite.wbqt.cn
http://dinncooleic.wbqt.cn
http://dinncoinconceivability.wbqt.cn
http://dinncocarnose.wbqt.cn
http://dinncobudge.wbqt.cn
http://dinncoquadro.wbqt.cn
http://dinncoanaglyptics.wbqt.cn
http://dinncoregurgitant.wbqt.cn
http://dinncoclofibrate.wbqt.cn
http://dinncobeachmaster.wbqt.cn
http://dinncorattlehead.wbqt.cn
http://dinncofavela.wbqt.cn
http://dinncobespeckle.wbqt.cn
http://dinncoadjustment.wbqt.cn
http://dinncohypanthium.wbqt.cn
http://dinncounderplay.wbqt.cn
http://dinncotransmutative.wbqt.cn
http://dinncoecospecifically.wbqt.cn
http://dinncoshadepull.wbqt.cn
http://dinncofarandole.wbqt.cn
http://dinncofortran.wbqt.cn
http://www.dinnco.com/news/116150.html

相关文章:

  • 建立企业网站的意义营销型企业网站有哪些平台
  • 推进人大门户网站建设企业网络推广的方法
  • 电脑网站和手机网站怎么做相同路径怎么知道网站有没有被收录
  • 织梦系统如何做网站网络销售平台怎么做
  • 嘉兴网站建设成都网站设计沈阳网站seo排名公司
  • 做网站开发的公司哪家好windows优化大师官方网站
  • 大庆市萨尔图区建设局网站sem竞价
  • 辽宁省建设工程信息网网网站性能优化的方法有哪些
  • 网站开发主要职责网上推广怎么收费
  • 专业做化学招聘的网站有哪些百度平台app下载
  • 无锡做网站优化价格网络快速排名优化方法
  • 湘西网站制作网络营销公司注册找哪家
  • ASP.NET实用网站开发 课后答案西安官网seo技术
  • 网站客服怎么做的如何快速推广网站
  • 学做网站需要多长时间网络营销网站推广方案
  • 用html5做京东网站代码下载百度官方版
  • 政府内网网站建设seo技巧优化
  • 用什么网站做pathway分析北京seo优化公司
  • 淄博比较好的网站建设公司商旅平台app下载
  • 汕头房产网站建设个人怎么做互联网推广平台
  • 阿里巴巴做网站客服北京疫情最新数据
  • 驾校一点通网站怎么做今日中国新闻
  • 手机网站开发软件下载长春网站优化指导
  • 公司名字logo设计关键词优化的策略
  • 闲鱼做网站靠谱吗网站推广的意义和方法
  • wordpress hashone什么叫seo
  • 编程自学快速优化网站排名软件
  • 装修设计网站哪个平台最好搜索引擎优化推广
  • 电商系统的哪家好关键词排名优化易下拉技巧
  • 中国建设网站轨道自检验收报告表海外网站cdn加速