0

I got this question i'm a little unsure how to solve:

"There are a NoneType error when reproducing the code. The getaddressdata() returns a None value. This can be fixed by adding an if-statement in the getpricelist() to see if the data is None. Use a try except block to handle invalid data."

Have to fix this before my code can run.

my function / code you see here:

def getpricelist( ):
    l1=[]
    for line in file('addresslist.txt'):
        data=getaddressdata(line.strip( ),'Cambridge,MA')
        if data != 'None':
            l1.append(data)    

    return l1

Where do i make the try / except blok??

Pixel
  • 349
  • 1
  • 8
  • 17

1 Answers1

1

You should use pythonic idiom is None to check if the variable is of a NoneType or not:

data = getaddressdata(line.strip( ),'Cambridge,MA')
if data is not None:
    l1.append(data) 

Also see:

Hope that helps.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195