X
X
xefimovgmail2021-12-09 03:30:52
Python
xefimovgmail, 2021-12-09 03:30:52

Why doesn't else work in try?

Good evening! I'm just starting to learn Japanese and I'm stuck on trifles ... I would be grateful for tips

import telegram

import config

from telegram import Update
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from Service.Database import DatabaseService

class TelegramBot:
  updater = None
  database_service =  None

  def __init__(self, token):

    try:
      self.database_service = DatabaseService(config.bd_name, config.bd_user, config.bd_pass, config.bd_host)

    except Exception as e:
      print(e)

    else:
      print("Connect database {}".format(config.bd_name))

    self.updater = Updater(token)
    self.handler()
    self.updater.start_polling()
    self.updater.idle()

  def handler(self):

    dispatcher = self.updater.dispatcher

    # обработчик событий
    dispatcher.add_handler(CommandHandler('start', self.start))


import psycopg2

class DatabaseService:

  conn = None
  cursor = None

  def __init__(self, bd_name, bd_user, bd_pass, bd_host):

    self.conn = psycopg2.connect("dbname={}, user={}, password={}, host={}".format(
                    bd_name, bd_user, bd_pass, bd_host))
    self.cursor = conn.cursor()


else from the first file for some reason does not work, according to the idea it should have output Connect database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xefimovgmail, 2021-12-09
@xefimovgmail

I solved the problem by removing the try construct. There was an error, but it was not displayed completely. This article helped

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question