I am using os.system
method in Python to open a file in Linux. But I don't know how to pass the variable (a) inside the os.system command
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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.