1

images_name = "%s/%03d_image.jpg" % (target, i)

I have formatted it to images_name = '{:03d_image.jpg}'.format((target, i))

Could you please point me out the mistake?

Also can this be formatted in a better manner?

format_str = ('%s: Step %d, Loss = %.2f (%.1f examples/sec; %.3f ' 'sec/batch)')

print(format_str % (datetime.now(), step, loss_value,examples_per_sec, duration))

1 Answer 1

1

You should specify separate placeholders just like you've done with the old-format style and not include parts that do not need formatting within the curly braces:

images_name = '{}/{:03d}_image.jpg'.format(target, i)

The same rule applies to the second string:

format_str = '{}: Step {:d}, Loss = {:.2f} ({:.1f} examples/sec; {:.3f} sec/batch)'
print(format_str.format(datetime.now(), step, 
                        loss_value, examples_per_sec, duration))

Read more about the old and new format specifications in Python.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.