Skip to content

Instantly share code, notes, and snippets.

@teepark
Created June 25, 2010 02:14
Show Gist options
  • Save teepark/452296 to your computer and use it in GitHub Desktop.
Save teepark/452296 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
mkdir -p a/b/c
touch {a,a/b,a/b/c}/__init__.py
cat >a/b/c/d.py<<EOF
class e(object):
pass
EOF
cat >a/b/__init__.py<<EOF
from c.d import e
EOF
python -c "import a.b.c.d; print a.b.e is a.b.c.d.e"
python -c "from a.b.c.d import e; from a.b.c import d; print d.e is e"
PYTHONPATH=`pwd`/a python -c "import a.b.c.d; import b.c.d; print a.b.c.d.e is b.c.d.e"
python -c "import a.b.c.d; import imp; print a.b.c.d.e is imp.load_module('a.b.c.d', *imp.find_module('d', ['a/b/c'])).e"
python -c "import a.b.c.d; print a.b.c.d.e is __import__('a.b.c.d').b.c.d.e"
rm -r a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment