I'm new to Python. I'm trying to open a file. And, it works.
I understand that we use from sys import argv to import just the function argv from the sys module.
The code I used to open a file is
from sys import argv
import subprocess
script, filename = argv
txt = open (filename)
print "Here's your file %r: " % filename
proc = subprocess.Popen(['scratch-text-editor', 'sample_file'])
proc.wait()
I tried using from subprocess import Popen, but it throws an error.
Here's your file 'sample_file':
Traceback (most recent call last):
File "ex12.py", line 9, in <module>
proc = subprocess.Popen(['scratch-text-editor', 'sample_file'])
NameError: name 'subprocess' is not defined
How can I make it work using from subprocess import Popen. What am I missing here? Isn't this the better way to do it?