Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access files inside a Python egg file?

Tags:

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 an 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?

like image 768
Ripley Avatar asked Sep 07 '10 02:09

Ripley


People also ask

How do I access the egg file?

EGG files can be opened with Python using the "SetupTools" package. The files can also be decompressed with a Zip-decompression program, such as Microsoft File Explorer, Corel WinZip, or Apple Archive Utility.

How do I uncompress a egg file?

Open File Explorer to locate the zipped folder. To unzip the entire folder click on the right-click menu and select Extract All. Follow the instructions. Double-click the zip folder to unzip it.

What is a Python egg file?

Python eggs are an older distribution format for Python. The new format is called a Python wheel, which we will look at in the next chapter. An egg file is basically a zip file with a different extension. Python can import directly from an egg. You will need the SetupTools package to work with eggs.

What are egg info files?

egg-info format: a file or directory placed adjacent to the project's code and resources, that directly contains the project's metadata.


1 Answers

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!

like image 131
Alex Martelli Avatar answered Sep 21 '22 15:09

Alex Martelli