Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created February 16, 2012 18:00
Show Gist options
  • Save hidsh/1846753 to your computer and use it in GitHub Desktop.
Save hidsh/1846753 to your computer and use it in GitHub Desktop.
python dictionary test
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)
@hidsh
Copy link
Author

hidsh commented Feb 16, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment