Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 42 |
Nodes: | 6 (0 / 6) |
Uptime: | 00:30:39 |
Calls: | 220 |
Calls today: | 1 |
Files: | 824 |
Messages: | 121,520 |
Posted today: | 6 |
Despite the fact that "everything is an object" in Python, you don't
have to put data or functions inside classes or objects. I also know
nothing about Typer, but there's nothing wrong with functions in a
module.
On 21 Sep 2024, at 11:40, Dan Sommers via Python-list <python-list@python.org> wrote:
Despite the fact that "everything is an object" in Python, you don't
have to put data or functions inside classes or objects. I also know
nothing about Typer, but there's nothing wrong with functions in a
module.
On 21 Sep 2024, at 11:40, Dan Sommers via Python-list <python-list@python.org> wrote:
But once your code gets big the disciple of using classes helps
maintenance. Code with lots of globals is problematic.
On 2024-09-23 at 19:00:10 +0100,
Barry Scott <barry@barrys-emacs.org> wrote:
Even before your code gets big, discipline helps maintenance. :-)On 21 Sep 2024, at 11:40, Dan Sommers via Python-list <python-list@python.org> wrote:But once your code gets big the disciple of using classes helps
maintenance. Code with lots of globals is problematic.
Every level of your program has globals. An application with too many classes is no better (or worse) than a class with too many methods, or a module with too many functions. Insert your own definitions of (and tolerances for) "too many," which will vary in flexibility.
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?
Cheers,
Loris
--
This signature is currently under constuction.
--
https://mail.python.org/mailman/listinfo/python-list
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)