annotate gamelib/data.py @ 1:c90a6586cd66

PEP8-ify skellington (because)
author Neil Muller <drnlmuller@gmail.com>
date Sun, 06 May 2012 10:32:24 +0200
parents d0de8832774b
children 51ff46f42ed2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
1 '''Simple data loader module.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
2
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
3 Loads data files from the "data" directory shipped with a game.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
4
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
5 Enhancing this to handle caching etc. is left as an exercise for the reader.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
6 '''
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
7
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
8 import os
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
9
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
10 data_py = os.path.abspath(os.path.dirname(__file__))
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
11 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
12
1
c90a6586cd66 PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents: 0
diff changeset
13
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
14 def filepath(filename):
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
15 '''Determine the path to a file in the data directory.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
16 '''
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
17 return os.path.join(data_dir, filename)
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
18
1
c90a6586cd66 PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents: 0
diff changeset
19
0
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
20 def load(filename, mode='rb'):
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
21 '''Open a file in the data directory.
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
22
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
23 "mode" is passed as the second arg to open().
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
24 '''
d0de8832774b Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff changeset
25 return open(os.path.join(data_dir, filename), mode)