learning python ...

hw hw at adminart.net
Wed May 26 03:15:56 EDT 2021


On 5/25/21 9:42 AM, Greg Ewing wrote:
> On 25/05/21 2:59 pm, hw wrote:
>> Then what is 'float' in the case of isinstance() as the second 
>> parameter, and why can't python figure out what 'float' refers to in 
>> this case? 
> 
> You seem to be asking for names to be interpreted differently
> when they are used as parameters to certain functions.

Sure, why not.  Since python allows me to use the name of a variable 
type as a name for a variable, it could at least figure out which, the 
type or the variable, to use as parameter for a function that should 
specify a variable type when the name is given.  Obviously, python knows 
what's expected, so why not chose that.

> Python doesn't do that sort of thing. The way it evaluates
> expressions is very simple and consistent, and that's a good
> thing. It means there aren't any special cases to learn and
> remember.

Ok, that's certainly a valid point.  It could be a general case that 
python picks for functions what is expected of their parameters when 
their parameters have ambigous names.

> Maybe you're not aware that isinstance is just a function,
> and not any kind of special syntax?
> 
>> Perhaps type names should be keywords to avoid confusion.
> 
> Python has quite a lot of built-in types, some of them in
> the builtin namespace, some elsewhere. Making them all keywords
> would be impractical, even if it were desirable.
> 
> And what about user-defined types? Why should they be treated
> differently to built-in types? Or are you suggesting there
> should be a special syntax for declaring type names?

I don't know; how many different types does it have?  Maybe a special 
syntax for declaring type names which then can not become ambigous so 
easily would be a good thing?

I already wondered that the scope of variables is not limited to the 
context they are declared within:


for number in something:
     # do stuff

# do more stuff or not ...
print(number)


When you do something like that in perl, the variable you declared is 
out of scope outside the loop whereas python surprises me by keeping it 
around.  Somehow, the more I learn about python, the harder it becomes 
for me to read.

Maybe that changes over time, yet keeping variables around like that is 
not something I would prefer.


More information about the Python-list mailing list