Skip to Content
Perl To Python Migration
book

Perl To Python Migration

by Martin C. Brown
November 2001
Beginner
320 pages
5h 53m
English
Pearson Business
Content preview from Perl To Python Migration

ERROR TRAPPING IN PYTHON

When migrating to Python it's important to basically forget everything you know about error trapping in Perl. Python functions don't as a rule return a value that indicates their success or failure. When opening a file for example we don't have to explicitly test the return value of the open function to determine whether the open has succeeded. Instead, Python supports a number of exceptions.

In principle, these appear to work in the same fashion as embedding Perl statements into eval blocks. Exceptions propagate up through the code and they can be trapped and located locally, or “remotely.” For example, below is a function which accepts a single argument, the file name. The function opens the file, reads the lines from ...

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

Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Perl by Example

Perl by Example

Ellie Quigley
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 0201734885Purchase book