why 'os' appears as submodule of my package

Viewed 29

Importing my package shows 'os' as submodule of my package. Example: Suppose I have a package with the following structure:

-- setup.py
-- my_package
  |-- __init__.py
  |-- example.py

example.py could be:

import os

def helloWorld():
    print('Hello World')

The package is installed using python setup.py install.

When further using import my_package I find my_package.example.os. How can I avoid 'os' from appearing as submodule?

I use python 2.7

1 Answers

You can't, but it's normal and desired.

The same way import mypackage gives you access to mypackage.example.helloWorld, you get access to mypackage.example.os, because both are in the main namespace of mypackage.example (you can use os within helloWorld, for example).

Note that this does not mean that os is included in your package.

Related