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
  value null when update in json file 3lnyn0 6 3,293 Dec-30-2021, 05:52 PM
Last Post: ndc85430
  Multiple conditions, one is null moralear27 1 2,204 Sep-13-2020, 06:11 AM
Last Post: scidam
  I didnt get the NULL values salwa17 0 1,590 Jul-10-2020, 02:54 PM
Last Post: salwa17
  Find only the rows containing null values Bhavika 2 2,447 Jun-10-2020, 01:25 PM
Last Post: Bhavika
  CGI in python, problem with pandas, plotly.express and export html HK2432 0 2,137 Jan-19-2020, 01:30 PM
Last Post: HK2432
  g Null Byte using DictReader eshwinsukhdeve 13 7,593 May-15-2019, 08:50 AM
Last Post: buran
  Array/Jarray problem contains null value? Maverick0013 1 3,976 Aug-10-2018, 12:56 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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