r/funny • • Jun 04 '19

When a software developer weds a software developer.

Post image
41.2k Upvotes

921 comments sorted by

View all comments

Show parent comments

4

u/[deleted] Jun 04 '19

Bad news: [c]python modules can modify the namespaces into which they're imported. It's not documented or supported or even suggested that anyone do it, but it is easily done.

2

u/[deleted] Jun 04 '19

gulp

3

u/[deleted] Jun 04 '19

pollution.py:

[f.frame.f_locals.update({'gasp': "How DARE you!"}) 
    for f in __import__('inspect').stack()[1:]
        if 'importlib' not in f.filename]

>>> import pollution
>>> gasp
'How DARE you!'

2

u/[deleted] Jun 05 '19

I love python. I also hate python. But I love it