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
4
  • What do you mean "send"? Commented Apr 26, 2020 at 14:59
  • Does this answer your question? Pass variable between python scripts Commented Apr 26, 2020 at 14:59
  • If those scripts are different processes, any IPC method will do. Commented Apr 26, 2020 at 15:01
  • jonrsharpe, I mean "pass" Commented Apr 26, 2020 at 15:02

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

Comments

-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

1 Comment

I tried it, didn't work. bot.py passed empty dictionary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.