I'm still new to Python, so this may be a dumb question, but I don't understand the purpose of the first parameter to type() and namedtuple():
tuple_typename = namedtuple( 'tuple_typename', 'member1 member2 member3' )
custom_typename = type( 'custom_typename', (base_type,), members_dictionary )
I don't understand the difference between the return value and the string parameter? If the return value is a type reference, why do we need to specify it as a parameter? Or if we need to specify it as a string parameter, why do we need to capture the return value?
And one other related question: If the input string is a type-name specification, is there any way to control the namespace that type-name will be added to? For example, can I add a sub-class to an existing class from outside of that class?
Edit: Even though I accepted a good answer, I was wondering if anyone could clear one other thing up. Once I define a named tuple or custom type, when and/or where would I make use of the first string parameter? How can I reference the type-name later on using the name I specified for that parameter? Is that possible? Or is the type-reference lost once the function return value falls out of scope? Update: See comments of accepted answer