Does the python code executes in order
Question: I am creating a file and then doing diff on it.

I want to do diff on the file which iscreated in previous step but i get the
error that file dont exist .

This is my code

    
    
    os.popen("mysqldump --login-path=server1_mysql -e --opt --skip-lock-tables  --skip-extended-insert -c %s > %s.sql" % (database, filename))
    os.popen("diff %s %s > %s" % (weekly, filename, filename+".PATCH"))
    


Answer: [`os.popen` is deprecated. Use the subprocess
module](http://docs.python.org/2/library/subprocess.html). `subprocess.call`
will block the main process until the command is finished. You should inspect
the returncode, `retval`, in case there was an error while executing the
`mysqldump` command. In that case, you can not continue with the `diff`:

    
    
    import subprocess
    import shlex
    with open("{f}.sql".format(f=filename), 'w') as fout:
        retval = subprocess.call(
            shlex.split(
                """mysqldump --login-path=server1_mysql -e --opt --skip-lock-tables
                --skip-extended-insert -c %s""" % (database, )),
            stdout=fout)
    
    if not retval == 0:
        raise Exception('Error executing command: {r}'.format(r=retval))
    else:
        with open("{f}.PATCH".format(f=filename), 'w') as fout:
            retval = subprocess.call(
                shlex.split("diff {w} {f}".format(w=weekly, f=filename)),
                stdout=fout)
    

