Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
python_modules_and_packages [2017/10/19 18:55] – created mgupton | python_modules_and_packages [2017/10/25 12:33] (current) – [Example] mgupton | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Python Modules and Packages]====== | + | ======Python Modules and Packages====== |
* A Python module is a file containing Python code. | * A Python module is a file containing Python code. | ||
* A package is a group of modules in a subdirectory. | * A package is a group of modules in a subdirectory. | ||
* To make a directory package include a file in the directory named // | * To make a directory package include a file in the directory named // | ||
+ | |||
+ | ======Example===== | ||
+ | To create a package //foo// that contains a module //bar// and function //hello//. | ||
+ | |||
+ | < | ||
+ | from foo.bar import hello | ||
+ | |||
+ | hello() | ||
+ | </ | ||
+ | |||
+ | Directory named //foo// contains empty file named // | ||
+ | |||
+ | General scheme | ||
+ | < | ||
+ | from < | ||
+ | </ | ||
+ | |||
+ | The // | ||
+ | |||
+ | < | ||
+ | from < | ||
+ | </ | ||
+ | |||
+ | Which would allow the module to be imported into other modules with the following import statement that imports directly from the package and not the module. | ||
+ | |||
+ | < | ||
+ | from < | ||
+ | </ | ||
+ |