Skip to Content
Python语言及其应用(第2版)
book

Python语言及其应用(第2版)

by Bill Lubanovic
March 2022
Intermediate to advanced
522 pages
13h 52m
Chinese
Posts & Telecom Press
Content preview from Python语言及其应用(第2版)
222
14
文件和目录
我有文件,电子版的、纸质版的,都有。不过大部分东西在我的脑子里。所以,
要是我的脑袋出了事,上帝保佑吧!
——
Geor
ge R. R. Martin
在你刚开始编程时,有些词会反复出现在耳边,但你又不确定它们是否有具体的技术含
义,或者只是随手写出来的。术语
文件
目录
就是这种词,而且两者确实有实际的技术含
义。
文件
是存储在某种
文件系统
中的字节序列,可以通过
文件名称
进行访问。
目录
是文件
的集合,其中可能还有其他目录。术语
文件夹
是目录的同义词。这个词是随着计算机图形
用户界面出现的,模仿了办公室里物品的概念,使事物看起来更熟悉。
很多文件系统是分层次的,经常被称为树。真正的办公室里不会有树,而文件夹的比喻也
只有顺着这个思路想象子文件夹时才管用。
14.1
文件输入和输出
普通文件,有时也称为
平面文件
flat file
),是最简单的持久化形式。你将文件内容
读入
内存,再将内存中的内容
写入
文件。
Python
这种活儿可谓驾轻就熟。和很多语言一样,
Python
的文件操作在很大程度上是以熟悉和流行的
Unix
操作系统为模型。
14.1.1
使用
open()
创建或打开文件
在执行下列操作之前,需要先调用
open
函数。
读取现有文件
写入新文件
文件和目录
223
向现有文件中追加内容
• ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
Python实用技能学习指南

Python实用技能学习指南

Posts & Telecom Press, Robert Smallshire, Austin Bingham
量子计算机编程:从入门到实践

量子计算机编程:从入门到实践

Eric R. Johnston, Nicholas Harrigan, Mercedes Gimeno-Segovia
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787115586223