0

I have tried implementing a hashtable from scratch by reading in a csv file. The data itself reads correctly, and the key reads in correctly as well. The values are reading in as memory locations and I can't figure out why. Other posts have suggested that you need to implement a self or str, but unless I'm misunderstanding I believe I've done that here? Any help would be appreciated.

class DeliveryInfo:
def __init__(self, idc, address, city, state, zipc, delivery, size, note):
    self.idc = idc
    self.address = address
    self.city = city
    self.state = state
    self.zipc = zipc
    self.delivery = delivery
    self.size = size
    self.note = note

def __str__(self):
    return "%s,%s,%s,%s,%s,%s,%s,%s" % (self.idc, self.address, self.city, self.state,
                                        self.zip, self.delivery, self.size, self.note)


def loadDeliveryInfo(fileName):
    with open(fileName,'r', encoding="utf-8-sig") as PackageInfo:
        PackageData = csv.reader(PackageInfo, delimiter=',')

    for d_Info in PackageData:
        dID = int(d_Info[0])
        dAddress = d_Info[1]
        dCity = d_Info[2]
        dState = d_Info[3]
        dZip = d_Info[4]
        dDelivery = d_Info[5]
        dSize = d_Info[6]
        dNote = d_Info[7]

        d_Info = DeliveryInfo(dID, dAddress, dCity, dState, dZip, dDelivery, dSize, dNote)
        hashMap.insert(dID, d_Info)

hashMap = chainedHashTable()
loadDeliveryInfo('PackageData.csv')
print(hashMap.table)
Kg123
  • 1
  • "The values are reading in as memory locations and I can't figure out why." No, they aren't. Please provide a [mcve] and actually show the outputs you are seeing and the outputs you are *expecting* – juanpa.arrivillaga Jan 20 '21 at 15:51
  • When I run it results in this output [[[10, ], [20, ], Process finished with exit code 0 – Kg123 Jan 20 '21 at 15:53
  • Your code indentation seems off. The methods for `DeliveryInfo` should be indented. – scotty3785 Jan 20 '21 at 15:54
  • It's **very** important to understand that implementing `__str__` changes nothing about the way the values are read in, merely *how they are printed to the screen by default*. In this case, you are printing a list, and the list uses `__repr__` instead of the `__str__` of the objects you put in. So implement `__repr__` – juanpa.arrivillaga Jan 20 '21 at 15:54
  • @Kg123 in the future, don't put that in a comment, edit your question and add it as formatte output. An again, always provide a [mcve] – juanpa.arrivillaga Jan 20 '21 at 15:55

0 Answers0