Skip to content

Commit 100d00c

Browse files
author
Glenn Gailey
committed
1 parent 6a2c00c commit 100d00c

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

articles/azure-functions/functions-reference-python.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,47 @@ The main project folder (\_\_app\_\_) can contain the following files:
8484

8585
Each function has its own code file and binding configuration file (function.json).
8686

87-
Shared code should be kept in a separate folder in \_\_app\_\_. To reference modules in the shared\_code folder, you can use the following syntax:
87+
When deploying your project to a function app in Azure, the entire contents of the main project (*\_\_app\_\_*) folder should be included in the package, but not the folder itself. We recommend that you maintain your tests in a folder separate from the project folder, in this example `tests`. This keeps you from deploying test code with your app. For more information, see [Unit Testing](#unit-testing).
88+
89+
## Import behavior
90+
91+
You can import modules in your function code using both explicit relative and absolute references. Based on the folder structure shown above, the following imports work from within the function file *\_\_app\_\_\my\_first\_function\\_\_init\_\_.py*:
8892

8993
```python
90-
from __app__.shared_code import my_first_helper_function
94+
from . import example #(explicit relative)
95+
```
96+
97+
```python
98+
from ..shared_code import my_first_helper_function #(explicit relative)
9199
```
92100

93-
To reference modules local to a function, you can use the relative import syntax as follows:
101+
```python
102+
from __app__ import shared_code #(absolute)
103+
```
94104

95105
```python
96-
from . import example
106+
import __app__.shared_code #(absolute)
97107
```
98108

99-
When deploying your project to a function app in Azure, the entire contents of the main project (*\_\_app\_\_*) folder should be included in the package, but not the folder itself. We recommend that you maintain your tests in a folder separate from the project folder, in this example `tests`. This keeps you from deploying test code with your app. For more information, see [Unit Testing](#unit-testing).
109+
The following imports *don't work* from within the same file:
110+
111+
```python
112+
import example
113+
```
114+
115+
```python
116+
from example import some_helper_code
117+
```
118+
119+
```python
120+
import shared_code
121+
```
122+
123+
Shared code should be kept in a separate folder in *\_\_app\_\_*. To reference modules in the *shared\_code* folder, you can use the following syntax:
124+
125+
```python
126+
from __app__.shared_code import my_first_helper_function
127+
```
100128

101129
## Triggers and Inputs
102130

0 commit comments

Comments
 (0)