From lyonmatt13 at gmail.com  Tue Nov  1 14:29:50 2022
From: lyonmatt13 at gmail.com (Matt Lyon)
Date: Tue, 1 Nov 2022 15:29:50 -0300
Subject: [Tutor] Tkinter isn't working on Beagle Bone Black
Message-ID: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>

Hello,
I'm having trouble running tkinter on my beagle bone black. I'm using the
BBB through debian. I'm using python3 and pip3 for commands.

ssh debian at beaglebone.local.

I downloaded Tkinter with this command

pip3 install tk

Here's the list of libraries on my beaglebone.

*debian at beaglebone*:*~*$ pip3 list

Package                          Version

-------------------------------- -------

Adafruit-BBIO                    1.2.0

Adafruit-Blinka                  8.5.0

adafruit-circuitpython-busdevice 5.2.3

adafruit-circuitpython-requests  1.12.8

adafruit-circuitpython-typing    1.8.2

Adafruit-PlatformDetect          3.31.0

Adafruit-PureIO                  1.1.9

Click                            7.0

colorama                         0.3.7

cycler                           0.11.0

decorator                        4.3.0

distro                           1.3.0

Flask                            1.0.2

fonttools                        4.38.0

itsdangerous                     0.24

Jinja2                           2.10

kiwisolver                       1.4.4

MarkupSafe                       1.1.0

matplotlib                       3.5.3

numpy                            1.21.6

packaging                        21.3

pandas                           1.3.5

Pillow                           9.3.0

pip                              18.1

pyctrl                           0.4.3

pyftdi                           0.54.0

pyparsing                        3.0.9

pyserial                         3.5

python-dateutil                  2.8.2

pytz                             2022.5

pyusb                            1.2.1

rcpy                             0.5.1

scipy                            1.1.0

setuptools                       40.8.0

six                              1.16.0

tk                               0.1.0

typing-extensions                4.4.0

Werkzeug                         0.14.1

wheel                            0.32.3

I'm not sure if I need to download another package or if I need to set up
some link between my BBB and PC.Whenever I try to run a program with
tkinter I get:

ModuleNotFoundError: No module named 'tkinter'


I appreciate any help you can give me.


Thanks


Matt Lyon


lyonmatt13 at gmail.com

From alan.gauld at yahoo.co.uk  Tue Nov  1 20:35:57 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 2 Nov 2022 00:35:57 +0000
Subject: [Tutor] Tkinter isn't working on Beagle Bone Black
In-Reply-To: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>
References: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>
Message-ID: <tjse1d$sda$1@ciao.gmane.io>

On 01/11/2022 18:29, Matt Lyon wrote:
> Hello,
> I'm having trouble running tkinter on my beagle bone black. I'm using the
> BBB through debian. I'm using python3 and pip3 for commands.

Caveat: I have no idea what Beagle Bone Black is...

> I downloaded Tkinter with this command
> 
> pip3 install tk

Thats probably not tkinter, its probably Tk the underlying
Tcl/Tk library.

You need something like python3-tk or tkinter or somesuch
(I don't have a Linux box fired up at the moment!)

> Here's the list of libraries on my beaglebone.
> I'm not sure if I need to download another package or if I need to set up
> some link between my BBB and PC.Whenever I try to run a program with
> tkinter I get:
> 
> ModuleNotFoundError: No module named 'tkinter'

You need to install tkinter.
But I'd use the apt tool if possible. Pip is OK but I
always found the software update tools in Linux to be
simpler/safer.

-- 
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 eryksun at gmail.com  Tue Nov  1 21:56:45 2022
From: eryksun at gmail.com (Eryk Sun)
Date: Tue, 1 Nov 2022 20:56:45 -0500
Subject: [Tutor] Tkinter isn't working on Beagle Bone Black
In-Reply-To: <tjse1d$sda$1@ciao.gmane.io>
References: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>
 <tjse1d$sda$1@ciao.gmane.io>
Message-ID: <CACL+1at0qXawO0fw_YW+dEJrGWiMsXgfZQ_W8HCb7M_bhhYNjg@mail.gmail.com>

On 11/1/22, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> You need to install tkinter.
> But I'd use the apt tool if possible. Pip is OK but I
> always found the software update tools in Linux to be
> simpler/safer.

tkinter is part of Python's standard library and has to be installed
via the system package manager or, on Windows, by enabling the
tkinter/IDLE component of the installer. There is no "tkinter" package
on PyPI. The "tk" package is TensorKit, which is apparently a deep
learning helper between Python and C++. It has nothing to do with the
Tk GUI toolkit.

From wlfraed at ix.netcom.com  Wed Nov  2 16:52:03 2022
From: wlfraed at ix.netcom.com (Dennis Lee Bieber)
Date: Wed, 02 Nov 2022 16:52:03 -0400
Subject: [Tutor] Tkinter isn't working on Beagle Bone Black
References: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>
 <tjse1d$sda$1@ciao.gmane.io>
Message-ID: <knk5mh9ohcv0if8qg2o7lk13lajpj40u4i@4ax.com>

On Wed, 2 Nov 2022 00:35:57 +0000, Alan Gauld via Tutor <tutor at python.org>
declaimed the following:

>On 01/11/2022 18:29, Matt Lyon wrote:
>> Hello,
>> I'm having trouble running tkinter on my beagle bone black. I'm using the
>> BBB through debian. I'm using python3 and pip3 for commands.
>
>Caveat: I have no idea what Beagle Bone Black is...
>

	Consider it a less advertised competitor to a Raspberry Pi -- both run
variants of Debian -- but with more GPIO and onboard ADC and PWM (ie:
analog I/O). And with PRU (programmable real-time unis) for creating
dedicated I/O protocols
https://beagleboard.org/black
https://beagleboard.org/ai
https://beagleboard.org/ai-64

	I have two Blacks and one AI (but then, I also have three or four
Propeller microcontrollers (weird concept -- no interrupts, but 8
sequential cores so one uses a core to implement drivers for things that
would be interrupts in other systems), something like four Arduinos and two
AdaFruit Metro (running CircuitPython), and ancient overpriced BASIC
Stamps.


>
>You need something like python3-tk or tkinter or somesuch
>(I don't have a Linux box fired up at the moment!)
>
	For the OP, this is the listing from apt for tkinter

debian at beaglebone:~$ apt search tkinter
Sorting... Done
Full Text Search... Done
idle/oldstable 3.7.3-1 all
  IDE for Python using Tkinter (default version)

idle-python2.7/oldstable 2.7.16-2+deb10u1 all
  IDE for Python (v2.7) using Tkinter

idle-python3.7/oldstable 3.7.3-2+deb10u3 all
  IDE for Python (v3.7) using Tkinter

idle3/oldstable 3.7.3-1 all
  IDE for Python using Tkinter (transitional package)

libsnack-alsa/oldstable 2.2.10.20090623-dfsg-8 armhf
  Sound extension to Tcl/Tk and Python/Tkinter - ALSA files

libsnack-oss/oldstable 2.2.10.20090623-dfsg-8 armhf
  Sound extension to Tcl/Tk and Python/Tkinter - OSS files

pypy-tk/oldstable 7.0.0+dfsg-3 armhf
  Tkinter module for PyPy (an alternative Python interpreter)

pypy3-tk/oldstable 7.0.0+dfsg-3 armhf
  Tkinter module for PyPy (an alternative Python 3.x interpreter)

python-tk/oldstable 2.7.16-2 armhf
  Tkinter - Writing Tk applications with Python2

python-tk-dbg/oldstable 2.7.16-2 armhf
  Tkinter - Writing Tk applications with Python2 (debug extension)

python-tksnack/oldstable 2.2.10.20090623-dfsg-8 all
  Sound extension to Tcl/Tk and Python/Tkinter - Python 2.x library

python-tktreectrl/oldstable 2.0.2-1 all
  Tkinter-based wrapper for Tk TreeCtrl

python3-tk/oldstable 3.7.3-1 armhf
  Tkinter - Writing Tk applications with Python 3.x

python3-tk-dbg/oldstable 3.7.3-1 armhf
  Tkinter - Writing Tk applications with Python 3.x (debug extension)

python3-tksnack/oldstable 2.2.10.20090623-dfsg-8 all
  Sound extension to Tcl/Tk and Python/Tkinter - Python 3.x library

python3-tktreectrl/oldstable 2.0.2-1 all
  Tkinter-based wrapper for Tk TreeCtrl for Python 3

tcl-snack/oldstable 2.2.10.20090623-dfsg-8 armhf
  Sound extension to Tcl/Tk and Python/Tkinter - Tcl/Tk library

tcl-snack-dev/oldstable 2.2.10.20090623-dfsg-8 armhf
  Sound extension to Tcl/Tk and Python/Tkinter - development files

tcl-snack-doc/oldstable 2.2.10.20090623-dfsg-8 all
  Sound extension to Tcl/Tk and Python/Tkinter - documentation

(I'm still running

debian at beaglebone:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

... should probably update -- they have images for bullseye available)


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/


From mats at wichmann.us  Wed Nov  2 17:15:47 2022
From: mats at wichmann.us (Mats Wichmann)
Date: Wed, 2 Nov 2022 15:15:47 -0600
Subject: [Tutor] Tkinter isn't working on Beagle Bone Black
In-Reply-To: <CACL+1at0qXawO0fw_YW+dEJrGWiMsXgfZQ_W8HCb7M_bhhYNjg@mail.gmail.com>
References: <CALeLg4tj+di7EXDP46eVj4UQfL-MtCrCnRLhm4iC-YXJcDCyGw@mail.gmail.com>
 <tjse1d$sda$1@ciao.gmane.io>
 <CACL+1at0qXawO0fw_YW+dEJrGWiMsXgfZQ_W8HCb7M_bhhYNjg@mail.gmail.com>
Message-ID: <d0f88fc2-1cd3-c079-c264-9271e13c4531@wichmann.us>

On 11/1/22 19:56, Eryk Sun wrote:
> On 11/1/22, Alan Gauld via Tutor <tutor at python.org> wrote:
>>
>> You need to install tkinter.
>> But I'd use the apt tool if possible. Pip is OK but I
>> always found the software update tools in Linux to be
>> simpler/safer.
> 
> tkinter is part of Python's standard library and has to be installed
> via the system package manager or, on Windows, by enabling the
> tkinter/IDLE component of the installer. There is no "tkinter" package
> on PyPI. The "tk" package is TensorKit, which is apparently a deep
> learning helper between Python and C++. It has nothing to do with the
> Tk GUI toolkit.

debian calls the package python3-tk




From samiraeastcoast at gmail.com  Wed Nov  2 15:39:12 2022
From: samiraeastcoast at gmail.com (samira khoda)
Date: Wed, 2 Nov 2022 16:39:12 -0300
Subject: [Tutor] How to change the values in python code?
Message-ID: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>

Hi

Could you please help me to understand why the code below does not work? I
am trying to read a txt.file line by line that has integer timestamp
values, the last number should be compared to the previous number.

And then split it where the value of the last is less than previous. But
when I run the code prints 0 for previous in each line which technically
says should not be split anywhere. I did a manual check up and I know there
are various spots that the split should happen.

How can I make the value of the previous update to the value of the
previous timestamp and not stay zero for every line?

Thanks in advance

Sam

Import pandas as pd
previous=0
i=0
data=open('time-.txt', mode="r")

for line in data:

    x=line.split(", ")
    last=int(x[7])

if last < previous :
    print("split here"+i)
    previous=last
    i=i+1

 #end the loop

From mats at wichmann.us  Wed Nov  2 19:48:07 2022
From: mats at wichmann.us (Mats Wichmann)
Date: Wed, 2 Nov 2022 17:48:07 -0600
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
Message-ID: <d88e3486-cbe5-f2b8-8f22-6ab848356755@wichmann.us>

On 11/2/22 13:39, samira khoda wrote:
> Hi
> 
> Could you please help me to understand why the code below does not work? I
> am trying to read a txt.file line by line that has integer timestamp
> values, the last number should be compared to the previous number.
> 
> And then split it where the value of the last is less than previous. But
> when I run the code prints 0 for previous in each line which technically
> says should not be split anywhere. I did a manual check up and I know there
> are various spots that the split should happen.
> 
> How can I make the value of the previous update to the value of the
> previous timestamp and not stay zero for every line?
> 
> Thanks in advance
> 
> Sam
> 
> Import pandas as pd
> previous=0
> i=0
> data=open('time-.txt', mode="r")
> 
> for line in data:
> 
>      x=line.split(", ")
>      last=int(x[7])
> 
> if last < previous :

as long as "last" can't be negative, it can never be less than previous, 
since you initialized previous to 0.

>      print("split here"+i)
>      previous=last
>      i=i+1
> 
>   #end the loop
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


From alan.gauld at yahoo.co.uk  Wed Nov  2 20:03:35 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 3 Nov 2022 00:03:35 +0000
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
Message-ID: <tjv0go$76o$1@ciao.gmane.io>

On 02/11/2022 19:39, samira khoda wrote:

> And then split it where the value of the last is less than previous. But
> when I run the code prints 0 for previous 

You never print previous.

in each line which technically
> says should not be split anywhere. I did a manual check up and I know there
> are various spots that the split should happen.


It might help if you post a few lines of sample data including some
lines where the last < previous and others where it is not.
> 
> How can I make the value of the previous update to the value of the
> previous timestamp and not stay zero for every line?

There are seeral issues in your code:

> Import pandas as pd

That should be lower ase import. Please post actual code not
retyped. It avoids wasting time on typos that don't exist
in the real thing.

> previous=0
> i=0
> data=open('time-.txt', mode="r")

Notice that there is no value for last at this point.

> for line in data:
>     x=line.split(", ")
>     last=int(x[7])

You assign it here but if the file were empty it would not exist.

However, as written, this is your complete loop.
You simply iterate over each line in the file then exit the
loop with last assigned to the 8th field of the last line.
What does the last line of your data look like?
It must have at least 8 fields or you'd get an error...
But the fields could be from any old string. Of course there
must be a number or the int() call would fail. But is it valid?

> if last < previous :

Now you never changed previous during the loop so it is still 0.
and last is the value from the last line of the file.
So the if block will only execute if the last value is negative.
Is that likely?

>     print("split here"+i)

i is never changed in the loop either so i is also zero.
But i is not previous!

>     previous=last
>     i=i+1

These lines change the variables but its too late, we are
at the end of the code.

And worryingly you have not closed the file.

Things to change?
1) Use a with statement for opening the file - then you don't
need to worry about closing it.

2) Move the if statement and block inside the loop.
But consider whether you really only want the previous
and i increment to be done when last < previous?

3) put more print statements in. Especially put
in

print("last = ", last)
print("previous = ", previous)

Just before the if statement.

-- 
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 nathan-tech at hotmail.com  Thu Nov  3 13:35:01 2022
From: nathan-tech at hotmail.com (Nathan Smith)
Date: Thu, 3 Nov 2022 17:35:01 +0000
Subject: [Tutor] syntax parsing and ast
Message-ID: <DB7PR07MB5093A70EA1AECC56E08333B6E4389@DB7PR07MB5093.eurprd07.prod.outlook.com>

Hi guys,


I'm hoping someone can give me direction here (this is not to do with my 
main project which I mentioned a little while ago and turned out to be 
unrelated to what I suspected) typical.


This time I want to parse code of another language into python.

It's not a mainstream language and is relatively simple in that in that 
it has only a couple of rules:

1. Everything can be a considered a function.

2. There is a small number of builtins (about 50 in total).

3. It uses spaces to separate arguments, unless a space is needed in 
which case the argument is inclosed in brackets like so: {arg with 
spaces} {arg 2 with spaces}


I want to pass this into some objects that would allow a tree like so:

main

 ? main.func1

 ? main.func2

main2:

 ? main.if

 ??? main.func4


I was thinking ast maybe be the way to go about this, and perhaps rejex 
for syntax matching, but beyond that I may need some pointers.


thanks in advance for anything you can offer in the way of help.

-- 

Best Wishes,

Nathan Smith, BSC


My Website: https://nathantech.net



From Steve.Flynn at capita.com  Thu Nov  3 14:07:48 2022
From: Steve.Flynn at capita.com (Flynn, Stephen (Life & Pensions))
Date: Thu, 3 Nov 2022 18:07:48 +0000
Subject: [Tutor] syntax parsing and ast
In-Reply-To: <DB7PR07MB5093A70EA1AECC56E08333B6E4389@DB7PR07MB5093.eurprd07.prod.outlook.com>
References: <DB7PR07MB5093A70EA1AECC56E08333B6E4389@DB7PR07MB5093.eurprd07.prod.outlook.com>
Message-ID: <LO2P265MB5470EEC98A064585EB5BECEE97389@LO2P265MB5470.GBRP265.PROD.OUTLOOK.COM>

There are a number of parsers already built as libraries - I strongly recommend you take a look at some of them ,have a play and see which one suits your application.

A pretty comprehensive list is kept (up-to-date too) on Github in the webmaven/python-parsing-tools repo.

S.

-----Original Message-----
From: Tutor <tutor-bounces+steve.flynn=capita.co.uk at python.org> On Behalf Of Nathan Smith
Sent: Thursday, November 3, 2022 5:35 PM
To: tutor <tutor at python.org>
Subject: [Tutor] syntax parsing and ast

**EXTERNAL**

Hi guys,


I'm hoping someone can give me direction here (this is not to do with my main project which I mentioned a little while ago and turned out to be unrelated to what I suspected) typical.


This time I want to parse code of another language into python.

It's not a mainstream language and is relatively simple in that in that it has only a couple of rules:

1. Everything can be a considered a function.

2. There is a small number of builtins (about 50 in total).

3. It uses spaces to separate arguments, unless a space is needed in which case the argument is inclosed in brackets like so: {arg with spaces} {arg 2 with spaces}


I want to pass this into some objects that would allow a tree like so:

main

   main.func1

   main.func2

main2:

   main.if

     main.func4


I was thinking ast maybe be the way to go about this, and perhaps rejex for syntax matching, but beyond that I may need some pointers.


thanks in advance for anything you can offer in the way of help.

--

Best Wishes,

Nathan Smith, BSC


My Website: https://nathantech.net


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


This message has been scanned by Capita systems, but if you believe it to be spam, please send it to spam at forcepoint.com.

Messages sent to spam at forcepoint.com are queued for email analysis by Forcepoint Threat Lab.
This email originates from outside of Capita.
Keep this in mind before responding, opening attachments or clicking any links. Unless you recognise the sender and know the content is safe.
If in any doubt, the grammar and spelling are poor, or the name doesn't match the email address then please contact the sender via an alternate known method.



This email is security checked and subject to the disclaimer on web-page: https://www.capita.com/email-disclaimer.aspx

From PythonList at DancesWithMice.info  Thu Nov  3 20:26:59 2022
From: PythonList at DancesWithMice.info (dn)
Date: Fri, 4 Nov 2022 13:26:59 +1300
Subject: [Tutor] Challenge-week 4: Groups of solutions, starts today!
Message-ID: <c8881dae-741d-3e54-00d7-3fabd4bb8d78@DancesWithMice.info>

A virtual event run by the Auckland Branch of the New Zealand Python 
Users' Group. Details from the Meetup site: 
https://www.meetup.com/nzpug-auckland/events/289531194/ where you may 
also sign-up.


It's Week 4 of the Smart Iterator Challenge! We've looked at taking our 
early results and generalising them to suit various solutions. The next 
view is how a range of similar solutions might be grouped - and 
re-shaped to enable us to re-use and share code.

We commence with a review of Challenge-week 3 and sample-code to 
download and compare with your own efforts. This time there is no 
tutorial-content. Even the provided testing/proofs are rather sparse - 
and really only there to make sure you're on-the-right-track. In many 
ways, the challenge is not so much writing code, as it is designing 
code-solutions. Putting code-modules together, and then pulling them 
apart to satisfy groups of solutions. Ooh mysterious!


This Challenge will interest Python-Journeymen, and Python-Apprentices 
ready to move-on from ?the basics?. As usual, there are "Extra Credit" 
challenges which will 'push' Python-Masters and advanced Journeymen.

It's not a requirement that you have completed the previous challenges - 
but they will help. Challenge-week 4 starts with either your own or a 
provided template-script. So, you don't have to have completed 
Challenge-weeks 1, 2, and 3 (but it would help - there's nothing to stop 
you from 'catching up' and gaining full benefit from the exercise). 
There's some 'template code' which will enable starting from this week.


Challenge Schedule: Groups of solutions
Starting: Sat 5 Nov
Office Hours: 1830*, Wed 9 Nov
Concluding: midnight after Sun 13 Nov
* all times NZDT (UTC+13)


Are you up for a challenge?
Regards =dn (for Pete and DJ)

From alex.ochoa0429 at gmail.com  Sun Nov  6 20:36:12 2022
From: alex.ochoa0429 at gmail.com (Enid Villalobos)
Date: Sun, 6 Nov 2022 19:36:12 -0600
Subject: [Tutor] help with program
Message-ID: <CAEjcTLGC7dOA5R4-dXeNkeF2OpD4-pgqdf1B16Hw8vys7KFj=w@mail.gmail.com>

I need to create a reverse program using the reverseArray function

my program works and runs as it should but they want me to define the
reverseArray function

I am copying my program below

#The original array
original_array = [9, 8, 7, 6, 5]
print("original contents of array:",original_array)
original_array.reverse() #reversing using reverse()

print("Reversed contents of array:",original_array)

when i run this program my output is this:
original contents of array [9,8,7,6,5]
reverse contents of array [5,6,7,8,9]
But they want me to use the array function

please help

From alan.gauld at yahoo.co.uk  Mon Nov  7 06:52:06 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 7 Nov 2022 11:52:06 +0000
Subject: [Tutor] help with program
In-Reply-To: <CAEjcTLGC7dOA5R4-dXeNkeF2OpD4-pgqdf1B16Hw8vys7KFj=w@mail.gmail.com>
References: <CAEjcTLGC7dOA5R4-dXeNkeF2OpD4-pgqdf1B16Hw8vys7KFj=w@mail.gmail.com>
Message-ID: <tkarh6$l8v$1@ciao.gmane.io>

On 07/11/2022 01:36, Enid Villalobos wrote:

> my program works and runs as it should but they want me to define the
> reverseArray function

I assume you mean they want you to design and write a
function called reverseArray()?

> #The original array
> original_array = [9, 8, 7, 6, 5]
> print("original contents of array:",original_array)
> original_array.reverse() #reversing using reverse()
> 
> print("Reversed contents of array:",original_array)

You need to define a function to replace the call to reverse() above.

Do you know how to define a function? Can you write a function
that simply prints its input list?

If so then start with that and modify it to print each
item in the list individually.

Then modify that so it prints the items in reverse order.

Then modify it so that instead of printing it puts the items
into a new list

Finally, remove all print statements and return the new list.

Rewrite your original program to use your new function.

If you are stuck with any of that tell us about it, including
any code that you have tried.

-- 
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  Mon Nov  7 11:22:57 2022
From: threesomequarks at proton.me (ThreeBlindQuarks)
Date: Mon, 07 Nov 2022 16:22:57 +0000
Subject: [Tutor] help with program
In-Reply-To: <CAEjcTLGC7dOA5R4-dXeNkeF2OpD4-pgqdf1B16Hw8vys7KFj=w@mail.gmail.com>
References: <CAEjcTLGC7dOA5R4-dXeNkeF2OpD4-pgqdf1B16Hw8vys7KFj=w@mail.gmail.com>
Message-ID: <Vss-qwoBqfC_avWiU39oHIh-Ac5WLNawRXhAacxtD7JcNIBApNxut8vBT23q0PgcUCdlYiRPgRkexJOqEwzzSf0t9rbS6G3p_pnwfxBfmsk=@proton.me>



Alan provided a fairly detailed step by step suggestion which answers one of many possible questions if done carefully. It has lots of extra and later retracted steps meant to teach and assumes you are a beginner.

I go a bit further back and ask that you make sure you understand what the question is perhaps by looking at the original assignment description that you paraphrased or asking the teacher or looking at what else was taught recently or is in the textbook.

It does sound like Alan's guess is what is wanted and the goal is to take any thing you call an array and reverse it. But it is not that simple. Your example uses the built-in python data structure we normally call a "list" as in [9,8,7,6,5] but there are other python data structures that also have a concept of being reversible.

So some of these data structures may be objects with a built-in reverse functionality and some may change the order internally so the data structure is changed and some may return a copy in the new order. Generally calling a function to get the reverse might be expected to not change the argument supplied but return a new one.

There are oodles of ways to play with a list and Alan is not specifying any one way, albeit his sequence of steps suggests some ways more than others such as when he suggests you print one at a time.

The choice of how to do it depends on what has been taught in your class. Do you already know how to determine how many items are in your list/array? Do you know how to do loops? Do you know how to create slices including a way to specify starting at the end and going back by ones? 

And is your function required to work only on one kind of data structure? What if the object is a numpy array or sequence or some kind of matrix or dataframe? My guess is it needs to only work for one scenario and return an object of the same kind. But you need to know.

And consider edge cases. What should your reverser return if it gets an empty list/array? What if it gets a single thing not in a list? What should it do if given an argument that it cannot handle or something weird like a generator of all primes.

Chances are you are not being asked to handle complex cases. Chances are you are not being asked to write a member function meant to be placed in objects of type "array" that provide the functionality as in your early attempt. My point is that your description is not detailed enough to allow us to be sure of what the required result should be. Alan provided a reasonable guess that if you fill it in properly will get you a result you can test. But if the request is a bit different, make sure you understand it rather that suggest his method is wrong.

As to specifics, your example is a bit disconcerting on these lines:

original_array = [9, 8, 7, 6, 5]
print("original contents of array:",original_array)
original_array.reverse() #reversing using reverse()

print("Reversed contents of array:",original_array)


The above looks like it reverses the array INTERNALLY. It changes it permanently as you seem to print the original before and after.

I suspect your assignment is to have a line like:

print("Reversed contents of array:", reverseArray(original_array))

Meaning take the original array and LEAVE IT ALONE but ask a function to take it and calculate a new array with the items reversed and return that.

Just make sure you understand the question and then finding a solution can be done.





Sent with Proton Mail secure email.

------- Original Message -------
On Sunday, November 6th, 2022 at 8:36 PM, Enid Villalobos <alex.ochoa0429 at gmail.com> wrote:


> I need to create a reverse program using the reverseArray function
> 
> my program works and runs as it should but they want me to define the
> reverseArray function
> 
> I am copying my program below
> 
> #The original array
> original_array = [9, 8, 7, 6, 5]
> print("original contents of array:",original_array)
> original_array.reverse() #reversing using reverse()
> 
> print("Reversed contents of array:",original_array)
> 
> when i run this program my output is this:
> original contents of array [9,8,7,6,5]
> reverse contents of array [5,6,7,8,9]
> But they want me to use the array function
> 
> please help
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From samiraeastcoast at gmail.com  Mon Nov  7 15:43:43 2022
From: samiraeastcoast at gmail.com (samira)
Date: Mon, 7 Nov 2022 16:43:43 -0400
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <tjv0go$76o$1@ciao.gmane.io>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
Message-ID: <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>

Hi Alan

Thanks for the suggestions. I tried to address what you mentioned but I am
not sure if I understood it correctly as the codes are still not outputting
what I am looking for. I am also very new to coding so understanding some
of the python language is challenging. Thanks for the patience in advance.

Below is the example of data you have requested. As you can see there are
changes in numbers that are less than previous in multiple locations and
that is where I want the python to print "split here" so that I can split
the file and write to a new file later once I can see where splits happen.
Hope that helps

Line1: -1.75, 1.08, 10.35, -0.10, -0.01, -0.01, 23.19, 488

Line2: -1.75, 1.12, 10.39, -0.10, -0.01, -0.01, 23.20, 521

Line4: -1.75, 1.10, 10.40, -0.10, -0.00, -0.01, 23.30, 967

Line5: -1.77, 1.09, 10.40, -0.10, -0.01, -0.01, 23.28, 1000

Line6: -1.72, 1.08, 10.40, -0.10, -0.00, -0.01, 23.31, 1032



Line1340: -1.97, 0.84, 10.35, -0.10, -0.01, -0.01, 24.16, 48040

Line1341: -1.97, 0.86, 10.35, -0.10, -0.01, -0.01, 24.16, 48075


****this is where the split needs to happen where Last<previous

Line1342: -2.16, 0.54, 10.25, -0.10, -0.00, -0.01, 24.18, 493

Line1343: -2.20, 0.54, 10.34, -0.10, -0.01, -0.01, 24.17, 528



previous=0

with open ('test-copy.txt', mode="r") as timestamp:

    for line in timestamp:
          x=line.split(", ")
    last=int(x[7])
    print(last)
    print("last = ", last)
    print("previous = ", previous)

    if last < previous :
        print("split here")


Output is as below:

15339495
last =  15339495
previous =  0


Thanks

Sam



On Wed, Nov 2, 2022 at 9:05 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 02/11/2022 19:39, samira khoda wrote:
>
> > And then split it where the value of the last is less than previous. But
> > when I run the code prints 0 for previous
>
> You never print previous.
>
> in each line which technically
> > says should not be split anywhere. I did a manual check up and I know
> there
> > are various spots that the split should happen.
>
>
> It might help if you post a few lines of sample data including some
> lines where the last < previous and others where it is not.
> >
> > How can I make the value of the previous update to the value of the
> > previous timestamp and not stay zero for every line?
>
> There are seeral issues in your code:
>
> > Import pandas as pd
>
> That should be lower ase import. Please post actual code not
> retyped. It avoids wasting time on typos that don't exist
> in the real thing.
>
> > previous=0
> > i=0
> > data=open('time-.txt', mode="r")
>
> Notice that there is no value for last at this point.
>
> > for line in data:
> >     x=line.split(", ")
> >     last=int(x[7])
>
> You assign it here but if the file were empty it would not exist.
>
> However, as written, this is your complete loop.
> You simply iterate over each line in the file then exit the
> loop with last assigned to the 8th field of the last line.
> What does the last line of your data look like?
> It must have at least 8 fields or you'd get an error...
> But the fields could be from any old string. Of course there
> must be a number or the int() call would fail. But is it valid?
>
> > if last < previous :
>
> Now you never changed previous during the loop so it is still 0.
> and last is the value from the last line of the file.
> So the if block will only execute if the last value is negative.
> Is that likely?
>
> >     print("split here"+i)
>
> i is never changed in the loop either so i is also zero.
> But i is not previous!
>
> >     previous=last
> >     i=i+1
>
> These lines change the variables but its too late, we are
> at the end of the code.
>
> And worryingly you have not closed the file.
>
> Things to change?
> 1) Use a with statement for opening the file - then you don't
> need to worry about closing it.
>
> 2) Move the if statement and block inside the loop.
> But consider whether you really only want the previous
> and i increment to be done when last < previous?
>
> 3) put more print statements in. Especially put
> in
>
> print("last = ", last)
> print("previous = ", previous)
>
> Just before the if statement.
>
> --
> 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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From alan.gauld at yahoo.co.uk  Mon Nov  7 18:17:58 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 7 Nov 2022 23:17:58 +0000
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
Message-ID: <tkc3n7$e2l$1@ciao.gmane.io>

On 07/11/2022 20:43, samira wrote:
> Hi Alan
> 
> Thanks for the suggestions. I tried to address what you mentioned but I am
> not sure if I understood it correctly as the codes are still not outputting
> what I am looking for. 

I'm still not clear what exactly you are looking for.
However, to your data and code...

> Below is the example of data you have requested. As you can see there are
> changes in numbers that are less than previous in multiple locations 

It might help if you point those out because I'mnot clear which
ones you are looking for.

For example:

> Line1: -1.75, 1.08, 10.35, -0.10, -0.01, -0.01, 23.19, 488

We have 8 Fields, indexed 0-7. (based on splitting by a comma)


> Line2: -1.75, 1.12, 10.39, -0.10, -0.01, -0.01, 23.20, 521
> Line4: -1.75, 1.10, 10.40, -0.10, -0.00, -0.01, 23.30, 967

Here index 1 and 4 are both less than previous.
Which if any is significant?

> Line5: -1.77, 1.09, 10.40, -0.10, -0.01, -0.01, 23.28, 1000

And here index 1 and 6 are less.

> Line6: -1.72, 1.08, 10.40, -0.10, -0.00, -0.01, 23.31, 1032

Again it is 1 and 4

> Line1340: -1.97, 0.84, 10.35, -0.10, -0.01, -0.01, 24.16, 48040
> Line1341: -1.97, 0.86, 10.35, -0.10, -0.01, -0.01, 24.16, 48075
> 
> ****this is where the split needs to happen where Last<previous
> 
> Line1342: -2.16, 0.54, 10.25, -0.10, -0.00, -0.01, 24.18, 493

And here it is 1, 2, 4 and 7.

Again, what makes this row different to the others?

> previous=0
> 
> with open ('test-copy.txt', mode="r") as timestamp:
>     for line in timestamp:
>           x=line.split(", ")

Again you loop though all tyhe lines in the file  splitting
them then throwing the data away leaving only the last line
in x.

>     last=int(x[7])

Now you assign index 7, field 8, to last.
You never change previous so it is always zero.

>     print("last = ", last)
>     print("previous = ", previous)
> 
>     if last < previous :
>         print("split here")

Here you compare last to 0. It will only be less if x[7] is negative.
But the sample data suggests it is always positive.

I suspect you need more code inside the initial for loop,
something like this(untested)

previous = 0
with open ('test-copy.txt', mode="r") as timestamp:
    for line in timestamp:
          x=line.split(", ")
          last=int(x[7])
          print("last = ", last)
          print("previous = ", previous)
          if last < previous :
             print("split here - last = ", last)
          previous = last


-- 
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 mats at wichmann.us  Mon Nov  7 18:30:47 2022
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 7 Nov 2022 16:30:47 -0700
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <tkc3n7$e2l$1@ciao.gmane.io>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
 <tkc3n7$e2l$1@ciao.gmane.io>
Message-ID: <cbb406bd-c0b2-1916-4920-51c3e44af259@wichmann.us>

On 11/7/22 16:17, Alan Gauld via Tutor wrote:

>> Line1340: -1.97, 0.84, 10.35, -0.10, -0.01, -0.01, 24.16, 48040
>> Line1341: -1.97, 0.86, 10.35, -0.10, -0.01, -0.01, 24.16, 48075
>>
>> ****this is where the split needs to happen where Last<previous
>>
>> Line1342: -2.16, 0.54, 10.25, -0.10, -0.00, -0.01, 24.18, 493
> 
> And here it is 1, 2, 4 and 7.
> 
> Again, what makes this row different to the others?

I'm going to guess that the last field is something like "seconds since 
start of new processing period" (like midnight), and so the idea is to 
split the log into individual days.

The original example did call out the last field so pretty sure that's 
the one that's of interest:

     last=int(x[7])

This is way more readable if you unpack the split into named variables - 
then you don't have code which relies on magical but undocumented 
indices into a list. Pcessing things that look like csv are always 
fraught with field recognition problems unless someone is nice enough to 
emit the column names too.



From bouncingcats at gmail.com  Mon Nov  7 18:47:33 2022
From: bouncingcats at gmail.com (David)
Date: Tue, 8 Nov 2022 10:47:33 +1100
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
Message-ID: <CAMPXz=o=MEae2FAVQt57WvAYtEbkwob8x3esO1kd_JmrfbxhGw@mail.gmail.com>

On Tue, 8 Nov 2022 at 09:52, samira <samiraeastcoast at gmail.com> wrote:

> Line1: -1.75, 1.08, 10.35, -0.10, -0.01, -0.01, 23.19, 488
>
> Line2: -1.75, 1.12, 10.39, -0.10, -0.01, -0.01, 23.20, 521
>
> Line4: -1.75, 1.10, 10.40, -0.10, -0.00, -0.01, 23.30, 967
>
> Line5: -1.77, 1.09, 10.40, -0.10, -0.01, -0.01, 23.28, 1000
>
> Line6: -1.72, 1.08, 10.40, -0.10, -0.00, -0.01, 23.31, 1032
>
>
>
> Line1340: -1.97, 0.84, 10.35, -0.10, -0.01, -0.01, 24.16, 48040
>
> Line1341: -1.97, 0.86, 10.35, -0.10, -0.01, -0.01, 24.16, 48075
>
>
> ****this is where the split needs to happen where Last<previous
>
> Line1342: -2.16, 0.54, 10.25, -0.10, -0.00, -0.01, 24.18, 493
>
> Line1343: -2.20, 0.54, 10.34, -0.10, -0.01, -0.01, 24.17, 528

Hi list,

(aside:

I should resist the temptation to guess, because I think this
list does far too much of that, perhaps to the point that it might
be excessive for the questioner.

Observing recent hiccups, I wonder if things would work better
for everyone if tutors on the list initially engaged with questioners
in a minimal way until they show themselves to be responsive
and articulate clearly what they want.

Like what is in the process of occurring in this discussion.

Learning how to ask a clear question is a very important skill
that we can help people to learn.

However, I don't put much effort into answering questions,
so I don't want to appear critical of anyone here who does.

anyway ...)

I guess that what Sam tries to show us here is that the final
number in the line (aka "last") is increasing, until line 1342 where
493 < 48075 from the previous line.

From PythonList at DancesWithMice.info  Mon Nov  7 20:28:19 2022
From: PythonList at DancesWithMice.info (dn)
Date: Tue, 8 Nov 2022 14:28:19 +1300
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CAMPXz=o=MEae2FAVQt57WvAYtEbkwob8x3esO1kd_JmrfbxhGw@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
 <CAMPXz=o=MEae2FAVQt57WvAYtEbkwob8x3esO1kd_JmrfbxhGw@mail.gmail.com>
Message-ID: <62cecc25-4f92-4628-a412-4ffd318e4720@DancesWithMice.info>

On 08/11/2022 12.47, David wrote:
> Hi list,

Which is an interesting form of address. To you the list is a plurality. 
To me (and to most?all readers), I am singular.

"Communication" is interesting.
The tool often shapes how communication 'works'.
(and the particular (types of) problems of communication that arise)


> (aside:
> 
> I should resist the temptation to guess, because I think this
> list does far too much of that, perhaps to the point that it might
> be excessive for the questioner.

This is a symptom.
What is the cause?


> Observing recent hiccups, I wonder if things would work better
> for everyone if tutors on the list initially engaged with questioners
> in a minimal way until they show themselves to be responsive
> and articulate clearly what they want.

I'll leave the over-worked ListAdmin to answer the first part (for himself).


If someone is unable to articulate a problem, how can (s)he expect to 
express a solution?

Observation: I've seen people being given advice, the equivalent of 
'follow this link which describes how to post a 'good' question'. They 
typically do not follow the link. Their minds are too bound-up in 'the 
problem', and see the advice as a distraction.
(decide for yourself if there's a diagnosis of ego cf 'community')


Yes, the inescapable circumstances of learning are that one is not (yet) 
ready to express the problem in jargon. However, in this case, how many 
attempts have been made to understand the point at which the OP's 
data-set is to be "split"? Looking at other posts of recent days, do 
some post-ers even realise that this is a voluntary forum rather than a 
paid HelpDesk?
(which the poster has somehow managed to access without paying - again, 
decide for yourself about this logic/flight-of-fancy).

Some people have great difficulty in getting the requisite information 
'out' of their own heads, to be able to explain to others. If you've 
come-across the concept of asking folk to write code solving some 
problem, as part of a job-application process; I've often thought that 
I'd like to pose a scenario, and ask the applicant to describe the 
problem itself. (per above - understand, then solve)


All of which differs from students who would really like 'us' to 
do-homework.


There are also additional issues related to (English) language facility. 
As those of us who have lived outside of our own culture/language-group 
know only too well.


> Like what is in the process of occurring in this discussion.

Seeking clarification causes some back-and-forth. The reality is that 
you and I could be working on a problem, using English skilfully, and 
employing ComSc/Python-jargon correctly, but still find a need to 
clarify a point or clear some perceived ambiguity. I'd go so far as to 
suggest that such is one of the tasks (?and responsibilities) of 
anyone/everyone in a dev.team - all-day, every day.

Surely then, some 'extra' list-traffic is unavoidable?


Yes, having THE ListAdmin pre-process every first-enquiry might reduce 
list-traffic, but aside from the obvious, to what advantage?

If I was asking a question, a rapid-response from some 
Python-knowledgeable soul would be appreciated. Whereas, waiting for the 
ListAdmin to finish his entitled-portion of sleep, and do whatever else 
occupies his life, before turning to list-tasks; could become quite a 
frustrating experience.


> Learning how to ask a clear question is a very important skill
> that we can help people to learn.

As written, "we"!


> However, I don't put much effort into answering questions,
> so I don't want to appear critical of anyone here who does.
> 
> anyway ...)
> 
> I guess that what Sam tries to show us here is that the final
> number in the line (aka "last") is increasing, until line 1342 where
> 493 < 48075 from the previous line.

...and we read a solid, sensible, question; by way of clarification; 
which will equip you/us to better respond to the OP (and all whilst the 
ListAdmin (presumably) sleeps!


Has the proposal that the ListAdmin pre-process just been rendered 
null-and-void?
-- 
Regards,
=dn

From samiraeastcoast at gmail.com  Thu Nov 10 14:33:05 2022
From: samiraeastcoast at gmail.com (samira)
Date: Thu, 10 Nov 2022 15:33:05 -0400
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <tkc3n7$e2l$1@ciao.gmane.io>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
 <tkc3n7$e2l$1@ciao.gmane.io>
Message-ID: <CADn+fhBggH_wHnqunLmtxNDPdTOONzLvrd9Ssr7KxeGdvz9dGA@mail.gmail.com>

Hi all

Thanks for your comments and sorry I did not get a chance to respond back.
I did not wish to stir the pot, LOL just trying to get help. As a newbie it
is not always easy to pass on the clear content.

As David mentioned below "the final number in the line (aka "last") is
increasing, until line 1342 where 493 < 48075 from the previous line" .
Thanks for pointing this out. However, this is just an example. This
happens multiple times throughout the data with different numbers. That's
where I need to find where this happens and get the python print" split
here" so I can split the file at those locations. I have a large data set
and manually finding it is impossible.

In simple language, I would need to write a code  that reads line by line
and when the above happens, prints "split here" then actually splits the
file at that location and saves it to a new file.  I know how to write a
code to save it to file and all but I just can't get the first part right.

If not possible, it is all good and I will find another solution.

Thanks again
Sam

On Mon, Nov 7, 2022 at 7:20 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 07/11/2022 20:43, samira wrote:
> > Hi Alan
> >
> > Thanks for the suggestions. I tried to address what you mentioned but I
> am
> > not sure if I understood it correctly as the codes are still not
> outputting
> > what I am looking for.
>
> I'm still not clear what exactly you are looking for.
> However, to your data and code...
>
> > Below is the example of data you have requested. As you can see there are
> > changes in numbers that are less than previous in multiple locations
>
> It might help if you point those out because I'mnot clear which
> ones you are looking for.
>
> For example:
>
> > Line1: -1.75, 1.08, 10.35, -0.10, -0.01, -0.01, 23.19, 488
>
> We have 8 Fields, indexed 0-7. (based on splitting by a comma)
>
>
> > Line2: -1.75, 1.12, 10.39, -0.10, -0.01, -0.01, 23.20, 521
> > Line4: -1.75, 1.10, 10.40, -0.10, -0.00, -0.01, 23.30, 967
>
> Here index 1 and 4 are both less than previous.
> Which if any is significant?
>
> > Line5: -1.77, 1.09, 10.40, -0.10, -0.01, -0.01, 23.28, 1000
>
> And here index 1 and 6 are less.
>
> > Line6: -1.72, 1.08, 10.40, -0.10, -0.00, -0.01, 23.31, 1032
>
> Again it is 1 and 4
>
> > Line1340: -1.97, 0.84, 10.35, -0.10, -0.01, -0.01, 24.16, 48040
> > Line1341: -1.97, 0.86, 10.35, -0.10, -0.01, -0.01, 24.16, 48075
> >
> > ****this is where the split needs to happen where Last<previous
> >
> > Line1342: -2.16, 0.54, 10.25, -0.10, -0.00, -0.01, 24.18, 493
>
> And here it is 1, 2, 4 and 7.
>
> Again, what makes this row different to the others?
>
> > previous=0
> >
> > with open ('test-copy.txt', mode="r") as timestamp:
> >     for line in timestamp:
> >           x=line.split(", ")
>
> Again you loop though all tyhe lines in the file  splitting
> them then throwing the data away leaving only the last line
> in x.
>
> >     last=int(x[7])
>
> Now you assign index 7, field 8, to last.
> You never change previous so it is always zero.
>
> >     print("last = ", last)
> >     print("previous = ", previous)
> >
> >     if last < previous :
> >         print("split here")
>
> Here you compare last to 0. It will only be less if x[7] is negative.
> But the sample data suggests it is always positive.
>
> I suspect you need more code inside the initial for loop,
> something like this(untested)
>
> previous = 0
> with open ('test-copy.txt', mode="r") as timestamp:
>     for line in timestamp:
>           x=line.split(", ")
>           last=int(x[7])
>           print("last = ", last)
>           print("previous = ", previous)
>           if last < previous :
>              print("split here - last = ", last)
>           previous = last
>
>
> --
> 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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From alan.gauld at yahoo.co.uk  Thu Nov 10 17:20:16 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 10 Nov 2022 22:20:16 +0000
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhBggH_wHnqunLmtxNDPdTOONzLvrd9Ssr7KxeGdvz9dGA@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
 <tkc3n7$e2l$1@ciao.gmane.io>
 <CADn+fhBggH_wHnqunLmtxNDPdTOONzLvrd9Ssr7KxeGdvz9dGA@mail.gmail.com>
Message-ID: <tkjtf1$vcr$1@ciao.gmane.io>

On 10/11/2022 19:33, samira wrote:

> As David mentioned below "the final number in the line (aka "last") is
> increasing, until line 1342 where 493 < 48075 from the previous line" .

OK, That makes life much easier.

> where I need to find where this happens and get the python print" split
> here" so I can split the file at those locations.

You don't really want to split the original file, you just
want to output the data into a different new file.

> If not possible, it is all good and I will find another solution.

It ids very possible, especially now you have told us that
it is only one field we need to monitor.

In fact your code is not far from correct, you just need
to put more code inside the for loop.

Do you understand the significance of indentation in Python?


for item in sequence:
    code to be executed in loop
    more loop code here
code executed after loop.

Only the indented code is repeated, the code aligned with
the for are only executed once after the loop completes.

So in your code you have:

>>> with open ('test-copy.txt', mode="r") as timestamp:
>>>     for line in timestamp:
>>>           x=line.split(", ")

That loops through the entire file splitting every
line and assigning the result to x. Each time a new line
is read it is split and its list of values is assigned
to x, throwing the previous line away.

You need to add your comparison code inside the loop,
but at present you have it outside.

In outline it should look something like:

>> previous = 0
>> with open ('test-copy.txt', mode="r") as timestamp:
>>     for line in timestamp:
>>           x=line.split(", ")
>>           last=int(x[7])
>>           print("last = ", last)
>>           print("previous = ", previous)
>>           if last < previous :
>>              print("split here - last = ", last)
>>           previous = last

Notice the difference in the indentation level.
This time all of the code after the for... line is
executed for every line in the file.

To do what you want you need to add an output filename variable and
instead of just printing the message write the line to the output file.
Everytime the split is needed just change the output filename and open
the new file (close the old one first!) Something like:

inputfile = open("WhateverItsCalled")
outroot = 'Part-'
count = 1
outfile = outroot + str(count)+".dat"
output = open(outfile,'w')
previous = 0

for line in inputfile:
    fields = line.split(', ')
    if fields[-1] < previous:
       output.close()
       count +=1
       outfile = outroot+str(count)+".dat"
       output = open(outfile, 'w')
    output.write(line + '\n')  # add a newline
    previous = fields[-1]
inputfile.close()
output.close()

We can tighten that up quite a lot but I've kept it
as self explanatory as possible.

That should take your original file and produce a set
of files called Part-1.dat, Part-2.dat, ....Part-N.dat.
You will likely need to tweak it, I haven't run or
tested it in any way.

-- 
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 PythonList at DancesWithMice.info  Thu Nov 10 17:41:00 2022
From: PythonList at DancesWithMice.info (dn)
Date: Fri, 11 Nov 2022 11:41:00 +1300
Subject: [Tutor] How to change the values in python code?
In-Reply-To: <CADn+fhBggH_wHnqunLmtxNDPdTOONzLvrd9Ssr7KxeGdvz9dGA@mail.gmail.com>
References: <CADn+fhBZfR3L0YKqKUpf7srVvP459vj=Nsxx8hdqkTYSW+wfwQ@mail.gmail.com>
 <tjv0go$76o$1@ciao.gmane.io>
 <CADn+fhCOQ+DbeArkofjha6DFx7x486_8UsqcSiJ3GvDTfd7S_g@mail.gmail.com>
 <tkc3n7$e2l$1@ciao.gmane.io>
 <CADn+fhBggH_wHnqunLmtxNDPdTOONzLvrd9Ssr7KxeGdvz9dGA@mail.gmail.com>
Message-ID: <ec4d19b3-a761-4701-fd99-6353fcd3e1ab@DancesWithMice.info>

On 11/11/2022 08.33, samira wrote:
> Hi all
> 
> Thanks for your comments and sorry I did not get a chance to respond back.
> I did not wish to stir the pot, LOL just trying to get help. As a newbie it
> is not always easy to pass on the clear content.
> 
> As David mentioned below "the final number in the line (aka "last") is
> increasing, until line 1342 where 493 < 48075 from the previous line" .
> Thanks for pointing this out. However, this is just an example. This
> happens multiple times throughout the data with different numbers. That's
> where I need to find where this happens and get the python print" split
> here" so I can split the file at those locations. I have a large data set
> and manually finding it is impossible.
> 
> In simple language, I would need to write a code  that reads line by line
> and when the above happens, prints "split here" then actually splits the
> file at that location and saves it to a new file.  I know how to write a
> code to save it to file and all but I just can't get the first part right.
> 
> If not possible, it is all good and I will find another solution.


OK then, let's start from first-principles - to suit someone new to 
programming.


The best way to solve a multi-part problem, is to break it into smaller 
problems, or steps in the process.

1 be able to read the entire file
2 be able to identify the dependent-data on each row/record/line of the file
3 splitting into (potentially) multiple output files

The advantage of these smaller problems is that they are (potentially) 
easier to understand and solve.

Indeed, we may even further-divide sub-problem (3):

3a detect when the data directs that a split should happen
3b organise the output files

...and keep dividing down the problems until solutions become more 
evident. (the level at which this happens for you (as a 
Python-Apprentice may be more-detailed than for someone with years of 
experience - but who cares, because the objective is the solution!)


First Step:

Can you write code to solve (1)?

Prove it by adding a 'debug-print' to the loop, and thus being able to 
'see' that the file is being read.


Second Step:

Take one of the printed-lines of *actual data* output by the 'First 
Step'. Write a separate routine which takes that data as a 
literal/constant string-value, and selects the pertinent control-data 
from the line (the piece of data on which the 'Third Step' will depend - 
remember that word?)

If the code can achieve this successfully for one line, it can be 
located inside a code-loop, and perform same on each line of the 
data-file in-turn!

Thus, we have simplified the task, and are solving the sub-problem 
without any influence from other code, ie if we find an error, we know 
it is within this little routine, and has nothing to do with the logic 
in the 'First Step'! Also, there's no need to tackle every line at-once 
- deal with the sub-problem first, and then get more ambitious ideas!


New question:

Are you aware that there are different data-types? That strings are not 
the same as integers (for example). Have you come-across type()?
(if not, time for some research/study)

Accordingly, once the code is able to extract the pertinent field from 
the line check what data-type it is. Consider if that is what you need 
for Step 3a.


Method:

Above I used the term 'routine'. If you are using an editor/IDE, then 
this will be a Python script, ie a .py file. Fine! An alternative 
approach is that some IDEs, eg PyCharm, provide a "Python Console"; or 
if you are a Terminal user, firing-up python[3] will give access to an 
"interactive console", aka the REPL.

These tools are ideal for experimenting, in the sense of the two Steps 
outlined above - I've been shown code using a particular library which 
interacts with workbooks (spreadsheets) and used the Python Console to 
be sure I understood how it works and the differences between several 
grab-some-data methods!

Input: if you already have some code, or care to 'borrow' from solutions 
suggested earlier in this thread, it can be copy-pasted from the editor 
or email-message into the Python Console - to ease your effort.

Output: likewise, after solving a problem in the Python Console, it is a 
simple matter of copy-pasting the (successful) experiment into the 
editor as part of assembling your 'final code'!


You may already have these steps 'done', and only have to extract them 
from an existing attempt to be able to prove the sub-problem(s). That's 
fine. Recommend following the above steps anyway, if only to give you a 
sense of how to solve the next coding-problem which comes your way...


Reverting to this List:

Please copy-paste the two snippets into a reply-message.


You might also like to suggest (in English) how one might attack the 
sub-problems in the "Third Step".

Someone will happily verify your thinking, and perhaps point-out any 
errors or improvements. (list-members find it easier to help with 
existing code than with a 'blank canvas'!)

To get a head-start on such, please consider the sub-problem of perhaps 
multiple output files being output by the completed program[me]:
- what file-names will they need?
- where will the 'base-name' come-from?
- how will the multiple files be distinguished from each-other?

Thereafter, someone will be able to offer advice about tackling the last 
step(s) - but again, if you'd like to show some code, even attempts at a 
sub-solution, it will help you and help improve contributions 'here'.

-- 
Regards,
=dn

From PythonList at DancesWithMice.info  Sun Nov 13 14:58:40 2022
From: PythonList at DancesWithMice.info (dn)
Date: Mon, 14 Nov 2022 08:58:40 +1300
Subject: [Tutor] Wed 16 Nov, Virtual PUG meeting
Message-ID: <b78f7b07-b69c-293f-dbfc-2c742e54d762@DancesWithMice.info>

Wed 16 November, 1800 for 1830 NZDT (0500 for 0530 UTC)


1 The When of Python
Looking at a range of Python features with the aim of determining when 
or when not to use them in your Python code. Grant and Ben will be 
following up on their eponymous Kiwi Pycon talk - guidance on when to 
use Python's various features (and when not to). See 
https://www.youtube.com/watch?v=JnY5MEiqG44&ab_channel=KiwiPyCon)

2 SOLID's Open-Closed Principle
Continuing our Software Craftsmanship series. Do you understand the 
Open-Closed Principle? Did you know that the OCP strongly influences 
software architecture and how we should design our programs?


Something for Tutors and Python Apprentices. All welcome!

For BigBlueButton web-conference URL, please RSVP at 
https://www.meetup.com/nzpug-auckland/events/njdjssydcpbvb/
(other enquiries to the under-signed, off-list please)
-- 
Regards,
=dn

From reply.to.edgar at hotmail.co.uk  Fri Nov 25 09:20:59 2022
From: reply.to.edgar at hotmail.co.uk (Edgar Byaruhanga)
Date: Fri, 25 Nov 2022 14:20:59 +0000
Subject: [Tutor] PYTHON installation problem
Message-ID: <CWXP265MB25336F81DA8F84F728F282998E0E9@CWXP265MB2533.GBRP265.PROD.OUTLOOK.COM>

Dear all,

I am new to python and programming in general ? so please kindly do not assume I know what you know and proceed to use acronyms, technical terms or slang terms which are common place in your field of expertise, as if I will know what they mean and or how to action them! (No offence intended)

I have attached screenshots of messages which I keep getting when I try to download python on my laptop ? (windows 10, intel 5, 64-bit cpu, chrome browser)

Please advise what the problem is and how I can fix it ? in order to download the program and start learning.

I did previously install python 3.9 a long time ago ? but didn?t have time to fully start using it. When I click the desktop icon for python 3.9 I get a message saying;


  *   ??the item ?pythonw.exe? that this short cut refers to has been changed or moved, so this shortcut will no longer work properly?? ? Do you want to delete this shortcut?

I tried to find python 3.9 in my system but couldn?t ? not sure why or what happened to it, since I don?t remember uninstalling it!

Please advise what the likely problem is and how I can fix it.



  1.  Also as a separate but slightly related issue ? can I technically download python onto a usb stick/drive, then then install it onto a laptop which isn?t connected to the internet? I want a wall/vacuum between what I program and the internet!
  2.  I am not if this is relevant or within your remit but ? I was looking into what I believe are called ??text editors??, to help arrange and help me structure my programming in a way which is helpful to understand, remember and read ? are there any specific text editors which you recommend to use with python? ? AND DO THEY ACTUALLY HELP WHEN PROGRAMMING? I saw programs like, sublime, Atom, Visual studio, Vin, etc. (see link below)
  3.  https://www.techradar.com/best/best-text-editors

Please advise

Edgar


Get Outlook for Android<https://aka.ms/AAb9ysg>

From mats at wichmann.us  Fri Nov 25 13:00:17 2022
From: mats at wichmann.us (Mats Wichmann)
Date: Fri, 25 Nov 2022 11:00:17 -0700
Subject: [Tutor] PYTHON installation problem
In-Reply-To: <CWXP265MB25336F81DA8F84F728F282998E0E9@CWXP265MB2533.GBRP265.PROD.OUTLOOK.COM>
References: <CWXP265MB25336F81DA8F84F728F282998E0E9@CWXP265MB2533.GBRP265.PROD.OUTLOOK.COM>
Message-ID: <114b157b-f2d8-2e3e-c890-e83da18a82ca@wichmann.us>

On 11/25/22 07:20, Edgar Byaruhanga wrote:
> Dear all,
> 
> I am new to python and programming in general ? so please kindly do not assume I know what you know and proceed to use acronyms, technical terms or slang terms which are common place in your field of expertise, as if I will know what they mean and or how to action them! (No offence intended)
> 
> I have attached screenshots of messages which I keep getting when I try to download python on my laptop ? (windows 10, intel 5, 64-bit cpu, chrome browser)

that doesn't help - the list strips attachments for security reasons, 
you have to describe the problem in words and/or include text cut and 
pasted from your screen.

since we can't see your snips, the first thing is to clearly describe 
whether it's actually a *download* problem - does the installer download 
or not? - or something that happens *after* the download. Are you 
getting an error when you try to start the download? Else, Chrome has a 
button (and a menu entry) to see downloaded files - did it download?





From alan.gauld at yahoo.co.uk  Mon Nov 28 12:12:20 2022
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 28 Nov 2022 17:12:20 +0000
Subject: [Tutor] PYTHON installation problem
In-Reply-To: <CWXP265MB25336F81DA8F84F728F282998E0E9@CWXP265MB2533.GBRP265.PROD.OUTLOOK.COM>
References: <CWXP265MB25336F81DA8F84F728F282998E0E9@CWXP265MB2533.GBRP265.PROD.OUTLOOK.COM>
Message-ID: <tm2q5l$15j7$1@ciao.gmane.io>

On 25/11/2022 14:20, Edgar Byaruhanga wrote:

> I have attached screenshots of messages

As Mats has already pointed out the tutor list does not accept binary
attachments such as screenshots because they present a security risk.
Please copy/paste the text of any error messages or code etc within
yoiur mail message.

> I keep getting when I try to download python on my laptop
>  ? (windows 10, intel 5, 64-bit cpu, chrome browser)

Where are you trying to download from - a URL please?

> I tried to find python 3.9 in my system but couldn?t ? not 
> sure why or what happened to it, since I don?t remember uninstalling it!
> 
> Please advise what the likely problem is and how I can fix it.

That's really an OS issue on your system and without access to the
machine it's impossible for us to suggest much. It sounds like it has
been uninstalled somehow. I'd focus on getting the current version
installed. There are 3 places you can try:
1) python.org - recommended
2) Windows store - usually a version behind current but that's not
a problem - it may be the simplest option.
3) ActiveState.com - they do a Windows specific bundle with improved
help system and programming tools. This is the version I usually
recommend for Windows users.

4) There are a couple of online Python interpreters which are
fine when starting out. They let you type code into a web page
and run it. I've used:

https://www.online-python.com

But there are several others.


>   1.  Also as a separate but slightly related issue ? can I 
technically download python onto a usb stick/drive, then then
install it onto a laptop which isn?t connected to the internet?
I want a wall/vacuum between what I program and the internet!

It's technically possible and there are some web pages and Youtube
videos shhowing how to set it up, but its not trivial. And it brings
its own set of limitations so I wouldn't recommend it for beginners.

>   2.  I am not if this is relevant or within your remit but ? I 
> was looking into what I believe are called ??text editors??, 

Programming text editors are a very personal subject and can result
in "flame wars" breaking out. For beginners it's not too important
and any basic programming editor will do. so long as it saves in
plain text and not HTML or a binary format like "rich text" or
MS Word.

Standard Python comes with a basic but effective one called IDLE
which is itself written in Python. The activestate.com bundle
includes pythonwin.exe which is a more Windows-like editor.

Other recommendations for windows users include:
Notepad++
PyCharm(more powerful, and more complex)
Microsoft VisualCode editor. (Very powerful and very windows-like)
Netbeans or Eclipse(much more powerful and complicated)

There are others, and if you have a Unix background vi/vim/elvis
or emacs have Python modes too. But if you don't already know them
I'd stick with the options above. But do try IDLE first, it may be
all you ever need!

> ...I saw programs like, sublime, Atom, Visual studio, Vin, etc. 

There are literally hundreds of programmers editors (or IDEs).
Some swear by one while others swear at it. It is a very prersonal
choice and you are best to just try a few and seee what suits
you best. At the beginner level they all offer the ability to
create files, syntax colour them, offer suggestions and
auto-layout the code. Its only when you get into working
with multiple files and bigger files that the differences
become significant.

-- 
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 PythonList at DancesWithMice.info  Wed Nov 30 15:44:46 2022
From: PythonList at DancesWithMice.info (dn)
Date: Thu, 1 Dec 2022 09:44:46 +1300
Subject: [Tutor] AuckPUG's last (virtual) Coding Evening for 2022
Message-ID: <7de9acc1-fefa-7143-2d4d-135fbe0472b3@DancesWithMice.info>

Wednesday 7 December, 1800 for 1830 NZDT/0530 UTC

We will continue the "Crafting Software" series, gradually developing 
Monty's Python Supermarket. The evening's aim is to move the 
product-prices from their hard-coded dict[ionary] into a flat-file 
(introducing Python I/O), and then to do same with the Accountant's 
favorite tool - a Workbook or Spreadsheet (Python's library to interact 
with LibreOffice-Calc and MS-Excel). You can treat it as a 
code-along-at-home exercise or just watch the fun. The Web-conference 
URL and a QuickStart Guide (for those who didn't attend last time) will 
be provided upon RSVP. All welcome!

https://www.meetup.com/nzpug-auckland/events/hgxmwsydcqbkb/



The Smart Iterators Challenge has finished (after five Challenge-weeks). 
Congratulations to all who participated (and if you didn't have time to 
complete, you're welcome to continue at your own pace). Particular pride 
for those who hung-in-there right to the end, making astute discoveries 
and learning ideas which have already been adopted into 
professional-practice. Well done! A "Retrospective, Review, and 
Reflection Wrap-up" document is available to participants/upon request. 
Advice and assistance will continue to be available - please email off-list.

-- 
Regards,
=dn