x:' int'不支持的操作数类型和' str"

时间:2014-09-16 01:26:28

标签: python-2.7

我目前正在尝试在我的覆盆子pi上制作一个python脚本,以允许自己通过网址中的字符串观看抽搐流。我已经尝试了很多方法来将字符串添加到url但是所有似乎都得出了相同的结果。 " TypeError:%:' int'不支持的操作数类型和' str'"

请记住,我对python编码很新。

import os

print 'You have entered Stream, this program uses twitch.com to stream'

stream = raw_input('Twitch stream you would like to watch. http://www.twitch/')

os.system("livestreamer http://twitch.tv/'%s' medium -np 'omxplayer -o hdmi'") % (stream)

提前致谢 〜iSlendy

1 个答案:

答案 0 :(得分:0)

你的括号看起来错位了。

试试这个:

os.system("livestreamer http://twitch.tv/'%s' medium -np 'omxplayer -o hdmi'" % (stream))

正在发生的事情是os.system来电正在返回int,然后你在%int之间使用str操作数在stream变量中。如果你的意图是stream变量是一个整数,你需要这样做,因为来自raw_input的输入总是一个字符串。