RE: What to use for finding as many syntax errors as possible.

2022-10-11 Thread avi.e.gross
Thanks for a rather detailed explanation of some of what we have been
discussing, Chris. The overall outline is about what I assumed was there but
some of the details were, to put it politely, fuzzy.

I see resemblances to something like how a web page is loaded and operated.
I mean very different but at some level not so much.

I mean a typical web page is read in as HTML with various keyword regions
expected such as  ...  or  ...  with things
often cleanly nested in others. The browser makes nodes galore in some kind
of tree format with an assortment of objects whose attributes or methods
represent aspects of what it sees. The resulting treelike structure has
names like DOM.

To a certain approximation, this tree starts a certain way but is regularly
being manipulated (or perhaps a copy is) as it regularly is looked at to see
how to display it on the screen at the moment based on the current tree
contents and another set of rules in Cascading Style Sheets. But bits and
pieces of JavaScript are also embedded or imported that can read aspects of
the tree (and more) and modify the contents and arrange for all kinds of
asynchronous events when bits of code are invoked such as when you click a
button or hover or when an image finishes loading or every 100 milliseconds.
It can insert new objects into the DOM too. And of course there can be
interactions with restricted local storage as well as with servers and code
running there.

It is quite a mess but in some ways I see analogies. Your program reads a
stream of data and looks for tokens and eventually turns things into a tree
of sorts that represents relationships to a point. Additional structures
eventually happen at run time that let you store collections of references
to variables such as environments or namespaces and the program derived from
the trees makes changes as it goes and in a language like Python can even
possibly change the running program in some ways.

These are not at all the same thing but share a certain set of ideas and
methods and can be very powerful as things interact. In the web case, the
CSS may search for regions with some class or ID or that are the third
element of a bullet list and more, using powerful tools like jQuery, and
make changes. A CSS rule that previously ignored some region as not having a
particular class, might start including it after a JavaScript segment is
aroused while waiting on an event listener for say a mouse hovering over an
area and then changes that part of the DOM (like a node) to be in that
class. Suddenly the area on your screen changes background or whatever the
CSS now dictates. We have multiple systems written in an assortment of
"languages" that complement each other. Some running programs, especially
ones that use asynchronous methods like threads or callbacks on events, such
as a GUI, can effectively do similar things. 

In effect the errors in the web situation have such analogies too as in what
happens if a region of HTML is not well-formed or uses a keyword not
recognized. This becomes even more interesting in XML where anything can be
a keyword and you often need other kinds of files (often also in ML) to
define what the XML can be like and what restrictions it may have such as
can a  have multiple authors but only one optional publication date
and so on. It can be fascinating and highly technical. So I am up for a
challenge of studying anything from early compilers for languages of my
youth to more recent ways including some like what you show.

I have time to kill and this might be more fun than other things, for a
while.

There was a guy around a few years ago who suggested he would create a
system where you could create a series of some kind of configuration files
for ANY language and his system would them compile or run programs for each
and every such language? Was that on this forum? What ever happened to him?

But although what he promised seemed a bit too much, I can see from your
comments below how in some ways a limited amount of that might be done for
some subset of languages which can be parsed and manipulated as described. 

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Monday, October 10, 2022 11:55 PM
To: [email protected]
Subject: Re: What to use for finding as many syntax errors as possible.

On Tue, 11 Oct 2022 at 14:26,  wrote:
>
> I stand corrected Chris, and others, as I pay the sin tax.
>
> Yes, there are many kinds of errors that logically fall into different 
> categories or phases of evaluation of a program and some can be 
> determined by a more static analysis almost on a line by line (or 
> "statement" or "expression", ...)  basis and others need to sort of 
> simulate some things and look back and forth to detect possible 
> incompatibilities and yet others can only be detected at run time and 
> likely way more categories depending on the language.
>
> But when I run the Python interpreter on code, aren't many such phases 
>

Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Roel Schroeven

Op 10/10/2022 om 19:08 schreef Robert Latest via Python-list:

Antoon Pardon wrote:
> I would like a tool that tries to find as many syntax errors as possible 
> in a python file.


I'm puzzled as to when such a tool would be needed. How many syntax errors can
you realistically put into a single Python file before compiling it for the
first time?
I've been following the discussion from a distance and the whole time 
I've been wondering the same thing. Especially when you have unit tests, 
as Antoon said he has, I can't really imagine a situation where you add 
so much code in one go without running it that you introduce a painful 
amount of syntax errors.


My solution would be to use a modern IDE with a linter, possibly with 
style warnings disabled, which will flag syntax errors as soon as you 
type them. Possibly combined with a TDD-style tactic which also prevents 
large amounts of errors (any errors) to build up. But I have the 
impression that any of those doesn't fit in Antoon's workflow.


--
"Peace cannot be kept by force. It can only be achieved through understanding."
-- Albert Einstein

--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Antoon Pardon




Op 10/10/2022 om 19:08 schreef Robert Latest via Python-list:

Antoon Pardon wrote:

I would like a tool that tries to find as many syntax errors as possible
in a python file.

I'm puzzled as to when such a tool would be needed. How many syntax errors can
you realistically put into a single Python file before compiling it for the
first time?


Why are you puzzled? I don't need to make that many syntaxt errors to find
such a tool useful.

--
Antoon Pardon
--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Weatherby,Gerard
Sure it does. They’re optional and not enforced at runtime, but I find them 
useful when writing code in PyCharm:

import os
from os import DirEntry

de : DirEntry
for de in os.scandir('/tmp'):
print(de.name)

de = 7
print(de)

Predeclaring de allows me to do the tab completion thing with DirEntry fields / 
methods

From: Python-list  on 
behalf of [email protected] 
Date: Monday, October 10, 2022 at 10:11 PM
To: [email protected] 
Subject: RE: What to use for finding as many syntax errors as possible.
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Michael,

A reasonable question. Python lets you initialize variables but has no
explicit declarations.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Chris Angelico
On Tue, 11 Oct 2022 at 18:12,  wrote:
>
> Thanks for a rather detailed explanation of some of what we have been
> discussing, Chris. The overall outline is about what I assumed was there but
> some of the details were, to put it politely, fuzzy.
>
> I see resemblances to something like how a web page is loaded and operated.
> I mean very different but at some level not so much.
>
> I mean a typical web page is read in as HTML with various keyword regions
> expected such as  ...  or  ...  with things
> often cleanly nested in others. The browser makes nodes galore in some kind
> of tree format with an assortment of objects whose attributes or methods
> represent aspects of what it sees. The resulting treelike structure has
> names like DOM.

Yes. The basic idea of "tokenize, parse, compile" can be used for
pretty much any language - even English, although its grammar is a bit
more convoluted than most programming languages, with many weird
backward compatibility features! I'll parse your last sentence above:

LETTERS The
SPACE
LETTERS resulting
SPACE
... you get the idea
LETTERS like
SPACE
LETTERS DOM
FULLSTOP # or call this token PERIOD if you're American

Now, we can group those tokens into meaningful sets.

Sentence(type=Statement,
subject=Noun(name="structure", addenda=[
Article(type=The),
Adjective(name="treelike"),
]),
verb=Verb(type=Being, name="has", addenda=[]),
object=Noun(name="name", plural=True, addenda=[
Adjective(phrase=Phrase(verb=Verb(name="like"), object=Noun(name="DOM"),
]),
)

Grammar nerds will probably dispute some of the awful shorthanding I
did here, but I didn't want to devise thousands of AST nodes just for
this :)

> To a certain approximation, this tree starts a certain way but is regularly
> being manipulated (or perhaps a copy is) as it regularly is looked at to see
> how to display it on the screen at the moment based on the current tree
> contents and another set of rules in Cascading Style Sheets.

Yep; the DOM tree is initialized from the HTML (usually - it's
possible to start a fresh tree with no HTML) and then can be
manipulated afterwards.

> These are not at all the same thing but share a certain set of ideas and
> methods and can be very powerful as things interact.

Oh absolutely. That's why there are languages designed to help you
define other languages.

> In effect the errors in the web situation have such analogies too as in what
> happens if a region of HTML is not well-formed or uses a keyword not
> recognized.

And they're horribly horribly messy, due to a few decades of
sloppy HTML programmers and the desire to still display the page even
if things are messed up :) But, again, there's a huge difference
between syntactic errors (like omitting a matching angle bracket) and
semantic errors (a keyword not known, like using  when you
should have used ). In the latter case, you can still build a
DOM tree, but you have an unknown element; in the former case, you
have to guess at what the author meant, just to get anything going at
all.

> There was a guy around a few years ago who suggested he would create a
> system where you could create a series of some kind of configuration files
> for ANY language and his system would them compile or run programs for each
> and every such language? Was that on this forum? What ever happened to him?

That was indeed on this forum, and I have no idea what happened to
him. Maybe he realised that all he'd invented was the Unix shebang?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-11 Thread Antoon Pardon




Op 10/10/2022 om 04:38 schreef [email protected]:

[This is an answer for Peter and can easily be skipped by those who know or
have no wish to.]

Strictly speaking Peter, the word "pipe" may not mean quite something in
Python but other concepts like chaining may be better.

The original use of the word I am used to was at the UNIX shell level where
an in-core data structure called a pipe was used to connect the output of
one process to the inputr of another, sometimes in long chains like:

  cat file1 file2 file3 | grep pattern | ... | lp


Something like that can be done in python with the same kind of syntax:

https://code.activestate.com/recipes/580625-collection-pipeline-in-python/

I have my own python3 module with stuff like that and I find it very usefull.

--
Antoon Pardon
--
https://mail.python.org/mailman/listinfo/python-list


WG: Modify setup window

2022-10-11 Thread evagreven16
 

Hi,

 

this window comes up every time I try to run the code. I am not sure how to
solve it. I tried to repair and modify but it didn´t change anything.

 

Kind regards,

Eva 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: WG: Modify setup window

2022-10-11 Thread Mats Wichmann

On 10/11/22 01:20, [email protected] wrote:
  


Hi,

  


this window comes up every time I try to run the code. I am not sure how to
solve it. I tried to repair and modify but it didn´t change anything.



We don't know what you're asking, because this list doesn't forward 
images. You'll need to explain the problem in words - or select text and 
paste it if possible.


From the subject line, there's a reasonable chance you're rerunning the 
installer, since that seems to come up a lot. That won't get you Python 
itself - it's just doing its job, which is to *manage* the Python 
installation. You can delete the installer once you're done with it, 
that way there's less chance of confusion.  If you're on Windows, try 
using the start menu to find Python. You can pick "Python 3.10 (64-bit)" 
to get the interpreter, or "IDLE (Python 3.10 64-bit)" to get a basic 
IDE  (substitute appropriate version).


--
https://mail.python.org/mailman/listinfo/python-list


Cannot import gdal in jupyter notebook

2022-10-11 Thread Abdul Haseeb Azizi
Hi everyone,
I am new to python and I am trying to utilize this code "from osgeo import 
gdal". I installed python 3.10 and also I installed anaconda3 to solve this 
matter but I could not succeed. When I run that code I get the following error.
---
ModuleNotFoundError   Traceback (most recent call last)
Cell In [1], line 1
> 1 from osgeo import gdal

ModuleNotFoundError: No module named 'osgeo'

I also tried to create anaconda environment and enter the following codes:
conda crate --name pygdal
conda activate pygdal
conda install -c conda-forge gdal

I don't what is the problem. Any help is appreciated to solve this matter.
Looking forward to hear from you.

with regards
Abdul
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: for -- else: what was the motivation?

2022-10-11 Thread avi.e.gross
Anton,

Your example overlaps with the use of generators in Python to do variants of
the same pipeline ideas. 

But is that native python or some extension where "|" has been modified to
mean something other than a form of OR in some places? What module do you
need to load to make that happen?

I think there is a long history in Computing where it may be easier to write
languages that do things in what some call Reverse Polish Notation and you
have languages of the LISP variety, as one example, that suggest code like
(MULT (ADD 1 2) (SUB 5 3)) which gets really annoying for longer
calculations like say the quadratic formula. People (and many programmers
are still people) often prefer some form of infix notation even if the
machine gets re-arranged code that does something like the above. 

Pipes in UNIX had real asynchronous but coordinated meaning and often ran
quite a bit faster as some parts could run while others were doing I/O or
otherwise waiting. BUT it often led to fairly quick and sloppy solutions
that probably could have been done faster within one application without
lots of overhead.

The kind of pipelines we have been talking about, mainly in Python albeit I
mentioned the versions in R, are largely syntactic sugar where often there
is really a single thread of execution which can range from almost
meaningless (as in each part runs to completion and generates lots of data
that is then used by the next stage and eventually intermediates are garbage
collected) to some with a sort of zig-zag approach where smaller chunks of
data are made as various functions are called and yield a partial result and
go to sleep as the next function that called it does something similar.
There may be little or no speedup of the code or even a slowing down.

What would be needed for a better emulation of the UNIX (and later LINUX and
etc.) pipeline is closer to having asynchronous processes running on
multiple cores and yet communicating efficiently. And it need not be linear.
Consider a merge sort as an example where each level subdivides the data and
calls multiple others to recursively work on it and the parent waits for
them all to complete and then merges the results. Some algorithms along
those lines can be run across machines entirely or using machines all over
the internet. You can imagine a chess program that ships all reasonable
possible next moves to others and gets back some analysis of how well each
move is rated based on multiple levels of look-ahead from each child that
farmed out the possible moves to the next level. This kind of approach can
be treelike or a generalized graph and also in higher dimensions. 

An example of what I mean by dimensions is tools that work on XML or just
HTML, like xpath or jquery and have various "dimensions" such as following
in  a direction that chooses based on ID versus a direction based on CLASS
versus a direction based on ancestry, or siblings, or ordinality and many
other such attributes. But enough of that.

Back to your point, the map/filter/reduce kinds of functionality have long
been used in various kinds of functional programming in many languages and
are a way to do pipelining, albeit usually in a more RPN way by nesting
function calls within function calls in a harder-to-read way. If the syntax
change allows a pipe symbol so it can be written infix, that helps
programmers who prefer to think more linearly. 

But since the original topic here was loosely about loops and the silly
choice (there was no great choice) of re-using the ELSE keyword, I note how
commonly we often use loops as in:

for first in iterator:
   for second in iterator:
...

The second (and deeper) loop(s) sort of run faster than the outer ones. But
compare that to how you might write a comprehension like:

[x*y*z for x in range(5) for y in range(5) for z in range(5)]

The above acts sort of like a pipeline as in the first "for" sends 0 to 4 to
the second which passes that along plus another 0..4 to the next one which
passes that plus it's own contribution to the main body which multiplies
them and adds them to a growing list. Of course the problem in the example
is that the main body is in front even as it is I a sense done last, and the
entire construct does the collecting of the results invisibly into a list.
For some people I know, the nested loop version makes more sense and for
some people the comprehension method seems more inline, or at least
condensed. 

My point is perhaps both subtle and blatant. There are tons of IDEAS out
there that superficially have some ways they can be perceived as similar but
ultimately can be seen to differ in many ways and are not the same thing and
often are not interchangeable. A pipeline construct with some kinds of
generators can generate an "infinite" amount of data in theory, but in
practice only an indefinite amount, such as the first N primes with N not
being a constant. Another pipeline that calculates the first million primes
and feeds 

Please remove me from the python list

2022-10-11 Thread evagreven16
 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Thomas Passin

On 10/11/2022 3:10 AM, [email protected] wrote:

I see resemblances to something like how a web page is loaded and operated.
I mean very different but at some level not so much.

I mean a typical web page is read in as HTML with various keyword regions
expected such as  ...  or  ...  with things
often cleanly nested in others. The browser makes nodes galore in some kind
of tree format with an assortment of objects whose attributes or methods
represent aspects of what it sees. The resulting treelike structure has
names like DOM.


To bring things back to the context of the original post, actual web 
browsers are extremely tolerant of HTML syntax errors (including 
incorrect nesting of tags) in the documents they receive.  They usually 
recover silently from errors and are able to display the rest of the 
page.  Usually they manage this correctly.  The OP would like to have a 
parser or checker that could do the same, plus giving an output showing 
where each of the errors happened.


I can imagine such a parser also reporting which lines it had to skip 
before it was able to recover.

--
https://mail.python.org/mailman/listinfo/python-list


[Meeting] Problem-solving, perspectives, programming, and presentation, 19Oct

2022-10-11 Thread dn
With all that "p"-alliteration, it must be a Pppresentation with the 
virtual-Auckland branch of NZPUG!


Wed 19 Oct,
1800 for 1830 ~ 2030 NZDT
0500, 0530, and 0730 UTC+13 resp
by web-conference

Nathan Smith had an 'itch' caused by a problem related to the game of 
Scrabble. Solving a problem with Python, from start-to-finish. A journey 
of challenges, a lesson of not giving in and hopefully a good story all 
round. Featuring, steps forwards, brick-walls, data-structures related 
to words, dictionaries (of both definitions) and Directed Acyclic Word 
Graphs (DAWG - application of DAG graph/network structures). Plus, a 
blind person's perspective on coding through the project, presenting 
overview information on the way a blind person may access code and what 
similarities or differences may crop up.



Creative Coding With Python: Learn how to code simple visuals in Python 
for games, innovative stats, simulations and generative art using a 
flavour of the processing library. This can be incredibly useful for 
teaching programming, visualising concepts and sharpening thinking 
skills. This list's own Abdur-Rahman Janhangeer organises the Python 
Mauritius User Group and FlaskCon* (amongst many other contributions to 
the Python Community including graphic presentation libraries)

* Flask is a very popular web framework


More info about the group, and to RSVP (and thus receive the meeting 
URL) see Meetup group at: 
https://www.meetup.com/nzpug-auckland/events/njdjssydcnbzb/



Regards =dn (Pete and DJ)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot import gdal in jupyter notebook

2022-10-11 Thread Thomas Passin
On Windows, when I tried to install gdal using pip, it needed to compile 
part of it.  I'm not set up with the Microsoft compiler and header 
files, so that failed.  If you are on Windows, you will need to look for 
a binary wheel to install, or install and configure the compiler and 
header files.


On 10/11/2022 11:53 AM, Abdul Haseeb Azizi wrote:

Hi everyone,
I am new to python and I am trying to utilize this code "from osgeo import 
gdal". I installed python 3.10 and also I installed anaconda3 to solve this matter 
but I could not succeed. When I run that code I get the following error.
---
ModuleNotFoundError   Traceback (most recent call last)
Cell In [1], line 1
> 1 from osgeo import gdal

ModuleNotFoundError: No module named 'osgeo'

I also tried to create anaconda environment and enter the following codes:
conda crate --name pygdal
conda activate pygdal
conda install -c conda-forge gdal

I don't what is the problem. Any help is appreciated to solve this matter.
Looking forward to hear from you.

with regards
Abdul


--
https://mail.python.org/mailman/listinfo/python-list


flattening lists

2022-10-11 Thread SquidBits _
Does anyone else think there should be a flatten () function, which just turns 
a multi-dimensional list into a one-dimensional list in the order it's in. e.g.

[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].

I have had to flatten lists quite a few times and it's quite tedious to type 
out. It feels like this should be something built in to python, anyone else 
think this way?
-- 
https://mail.python.org/mailman/listinfo/python-list


[RELEASE] Python versions 3.10.8, 3.9.15, 3.8.15, 3.7.15 now available

2022-10-11 Thread Łukasz Langa
Déjà vu? Right, a month after the expedited releases we are doing the dance 
again. This coincides with the regular scheduled time for 3.10.8 but since we 
accrued a few fixes in 3.7 - 3.9 as well, we’re again releasing all four 
editions at the same time. We’re not promising to continue at this pace 😅

 
Security
 content this time

CVE-2022-40674: bundled libexpat was upgraded from 2.4.7 to 2.4.9 which fixes a 
heap use-after-free vulnerability in function doContent
gh-97616: a fix for a possible buffer overflow in list *= int
gh-97612: a fix for possible shell injection in the example script 
get-remote-certificate.py (this issue originally had a CVE assigned to it, 
which its author withdrew)
gh-96577: a fix for a potential buffer overrun in msilib
 
Python
 3.10.8

Get it here: https://www.python.org/downloads/release/python-3108/ 

As a bugfix release coming a mere month after an out-of-schedule security 
release, 3.10.8 is somewhat smaller compared to 3.9.8 released at the same 
stage of the release cycle a year ago. There’s 151 commits vs 204 in 3.9. It’s 
still a larger release than 3.10.7 at 113 commits. One way or the other, it’s 
worth checking out the change log 
.

 
And
 now for something completely different

Granular convection is a phenomenon where granular material subjected to 
shaking or vibration will exhibit circulation patterns similar to types of 
fluid convection.

It is sometimes described as the Brazil nut effect when the largest particles 
end up on the surface of a granular material containing a mixture of variously 
sized objects; this derives from the example of a typical container of mixed 
nuts, where the largest will be Brazil nuts.

The phenomenon is also known as the muesli effect since it is seen in packets 
of breakfast cereal containing particles of different sizes but similar 
densities, such as muesli mix.

Under experimental conditions, granular convection of variously sized particles 
has been observed forming convection cells similar to fluid motion.

 
We
 hope you enjoy the new releases!

Thanks to all of the many volunteers who help make Python Development and these 
releases possible! Please consider supporting our efforts by volunteering 
yourself or through organization contributions to the Python Software 
Foundation.

Your friendly release team,

Ned Deily @nad 
Steve Dower @steve.dower 
Pablo Galindo Salgado @pablogsal 
Łukasz Langa @ambv 


signature.asc
Description: Message signed with OpenPGP
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread Larry Martell
On Tue, Oct 11, 2022 at 12:48 PM SquidBits _  wrote:
>
> Does anyone else think there should be a flatten () function, which just 
> turns a multi-dimensional list into a one-dimensional list in the order it's 
> in. e.g.
>
> [[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
>
> I have had to flatten lists quite a few times and it's quite tedious to type 
> out. It feels like this should be something built in to python, anyone else 
> think this way?

x = [[1,2,3],[4,5,6,7],[8,9]]
[i for j in x for i in j]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Chris Angelico
On Wed, 12 Oct 2022 at 05:23, Thomas Passin  wrote:
>
> On 10/11/2022 3:10 AM, [email protected] wrote:
> > I see resemblances to something like how a web page is loaded and operated.
> > I mean very different but at some level not so much.
> >
> > I mean a typical web page is read in as HTML with various keyword regions
> > expected such as  ...  or  ...  with things
> > often cleanly nested in others. The browser makes nodes galore in some kind
> > of tree format with an assortment of objects whose attributes or methods
> > represent aspects of what it sees. The resulting treelike structure has
> > names like DOM.
>
> To bring things back to the context of the original post, actual web
> browsers are extremely tolerant of HTML syntax errors (including
> incorrect nesting of tags) in the documents they receive.  They usually
> recover silently from errors and are able to display the rest of the
> page.  Usually they manage this correctly.

Having had to debug tiny errors in HTML pages that resulted in
extremely weird behaviour, I'm not sure that I agree that they usually
manage correctly. Fundamentally, they guess, and guesswork is never
reliable.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread David Lowry-Duda

On Tue, Oct 11, 2022 at 12:32:23PM -0700, SquidBits _ wrote:

Does anyone else think there should be a flatten () function, which just turns 
a multi-dimensional list into a one-dimensional list in the order it's in. e.g.

[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].

I have had to flatten lists quite a few times and it's quite tedious to 
type out. It feels like this should be something built in to python, 
anyone else think this way?


I typically don't mind things that are one liners, especially if the one 
liner is a list comprehension.



def flatten1(inlist):
return [l for sublist in inlist for l in sublist]

givenlist = [[1, 2, 3], [4, 5, 6, 7], [8, 9]]
print(flatten1(givenlist))

def flatten2(inlist):
return sum(inlist, [])

print(flatten2(givenlist))


Looking up "flatten" in python's source reveals the (not at all obvious 
to me as I don't use chain) alternative



import itertools
def flatten3(inlist):
return list(itertools.chain.from_iterable)

print(flatten3(givenlist))


I notice that "flatten" appears many times in python's source. I didn't 
check how many times it's used with the same meaning, though.


- DLD
--
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-11 Thread dn

On 10/10/2022 16.19, [email protected] wrote:

I won't reply to everything Dave says and especially not the parts I fully 
agree with.

I think in many situations in life there is no ONE way to do things so most 
advice is heuristic at best and many exceptions may exist depending on your 
chosen approach. As such, I do not really think in PYTHON when writing code but 
an amalgam of many languages with all kinds of ways of doing things and then 
zoom in on how to do it in the current language be it Python or R or JavaScript 
and so on. Yes, I am in some sense focused but also open, just as in Human 
languages I may mostly be thinking in English but also sometimes see words and 
phrases pop into my mind from other languages that mean about the same thing 
and then filter it out to focus on whichever language I am supposed to be using 
at the time.


Given that we can both remember programming last-century, this 
surprised. (or may have misunderstood!)



If we think, in German, of some parting words for an older friend 
departing on a long trip, and translate word-for-word into English we 
might come out with: "May God pickle you".


There is a second step, which is to examine the 'solution' in terms of 
its expression (how the communication will be received), and thus the 
more-correct English expression would be: "May God preserve you"!


The two p-words are sufficiently-similar in meaning to appear 
synonymous, when examined in-isolation. However, that first expression 
would at least bemuse an (only) English-speaker, and quite possibly confuse!



One of the problems which 'appeared' when programmers were first given 
direct-access to the computer, eg time-sharing mini-computers; and which 
persists to this day, is "the rush to code". Indeed there are (still) 
some 'managers' who think that unless a programmer is writing code (s)he 
isn't 'working' - but we're only interested in our own behavior.


Accordingly, "design" and "development".

Back-when, some lecturers insisted that we first create a flow-chart or 
a pseudo-code solution for an assignment - BEFORE we coded in COBOL, 
FORTRAN, or whatever. In many ways, because we were learning the 
programming-language, most felt it very difficult to draw a flow-chart 
that didn't merely look like FORTRAN.
(to make that worse (for ourselves) I suspect many of us performed the 
latter first, and then ...) Many of us will have felt this some sort of 
academic-exercise or even 'a nuisance', but there was 'method in their 
madness'!



Relating back to the comment (above): when *designing* a 
solution/flow-charting/pseudo-code, an "amalgam" of programming 
constructs and human-language expressions will indeed add richness, 
opportunity, and alternatives. All serving to amplify analytic and 
design skill.


Conversely, when *coding*, the skill comes from employing the (specific, 
programming) language to best advantage. At which time, one's 
JS-knowledge is almost irrelevant, because the task is to convert a 
design outline or planned-solution, into Python.

(idiomatic, pythonic, efficient, readable, ...)
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread Thomas Passin

Is this what you usually do?

l1 = [[1,2,3],[4,5,6,7],[8,9]]
l2 = []
for lz in l1:
 l2.extend(lz)

print(l2)  # [1,2,3,4,5,6,7,8,9]

Not all that "tedious", perhaps... I tend to accumulate little utilities 
like this in a file and point to it with a .pth file.  Of course, you 
have to remember to include it if you share your program with someone else.


On 10/11/2022 3:32 PM, SquidBits _ wrote:

Does anyone else think there should be a flatten () function, which just turns 
a multi-dimensional list into a one-dimensional list in the order it's in. e.g.

[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].

I have had to flatten lists quite a few times and it's quite tedious to type 
out. It feels like this should be something built in to python, anyone else 
think this way?


--
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot import gdal in jupyter notebook

2022-10-11 Thread MRAB

On 2022-10-11 20:38, Thomas Passin wrote:

On Windows, when I tried to install gdal using pip, it needed to compile
part of it.  I'm not set up with the Microsoft compiler and header
files, so that failed.  If you are on Windows, you will need to look for
a binary wheel to install, or install and configure the compiler and
header files.


The PyPI page at https://pypi.org/project/GDAL/ has this:

"""
Conda
GDAL can be quite complex to build and install, particularly on Windows 
and MacOS. Pre built binaries are provided for the conda system:


https://docs.conda.io/en/latest/

By the conda-forge project:

https://conda-forge.org/
"""


On 10/11/2022 11:53 AM, Abdul Haseeb Azizi wrote:

Hi everyone,
I am new to python and I am trying to utilize this code "from osgeo import 
gdal". I installed python 3.10 and also I installed anaconda3 to solve this matter 
but I could not succeed. When I run that code I get the following error.
---
ModuleNotFoundError   Traceback (most recent call last)
Cell In [1], line 1
> 1 from osgeo import gdal

ModuleNotFoundError: No module named 'osgeo'

I also tried to create anaconda environment and enter the following codes:
conda crate --name pygdal
conda activate pygdal
conda install -c conda-forge gdal

I don't what is the problem. Any help is appreciated to solve this matter.
Looking forward to hear from you.

with regards
Abdul




--
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread dn

On 12/10/2022 08.32, SquidBits _ wrote:

Does anyone else think there should be a flatten () function, which just turns 
a multi-dimensional list into a one-dimensional list in the order it's in. e.g.

[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].

I have had to flatten lists quite a few times and it's quite tedious to type 
out. It feels like this should be something built in to python, anyone else 
think this way?



There is a flatten function!

First though, are we ONLY talking about 'flattening' a 2D list (per 
example, above) or might the requirements extend to multiple-dimensions? 
The solutions vary accordingly!



Two-dimensions:
(don't think this method previously-mentioned, but very readable)

>>> l = [[1,2,3],[4,5,6,7],[8,9]]
>>> flattened = list()
>>> for element in l:
... flattened += element
...
>>> flattened
[1, 2, 3, 4, 5, 6, 7, 8, 9]

(NB if "l" were three-dimensional, "flattened" would become 2D)


Multi-dimensional:
Reach for itertools:
(https://docs.python.org/3/library/itertools.html#itertools.chain)

>>> import itertools as it
>>> iter_flattened = it.chain( *l )
>>> list( iter_flattened )
[1, 2, 3, 4, 5, 6, 7, 8, 9]


Wrt "I have had to flatten lists quite a few times and it's quite 
tedious to type out.", isn't this a "code-smell"?


Certainly motivation to generalise and write a solution as a function. 
Do it once, and do it right!


Hence advice elsewhere to build a list-processing utility-library.

On the other hand, has it already been done for us?


An exercise for the reader:
is reaching for itertools 'over-kill' in 2D?
- speed-comparison between loading the itertools library and then 
employing the speedy method, or using a (built-in) for-loop at 
Python-speed with no import-overhead?
(results will vary significantly according to len( l ), but do they 
remain consistently in-favor or one method or the other?)

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Thomas Passin

On 10/11/2022 4:00 PM, Chris Angelico wrote:

On Wed, 12 Oct 2022 at 05:23, Thomas Passin  wrote:


On 10/11/2022 3:10 AM, [email protected] wrote:

I see resemblances to something like how a web page is loaded and operated.
I mean very different but at some level not so much.

I mean a typical web page is read in as HTML with various keyword regions
expected such as  ...  or  ...  with things
often cleanly nested in others. The browser makes nodes galore in some kind
of tree format with an assortment of objects whose attributes or methods
represent aspects of what it sees. The resulting treelike structure has
names like DOM.


To bring things back to the context of the original post, actual web
browsers are extremely tolerant of HTML syntax errors (including
incorrect nesting of tags) in the documents they receive.  They usually
recover silently from errors and are able to display the rest of the
page.  Usually they manage this correctly.


Having had to debug tiny errors in HTML pages that resulted in
extremely weird behaviour, I'm not sure that I agree that they usually
manage correctly. Fundamentally, they guess, and guesswork is never
reliable.


Still, browsers generally do a very decent job of recovery, even though 
perfection isn't possible.  The OP wants to get help with problems in 
his files even if it isn't perfect, and I think that's reasonable to 
wish for.  The link to a post about the lezer parser in a recent message 
on this thread is partly about how a real, practical parser can do some 
error correction in mid-flight, for the purposes of a programming editor 
(as opposed to one that has to build a correct program).


--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Thomas Passin

On 10/11/2022 5:09 PM, Thomas Passin wrote:

The OP wants to get help with problems in 
his files even if it isn't perfect, and I think that's reasonable to 
wish for.  The link to a post about the lezer parser in a recent message 
on this thread is partly about how a real, practical parser can do some 
error correction in mid-flight, for the purposes of a programming editor 
(as opposed to one that has to build a correct program).


One editor that seems to do what the OP wants is Visual Studio Code.  It 
will mark apparent errors - not just syntax errors - not limited to one 
per page.  Sometimes it can even suggest corrections.  I personally 
dislike the visual clutter the markings impose, but I imagine I could 
get used to it.


VSC uses a Microsoft system they call "PyLance" - see

https://devblogs.microsoft.com/python/announcing-pylance-fast-feature-rich-language-support-for-python-in-visual-studio-code/

Of course, you don't get something complex for free, and in this case 
the cost is having to run a separate server to do all this analysis on 
the fly.  However, VSC handles all of that behind the scenes so you 
don't have to.


Personally, I'd most likely go for a decent programming editor that you 
can set up to run a program on your file, use that to run a checker, 
like pyflakes for instance, and run that from time to time.  You could 
run it when you save a file.  Even if it only showed one error at a 
time, it would make quick work of correcting mistakes.  And it wouldn't 
need to trigger an entire tool chain each time.


My editor of choice for setting up helper "tools" like this on Windows 
is Editplus (non-free but cheap and very worth it), and I have both 
py_compile and pyflakes set up this way in it.  However, as I mentioned 
in an earlier post, the Leo Editor 
(https://github.com/leo-editor/leo-editor) does this for you 
automatically when you save, so it's very convenient.  That's what I 
mostly work in.

--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Cameron Simpson

On 11Oct2022 17:45, Thomas Passin  wrote:
Personally, I'd most likely go for a decent programming editor that you 
can set up to run a program on your file, use that to run a checker, 
like pyflakes for instance, and run that from time to time.  You could 
run it when you save a file.  Even if it only showed one error at a 
time, it would make quick work of correcting mistakes.  And it wouldn't 
need to trigger an entire tool chain each time.


Aye.

I've got my editor (vim) configured to run an autoformatter on my code 
when I save (this can be turned off, and parse errors prevent any 
reformatting).


Linters I run by hand from the adjacent shell window, via a small script 
which runs my preferred linters with their preferred options.


My current workplace triggers the CI workflow when you push commits 
upstream, and you can make branch names which do not trigger the CI 
stuff.


So there's a decent separation between saving (and testing or locally 
running the dev code) from the CI cycle.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-11 Thread Grant Edwards
On 2022-10-11,   wrote:

> But is that native python or some extension where "|" has been modified to
> mean something other than a form of OR in some places?

The latter.

> What module do you need to load to make that happen?

The provided link is for a page that shows the module and explains the
usage.



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread MRAB

On 2022-10-11 21:09, Stefan Ram wrote:

[email protected] (Stefan Ram) writes:

. I never understood "yield from" until just now, when I was
thinking, "Maybe this could be the piece that fits in here!"


   PS: If I'm starting to think about it: Having succeeded
   after using it by trial in one case does not mean that I
   have understood it!



This:

yield from iterable

is equivalent to:

for item in iterable:
yield item

but is more efficient.

That's really all you need to know!

--
https://mail.python.org/mailman/listinfo/python-list


How to fix Python error, The term '.../python.exe' is not recognized as the name of a cmdlet, function, script file, or operable program, in VS Code?

2022-10-11 Thread LouisAden Capellupo via Python-list
 Hi! I've just downloaded and installed Python 3.10.7 (64-bit) for Windows 
10 from python.org. I'm quite new but, I've already downloaded and installed 
Visual Studio Code as well. I have included the two paths for python under User 
Variables. 
C:\Users\It'sMeLil'Loui\AppData\Local\Programs\Python\Python310\Scripts\, and 
C:\Users\It'sMeLil'Loui\AppData\Local\Programs\Python\Python310\. I verified 
that python is recognized in the Command Prompt and PowerShell and installed 
the necessary extensions for python in Visual Studio Code. I created a test 
python file in the directory of D:\Projects\Python\Test\HelloWorld.py, and 
opened it in Visual Studio Code. I also restarted my laptop after all of this. 
Under the arrow used to run the code, I clicked "Run Code" (since I have Code 
Runner by Jun Han installed), and it worked just fine, displaying the output in 
the terminal.

Code:

print("Hello, world.")
input("Press Enter to continue...")

Output in Terminal when using Code Runner:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\Projects\Python\Test> python -u "d:\Projects\Python\Test\HelloWorld.py"
Hello, world.
Press Enter to continue...
PS D:\Projects\Python\Test> 
However, under the arrow to run code, when I click "Run Python File", I get 
this error message:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Output in Terminal when normally running it:

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS D:\Projects\Python\Test> & 
C:/Users/It'sMeLil'Loui/AppData/Local/Programs/Python/Python310/python.exe 
d:/Projects/Python/Test/HelloWorld.py
& : The term 
'C:/Users/ItsMeLilLoui/AppData/Local/Programs/Python/Python310/python.exe' is 
not recognized as the name of a cmdlet, function, script 
file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At line:1 char:3
+ & C:/Users/It'sMeLil'Loui/AppData/Local/Programs/Python/Python310/pyt ...
+   ~~~
    + CategoryInfo  : ObjectNotFound: 
(C:/Users/ItsMeL...n310/python.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS D:\Projects\Python\Test>

 So basically, I get, "The term '...\python.exe' is not recognized as the 
name of a cmdlet, function, script, file, or operable program... At line: 1 
char: 3." It works the first way I showed with Code Runner, but the second or 
original way doesn't work. What if I don't want to use Code Runner? Any help in 
fixing this problem would be greatly appreciated. Sorry if certain things are 
unclear as this is my first time using Python.

Thanks, 
LouisAden


Sent from Mail for Windows

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to fix Python error, The term '.../python.exe' is not recognized as the name of a cmdlet, function, script file, or operable program, in VS Code?

2022-10-11 Thread Eryk Sun
On 10/11/22, LouisAden Capellupo via Python-list  wrote:
> Variables. 
> C:\Users\It'sMeLil'Loui\AppData\Local\Programs\Python\Python310\Scripts\,
> and C:\Users\It'sMeLil'Loui\AppData\Local\Programs\Python\Python310\.

I suggest that you switch to a user account that doesn't have single
quotes in the name. Using a name that contains single quotes is asking
for trouble. In most command-line shells, which includes PowerShell
(but not CMD), a literal (verbatim) string is contained by single
quotes. The shell usually consumes the quote character if it's not
escaped. See the following sections of the PowerShell documentation:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2#single-quoted-strings

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2#including-quote-characters-in-a-string
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: flattening lists

2022-10-11 Thread Dan Stromberg
On Tue, Oct 11, 2022 at 12:48 PM SquidBits _  wrote:

> Does anyone else think there should be a flatten () function, which just
> turns a multi-dimensional list into a one-dimensional list in the order
> it's in. e.g.
>
> [[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].
>
> I have had to flatten lists quite a few times and it's quite tedious to
> type out. It feels like this should be something built in to python, anyone
> else think this way?
>

I think the usual argument against putting something like this in the
standard library (I hope it won't be built in), is that there are many ways
to define "flatten".  That is, should it only go one level deep?   All the
way to the bottom?  n levels deep?  Should it do something special with
lists, dicts, tuples, sets?

This looks like a nice URL on the topic:
https://www.pythonpool.com/flatten-list-python/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-11 Thread Axy via Python-list



On 10/10/2022 06:15, [email protected] wrote:

Chris, a short(er) answer to your addition below.

I did not at first share your perception but maybe do now. If the argument
was that ELSE and other constructs like FINALLY or CATCH are horrible
because they follow other code and important things should be first, that is
a silly argument.


You know, sometimes I'm of the same opinion, especially looking at 
"defer" efforts in Go.


However, I wouldn't judge that in terms of mental capabilities. Every 
construct has some initial rationale but sometimes even best practices 
eventually become notorious. There are many point of views to every 
feature but in general features aren't divine and worth revising even 
this looks disparaging.


Axy.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Help, PyCharm fails to recognize my tab setting...See attached picture of the code.

2022-10-11 Thread dn

On 11/10/2022 10.48, Kevin M. Wilson via Python-list wrote:

C:\Users\kevin\PycharmProjects\Myfuturevalue\venv\Scripts\python.exe 
C:\Users\kevin\PycharmProjects\Myfuturevalue\FutureValueCal.py   File 
"C:\Users\kevin\PycharmProjects\Myfuturevalue\FutureValueCal.py", line 31    elif 
(years > 50.0) or (years < 1.0) :    ^IndentationError: expected an indented block after 
'if' statement on line 29
Process finished with exit code 1


Indentation depends upon what went before, as well as what is being 
indented 'right now'.


As you can see from the reproduction of the OP (above), any comment on 
formatting would be a guess.


Please copy-paste the entire block of the if-statement and its nested 
suites...

(this list will not pass-along images)
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list