2

I need to modify one line of an extremely nested python file in an imported library.

I needed to handle 1 error exception not covered by the library, so I made a class that inherits the error throwing class (and adds a try/except block).

Now I just need to swap my new class for the old one, but I'm sure its terrible pythonic form to actually modify an imported library source code.

jonbon
  • 1,142
  • 3
  • 12
  • 37
  • You could just modify the source code and re-run setup.py – cs95 Apr 13 '18 at 19:26
  • I need this to be portable, so I really don't want to modify a line of a dependency – jonbon Apr 13 '18 at 19:28
  • Relevant: https://stackoverflow.com/questions/5626193/what-is-monkey-patching – Blckknght Apr 13 '18 at 19:57
  • 1
    I think your assumption "it's terrible pythonic form to actually modify an imported library source" is incorrect. What you describe is monkey patching, and it is pretty common in Python and other dynamic languages. – Blckknght Apr 13 '18 at 20:01

0 Answers0