- Secret Recipes of the Python Ninja
- Cody Jackson
- 162字
- 2021-06-25 22:14:43
How to do it...
- When making a package, follow the normal filesystem hierarchy in terms of directory structure; that is, modules that relate to each other should be placed in their own directory.
- A possible package for a video file handler is shown in package_tree.py:
video/ # Top-level package
__init__.py # Top-level initialization
formats/ # Sub-package for file formats
__init__.py # Package-level initialization
avi_in.py
avi_out.py
mpg2_in.py
mpg2_out.py
webm_in.py
webm_out.py
effects/ # Sub-package for video effects
specialFX/ # Sub-package for special effects
__init__.py
sepia.py
mosaic.py
old_movie.py
glass.py
pencil.py
tv.py
transform/ # Sub-package for transform effects
__init__.py
flip.py
skew.py
rotate.py
mirror.py
wave.py
broken_glass.py
draw/ # Sub-package for draw effects
__init__.py
rectangle.py
ellipse.py
border.py
line.py
polygon.py
- But, what happens if you were already in the specialFX/ directory and wanted to import from another package? Use relative paths to walk the directory and import using dots, just like changing directories on the command-line:
from . import mosaic from .. import transform from .. draw import rectangle
推薦閱讀
- Learning Neo4j
- Learning Cython Programming
- The Android Game Developer's Handbook
- 算法訓(xùn)練營(yíng):入門篇(全彩版)
- Vue.js 3.0源碼解析(微課視頻版)
- Mastering KnockoutJS
- Mastering Drupal 8 Views
- PySpark Cookbook
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Learning AngularJS for .NET Developers
- 深入理解BootLoader
- RESTful Web Clients:基于超媒體的可復(fù)用客戶端
- 零基礎(chǔ)輕松學(xué)C++:青少年趣味編程(全彩版)
- 軟件工程與UML案例解析(第三版)
- STM8實(shí)戰(zhàn)