收录日期:2020/10/28 08:21:51 时间:2010-09-07 02:19:58 标签:python,egg

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.

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!