Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


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

SubjectAuthor
o Re: learning python ...Michael Torrie

1
Re: learning python ...

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: torr...@gmail.com (Michael Torrie)
Newsgroups: comp.lang.python
Subject: Re: learning python ...
Date: Tue, 25 May 2021 08:37:22 -0600
Lines: 83
Message-ID: <mailman.335.1621953448.3087.python-list@python.org>
References: <7dc017ca-c0a3-c66e-8b7c-ceea1c786c73@adminart.net>
<YKty/XyqeCBH9rcH@cskk.homeip.net>
<2ba5b89e-df8c-df0f-5a18-57852aa3a8bb@adminart.net>
<aa786fa5-4e27-7781-87f6-e21da8c64d9d@gmail.com>
<f5f53e28-57c9-eeb5-bf3e-a82ce9b2167b@adminart.net>
<9b826a97-e4f5-535c-0574-959da921e2e5@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de zOn3qmNuiKP+qe8uUckb3Qm1agXCJVVQK+i+cxABvUPQ==
Return-Path: <torriem@gmail.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=gmail.com header.i=@gmail.com header.b=txfLsvar;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(which': 0.04; 'def':
0.04; 'parameter': 0.05; "python's": 0.05; 'string': 0.05;
'variable': 0.05; 'subject:python': 0.06; 'binding': 0.07;
'formal': 0.07; 'mechanism': 0.07; 'expression': 0.09;
'situations': 0.09; 'string,': 0.09; 'though.': 0.09; 'values.':
0.09; 'arguments': 0.16; 'changed.': 0.16; 'digress.': 0.16;
'easier.': 0.16; 'extracts': 0.16; 'implements': 0.16; 'integer':
0.16; 'lambda': 0.16; 'languages.': 0.16; 'mechanics': 0.16;
'object."': 0.16; 'passing.': 0.16; 'received:209.85.215': 0.16;
'something.': 0.16; 'though?': 0.16; 'variable,': 0.16;
'variable.': 0.16; 'wrote:': 0.16; 'memory': 0.16; 'values': 0.16;
'python': 0.16; 'instead': 0.17; 'it?': 0.18; 'message-
id:@gmail.com': 0.19; 'all,': 0.19; 'pm,': 0.20; 'goes': 0.22;
"i've": 0.22; 'language': 0.22; 'languages': 0.23; 'object': 0.23;
'to:addr:python-list': 0.23; 'discussion': 0.24; 'code': 0.24;
'written': 0.24; 'cannot': 0.24; 'thinking': 0.26; 'seems': 0.26;
'brought': 0.27; 'course.': 0.27; 'else': 0.27; 'old': 0.28;
'done': 0.28; "isn't": 0.29; 'header:User-Agent:1': 0.31; 'it,':
0.31; 'there': 0.31; 'think': 0.31; 'but': 0.31; "doesn't": 0.32;
'objects': 0.32; 'passes': 0.32; 'header:In-Reply-To:1': 0.33;
'same': 0.34; 'received:google.com': 0.34; 'example,': 0.35;
'bar': 0.35; 'words': 0.35; 'from:addr:gmail.com': 0.35; 'table':
0.37; 'changes': 0.37; 'received:192.168': 0.37; 'way': 0.37;
"that's": 0.37; 'change': 0.37; 'received:209.85': 0.38; 'those':
0.38; "it's": 0.38; 'something': 0.38; 'received:209': 0.38;
'use': 0.38; 'does': 0.38; 'reason': 0.40; 'whether': 0.40;
'called': 0.40; 'reference': 0.61; 'lot': 0.62; 'them,': 0.63;
"you'd": 0.63; 'pass': 0.64; 'your': 0.64; 'becomes': 0.65;
'demand': 0.68; 'exactly': 0.69; 'matter': 0.69; 'changing': 0.69;
'implications': 0.69; 'visible': 0.69; 'analysis': 0.70;
'compared': 0.71; 'stand': 0.71; 'content': 0.72; 'yes': 0.77;
'reference.': 0.81; 'practical': 0.84; 'collector': 0.84;
'distinction': 0.84; 'eventually': 0.84; 'garbage': 0.84;
'locals': 0.84; 'strings': 0.84; 'weird': 0.84; 'truth': 0.86;
'placing': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=subject:to:references:from:message-id:date:user-agent:mime-version
:in-reply-to:content-language:content-transfer-encoding;
bh=Aicc541WESyvnL9I6fzGt0MLHklmg2tIOtgw2rAgHu8=;
b=txfLsvarDiALRjjW/A28JqsTKu0rKZQyIEaOV6jzSmDY/MsbNSgQYn0AQHPcpj64/X
s6n0NJI5Le9yhBZVnlvfwj3Hu92e0QWK9a5/HIg4t4OZdQNcNI/gPr13xfSOPr8tHfK3
JgQKS69Lpq2pOFN9fkIyNTwnT8ttyRp/grXxF74lAxlAQm3dJ+x+M3mcLcEMRl8WBGvL
fJo8GRfskPs4KcxJWUd5s+2zjif9MpJ4UB7tXKsy3O3+KnLsmJhWv6Lxlg4NyS7+bode
GcKiE7ftzgUIbEaLCK/b3yLKFeu/8GgTeIneVfvJfDNh9xnDOm12+TEWUl0R8bJomgIE
ULnQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:subject:to:references:from:message-id:date
:user-agent:mime-version:in-reply-to:content-language
:content-transfer-encoding;
bh=Aicc541WESyvnL9I6fzGt0MLHklmg2tIOtgw2rAgHu8=;
b=sy2yRQ0yEiAhuaBN0tHJhwyFRKgxCT6SjaurxZc/hc+c5WPCZo5xqmcpf9t7PHcT5h
YTgTw2gRk/3j/IjZRycgCJRcl/t6UFCATLpW19qyIqcsh+O19TtKTKq9CB8NxiPec0CF
SQlgGIVR4pOx7WAsSNkfy+zDNXvVVzzLR8ANcAi8ZAXOKnlPjCbcAaK4e+MYZALIes1k
DSZ9SY/rsbSWryYDRhUeU50ovQvbxYhy4mEp0YA/AR91uTd8XjpeFKJhcsdHoeaF9daA
vJaGU65CEJ/ZcnqXKf8GLZGN70q2TgXvNqDcSqlGJAfbshKxZ/AB0j2DLgxQ6HtgFMyq
KZjA==
X-Gm-Message-State: AOAM532gal78k9/RuchQ17PGGAtqnxAvp3k0wATb0lblonGP2QnfhVWN
6Ra/rKJVCJ+5HDev2HYNgeOp91Regyc=
X-Google-Smtp-Source: ABdhPJxFlCPbXaryI1qN4XfiOe8dio60TnDummTN4YUPi0Te5/BsnQtcHucAGoX9KcwdjLNOOzPQRA==
X-Received: by 2002:a63:f651:: with SMTP id u17mr19099183pgj.300.1621953444459;
Tue, 25 May 2021 07:37:24 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.7.0
In-Reply-To: <f5f53e28-57c9-eeb5-bf3e-a82ce9b2167b@adminart.net>
Content-Language: en-US
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: <9b826a97-e4f5-535c-0574-959da921e2e5@gmail.com>
X-Mailman-Original-References: <7dc017ca-c0a3-c66e-8b7c-ceea1c786c73@adminart.net>
<YKty/XyqeCBH9rcH@cskk.homeip.net>
<2ba5b89e-df8c-df0f-5a18-57852aa3a8bb@adminart.net>
<aa786fa5-4e27-7781-87f6-e21da8c64d9d@gmail.com>
<f5f53e28-57c9-eeb5-bf3e-a82ce9b2167b@adminart.net>
 by: Michael Torrie - Tue, 25 May 2021 14:37 UTC

On 5/24/21 9:53 PM, hw wrote:
> That seems like an important distinction. I've always been thinking of
> variables that get something assigned to them, not as something that is
> being assigned to something.

Your thinking is not incorrect. Assignment is how you set a variable to
something. For the most part the details of how the variables work
doesn't matter all that much. An expression in Python works about the
same as it does in other languages. Where it becomes important to
understand the name binding mechanism is in situations like you found
yourself. What happens, for example, when you do something like
float=5? Hence the discussion about name shadowing.

The reason I brought up the distinction of how python's variables work
compared to a language like C is because under the hood Python's
assignment doesn't "alter" the variable. Assignment replaces it
entirely in the name space. This is consistent with a more formal
definition of variable found in lambda calculus. I learned in uni there
are some formal languages that don't allow any variable names to be
rebound at all, which makes formal proofs and analysis easier. But I
digress.

There are also implications for parameter passing. All of this is in
the language reference documentation of course. But even still there
have been many arguments about whether Python is pass by value or pass
by reference. Consider:

def foo(bar):
bar += 1

a = 5
foo(a)
print(a)

or

def frob(foo):
foo.append('bar')

a = [ 'one', 'two' ]
frob(a)
print(a)

The truth is Python might be said to "pass by object." In other words
when you call a function, it goes through the names table and extracts
references to all the objects involves with the arguments and passes
those objects to the function. Objects that are mutable can be changed
by a function, and those changes are visible in the code that called it,
since both caller and callee are dealing with the *same object*, just by
different names (aliases). Strings and other values like ints are
*immutable*. They cannot be changed. Assignment will not change them,
only overwrite the names in the locals table.

> I would think of it as assigning a string to a variable and then
> changing the content of the variable by assigning something else to the
> same variable. When variables are typeless, it doesn't matter if a
> string or an integer is assigned to one (which is weird but can be very
> useful).

Yes that's how it's done in many lower-level languages. Python does not
assign that way, though. It's not clearing the contents and placing
something else there. Instead assignment overwrites the binding in the
name table, connecting the name to the new string object that was
created. The old object is dereferenced, and the garbage collector will
eventually remove it.

> It seems much more practical to assign different strings to the same
> variable rather than assigning a different variable to each string, or
> to assign a string to a variable and then to assign an integer to it.

How exactly would one overwrite an integer in memory with a string,
though? You would have to either preallocate a lot of memory for it in
case something large were to be written to the variable, or you'd
allocate it on the heap on demand and use a reference for it. Under the
hood, Python does the second. How else would you do it?

> Isn't that what variables are for?

In the formal sense, variables are just names that stand in for values.
Don't get too hung up on the mechanics of how one implements that as
being a formal part of the definition, and don't think that one
language's implementation of variables is the only way to do it.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor