我正在使用电话号码模块来验证电话号码。效果很好,但是我只需要输出国家数字

问题描述 投票:2回答:2
import phonenumbers
ph_no = "918332 88 1992"
print(phonenumbers.parse(ph_no, "IN"))

输出:

Country Code: 91 National Number: 8332881992

所需的输出:

8332881992

我只需要电话号码即可返回。请帮助!

python phone-number
2个回答
1
投票

您需要解析的电话号码的national_number属性。 Docs can be found here

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

0
投票

您可以访问已解析的电话号码的.national_number attribute [GitHub]

© www.soinside.com 2019 - 2024. All rights reserved.