Clickable hyperlinks

Steven D'Aprano steve+comp.lang.python at
Tue Jan 3 23:04:02 EST 2017

On Wednesday 04 January 2017 14:04, Deborah Swanson wrote:

> Steve D'Aprano wrote, on January 03, 2017 4:56 PM
>> Python can't force the console to treat something as a
>> clickable link, if the console has no capacity for clickable
>> links. Nor can Python predict what format the console uses to
>> recognise a link.
>> The best you can do is to experiment with a couple of simple
>> formats and see which, if any, your console understands:
>> # HTML
>> <a href="">Example.</a>
>> # URL in angle brackets
>> Example <>
>> # URL alone
>> # I can't remember what these are called 
>> <url:>
>> # Markup
>> [Example](
>> # Rest
>> `Example <>`_

> I tried all of your examples in IDLE, and they all get syntax errors.
> I'd expect the same from PyCharm, though I didn't try it.

Syntax errors? How can you get syntax errors from *output* text?

The above are just text, no different from:

    Hello World!

Of course you have to put quotes around them to enter them in your source code. 
We don't expect this to work:

    print(Hello World!)

you have to use a string literal with quotes:

    print('Hello World!')

Same for all of the above.

py> print('<a href="">Example.</a>')
<a href="">Example.</a>

That's the Python interactive interpreter (with a custom prompt, I prefer "py>" 
rather than the default ">>>"). Or I can do this from the operating system's 
shell prompt:

steve at runes:~$ python -c "print ''"

If I do this in GNOME Terminal 2.30.2, the URL http... is a clickable link. But 
that's specific to the terminal. Other terminals may or may not recognise it.

"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson

More information about the Python-list mailing list