string formatting with mapping & '*'... is this a bug?
Diez B. Roggisch
deetsNOSPAM at web.de
Thu Sep 9 17:53:13 EDT 2004
More information about the Python-list mailing list
Thu Sep 9 17:53:13 EDT 2004
- Previous message (by thread): string formatting with mapping & '*'... is this a bug?
- Next message (by thread): string formatting with mapping & '*'... is this a bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Darn... I was hoping that Python would let me format strings with
> mappings in a more readable/maintainable way than thusly:
Maybe you can simply combine the sequence and the map - if you don't have
numeric keys, that might work. Like this:
vals = ['first' , 'second']
map = {'foo' : 'bar'}
map2 = dict(map.items() + [(str(i), v) for i, v in enumerate(vals)])
print "%(0)s %(foo)s %(1)s" % map2
Not perfect, but IMHO better than your eval-based solution.
--
Regards,
Diez B. Roggisch
- Previous message (by thread): string formatting with mapping & '*'... is this a bug?
- Next message (by thread): string formatting with mapping & '*'... is this a bug?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list