[英]python error: TypeError: an integer is required
I'm working on my python script as I'm stored the list of elements in the arrays. 我正在将自己的python列表存储在数组中,因此我正在使用python脚本。
I have got a very weird error when I'm trying to put each element in the getControl
to allowed me to change the width size. 当我尝试将每个元素放入
getControl
以允许我更改宽度大小时,我遇到了一个非常奇怪的错误。 I can get the list of elements from the arrays without have any problem. 我可以毫无问题地从数组中获取元素列表。
When I try this: 当我尝试这个:
programs_width = list()
for pos_X, prog_width, prog_ids in zip(program_X, program_width, program_id):
if pos_X == '1073':
#30 mins
if prog_width == '342':
programs_width = 181
#1 hour
if prog_width == '691':
programs_width = 181
#need to find out how to get the programs_width outside
print programs_width
print prog_ids
self.getControl(prog_ids).setWidth(programs_width)
It give me an error: 它给我一个错误:
01:03:24 T:2084 ERROR: Exception in thread All_Channels_BACKUP_thread:
Traceback (most recent call last):
File "C:\Program Files (x86)\XBMC\system\python\Lib\threading.py", line 532, in __bootstrap_inner
self.run()
File "C:\Users\user\AppData\Roaming\XBMC\addons\script.tvguide\test.py", line 8158, in run
self.xtarget()
File "C:\Users\user\AppData\Roaming\XBMC\addons\script.tvguide\test.py", line 1410, in All_Channels_BACKUP self.getControl(str(prog_ids)).setWidth(str(programs_width))
TypeError: an integer is required
The error are jumping on this line: 错误在此行上跳跃:
self.getControl(prog_ids).setWidth(programs_width)
Here is a output for the width and ids: 这是宽度和ID的输出:
01:13:18 T:5032 NOTICE: 181
01:13:18 T:5032 NOTICE: 3072
01:13:18 T:5032 NOTICE: 181
01:13:18 T:5032 NOTICE: 3211
01:13:18 T:5032 NOTICE: 181
01:13:18 T:5032 NOTICE: 3279
01:13:18 T:5032 NOTICE: 181
01:13:18 T:5032 NOTICE: 3348
01:13:18 T:5032 NOTICE: 181
01:13:18 T:5032 NOTICE: 3417
I got no idea why I have an error, all I'm trying to do is to use the variable prog_ids
to get each element from the arrays to put each id in the getcontrol
before I could use the variable programs_width
to change the width size each time. 我不知道为什么会出错,我要做的就是使用变量
prog_ids
从数组中获取每个元素,然后将每个id放入getcontrol
然后再使用变量programs_width
更改每个getcontrol
的宽度大小。时间。 The type for program_width
is int
and the type for prog_id
is str
which is a string. program_width
的类型为int
, prog_id
的类型为str
(字符串)。
Do you know why I have got an error and do you know how to fix it? 您知道我为什么会出错并且知道如何解决吗?
Edit: I realised that the problem are coming from this line: 编辑:我意识到问题来自此行:
elif pos_X == '1073':
Here is the list of elements: 这是元素列表:
15:34:08 T:5872 NOTICE: 375
15:34:08 T:5872 NOTICE: 724
15:34:08 T:5872 NOTICE: 2804
15:34:08 T:5872 NOTICE: 5226
15:34:08 T:5872 NOTICE: 5924
15:34:08 T:5872 NOTICE: 6273
15:34:08 T:5872 NOTICE: 6622
15:34:08 T:5872 NOTICE: 6971
15:34:08 T:5872 NOTICE: 7320
15:34:08 T:5872 NOTICE: 7669
15:34:08 T:5872 NOTICE: 8018
15:34:08 T:5872 NOTICE: 8716
15:34:08 T:5872 NOTICE: 9065
15:34:08 T:5872 NOTICE: 9414
15:34:08 T:5872 NOTICE: 9763
15:34:08 T:5872 NOTICE: 10112
15:34:08 T:5872 NOTICE: 10461
15:34:08 T:5872 NOTICE: 10810
15:34:08 T:5872 NOTICE: 11159
15:34:08 T:5872 NOTICE: 11508
15:34:08 T:5872 NOTICE: 11857
15:34:08 T:5872 NOTICE: 12206
15:34:08 T:5872 NOTICE: 13937
15:34:08 T:5872 NOTICE: 14635
15:34:08 T:5872 NOTICE: 14984
15:34:08 T:5872 NOTICE: 15333
15:34:08 T:5872 NOTICE: 15682
15:34:08 T:5872 NOTICE: 16031
15:34:08 T:5872 NOTICE: 16380
15:34:08 T:5872 NOTICE: 16729
15:34:08 T:5872 NOTICE: 17078
15:34:08 T:5872 NOTICE: 17427
15:34:08 T:5872 NOTICE: 17776
15:34:08 T:5872 NOTICE: 18125
15:34:08 T:5872 NOTICE: 18474
15:34:08 T:5872 NOTICE: 18823
15:34:08 T:5872 NOTICE: 19172
15:34:08 T:5872 NOTICE: 19521
15:34:08 T:5872 NOTICE: 19870
15:34:08 T:5872 NOTICE: 20219
15:34:08 T:5872 NOTICE: 20568
15:34:08 T:5872 NOTICE: 20917
15:34:08 T:5872 NOTICE: 22648
15:34:08 T:5872 NOTICE: 23346
15:34:08 T:5872 NOTICE: 23695
15:34:08 T:5872 NOTICE: 24044
15:34:08 T:5872 NOTICE: 24393
15:34:08 T:5872 NOTICE: 24742
15:34:08 T:5872 NOTICE: 25091
15:34:08 T:5872 NOTICE: 25440
15:34:08 T:5872 NOTICE: 26138
15:34:08 T:5872 NOTICE: 26487
15:34:08 T:5872 NOTICE: 26836
15:34:08 T:5872 NOTICE: 27185
15:34:08 T:5872 NOTICE: 27534
15:34:08 T:5872 NOTICE: 27883
15:34:08 T:5872 NOTICE: 28232
15:34:08 T:5872 NOTICE: 28581
15:34:08 T:5872 NOTICE: 28930
15:34:08 T:5872 NOTICE: 29279
15:34:08 T:5872 NOTICE: 29628
15:34:08 T:5872 NOTICE: 31359
15:34:08 T:5872 NOTICE: 32057
15:34:08 T:5872 NOTICE: 32406
15:34:08 T:5872 NOTICE: 32755
15:34:08 T:5872 NOTICE: 33104
15:34:08 T:5872 NOTICE: 33453
15:34:08 T:5872 NOTICE: 33802
15:34:08 T:5872 NOTICE: 34151
15:34:08 T:5872 NOTICE: 375
15:34:08 T:5872 NOTICE: 1073
15:34:08 T:5872 NOTICE: 3153
The problem is that programs_width
is a list. 问题在于,
programs_width
是一个列表。
programs_width = list()
If none of these if
statements 如果这些都不是
if
语句
if prog_width == '342':
programs_width = 181
#1 hour
if prog_width == '691':
programs_width = 181
trigger, then programs_width
will still be a list here: 触发,然后
programs_width
仍然是此处的列表:
self.getControl(prog_ids).setWidth(programs_width)
which causes an error. 这会导致错误。
Your quotes are making these values strings, not integers. 您的引号使这些值成为字符串,而不是整数。 Remove the quotes on your values.
删除值上的引号。 In addition, the error message clearly indicates the bad line:
此外,错误消息清楚地指示错误的行:
self.getControl(str(prog_ids)).setWidth(str(programs_width))
Notice that you are explicitly converting the parameter to a string with "str". 请注意,您正在将参数显式转换为带有“ str”的字符串。 Use "int", instead:
使用“ int”代替:
self.getControl(str(prog_ids)).setWidth(int(programs_width))
... or omit the conversion altogeher if you know the input is already an integer. ...或如果您知道输入已经是整数,则忽略转换算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.