Open-source Languages & Tools for z/OS

 View Only

 Python FileNotFoundError

Gary Grossi's profile image
Gary Grossi posted 11-07-2022 08:57
Hello,
We're having an issue trying to read a z/OS dataset. It works for a USS file. Running Python 3.95 in the base environment.
What are we missing?
thanks

# FileNotFoundError: [Errno 129] EDC5129I No such file or directory.
with open("//'xxxxxx.x.xxxxx'", 'r') as f:
    print(f.read())

# this works
with open('/u/xxxxxx/python/aws.py', 'r') as f:
    print(f.read())
Alexander Klochkov's profile image
ROCKETEER Alexander Klochkov

Hi Garry,

AFAIK, there's no way to open data sets using IBM's Python built-in functions. 
You can use the functions zoautil_py.datasets.read() and zoautil_py.datasets.write() from ZOAUtil.
More examples can be found in this blog (recommended in IBM's doc for Python).
Another workaround would be to use the subprocess module to pipe the data set contents through a shell command, e.g. cat.
See example #1 and example #2 below:

example 1
import subprocess

print(subprocess.run(["cat", "//'DATA.SET.NAME'"], capture_output = True, encoding = "iso8859-1").stdout)

example 2
import subprocess

with subprocess.Popen("cat \"//'DATA.SET.NAME'\"", shell=True, stdout=subprocess.PIPE, encoding = "iso8859-1").stdout as pipe:
print(pipe.readlines())

Note that the encoding is deliberately specified as ISO8859-1 because cat will automatically convert data set contents to this encoding.

Thanks,

Alexander

Gary Grossi's profile image
Gary Grossi
Hello Alexander,
Thanks for the update regarding IBM's ZOAU and also the examples.

Is this a feasible way using cat as well? Any limitations?

import os
os.system("cat \"//'xxx.xxx(xxx)'\"")
os.system("cat \"//'xxx.xxx'\"")


Thanks,
Gary

Alexander Klochkov's profile image
ROCKETEER Alexander Klochkov

Hi Garry,

According to os.system documentation it just executes the command, it doesn't capture the output and the return value is the exit status of the process.

Thanks,
Alexander