简体   繁体   中英

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.

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. 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:

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. The type for program_width is int and the type for prog_id is str which is a string.

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 = list()

If none of these if statements

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:

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". Use "int", instead:

self.getControl(str(prog_ids)).setWidth(int(programs_width))

... or omit the conversion altogeher if you know the input is already an integer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM