Python full stack development "supplemental" package supplement

Source: Internet
Author: User
Tags create directory

1. A module with the same name under Package A and package B does not conflict because A.A and B.A come from two namespaces

2. Common directory Structure

# Create Directory Code import osos.makedirs (' Glance/api ') os.makedirs (' Glance/cmd ') os.makedirs (' glance/db ') L = []l.append (' glance/__init__.py ', ' W ')) l.append (open (' glance/api/__init__.py ', ' W ')) l.append (open (' glance/api/policy.py ', ' W ') ) L.append (Open (' glance/api/versions.py ', ' W ')) l.append (open (' glance/cmd/__init__.py ', ' W ')) l.append (Open (' glance /cmd/manage.py ', ' W ')) l.append (open (' glance/db/models.py ', ' W ')) Map (Lambda F:f.close (), L)

 

3. Directory structure

glance/                   #Top-level package├──__init__.py      #Initialize The Glance package├──api                  #Subpackage for api│   ├──__init__.py│   ├──policy.py│   └──versions.py├──cmd                #Subpackage for cmd│   ├──__init__.py│   └── Manage.py└──db                  #Subpackage for db    ├──__init__.py    └──models.py

  

4. File contents

#文件内容 #policy.pydef Get ():    print (' from policy.py ') #versions. Pydef create_resource (conf):    print (' From version.py: ', conf) #manage. Pydef Main ():    print (' from manage.py ') #models. Pydef register_models (engine):    Print (' From models.py: ', engine)

5. Software Development Specification

6. Absolute Import

glance/                   ├──__init__.py from      glance Import API from                             glance import cmd from                             glance import Db├──api                  │< c5/>├──__init__.py from  glance.api Import policy from                              glance.api import versions│   ├──policy.py│   └── Versions.py├──cmd from                 glance.cmd import manage│   ├──__init__.py│   └──manage.py└──db                   from GLANCE.DB Import Models    ├──__init__.py    └──models.py

  

7. Relative Import

glance/                   ├──__init__.py from      . Import API  #. Indicates the current directory from the                     . Import cmd from                     . Import Db├──api                  │
   ├──__init__.py from. Import  Policy from                     . Import versions│   ├──policy.py│   └──versions.py├──cmd< C11/>from. Import manage│   ├──__init__.py│   └──manage.py from    : API Import Policy                        #: Represents the previous level of the directory, you want to manage the method in the policy will need to go back to the previous level glance directory to find the API package, import from the API policy└──db from               . Imports Models    ├──__init__ . PY    └──models.py

8.import glance directly after calling the method in the module

glance/                   ├──__init__.py from,     API import * from.                    cmd import * from                    . DB Import *    ├──api                  │   ├── __init__.py   __all__ = [' policy ', ' versions ']│   ├──policy.py│   └──versions.py├──cmd               __all__ = [' Manage ']    │   ├──__init__.py│   └──manage.py    └──db                __all__ = [' models ']                  ├──__init__.py    └──models.pyimport glancepolicy.get () Import glance

 

Python full stack development "supplemental" package supplement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.