Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify string formats when formatting stings #169

Closed
micahflee opened this issue Dec 10, 2014 · 2 comments
Closed

Specify string formats when formatting stings #169

micahflee opened this issue Dec 10, 2014 · 2 comments
Labels
Milestone

Comments

@micahflee
Copy link
Collaborator

Some feedback:

What about specifying formats every time it's possible to do so when you're using the str.format() method instead of accessing argument by position? https://docs.python.org/2/library/string.html#formatspec

@micahflee micahflee added the bug label Dec 10, 2014
@micahflee micahflee modified the milestone: 0.7 May 13, 2015
@micahflee
Copy link
Collaborator Author

I'm trying to figure out how to actually specify format strings using str.format(), and it's quite confusing. Right now I do stuff like this:

'This is a string {0}, and this is an int {1}'.format('foobar', 100)

But I'm not specifying types. I know I can specify types if I use the % string formatting operator, like this:

'This is a string %s, and this is an int %d' % ('foobar', 100)

But how can I specify the types while still keeping the .format() syntax?

@micahflee
Copy link
Collaborator Author

Aha, figured it out.

'This is a string {0:s}, and this is an int {1:d}'.format('foobar', 100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant