Formatted String Literals in Python 2 -


while writing module in python 2.7 had need of way doing

name = "rodrigo" age = 34 print f"hello {name}, age {age}".format() 

although know do:

print "hello {name}, age {age}".format(name=name, age=age) 

format() in scope variables name , age, cast them string (if possible) , paste message. i've found implemented in python 3.6+, called formatted string literals. so, wondering (couldn't find googling) if has made approach similar python 2.7

you can try hackish way of doing things combining builtin locals function , format method on string:

foo = "asd" bar = "ghi"  print("{foo} , {bar}".format(**locals()) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -