Python, could I import * without Imported classes -


let's pretend have file called file1.py:

from app1 import classx  class class1:     pass  class class2:     pass 

if in file called file2.py want import class1 , class2 without explicit import classes need use

from file1 import * 

my problem is, when i'm importing classx too, don't want import classx , don't import class1 , class2 explicit.

there way import classes developed in file1?

to put finer point on jonathon reinhart's comment on question:

# app2.py app1 import classx  __all__ = ['class1', 'class2']  class class1:     pass  class class2:     pass 

 

# test.py app2 import *  c = class1() d = class2() try:     e = classx() except nameerror:     print "working intended!" 

Comments