Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

Roel Schroeven roel at roelschroeven.net
Wed Mar 6 13:28:29 EST 2024



Grant Edwards via Python-list schreef op 6/03/2024 om 18:59:
> On 2024-03-06, Roel Schroeven via Python-list <python-list at python.org> 
> wrote:
> > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list:
> >> >>> from scoping2 import *
> >
> > [...]
> >
> > I would advice not to use 'import *', if at all possible, for 
> multiple > reasons, one of which is to prevent problems like this.
>
> Unfortunately, many (most?) tutorials for particular modules (and even
> example code in the Python documentation itself) are all written
> assuming that you do "from <module> import *". It saves the tutorial
> write a few keystrokes, but causes untold trouble for people who learn
> incorrectly that "from <module> import *" is the proper way to do
> things.

I know ... it's really irritating.

-- 
"There is a theory which states that if ever anyone discovers exactly what the
Universe is for and why it is here, it will instantly disappear and be
replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened."
         -- Douglas Adams, The Restaurant at the End of the Universe



More information about the Python-list mailing list