Re: Weak Type Ability for Python

2023-04-15 Thread Peter J. Holzer
On 2023-04-13 03:28:37 +0100, MRAB wrote:
> On 2023-04-13 03: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.
> > 
> In the case of Perl, there are distinct operators for addition and string
> concatenation, with automatic type conversion (non-numeric strings have a
> numeric value of 0, which can hide bugs).

You get a warning for that, though.

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-15 Thread Peter J. Holzer
On 2023-04-14 10:19:03 +1000, Chris Angelico wrote:
> 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.

Or alternatively you might be able to add or replace methods on the
existing int class. So 5 is still just an int, but now (5 + "x") calls
the modified __add__ method which knows how add a string to an int.

Might make even more of a mess ;-).

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-14 Thread avi.e.gross
an be created that is published and suggests the names and so on to 
use in constructing your own implementation. And, it may be helpful if a module 
is made available that makes it even simpler to use.

I think it is time for me to drop out of this discussion unless I hear 
something of interest. It is just an idea I have been pondering. 

-Original Message-
From: Python-list  On 
Behalf Of Dennis Lee Bieber
Sent: Friday, April 14, 2023 12:23 AM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon
 declaimed the following:

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

I sure don't want to see the documentation for that...

a = thisType(3)
b = thisType(7)
c = 9   #plain integer

print(a + b + c)

(Since I presume left to right evaluation of equal level operations) Does
this result in

46 ("3" + "7" => "37", int("37") + 9 => 46)

or

19 (as int("3") + int("7") => 10, + 9 => 19)

Worse... changing order of a/b/c would make completely different
results...

82 (b + a + c)
127 (int(a) + c returning thisType(12) + b as strings)

and does (c + a) result in returning an integer (a conforming to c); or a
string (a coercing c to thisType).

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

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


Re: Weak Type Ability for Python

2023-04-14 Thread Dennis Lee Bieber


{one more entry in the thread drift, and then I think I'll shut up}

On Fri, 14 Apr 2023 17:22:47 +1000, Chris Angelico 
declaimed the following:


>Yeah, the "ADDRESS" command has so much potential. Back in the day, I
>built a MUD with REXX scripting, and within those scripts, the default
>ADDRESS target was "send message to the invoker of the command", so
>you could do something like this:

I used to think (Open)VMS would have been a potential platform for an
effective ADDRESS command. Where ARexx used a shared memory linked-list for
the "port" (as I'd stated, avoiding copying of data), (Open)VMS had
"mailboxes" (they would have to copy data -- or at best remap the virtual
memory from one process to another) which could serve the same purpose;
receiving application creates/owns the named mailbox, sending applications
would provide the data packet including a return mailbox link.

>
>/* A bare string gets sent to the client */
>"Hello!"
>/* You can still invoke shell commands, if you actually need to */
>address cmd "do_a_thing"
>
Yeah, that was the other feature -- anything that could not be parsed
as a REXX statement was automatically sent to whatever the current ADDRESS
host happened to be.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-14 Thread Chris Angelico
On Fri, 14 Apr 2023 at 17:17, Dennis Lee Bieber  wrote:
>
> On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico 
> declaimed the following:
>
> >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.
> >
>
> I still miss the Amiga ARexx implementation which piggy-backed on the
> Amiga IPC scheme* such that any application that opened a "RexxPort" could
> be the target for "ADDRESS ", and hence scripted using ARexx (Did
> IBM ever get beyond the two choices of command-line and a line-editor?).
>
>
> *   Granted, that IPC relied upon the fact that all applications shared 
> one
> memory space, so there wasn't the overhead of copying data structures from
> sending application to the port's linked list and thence to the receiving
> application.

Yeah, the "ADDRESS" command has so much potential. Back in the day, I
built a MUD with REXX scripting, and within those scripts, the default
ADDRESS target was "send message to the invoker of the command", so
you could do something like this:

/* A bare string gets sent to the client */
"Hello!"
/* You can still invoke shell commands, if you actually need to */
address cmd "do_a_thing"

Rabid proponents of OOP say that it's all about sending messages to
things. Well, the ADDRESS command truly lets you send messages, so
that means REXX is the most object oriented language there is, right?

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


Re: Weak Type Ability for Python

2023-04-14 Thread Dennis Lee Bieber
On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico 
declaimed the following:

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

I still miss the Amiga ARexx implementation which piggy-backed on the
Amiga IPC scheme* such that any application that opened a "RexxPort" could
be the target for "ADDRESS ", and hence scripted using ARexx (Did
IBM ever get beyond the two choices of command-line and a line-editor?).


*   Granted, that IPC relied upon the fact that all applications shared one
memory space, so there wasn't the overhead of copying data structures from
sending application to the port's linked list and thence to the receiving
application.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Weak Type Ability for Python

2023-04-14 Thread Dennis Lee Bieber
On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon
 declaimed the following:

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

I sure don't want to see the documentation for that...

a = thisType(3)
b = thisType(7)
c = 9   #plain integer

print(a + b + c)

(Since I presume left to right evaluation of equal level operations) Does
this result in

46 ("3" + "7" => "37", int("37") + 9 => 46)

or

19 (as int("3") + int("7") => 10, + 9 => 19)

Worse... changing order of a/b/c would make completely different
results...

82 (b + a + c)
127 (int(a) + c returning thisType(12) + b as strings)

and does (c + a) result in returning an integer (a conforming to c); or a
string (a coercing c to thisType).

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


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

2023-04-13 Thread avi.e.gross
..@gmail.com; python-list@python.org
Subject: Re: RE: Weak Type Ability for Python

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

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


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


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


RE: Weak Type Ability for Python

2023-04-12 Thread avi.e.gross
 why have the program choose when it quite likely reflects an error in
the code. And, no, I do not suggest 2.5 be interpreted as putting in an
approximate percentage so that .8 * "Hello" should result in "Hell" ...




-Original Message-
From: Python-list  On
Behalf Of Cameron Simpson
Sent: Wednesday, April 12, 2023 11:43 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On 13Apr2023 03:36, MRAB  wrote:
>I thought that in Java you can, in fact, concatenate a string and an 
>int, so I did a quick search online and it appears that you can.

I stand corrected. I could have sworn it didn't, but it has been a long 
time. - Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: Weak Type Ability for Python

2023-04-12 Thread Cameron Simpson

On 13Apr2023 03:36, MRAB  wrote:
I thought that in Java you can, in fact, concatenate a string and an 
int, so I did a quick search online and it appears that you can.


I stand corrected. I could have sworn it didn't, but it has been a long 
time. - Cameron Simpson 

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


RE: Weak Type Ability for Python

2023-04-12 Thread avi.e.gross
On closer reading, the OP may be asking how to make a function doing what
they want, albeit without a plus.

Here is a python function as a one-liner that takes exactly two arguments of
any kind (including string and integer) and concatenates them into one
string without anything between and prints them:

def strprint(first, second): print(str(first) + str(second))

>>> strprint(5,1)
51
>>> strprint("a5",1)
a51
>>> strprint(12,"o'clock")
12o'clock
>>> strprint(3.1415926535,complex(3,4))
3.1415926535(3+4j)

Want something similar for any number of arguments? Here is a slightly
longer one-liner:

def strprintall(*many): print(''.join([str(each) for each in many]))

>>>
strprintall(1,"=egy\n",2,"=kettő\n",3,"=három\n",4,"=négy\n",5,"=öt\n","in
my childhood language.\n")
1=egy
2=kettő
3=három
4=négy
5=öt
in my childhood language.

Note my meager attempt is not using a plus sign as I addressed a sort of way
that could be done using a __radd__ method or other ways like an f-string.

I can not repeat this often enough. The easiest way to do something you want
in a new language is to work within the existing language as-is and not to
ask the language to change to be the way you want. That can take years or
never happen, and especially if the designers did not want the feature you
ask for. 





-Original Message-
From: Python-list  On
Behalf Of 2qdxy4rzwzuui...@potatochowder.com
Sent: Wednesday, April 12, 2023 3:17 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On 2023-04-12 at 14:51:44 -0400,
Thomas Passin  wrote:

> On 4/12/2023 1:11 PM, Chris Angelico wrote:
> > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
> >  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.
> > > 
> > 
> > Try:
> > 
> > print(x, y)
> > 
> > ChrisA
> 
> It puts a space between "1" and "a", whereas the question does not want
the
> space.  print(f'{x}{y}') would do it, but only works for variables named
"x"
> and "y".

Or possibly print(x, y, sep='').

> As happens so often, the OP has not specified what he actually wants to do
> so we can only answer the very specific question.

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

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


Re: Weak Type Ability for Python

2023-04-12 Thread MRAB

On 2023-04-13 03:21, 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. Java acts like Python and will
forbid it on type grounds (at compile time with Java, being staticly
typed).

I thought that in Java you can, in fact, concatenate a string and an 
int, so I did a quick search online and it appears that you can.

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


Re: Weak Type Ability for Python

2023-04-12 Thread MRAB

On 2023-04-13 03:12, avi.e.gr...@gmail.com wrote:

As originally written, the question posed has way too many possible answers
but the subject line may give a hint. Forget printing.

The Python statement
1 + "a"

SHOULD fail. The first is an integer and the second is  string. These two
are native Python objects that neither define what to do if they are paired
with an object of the other type on the left or the right.

In any case, what should the answer be? Since "a" has no integer value, it
presumably was intended to be the string "1a".

So why NOT use the built-in conversion and instead of:

print(x+y) # where x=1, y='a'

It should be:

print(str(x) + y)

Could this behavior be added to Python? Sure. I wonder how many would not
like it as it often will be an error not caught!

If you defined your own object derived from string and added a __radd__()
method then the method could be made to accept whatever types you wanted
(such as integer or double or probably anything) and simply have code that
converts it to the str() representation and then concatenates them with, or
if you prefer without, any padding between.

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.

In the case of Perl, there are distinct operators for addition and 
string concatenation, with automatic type conversion (non-numeric 
strings have a numeric value of 0, which can hide bugs).



Python does not generally choose that as it is quite easy to use one of so
many methods, and lately an f-string is an easy way as others mentioned.


-Original Message-
From: Python-list  On
Behalf Of Thomas Passin
Sent: Wednesday, April 12, 2023 2:52 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On 4/12/2023 1:11 PM, Chris Angelico wrote:

On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 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.



Try:

print(x, y)

ChrisA


It puts a space between "1" and "a", whereas the question does not want
the space.  print(f'{x}{y}') would do it, but only works for variables
named "x" and "y".

As happens so often, the OP has not specified what he actually wants to
do so we can only answer the very specific question.



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


Re: Weak Type Ability for Python

2023-04-12 Thread Cameron Simpson

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


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


RE: Weak Type Ability for Python

2023-04-12 Thread avi.e.gross
As originally written, the question posed has way too many possible answers
but the subject line may give a hint. Forget printing.

The Python statement
1 + "a"

SHOULD fail. The first is an integer and the second is  string. These two
are native Python objects that neither define what to do if they are paired
with an object of the other type on the left or the right.

In any case, what should the answer be? Since "a" has no integer value, it
presumably was intended to be the string "1a".

So why NOT use the built-in conversion and instead of:

print(x+y) # where x=1, y='a'

It should be:

print(str(x) + y)

Could this behavior be added to Python? Sure. I wonder how many would not
like it as it often will be an error not caught!

If you defined your own object derived from string and added a __radd__()
method then the method could be made to accept whatever types you wanted
(such as integer or double or probably anything) and simply have code that
converts it to the str() representation and then concatenates them with, or
if you prefer without, any padding between.

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.

Python does not generally choose that as it is quite easy to use one of so
many methods, and lately an f-string is an easy way as others mentioned.


-Original Message-
From: Python-list  On
Behalf Of Thomas Passin
Sent: Wednesday, April 12, 2023 2:52 PM
To: python-list@python.org
Subject: Re: Weak Type Ability for Python

On 4/12/2023 1:11 PM, Chris Angelico wrote:
> On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
>  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.
>>
> 
> Try:
> 
> print(x, y)
> 
> ChrisA

It puts a space between "1" and "a", whereas the question does not want 
the space.  print(f'{x}{y}') would do it, but only works for variables 
named "x" and "y".

As happens so often, the OP has not specified what he actually wants to 
do so we can only answer the very specific question.

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

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


Re: Weak Type Ability for Python

2023-04-12 Thread 2QdxY4RzWzUUiLuE
On 2023-04-12 at 14:51:44 -0400,
Thomas Passin  wrote:

> On 4/12/2023 1:11 PM, Chris Angelico wrote:
> > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
> >  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.
> > > 
> > 
> > Try:
> > 
> > print(x, y)
> > 
> > ChrisA
> 
> It puts a space between "1" and "a", whereas the question does not want the
> space.  print(f'{x}{y}') would do it, but only works for variables named "x"
> and "y".

Or possibly print(x, y, sep='').

> As happens so often, the OP has not specified what he actually wants to do
> so we can only answer the very specific question.

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


Re: Weak Type Ability for Python

2023-04-12 Thread Grant Edwards
On 2023-04-12, Ali Mohseni Roodbari  wrote:
> Hi all,
> Please make this command for Python (if possible):
>
 x=1
 y='a'
 wprint (x+y)
 1a

If that's what you want, use PHP or some other language. Don't try to ruin 
Python.

> In fact make a new type of print command which can print and show strings
> and integers together.


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


Re: Weak Type Ability for Python

2023-04-12 Thread MRAB

On 2023-04-12 19:57, Mats Wichmann wrote:

On 4/12/23 11:11, Chris Angelico wrote:

On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 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.



Try:

print(x, y)

ChrisA



To continue on, what do you want "addition" of dissimilar types to do -
since that's what you have asked for above.

You can write yourself an object which is happy with certain
combinations, so you don't have this scenario:

  >>> x + y
Traceback (most recent call last):
File "", line 1, in 
  x + y
   ~~^~~
TypeError: can only concatenate str (not "int") to str
  >>> y + x
Traceback (most recent call last):
File "", line 1, in 
  y + x
   ~~^~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'
  >>>


Or you can help out the print function by doing some of the fiddling
yourself:

  >>> print(f"{x}{y}")
1a


Or:


print(x, y, sep='')

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


Re: Weak Type Ability for Python

2023-04-12 Thread Thomas Passin

On 4/12/2023 1:11 PM, Chris Angelico wrote:

On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 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.



Try:

print(x, y)

ChrisA


It puts a space between "1" and "a", whereas the question does not want 
the space.  print(f'{x}{y}') would do it, but only works for variables 
named "x" and "y".


As happens so often, the OP has not specified what he actually wants to 
do so we can only answer the very specific question.


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


Re: Weak Type Ability for Python

2023-04-12 Thread Mats Wichmann

On 4/12/23 11:11, Chris Angelico wrote:

On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 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.



Try:

print(x, y)

ChrisA



To continue on, what do you want "addition" of dissimilar types to do - 
since that's what you have asked for above.


You can write yourself an object which is happy with certain 
combinations, so you don't have this scenario:


>>> x + y
Traceback (most recent call last):
  File "", line 1, in 
x + y
 ~~^~~
TypeError: can only concatenate str (not "int") to str
>>> y + x
Traceback (most recent call last):
  File "", line 1, in 
y + x
 ~~^~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>


Or you can help out the print function by doing some of the fiddling 
yourself:


>>> print(f"{x}{y}")
1a




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


Re: Weak Type Ability for Python

2023-04-12 Thread Chris Angelico
On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari
 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.
>

Try:

print(x, y)

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


Weak Type Ability for Python

2023-04-12 Thread Ali Mohseni Roodbari
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