2

I have this format string:

print "{u: <16}  {l: >16}  {lse: <19}  {active: <12}".format(...)

which works fine in the Python console, but when run in my program, it prints <19 (literally) for the lse part. When I remove the <19 in the format specifier for lse, it does work...

My data is fine, because when just using plain {u}, etc, the correct data is printed.

Update the field is a datetime field. How can I print a datetime field using the format specifiers?

Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185
  • Maybe this answer is [relevant](http://stackoverflow.com/questions/311627/how-to-print-date-in-a-regular-format-in-python) ? `print "We are the {:%d, %b %Y}".format(today)` – Lorenzo Belli Oct 14 '16 at 09:28

1 Answers1

1

Apparently, a datetime object does not abide by the format specifier rules. When cast to a str, it works:

print "{d: <12}".format(str(datetime.datetime.now()))
Moses Koledoye
  • 74,909
  • 8
  • 119
  • 129
Bart Friederichs
  • 32,037
  • 14
  • 96
  • 185