0

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.

Ryan
  • 25
  • 1
  • 5
  • 1
    What exactly is the problem here? Could you show how you are calling these functions, and provide the full error traceback? – jonrsharpe Jun 24 '14 at 16:47
  • it looks like you're confused about where to place the parameters. Does this help you a bit: https://gist.github.com/anonymous/c2429c27738c4f31fa94 – STW Jun 24 '14 at 18:38
  • Which variable do you want to call, specifically? – Anderson Green Jun 24 '14 at 18:59
  • Take a few minutes to read StackOverflow's FAQs on how to ask a good question, and how the site works. Edit your question to say specifically what your goal is, what you've tried (with a minimal code sample), and add your comments/discussions as comments rather than editing the answer--StackOverflow is a great place to get help, but really requires you to ask pointed and well formed questions to avoid them being closed. – STW Jun 24 '14 at 19:02

0 Answers0