Went on a break and decided to tweak my 2 second decorator, in anticipation of an early early Spring (cross your fingers). Twenty minutes after adding umbrellas (you might have to replace them with another UTF-8 character), the first line was driving me nuts, no matter what 'I wish it worked this way' stuff I threw at the string.
Finally, using the +
operator (the second line) fixed my problem, even though it couldn't be used in the first separation. So, I ask you: Why is the spacing off at all (when both concatenation operators are the same), and, well, why does this non-standard approach work?
from functools import wraps
def dasher(f):
@wraps(f)
def wrapped(*args, **kwargs):
brella = '\U00002602'
print(f"{brella} #", f"{brella} # "*8, f"{brella}")
print(f"{brella} #", f"{brella} # "*8 + f"{brella}") # concat and crazy
# print("\U00002602 #","\U00002602 # "*8,"\U00002602")
# print(f"\U00002602 #",f"\U00002602 # "*8,f"\U00002602")
print()
return wrapped
@dasher
def dashed():
pass
dashed()
☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂
☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂ # ☂
Pythonic Refactoring
Thanks to Chris Doyle's answer in the comments, following an explanation of spacing differences between ,
and +
, the following dirties things up again with some complexity, but extends usability, illustrating spacing while avoiding the need for sep=''
.
print(' # '.join(brella*3), '#' ,' xx '.join(brella*5) , '#' ,' # '.join(brella*3))
print(' # '.join(brella*3) + ' o ' +' xx '.join(brella*5) + ' o ' +' # '.join(brella*3))
With output:
☂ # ☂ # ☂ # ☂ xx ☂ xx ☂ xx ☂ xx ☂ # ☂ # ☂ # ☂
☂ # ☂ # ☂ o ☂ xx ☂ xx ☂ xx ☂ xx ☂ o ☂ # ☂ # ☂