Why use backticks?

John Roth johnroth at ameritech.net
Wed May 7 06:16:52 EDT 2003


"Iwan van der Kleyn" <none at none.com> wrote in message
news:3eb81743$0$123$e4fe514c at dreader4.news.xs4all.nl...
> 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 ? :-)

I believe they are a hangover from very early versions of Python,
and have not been removed because there's not enough benefit
for the hassle.

John Roth
>
> Regards,
>
> Iwan
>






More information about the Python-list mailing list