[英]Variable in os.system
I am using os.system
method in Python to open a file in Linux. 我在Python中使用os.system
方法在Linux中打开文件。 But I don't know how to pass the variable (a) inside the os.system command 但我不知道如何在os.system命令中传递变量(a)
import os
a=4
os.system('gedit +a test.txt')
How can i pass the variable as an integer inside the command? 如何在命令中将变量作为整数传递?
os.system('gedit +%d test.txt' % (a,))
建议使用子进程 ,而不是os.system
:
subprocess.call(['gedit', '+%d' % (a,), 'test.txt'])
os.system("gedit +" + str(a) + " test.txt")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.