0

Say, I have a list full of html links that looks something like this:

https://www.nytimes.com/2017/05/19/realestate/they-can-afford-to-buy-but-they-would-rather-rent.html

When I run a script in Python 3.6 Idle, I get the list as an output in Python 3.6 shell; however, they are not clickable. Is there a simple way to make them clickable in the shell?

I've googled around but I can't seem to find anything involving the Python shell.

Thank you.

Moondra
  • 3,638
  • 5
  • 37
  • 75
  • 2
    That's a limitation of the shell in general. It's a text interface. Clicking isn't a "thing". – Arya McCarthy May 19 '17 at 21:04
  • 1
    I don't know if this will help you at all, but there is the `webbrowser` module that will let you launch your default web browser at a provided URL. – FamousJameous May 19 '17 at 21:07
  • A duplicate of http://stackoverflow.com/questions/40419276/python-how-to-print-text-to-console-as-hyperlink – whackamadoodle3000 May 19 '17 at 22:30
  • @aryamccarthy I see. What options do I have? Jupyter Notebook allows me to have an output of clickable links. Besides this, any suggestion as to what I should look into? – Moondra May 19 '17 at 23:56
  • @FamousJameous Yeah, I know about `webrowser` but I think I would have to create a GUI, to do the whole "click to launch" right? – Moondra May 19 '17 at 23:57
  • @whackamadoodle3000 That link seems to be referring to output of command prompt, which is not what I'm asking. – Moondra May 20 '17 at 00:01
  • @Moondra did my answer work for you? – rdrey Jul 11 '19 at 19:42

2 Answers2

6

Since you mentioned py3.6, I'm using f-strings:

text = "This is a link"
target = "http://example.com"
print(f"\u001b]8;;{target}\u001b\\{text}\u001b]8;;\u001b\\")

This will make a clickable link in some terminals. (iTerm2, Gnome Terminal and even iPython running in one of these shells.)

To learn more about hyperlink escape sequences, see this Gist or this blog post https://purpleidea.com/blog/2018/06/29/hyperlinks-in-gnome-terminal/

ipython example of hyperlinks

rdrey
  • 8,529
  • 3
  • 34
  • 50
0

Sorry. No. IDLE is the most basic of editors and the shell is just that.

KDM
  • 153
  • 12