1

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

1
  • notepad sample_data.txt? Commented Dec 10, 2020 at 19:18

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think you can find gedit for MacOS. (It's probably not installed on Linux either if you are not running Gnome.)
TextEdit comes bundled with OSX

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.