Skip to content Skip to sidebar Skip to footer

How To Open A File In Python 3

I want to actually open it not just read it. I tried to do something like this: x = open('filename', 'r') abc = x.read() x.close() The above code just read the file, it did not ac

Solution 1:

open creates a stream of data associated with the file. It does not initiate a file viewing software.

os.startfile('path/to/file.ext') # opens file in respective program

Solution 2:

You must invoke filename.bat

Also, the explicit .read() can be removed in abc = x.read().

Post a Comment for "How To Open A File In Python 3"