comparison python/example/resource_filename.py @ 803:70e9f82c2443

* prime actually doesnt work; if i had a decent CI for my own software, i would have known that; but i dont * resource_filename.py even _says_ example in it. let us hope it is telling the truth
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 17:00:37 -0700
parents python/resource_filename.py@cbd7651dbd52
children
comparison
equal deleted inserted replaced
802:b5a59c3e4421 803:70e9f82c2443
1 #!/usr/bin/env python
2
3 # example code
4
5 import os
6
7 def resource_path(path):
8 """
9 getting a resource filename (absolute path)
10 - path: relative path
11 """
12
13 try:
14 # use pkg_resources if available
15 # http://pythonhosted.org/distribute/setuptools.html#non-package-data-files
16 from pkg_resources import Requirement, resource_filename
17 return resource_filename(Requirement.parse("MyProject"),path)
18 except ImportError:
19 # assume file lives relative to this file
20 here = os.path.dirname(os.path.abspath(__file__))
21 return os.path.join(here, path)