I am trying to call a variable in one function from another in Python
.
I tried returning the desired variables then putting them as inputs in the second function but it tells me that they are not defined. I don't know why it's doing this.
Basically, I want to use the Steps
list from Create_Array()
inside the Edit_PPress()
function without having to request user input again to ask which test, since this would be an inconvenience to the user.
def Create_Array():
outside_range = True
while outside_range == True:
test=getInput('What test?\n\n1 for Test A\n\n2 for TestB\n\n3 for Test C')
if test == '1':
Steps = [1,2,3]
outside_range = False
return Steps
elif test == '2':
Steps = [4,5,6]
outside_range = False
return Steps
elif test == '3':
Steps = [7,8,9]
outside_range = False
return Steps
else:
getWarningReply('Input is outside range. Please enter 1, 2, or 3.', "OKAY")
def Edit_PPress(Steps):
print Steps
Which produces this error:
`<type 'TypeError'>: Edit_PPress() takes exactly 4 arguments (0 given)`
I am using it in Abaqus, so when I run Edit_PPress, it will be just like putting Edit_PPress(Steps)
into the command prompt. I cannot create a class because Abaqus will not read functions inside of a class in its macro manager.
I am trying to call the Steps
variable that is generated as a list
in the Create_Array()
function into the second function Edit_PPress()
. I would add my comments as comments, but the format on my browser is messed up and won't let me add comments. I can only edit my original question. Also...I did read the FAQ on how to ask a good question. What information am I missing?
What I want to accomplish: Use the Steps variable that is defined in the first function, in the second function.
Problems: tells me that the Steps variable is not defined when I attempt to run second function following first function.