In Python, why can't you parse a file immediately after it is created using subprocess? -


i trying read 1 input file (listed below 'infile2', can file), , each line in file, make file2, , parse file2 make file3. regardless of why want code way (unless reason problem of course...), why first block of code work, , next fail?

#!/usr/bin/env python import sys import subprocess #this works def createfile():     command = "echo 'here text' > createfile.txt"     subprocess.popen(command,shell=true)  def parse():     open("createfile.txt") infile1:         line in infile1:             return line if __name__ == '__main__':     infile2 = sys.argv[1]     open(infile2) f:         line in f:             createfile()      open(infile2) g:                    print parse()             outfile=open("createfile.txt",'w') 

 

#!/usr/bin/env python import sys import subprocess  def createfile():     command = "echo 'here text' > createfile.txt"     subprocess.popen(command,shell=true)  def parse():     open("createfile.txt") infile1:         line in infile1:             return line if __name__ == '__main__':     infile2 = sys.argv[1]     open(infile2) f:         line in f:             createfile()                 print parse()             outfile=open("createfile.txt",'w') 

the second block produces error: ioerror: [errno 2] no such file or directory: 'createfile.txt' python interpreter not wait until previous line complete?

does python interpreter not wait until previous line complete?

not if previous line is: subprocess.popen(command,shell=true)

popen() creates asynchronous process , returns. if want wait process complete, try subprocess.call() or subprocess.check_call.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -