Andre Alexander Bell wrote:
On 09/14/2010 08:20 PM, Miki wrote:
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
Thanks for your answer. Actually your answer tells me that my example
was misleading. Consider the template
s = 'A template with {variable1} and
Peter Otten wrote:
Andre Alexander Bell wrote:
On 09/14/2010 08:20 PM, Miki wrote:
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
Thanks for your answer. Actually your answer tells me that my example
was misleading. Consider the template
s = 'A template with
On 09/15/2010 10:00 AM, Peter Otten wrote:
def extract_names(t, recurse=1):
for _, name, fmt, _ in t._formatter_parser():
if name is not None:
yield name
if recurse and fmt is not None:
for name in extract_names(fmt, recurse-1):
Andre Alexander Bell wrote:
On 09/15/2010 10:00 AM, Peter Otten wrote:
def extract_names(t, recurse=1):
for _, name, fmt, _ in t._formatter_parser():
if name is not None:
yield name
if recurse and fmt is not None:
for name in
On 09/15/2010 10:48 AM, Peter Otten wrote:
I personally would not be too concerned about the leading underscore, but
you can use
string.Formatter().parse(template)
instead.
Thanks for this pointer. I like it this way. So if I now combine your
generator with your suggestion, I end up with
Hello,
I'm used to write in Python something like
s = 'some text that says: %(hello)s'
and then have a dictionary like
english = { 'hello': 'hello' }
and get the formatted output like this:
s % english
Occasionally I want to extract the field names from the template string.
I was used
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
On Sep 14, 9:59 am, Andre Alexander Bell p...@andre-bell.de wrote:
Hello,
I'm used to write in Python something like
s = 'some text that says: %(hello)s'
and then have a dictionary like
english = { 'hello':
On Tuesday 14 September 2010, it occurred to Miki to exclaim:
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
No, you can't. This only works with dicts, not with arbitrary mappings, or
dict subclasses that try to do some kind of funny stuff.
On Sep 14, 9:59 am,
On Tue, Sep 14, 2010 at 3:20 PM, Thomas Jollans tho...@jollybox.de wrote:
On Tuesday 14 September 2010, it occurred to Miki to exclaim:
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
No, you can't. This only works with dicts, not with arbitrary mappings, or
dict
On 09/14/2010 08:20 PM, Miki wrote:
You can use ** syntax:
english = {'hello':'hello'}
s.format(**english)
Thanks for your answer. Actually your answer tells me that my example
was misleading. Consider the template
s = 'A template with {variable1} and {variable2} placeholders.'
I'm
10 matches
Mail list logo