So far I have only been able to do it by assigning the comma to another string and then using that other string in the ljust command like this:
Code: Select all
d =','
ljust( myvariable, d)Could someone please advise me if there is a better way.
Code: Select all
d =','
ljust( myvariable, d)Code: Select all
# right adjust
s = "{data:,>10s}".format(data="abc")
print("<" + s + ">")
# left adjust
s = "{data:,<10s}".format(data="abc")
print("<" + s + ">")
# join
s = "{data_0:s},{data_1:s}".format(data_0="abc", data_1="xyz")
print("<" + s + ">")
# ljust, rjust
print ( "<" + "abc".ljust(10, ",") + ">")
print ( "<" + "abc".rjust(10, ",") + ">")Code: Select all
'abc'.ljust(10, ',') #should work just as well (as " version), but I like format()