Clickable hyperlinks

Deborah Swanson python at deborahswanson.net
Tue Jan 3 23:46:31 EST 2017


Steven D'Aprano wrote, on January 03, 2017 8:04 PM
> 
> 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="http://www.example.com">Example.</a>
> >> 
> >> # URL in angle brackets
> >> Example <http://www.example.com>
> >> 
> >> # URL alone
> >> http://www.example.com
> >> 
> >> # I can't remember what these are called
> >> <url:http://www.example.com>
> >> 
> >> # Markup
> >> [Example](http://www.example.com)
> >> 
> >> # Rest
> >> `Example <http://www.example.com>`_
> [...]
> 
> > 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!
 
I closed the IDLE window these were on, but the error arrow was pointing
to punctuation in each case, a colon in one case, angle bracket in
another. Sorta seems like IDLE is trying to do something with them and
not taking them as simple plain text. But it's not making hyperlinks, so
I'm not sure how much I care exactly what it's doing.
 
> 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.

I didn't try printing them before, but I just did. Got:

>>> print([Example](http://www.example.com)
      
SyntaxError: invalid syntax  (arrow pointing at the colon)
 
> py> print('<a href="http://www.example.com">Example.</a>')
> <a href="http://www.example.com">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 'http://www.example.com'" 
http://www.example.com


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.




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

I need to get a new power supply in my Linux-capable machine, but for
now I'm stuck with Winblows on a very old PC.

As I've mentioned in other posts on this thread, I'm now thinking that I
need to write a class to do this, and find out how Firefox and url aware
terminals in Linux do it. There must be a way.



More information about the Python-list mailing list