Import and Ownership Tips
Learn how to run the first "Hello World!" program and tips related to Python's ownership and licensing.
We'll cover the following
Software documentation is essential. A poorly documented program is hard to understand and, as a result, hard to maintain. Python is a self-documented language, not a self-documenting language. We, as a programmer, must still develop documentation.
Quality documentation begins with proper formatting, which Python enforces at the syntactic level. Quality documentation includes properly constructed identifiers (variable, function, method, class, and module names) and the proper choice of quotation symbols for our strings. We’ll learn how to avoid “magic” or unclear values. Finally, we’ll master the docstring mechanism that allows us to attach documentation to every Python code unit.
Writing documentation is a tedious, though worthwhile process to improve readability in the future.
Hello world!
Python has its own way of saying “Hello world!” This is likely the first program you wrote when learning to code. You don’t even need to know how to do the printing. Import the module, __hello__
, and enjoy the greeting:
import __hello__
Import this
Every Python installation comes with the module named this
. The module has nothing to do with the namesake Java or C++ keyword denoting a reference to a class object. The module contains The Zen of Python, a set of guiding principles that define the Pythonic programming style. Like any kind of Zen, the Zen of Python is learned by practicing.
Let’s start our practice by looking at the principles.
import this
The Zen of Python is stored in the module as a scrambled string, this.s
(this
is the name of the module), that comes with a dictionary, this.d
, for unscrambling.
The unscrambling process is simple:''.join(this.d.get(x, x) for x in this.s)
''.join(this.d.get(x, x) for x in this.s)
Know ownership and licensing
Creating a Python program means that we own the program and its copyrights.
Python’s ownership is worth considering.
copyright()
As are those who contributed to it.
credits()
We should also consider the product’s current legal status and if it’s legally suitable to our needs.
license()
The other functions’ output is not included, because it may differ for different Python builds. There seems to be a function for every occasion, though.
Quiz on import and ownership
What’s the efficient way to display “Hello World” in Python, without using a print()
call?
print("Hello World!")
import __hello__