Text formatting error: ‘=’ alignment not allowed in string format specifier

The error message occurs because ‘=’ alignment has been implied by the format specifier. The str.format format spec mini-language parser has decided on the alignment specifier “=” because: Preceding the width field by a zero (‘0’) character enables sign-aware zero-padding for numeric types. This is equivalent to a fill character of ‘0’ with an alignment … Read more

Using locals() and format() method for strings: are there any caveats?

There is now an official way to do this, as of Python 3.6.0: formatted string literals. It works like this: f’normal string text {local_variable_name}’ E.g. instead of these: “hello %(name) you are %(age) years old” % locals() “hello {name} you are {age} years old”.format(**locals()) “hello {name} you are {age} years old”.format(name=name, age=age) just do this: … Read more

Get AM/PM for a date time in lowercase using only a datetime format

I would personally format it in two parts: the non-am/pm part, and the am/pm part with ToLower: string formatted = item.PostedOn.ToString(“dddd, MMMM d, yyyy a\\t h:mm”) + item.PostedOn.ToString(“tt”).ToLower(); Another option (which I’ll investigate in a sec) is to grab the current DateTimeFormatInfo, create a copy, and set the am/pm designators to the lower case version. … Read more