如果您以python -c
启动脚本,有没有办法在while
中循环?这似乎并不可能与平台或Python版本...python -c and` while`
Linux的
[[email protected] ~]$ python -c "import os;while (True): os.system('ls')"
File "<string>", line 1
import os;while (True): os.system('ls')
^
SyntaxError: invalid syntax
[[email protected] ~]$
[[email protected] ~]$ python -V
Python 2.6.6
[[email protected] ~]$ uname -a
Linux Hotcoffee 2.6.32-5-amd64 #1 SMP Sun May 6 04:00:17 UTC 2012 x86_64 GNU/Linux
[[email protected] ~]$
的Windows
C:\Users\mike_pennington>python -c "import os;while True: os.system('dir')"
File "<string>", line 1
import os;while True: os.system('dir')
^
SyntaxError: invalid syntax
C:\Users\mike_pennington>python -V
Python 2.7.2
C:\Users\mike_pennington>
我试图在while
声明删除括号,但似乎没有让这个运行。
upvoted使用子进程而不是os。系统 –
'os.system()'显然不是规范的,但我发现在[so]上更短的问题更好。 'os'比'subprocess'短 –
如果它只是一个例子,'print 1234'(或'print(1234)')就足够了。但这不是这一切的主要... – glglgl