source: gamelib/data.py @ 2:e057e9483488

Last change on this file since 2:e057e9483488 was 2:e057e9483488, checked in by Jeremy Thurgood <firxen@…>, 11 years ago

Added pyweek skellington.

File size: 633 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'''
7
8import os
9
10data_py = os.path.abspath(os.path.dirname(__file__))
11data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
12
13def filepath(filename):
14    '''Determine the path to a file in the data directory.
15    '''
16    return os.path.join(data_dir, filename)
17
18def load(filename, mode='rb'):
19    '''Open a file in the data directory.
20
21    "mode" is passed as the second arg to open().
22    '''
23    return open(os.path.join(data_dir, filename), mode)
24
Note: See TracBrowser for help on using the repository browser.