Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
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.
Start your free trial
You might also like
Python编程入门与实战
Posts & Telecom Press, Fabrizio Romano
Python实用技能学习指南
Posts & Telecom Press, Robert Smallshire, Austin Bingham
Python技术基础视频教程
保罗·J·戴特尔
Python面向对象编程指南
Posts & Telecom Press, Steven F. Lott
Publisher Resources
ISBN: 9787115586223