I have Python code repository compute module function.
How do I read the contents (json text file) stored as configuration in the same location as code repository?
Hey you can put the file under the same python directory your app.py
is in. In the container, the python folder should be mapped to /app/client/queries
. So inside your python code, you should be able to open it with open(f'./client/queries/{file_name}', 'r')
and then read it with file.read()
.
An alternative is you can write the file contents to a volume on compute module configuration. Then add that mount that volume to your container. Then inside the container you will be able to read the file from there. To config that in compute module app, go to configuration ā volumes, add a volume there. Then got to configuration ā containers ā add volume, mount the volume into your container.
This code works
with open("./client/queries/config.json", "r") as file:
content = file.read() ```
This code works with a compute module, but it does not seem to work with in a UDF.
with open("./client/queries/sample.json", "r") as file:
content = file.read()
print(content)
Can you advise on the path for UDF please?
UDF is a separate thing from compute module. The code-repository template organizes and packages directories differently. Iām not sure if there is even a ./client/queries directory. Would you mind checking with code-repositories or transforms-python?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.