faqts : Computers : Programming : Languages : PHP : Common Problems : Files : Tips and Tricks : Importing

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 5 people (60%) answered Yes
Recently 1 of 3 people (33%) answered Yes

Entry

Is it possible to not have to explicitly do imports?

Mar 3rd, 2000 20:51
Nathan Wallace, Paul Prescod


I would suggest instead that you add an object to the globals dictionary
in your site setup. It could be called "mods" (for brevity). You would
hook up "mods.__getattr__" so that you would say:

fl=mods.glob.glob('*')

You would use __import__ in mods.__getattr__

I thought about this once and it seemed pretty cool to me as a shortcut.
You could argue that we could dump the import statement...(but I
wouldn't)

Having an explicit object as the root for the dynamically generated
package tree would be more Pythonic than having every module magically
appear in your global package namespace.

Package support needs more thinking through...