Re: new string formatting with local variables

2011-06-07 Thread Ben Finney
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: On Tue, 07 Jun 2011 10:11:01 +1000, Ben Finney wrote: I tend to use ‘ufoo {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

Re: new string formatting with local variables

2011-06-06 Thread Chris Rebert
On Mon, Jun 6, 2011 at 9:15 AM, Jabba Laci jabba.l...@gmail.com 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

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: mailman.2490.1307376958.9059.python-l...@python.org: 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

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: mailman.2490.1307376958.9059.python-l...@python.org: 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

Re: new string formatting with local variables

2011-06-06 Thread Eric Snow
On Mon, Jun 6, 2011 at 10:15 AM, Jabba Laci jabba.l...@gmail.com 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

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

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 Ben Finney
Chris Rebert c...@rebertia.com writes: print {solo} was captured by {jabba}.format(**locals()) # RIGHT I tend to use ‘ufoo {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

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney ben+pyt...@benfinney.id.au 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

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney ben+pyt...@benfinney.id.au wrote: Chris Rebert c...@rebertia.com writes: print {solo} was captured by {jabba}.format(**locals()) # RIGHT I tend to use ‘ufoo {bar} baz.format(**vars())’, since ‘vars’ can also take the namespace of an object. I only

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 c...@rebertia.com writes: print {solo} was captured by {jabba}.format(**locals()) # RIGHT I tend to use ‘ufoo {bar} baz.format(**vars())’, since ‘vars’ can also take the namespace of an object. I only need to remember one