1

I'm trying to find help for string formatting in Python. I have tried the following:

>>> help(''.format)

But the help I get is:

Help on built-in function format:

format(...)
    S.format(*args, **kwargs) -> string

    Return a formatted version of S, using substitutions from args and kwargs.
    The substitutions are identified by braces ('{' and '}').
(END)

What I'm looking for is the equivalent of the online string format specification. Is this information available through the help() command? If so, how can I access it?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • 2
    No, I don't think it is. – jonrsharpe May 10 '15 at 19:46
  • Down voters, please don't down vote without saying why - this leaves me with little opportunity to improve my question. – Chris Snow May 10 '15 at 19:51
  • I don't know why this was downvoted, it is a legitimate question. – Padraic Cunningham May 10 '15 at 19:52
  • I personally rarely find the online help useful for stuff like this, because even when you find what you want, it's only broken down by top-level sections, and there's just way too much to wade through… but it seems reasonable that you could be in some situation where you don't have online access or an external build of the docs or the source to build them from, in which case you'd want to know how to do this, so I think it's worth upvoting the question. – abarnert May 10 '15 at 20:02

1 Answers1

4

There are two ways to find this.

First, type help() to get interactive help, then topics, then look at the list of topics and try to guess see if any of them look relevant. FORMATTING looks good. And help('FORMATTING') does give you the Format String Syntax, which includes the Format Specification Mini-Language section you wanted.

Alternatively, you can ack or grep the source for a string that only appears in that section of the docs. (I used the section title, 'Format Specification Mini-Language', but that obviously has the problem that it will find links to that section as well as the section itself, so be a little smarter than me…:) This will ultimately get you to the same information—although you do have to know enough about the structure of the source tree and how the internal help, web docs, and other documentation formats are built to know what is and isn't relevant, or you'll waste a lot of time.

abarnert
  • 354,177
  • 51
  • 601
  • 671