FILE PROCESSING

The basic processes of opening a file have already been covered in Chapters 4 and 8. Once the file has been opened you end up with a file object which is then used to access the information from the file. The methods supported by a file object closely mimic the functions and operators we would normally use in Perl and other oddities, such as using line based input (as opposed to free-form or byte based input) are supported natively by the file object.

The basic Perl functions and equivalent Python file methods are listed in Table 11.1. We'll have a look at the specifics of reading, writing, and locating our position within a file in this section.

Table 11.1. Reading and writing files in Perl and Python
Perl operation Python equivalent ...

Get Perl To Python Migration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.