GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BlogCode/PythonImportExample at main · Polaris000/BlogCode

Expand file tree

/

PythonImportExample

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

PythonImportExample

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
pythonimportexample
pythonimportexample
 
 
README.md
README.md
 
 
setup.py
setup.py
 
 

README.md

Outline

PythonImportExample

This is the example package used in my blogpost How Imports Work in Python, published in Better Programming, one of the top publications on Medium.

The post discusses:

  • what happens when you import a python module
  • some key terms associated with Python's import system, like __init__.py and sys.path
  • some scenarios that might arise while working with imports
  • creating your own package
  • and relative vs absolute imports.

The code here is the final result that is achieved in the article.

Contents

The file structure is:

PythonImportExampleProject/
    setup.py
    
    config related files (gitignore, LICENCE, etc.)
    pythonimportexample/
        __init__.py
        file1.py
        file2.py
        subpackage1/
            __init__.py
            file3.py
            file4.py
        subpackage2/
            __init__.py
            file5.py
            file6.py

Modules are imported in the following way:

  • file1 into file2
  • file3 into file4
  • file3 into file5
  • file6 into file2
  • file2 into file6

Yup, the last one's a circular import.

Usage

  1. Clone this repo
  2. Navigate to the PythonImportExample directory
  3. Install this package

Simply execute:

$ git clone https://github.com/Polaris000/BlogCode.git 
$ cd PythonImportExample
$ pip install -e .

You can find me on medium here.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.