question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Referencing modules

See original GitHub issue

Currently, any file / module references in main.py have to be with respect to the top level function app.

For e.g. -

FunctionApp
    |__ HttpTrigger1
             |__ function.json
             |__ main.py
             |__ model.pkl
    |__ host.json
    |__ requirements.txt
# main.py
import os
import azure.functions

def main(req: azure.functions.HttpRequest):

    # file reference wrt top level function app
    f = open('HttpTrigger1/model.pkl', 'rb')
   

Can we have relative paths instead? E.g. - f = open('model.pkl', 'rb')

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
elpranscommented, Mar 14, 2018

Modules should be imported using the relative import syntax:


from . import example

5reactions
anindya5commented, May 22, 2019

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

FunctionApp
|_ HttpTrigger1
     |_ __init__.py
     |_ function.json
     |_ SharedCode
        |_ module1.py
        |_ module2.py
|_ HttpTrigger2
     |_ __init__.py
     |_ function.json

The functions are defined inside module1 and module2

Usually I’d have done from ShareCode.module1 import function1

That does not work.

from .ShareCode.module1 import function1 also gives module not found error, shown below

Executed ‘Functions.HtmBatchAzureFunc’ (Failed, Id=d70ee3dc-dca2-4d89-b39c-5c902ed64b11) [5/22/19 8:54:05 PM] System.Private.CoreLib: Exception while executing function: Functions.HtmBatchAzureFunc. System.Private.CoreLib: Result: Failure [5/22/19 8:54:05 PM] Exception: ModuleNotFoundError: No module named ‘htm_shared_src’ [5/22/19 8:54:05 PM] Stack: File “/usr/local/Cellar/azure-functions-core-tools/2.7.1158/workers/python/deps/azure/functions_worker/dispatcher.py”, line 229, in _handle__function_load_request

Can anyone help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Referencing module texts - The Open University
This activity will focus on how you create a reference to a module text. Which referencing style? There are lots of different referencing...
Read more >
APA References and Citations - Modules - Academic Guides
The introduction to references and citations modules on this page offer students the opportunity to learn the basics of APA references and citations....
Read more >
Q. How do I cite modules or materials from courses?
No official format for citing online classroom materials exists - we do have a recommended format to use in citing such documents that...
Read more >
Referencing objects defined in modules - IBM
You can reference module objects by 3-part, 2-part, or sometimes 1-part names. Resolution of name references is done deterministically and depends on the...
Read more >
Citing and referencing: University course materials
Not all lecturers approve the use of Unit materials, such as lecture slides, in assignments. Check with your lecturer first to see if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found