-
Notifications
You must be signed in to change notification settings - Fork 107
Referencing modules #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The issue is that the current working directory is a global per-process setting. It's impossible to do a |
The recommended way to reference local files in Python in general is to use import pathlib
open(pathlib.Path(__file__).parent / 'model.pkl', 'rb') |
Okay. Do you recommend the same for importing modules as well? Here's the issue I'm running into:
# main.py
import example #fails
import HttpTrigger/example #also fails |
Modules should be imported using the relative import syntax: from . import example |
That works - thanks! |
What about if the function uses packages like helpers in the sample below?
It looks like placing the helpers package in the same folder as the python function is not enough. As a workaround, we had to explicitly add the current folder to the path as follows: from sys import path
from os.path import dirname, join
path.append(dirname(__file__))
import json
from helpers.jwt import JWT
... |
Use |
Thanks @elprans |
Hi, My issue is if I want to import a function say function1 in module1 of SharedCode, but for me the SharedCode is inside the API folder, like below
The functions are defined inside module1 and module2 Usually I'd have done That does not work.
Can anyone help |
Uh oh!
There was an error while loading. Please reload this page.
Currently, any file / module references in
main.py
have to be with respect to the top level function app.For e.g. -
Can we have relative paths instead? E.g. -
f = open('model.pkl', 'rb')
The text was updated successfully, but these errors were encountered: