269
|
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)
|