我正在使用电话号码模块来验证电话号码.它运行良好,但是我只需要国家号码作为输出


import phonenumbers
ph_no = "918332 88 1992"
print(phonenumbers.parse(ph_no, "IN"))

输出:

Country Code: 91 National Number: 8332881992

期望输出:

8332881992

我只需要电话号码返回。请帮忙!

您需要已分析电话号码的national_number属性。文档可以在这里找到。

import phonenumbers
ph_no = "918332 88 1992"
p = phonenumbers.parse(ph_no, "IN")
print(p.national_number)

您可以访问解析的电话号码的.national_number属性 [GitHub]:

import phonenumbers
ph_no = "918332 88 1992"
print(phonenumbers.parse(ph_no, "IN").national_number)

最新更新