Steven D'Aprano writes:
> On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote:
>
> > I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can
> > also take the namespace of an object. I only need to remember one
> > “give me the namespace” function for formatting.
[…]
>
> It's a code
On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote:
> Chris Rebert writes:
>
>> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
>
> I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
> take the namespace of an object. I only need to remember one “give m
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote:
> Chris Rebert writes:
>
>> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
>
> I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
> take the namespace of an object. I only need to remember one “give me
> th
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote:
>> You must use prefix-** in the call to unpack the mapping as keyword
>> arguments. Note that using locals() like this isn't best-practice.
>
> Who says so, and do you find their argument convincing? Do you have a
> reference for that so we can se
Chris Rebert writes:
> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT
I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also
take the namespace of an object. I only need to remember one “give me
the namespace” function for formatting.
> You must use prefix-*
Prasad, Ramit wrote:
print "{} was captured by {}".format(solo, jabba)
Is this Python2.7 specific?
Python 2.6.x :
print "{} was captured by {}".format('t1', 't2')
ValueError: zero length field name in format
Apparently it is 2.7 and greater -- my apologies for not specifying that.
~Ethan~
> print "{} was captured by {}".format(solo, jabba)
Is this Python2.7 specific?
Python 2.6.x :
>>>print "{} was captured by {}".format('t1', 't2')
ValueError: zero length field name in format
Ramit
This communication is for informational purposes only. It is not
intended as an offer or soli
On Mon, Jun 6, 2011 at 10:15 AM, Jabba Laci wrote:
> Hi,
>
> I'd like to simplify the following string formatting:
>
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
> # Han Solo was captured by Jabba the Hutt
>
> What I don't l
Steve Crook wrote:
On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: :
solo = 'Han Solo'
jabba = 'Jabba the Hutt'
print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
# Han Solo was captured by Jabba the Hutt
How about:-
print "%s was captured by %s" % (solo
On Mon, 6 Jun 2011 12:15:35 -0400, Jabba Laci wrote in
Message-Id: :
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
> # Han Solo was captured by Jabba the Hutt
How about:-
print "%s was captured by %s" % (solo, jabba)
--
ht
On Mon, Jun 6, 2011 at 9:15 AM, Jabba Laci wrote:
> Hi,
>
> I'd like to simplify the following string formatting:
>
> solo = 'Han Solo'
> jabba = 'Jabba the Hutt'
> print "{solo} was captured by {jabba}".format(solo=solo, jabba=jabba)
> # Han Solo was captured by Jabba the Hutt
>
> What I don't li
11 matches
Mail list logo