Re: Android APK

2023-01-25 Thread jacob kruger

Beeware is the only one I have tried out:

https://beeware.org/


Jacob Kruger
+2782 413 4791
"Resistance is futile...but, acceptance is versatile..."


On 2023/01/25 22:55, Jules Tillinghast wrote:

Is there a good python library for converting python3 to android APK


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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Dino

On 1/25/2023 3:27 PM, Dino wrote:

On 1/25/2023 1:33 PM, orzodk wrote:


I have used locust with success in the past.

https://locust.io


First impression, exactly what I need. Thank you Orzo!


the more I learn about Locust and I tinker with it, the more I love it. 
Thanks again.

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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Thomas Passin

On 1/25/2023 8:36 PM, Chris Angelico wrote:

On Thu, 26 Jan 2023 at 12:06, Thomas Passin  wrote:


On 1/25/2023 7:38 PM, Peter J. Holzer wrote:

On 2023-01-25 16:30:56 -0500, Thomas Passin wrote:

Great!  Don't forget what I said about potential overheating if you
hit the server with as many requests as it can handle.


Frankly, if you can overheat a server by hitting it with HTTP requests,
get better hardware and/or put it into a place with better airflow.



Frankly, if you have a server-grade machine then well and good but if
you are running a nice quiet consumer grade laptop - my development
machine - you need to be careful.  We don't know what hardware the OP is
using.  And it's not servicing the requests per se that's the issue,
it's the heavy computing load that has to be done for each request.  The
CPU is generally pegged at 100% for most or all of the test.


If you have to worry about thermals because of CPU load, then worry
about thermals because of CPU load. The HTTP request testing is
completely separate.

Load testing means putting a system under load. I'm not sure why you'd
be concerned about one specific possible consequence, rather than, I
dunno, just put the system under load and see how it performs?


This is not that hard, folks!  I needed to know the throughput of this 
system if it were hit with a great many queries at once, as if it were a 
busy help desk, for instance.  The intent is not to bring the server to 
its knees as a load test for the server, it's to measure the maximum 
throughput for independent queries.  It happens that each query takes a 
lot of processing, so the system is not IO bound, it's CPU bound.  The 
result is a large CPU load and a large amount of heat generated.


"just put the system under load and see how it performs" This is exactly 
what was happening, but not in the service of stressing the computer, 
but in finding the throughput for this particular Tomcat app with 
representative queries.  As a byproduct, I noticed very high CPU 
temperatures, which probably wouldn't have occurred in a datacenter 
server with much better cooling.  I didn't care about that except for 
protecting my own laptop.


And this is way OT for the OP's question.
--
https://mail.python.org/mailman/listinfo/python-list


RE: bool and int

2023-01-25 Thread avi.e.gross
Like Chris, I appreciate precision when it matters but since I am not
writing a textbook here, I often talk more informally.

There are many variations on now variables or objects are treated
differently in certain languages and when I said "STRONG" I simply meant a
sort of opposite to "WEAK". I could have used any number of silly words like
"mighty typing" and most would have been meaningless.

As pyt...@bladeshadow.org points out, from some perspectives, Python plays
quite fast and lose about what a variable can refer to. It is not a bug but
a proud feature of the language that you can easily do all kinds of things
with a kind of polymorphism (and I do NOT want to hear how I misused that
term in some technical way).

I have been reading about the ways Python keeps amending the ways you can
tell a program about the types a variable can hold and it gets quite amusing
in some ways. First, almost anything you write has to be IGNORED at
run-time. You are sort of just slowing down things and making your program
text longer, albeit the byte-compiled files may toss much of that. The main
purpose if of static type checkers like mpy to badger you until you come up
with just the right incantation and even then, your program can have plenty
of bugs and fail at run-time. There is a rich and seemingly ever-growing new
set of quasi-language features for specifying more closely what a function
expects as arguments and what it might return and some are potentially very
useful except for the minor detail that at runtime, your suggestion that
your function takes only objects that implement some protocol such as
defining __lt__  is absolutely ignored. All that mpy can do is static
testing of what you CLAIM you want. 

I am not making fun, of course, but in code I develop, I have negligible
interest in using the optional typing system and checking at first. It can
truly slow things down and some of the constraints can turn out to be too
tight if you later find the method you used excludes lots of things people
would use it on. I prefer having working code before I mark it up to be less
legible but in a way that finds some possible errors, or maybe mainly forces
me to change the markup to something else. And, if I really want my code to
CATCH errors when running, the beginning of many functions will have to
contain active tests such as checking if it is one of the types I want it to
support or implements some protocol, and if not, handle the error
gracefully. Such code can be way more detailed or correct than the type
system or may be way worse but it can also in some sense be a
self-documentation that some can read easier than trying to enforce strong
typing.

If I was working on a large project with many people and the organization
had all kinds of protocols and rules, then sure, you follow them or leave.
But at some point you may ask the dumb question of why they are using Python
at all, rather than a much "safer" language designed to minimize any ability
to make many errors as the program refuses to run until highly polished?


-Original Message-
From: Python-list  On
Behalf Of Python
Sent: Wednesday, January 25, 2023 10:06 PM
To: python-list@python.org
Subject: Re: bool and int

On Wed, Jan 25, 2023 at 01:01:24PM +1100, Chris Angelico wrote:
> On Wed, 25 Jan 2023 at 12:43,  wrote:
> > Python has a different philosophy than some other languages with 
> > strong typing. In some of those, you would not be allowed to add or 
> > multiply at random but would need to convert parts of your 
> > calculation to all be the same, such as a 32-bit integer. You could 
> > still do things like I mention above but only after consciously 
> > mapping your Boolean to an actual zero or one of the kind wanted.
> 
> Python is strongly dynamically typed. You may be thinking of "static 
> typing" rather than "strong typing" here,

You often insist on this but frankly it does not jibe with the definitions
of "strongly typed language" that I was taught or that I still see used
commonly, including in literature and on sites that aim to teach people
about computer science, which basically amount to:

1. A language whose variables are defined by type, and can only hold
   that type, typically but not necessarily compiled.
2. A language which strongly enforces restrictions on mixing or
   operating on, and/or implicitly converting different data types,
   with the implication that the structure of types is well-defined
   and rigid.

Python conforms to neither--its VARIABLES are normally untyped (though the
object data they hold obviously is).  Object instances can have new fields
added to them on the fly, willy-nilly, and Python allows for any object
which has an interface--or rather only the portion of interface you care
about in the moment--like the one it expects, to be used in a given context,
i.e. duck typing.  Useful properties (when used carefully!) but not
intuitively consistent with the idea of "strong typing" and potentially

[Help Request] Embedding Python in a CPP Application Responsibly & Functionally

2023-01-25 Thread John McCardle

Greetings,

I'm working on embedding a Python interpreter into a C++ application. My 
embedding example program is here, largely taken from Python docs: 
https://gist.github.com/jmccardle/f3f19d3753ae023aa52b927f0d181c43


I'm simply not interested in writing in Lua, so regardless of any 
particular downsides like `sys` in the standard library or performance 
issues, I'm committed to Python itself as what I want to hack in. This 
is for fun.


I started by compiling Python:

`./configure --enable-shared --enable-optimizations`

Then I can compile my example embedded program:

`g++ -I Python-3.11.1/Include -I Python-3.11.1 -L Python-3.11.1 -pthread 
scripting_engine.cpp libpython3.11.a -o scripteng -lm -ldl -lutil`


This is working not so bad! I can control what C++ functionality is 
exposed and I seemingly don't need anything but the Python shared object 
to execute. But the finer details of making this work truly correctly 
are eluding me.


1) To get the compiled Python to run independently, I have to hack 
LD_LIBRARY_PATH to get it to execute. `LD_LIBRARY_PATH=./Python-3.11.1 
./Python-3.11.1/python` . Even when trying to execute from the same 
directory as the binary & executable, I get an error, `/python: error 
while loading shared libraries: libpython3.11.so.1.0: cannot open shared 
object file: No such file or directory`.


2) When running the C++ program that embeds Python, I see these messages 
after initializing:

`Could not find platform independent libraries 
Could not find platform dependent libraries `

This is seemingly connected to some issues regarding libraries: When I 
run the Python interpreter directly, I can get some of the way through 
the process of creating a virtual environment, but it doesn't seem to 
leave me with a working pip:


`$ LD_LIBRARY_PATH=./Python-3.11.1 ./Python-3.11.1/python
>>> import venv
>>> venv.create("./venv", with_pip=True)
subprocess.CalledProcessError: Command 
'['/home/john/Development/7DRL/cpp_embedded_python/venv/bin/python', 
'-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit 
status 127.`


Meanwhile, if I try to run a script from the C++ program that includes 
`import venv`, I get a traceback about a platform library:


`Traceback (most recent call last):
  File "engine_user.py", line 7, in 
    import venv
  File 
"/home/john/Development/7DRL/cpp_embedded_python/Python-3.11.1/Lib/venv/__init__.py", 
line 10, in 

    import subprocess
  File 
"/home/john/Development/7DRL/cpp_embedded_python/Python-3.11.1/Lib/subprocess.py", 
line 104, in 

    from _posixsubprocess import fork_exec as _fork_exec
ModuleNotFoundError: No module named '_posixsubprocess'
`

3) I'm not sure I even need to be statically linking the interpreter.

My desired end state is this:
* Deploy a C++ program that doesn't rely on a system Python. I'm not 
sure if I need just the shared object / DLLs, or a Python executable in 
a subdirectory - I'd like to "do it the right way".
* C++ program can run a script to create a virtual environment, which 
the embedded Python environment will use. Users can activate the venv 
like any other Python environment and install packages with pip.
* ideally, some sort of "inside-out" runnable mode, where the API 
exposed by the C++ executable is available in that venv, so that I can 
test a script in Thonny or other IDE. I think I'd do this by providing a 
separate test-mode library in the venv, and when C++ executes 
`PyImport_AppendInittab("scriptable", _scriptable);` then the 
module of the same name should be overwritten with the C++ program's 
functionality.


I've been through the embedded programming docs a bit, and they seem 
quite good as a reference, but I don't know what I'm doing well enough 
to solve my problems using them. Thanks for reading.


My ultimate goal is to expose features written in C++ for a game engine 
using SFML, and run .py files in a subdirectory to generate maps, 
control NPC dialogue and actions, etc. I'm hoping to have something 
usable for this year's 7DRL, which starts March 4th. I'd like to spend 
the time until then getting this engine working smoothly and porting it 
to Windows, so I can focus exclusively on "game content" for the 
timeboxed 7-day portion.


Kind Regards,
-John McCardle

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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 14:13, Jach Feng  wrote:
> Now I understand some oppose this idea and saying that you shouldn't use a 
> kitchen knife to cut a cake:-)

You shouldn't use a chainsaw to cut a cake, and then ask us why
cake-cutting is so noisy.

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


Re: bool and int

2023-01-25 Thread Python
On Wed, Jan 25, 2023 at 01:01:24PM +1100, Chris Angelico wrote:
> On Wed, 25 Jan 2023 at 12:43,  wrote:
> > Python has a different philosophy than some other languages with strong
> > typing. In some of those, you would not be allowed to add or multiply at
> > random but would need to convert parts of your calculation to all be the
> > same, such as a 32-bit integer. You could still do things like I mention
> > above but only after consciously mapping your Boolean to an actual zero or
> > one of the kind wanted.
> 
> Python is strongly dynamically typed. You may be thinking of "static
> typing" rather than "strong typing" here,

You often insist on this but frankly it does not jibe with the
definitions of "strongly typed language" that I was taught or that I
still see used commonly, including in literature and on sites that aim
to teach people about computer science, which basically amount to:

1. A language whose variables are defined by type, and can only hold
   that type, typically but not necessarily compiled.
2. A language which strongly enforces restrictions on mixing or
   operating on, and/or implicitly converting different data types,
   with the implication that the structure of types is well-defined
   and rigid.

Python conforms to neither--its VARIABLES are normally untyped (though
the object data they hold obviously is).  Object instances can have
new fields added to them on the fly, willy-nilly, and Python allows
for any object which has an interface--or rather only the portion of
interface you care about in the moment--like the one it expects, to be
used in a given context, i.e. duck typing.  Useful properties (when
used carefully!) but not intuitively consistent with the idea of
"strong typing" and potentially dangerous if care is not taken.  When
YOU say that Python is strongly typed, you're using some other
definition--one that is perhaps technically correct, but seemingly
quite a lot of people in the field--including active students, college
professors, and seasoned professionsals--are unaware of...

The above usages are common and widespread, widely accepted--which is
inherently what makes word usages correct--and you very obviously know
full well what people mean when they use them; so "correcting" people
who use them seems rather unhelpful (certainly without detailing what
you think it means), inappropriate, and arguably just simply wrong.
It seems to serve no purpose other than to make communication harder,
and possibly to irritate people.  I would encourage you to consider
ceasing the practice, so as to not needlessly detract from the
otherwise usually good info you routinely provide...

And FWIW if you want some references, a google search will return
voluminous examples of people using the term as I described--from
acadamia to business--but here are just a few: 

https://www.cs.cornell.edu/courses/cs1130/2012sp/1130selfpaced/module1/module1part4/strongtyping.html
https://courses.yarrahills.vic.edu.au/moodle/mod/book/view.php?id=18778=28
https://www.oreilly.com/library/view/mastering-c-and/9781785884375/ch02s02.html
https://www.postgresql.org/docs/current/typeconv-overview.html
https://www.sciencedirect.com/topics/computer-science/strongly-typed-language
https://www.techtarget.com/whatis/definition/strongly-typed

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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread Jach Feng
Jach Feng 在 2023年1月22日 星期日上午11:11:22 [UTC+8] 的信中寫道:
> Fail on command line, 
> 
> e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2" 
> usage: infix2postfix.py [-h] [infix] 
> infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2 
> 
> Also fail in REPL, 
> 
> e:\Works\Python>py 
> Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
> (Intel)] on win32 
> Type "help", "copyright", "credits" or "license" for more information. 
> >>> import argparse 
> >>> parser = argparse.ArgumentParser(description='Convert infix notation to 
> >>> postfix') 
> >>> parser.parse_args("-4^2+5.3*abs(-2-1)/2") 
> usage: [-h] 
> : error: unrecognized arguments: - 4 ^ 2 + 5 . 3 * a b s ( - 2 - 1 ) / 2 
> 
> Just can't figure out where is wrong!? 
> 
> --Jach
I appreciate every comment/suggestion in this thread even sometimes I may not 
fully understand what they mean. To me, argparse has been just a tool which I 
can use in a CLI app. I use it as long as the situation allows, even it's as 
simple as only one positional argument is needed. Now I understand some oppose 
this idea and saying that you shouldn't use a kitchen knife to cut a cake:-)
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: bool and int

2023-01-25 Thread avi.e.gross
Chris,

We generally agree albeit I have a question in python with the concept of
being truthy that results in either a Boolean value that boils down to 0 and
1 but in some cases may boil down to the last evaluated argument which
remains in a form that may not be either a Boolean or an integer. I think
this can happen with something like a short-circuit OR. 

Assuming I vaguely remember something real and actual, you can end up with a
variable holding either a Boolean or almost anything and should not use it
in an arithmetical capacity directly but perhaps only use bool(thing) ...

Avi

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Wednesday, January 25, 2023 5:43 PM
To: python-list@python.org
Subject: Re: bool and int

On Thu, 26 Jan 2023 at 08:19, Dino  wrote:
>
> On 1/23/2023 11:22 PM, Dino wrote:
> >  >>> b = True
> >  >>> isinstance(b,bool)
> > True
> >  >>> isinstance(b,int)
> > True
> >  >>>
>
> ok, I read everything you guys wrote. Everyone's got their reasons 
> obviously, but allow me to observe that there's also something called 
> "principle of least surprise".
>
> In my case, it took me some time to figure out where a nasty bug was 
> hidden. Letting a bool be a int is quite a gotcha, no matter how hard 
> the benevolent dictator tries to convince me otherwise!
>

Try this (or its equivalent) in as many languages as possible:

x = (1 > 2)
x == 0

You'll find that x (which has effectively been set to False, or its
equivalent in any language) will be equal to zero in a very large number of
languages. Thus, to an experienced programmer, it would actually be quite
the opposite: having it NOT be a number would be the surprising thing!

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

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


RE: bool and int

2023-01-25 Thread avi.e.gross
Dino,

There is no such things as a "principle of least surprise" or if you insist
there is, I can nominate many more such "rules" such as "the principle of
get out of my way and let me do what I want!"

Computer languages with too many rules are sometimes next to unusable in
practical situations.

I am neither defending or attacking choices Python or other languages have
made. I merely observe and agree to use languages carefully and as
documented.

But consider that the history of computer science when it came to counting
numbers depends on bits. Pretty much everything is in base two. When space
was a major concern, or efficiency, people often used smaller units when
possible. If you look at something like how one stored files on UNIX, they
set aside a group of bits of some size as part of some larger entity and
each bit represented a BOOLEAN concept of 1 and 0 to mean is that bit set to
some sort of ON or off. Three of those bits controlled whether the owner of
a file had permission to read, write or execute the file. Another three
governed the same idea for everyone listed as being in the same group and
another three listed permissions for "other". The whole thing took up more
room in something larger where perhaps 14 bytes (of 8 bits each) were set
aside to hold a filename and other parts held things like perhaps a link
count. At some point they noticed the chink had a few unused bits and
invented a purpose for them and patented the setuid bit concept and the
setgid bit.

So back to integers. You can use 16 bits in a signed or unsigned manner and
cover numbers between a low and a high. You can use 64 bits or 128 bits or
whatever makes you happy and it remains an integer albeit trying to do
arithmetic between them can result in an overflow situation and the hardware
often does not trivially support it. It turned out that often there was a
use for 8 bits even though they hold only 256 possible integers and before
the alphabets grew to need more room, that was enough space for an ASCII or
EBCDIC character. Sometimes you did things at the nibble level of 4 bits or
a hex digit. Booleans were even simpler at 1 bit. But all SIZES can be used
to hold some range of integers. Modern python has made some extensions that
let you store integers of unlimited size but underneath it all, the
operations are still dealing with the same ideas as shorter versions
including ones that hold more limited numbers down to binary/Boolean.

So if you want to save space in memory or on a hard disk or sending across
the internet, you well may want the ability to set aside a "char" to hold
smallish numbers or treat a Boolean value as a "1" and so on. If you know
what you are doing, it is not much of a surprise. On many systems, there may
well be some registers that load 32 or 64 bits and then you use them for
something like addition. If I supply a 16-bit or 8-bit or even 1-bit
quantity, the software generally ends up putting it into the standard size
register and pads unused areas with zeroes. No big deal. If the number is
too large to fit, as with any larger integer in python, then the software
does whatever it needs to such as calculating how many chunks need adding
and doing the addition in the same registers in smaller chunks while
managing any carryover and finally assembling the possibly longer result. 

Floating point is a slightly different animal than the others that arguably
are all of a similar if not identical type. But even there, your storage has
two components which are actually both seen as integers of sorts. 6.02 times
ten to the 23rd might also be written as 602 times ten to the 21st and now
you have two integers you can use in calculations that registers do on
integers and recombine into a new floating point format. Or, of course, you
might have hardware that does the work.

If you move on to complex variables, they tend to be a sort of named  tuple
containing a real and imaginary part with special rules on how to add and do
other mathematical operations. Underneath it all, they are often implemented
as a pair of linked  floating point structures. And in one sense, all real
numbers represented in a floating point variable are a strict subset of
complex numbers with imaginary part being zero. All integers are in a sense
floating point numbers with fractional part (meaning beyond the decimal
point) being all zeroes.  Similarly, all smaller integral types such as
bytes are Booleans are a limited subset. 

So some of us who know a bit about CS and not just this language, are less
often surprised by a choice of implementations. We often do not mix things
but when we do, we know what we are doing much of the time and appreciate
how easily it can be done. Consider what happens if you want to circularly
permute alphabetic characters of the English Alphabet by 13, sometimes
called rot13. There are quite a few ways to do it but one of them depends on
the fact that the numerical value in ASCII of the letter 'A' is one less

Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 12:06, Thomas Passin  wrote:
>
> On 1/25/2023 7:38 PM, Peter J. Holzer wrote:
> > On 2023-01-25 16:30:56 -0500, Thomas Passin wrote:
> >> Great!  Don't forget what I said about potential overheating if you
> >> hit the server with as many requests as it can handle.
> >
> > Frankly, if you can overheat a server by hitting it with HTTP requests,
> > get better hardware and/or put it into a place with better airflow.
> >
>
> Frankly, if you have a server-grade machine then well and good but if
> you are running a nice quiet consumer grade laptop - my development
> machine - you need to be careful.  We don't know what hardware the OP is
> using.  And it's not servicing the requests per se that's the issue,
> it's the heavy computing load that has to be done for each request.  The
> CPU is generally pegged at 100% for most or all of the test.

If you have to worry about thermals because of CPU load, then worry
about thermals because of CPU load. The HTTP request testing is
completely separate.

Load testing means putting a system under load. I'm not sure why you'd
be concerned about one specific possible consequence, rather than, I
dunno, just put the system under load and see how it performs?

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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Thomas Passin

On 1/25/2023 7:38 PM, Peter J. Holzer wrote:

On 2023-01-25 16:30:56 -0500, Thomas Passin wrote:

Great!  Don't forget what I said about potential overheating if you
hit the server with as many requests as it can handle.


Frankly, if you can overheat a server by hitting it with HTTP requests,
get better hardware and/or put it into a place with better airflow.



Frankly, if you have a server-grade machine then well and good but if 
you are running a nice quiet consumer grade laptop - my development 
machine - you need to be careful.  We don't know what hardware the OP is 
using.  And it's not servicing the requests per se that's the issue, 
it's the heavy computing load that has to be done for each request.  The 
CPU is generally pegged at 100% for most or all of the test.


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


Re: Android APK

2023-01-25 Thread Skip Montanaro
>
> Is there a good python library for converting python3 to android APK
>

I'm not an app type of person, so don't watch that space. I've heard of
Kivy:

https://kivy.org/

I also something called python-for-android on PyPI with a recent release:

https://pypi.org/project/python-for-android/

I'd be interested to see what else turns up.

Skip

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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Peter J. Holzer
On 2023-01-25 16:30:56 -0500, Thomas Passin wrote:
> Great!  Don't forget what I said about potential overheating if you
> hit the server with as many requests as it can handle.

Frankly, if you can overheat a server by hitting it with HTTP requests,
get better hardware and/or put it into a place with better airflow.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread David
On Thu, 26 Jan 2023 at 04:24, Jach Feng  wrote:
> Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道:
> > On Wed, 25 Jan 2023 at 14:42, Jach Feng  wrote:

> > You're still not really using argparse as an argument parser. Why not
> > just do your own -h checking? Stop trying to use argparse for what
> > it's not designed for, and then wondering why it isn't doing what you
> > expect it to magically know.

> I just don't get what you mean?

Hi, I am writing because there seems to be a communication
problem here, not a programming problem. The thread is long
and seems to be making no progress.

You seem like a traveller who is lost and keeps looking at the
map, but they have the wrong map for where they are.

You seem to be not understanding the purpose of argparse.

In this thread, you have not mentioned any reason that requires
the use of argparse.

argparse is intended to help when your program accepts
>>> more than one kind of argument <<<
and then uses those different kinds of argument
>>> for different purposes <<<.

The programmer can handle that situation without argparse.
But argparse makes it easier.

In this thread, you have not described your program as accepting
different kinds of arguments. Therefore the people replying to you
are telling you that you do not need it.

You seem to be not listening to that, and you have not explained why,
you seem to just keep ignoring what people are telling you.

If you disagree with this, then a way forward is for you to think harder
about what benefits you are getting in your program by using argparse,
and >>> explain those benefits clearly to your readers here <<<.

An alternative approach would be for you to remove argparse from
your program, and try to write your program without it. And
then ask here about any difficulties that you have with doing that,
and I imagine people will be glad to help you.

All of the replies you have received so far are trying to help you,
even if you don't feel that. Good luck.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool and int

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 08:19, Dino  wrote:
>
> On 1/23/2023 11:22 PM, Dino wrote:
> >  >>> b = True
> >  >>> isinstance(b,bool)
> > True
> >  >>> isinstance(b,int)
> > True
> >  >>>
>
> ok, I read everything you guys wrote. Everyone's got their reasons
> obviously, but allow me to observe that there's also something called
> "principle of least surprise".
>
> In my case, it took me some time to figure out where a nasty bug was
> hidden. Letting a bool be a int is quite a gotcha, no matter how hard
> the benevolent dictator tries to convince me otherwise!
>

Try this (or its equivalent) in as many languages as possible:

x = (1 > 2)
x == 0

You'll find that x (which has effectively been set to False, or its
equivalent in any language) will be equal to zero in a very large
number of languages. Thus, to an experienced programmer, it would
actually be quite the opposite: having it NOT be a number would be the
surprising thing!

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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Thomas Passin

On 1/25/2023 3:29 PM, Dino wrote:

On 1/25/2023 1:21 PM, Thomas Passin wrote:



I actually have a Python program that does exactly this. 


Thank you, Thomas. I'll check out Locust, mentioned by Orzodk, as it 
looks like a mature library that appears to do exactly what I was hoping.


Great!  Don't forget what I said about potential overheating if you hit 
the server with as many requests as it can handle.


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


Android APK

2023-01-25 Thread Jules Tillinghast
Is there a good python library for converting python3 to android APK

-- 


Please consider the environment before printing this email.Remember when 
writing or responding to email, the Massachusetts Secretary of State has 
determined that e-mail is a public record. All electronic messages sent 
from the Northampton Public Schools are archived in conformance with 
Massachusetts and Federal Public Records law.

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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Dino

On 1/25/2023 1:21 PM, Thomas Passin wrote:



I actually have a Python program that does exactly this.  


Thank you, Thomas. I'll check out Locust, mentioned by Orzodk, as it 
looks like a mature library that appears to do exactly what I was hoping.




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


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Dino

On 1/25/2023 1:33 PM, orzodk wrote:



I have used locust with success in the past.

https://locust.io


First impression, exactly what I need. Thank you Orzo!
--
https://mail.python.org/mailman/listinfo/python-list


Re: bool and int

2023-01-25 Thread Dino

On 1/23/2023 11:22 PM, Dino wrote:

 >>> b = True
 >>> isinstance(b,bool)
True
 >>> isinstance(b,int)
True
 >>>


ok, I read everything you guys wrote. Everyone's got their reasons 
obviously, but allow me to observe that there's also something called 
"principle of least surprise".


In my case, it took me some time to figure out where a nasty bug was 
hidden. Letting a bool be a int is quite a gotcha, no matter how hard 
the benevolent dictator tries to convince me otherwise!




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


Re: Languages working together

2023-01-25 Thread Thomas Passin

On 1/25/2023 2:21 PM, avi.e.gr...@gmail.com wrote:

  [...] Sharing can come at many levels. I am fairly certain many
very different languages may still share libraries written ages ago and
written in C or FORTRAN and thus external to other languages and just need
some way to interface to them.


For example, good old FORTRAN LINPACK has been wrapped for many 
languages and computing frameworks.


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


Re: Evaluation of variable as f-string

2023-01-25 Thread Thomas Passin

On 1/25/2023 1:26 PM, Antoon Pardon wrote:

Op 23/01/2023 om 17:24 schreef Johannes Bauer:

Hi there,

is there an easy way to evaluate a string stored in a variable as if 
it were an f-string at runtime?


I.e., what I want is to be able to do this:

x = { "y": "z" }
print(f"-> {x['y']}")

This prints "-> z", as expected. But consider:

x = { "y": "z" }
s = "-> {x['y']}"
print(s.format(x = x))
Traceback (most recent call last):
  File "", line 1, in 
KeyError: "'y'"

Even though

s = "-> {x}"
print(s.format(x = x))

Prints the expected "-> {'y': 'z'}".

I am probably missing something but is there a reason why the following 
wouldn't do what you want:


x = { "y": "z" }
s = "-> {target}"
print(s.format(target = x['y']))


Stack overflow to the rescue:

Search phrase:  "python evaluate string as fstring"

https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string

def effify(non_f_str: str):
return eval(f'f"""{non_f_str}"""')

print(effify(s))  # prints as expected: "-> z"
--
https://mail.python.org/mailman/listinfo/python-list


Languages working together

2023-01-25 Thread avi.e.gross
Thomas,


I changed the subject line as we are not talking about bool and int anymore.

For me, there are several sides to JAVA that go beyond the "language" to the
JVM, or Java Virtual Machine. What you are describing is an example of
interoperability you can get if your language also is built on using the
JVM. Jython is an example as you mention and thus you can access
functionality written in another language as they sort of meet at the JVM
level. I have studied several others like Kotlin and Scala. 

Every language has to have some reason to exist, sometimes not a great
reason, and it is nice when you can combine the strengths of some language
you like to use for some purposes, with another language that already has
lots of code and resources you may find useful. 

They need not necessarily share an underlying sub-language like the JVM,
though. For example, I have written combination programs that in a sense
operate back and forth on data using Python and R and let me use things I
handle well in each, but of course only up to some point. But as you pointed
out a while ago, it may not always be necessary as you showed a ggplot()
implementation within python, so if all I wanted was to finish off a program
using a graphics system I am fluent in, I could have possibly remained just
within Python. Sharing can come at many levels. I am fairly certain many
very different languages may still share libraries written ages ago and
written in C or FORTRAN and thus external to other languages and just need
some way to interface to them.

Avi


-Original Message-
From: Python-list  On
Behalf Of Thomas Passin
Sent: Wednesday, January 25, 2023 8:47 AM
To: python-list@python.org
Subject: Re: bool and int

On 1/25/2023 6:53 AM, 2qdxy4rzwzuui...@potatochowder.com wrote:
> They used Java at my last job (as in, the last job I had before I 
> retired), and it was absolutely awful, for any number of reasons, the 
> gymnastics (on many levels) required to support "primitive types" 
> being one of them.

In my one serious java program, a Tomcat application, I use a small amount
of Java for the servlets and startup filters, and Jython for the heart of
the computing.  Thank goodness for Jython!
--
https://mail.python.org/mailman/listinfo/python-list

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


Re: bool and int

2023-01-25 Thread Dennis Lee Bieber
On Tue, 24 Jan 2023 20:16:31 -0500, Mike Baskin 
declaimed the following:

>Will all of you please stop sending me emails
>

Nobody is sending "you" emails deliberately (unless they have a poorly
[to me] set up client that sends to the list AND the person who wrote the
message they replied to) -- they are sending them to a Python mailing list.
The mailing list only sends them to /subscribed/ users.

Read the headers in the message for instructions...

List-Id: General discussion list for the Python programming language
 
List-Unsubscribe: ,
 
List-Archive: 
List-Post: 
List-Help: 
List-Subscribe: ,
 


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread orzodk
Dino  writes:

> Hello, I could use something like Apache ab in Python (
> https://httpd.apache.org/docs/2.4/programs/ab.html ).
>
> The reason why ab doesn't quite cut it for me is that I need to define
> a pool of HTTP requests and I want the tool to run those (as opposed
> to running the same request over and over again)
>
> Does such a marvel exist?
>
> Thinking about it, it doesn't necessarily need to be Python, but I
> guess I would have a chance to tweak things if it was.
>
> Thanks
>
> Dino


I have used locust with success in the past.

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


Re: Evaluation of variable as f-string

2023-01-25 Thread Antoon Pardon

Op 23/01/2023 om 17:24 schreef Johannes Bauer:

Hi there,

is there an easy way to evaluate a string stored in a variable as if 
it were an f-string at runtime?


I.e., what I want is to be able to do this:

x = { "y": "z" }
print(f"-> {x['y']}")

This prints "-> z", as expected. But consider:

x = { "y": "z" }
s = "-> {x['y']}"
print(s.format(x = x))
Traceback (most recent call last):
  File "", line 1, in 
KeyError: "'y'"

Even though

s = "-> {x}"
print(s.format(x = x))

Prints the expected "-> {'y': 'z'}".

I am probably missing something but is there a reason why the following 
wouldn't do what you want:


x = { "y": "z" }
s = "-> {target}"
print(s.format(target = x['y']))
--
https://mail.python.org/mailman/listinfo/python-list


Re: HTTP server benchmarking/load testing in Python

2023-01-25 Thread Thomas Passin

On 1/25/2023 10:53 AM, Dino wrote:


Hello, I could use something like Apache ab in Python ( 
https://httpd.apache.org/docs/2.4/programs/ab.html ).


The reason why ab doesn't quite cut it for me is that I need to define a 
pool of HTTP requests and I want the tool to run those (as opposed to 
running the same request over and over again)


Does such a marvel exist?

Thinking about it, it doesn't necessarily need to be Python, but I guess 
I would have a chance to tweak things if it was.



I actually have a Python program that does exactly this.  The intention 
was to simulate a large number of independent users hitting a particular 
web site as rapidly as possible, so see what the typical throughput is. 
The program is somewhat specialized in the nature of the requests, but 
the method is easy enough to implement.


The requests are composed from a pool of 300 pieces, and for each 
request, four pieces are selected randomly with replacement and combined 
to form the entire request. The idea here is to try to minimize caching, 
so as to better assess the throughput for random queries.


The program runs a configurable number of threads.  Each thread tries to 
maintain an average query rate, but you have to throttle them to prevent 
an exponential buildup of the request queue.  If you run the program, 
the server machine (usually the same as the querying machine) is likely 
to get very hot - it's can be quite a stress test - and you want to 
monitor the CPU temperatures just in case.


I can't share the actual code for copyright reasons, but the above 
description should be helpful.  The actual code is not very complicated 
nor hard to develop.


I also have a version that uses async techniques instead of threads.  To 
give a feel for using a program like this, I think I can show the 
'__main__' bit:


if __name__ == '__main__':
handleCmdLine()

# Warm up [redacted] in case it is not ready to get flooded with 
queries

for n in range(WARMUP_REPS):
HTTPClient(HOST, setpath(), True)
asyncore.loop()

# Warmup done, reset hit counter
reps = 0

# And away we go ...
for n in range(NUMCLIENTS):
HTTPClient(HOST, setpath())

start = clock()
asyncore.loop(timeout=50)
now = clock()

sys.stderr.write('\n')
reps_per_sec = reps / (now - start)
print ('%0.1f hits/sec' % reps_per_sec)


There are also some polling-based systems available that do a similar 
job.  I don't remember the name of the one I tried a few years ago.  It 
ran a server to run the queries and reported the results via your browser.



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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread Weatherby,Gerard
Use a different prefix character

parser = argparse.ArgumentParser(prefix_chars='%')
parser.add_argument('expression')

args = parser.parse_args()
print(args.expression)

argparser is for allowing multiple command line options to be passed, providing 
default, controlling the number of arguments and the like.


From: Python-list  on 
behalf of Jach Feng 
Date: Wednesday, January 25, 2023 at 12:25 PM
To: python-list@python.org 
Subject: Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道:
> On Wed, 25 Jan 2023 at 14:42, Jach Feng  wrote:
> > I was happy working with argparse during implement my script. To save the 
> > typing, I used a default equation for testing.
> >
> > sample = "-4^2+5.3*abs(-2-1)/2, abs(Abc)*(B+C)/D, (-3) * 
> > sqrt(1-(x1/7)*(y1/7)) * sqrt(abs((x0-4.5)/(y0-4)))"
> > parser = argparse.ArgumentParser(description='Convert infix notation to 
> > postfix')
> > parser.add_argument('infix', nargs='?', default=sample, help="")
> >
> You're still not really using argparse as an argument parser. Why not
> just do your own -h checking? Stop trying to use argparse for what
> it's not designed for, and then wondering why it isn't doing what you
> expect it to magically know.
>
> ChrisA
I just don't get what you mean?

> You're still not really using argparse as an argument parser. Why not just do 
> your own -h checking?

Is a math equation not qualified as a command line "argument"? What criteria do 
you use when judging the quality of an "argument"?

> Stop trying to use argparse for what it's not designed for,

Even the author considers a positional argument begin with '-' is a legal 
argument. Below is a quote from its manual.

"If you have positional arguments that must begin with - and don’t look like 
negative numbers, you can insert the pseudo-argument '--' which tells 
parse_args() that everything after that is a positional argument"

> and then wondering why it isn't doing what you expect it to magically know."

I don't expect magic, I expect the consistency of a parser.
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jfetVCL_U0v2RwXvkQWkim9VOYbZSJsWxRjWVlhpCDNHLoBWGyPJKGC_vh1Hwkrm3AzcX2KNEOUFKNNBx0tG$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 04:25, Jach Feng  wrote:
>
> Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道:
> > On Wed, 25 Jan 2023 at 14:42, Jach Feng  wrote:
> > > I was happy working with argparse during implement my script. To save the 
> > > typing, I used a default equation for testing.
> > >
> > > sample = "-4^2+5.3*abs(-2-1)/2, abs(Abc)*(B+C)/D, (-3) * 
> > > sqrt(1-(x1/7)*(y1/7)) * sqrt(abs((x0-4.5)/(y0-4)))"
> > > parser = argparse.ArgumentParser(description='Convert infix notation to 
> > > postfix')
> > > parser.add_argument('infix', nargs='?', default=sample, help="")
> > >
> > You're still not really using argparse as an argument parser. Why not
> > just do your own -h checking? Stop trying to use argparse for what
> > it's not designed for, and then wondering why it isn't doing what you
> > expect it to magically know.
> >
> > ChrisA
> I just don't get what you mean?
>
> > You're still not really using argparse as an argument parser. Why not just 
> > do your own -h checking?
>
> Is a math equation not qualified as a command line "argument"? What criteria 
> do you use when judging the quality of an "argument"?
>

Print out sys.argv and then figure out whether you need an argument
*parser* to *parse* your arguments. From what I'm seeing, you don't.
You just need the arguments.

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


HTTP server benchmarking/load testing in Python

2023-01-25 Thread Dino



Hello, I could use something like Apache ab in Python ( 
https://httpd.apache.org/docs/2.4/programs/ab.html ).


The reason why ab doesn't quite cut it for me is that I need to define a 
pool of HTTP requests and I want the tool to run those (as opposed to 
running the same request over and over again)


Does such a marvel exist?

Thinking about it, it doesn't necessarily need to be Python, but I guess 
I would have a chance to tweak things if it was.


Thanks

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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-25 Thread Jach Feng
Chris Angelico 在 2023年1月25日 星期三下午1:16:25 [UTC+8] 的信中寫道:
> On Wed, 25 Jan 2023 at 14:42, Jach Feng  wrote: 
> > I was happy working with argparse during implement my script. To save the 
> > typing, I used a default equation for testing. 
> > 
> > sample = "-4^2+5.3*abs(-2-1)/2, abs(Abc)*(B+C)/D, (-3) * 
> > sqrt(1-(x1/7)*(y1/7)) * sqrt(abs((x0-4.5)/(y0-4)))" 
> > parser = argparse.ArgumentParser(description='Convert infix notation to 
> > postfix') 
> > parser.add_argument('infix', nargs='?', default=sample, help="") 
> >
> You're still not really using argparse as an argument parser. Why not 
> just do your own -h checking? Stop trying to use argparse for what 
> it's not designed for, and then wondering why it isn't doing what you 
> expect it to magically know. 
> 
> ChrisA
I just don't get what you mean?

> You're still not really using argparse as an argument parser. Why not just do 
> your own -h checking?

Is a math equation not qualified as a command line "argument"? What criteria do 
you use when judging the quality of an "argument"?

> Stop trying to use argparse for what it's not designed for,

Even the author considers a positional argument begin with '-' is a legal 
argument. Below is a quote from its manual.

"If you have positional arguments that must begin with - and don’t look like 
negative numbers, you can insert the pseudo-argument '--' which tells 
parse_args() that everything after that is a positional argument"

> and then wondering why it isn't doing what you expect it to magically know."

I don't expect magic, I expect the consistency of a parser.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool and int

2023-01-25 Thread rbowman
On Wed, 25 Jan 2023 06:53:44 -0500, 2QdxY4RzWzUUiLuE wrote:


> They used Java at my last job (as in, the last job I had before I
> retired), and it was absolutely awful, for any number of reasons, the
> gymnastics (on many levels) required to support "primitive types" being
> one of them.

My first brush with Java was around '98 when it was first becoming 
popular. To familiarize myself with the AWT I decided to write a simple 
IDE for the AVR microcontrollers. What a disaster. The UI wasn't bad but 
the instructions for 8-bit processors require a lot of bit fiddling that 
was extraordinarily difficult in Java.

Then they came out with Swing and the assumption if the app ran with 
glacial slowness you should get a faster machine.

The company I work for has one Java app created around 2000 as a cross 
platform solution as people moved to Windows. Originally it ran as an 
applet but when that window was slammed shut it became increasingly 
unwieldy.

For what I'm developing today I used either .NET C# or Python3. The .NET 
UI's on Linux aren't quite there yet but back end applications are fine. 
PyQt (PySide actually. If there is a way to screw up commercial licensing 
Qt will find it) is fine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool and int

2023-01-25 Thread Chris Angelico
On Thu, 26 Jan 2023 at 03:19, <2qdxy4rzwzuui...@potatochowder.com> wrote:
> > Strongly disagree. There is PLENTY of practical value in using
> > booleans as numbers. This is nothing to do with counting bytes, and
> > everything to do with how useful it is in practice.
>
> IMO, the difference in readability between
>
> autothrust_last_dv *= AT_mode == AT.Idle;
>
> and
>
> if(AT_mode != AT.Idle)
> autothrust_last_dv = 0;
>
> outweighs the practicality, whether C, C#, Java, or Python (ignoring the
> insignificant differences in syntax).

Yeah, that example was completely synthetic and not really a good
showcase. But what often comes up is either multiplying a string by a
boolean (equivalent to "have this string if this is true") or
subscripting something with a boolean.

> I could argue that the only reason the first one is readable at all is
> that we've both been exposed to languages where fanatics assume that
> True is 1 and False is 0.

I'm fine with any definition as long as it's dependable.

> I've also written low-level code with
> hardware fanatics who insist that True is 0 and False is -1 (or 255,
> depending on how much math they know).

BASIC was like that too, although it (at least, the versions I used in
my childhood) didn't have "True" and "False", you just got the actual
values -1 and 0. They were the other way around compared to what
you're saying here though.

> In a posix shell script (or a
> program that knows it might be run inside such a script), 0 is "true"
> and non-zero is "false."

And that's a consequence of a system wherein there is only one concept
of "success", but many concepts of "failure". Whoever devised that
system was clearly a pessimist :)

> My point here is that you have to understand
> how to work within whatever environment you're using, and that future
> programmers (and future you!)  will have to deal with your choices
> regardless of their background, biases, and preferences.

That's always the case, though.

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


Re: bool and int

2023-01-25 Thread 2QdxY4RzWzUUiLuE
On 2023-01-25 at 23:11:37 +1100,
Chris Angelico  wrote:

> On Wed, 25 Jan 2023 at 22:55, <2qdxy4rzwzuui...@potatochowder.com> wrote:

> > So, I think what you're trying to say is that you prefer the razor sharp
> > quality of truthiness to the zen of explicit being better than implicit.
> 
> Not sure what you mean here. If you want to bring this back to the Zen
> of Python, I would reference "practicality beats purity". We can do
> arithmetic on integers and floats without having to explicitly cast
> one to the other, because there's really no point in distinguishing
> them. We can do that with booleans and other types, too.

My point was that we all have our own preferences and biases, and in
this case, I think you and I lean in opposite directions, and Python is
big enough for both of us.

> > To bring this back to Python (sorry), blurring the line between booleans
> > and integers is an old machine language trick, born of the days when we
> > measured memory in bytes (and large sums of cash!) rather than gigs[0].
> > In Python3, there's no more reason to use a boolean value as integer
> > (whether to accumulate values or to test a value against zero) as there
> > is to use a string (e.g., from an HTML form) as an integer.
> 
> Strongly disagree. There is PLENTY of practical value in using
> booleans as numbers. This is nothing to do with counting bytes, and
> everything to do with how useful it is in practice.

IMO, the difference in readability between

autothrust_last_dv *= AT_mode == AT.Idle;

and

if(AT_mode != AT.Idle)
autothrust_last_dv = 0;

outweighs the practicality, whether C, C#, Java, or Python (ignoring the
insignificant differences in syntax).

Maintainability, too:  as soon as there's something else to do when
AT_mode isn't AT.Idle, I'm going to rewrite the first one as the second
one anyway.  (No, I won't mess up the braces.)

I could argue that the only reason the first one is readable at all is
that we've both been exposed to languages where fanatics assume that
True is 1 and False is 0.  I've also written low-level code with
hardware fanatics who insist that True is 0 and False is -1 (or 255,
depending on how much math they know).  In a posix shell script (or a
program that knows it might be run inside such a script), 0 is "true"
and non-zero is "false."  My point here is that you have to understand
how to work within whatever environment you're using, and that future
programmers (and future you!)  will have to deal with your choices
regardless of their background, biases, and preferences.

> C# is a pain to work with because it fails on these points of
> practicality. I'm morbidly curious as to how C# fanatics justify this
> sort of thing, given that so many languages just DTRT without needing
> to be told.

They say that Perl is practical.  ;-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool and int

2023-01-25 Thread Thomas Passin

On 1/25/2023 6:53 AM, 2qdxy4rzwzuui...@potatochowder.com wrote:

They used Java at my last job (as in, the last job I had before I
retired), and it was absolutely awful, for any number of reasons, the
gymnastics (on many levels) required to support "primitive types" being
one of them.


In my one serious java program, a Tomcat application, I use a small 
amount of Java for the servlets and startup filters, and Jython for the 
heart of the computing.  Thank goodness for Jython!

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


Re: bool and int

2023-01-25 Thread Chris Angelico
On Wed, 25 Jan 2023 at 22:55, <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2023-01-25 at 12:14:50 +1100,
> Chris Angelico  wrote:
>
> > On Wed, 25 Jan 2023 at 10:32, <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> > > The usual complaint is that some people write FORTRAN no matter what
> > > language they're actually using.  Are you writing Python in C#?  ;-)
>
> > But the way I have to write it in C# is a messed-up version of C:
>
> There's your problem:  C# isn't C, it's Java.  Java looks like C, too,
> but it isn't C, either.
>
> > So the problem isn't that I'm trying to write Python in C#, but that
> > I'm trying to write code that would work on pretty much *any other
> > C-family language*, but doesn't work on C#. I could use those
> > techniques in plenty of C-derived and C-inspired languages, but no
> > not in C#, despite looking very much C-inspired. Unfortunately the
> > truth is that C# is not *actually* C-inspired; it's really Microsoft
> > Java, so it has all the stupidities of Java:
>
> There.  Even ChrisA agrees with me.  ;-)
>
> So, I think what you're trying to say is that you prefer the razor sharp
> quality of truthiness to the zen of explicit being better than implicit.

Not sure what you mean here. If you want to bring this back to the Zen
of Python, I would reference "practicality beats purity". We can do
arithmetic on integers and floats without having to explicitly cast
one to the other, because there's really no point in distinguishing
them. We can do that with booleans and other types, too.

> To bring this back to Python (sorry), blurring the line between booleans
> and integers is an old machine language trick, born of the days when we
> measured memory in bytes (and large sums of cash!) rather than gigs[0].
> In Python3, there's no more reason to use a boolean value as integer
> (whether to accumulate values or to test a value against zero) as there
> is to use a string (e.g., from an HTML form) as an integer.

Strongly disagree. There is PLENTY of practical value in using
booleans as numbers. This is nothing to do with counting bytes, and
everything to do with how useful it is in practice.

> > But this is hardly a Python-versus-C# thing; it's Java versus most of
> > the rest of the world, and C# feigns to be part of the C style while
> > retaining the limitations of Java.
>
> IMO, the problem started when Java tried to be too much like C to
> attract (or should I say "trap"?) C developers.

Maybe. No idea. In any case, Java's restrictiveness is VERY different
from the way Python works (for instance, operator overloading, the way
strings are handled, etc), and I don't think people here want the
shackles of Java.

> > (My apologies if the Java entries look synthetic. It's because they
> > are, and that's a consequence of me not having ANY reason to write
> > Java code in, like, ever. In fact, I had to go and install a JDK just
> > to confirm that Java really did have these limitations.)
>
> They used Java at my last job (as in, the last job I had before I
> retired), and it was absolutely awful, for any number of reasons, the
> gymnastics (on many levels) required to support "primitive types" being
> one of them.

Yeah. "Primitive types" being different from "boxed types" is an
unnecessary and arbitrary distinction, like between types and classes,
or old-style classes and those that subclass object. Neither is needed
in modern Python, neither is beneficial.

Keeping bool as a subclass of int has never been in dispute. Nor has
the treatment of other types in a boolean context. I can't find
anything in the Python 3000 proposals that ever even suggested
changing either; the best I can find is this reference in PEP 285
which rejected the notions:

"""
Should we strive to eliminate non-Boolean operations on bools in the
future, through suitable warnings, so that for example True+1 would
eventually (in Python 3000) be illegal?

=> No.

Should we strive to require that Boolean operations (like “if”, “and”,
“not”) have a bool as an argument in the future, so that for example
“if []:” would become illegal and would have to be written as “if
bool([]):” ???

=> No!!!
"""

See: https://peps.python.org/pep-0285/

C# is a pain to work with because it fails on these points of
practicality. I'm morbidly curious as to how C# fanatics justify this
sort of thing, given that so many languages just DTRT without needing
to be told.

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


Re: bool and int

2023-01-25 Thread 2QdxY4RzWzUUiLuE
On 2023-01-25 at 12:14:50 +1100,
Chris Angelico  wrote:

> On Wed, 25 Jan 2023 at 10:32, <2qdxy4rzwzuui...@potatochowder.com> wrote:

> > The usual complaint is that some people write FORTRAN no matter what
> > language they're actually using.  Are you writing Python in C#?  ;-)

> But the way I have to write it in C# is a messed-up version of C:

There's your problem:  C# isn't C, it's Java.  Java looks like C, too,
but it isn't C, either.

> So the problem isn't that I'm trying to write Python in C#, but that
> I'm trying to write code that would work on pretty much *any other
> C-family language*, but doesn't work on C#. I could use those
> techniques in plenty of C-derived and C-inspired languages, but no
> not in C#, despite looking very much C-inspired. Unfortunately the
> truth is that C# is not *actually* C-inspired; it's really Microsoft
> Java, so it has all the stupidities of Java:

There.  Even ChrisA agrees with me.  ;-)

So, I think what you're trying to say is that you prefer the razor sharp
quality of truthiness to the zen of explicit being better than implicit.

To bring this back to Python (sorry), blurring the line between booleans
and integers is an old machine language trick, born of the days when we
measured memory in bytes (and large sums of cash!) rather than gigs[0].
In Python3, there's no more reason to use a boolean value as integer
(whether to accumulate values or to test a value against zero) as there
is to use a string (e.g., from an HTML form) as an integer.

[0] I remember meetings where the agenda was to allocate memory (yes, at
design time) for a particular value, and the answer was along the lines
of "you can have these five bits, and this would have taken a lot less
time had you told us sooner that you needed that value to persist across
input messages."

> But this is hardly a Python-versus-C# thing; it's Java versus most of
> the rest of the world, and C# feigns to be part of the C style while
> retaining the limitations of Java.

IMO, the problem started when Java tried to be too much like C to
attract (or should I say "trap"?) C developers.

> (My apologies if the Java entries look synthetic. It's because they
> are, and that's a consequence of me not having ANY reason to write
> Java code in, like, ever. In fact, I had to go and install a JDK just
> to confirm that Java really did have these limitations.)

They used Java at my last job (as in, the last job I had before I
retired), and it was absolutely awful, for any number of reasons, the
gymnastics (on many levels) required to support "primitive types" being
one of them.
-- 
https://mail.python.org/mailman/listinfo/python-list