0

Simple error while inserting variable . Can't seem to figure it out ! meaning and word are of type str .

rest_command = "display notification \'%s\' with title \'%s\'", %(meaning[0],word[0])
os.system(osascript -e + rest_command)

Error:

File "word-scraper.py", line 20
    rest_command = "display notification \'%s\' with title \'%s\'", %(meaning[0],word[0])
                                                                    ^
SyntaxError: invalid syntax
1
  • 1
    What's the comma in aid of? Commented May 7, 2015 at 12:11

2 Answers 2

5

Get rid of the comma

>>> "display notification \'%s\' with title \'%s\'" % (meaning[0],word[0])
"display notification 'hello' with title 'foo'"

Or use format

>>> "display notification \'{}\' with title \'{}\'".format(meaning[0],word[0])
"display notification 'hello' with title 'foo'"
Sign up to request clarification or add additional context in comments.

Comments

0

You don't need the comma between the string and the '%'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.