| Deutsch English Français Italiano |
|
<vqfl8c$3nfmd$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Mark Bourne <nntp.mbourne@spamgourmet.com>
Newsgroups: comp.lang.c
Subject: Re: Python recompile
Date: Fri, 7 Mar 2025 20:34:18 +0000
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <vqfl8c$3nfmd$1@dont-email.me>
References: <vq1qas$j22$1@gallifrey.nk.ca> <vq1uvb$qbuq$1@dont-email.me>
<vq22nc$rvb8$1@dont-email.me> <vq24kd$rg6i$1@dont-email.me>
<vq3oag$18iv6$1@dont-email.me> <vq4hf2$1brf7$1@dont-email.me>
<vq4l3d$1ck9e$1@dont-email.me> <vq4m0u$1ctpn$1@dont-email.me>
<vq4n05$1d5dv$1@dont-email.me> <vq4om7$1dbo2$2@dont-email.me>
<vq6dqh$1pskk$1@dont-email.me> <vq6f8p$1pmnk$1@dont-email.me>
<vq6gqc$1qcp8$1@dont-email.me> <vq6ips$1pmnk$2@dont-email.me>
<vq6j5h$1qosf$1@dont-email.me> <20250304092827.708@kylheku.com>
<vq7g1p$1vmg5$1@dont-email.me> <vq8544$23f55$4@dont-email.me>
<vq88s7$242vk$1@dont-email.me> <vq8cdq$24hi9$2@dont-email.me>
<vq9di0$2db82$1@dont-email.me> <vq9m4p$2eqra$1@dont-email.me>
<vqaqof$2lg6a$4@dont-email.me> <vqbn4r$2tdu2$1@dont-email.me>
<20250306115048.606@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 07 Mar 2025 21:34:21 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f0ce4a01166aa473ecb851db25d1c853";
logging-data="3915469"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SF/ieczV8eGc+uOvsw/VY"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101
SeaMonkey/2.53.20
Cancel-Lock: sha1:0ln6xWENVvT3G/rYPbKSlUS8jA8=
In-Reply-To: <20250306115048.606@kylheku.com>
Bytes: 2864
Kaz Kylheku wrote:
> When imports are being compiled automatically to .pyc files,
> their statements are being executed; like if you have a top-level
> print('hello'), you will see the hello output, and you will see
> a .pyc file in __pycache__ for that file. Was that hello printed
> after the .pyc file was produced, or during? I suspect during.
No, the top-level code in the module is executed when the import is
executed, not when it is compiled. If the imported module hasn't
already been compiled to bytecode, that needs to be done before the
import can be completed.
In your example, "hello" will be printed when the module is imported,
without any functions etc. within the module being called, but it's done
when the bytecode is executed, not when it's compiled compilation. If
you ran the same program again (after the bytecode had been cached in a
..pyc file) without modifying the source (so it doesn't need to be
recompiled), you'd still get that output printed, even though the
imported module isn't compiled again.
--
Mark.