Skip to content

func .__ code__ ? #4045

@lukasmwerner

Description

@lukasmwerner

I know this was asked for in micropython 5ish years ago, but it seems that it still hasnt been implemented. I was wondering if this would be possible to add? Im currently working on creating a calculator that can be plugged in and have programs modified. The menu system ended up using that functionality.

class Program(object):

    def exec():
        '''to be implemented in programs'''
        pass

    def run(self):
        params = self.exec.__code__.co_varnames[1:self.exec.__code__.co_argcount]
        argList = []
        for param in params:
            argList.append(float(input(f"{param}: ")))
        funcKwarg = dict(zip(params, argList))
        print(f"Result: {self.exec(**funcKwarg)}")

If this isnt possible thats also fine, just wondering if it is possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions