Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9118

Re: String concatenation vs. string formatting

Date 2011-07-09 17:02 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
Subject Re: String concatenation vs. string formatting
References <4E17661D.6020307@gmail.com> <loom.20110709T125838-983@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.806.1310248971.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 2011.07.09 06:06 AM, Vinay Sajip wrote:
> In a logging context at least, using the form like
>
> logger.debug("formatting message with %s", "arguments")
>
> rather than
>
> logger.debug("formatting message with %s" % "arguments")
How would I do that with the newer formatting? I've tried:
> logger.info('Binary preset file {file} successfully stored.', {file :
> queue[0].preset_file})
(global name 'file' not defined)
and
> logger.info('Binary preset file {file} successfully stored.',
> file=queue[0].preset_file)
(unexpected keyword 'file')

> By the way, logging primarily uses %-formatting instead of the newer
> {}-formatting, because it pre-dates {}-formatting. In more recent versions of
> Python, all of Python's three formatting styles are supported - see
I've noticed. :-)
> log_formatter = logging.Formatter('{asctime} - __main__ - {funcName} -
> line {lineno} - {levelname} - {message}', style='{')

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: String concatenation vs. string formatting Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-09 17:02 -0500

csiph-web