I'm having difficulty accessing a variable.
I'm working toward the following, calling python script from bash, with arguments, which then imports a function defined in a second python script, executes it and thereby creates a variable which will be used later in the first python script.
At the moment,to test I'm copying and pasting directly into a Python terminal some commands like this:
from script2 import *
foofunction(arg)
print(newlist)
The foo function defined in script2 is executing, I can see files have been written but when I try to print the list supposedly created while executing the imported function, I get a message telling me it's undefined.
Inside my script2.py, i made sure to enter a statement
global newlist
before defining its length and populating it.
I'm scratching my head at this stage.
return newlistin that function and assign it to a variable?globalkeyword does not work that way in python. Have a look herefrom some_module import *is rarely a good practice as it mangles up your namespace. This is a prime example - without the knowledge ofscript2.pywe have no idea whetherfoofunctionandnewlistwould be aNameErroror an object that was defined inscript2.py. It's best to be explicit.