I'm making a lambda function in python. Here is the current structure of my project.
lambda/
|-- datas/
| |-- d.json
|
|-- package_name/
| |-- __init__.py
| |-- lambda_function.py # this is using d.json
| |-- a.py # this is some classes used on lambda_function
| |-- b.py # this is some basic time functions that a.py need
| |-- utils.py
|
|-- tests/
| |-- __init__.py
| |-- test_main.py
|-- setup.py
|-- README
I have some issues with imports.
# lambda_function.py files
from a import *
from utils import *
# a.py files
from b import *
# b.py files
from a import *
It's working locally, but not in aws lambda console. To make it working in aws lambda console, I need to change this :
# lambda_function.py files
from package_name.a import *
So my first question is : why ?
And my second question is : If I want to import package_name/a.py in tests/tests_main.py, what should I do ?
I tried
from a import *
from package_name import *
But it doesn't work
I'm still a little bit lost with how imports work, even after reading what internet had to say about it. Moreover, I'm not sure about my project files structure (but it's an other subject I guess)
use
# lambda_function.py files
from .a import *
from .utils import *
# a.py files
from .b import *
# b.py files
from .a import *
this will tell that from the current directory read the module and import all functions, classess, variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With