Revision: 890
http://svn.sourceforge.net/pygccxml/?rev=890&view=rev
Author: roman_yakovenko
Date: 2007-01-31 10:53:51 -0800 (Wed, 31 Jan 2007)
Log Message:
-----------
removing named_tuple.py
Removed Paths:
-------------
pyplusplus_dev/unittests/temp/named_tuple.py
Deleted: pyplusplus_dev/unittests/temp/named_tuple.py
===================================================================
--- pyplusplus_dev/unittests/temp/named_tuple.py 2007-01-31 08:41:50 UTC (rev 889)
+++ pyplusplus_dev/unittests/temp/named_tuple.py 2007-01-31 18:53:51 UTC (rev 890)
@@ -1,46 +0,0 @@
-# This file has been generated by Py++.
-
-# Copyright 2004 Roman Yakovenko.
-# Distributed under the Boost Software License, Version 1.0. (See
-# accompanying file LICENSE_1_0.txt or copy at
-# http://www.boost.org/LICENSE_1_0.txt)
-
-class named_tuple(tuple):
- """Creates tuple, which allows access to stored values by name and\or by index.
-
- Construction example: named_tuple( ('a',0), ('b',1) )
- 'a' and 'b' are names, while 0 and 1 are values
- """
-
- def __new__(cls, *args):
- return tuple.__new__( cls, [ val for name, val in args] )
-
- def __init__(self, *args):
- tuple.__init__( self )
- self.__dict__[ '__name2value' ] = dict( args )
-
- def __getattr__(self, name):
- try:
- return self.__dict__['__name2value'][ name ]
- except KeyError:
- raise AttributeError( "named_tuple has no attribute '%s'" % name )
-
- def __setattr__(self, name, value):
- raise AttributeError( "named_tuple has no attribute '%s'" % name )
-
- def __getitem__( self, key ):
- #TODO: it could be nice to support slicing. So the __getitem__ in case of
- #slicing will return new named_tuple.
- if isinstance( key, basestring ):
- return self.__dict__['__name2value'][ key ]
- else:
- return super( named_tuple, self ).__getitem__( key )
-
-if __name__ == '__main__':
- nt = named_tuple( ('a',0), ('b',1) )
- assert nt.a == 0 and nt.b == 1
- a,b = nt
- assert a == 0 and b == 1
- assert nt[ "a" ] == 0 and nt[ "b" ] == 1
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|