by NelsonMinar · 9y ago · 0 comments
(BTW if you need a quick and dirty way to make Python start up faster, see if you can use the -S flag for your application. It skips the site-specific initialization and has a significant impact on startup times.)
import collections
collections.namedtuple = lambda _0, _1, _2=False, _3=False: "Where is your god now?"
import b
b.py: import collections
print(collections.namedtuple('Point', ['x', 'y']))
And this is not even particularly 'evil' code, in the sense of relying on internal implementation details; that's just your bread-and-butter Python language semantics. It prevents (or at least complicates) many other potential optimisations as well.You can do some pretty amazing metaprogramming in Python with metaclasses, and the inspect and ast modules give you access to the guts of the language.
This video talks about it: https://youtu.be/sPiWg5jSoZI?t=1h37m18s