On Sat, Nov 14, 2020 at 04:32:20AM +, Steve Barnes wrote:
> I love the idea of __imported__ but would like to suggest taking it
> even further - why not, rather that a bool for __imported__, have the
> value of it be either None (if __name__ == "__main__")
What if you imported `__main__`?
On Fri, Nov 13, 2020 at 05:59:29AM -0400, André Roberge wrote:
> As a goal of making it even more obvious what the (new) idiom mans, I would
> suggest a variable named __imported__ with the opposite value to what is
> proposed.
What if you import the `__main__` module? What does `__imported__` sa
On Sat, Nov 14, 2020 at 7:56 AM Steven D'Aprano wrote:
> On Fri, Nov 13, 2020 at 05:59:29AM -0400, André Roberge wrote:
>
> > As a goal of making it even more obvious what the (new) idiom mans, I
> would
> > suggest a variable named __imported__ with the opposite value to what is
> > proposed.
>
Here's my take on a Python one liner tool:
https://github.com/hauntsaninja/pyp
It handles automatic intelligent printing, importing and more. It
explicitly aims to feel very much like writing Python, as opposed to a DSL.
In fact, it can even generate a runnable Python script to show you exactly
wh
On Sat, Nov 14, 2020 at 08:10:44AM -0400, André Roberge wrote:
> > What if you import the `__main__` module? What does `__imported__` say
> > now, and how do you check for "running as a script" if `__main__` has
> > imported itself -- or some other module has imported it?
> >
>
> Running a module
Sorry, forgot to use "reply to all"
-- Forwarded message -
From: André Roberge
Date: Sat, Nov 14, 2020 at 11:06 AM
Subject: Re: [Python-ideas] Re: Global flag for whether a module is __main__
To: Steven D'Aprano
On Sat, Nov 14, 2020 at 10:45 AM Steven D'Aprano
wrote:
> On S
The module __main__ is somewhat special. It's there from the very beginning
(so far as I can tell).
$ python3 -c 'import __main__; print(__main__)'
And without importing __main__.
$ python3 -c 'import sys; print(sys.modules["__main__"])'
In light of this, it seems to me that the
From PEP 636 (Structural Pattern Matching):
> Mapping patterns: {"bandwidth": b, "latency": l} captures the
"bandwidth" and "latency" values from a dict. Unlike sequence patterns,
extra keys are ignored.
It surprises me that ignoring extra keys would be the *default*
behavior. This seems unsa
It’s a usability issue; mappings are used quite differently than sequences.
Compare to class patterns rather than sequence patterns.
On Sat, Nov 14, 2020 at 22:04 David Foster wrote:
> From PEP 636 (Structural Pattern Matching):
> > Mapping patterns: {"bandwidth": b, "latency": l} captures the
On 11/14/20 10:17 PM, Guido van Rossum wrote:
It’s a usability issue; mappings are used quite differently than
sequences. Compare to class patterns rather than sequence patterns.
I just found the following explanation from the superceded PEP 622 as to
why extra keys are ignored:
> Extra keys
I’m surprised PEP 635 doesn’t explain this at least as well as 622?
Also in your example 1, the narrower pattern (three keys) should precede
the more general pattern (two). Again, same as class patterns. Or except
clauses (catch RuntimeError *before* Exception).
On Sat, Nov 14, 2020 at 22:49 Davi
David Mertz writes:
> [T]he semantics of __main__ being implicitly defined when scripts
> are run is easy to explain.
Especially to C programmers on Unix. ;-)
To be honest, I think this is pretty icky[1]. IMO, it would be more
consistent with the Python runtime if it were a function is_main()
On Sat, Nov 14, 2020 at 05:22:41PM +, Jonathan Fine wrote:
> The module __main__ is somewhat special. It's there from the very beginning
> (so far as I can tell).
https://docs.python.org/3/library/__main__.html
[...]
> 2. When initializing the built-in __main__ module, set
> __main_
13 matches
Mail list logo