Michael Hudson <mwh21 at cam.ac.uk> writes: > Why wouldn't __import__("Crypto.Cipher.%s"%(CIPHER,),globals(),{},[1]) > followed by cipher = getattr(Crypto.Cipher, CIPHER) work? To get the module for CIPHER imported properly, you just need to pass its name in the fourth parameter to __import__: >>> CIPHER = 'DES3' >>> pkg = __import__('Crypto.Cipher', globals(), locals(), [CIPHER]) >>> module = getattr(pkg, CIPHER) >>> print module <module 'Crypto.Cipher.DES3' from '/home/carey/lib/python/Crypto/Cipher/DES3.pyc'> No need to use exec, eval or %s anywhere. keeping-the-world-free-of-exec-ly y'rs - Carey -- "Quiet, you'll miss the humorous conclusion."
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4