Skip to content Skip to sidebar Skip to footer

Variable In Os.system

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

Solution 1:

os.system('gedit +%d test.txt' % (a,))

It is recommended to use subprocess instead of os.system:

subprocess.call(['gedit', '+%d' % (a,), 'test.txt'])

Solution 2:

os.system("gedit +" + str(a) + " test.txt")

Post a Comment for "Variable In Os.system"