Deutsch   English   Français   Italiano  
<mailman.3.1726897116.2990.python-list@python.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail
From: Barry <barry@barrys-emacs.org>
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI commands with Typer
Date: Sat, 21 Sep 2024 06:38:05 +0100
Lines: 39
Message-ID: <mailman.3.1726897116.2990.python-list@python.org>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
 <28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
Mime-Version: 1.0 (1.0)
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de tjeFCLbCaP4yIVzYkJ1faQQ+jvbRmoi07QcMOfjkaxxQ==
Cancel-Lock: sha1:dazwGLoRJ/dpyrhRS32zMggItqs= sha256:F1YWV6EUxQ96a8eE9+PhHoH0EpOB8EHPbnPdMh4iRys=
Return-Path: <barry@barrys-emacs.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
 dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'knows': 0.04; 'cc:addr
 :python-list': 0.09; 'enough.': 0.09; 'from:addr:barry': 0.09;
 'objects,': 0.09; 'received:217.70': 0.09; 'received:217.70.178':
 0.09; 'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09;
 'cheers,': 0.11; 'cc:no real name:2**0': 0.14; 'url:mailman':
 0.15; 'attributes': 0.16; 'barry': 0.16; 'bennett': 0.16;
 'from:addr:barrys-emacs.org': 0.16; 'instance': 0.16; 'ldap':
 0.16; 'message-id:@barrys-emacs.org': 0.16; 'wrote:': 0.16;
 'cc:addr:python.org': 0.20; 'creates': 0.22; 'maybe': 0.22;
 'command': 0.23; 'url-ip:188.166.95.178/32': 0.25; 'url-
 ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25;
 'url-ip:188.166/16': 0.25; 'function': 0.27; 'url-ip:188/8': 0.31;
 'expand': 0.32; 'python-list': 0.32; 'sep': 0.32; 'but': 0.32;
 "i'm": 0.33; 'subject:for': 0.33; 'there': 0.33; 'header:In-Reply-
 To:1': 0.34; 'following': 0.35; 'member': 0.37; 'currently': 0.37;
 'using': 0.37; 'class': 0.37; 'way': 0.38; 'single': 0.39;
 'define': 0.40; 'forms': 0.40; 'program.': 0.40; 'something':
 0.40; 'tell': 0.60; 'brief': 0.62; 'your': 0.64; 'received:217':
 0.67; 'skip:t 30': 0.67; 'signature': 0.76; 'database': 0.80;
 'about,': 0.84; '\xe2\x80\xa6': 0.91
In-Reply-To: <87tteayavt.fsf@zedat.fu-berlin.de>
X-Mailer: iPad Mail (22A3354)
X-GND-Sasl: barry@barrys-emacs.org
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
 <python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
 <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
 <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
X-Mailman-Original-References: <87tteayavt.fsf@zedat.fu-berlin.de>
Bytes: 4262



> On 20 Sep 2024, at 21:01, Loris Bennett via Python-list <python-list@pytho=
n.org> wrote:
>=20
> =EF=BB=BFHi,
>=20
> 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.
>=20
> 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.
>=20
> 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 yo=
ur class
and tell typer to call member function of the instance.

app =3D Application()
=E2=80=A6
typer.set_callback(app.my_handler)

Barry

>=20
> Cheers,
>=20
> Loris
>=20
> --
> This signature is currently under constuction.
> --
> https://mail.python.org/mailman/listinfo/python-list
>=20