-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththree.py
More file actions
38 lines (36 loc) · 1.06 KB
/
three.py
File metadata and controls
38 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# sys_shelve_importer_create.py
import shelve
import os
filename = '/tmp/pymotw_import_example.shelve'
if os.path.exists(filename + '.db'):
os.unlink(filename + '.db')
with shelve.open(filename) as db:
db['data:README'] = b"""
==============
package README
==============
This is the README for ``package``.
"""
db['package.__init__'] = b"""
print('package imported')
message = 'This message is in package.__init__'
"""
db['package.module1'] = b"""
print('package.module1 imported')
message = 'This message is in package.module1'
"""
db['package.subpackage.__init__'] = b"""
print('package.subpackage imported')
message = 'This message is in package.subpackage.__init__'
"""
db['package.subpackage.module2'] = b"""
print('package.subpackage.module2 imported')
message = 'This message is in package.subpackage.module2'
"""
db['package.with_error'] = b"""
print('package.with_error being imported')
raise ValueError('raising exception to break import')
"""
print('Created {} with:'.format(filename))
for key in sorted(db.keys()):
print(' ', key)