Why using print() can get you into trouble
Vložit
- čas přidán 9. 05. 2024
- In this tutorial, I'll show you how to simplify your coding process by integrating the logging module into your Python scripts and add-ons for Blender. Discover how to effectively debug and track your script's behavior, enhancing your development workflow. Perfect for Blender developers looking to streamline their coding with better logging practices!
Blender: How to set up Python console output on Linux
• Blender: How to set up...
Blender: How to set up Python console output on macOS
• Blender: How to set up...
📨 Subscribe, to see the extended video cg-python.ck.page/43d610dfb9
🟠 Dr. Sybren article on logging code.blender.org/2016/05/logging-from-python-code-in-blender/
Do you sen out the link manually, I subbed but didn't get an email. Perhaps it takes couple minutes.
@@RomboutVersluijs it should be automatic
please let me know if you have not gotten it yet
@@CGPython yesgot, it did took until next day. But I got the link, thanks
This is very handy and functional. Thank you for the recommendation.
You're welcome! 🙂
This is amazing! Thank you for this!
Glad you like it!
Great overview on logging, thank you! I double checked my repos; there's some prints left in my add-ons that I need to upgrade 😄many are in building/zipping the add-on. Another downside to print() - it's quite slow, relative to other code statements. Removing them can speed operations up quite a bit.
For the sake of discussion, I'd also add:
- if the print() statements are for debugging, my opinion is to just remove them. Don't replace them. If it's a common issue area, there's probably something else worth fixing there. I usually don't ask for logs from customers; just a minimal .blend file and/or list of steps to cause the error.
- if it's an error, raise it instead. Pop-up errors reported by operators are automatically logged, including the stack trace. Users will also see the error and ask for support. I hear the error message, telling me where to look in the code.
That is a great point!
Thanks!
More great points!
I think there is a difference between prints for "printf debugging" and prints for more context.
I would agree that the prints for "printf debugging" would need to go, but there are cases where you constantly are adding that print to debug something.