James Tauber : Pyworks Common Library and Import Issues

James Saiz

journeyman of some

Pyworks Common Library and Import Issues

Demokritos contains some modules that might be useful in other software, so I decided to create a little package for these common modules called 'pyworks' (seeing as that's the umbrella I'm starting to use for my various Python-related projects).

So I was thinking I could rename webbase.py to pyworks.web and call my Subversion library pyworks.svn. I also have a library for helping build domain objects from xml parsing events. I was going to call it pyworks.xml

But that means a 'from svn import repos' in pyworks/svn.py won't work and nor will 'from xml.parsers import expat' in pyworks/xml.py

This problem doesn't exist outside of the pyworks package itself. 'import xml' only means the standard library package and 'from pyworks import xml' gives you the pyworks xml module. Similary with 'import svn' versus 'import pyworks.svn'.

For this reason, I don't mind a little hack internal to pyworks.

I seem to recall the py library (that py.test is in) does something similar.

Unfortunately, calling the module 'pyworks_xml.py' and putting 'import pyworks_xml as xml' in 'pyworks/__init__.py' doesn't work.

UPDATE: The following seems to work in pyworks/__init__.py:

import sys
import pyworks_xml
sys.modules["pyworks.xml"] = pyworks_xml

UPDATE (2006-02-15): Looks like PEP-328 might be exactly what I need. Another reason I'm looking forward to Python 2.5.

Categories: Python pyworks

Trackbacks (0)

Comments (1)

Jean-Paul on Friday 10 February, 2006:

You could also use __import__('xml') inside xml.py to get the standard xml module.

This has the advantage of not pulling in the module until someone actually asks for it.

Add a Comment

What is 90+0?
Comments are text only.
The math question is to ensure you are a human!
This page last modified Wednesday 15 February, 2006 by James Saiz
Content made available under a Creative Commons Attribution-NonCommercial-ShareAlike license