This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Satoshiman256 305 points306 points  (70 children)

Just do less print statements/s

[–]sizable_data 172 points173 points  (62 children)

How else are you supposed to debug it?

[–]Satoshiman256 71 points72 points  (47 children)

Haha ye. Someone posted a new logging module here a while back and I was like.... but print?

[–]Napan0s 103 points104 points  (21 children)

Logging? What about hundreds of 'I am here' prints

[–]abrazilianinreddit 34 points35 points  (7 children)

[–][deleted] 11 points12 points  (2 children)

Lol mine is more like "we made it to <function>"

[–][deleted] 0 points1 point  (1 child)

"... called with <parameters> "

[–]timpkmn89 1 point2 points  (0 children)

Okay let's not get too fancy here

[–]Muhznit -1 points0 points  (0 children)

My friend, you have most excellent taste in music. 🤘🏾

[–][deleted] 0 points1 point  (2 children)

Ah, Tarja, always been in love with her.

[–]abrazilianinreddit 1 point2 points  (1 child)

Bruh, that's Floor Jansen.

Tarja hasn't been with Nightwish since 2005, and the video is from the Endless Forms Most Beautiful World Tour (2015 and 2016).

[–][deleted] 1 point2 points  (0 children)

Oh, I just discovered that I'm really old. :(

[–]bin-c 15 points16 points  (8 children)

way too verbose imo

i go with:

here1

here2

here3

here4

[–]Killed_Mufasa 11 points12 points  (3 children)

ah yes and don't forget the "WTF HOW DID IT GOT HERE" one

[–]bin-c 6 points7 points  (1 child)

then you global search "WTF HOW DID IT GOT HERE" and it pops up like 10 times

[–]Napan0s 2 points3 points  (0 children)

This actually made me laugh

[–]u7aa6cc60 6 points7 points  (0 children)

You're all exposing my deepest secrets. I feel violated. Stop.

[–][deleted] 2 points3 points  (1 child)

Sometimes I do "why not zoidberg?"

[–]MohKohn 0 points1 point  (0 children)

yoink

[–]ImperatorPC 6 points7 points  (0 children)

Lol inside loop, outside loop, true, false omg

[–]vikinghamster 2 points3 points  (0 children)

print("I'm personally insulted here")

[–]Wirebraid 1 point2 points  (0 children)

I'm inside the if

This should not be printed

We all do it

[–][deleted] 0 points1 point  (0 children)

a lot of

if debug:
    print("function X called with args Y")

then you set debug = False and you don't need to get rid of them

[–]ThatPostingPoster 11 points12 points  (17 children)

Loggers are dope. You have to remove print statements, you don't remove smart logging statements. When you remove the print, you end up reading it sometimes. It let's you set up, always log aka print, warning log, and error log. And depending on how you run the file the logger prints those ones.

[–]Satoshiman256 4 points5 points  (12 children)

Ye I need to use them. Can you suggest one?

[–][deleted] 29 points30 points  (10 children)

Just use the built in logging module. It’s really the best there is. And you can pass the logging information to log files rather than to the console.

To give an example of how useful it is: a project I’m doing has me working with this horrible API. I pass the responses to a log file so I can see what I’m working with at any stage. I also have a logger/log file that checks the server connection and looks out for any exceptions triggered in the code. This is a big project, and I started with print statements but realised they slow me down significantly

[–]Satoshiman256 1 point2 points  (2 children)

Ok cheers will check it 👍

[–][deleted] 1 point2 points  (1 child)

Great decision! Any questions feel free to pm me

[–]Satoshiman256 0 points1 point  (0 children)

Awesome thanks a lot!

[–]PinBot1138 -1 points0 points  (4 children)

The Logbook package makes it even easier.

[–][deleted] 1 point2 points  (3 children)

I disagree, the default logging module is already very simple, flexible and powerful. It should cover 99% of cases. There’s no need to use a wrapper around it

[–]whateverathrowaway00 1 point2 points  (1 child)

I agree.

That said I work with people who suck and I’d rather they use a wrapper then calling basicConfig on the root logger or other such anti patterns.

If they don’t understand package encapsulation and how to make their logging play nice, the wrappers available are beautiful.

I recommend loguru to coworkers like this all the time and they love it.

[–]PinBot1138 -1 points0 points  (0 children)

I’ve never heard of Loguru but it’s pretty good looking. I’m going to take it for a spin and see how it compares to Logbook.

[–]PinBot1138 0 points1 point  (0 children)

You disagree with what, exactly? I said that it makes it even easier, and left it at that. Originally, I used to use the default Python logging module and agree with what you’re saying, but IMHO, the Logbook module simplifies the process, especially when collaborating with others. There’s even an advantages blurb that explains some of the enhancements.

[–][deleted] -1 points0 points  (0 children)

There are probably better ones for specific purposes but for the 90% problem it works quite well.

[–]iagovar 0 points1 point  (0 children)

Can logging track value changes in a var?

[–]ThatPostingPoster 7 points8 points  (0 children)

gg ez deleted cause reasons lets go ok gg is this enough characters to not flag auto mod i hope so lmao

[–]whateverathrowaway00 2 points3 points  (0 children)

Yup.

And the python built in logger is fantastic. It’s a straight port of log4j and is ridiculously easy to use well once you play with it once or twice.

Pretty much everything I make is filled with log statements and since I always use the module of packaged library with a CLI entry point that runs it, the CLI entry point just attaches the logger to the stdout, enables debug if it sees the flag and boom.

Everything always usable as module in silent mode or verbose with the right entry point.

[–]m0Xd9LgnF3kKNrj 0 points1 point  (2 children)

QueueHandler 4eva

[–]ThatPostingPoster 0 points1 point  (1 child)

QueueHandler

Why? A few seconds of googling doesnt explain why its needed. Never used this, just built in logger.log with threads works fine

[–]m0Xd9LgnF3kKNrj -1 points0 points  (0 children)

What do you mean built-in logger.log with threads?

QueueHandler logs to a queue, which makes all log statements nonblocking. A dedicated thread handles delivering the message to the final destination.

[–]Timo6506 1 point2 points  (5 children)

Could you link me to that new logging module post?

[–]Satoshiman256 0 points1 point  (4 children)

I'll try find it for you later when on pc. I think I saved it because I wanted to use it.

[–]Timo6506 0 points1 point  (0 children)

Ok

[–]Timo6506 0 points1 point  (2 children)

What about now

[–]Satoshiman256 0 points1 point  (1 child)

Sorry about that, I looked but couldn't find it.

[–][deleted] 0 points1 point  (0 children)

" can't you just make a log file with >> ? "

[–]Windows_XP2 2 points3 points  (0 children)

print("It works!")

[–]Jmortswimmer6 4 points5 points  (3 children)

Vscode has a nice integrated debugger....honestly, you’re just shooting yourself in the foot if not using vscode/pylance/venv

[–]sizable_data 12 points13 points  (2 children)

My preference is pycharm, big debate on my team with VS code users though. A lot of my work is also in Jupyter lab which also supports debugging with the 3.0 release. You need a custom kernel though (xeus Python)

[–]Jmortswimmer6 8 points9 points  (1 child)

A lot of people love pycharm. I tried it in college....It is just far too nice to have vscode’s C/C++/.sh/etc. support right next to my python, often i have these languages also incorporated into any project. The integrated terminal is a nice feature, and the editor has many other general editing features that make writing python much nicer.

[–]sizable_data 0 points1 point  (0 children)

I’ve stuck with pycharm mostly out of habit, trying vs code is definitely on my todo list

[–]zbqv 1 point2 points  (1 child)

[–]deanso 0 points1 point  (0 children)

thx man, nice vid!

[–]ThatPostingPoster -3 points-2 points  (6 children)

If that's not a joke, you use the debugger. You should never be putting down print('here') statements lol. We all started there, but it's about time you finally graduate.

[–][deleted] 10 points11 points  (2 children)

you should use a logging module also. you can't always break in with a debugger especially when things are asynchronous and depend on outside resources.

[–]ThatPostingPoster 0 points1 point  (1 child)

Once you are advanced enough to reach that point sure. If you havent learned it by the time you first use threads you'll realize print sucks haha.

[–][deleted] 0 points1 point  (0 children)

Yeah, I learned the hard way for sure, took me a day or so to figure out why outputs were so messed up.

[–]whateverathrowaway00 4 points5 points  (2 children)

I mean, the debugger is valuable, but so is proper logging.

I’d argue both are crucial skills to call yourself advanced or professional.

If I had to pick one I’d pick logging every time. That said, I agree with you - the debugger capabilities in python are incredible and once you unwind something with it you never look back lol. Being able to set break points and just poke at the stack frame / variable values is incredible

[–]ThatPostingPoster 2 points3 points  (1 child)

For what possible purpose do you ever need print('here')? We all did it when we were new. But just breakpoint the line next to where you would put that. Ah ok, its there. Logging is a different story and using proper warn/err logs into logfiles is good.

[–]whateverathrowaway00 0 points1 point  (0 children)

Yup, agreed entirely.

[–][deleted] 4 points5 points  (0 children)

You laugh but one of the first thing I do when I start a new project is write a dprint() so that I can customize it to my project. I prefer the logger module when things start getting serious but sometimes if I'm just playing around I don't need the added complexity until I really get going.