Python Classroom Series – 25/Jun/2021

Relative and Absolute Imports

  • We have imported our own modules from
    • current directory
    • subdirectory
    • python Standard Library
  • All the examples of imports done so far are referred as absolute imports.
import utils
  • Python supports relative imports
    • if utils.py in the same directory from . import utils
    • if utils.py is in the parent directory from .. import utils
  • Refer Here for the changeset to fix the No Module utils found by using relative imports

Writing and importing our Module

  • Create the following folder structure Preview
  • In the models Folder create a module called as
    • models.py
  • In the viewmodels add operations module (operations.py)
    • define a function inside operations.py which will create a new employee by asking from users Refer Here
  • Refer Here for the resolution of the import issue

Python Standard Library

  • One of the pythons prominent claims is that it has "batteries include" a large standard library of modules that perform many useful tasks are shipped along with python installation.
  • They are kept seperate to avoid bloading the core language. Refer Here for the official docs

Print Nicely with pprint()

Get Random

Text Related Standard Libraries

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin