Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

We are drowning in information but starved for knowledge. -- John Naisbitt, Megatrends


devel / comp.lang.python / Re: learning python ...

SubjectAuthor
o Re: learning python ...Cameron Simpson

1
Re: learning python ...

<mailman.285.1621807417.3087.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17668&group=comp.lang.python#17668

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: learning python ...
Date: Mon, 24 May 2021 08:03:24 +1000
Lines: 63
Message-ID: <mailman.285.1621807417.3087.python-list@python.org>
References: <CACFDE8bsJe2BMNwsXAiGyxsMxNE+RuENj62GtfEzqodh5O_mMA@mail.gmail.com>
<YKrRLP46qmZ51Nzk@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de U6/Fgge9UBT+PDQ+VWE4iwlNy/FNQUs/KlUB0PflPB8w==
Return-Path: <cameron@cskk.id.au>
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.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'this:': 0.03; 'def': 0.04;
'variable': 0.05; 'subject:python': 0.06; 'lets': 0.07; 'sun,':
0.07; 'effectively': 0.09; 'situations': 0.09; 'cheers,': 0.10;
'import': 0.14; '_are_': 0.16; 'builtin': 0.16; 'cameron': 0.16;
'confusing.': 0.16; 'false.': 0.16; 'from:addr:cs': 0.16;
'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16;
'idiomatic': 0.16; 'inspect': 0.16; 'mentioned,': 0.16; 'message-
id:@cskk.homeip.net': 0.16; 'naming': 0.16; 'received:10.10':
0.16; 'received:l': 0.16; 'runtime': 0.16; 'simpson': 0.16;
'skip:> 10': 0.16; 'wrote:': 0.16; 'python': 0.16; 'name.': 0.20;
'progress': 0.23; 'to:addr:python-list': 0.23; 'lines': 0.24;
'code': 0.24; 'idea': 0.25; 'thinking': 0.26; 'seems': 0.26;
'creating': 0.27; 'bit': 0.28; 'function': 0.28; 'saying': 0.28;
'this.': 0.29; 'local': 0.29; 'header:User-Agent:1': 0.31;
'there': 0.31; 'think': 0.31; 'code,': 0.31; 'wide': 0.31; 'ton':
0.32; 'class': 0.33; 'header:In-Reply-To:1': 0.33; 'able': 0.36;
'cases': 0.37; 'errors': 0.37; 'inside': 0.37; 'going': 0.38;
'use': 0.38; 'called': 0.40; 'example': 0.40; 'built': 0.40;
'common': 0.60; 'normal': 0.60; 'potential': 0.61; 'likely': 0.61;
'them,': 0.63; 'true': 0.63; 'header:Received:6': 0.63;
'received:userid': 0.64; 'your': 0.64; 'similar': 0.66; 'times':
0.66; 'bad': 0.68; 'changing': 0.69; 'global': 0.72; 'little':
0.75; 'tools': 0.75; 'name,': 0.75; 'reasons': 0.75;
'received:172.16': 0.77; '2021': 0.84; 'variety': 0.84;
'activity.': 0.84; 'bars': 0.84; 'discouraged': 0.84; 'lines,':
0.84; 'maintains': 0.84; 'type,': 0.84; 'stopping': 0.91
X-RG-Spam: Unknown
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgeduledrvdejjedguddvvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfupfevtfgpvffgnffuvffttedpqfgfvfenuceurghilhhouhhtmecugedttdenucenucfjughrpeffhffvuffkgggtugfgjggffhesthekredttderjeenucfhrhhomhepvegrmhgvrhhonhcuufhimhhpshhonhcuoegtshestghskhhkrdhiugdrrghuqeenucggtffrrghtthgvrhhnpeektdejheekfedtveevieetkeefledukefgveeltdffteeugefgtddtgeevgedvjeenucfkphepuddruddvledrudektddrieefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghlohepshhovghkrhhishdrfigruhhkrdgtshhkkhdrhhhomhgvihhprdhnvghtpdhinhgvthepuddruddvledrudektddrieefpdhmrghilhhfrhhomhepoegtrghmvghrohhnsegtshhkkhdrihgurdgruhequceuqfffjgepkeeukffvoffkoffgpdhrtghpthhtohepoehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrgheq
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-RG-VS-CLASS: clean
X-Authentication-Info: Submitted using ID cskk@bigpond.com
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CACFDE8bsJe2BMNwsXAiGyxsMxNE+RuENj62GtfEzqodh5O_mMA@mail.gmail.com>
User-Agent: Mutt/2.0.3 (2020-12-04)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <YKrRLP46qmZ51Nzk@cskk.homeip.net>
X-Mailman-Original-References: <CACFDE8bsJe2BMNwsXAiGyxsMxNE+RuENj62GtfEzqodh5O_mMA@mail.gmail.com>
 by: Cameron Simpson - Sun, 23 May 2021 22:03 UTC

On 23May2021 21:02, Stestagg <stestagg@gmail.com> wrote:
>On Sun, 23 May 2021 at 20:37, hw <hw@adminart.net> wrote:
>> I don't know about shadowing.
>
>Shadowing is effectively saying “within this bit of code, (scope) I’m going
>to use an already-used name for my own value”

An example might make this clearer:

x = 1 # global variable

def f(a):
x = a * 2
return x

Inside the function f() the name 'x" shadows the global "x"; references
to "x" are to the function's local vairable. Which is very desireable.

>If I have defeated a whole variable type
>> by naming a variable like a variable type, I would think it is a bad
>> idea for python to allow this without warning.
>
>There are some reasons why allowing this is quite nice. And there’s
>actually a ton of corner cases to consider when thinking about changing the
>rules

As Stestagg has mentioned, there are also tools called linters which
warn you about issues like this. Tools like pyflakes, pylint,
pycodestyle all inspect your code for a wide variety of potential errors
and discouraged habits. Not to mention tools like mypy which do type
validation.

>Interestingly python 3 made this a little bit better by stopping you from
>rebinding (shadowing) a number of built ins, such as True and False.
>
>In your case, I agree that it is super confusing. One thing to learn to
>look out for is if you assign to a name, then use that name on a different
>context, expecting it to be different, then that’s not likely to work as
>you expect.
>
>It seems like a recipie
>> for creating chaos.

The runtime lets you do all sorts of things. Linters and type checkers
exist to help you notice if you're writing such a recipe.

There _are_ times when it is useful to shadow a builtin name. Not being
able to prevents a useful activity.

A common example in my own code is this:

from cs.upd import Upd, print

which shadows the print() builtin. The Upd class maintains status lines
such as progress bars and so forth. It provides a print() function which
withdraws the status lines, runs the builtin print, then restores them,
allowing normal idiomatic use of print() in scripts making use of the
status lines.

Similar situations abound.

Cheers,
Cameron Simpson <cs@cskk.id.au>


devel / comp.lang.python / Re: learning python ...

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor