Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #79: Look, buddy: Windows 3.1 IS A General Protection Fault.


comp / comp.lang.python / Re: Common objects for CLI commands with Typer

SubjectAuthor
* Common objects for CLI commands with TyperLoris Bennett
+- Re: Common objects for CLI (Posting On Python-List Prohibited)Lawrence D'Oliveiro
+- Re: Common objects for CLI commands with TyperBarry
+* Re: Common objects for CLI commands with Typer2QdxY4RzWzUUiLuE
|`- Re: Common objects for CLI commands with TyperGilmeh Serda
+- Re: Common objects for CLI commands with TyperBarry Scott
+- Re: Common objects for CLI commands with Typer2QdxY4RzWzUUiLuE
`- Re: Common objects for CLI commands with TyperRoland Müller

1
Subject: Common objects for CLI commands with Typer
From: Loris Bennett
Newsgroups: comp.lang.python
Organization: FUB-IT, Freie Universität Berlin
Date: Fri, 20 Sep 2024 08:42 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Common objects for CLI commands with Typer
Date: Fri, 20 Sep 2024 10:42:14 +0200
Organization: FUB-IT, Freie Universität Berlin
Lines: 19
Message-ID: <87tteayavt.fsf@zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de laEYfMurQ+BMTCoUiBaw8A5IsrUlWKAnD0rtY91vvvGmds
Cancel-Lock: sha1:vOqHBbNcYsCkNHhARzlNzY4QIRo= sha1:iX2L2BsjAxhev9HqugU6tQPbbkE= sha256:vH4ClPfrzqx3In3am4OaJMWdj+pMKgK87RJjthb6Y/U=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
View all headers

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.

Subject: Re: Common objects for CLI (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Fri, 20 Sep 2024 21:28 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI (Posting On Python-List Prohibited)
Date: Fri, 20 Sep 2024 21:28:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vckpeq$18k7r$1@dont-email.me>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 20 Sep 2024 23:28:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e114a577b81d0eff5431452080854aaa";
logging-data="1331451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+P5atIENdVBO3WnRp+goWg"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:3hG6M8kZll/JYPWm5gVS6Ujuudw=
View all headers

On Fri, 20 Sep 2024 10:42:14 +0200, Loris Bennett wrote:

> 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?

Never used Typer, but I see some details about more advanced use that
might be relevant here:

<https://typer.tiangolo.com/tutorial/subcommands/single-file/>

Subject: Re: Common objects for CLI commands with Typer
From: Barry
Newsgroups: comp.lang.python
Date: Sat, 21 Sep 2024 05:38 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: barry@barrys-emacs.org (Barry)
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>
View all headers

> 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
>

Subject: Re: Common objects for CLI commands with Typer
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Date: Sat, 21 Sep 2024 10:40 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI commands with Typer
Date: Sat, 21 Sep 2024 06:40:37 -0400
Lines: 52
Message-ID: <mailman.4.1726916551.2990.python-list@python.org>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de IPK7NAWf1Mw1WKcP+SgThAgFjiOqGvPJ7sMjUc/H6vJA==
Cancel-Lock: sha1:HIumQcVYBbbEv9MMPmZmbO+xK+E= sha256:tj/OgmmUDL/hP3OxO7ogTjKxpYQom+9CCjaJO57tjDU=
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=potatochowder.com header.i=@potatochowder.com
header.b=KS6ov+s4; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'knows': 0.04; 'despite':
0.05; 'python.': 0.08; ':-)': 0.09; 'enough.': 0.09; 'instances':
0.09; 'module.': 0.09; 'objects,': 0.09; 'received:78': 0.09;
'ahead,': 0.16; 'attributes': 0.16; 'barry': 0.16; 'bennett':
0.16; 'command.': 0.16; 'from:addr:2qdxy4rzwzuuilue': 0.16;
'from:addr:potatochowder.com': 0.16; 'instance': 0.16; 'invoke':
0.16; 'ldap': 0.16; 'objects.': 0.16; 'received:136.243': 0.16;
'received:172.58': 0.16; 'received:78.46': 0.16;
'received:78.46.172': 0.16; 'received:78.46.172.2': 0.16;
'received:sslproxy05.your-server.de': 0.16; 'received:www458.your-
server.de': 0.16; 'received:your-server.de': 0.16; 'things,':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; 'creates':
0.22; 'maybe': 0.22; 'returns': 0.22; 'command': 0.23; 'lines':
0.23; 'received:de': 0.23; 'python,': 0.25; 'classes': 0.26;
'manager,': 0.26; 'function': 0.27; 'fact': 0.28; 'wrong': 0.28;
'effect': 0.31; 'context': 0.32; 'expand': 0.32; 'python-list':
0.32; 'received:136': 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;
'complex': 0.35; 'following': 0.35; 'close': 0.35; 'functions':
0.36; 'possibly': 0.36; 'those': 0.36; 'member': 0.37;
'currently': 0.37; 'using': 0.37; 'class': 0.37; 'way': 0.38;
'put': 0.38; 'two': 0.39; 'single': 0.39; 'neither': 0.39;
'define': 0.40; 'forms': 0.40; 'program.': 0.40; 'something':
0.40; 'sorry': 0.60; 'tell': 0.60; "there's": 0.61; 'brief': 0.62;
'your': 0.64; 'top': 0.65; 'numbers': 0.67; 'skip:t 30': 0.67;
'within': 0.69; 'database': 0.80; 'about,': 0.84; 'eliminate':
0.84; '\xe2\x80\xa6': 0.91; '(all': 0.93
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=potatochowder.com; s=default2305; h=In-Reply-To:Content-Transfer-Encoding:
Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date:Sender:
Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=JpryJ5UIALw61BcOvbG0f5/2F+jjBCY//tC4jaJCmAY=; b=KS6ov+s42jq0YRZprZocaSEa7n
T9cJOSiPRVmJ16ocWp0coMrgXB2WqdgIUZISSwAIOjQ4sBbPvZTG4I8ESli5Msc2lFOS7iOy/4jbt
/AOLcfPuAiHc2rwWfX8andn5kMH6FDzTg+nk7uDf6ucIEvmWySaWHWVK9eepzEhyRVBJu28bkq7nr
yjEIrfgU6iIoatn/5ePzsTO1uTSMpGpRr/vMgzBFAqwwteJ22i2IFOaQYtHAgHSWQEj5xtEVywZWs
h63Vm+X15ZQ5157SDuAXAAsp09gOzQdGdZi6e79LrVFyxxjxB6fTxY46evV3W/lIpVTIFsEv29D9h
fskF7YSg==;
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.10/27405/Sat Sep 21 10:31:03 2024)
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: <Zu6ipTbew8LSHvKG@anomaly>
X-Mailman-Original-References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
View all headers

On 2024-09-21 at 06:38:05 +0100,
Barry via Python-list <python-list@python.org> wrote:

> > 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)

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.

There's also nothing wrong with writing a function that creates and
returns the database and LDAP connections (perhas as instances of
application-level classes), amd calling that function from within each
command.

DRY. Yeah, yeah, yeah. :-/ So there's one line at the top of each
comamnd that initializes things, and possibly a line at the bottom to
close those things down. Turn those lines into a context manager, which
is actually a sub-framework inside Typer. Don't convolute/compilicate
your design to eliminate one line at the top of each command.

Go ahead, accuse me of writing FORTRAN (all caps, no numbers or
qualifiers, as $deity intended) in Python. But neither optimize
prematurely nor invoke the Inner Platform Effect to save one or two
lines in your not-yet-written commands, either.

Sorry for the rant. :-)

Simple is better than complex.
Complex is better than complicated.

HTH.

Subject: Re: Common objects for CLI commands with Typer
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Sun, 22 Sep 2024 17:33 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx02.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Common objects for CLI commands with Typer
Newsgroups: comp.lang.python
References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<mailman.4.1726916551.2990.python-list@python.org>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.160 (Toresk; 9d04e24)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 25
Message-ID: <ZxYHO.684752$qP12.528438@fx02.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 22 Sep 2024 17:33:45 GMT
X-Received-Bytes: 1726
View all headers

On Sat, 21 Sep 2024 06:40:37 -0400, 2QdxY4RzWzUUiLuE 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.

Hear, hear!

Yet, lots of people put the word class in every module they ever create
and add the notion of @property readers/writers in as well, just because
that's what they always do.

More people (mainly Java and C++ folks, I suppose, and a few Delphi
ditto's) should watch and listen to what Hettinger has to say about _ and
__ and classes and how to use them and why those things were invented.

Python != (Java || C++ || Delphi)

Python == language_for_consenting_adults

--
Gilmeh

It pays to be obvious, especially if you have a reputation for subtlety.

Subject: Re: Common objects for CLI commands with Typer
From: Barry Scott
Newsgroups: comp.lang.python
Date: Mon, 23 Sep 2024 18:00 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: barry@barrys-emacs.org (Barry Scott)
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI commands with Typer
Date: Mon, 23 Sep 2024 19:00:10 +0100
Lines: 18
Message-ID: <mailman.5.1727114437.2990.python-list@python.org>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3818.100.11.1.3\))
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 5hgj9msCV42dSVkVXnTbNwtFpzqQIO3owl6wV+6uMUgw==
Cancel-Lock: sha1:X6n6k33+DMySPB4D83WHy0cABUM= sha256:upvZ38C45hBS5B9br1MSQhBStbal2Ek4aSJE0M/3YwU=
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.050
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'despite': 0.05; 'cc:addr
:python-list': 0.09; 'dan': 0.09; 'from:addr:barry': 0.09;
'module.': 0.09; 'received:217.70': 0.09; 'received:gandi.net':
0.09; 'received:mail.gandi.net': 0.09; 'cc:no real name:2**0':
0.14; 'barry': 0.16; 'from:addr:barrys-emacs.org': 0.16;
'from:name:barry scott': 0.16; 'message-id:@barrys-emacs.org':
0.16; 'objects.': 0.16; 'wrote:<span': 0.16; 'wrote:': 0.16;
'python': 0.16; 'cc:addr:python.org': 0.20; 'code': 0.23; 'lines':
0.23; 'python,': 0.25; 'cc:2**0': 0.25; 'classes': 0.26; 'fact':
0.28; 'email addr:python.org&gt;': 0.28; 'wrong': 0.28; 'python-
list': 0.32; 'sep': 0.32; 'but': 0.32; 'subject:for': 0.33; '0);':
0.33; 'rgb(0,': 0.33; 'header:In-Reply-To:1': 0.34; 'functions':
0.36; 'couple': 0.37; 'using': 0.37; 'put': 0.38; 'use': 0.39;
'helps': 0.60; 'font-family:': 0.60; 'inline': 0.61; 'skip:h 10':
0.61; "there's": 0.61; 'display:': 0.62; 'none;': 0.62; 'font-
weight:': 0.62; 'great': 0.63; '0px;': 0.63; 'once': 0.63; 'your':
0.64; 'text-indent:': 0.64; 'normal;': 0.66; 'received:217': 0.67;
'skip:! 10': 0.67; 'float:': 0.74; 'skip:! 20': 0.81; 'email
name:&lt;python-list': 0.84; '400;': 0.89; '13px;': 0.91;
'none;">': 0.91
In-Reply-To: <Zu6ipTbew8LSHvKG@anomaly>
X-Mailer: Apple Mail (2.3818.100.11.1.3)
X-GND-Sasl: barry@barrys-emacs.org
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
X-Mailman-Original-References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
View all headers

> 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.

Python is great in allowing you to pick your style.
A few lines in a module, a couple of functions or use classes.

But once your code gets big the disciple of using classes helps
maintenance. Code with lots of globals is problematic.

Barry

Subject: Re: Common objects for CLI commands with Typer
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Date: Mon, 23 Sep 2024 19:51 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI commands with Typer
Date: Mon, 23 Sep 2024 14:51:49 -0500
Lines: 21
Message-ID: <mailman.6.1727121120.2990.python-list@python.org>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
<ZvHG1Vzokb0yrUhv@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de RUwGCqVKPF8ZQTkVB8V3DAWV5i5YSlbEzeJUdmcwiVKA==
Cancel-Lock: sha1:GAv1/dBsWUBOf6fgETjTZVZ+iwk= sha256:wlq0oXgM28CwsPqciPTkOgNaHCCwx59rC9d1oNcQRHU=
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=potatochowder.com header.i=@potatochowder.com
header.b=ZNMeonAC; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; ':-)': 0.09; 'dan': 0.09;
'methods,': 0.09; 'received:78': 0.09; '"too': 0.16; 'barry':
0.16; 'definitions': 0.16; 'discipline': 0.16; 'elsewhere': 0.16;
'flexibility.': 0.16; 'from:addr:2qdxy4rzwzuuilue': 0.16;
'from:addr:potatochowder.com': 0.16; 'functions.': 0.16;
'namespaces': 0.16; 'received:136.243': 0.16; 'received:78.46':
0.16; 'received:www458.your-server.de': 0.16; 'received:your-
server.de': 0.16; 'wrote:': 0.16; 'python': 0.16; 'probably':
0.17; 'to:addr:python-list': 0.20; 'languages': 0.22; 'code':
0.23; 'received:de': 0.23; 'idea': 0.24; '(and': 0.25;
'programming': 0.25; 'classes': 0.26; 'module': 0.31; 'program':
0.31; 'python-list': 0.32; 'received:136': 0.32; 'sep': 0.32;
'but': 0.32; 'subject:for': 0.33; 'header:In-Reply-To:1': 0.34;
'people': 0.36; 'using': 0.37; 'class': 0.37; 'could': 0.38;
'helps': 0.60; 'great': 0.63; 'once': 0.63; 'your': 0.64; 'vary':
0.76; 'big,': 0.84; 'scott': 0.84
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=potatochowder.com; s=default2305; h=In-Reply-To:Content-Type:MIME-Version:
References:Message-ID:Subject:To:From:Date:Sender:Reply-To:Cc:
Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:
Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=/DkUhFBIOEVP2ysLswXvo/BEl0r7Dfz+tB5yUvk7iqE=; b=ZNMeonAC8lxNaijLIOWZV7s+S6
IHUTAZgQRPcFBZax/waYV3SYHRK6JSIbkiBVdaULv+Su9P+h77EzbB0/L8S90FLLK4ZHeziX0QXMh
T3VdN8qZGKJWh90ouhWmdhbAeGZKsus0y0vEY9hlsxGtWzGHsl3QM2Gj/DhSxIkO0aErvQaBOZwMZ
63+8yT3zPFmRHlRD5NnWMhOnHa3KSietZNd5scXTwsFPd688hofMWatIbFudJjBVkiVgZHPs29puE
07zZfVAqpQjilY1iNPjEAo8xa26YPJgMfm/Yfa0Ij9cQ2pfqtUFWbaf1tTlUXrnDm7v3m9nfl8nKx
vm0ofkgw==;
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.10/27407/Mon Sep 23 10:31:24 2024)
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: <ZvHG1Vzokb0yrUhv@anomaly>
X-Mailman-Original-References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
View all headers

On 2024-09-23 at 19:00:10 +0100,
Barry Scott <barry@barrys-emacs.org> wrote:

> > 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.

Even before your code gets big, discipline helps maintenance. :-)

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.

(And as was alluded to elsewhere in this thread, you could probably
deduce the original and/or preferred programming languages of people
with certain such definitions. But I digress.)

$ python -m this|grep Namespaces
Namespaces are one honking great idea -- let's do more of those!

Subject: Re: Common objects for CLI commands with Typer
From: Roland Müller
Newsgroups: comp.lang.python
Date: Wed, 16 Oct 2024 18:32 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: roland.em0001@googlemail.com (Roland Müller)
Newsgroups: comp.lang.python
Subject: Re: Common objects for CLI commands with Typer
Date: Wed, 16 Oct 2024 21:32:32 +0300
Lines: 28
Message-ID: <mailman.27.1729103559.4695.python-list@python.org>
References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
<ZvHG1Vzokb0yrUhv@anomaly>
<aa3149ba-a358-42a6-9e45-f408b745b7a8@googlemail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de /BNGZ7ZpJxPj0peP3iiTvgdnHH0Cdk/wEOlVvHQaxJqg==
Cancel-Lock: sha1:SHu+RBXSpWgB81j1Tj/3+V09/qk= sha256:iDt2zNruFkQTanjwaqCIfanc1zBukYrITpKIfVzzIqo=
Return-Path: <roland.em0001@googlemail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=googlemail.com header.i=@googlemail.com header.b=kTNE9vnh;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'modules': 0.07; ':-)':
0.09; 'aspect': 0.09; 'choice.': 0.09; 'dan': 0.09;
'from:addr:googlemail.com': 0.09; 'message-id:@googlemail.com':
0.09; 'methods,': 0.09; '"too': 0.16; 'barry': 0.16;
'definitions': 0.16; 'discipline': 0.16; 'flexibility.': 0.16;
'functions.': 0.16; 'objects.': 0.16; 'received:192.168.100':
0.16; 'received:mail-lf1-x136.google.com': 0.16; 'reuse': 0.16;
'structures': 0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20;
'code': 0.23; '(and': 0.25; 'classes': 0.26; 'object': 0.26;
'>>>': 0.28; 'header:User-Agent:1': 0.30; 'module': 0.31;
'program': 0.31; 'think': 0.32; 'objects': 0.32; 'python-list':
0.32; 'sep': 0.32; 'but': 0.32; 'subject:for': 0.33; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34; 'cases': 0.36;
'functions': 0.36; 'using': 0.37; 'class': 0.37;
'received:192.168': 0.37; 'single': 0.39; 'helps': 0.60; 'best':
0.61; 'once': 0.63; 'from:charset:utf-8': 0.64; 'thus': 0.64;
'times.': 0.64; 'your': 0.64; 'vary': 0.76; 'big,': 0.84;
'inherit': 0.84; 'scott': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=20230601; t=1729103557; x=1729708357; darn=python.org;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id:from
:to:cc:subject:date:message-id:reply-to;
bh=n+XLvxDrvrl4m9v6q6Y56FC2rI1IzbH8jLzcTVKvyxI=;
b=kTNE9vnhMiDaaVJusJjcIKiiW2Mw1l6QsSVzy0bV/LgJe3ESnRv0k0anDrKE1aT8mD
8ryYDoAnoB0Pdy7xHpJsApStikYSO5HxRpQXREf6syVtIDA5e/1RuaAklnJiNpTARS8o
TW5PTazwB9w4uEiBuOQ/CxFmMnlROyV4tulPMjFs8qWEaLv6Ci+bAFpgBhfY1Pf+E0fF
lC63ec9W2g1+xZ7Sh88kHNyu8QOszfFRms9ei3XPjFGzM2T/Ep7pJIQnq78n8eiiL3Js
Zeq2MBpx2IwZpVBqYR34blA5+PRaWormCiW3Vt6HQFcHR+aoBYTmyY6zsK6fioLIJbWw
IPvA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1729103557; x=1729708357;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=n+XLvxDrvrl4m9v6q6Y56FC2rI1IzbH8jLzcTVKvyxI=;
b=Xk0H6r6+pAAgsJpJBtIybcP2bjQKh5EAA1NfdGIn6OiizVeu74kvpyy3WgI6m0zrzr
rqv9PVSiGeERmlxDJ5mKo7DOkwRNjH+pzrPWpn8AwIei4VWym8uA+mCniO4qnzYpK6w6
/K1l/V+VRexwoFK2/nbwV3IqaIiwYj6tsdrdeJgD8EGv+GLUEfcnpDgd7GVOOPVSb2jG
CqzBWwFIKpvQFaP6zp2UQOJjDUketB3EZxxHlq221NS/Zbie1Axp5uDIBa35Qal2J4yS
csbMJerTvcL2KbghR9RGY0+gKbGSu5aDpmmIbvqCAJEzkankAe7hbedjbon2XfCipd3G
vqbQ==
X-Gm-Message-State: AOJu0Yyz1Od1iXYkLZhRiygultxZ/xvKG8WJoB08auZmXxDb3t4eMwvu
Mprv+8AP1BHFbuBl3Gyt8P9Z3+G1espx+43MWz9PQeqMfz91ALEXt7MeDg==
X-Google-Smtp-Source: AGHT+IEoO+EI+vm4f+rm8vspZzUSM61e+5bPp7SXdnLs1C1eL7zvY4J9AunDcxqx6u94EvTjVzLnWw==
X-Received: by 2002:a05:6512:31c2:b0:53a:c16:a9e with SMTP id
2adb3069b0e04-53a0c160b96mr728407e87.51.1729103557254;
Wed, 16 Oct 2024 11:32:37 -0700 (PDT)
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ZvHG1Vzokb0yrUhv@anomaly>
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: <aa3149ba-a358-42a6-9e45-f408b745b7a8@googlemail.com>
X-Mailman-Original-References: <87tteayavt.fsf@zedat.fu-berlin.de>
<28833A4D-B57C-4195-87BF-FAAF9EFF5F19@barrys-emacs.org>
<Zu6ipTbew8LSHvKG@anomaly>
<1E3ED29E-161E-430C-9E99-F89266472ADB@barrys-emacs.org>
<ZvHG1Vzokb0yrUhv@anomaly>
View all headers

On 9/23/24 22:51, Dan Sommers via Python-list wrote:
> On 2024-09-23 at 19:00:10 +0100,
> Barry Scott <barry@barrys-emacs.org> wrote:
>
>>> 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.
> Even before your code gets big, discipline helps maintenance. :-)
>
> 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.
>
I think the need of classes comes when you need objects thus a set of
variables with an identity and that may be created N times. Classes are
object factories.

A second aspect is inheritance: classes may inherit from other classes
and reuse existing functionality and data structures for their objects.

In cases where you only need to encapsulate a single set of data and
functions modules are the best choice.

1

rocksolid light 0.9.8
clearnet tor