Exposing some Python classes without coupling to file structure -


my project consists of several python classes, split several files.

projname/     a.py # has classes a1 , a2     b.py # has classes b1 b2 b3     c.py # has class c test/ doc/ bin/ 

i'd able make (or all) of classes public, that, either bin dir, or python script, can like:

import projname ... myvar = projname.a1() 

i can't figure out how that. best can far is:

import projname.a import projname.b import projname.c  myvar = projname.a.a1() 

i don't 2 reasons:

  1. i don't want clients of code have know , care files used distribute classes. don't want break clients if change files
  2. i'd prefer expose classes outside project - not of them

put __init__.py projname/ following content:

from .a import a1, a2 .b import b1, b2, b3 .c import c 

this turns projname package namespace contains whatever __init__.py contains, in case a1, a2, b1, b2, b3 , c.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -