[Tutor] Is this a scope issue?
Rafael Skovron
rskovron at gmail.com
Sun Mar 5 20:33:52 EST 2017
This project compares two text files with parcel numbers. I think I'm
messing up the function call. I'm getting this error:
Traceback (most recent call last):
File "amador.py", line 48, in <module>
remaining_parcels(auctionlist,removedlist)
NameError: name 'auctionlist' is not defined
import re
fname = 'saclisting.txt'
removed = 'removed.txt'
def get_parcel_number(fname):
#this retrieves parcel numbers from the saclisting file and stores to
auctionlist
pattern = r'^(\d{3})-(\d{3})-(\d{3})-(\d{3})'
auctionlist = []
with open(fname,'r') as file:
text = file.readlines()
for index,line in enumerate(text):
if re.search(pattern,line):
#add line to auctionlist if the pattern is found
auctionlist.append(line)
return auctionlist
def get_removed_number(removed):
#this grabs the removed parcel numbers and stores to a list
pattern = r'^(\d{3})-(\d{3})-(\d{3})-(\d{3})'
removedlist = []
with open(removed,'r') as file:
text = file.readlines()
for index,line in enumerate(text):
if re.search(pattern,line):
# add line to removedlist
removedlist.append(line)
return removedlist
def remaining_parcels(auctionlist,removedlist):
#compares parcels in auctionlist to removedlist and returns parcels that
have not bee removed
remainingparcels =[]
for parcel in auctionlist:
if parcel not in removedlist:
remainingparcels.append(parcel)
return remainingparcels
get_parcel_number(fname)
get_removed_number(removed)
remaining_parcels(auctionlist,removedlist)
More information about the Tutor
mailing list