We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The methodo "exec" runs the string as if it were python code.
>>> a = 2
>>> exec("a = a + 1")
>>> a
3
The "format" method replaces occurances of "{n}"
>>> "foo {0} {1}".format("bar","baz")
'foo bar baz'
I think the reason they did it may have something to do with formatting the input to range into an integer combined with a functional style "let" binding, but the formatting aspect doesn't seem to work for me. Range throws an error that it got a float.
But honestly you shouldn't write code like this. If a user can get a string into the "format" method then you have a security vulnerability. Also it is unreadable even if you know what the methods do.
Encryption
You are viewing a single comment's thread. Return to all comments →
The methodo "exec" runs the string as if it were python code.
The "format" method replaces occurances of "{n}"
I think the reason they did it may have something to do with formatting the input to range into an integer combined with a functional style "let" binding, but the formatting aspect doesn't seem to work for me. Range throws an error that it got a float.
But honestly you shouldn't write code like this. If a user can get a string into the "format" method then you have a security vulnerability. Also it is unreadable even if you know what the methods do.