Python - Converting CSV to Objects - Code Design

前端 未结 2 1182
清酒与你
清酒与你 2021-02-09 19:35

I have a small script we\'re using to read in a CSV file containing employees, and perform some basic manipulations on that data.

We read in the data (import_gd_dump), a

相关标签:
2条回答
  • 2021-02-09 19:47

    you should close your files after reading them I suggest moving all compiled re's tot he top level (otherwise you compile them every call) if self.telephoneNumber is None or self.telephoneNumber == '': cen be easily rewrittent as if not self.telephoneNumber

    0 讨论(0)
  • 2021-02-09 19:50

    Looks fine to me. Good job. How often are you going to run this script? Most of your questions are moot if this is a one-off thing.

    1. I like the way Employees.cleen_all_phone_numbers() delegates to Employee.clean_phone_number()
    2. You really should be using an index (dictionary) here. You can index each employee by hrid when you create them in O(n) and then look them up in O(1).
      • But only do this if you ever have to run the script again...
      • Just get into the habit of using dictionaries. They are painless and make code easier to read. Whenever you write a method lookup_* you probably just want to index a dictionary.
    3. not sure. I like explicitly setting state, but this is actually bad design - clean_phone_number() should do that, Employees should be responsible for their own state.
    0 讨论(0)
提交回复
热议问题