Why use backticks?
Iwan van der Kleyn
none at none.com
Tue May 6 18:13:14 EDT 2003
I was showing a friend around Python using the Shell. He asked for a few
Python equivalents of common Perl and VB constructs. The use of
backticks come up. After showing the use of os.popen I demonstrated
out = `ls`
but to my surprise it didn't generate the expected SyntaxError but
rather a NameError. So after some Googling I found that backticks around
an expression ( `expression`) are equivalent to calling
repr(expression). Every day a learning moment.
But why this rather obscure use of backticks? Is there any use for them
except making code harder to read ? :-)
Regards,
Iwan
More information about the Python-list
mailing list