how to get os.py to use an ./ntpath.py instead of Lib/ntpath.py

Aahz aahz at pythoncraft.com
Sat Nov 10 01:42:43 CET 2012


In article <k2p9da$ktu$1 at r03.glglgl.gl>,
Thomas Rachel  <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de> wrote:
>Am 11.09.2012 05:46 schrieb Steven D'Aprano:
>>
>> Good for you. (Sorry, that comes across as more condescending than it is
>> intended as.) Monkey-patching often gets used for quick scripts and tiny
>> pieces of code because it works.
>>
>> Just beware that if you extend that technique to larger bodies of code,
>> say when using a large framework, or multiple libraries, your experience
>> may not be quite so good. Especially if *they* are monkey-patching too,
>> as some very large frameworks sometimes do. (Or so I am lead to believe.)
>
>This sonds like a good use case for a context manager, like the one in 
>decimal.Context.get_manager().

Note that because get_manager() applies to a specific Context instance it
is safe in a threaded application, which is NOT true for monkey-patching
modules even with a context manager.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"....Normal is what cuts off your sixth finger and your tail..."  --Siobhan


More information about the Python-list mailing list