Is it possible to open windows files with python?
Like notepad, and stuff..

Thanks Dan08.

Recommended Answers

All 3 Replies

Member Avatar for sravan953

Yes, yes you can!

If you want to open a .txt file named: "log.txt" which is in the same directory as where you are working from:

log=open("log.txt",'r')
"""
Here, you can replace 'log' with any name you want. And 'r' specifies that you want to read from the file, whereas 'w' specifies that you want to write to a document.
"""
log_read=log.read()
# read() method returns a string variable
log_readlines=log.readlines()
# readlines() returns a variable of list data type

If you want to open notepad.
You can use the os module.

import os
os.system('start notepad.exe')

#Open a webpage
os.system('start iexplore.exe http://www.google.com')

If you want to open notepad.
You can use the os module.

import os
os.system('start notepad.exe')

Thats exactly what i wanted to do, thanks snippsat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.