How to run additional python files in main.py? (discord bot)
I'm trying to clean up my python code so that different parts are in separate files but I'm unsure on how to get these files to run in my main python file. I've done:
from file_name import *
but it says it is unused, and that it is unable to detect undefined names. When i try to run the code in discord, it works fine with any code in main.py but does nothing when i try code from my separate files.
import filename
will run the file. You can then do filename.somethingElse
to get a function or variable from the file
from filename import somethingElse
will import a specific function or variable from that file. You can then just do somethingElse
to use the thing you imported
from filename import *
imports all the functions, variables etc from the file and all of them can be access with just their name rather than filename.somethingElse
I think in your case you may just want to do import single_response
@CodingCactus what do you mean by somethingElse please give an example
one way is to go to the shell, and type in python FILENAME.py
, so replace FILENAME
with the file you want to run.
Ok, first add a python file, were going to be using
example.py
.Second, add this code to
example.py
And finally, your going to add this code to
main.py
: