Re: Register multiple excepthooks?

2022-08-04 Thread Albert-Jan Roskam
   On Aug 1, 2022 19:34, Dieter Maurer  wrote:

 Albert-Jan Roskam wrote at 2022-7-31 11:39 +0200:
 >   I have a function init_logging.log_uncaught_errors() that I use for
 >   sys.excepthook. Now I also want to call another function
 (ffi.dlclose())
 >   upon abnormal termination. Is it possible to register multiple
 >   excepthooks, like with atexit.register? Or should I rename/redefine
 >   log_uncaught_errors() so it does both things?

 `sys.excepthook` is a single function (not a list of them).
 This means: at any moment a single `excepthook` is effective.

 If you need a modular design, use a dispatcher function
 as your `excepthook` associated with a registry (e.g. a `list`).
 The dispatcher can then call all registered function.

   
   Thank you both. I'll give this a try. I think it would be nice if the
   standard library function atexit.register would be improved, such that the
   registered functions would not only be called upon (a) normal program
   termination, but that one could also register functions that are called
   (b) upon error (c) unconditionally. Much like (a) try - (b) except - (c)
   finally.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Turritopsis Dohrnii Teo En Ming
On Thu, 4 Aug 2022 at 10:47, orzodk  wrote:
>
> Turritopsis Dohrnii Teo En Ming  writes:
>
> > noted with thanks. I have been using Linux for more than 10 years already
>
> Ah, if you're familiar with Redhat (RPM) based distributions, consider
> Fedora as you will have access to newer versions sooner.
>
> If you're more familiar with Debian (DEB) based distributions, consider
> Ubuntu, again, as the new version release cycle is twice a year.
>
> (Also, my apologies -- I meant to CC the list but failed to do so.)

I am actually quite familiar with many linux distros. I am familiar
with RPM-based linux distros as well as DEB-based linux distros.

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Turritopsis Dohrnii Teo En Ming
On Thu, 4 Aug 2022 at 11:05, dn  wrote:
>
> On 04/08/2022 14.31, Paul Bryan wrote:
> > I wouldn't say any particular Linux distribution is appreciably better
> > for Python development than another. I would suggest using a version of
> > a Linux distribution that supports a recent Python release (e.g. 3.9 or
> > 3.10).
>
> +1
>
> As a Python-learner (there's no comment about current programming
> expertise), it is unlikely to make any difference which Linux distro is
> used.
>
> Answers to such open-ended questions are usually seated in bias - which
> in-turn is mostly likely to be the same answer as 'which is the Linux
> distro *I* use?
> (I've used a number, with Python, over the years)
>
> The better alignment is to match the version of Python with the book or
> course you are using as learning-materials. That way, there are unlikely
> to be surprises.

Noted on this.

>
> There are differences in Python implementations between Linux, Mac, and
> Windows. However, I can't think of a book or course which spends any
> time discussing them, or having a chapter which demands one or other OpSys.
>
> When you become more experienced two things will happen: firstly you
> will start using tools which enable the use of different versions of
> Python for different dev.projects; and secondly you will form your own
> opinions of "best"!
> (it's not difficult to change distro)
>
>
> PS most of us will qualify for RedHat's Developer program[me] and free
> copies of software.

I can download free copies of RHEL 7.x, 8.x, and 9.x :) Just that I
dunno which RHEL version is better. Is RHEL 9.0 the best out of 7.x,
8.x and 9.x?

> --
> Regards,
> =dn

Regards,

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Turritopsis Dohrnii Teo En Ming
On Thu, 4 Aug 2022 at 13:02, Kushal Kumaran  wrote:
>
> On Thu, Aug 04 2022 at 10:22:41 AM, Turritopsis Dohrnii Teo En Ming 
>  wrote:
> > Subject: Which linux distro is more conducive for learning the Python
> > programming language?
> >
> > Good day from Singapore,
> >
> > May I know which linux distro is more conducive for learning the
> > Python programming language?
> >
> > Since I have absolutely and totally FREE RHEL developer subscription
> > (I don't need to spend a single cent), can I use Red Hat Enterprise
> > Linux version 9.0 to learn Python?
> >
> > Is it the most popular linux distro for learning Python?
> >
> > I just want to know which linux distro and version is more conducive
> > for learning Python. Because there are thousands of linux distros out
> > there. And I just want to settle down on a particular linux distro and
> > version.
> >
>
> The best one would be whatever you happen to have installed and for
> which you understand system administration.  Beyond that, distribution
> choice matters very little.  Every distribution I've used ships python3
> packages, which was fine for learning the language.
>
> --
> regards,
> kushal

Noted with thanks Kushal. Since I can download FREE copies of RHEL
9.0, I will use it then.

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread dn
>> PS most of us will qualify for RedHat's Developer program[me] and free
>> copies of software.
> 
> I can download free copies of RHEL 7.x, 8.x, and 9.x :) Just that I
> dunno which RHEL version is better. Is RHEL 9.0 the best out of 7.x,
> 8.x and 9.x?

RedHat is a stable OpSys. Accordingly, it doesn't much matter which
version. The general assumption is that the more recent distribution has
more advanced facilities, eg improved security features in RHEL9.

As another post says, Fedora is closer to the bleeding-edge of Linux
development.

Be aware that there are many methods of adding Python. For example, if
your training is based on the Anaconda [Python] distribution, then it is
irrelevant which version of Python comes with the Linux distro. As
mentioned before, if you advance to developing in [Python] virtual
environments, then each of these could run a different version of
Python. Similarly, using a VM...

The question is relatively minor. More important to 'get going'!
(also mentioned previously: relatively easy to change (Python or distro)
'later'!)
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Turritopsis Dohrnii Teo En Ming
On Thu, 4 Aug 2022 at 16:50, dn  wrote:
>
> >> PS most of us will qualify for RedHat's Developer program[me] and free
> >> copies of software.
> >
> > I can download free copies of RHEL 7.x, 8.x, and 9.x :) Just that I
> > dunno which RHEL version is better. Is RHEL 9.0 the best out of 7.x,
> > 8.x and 9.x?
>
> RedHat is a stable OpSys. Accordingly, it doesn't much matter which
> version. The general assumption is that the more recent distribution has
> more advanced facilities, eg improved security features in RHEL9.
>
> As another post says, Fedora is closer to the bleeding-edge of Linux
> development.

RHEL 9.0 is also quite close to the bleeding edge of Linux
development. It has Linux kernel version 5.14.0.

>
> Be aware that there are many methods of adding Python. For example, if
> your training is based on the Anaconda [Python] distribution, then it is
> irrelevant which version of Python comes with the Linux distro. As
> mentioned before, if you advance to developing in [Python] virtual
> environments, then each of these could run a different version of
> Python. Similarly, using a VM...
>
> The question is relatively minor. More important to 'get going'!

I am going to get going on learning Python with RHEL 9.0.

> (also mentioned previously: relatively easy to change (Python or distro)
> 'later'!)
> --
> Regards,
> =dn

Regards,

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Weatherby,Gerard
Just be aware https://docs.python.org/3/ defaults to the latest Python version 
(3.10). When looking up a module, it’s best to explicitly set the documentation 
to the version you are using. It won’t matter the vast majority of the time but 
I have been burned by trying to use a function or parameter that was introduced 
with a later version.

—
Gerard Weatherby | Application Architect NMRbox | NAN | Department of Molecular 
Biology and Biophysics
 UConn Health 263 Farmington Avenue, Farmington, CT 06030-6406 uchc.edu
On Aug 4, 2022, 5:00 AM -0400, Turritopsis Dohrnii Teo En Ming 
, wrote:
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On Thu, 4 Aug 2022 at 16:50, dn  wrote:

PS most of us will qualify for RedHat's Developer program[me] and free
copies of software.

I can download free copies of RHEL 7.x, 8.x, and 9.x :) Just that I
dunno which RHEL version is better. Is RHEL 9.0 the best out of 7.x,
8.x and 9.x?

RedHat is a stable OpSys. Accordingly, it doesn't much matter which
version. The general assumption is that the more recent distribution has
more advanced facilities, eg improved security features in RHEL9.

As another post says, Fedora is closer to the bleeding-edge of Linux
development.

RHEL 9.0 is also quite close to the bleeding edge of Linux
development. It has Linux kernel version 5.14.0.


Be aware that there are many methods of adding Python. For example, if
your training is based on the Anaconda [Python] distribution, then it is
irrelevant which version of Python comes with the Linux distro. As
mentioned before, if you advance to developing in [Python] virtual
environments, then each of these could run a different version of
Python. Similarly, using a VM...

The question is relatively minor. More important to 'get going'!

I am going to get going on learning Python with RHEL 9.0.

(also mentioned previously: relatively easy to change (Python or distro)
'later'!)
--
Regards,
=dn

Regards,

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mxIe1U15eEI7AomZUwIzjK0lVTfFXHto6Atu7jqaE58V0YUQc2K8s9LrjPDNjOXjQ5NB3Tu-cqbRDnx0pmu6$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Register multiple excepthooks?

2022-08-04 Thread 2QdxY4RzWzUUiLuE
On 2022-08-04 at 09:41:00 +0200,
Albert-Jan Roskam  wrote:

>Thank you both. I'll give this a try. I think it would be nice if
>the standard library function atexit.register would be improved,
>such that the registered functions would not only be called upon
>(a) normal program termination, but that one could also register
>functions that are called (b) upon error (c) unconditionally. Much
>like (a) try - (b) except - (c) finally.

There.  You've just designed the top level of a better behaved, more
robust application (completely untested):

on_normal_exit_funcs = list()
on_error_exit_funcs = list()
on_any_exit_funcs = list()

def run_exit_funcs(exit_funcs):
for func in exit_funcs:
try: func()
except e: maybe_do_some_logging(e)

try:
run_the_application()
run_exit_funcs(on_normal_exit_funcs)
except:
run_exit_funcs(on_error_exit_funcs)
finally:
run_exit_funcs(on_any_exit_funcs)

def register_normal_exit_func(f):
on_normal_exit_funcs.append(f)

def register_error_exit_func(f):
on_error_exit_funcs.append(f)

def register_any_exit_func(f):
on_any_exit_funcs.append(f)

No, really.  There are worse ways to build an extremely generic, fairly
minimalist application framework.

Season to taste,¹ add it to your personal (or company) toolbox, and
refine and improve it as things come up.  You may discover some number
of common exit functions that are useful across appliations, too.

¹ are you object oriented, functional, imperative, or something else?
do you like long names, short names, names that follow some existing
coding standard, non-English names? do you have a standardized
logging/exception library?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Grant Edwards
On 2022-08-04, Turritopsis Dohrnii Teo En Ming  wrote:

> Subject: Which linux distro is more conducive for learning the Python
> programming language?

You can learn Python on any Linux distribution.

First answer this question:

 * Whom are you going to ask for help when you run into Linux questions?

Install the Linux distro that person uses.


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


My application failed to start because no Qt platform plugin could be initialized. Reinstalled the application several times my problem didn't got fixed.

2022-08-04 Thread MahaRaja Shiv



Sent from Mail for Windows

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


Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Loris Bennett
[email protected] (Stefan Ram) writes:

> "Loris Bennett"  writes:
>>data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
> ...
>>filtered_data = list(filter(None, data))
>
>   You could have "get_job_efficiency_dict" return an iterable
>   that yields either zero dictionaries or one dictionary.
>   For example, a list with either zero entries or one entry.
>
>   Then, use "itertools.chain.from_iterable" to merge all those
>   lists with empty lists effectively removed. E.g.,
>
> print( list( itertools.chain.from_iterable( [[ 1 ], [], [ 2 ], [ 3 ]])))
>
>   will print
>
> [1, 2, 3]

'itertool' is a bit of a blind-spot of mine, so thanks for pointing that
out. 

>   . Or, consider a boring old "for" loop:
>
> data = []
> for job_id in job_ids:
> dictionary = get_job_efficiency_dict( job_id )
> if dictionary:
> data.append( dictionary )
>
>   . It might not be "elegant", but it's quite readable to me.

To me to.  However, 'data' can occasionally consist of many 10,000s of
elements.  Would there be a potential performance problem here?  Even if
there is, it wouldn't be so bad, as the aggregation of the data is not
time-critical and only occurs once a month.  Still, I wouldn't want the
program to be unnecessarily inefficient.

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Tobiah

On 8/3/22 19:01, Turritopsis Dohrnii Teo En Ming wrote:

Subject: Which linux distro is more conducive for learning the Python 
programming language?


You might try Pythontu.

Not really.  Get the distro that looks appealing to you.
One won't be better than the other with regard to learning
python.




Good day from Singapore,

May I know which linux distro is more conducive for learning the Python 
programming language?

Since I have absolutely and totally FREE RHEL developer subscription (I don't 
need to spend a single cent), can I use Red Hat Enterprise Linux version 9.0 to 
learn Python?

Is it the most popular linux distro for learning Python?

I just want to know which linux distro and version is more conducive for 
learning Python. Because there are thousands of linux distros out there. And I 
just want to settle down on a particular linux distro and version.

Thank you.

Regards,

Mr. Turritopsis Dohrnii Teo En Ming
Targeted Individual in Singapore
4 Aug 2022 Thursday
Blogs:
https://tdtemcerts.blogspot.com
https://tdtemcerts.wordpress.com


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


Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Loris Bennett
Hi,

I am constructing a list of dictionaries via the following list
comprehension:

  data = [get_job_efficiency_dict(job_id) for job_id in job_ids]

However,

  get_job_efficiency_dict(job_id)

uses 'subprocess.Popen' to run an external program and this can fail.
In this case, the dict should just be omitted from 'data'.

I can have 'get_job_efficiency_dict' return 'None' and then run

  filtered_data = list(filter(None, data))

but is there a more elegant way?

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Barry


> On 4 Aug 2022, at 09:48, Turritopsis Dohrnii Teo En Ming 
>  wrote:
> 
> On Thu, 4 Aug 2022 at 13:02, Kushal Kumaran  wrote:
>> 
>>> On Thu, Aug 04 2022 at 10:22:41 AM, Turritopsis Dohrnii Teo En Ming 
>>>  wrote:
>>> Subject: Which linux distro is more conducive for learning the Python
>>> programming language?
>>> 
>>> Good day from Singapore,
>>> 
>>> May I know which linux distro is more conducive for learning the
>>> Python programming language?
>>> 
>>> Since I have absolutely and totally FREE RHEL developer subscription
>>> (I don't need to spend a single cent), can I use Red Hat Enterprise
>>> Linux version 9.0 to learn Python?
>>> 
>>> Is it the most popular linux distro for learning Python?
>>> 
>>> I just want to know which linux distro and version is more conducive
>>> for learning Python. Because there are thousands of linux distros out
>>> there. And I just want to settle down on a particular linux distro and
>>> version.
>>> 
>> 
>> The best one would be whatever you happen to have installed and for
>> which you understand system administration.  Beyond that, distribution
>> choice matters very little.  Every distribution I've used ships python3
>> packages, which was fine for learning the language.
>> 
>> --
>> regards,
>> kushal
> 
> Noted with thanks Kushal. Since I can download FREE copies of RHEL
> 9.0, I will use it then.

I consider rhel 9 is an old os. I would suggest using fedora over rhel.
Fedora 36 has python 3.10 and the when fedora 37 is released it will have 
python 3.11.
And fedora is free as well.

Barry


> 
> Mr. Turritopsis Dohrnii Teo En Ming
> Targeted Individual in Singapore
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Christian Heimes

On 04/08/2022 20.12, Barry wrote:

Noted with thanks Kushal. Since I can download FREE copies of RHEL
9.0, I will use it then.


I consider rhel 9 is an old os. I would suggest using fedora over rhel.
Fedora 36 has python 3.10 and the when fedora 37 is released it will have 
python 3.11.
And fedora is free as well.


Fedora is an excellent choice for Python users. Fedora 36 already comes 
with Python 3.11.0b5 in its main repository. In fact you have Python 
2.7, 3.5-3.11, PyPy 2.7, PyPy 3.7-3.9, and MicroPython at your fingertips.


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


Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Antoon Pardon

Op 4/08/2022 om 13:51 schreef Loris Bennett:

Hi,

I am constructing a list of dictionaries via the following list
comprehension:

   data = [get_job_efficiency_dict(job_id) for job_id in job_ids]

However,

   get_job_efficiency_dict(job_id)

uses 'subprocess.Popen' to run an external program and this can fail.
In this case, the dict should just be omitted from 'data'.

I can have 'get_job_efficiency_dict' return 'None' and then run

   filtered_data = list(filter(None, data))

but is there a more elegant way?


Just wondering, why don't you return an empty dictionary in case of a failure?
In that case your list will be all dictionaries and empty ones will be processed
fast enough.

--
Antoon Pardon.

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


Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread MRAB

On 2022-08-04 12:51, Loris Bennett wrote:

Hi,

I am constructing a list of dictionaries via the following list
comprehension:

   data = [get_job_efficiency_dict(job_id) for job_id in job_ids]

However,

   get_job_efficiency_dict(job_id)

uses 'subprocess.Popen' to run an external program and this can fail.
In this case, the dict should just be omitted from 'data'.

I can have 'get_job_efficiency_dict' return 'None' and then run

   filtered_data = list(filter(None, data))

but is there a more elegant way?


I'm not sure how elegant it is, but:

data = [result for job_id in job_ids if (result := 
get_job_efficiency_dict(job_id)) is not None]

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


Re: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread Grant Edwards
On 2022-08-04, Christian Heimes  wrote:

> Fedora is an excellent choice for Python users. Fedora 36 already comes 
> with Python 3.11.0b5 in its main repository. In fact you have Python 
> 2.7, 3.5-3.11, PyPy 2.7, PyPy 3.7-3.9, and MicroPython at your fingertips.

Except that real programmers use Python 1.52 because they depend on the
assumption that integers are native word size and arithmatic is done
modulo-maxunsigned the same way it is in assembly language...

;)

Honestly, back when I was implementing netowrk protocols in Python on
a 32-bit machine, it was very useful having 32-bit Python integers.


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


Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Weatherby,Gerard
Or:

data = [d for d in [get_job_efficiency_dict(job_id) for job_id in job_ids] if d 
is not None]

or

for job_id in job_ids:
if (d := get_job_efficiency_dict(job_id)) is not None:
  data.append(d)


Personally, I’d got with the latter in my own code.

—
Gerard Weatherby | Application Architect NMRbox | NAN | Department of Molecular 
Biology and Biophysics
 UConn Health 263 Farmington Avenue, Farmington, CT 06030-6406 uchc.edu
On Aug 4, 2022, 2:52 PM -0400, MRAB , wrote:
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 2022-08-04 12:51, Loris Bennett wrote:
Hi,

I am constructing a list of dictionaries via the following list
comprehension:

data = [get_job_efficiency_dict(job_id) for job_id in job_ids]

However,

get_job_efficiency_dict(job_id)

uses 'subprocess.Popen' to run an external program and this can fail.
In this case, the dict should just be omitted from 'data'.

I can have 'get_job_efficiency_dict' return 'None' and then run

filtered_data = list(filter(None, data))

but is there a more elegant way?

I'm not sure how elegant it is, but:

data = [result for job_id in job_ids if (result :=
get_job_efficiency_dict(job_id)) is not None]
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iqxhYMoHcYQY1xohGCpafpBKZIUcGEV6Zj1-RLzOCF61TUXGr-8oh9HLuL-H8w4gxgDCypcOYOYkqNXLJxUIqhWd$
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Which linux distro is more conducive for learning the Python programming language?

2022-08-04 Thread avi.e.gross
To be clear, the discussion strikes me oddly.

You can learn python without a computer. Of course to actually have people
write code and try it out is another story.

Python by itself is simply a program that can be typed into an interpreter
or given a file to process and works just as well on LINUX, Windows and so
on. I have half a dozen varieties on my machine from various
modes/distributions.

As some have pointed out, any RECENT version of python (presumably the 3
version unless your goal is to teach the older version) should be fine for
teaching but obviously all kinds of tools can help. But there are online
resources that may be adequate that require NOTHING but a browser:

https://py3.codeskulptor.org/

The above URL allows you to create and run and save python files and is
probably adequate for teaching basics and for sharing programs others have
saved by sending you the URL. 

Of course, beyond a certain point, it fails to meet needs such as not
supporting importing random modules.

But as was discussed here before, you can find little time to teach python
if you also have to teach every environment and editor and especially handle
students using other choices. But to ask everyone to use the same LINUX
distribution may also be a drastic step. 

The reality is that simple python programs can be handled with any standard
text editor. Sure, lots of bells and whistles can be added and there may
well be advantages to using systems ranging from anaconda  to lately RSTUDIO
but they often come with many superfluous features and lots of complexity.

-Original Message-
From: Python-list  On
Behalf Of Grant Edwards
Sent: Thursday, August 4, 2022 10:35 AM
To: [email protected]
Subject: Re: Which linux distro is more conducive for learning the Python
programming language?

On 2022-08-04, Turritopsis Dohrnii Teo En Ming  wrote:

> Subject: Which linux distro is more conducive for learning the Python 
> programming language?

You can learn Python on any Linux distribution.

First answer this question:

 * Whom are you going to ask for help when you run into Linux questions?

Install the Linux distro that person uses.


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

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