chuy
chuy

Reputation: 15

Is micropython compatible with Ply?

I would like to use the ply parser on micropython.

Running lex.py in micropython gives me a syntax error. Line 341.

def get_caller_module_dict(levels):
    f = sys._getframe(levels)
    return { **f.f_globals, **f.f_locals }  //<--- syntax error here

Also with circuitpython. No with cpython.

I use cpython 3.8.10, micropython 1.23 and circuitpython 9.2.

Any recommendations you can give me?

Upvotes: 0

Views: 41

Answers (1)

Jon Nordby
Jon Nordby

Reputation: 6299

This uses a feature from Python 3.5. MicroPython supports some features for Python 3.5+, but not all.

There are usually ways to rewrite the code to use a more basic. In this case you can try the following:

def get_caller_module_dict(levels):
    f = sys._getframe(levels)
    out = dict()
    out.update(f.f_globals)
    out.update(f.f_locals)
    return out

Upvotes: 0

Related Questions