Clickable hyperlinks

Steve D'Aprano steve+python at pearwood.info
Wed Jan 4 05:39:15 EST 2017


On Wed, 4 Jan 2017 08:32 pm, Deborah Swanson wrote:

> Thanks, Steven. Yes, of course if you want to print strings you must
> enclose them in quotes. I think you learn that in Week 1 of any
> introductory course on Python.
> 
> But we aren't trying to print strings here, the point is to produce
> clickable links. I didn't enclose them with quotes because I didn't see
> any point in printing plain text when I wanted clickable links. I
> actually didn't understand why you thought I should print them, but it
> never would have occurred to me that you wanted me to print out a bunch
> of silly plain text strings, apparently just for the heck of it.

What we have here is a failure to communicate :-)

I apologise for ruffling your feathers, but its difficult to judge another
person's level of knowledge. In someways you're obviously quite
knowledgeable about Python, but in other ways you're still learning (as we
all are!) and I'm afraid I may have misjudged exactly what your level of
knowledge was. Sorry about that.

I'm not suggesting that you print "silly plain text strings" just for the
heck of it. You've asked how to get a clickable link using Python. There is
only one way I know of to get a clickable link using Python:

Write out a link as plain text to another application which then interprets
the plain text as a clickable link.

You *might* be able to get clickable links in Python by writing an entire
GUI application, using (say) the tkinter library, or one of the third-party
GUI libraries like wxPython, kivy, pyqt, or others, but I haven't a clue
how. But even there, your links will start off as text, which means you
will still need to surround them with quotes to make them strings.


Aside: you've actually raised a fascinating question. I wonder whether there
are any programming languages that understand URLs as native data types, so
that *source code* starting with http:// etc is understood in the same way
that source code starting with [ is seen as a list or { as a dict?


But back to your problem: short of writing you own GUI application, in which
case you can do *anything you like*, you can:

- write out a HTML file containing the URLs you want, in <a href= ... </a>
tags, then open the HTML file in a web browser and let the web browser
interpret the HTML tags as clickable links;


- write out an Excel spreadsheet, using whatever format Excel expects, open
the spreadsheet in Excel, and let Excel interpret the mystery format as a
clickable link;

- print the URL to the console, and see if the console is smart enough to
interpret it as a clickable link.


I'm sorry that I can't give you a one-sentence answer "just use
such-and-such a function, that does exactly what you want in a
platform-independent manner" :-(




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list