943,742 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 587
  • Python RSS
Aug 21st, 2009
0

Opening files

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

Thanks Dan08.
Similar Threads
Reputation Points: 18
Solved Threads: 9
Junior Poster
Dan08 is offline Offline
133 posts
since Jul 2009
Aug 21st, 2009
0

Re: Opening files

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:
python Syntax (Toggle Plain Text)
  1. log=open("log.txt",'r')
  2. """
  3. 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.
  4. """
  5. log_read=log.read()
  6. # read() method returns a string variable
  7. log_readlines=log.readlines()
  8. # readlines() returns a variable of list data type
Last edited by sravan953; Aug 21st, 2009 at 10:56 pm.
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Aug 21st, 2009
1

Re: Opening files

If you want to open notepad.
You can use the os module.
python Syntax (Toggle Plain Text)
  1. import os
  2. os.system('start notepad.exe')
  3.  
  4. #Open a webpage
  5. os.system('start iexplore.exe http://www.google.com')
Last edited by snippsat; Aug 21st, 2009 at 11:39 pm.
Reputation Points: 280
Solved Threads: 278
Master Poster
snippsat is online now Online
770 posts
since Aug 2008
Aug 22nd, 2009
0

Re: Opening files

Click to Expand / Collapse  Quote originally posted by snippsat ...
If you want to open notepad.
You can use the os module.
python Syntax (Toggle Plain Text)
  1. import os
  2. os.system('start notepad.exe')
Thats exactly what i wanted to do, thanks snippsat.
Reputation Points: 18
Solved Threads: 9
Junior Poster
Dan08 is offline Offline
133 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: tkFileDialog
Next Thread in Python Forum Timeline: What is EOF and what it it's significane in python?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC