Python命令行参数

时间:2013-07-30 17:42:03

标签: python command-line tweepy

我正在尝试接受命令行参数并将值放在我的代码中的某个位置

我很难这样做....

 hash = sys.argv[1]

 def on_timeout(self):
    print >> sys.stderr, 'Timeout...'
    return True # Don't kill the stream
 sapi = tweepy.streaming.Stream(auth, CustomStreamListener())
 sapi.filter(track=['%s']% hash)

我想将接收到的值作为命令行参数放在

 sapi.filter(track=['%s']% hash)

我收到以下错误:

File "./twitter", line 31, in <module>

sapi.filter(track=['%s']% hash)

TypeError: unsupported operand type(s) for %: 'list' and 'str'

我只想在命令行或其他脚本中表示我想要遵循的术语。

1 个答案:

答案 0 :(得分:3)

试试这个:

sapi.filter(track=['%s' % hash ])