hasAnyoneElseBeenHere
MemeThey're all wrong.. `print(f"{x=}")`
I've been writing Python for about 8 years and never heard of this, TIL
I think this is quite a recent addition. Saves so much time
f-strings were introduced more than 3 years ago I think so that’s not that recently.
fstrings yes, the specific debug formatting (f'{x=}'
) however is relatively recent (3.12? Going by memory)
I use it in 3.8. I’m not going to google the exact version the syntax got introduced though…
If I remember right the only thing new in 3.12 and f-strings is being able to use "" inside {} (like f"{"6"*8}"
). I checked now and this syntax has been here since 3.8.
Ah you're right.
Isn't python 3.6 (or 3.5? I don't remember) like 7 years old at this point?
f-strings in 3.6 and this syntax in 3.8.
It’s always good to check the most notable things in every Python edition.
Only if you get to use it. Some of us are bound by our dependencies’ limitations.
ofc, as a student who isn’t really limited to that thing I still can’t use the latest version mostly. But when I can use it I know what I can do. If I would have been tied to a longer schedule I think I’ll check when I can update what’s new in this update or something like that.
Came here to say this. Turns out OP is not guru. ;)
I got the more important part right which is to use a logging library and not raw dog print statements 😭
Haha, that’s a great point.
Buuuut technically print() could be a logging library… if you’re a psychopath! :D
which i am
class PrintHandler(LoggingHandler): def emit(self, message): print(message)
Just use your own debug function with some internal spaghetti that returns an input("debug msg"). It's a break point and a debug print() at the same time. You can even use the inspection module to print out the wrapping function name so you know from where your ensuing hundreds of "break points" are called.
print("Hello world", file=open("today.log"))
I'm like 90% sure the default mode for open means you'll be overwriting the contents with this
Also, leaking file descriptors. Straight to jail
it will overwrite it, just set the mode to append.
And yeah, it was just a quick example
with open("today.log", "a") as log:
print("Hello, world!", file=log)
i think default is read only, but not sure
U right
Default is 'r'
why? I like to make way too much noise all over the general area I think the problem is in and then clean it up after I find the issue, print seems to work just fine. What are the upsides of a logging library?
Works with logging.debug() as well.
What witchcraft is this?! I hate that I like this... Syntax is wonky but so neat at the same time...
Nice, I didn't know this
At least keep the spaces print(f"{x = }")
I love this feature but when I'm printing\logging a member object's member, it basically prints self.member.object, which is nice as a default but I'd like a quick option to only print the child name. A workaround is to just make a new local variable with the shorter name I guess, but at that point I'd just revert to not using the = syntax.
200 IQ
you can also put spaces around, if you want `f"{x = }"` which would produce "x = 42"