It seems that '5187621769' should be very simple for the phonenumbers library for parsing. These are 10 digits with a country code in the USA. But ... no luck.
Setup:
import phonenumbers
number = '5187621769'
Method 1:
parsed = phonenumbers.parse(number)
This causes an error.
Method 2:
parsed = phonenumbers.parse("+" + number)
Gives the country code = 51, which is not the United States.
I know that I can:
parsed = phonenumbers.parse(number,region="US")
But I do not always know that the number will be US (this is just one case when I found that I did not get the desired behavior). Is there an option or trick for formatting that I skip? Thank!
source
share