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

2022-10-14 Thread Rob Cliffe via Python-list
I too have occasionally used for ... else.  It does have its uses. But 
oh, how I wish it had been called something else more meaningful, 
whether 'nobreak' or whatever.  It used to really confuse me.  Now I've 
learned to mentally replace "else" by "if nobreak", it confuses me a bit 
less.

Rob Cliffe

On 12/10/2022 22:11, Weatherby,Gerard wrote:

As did I.

tree = ET.parse(lfile)
 for child in tree.getroot():
 if child.tag == 'server':
 break
 else:
 raise ValueError(f"server tag not found in {lfile}")

I think there are other places I could be using it, but honestly I tend to 
forget it’s available.

From: Python-list  on behalf of 
Stefan Ram 
Date: Wednesday, October 12, 2022 at 2:22 PM
To: python-list@python.org 
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Axy  writes:

So, seriously, why they needed else if the following pieces produce same
result? Does anyone know or remember their motivation?

   Just wrote code wherein I used "else"! This:

import locale
for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
 try: locale.setlocale( locale.LC_ALL, name ); break
 except locale.Error: pass
else: print( "Programm kann deutsche Schreibweise nicht einrichten." )

   .


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$


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


systemd Re: Find the path of a shell command

2022-10-14 Thread Weatherby,Gerard
Only the first one or two require more work. The rest are your copy-pastes from 
the last time you did one.

Typically I only have to changed descriptions, the executable in the *service 
and the timing in the *timer. They’re lot more readable and flexible than the 
cronjobs.

From: Python-list  on 
behalf of Albert-Jan Roskam 
Date: Friday, October 14, 2022 at 1:59 PM
To: Peter J. Holzer 
Cc: python-list@python.org 



   =
   Lately I've been using systemd timers instead of cronjobs. They are easier
   to debug (journalctl) but require a bit more work to write. Systemd is
   available on Fedora & friends and Debian based systems, maybe more. It has
   no builtin MAILTO. I use an OnFailure stanza to send a Slack message with
   curl instead.
   
https://urldefense.com/v3/__https://www.freedesktop.org/software/systemd/man/systemd.timer.html__;!!Cn_UX_p3!l6ZRc2Ur6rwspaC1V71wsENqmq5RNIR3lU2suC1LJLzYp097e-r2NwNBD3a_RhjuUkrSmfq3emmUsY-1m0PxT2TM$
   
https://urldefense.com/v3/__https://unix.stackexchange.com/questions/278564/cron-vs-systemd-timers__;!!Cn_UX_p3!l6ZRc2Ur6rwspaC1V71wsENqmq5RNIR3lU2suC1LJLzYp097e-r2NwNBD3a_RhjuUkrSmfq3emmUsY-1m6sDQHR0$
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!l6ZRc2Ur6rwspaC1V71wsENqmq5RNIR3lU2suC1LJLzYp097e-r2NwNBD3a_RhjuUkrSmfq3emmUsY-1m3Q-bOmf$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-14 Thread Albert-Jan Roskam
   On Oct 14, 2022 18:19, "Peter J. Holzer"  wrote:

 On 2022-10-14 07:40:14 -0700, Dan Stromberg wrote:
 > Alternatively, you can "ps axfwwe" (on Linux) to see environment
 > variables, and check what the environment of cron (or similar) is.  It
 > is this environment (mostly) that cronjobs will inherit.

 The simplest (and IMHO also most reliable) way to find out the
 environment a cronjob has is to write a cronjob which just dumps the
 environment.

   

   =
   Lately I've been using systemd timers instead of cronjobs. They are easier
   to debug (journalctl) but require a bit more work to write. Systemd is
   available on Fedora & friends and Debian based systems, maybe more. It has
   no builtin MAILTO. I use an OnFailure stanza to send a Slack message with
   curl instead.
   https://www.freedesktop.org/software/systemd/man/systemd.timer.html
   https://unix.stackexchange.com/questions/278564/cron-vs-systemd-timers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-14 Thread Peter J. Holzer
On 2022-10-14 07:40:14 -0700, Dan Stromberg wrote:
> Alternatively, you can "ps axfwwe" (on Linux) to see environment
> variables, and check what the environment of cron (or similar) is.  It
> is this environment (mostly) that cronjobs will inherit.

The simplest (and IMHO also most reliable) way to find out the
environment a cronjob has is to write a cronjob which just dumps the
environment.

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: Find the path of a shell command

2022-10-14 Thread Dan Stromberg
On Wed, Oct 12, 2022 at 11:13 AM Paulo da Silva <
p_d_a_s_i_l_v_a...@nonetnoaddress.pt> wrote:

> Hi!
>
> The simple question: How do I find the full path of a shell command
> (linux), i.e. how do I obtain the corresponding of, for example,
> "type rm" in command line?
>
> The reason:
> I have python program that launches a detached rm. It works pretty well
> until it is invoked by cron! I suspect that for cron we need to specify
> the full path.
> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> What about other commands?
>
I like to test my cronjobs with something like:

env - /usr/local/bin/my-cronjob

This will empty out the environment, and force you to set $PATH yourself.

Alternatively, you can "ps axfwwe" (on Linux) to see environment variables,
and check what the environment of cron (or similar) is.  It is this
environment (mostly) that cronjobs will inherit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What might suddenly provoke this poplib error?

2022-10-14 Thread Peter J. Holzer
[The OP has stated that the problem has been fixed. The following are
generic comments about troubleshooting.]

On 2022-10-14 11:31:56 +1300, dn wrote:
> On 14/10/2022 01.47, Chris Green wrote:
> >File "/usr/lib/python3.10/poplib.py", line 157, in _getresp
> >  raise error_proto(resp)
> >  poplib.error_proto: b'-ERR internal server error'
...
> > It seems to be saying that the POP3 server has a problem, if so
> > there's not much I can do about it as it's my hosting provider's
> > mail server.  Is it really saying the server has a problem?
> 
> 
> There's a range of possibilities here. The first question to ask (as
> you probably have) is "what has changed?" - has the Python/PSL on this
> computer been updated*, has the computer's SSL/TLS library been
> updated, etc. Then there are possible changes at 'the other end' - per
> previous responses.

I think this should be the second question. The first quesion is: What
are the actual symptoms?

In this case we have a relatively clear error message which was
obviously[2] sent by the server. So anything else must[1] be consistent
with this error message (and the fact that we were able to get this
error message in the first place).

So it can't[1] be TLS, because if you can't establish a connection, the
server can't send an error message.

The message also says "internal server error", and this is not something
a client should be able to provoke. So it's unlikely to be anything on
the client side.

What's left is that there was a change or operational error on the
server side, so further analysis must be conducted there.

hp


[1] Take absolute assertions like this with a grain of salt. There are
always misleading error messages, weird edge cases, etc. But
consider those only after ruling out everything else.

[2] What may be obvious to one person is of course not necessarily
obvious to another.

-- 
   _  | 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