'How do I open a specific webpage in a new tab before a Python function returns?

In my main.py I have a Python function called def loop(request) and it returns a string. At the end of the function, before I return the value, I try to open a webpage

def loop (request):

    text = "BLAH"
    #THESE DIDN'T WORK
    webbrowser.open('http://net-informations.com', new=2)
    urllib.request.urlopen('https://www.google.com/')
    return text

and the rest of the script is as follows:

with open('abc.json', 'r') as f:
    dt = json.load(f)
f.close()
ret = loop(dt)
# print('RET ' + str(ret))
#THESE DIDNT OPEN THE PAGE AS WELL :(
try:
    print("?????????????")
    urllib.request.urlopen('https://www.google.com/')
except Exception as e:
    print(str(e))

I run my python in the terminal as python3 main.py However on the terminal I can execute python3 and it launches the webpage...

>>> import webbrowser
>>> webbrowser.open('http://net-informations.com', new=2)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source