PyCon Pune 2017

A conference on the Python programming language

Tasdik Rahman

@tasdikrahman

Diving deep on how imports work in Python

Submitted Nov 28, 2016

It just so happens python abstracts away the inner workings of import statement beautifully. But are we aware of how python behaves when it encounters an import statement for a module?

  • Better yet what is a module actually?
  • Packages anybody?
  • More than one import style? How to choose between them.
  • How would different import styles compare with each other.
  • Any Best practices when importing modules. What about that __init.py__ you saw the last time you read someone else’s code.

This talk will walk you through the above and more.

Outline

Materials @ github

  • Modules
  • What happens when you import a module?
  • Packages
  • Why packages
  • Different styles for importing modules
  • python 2 pitfalls
  • Module names best practices
  • Module lookup
  • Modules get imported Only once!
  • What really happens when you reload a module?
  • Implicit Relative imports
  • Absolute relative imports
  • Explicit relative imports
  • What should you put into __init__.py? Advantages in doing so?
  • Questions?

A rough slide presentation has been created uploaded on speakerdeck.

Requirements

python3
material present at: https://github.com/prodicus/talks/tree/master/pyconpune2017

Speaker bio

Slides

https://speakerdeck.com/tasdikrahman/diving-deep-on-how-imports-work-in-python-pycon-pune-2017-proposed-talk

Comments

{{ gettext('Login to leave a comment') }}

{{ gettext('Post a comment…') }}
{{ gettext('New comment') }}
{{ formTitle }}

{{ errorMsg }}

{{ gettext('No comments posted yet') }}

Hosted by

PyCon Pune 2017 more