MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/igvny1/python_goes_brrrr/g2y3n37
r/ProgrammerHumor • u/das_freak • Aug 26 '20
789 comments sorted by
View all comments
Show parent comments
1
IN that case, couldn't you just use log(f'python goes b{"r"*10}') instead, for a cleaner execution? If it's only formatting on execution, the format string can still handle inline processing.
log(f'python goes b{"r"*10}')
2 u/nemec Aug 26 '20 No, that's immediate evaluation. Imagine this is the definition of log:def log(fmt, *args): if LOGGING_IS_ENABLED: print(fmt.format(*args))Note how the arguments aren't formatted into the string unless logging is enabled. In your example, the log method would see only one string argument. 1 u/mxzf Aug 27 '20 Fair enough. I haven't actually dug into the implementation of logging.
2
No, that's immediate evaluation. Imagine this is the definition of log:
log
def log(fmt, *args): if LOGGING_IS_ENABLED: print(fmt.format(*args))
Note how the arguments aren't formatted into the string unless logging is enabled. In your example, the log method would see only one string argument.
1 u/mxzf Aug 27 '20 Fair enough. I haven't actually dug into the implementation of logging.
Fair enough. I haven't actually dug into the implementation of logging.
logging
1
u/mxzf Aug 26 '20
IN that case, couldn't you just use
log(f'python goes b{"r"*10}')instead, for a cleaner execution? If it's only formatting on execution, the format string can still handle inline processing.