tags:

views:

71

answers:

2

Folks

This might be a weird requirement but it's what I've run into. I googled but yield nothing.

I'm coding an application who's using a lot of constant attributes / values recorded in a XML file (they'll not change so a static file), things work fine until I generated an egg file for it.

When the logic reaches the xml accessing part, I got one complaint like this: /home/Workspace/my_proj/dist/mps-1.2.0_M2-py2.6.egg/mps/par/client/syntax/syntax.xml

Actually I've bundled the xml file in the path above but seems python doesn't know how to access it.

The code to access the xml is as ...

    file_handler = open(path_to_the_file)
    lines = file_handler.read().splitlines()

Any idea ?

Thank you guys in advance.

+4  A: 

egg files are zipfiles, so you must access "stuff" inside them with the zipfile module of the Python standard libraries, not with the built-in open function!

Alex Martelli
I read the doc for zipfile module and surely it could do the job. Thank you ~
Ripley
you can even install them using, sudo easy_install your_eggfile
Tumbleweed
+1  A: 

An egg file is just a zip file with a .egg extension. Maybe you can open it using the zipfile module.

Paul McGuire