Permalink
Browse files

Example that uses namedtuple

  • Loading branch information...
1 parent 5e43a96 commit 058e42b57e0c850940001d542c4e237225651b62 @mitsuhiko committed Jun 20, 2011
Showing with 8 additions and 5 deletions.
  1. +8 −5 assname.py
View
@@ -35,8 +35,11 @@ def assigned_name():
if __name__ == '__main__':
- class Module(object):
- def __init__(self):
- self.name = assigned_name()
- admin = Module()
- print admin.name
+ import collections
+ def namedtuple(*names):
+ rv = collections.namedtuple(assigned_name(), names)
+ rv.__module__ = sys._getframe(1).f_globals['__name__']
+ return rv
+
+ Token = namedtuple('type', 'value', 'lineno')
+ print Token, Token('int', 42, 1)

0 comments on commit 058e42b

Please sign in to comment.