我正在使用Python语言中的os.system方法在Linux中打开一个文件。但是我不知道如何在os.system命令中传递变量(a
import os
a=4
os.system('gedit +a test.txt')如何在命令中将变量作为整数传递?
发布于 2015-12-10 01:45:40
os.system('gedit +%d test.txt' % (a,))建议使用subprocess而不是os.system
subprocess.call(['gedit', '+%d' % (a,), 'test.txt'])发布于 2015-12-10 01:48:39
os.system("gedit +" + str(a) + " test.txt")https://stackoverflow.com/questions/34185488
复制相似问题