What I want to do is patch an existing Python module that uses urllib2 to run on App Engine, but I don't want to break it so it can be used elsewhere. So I'm looking for a quick solution to test if the module is imported in the App Engine environment or not. Catching ImportError on urllib2 might not be the best solution.
You could simply use sys.modules to test if a module has been imported (I'm using unicodedata as an example):
>>> import sys
>>> 'unicodedata' in sys.modules
False
>>> import unicodedata
>>> 'unicodedata' in sys.modules
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With