RE: Python: Please Help Understanding String Formatting Syntax

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 2 Aug 2011 16:20:09 -0400

 

If you search for "two or more" on this page it will take you right to what
your wanting.

 

http://docs.python.org/library/stdtypes.html

 

From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Homme, James
Sent: Tuesday, August 02, 2011 1:22 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Python: Please Help Understanding String Formatting Syntax

 

Hi,

I understand what I have read about string formatting so far in the Python
Standard Library documentation, namely, I understand about using the % sign
and various letters, then using either a single string or a tuple to specify
what to substitute, but I don't understand some things about the below
string formatting. This piece of text is from the book The Python Standard
Library By Example, and talks about the ConfigParser module. Specifically, I
don't understand why it excepts the formatting without quotes, and I'm
guessing that the s after the  parentheses means that the various pieces are
strings.  I can see that it's grabbing values from the key-value pares. In
my reading, though, about string formatting, I haven't seen this particular
syntax. Where is it in the Python docs?

 

See below.

 

14.8.7. Combining Values with Interpolation

 

SafeConfigParser provides a feature called interpolation

that can be used to combine values together. Values containing standard
Python format strings trigger the interpolation feature when they are
retrieved

with get(). 

Options named within the value being fetched are replaced with their values
in turn, until no more substitution is necessary.

 

... For example, this configuration file separates the protocol, hostname,
and port from the URL as separate options.

 

[bug_tracker]

protocol = http

server = localhost

port = 8080

url = %(protocol)s://%(server)s:%(port)s/bugs/

 

Thanks.

 

Jim

Jim Homme,

Usability Services,

Phone: 412-544-1810.

 

 

  _____  

This e-mail and any attachments to it are confidential and are intended
solely for use of the individual or entity to whom they are addressed. If
you have received this e-mail in error, please notify the sender immediately
and then delete it. If you are not the intended recipient, you must not
keep, use, disclose, copy or distribute this e-mail without the author's
prior permission. The views expressed in this e-mail message do not
necessarily represent the views of Highmark Inc., its subsidiaries, or
affiliates.

Other related posts: