Python on IBM i


Python on IBM i has been around for many years now but only few are using it. In most banking application, using open source language is not allowed. So though we are able to run some basic programs on pyton/Node.js we do not get to install/use all the modules. ITjungle has many articles on iseriespython. I assume earler it had to installed but with V7R1 i assume it comes pre-installed.
On IBM i, 5733-OPS placeholder for open source technologies contains python,Node.js.

Thanks to Aaron Bartell, litmis spaces for providing the platform for learning. Litmis spaces is hosting IBM i on cloud and provides single tenant for free. You can also try out pub400.com which is a free server.

Open the Qshell with QSH  from command line and to identify the location of python runtime type below command -
$which python3
/QOpenSys/usr/bin/python3

Python3 does not reside here but a symbolic representation. The original location /QOpenSys/QIBM/ProdData/OPS/Python3.4/bin/python3.

$python3 --version
Python 3.4.4

In the IFS, we must create a file 'Helloworld.py'. Open the file and type
print ('Hello world')

Go to shell and type
python3 Helloworld.py
Hello world

Simple loop in shell

$ for x in range(5):
...    print (x)
0
1
2
3
4

Sample python program -

Input file - Loop.py





Output file.









Web application -
We can use bottle web-framework to run a simple 'hello world' web page. Bottle can run as stand-alone web server. Bottle needs to be installed with pip command. pip is a package manager to install and manage package in python.

Below is example from bottle.org

Example: “Hello World” in a bottle
from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

Popular posts from this blog

PF2XLS - Python

Stock Analysis - Example with Ashok Leyland