Products Resources Support About Us

Rocket Software

Python 2.7 in z/OS USS - Unprintable characters displayed in the code while executing

I am trying to execute a simple python code on z/OS USS. The code was working fine until I added code to assign values to a dictionary. When I run my code, it displays unprintable characters in the output at the code location where I assign a value to the dictionary. ie., in line d[“Alias”] = line[0:4]
It appears that square brackets ‘[’ are not valid. When I run the same code in my workstation using pycharm editor, it runs fine. So, I am not sure what the issue is. Can anyone help me to resolve this issue ?

d = {}
file1 = open(inp_file_path,“r”)
line = file1.readline().strip()
while line!="":
d[“Alias”] = line[0:4]
jsonstr = json.dumps(d)
line = file1.readline.strip()
file1.close()
print(jsonstr)

Here is the output in the job:
File “/u/test/python/pyfilr.py”, line 15
dï…"Alias"ï… = lineï…0:4ï…
¬
SyntaxError: invalid syntax

Hi,
this is probably a code page issue. If you’re using Python 2.7.6 then you need to convert the python script to EBCDIC. The USS code page is 1047.
When you transferred the script you should make sure to have it converted to 1047.

In other EBCDIC code pages the binary values of special characters vary wildely.

So for opening/closing square bracket cp1047 is AD/BD vs. cp37 BA/BB.

With later Python versions you could transfer the script in binary mode if it is encoded in latin1. And you tag the script with the encoding that it is in.

chtag -tc ISO8859-1 your_script.py

HTH,
mm

Thank you very much!.