rezamnk
rezamnk

Reputation: 31

How to use libraries in imported module in python

I was trying to create a telegram bot using pytelegrambotapi. I decided to write every functions in separate files like files bellow, but I don't know how to use a library in main file and use it in other files (modules) ?

main.py :

import telebot
def call_back(call):
    setadmins.callback(call)

setadmins.py (module) :

def callback(call):
    markup = telebot.types.InlineKeyboardMarkup()

    # rest of code is not related

The error that python interpreter returns is : NameError: name 'telebot' is not defined

Im using python 3.6.9 (linux mint stock)

and in the end , sorry for my bad english :)

Upvotes: 0

Views: 206

Answers (1)

AbbeGijly
AbbeGijly

Reputation: 1211

In order to resolve the name telebot.types the module source setadmins.py must include

import telebot

(typically placed near the top of the module).

Similarly main.py will have to include

import setadmins

Upvotes: 1

Related Questions