Your search query "linkto%253A%2522QuestionType%2522" didn't return any results. Please change some terms and refer to HelpOnSearching for more information.
(!) Consider performing a full-text search with your search terms.

Clear message

-- DavidLambert 2007-07-18 14:49:27

Nameless functions, nameless types.

Please, what is purpose of name argument to new type call?

'''
$ python
Python 2.5.1 (r251:54863, Jun 25 2007, 14:55:49) 
[GCC 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)] on cygwin
'''

cls1 = type('*',(object,),{})        # create type named by asterisk.
# del *                              # silly.
# del '*'                            # silly.


cls2 = type('*',(object,),{'f':lambda s,x: x*3})
# cls1().f('abc')                    # causes expected AttributeError
cls2().f('abc') == 'abcabcabc'       # class name unused


str(cls1) == "<class '__main__.*'>"
str(cls2) == "<class '__main__.*'>"  # so what, the classes differ.


cls_named = type('valid_name',(object,),{})
# del valid_name                     # raises NameError


class C(object):
    pass
del C

Unable to edit the page? See the FrontPage for instructions.