[wingide-users] Question on calling SubroutineA in SubroutineB

Joseph POLLACCO pollacco.water at gmail.com
Thu Nov 14 02:12:49 MST 2013

Dear John and Yarko Tymciurak,

Many thanks for responding to my question so promptly.

Thanks for introducing me to MumPy/ SciPy which will make my transition 
from MATLAB to PYTHON easier. To date I am using an excellent textbook 
Think Python (How to think like a computer scientist).

Many thanks for informing me that PYTHON reads from top to bottom.

def test2():

      return 'hello'

def test1():

      return test2()

print( test2() )

Now I have an other question, which worked well when I started using an 
interpreter like bpython but to date not with WINGWARE:

Saved as TEST2.py

def TEST2():

      return 'hello'


Saved as TEST1.py

def TEST1():

      return TEST2()

print( TEST2() )

Running TEST1


File "C:\JOSEPH\PYTHON2\TESTING\TEST1.py", line 4, in <module>
        print( TEST2() )

         NameError: name 'TEST2' is not defined

I have performed the following action which did not help:

1) Created a NewProject;

2) Add existing directory

3) Project properties -> Environment -> Python path (Custom)

Many thanks for any help you may provide to help me call functions 
defined by the users.

Kind regards,


Joseph Alexander Paul POLLACCO
(: (+33) 1 69 86 16 61
)skype: joseph_pollacco

------ Original Message ------
From: "Yarko Tymciurak" <yarkot at uchicago.edu>
To: "Wingware Support" <support at wingware.com>
Cc: "Joseph POLLACCO" <pollacco.water at gmail.com>; 
"wingide-users at wingware.com" <wingide-users at wingware.com>
Sent: 13/11/2013 18:19:01
Subject: Re: [wingide-users] Question on calling SubroutineA in 
>On Nov 13, 2013, at 9:52 AM, Wing IDE Support <support at wingware.com> 
>>  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 
>>>  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/wingide-users/attachments/20131114/066db40a/attachment.html>

More information about the wingide-users mailing list