Имеется класс
User :
class User(object):
def __init__(self,name):
self.name = name
self.number = None
Также иммется форма :
def name(message):
name = message.text
if name.isdigit():
msg = bot.send_message(message.chat.id, 'В имени не должно быть цифр')
bot.register_next_step_handler(msg ,name)
else:
user = User(name)
msg = bot.send_message(message.chat.id, 'Введите ваш номер телефона')
bot.register_next_step_handler(msg, phone_number)
# Проверка введенного номера
def phone_number(message):
number = message.text
if not number.isdigit():
msg = bot.send_message(message.chat.id, 'В номере не должны содержаться буквы')
bot.register_next_step_handler(msg, phone_number)
else:
user.number = number
msg = bot.send_message(message.chat.id, 'Заказ принят')
bot.register_next_step_handler(msg, send_info(message))
При указании номера Объект
user куда-то исчезает:
2019-02-01 17:44:10,007: Exception on /`TopSecret` [POST]
Traceback (most recent call last):
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/PyRayman/venv/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/PyRayman/TelegramBot/mainbot.py", line 64, in webhook
bot.process_new_updates([update])
File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 314, in process_new_updates
self.process_new_messages(new_messages)
File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 333, in process_new_messages
self._notify_next_handlers(new_messages)
File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 1299, in _notify_next_handlers
self._exec_task(handler["callback"], message, *handler["args"], **handler["kwargs"])
File "/home/PyRayman/venv/lib/python3.6/site-packages/telebot/__init__.py", line 464, in _exec_task
task(*args, **kwargs)
File "/home/PyRayman/TelegramBot/mainbot.py", line 324, in phone_number
user.number = number
NameError: name 'user' is not defined
В чем проблема?