Skip to content

Instantly share code, notes, and snippets.

@ggand0
Last active March 24, 2017 05:04
Show Gist options
  • Select an option

  • Save ggand0/5773e292b0b3990195edad7bd35a4c64 to your computer and use it in GitHub Desktop.

Select an option

Save ggand0/5773e292b0b3990195edad7bd35a4c64 to your computer and use it in GitHub Desktop.
Preventing importing modules in Python
# see: http://stackoverflow.com/questions/1350466/preventing-python-code-from-importing-certain-modules
>>> import tensorflow
>>> tensorflow.contrib
<tensorflow._LazyContribLoader object at 0x1130b9050>
>>> tensorflow.contrib.layers
<module 'tensorflow.contrib.layers' from '/Users/pentiumx/.pyenv/versions/2.7.10/lib/python2.7/site-packages/tensorflow/contrib/layers/__init__.pyc'>
>>> import sys
>>> del tensorflow.contrib.layers
>>> sys.modules['tensorflow.contrib.layers']=None
>>> tensorflow.contrib.layers
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'layers'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment