I have an Employee class for which I want to create a method/attribute/property that outputs a formatting of the firstname lastname and the employeeid. It's a standard output for logging purposes primarily. I don't like the

def need_a_good_name(self):
    return f"'{self.fname} {self.lname}' {self.idnum}"
  • identity came to mind, but that's not quite right.
  • logstr is closer to being an accurate description but reads poorly.
  • logformat might work but it describes what it does not what it is.
  • 2
    The standard __repr__ method is supposed to provide exactly this. Is there a reason you need a hand-rolled method? – Kilian Foth Feb 5 at 15:37
  • 1
    Looks like __str__ could be useful too depending on the needs: stackoverflow.com/questions/1436703/… – bitsoflogic Feb 5 at 16:23
  • That's a good point. I thought I needed a separate one for formatting purposes in the log file, but I don't see why the __str__ output couldn't act as this. Still.. the point of this post is finding a readable name. – Marcel Wilson Feb 5 at 21:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.