Unsolved Call HTML file from a Python program
-
Hello,
my text editor has a program help as an HTML file.
I solved the call of this HTML file as follows:def help displays (): self.statusBar (). showMessage ("Show help") filename = os.path.abspath (".") + '\\ Help.html' filename = os.path.realpath (filename) webbrowser.open_new_tab (filename)
when I call my program from PyCharm it works.
when I start my program from the Dos window (Windows 10),
then go to https://www.google.de/#spf=1593888337401.Question:
How can I use Python to call an HTML file so that it ALWAYS works?
it should also work on all operating systems. -
Hi
Where is this help file ?
Maybe its just a path issue.
When run from PyCharm, it current dir is set to the correct one.
When run from cmd prompt, its not.or something like that.
You could add some checks to see if file really exists when run from prompt.
#include <QFileInfo> bool fileExists(QString path) { QFileInfo check_file(path); // check if path exists and if yes: Is it really a file and no directory? return check_file.exists() && check_file.isFile(); } (c++ but should be somewhat the same in python)
-
Hi,
the Helpfile is in the same directory like the pythonfile. -
@PythonQTMarlem said in Call HTML file from a Python program:
os.path.abspath (".")
I know my Problem:
os.path.abspath (".")
don't return the directory where my python-file is.
Question:
How I get the directory where my python-file is? -
Hi
In c++ this gives me the folder where the .exe is
qDebug() << "App path : " << qApp->applicationDirPath();However, i dont know if it will work the same with python ?
the py file sort of being the exe but not really. -
Hi,
@PythonQTMarlem said in Call HTML file from a Python program:
How I get the directory where my python-file is?
os.path.abspath(__file__)
-
@mrjj
filename = QApplication.applicationDirPath() doesn't work.
it returns this directory: C:/ProgramData/Anaconda3@SGaist
it returns C:\Projekte\Python\PQT-Texteditor\PQTTexteditor.pyQuestion:
how can i get this without "PQTTexteditor.py" -
By looking at the os.path documentation: dirname.
-
this is the solution:
def hilfeanzeigen(): self.statusBar().showMessage("Hilfe anzeigen") filename = os.path.dirname(os.path.abspath(__file__)) + '\\Hilfe.html' webbrowser.open_new_tab(filename)
-
it's not perfect! it doesn't work in Ubntu.
Question:
What I have to change? -
I try this:
def hilfeanzeigen(): self.statusBar().showMessage("Hilfe anzeigen") filename = os.path.dirname(os.path.abspath(__file__)) + '//Hilfe.html' webbrowser.open_new_tab(os.path.abspath(filename))
it works in Windows and in Ubuntu.
But I don't know if it is the profi solution. -
If you want to be safe use os.path.join to build paths.