Parsing my string to int is causing ValueError in python -


for reason int(str) causing error. can't work out why. i'm wondering if can tell me why.

cx4_list_reduce = ['[#1]',(1,3,5),(7,6,9)] list2= ['[#2]',(2,5,4), (1,3,5), (5,8,1), (7,2,6)] n2 =3 process_tuple in cx4_list_reduce:       d_num = ""       if process_tuple == list2[0]:             d_num = process_tuple[2:3]       n1 = int(d_num)       if n1 <= n2:            print('n1 =< n2')            continue       else:             print('n1 => n2') 

error: invalid literal int() base 10: ''

look closely @ condition:

d_num = "" if process_tuple == list2[0]:     d_num = process_tuple[2:3] 

so should happen when if test false (when value not equal list2[0]? d_num remains empty string , cannot convert integer.

the error message tells that; invalid literal int() base 10: '' tells empty string cannot converted.

your first value in cx4_list_reduce list '[#1]', , string not equal list2[0] ('[#1] not equal '[#2]'), above equality test fails.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -