Is there any way to pass an “empty” numeric type into a numeric format specifier and have it print the blank space associated with that specifier?
ie.
n = "Scientific:"
v = 123.321
strfmt = "%5.4E"
output = "%s|"+strfmt+"|"
print output % (n, v)
> Scientific:|1.2332E+02|
v = EMPTY
print output % (n, v)
> Scientific:| |
The ultimate goal is to deal with incomplete lines without adaptively changing the format string while looping
perline = 3
n = ["1st:","2nd:","3rd:","4th:","5th:","6th:"]
v = [1.0, 2.0, 3.0, 4.0]
strfmt = "%5.4E"
output = ("%s|"+strfmt+"| ")*perline+"\n"
for args in map(EMPTY,*[iter(n),iter(v)]*perline):
print output % args
> 1st:|1.0000E+00| 2nd:|2.0000E+00| 3rd:|3.0000E+00|
> 4th:|4.0000E+00| 5th:| | 6th:| |
To execute the above code I replaced EMPTY with None although that gives an error when you pass None to the format string
After viewing the responses it appears that there is no thing you can pass to a numeric format specifier to have it print the blank space associated with it.
There are a number of ways to work around this shown below. Personally I liked parts of Unutbu’s answer. I think the way I will ultimately do it is create two format specifiers at the beginning and use logic as suggested by Blender.