Home > Store

Perl to Python Migration

Register your product to gain access to bonus material or receive a coupon.

Perl to Python Migration

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

Description

  • Copyright 2002
  • Dimensions: 7-3/8x9-1/4
  • Pages: 320
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-73488-5
  • ISBN-13: 978-0-201-73488-1

Perl to Python Migration provides a useful and practical resource for programmers that are currently intermediate or expert in using Perl and who want to migrate to using Python for different programming projects. The book achieves this by first giving the user an overview and refresher of the Perl techniques required before giving the information on using Python to achieve the same result. Examples of both Python and Perl will be available on-line on the author's website.

Sample Content

Table of Contents

CONTENTS

Introduction
Python Overview
Python Execution
Components of a Python Program
Functions
Exceptions
Modules, Classes, and Object Orientation
Processing Information
Interfacing to the OS
File Manipulation
Data Management
Communicationing over a Network
Using Python for Web Development
Interface Building with Tk
Resource Guide - (in conjunction with material on the web)

Preface

As a long time Perl and Python programmer, I’m constantly finding myself using Perl constructs in Python or Python constructs in Perl. Worse, I can suddenly find myself trying to use a feature or system in a Python program that just doesn’t exist, or does and works differently. What I needed was some sort of cross reference.

After talking to other programmers and developers it became apparent that a number of people were "jumping ship" from Perl to Python. Some with varying levels of success. The reasons for using Python in preference to Perl were different for each person, but there were some common themes:

Python is object-oriented. Although Perl has object orientation facilities they are not integrated into the system. In Python everything is an object or class — even the base data types are objects and have their own methods and attributes. This makes Python a great language to use in situations where you are working on applications that use object orientation as a core technology.

Python is easy to use. Python has a very clean and structured layout, and it’s very easy to follow what’s going on. Perl can frequently look like line noise, and particularly for new programmers this becomes a problem as they try to understand why their program works.

Python does what you tell it to. Perl suffers from a severe case of semi-intelligence. Statements and expressions in Perl have all sorts of rules, exceptions to those rules, and other artefacts that can make it difficult to follow what is going on. Just think about what happens when you call a function, was it called in list or scalar context?, what arguments did it have?, how do I get them back? These are regular questions when programming with Perl.

Python is cross-platform compatible. Perl is also cross-platform compatible, for certain values of compatible. Because of Perl’s Unix roots — it is very much a Unix language — use Perl under Windows or MacOS and a large proportion of the built-in functions become obsolete. Python’s functionality is supported by external modules, many of which use the correct version according to their platform whilst retaining the same API.

These aren’t really hard and fast reasons for why you should make the jump to Python, but they are compelling reasons for why Python is at least worth a look.

In this book that’s exactly what we try to do — show you how you can make the move from Perl to Python. Many of the basics are the same, and despite a change of language, you’re unlikely to need to change the algorithms you are already using.

For the more advanced programmer, or, like me, the programmer who has to use both languages most days, the book should also work as a handy cross reference to allow you to look up Perl and Python statements and functions, and find out what you should use in both languages.

Who is the book for?

Anybody who has used Perl and who wants or needs to learn Python will find this book useful. The book gives a full guide on the basics of programming in Python from the perspective of a Perl programmer. Right from the basics of line and program structure all the way up to object-orientation and using external modules.

You don’t need to be an expert Perl programmer , you just need to be able to understand the basics. I’ve tried to make the text as easy to read and follow as possible. However, on occasion things get technical, and to get the best out of the book you should at least know how to use and create your own functions, extension modules and classes and objects.

Without trying to give you the plot before you’ve read the book, if you know how to work with references, classes and objects in Perl, then your migration to Python is already 50% there!

How to use this book

The book is split into three main sections. The first section gives you an introduction to Python, including information on the basic mechanics of the language and information on who and where it is used.

Section 2 concentrates on the fundamentals of the language from the basics of expressions and statements through to comparing Python’s object types with Perl variables. We’ll also look at creating functions, error handling, and extending Python with modules and classes.

The last section concentrates on applying Python in real situations compared to the equivalent Perl process, function or module. For example, Chapter 8 looks at Python’s built-in functions and their Perl equivalents, whilst Chapter 10 looks at manipulating data and regular expressions.

There are also two appendices at the back of the book. Appendix A provides a handy guide to getting more information about Python, including other books, websites, newsgroups, mailing lists and details on how to get the Python documentation to help you with your programming. Appendix B is a quick reference — it lists every Perl token, variable or function and provides you with the Python alternative. Where possible, it will also direct you straight to the page elsewhere in the book where you can find more information on the Python alternative.

If you are completely new to Python but know Perl then read Sections 1 and 2 first. If you’ve played with Python but never used it in anger, then start with Section 2. Finally if you know Python and just want quick reference information then use Appendix B to look up the Perl fragment you are looking for, or go straight to the suitable chapters in sections 2 and 3.

If you don’t know Perl, then this book will not be a lot of help. Try reading Perl: The Complete Reference 2nd Edition (Osborne/McGraw-Hill, 2001) or Learning Perl, 2nd Edition (O’Reilly, 1997).

Chapter breakdown

There are fourteen chapters and two appendices in the book. Throughout the book examples of a Perl expression or statement are given, along with the equivalent Python version and information on why the changes and modifications are required. The rough content of each chapter is as follows:

Chapter 1, Introduction — An overview of Python covering information on it’s history and who uses the language.

Chapter 2, Executing Python Programs — Python is much more of an interactive language, so before we look at the specifics of Perl and Python programs, we’ll look at how to use and execute Python programs.

Chapter 3, Python Overview — Our first look at how Perl and Python differ from an overall structure and approach perspective.

Chapter 4, Components of a Python Program — Details the statements, data types and operators supported by Python and how they relate to their Perl equivalents.

Chapter 5, Functions — How to create and use Python functions and to migrate your Perl functions and argument handling into Python.

Chapter 6, Exceptions and Error Trapping — The mechanics of Python’s exception system which is used throughout the language as a method for highlighting errors, right from parsing the source code through to creating and raising your own exceptions to indicate errors.

Chapter 7, Modules, Classes, and Object Orientation — Information on how to extend your Python applications with modules and classes, and how these relate to the Perl module and class structure.

Chapter 8, Built-in Functions — Quick guide to the functions that Python supports in the native interpreter.

Chapter 9, Interfacing with the Operating System — Details on how to communicate with the operating system, including information on getting command-line arguments, determining your environment and communicating with and starting new processes.

Chapter 10, Data Manipulation — How to manipulate numbers, strings, and work with regular expressions in Python.

Chapter 11, File Manipulation — File processing and management, from reading and writing to files through to managing directories, file permissions and controlling access.

Chapter 12, Communicating Over a Network — Details the processes behind communicating with network services, both from the perspective of a client and a server.

Chapter 13, Web Development — A quick guide to programming for the web under Python.

Chapter 14, GUI Development with Tk — Information on how to migrate your user interfaces from Perl/Tk to Python’s Tkinter system.

Appendix A, Python Resources — A guide to the books, mailing lists, websites and online documentation available for information on Python.

Appendix B, Perl to Python Quick Reference — A cross reference that lists all the Perl tokens, variables and functions used in Perl and the corresponding Python equivalent.

Conventions Used in This Book

All Perl keywords are highlighted in bold, but functions are listed without parentheses. This is because the C functions on which the Perl versions may be based are shown like this().

Examples and code are displayed using a fixed-width font.

Function descriptions are formatted using the same fixed-width font.

Note: notes are formatted like this and include additional information about a particular topic. You’ll also find similarly formatted "Warnings," which highlight possible dangerous tools or tricks to watch out for when programming.

Contacting the Author

I always welcome comments and suggestions on my work. The best way to contact me is via e-mail. You can use either books@mcwords.com. Alternatively, visit my website, http://www.mcwords.com, which contains resources and updated information about the scripts and contents of this book. You can find the homepage for this book at http://www.mcwords.com/projects/books/p2py/.



0201734885P10012001

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020