OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to redirect file location for a python package

  • Thread starter Thread starter Mykola Zotko
  • Start date Start date
M

Mykola Zotko

Guest
I have a package that uses one temporary file, and this file is written and loaded using the package functions. The problem is that I am using this package with Azure Functions, and you are only allowed to write to a special location there. How can I force this package to write to this location? The path is defined inside the package as a global variable:

Code:
### foo_package.py ###

path = 'file.json'

def read_file():
    with open(path, "r") as file:
        json_data = json.load(file)

def save_file(json_data):
    with open(path, "w") as file:
        json.dump(json_data, file)


def foo_function():
    file = load_file()
    ...
    save_file(json_data)

### my_code.py ###

from foo_package import foo_function

foo_function() # writes to ./, but i need to write to /some/path
<p>I have a package that uses one temporary file, and this file is written and loaded using the package functions. The problem is that I am using this package with Azure Functions, and you are only allowed to write to a special location there. How can I force this package to write to this location? The path is defined inside the package as a global variable:</p>
<pre><code>### foo_package.py ###

path = 'file.json'

def read_file():
with open(path, "r") as file:
json_data = json.load(file)

def save_file(json_data):
with open(path, "w") as file:
json.dump(json_data, file)


def foo_function():
file = load_file()
...
save_file(json_data)

### my_code.py ###

from foo_package import foo_function

foo_function() # writes to ./, but i need to write to /some/path
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top