1

This function sends a google hangouts message to the recipient in the EMAIL variable.

It works in the following case where the email in inline with no quotes.

import os
EMAIL='in06khattab@gmail.com'

os.system('sudo echo "jjj" | sendxmpp -v -t in06khattab@gmail.com') #send hangouts message

However, when I insert the variable in its place, it doesn't send. There are no error message and the debug appears to be sending correctly, but I think it is sending to 'in06khattab@gmail.com' rather than in06khattab@gmail.com. So it may be including the quotes,

os.system('sudo echo "jjj" | sendxmpp -v -t EMAIL') #send hangouts message
Hamoudy
  • 559
  • 2
  • 8
  • 24

2 Answers2

3

Python won't interpret variables in a string like that.

Use concatenation:

os.system('sudo echo "jjj" | sendxmpp -v -t ' + EMAIL)

Or string formatting:

os.system('sudo echo "jjj" | sendxmpp -v -t %s' % EMAIL)
Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
2

For forwards compatibility and readability, I would suggest using format to substitute in the EMAIL variable.

os.system('sudo echo "jjj" | sendxmpp -v -t {email}'.format(email=EMAIL))

See this thread for why this is preferable to % encoding

Community
  • 1
  • 1
talwai
  • 59
  • 5