Skip to content

Instantly share code, notes, and snippets.

@sheljohn
Created August 17, 2018 13:32
Show Gist options
  • Save sheljohn/89ff7538a14883aaba55ead0a9f18e06 to your computer and use it in GitHub Desktop.
Save sheljohn/89ff7538a14883aaba55ead0a9f18e06 to your computer and use it in GitHub Desktop.
wtf-python: Features, not bugs
# Take any version of Python that can import numpy, and run this in a terminal
D=$(mktemp -d) # temporary folder
pushd "$D" # move there
mkdir foo # create subfolder
echo 'import numpy' >| foo/a.py # script a.py
echo 'x++' >| foo/math.py # script math.py (invalid)
python foo/a.py # run a.py
popd # leave temp folder
# .
# ..
# ... waaaaaat
# What happened?
#
# We basically messed with the import path _inside_ NumPy,
# by calling a script, in a folder which contains another script,
# which name conflicts with a Python builtin module.
#
# Result: when numpy tries to execute "import math", Python serves
# our local foo/math.py, instead of the standard math module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment