I’m new and trying to make a simple random sentence generator-
How can I pull a random item out of a list that is stored in another .py document?
I’m using
random.choice(verb_list)
to pull from the list. How do I tell python that verb_list is in another document?
Also it would be helpful to know what the principle behind the solution is called. I imagine it’s something like ‘file referencing’ ‘file bridging’ etc..
You can import the variables from the file:
vardata.py
mainfile.py
you can also do:
to import everything from that file. Be careful with this though. You don’t want to have name collisions.
Alternatively, you can just import the file and access the variables though its namespace: