D
D
duduychvbk992021-08-28 18:54:29
Python
duduychvbk99, 2021-08-28 18:54:29

phonenumbers module. How can I remove this text and not get an error?

Working with the phonenumbers module
Here is a piece of code:

try:
            number_parse = phonenumbers.parse("+375298571212")
            number_code = (region_code_for_country_code(number_parse.country_code))
            number_city = (geocoder.description_for_number(number_parse, "en"))
            number_operator = (carrier.name_for_number(number_parse, "en"))
            number_timezone = (timezone.time_zones_for_number(number_parse))
            bot.send_message(message.chat.id, f'<b>Номер:</b> <code>{number_parse}</code>\n\n<b>Страна:</b> {number_city}\n<b>Код:</b> {number_code}\n<b>Оператор:</b> {number_operator}\n<b>Часовой пояс:</b> {number_timezone}', parse_mode="html", reply_markup=menu)
        except Exception as e:
            bot.send_message(message.chat.id, f'❌ <b>Произошла ошибка: {e}</b>\n<em>Вы перемещены в меню.</em>', parse_mode="html", reply_markup=menu)

I get:

Номер: Country Code: 375 National Number: 298571212

Страна: Belarus
Код: BY
Оператор: MTS
Часовой пояс: ('Europe/Moscow',)


It is necessary to remove the text "Country Code: 375 National Number: 298571212".
I wanted to solve it like this:
Remove number_parse = phonenumbers.parse("+375298571212")
And replace it with number_parse = '+375298571212'
But now I get this error: 'int' object has no attribute 'country_code'
How to find the best option? That is, so that everything would work and there would be no text "Country Code: 375 National Number: 298571212"? If you do not understand something, ask me a question, I will throw off everything and answer everything. I am a beginner in this business.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question