comparison gamelib/data.py @ 2:e057e9483488

Added pyweek skellington.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 30 Aug 2009 11:58:53 +0000
parents
children 498e4732bc1f
comparison
equal deleted inserted replaced
1:837c3c7be8f6 2:e057e9483488
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