r/learnpython • • May 06 '21

What are some programming tools that every beginner programmer should know about?

Example, today I learned about Git and GitHub and it felt incredible.

480 Upvotes

190 comments sorted by

View all comments

Show parent comments

58

u/TaranisPT May 06 '21

As someone still fairly new to coding, this has been such a blessing for me. Knowing what makes the program crashes instead of just messing around with what you think crashes it is really helpful.

165

u/greasycilantro May 06 '21

And yet I still use the good ole "let's put a print statement here and see what happens" method lmao

5

u/MyPythonDontWantNone May 06 '21

I try really hard to import logging before I need print statements. It allows me to leave the print statements in and just set a different log level. It is a better way to use the print statements. Plus it tracks the debugging if someone else runs the program.

2

u/Gh0st1nTh3Syst3m May 06 '21

How would that look if implemented?

5

u/dnswblzo May 06 '21

logging.debug('This is a debugging message')

https://docs.python.org/3/howto/logging.html

2

u/MyPythonDontWantNone May 06 '21

I'm on mobile, so I don't know how to add a code block. Here's a paste bin link with a toy example.

https://pastebin.pl/view/a4dc4f48

Try changing the 10 inside the function to something else (such as an empty dictionary {}) to see what an error does. Also, try changing the level parameter to logging.DEBUG or logging.ERROR to test the output.

Feel free to ask me questions. I'll attempt to help, but I'm self-taught and I've always been a solo dev. People working in a more structured environment are likely to have some insights that I lack.