Created
February 4, 2023 15:41
-
-
Save mkckr0/b31fefb723ba6673e8012a98170450bc to your computer and use it in GitHub Desktop.
format all int to same width
This file contains 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
class int_fmt: | |
digit_count: int | |
def __init__(self, max_n: int) -> None: | |
self.digit_count = len(str(max_n)) | |
def __call__(self, n: int) -> str: | |
return '{n:0{w}d}'.format(n=n, w=self.digit_count) | |
fmt = int_fmt(100) | |
fmt(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment