电话号码python模块没有给出正确的国家代码



我正在尝试使用python中的电话号码模块,但遇到了以下问题,它错误地提供了国家代码;这两个都是美国的电话号码。有人能建议如何处理吗

import phonenumbers
print(phonenumbers.parse("+301.795.1400")) 
Output: Country Code: 30 National Number: 17951400 ---Wrong
print(phone numbers.parse("+1301.795.1400")) --- ( After Adding +1 or removing '+'  it becomes correct)
output: Country Code: 1 National Number: 3017951400

例如:

+44 7923 903949 -- Country Code +44  which is correct
+782-205-2583   --Country Code +7 which is wrong
My expectation is +1 as country code ,phone number as 782-205-2583

加号('+'(表示以下数字是国家代码。美国的国家代码是"1"(即"+1"(。您输入加号,告诉解析器下一个或多个数字是国家代码,但随后省略所需的国家代码。

在我看来,这个模块工作正常。

参见:

https://countrycode.org/

最新更新