I have some streets names and I've made a function to read those names. I need to add these streets to a list, but the problem is I override the list everytime the function is accessed. I want to keep it without writting it to an external file.
import random
def readAddress(self,streetName):
self.streetName = streetName
#declare list, it overrides the list with an empty one
addressList = []
if streetName is not in addressLis:
addressList.append(streetName)
newName = rd.choice(addressList)
I've also tried an extra function to maintain the values
def keepList(self,extList):
self.extList = extList
return extList
And changed readAddress to use it. But of course I am replacing the list and not extending it. I also tried to yield the names in the external function. None worked.
def readAddress(self,streetName):
self.streetName = streetName
#declare list, it overrides the list with an empty one
addressList = []
if streetName is not in addressLis:
addressList.append(streetName)
adress=keepList(addressList)
newName = rd.choice(address)
The input data is:
address1 = modifyAddress('Naciones')
address2 = modifyAddress('Juncal')
address3 = modifyAddress('Rocafort')
address4 = modifyAddress('Mare de Déu de Bellvitge')
The print of address should be:
['Naciones','Juncal','Rocafort','Mare de Déu de Bellvitge]