Last active
May 4, 2019 16:03
-
-
Save 4383/6b8160c1db5dae411ec91ba505d27cfe to your computer and use it in GitHub Desktop.
Test padding implementation
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
threads = [ | |
"", | |
"1111111111111-thread1-base ", | |
"1111111111111-thread2-base ", | |
"1111111111111-thread3-very-long ", | |
"1111111111111-short ", | |
"1111111111111-thread4-base ", | |
"1111111111111-thread3-very-long-long ", | |
"1111111111111-short ", | |
"1111111111111-thread5-base ", | |
"", | |
"1111111111111-thread6-base ", | |
] | |
tasks = [ | |
"time {}line task1", | |
"time {}call task2", | |
"time {}line task3", | |
] | |
class Test: | |
def __init__(self): | |
self.padding = 0 | |
def set_padding(self, thread_info): | |
current_thread_len = len(thread_info) | |
self.padding = max(self.padding, current_thread_len) | |
return thread_info.ljust(self.padding) | |
def trace(self): | |
for thread in threads: | |
for line in tasks: | |
print(line.format(self.set_padding(thread))) | |
if __name__ == "__main__": | |
test = Test() | |
test.trace() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will output: