Ding-Yi Chen: Legacy Python str.format() gotcha

In Python 2.7, str.format() works with empty string like:

python -c "print '{}'.format(''')"

However, in Python < 2.6,  you will see:

ValueError: zero length field name in format

Workaround? Use %-formatting like:

python -c "print '%s' % ''"

 


Source From: fedoraplanet.org.
Original article title: Ding-Yi Chen: Legacy Python str.format() gotcha.
This full article can be read at: Ding-Yi Chen: Legacy Python str.format() gotcha.

Advertisement


Random Article You May Like

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*