Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

UNIX is many things to many people, but it's never been everything to anybody.


devel / comp.lang.python / Re: A question about import

SubjectAuthor
o Re: A question about importCameron Simpson

1
Re: A question about import

<mailman.68.1708118042.3227.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=25050&group=comp.lang.python#25050

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.network!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs...@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: A question about import
Date: Sat, 17 Feb 2024 08:13:50 +1100
Lines: 40
Message-ID: <mailman.68.1708118042.3227.python-list@python.org>
References: <c149f0a4-93c0-4a86-8865-915fc236530f@mrabarnett.plus.com>
<Zc/QDsbFobsM+VoW@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-Trace: news.uni-berlin.de 9n027Obslazq2BWF2l0pwQ8kn0L0LT9sT5UsWv5ZAkmw==
Cancel-Lock: sha1:yYxlbU0N1RgWYK1m6gXpM2XzZ38= sha256:Ts5yWOnjFTPy6vT01szypBgRzmloH3C9fM/R3WNGRT8=
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'modules': 0.07;
'subject:import': 0.07; 'used.': 0.07; 'datetime': 0.09;
'modules.': 0.09; 'namespace': 0.09; 'cheers,': 0.11; 'import':
0.15; 'cameron': 0.16; 'eg:': 0.16; 'from:addr:cs': 0.16;
'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16;
'importing': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'once.':
0.16; 'received:13.237': 0.16; 'received:13.237.201': 0.16;
'received:13.237.201.189': 0.16; 'received:cskk.id.au': 0.16;
'received:id.au': 0.16; 'received:mail.cskk.id.au': 0.16;
'script,': 0.16; 'simpson': 0.16; 'variable.': 0.16; 'wrote:':
0.16; 'subject:question': 0.17; 'to:addr:python-list': 0.20;
'written': 0.22; 'code': 0.23; 'local': 0.27; 'header:User-
Agent:1': 0.30; 'module': 0.31; 'python-list': 0.32; 'but': 0.32;
'there': 0.33; 'script': 0.33; 'header:In-Reply-To:1': 0.34;
'received:au': 0.35; 'really': 0.37; 'put': 0.38; 'use': 0.39;
'something': 0.40; 'imagine': 0.64; 'received:13': 0.64; 'your':
0.64; 'let': 0.66; 'received:userid': 0.66; 'direct': 0.73;
'known': 0.84; 'imports': 0.84; 'urban': 0.91
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <c149f0a4-93c0-4a86-8865-915fc236530f@mrabarnett.plus.com>
User-Agent: Mutt/2.2.7 (2022-08-07)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Zc/QDsbFobsM+VoW@cskk.homeip.net>
X-Mailman-Original-References: <c149f0a4-93c0-4a86-8865-915fc236530f@mrabarnett.plus.com>
 by: Cameron Simpson - Fri, 16 Feb 2024 21:13 UTC

On 16Feb2024 20:32, MRAB <python@mrabarnett.plus.com> wrote:
>On 2024-02-16 20:07, Gabor Urban via Python-list wrote:
>>I need something about modules to be clarified.
>>
>>Suppose I have written a module eg: ModuleA which imports an other
>>module, let us say the datetime.
>>
>>If I import ModuleA in a script, will be datetime imported automatically?
>>
>Yes. When a module is imported it can import other modules.

But note that `datetime` does not magicly get put in the script's
namespace.

Module A:

import datetime

Script:

import A

In the code in module A the name datetime is known and can be used.

In the code in the script the name A is known and can be used. Importing
A does not magicly set the name datetime in the script's namespace -
imagine the the pollution!

You _can_ access it as A.datetime because it is in the A module's
namespace. But really if you just wanted datetime for direct use in the
script you would import it there too:

import datetime
import A

Note that the datetime module is only actually loaded once. The import
binds the name into your local namespace like any other variable.

Cheers,
Cameron Simpson <cs@cskk.id.au>

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor