using JavApp with python programs ...

If the JavApp loads a file having .py suffix, it assumes that the file contains a python program. The following example assumes that your computer has python installed.

For example, suppose that file /pylib/fibo.py contains the following code, which computes Fibonacci sequences, and that this file is currently loaded into the JavaEditor:

# fibo.py

def fib(n): # return Fibonacci series up to n 
   '''return Fibonacci series up to n, as a sequence'''
   result = []
   a, b = 0, 1 
   while b < n:
      result.append(b)
      a, b = b, a+b 
   return result

#############
# test script
#############
if __name__ == "__main__":
   import sys
   print fib(int(sys.argv[1]))

The test script allows us to test the fib function. Hit the editor's run button
... and the following dialog pops up. The python run command and the file specifications are automatically filled in.

In the textbox labelled "Command line parameters" enter 10 (or other natural number), assuming we want the Fibonacci sequence bounded by 10.
The result [1, 1, 2, 3, 5, 8] is printed in the JavApp console window.

It is easy to adapt the JavaEditor for more sophisticated python program editing and testing.
For example, if one uses the run command /Library/Frameworks/Python.framework/Versions/3.5/Resources/Python.app/Contents/MacOS/Python
(on Mac) then python3.5 will run the program.


© John Fisher 1998-2016