How do I skip null values in Python 2.7?

38 Views Asked by At

I'm trying to read a simple file of dates and corresponding river flows (cubic feet/second, or cfs). Some dates do not have a flow. They're just blank. I'm trying to skip these null values and read the rest of the file. Here is my code:

import urllib
flow = 100.0
#
page = urllib.urlopen('https://waterdata.usgs.gov/nwis/dv?cb_00060=on&format=rdb&site_no=08396500&legacy=&referred_module=sw&period=&begin_date=1905-10-01&end_date=2023-07-27')
for line in page:
    text = str(page.readline(4))
    if text == "USGS":
        page.readline(10)
        newdate = page.readline(10)
        newflow = float(page.readline(5))
        if newflow is None:
            print("Found a null!")
            continue
        if newflow <= flow:
            flow = newflow
            date = newdate
            print(date)
            print(flow)

This is the error I get:

Traceback (most recent call last): File "U:\PYTHON SCRIPTS\LOW FLOW TWO .py", line 23, in newflow = float(page.readline(5)) ValueError: could not convert string to float:

0

There are 0 best solutions below