Chris Shenton wrote: > I've got an app that needs to read and parse a data file (a RADIUS > dictionary, not a Python "dictionary" but a flat file). I want to > include this file in my egg so I don't have to depend on the OS having > RADIUS installed. > > In the application's top-level setup.py, I add my data/ subdir to the > package_data list: > > package_data={'bianca': ['i18n/*/LC_MESSAGES/*.mo', 'data/*']}, > > and see that the files in data/ get added to my egg. Good so far. > > What path do I use to reference that file for reading? Again, I am > trying to avoid hard-coded absolute filesystem paths. But trying paths > like: > > freeradius_dictionary > /data/freeradius_dictionary > /bianca/data/freeradius_dictionary > /bianca/freeradius_dictionary > > didn't work for me: file not found. > > What's the pattern for paths to files that live inside eggs, rather than > on the larger filesystem? Is there some PATH I need to specify to the > app or Pylons? Something else?
from pkg_resources import resource_filename path = resource_filename('bianca', 'data/freeradius_dictionary') If data would have been a python package, which I suppose it's not, then: path = resource_filename('bianca.data', 'freeradius_dictionary') HTH, Alberto --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---