官术网_书友最值得收藏!

How to do it...

  1. 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.
  2. 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
  1. 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
主站蜘蛛池模板: 安徽省| 金阳县| 嘉鱼县| 孝感市| 康平县| 阿克陶县| 黄平县| 克山县| 河南省| 锡林浩特市| 文山县| 军事| 深水埗区| 宝山区| 德化县| 南乐县| 蒙山县| 临泽县| 临夏市| 南皮县| 达拉特旗| 溧水县| 昌黎县| 朝阳区| 油尖旺区| 凤翔县| 民勤县| 临洮县| 论坛| 金秀| 盐边县| 揭西县| 竹山县| 吴江市| 兴海县| 胶南市| 平安县| 横峰县| 米林县| 苍山县| 镇赉县|