using a variable in a different file /u/bruhmoment0000001 Python Education

hi guys, im learning python by myself and coding my first big project (tg bot on aiogram), and i read that i should put handlers in different files, so its easier to work with them, so i did.

but now when i want to use a variable from main (which should work because handlers files are imported in main and im running main) it says that variable is not defined, so im not sure how to do it. I think i can try to import this variable from main but im already importing the whole file to main so importing this variable from main to this file feels incorrect.

Thanks in advance!

upd Im making a dictionary to store all users data (i know it isnt efficient, i will use a db, thats basically a prototype), and obviously i need to use it in handlers, but i dont know how to do it because i cant import it. Should i just put everything back in one file? im pretty sure it would work but again it feels very stupid

submitted by /u/bruhmoment0000001
[link] [comments]

​r/learnpython hi guys, im learning python by myself and coding my first big project (tg bot on aiogram), and i read that i should put handlers in different files, so its easier to work with them, so i did. but now when i want to use a variable from main (which should work because handlers files are imported in main and im running main) it says that variable is not defined, so im not sure how to do it. I think i can try to import this variable from main but im already importing the whole file to main so importing this variable from main to this file feels incorrect. Thanks in advance! upd Im making a dictionary to store all users data (i know it isnt efficient, i will use a db, thats basically a prototype), and obviously i need to use it in handlers, but i dont know how to do it because i cant import it. Should i just put everything back in one file? im pretty sure it would work but again it feels very stupid submitted by /u/bruhmoment0000001 [link] [comments] 

hi guys, im learning python by myself and coding my first big project (tg bot on aiogram), and i read that i should put handlers in different files, so its easier to work with them, so i did.

but now when i want to use a variable from main (which should work because handlers files are imported in main and im running main) it says that variable is not defined, so im not sure how to do it. I think i can try to import this variable from main but im already importing the whole file to main so importing this variable from main to this file feels incorrect.

Thanks in advance!

upd Im making a dictionary to store all users data (i know it isnt efficient, i will use a db, thats basically a prototype), and obviously i need to use it in handlers, but i dont know how to do it because i cant import it. Should i just put everything back in one file? im pretty sure it would work but again it feels very stupid

submitted by /u/bruhmoment0000001
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *