Sujet : Re: Common objects for CLI commands with Typer
De : barry (at) *nospam* barrys-emacs.org (Barry)
Groupes : comp.lang.pythonDate : 21. Sep 2024, 07:38:05
Autres entêtes
Message-ID : <mailman.3.1726897116.2990.python-list@python.org>
References : 1 2
User-Agent : iPad Mail (22A3354)
On 20 Sep 2024, at 21:01, Loris Bennett via Python-list <python-list@python.org> wrote:
Hi,
Apologies if the following description is to brief - I can expand if no
one knows what I'm on about, but maybe a short description is enough.
I am developing a command line application using Typer. Most commands
need to do something in a database and also do LDAP stuff. Currently
each command creates its own Database and LDAP objects, since each
command forms an entry point to the program.
With Typer, is there a way I can define the equivalent of class
attributes at a single point which are then available to all commands?
I do not know typer. But the general solution is to create an instance of your class
and tell typer to call member function of the instance.
app = Application()
…
typer.set_callback(app.my_handler)
Barry
Cheers,
Loris
--
This signature is currently under constuction.
--
https://mail.python.org/mailman/listinfo/python-list