Deutsch English Français Italiano |
<20250306115048.606@kylheku.com> 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: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.c Subject: Re: Python recompile Date: Thu, 6 Mar 2025 20:28:41 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: <20250306115048.606@kylheku.com> 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> Injection-Date: Thu, 06 Mar 2025 21:28:41 +0100 (CET) Injection-Info: dont-email.me; posting-host="04955cbd15ca2b8c7171511d202c7356"; logging-data="3296427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19gWAw7y6577dAdc+uGit+R6k8xF9Xu+oc=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:hXx8IWLk40z1R8lOLcmQ23kyENU= Bytes: 3577 On 2025-03-06, Muttley@DastardlyHQ.org <Muttley@DastardlyHQ.org> wrote: > Compilation and runtime are the same thing in Python arn't they? Can you > precompile code? I'm not an expert on the language to any extent though I > can write simple code in it. Python is ahead-of-time compiled into byte code. Python interpretation runs the byte code. In some situations, Python compiles .py file into .pyc files which are stored in a __pycache__ directory, doing this as it executes the files. You can force ahead-of-time file compiling "python3 -m compileall yourprogram.py". When you have local imports: e.g. you have a foo.py which has "import bar", referring to bar.py, and you run "python3 foo.py", it will compile the bar inport and cache its byte code in a file in __pycache__. I suspect that in cases when a .pyc file is not being dropped, Python does incremental ahead-of-time compiling, meaning that it reads successive top-level statements of the .py file, compiles them to bytecode in memory, and immediately executes them, rather than compiling the whole file first. Quite possibly, it might do this even when it *is* generating a .pyc file, in those cases when it's doing so automatically (the foo and bar scenario described above). 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. But anyway, Python obviously has compile time separate from run-time. Or, should we say, compile times separate from run-times. There is a time when source is being compiled to byte code, and that is not the same time as when that byte code is executed. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca