Book Image

The Python Apprentice

By : Robert Smallshire, Austin Bingham
Book Image

The Python Apprentice

By: Robert Smallshire, Austin Bingham

Overview of this book

Experienced programmers want to know how to enhance their craft and we want to help them start as apprentices with Python. We know that before mastering Python you need to learn the culture and the tools to become a productive member of any Python project. Our goal with this book is to give you a practical and thorough introduction to Python programming, providing you with the insight and technical craftsmanship you need to be a productive member of any Python project. Python is a big language, and it’s not our intention with this book to cover everything there is to know. We just want to make sure that you, as the developer, know the tools, basic idioms and of course the ins and outs of the language, the standard library and other modules to be able to jump into most projects.
Table of Contents (21 chapters)
Title Page
Credits
About the Authors
www.PacktPub.com
Customer Feedback
Preface
12
Afterword – Just the Beginning

Shebang


It's common on Unix-like systems to have the first line of a script include a special comment, #!, called a shebang. This allows the program loader to identify which interpreter should be used to run the program. Shebangs have an additional purpose of conveniently documenting at the top of a file whether the Python code therein is Python 2 or Python 3.

The exact details of your shebang command depend on the location of Python on your system. Typical Python 3 shebangs use the Unix env program to locate Python 3 on your PATH environment variable, which importantly is compatible with Python virtual environments:

#!/usr/bin/env python3

Executable Python programs on Linux and Mac

On Mac or Linux, we must mark our script as executable using the chmod command before the shebang will have any effect:

$ chmod +x words.py

Having done that, we can now run our script directly:

$ ./words.py http://sixty-north.com/c/t.txt

Executable Python programs on Windows

Starting with Python 3.3, Python on Windows...