Learning Python 5th edition — Reading notes

Chapter 1 A Python Q&A Session

Advantages:

  • Software quality, object-oriented
  • Developer productivity
  • Program portability
  • Support libraries
  • Component integration
  • Enjoyment XD
  • not only a Scripting Language

Disadvantage:

  • execution speed: not fully compiled

Fun notes:

  • try import this

Chapter 2 How Python Runs Programs

Python as an interpreter: a layer of software logic between code and
computer hardware.

Source m.py -> Byte code m.pyc -> Runtime in python virtual machine(PVM)

Note that Python byte code is not binary machine code (instructions for an
Intel or ARM chip). Byte code is a Python-specific representation. That is
why some python code may not run as fast as C/C++.

Chapter 3 How You Run Programs

hash bang / shebang

tell the system where the python interpreter is, use sys.executable to find location.

#!/usr/local/bin/python3.4

or set the environment like:

#!/usr/bin/env python3

How to run programs

Just simply

python3 script

or change executable privileges with chmod +x and

./script

Import and Reload

import script

Note that after the first import, later imports do nothing. If you want to run
the import again, use reload:

from imp import reload

reload(script)

Note the differences between import X and from X import Y.

import X

X.Y

from X import Y

Y