mimedecode 3.1.0

2021-05-23 Thread Oleg Broytman
  mimedecode

WHAT IS IT

   Mail users, especially in non-English countries, often find that mail
messages arrived in different formats, with different content types, in
different encodings and charsets. Usually this is good because it allows
us to use appropriate format/encoding/whatever. Sometimes, though, some
unification is desirable. For example, one may want to put mail messages
into an archive, make HTML indices, run search indexer, etc. In such
situations converting messages to text in one character set and skipping
some binary attachments is much desirable.

   Here is the solution - mimedecode.

   This is a program to decode MIME messages. The program expects one
input file (either on command line or on stdin) which is treated as an
RFC822 message, and decodes to stdout or an output file. If the file is
not an RFC822 message it is just copied to the output one-to-one. If the
file is a simple RFC822 message it is decoded as one part. If it is a
MIME message with multiple parts ("attachments") all parts are decoded.
Decoding can be controlled by command-line options.

   Think about said mail archive; for example, its maintainer wants to
put there only texts, convert PDF/Postscript to text, pass HTML and
images decoding base64 to html but leaving images encoded, and ignore
everything else. This is how it could be done:

   mimedecode -t application/pdf -t application/postscript -t text/plain -b 
text/html -B 'image/*' -i '*/*'


Version 3.1.0 (2021-05-23)

   Convert mimedecode.docbook to reST. Generate html/man/text
   using Sphinx.

   Replaced outdated and insecure `mktemp` with `NamedTemporaryFile`.

   Python 3.8, 3.9.


WHERE TO GET
   Home page: https://phdru.name/Software/Python/#mimedecode
git clone https://github.com/phdru/mimedecode.git
git clone https://git.phdru.name/mimedecode.git
git clone  git://git.phdru.name/mimedecode.git

   Requires: Python 2.7 or Python 3.4+, m_lib.defenc 1.0+.
   Tests require: tox, m_lib 3.1+.

   Recommends: configured mailcap database.

   Documentation: https://phdru.name/Software/Python/mimedecode.html
  (also included in the package in html, man and txt formats).


AUTHOR
   Oleg Broytman 

COPYRIGHT
   Copyright (C) 2001-2021 PhiloSoft Design.

LICENSE
   GPL

Oleg.
-- 
Oleg Broytmanhttps://phdru.name/[email protected]
   Programmers don't die, they just GOSUB without RETURN.
-- 
https://mail.python.org/mailman/listinfo/python-list


Question for potential python development contributions on Windows

2021-05-23 Thread pjfarley3
I asked this question on python-dev last week but did not get an answer.  If
anyone here know the answer I would appreciate it.

The Python Developers Guide specifically states to get VS2017 for developing
or enhancing python on a Windows system.

Is it still correct to specifically use VS2017 , or is VS2019 also
acceptable?

I ask this because I know that the *.vcxproj files and other
build-environment files have changed format pretty dramatically over the
many releases of VS.  If a potential new contribution targeted for current
and future python will require new build environment files, I wouldn’t want
to have to “down release” those files (or expect core dev’s to do it) at or
after submission to the community for approval.  Much better to use the same
setup as core dev’s use than to introduce up-level differences in the build
environment.

IOW, for new releases on Windows are core dev’s still using VS2017 and so
potential contributors should also use that version, or has the core dev’s
process for Windows releases been updated to use VS2019?

Peter
--


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


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread max pothier
Hi,
Seems like that could be a method of doing things. Just one clarification: the 
website has unselectable text, looks like it's an image strangely generated, so 
if I can get the packet with it, it would be perfect. As I said (I think), 
logging in with Selenium was already possible, and I could get a screenshot of 
the page after logging in.
If you got this working like a packet listener in browser capable of seeing 
packet data, I'd gladly accept the code.
I've tried to do this for 3 years now (since I came into that school 
basically), looks like it's coming to an end!
Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread Curt
On 2021-05-21, max pothier  wrote:
> Hello, Thanks for you answer!  Actually my goal is not to
> automatically get the file once I open the page, but more to
> periodically check the site and get a notification when there's new
> homework or, at the morning, know when an hour is cancelled, so I
> don't want to have to open the browser every time.  I have pretty good
> javascript knowledge so if you could better explain that idea, it
> would be a great help.

It seems there's a smartphone app that does what you want, so this wheel
may already have been invented (in a manner of speaking).

Maybe you are already aware of this and are looking for a way to improve
your hacking skills, or perhaps you don't have a
smartphone--unlikely!--or want your notifications on your computer
rather than your phone, etc.

https://www.parisclassenumerique.fr/lutece/jsp/site/Portal.jsp?page_id=9

 Notifications

 Afin de rester informé en temps réel de tous les événements qui vous
 concernent (actualités, messages, blogs, espace documentaire…), il est
 nécessaire d’activer sur votre mobile les notifications pour
 l’application (par défaut, à votre arrivée sur l’application, toutes
 les notifications sont activées).

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


learning python ...

2021-05-23 Thread hw



Hi,

I'm starting to learn python and have made a little example program 
following a tutorial[1] I'm attaching.


Running it, I'm getting:


Traceback (most recent call last):
  File "[...]/hworld.py", line 18, in 
print(isinstance(int, float))
TypeError: isinstance() arg 2 must be a type or tuple of types


I would understand to get an error message in line 5 but not in 18.  Is 
this a bug or a feature?



[1]: https://www.learnpython.org/en/Variables_and_Types
--
https://mail.python.org/mailman/listinfo/python-list


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread max pothier
@Curt: That is notifications for the ENT app, I want the notifications for the 
app named ProNote. ENT is for e-mails and Pronote for homework, quotes, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread Curt
On 2021-05-23, max pothier  wrote:
> @Curt: That is notifications for the ENT app, I want the notifications
> for the app named ProNote. ENT is for e-mails and Pronote for
> homework, quotes, etc.

https://doc.index-education.com/fr-fr/pn/2018/N/Notification.htm

 Notifications dans PRONOTE 
 Paramétrer les notifications
 Vous êtes notifié lorsque vous recevez un message, une information, un
 sondage ou un document.

 1.   Rendez-vous dans le menu Mes préférences > communication >
 Messagerie.

 2.   Cochez le ou les modes de notification souhaités.

...

 Notification via l'application (parents / élèves / professeurs)
 Dès la rentrée, un système de notifications sur mobile permettra aux
 parents, élèves et professeurs d'avoir une notification sur leur
 téléphone à l'arrivée d'un nouveau message ou d'une nouvelle
 information.



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


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread max pothier
Already tried this, only works for messages and not for homework etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread Curt
On 2021-05-23, max pothier  wrote:
> Already tried this, only works for messages and not for homework etc.

https://play.google.com/store/apps/details?id=com.androz2091.pronote_notifications&gl=FR

 Notifications pour Pronote vous permet de recevoir des notifications
 push lorsqu'une nouvelle note ou un nouveau *devoir* est ajouté sur
 Pronote ! Soyez informés en direct et évitez de vous connecter 50 fois
 par semaine pour voir si le prof d'histoire géo a enfin mis les notes du
 contrôle 😄

Et voilà l'appli qui fait tout ! 
-- 
https://mail.python.org/mailman/listinfo/python-list


Issue in software

2021-05-23 Thread pradeep Y
I I couldn't get the solution for this issue since last week will you
please help me to solve this issue the issue is when I opened command
prompt this below message will Pop up


"The program can't start because api-ms-win-crt-runtime-[1-1-0.dl] is
missing from your computer.try reinstalling the program to fix this
problem."



I tried to solve several times and many times but I didn't get any expected
outcome. Can you please help me please.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in software

2021-05-23 Thread Igor Korot
Hi,

On Sun, May 23, 2021 at 11:50 AM pradeep Y  wrote:
>
> I I couldn't get the solution for this issue since last week will you
> please help me to solve this issue the issue is when I opened command
> prompt this below message will Pop up
>
>
> "The program can't start because api-ms-win-crt-runtime-[1-1-0.dl] is
> missing from your computer.try reinstalling the program to fix this
> problem."

You should download the above mentioned DLL from MS website and install it.

Thank you.

>
>
>
> I tried to solve several times and many times but I didn't get any expected
> outcome. Can you please help me please.
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: learning python ...

2021-05-23 Thread Peter Otten

On 23/05/2021 06:37, hw wrote:


Hi,

I'm starting to learn python and have made a little example program 
following a tutorial[1] I'm attaching.


Running it, I'm getting:


Traceback (most recent call last):
   File "[...]/hworld.py", line 18, in 
     print(isinstance(int, float))
TypeError: isinstance() arg 2 must be a type or tuple of types


I would understand to get an error message in line 5 but not in 18.  Is 
this a bug or a feature?


It is a bug in your code (which you don't provide). Did you assign some 
value to float, e. g.:


>>> float = 42.0
>>> isinstance(int, float)
Traceback (most recent call last):
  File "", line 1, in 
isinstance(int, float)
TypeError: isinstance() arg 2 must be a type or tuple of types

If you do not shadow the built-in you should get

>>> isinstance(int, float)
False

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


Re: learning python ...

2021-05-23 Thread hw

On 5/23/21 7:28 PM, Peter Otten wrote:

On 23/05/2021 06:37, hw wrote:


Hi,

I'm starting to learn python and have made a little example program 
following a tutorial[1] I'm attaching.


Running it, I'm getting:


Traceback (most recent call last):
   File "[...]/hworld.py", line 18, in 
 print(isinstance(int, float))
TypeError: isinstance() arg 2 must be a type or tuple of types


I would understand to get an error message in line 5 but not in 18.  
Is this a bug or a feature?


It is a bug in your code (which you don't provide). Did you assign some 
value to float, e. g.:


 >>> float = 42.0
 >>> isinstance(int, float)
Traceback (most recent call last):
   File "", line 1, in 
     isinstance(int, float)
TypeError: isinstance() arg 2 must be a type or tuple of types

If you do not shadow the built-in you should get

 >>> isinstance(int, float)
False



Apparently the attachment was stripped from my message.  I'll put a 
smaller version directly into this message instead of an attachment:



#!/usr/bin/python

print("world!")

int = 17
print("world", int)

float = 6.670
print("world", float)

foo = 0
print(type(int))
print(type(float))
print(type(foo))

print(isinstance(foo, str))
print(isinstance(int, float))
print(isinstance(float, float))


I don't know about shadowing.  If I have defeated a whole variable type 
by naming a variable like a variable type, I would think it is a bad 
idea for python to allow this without warning.  It seems like a recipie 
for creating chaos.

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


Re: learning python ...

2021-05-23 Thread MRAB

On 2021-05-23 20:34, hw wrote:

On 5/23/21 7:28 PM, Peter Otten wrote:

On 23/05/2021 06:37, hw wrote:


Hi,

I'm starting to learn python and have made a little example program 
following a tutorial[1] I'm attaching.


Running it, I'm getting:


Traceback (most recent call last):
   File "[...]/hworld.py", line 18, in 
 print(isinstance(int, float))
TypeError: isinstance() arg 2 must be a type or tuple of types


I would understand to get an error message in line 5 but not in 18.  
Is this a bug or a feature?


It is a bug in your code (which you don't provide). Did you assign some 
value to float, e. g.:


 >>> float = 42.0
 >>> isinstance(int, float)
Traceback (most recent call last):
   File "", line 1, in 
     isinstance(int, float)
TypeError: isinstance() arg 2 must be a type or tuple of types

If you do not shadow the built-in you should get

 >>> isinstance(int, float)
False



Apparently the attachment was stripped from my message.  I'll put a
smaller version directly into this message instead of an attachment:


#!/usr/bin/python

print("world!")

int = 17
print("world", int)

float = 6.670
print("world", float)

foo = 0
print(type(int))
print(type(float))
print(type(foo))

print(isinstance(foo, str))
print(isinstance(int, float))
print(isinstance(float, float))


I don't know about shadowing.  If I have defeated a whole variable type
by naming a variable like a variable type, I would think it is a bad
idea for python to allow this without warning.  It seems like a recipie
for creating chaos.

The example you're following calls the variables "myfloat", etc, not 
"float", etc, so, yes, you're hiding the names of the types. Don't do that.


As far as Python is concerned, it's just a name that refers to 
something. It doesn't care whether that something is a type or a 
function or something else, it's just a name that refers to something.

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


Re: learning python ...

2021-05-23 Thread Stestagg
On Sun, 23 May 2021 at 20:37, hw  wrote:

> On 5/23/21 7:28 PM, Peter Otten wrote:
> > On 23/05/2021 06:37, hw wrote:
> >>
> >> Hi,
> >>
> >> I'm starting to learn python and have made a little example program
> >> following a tutorial[1] I'm attaching.
> >>
> >> Running it, I'm getting:
> >>
> >>
> >> Traceback (most recent call last):
> >>File "[...]/hworld.py", line 18, in 
> >>  print(isinstance(int, float))
> >> TypeError: isinstance() arg 2 must be a type or tuple of types
> >>
> >>
> >> I would understand to get an error message in line 5 but not in 18.
> >> Is this a bug or a feature?
> >
> > It is a bug in your code (which you don't provide). Did you assign some
> > value to float, e. g.:
> >
> >  >>> float = 42.0
> >  >>> isinstance(int, float)
> > Traceback (most recent call last):
> >File "", line 1, in 
> >  isinstance(int, float)
> > TypeError: isinstance() arg 2 must be a type or tuple of types
> >
> > If you do not shadow the built-in you should get
> >
> >  >>> isinstance(int, float)
> > False
> >
>
> Apparently the attachment was stripped from my message.  I'll put a
> smaller version directly into this message instead of an attachment:
>
>
> #!/usr/bin/python
>
> print("world!")
>
> int = 17
> print("world", int)
>
> float = 6.670
> print("world", float)
>
> foo = 0
> print(type(int))
> print(type(float))
> print(type(foo))
>
> print(isinstance(foo, str))
> print(isinstance(int, float))
> print(isinstance(float, float))
>
>
> I don't know about shadowing.


Shadowing is effectively saying “within this bit of code, (scope) I’m going
to use an already-used name for my own value”

If I have defeated a whole variable type
> by naming a variable like a variable type, I would think it is a bad
> idea for python to allow this without warning.


There are some reasons why allowing this is quite nice. And there’s
actually a ton of corner cases to consider when thinking about changing the
rules

Interestingly python 3 made this a little bit better by stopping you from
rebinding (shadowing) a number of built ins, such as True and False.

In your case, I agree that it is super confusing. One thing to learn to
look out for is if you assign to a name, then use that name on a different
context, expecting it to be different, then that’s not likely to work as
you expect.

It seems like a recipie
> for creating chaos.


Luckily almost every python code checker and/or linter will highlight this
for you.

If you’re learning python, I’d highly recommend doing so in an ide or
editor that has a code checker running.


> --



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


Re: Issue in software

2021-05-23 Thread Mats Wichmann

On 5/22/21 10:45 PM, pradeep Y wrote:

I I couldn't get the solution for this issue since last week will you
please help me to solve this issue the issue is when I opened command
prompt this below message will Pop up


"The program can't start because api-ms-win-crt-runtime-[1-1-0.dl] is
missing from your computer.try reinstalling the program to fix this
problem."



I tried to solve several times and many times but I didn't get any expected
outcome. Can you please help me please.



You're running Windows 7?  That's where this usually happens.

Here's (some of) the deal: when you build a program with Microsoft
compilers (MSVC) it links in a way so that it requires certain runtime 
components. This is absolutely no different than other compilers + 
operating systems, to start with.  In this case, the msvc version 
current Pythons are built with require a component that isn't available 
by default on Windows 7, or in fact, the WIndows 8 variants, which are 
quite old (*); it is included in Windows 10.  The Python installer 
includes this piece, because it's a known issue, and it will try to 
installe it, but if you don't select an install with administrator 
privilege - and the Python devs worked hard to make it not necessary to 
do an admin install otherwise - installing it will fail... often 
silently from the point of view of what you as the user see  (probably 
will be in the logfile). Sometimes it fails even with admin privilege 
AFAIK. Easiest workaround is to install the package that contains it - 
manually copying in dll files rarely works as expected.  It comes from 
"Visual C++ 2015 Redistributable", if I'm not remembering wrong - that's 
something you should be able to find and install.



(*) Win7 came out in 2009; Win8 in 2012; Win8.1 in 2013. It's somehow 
not entirely unsurprising that they wouldn't come with a piece of 
software that was introduced with Visual Studio 2015.

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


Re: learning python ...

2021-05-23 Thread Cameron Simpson
On 23May2021 21:02, Stestagg  wrote:
>On Sun, 23 May 2021 at 20:37, hw  wrote:
>> I don't know about shadowing.
>
>Shadowing is effectively saying “within this bit of code, (scope) I’m going
>to use an already-used name for my own value”

An example might make this clearer:

x = 1 # global variable

def f(a):
x = a * 2
return x

Inside the function f() the name 'x" shadows the global "x"; references 
to "x" are to the function's local vairable. Which is very desireable.

>If I have defeated a whole variable type
>> by naming a variable like a variable type, I would think it is a bad
>> idea for python to allow this without warning.
>
>There are some reasons why allowing this is quite nice. And there’s
>actually a ton of corner cases to consider when thinking about changing the
>rules

As Stestagg has mentioned, there are also tools called linters which 
warn you about issues like this. Tools like pyflakes, pylint, 
pycodestyle all inspect your code for a wide variety of potential errors 
and discouraged habits.  Not to mention tools like mypy which do type 
validation.

>Interestingly python 3 made this a little bit better by stopping you from
>rebinding (shadowing) a number of built ins, such as True and False.
>
>In your case, I agree that it is super confusing. One thing to learn to
>look out for is if you assign to a name, then use that name on a different
>context, expecting it to be different, then that’s not likely to work as
>you expect.
>
>It seems like a recipie
>> for creating chaos.

The runtime lets you do all sorts of things. Linters and type checkers 
exist to help you notice if you're writing such a recipe.

There _are_ times when it is useful to shadow a builtin name. Not being 
able to prevents a useful activity.

A common example in my own code is this:

from cs.upd import Upd, print

which shadows the print() builtin. The Upd class maintains status lines 
such as progress bars and so forth. It provides a print() function which 
withdraws the status lines, runs the builtin print, then restores them, 
allowing normal idiomatic use of print() in scripts making use of the 
status lines.

Similar situations abound.

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


Re: Use Chrome's / Firefox's dev-tools in python

2021-05-23 Thread Martin Di Paola
"unselectable text" not necessary means that it is an image. There is 
a CSS property that you can change to make a text 
selectable/unselectable.


And if it is an image, it very likely that it comes from the server as 
such, so "intercepting" the packet coming from there will be for 
nothing: you will have the same image.


About the "packet listener", you could setup a proxy between your 
browser and the server and use the proxy to see the messages. "Burp" is 
the classical tool for this.


But I have the feeling that the solution is easier.

Try the following: do it manually but take note of the steps you do.

Example:

1) Go to page https://www.parisclassenumerique.fr
2) Click in the upper-right menu button and choose "Tutoriels". Now the 
URL is 
https://www.parisclassenumerique.fr/lutece/jsp/site/Portal.jsp?page_id=9

3) Then click in "Comment démarrer sur PCN ?", on the left panel

... and so on.

Basically you can then translate those steps to Selenium/selectq and 
automate them. It's here where I could help you but I cannot do much 
without more info because I don't know which page you are looking and in 
which link you are trying to click and stuff like that.


On Sun, May 23, 2021 at 01:36:48AM -0700, max pothier wrote:

Hi,
Seems like that could be a method of doing things. Just one clarification: the 
website has unselectable text, looks like it's an image strangely generated, so 
if I can get the packet with it, it would be perfect. As I said (I think), 
logging in with Selenium was already possible, and I could get a screenshot of 
the page after logging in.
If you got this working like a packet listener in browser capable of seeing 
packet data, I'd gladly accept the code.
I've tried to do this for 3 years now (since I came into that school 
basically), looks like it's coming to an end!
Thanks!
--
https://mail.python.org/mailman/listinfo/python-list

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


Re: Question for potential python development contributions on Windows

2021-05-23 Thread Terry Reedy

On 5/23/2021 12:20 PM, [email protected] wrote:

I asked this question on python-dev last week but did not get an answer.  If
anyone here know the answer I would appreciate it.

The Python Developers Guide specifically states to get VS2017 for developing
or enhancing python on a Windows system.

Is it still correct to specifically use VS2017 , or is VS2019 also
acceptable?

I ask this because I know that the *.vcxproj files and other
build-environment files have changed format pretty dramatically over the
many releases of VS.  If a potential new contribution targeted for current
and future python will require new build environment files, I wouldn’t want
to have to “down release” those files (or expect core dev’s to do it) at or
after submission to the community for approval.  Much better to use the same
setup as core dev’s use than to introduce up-level differences in the build
environment.

IOW, for new releases on Windows are core dev’s still using VS2017 and so
potential contributors should also use that version, or has the core dev’s
process for Windows releases been updated to use VS2019?


I am pretty sure that VS2019 output is binary compatible with with 
output from VS2017 and VS2015.  I believe the only issue would be is one 
were developing a patch to a CPython .c file and one used recent C## 
features not allowed in CPython code.


You could open an issue on bugs.python.org asking that the doc be clarified.


--
Terry Jan Reedy


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


Re: learning python ...

2021-05-23 Thread hw

On 5/23/21 10:02 PM, Stestagg wrote:



On Sun, 23 May 2021 at 20:37, hw > wrote:


On 5/23/21 7:28 PM, Peter Otten wrote:
 > On 23/05/2021 06:37, hw wrote:
 >>
 >> Hi,
 >>
 >> I'm starting to learn python and have made a little example program
 >> following a tutorial[1] I'm attaching.
 >>
 >> Running it, I'm getting:
 >>
 >>
 >> Traceback (most recent call last):
 >>    File "[...]/hworld.py", line 18, in 
 >>  print(isinstance(int, float))
 >> TypeError: isinstance() arg 2 must be a type or tuple of types
 >>
 >>
 >> I would understand to get an error message in line 5 but not in 18.
 >> Is this a bug or a feature?
 >
 > It is a bug in your code (which you don't provide). Did you
assign some
 > value to float, e. g.:
 >
 >  >>> float = 42.0
 >  >>> isinstance(int, float)
 > Traceback (most recent call last):
 >    File "", line 1, in 
 >      isinstance(int, float)
 > TypeError: isinstance() arg 2 must be a type or tuple of types
 >
 > If you do not shadow the built-in you should get
 >
 >  >>> isinstance(int, float)
 > False
 >

Apparently the attachment was stripped from my message.  I'll put a
smaller version directly into this message instead of an attachment:


#!/usr/bin/python

print("world!")

int = 17
print("world", int)

float = 6.670
print("world", float)

foo = 0
print(type(int))
print(type(float))
print(type(foo))

print(isinstance(foo, str))
print(isinstance(int, float))
print(isinstance(float, float))


I don't know about shadowing. 



Shadowing is effectively saying “within this bit of code, (scope) I’m 
going to use an already-used name for my own value”


That should give at least a warning.


If I have defeated a whole variable type
by naming a variable like a variable type, I would think it is a bad
idea for python to allow this without warning. 



There are some reasons why allowing this is quite nice. And there’s 
actually a ton of corner cases to consider when thinking about changing 
the rules


Perl has a way to turn off unwanted warnings.  It won't change the rules 
to give a warning.


Interestingly python 3 made this a little bit better by stopping you 
from rebinding (shadowing) a number of built ins, such as True and False.


In your case, I agree that it is super confusing.


It seems dangerous and seems to show that python is too unfinished to be 
used.  For all I know, it makes it easy to, for example, drop a whole 
table in a database because something was shadowed without warning.


I can imagine that there can be all kinds of situations in which 
something like that happens, and you can spend hours or days trying to 
figure out what's wrong and may never find it.


One thing to learn to 
look out for is if you assign to a name, then use that name on a 
different context, expecting it to be different, then that’s not likely 
to work as you expect.


Then why doesn't give it at least a warning?

There is even no indication from the output from the program before it 
aborts with an error message that something might be wrong:  For 
'type(float)', it prints "" just like it does for int. 
How is anyone supposed to debug stuff like that?


Why doesn't print(type(float)) give an error message after the variable 
type was already defeated (or prints something else)?  What is it 
actually printing?



It seems like a recipie
for creating chaos.


Luckily almost every python code checker and/or linter will highlight 
this for you.


If you’re learning python, I’d highly recommend doing so in an ide or 
editor that has a code checker running.


Emcas highlights the syntax fine; I don't know if it can do more for 
python.  It shouldn't need to.


Things get creepy when a programming language makes it so that the 
programmer can't figure out anymore how a result produced by his program 
has come about.

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


Re: learning python ...

2021-05-23 Thread Igor Korot
Hi,

On Mon, May 24, 2021 at 12:26 AM hw  wrote:
>
> On 5/23/21 10:02 PM, Stestagg wrote:
> >
> >
> > On Sun, 23 May 2021 at 20:37, hw  > > wrote:
> >
> > On 5/23/21 7:28 PM, Peter Otten wrote:
> >  > On 23/05/2021 06:37, hw wrote:
> >  >>
> >  >> Hi,
> >  >>
> >  >> I'm starting to learn python and have made a little example program
> >  >> following a tutorial[1] I'm attaching.
> >  >>
> >  >> Running it, I'm getting:
> >  >>
> >  >>
> >  >> Traceback (most recent call last):
> >  >>File "[...]/hworld.py", line 18, in 
> >  >>  print(isinstance(int, float))
> >  >> TypeError: isinstance() arg 2 must be a type or tuple of types
> >  >>
> >  >>
> >  >> I would understand to get an error message in line 5 but not in 18.
> >  >> Is this a bug or a feature?
> >  >
> >  > It is a bug in your code (which you don't provide). Did you
> > assign some
> >  > value to float, e. g.:
> >  >
> >  >  >>> float = 42.0
> >  >  >>> isinstance(int, float)
> >  > Traceback (most recent call last):
> >  >File "", line 1, in 
> >  >  isinstance(int, float)
> >  > TypeError: isinstance() arg 2 must be a type or tuple of types
> >  >
> >  > If you do not shadow the built-in you should get
> >  >
> >  >  >>> isinstance(int, float)
> >  > False
> >  >
> >
> > Apparently the attachment was stripped from my message.  I'll put a
> > smaller version directly into this message instead of an attachment:
> >
> >
> > #!/usr/bin/python
> >
> > print("world!")
> >
> > int = 17
> > print("world", int)
> >
> > float = 6.670
> > print("world", float)
> >
> > foo = 0
> > print(type(int))
> > print(type(float))
> > print(type(foo))
> >
> > print(isinstance(foo, str))
> > print(isinstance(int, float))
> > print(isinstance(float, float))
> >
> >
> > I don't know about shadowing.
> >
> >
> > Shadowing is effectively saying “within this bit of code, (scope) I’m
> > going to use an already-used name for my own value”
>
> That should give at least a warning.
>
> > If I have defeated a whole variable type
> > by naming a variable like a variable type, I would think it is a bad
> > idea for python to allow this without warning.
> >
> >
> > There are some reasons why allowing this is quite nice. And there’s
> > actually a ton of corner cases to consider when thinking about changing
> > the rules
>
> Perl has a way to turn off unwanted warnings.  It won't change the rules
> to give a warning.
>
> > Interestingly python 3 made this a little bit better by stopping you
> > from rebinding (shadowing) a number of built ins, such as True and False.
> >
> > In your case, I agree that it is super confusing.
>
> It seems dangerous and seems to show that python is too unfinished to be
> used.  For all I know, it makes it easy to, for example, drop a whole
> table in a database because something was shadowed without warning.
>
> I can imagine that there can be all kinds of situations in which
> something like that happens, and you can spend hours or days trying to
> figure out what's wrong and may never find it.
>
> > One thing to learn to
> > look out for is if you assign to a name, then use that name on a
> > different context, expecting it to be different, then that’s not likely
> > to work as you expect.
>
> Then why doesn't give it at least a warning?
>
> There is even no indication from the output from the program before it
> aborts with an error message that something might be wrong:  For
> 'type(float)', it prints "" just like it does for int.
> How is anyone supposed to debug stuff like that?
>
> Why doesn't print(type(float)) give an error message after the variable
> type was already defeated (or prints something else)?  What is it
> actually printing?
>
> > It seems like a recipie
> > for creating chaos.
> >
> >
> > Luckily almost every python code checker and/or linter will highlight
> > this for you.
> >
> > If you’re learning python, I’d highly recommend doing so in an ide or
> > editor that has a code checker running.
>
> Emcas highlights the syntax fine; I don't know if it can do more for
> python.  It shouldn't need to.
>
> Things get creepy when a programming language makes it so that the
> programmer can't figure out anymore how a result produced by his program
> has come about.

Remember - python is an untyped language.
It is not C, C++ or even Pascal.

So there is no difference whether you write

float = 5.0

or

float1 = 5.0

Thank you.

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


Re: learning python ...

2021-05-23 Thread hw


PS:

On 5/24/21 7:20 AM, hw wrote:
There is even no indication from the output from the program before it 
aborts with an error message that something might be wrong:  For 
'type(float)', it prints "" just like it does for int. 
How is anyone supposed to debug stuff like that?


Ok, it prints "" for type(str) when str hasn't been defeated.

But still:


#!/usr/bin/python

foo = 0
print(type(int))
print(type(float))
print(type(foo))
print(type(str))
type = 4
print(type(str))


line 9, in 
print(type(str))
TypeError: 'int' object is not callable


How is this /not/ bad?  It seems like a no-go for any programming 
language that isn't designed for the programmer to shoot into thier own 
feet.

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


Re: learning python ...

2021-05-23 Thread hw

On 5/24/21 12:03 AM, Cameron Simpson wrote:

On 23May2021 21:02, Stestagg  wrote:

On Sun, 23 May 2021 at 20:37, hw  wrote:

I don't know about shadowing.


Shadowing is effectively saying “within this bit of code, (scope) I’m going
to use an already-used name for my own value”


An example might make this clearer:

 x = 1 # global variable

 def f(a):
 x = a * 2
 return x

Inside the function f() the name 'x" shadows the global "x"; references
to "x" are to the function's local vairable. Which is very desireable.


If it works that way, I would consider it an entirely different 
variable.  Is there a way to access the global x from within a function 
without transferring it through parameters of the function?  Than can 
also sometimes be useful.



If I have defeated a whole variable type

by naming a variable like a variable type, I would think it is a bad
idea for python to allow this without warning.


There are some reasons why allowing this is quite nice. And there’s
actually a ton of corner cases to consider when thinking about changing the
rules


As Stestagg has mentioned, there are also tools called linters which
warn you about issues like this. Tools like pyflakes, pylint,
pycodestyle all inspect your code for a wide variety of potential errors
and discouraged habits.  Not to mention tools like mypy which do type
validation.


So you're saying one can't really go without those unless you want to 
take the risk?



Interestingly python 3 made this a little bit better by stopping you from
rebinding (shadowing) a number of built ins, such as True and False.

In your case, I agree that it is super confusing. One thing to learn to
look out for is if you assign to line 9, in 

print(type(str))
TypeError: 'int' object is not callablea name, then use that name on a 
different

context, expecting it to be different, then that’s not likely to work as
you expect.

It seems like a recipie

for creating chaos.


The runtime lets you do all sorts of things. Linters and type checkers
exist to help you notice if you're writing such a recipe.

There _are_ times when it is useful to shadow a builtin name. Not being
able to prevents a useful activity.

A common example in my own code is this:

 from cs.upd import Upd, print

which shadows the print() builtin. The Upd class maintains status lines
such as progress bars and so forth. It provides a print() function which
withdraws the status lines, runs the builtin print, then restores them,
allowing normal idiomatic use of print() in scripts making use of the
status lines.

Similar situations abound.


I'm not saying it shouldn't be allowed to defeat or to re-define stuff, 
only that it shouldn't go through quietly.

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