Python上引用shell命令导致错:
File “test.py”, line 6
os.system(‘adb devices|awk “{if(found) print} /List of devices attached/{found=1}”|awk ‘{gsub(“device”, “”);print}’’)
^
SyntaxError: invalid syntax
解决方法:shell中单引号与python的冲突了,在shell部分单引号前加 “”,如下:
os.system('adb devices|awk "{if(found) print} /List of devices attached/{found=1}"|awk \'{gsub("device", "");print}\'')

博客指出Python引用shell命令时出现SyntaxError: invalid syntax错误,原因是shell中单引号与Python冲突。解决方法是在shell部分单引号前加 “\\” 。
71万+

被折叠的 条评论
为什么被折叠?



