chapter 1 Flashcards
Code compilation
source code -> byte code and byte code is platform independent
what does a byte code look like
*.pyc
sometimes, the *.pyc cannot be written into your system, but the script is still be run
PVM
The last step of what is called the Python interpreter
python virtual machine that iterates through your byte code instructions one by one.
exit an interactive python session
ctrl + D
When do we have to use print
in the text file, we have to use print to show the result
in the interactive window, we don’t need to
route the output of a Python script to a file to save it for later use
python filename.py > filename
import script
> > > import script
top-level file
one which launches the entire program
what will import do
find the files->compile them to byte code->run the code
So import is an expensive operation
How to reload the same module
reload(module name)
what is the difference between a reload and an import
reload must have a parenthesis and import don’t
Mostly, what is a module
More generally, a module is mostly just a package of variable names, known as a namespace
how to use the content in the module
First, the module must be imported. Second, the attribute in the file should be used with prefix which is the name of the file
How to import a specific attribute from a module
from module_name import attribute name
In this case, the use of the attribute is direct and no prefix is needed to specified in the command
What is the difference between from filename import attributes
and import wholemodule
The import command executes the module and from ~~ copy the attribute names. That is why in the second case, the prefix is not needed