+ File Handling
n File
operations
n Reading content
n Writing content
n Thefile workflow
n Open the file
n Read/write content
n Close the file
+ Reading Files - Technique 1
+ Reading Files – Technique 2
This is the better technique for handling large files!.
+ Writing Files
+ Respuestas
+ Example #1
Write all lines in source.txt that have less than 10
characters to file output.txt
+ Example #2
Creating two files based on one.→ (The file)
+ Archivos CSV
+ Data Storage
§ Record-oriented data storage
§ CSV (Comma-separated-value), so called “flat
files”
§ Database
§ CSV (Comma Separated Values) format is the most
common import and export format for spreadsheets
and databases. They contain a number of rows, each
containing a number of columns, usually separated
by commas.
§ CSV files
§ Easy to read and write!
§ Easy to share!
+ CSV files in Python
§ To read (cvs) files you can simply loop over the lines and use
split method to get individual columns.
§ The csv module's purpose is to make it easier to deal with csv
formatted file, especially when working with data exported
from spreadsheets and databases into text files.
§ There is no well-defined standard, so the CSV module uses
"dialects" to support parsing using different parameters.
Along with a generic reader and writer, the module includes a
dialect for working with Microsoft Excel.
§ The CSV module contains the following functions:
§ csv.reader
§ csv.writer
§ csv.register_dialect
§ csv.unregister_dialect
+ Reading CSV files
+ Reading CSV files
+ Writing CSV files
+ Ejemplo Real
CSV
+ A Simple Example