Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111116

Re: How well do you know Python?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: How well do you know Python?
Date Tue, 5 Jul 2016 19:21:47 +1000
Lines 62
Message-ID <mailman.93.1467710511.2295.python-list@python.org> (permalink)
References <CAPTjJmoZobGYDh8jWDPPWQqoN-gid+-HUp9-dtKX_Vp=BgHc+w@mail.gmail.com> <nlfrhl$bq1$1@ger.gmane.org> <CAPTjJmqn_asKVPpLwTQFWCSXe3w6hxQdXxXnfznZ6ucJO0yrsw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de x14ibOamTxPYdDFyJzA3hghYJkuxOgjXbYFrHxqeuhcA==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'subject:Python': 0.05; 'python3': 0.05; 'classes.': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'differently.': 0.09; 'imports': 0.09; 'integers': 0.09; 'subclass': 0.09; 'python': 0.10; 'explicitly': 0.15; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'old-style': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'wrote:': 0.16; 'circular': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'pass': 0.22; 'sets': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'object,': 0.27; 'looks': 0.29; 'cat': 0.29; 'hash': 0.29; "i'm": 0.30; 'print': 0.30; 'code': 0.30; "i'd": 0.31; 'guess': 0.31; 'run': 0.33; 'class': 0.33; 'foo': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'replace': 0.35; 'but': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'display': 0.37; 'skip:p 20': 0.38; 'sure': 0.39; 'where': 0.40; 'ever': 0.60; 'different': 0.63; 'times': 0.63; 'results.': 0.67; 'jul': 0.72; 'sounds': 0.76; "'1'}": 0.84; "'2'}": 0.84; 'case?': 0.84; 'chrisa': 0.84; 'construct': 0.84; 'otten': 0.84; 'significance': 0.84; 'subject:you': 0.85; 'to:none': 0.91; 'involved.': 0.91; 'subject:know': 0.91; 'why?': 0.91; 'refuse': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=Q7fo63F8EBHEKBohosVOVHiBb4uf/PfhnN5w4x0T9Ls=; b=MwNiRpThIiPe67NM8l6hytTR9p5FBgZN3m217DkKDAEwNbd5gdejLNeoUKIXJMRpNW 3n6PHf6eWqe6JjSUtiujViK/KnQ6k1MxobUWOo3WVexWRqCt0gQ/93iulPFI+vfcnK18 9acRWX+a6djvvbVNWORa3VjpiOVfqf0GQ4WcAOi0Xac8DuhNIVL9/CQLLkhb3oODGSf1 30c3ldHqRgGuW4RmJ8iQ5ojs6f/M15QtMCz8Iz6kIuqItmFQ9TSrsU5bNRB90IezDm2d 0eu1nGYwCt3zKAy+gySNWTKPO/1dwqRVPegEP2lBZ7ikETViijidsI8WgbQvMujibG3y X2QA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=Q7fo63F8EBHEKBohosVOVHiBb4uf/PfhnN5w4x0T9Ls=; b=Akj5jGuCdvK4cXIA06dg/sBRJMXy5k+Qx42X0VXIrv4tpbAYy2e8DI+ai0mDXM4XK8 vX71ziFlveP1734eyLsLl/8SKsxJq9G/l5JsaZu9Y1bl/2hmf6jy/uwVadA+Pixduz61 Cqw0Yayy15yeZUjgGDqroCRZNZax2Nyy8jQWKV8NoayvwUWIHCYOvmcCceaX0WoSWLsx le+H1A6LBiaqkf3EOxIvKtX3XNptL6skqdUn2zZlyXyoBnxErmPtS3x8ktk4NBJcit4L /SkYSWFEXKdUJkB8wkTW2O47BL96Yr6+qF8OJV5z+5vCs9dK9NsEwOEgVpAh5eItb5Qt A8NA==
X-Gm-Message-State ALyK8tL1YM1gOhVCzlw2Zshm3qr4eg8Aj6J13QXhBnHoxQkQYivoSmokeh8q7qi419HcqtX2htE2vG97GbYzmg==
X-Received by 10.28.67.69 with SMTP id q66mr14301401wma.81.1467710508756; Tue, 05 Jul 2016 02:21:48 -0700 (PDT)
In-Reply-To <nlfrhl$bq1$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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 <http://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 <CAPTjJmqn_asKVPpLwTQFWCSXe3w6hxQdXxXnfznZ6ucJO0yrsw@mail.gmail.com>
X-Mailman-Original-References <CAPTjJmoZobGYDh8jWDPPWQqoN-gid+-HUp9-dtKX_Vp=BgHc+w@mail.gmail.com> <nlfrhl$bq1$1@ger.gmane.org>
Xref csiph.com comp.lang.python:111116

Show key headers only | View raw


On Tue, Jul 5, 2016 at 6:36 PM, Peter Otten <__peter__@web.de> wrote:
> What will
>
> $ cat foo.py
> import foo
> class A: pass
> print(isinstance(foo.A(), A))
> $ python -c 'import foo'
> ...
> $ python foo.py
> ...
>
> print?

I refuse to play around with isinstance and old-style classes.
Particularly when circular imports are involved. Run this under Python
3 and/or explicitly subclass object, and then I'd consider it. :)

> It looks like
>
> $ python3 -c 'print({1, 2})'
> {1, 2}
> $ python3 -c 'print({2, 1})'
> {1, 2}
>
> will always print the same output. Can you construct a set from two small
> integers where this is not the case? What's the difference?

Given that the display (iteration) order of sets is arbitrary, I'm not
sure what the significance would ever be, but my guess is that the
display order would be the same for any given set, if constructed this
way. But it sounds as if you know of a set that behaves differently.

> What happens if you replace the ints with strings? Why?

Then hash randomization kicks in, and you can run the exact same line
of code multiple times and get different results. It's a coin toss.

rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'2', '1'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'2', '1'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'2', '1'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'2', '1'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}
rosuav@sikorsky:~$ python3 -c 'print({"1", "2"})'
{'1', '2'}

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: How well do you know Python? Chris Angelico <rosuav@gmail.com> - 2016-07-05 19:21 +1000
  Re: How well do you know Python? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-05 12:51 +0300
    Re: How well do you know Python? Steven D'Aprano <steve@pearwood.info> - 2016-07-05 20:46 +1000
      Re: How well do you know Python? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-07-06 09:19 +0300
    Re: How well do you know Python? Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-05 20:08 -0700

csiph-web