Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Most legends have their basis in facts. -- Kirk, "And The Children Shall Lead", stardate 5029.5


devel / comp.lang.python / Re: importing a module from a file without the '.py' suffix

SubjectAuthor
o Re: importing a module from a file without the '.py' suffixChris Angelico

1
Re: importing a module from a file without the '.py' suffix

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: importing a module from a file without the '.py' suffix
Date: Fri, 22 Oct 2021 23:26:20 +1100
Lines: 14
Message-ID: <mailman.8.1634905593.23718.python-list@python.org>
References: <b54f13d9-0d60-5c87-877a-2ab9d429c533@vub.be>
<CAPTjJmpPYcMojBSsXaYofJzMULHMZrb0TiyxHZ=ufqnoQSJN9A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de CZW3XSy8D8c60jHSaZSBCAEC7DEr0+RSX4VIbcDG5o/g==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=D460ZGmX;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03;
'subject:module': 0.07; 'subject:without': 0.07; 'import': 0.15;
'antoon': 0.16; 'chrisa': 0.16; 'easiest': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'pardon': 0.16; 'received:209.85.221.42': 0.16; 'received:mail-
wr1-f42.google.com': 0.16; 'wrote:': 0.16; 'python': 0.16;
'to:addr:python-list': 0.20; 'fri,': 0.22; 'subject:file': 0.22;
'code': 0.23; 'module': 0.31; "doesn't": 0.32; 'to:name:python':
0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'subject:from': 0.37;
'received:209.85': 0.37; 'file': 0.38; 'way': 0.38;
'received:209': 0.39; 'use': 0.39; '22,': 0.40; 'should': 0.40;
'2021': 0.71
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=JfLx8fkTk8DNzhgsZDY5f6H89/JDPCsO/bJzoEvJbrQ=;
b=D460ZGmXTzYFAD0mru5d3DG9y3uIY0K+JoQ4i5/n10FCyFL7NQTGpKLtNPzuRy5p/S
vrq0Y319U94KohzfNNIr1emQKV8/aK+lrKWf+c+O6sKMBT7ql/pivCd2/Eu1Xk05urtR
4KCxqYXCrGlcZKlQqtpvPauN2BODqwZb+IzG8bEHNqXtIaQuUtDLjRioNi2z/HbYF5d8
Q05RPir1tWHPaq1mXFgYE8K/w96jUc8L2Zfx7myz0EE0N0Gg7pAWShX5U8lU827Qp+6g
LTHSl5Mnn1VIPdntRrejkzTopvXNWUkCcGUpmlrn2q6yyNrxeuZAU/IgsLV+CkR3PZ+x
jatw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=JfLx8fkTk8DNzhgsZDY5f6H89/JDPCsO/bJzoEvJbrQ=;
b=YHagbDIhEVO7M3cFlpiSYMqLjARzsNfDwOIKDrEi8laD6ZRpBiURgCEaq7ujiZJWHK
utBl1UKKA1CNNN1Y6bxD09HjbLj07ZUXKgoVBN1HjV8irZpKePRUrA8ZULfzwz7IUW2i
tAOYVVv7OeqnxhEpZZPRNaXINt0GZdlHwMOaHTPStOCMLweEQ8RgSXGa7mQHUPeRriJD
zux4HdZyBCnDyuSZq9WcRefwnW+gOvojmcvq+gs2a9fY2Gcd4UD4h7NavEwl0BbEGC24
qGbxCYZP+SUamiJ3vGQhpSLcXbXHG8/Pa3TRJf6/RjeJCbdIQzpJBCUQKLihPQxquBF0
RSWQ==
X-Gm-Message-State: AOAM530ASwJwv75zvaSgfEwBSI1Q04qlfoOs8/nANyZLxRbJtsGJbLro
DrHi7V/IRJlCKx8+IEz1xXKPRrco1cJ14Mn3STqbAOZ6hb2WFQ==
X-Google-Smtp-Source: ABdhPJw71V+3fxdRm4lz7jVOJYXlUTh1fD+zPBfMP9yTK5Xc3jluUKU/YsFQe73FefcaRpJ1treghiTKuiXvKyIUkqA=
X-Received: by 2002:a05:6000:1b90:: with SMTP id
r16mr14717120wru.153.1634905591330;
Fri, 22 Oct 2021 05:26:31 -0700 (PDT)
In-Reply-To: <b54f13d9-0d60-5c87-877a-2ab9d429c533@vub.be>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.35
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: <CAPTjJmpPYcMojBSsXaYofJzMULHMZrb0TiyxHZ=ufqnoQSJN9A@mail.gmail.com>
X-Mailman-Original-References: <b54f13d9-0d60-5c87-877a-2ab9d429c533@vub.be>
 by: Chris Angelico - Fri, 22 Oct 2021 12:26 UTC

On Fri, Oct 22, 2021 at 10:36 PM Antoon Pardon <antoon.pardon@vub.be> wrote:
>
> I have a file with python code but the name doesn't end with the '.py'
> suffix.
>
> What is the easiest way to import this code as a module without changing
> its name?
>

It should be possible to use importlib for this:

https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly

ChrisA


devel / comp.lang.python / Re: importing a module from a file without the '.py' suffix

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor