Re: Now for something completely different...

2022-05-22 Thread MRAB

On 2022-05-23 00:30, Chris Angelico wrote:

On Mon, 23 May 2022 at 09:19, Skip Montanaro  wrote:

That's not too informative (other than its relationship to moi), and I have
room for probably four or five more characters. (I have a graphic artist in
mind, so the space need not strictly be text either.)


Aww, not enough room to say "straight line", because (in Euclidean
space) it's the fastest way from B to A.


Instead of "straight line", "A → B".
--
https://mail.python.org/mailman/listinfo/python-list


Re: Now for something completely different...

2022-05-22 Thread Chris Angelico
On Mon, 23 May 2022 at 09:19, Skip Montanaro  wrote:
> That's not too informative (other than its relationship to moi), and I have
> room for probably four or five more characters. (I have a graphic artist in
> mind, so the space need not strictly be text either.)

Aww, not enough room to say "straight line", because (in Euclidean
space) it's the fastest way from B to A.

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


Re: how to distinguish return from print()

2022-05-22 Thread Chris Angelico
On Mon, 23 May 2022 at 09:23, Stefan Ram  wrote:
>   You are making it extra hard by wording the question in this
>   way. "What's the difference between the moon and liberty?". Uh ...
>
>   It's much easier to explain the moon and liberty separately.

"You can't tell the difference between a lump on the head and
margarine. The leadership of the Conservative Party is yours for the
asking!"
-- Grytpype Thynne, "The Last Goon Show of All"

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


Re: Convert the decimal numbers expressed in a `numpy.ndarray` into a matrix representing elements in fractional form

2022-05-22 Thread hongy...@gmail.com
On Thursday, May 19, 2022 at 5:26:25 AM UTC+8, Cousin Stanley wrote:
> #!/usr/bin/env python3 
> 
> ''' 
> NewsGroup  comp.lang.python 
> 
> Subject .. Convert the decimal numbers
> expressed in a numpy.ndarray 
> into a matrix representing elements 
> in fractiona
> Date . 2022-05-16 
> 
> Post_By .. hongy... 
> 
> Edit_By .. Stanley C. Kitching 
> '''
> import numpy as np 
> 
> from fractions import Fraction
> b = [ 
> [ 0.0 , -1.0 , 0.0 , 0.25 ] , 
> [ 1.0 , 0.0 , 0.0 , 0.25 ] , 
> [ 0.0 , 0.0 , 1.0 , 0.25 ] , 
> [ 0.0 , 0.0 , 0.0 , 1.0 ] ] 
> 
> a = [ ] 
> 
> print( '\n b  \n' ) 
> 
> for row in b : 
> arow = [] 
> print( ' ' , row ) 
> 
> for dec_x in row : 
> frac_x = Fraction( dec_x ) 
> arow.append( frac_x ) 
> 
> a.append( arow ) 
> 
> 
> # using f-string format 
> 
> print( '\n a  \n' ) 
> 
> for row in a : 
> 
> for item in row : 
> 
> print( f' {item} ' , end = '' ) 
> 
> print() 
> 
> # -- 

This method doesn't work, as shown below:


 b  

  [0.0, -1.0, 0.0, 0.25]
  [1.0, 0.0, 0.0, 0.25]
  [0.0, 0.0, 1.0, 0.25]
  [0.0, 0.0, 0.0, 1.0]

 a  

 0  0  0  1 


 
> -- 
> Stanley C. Kitching 
> Human Being 
> Phoenix, Arizona
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: Could not load correctly

2022-05-22 Thread Robert Loomis





 Forwarded Message 
Subject:Could not load correctly
Date:   Sat, 21 May 2022 10:58:39 -0400
From:   Robert Loomis 
Reply-To:   b...@loomisengineering.com
To: python-list@python.org



I am new to python.I tried to download it to a virtual environment since 
I have been learning on another version. I downloaded version 3.10.4 
into my windows10 operating system into directory 
c:\Users\Bob\PyVer\Py3913 and it said it was successful.I went to 
C:\Users\Bob\PyProj and made my environment by 
c:\Users\Bob\PyVer\Py3913\python -m venv my_env.I then activated it by 
my_env\Scripts\activate and it came back with a prompt.Then I tried to 
test it by typing python and I got what is below.


What did I do wrong?

Thank you,

Bob Loomis


--
This email has been checked for viruses by AVG.
https://www.avg.com
--
https://mail.python.org/mailman/listinfo/python-list


how to distinguish return from print()

2022-05-22 Thread Meredith Montgomery
Students seeing a programming language for the first time and using
Python's REPL for the first time have asked me what is the difference
between a return statement and a print() call.  They got a point.

--8<---cut here---start->8---
def f(x):
return x + 1

>>> f(1)
2

>>> print("hello")
hello
--8<---cut here---end--->8---

There's no visual difference.

(*) My answer

The way I know how to answer the difference there is to explain how a
typical computer system works, which is a more or less long answer.  A
return statement is usually just another CPU instruction, while /print/
is a procedure that must eventually run a CPU instruction that
interrupts the CPU, passes control to the operating system which, in
turn, talks to the i/o devices in question (the video, for example) to
get the job finally done.  (We may expect a print() call, therefore, to
be usually much slower than a return statement.)

I also explain that if, say, math.sin(x) is going to print a message to
the screen...

>>> sin(pi/2)
calculating your sine... hang on...
1.0

... I might as well not use it because this will get mixed with my own
print() statements and I'll be surprised about who added that
calculating-your-sine message.  So adding print() statements to
procedures is, in practice, rare.  (To them it's the most typical
operation because they never do any serious programming and they learn
their first steps out on the Internet.  In my course, print() is only
allowed after at 10th homework, after 10 weeks.)

I also explain that if f(x) prints its answer to the screen instead of
returning it, it will be harder to capture the answer in a variable.
For example,

>>> def f(x):
...   print(x + 1)
... 
>>> f(1)
2
>>> y = f(1)
2
>>> y
>>> 
>>> y == None
True

I take this opportunity to remark that Python seems to always returns
something, even if it's the ``special'' value None.

(*) The REPL

I also explain that the REPL is just another program.  Its purpose
happens to be to [r]ead, [e]val, [p]rint and [l]oop, which is why we get
to see return values printed to the screen.

(*) My insatisfaction

I wish I had simpler answers.  Explaining about operating systems, the
CPU, system calls...  I wish there was an easier way to clarify such
things.  You guys might have ideas.

I'm thinking about showing them the code for the simplest toy-REPL so
that we can perhaps demystify the REPL.  I think they see the REPL as
part of the programming language, so I think it might help to figure out
that nothing happens unless code is written to make it happen.  If
something gets displayed on the screen, there is definitely some i/o
going on and print() is the one initiating that i/o, while return is
just another ``arithmetic'' operation such as addition.

Thank you so much.
-- 
https://mail.python.org/mailman/listinfo/python-list


Now for something completely different...

2022-05-22 Thread Skip Montanaro
This isn't really Python-related, but I don't wander around any more
general software engineering/computer science places on the web, so I will
throw this out here.

I start a framebuilding class next week (lugged steel construction for
those into bikes). After about three weeks of work, I should have a
custom-made frame, which will also happen to have been built by me. It will
need paint or powder coat and graphics. I'm looking for ideas about the
graphics.

Though I spent most of my professional life noodling around with Python
(I'm now retired), I don't really want the graphics to be terribly
Python-centric. Consequently, "import this" is probably not going to work.
I have decided to go ahead and use my first name in lower case Courier as
the core piece of the downtube graphic:

skip

That's not too informative (other than its relationship to moi), and I have
room for probably four or five more characters. (I have a graphic artist in
mind, so the space need not strictly be text either.)

So, how would you fill the remaining space? I've considered "n++" or "n+1",
but not thought of anything more than that. For those who are not into
bikes, you may not have heard of the Velominati Rules
. I quote Rule #12:

*The correct number of bikes to own is n+1.*
While the minimum number of bikes one should own is three, the correct
number is n+1, where n is the number of bikes currently owned. This
equation may also be re-written as s-1, where s is the number of bikes
owned that would result in separation from your partner.

I currently have six to ten, depending on how demanding you are that they
be ready to ride with nothing more than air in the tires. This project,
while definitely n+1 might well also be approaching s-1. :-)

Ideas about head tube graphics are also welcome. I have no idea there at
all yet. Again, some subtle reference to software engineering would be nice.

So, if you'd like to play along, toss out some ideas. I'll consider
everything as long as it's not NSFW.

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