I am trying to execute the below python code on z/OS Mainframe USS. The problem I'm facing is that when I run the code, I get the below error message. It appears the square brackets are not recognized in my code.
File "/u/q123/python/pyfilr.py", line 11
print(lineï..0:4ï..)
¬
SyntaxError: invalid syntax
Below is my code:
#!/usr/local/bin/rocket/python/python27
# -*- coding: utf-8 -*-
import os
import json
def main():
curpath = os.path.abspath(os.curdir)
inp_file_path = os.path.join(curpath, os.path.join("python","inp.txt")
file1 = open(inp_file_path,"r")
line = file1.readline().strip()
while line!="":
print(line[0:4])
jsonstr = json.dumps(line)
line = file1.readline().strip()
print(jsonstr)
file1.close()
if __name__ == "__main__":
main()
If my remove the 2nd line "# -- coding: utf-8 -- " in my code then it errors out for below error message.
SyntaxError: Non-ASCII character '\xdd' in file /u/q123/python/pyfilr.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
I am not sure how to fix the error. I am using python 2.7.
Can you suggest a solution to this problem so that I can use square brackets in my code?.