idoodler
idoodler

Reputation: 3545

How to add a string to os.system() command? (Python)

I like to add tweet = "@idoodler My CPU temperature is " + str(CPU_temp) to os.system("sudo twidge update \"tweet\"") (tweet is the tweet string above). Can anyone please tell me how I can add the tweet string to the os.system() command?

Upvotes: 0

Views: 3771

Answers (1)

Joran Beasley
Joran Beasley

Reputation: 113930

cmd = "sudo twidge update \"{0}\"".format(tweet)
print cmd
os.system(cmd)

although to be honest you are probably better off using subprocess.call

import subprocess
subprocess.call(["sudo","twidge","update",tweet])

Upvotes: 1

Related Questions