Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取python中数字的匹配区域';s电话号码库_Python_Phone Number_Libphonenumber_Phonenumberutils - Fatal编程技术网

获取python中数字的匹配区域';s电话号码库

获取python中数字的匹配区域';s电话号码库,python,phone-number,libphonenumber,phonenumberutils,Python,Phone Number,Libphonenumber,Phonenumberutils,我使用python的库来解析和验证数字,如下所示: >> import phonenumbers >>> x = phonenumbers.parse("+442083661177") >>> print x Country Code: 44 National Number: 2083661177 Leading Zero: False 并且想知道是否有任何可能的方法来获得给定数字的2字母区域的匹配值,以便进一步使用 我尝试过这种方法,自述文件中

我使用python的库来解析和验证数字,如下所示:

>> import phonenumbers
>>> x = phonenumbers.parse("+442083661177")
>>> print x
Country Code: 44 National Number: 2083661177 Leading Zero: False
并且想知道是否有任何可能的方法来获得给定数字的2字母区域的匹配值,以便进一步使用

我尝试过这种方法,自述文件中提到过:

>>> from phonenumbers import timezone
>>> gb_number = phonenumbers.parse("+447986123456")
>>> list(timezone.time_zones_for_number(gb_number))
['Europe/London']

但问题是我找不到一种方法来解析另一个使用这些时区的数字。(
phonenumbers.parse(“07986123456”,“欧洲/伦敦”)
将引发异常)

您需要首先获取国家代码,而不是时区:

>>> gb_number = phonenumbers.parse("+447986123456")
>>> cc = phonenumbers.region_code_for_number(gb_number)
>>> cc
'GB'
>>> phonenumbers.parse("07986123456", cc)
PhoneNumber(country_code=44, national_number=7986123456, extension=None, italian_leading_zero=None, number_of_leading_zeros=None, country_code_source=None, preferred_domestic_carrier_code=None)
这是因为许多国家都有不同的拨号代码,但时区相同