1

I'm working on my python script as I'm compared the value to see if it match it then do something.

I have got a problem with the code that I'm using.

When I try this:

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
    self.getControl(prog_ids).setWidth(programs_width)

I can get pass on if statement, but it will give me the error: TypeError: an integer is required.

The problem I found are coming from this:

if pos_X == '1073': 

It will work if I try this but it won't get pass on:

if pos_X == 1073: 

Here is the list of elements:

16:00:21 T:7084  NOTICE: 375
16:00:21 T:7084  NOTICE: 724
16:00:21 T:7084  NOTICE: 2804
16:00:21 T:7084  NOTICE: 5226
16:00:21 T:7084  NOTICE: 5924
16:00:21 T:7084  NOTICE: 6273
16:00:21 T:7084  NOTICE: 6622
16:00:21 T:7084  NOTICE: 6971
16:00:21 T:7084  NOTICE: 7320
16:00:21 T:7084  NOTICE: 7669
16:00:21 T:7084  NOTICE: 8018
16:00:21 T:7084  NOTICE: 8716
16:00:21 T:7084  NOTICE: 9065
16:00:21 T:7084  NOTICE: 9414
16:00:21 T:7084  NOTICE: 9763
16:00:21 T:7084  NOTICE: 10112
16:00:21 T:7084  NOTICE: 10461
16:00:21 T:7084  NOTICE: 10810
16:00:21 T:7084  NOTICE: 11159
16:00:21 T:7084  NOTICE: 11508
16:00:21 T:7084  NOTICE: 11857
16:00:21 T:7084  NOTICE: 12206
16:00:21 T:7084  NOTICE: 13937
16:00:21 T:7084  NOTICE: 14635
16:00:21 T:7084  NOTICE: 14984
16:00:21 T:7084  NOTICE: 15333
16:00:21 T:7084  NOTICE: 15682
16:00:21 T:7084  NOTICE: 16031
16:00:21 T:7084  NOTICE: 16380
16:00:21 T:7084  NOTICE: 16729
16:00:21 T:7084  NOTICE: 17078
16:00:21 T:7084  NOTICE: 17427
16:00:21 T:7084  NOTICE: 17776
16:00:21 T:7084  NOTICE: 18125
16:00:21 T:7084  NOTICE: 18474
16:00:21 T:7084  NOTICE: 18823
16:00:21 T:7084  NOTICE: 19172
16:00:21 T:7084  NOTICE: 19521
16:00:21 T:7084  NOTICE: 19870
16:00:21 T:7084  NOTICE: 20219
16:00:21 T:7084  NOTICE: 20568
16:00:21 T:7084  NOTICE: 20917
16:00:21 T:7084  NOTICE: 22648
16:00:21 T:7084  NOTICE: 23346
16:00:21 T:7084  NOTICE: 23695
16:00:21 T:7084  NOTICE: 24044
16:00:21 T:7084  NOTICE: 24393
16:00:21 T:7084  NOTICE: 24742
16:00:21 T:7084  NOTICE: 25091
16:00:21 T:7084  NOTICE: 25440
16:00:21 T:7084  NOTICE: 26138
16:00:21 T:7084  NOTICE: 26487
16:00:21 T:7084  NOTICE: 26836
16:00:21 T:7084  NOTICE: 27185
16:00:21 T:7084  NOTICE: 27534
16:00:21 T:7084  NOTICE: 27883
16:00:21 T:7084  NOTICE: 28232
16:00:21 T:7084  NOTICE: 28581
16:00:21 T:7084  NOTICE: 28930
16:00:21 T:7084  NOTICE: 29279
16:00:21 T:7084  NOTICE: 29628
16:00:21 T:7084  NOTICE: 31359
16:00:21 T:7084  NOTICE: 32057
16:00:21 T:7084  NOTICE: 32406
16:00:21 T:7084  NOTICE: 32755
16:00:21 T:7084  NOTICE: 33104
16:00:21 T:7084  NOTICE: 33453
16:00:21 T:7084  NOTICE: 33802
16:00:21 T:7084  NOTICE: 34151
16:00:21 T:7084  NOTICE: 375
16:00:21 T:7084  NOTICE: 1073

The type of pos_X is str.

Can you please tell me how I can compare the value using with pos_X to see if I have the match value without require an integer?

  • @qqvc thank you for your help but it still give me the error: TypeError: an integer is required. I don't understand what the problem is. Do you know what the problem is? –  Dec 27 '14 at 16:00
  • what does _it won't get pass on_ means ? You mean that if statement not processing? – GLHF Dec 27 '14 at 16:01
  • @qqvc yes you are correct. But I realised why the if statement is not processing is because the variable `pos_X` is a string which it will need to convert from str to int. Can you tell me how I can convert from str to int? –  Dec 27 '14 at 16:05

3 Answers3

3
if int(pos_X) == 1073: 

This will solve your problem.

GLHF
  • 3,835
  • 10
  • 38
  • 83
0

do

int(pos_X) == 1073

to match both the values, you need to convert pos_X as integer.

Rishi
  • 1,646
  • 2
  • 15
  • 34
-1

In pos_X == '1073' you are comparing if pos_X is a STRING with value of '1073' (which is equal to '1'+'0'+'7'+'3', and in pos_X == 1073 you compare INTEGER of value 1073 (1000+70+3). You need to convert from/to string or integer, using str or int methods, and then compare.

Therefore:

1073 == int('1073')

and

'1073' == str(1073)
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
  • yes of course you are right. I'm trying to comppare the integer of value 1073 to see if it match it. I just realised that the type of `pos_X` is a string. Can you please tell me how I can convert from str to int? –  Dec 27 '14 at 16:04
  • `1073 == int('1073')` – Jakub M. Dec 27 '14 at 16:05
  • thank you very much for your help. How I can compare on the value to see if it match it as I want to use the if statement? do i need to use `if 1073 == int('1073')`? how I can use `pos_X` on if statement to compare the value using with int? –  Dec 27 '14 at 16:07
  • 1
    use `if int(pos_X) == 1073`, as in *qqvc* answer – Jakub M. Dec 27 '14 at 16:17
  • @qqvc thank you very much for your help, I can see it have fixed the issue, but there is a problem. I'm getting an error `TypeError: an integer is required` in this line: `self.getControl(prog_ids).setWidth(int(program_width))`. the type of `programs_width` is a list. do you know why i get an error? –  Dec 27 '14 at 16:29