__main__ vs official module name: distinct module instances

Jonas Wielicki jonas at wielicki.name
Tue Aug 4 14:42:22 CEST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512



On 02.08.2015 05:53, Cameron Simpson wrote:
> When invoked this way, the module cs.app.maildb that is being
> executed is actually the module named "__main__". If some other
> piece of code imports "cs.app.maildb" they get a _different_
> instance of the module. In the same program! And how did it cause
> me trouble? I am monkey patching my module for debug purposes, and
> that monkey patcher imports the module by name. So I was monkey
> patching cs.app.maildb, and _not_ patching __main__. And thus not
> seeing any effect from the patch.
> 

So I guess you just explained my issues with Flask and trying to wrap
an application up in __main__.py. Thank you. And also, +1 on your
proposal, please bring it to -ideas.

regards,
jwi
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCgAGBQJVwLMlAAoJEMBiAyWXYliKJSAP/i+UUJpQyVZVhTYAGax3ZPak
MWhdvGpQhq5iJIDImBJCGtiLtt+8Qy/UuJC4sAbz080XRJs9V3goYWCdZABpynln
VOCbd1vvTHadmOxTjX98D++bIg4ZFvaWFruk/TYcx35GtbQb52/LH6nq4b8EpMY+
1wFdMQ8ccUixiMbvEeNtgRWw4g2fG5LGceiT1Hs9ThVlin5di0jjAz4MrZa49eNt
tdTMQBaoap+yL1VXU10e+2vF8EiqtmfQwrRME2WLglJcYw8p2WMe+FLHvGVpKu9+
nVkZfWHBjOA9Ym4HdugCCiQPW12R/kuExrixjw6FYKeb7QXaF67yjWUXVOAW2XcP
oaTIk4+U4WoeMReVyRzyWLPShKKaoR5djJbpKFW8GzD1XHulh/CWWuL/R1rt+LSF
e5ME6HvKVZoh+4QT4CcL6K8Gv+w5RbgFXPidREuZzavXCQVo2IoCOs2JCClBu4Gy
zy8tYk8gt5+8bub74Bkm6+FhdwMNQgKRCpXkgoqj5EgKEkeWiPl0d89geUq6PC0x
boSKVDn1rg2OmQWSjqKs+rUHK6XSVt4C+P6pb/lW9zsAs87AfQcjdrG6xaC2+dKo
/YeZVvq0Y1PCf6IIjPGp5DsKkN1bJtvUPGFH8ZFY+xZ/nHYI/UToKoo7cF5J2xf/
0h2t4lfozMVs9fswpHlz
=ITon
-----END PGP SIGNATURE-----


More information about the Python-list mailing list