Re: new string formatting with local variables

2011-06-07 Thread Ben Finney
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

Re: new string formatting with local variables

2011-06-06 Thread Steven D'Aprano
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

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
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

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
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

Re: new string formatting with local variables

2011-06-06 Thread Ben Finney
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-*

Re: new string formatting with local variables

2011-06-06 Thread Ethan Furman
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~

RE: new string formatting with local variables

2011-06-06 Thread Prasad, Ramit
> 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

Re: new string formatting with local variables

2011-06-06 Thread Eric Snow
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

Re: new string formatting with local variables

2011-06-06 Thread Ethan Furman
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

Re: new string formatting with local variables

2011-06-06 Thread Steve Crook
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

Re: new string formatting with local variables

2011-06-06 Thread Chris Rebert
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

new string formatting with local variables

2011-06-06 Thread Jabba Laci
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 like here is this: "solo=solo, jabba=jabba", i.e. the same thing is re