I'm attempting to learn how to use timeit to time command line arguments driven by python.
from subprocess import *
import timeit
p = Popen( ["cmd.exe"], stdin=PIPE, stdout=PIPE )
dir_time = timeit.timeit('p.stdin.write("dir\n"),p.stdin.write("exit\n")')
print p.stdout.read()
Unfortunately, when I run it I get
"exceptions.SyntaxError: EOL while scanning string literal (line 6, offset 26): 'p.stdin.write(""dir'"
I've seen a similar question about EOL syntax error when using timeit and cmd and it's solution was replacing single quotation marks however I'm not feeding code snippets directly into cmd, their commands never contain an end line character in it and double quotations produce a syntax error.
Is there any way to delimit the end of line character but still be valid in cmd? Have I used the incorrect syntax for two arguments in timeit?
Aucun commentaire:
Enregistrer un commentaire