Open files in the webbroser via the file:/// url scheme
With Pyhonista I want to write a small documentation viewer for html files I have created in Pythonista.
Let's say I have created a file "doco.html" under Pythonista's local file area. How can I view such a file via the webbrowser module?
does not work for me. However the file certainly exists: With open("doco.html") as f I can read the lines of the html file straight away.
You need to use the full path for a file URL, i.e. it needs to include the current directory path. You can get that via <code>os.getcwd()</code>. Here's a full example:
filename = 'doco.html'
with open(filename, 'w') as f:
full_path = os.path.join(os.getcwd(), filename)
fileurl = 'file://' + urllib.pathname2url(full_path)
Many thanks, omz. That's exactly what I want! :-)