python - Grabbed numbers from an online page, converted to int(), but cannot multiply -
i wrote python script goes online, fetches page, parses page, locates string of numbers (e.g, 5678), , stores in num. now, need perform mathematical functions on num. why can't that?
grabbed line page: number '6678'. hence, line = "the number '6678'"
c = "" num = ''.join(c c in line if c.isdigit()) int(num) print num try=(num*2) print try
error:
file "script", line 20 try=(num*2) ^ syntaxerror: invalid syntax
edit: changed 'try' 't'. silly mistake! but, have new error trying maths 'num', further code:
new = (((num*3)+3)-1000) print new
error:
traceback (most recent call last): file "602", line 22, in new = (((num*3)+2)-250) typeerror: coercing unicode: need string or buffer, int found
you need reassign casted number:
num = int(num) # num string right
Comments
Post a Comment