How can I use instance methods as commands in Argh?

4 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Zach Abresch

ungelesen,
01.04.2020, 12:48:1201.04.20
an argh-users
I have a class that bundles a bunch of related functionality. I'd like to make an instance's methods available as commands with Argh. I used a snippet to extract a list of callable, non-dunder methods from my instance and then tried passing those to `.add_commands()` but, when running the app, I get the following error:

`AttributeError: 'str' object has no attribute '__name__'`

Is this possible? I've been scouring the docs and provided examples but haven't found anything that addresses my use case. Thanks for any help anyone can provide.

Zach Abresch

ungelesen,
01.04.2020, 12:49:1401.04.20
an argh-users
Here's the comprehension I'm using to get the instance methods:

object_methods = [
       method_name
       for method_name in dir(git)
       if callable(getattr(git, method_name))
       and not (method_name.startswith("__") and method_name.endswith("__"))
   ]


Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten