Created
February 16, 2012 18:00
-
-
Save hidsh/1846753 to your computer and use it in GitHub Desktop.
python dictionary test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class t_path: | |
def __init__(self, path, externp): | |
self.path = path | |
self.externp = externp | |
d = dict() | |
# append | |
d['varx'] = t_path('path/to/srcx.c', True) | |
d['var1'] = t_path('path/to/src1.c', False) | |
d['var2'] = t_path('path/to/src2.c', True) | |
# value get | |
print '-- value get' | |
print d['var1'].path | |
print d['var1'].externp | |
# print d['var3'].path # KeyError: 'var3' at runtime | |
# test | |
print '-- test' | |
print 'a' in d | |
print 'var2' in d | |
# list | |
print '-- list' | |
print d.keys() | |
for k, v in d.iteritems(): | |
print '%s: %s: %s' % (k, v.externp, v.path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result
-- value get
path/to/src1.c
False
-- test
False
True
-- list
['var1', 'varx', 'var2']
var1: False: path/to/src1.c
varx: True: path/to/srcx.c
var2: True: path/to/src2.c