Python使用平面文件进行存储
python使用平面文件进行存储
文本文件包含数据,但是它没有内部层次结构,通常不会引用外部文件。一个平面文件包含人们可以阅读的字符,它在创建和阅读数据时很有用。因为平面文件不一定要使用固定字段宽度,所以他们通常会使用其他结构,让程式可以解析文字。
举例来说,CSV(comma-separatedvalue)是一个纯文本文件,用逗号分隔数据元素,用逗号字符分隔数据元素。每行文本代表一行数据,并以逗号分隔,值为行中的一个字段。一个逗号分隔符表示两个数据值的边界。
Python的读取和保存都很好。通过使用Python读取数据文件,可以在稍后重新运行应用程序时将数据文件恢复到可用状态。在文件中保存数据,这样你就可以在程序用户和网站之间共享程序中的数据信息。
它必须能够理解数据,然后程序才能读取数据文件。一般情况下,这意味着数据文件需要有一些应用程序可以用于读取和解析文本的结构。
first_name,last_name,title,publisher
Isaac,Asimov,Foundation,RandomHouse
Pearl,Buck,TheGoodEarth,RandomHouse
Pearl,Buck,TheGoodEarth,Simon&Schuster
Tom,Clancy,TheHuntForRedOctober,Berkley
Tom,Clancy,PatriotGames,Simon&Schuster
Stephen,King,It,RandomHouse
Stephen,King,It,PenguinRandomHouse
Stephen,King,DeadZone,RandomHouse
Stephen,King,TheShining,PenguinRandomHouse
John,LeCarre,"Tinker,Tailor,Soldier,Spy:AGeorgeSmileyNovel",Berkley
Alex,Michaelides,TheSilentPatient,Simon&Schuster
Carol,Shaben,IntoTheAbyss,Simon&Schuster
第一行提供以逗号分隔的字段列表,这些字段是其余各行后面数据的列名。其余各行包含数据,每行代表一条记录。
以上就是Python使用平面文件进行存储的方法,希望能对大家有所帮助!更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python中如何dataframe转换为ndarray?
python中如何dataframe转换为ndarray?小编介绍过python中ndarray与series如何相互转换的方法,其实Series转换为ndarray是一个一维数组,作为pan...详情>>
2023-11-14 05:21:25
python中os.remove()的使用注意
python中os.remove()的使用注意计算机一般来说是需要定期的清理,系统的内存不能延伸,同时有一些不需要的文件也可以得以清除掉。有些人会使用o...详情>>
2023-11-14 04:47:11
python元组的优势有哪些
python元组的优势有哪些本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、因为元素不可变性,它可以作为哈希类型的key值。这样使...详情>>
2023-11-14 03:55:04
python如何获取当前文件的部分信息?
python中如何获取当前文件的部分信息?一、文件对象常用的属性1、file.name:文件的名称2、file.mode:打开文件时,采用的文件打开模式3、file.e...详情>>
2023-11-14 03:24:14热门推荐
python中如何应用视图函数?
沸python根据键值(value)返回键(key)
热python中pickle模块是什么?
热python解析json文件方法
新python中如何dataframe转换为ndarray?
python中os.remove()的使用注意
Python中if嵌套是什么?
python元组的优势有哪些
python如何获取当前文件的部分信息?
Python使用平面文件进行存储
python中remove()方法如何使用删除后的值?
python如何使用RE正则表达检验字符串
pythonSelenium操作Cookie的方法
python类方法的注意点
技术干货






