From cs at cskk.id.au  Sun Oct  1 02:13:12 2023
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 1 Oct 2023 17:13:12 +1100
Subject: [Tutor] Image processing
In-Reply-To: <65C5231D-2326-4F35-8C38-2EC5AB10472C@gmail.com>
References: <65C5231D-2326-4F35-8C38-2EC5AB10472C@gmail.com>
Message-ID: <ZRkN+FmdqZ+XFS75@cskk.homeip.net>

On 30Sep2023 09:12, Diana Katz <diana.katz at gmail.com> wrote:
>My daughter has voltage data points from
>A homemade ultrasound that she is trying to convert into an ultrasound 
>image. even a rudimentary picture. Is there any expert on here that can 
>help us turning voltage signals into pixels? Knowledge of some high 
>pass filtering too.

I am no expert. But in Python most numeric data processing is done with 
the scipy and numpy toolkits. You don't need to pick - scipy uses numpy, 
and things like high pass filters are part of scipy.

Maybe these links will be of some help:

Filtering Data with SciPy
https://danielmuellerkomorowska.com/2020/06/08/filtering-data-with-scipy/

High Pass Filter for Image Processing in Python using scipy/numpy
https://saturncloud.io/blog/high-pass-filter-for-image-processing-in-python-using-scipynumpy/

The reference manual for SciPy has a signal processing section:
https://docs.scipy.org/doc/scipy/reference/signal.html

which, being a reference, requires you to know what you're trying to do.  
But a lot of the pages for indivdual functions have examples at the 
bottom of using the function for various things.

Installing packages for use by your local Python is usually done with 
pip, example:

     python3 -m pip install scipy numpy matplotlib

The incantation "python3 -m pip" runs the pip module using your normal 
Python3 install. We usually use this form because it ensures that the 
packages are installed for that Python, if you've got more than one.

On Windows "python3" is, I gather, usually spelled "py3".

Feel free to ask further questions.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From jpatierno1 at yahoo.com  Fri Oct 13 22:33:58 2023
From: jpatierno1 at yahoo.com (Verizon!!)
Date: Sat, 14 Oct 2023 02:33:58 +0000 (UTC)
Subject: [Tutor] Local Coder/Tutor
References: <614734523.5877746.1697250838169.ref@mail.yahoo.com>
Message-ID: <614734523.5877746.1697250838169@mail.yahoo.com>

I'm a 67 year old retired guy that wants to learn python. I was hoping to find someone local in the Fort Lauderdale Florida area. I also have a csv datafile that I thought would be a good project to learn how to manipulate and read the data. Any help would be appreciated. I've been doing some research and reading. Sounds Like Pandas and Numpy and Anaconda. I'm excited.

From alan.gauld at yahoo.co.uk  Sat Oct 14 04:19:19 2023
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 14 Oct 2023 09:19:19 +0100
Subject: [Tutor] Local Coder/Tutor
In-Reply-To: <614734523.5877746.1697250838169@mail.yahoo.com>
References: <614734523.5877746.1697250838169.ref@mail.yahoo.com>
 <614734523.5877746.1697250838169@mail.yahoo.com>
Message-ID: <ugdiu7$2vc$1@ciao.gmane.io>

On 14/10/2023 03:33, Verizon!! via Tutor wrote:
> I'm a 67 year old retired guy that wants to learn python. 
> I was hoping to find someone local in the Fort Lauderdale Florida area.

There may be a Python user group in your area.
However, the tutor list is a Q&A style community. You ask
questions and we answer them, we don't offer 1-1 in person tutors.
 > I also have a csv datafile that I thought would be a good project

Yes, that's a fair place to start. If you are just learning the
language the csv module in the standard library will let you
read it into a tuple or dictionary. If you need to do some
heavy data processing then Pandas is a better option but has
a lot of other "stuff" that comes with it!.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




From leamhall at gmail.com  Sat Oct 14 06:06:03 2023
From: leamhall at gmail.com (Leam Hall)
Date: Sat, 14 Oct 2023 05:06:03 -0500
Subject: [Tutor] Local Coder/Tutor
In-Reply-To: <ugdiu7$2vc$1@ciao.gmane.io>
References: <614734523.5877746.1697250838169.ref@mail.yahoo.com>
 <614734523.5877746.1697250838169@mail.yahoo.com> <ugdiu7$2vc$1@ciao.gmane.io>
Message-ID: <6c7a196d-9707-c366-0e8b-ddcfc9f76aca@gmail.com>

Hey, welcome to the list!

Learning Python is pretty easy, and fun! You've done some research, and you know what a CSV file is, so that puts you ahead of the game. How much python do you know? Have you done something like Alan's tutorial (http://www.alan-g.me.uk/l2p2/index.htm)?

As Alan said, the Standard Library CSV module may give you everything you need. Once you read the data in, Python will let you do lots, even without Pandas or NumPy.

Programming is open to whatever you put into it. The code doesn't care about your age, skin tone, gender, or cultural background.

Leam

On 10/14/23 03:19, Alan Gauld via Tutor wrote:
> On 14/10/2023 03:33, Verizon!! via Tutor wrote:
>> I'm a 67 year old retired guy that wants to learn python.
>> I was hoping to find someone local in the Fort Lauderdale Florida area.
> 
> There may be a Python user group in your area.
> However, the tutor list is a Q&A style community. You ask
> questions and we answer them, we don't offer 1-1 in person tutors.
>   > I also have a csv datafile that I thought would be a good project
> 
> Yes, that's a fair place to start. If you are just learning the
> language the csv module in the standard library will let you
> read it into a tuple or dictionary. If you need to do some
> heavy data processing then Pandas is a better option but has
> a lot of other "stuff" that comes with it!.
> 

-- 
Software Engineer          (reuel.net/resume)
Scribe: The Domici War     (domiciwar.net)
General Ne'er-do-well      (github.com/LeamHall)

From phillor9 at gmail.com  Thu Oct 26 01:18:58 2023
From: phillor9 at gmail.com (Phil)
Date: Thu, 26 Oct 2023 15:18:58 +1000
Subject: [Tutor] Tkinter grid layout question
Message-ID: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>

This a customtkinter project but I expect the grid layout works exactly 
the same in standard Tkinter.

The aim is to display an image at the top left of the window and four 
direction buttons in a cross formation centred on the image and to the 
right of the image.

I've got this working through a trial and error but I'd like to know how 
I should have arrived at the same solution without all the fuss. 
Gradually increasing the label rowspan finally led to the solution.

I have a large label defined and displayed as follows:

 ??????? my_image = customtkinter.CTkImage(
 ??????????? dark_image=Image.open("background.png"), size=(250, 230)
 ??????? )


 ??????? image_label = customtkinter.CTkLabel(self, image=my_image, 
text="",fg_color="yellow")
 ??????? image_label.grid(row=0, column=0, rowspan=18, padx=10, pady=10, 
sticky="nw")

The four direction arrow buttons are as follows (I'll just show one):

 ??????? up_arrow_image = customtkinter.CTkImage(
 ??????????? dark_image=Image.open("up.png"), size=(40, 40)


 ??????? up_button = customtkinter.CTkButton(
 ??????????? self, text="", image=up_arrow_image, width=50, height=50
 ??????? )

 ??????? up_button.grid(row=0, column=4, pady=(40,0),sticky="ne")

The up_button pady=(40,0) shifts the group of buttons down so that 
they're centred to the right of the label.

I'm not confident that I've attacked the problem correctly but if the 
solution is correct then all is well.
-- 

Regards,
Phil


From alan.gauld at yahoo.co.uk  Fri Oct 27 05:08:01 2023
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 27 Oct 2023 10:08:01 +0100
Subject: [Tutor] Tkinter grid layout question
In-Reply-To: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
References: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
Message-ID: <uhfulh$k7t$1@ciao.gmane.io>

On 26/10/2023 06:18, Phil wrote:
> This a customtkinter project but I expect the grid layout works exactly 
> the same in standard Tkinter.
> 
> The aim is to display an image at the top left of the window and four 
> direction buttons in a cross formation centred on the image and to the 
> right of the image.

I don't understand this bit. How can it be centred both on
the image and to the right of it? Are there two locations
and the group can move from one to the other?

Or do you mean the buttons are positioned to the right of
the image but with the image horizontally level with the
centre of the buttons? In which case the image surely
can't be top-left? Or is it a big image, bigger than
the 4 buttons?

Can you use ASCII art to show what you are aiming for?


> I've got this working through a trial and error but I'd like to know how 
> I should have arrived at the same solution without all the fuss. 
> Gradually increasing the label rowspan finally led to the solution.

Increasing rowspan generally only works when there are
other objects in the rows being spanned, otherwise
Tk considers the empty rows as having zero size...

> I have a large label defined and displayed as follows:
> 
>  ??????? my_image = customtkinter.CTkImage(
>  ??????????? dark_image=Image.open("background.png"), size=(250, 230)
>  ??????? )
>  ??????? image_label = customtkinter.CTkLabel(self, image=my_image, 
> text="",fg_color="yellow")
>  ??????? image_label.grid(row=0, column=0, rowspan=18, padx=10, pady=10, 
> sticky="nw")

OK, That puts the image top-left spanning 18 rows. - But no columns?
I'd have expected a colspan of 3 at least(see below)

> The four direction arrow buttons are as follows (I'll just show one):
> 
>  ??????? up_arrow_image = customtkinter.CTkImage(
>  ??????????? dark_image=Image.open("up.png"), size=(40, 40)
>  ??????? up_button = customtkinter.CTkButton(
>  ??????????? self, text="", image=up_arrow_image, width=50, height=50
>  ??????? )
> 
>  ??????? up_button.grid(row=0, column=4, pady=(40,0),sticky="ne")

I would have expected column 1 if you are putting the buttons
on top of the image: 0 for the left, 1 for up/down and 2
for the right.

> The up_button pady=(40,0) shifts the group of buttons down so that 
> they're centred to the right of the label.

Again I don't really understand this. Is this an action performed
by the button or what happens when you insert it into the geometry?

> I'm not confident that I've attacked the problem correctly but if the 
> solution is correct then all is well.

Sorry, but I'm not clear what your solution is. Nor what
it is supposed to be. Maybe if you showed all of the
button grid calls it would help.

Assuming you want to superimpose the image on the buttons then
I'd expect the image to be in cell [0,0] and have row and
colspan set to 3.
Then have the buttons in cells [0,1][1,0][1,2],[2,2]

Although I'm not sure how TK handles multiple objects in
a cell, I've never tried that! I'd probably have used a Canvas
widget and drawn all the button images on that then used
then used click events on the images to trigger the events.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




From phillor9 at gmail.com  Fri Oct 27 20:40:42 2023
From: phillor9 at gmail.com (Phil)
Date: Sat, 28 Oct 2023 10:40:42 +1000
Subject: [Tutor] Tkinter grid layout question
In-Reply-To: <uhfulh$k7t$1@ciao.gmane.io>
References: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
 <uhfulh$k7t$1@ciao.gmane.io>
Message-ID: <0c15198d-acd7-4943-8d47-912f06c459c0@gmail.com>


On 27/10/23 19:08, Alan Gauld via Tutor wrote:

Thank you Alan for taking the time to reply.

> Or do you mean the buttons are positioned to the right of
> the image but with the image horizontally level with the
> centre of the buttons? In which case the image surely
> can't be top-left? Or is it a big image, bigger than
> the 4 buttons?

Yes to both.

> Can you use ASCII art to show what you are aiming for?

 ?|-------------------|? |------------------|
 ?|??????????????? ? ? ? ? |? | ? frame 2 ? ? |
 ?|??? image? ? ? ?? |? |????????? ? ? ? ? ? ? |
 ?|????????????????? ? ??? |? |??? ? ? ?? X???????? |
 ?|?? 250 x 230? ? |? |??????? X?? X ?? ?? |
 ?|???????????????????? ?? |? |????????? X??? ? ? ? |
 ?|?? frame 1?? ? ? |? |????????????????????? |
 ?|-------------------|? |------------------|

The Xes represent the four direction buttons. There is a label
in the blank space between the up and down buttons that shows
which button was pressed.

I thought about using two frames when the positioning of the
buttons became difficult but I persisted. The buttons kept
splitting apart until I hit upon the idea of using rowspan on
image. I thought this was a bogie idea, but it worked and I didn't
really understand the reason why it worked, hence my message
to the list.

Using two frames is a far better approach which worked
without any editing at all. Just a bit of copying and pasting
from the original code.

Of course I don't know what use I can put to, it was just an exercise to 
create an image to put on a button.

By the way, each button is 50 x 50 and not the usual rectangular shape.

-- 
Regards,
Phil

From alan.gauld at yahoo.co.uk  Sat Oct 28 08:09:33 2023
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 28 Oct 2023 13:09:33 +0100
Subject: [Tutor] Tkinter grid layout question
In-Reply-To: <0c15198d-acd7-4943-8d47-912f06c459c0@gmail.com>
References: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
 <uhfulh$k7t$1@ciao.gmane.io> <0c15198d-acd7-4943-8d47-912f06c459c0@gmail.com>
Message-ID: <uhitlt$5o7$1@ciao.gmane.io>

On 28/10/2023 01:40, Phil wrote:

>> Can you use ASCII art to show what you are aiming for?
> 
>  ?|-------------------|? |------------------|
>  ?|??????????????? ? ? ? ? |? | ? frame 2 ? ? |
>  ?|??? image? ? ? ?? |? |????????? ? ? ? ? ? ? |
>  ?|????????????????? ? ??? |? |??? ? ? ?? X???????? |
>  ?|?? 250 x 230? ? |? |??????? X?? X ?? ?? |
>  ?|???????????????????? ?? |? |????????? X??? ? ? ? |
>  ?|?? frame 1?? ? ? |? |????????????????????? |
>  ?|-------------------|? |------------------|

Unfortunately that hasn't worked.

Can you strip out all code except the UI layout and just
post it, that might be simplest.

I'm kind of intrigued to see
a) exactly what you are trying to do
and
b) How it might be done most elegantly in Tkinter


> Using two frames is a far better approach which worked
> without any editing at all. Just a bit of copying and pasting
> from the original code.

Again, I'm not sure how that would work.

> By the way, each button is 50 x 50 and not the usual rectangular shape.

That shouldn't be an issue.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




From phillor9 at gmail.com  Sat Oct 28 20:02:56 2023
From: phillor9 at gmail.com (Phil)
Date: Sun, 29 Oct 2023 10:02:56 +1000
Subject: [Tutor] Tkinter grid layout question
In-Reply-To: <uhitlt$5o7$1@ciao.gmane.io>
References: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
 <uhfulh$k7t$1@ciao.gmane.io> <0c15198d-acd7-4943-8d47-912f06c459c0@gmail.com>
 <uhitlt$5o7$1@ciao.gmane.io>
Message-ID: <1220f115-8597-4437-bcf6-f7d8295f7c14@gmail.com>


On 28/10/23 22:09, Alan Gauld via Tutor wrote:
>>   ?|-------------------|? |------------------|
>>   ?|??????????????? ? ? ? ? |? | ? frame 2 ? ? |
>>   ?|??? image? ? ? ?? |? |????????? ? ? ? ? ? ? |
>>   ?|????????????????? ? ??? |? |??? ? ? ?? X???????? |
>>   ?|?? 250 x 230? ? |? |??????? X?? X ?? ?? |
>>   ?|???????????????????? ?? |? |????????? X??? ? ? ? |
>>   ?|?? frame 1?? ? ? |? |????????????????????? |
>>   ?|-------------------|? |------------------|
> Unfortunately that hasn't worked.
So I see. It was correct at the sending end and it sort of demonstrates 
the interaction of the button group layout with image to group's left . 
Except that the button layout was mangled vertically and not 
horizontally. If you copy my diagram to a text editor and move the 
vertical characters so that they are in line vertically then you'll see 
two frames and a button group.
>
> Can you strip out all code except the UI layout and just
> post it, that might be simplest.

There really isn't any other code, it's just one app class and nothing 
else. It amounts to 96 lines.

>> Using two frames is a far better approach which worked
>> without any editing at all. Just a bit of copying and pasting
>> from the original code.
> Again, I'm not sure how that would work.

I'm more confident now that using two frames is the best and simplest 
method. The image is displayed in one frame and the button group is 
displayed in the second frame. There is no interaction between the 
frames. The image can be increased or reduced to any odd size, 
vertically or horizontally, without any movement of the buttons in the 
other frame. Just using one frame for the buttons or the image would 
probably work just as well.

>> By the way, each button is 50 x 50 and not the usual rectangular shape.
> That shouldn't be an issue.

I was just remarking that the button group size is a multiple of the 
image's vertical size but not the same size. I found that by reducing 
the size of the image by about 1/8 then the buttons returned to their 
desired layout.

Anyway, the two fame method works perfectly and I think this thread 
should probably be closed for the sanity of others. Thank you again Alan 
for your time.

-- 
Regards,
Phil

From alan.gauld at yahoo.co.uk  Sun Oct 29 04:48:25 2023
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sun, 29 Oct 2023 08:48:25 +0000
Subject: [Tutor] Tkinter grid layout question
In-Reply-To: <1220f115-8597-4437-bcf6-f7d8295f7c14@gmail.com>
References: <a7534e90-1de9-4f26-a90d-1b7ea56c8ed1@gmail.com>
 <uhfulh$k7t$1@ciao.gmane.io> <0c15198d-acd7-4943-8d47-912f06c459c0@gmail.com>
 <uhitlt$5o7$1@ciao.gmane.io> <1220f115-8597-4437-bcf6-f7d8295f7c14@gmail.com>
Message-ID: <uhl68p$v07$1@ciao.gmane.io>

On 29/10/2023 01:02, Phil wrote:

> horizontally. If you copy my diagram to a text editor and move the 
> vertical characters so that they are in line vertically then you'll see 
> two frames and a button group.

Yes, I thought of that later and understand your aim now.

> It amounts to 96 lines.

For future reference that would have been fine to just post
in the message, around 100 lines is about the limit. And
having the code is always better than guessing.

>>> Using two frames is a far better approach which worked

Having seen what you wanted to do I agree. Two frames is the best
approach. I actually thought you wanted to overlay the buttons
on top of the image. That would have been harder with 2 Frames.

> Anyway, the two fame method works perfectly and I think this thread 
> should probably be closed for the sanity of others. 

Yes, that's fine.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




From sjeik_appie at hotmail.com  Sun Oct 29 10:27:51 2023
From: sjeik_appie at hotmail.com (Albert-Jan Roskam)
Date: Sun, 29 Oct 2023 15:27:51 +0100
Subject: [Tutor] Multiprocessing question
Message-ID: <DB9PR10MB6689B282CD67CA21F334458E83A2A@DB9PR10MB6689.EURPRD10.PROD.OUTLOOK.COM>

   Hi,
   I'm trying to create multiprocessing task that runs multiple SQL queries
   in parallel (COPY TO csv), then adds those csv files to a zip. In the code
   below, tge csv files don't end up in the zip. Why not?
   I'm using a buffer instead of a file for the zip because in my actual
   scenario, a Flask endpoint returns the .zip
   Thanks in advance!
   Albert-Jan
   import io
   import logging
   import multiprocessing as mp
   #from multiprocessing.shared_memory import SharedMemory
   from random import randint
   from time import sleep
   from zipfile import ZipFile, ZIP_DEFLATED
   mp.log_to_stderr(logging.DEBUG)
   def task(lock, archive):
       # Do some work in parellel (SQL), followed
       # by adding the query result to a zip
       name = mp.current_process().name
       print(f"==begin {name}")
       sleep(randint(1, 5))
       csv_buff = io.BytesIO(b"name = " + name.encode("utf-8"))
       with lock:
           print(f"* begin zipping {name}")
           sleep(randint(1, 5))
           data = csv_buff.getvalue()
           print("csv data", data)
           archive.writestr(name, data)
           print(f"* end zipping {name}")
       print(f"==end {name}")
   def main():
       #shm = SharedMemory(create=True, size=2048) # read-only! :-(
       #zip_buff = shm.buf
       zip_buff = io.BytesIO()
       archive = ZipFile(zip_buff, "w", ZIP_DEFLATED, False, 2)
       lock = mp.Lock()
       procs = [mp.Process(target=task, args=(lock, archive)) for _ in
   range(3)]
       for proc in procs:
           proc.start()
       for proc in procs:
           proc.join()
       with archive:
           archive.writestr("main", b"from main")
       zip_buff.seek(0)
       data = zip_buff.getvalue()
       assert len(data), "No data!"
       print("data:", data)

       with open("archive.zip", mode="wb") as archive:
           archive.write(data)
   if __name__ == "__main__":
       main()

From sjeik_appie at hotmail.com  Sun Oct 29 10:39:56 2023
From: sjeik_appie at hotmail.com (Albert-Jan Roskam)
Date: Sun, 29 Oct 2023 15:39:56 +0100
Subject: [Tutor] Multiprocessing question
In-Reply-To: <DB9PR10MB6689B282CD67CA21F334458E83A2A@DB9PR10MB6689.EURPRD10.PROD.OUTLOOK.COM>
Message-ID: <DB9PR10MB6689D3C40CA6EB1B26C90A4A83A2A@DB9PR10MB6689.EURPRD10.PROD.OUTLOOK.COM>

   By the way, I should have added that I'm using Python 3.8. The test script
   was written on Linux Debian Jesse. Target system is RHEL 8.
   So no Windows involved!
   On Oct 29, 2023 15:27, Albert-Jan Roskam <sjeik_appie at hotmail.com> wrote:

        Hi,
        I'm trying to create multiprocessing task that runs multiple SQL
     queries
        in parallel (COPY TO csv), then adds those csv files to a zip. In the
     code
        below, tge csv files don't end up in the zip. Why not?
        I'm using a buffer instead of a file for the zip because in my actual
        scenario, a Flask endpoint returns the .zip
        Thanks in advance!
        Albert-Jan
        import io
        import logging
        import multiprocessing as mp
        #from multiprocessing.shared_memory import SharedMemory
        from random import randint
        from time import sleep
        from zipfile import ZipFile, ZIP_DEFLATED
        mp.log_to_stderr(logging.DEBUG)
        def task(lock, archive):
            # Do some work in parellel (SQL), followed
            # by adding the query result to a zip
            name = mp.current_process().name
            print(f"==begin {name}")
            sleep(randint(1, 5))
            csv_buff = io.BytesIO(b"name = " + name.encode("utf-8"))
            with lock:
                print(f"* begin zipping {name}")
                sleep(randint(1, 5))
                data = csv_buff.getvalue()
                print("csv data", data)
                archive.writestr(name, data)
                print(f"* end zipping {name}")
            print(f"==end {name}")
        def main():
            #shm = SharedMemory(create=True, size=2048) # read-only! :-(
            #zip_buff = shm.buf
            zip_buff = io.BytesIO()
            archive = ZipFile(zip_buff, "w", ZIP_DEFLATED, False, 2)
            lock = mp.Lock()
            procs = [mp.Process(target=task, args=(lock, archive)) for _ in
        range(3)]
            for proc in procs:
                proc.start()
            for proc in procs:
                proc.join()
            with archive:
                archive.writestr("main", b"from main")
            zip_buff.seek(0)
            data = zip_buff.getvalue()
            assert len(data), "No data!"
            print("data:", data)

            with open("archive.zip", mode="wb") as archive:
                archive.write(data)
        if __name__ == "__main__":
            main()
     _______________________________________________
     Tutor maillist  -  Tutor at python.org
     To unsubscribe or change subscription options:
     https://mail.python.org/mailman/listinfo/tutor

From nadeem_559 at yahoo.com  Tue Oct 31 07:43:35 2023
From: nadeem_559 at yahoo.com (nadeem nan)
Date: Tue, 31 Oct 2023 11:43:35 +0000 (UTC)
Subject: [Tutor] Help with storing a variable
References: <753023326.1800082.1698752615619.ref@mail.yahoo.com>
Message-ID: <753023326.1800082.1698752615619@mail.yahoo.com>

Hi Alan,
I hope you are doing well. I am a beginner at Python and as a practice trying to code a rental property management application using tkinter/ttkbootstrap as GUI and MS Excel to store the data.
In the application, the end user (here the property agent) can add tenants and their details, properties, rent etc. What I am trying to do is whenever the user adds a new tenant via the user interface, it will generate a tenant-code like MR0001 for a male tenant or MS0001??for a female tenant and the numbers would increment as more tenants are added.?
I was wondering how would I go about storing this tenant-code so when the user returns to the application to add more tenants the tenant-code is incremented from where it was left.
My idea is to store a variable for tenant-code some where in the excel sheet where the tenants data is being saved. This variable can be then accessed when the application is used and incremented accordingly. Do you think this idea would work or if you have a better and efficient way, please let me know.
I haven't started coding yet but just gathering ideas on paper. Any help will be much appreciated.
I look forward to hearing from you soon.

Regards,
Nadeem Nan
?

??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

From alan.gauld at yahoo.co.uk  Tue Oct 31 20:41:33 2023
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 1 Nov 2023 00:41:33 +0000
Subject: [Tutor] Help with storing a variable
In-Reply-To: <753023326.1800082.1698752615619@mail.yahoo.com>
References: <753023326.1800082.1698752615619.ref@mail.yahoo.com>
 <753023326.1800082.1698752615619@mail.yahoo.com>
Message-ID: <uhs6rt$hoc$1@ciao.gmane.io>

On 31/10/2023 11:43, nadeem nan via Tutor wrote:
> Hi Alan,

Hi. but there are quite a few others here to help too! :-)

> I was wondering how would I go about storing this tenant-code 
> so when the user returns to the application to add more tenants 
> the tenant-code is incremented from where it was left.

There are several ways to do this but your idea of saving it as a
special field in the Excel spreadsheet is OK.

I would say that this project sounds more suited to a database
(such as SQLite) than a spreadsheet however, but the principles
are the same. (A database handles this particular problem
automatically, by maintaining its own unique identifiers etc
and makes retrieving data much easier than using a spreadsheet.)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




From threesomequarks at proton.me  Tue Oct 31 21:48:10 2023
From: threesomequarks at proton.me (ThreeBlindQuarks)
Date: Wed, 01 Nov 2023 01:48:10 +0000
Subject: [Tutor] Help with storing a variable
In-Reply-To: <753023326.1800082.1698752615619@mail.yahoo.com>
References: <753023326.1800082.1698752615619.ref@mail.yahoo.com>
 <753023326.1800082.1698752615619@mail.yahoo.com>
Message-ID: <lSHxLGj5NnChDaZoVNemqjBNCutWIkD_csxRz88X0KzSTqqL7rC2OURN0Oi9mybzgomlHIl9tJWzMzvyhL2QN_oUS4IOdS_QWXWSchmZjLk=@proton.me>


NN,

Your question is wide open with many possible solutions.

You say you are storing (presumably reading in if a specific EXCEL file exists, and the updating or rewriting it) so clearly the obvious place is the same file. This would allow portability.

Allen has already suggested a database for all the data as a better alternative but that could require the machine you store it on be known and have the right software.

Do note that handling EXCEL files requires one of many modules that would need to be available and reading just a part of a sheet for data and another for stored variables has some drawbacks. You may want to consider having two or more tabs with one being the current data and another one or more containing other info or even the backup of the data before you updated it.

There are many in-between solutions to consider which can include saving info in multiple text files with perhaps one in CSV format, or even hiding the saved data in a comment in such a file to keep them together. Other options let you save data in text or binary files in ways that can easily be retrieved. Some are much faster to work with than EXCEL or easier to update perhaps in place and to work with any other programs that may need to interoperate with your data.

You may know about your needs and choose what works. My first choice would not be EXCEL unless someone needs to be able to access it certain ways or update it.









Sent with Proton Mail secure email.

------- Original Message -------
On Tuesday, October 31st, 2023 at 7:43 AM, nadeem nan via Tutor <tutor at python.org> wrote:


> Hi Alan,
> I hope you are doing well. I am a beginner at Python and as a practice trying to code a rental property management application using tkinter/ttkbootstrap as GUI and MS Excel to store the data.
> In the application, the end user (here the property agent) can add tenants and their details, properties, rent etc. What I am trying to do is whenever the user adds a new tenant via the user interface, it will generate a tenant-code like MR0001 for a male tenant or MS0001 for a female tenant and the numbers would increment as more tenants are added.
> I was wondering how would I go about storing this tenant-code so when the user returns to the application to add more tenants the tenant-code is incremented from where it was left.
> My idea is to store a variable for tenant-code some where in the excel sheet where the tenants data is being saved. This variable can be then accessed when the application is used and incremented accordingly. Do you think this idea would work or if you have a better and efficient way, please let me know.
> I haven't started coding yet but just gathering ideas on paper. Any help will be much appreciated.
> I look forward to hearing from you soon.
> 
> Regards,
> Nadeem Nan
> 
> 
> 
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor