| Deutsch English Français Italiano |
|
<scope-20240306173836@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Variable scope inside and outside functions
Date: 6 Mar 2024 16:40:26 GMT
Organization: Stefan Ram
Lines: 22
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <scope-20240306173836@ram.dialup.fu-berlin.de>
References: <mailman.48.1709742549.3452.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de O1OZ6wP8lc7VqphvRnnH4A1l1axpOK6fIq/yWa0MZiPuhK
Cancel-Lock: sha1:YDAls/P9sryB8l8EU3tfFu8eXyU= sha256:RvqxH4z35j4J4cpL+ium4mihhpyosFhUO9wmRlsRY0g=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
Jacob Kruger <jacob.kruger.work@gmail.com> wrote or quoted:
> >>> from scoping2 import *
Now, "dt_expiry" exists in /two/ modules: In "scoping2" and in the
current module (as a copy). To avoid this, "import scoping2" instead.
> >>> print(dt_expiry)
>1970-01-01 00:00:00+00:00
> >>> do_it()
>2024-03-06 18:12
This changes the variable "dt_expiry" in "scoping2", but not the
copy (also named "dt_expiry") in the current module.
> >>> print(dt_expiry)
>1970-01-01 00:00:00+00:00
This prints "dt_expiry" from the current module, not from "scoping2".
To avoid this, replace "from scoping2 import *" by "import scoping2"
and replace the "dt_expiry" in the two print statements by
"scoping2.dt_expiry".