在shell中,当我尝试导入我的程序时,出现以下响应。Python语法错误无效
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "tweet.py", line 26
print "Favorited: %s" % (result['text'])
^
SyntaxError: invalid syntax
为什么print "Favorited: %s" % (result['text'])
会返回错误?谷歌搜索已于事无补,这一点我们已经为我工作...
更新,我运行的Python的版本如下:再次
Python 2.7.5 |Anaconda 1.6.1 (x86_64)| (default, Jun 28 2013, 22:20:13)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
更新,这里是功能:
def fetch_tweet(tweet):
try:
result = t.favorites.create(_id=tweet['id'])
print "Favorited: %s" % (result['text'])
return result
# when you have already favourited a tweet, this error is thrown
except TwitterHTTPError as e:
print "Error: ", e
return None
更新#3 - 发现错误!
原来我的Python解释实在很讨厌一些代码我在上面,这与print
某种程度上搞乱 - 我从文件的顶部删除from __future__ import print_function
,一切都开始工作顺利进行。
什么Python版本您使用的? – BrenBarn
更新以上信息... – gersande
它可能只是一个缩进问题。尽量减少到最简单的程序,重现问题,并重新发布整个代码。我相信你会得到有用的答案。 –