[go: up one dir, main page]

0% found this document useful (0 votes)
8 views15 pages

00-Python Archivos-Sept03

File handling with python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

00-Python Archivos-Sept03

File handling with python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

+ 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

You might also like