You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-python.md
+38-10Lines changed: 38 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,16 +60,16 @@ The recommended folder structure for a Python Functions project looks like the f
60
60
61
61
```
62
62
__app__
63
-
| - MyFirstFunction
63
+
| - my_first_function
64
64
| | - __init__.py
65
65
| | - function.json
66
66
| | - example.py
67
-
| - MySecondFunction
67
+
| - my_second_function
68
68
| | - __init__.py
69
69
| | - function.json
70
-
| - SharedCode
71
-
| | - myFirstHelperFunction.py
72
-
| | - mySecondHelperFunction.py
70
+
| - shared_code
71
+
| | - my_first_helper_function.py
72
+
| | - my_second_helper_function.py
73
73
| - host.json
74
74
| - requirements.txt
75
75
tests
@@ -84,19 +84,47 @@ The main project folder (\_\_app\_\_) can contain the following files:
84
84
85
85
Each function has its own code file and binding configuration file (function.json).
86
86
87
-
Shared code should be kept in a separate folder in \_\_app\_\_. To reference modules in the SharedCode 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*:
88
92
89
93
```python
90
-
from__app__.SharedCodeimportmyFirstHelperFunction
94
+
from.importexample #(explicit relative)
91
95
```
92
96
93
-
To reference modules local to a function, you can use the relative import syntax as follows:
97
+
```python
98
+
from ..shared_code import my_first_helper_function #(explicit relative)
99
+
```
94
100
95
101
```python
96
-
from.importexample
102
+
from__app__importshared_code #(absolute)
97
103
```
98
104
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).
105
+
```python
106
+
import __app__.shared_code #(absolute)
107
+
```
108
+
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
0 commit comments