TM4C123G - def functions

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
SvenGlueck
Posts: 3
Joined: Thu Mar 26, 2020 5:09 pm

TM4C123G - def functions

Post by SvenGlueck » Mon Sep 14, 2020 12:12 pm

Hi all,

we are trying to get MicroPython work on the Tiva C Series TM4C123G. It is working pretty solid but we still have a big issue, which we were not able to resolve yet.

When we define a function like following:
def abc():
print('5')

and call I afterwards with abc(), e get he following error:

Traceback (most recent call last):
File "<stdin>", in <module>
NameError: name 'abc' is not defined

Does anyone of you know how to solve this issue or where to start looking at? Thank you in advance.

User avatar
pythoncoder
Posts: 4674
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: TM4C123G - def functions

Post by pythoncoder » Mon Sep 14, 2020 4:46 pm

Just to clarify, are you defining the function interactively at the REPL or in a Python source file?
Peter Hinch

SvenGlueck
Posts: 3
Joined: Thu Mar 26, 2020 5:09 pm

Re: TM4C123G - def functions

Post by SvenGlueck » Thu Sep 17, 2020 11:39 am

Currently I am just using the REPL.

User avatar
pythoncoder
Posts: 4674
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: TM4C123G - def functions

Post by pythoncoder » Sat Sep 19, 2020 5:32 pm

I have no experience of porting MicroPython but it might help those who have if you create the abc function then run locals() at the REPL. You should see something like

Code: Select all

{'__name__': '__main__', 'abc': <function abc at 0x7fa313905960>}
If you save the function definition and a function call as a Python file and import it, does it run?

Code: Select all

def abc():
    print('5')
abc()
Peter Hinch

Post Reply