Exclude Char from Python For -
i array values request.post
:
array = [1,2,3]
when iterating in for
this:
for item in array
i invalid literal int() base 10: ','
i need save values in database table.
what best way solve this?
thanks
looks you're getting string, not array. in case, can this:
import json array = '[1, 2, 3]' item in json.loads(array): print item # prints 1, 2, 3
alternatively, if want skip isn't integer (though not recommended), can use try/except
block in loop:
array = '[1, 2, 3]' # or array = '1, 2, 3', whatever case may item in array: try: print int(item) except valueerror: pass
this silently ignore isn't integer.
Comments
Post a Comment