Re: bool and int

2023-01-24 Thread Mike Baskin via Python-list
Will all of you please stop sending me emails

Sent from my iPhone

> On Jan 24, 2023, at 2:59 PM, rbowman  wrote:
> 
> On Mon, 23 Jan 2023 23:22:00 -0500, Dino wrote:
> 
>> $ python Python 3.8.10 (default, Mar 15 2022, 12:22:08)
>> [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license"
>> for more information.
> b = True isinstance(b,bool)
>> True
> isinstance(b,int)
>> True
> 
> 
>> WTF!
> 
> 
 b = True
 isinstance(b, bool)
> True
 isinstance(b, int)
> True
 c = b + 10
 print(c)
> 11
 b = False
 c = b + 10
 print(c)
> 10
> 
> 
> bool is a subtype of integer. I never dug that deep into Python's guts but 
> I assume it goes back to boolean being an afterthought in C. Some people 
> fancy it up with #defines but I always use int.  0 is false, anything else 
> is true.
> 
> C# is pickier, which I guess is a good thing. 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


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

2023-01-24 Thread Mike Baskin via Python-list
Can you stop please


Sent from Yahoo Mail for iPhone


On Tuesday, January 24, 2023, 10:12 AM, Thomas Passin  
wrote:

On 1/23/2023 9:12 PM, Chris Angelico wrote:
> On Tue, 24 Jan 2023 at 13:09, Jach Feng  wrote:
>>
>> Chris Angelico 在 2023年1月24日 星期二清晨5:00:27 [UTC+8] 的信中寫道:
>>> On Tue, 24 Jan 2023 at 07:47, Cameron Simpson  wrote:

 But for Jach Feng: the "--" is really expected as something the user
 does when they invoke your programme, _explicitly_ saying that what
 follows from here is not an argument. So the user is expected to type:

 your_script -x -y -- "-4^2+5.3*abs(-2-1)/2"

 where there are -x and -y options, then end of options, then an
 argument, which would look like an option if there wasn't the "--"
 argument.
>>> And if you DON'T expect the user to enter the "--", then why use
>>> argparse? You can just check argv directly to get your arguments.
>>>
>>> This entire thread is a massive "how can I use X to do Y?" problem.
>>>
>>> ChrisA
>> The '--' requirement makes its usage less instinctive, and handling argv 
>> directly makes me loss the benefit of using '-h':-)
> 
> if "-h" in sys.argv: usage()
> else: do_stuff_with(sys.argv[1:])
> 
> What is argparse really doing for you?

I second this.  "if '-h' in sys.argv:"  is usually what I do.

Alternatively, you could use "--arg=" syntax and place your string 
"-4^2+5.3*abs(-2-1)/2" its right-hand side":

infix2postfix [options] "--infix=-4^2+5.3*abs(-2-1)/2"

This shouldn't be too hard for a user to work with.  You could scan the 
argument list for the presence of "--infix=" and display the help 
message if it isn't there.

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



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


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

2023-01-24 Thread Mike Baskin via Python-list
Stop please


Sent from Yahoo Mail for iPhone


On Tuesday, January 24, 2023, 1:05 AM, Cameron Simpson  wrote:

On 23Jan2023 17:58, Jach Feng  wrote:
 parser.parse_args(['--', 'infix2postfix.py', '-4.3+5'])
>usage: [-h] infix
>: error: unrecognized arguments: -4.3+5

This error doesn't look like "-4.3+5 looks like an option" but instead 
"we don't expect any arguments after "infix".

Not personally a fan of argparse myself, but then I have my own 
elaborate command line framework which generally uses getopt for the 
option stuff.

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



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