1

My directory structure on RPi:

/
firmware
   __init__.py
   functions.py
main.py

__init__.py is empty, in my main.py, I have:

import firmware

print(current_version)

while functions.py contains just:

current_version='1.0.0'

When I run, I get the following error:

NameError: name 'current_version' isn't defined

My question is: how can I import functions from files inside the /firmware directory? I tried all Python ways known to me, including sys.path.add but to my great disappointment, it failed to work. Is Micropython on RPi Pico special in that way? According to this link, it should work...

1 Answer 1

0

I think you are almost there, you just need to import the functions definition.

I have this structure

└── firmware
    ├── functions.py
    ├── __init.py__

__init.py__ is empty.

funtions.py is

cat firmware/functions.py 
version="1.0.1"

def current_version():
    return version

Testing in Python

>>> from firmware import functions
>>> print(functions.version)
1.0.1
>>> print(functions.current_version())
1.0.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.