# HG changeset patch # User Jeff Hammel # Date 1364099876 25200 # Node ID cbd7651dbd5246f8e18c3a19303dfcfd2b98a170 # Parent 06fcec56e8fe26a1b514d6d3a4755e36cac394eb add sample example code diff -r 06fcec56e8fe -r cbd7651dbd52 python/recipes.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/recipes.txt Sat Mar 23 21:37:56 2013 -0700 @@ -0,0 +1,3 @@ +Catalog of Generic Requested Python Implementations That Should Be Written + +(empty placeholder) diff -r 06fcec56e8fe -r cbd7651dbd52 python/resource_filename.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/resource_filename.py Sat Mar 23 21:37:56 2013 -0700 @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# example code + +import os + +def resource_path(path): + """ + getting a resource filename (absolute path) + - path: relative path + """ + + try: + # use pkg_resources if available + # http://pythonhosted.org/distribute/setuptools.html#non-package-data-files + from pkg_resources import Requirement, resource_filename + return resource_filename(Requirement.parse("MyProject"),path) + except ImportError: + # assume file lives relative to this file + here = os.path.dirname(os.path.abspath(__file__)) + return os.path.join(here, path)