0

How can I send one variable to another script? I have 3 scripts (bot.py, language_dict.py, markups.py)

language_dict.py (dictionary)

russian = {
       "section": "Выберите раздел ➡",
       "individual": "Физические лица",
       "legal_entity": "Юридические лица",
   }

In bot.py I declare this dictionary to dic variable

import language_dict

def language(message):
chat_id = message.chat.id
if message.text == "Русский":
    dic = language_dict.russian
    msg = bot.send_message(chat_id, dictionary["section"])

So, I need to send dic to markups.py

import bot

#to here
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Pie
  • 3
  • 1

2 Answers2

0

I think you need to do something like this.

#in bot.py 
def class1():
    def func1(self):
        #do something
        #dic = language_dict.russian
        return #dic

#in markups.py
#from bot.py import class1
#create object of class1 under main method 
class1_obj = class1()
dic = class1.func1()
-1

You are assigning dic as a local variable in your language() method.

To fix this just assign dic above your language() method like this:

dic = {}

def language(message):
    global dic
    ...

you also need to put global dic in your method so that the interpreter knows you are changing the global variable dic inside your method

xSparfuchs
  • 132
  • 7