Created
July 11, 2022 20:46
-
-
Save RobiMez/2a20e3e298d6685608cd579bbdcd79a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def padd_str(text, to_chars, push_r: bool = False, push_l: bool = False): | |
"""Padds the string given with spaces to a certain char count ( like setw() in cpp )""" | |
if len(text) < to_chars: | |
excess = to_chars - len(text) | |
if push_r: # we pad to the left of text | |
text = ' ' * excess + text | |
elif push_l: # we pad to the right of text | |
text = text + ' ' * excess | |
else: # we dont pad if no direction | |
print('No direction specified , returning normal') | |
assert len(text) == to_chars | |
return text | |
elif len(text) == to_chars: | |
return text | |
else: | |
print('Text larger than max chars.') | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment