5 ms·
> Monkeypatching anywhere except unittests is a nono for me. What do you think about adding pprint to builtins so that you don't need to import it each time wh
by Alex3917 6y ago
> Monkeypatching anywhere except unittests is a nono for me.
What do you think about adding pprint to builtins so that you don't need to import it each time when debugging? (Or, alternatively, so that you don't need to add it to the top of every single file?) It seems kind of wrong, but the alternatives are bad also. I'm not sure why Python didn't do this themselves when they added breakpoint in 3.7.
- orf 6y agopprint is a standard library module which isn’t necessarily available everywhere. You can run python without the standard library, but the moment you add it to the default builtins it needs to become part of the language.
- lacker 6y agoMonkeypatching in one application is maybe okay. You really want pprint in builtins, fine, who is it really hurting? Monkeypatching in a library like fastcore that many other people use is really bad. All sorts of bugs and incompatibilities will happen down the road, as software becomes dependent on your monkeypatch without anyone realizing it.
- xapata 6y agoCan you configure your debugger to include it? I'd rather do that than modify production code to include a debugging tool.
- kristjansson 6y agoPdb already has pretty print built in? $ python -m pdb ... (Pdb) help pp pp expression Pretty-print the value of the expression. (Pdb) pp ...
- linkdd 6y agoThe debug code you add doesn't get removed before going into production?
- nuclear_eclipse 6y agoIf you want it in your debugger (or ipython, etc), add an import to your `.pythonrc` or equivalent. Then it's ready and waiting for you without influencing your production environment or other engineer's testing environments. If you want to use it in all your modules, create a template/snippet so that it's imported at the top ofevery new file you create. Then it's obvious to every new engineer you hire as to what's going on, rather than having non-standard behavior everywhere without any obvious indications.