[wingide-users] Question on calling SubroutineA in SubroutineB

Yarko Tymciurak yarkot at uchicago.edu
Wed Nov 13 10:19:01 MST 2013


On Nov 13, 2013, at 9:52 AM, Wing IDE Support <support at wingware.com> wrote:

> On 11/13/13 3:46 AM, Joseph POLLACCO wrote:
>> I am new to the WingIDE 5community and I have a trivial question
>> concerning how to call another subroutine. This action is easily
>> performed in MATLAB and in FORTRAN but I do not know why this does not
>> work for me in WingIDE.
>> 
>> For example, calling the subroutine *TEST1(a,b) *[works well
>> independently] from subroutine TEST2.
> 
> Where are you defining your subroutines / functions?  In Python, it's typical to define multiple functions in one file, as in:

You might want to try this in a file outside of wing, perhaps bpython.
What you have going on is that python is an interpreter, which reads the file in order.
What is likely going on is that your first function is “read” and executed before the second function’s definition is read,
i.e. before the second function even exists in the interpreter’s dictionary of names.

The typical way to address this in python is to define a function near the bottom of a file (a “main()”)  which then delegates
to functions.   In this way, all the function definitions have been read before an attempt to execute them.

For example, 

def test1():
     result = test2()

def test2():
     return “hello”

# this will work - but if this line is at top of file, it won’t;

my_total_result = test1()


You can also import from the current directory into the top of a file, if readability is your concern, and
you’d like to just have the logic that “gets on with it” at the top of the file.

Google for “python forward reference” and “import”  and that should get you started.
bpython (bpython-interpreter.org) is a nice interactive tool, with nice completions to play around with (and save your results).


> 
> def test1():
>  ...
> 
> def test2():
>  ...
> 
> Note that this is more of a question about Python than about Wing IDE. You may want to look at some of the introductions to Python for programmers found on https://wiki.python.org/moin/BeginnersGuide/Programmers and elsewhere. I also found http://wiki.scipy.org/NumPy_for_Matlab_Users through google, which could be helpful if you use NumPy / SciPy.
> 
> Cheers,
> 
> John
> 
> _________________________________________________
> Wing IDE users list
> http://wingware.com/lists/wingide



More information about the wingide-users mailing list