Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to express null value
#1
Hi, problem i have is i am downloading a json file and putting in a string, when i am getting data from the string at times there is some info that is not in the json file because ii is just not available, i need to replace this blank info with a zero so when i process all the other data i don't get errors, he is some simple code where i add all the data from that item to a list.

laststart = previous[0]["handicap"]
weightchange += [laststart]

the variable laststart should contain the output of "handicap" but when "handicap" is not in the json file this is missing from my list, as an example the list should contain 14 items but only has 13
Reply
#2
this looks like it solved the issue.


        try:
            laststart = previous[0]["handicap"]
            weightchange += [laststart]
        except:
            laststart = 0
            weightchange += [laststart]
            pass
Reply
#3
Dictionaries also have a get method that lets you specify a default value if the key is missing: https://docs.python.org/3/library/stdtyp...l#dict.get.
Reply
#4
cheers
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple conditions, one is null moralear27 1 2,812 Sep-13-2020, 06:11 AM
Last Post: scidam
  I didnt get the NULL values salwa17 0 1,982 Jul-10-2020, 02:54 PM
Last Post: salwa17
  CGI in python, problem with pandas, plotly.express and export html HK2432 0 2,724 Jan-19-2020, 01:30 PM
Last Post: HK2432
  g Null Byte using DictReader eshwinsukhdeve 13 10,240 May-15-2019, 08:50 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020