2
|
1 '''Simple data loader module.
|
|
2
|
|
3 Loads data files from the "data" directory shipped with a game.
|
|
4
|
|
5 Enhancing this to handle caching etc. is left as an exercise for the reader.
|
|
6 '''
|
|
7
|
|
8 import os
|
|
9
|
|
10 data_py = os.path.abspath(os.path.dirname(__file__))
|
|
11 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
|
|
12
|
|
13 def filepath(filename):
|
|
14 '''Determine the path to a file in the data directory.
|
|
15 '''
|
|
16 return os.path.join(data_dir, filename)
|
|
17
|
|
18 def 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
|