I’m looking at code that does uses an _ for typename in a namedtuple. I was wondering what the purpose of this is.
example = namedtuple('_', ['NameOfClass1', 'NameOfClass2'])
Why not just use String?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That is a somewhat odd example of a namedtuple. The whole point is to give meaningful names to the class and its attributes. Some of the features such as the __repr__ and the class docstring derive most of their benefit from meaningful names.
FWIW, the namedtuple factory includes a verbose option which makes it easy to understand what the factory is doing with its inputs. When
verbose=True, the factory prints out the class definition it has created: