0

I am using a particular version of Python (v 2.7.0) that doesn't allow me to use webbrowser or selenium libraries.

It also doesn't recognise os.startfile.

Is there another module to use that allows me to open up a locally addressed html file in my browser?

4
  • What is your python version? Commented Jan 14, 2022 at 12:43
  • It is Python 2.7.0 - cannot update it. Commented Jan 14, 2022 at 12:46
  • Which os you are using? Commented Jan 14, 2022 at 12:49
  • Using Windows 10 Commented Jan 14, 2022 at 12:50

2 Answers 2

1

Since you are using windows you can use os.startfile which will start a file with its associated application.

>>> import os
>>> os.startfile("PATH_TO_HTML_FILE")
Sign up to request clarification or add additional context in comments.

3 Comments

Though this works on most versions of python - it doesn't see the attribute startfile in the version I am using.
@MarkQuinn Ideally it should. Because startfile available in the python 2 documentation
Ideally yes and it does so on sublime text - but not of the software I require it to work on.
0

I fumbled on a result by treating it as an exe and project. Subprocess module worked. Tested a little further and should work for Jython 2.7.0 also.

import subprocess as sp
    sp.Popen(["browser_exe_path","html_path"])

Note - if using brave browser - it's exe wasn't recognised. chrome_proxy.exe worked in it's place.

Happy to learn something via feedback.

2 Comments

Glad that you find the solution. May be you should mark your solution as accepted. I will delete mine!
Thanks Abdul - we live and learn. That's the thing when you solve it yourself - it doesn't let you do that straight away - need to wait two days. But don't delete yours! It shows a workflow for others to learn from should they come to the same trouble.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.