3

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
6
  • self.getControl(prog_ids).setWidth(int(programs_width)) Commented Dec 27, 2014 at 1:20
  • @AvinashRaj thank you very much for that, but I still get the same error when I change the code. Do you know why I still get the same error? Commented Dec 27, 2014 at 1:22
  • 1
    You say the error is in the line self.getControl(prog_ids).setWidth(programs_width), but in the traceback, it says the line is really self.getControl(str(prog_ids)).setWidth(str(programs_width)). This makes it hard to know whether you're running the code you think you are, or whether you're right about what the types are. Commented Dec 27, 2014 at 1:24
  • it shows the above error if you're doing any arithmetic calculation. In this case, convert the corresponding variables to the type int and then convert back the result to string while printing. Commented Dec 27, 2014 at 1:25
  • I have tried self.getControl(str(prog_ids)).setWidth(str(programs_width)) but it give me the same error. do I need to use something is like int(programs_width = 181) before I convert it back to string? Commented Dec 27, 2014 at 1:29

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

@Rawling thank you for your advice, do you know what i would need to do to fix the problem?
@David: I'm not sure what your code is supposed to do, but I guess you should set a default value that's used when the two if-statements don't trigger. (an integer!)
I'm trying to compared the value to see if it match it then do something. What I would need to do in order to fix the problem? remove the quotes on the values?
I realised that the problem are coming from if pos_X == 1073:. I have put the list of elements for the pos_X, please see in my question that I have updated.
0

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.

1 Comment

I have removed the quotes on my values, but it still get the same error. And I have tried with self.getControl(str(prog_ids)).setWidth(int(programs_width)) which it give me the same error. Do you have know why and what is wrong? :S

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.