Modules in Python work in a slightly different way to Perl. We still import the modules, but modules can be imported in different ways, and once imported accessing the information within them is also different. However, if you've followed the notes so far on using Python objects and methods you'll begin to see a familiar pattern.


Python uses a very simple system for controlling the namespaces for importing modules. Python uses these namespaces in the same way as Perl uses packages (through the package statement). In Perl the package name for the main script is main and in Python —main—. The big difference between Perl and Python is how the namespaces affect how functions and objects in external modules are accessed.

In Perl, ...

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.