tkinter ttk.Treeview: changing background colour of single item when selected

2023-02-04 Thread John O'Hagan
Hi list

I'm using a ttk Treeview to display a hierarchical data structure. When
an error condition arises in a node, I want the corresponding item in
the Treeview to flash its background color. 

Using a tag to flash the item background works, except when the item is
selected, when the tag has no effect. I want the item to keep flashing
even when selected.

The code below is a minimal example of the issue. It displays a
Treeview containing two items with the first one flashing. If you
select it, you don't see the flashing anymore.

from tkinter import *
from tkinter.ttk import *

root = Tk()
t = Treeview(root)

t.insert('', 0, iid='item1', text='item1')
t.insert('', 1, text='item2')
t.tag_configure('flashtag', background='red')
t.pack()

def flash():
 tags = t.item('item1', 'tags')
 t.item('item1', tags='' if tags else 'flashtag')
 t.after(500, flash)

flash()
mainloop()

Other than tags, the only other way I've found to dynamically change
Treeview backgrounds is using styles, in particular Style.map to
configure the background of a selected item, but they apply to all
items in the Treeview and would flash all selected items, not just the
one I want to keep flashing.

Is there another way to do what I want?

Thanks

--

John

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


Re: Organizing modules and their code

2023-02-04 Thread Weatherby,Gerard
You’re overthinking it. It doesn’t really matter. Having small chunks of codes 
in separate files can be hassle when trying to find out what the program does. 
Having one file with 2,000 lines in it can be a hassle.  This is art / opinion, 
not science.

From: Python-list  on 
behalf of transreductionist 
Date: Friday, February 3, 2023 at 4:48 PM
To: python-list@python.org 
Subject: Organizing modules and their code
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Here is the situation. There is a top-level module (see designs below) 
containing code, that as the name suggests, manages an ETL pipeline. A 
directory is created called etl_helpers that organizes several modules 
responsible for making up the pipeline. The discussion concerns the Python 
language, which supports OOP as well as Structural/Functional approaches to 
programming.

I am interested in opinions on which design adheres best to standard 
architectural practices and the SOLID principles. I understand that this is one 
of those topics where people may have strong opinions one way or the other. I 
am interested in those opinions.

Allow me to give my thoughts. First, I don't think there would be much 
difference if I was using OOP for the functionality, or using a structural 
paradigm. A structural paradigm in my opinion, along the lines of Rich Hickey's 
comments on simple versus complex, would be a simpler implementation. In this 
case there is no reason to create a construct with state. So let's assume the 
code is structural and not OOP.

I would go with Design I. Succinctly stated, Design I supports readability and 
maintainability at least as well, if not better than the other designs. The 
goal of the SOLID principles are the creation of mid-level software structures 
that (Software Architecture: SA Martin). I think Design I best adheres to these 
principles of:
 Tolerate change,
 Are easy to understand, and
 Are the basis of components that can be used in many software systems.

I could point to the Single Responsibility Principle which is defined as (SA 
Martin): a module should be responsible to one, and only one, actor. It should 
satisfy the Liskov Substitution Principle as well. Further, each module in the 
etl_helpers directory is at the same level of abstraction.

I could also mention that as Dijkstra stressed, at every level, from the 
smallest function to the largest component, software is like a science and, 
therefore, is driven by falsifiability. Software architects strive to define 
modules, components, and services that are easily falsifiable (testable). To do 
so, they employ restrictive disciplines similar to structured programming,
albeit at a much higher level (SA Martin).

One can point to multiple reasons why Design I might be preferred, but what are 
the compelling reasons, if there are any, that would suggest another design was 
superior.

Finally, let me reference an interesting research paper I read recently that 
seems to support the other designs as anti-patterns: 
Architecture_Anti-patterns_Automatically.pdf

  
(https://urldefense.com/v3/__https://www.cs.drexel.edu/*yfcai/papers/2019/tse2019.pdf__;fg!!Cn_UX_p3!jcpCdxiLoPobR0IdlyJHwyPiNP4_iVC6dAMtg_HsLr5hStszx-WnYyZQHJ-4pJTOGsw4-6pEGJyDpSytZQqfpvATg06FMA$
 )

SEVERAL DESIGNS FOR COMPARISON

DESIGN I:

 manage_the_etl_pipeline.py
 etl_helpers
   extract.py
   transform.py
   load.py

Of course one could also

DESIGN II:

 manage_the_etl_pipeline.py
 etl_helpers
   extract_transform_load.py

or probably even:

DESIGN III:

 manage_the_etl_pipeline.py
 extract_transform_load.py
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jcpCdxiLoPobR0IdlyJHwyPiNP4_iVC6dAMtg_HsLr5hStszx-WnYyZQHJ-4pJTOGsw4-6pEGJyDpSytZQqfpvBaJ2e2VA$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter ttk.Treeview: changing background colour of single item when selected

2023-02-04 Thread Thomas Passin
I haven't worked specifically with a Treeview, but I think you need to 
detect the onClick event (or an onSelect event if there is one) and have 
that trigger the flashing.  Otherwise the selection probably overwrites 
styling that you added. That's what I do for classic Tk buttons to make 
them flash when selected.  (I only flash once, though; I don't keep them 
flashing).


On 2/4/2023 5:42 AM, John O'Hagan wrote:

Hi list

I'm using a ttk Treeview to display a hierarchical data structure. When
an error condition arises in a node, I want the corresponding item in
the Treeview to flash its background color.

Using a tag to flash the item background works, except when the item is
selected, when the tag has no effect. I want the item to keep flashing
even when selected.

The code below is a minimal example of the issue. It displays a
Treeview containing two items with the first one flashing. If you
select it, you don't see the flashing anymore.

from tkinter import *
from tkinter.ttk import *

root = Tk()
t = Treeview(root)

t.insert('', 0, iid='item1', text='item1')
t.insert('', 1, text='item2')
t.tag_configure('flashtag', background='red')
t.pack()

def flash():
  tags = t.item('item1', 'tags')
  t.item('item1', tags='' if tags else 'flashtag')
  t.after(500, flash)

flash()
mainloop()

Other than tags, the only other way I've found to dynamically change
Treeview backgrounds is using styles, in particular Style.map to
configure the background of a selected item, but they apply to all
items in the Treeview and would flash all selected items, not just the
one I want to keep flashing.

Is there another way to do what I want?

Thanks

--

John



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


How to read file content and send email on Debian Bullseye

2023-02-04 Thread ^Bart

Hi guys,

On a Debian Bullseye server I have a lftp upload and after it I should 
send an email.


I thought to read the lftp log file where I have these lines:

2023-01-30 18:30:02 
/home/my_user/local_folder/upload/my_file_30-01-2023_18-30.txt -> 
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_30-01-2023_18-30.txt 
0-1660576 4.92 MiB/s


2023-02-02 18:30:02 
/home/my_user/local_folder/upload/my_file_02-02-2023_18-30.txt -> 
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_02-02-2023_18-30.txt 
0-603093 3.39 MiB/s


I'd like to use Python to check, from monday to friday (the lftp script 
runs in crontab from monday to friday) when the upload works is finished 
and I should send an email.


I could read by Python lftp.log and after it if there's a line with the 
same day of the machine I could send an email with ok otherwise the 
email will send a message with "no upload".


How could I do by Python?

Regards.
^Bart
--
https://mail.python.org/mailman/listinfo/python-list


Re: Organizing modules and their code

2023-02-04 Thread transreductionist
On Friday, February 3, 2023 at 5:31:56 PM UTC-5, Thomas Passin wrote:
> On 2/3/2023 4:18 PM, transreductionist wrote: 
> > Here is the situation. There is a top-level module (see designs below) 
> > containing code, that as the name suggests, manages an ETL pipeline. A 
> > directory is created called etl_helpers that organizes several modules 
> > responsible for making up the pipeline. The discussion concerns the Python 
> > language, which supports OOP as well as Structural/Functional approaches to 
> > programming. 
> > 
> > I am interested in opinions on which design adheres best to standard 
> > architectural practices and the SOLID principles. I understand that this is 
> > one of those topics where people may have strong opinions one way or the 
> > other. I am interested in those opinions.
> Well, you have pretty well stacked the deck to make DESIGN 1 the 
> obviously preferred choice. I don't think it has much to do with Python 
> per se, or even with OO vs imperative style. 
> 
> As a practical matter, once you got into working with 
> extract_transform_load.py (for the other designs), I would expect that 
> you would start wanting to refactor it and eventually end up more like 
> DESIGN 1. So you might as well start out that way. 
> 
> The reasons are 1) what you said about separation of concerns, 2) a 
> desire to keep each module or file relatively coherent and easy to read, 
> and 3, as you also suggested, making each of them easier to test. 
> Decoupling is important too (one of the SOLID prescriptions), but you 
> can violate that with any architecture if you don't think carefully 
> about what you are doing. 
> 
> On the subject of OO, I think it is a very good approach to think about 
> architecture and design in object terms - meaning conceptual objects 
> from the users' point of view. For example, here you have a pipeline (a 
> metaphorical or userland object). It will need functionality to load, 
> transform, and output data so logically it can be composed of a loader, 
> one or more transformers, and one or more output formatters (more 
> objects). You may also need a scheduler and a configuration manager 
> (more objects). 
> 
> (*Please* let's not have any quibbling about "class" vs "object". We 
> are at a conceptual level here!) 
> 
> When it comes to implementation, you can choose to implement those 
> userland objects with either imperative, OO, or functional techniques, 
> or a mixture.
> > Allow me to give my thoughts. First, I don't think there would be much 
> > difference if I was using OOP for the functionality, or using a structural 
> > paradigm. A structural paradigm in my opinion, along the lines of Rich 
> > Hickey's comments on simple versus complex, would be a simpler 
> > implementation. In this case there is no reason to create a construct with 
> > state. So let's assume the code is structural and not OOP. 
> > 
> > I would go with Design I. Succinctly stated, Design I supports readability 
> > and maintainability at least as well, if not better than the other designs. 
> > The goal of the SOLID principles are the creation of mid-level software 
> > structures that (Software Architecture: SA Martin). I think Design I best 
> > adheres to these principles of: 
> >  Tolerate change, 
> >  Are easy to understand, and 
> >  Are the basis of components that can be used in many software systems. 
> > 
> > I could point to the Single Responsibility Principle which is defined as 
> > (SA Martin): a module should be responsible to one, and only one, actor. It 
> > should satisfy the Liskov Substitution Principle as well. Further, each 
> > module in the etl_helpers directory is at the same level of abstraction. 
> > 
> > I could also mention that as Dijkstra stressed, at every level, from the 
> > smallest function to the largest component, software is like a science and, 
> > therefore, is driven by falsifiability. Software architects strive to 
> > define modules, components, and services that are easily falsifiable 
> > (testable). To do so, they employ restrictive disciplines similar to 
> > structured programming, 
> > albeit at a much higher level (SA Martin). 
> > 
> > One can point to multiple reasons why Design I might be preferred, but what 
> > are the compelling reasons, if there are any, that would suggest another 
> > design was superior. 
> > 
> > Finally, let me reference an interesting research paper I read recently 
> > that seems to support the other designs as anti-patterns: 
> > Architecture_Anti-patterns_Automatically.pdf 
> > 
> >  (https://www.cs.drexel.edu/~yfcai/papers/2019/tse2019.pdf) 
> > 
> > SEVERAL DESIGNS FOR COMPARISON 
> > 
> > DESIGN I: 
> > 
> >  manage_the_etl_pipeline.py 
> >  etl_helpers 
> >  extract.py 
> >  transform.py 
> >  load.py 
> > 
> > Of course one could also 
> > 
> > DESIGN II: 
> > 
> >  manage_the_etl_pipeline.py 
> >  etl_helpers 
> >  extract_transform_load.py 
> > 

DeprecationWarning but replacement doesn't work

2023-02-04 Thread Chris Green
I am using Image from PIL and I'm getting a deprecation warning as
follows:-

/home/chris/bin/picShrink.py:80: DeprecationWarning: ANTIALIAS is deprecated 
and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.


The code is very simple:-

...
...
from PIL import Image
...
...
im = Image.open(srcFile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(dstFile, "JPEG")


But if I change line 80 to:-

im.thumbnail(size, Resampling.LANCZOS)

I simply get an error as follows:-

picShrink.py
Traceback (most recent call last):
  File "/home/chris/bin/picShrink.py", line 80, in 
im.thumbnail(size, Resampling.LANCZOS)
NameError: name 'Resampling' is not defined


So, presumably there's more I need to change.  Where can I find out what
I need to do?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: DeprecationWarning but replacement doesn't work

2023-02-04 Thread Chris Angelico
On Sun, 5 Feb 2023 at 07:52, Chris Green  wrote:
>
> I am using Image from PIL and I'm getting a deprecation warning as
> follows:-
>
> /home/chris/bin/picShrink.py:80: DeprecationWarning: ANTIALIAS is deprecated 
> and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
>
>
> im = Image.open(srcFile)
> im.thumbnail(size, Image.ANTIALIAS)
> im.save(dstFile, "JPEG")
>
> im.thumbnail(size, Resampling.LANCZOS)
>
> I simply get an error as follows:-
>
> picShrink.py
> Traceback (most recent call last):
>   File "/home/chris/bin/picShrink.py", line 80, in 
> im.thumbnail(size, Resampling.LANCZOS)
> NameError: name 'Resampling' is not defined
>

It looks like Resampling is an enumeration. The warning said
"ANTIALIAS" as a bare name, and you were using Image.ANTIALIAS; it
looks like Image.Resampling.LANCZOS has the same effect.

In fact, it looks like they're actually the same value:

>>> Image.ANTIALIAS is Image.Resampling.LANCZOS
:1: DeprecationWarning: ANTIALIAS is deprecated and will be
removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
True

So that should be a safe move forward.

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


Re: DeprecationWarning but replacement doesn't work

2023-02-04 Thread Roel Schroeven

Chris Green schreef op 4/02/2023 om 16:17:

I am using Image from PIL and I'm getting a deprecation warning as
follows:-

/home/chris/bin/picShrink.py:80: DeprecationWarning: ANTIALIAS is deprecated 
and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.


But if I change line 80 to:-

 im.thumbnail(size, Resampling.LANCZOS)

I simply get an error as follows:-

 picShrink.py
 Traceback (most recent call last):
   File "/home/chris/bin/picShrink.py", line 80, in 
 im.thumbnail(size, Resampling.LANCZOS)
 NameError: name 'Resampling' is not defined


So, presumably there's more I need to change.  Where can I find out what
I need to do?
There's some information about changes in constants in the release notes 
for version 9.1.0, see 
https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html. At 
first sight it looks like that indicates you have to do either


    from PIL import Image.Resampling as Resampling
    ...
    im.thumbnail(size, Resampling.LANCZOS)

or

    from PIL import Image.Resampling
    ...
    im.thumbnail(size, Image.Resampling.LANCZOS)

BUT according to the release notes of version 9.4.0 (see 
https://pillow.readthedocs.io/en/stable/releasenotes/9.4.0.html#restored-image-constants) 
the constants in Image will remain (it's not clear to me if the ones in 
Image.Resample will remain too). As far as I can see ANTIALIAS is still 
deprecated in favor of LANCZOS though. All in all, it looks like the way 
to go is to use Image.LANCZOS. In versions 9.1.0 up to but not including 
9.4.0 that will give you a deprecation warning but that can safely be 
ignored.


--
"Life ain't no fairy tale
Just give me another ale
And I'll drink to Rock 'n Roll"
-- Barkeep (The Scabs)

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


RE: How to read file content and send email on Debian Bullseye

2023-02-04 Thread avi.e.gross
Bart, you may want to narrow down your request to something quite specific.
For example, try to do whatever parts you know how to do and when some part
fails or is missing, ask.

I might have replied to you directly if your email email address did not
look like you want no SPAM, LOL!

The cron stuff is not really relevant and it seems your idea is to read a
part or all of a log file, parse the lines in some way and find a line that
either matches what you need or fail to find it. Either way you want to send
an email out with an appropriate content.

Which part of that do you not know how to do in python? Have you done some
reading or looking?



-Original Message-
From: Python-list  On
Behalf Of ^Bart
Sent: Saturday, February 4, 2023 10:05 AM
To: python-list@python.org
Subject: How to read file content and send email on Debian Bullseye

Hi guys,

On a Debian Bullseye server I have a lftp upload and after it I should send
an email.

I thought to read the lftp log file where I have these lines:

2023-01-30 18:30:02
/home/my_user/local_folder/upload/my_file_30-01-2023_18-30.txt ->
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_30-01-2023_18-30
.txt
0-1660576 4.92 MiB/s

2023-02-02 18:30:02
/home/my_user/local_folder/upload/my_file_02-02-2023_18-30.txt ->
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_02-02-2023_18-30
.txt
0-603093 3.39 MiB/s

I'd like to use Python to check, from monday to friday (the lftp script runs
in crontab from monday to friday) when the upload works is finished and I
should send an email.

I could read by Python lftp.log and after it if there's a line with the same
day of the machine I could send an email with ok otherwise the email will
send a message with "no upload".

How could I do by Python?

Regards.
^Bart
--
https://mail.python.org/mailman/listinfo/python-list

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


Re: How to read file content and send email on Debian Bullseye

2023-02-04 Thread Thomas Passin

On 2/4/2023 10:05 AM, ^Bart wrote:

Hi guys,

On a Debian Bullseye server I have a lftp upload and after it I should 
send an email.


I thought to read the lftp log file where I have these lines:

2023-01-30 18:30:02 
/home/my_user/local_folder/upload/my_file_30-01-2023_18-30.txt -> 
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_30-01-2023_18-30.txt 0-1660576 4.92 MiB/s


2023-02-02 18:30:02 
/home/my_user/local_folder/upload/my_file_02-02-2023_18-30.txt -> 
sftp://ftp_user@ftpserver_ip:2201/remote_ftp_folder/my_file_02-02-2023_18-30.txt 0-603093 3.39 MiB/s


I'd like to use Python to check, from monday to friday (the lftp script 
runs in crontab from monday to friday) when the upload works is finished 
and I should send an email.


I could read by Python lftp.log and after it if there's a line with the 
same day of the machine I could send an email with ok otherwise the 
email will send a message with "no upload".


How could I do by Python?


Not Python, but you could run a shell script that sends the file with 
lftp, and depending on the return code uses xdg-email to send one of the 
two messages. This would probably be simpler than using Python.


Otherwise you haven't said what part of the process you need help with. 
Reading the log file?  Checking the date?  Triggering the Python script? 
 Sending the email message with Python?


For the latter, it's covered in the Python docs -

https://docs.python.org/3.10/library/email.examples.html


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


Re: Organizing modules and their code

2023-02-04 Thread Greg Ewing via Python-list

On 5/02/23 11:18 am, transreductionist wrote:

This analogy came to me the other day. For me, I would rather walk into a 
grocery store where the bananas, apples, and oranges are separated in to their 
own bins, instead of one common crate.


On the other hand, if the store has an entire aisle devoted to each
fruit, but only ever one crate of fruit in each aisle, one would think
they could make better use of their shelf space.

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


Re: Organizing modules and their code

2023-02-04 Thread transreductionist
Thank you for all the helpful replies and consideration. I do hope for other 
opinions

I would rather say it is more like engineering than art. Whether it is a matter 
of overthinking, or under thinking, is another matter. I enjoyed Dijkstra's 
letter to his colleagues on the role of scientific thought in computer 
programming. It is located at:

 https://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD447.html 

It is my academic training in physics that makes me enjoy picking up an idea 
and examining  it from all sides, and sharing thoughts with friends. Just 
inquisitive curiosity, and not a homework problem,. Thanks for the great link 
to the ETL site. That was a good read. A few years back I built a prod ETL 
application in Golang using gRPC with a multiprocessing pipeline throughout. It 
handled GB of data and was fast.

This analogy came to me the other day. For me, I would rather walk into a 
grocery store where the bananas, apples, and oranges are separated in to their 
own bins, instead of one common crate.


On Friday, February 3, 2023 at 4:18:57 PM UTC-5, transreductionist wrote:
> Here is the situation. There is a top-level module (see designs below) 
> containing code, that as the name suggests, manages an ETL pipeline. A 
> directory is created called etl_helpers that organizes several modules 
> responsible for making up the pipeline. The discussion concerns the Python 
> language, which supports OOP as well as Structural/Functional approaches to 
> programming. 
> 
> I am interested in opinions on which design adheres best to standard 
> architectural practices and the SOLID principles. I understand that this is 
> one of those topics where people may have strong opinions one way or the 
> other. I am interested in those opinions. 
> 
> Allow me to give my thoughts. First, I don't think there would be much 
> difference if I was using OOP for the functionality, or using a structural 
> paradigm. A structural paradigm in my opinion, along the lines of Rich 
> Hickey's comments on simple versus complex, would be a simpler 
> implementation. In this case there is no reason to create a construct with 
> state. So let's assume the code is structural and not OOP. 
> 
> I would go with Design I. Succinctly stated, Design I supports readability 
> and maintainability at least as well, if not better than the other designs. 
> The goal of the SOLID principles are the creation of mid-level software 
> structures that (Software Architecture: SA Martin). I think Design I best 
> adheres to these principles of: 
>  Tolerate change, 
>  Are easy to understand, and 
>  Are the basis of components that can be used in many software systems. 
> 
> I could point to the Single Responsibility Principle which is defined as (SA 
> Martin): a module should be responsible to one, and only one, actor. It 
> should satisfy the Liskov Substitution Principle as well. Further, each 
> module in the etl_helpers directory is at the same level of abstraction. 
> 
> I could also mention that as Dijkstra stressed, at every level, from the 
> smallest function to the largest component, software is like a science and, 
> therefore, is driven by falsifiability. Software architects strive to define 
> modules, components, and services that are easily falsifiable (testable). To 
> do so, they employ restrictive disciplines similar to structured programming, 
> albeit at a much higher level (SA Martin). 
> 
> One can point to multiple reasons why Design I might be preferred, but what 
> are the compelling reasons, if there are any, that would suggest another 
> design was superior. 
> 
> Finally, let me reference an interesting research paper I read recently that 
> seems to support the other designs as anti-patterns: 
> Architecture_Anti-patterns_Automatically.pdf 
> 
>  (https://www.cs.drexel.edu/~yfcai/papers/2019/tse2019.pdf) 
> 
> SEVERAL DESIGNS FOR COMPARISON 
> 
> DESIGN I: 
> 
>  manage_the_etl_pipeline.py 
>  etl_helpers 
>  extract.py 
>  transform.py 
>  load.py 
> 
> Of course one could also 
> 
> DESIGN II: 
> 
>  manage_the_etl_pipeline.py 
>  etl_helpers 
>  extract_transform_load.py 
> 
> or probably even: 
> 
> DESIGN III: 
> 
>  manage_the_etl_pipeline.py 
>  extract_transform_load.py
-- 
https://mail.python.org/mailman/listinfo/python-list


Typing Number, PyCharm

2023-02-04 Thread dn via Python-list

Do we have a typing type-hint for numbers yet?


Often wanting to combine int and float, discovered that an application 
was doing a walk-through with/for uses three numeric types. Was 
intrigued to note variance, in that the code-set features two different 
methods for typing, in this situation:


def func( value ):
...using value...

where value may be an integer, a floating-point value, or a 
complex-number (but not decimal-type).

NB code snippets from memory (cf copy-paste)


Method 1 (possibly older code):-

from typing import Union
...
def fun( value:Union[ int, float, complex ] ):


Method 2:-

def fun( value:int|float|complex  ):


Pondering this, realised could use an alias to de-clutter the 
function-definition/signature:


Method 3:-

number_type = int|float|complex
...
def fun( value:number_type  ):


If it was important to have type consistency within the union, eg 
argument and return, could go for:


Method 4:-

from typing import TypeVar
number_type = TypeVar( 'number_type', int, float, complex )
...
def fun( value:number_type  ):


Then remembered the way we'd code an execution-time check for this using 
isinstance():


Method 5:-

from numbers import Number
...
def fun( value:Number  ):


Each of these will execute correctly.

All cause PyCharm to object if I try to call the fun(ction) with a 
string parameter - and execute an exception, as expected.



Accepting all the others, am curious as to why PyCharm objects to Method 
5 with "Expected type 'SupportsFloat | SupportsComplex | complex | 
SupportsIndex', got 'Number' instead? - yet still highlights the 
erroneous string parameter but none of the 'legal' data-types?


As soon as a list (in this case types) reaches three, my aged-eyes start 
to think de-cluttering is a good idea!


Do you know of another way to attack this/more properly?

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


Re: How to read file content and send email on Debian Bullseye

2023-02-04 Thread 2QdxY4RzWzUUiLuE
On 2023-02-04 at 17:59:11 -0500,
Thomas Passin  wrote:

> On 2/4/2023 10:05 AM, ^Bart wrote:
> > Hi guys,
> > 
> > On a Debian Bullseye server I have a lftp upload and after it I should
> > send an email.

[...]

> [...] you could run a shell script that sends the file with lftp, and
> depending on the return code uses xdg-email to send one of the two
> messages. This would probably be simpler than using Python.

xdg-email appears to be for interactive use (it opens the user's
"preferred email composer"); I think sendmail would work much better
from a script.

Otherwise, I had the same initial thought, to add to and/or build a
wrapper around the existing lftp script.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to read file content and send email on Debian Bullseye

2023-02-04 Thread Thomas Passin

On 2/4/2023 10:13 PM, 2qdxy4rzwzuui...@potatochowder.com wrote:

On 2023-02-04 at 17:59:11 -0500,
Thomas Passin  wrote:


On 2/4/2023 10:05 AM, ^Bart wrote:

Hi guys,

On a Debian Bullseye server I have a lftp upload and after it I should
send an email.


[...]


[...] you could run a shell script that sends the file with lftp, and
depending on the return code uses xdg-email to send one of the two
messages. This would probably be simpler than using Python.


xdg-email appears to be for interactive use (it opens the user's
"preferred email composer"); I think sendmail would work much better
from a script.

Otherwise, I had the same initial thought, to add to and/or build a
wrapper around the existing lftp script.


I have never used it, and I did see that wording in the man page, but it 
also showed putting all the info on the command line - from, to, 
subject, etc - so I thought it might be able to use a command line 
client without needed any GUI interaction.  But I don't know for sure.


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