Reputation: 21
I am creating a GUI in Python that needs to be ran in Unix and Windows. In the python main script I need to create and open (like a popup) a text file. I have the code for unix operative system and it is:
os.chdir(path=app.sourceFolder+"/Fastq_downloaded")
files = os.listdir(os.getcwd())
sample_data = open("sample_data.txt", "w")
sample_data.write("ID" + "\t" + "Condition" + "\n")
for i in range(len(files)-1):
sample_data.write(files[i][:-6] + "\t" + "\n")
sample_data.write(files[-1][:-6] + "\t")
sample_data.close()
if "Linux" in o_sys or "Darwin" in o_sys:
os.system('gedit sample_data.txt')
First I create a file with information and then I open it calling the gedit from the terminal. But in windows I don't have any idea of how we can open a text file from terminal and show it to the user. Some advise? Thank you very much
Upvotes: 1
Views: 738
Reputation: 1284
This is simple. In windows you use notepad.
Code:
import sys
import os
if sys.platform == 'win32':
os.system('notepad sample_data.txt')
OR to add to your code
if "Linux" in o_sys or "Darwin" in o_sys:
os.system('gedit sample_data.txt')
elif 'win32' in o_sys:
os.system('notepad sample_data.txt')
Upvotes: 1