r/Python • • Jun 23 '14

Writing better python code

https://gist.github.com/kracekumar/09a60ec75a4de19b346e
143 Upvotes

126 comments sorted by

View all comments

Show parent comments

7

u/pstch Jun 23 '14

Could you expand on why "namedtuple" is such a hack ?

9

u/robin-gvx Jun 23 '14

Because it's implemented as piecing together a string that contains a class statement and compiling that to obtain the tuple subclass (see source).

4

u/[deleted] Jun 23 '14

Goofy implementation, doesn't need to be written that way

1

u/robin-gvx Jun 23 '14

Theoretically, it could just be rewritten as a call to type, but maybe there are practical issues?

2

u/[deleted] Jun 23 '14

The point is that it's not really a hack. Their implementation may be "hackish" but it doesn't depend on a hack to work.