Re: Behavior of the for-else construct

2022-03-05 Thread Peter J. Holzer
On 2022-03-05 00:25:44 +0100, Peter J. Holzer wrote:
> On 2022-03-04 11:34:07 +1100, Chris Angelico wrote:
> > What I'm hearing is that there are, broadly speaking, two types of
> > programmers [1]:
> > 
> > 1) Those who think about "for-else" as a search tool and perfectly
> > understand how it behaves
> > 2) Those who have an incorrect idea about what for-else is supposed to
> > do, don't understand it, and don't like it.
> 
> 3) Those who understand what it does und don't even find it*s syntax
> very confusing, yet only very rarely find it useful.
> 
> I have probably used it a handful of times in 8 years of Python
> programming. Coincidentally, I think I used it just this week - but I
> can't find it any more which probably means that it was either in a
> throwaway script or I have since rewritten the code.

Just found it again. Not yet committed, and I may still end up rewriting
it again before turning in the pull request, but for now it's the
simplest solution for the problem.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-05 Thread Rob Cliffe via Python-list




On 05/03/2022 01:15, Cameron Simpson wrote:


I sort of wish it had both "used break" and "did not use break"
branches, a bit like try/except/else.

And "zero iterations".
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Cpython: when to incref before insertdict

2022-03-05 Thread Marco Sulla
I noticed that some functions inside dictobject.c that call insertdict
or PyDict_SetItem do an incref of key and value before the call, and a
decref after it. An example is dict_merge. Other functions, such as
_PyDict_FromKeys, don't do an incref before.

When an incref of key and value is needed before insertdict and when
is not? And why is an incref needed?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Syslog working on OSX Monterey

2022-03-05 Thread Barry Scott



> On 4 Mar 2022, at 21:23, Peter J. Holzer  wrote:
> 
> On 2022-02-28 22:05:05 +, Barry Scott wrote:
>> On 28 Feb 2022, at 21:41, Peter J. Holzer  wrote:
>>> On 2022-02-27 22:16:54 +, Barry wrote:
 I have always assumed that if I want a logger syslog handler that I would 
 have
 to implement it myself. So far I have code that uses syslog directly and 
 have
 not written that code yet.
>>> 
>>> What do you mean by using syslog directly? The syslog(3) library
>>> function also just sends messages to a "syslog listener" (more commonly
>>> called a syslog daemon) - at least on any unix-like system I'm familiar
>>> with (which doesn't include MacOS). It will, however, always use the
>>> *local* syslog daemon - AFAIK there is no standard way to open a remote
>>> connection (many syslog daemons can be configured to forward messages to
>>> a remote server, however).
>> 
>> I'm re-reading the code to check on what I'm seeing. (Its been a long
>> time since I last look deeply at this code).
>> 
>> You can write to /dev/log if you pass that to
>> SysLogHandler(address='/dev/log'), but the default is to use a socket
>> to talk to a network listener on localhost:514. There are no deamons
>> listening on port 514 on my Fedora systems or mac OS.
> 
> If you are saying that SysLogHandler should use a system specific
> default (e.g. "/dev/log" on Linux) instead of UDP port 514 everywhere, I
> agree 99 % (the remaining 1 % is my contrarian alter ego arguing that
> that's really the distribution maintainer's job since a Linux
> distribution might use some other socket).
> 
> If you are saying it should use the libc syslog routines, I disagree for
> at least two reasons: a) they are OS specific, b) you can't configure the
> destination. So that would remove useful functionality.
> 
> In any case it seems strange to me that you want to rewrite it just to
> avoid passing a single parameter to the constructor (or - more likely -
> adding a single line to a config file).

What I am used to is a setup where programs use syslog() to log and
a dameon like rsyslog is responsible for routing the logs to local files
and/or remote systems. On a modern linux I think the route is
syslog() -> journald. And you can have syslog() -> journald -> rsyslogd.

Using the syslog() function means that any platform/distro details are
hidden from the user of syslog() and as is the case of macOS it
"just works". (I assume, not checked, that the write to the socket does not work
because Apple is not implementing the syslog protocol from the RFC).

> 
>> What you do not see used in the SyslogHandler() is the import syslog
>> and hence its nor using openlog() etc from syslog API.
> 
> For good reasons. The C syslog API is missing important functionality.

What are you think about being missing? Just curious.

As an aside if I had the need to log into a system log mechanism I'd be
looking to use the jounald API so that I can use structured logging on linux
systems.

Barry


> 
>hp
> 
> -- 
>   _  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | h...@hjp.at |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Barry Scott


> On 4 Mar 2022, at 13:03, Hartmut Goebel  wrote:
> 
> Hi,
> 
> How can I make installing a virtual environment honor DESTDIR? How can I 
> install a virtual environment in $(DESTDIR)$(PREFIX), which behaves as being 
> set-up in $(PREFIX)? (Of course, this virtual environment can not be used. My 
> aim is to ship it as part of a rpm package)
> 
> In Makefiles is good practice to honor DESTDIR in the "install" target, like 
> this
> 
> install:
> install -t $(DESTDIR)$(PREFIX)/bin build/bin/my-tool
> 
> Now when running
> 
> python3 -m venv $(DESTDIR)$(PREFIX)
> 
> all paths in this virtual environment refer to $(DESTDIR)$(PREFIX) instead of 
> just $$(PREFIX)
> 
> Any ideas?
> 
> 
> Background:
> 
> More about DESTDIR: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
> 
> Following Redhat's commendations, I want to install my (somewhat complex) 
> software into /opt/my-software. To make it easier for users to use the 
> software, my idea was to setup a virtual environment in /opt/my-software. 
> Thus users can easily use /opt/my-software/bin/python and have the library 
> provided by my-software available. My Software also includes some scripts, 
> which will also reside in /opt/my-software/bin and refer to 
> /opt/my-software/bin/python. This will avoid to require users to set up 
> PYTHONPATH when thy want to use MY Software.

If you are packaging the code then I do not see the need to use a venv at all.

Have the RPM install all the pythone code and dependencies and also install a 
short script that
sets up PYTHONPATH, LD_LIBRARY_PATH, etc and execs the python3 .py.

Note: you usually cannot use pip when building an RPM with mock as the network 
is disabled inside the build for
security reasons.

I package two of my projects this was for Fedora as RPMs.

Barry


> 
> 
> -- 
> Schönen Gruß
> Hartmut Goebel
> Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
> Information Security Management, Security Governance, Secure Software 
> Development
> 
> Goebel Consult, Landshut
> http://www.goebel-consult.de
> 
> Blog: https://www.goe-con.de/blog/why-a-pki-is-barely-trustworthy
> Kolumne: 
> https://www.goe-con.de/hartmut-goebel/cissp-gefluester/2011-11-in-troja-nichts-neues
>  
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Marco Sulla
On Sat, 5 Mar 2022 at 17:36, Barry Scott  wrote:
> Note: you usually cannot use pip when building an RPM with mock as the 
> network is disabled inside the build for
> security reasons.

Can't he previously download the packages and run pip on the local packages?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Barry Scott



> On 5 Mar 2022, at 16:59, Marco Sulla  wrote:
> 
> On Sat, 5 Mar 2022 at 17:36, Barry Scott  wrote:
>> Note: you usually cannot use pip when building an RPM with mock as the 
>> network is disabled inside the build for
>> security reasons.
> 
> Can't he previously download the packages and run pip on the local packages?
> 

I guess that can work. In this case I would install with pip install --user and 
move the
files out of .local into an appropriate place in /opt/.

At work I package a lot of packages for python and what we do is get the 
sources, 
review them then turn them into an RPM using the setup.py to do the file 
placement.

We do not use the wheels from PyPI ever. They may not match the claimed sources.
Which I have seen a few times; the version on PyPI can contain helpful patches 
that
are not in the sources.

Barry


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


looking for a freelancer to update a python NNTP script

2022-03-05 Thread RS Wood


I'm looking for a mid-level python programmer to help me with a python
script that accesses Usenet. I've got a non-working 2.7 script that
needs a little more attention than just running 2to3 on it.  Estimated
level of effort: about 2 hours or less.

If interested please send me an email at moc.liamg@71orifaz (spell that
backwards - rudimentary anti-spam measure). Tell me your hourly rate or
fixed price for the work and explain your qualifications.  (Use email,
don't post here).

Payment would be through Paypal - half up front, half on
completion. Selection will be made on the basis of both qualifications
and cost - I'm not just looking for the lowest bidder.

I'm posting the offer here because to test the script you need to have
some understanding of Usenet and working Usenet access, obviously.

I'll respond to this post when the job is filled.

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


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Kirill Ratkin

Hi,

As far I know there is tool rpmvenv 
(https://github.com/kevinconway/rpmvenv).


Try it, maybe ot helps.

04.03.2022 16:03, Hartmut Goebel wrote:

Hi,

How can I make installing a virtual environment honor DESTDIR? How can 
I install a virtual environment in $(DESTDIR)$(PREFIX), which behaves 
as being set-up in $(PREFIX)? (Of course, this virtual environment can 
not be used. My aim is to ship it as part of a rpm package)


In Makefiles is good practice to honor DESTDIR in the "install" 
target, like this


install:
    install -t $(DESTDIR)$(PREFIX)/bin build/bin/my-tool

Now when running

    python3 -m venv $(DESTDIR)$(PREFIX)

all paths in this virtual environment refer to $(DESTDIR)$(PREFIX) 
instead of just $$(PREFIX)


Any ideas?


Background:

More about DESTDIR: 
https://www.gnu.org/prep/standards/html_node/DESTDIR.html


Following Redhat's commendations, I want to install my (somewhat 
complex) software into /opt/my-software. To make it easier for users 
to use the software, my idea was to setup a virtual environment in 
/opt/my-software. Thus users can easily use 
/opt/my-software/bin/python and have the library provided by 
my-software available. My Software also includes some scripts, which 
will also reside in /opt/my-software/bin and refer to 
/opt/my-software/bin/python. This will avoid to require users to set 
up PYTHONPATH when thy want to use MY Software.




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


Re: Behavior of the for-else construct

2022-03-05 Thread Avi Gross via Python-list
Since we still seem to be dreaming, I wonder when someone will suggest using 
some variation of the new match statement. All you need is for the for loop 
(and possibly other such constructs) to return some kind of status that can be 
matched

match (for var in something:
... ) :
  case break():
  case skipped():
  case did(1):
  case didall():

  case crash():
  case _ :

As always, the above is not even pseudocode. But my point is there are 
languages I have seen that are built on such pattern matching and provide 
abilities to do a multi-way branching as long as you are very careful about the 
order you place the things to match.

If not understood, the above function calls are meant to suggest something. For 
argument's sake, the for loop could return a non-negative number that shows the 
number of iterations done completely or even partially. It could also return 
various out-of-band (perhaps negative) values. So if it is skipped you get a 
zero or a value matching what my make-believe function skipped() returns. If 
the loop just ran once, it matched did(1).  If it completed without breaks, it 
didall() and if it broke out, or crashed it matches something. I hope the idea 
comes across, even if you disagree with my indenting or exact method.

Constructs like the above do in theory allow some really complex matching and 
often in a way easier to understand than having endless clauses added below the 
for group. 

But as repeatedly stated, Python currently has no concept of returning a value 
directly from a for loop or lots of other things. A brand new language that 
superficially resembled python could be designed but that is a rather 
formidable task.

And where does it end? I mean you could set it up so the language allows you to 
return an invisible (meaning it does not print unless you ask for it) object 
among many possible objects. 

The simplest object may be an integer or perhaps an object of a class with a 
name like counter so you matched against counter(1) or against counter(n) if 
you want to capture the exact number for further processing. Various other 
object types might be returned including one that tells you about a break and 
also on which iteration it broke out of or even the value of the  item it was 
looping on at the moment. If this starts looking a bit like how errors can be 
created and propagated, that is no coincidence.

But the above also might come with serious overhead. And for many, it would not 
be seen as necessary. I will say that by allowing the match statement in the 
current form, the door has been opened wide for all kinds of potential 
enhancements. Older code and features may be left alone, but newer code is now 
free to do esoteric things. If I rewrote my call to the loop into a function 
that takes arguments including the data I want to have used and internally does 
the for loop while setting various variables that capture all kinds of info 
needed, then it potentially could return one of a series of objects you could 
pattern match against to your heart's content. A call to the function could be 
used in a match statement vaguely as in my hand-waving above. And of course you 
can use unpacking to make all kinds of compound patterns if done carefully.

I think my part of this endless conversation may have gone a bit beyond far 
enough and I await some new topics.


-Original Message-
From: Rob Cliffe via Python-list 
To: python-list@python.org
Sent: Sat, Mar 5, 2022 7:15 am
Subject: Re: Behavior of the for-else construct




On 05/03/2022 01:15, Cameron Simpson wrote:
>
> I sort of wish it had both "used break" and "did not use break"
> branches, a bit like try/except/else.
And "zero iterations".
Rob Cliffe

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

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


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Hartmut Goebel

Am 05.03.22 um 17:34 schrieb Barry Scott:

Have the RPM install all the pythone code and dependencies and also install a 
short script that
sets up PYTHONPATH, LD_LIBRARY_PATH, etc and execs the python3 .py.


The scripts are already created by entry-points. So basically this means 
to reinvent the wheel. Or did I miss something?


--
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
Information Security Management, Security Governance, Secure Software 
Development


Goebel Consult, Landshut
http://www.goebel-consult.de

Blog: 
https://www.goe-con.de/blog/eilt-petition-auf-weact-gegen-vds-jetzt-unterschreiben 

Kolumne: 
https://www.goe-con.de/hartmut-goebel/cissp-gefluester/2011-11-in-troja-nichts-neues 


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


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Barry Scott


> On 5 Mar 2022, at 19:56, Hartmut Goebel  wrote:
> 
> Am 05.03.22 um 17:34 schrieb Barry Scott:
>> Have the RPM install all the pythone code and dependencies and also install 
>> a short script that
>> sets up PYTHONPATH, LD_LIBRARY_PATH, etc and execs the python3 .py.
> The scripts are already created by entry-points. So basically this means to 
> reinvent the wheel. Or did I miss something?
> 
Are you saying that the only thing you want from the venv is a script that sets 
up PYTHONPATH?

That a trivia thing to write and far easier then battling with packaging a venv 
I'd expect.

Did I miss something?

Barry

> -- 
> Schönen Gruß 
> Hartmut Goebel 
> Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
> Information Security Management, Security Governance, Secure Software 
> Development
> Goebel Consult, Landshut 
> http://www.goebel-consult.de 
> Blog: 
> https://www.goe-con.de/blog/eilt-petition-auf-weact-gegen-vds-jetzt-unterschreiben
>  
> 
>  
> Kolumne: 
> https://www.goe-con.de/hartmut-goebel/cissp-gefluester/2011-11-in-troja-nichts-neues
>  
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-05 Thread Dennis Lee Bieber
On Sat, 5 Mar 2022 12:39:36 -0600, "Michael F. Stemper"
 declaimed the following:

>... especially Pascal, which was probably bigger in Germany and Austria
>in the 1980s than was C.

Pascal also defined alternate representations (per Jensen&Wirth) for
some of those (and I don't recall ever seeing a system that actually had an
up-arrow character -- and selecting one in character map doesn't help, my
client doesn't render it).

direct  alternate
?   ^ or @  
[   (.
]   .)
{   (*
}   *)

I'll admit... (. is a clumsy sequence to type in place of [ (RH ring
finger to top-row  on modern keyboards followed by RH ring finger
to bottom-row .), but it is a sequence any terminal mapping to a common
/typewriter/ keyboard should have available. (* isn't quite as clumsy (RH
ring finger to top-row  followed by RH middle finger to top-row
).

More fun is had when doing APL without a dedicated APL keyboard 
(Though Xerox Sigma APL also had plain text alternatives: $RHO for example)


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-05 Thread Michael F. Stemper

On 04/03/2022 18.11, Peter J. Holzer wrote:

On 2022-03-04 23:47:09 +, Avi Gross via Python-list wrote:

I am not sure a reply is needed, Peter, and what you say is true. But
as you point out, when using a German keyboard, I would  already have
a way to enter symbols like ä, ö, ü and ß and no reason not to include
them in variable names and so on if UNICODE is being used properly. I
can use my last name in German notation as a variable in Python now:

Groß = 144
Groß / 12
12.0


Yes, I'm using umlauts occasionally in variable names in Python, and
I've also used Greek characters and others.

But in Python I CAN use them. I DON'T HAVE to.

That's a big difference.

Characters like [] or {} are a part of Python's syntax. You can't avoid
using them. If you can't type them, you can't write Python. If it is
awkward to enter them (like having to type Alt-91 or pasting them from a
character table) it is painful to write programs.

German keyboards aquired an AltGr key and the ability to type these
characters in the mid to late 1980's. Presumably because those
characters were common in C and other programming languages


... especially Pascal, which was probably bigger in Germany and Austria
in the 1980s than was C.

--
Michael F. Stemper
Psalm 94:3-6
--
https://mail.python.org/mailman/listinfo/python-list


Re: virtualenv and make DESTDIR=

2022-03-05 Thread Barry Scott


> On 5 Mar 2022, at 19:56, Hartmut Goebel  wrote:
> 
> Am 05.03.22 um 17:34 schrieb Barry Scott:
>> Have the RPM install all the pythone code and dependencies and also install 
>> a short script that
>> sets up PYTHONPATH, LD_LIBRARY_PATH, etc and execs the python3 .py.
> The scripts are already created by entry-points. So basically this means to 
> reinvent the wheel. Or did I miss something?
> 

 For example I assume you need something like this:

#!/bin/bash
export PYTHONPATH=/opt//lib
exec /usr/bin/python3 /opt//lib/main.py "$@"

I'm assuming you put all the python code into /opt//lib
and any runnable command into /opt//bin

Barry

> -- 
> Schönen Gruß 
> Hartmut Goebel 
> Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer
> Information Security Management, Security Governance, Secure Software 
> Development
> Goebel Consult, Landshut 
> http://www.goebel-consult.de 
> Blog: 
> https://www.goe-con.de/blog/eilt-petition-auf-weact-gegen-vds-jetzt-unterschreiben
>  
> 
>  
> Kolumne: 
> https://www.goe-con.de/hartmut-goebel/cissp-gefluester/2011-11-in-troja-nichts-neues
>  
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-05 Thread Avi Gross via Python-list
I am not sure how we end up conversing about PASCAL on a Python forum. But it 
is worth considering how people educated in aspects of Computer Science often 
come from somewhat different background and how it flavors what they do now.

I paid no attention to where PASCAL was being used other than I did much of my 
grad school work in PASCAL in the early 80's including my thesis being a 
document that could be typeset or run from the same file ;-)

And my first job in the field also was doing programming in PASCAL. At the time 
it seemed to be a new and upcoming language with lots of nifty features. It 
seemed to have so many ways it was an improvement on languages I had been using 
including BASIC and Fortran and versions of LISP. So it was a tad surprising 
when my next job at Bell Labs focused on C (and later C++) as well as a large 
array of utilities and small languages in the UNIX world. PASCAL was nowhere to 
be seen nor others that arrived to take over the world like Modula and Ada, and 
yet didn't. It depends where you are and on your perspective, and perhaps it 
survived in places like Europe and often has been enhanced. We have mentioned 
how things like Fortran keep evolving and, in any case, tons of the code we use 
in aspects of Python and especially some add-in modules, is from libraries of 
well-honed   libraries of functions written in Fortran or C or I am sure in 
some cases even assembler languages.

I wonder if some languages of the future may supersede languages like Python 
but retain aspects of them in a similar way? As a hobby, I study lots of 
languages to see if they add anything or are likely to take over. Some seem to 
really be focused on a company like Microsoft or Google using it for their own 
purposes and others who wish to play in their arena may have to go along to 
operate there. Others seem to be the kind of things academics invent to play 
with various ideas. So will SCALA or GO or RUST become major players or will 
they wither away? Will languages that make major changes that make older 
software not compatible, think Python or PERL as examples, end up stronger or 
... motivate some to abandon their projects and switch to a new 
language/system/paradigm?

I do a lot of data manipulation in an assortment of languages including 
multiple methods within a language. I can sometimes see how a person asking for 
features or writing programs has been influenced by earlier experiences. 
Database people who started with a relational database and mainly used some 
dialect of SQL, may face some problems in their own way and think making lots 
of smaller tables in third normal form and constantly doing all kinds of table 
merges is the natural way to do things. Those who start doing things using 
Python or R may view things quite differently and often see ways to do things 
gradually and in a pipelined method and not do what is seen as expensive 
operations like some kinds of merge. I am not saying everyone does things in a 
stereotypical way, just that people learn tools and methods and it may show.

Given how much faster some things have become, even hybrid programmers may play 
games. Yes, you can issue SQL to load data from a database into your Python or 
R programs but some issue a very basic command and then massage it locally 
while others do most of the processing in the SQL component so that less is 
dragged in. Some habits persist even after circumstances change.

I have little against PASCAL and have not looked at how it has evolved but 
found it a very limiting language after a while. But I find most languages 
somewhat limited and now think they should be. What makes a language great for 
me is if it does not try to be too complete but provides a way to extend it so 
people can come up with their own ways to do more complex things, including 
various ways to do graphics or statistical analyses and so on, as sort of 
add-ons which become little languages or worlds grafted on when needed and 
ignored when not.

Python qualifies albeit it is already too bloated! LOL!


Avi

Palm: 3rd digit from the right, vertically.


-Original Message-
From: Michael F. Stemper 
To: python-list@python.org
Sent: Sat, Mar 5, 2022 1:39 pm
Subject: Re: Behavior of the for-else construct


On 04/03/2022 18.11, Peter J. Holzer wrote:

> On 2022-03-04 23:47:09 +, Avi Gross via Python-list wrote:

>> I am not sure a reply is needed, Peter, and what you say is true. But

>> as you point out, when using a German keyboard, I would  already have

>> a way to enter symbols like ä, ö, ü and ß and no reason not to include

>> them in variable names and so on if UNICODE is being used properly. I

>> can use my last name in German notation as a variable in Python now:

>>

>> Groß = 144

>> Groß / 12

>> 12.0

> 

> Yes, I'm using umlauts occasionally in variable names in Python, and

> I've also used Greek characters and others.

> 

> But in Python I CAN use them. I DON'T HAVE to.

> 

> T

Re: Behavior of the for-else construct

2022-03-05 Thread Cameron Simpson
On 05Mar2022 17:48, Avi Gross  wrote:
>Since we still seem to be dreaming, I wonder when someone will suggest using 
>some variation of the new match statement.

Ugh :-)

But...

What if break were implemented with an exception, like StopIteration but 
for interruption instead of stop? And for-loops were an implied 
try/except:

for ...
except BrokenIteration: # <-- implied
  pass

and you could go:

for ...
except BrokenIteration:
  ... a break occurred
else:
  ... a break did not occur

and, indeed,

for ...
except BrokenIteration:
  ... a break occurred
except StopIteration as stopped:
  print("I did", stopped.count, "iterations")
else:
  # not reached because of the "except StopIteration" above
  ... a break did not occur

if we wanted to cover off the count iterations wish item.

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


Help: Unable to find IDLE folder inside the Python Lib folder

2022-03-05 Thread Deji Olofinboba via Python-list

Dear Python officer,
Please I am new to programming. I have justinstalled the python 3.10.2. After 
the installation, I was able to locate thePython Shell but unable to locate 
IDLE despite checking it before downloading in the python installation folder. 
I also reinstalled Python and checked IDLE; still the IDLE is still missing. 
Please. explain to me how I can retrieve the python IDLE.
Thank You,

 

Deji Olofinboba 

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


Re: Help: Unable to find IDLE folder inside the Python Lib folder

2022-03-05 Thread MRAB

On 2022-03-05 20:36, Deji Olofinboba via Python-list wrote:


Dear Python officer,
Please I am new to programming. I have justinstalled the python 3.10.2. After 
the installation, I was able to locate thePython Shell but unable to locate 
IDLE despite checking it before downloading in the python installation folder. 
I also reinstalled Python and checked IDLE; still the IDLE is still missing. 
Please. explain to me how I can retrieve the python IDLE.
Thank You,


If you're on Windows 10, type "idle" into the search box on the taskbar.
Alternatively, look in python_folder\Lib\idlelib for idle.bat if you're 
on an older version of Windows.

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


Re: Behavior of the for-else construct

2022-03-05 Thread Dennis Lee Bieber
On Sat, 5 Mar 2022 21:40:08 + (UTC), Avi Gross 
declaimed the following:

>I am not sure how we end up conversing about PASCAL on a Python forum. But it 
>is worth considering how people educated in aspects of Computer Science often 
>come from somewhat different background and how it flavors what they do now.
>
You'd prefer REBOL, perhaps? 

REXX at least has some structure to it 

NB: Pascal has, like Ada, always been a  name -- not
like the origins of COBOL, FORTRAN, BASIC, et al.

>I paid no attention to where PASCAL was being used other than I did much of my 
>grad school work in PASCAL in the early 80's including my thesis being a 
>document that could be typeset or run from the same file ;-)
>
Very early? The common versions were probably UCSD (running on UCSD
P-System); or a port of the P-4 compiler (which had been published in book
form) -- maybe a "tinyPascal" (integer only I suspect). Radio Shack did
provide Alcor Pascal for the TRS-80.

Later, you might have encountered TurboPascal -- which bore little
resemblance to a Jensen&Wirth Pascal. 

J&W was one-program<>one-file (no link libraries, no "include" files as
I recall); very limited math functions if one is trying for scientific
applications (sin, cos, arctan were the trig functions I recall), and that
very unfriendly I/O system (console I/O required special handling from file
I/O as Pascal does a one-element pre-read when an I/O channel is opened --
which occurs on program load for stdin, much before a program could output
a prompt to the user).

Even my first exposure to VAX/VMS Pascal, which did allow for separate
compilation and linking, required me to declare interfaces to the FORTRAN
run-time library to get advanced math functions (I believe later versions
incorporated the FORTRAN math natively).




-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cpython: when to incref before insertdict

2022-03-05 Thread Inada Naoki
On Sat, Mar 5, 2022 at 11:22 PM Marco Sulla
 wrote:
>
> I noticed that some functions inside dictobject.c that call insertdict
> or PyDict_SetItem do an incref of key and value before the call, and a
> decref after it. An example is dict_merge.

First of all, insertdict and PyDict is totally different about
reference ownership handling.

* PyDict_SetItem borrows reference of key and value from the caller as
usual Python/C APIs. And it INCREF them before calling the
insertdict().
* insertdict() takes the reference from its caller. In other words,
insertdict() moves the owner of reference from its caller to the dict.

merge_dict is very special and complex case.
I assume you are talking about this part.
https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Objects/dictobject.c#L2885-L2912

In general, when reference is borrowed from a caller, the reference is
available during the API.
But merge_dict borrows reference of key/value from other dict, not caller.
So dict_merge must have strong reference of key/value by INCREF before
calling any APIs (e.g. _PyDict_Contains_KnownHash).
That's why dict_merge calls INCREF key/value **twice** before calling
insertdict, and DECREF key/value **once** after it.

> Other functions, such as
> _PyDict_FromKeys, don't do an incref before.
>

Again, insertdict takes the reference. So _PyDict_FromKeys() **does**
INCREF before calling insertdict, when key/value is borrowed
reference.
https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Objects/dictobject.c#L2287-L2290
https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Objects/dictobject.c#L2309-L2311

On the other hand, slow path uses PyIter_Next() which returns strong
reference. So no need to INCREF it.
Additionally, the slow path uses PyDict_SetItem(), not insertdict().
PyDict_SetItem() does INCREF key/value for insertdict.
So the slow path need to DECREF(key).
https://github.com/python/cpython/blob/6927632492cbad86a250aa006c1847e03b03e70b/Objects/dictobject.c#L2327-L2329

This is complete guide why/when INCREF/DECREF key/value.
-- 
Inada Naoki  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Behavior of the for-else construct

2022-03-05 Thread Avi Gross via Python-list
I am not clear on what you are commenting, Dennis. You are responding to what I 
do not believe I wrote. You did not quote the part of my message where I wrote 
what "I" did in the early 80's and did not say when PASCAL was available 
elsewhere.

"I paid no attention to where PASCAL was being used other than I did much of my 
grad school work in PASCAL in the early 80's including my thesis being a 
document that could be typeset or run from the same file ;-)"

I might have encountered it in the early 70's had I had any room in my college 
course schedule where I ended up with a triple major in other subjects or while 
I was in Medical school. But no, I only went back to study C.S. afterwards. So, 
I apologize for being late. Heck I was also not there when ALGOL was created or 
FORTRAN, let alone COBOL! But if it helps, I taught FORTRAN and other languages 
to undergrads ;-)

-Original Message-
From: Dennis Lee Bieber 
To: python-list@python.org
Sent: Sat, Mar 5, 2022 7:00 pm
Subject: Re: Behavior of the for-else construct


On Sat, 5 Mar 2022 21:40:08 + (UTC), Avi Gross 

declaimed the following:



>I am not sure how we end up conversing about PASCAL on a Python forum. But it 
>is worth considering how people educated in aspects of Computer Science often 
>come from somewhat different background and how it flavors what they do now.

>

    You'd prefer REBOL, perhaps? 



    REXX at least has some structure to it 



    NB: Pascal has, like Ada, always been a  name -- not

like the origins of COBOL, FORTRAN, BASIC, et al.



>I paid no attention to where PASCAL was being used other than I did much of my 
>grad school work in PASCAL in the early 80's including my thesis being a 
>document that could be typeset or run from the same file ;-)

>

    Very early? The common versions were probably UCSD (running on UCSD

P-System); or a port of the P-4 compiler (which had been published in book

form) -- maybe a "tinyPascal" (integer only I suspect). Radio Shack did

provide Alcor Pascal for the TRS-80.



    Later, you might have encountered TurboPascal -- which bore little

resemblance to a Jensen&Wirth Pascal. 



    J&W was one-program<>one-file (no link libraries, no "include" files as

I recall); very limited math functions if one is trying for scientific

applications (sin, cos, arctan were the trig functions I recall), and that

very unfriendly I/O system (console I/O required special handling from file

I/O as Pascal does a one-element pre-read when an I/O channel is opened --

which occurs on program load for stdin, much before a program could output

a prompt to the user).



    Even my first exposure to VAX/VMS Pascal, which did allow for separate

compilation and linking, required me to declare interfaces to the FORTRAN

run-time library to get advanced math functions (I believe later versions

incorporated the FORTRAN math natively).









-- 

    Wulfraed                 Dennis Lee Bieber         AF6VN

    wlfr...@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

-- 

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

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