I'm new to using Python on z/OS; I am creating a program in a USS directory on our mainframe and using a Rocket Software 3270 emulator; I am trying to use square brackets in my code, but as soon as I add them and do anything they change from brackets to a strange triangular symbols, and then when I try to run the program it either gives me an encoding or syntax error. Here's my test code:
from zoautil_py import datasets
dataset_name = "'CICS.H39808.PROCLIB(S55CTL)'"
results = datasets.read(dataset_name)
lines = results.split('\n')
for line in lines:
print(line[0:4])
Test1 - change to print(line); it compiles and runs fine
For all following tests, put back to print(line[0:4])
Test2 - add '# -- coding: cp1047 --' to the top; results in: SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0x86 in position 0: invalid start byte
Test3 - remove '# -- coding: cp1047 --'; use this command first:
iconv -f UTF-8 -t IBM-1047 test1.py >test2.py
resulted in: 132 illegal character sequence(s) for codeset in input file
Test4 - use this command instead: iconv -f IBM-1047 -t UTF-8 test1.py >test3.py Executed with no errors reports; trying to run the program returns: SyntaxError: Non-UTF-8 code starting with '\xc3' in file test3.py on line 1, but no encoding declared
Test5 - add '# -- coding: cp1047 --' to the top; used this command again iconv -f UTF-8 -t IBM-1047 test1.py >test2.py resulted in: 130 illegal character sequence(s) for codeset in input file
Any suggestions? I saw there was a very similar issue raised 5 years ago, but that was in Python 2 and Python 3 changed the source code formatting from ASCII to UTF-8 so I didn't think I'd need to tag my files with utf-8 the way it used to be done; I tried the iconv commands since I saw that recommended in the previously provided answer. If it has something to do with my emulator changing the brackets on me when it shouldn't, I tried looking in my keyboard and other settings and couldn't find anything that would fix it.
When using an emulator and TSO / ISPF Option 3.17 to edit the file. This has a strong relationship to your issue. I'm adding what I believe is the source of your issue which is the emulator settings. Check your code page in the emulator. Here is my setting which works fine editing the USS source file in the USS filesystem.
The other issue maybe that your keyboard mapping of the [
]
is sending in a different character. This was an issue in the past with z/OS but its addressed by using the correct code page and keyboard mapping.
Turn on Hex
in the editor and you should see this
x'ad' and x'bd' for the brackets