This posts contains small snippets of useful information about using IBM Python on z/OS.

Displaying [] in your OMVS session

The OMVS command has a CONVERT option that lets you specify a conversion
table for converting between code pages. The table you want to specify depends
on the code pages you are using in MVS and in the shell. For example, if you are
using code page IBM-037 in MVS and code page IBM-1047 in the shell, specify the
following when you enter the TSO OMVS command:
OMVS CONVERT((BPXFX111))

For example the program

a = {"a1",2,"a3"}
b = ["a1",2,"a3"]
print(a)
print(b)

With OMVS CONVERT((BPXFX111)) when you run it, you get

{'a1', 2, 'a3'}
['a1', 2, 'a3']

With OMVS you get

{'a1', 2, 'a3'}
Ý'a1', 2, 'a3'¨

How to edit source

The provided .py files format ok in ISPF when using US English 037. This is different to my normal code page of Bracket CP037 Modified.

With US English 037 in ISPF editor I get

a = {"a1",2,"a3"}
b = ["a1",2,"a3"]

With Bracket CP037 Modified - which works for normal C

a = {"a1",2,"a3"}
b = Ý"a1",2,"a3"¨

What machine is this running on ?

My z/OS is z/OS 2.4 on zPDT on Linux.

import platform
sys.path.append('./')
import pymqi
print("machine",platform.machine())
print("platform",platform.platform())
print("arch ",platform.architecture())
print("process ",platform.processor())
print("compiler",platform.python_compiler())
print("system ",platform.system())

gives

machine 1090
platform OS-390-27.00-1090-64bit
arch ('64bit', '')
process
compiler Clang 4.0.1 (tags/RELEASE_401/final)
system OS/390

Using struct.pack

I wanted to understand what pack did on z/OS. Using a statement like print("i",struct.pack("i",1)) to format a number I got

b b'\x01'
h b'\x00\x01'
H b'\x00\x01'
i b'\x00\x00\x00\x01'
I b'\x00\x00\x00\x01'
l b'\x00\x00\x00\x00\x00\x00\x00\x01'
L b'\x00\x00\x00\x00\x00\x00\x00\x01'
q b'\x00\x00\x00\x00\x00\x00\x00\x01'
Q b'\x00\x00\x00\x00\x00\x00\x00\x01'
n b'\x00\x00\x00\x00\x00\x00\x00\x01'
N b'\x00\x00\x00\x00\x00\x00\x00\x01'
P b'\x00\x00\x00\x00\x00\x00\x00\x01'

print("h",struct.pack("h",-1)) gave
h b'\xff\xff'

I also noticed a "funny"

z = b'AB23'
print("4sll" , struct.pack("4sll",z,2,1))

gave me

4sll b'AB23\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x01'

The red text is from the long variable, the green text is the padding to make the long value on a long boundary (8).