C
candide
With Python 2.7 :
What is this curious syntax on line 2 ? Where is it documented ?
What is this curious syntax on line 2 ? Where is it documented ?
With Python 2.7 :
What is this curious syntax on line 2 ? Where is it documented ?
With Python 2.7 :
What is this curious syntax on line 2 ? Where is it documented ?
With Python 2.7 :
'"Ha ha! \'Tis mine!", he said.''foo'
candide said:OK, thanks for your explanation, it was just stringisation !
I erroneously focused on
+x+
as a kind of placeholder unknown to me, instead of left and right
concatenations
It would be more readable for me if it were edited
or with string formatting :
This is one of the (very) few places PHP wins over Python. In PHP, I
would write this as
print "'$x'"
rusi said:You dont find
readable? Why?
Roy said:There's something nice about building up strings in-line, as
opposed to having to look somewhere to see what's being interpolated.
To give a more complex example, consider:
print "$scheme://$host:$port/$route#$fragment"
That certainly seems easier to me to read than:
print "%s://%s:%s/%s#%s" % (scheme,
port,
host,
route,
fragment)
because I don't have to line up the nth format specifier with the nth
data item.
well, in python3 you can use dict to format strings
b
and you can achieve php interpolation via locals()
b
well, in python3 you can use dict to format strings
b
'spam'
and you can achieve php interpolation via locals()
b
Steven said:You can do that, but when reading code I consider any direct use of
locals() (and globals() for that matter) to be a code smell:
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.