Reputation: 303
I'm printing out a bunch of data and it would make things much easier to debug if I could review it in-line.
I've added some -
which help but it's not always ideal as some of the .png
image names get quite long.
My string is:
`print(str("Search Count: ") + str(counter) + str(" - ") + str("Searching for: ") + str(name) + ' - ' + '%03d keypoints matched - %03d' % (len(good), len(keypoints_needle)))`
I can't find a single post on stack about adding padding to a terminal output/print.
What do I need to do to be able to align the section that starts with three integers?
Edit/Update: The lines are generated via a loop one at a time rather than a function that runs over them all then outputs the data.
Search Count: 79 - Searching for: The Flying Brick.png ---------------- 004 keypoints matched - 481
Search Count: 80 - Searching for: The Loud One.png ---------------- 001 keypoints matched - 478
Search Count: 81 - Searching for: theTobyKiDD.png ---------------- 001 keypoints matched - 474
Search Count: 82 - Searching for: Thoraner.png ---------------- 000 keypoints matched - 441
Search Count: 83 - Searching for: TiMe2BuRn.png ---------------- 002 keypoints matched - 479
Search Count: 84 - Searching for: Ty Pod Challenge (3).png ---------------- 010 keypoints matched - 416
Search Count: 85 - Searching for: UNSC_DD-906.png ---------------- 010 keypoints matched - 487
Search Count: 86 - Searching for: Wraithbourne.png ---------------- 001 keypoints matched - 500
Search Count: 87 - Searching for: xBiGx.png ---------------- 002 keypoints matched - 398
Search Count: 88 - Searching for: Yukaze.png ---------------- 013 keypoints matched - 390
Search Count: 89 - Searching for: zAreliusZ.png ---------------- 005 keypoints matched - 500
Search Count: 90 - Searching for: Zeg.png ---------------- 007 keypoints matched - 500
Search Count: 91 - Searching for: ZEII.png ---------------- 001 keypoints matched - 337
Search Count: 92 - Searching for: Zeppur.png ---------------- 010 keypoints matched - 361
Upvotes: 0
Views: 255
Reputation: 248
A similar solution, using formated string literals:
names = ["The Flying Brick.png", "The Loud One.png", "Ty Pod Challenge (3).png"]
counts = [79, 80, 84]
good_list = [4, 1, 10]
keypoints_list = [481, 478, 416]
max_len = len(max(names, key=len)) + 1
for name, count, good, keypoints_needle in zip(
names, counts, good_list, keypoints_list
):
print(
f"Search Count: {count} - Searching for: {name} " + "-" * (max_len - len(name)),
f"{good:0>3d} keypoints matched - {keypoints_needle}"
)
Output:
Search Count: 79 - Searching for: The Flying effefff Brick.png - 004 keypoints matched - 481
Search Count: 80 - Searching for: The Loud One.png ------------- 001 keypoints matched - 478
Search Count: 84 - Searching for: Ty Pod Challenge (3).png ----- 010 keypoints matched - 416
Upvotes: 0
Reputation: 146
Here, we should have the length of the longest PNG file name to calculate the number of dash required so that we can align the string.
If you have the list of PNG file names then you can find the longest PNG file name by using the max function.
# Creating a list of string with test data
string_lst = ['zLavender Town.png', 'zMitto.png']
# fetching file with longest name
longest_png_file_name = max(string_lst, key=len)
# taking dummy data for testing purpose
counter = 1
good = '2'
keypoints_needle = '3'
# Test case 1
name_0 = string_lst[0]
required_dash_0 = len(longest_png_file_name) - len(name_0) + 1
print(str("Search Count: ") + str(counter) + str(" - ") + str("Searching for: ") + str(name_0) +
' ' + '-'*required_dash_0 + ' %03d keypoints matched - %03d' % (len(good), len(keypoints_needle)))
# Test case 2
name_1 = string_lst[1]
required_dash_1 = len(longest_png_file_name) - len(name_1) + 1
print(str("Search Count: ") + str(counter) + str(" - ") + str("Searching for: ") + str(name_1) +
' ' + '-'*required_dash_1 + ' %03d keypoints matched - %03d' % (len(good), len(keypoints_needle)))
Upvotes: 1