Skip to content

Option to get None instead of empty string #44

Description

@Xennis

Hey,

is there an option to get None instead of an empty string for the components? E.g.

>>> name = HumanName("1 & 2, 3 4 5, Mr.")
>>> name.title
None
>>>name.first
'3'

Activity

  1. derek73 commented on Mar 18, 2016

    @derek73
    Owner

    There is not. Currently it returns the value from " ".join([]), which is an empty string. It would be pretty easy to make it do that though. Of course, you could do it easily too with something like name.title or None, but maybe there's some case where that's inconvenient? Idk, maybe it would be fine to make it always return None instead of an empty string? I don't have a strong preference.

  2. Xennis commented on Mar 19, 2016

    @Xennis
    Author

    For instance when you store the name components in a database and you want to store that values as NULL and not as empty string, it's easier when the module directly returns None.

  3. added this to the v0.3.14 milestone on Mar 19, 2016
  4. derek73 commented on Mar 19, 2016

    @derek73
    Owner

    Turns out the change breaks a bunch of tests, mostly to do with string formatting, so I just added a configuration option for it, documented here:

    http://nameparser.readthedocs.org/en/latest/modules.html#nameparser.config.Constants.empty_attribute_default

  5. Xennis commented on Mar 19, 2016

    @Xennis
    Author

    Maybe it's an idea to modify line 122: Do a .replace(CONSTANTS.empty_attribute_default, "") first; since you probably don't want to have an output like 'None John None Doe None (None)' when printing the hole name.

  6. derek73 commented on Mar 19, 2016

    @derek73
    Owner

    Thanks for the suggestion. I gave it a shot but my attempt doesn't pass the test. I made a branch and pull request: #45

    Here's the failed Travis build:
    https://travis-ci.org/derek73/python-nameparser/builds/117161574

  7. derek73 commented on Mar 19, 2016

    @derek73
    Owner

    I figured it out. It was a problem with the tests and me forgetting how to use my own software.

  8. derek73 commented on Mar 19, 2016

    @derek73
    Owner

    I posted the results of the tests when CONSTANTS.empty_attribute_default = None over on the pull request. Take a look and let me know if you think there's something better we could do or maybe it's all fine.

  9. Xennis commented on Mar 20, 2016

    @Xennis
    Author

    Thanks for you friendly support. I am now using this module for some days and it is quite nice.

    The code changes looks fine.

    Maybe they are all just problems with the tests, because its explicitly testing for '' instead of hn.C.empty_attribute_default?

    I think you are right. Probably you should test for hn.C.empty_attribute_default instead.

  10. added a commit that references this issue on Mar 21, 2016
  11. derek73 commented on Mar 21, 2016

    @derek73
    Owner

    Just released v0.3.15 that should take care of all this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions