J
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 repeated. In "solo=solo", the left part is a key and the
right part is the value of a local variable, but it looks strange.
I'd like something like this:
print "{solo} was captured by {jabba}".format(locals()) # WRONG!
But it doesn't work.
Do you have any idea?
Thanks,
Laszlo
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 repeated. In "solo=solo", the left part is a key and the
right part is the value of a local variable, but it looks strange.
I'd like something like this:
print "{solo} was captured by {jabba}".format(locals()) # WRONG!
But it doesn't work.
Do you have any idea?
Thanks,
Laszlo