On Aug 19, 8:16 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:

> Hussein B wrote:
> > Is the standard library of Python is compiled (you know, the pyc
> > thing)?
> > Is it allowed to edit the source code of the standard library?
> > I'm not talking about submitting the modified code to Python source
> > code repository, I'm just asking if some one can edit the source code
> > in his own machine.
>
> Python ships with the library sources, and you can of course edit them
> in exactly the same way as you'll edit any other Python file.  modules
> in the standard library are no different from your own modules in that
> respect.
>
> whether it's a good idea to edit them (unless you're trying to track
> down bugs or provide patches to the maintainers) is a different issue.
>
> </F>

A less invasive approach is monkey-patching [1], i.e. extend or modify
the runtime behavior without altering the original source code. For
instance I recently needed to patch the bug posted at
http://bugs.python.org/issue1651995 and I didn't have write access to
the standard library, so I monkeypatched SGMLParser:

# XXX: monkeypatch SGMLParser to fix bug introduced in 2.5
# http://bugs.python.org/issue1651995
if sys.version_info[:2] == (2,5):
    from sgmllib import SGMLParser
    SGMLParser.convert_codepoint = lambda self,codepoint:
unichr(codepoint)


HTH,
George

[1] http://en.wikipedia.org/wiki/Monkey_patch
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to