954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Opening files

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

Thanks Dan08.

Dan08
Junior Poster
133 posts since Jul 2009
Reputation Points: 18
Solved Threads: 9
 

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
sravan953
Posting Whiz in Training
243 posts since May 2009
Reputation Points: 2
Solved Threads: 30
 

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')
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
 

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.

Dan08
Junior Poster
133 posts since Jul 2009
Reputation Points: 18
Solved Threads: 9
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You