插入变量时出现简单错误。似乎无法解决这个问题! meaning
和word
的类型为str。
rest_command = "display notification \'%s\' with title \'%s\'", %(meaning[0],word[0])
os.system(osascript -e + rest_command)
错误:
File "word-scraper.py", line 20
rest_command = "display notification \'%s\' with title \'%s\'", %(meaning[0],word[0])
^
SyntaxError: invalid syntax
答案 0 :(得分:5)
摆脱逗号
>>> "display notification \'%s\' with title \'%s\'" % (meaning[0],word[0])
"display notification 'hello' with title 'foo'"
或使用format
>>> "display notification \'{}\' with title \'{}\'".format(meaning[0],word[0])
"display notification 'hello' with title 'foo'"
答案 1 :(得分:0)
您不需要字符串和'%'之间的逗号。