Python : Import modules once then share with several files

You will have to import something at least once per file. But you can set it up such that this is a single import line:

The probably cleanest way is to create a folder lib, move all lib?.py in there, and add an empty file called __init__.py to it.

This way you create a package out of your lib?.py files. It can then be used like this:

import lib
lib.lib7

Depending on where you want to end up, you might also want to have some code in the __init__.py:

from lib7 import *
from lib8 import *
from lib9 import *

This way you get all symbols from the individual lib?.py in a single import lib:

import lib
lib.something_from_lib7

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)