source: nagslang/data.py@ 8:3769f9d260d8

Last change on this file since 8:3769f9d260d8 was 8:3769f9d260d8, checked in by Neil Muller <drnlmuller@…>, 8 years ago

Add traditional / splite to filepath

File size: 834 bytes
Line 
1'''Simple data loader module.
2
3Loads data files from the "data" directory shipped with a game.
4
5Enhancing this to handle caching etc. is left as an exercise for the reader.
6
7Note that pyglet users should probably just add the data directory to the
8pyglet.resource search path.
9'''
10
11import os
12
13data_py = os.path.abspath(os.path.dirname(__file__))
14data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
15
16
17def filepath(filename):
18 '''Determine the path to a file in the data directory.
19 '''
20 # Allow using / as separator in filenames
21 filename = os.path.join(*filename.split('/'))
22 return os.path.join(data_dir, filename)
23
24
25def load(filename, mode='rb'):
26 '''Open a file in the data directory.
27
28 "mode" is passed as the second arg to open().
29 '''
30 return open(os.path.join(data_dir, filename), mode)
Note: See TracBrowser for help on using the repository browser.