Re: a simple question

2021-07-29 Thread Sean DiZazzo
On Tuesday, July 27, 2021 at 5:05:27 AM UTC-7, Terry Reedy wrote:
> On 7/26/2021 6:19 PM, Glenn Wilson via Python-list wrote: 
> > I recently downloaded the latest version of python, 3.9.6. Everything works 
> > except, the turtle module. I get an error message every time , I use basic 
> > commands like forward, backward, right and left. My syntax is correct: 
> > pat.forward(100) is an example. Can you tell me what is wrong.
> On Windows, normal install, 
> C:\Users\Terry>py -3.9 -m turtle 
> C:\Users\Terry>py -3.9 -m turtledemo 
> both work. 
> 
> 
> -- 
> Terry Jan Reedy

Welcome to programming!!  Ain't it fun?!
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Trying to read from a text file to generate a graph

2021-07-29 Thread Steve
Thank you, the responses here have been extremely helpful.
Steve



Footnote:
There's 99 bugs in the code, in the code.
99 bugs in the code.
Take one down and patch it all around.
Now there's 117 bugs in the code.





-Original Message-
From: Python-list  On
Behalf Of Stephen Berman
Sent: Wednesday, July 28, 2021 5:36 PM
To: [email protected]
Subject: Re: Trying to read from a text file to generate a graph

[Resending to the list only, since I couldn't post it without subscribing.]

On Wed, 28 Jul 2021 11:58:21 -0400 "Steve"  wrote:

> I forgot about the no-file rule...
>
>> On 28Jul2021 02:55, Steve  wrote:
>> I am going though a struggle with this and just don't see where it 
>> fails.  I am using the Dual Bar Graph.py program from 
>> https://matplotlib.org/stable/gallery/index.html website.  The file 
>> from the web site works so that shows that all my installations are 
>> complete.
>>
>> My program, LibreGraphics 05.py program runs but the graph is all 
>> smutched up.  I am pulling data from the EXCEL-FILE.txt into the 
>> program, selecting three values for each line and creating three 
>> variables formatted as is shown in the original demo file.
>>
>> When you run the program, choose 112 when prompted. You will see the 
>> values of the variables I want to pass to the graph section of the 
>> code.  If the values are hardcoded, the graphs look good.  When the 
>> variables generated by my section of the code, it does not.

The problem is due to the values of Sensors, TestStrips and SampleNumber
being strings; what you want is for them to be lists, as in the assignments
you commented out.  And since the data from the file is read in as strings,
you have to cast the elements of the Sensors and TestStrips lists to
integers, since you want the numerical values.  The following code does the
job:

Sensors = []
TestStrips = []
SampleNumber = []

x = 1
SensorNumber = input("Enter senaor number: ")
with open("_EXCEL-FILE.txt", 'r') as infile:
for lineEQN in infile:
if (lineEQN[0:1]== "."):
SN = lineEQN[44:48].strip()
if (SensorNumber == SN):
SN = x
SampleNumber.append(SN)

sv = lineEQN[25:29].strip()
Sensors.append(int(sv))

tv = lineEQN[32:37].strip()
TestStrips.append(int(tv))

x += 1

labels = SampleNumber

Add the rest of your code from the second half to make the desired bar
chart.

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

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


Re: Trying to read from a text file to generate a graph

2021-07-29 Thread Anssi Saari
"Steve"  writes:

> I am going though a struggle with this and just don't see where it fails.

It seems to me you're putting your data into strings when you need to
put it into lists. And no, adding brackets and commas to your strings so
that printing out the strings makes them look like lists doesn't make
them into lists.

There's python tutorial at https://docs.python.org/3/tutorial/index.html
which may help with the basics.

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


Subtle difference between any(a list) and any(a generator) with Python 3.9

2021-07-29 Thread ast

Hello

Reading PEP572 about Python 3.9 assignment expressions,
I discovered a subtle difference between any(a list)
and any(a generator)

see:

>>> lines = ["azerty", "#qsdfgh", "wxcvbn"]
>>> any((comment := line).startswith('#') for line in lines)
True
>>> comment
"#qsdfgh"

>>> any([(comment := line).startswith('#') for line in lines])
True
>>> comment
'wxcvbn'

The two code snippets which seems very similar provide a
different value for "comment".

When "any" deals with a generator, it stops as soon it finds
a True value and returns True.

When "any" deals with a list, the whole list is calculated
first, and then "any" looks for a True.

Before 3.9 and the walrus operator, the two ways always provide
the same result, in a faster way with a generator.

With 3.9 and the walrus operator, result can be different








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


Re: Subtle difference between any(a list) and any(a generator) with Python 3.9

2021-07-29 Thread Chris Angelico
On Thu, Jul 29, 2021 at 7:49 PM ast  wrote:
>
> Hello
>
> Reading PEP572 about Python 3.9 assignment expressions,
> I discovered a subtle difference between any(a list)
> and any(a generator)
>
> see:
>
>  >>> lines = ["azerty", "#qsdfgh", "wxcvbn"]
>  >>> any((comment := line).startswith('#') for line in lines)
> True
>  >>> comment
> "#qsdfgh"
>
>  >>> any([(comment := line).startswith('#') for line in lines])
> True
>  >>> comment
> 'wxcvbn'

"any" is irrelevant here. What you're seeing is that a list
comprehension is evaluated fully, and a generator expression isn't.
That's exactly what they're meant to do :)

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


Fast help with Python program

2021-07-29 Thread Arak Rachael
Hi guys,

I need fast help with this, can you please look at it?

I don't get how to visualize on the 3 axis in the for cycle with the list of 
colors and count of colors that I get from my array.

And I also don't get how to cluster the colors based on how many colors there 
are in the second array from get_unique_colors(img).

https://www.dropbox.com/s/ifvecwb5c0iy2pa/test_scripts.py?dl=0

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


Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py

2021-07-29 Thread Peter Otten

On 28/07/2021 18:40, Dennis Lee Bieber wrote:

On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <[email protected]>
declaimed the following:



Perhaps it has something to do with the X-No-Archive flag set by Dennis?


According to my properties page in Agent, I've turned that off except
if the message I'm replying to has it set.


I'm yet to see an archived post by you -- maybe that setting is 
overridden somewhere.


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


Re: [Errno 2] No such file or directory:

2021-07-29 Thread joseph pareti
indeed. There are better options than the one I attempted. Thanks for the
advice

Am Mi., 28. Juli 2021 um 18:19 Uhr schrieb Chris Angelico :

> On Thu, Jul 29, 2021 at 2:10 AM joseph pareti 
> wrote:
> >
> > The following code fails as shown in the title:
> >
> >
> >
> >
> >
> >
> > *import subprocesscmd = 'ls -l
> >
> /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> > | awk "{print  $9 }"'process = subprocess.Popen([cmd],
> >  stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr =
> > process.communicate()print('stdout ',stdout)print('stderr ',stderr)*
> >
> > 
> >
> > Traceback (most recent call last):
> >   File "PreProcess_1a.py", line 3, in 
> > process = subprocess.Popen([cmd],  stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE)
> >   File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line
> 854,
> > in __init__
> > self._execute_child(args, executable, preexec_fn, close_fds,
> >   File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line
> > 1702, in _execute_child
> > raise child_exception_type(errno_num, err_msg, err_filename)
> > FileNotFoundError: [Errno 2] No such file or directory: 'ls -l
> >
> /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48
> > | awk "{print  $9
> >
>
> First off, you'll want to post code in a way that keeps the
> formatting, otherwise it becomes very hard to read.
>
> But the immediate problem here is that Popen takes an array of command
> arguments, NOT a shell command line. You cannot invoke ls and pipe it
> into awk this way.
>
> Don't think like a shell script. Python has very good
> directory-listing functionality, and you will very very seldom need to
> shell out to pipelines. Figure out what you actually need to learn
> from the directory listing and get that information directly, rather
> than trying to use two external commands and text parsing. It's far
> FAR easier, cleaner, and safer that way.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Regards,
Joseph Pareti - Artificial Intelligence consultant
Joseph Pareti's AI Consulting Services
https://www.joepareti54-ai.com/
cell +49 1520 1600 209
cell +39 339 797 0644
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a clean exit

2021-07-29 Thread Dieter Maurer
jak wrote at 2021-7-29 00:07 +0200:
> ...
>Thanks to both of you for the replies. I know the rules you described to
>me for process synchronization but unfortunately, due to the structure
>of the library I am using, I cannot apply them. I can't even use
>try/except because the library, when the error occurs, displays it with
>the loggin libraries and no longer calls any of the callback functions
>my program is composed of.

I assume that you are using a class deriving from a library class
where your application is defined by methods on this class.
Look at the library class's code. Almost surely, the error
in handled by one of its methods. Override this method in
your class as necessary.

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


Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py

2021-07-29 Thread Dennis Lee Bieber
On Thu, 29 Jul 2021 15:45:26 +0200, Peter Otten <[email protected]>
declaimed the following:

>On 28/07/2021 18:40, Dennis Lee Bieber wrote:
>> On Wed, 28 Jul 2021 09:04:40 +0200, Peter Otten <[email protected]>
>> declaimed the following:
>> 
>>>
>>> Perhaps it has something to do with the X-No-Archive flag set by Dennis?
>> 
>>  According to my properties page in Agent, I've turned that off except
>> if the message I'm replying to has it set.
>
>I'm yet to see an archived post by you -- maybe that setting is 
>overridden somewhere.

And naturally, once I found the legacy (per persona) custom setting, I
failed to edit the main persona. Hopefully this time it's set...

Appears Agent added the per "folder" and "default' 
[x] X-no-Archive 
flags in some later release, and those are what I've been tweaking... 

But looking at the INI file, I found there were persona specific custom
settings for "additional header fields", Which I likely set up back in the
days of Agent 5 or so, currently on Agent 8



-- 
Wulfraed Dennis Lee Bieber AF6VN
[email protected]://wlfraed.microdiversity.freeddns.org/

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


Rotation of a cube

2021-07-29 Thread Michael F. Stemper

I would like to animate the rotation of a 3-cube. I know how to
do animation with pygame. My first thought was to set up a cube as
a list of coordinates, and then project those coordinates onto a
plane by ray-tracing from a viewpoint. I could then incrementally
rotate it using the rotation matrix[1], briefly showing each step.

However, it seems to me that this is a solved problem, so there is
probably a module that will do most of the scutwork for me. Any
suggestions on where to find such a module?

Thanks.


[1] 
--
Michael F. Stemper
This sentence no verb.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtle difference between any(a list) and any(a generator) with Python 3.9

2021-07-29 Thread Terry Reedy

On 7/29/2021 5:39 AM, Unknown wrote:

Hello

Reading PEP572 about Python 3.9 assignment expressions,
I discovered a subtle difference between any(a list)
and any(a generator)

see:

 >>> lines = ["azerty", "#qsdfgh", "wxcvbn"]
 >>> any((comment := line).startswith('#') for line in lines)
True
 >>> comment
"#qsdfgh"

 >>> any([(comment := line).startswith('#') for line in lines])


Same as

>>> booleans = [(comment := line).startswith('#') for line in lines]
>>> # comment == last item.
>>> any(booleans) # Iteration though booleans stops at 1st True.

> True
  >>> comment

'wxcvbn'

The two code snippets which seems very similar provide a
different value for "comment".

When "any" deals with a generator, it stops as soon it finds
a True value and returns True.

When "any" deals with a list, the whole list is calculated
first, and then "any" looks for a True.

Before 3.9 and the walrus operator, the two ways always provide
the same result, in a faster way with a generator.


Since the 'two ways' involve the new :=, I have no idea what 'two ways' 
and 'same result' you mean before :=.



With 3.9 and the walrus operator, result can be different




--
Terry Jan Reedy

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


Re: Subtle difference between any(a list) and any(a generator) with Python 3.9

2021-07-29 Thread Chris Angelico
On Fri, Jul 30, 2021 at 5:40 AM Terry Reedy  wrote:
> Since the 'two ways' involve the new :=, I have no idea what 'two ways'
> and 'same result' you mean before :=.
>

I'm not sure, but I think that a lot of people read patch notes as if
they say "this is how everyone needs to do things now", and then blame
or credit the newest features with everything that happens.

Personally, I'd search for the comments like this:

for line in lines:
if line.startswith("#"):
... # whatever you do if there is one
break
else:
... # whatever you do if there isn't one

But if you have to do it with a one-liner, much cleaner to use next on
your filter:

comment = next((l for l in lines if l.startswith("#")). None)

Neither of these depends on :=. I don't know what "two ways" there
are, but capturing the first element that matches a filter is a pretty
normal thing to do.

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


How do I modify a bar graph?

2021-07-29 Thread Steve
The following code is from the site: 
https://matplotlib.org/stable/gallery/index.html  bar graph.
Sometimes I want to project a graph that contains almost 100 elements. The 
program shows everything crammed into a default size graph.  Can I modify the 
size of the graph and make it longer?

Also, the numbers in the graph are horizontal, can I make them vertical?
100
Vs
1
0
0
?


=
Import matplotlib.pyplot as plt
import numpy as np


labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels))  # the label locations
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)

fig.tight_layout()

plt.show()

Steve



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


Re: Rotation of a cube

2021-07-29 Thread Greg Ewing

On 30/07/21 5:57 am, Michael F. Stemper wrote:

I would like to animate the rotation of a 3-cube.ng each step.

However, it seems to me that this is a solved problem, so there is
probably a module that will do most of the scutwork for me.


You might find something useful here:

https://medium.com/quick-code/3d-graphics-using-the-python-standard-library-99914447760c

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