Re: Weak Type Ability for Python

2023-04-13 Thread Chris Angelico
On Thu, 13 Apr 2023 at 15:40,  wrote:
> And, no, I do not suggest 2.5 be interpreted as putting in an
> approximate percentage so that .8 * "Hello" should result in "Hell" ...

$ pike
Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend)
Ok.
> "Hello, world! " * 2.5;
(1) Result: "Hello, world! Hello, world! Hello, "
> "Hello, world! Hello, world! Hello, " / 10;
(2) Result: ({ /* 3 elements */
"Hello, wor",
"ld! Hello,",
" world! He"
})
> "Hello, world! Hello, world! Hello, " % 10;
(3) Result: "llo, "
> "Hello, world! Hello, world! Hello, " / 10.0;
(4) Result: ({ /* 4 elements */
"Hello, wor",
"ld! Hello,",
" world! He",
"llo, "
})
>

Multiplying and dividing strings by floats makes perfect sense. (The
({ }) notation is Pike's array literal syntax; consider it equivalent
to Python's square brackets for a list.)

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


Embedded python is not 100% stable

2023-04-13 Thread Guenther Sohler
Hi Python LIst,

I have been working on adding embedded python into OpenSCAD (
www.openscad.org)
for some time already. For that i coded/added an additional Python Type
Object
which means to hold openscad geometric data.

It works quite well but unfortunately its not 100% stable and i have been
heavily checking
all the functions which are referenced in the PyType Object and tried to
match
them with the documentation which i found in the python web site but now i
am stuck
and i cant progress any further
I am specially interested why the program constantly crashes when i
activate the lines 14 and 15
in pyopenscad.cc.
I have attached the two most relevant files and I would be happy if anybody
interested
could tell me, if there is an obvious bug popping into your eyes.
If anybody is interested to see the complete picture, all source code is
available checked in
in github @

https://github.com/gsohler/openscad.git branch "libfive"
Thank you for reading. Any spotted bug found will make me happy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for a 'good python'

2023-04-13 Thread Lars Liedtke




Lars Liedtke
Software Entwickler

[Tel.]  +49 721 98993-
[Fax]   +49 721 98993-
[E-Mail]l...@solute.de


solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany


[Logo Solute]


Marken der solute GmbH | brands of solute GmbH
[Marken]
[Advertising Partner]

Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de 
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798



Informationen zum Datenschutz | Information about privacy policy
https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php




Am 13.04.23 um 00:21 schrieb jak:
Barry ha scritto:



On 12 Apr 2023, at 18:10, jak  wrote:
Hi everyone,
some time ago I wrote a class to determine if an ipv4 address belonged
to a subnet. Seldom using python I'm pretty sure it's not written in
'good python' nor too portable. Could you give me some advice to make it
better?

class calcip:
   def __init__(self, psubnet: str):
   ssubnet, scidr = psubnet.replace(' ', '').split('/')
   subnet = int.from_bytes(tuple(
 map(lambda n: (int(n)), ssubnet.split('.'))),
   'big')
   cidr = int(scidr)
   mask = ((2 ** cidr) - 1) << (32 - cidr)
   self.__network = subnet & mask
   self.__wildcard = ~mask & 0x
   self.__broadcast = (subnet | self.__wildcard) & 0x
   self.__tsubnet = tuple(subnet.to_bytes(4, 'big'))
   self.__tnetwork = tuple(self.__network.to_bytes(4, 'big'))
   self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big'))
   self.__tmask = tuple(mask.to_bytes(4, 'big'))
   self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big'))
   self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big'))
   self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big'))

   @staticmethod
   def __to_str(val: tuple):
   return '.'.join(str(v) for v in val)

   @property
   def subnet(self):
   return self.__to_str(self.__tsubnet)

   @property
   def network(self):
   return self.__to_str(self.__tnetwork)

   @property
   def broadcast(self):
   return self.__to_str(self.__tbroadcast)

   @property
   def mask(self):
   return self.__to_str(self.__tmask)

   @property
   def wildcard(self):
   return self.__to_str(self.__twildcard)

   @property
   def host_min(self):
   return self.__to_str(self.__host_min)

   @property
   def host_max(self):
   return self.__to_str(self.__host_max)

   @property
   def hosts_num(self):
   return self.__wildcard - 1

   @property
   def net_class(self):
   tst = (self.__tnetwork[0] & 0xf0) >> 4
   if (tst & 0x8) == 0:
   clx = 'A'
   elif (tst & 0xc) == 0x8:
   clx = 'B'
   elif (tst & 0xe) == 0xc:
   clx = 'C'
   elif (tst & 0xf) == 0xe:
   clx = 'D'
   elif (tst & 0xf) == 0xf:
   clx = 'E'
   return clx

   def __contains__(self, item):
   ret = True
   row_hdr = None
   try:
   row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), 
item.split('.'))), 'big')
   except:
   ret = False
   if ret:
   if not self.__network < row_hdr < self.__broadcast:
   ret = False
   return ret


def main():
   sn = calcip('10.0.0.0/26')

   print(f"subnet: {sn.subnet}")
   print(f"network: {sn.network}")
   print(f"broadcast: {sn.broadcast}")
   print(f"mask: {sn.mask}")
   print(f"wildcard: {sn.wildcard}")
   print(f"host_min: {sn.host_min}")
   print(f"host_max: {sn.host_max}")
   print(f"Avaible hosts: {sn.hosts_num}")
   print(f"Class: {sn.net_class}")

   tst_hdr = '10.0.0.31'
   is_not = 'is '
   if not tst_hdr in sn:
   is_not = 'is NOT '
   print("hdr %s %sin range %s - %s" %
 (tst_hdr, is_not, sn.host_min, sn.host_max))

if __name__ == '__main__':
   main()

There is this https://docs.python.org/3/howto/ipaddress.html if you just want a 
solution.

Or are you after code review feedback?

Barry

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


Thank you too. I had seen this library but I always try not to use
libraries outside the standard ones. Now I don't remember why I was
convinced that this wasn't part of it, perhaps because it was like that
at the time or because I got confused. Only now I realized that it is
not necessary to install it. Now I'm considering whether to use
'ipaddress' or 'socket'. What is certain is that this one you have
suggested is really comfortable. Thanks again for the report.

Unless I am not mistakes, ipadress is "standard" because it is in the standard 
library
--
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread J. Pic
print(f'{x}{y}') ?

On Wed, Apr 12, 2023 at 7:06 PM Ali Mohseni Roodbari <
ali.mohseniroodb...@gmail.com> wrote:

> Hi all,
> Please make this command for Python (if possible):
>
> >>> x=1
> >>> y='a'
> >>> wprint (x+y)
> >>> 1a
>
> In fact make a new type of print command which can print and show strings
> and integers together.
>
> Sincerely yours,
> Ali.
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Personnel et confidentiel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread Thomas Passin

On 4/13/2023 1:38 AM, avi.e.gr...@gmail.com wrote:

In Python, "+" does not
mean plus at all. It means whatever the programmer wanted it to mean. An
infix line of code that includes "obj1 + obj2" is supposed to investigate
how to do it. I am not sure if some built-in objects may be different, but
it does a sequence of operations till it finds what it needs and does it.


A really nice example of this is pathlib in the standard library.  You 
can write things like this, overloading the "/" operator:


>>> from pathlib import PurePath
>>> pth = PurePath('c:/') / 'temp' / 'python'
>>> pth
PureWindowsPath('c:/temp/python')
>>> str(pth)
'c:\\temp\\python'

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


Re: Embedded python is not 100% stable

2023-04-13 Thread Dieter Maurer
Guenther Sohler wrote at 2023-4-13 09:40 +0200:
> ...
>I have been working on adding embedded python into OpenSCAD (
>www.openscad.org)
>for some time already. For that i coded/added an additional Python Type
>Object
>which means to hold openscad geometric data.
>
>It works quite well but unfortunately its not 100% stable and i have been
>heavily checking
>all the functions which are referenced in the PyType Object and tried to
>match
>them with the documentation which i found in the python web site

The Python C/C++ interface is complex: it is easy to make
mistakes which may lead to crashes.

Often, `cython` (--> PyPI) can help you to define extension types
in a much safer way. Maybe, you check its documentation?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for a 'good python'

2023-04-13 Thread Barry


> On 13 Apr 2023, at 00:19, jak  wrote:
> 
> Barry ha scritto:
>> 
 On 12 Apr 2023, at 18:10, jak  wrote:
>>> Hi everyone,
>>> some time ago I wrote a class to determine if an ipv4 address belonged
>>> to a subnet. Seldom using python I'm pretty sure it's not written in
>>> 'good python' nor too portable. Could you give me some advice to make it
>>> better?
>>> class calcip:
>>>   def __init__(self, psubnet: str):
>>>   ssubnet, scidr = psubnet.replace(' ', '').split('/')
>>>   subnet = int.from_bytes(tuple(
>>> map(lambda n: (int(n)), 
>>> ssubnet.split('.'))),
>>>   'big')
>>>   cidr = int(scidr)
>>>   mask = ((2 ** cidr) - 1) << (32 - cidr)
>>>   self.__network = subnet & mask
>>>   self.__wildcard = ~mask & 0x
>>>   self.__broadcast = (subnet | self.__wildcard) & 0x
>>>   self.__tsubnet = tuple(subnet.to_bytes(4, 'big'))
>>>   self.__tnetwork = tuple(self.__network.to_bytes(4, 'big'))
>>>   self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big'))
>>>   self.__tmask = tuple(mask.to_bytes(4, 'big'))
>>>   self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big'))
>>>   self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big'))
>>>   self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big'))
>>>   @staticmethod
>>>   def __to_str(val: tuple):
>>>   return '.'.join(str(v) for v in val)
>>>   @property
>>>   def subnet(self):
>>>   return self.__to_str(self.__tsubnet)
>>>   @property
>>>   def network(self):
>>>   return self.__to_str(self.__tnetwork)
>>>   @property
>>>   def broadcast(self):
>>>   return self.__to_str(self.__tbroadcast)
>>>   @property
>>>   def mask(self):
>>>   return self.__to_str(self.__tmask)
>>>   @property
>>>   def wildcard(self):
>>>   return self.__to_str(self.__twildcard)
>>>   @property
>>>   def host_min(self):
>>>   return self.__to_str(self.__host_min)
>>>   @property
>>>   def host_max(self):
>>>   return self.__to_str(self.__host_max)
>>>   @property
>>>   def hosts_num(self):
>>>   return self.__wildcard - 1
>>>   @property
>>>   def net_class(self):
>>>   tst = (self.__tnetwork[0] & 0xf0) >> 4
>>>   if (tst & 0x8) == 0:
>>>   clx = 'A'
>>>   elif (tst & 0xc) == 0x8:
>>>   clx = 'B'
>>>   elif (tst & 0xe) == 0xc:
>>>   clx = 'C'
>>>   elif (tst & 0xf) == 0xe:
>>>   clx = 'D'
>>>   elif (tst & 0xf) == 0xf:
>>>   clx = 'E'
>>>   return clx
>>>   def __contains__(self, item):
>>>   ret = True
>>>   row_hdr = None
>>>   try:
>>>   row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), 
>>> item.split('.'))), 'big')
>>>   except:
>>>   ret = False
>>>   if ret:
>>>   if not self.__network < row_hdr < self.__broadcast:
>>>   ret = False
>>>   return ret
>>> def main():
>>>   sn = calcip('10.0.0.0/26')
>>>   print(f"subnet: {sn.subnet}")
>>>   print(f"network: {sn.network}")
>>>   print(f"broadcast: {sn.broadcast}")
>>>   print(f"mask: {sn.mask}")
>>>   print(f"wildcard: {sn.wildcard}")
>>>   print(f"host_min: {sn.host_min}")
>>>   print(f"host_max: {sn.host_max}")
>>>   print(f"Avaible hosts: {sn.hosts_num}")
>>>   print(f"Class: {sn.net_class}")
>>>   tst_hdr = '10.0.0.31'
>>>   is_not = 'is '
>>>   if not tst_hdr in sn:
>>>   is_not = 'is NOT '
>>>   print("hdr %s %sin range %s - %s" %
>>> (tst_hdr, is_not, sn.host_min, sn.host_max))
>>> if __name__ == '__main__':
>>>   main()
>> There is this https://docs.python.org/3/howto/ipaddress.html if you just 
>> want a solution.
>> Or are you after code review feedback?
>> Barry
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
> 
> 
> Thank you too. I had seen this library but I always try not to use
> libraries outside the standard ones. Now I don't remember why I was
> convinced that this wasn't part of it, perhaps because it was like that
> at the time or because I got confused. Only now I realized that it is
> not necessary to install it. Now I'm considering whether to use
> 'ipaddress' or 'socket'. What is certain is that this one you have
> suggested is really comfortable. Thanks again for the report.

Ipaddress was developed outside of the std lib and later added i recall.

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

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


Re: Weak Type Ability for Python

2023-04-13 Thread Grant Edwards
On 2023-04-13, Cameron Simpson  wrote:
> On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:
>
>>I suspect the OP is thinking of languages like PERL or JAVA which guess 
>>for you and make such conversions when it seems to make sense.
>
> JavaScript guesses. What a nightmare.

So does PHP. What's really impressive is that it never seems to guess
correctly. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
Chris, I was not suggesting it for Python as one of many possible
implementations.

I do see perfectly valid uses in other contexts. For example, if I have a
program that displays my text as pixels in some font and size, I may indeed
want the text clipped at 2 1/2 repetitions. But as always, when there are
choices to be made, you have to very clearly document the choice or offer
ways to do it another way. In a non-fixed-width font, 2.5 may mean knowing
how many pixels and adjusting so that a narrow letter "i" may be shown in
one font and not another, for example. 

If you want completeness, sure, you can define fractional parts of a string
in this context by the percentage of CHARACTERS in it. But as we have often
seen, in other encodings you need to differentiate between varying numbers
of bytes versus the underlying symbols they represent. Your  example from
the Pike language not only supports the multiplication of a string but
division and mod. Python currently does not allow those.

So why not extend it to allow complex numbers? 

>>> "Hello" * complex(5,0)
TypeError: can't multiply sequence by non-int of type 'complex'
>>> "Hello" * complex(0,5)
TypeError: can't multiply sequence by non-int of type 'complex'

The first one above is actually perfectly valid in the sense that the real
part is 5 and there is no imaginary component. With a bit of effort, I can
use the complexity to work:

>>> "Hello" * int(complex(5,0).real)
'HelloHelloHelloHelloHello'

Let me reiterate. There are languages that do all kinds of interesting
things and some of what Python has done is seen by others as interesting.
They regularly borrow from each other or use parts and innovate further. I
have no serious objection to making well-thought-out changes if they are
determined to be not only useful, but of higher priority than a long
shopping list of other requests. I am wary of overly bloating a language by
placing too many things in the core.

It strikes me as doable to create a module that encapsulates a feature like
this in a limited way. What may be needed is just a carefully constructed
class that starts off as similar to str and adds some methods. Any user
wanting to use the new feature would either start using the new class
directly or cast their str to it when they want it to be useable.

But the good news is that I am nowhere in the python hierarchy and have no
ability to make any changes. This is purely academic for me. And, if I want
such features and see tons of existing ways to get what I want or can roll
it for myself, ...


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Thursday, April 13, 2023 3:02 AM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On Thu, 13 Apr 2023 at 15:40,  wrote:
> And, no, I do not suggest 2.5 be interpreted as putting in an
> approximate percentage so that .8 * "Hello" should result in "Hell" ...

$ pike
Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend)
Ok.
> "Hello, world! " * 2.5;
(1) Result: "Hello, world! Hello, world! Hello, "
> "Hello, world! Hello, world! Hello, " / 10;
(2) Result: ({ /* 3 elements */
"Hello, wor",
"ld! Hello,",
" world! He"
})
> "Hello, world! Hello, world! Hello, " % 10;
(3) Result: "llo, "
> "Hello, world! Hello, world! Hello, " / 10.0;
(4) Result: ({ /* 4 elements */
"Hello, wor",
"ld! Hello,",
" world! He",
"llo, "
})
>

Multiplying and dividing strings by floats makes perfect sense. (The
({ }) notation is Pike's array literal syntax; consider it equivalent
to Python's square brackets for a list.)

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

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


Re: Weak Type Ability for Python

2023-04-13 Thread Chris Angelico
On Fri, 14 Apr 2023 at 02:05,  wrote:
> So why not extend it to allow complex numbers?
>
> >>> "Hello" * complex(5,0)
> TypeError: can't multiply sequence by non-int of type 'complex'
> >>> "Hello" * complex(0,5)
> TypeError: can't multiply sequence by non-int of type 'complex'
>

Clearly a missed opportunity to rotate the text through a specified angle.

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


RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
[THIS CLAIMER: a bit off a bit off a bit off topic, imagine that]

Chris,

You have a gift of taking things I think about but censor myself from
including in my post and then blurting it out! LOL!

The original question in this thread now seems a dim memory but we are now
discussing not how to add a number to a string but how to multiply a string
to make n combined copies and then what it means to have a fractional copy
and finally a way to specify a rotation to the result. Argh

But since you brought it up as a way of looking at what multiplying by an
imaginary number might mean, as in rotating text, I am now going to throw in
a May Tricks even if it is only April.

So should I now extend a language so a rotation matrix is allowed to
multiply text or even a nested list like:

[ [ cos(theta), -sin(theta) ],
  [ sin(theta), cos(theta) ]

While we are at it, why stop with imaginary numbers when you can imagine
extensions thereof? Unfortunately, it has been proven there are and can only
be two additional such constructs. Quaternions have three distinct imaginary
axes called i,j,k and some see them as interesting to show multidimensional
objects in all kinds of places such as computer vision or orbital mechanics.
Octonions have seven such other imaginary axes and have uses in esoteric
places like String Theory or Quantum Logic.

And, yes, you can use these critters in python. You can add a quaternion
type to numpy for example. Yep, octonions too. See modules like pyoctonion
and pyquaternion and much more.

The immoral moral of this story is that once you start opening some doors,
you may find people clamoring to let in ever more things and features. You
can easily bog down your code to the point where finding the commonly used
parts becomes a chore as you trudge through lots of code that is rarely used
but there for completeness.

Oh, I want to make something clear before I get another message spelling out
what I was thinking but chose to omit.

I slightly misled you above. Yes, it has been proven no number higher than 8
(meaning one real dimension and seven distinct imaginary ones) can exist so
octonions are the final part of that story. Well, not exactly. You lose
commutativity when going from quaternions to octonions and you lose full
associativity if you go higher. But you can make all kinds of mathematical
constructs like sedenions with 16 dimensions.

I cannot imagine ever trying to multiply a string by these critters but who
knows? As I noted above, if you set some parts of each of the above to zero,
they all can look like something with a real part like 3, and no (meaning
zero point zero) imaginary parts. So you could argue you should support all
kinds of things that MAY on examination turn out to be convertible to an
integer or double.

-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Thursday, April 13, 2023 12:12 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On Fri, 14 Apr 2023 at 02:05,  wrote:
> So why not extend it to allow complex numbers?
>
> >>> "Hello" * complex(5,0)
> TypeError: can't multiply sequence by non-int of type 'complex'
> >>> "Hello" * complex(0,5)
> TypeError: can't multiply sequence by non-int of type 'complex'
>

Clearly a missed opportunity to rotate the text through a specified angle.

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

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


Hide my query about covariance matrix syntax from google

2023-04-13 Thread Meghna Karkera
Respected Sir

I kindly request you to hide my query about covariance matrix syntax from
google which was emailed to you a few years back as it appears on google
page.

Hoping that you do the needful.

Dr. Meghna Raviraj Karkera
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread Dennis Lee Bieber
On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson 
declaimed the following:

>On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:
>>I suspect the OP is thinking of languages like PERL or JAVA which guess 
>>for
>>you and make such conversions when it seems to make sense.
>
>JavaScript guesses. What a nightmare. Java acts like Python and will 
>forbid it on type grounds (at compile time with Java, being staticly 
>typed).
>

REXX -- where everything is considered a string until it needs to be
something else.

REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
  rexxtry.rex lets you interactively try REXX statements.
Each string is executed when you hit Enter.
Enter 'call tell' for a description of the features.
  Go on - try a few...Enter 'exit' to end.
x = 1;
  ... rexxtry.rex on WindowsNT
y = "a";
  ... rexxtry.rex on WindowsNT
say x||y;
1a
  ... rexxtry.rex on WindowsNT
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for a 'good python'

2023-04-13 Thread jak

Dennis Lee Bieber ha scritto:

On Thu, 13 Apr 2023 00:21:58 +0200, jak  declaimed the
following:



Thank you too. I had seen this library but I always try not to use
libraries outside the standard ones. Now I don't remember why I was
convinced that this wasn't part of it, perhaps because it was like that
at the time or because I got confused. Only now I realized that it is
not necessary to install it. Now I'm considering whether to use
'ipaddress' or 'socket'. What is certain is that this one you have
suggested is really comfortable. Thanks again for the report.


It is useful to skim the contents of the standard library documentation
every couple of releases. ipaddress came in with Python 3.3

https://docs.python.org/3.10/library/index.html (I dropped down to 3.10
just as that is the version I have installed; some 3rd party modules
weren't ready when I tried to install on 3.11)



Then it was my fault. The version was 3.8.6
--
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread aapost

On 4/12/23 04:03, Ali Mohseni Roodbari wrote:
>
On 4/13/23 07:50, Stefan Ram wrote:
>If tomorrow Python would allow "string+int" and "int+string"
>in the sense of "string+str(int)" and "str(int)+string",
>what harm would be there?
>
>But for now, I think a typical approach would be to just use "str",
>i.e., "string+str(int)" and "str(int)+string".


I agree with Py Zen rule 2 in this case:
Explicit is better than implicit.

I hate when things try to guess what I am doing... It is why I can't use 
lxml.

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


Re: for a 'good python'

2023-04-13 Thread Dennis Lee Bieber
On Thu, 13 Apr 2023 00:21:58 +0200, jak  declaimed the
following:


>Thank you too. I had seen this library but I always try not to use
>libraries outside the standard ones. Now I don't remember why I was
>convinced that this wasn't part of it, perhaps because it was like that
>at the time or because I got confused. Only now I realized that it is
>not necessary to install it. Now I'm considering whether to use
>'ipaddress' or 'socket'. What is certain is that this one you have
>suggested is really comfortable. Thanks again for the report.

It is useful to skim the contents of the standard library documentation
every couple of releases. ipaddress came in with Python 3.3

https://docs.python.org/3.10/library/index.html (I dropped down to 3.10
just as that is the version I have installed; some 3rd party modules
weren't ready when I tried to install on 3.11)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread 2QdxY4RzWzUUiLuE
On 2023-04-12 at 22:47:17 -0400,
Dennis Lee Bieber  wrote:

>   REXX -- where everything is considered a string until it needs to be
> something else.

I see your REXX, and raise you an awk,¹ except that awk won't add a
string to a number, or a number to string, but it will concatenate in
both cases:

$ echo 1 a | awk '{print $1 $2}{print $1 + $2}'
1a
1

$ echo 1 a | awk '{print $2 $1}{print $2 + $1}'
a1
1

$ echo 1 2 | awk '{print $1 $2}{print $2 + $1}'
12
3

¹ GNU Awk 5.2.1, API 3.2, PMA Avon 8-g1, (GNU MPFR 4.2.0, GNU MP 6.2.1)

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


Re: Embedded python is not 100% stable

2023-04-13 Thread aapost

On 4/13/23 03:40, Guenther Sohler wrote:




Attachments are stripped, so they weren't included.

Glancing at the branch and the 2 lines you mentioned.

You have a comment with a link for python 2.3 documentation.
Yet you have python 3.10 code included elsewhere (and openscad itself 
requires the modern spec C++17, so I assume your aim is at current versions)


https://docs.python.org/3.10/extending/newtypes.html
is the equivalent doc for that.

I am not experienced in defining PyType objects in C, but notice 
syntactical discrepancies, missing "static" on dealloc, use of 
typecasted malloc rather than PyType_GenericAlloc()

https://docs.python.org/3.10/c-api/typeobj.html#c.PyTypeObject.tp_alloc

Without digging in deeper and learning more I can't say for certain 
whether or not those are issues, but intuitively I assume they would be 
and that the implementation needs to more closely mirror the syntactical 
flow implementations of modern working examples..


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


RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
This reminds me a bit of complaints that the parser does not do what you
want when you do not supply parentheses in an expression like:

5 * 4 + 3

In many and maybe most languages it is seen as (5*4)+3 UNLESS you tell it
you want 5*(4+3). There are precedence and associativity rules.

Of course the computer might guess you meant the latter or could refuse to
do it and offer you a choice before calculating it. Or the language may
insist on parentheses always so you would need to also say ((5*4)+3) with no
default behavior.

The golden rule remains. If there is more than one way something can be
done, then either the programmer must make the choice explicit OR the
documentation must very clearly warn which path was chosen and perhaps point
to ways to do other choices. 

Some people take more complex (but not Complex) arithmetic than the above
and break it up into quite a few simple parts like:

temp1 = 4 + 3
result = 5 + temp1

Of course, the latter can be hard to read and understand for some people,
and some (others?) find fully parenthesized versions hard. But having
precedence rules and also allowing the other methods, should work fine for a
good segment of people except perhaps the ones who like Reverse Polish
Notation and insist on 5 4 3 + * instead.


-Original Message-
From: Python-list  On
Behalf Of aapost
Sent: Thursday, April 13, 2023 12:28 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On 4/12/23 04:03, Ali Mohseni Roodbari wrote:
 >
On 4/13/23 07:50, Stefan Ram wrote:
 >If tomorrow Python would allow "string+int" and "int+string"
 >in the sense of "string+str(int)" and "str(int)+string",
 >what harm would be there?
 >
 >But for now, I think a typical approach would be to just use "str",
 >i.e., "string+str(int)" and "str(int)+string".


I agree with Py Zen rule 2 in this case:
Explicit is better than implicit.

I hate when things try to guess what I am doing... It is why I can't use 
lxml.
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Problem with Matplotlib example

2023-04-13 Thread Martin Schöön
Anyone had success running this example?
https://tinyurl.com/yhhyc9r

When I try I get this error:
"TypeError: __init__() got an unexpected keyword argument 'transform'"

This is for the line
"m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)"

Yes, I know, I could dive into the documentation myself but I hope
some kind soul here will help out.

As far as I know I have an up-to-date matplotlib installed. Pip has
nothing more modern to offer me.

TIA

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


Re: Weak Type Ability for Python

2023-04-13 Thread Thomas Passin

On 4/13/2023 2:36 PM, avi.e.gr...@gmail.com wrote:

But having
precedence rules and also allowing the other methods, should work fine for a
good segment of people except perhaps the ones who like Reverse Polish
Notation and insist on 5 4 3 + * instead.


For *reading*, I prefer the usual 5 * (4 + 3) form.  But for using a 
calculator, I much prefer RPN.


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


Re: Hide my query about covariance matrix syntax from google

2023-04-13 Thread Chris Angelico
On Fri, 14 Apr 2023 at 03:11, Meghna Karkera  wrote:
>
> Respected Sir
>
> I kindly request you to hide my query about covariance matrix syntax from
> google which was emailed to you a few years back as it appears on google
> page.
>
> Hoping that you do the needful.

These posts are public. While it's possible to ask for something to be
removed from the official python-list archive, that won't remove it
from Google Groups or any other third-party archive.

Also, there's nothing we can do here to remove your post; you'll have
to contact the list admins.

And just in case it's of interest to you:
https://en.wikipedia.org/wiki/Streisand_effect

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


Re: Problem with Matplotlib example

2023-04-13 Thread Thomas Passin

On 4/13/2023 2:41 PM, Martin Schöön wrote:

Anyone had success running this example?
https://tinyurl.com/yhhyc9r

When I try I get this error:
"TypeError: __init__() got an unexpected keyword argument 'transform'"

This is for the line
"m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)"

Yes, I know, I could dive into the documentation myself but I hope
some kind soul here will help out.

As far as I know I have an up-to-date matplotlib installed. Pip has
nothing more modern to offer me.


It works for me, copy-pasted as is.

Python 3.11.3

C:\Users\tom>py -m pip show matplotlib
Name: matplotlib
Version: 3.6.3

C:\Users\tom>py -m pip show numpy
Name: numpy
Version: 1.24.2

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


Re: Weak Type Ability for Python

2023-04-13 Thread Chris Angelico
On Fri, 14 Apr 2023 at 02:55,  wrote:
> And, yes, you can use these critters in python. You can add a quaternion
> type to numpy for example. Yep, octonions too.

Hang on hang on hang on. I can multiply a string by an onion? The
possibilities of script-controlled culinary arts just became that much
more awesome...

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


Re: Problem with Matplotlib example

2023-04-13 Thread MRAB

On 2023-04-13 19:41, Martin Schöön wrote:

Anyone had success running this example?
https://tinyurl.com/yhhyc9r

When I try I get this error:
"TypeError: __init__() got an unexpected keyword argument 'transform'"

This is for the line
"m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)"

Yes, I know, I could dive into the documentation myself but I hope
some kind soul here will help out.

As far as I know I have an up-to-date matplotlib installed. Pip has
nothing more modern to offer me.


All I can say is that it works for me!

Python 3.10 and 3.11, matplotlib 3.6.1 and then 3.7.1 after updating it.

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


Re: Weak Type Ability for Python

2023-04-13 Thread Chris Angelico
On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber  wrote:
>
> On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson 
> declaimed the following:
>
> >On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:
> >>I suspect the OP is thinking of languages like PERL or JAVA which guess
> >>for
> >>you and make such conversions when it seems to make sense.
> >
> >JavaScript guesses. What a nightmare. Java acts like Python and will
> >forbid it on type grounds (at compile time with Java, being staticly
> >typed).
> >
>
> REXX -- where everything is considered a string until it needs to be
> something else.
>
> REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
>   rexxtry.rex lets you interactively try REXX statements.
> Each string is executed when you hit Enter.
> Enter 'call tell' for a description of the features.
>   Go on - try a few...Enter 'exit' to end.
> x = 1;
>   ... rexxtry.rex on WindowsNT
> y = "a";
>   ... rexxtry.rex on WindowsNT
> say x||y;
> 1a
>   ... rexxtry.rex on WindowsNT

REXX - where everything is a string, arithmetic can be done on
strings, and data structures are done in the variable name instead of
the value.

I've seen quite a few strings-only languages, but I can't think of any
other language than REXX where you create arrays and dictionaries by
using computed variable names.

It was quite the experience back in the day (as OS/2's native
scripting language), and one that I'm truly glad to have had, as it
taught me so much about the differences between languages.

(It also taught me to treasure good documentation and value it as
truly precious, because SysSetObjectData was an incredibly powerful
function whose docs just referred to WinSetObjectData, and the window
manager's docs weren't part of what I had available.)

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


Re: Weak Type Ability for Python

2023-04-13 Thread gene heskett

On 4/13/23 13:34, Dennis Lee Bieber wrote:

On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson 
declaimed the following:


On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:

I suspect the OP is thinking of languages like PERL or JAVA which guess
for
you and make such conversions when it seems to make sense.


JavaScript guesses. What a nightmare. Java acts like Python and will
forbid it on type grounds (at compile time with Java, being staticly
typed).



REXX -- where everything is considered a string until it needs to be
something else.

REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
   rexxtry.rex lets you interactively try REXX statements.
 Each string is executed when you hit Enter.
 Enter 'call tell' for a description of the features.
   Go on - try a few...Enter 'exit' to end.


You missed the best REXX, Dennis.

ARexx for the amiga's. Bill Hawes wrote in a link to everything amigados 
had and we wrote, in ARexx, stuff that Amigados didn't have starting 
with a cron, a better cron than Paul Vixies. Worst, Bill never got a 
dime from commode-door for the best language it had,  We served our WDTV 
web page with it in the middle 90's. Using ARexx and early php. Now its 
farmed out and 99% commercial junk.



x = 1;
   ... rexxtry.rex on WindowsNT
y = "a";
   ... rexxtry.rex on WindowsNT
say x||y;
1a
   ... rexxtry.rex on WindowsNT


Cheers, Gene Heskett.
--
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
 - Louis D. Brandeis
Genes Web page 

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


RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
Can I bring a part of this discussion a bit closer to Python?

I stipulate that quite a few languages, including fairly early ones, treated
text often as numbers. Ultimately, much of programming is about taking in
text and often segregating parts into various buckets either explicitly or
by checking if it has a decimal point or looks like scientific notation or
in how it seems to be used.

Is there any concept in Python of storing information in some way, such as
text, and implementing various ideas or interfaces so that you can query if
the contents are willing and able to be viewed in one of many other ways?

As an example, an object may store a fairly large number as a text string in
decimal format. The number is big enough that it cannot be fully represented
in an 8 bit storage as in a byte or in a signed or unsigned 16-bit integer
but can be stored in something larger. It may be possible to store it in a
double precision floating point but not smaller. Yes, I know Python by
default uses indefinite length integers, but you get the idea.

Or it may be storing text in some format but the object is willing to
transform the text into one of several other formats when needed. The text
may also have attributes such as whether it is in English or Hungarian or is
mixed-language.

So for some applications, perhaps leaving the object as a string all the
time may be reasonable. If some operation wishes to use the contents, the
interface can be queried to see what other formats it can be coerced into
and perhaps a specified set of methods need to be included that perform your
transition for you such as object.return_as_int64() 

This can have wider implications. Imagine an object holding text in French
that has been tested by humans using a program like Google Translate and
deemed reasonable for translating into a specific dozen languages such as
Esperanto  and not certified into others like Klingon or High Valyrian or
ASL. The object could contain interfaces for the languages it supports but
does not store the translations, especially when the content is dynamic,
such as a form letter that has been instantiated with a name and address and
perhaps a part detailing what is being billed or shipped. Instead, the
object can present an interface that lets a user determine if it supports
dynamic translation to one or more target, such as the Quebec version of
French or a British versus American version of English.

I am being quite general here and lots of programs out there already
probably have their own way of providing such facilities on a case-by-case
basis. But do some languages have some support within the language itself?

I do note some languages allow objects to oddly belong to multiple classes
at once and have used that feature as a way to check if an object has some
capabilities. Some languages have concepts like a mix-in and Python does
allow thing like multiple inheritance albeit it often is best not to use it
much. It does have ideas about how to test if a class implements some things
by seeing if various dunder methods are in place.

My reason for asking, is based on the discussion. If I want to use plus with
an integer and a string, it may be reasonable for the interpreter to ask one
or the other operand if they are able to be seen another way. If an integer
indicates it can be seen as text, great. If a string indicates it believes
it can deliver a number, great.

Unfortunately, if they BOTH are flexible, how do you decide whether to add
them as numbers or concatenate them as strings?

Sigh!


-Original Message-
From: Python-list  On
Behalf Of Chris Angelico
Sent: Thursday, April 13, 2023 3:35 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber 
wrote:
>
> On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson 
> declaimed the following:
>
> >On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:
> >>I suspect the OP is thinking of languages like PERL or JAVA which guess
> >>for
> >>you and make such conversions when it seems to make sense.
> >
> >JavaScript guesses. What a nightmare. Java acts like Python and will
> >forbid it on type grounds (at compile time with Java, being staticly
> >typed).
> >
>
> REXX -- where everything is considered a string until it needs to
be
> something else.
>
> REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022
>   rexxtry.rex lets you interactively try REXX statements.
> Each string is executed when you hit Enter.
> Enter 'call tell' for a description of the features.
>   Go on - try a few...Enter 'exit' to end.
> x = 1;
>   ... rexxtry.rex on WindowsNT
> y = "a";
>   ... rexxtry.rex on WindowsNT
> say x||y;
> 1a
>   ... rexxtry.rex on WindowsNT

REXX - where everything is a string, arithmetic can be done on
strings, and data structures are done in the variable 

Re: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
On 13/04/2023 20:35, Chris Angelico wrote:

> REXX - where everything is a string,

> It was quite the experience back in the day (as OS/2's native
> scripting language), 

I briefly met REXX on a mainframe, but I did play with OS/2 for
a year or two. Back when it looked like it might be a rival to M$

OS/2 running NeXTstep now that would have been a platform
for the 90s...  both so near yet so far.

-- 
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


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


Re: RE: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
On 14/04/2023 00:25, avi.e.gr...@gmail.com wrote:

> Is there any concept in Python of storing information in some way, such as
> text, and implementing various ideas or interfaces so that you can query if
> the contents are willing and able to be viewed in one of many other ways?

Are you talking about something like a C union type (or a Pascal
variant record)? I'm not aware of any such feature in Python but
have often thought it would be a nice to have for the rare cases
where its useful.

> Or it may be storing text in some format but the object is willing to
> transform the text into one of several other formats when needed. The text
> may also have attributes such as whether it is in English or Hungarian or is
> mixed-language.

Or are you meaning something like an extension to the
struct module that can interpret a bytestring in any way
defined by a format string?

> basis. But do some languages have some support within the language itself?

The closest to what you seem to mean is, I think, the C union
type, at least in my experience. But you have to define all
the ways you can interpret the type up front in the type
definition.

> My reason for asking, is based on the discussion. If I want to use plus with
> an integer and a string, it may be reasonable for the interpreter to ask one
> or the other operand if they are able to be seen another way.

You can achieve that in a slightly different way in Tcl which
allows you to redefine all the operators (commands in Tcl-speak)
in the language so redefining plus is easy. Doing it based on
type is more tricky but doable.

> Unfortunately, if they BOTH are flexible, how do you decide whether to add
> them as numbers or concatenate them as strings?

Yes, that's where it becomes a designer's arbitrary choice.

-- 
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


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


Re: Weak Type Ability for Python

2023-04-13 Thread Chris Angelico
On Fri, 14 Apr 2023 at 09:49, Alan Gauld  wrote:
>
> On 13/04/2023 20:35, Chris Angelico wrote:
>
> > REXX - where everything is a string,
>
> > It was quite the experience back in the day (as OS/2's native
> > scripting language),
>
> I briefly met REXX on a mainframe, but I did play with OS/2 for
> a year or two. Back when it looked like it might be a rival to M$
>
> OS/2 running NeXTstep now that would have been a platform
> for the 90s...  both so near yet so far.
>

OS/2 was the primary operating system in our house from about 1992ish
until maybe the early 2000s - possibly 2010 even, depending on how you
count things. After a while we needed to permit the occasional Windows
system due to software that didn't work, and then I started deploying
some Linux systems. Eventually the Linux boxes outnumbered the OS/2,
and finally the last OS/2 system was virtualized under Linux,
completing the transition.

But along the way, I spent many years learning the way that OS/2
works, and that's been so valuable to me ever since. The system was
built from the ground up with threads in mind, so every programmer, as
a matter of course, just learned about threads. It's that simple. Want
to make a GUI app? The rule is, you respond to a window message within
a very few milliseconds; if you can't do your processing in that much
time, you spin off a thread. Easy. VX-REXX actually did that for every
message automatically, running thread zero for the system GUI message
loop, and feeding messages to a REXX message loop; you could, of
course, still spawn your own REXX threads as needed.

The entire Presentation Manager and Workplace Shell (broadly
equivalent to a Linux "desktop manager", I think? Kinda?) were object
oriented; you would have a WPDataFile for every, well, data file, but
some of those might be subclasses of WPDataFile. And it was fairly
straight-forward to write your own subclass of WPDataFile, and there
was an API to say "if you would ever create a WPDataFile, instead
create one of my class instead". This brilliant technique allowed
anyone to enhance the desktop in any way, quite impressive especially
for its time. I've yearned for that ever since, in various systems,
although I'm aware that it would make quite a mess of Python if you
could say "class EnhancedInt(int): ..." and then "any time you would
create an int, create an EnhancedInt instead". A bit tricky to
implement.

Ahh, the memories. Clinging onto several old Realtek RTL8029 cards
long past the days when ten megabit networking was considered
adequate, because I knew that I could ALWAYS rely on them. Seriously,
those things just never gave me issues. Problems with networking? Slap
in an 8029 and see if it's the card or something else. Need to
download the driver before your network card works? Grab an 8029, boot
with that, fetch driver, try again. Good times.

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


Re: Weak Type Ability for Python

2023-04-13 Thread Peter J. Holzer
On 2023-04-13 08:25:51 -0700, Grant Edwards wrote:
> On 2023-04-13, Cameron Simpson  wrote:
> > On 12Apr2023 22:12, avi.e.gr...@gmail.com  wrote:
> >
> >>I suspect the OP is thinking of languages like PERL or JAVA which guess 
> >>for you and make such conversions when it seems to make sense.
> >
> > JavaScript guesses. What a nightmare.
> 
> So does PHP.

Not in this case. Like Perl (Not PERL) it has different operators for
concatenation and addition. So $a + $b is always addition, never
concatenation.

Well, at least numbers and strings. For arrays its a (somewhat bizarre)
union.

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: Weak Type Ability for Python

2023-04-13 Thread Richard Damon

On 4/13/23 7:25 PM, avi.e.gr...@gmail.com wrote:

s there any concept in Python of storing information in some way, such as
text, and implementing various ideas or interfaces so that you can query if
the contents are willing and able to be viewed in one of many other ways?


There is nothing that I know of built into Python that does this.

There is no reason you can't write your own class to implement this. 
Something that by "default" looks like a string, but in some contexts 
(operated on by certain types) sees if its string could be treated as a 
value of some other type, and if so, converts its value to that type and 
does the operation.


--
Richard Damon

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


Re: Weak Type Ability for Python

2023-04-13 Thread Greg Ewing via Python-list

On 14/04/23 4:55 am, avi.e.gr...@gmail.com wrote:

While we are at it, why stop with imaginary numbers when you can imagine
extensions thereof? Unfortunately, it has been proven there are and can only
be two additional such constructs.


You can go beyond that if you broaden your horizons enough.
There are Clifford algebras, Lie algebras, ...

Not sure what any of those should do to strings, though. :-)

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


RE: RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
Alan,

Your guess is not quite what I intended.

Something like a C union is just a piece of memory large enough to hold one of 
several kinds of content and some way to figure out which is currently in place.

I am looking at a data structure that is an object of some class and stores the 
data in any way that it feels like. But it may be a bit of a chameleon that 
shows one face or another as needed. I can write code now that simply adds 
various access methods to the class used and also provides a way to query if it 
supports some interfaces.

Consider a dumb example. I have an object that holds a temperature and stores 
it in say degrees Celsius. There are simple formulas that can convert it to 
Fahrenheit or Kelvin or Rankine. So you can create access methods like 
get_as_Rankine() but this will only be useful for some programs that know about 
the interface.

So what if you had a variable in the class such as supported_formats that 
presented something like a list of scales supported using an official set of 
names? It may even be possible to get a reference to the function to call to 
get that functionality, or perhaps you have one access function that accepts 
any argument on the list and delivers what is wanted.

The temperature would only need to be stored in one format but be available in 
many. Of course, you could choose to precalculate and store others, or cache 
them when one request has come in and so forth.

Another example  would be dates stored in some format in a class that can 
deliver the result in all kinds of formats. Yes, we have functions that do 
things like that. But can you see advantages to the class hiding lots of 
details internally?

These are just examples but the point is motivated by some interfaces I have 
seen.

How do you know if something can be used by a context manner such as in a 
"with" statement? There may be other ways, but it seems two dunder methods, if 
present, likely mean it is. They are __enter__() and __exit__().

There are other interfaces like for iterators, that sometimes are more complex 
as when some things are not present, it uses others. Can you have a general 
function like is_iterator() or is_context_manager() that pretty much guarantees 
it is safe for the rest of the code to use the object in the way it wants?

My comments about overloading plus were a sort of extra idea. I think we have 
discussed the general algorithm for how Python tries to resolve something like 
"obj1 op obj2" and not just for the plus operator. There are quite a few dunder 
methods that cover many such operators.

What I was thinking about was a bit of a twist on that algorithm. I did 
something very vaguely like this years ago when I was working on how to 
translate documents from one format to another, such as WANG, Multimate, 
Wordperfect, plain text, etc. The goal was for a sender of an email to add an 
attachment and send it to many people at once. Each recipient would have a 
known preference for the type of document format they preferred. I wrote an 
algorithm in C++ which I got early access to as I was working at Bell Labs that 
effectively used a registered series of translator software along with info on 
how well or fast they worked, to do as few translations as possible and send 
each recipient the format they wanted.

Yes, there were major incompatibilities and you sometimes ended up with some 
features being dropped or changed. But that is not the point. If format A had 
do direct translator to format Z, I would find the intersection of formats we 
had software for to translate to from A, and anther set of languages that could 
be used to translate from to Z. Sometimes it needed multiple hops. It worked 
fine but never saw the light of day as, weirdly, the project had been canceled 
months earlier and they were stalling while planning the next project and thus 
let me do what I wanted even though I was integrating my C++ code into a 
project that was otherwise al in C. 

Now back to Python in this regard. If I type alpha + beta then maybe after 
trying the methods we have described, if still failing, the algorithm could see 
if alpha and beta registered what types they could output and see if a match 
could be made. If a number object offered a string version, that would be a 
match. If the string offered a numeric version, again problem solved. And even 
if the match was not precise, sometimes the interpreter might know enough to do 
a bit more and say convert an integer into a double if the sizes of the 
contents allowed.

The problem with this, and there are many, is that there is a certain 
nondeterministic aspect that may cause surprises and plenty of cost. 

It was just a academic thought that probably is not needed in the context 
albeit may  be implemented in some projects to bridge things as described or in 
other novel ways. 

-Original Message-
From: Alan Gauld  
Sent: Thursday, April 13, 2023 8:14 PM
To: avi.e.gr...@gmail.com; python-lis

Re: RE: Weak Type Ability for Python

2023-04-13 Thread 2QdxY4RzWzUUiLuE
On 2023-04-13 at 22:14:25 -0400,
avi.e.gr...@gmail.com wrote:

> I am looking at a data structure that is an object of some class and
> stores the data in any way that it feels like. But it may be a bit of
> a chameleon that shows one face or another as needed. I can write code
> now that simply adds various access methods to the class used and also
> provides a way to query if it supports some interfaces.

Python dicts act mostly like hash tables.  All by themselves, hash
tables are unordered (and in return for giving up that order, you get
O(1) access to an item if you know its key).

But when you ask a Python dict for the keys, you always get them in the
same order, skipping those that have been deleted since the last time
you asked, and appending the new keys to the end of the list in the
order in which you added them.

There's your chameleon.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-13 Thread Thomas Passin

On 4/13/2023 10:14 PM, avi.e.gr...@gmail.com wrote:

Alan,

Your guess is not quite what I intended.

Something like a C union is just a piece of memory large enough to hold one of 
several kinds of content and some way to figure out which is currently in place.

I am looking at a data structure that is an object of some class and stores the 
data in any way that it feels like. But it may be a bit of a chameleon that 
shows one face or another as needed. I can write code now that simply adds 
various access methods to the class used and also provides a way to query if it 
supports some interfaces.

Consider a dumb example. I have an object that holds a temperature and stores 
it in say degrees Celsius. There are simple formulas that can convert it to 
Fahrenheit or Kelvin or Rankine. So you can create access methods like 
get_as_Rankine() but this will only be useful for some programs that know about 
the interface.

So what if you had a variable in the class such as supported_formats that 
presented something like a list of scales supported using an official set of 
names? It may even be possible to get a reference to the function to call to 
get that functionality, or perhaps you have one access function that accepts 
any argument on the list and delivers what is wanted.


Now you are starting to sound like COM.  You ask an object for its 
IUnknown interface, and from that interface you can query what other 
interfaces it has available.  You go on from there.

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


RE: RE: Weak Type Ability for Python

2023-04-13 Thread avi.e.gross
Yes, Dave, there are many data structures that can be used to maintain a
list of output types the class claims to support. Dictionaries have the
interesting property that you can presumably have a value that holds a
member function to access the way the key specifies.

Ideally, the order is not important for what I am looking for. Generally, I
would think that any class like the ones I have been discussing, would want
to broadcast a fairly short list of output types it would support.

Of course, if you look at my date example, the list could be quite big but
if you simply use something like strftime() for many of the formats, perhaps
you may not need to list all possible ones. Any valid format could be
accepted as an argument and passed to such a utility function. Your
dictionary might simply store some commonly used formats known to work.

But I repeat. This is not a serious request. I know how to build limited
functionality like this if I ever want it, but wonder if anyone has ever
created a proposal for some protocols and perhaps helpers like say an
embedded object that handles aspects of it once you have initialized your
dictionary and also handles requests to show part of what is stored for any
shoppers wondering if you are compatible with their needs.

-Original Message-
From: Python-list  On
Behalf Of 2qdxy4rzwzuui...@potatochowder.com
Sent: Thursday, April 13, 2023 10:27 PM
To: python-list@python.org
Subject: Re: RE: Weak Type Ability for Python

On 2023-04-13 at 22:14:25 -0400,
avi.e.gr...@gmail.com wrote:

> I am looking at a data structure that is an object of some class and
> stores the data in any way that it feels like. But it may be a bit of
> a chameleon that shows one face or another as needed. I can write code
> now that simply adds various access methods to the class used and also
> provides a way to query if it supports some interfaces.

Python dicts act mostly like hash tables.  All by themselves, hash
tables are unordered (and in return for giving up that order, you get
O(1) access to an item if you know its key).

But when you ask a Python dict for the keys, you always get them in the
same order, skipping those that have been deleted since the last time
you asked, and appending the new keys to the end of the list in the
order in which you added them.

There's your chameleon.
-- 
https://mail.python.org/mailman/listinfo/python-list

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