Repository navigation
Option to get None instead of empty string #44
Description
Activity
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 likename.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.Reacted by Fabian RosenthalFor instance when you store the name components in a database and you want to store that values as
NULLand not as empty string, it's easier when the module directly returnsNone.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:
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.- added a commit that references this issue
on Mar 19, 2016 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/117161574I figured it out. It was a problem with the tests and me forgetting how to use my own software.
I posted the results of the tests when
CONSTANTS.empty_attribute_default = Noneover 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.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_defaultinstead.- added a commit that references this issue
on Mar 21, 2016 Just released v0.3.15 that should take care of all this
- added a commit that references this issue
on Aug 16, 2026
Hey,
is there an option to get
Noneinstead of an empty string for the components? E.g.