Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To downgrade the human mind is bad theology. -- C. K. Chesterton


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

SubjectAuthor
o Re: learning python ...Chris Angelico

1
Re: learning python ...

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: learning python ...
Date: Mon, 24 May 2021 17:52:20 +1000
Lines: 160
Message-ID: <mailman.292.1621842753.3087.python-list@python.org>
References: <143d4163-faf5-3794-095d-f28e85a18c58@adminart.net>
<s8e3bn$105v$1@ciao.gmane.io>
<6730da2c-1440-ad59-7494-b5ce5b5bccae@adminart.net>
<CACFDE8bsJe2BMNwsXAiGyxsMxNE+RuENj62GtfEzqodh5O_mMA@mail.gmail.com>
<5cec7f52-a66b-608c-4816-a3d8816658b2@adminart.net>
<CAPTjJmpOXQ0m4-=uty96t+K9VCvZ_7UWdzPOKYw-vocRFq50eQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de vJ9HjbqOhMHZEa7GyiCPvwuAYBgspyFIQ+t3zTl/1Qgg==
Return-Path: <rosuav@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=eQl0d//7;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python?': 0.03; '(which':
0.04; 'traceback': 0.04; '(most': 0.05; 'last):': 0.05;
'variable': 0.05; 'subject:python': 0.06; 'debug': 0.07; 'float':
0.07; 'programmer': 0.07; 'sun,': 0.07; 'that?': 0.07; 'thing.':
0.07; 'used.': 0.07; '18,': 0.09; 'apparently': 0.09;
'effectively': 0.09; 'int': 0.09; 'prints': 0.09;
'received:209.85.166.47': 0.09; 'received:mail-
io1-f47.google.com': 0.09; 'situations': 0.09; 'smaller': 0.09;
'typeerror:': 0.09; "can't": 0.14; '"too': 0.16; '18.': 0.16;
'assuming': 0.16; 'chrisa': 0.16; 'especially,': 0.16; 'feature.':
0.16; 'float,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'int)': 0.16; 'programmer.': 0.16; 'result.':
0.16; 'reuse': 0.16; 'something.': 0.16; 'tuple': 0.16; 'typing':
0.16; 'word,': 0.16; 'wrote:': 0.16; 'that.': 0.16; 'python':
0.16; 'instead': 0.17; 'figure': 0.18; 'all,': 0.19; 'bug': 0.20;
'name.': 0.20; 'pm,': 0.20; 'way.': 0.20; 'programming': 0.21;
'python,': 0.21; 'language': 0.22; 'version': 0.22; 'exception':
0.23; "what's": 0.23; 'anyone': 0.23; 'to:addr:python-list': 0.23;
'code': 0.24; '>>>': 0.26; 'section': 0.26; 'seems': 0.26;
'tried': 0.26; 'library': 0.27; 'wrong': 0.27; 'asked': 0.27;
'bit': 0.28; "i'll": 0.28; 'output': 0.28; 'saying': 0.28;
'error': 0.28; "isn't": 0.29; 'this.': 0.29; '(and': 0.30; 'it,':
0.31; 'there': 0.31; 'code,': 0.31; 'printed': 0.31; 'stuff':
0.31; 'but': 0.31; "doesn't": 0.32; "i'm": 0.32; '"",': 0.32;
'difference': 0.32; 'do.': 0.32; 'intend': 0.32; 'realize': 0.32;
'to:name:python': 0.32; 'message-id:@mail.gmail.com': 0.33;
'program': 0.33; 'using': 0.33; 'printing': 0.33;
'received:209.85.166': 0.33; 'header:In-Reply-To:1': 0.33;
'received:google.com': 0.34; 'example,': 0.35; 'following': 0.35;
'running': 0.35; 'from:addr:gmail.com': 0.35; 'trying': 0.36;
'table': 0.37; 'way': 0.37; '(or': 0.37; 'really': 0.37;
'received:209.85': 0.38; 'file': 0.38; "it's": 0.38; 'something':
0.38; 'received:209': 0.38; 'going': 0.38; 'use': 0.38; 'does':
0.38; 'put': 0.39; 'hi,': 0.39; 'whether': 0.40; 'called': 0.40;
'days': 0.61; 'entire': 0.61; 'likely': 0.61; 'simply': 0.62;
'choose': 0.62; 'rules': 0.63; 'types': 0.63; 'skip:# 10': 0.64;
'your': 0.64; 'his': 0.65; 'spend': 0.65; 'look': 0.66; 'right':
0.66; 'carry': 0.68; 'exactly': 0.69; 'perfectly': 0.69; 'above,':
0.71; 'production': 0.71; 'easy': 0.75; 'little': 0.75; 'happens':
0.75; 'name,': 0.75; 'database': 0.77; 'supposed': 0.77; '2021':
0.84; 'dangerous': 0.84; '10:02': 0.84; 'absolutely': 0.84;
'creepy': 0.84; 'highlights': 0.84; 'proving': 0.84; 'type,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=XOD7LZoOekfvmCRkxZLq6q+4r04LRSnBB6mxozQC+yc=;
b=eQl0d//7ojltQ5LH3hM0/fPEttvmiW5XDHc+fE/71d4CB/xJrvCeFWkSa6/wzbXH3e
doaEB4GlQsanZw6MX3K0zs5JBGhXcI19GP/RKzN2v/r7u26dFAD/vWMrPymwVoUJFzMJ
PQZH++bGV8eT8VobdWNQbZCii5qNSdmbYVGgIzzmJ7sK8swfLxARzK3345Q0QPiycPnn
C7QXwl17v0TBSsq2Bs1dUlDRvNQ/4AbsG9BKrVDbVpGLIQr7U3Ya86kKWEmmAWgLUNxk
LHXmDOd0Vkkfqw+E45Br996aooJUHwieyIJGW08RIGBLCtKBJBx5S1WoaUahNhM3MDeQ
YXLQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=XOD7LZoOekfvmCRkxZLq6q+4r04LRSnBB6mxozQC+yc=;
b=jqkDTYhjvJcvAtKP2W0RGkT8/Dxxq5oLVp22cWrPqA9XBMiuYf+JFs4yQTNHNEy6Un
bCcbsBW4scYtKkkh6PhTK4n0MmAa4ZNa9+Dys5BhzOPjHog2fBOvDV5djb+JH6qXxM2K
vK0KA1BMbJ24id3ddFv9UjVdTCF7YjkAVWpIMl2laTzu09Bu+0rX0iQsaGk7BBGWEX8B
LQtMwGnfl04ZBCycK68SzVjiFMAFNbUOzTunf8wf2nxQ3S06xnGU2DpX34Yj1a06EUOE
Le3tFQP2q/mC+ggkfVAqBeak1NxUucRzdm2KmeDa6eVx9yrxIZsS3zc4it1f53VuANGm
fFHg==
X-Gm-Message-State: AOAM531rmd0LIEbpxlgRyJMNYpho0fWnpYJ3OIsyU3ZWxqXWHq0YZ6bo
5K4BB24l0AMIT/7YsXp21Y/s+6ri7u2bWQtWJhKX+55Ls5Q=
X-Google-Smtp-Source: ABdhPJwhMxY9H08M5ewSf227sR0x0cDoTefzJwhRHEvqpIhERVPn2NKODaELXcWuQ9/GNAfhUYInmnAAgK0zDENoGvs=
X-Received: by 2002:a02:cac6:: with SMTP id f6mr23590415jap.142.1621842750864;
Mon, 24 May 2021 00:52:30 -0700 (PDT)
In-Reply-To: <5cec7f52-a66b-608c-4816-a3d8816658b2@adminart.net>
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: <CAPTjJmpOXQ0m4-=uty96t+K9VCvZ_7UWdzPOKYw-vocRFq50eQ@mail.gmail.com>
X-Mailman-Original-References: <143d4163-faf5-3794-095d-f28e85a18c58@adminart.net>
<s8e3bn$105v$1@ciao.gmane.io>
<6730da2c-1440-ad59-7494-b5ce5b5bccae@adminart.net>
<CACFDE8bsJe2BMNwsXAiGyxsMxNE+RuENj62GtfEzqodh5O_mMA@mail.gmail.com>
<5cec7f52-a66b-608c-4816-a3d8816658b2@adminart.net>
 by: Chris Angelico - Mon, 24 May 2021 07:52 UTC

On Mon, May 24, 2021 at 3:25 PM hw <hw@adminart.net> wrote:
>
> On 5/23/21 10:02 PM, Stestagg wrote:
> >
> >
> > On Sun, 23 May 2021 at 20:37, hw <hw@adminart.net
> > <mailto:hw@adminart.net>> wrote:
> >
> > On 5/23/21 7:28 PM, Peter Otten wrote:
> > > On 23/05/2021 06:37, hw wrote:
> > >>
> > >> Hi,
> > >>
> > >> I'm starting to learn python and have made a little example program
> > >> following a tutorial[1] I'm attaching.
> > >>
> > >> Running it, I'm getting:
> > >>
> > >>
> > >> Traceback (most recent call last):
> > >> File "[...]/hworld.py", line 18, in <module>
> > >> print(isinstance(int, float))
> > >> TypeError: isinstance() arg 2 must be a type or tuple of types
> > >>
> > >>
> > >> I would understand to get an error message in line 5 but not in 18.
> > >> Is this a bug or a feature?
> > >
> > > It is a bug in your code (which you don't provide). Did you
> > assign some
> > > value to float, e. g.:
> > >
> > > >>> float = 42.0
> > > >>> isinstance(int, float)
> > > Traceback (most recent call last):
> > > File "<pyshell#313>", line 1, in <module>
> > > isinstance(int, float)
> > > TypeError: isinstance() arg 2 must be a type or tuple of types
> > >
> > > If you do not shadow the built-in you should get
> > >
> > > >>> isinstance(int, float)
> > > False
> > >
> >
> > Apparently the attachment was stripped from my message. I'll put a
> > smaller version directly into this message instead of an attachment:
> >
> >
> > #!/usr/bin/python
> >
> > print("world!")
> >
> > int = 17
> > print("world", int)
> >
> > float = 6.670
> > print("world", float)
> >
> > foo = 0
> > print(type(int))
> > print(type(float))
> > print(type(foo))
> >
> > print(isinstance(foo, str))
> > print(isinstance(int, float))
> > print(isinstance(float, float))
> >
> >
> > 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”
>
> That should give at least a warning.

No, it shouldn't, because it's a deliberate feature. The entire point
of scoping rules - whether you're in C, Python, REXX, or any other
language - is to *allow* you to use a name for what you intend it to
be.

Does C give you a warning if you create a function-local variable
called "printf"? No, and it shouldn't. Does any other language
complain if you use its scoping rules to reuse a name? Nope. Does
Python? As above, no.

> It seems dangerous and seems to show that python is too unfinished to be
> used. For all I know, it makes it easy to, for example, drop a whole
> table in a database because something was shadowed without warning.

No, it doesn't. It simply allows you to use a name the way you choose
to. And if you want to learn how to use Python, stop insulting it -
calling it "too unfinished to be used" is a tad unfair to a language
that has been used in production code for three decades. All you're
really doing is proving the Blub Paradox - look it up.

> I can imagine that there can be all kinds of situations in which
> something like that happens, and you can spend hours or days trying to
> figure out what's wrong and may never find it.

What happens more often with me is that I'm typing out a perfectly
reasonable section of code, and my editor highlights some word, and I
realize that I'm shadowing some obscure standard library name or
something. (And then I usually just carry on, because there's no way
that it's going to matter.)

> > 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.
>
> Then why doesn't give it at least a warning?

Because there's no difference between shadowing a standard library
name and shadowing your own name. And there's absolutely nothing wrong
with that.

> There is even no indication from the output from the program before it
> aborts with an error message that something might be wrong: For
> 'type(float)', it prints "<class 'float'>" just like it does for int.
> How is anyone supposed to debug stuff like that?

You debug it by noticing that you changed the value of "float" between
where you printed it and where you tried to call it. Or changed the
value of "type", either way. You debug it by printing things out
*right where the exception is happening*. You debug it, especially, by
*reading the exception traceback* to figure out where your code isn't
doing the right thing.

This is what it is to be a programmer.

> Why doesn't print(type(float)) give an error message after the variable
> type was already defeated (or prints something else)? What is it
> actually printing?

It's calling type, whatever that is, with the value of float, whatever
that is, and then printing out the result. This is exactly what you
asked it to do.

> Things get creepy when a programming language makes it so that the
> programmer can't figure out anymore how a result produced by his program
> has come about.

Learn the language before you blame the language for this.

All you're doing is insulting Python, insulting all of us for using
it, moaning, complaining, and all in all, revealing your own
shortcomings.

If you want to become a better programmer, start by assuming that you
are an imperfect programmer, rather than assuming that Python should
be "better".

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor