Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for Karl Knechtelâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Edit | Post #291739 | Initial revision | — | 10 months ago |
Answer | — |
A: How can I make a standalone executable from Python code? Normally, Python is compiled, but it compiles to bytecode, not to your computer's native instructions. This bytecode is cross-platform, but it can't be used by the CPU directly - it can't be turned into a native executable. So fundamentally there are two ways to fix the problem: by using a custom ... (more) |
— | 10 months ago |
Edit | Post #291738 | Initial revision | — | 10 months ago |
Question | — |
How can I make a standalone executable from Python code? I know that I can make Python code run starting from the script, but this still requires the user to have Python installed (and will still rely on configuring the system so that it can find Python from the script, which can go wrong in a few different ways). I want to be able to distribute my prog... (more) |
— | 10 months ago |
Edit | Post #291737 | Initial revision | — | 10 months ago |
Answer | — |
A: How can I start my Python code, from the code itself? Mac/Linux In this environment, Python scripts can be given a shebang) line that tells the operating system that the file is a script, and what interpreter (i.e., Python) to use for it. Because `#` starts a comment in Python, Python itself doesn't need any special handling for this - it's just igno... (more) |
— | 10 months ago |
Edit | Post #291736 | Initial revision | — | 10 months ago |
Question | — |
How can I start my Python code, from the code itself? I have already learned how to tell the Python interpreter to run my code, but the standard approach feels a little unsatisfactory. I want the user experience to be that my program starts with the actual `.py` file, not with a Python interpreter. It's okay if a Python interpreter needs to be installed... (more) |
— | 10 months ago |
Edit | Post #291323 |
Post edited: rm content that will be moved to a separate Q&A |
— | 10 months ago |
Comment | Post #291708 |
I'm inclined to agree with John here. Numeric literals exist in programs for a wide variety of reasons, most of which are not engineering related. East Asian programmers typically don't use "localized" programming languages (these are a novelty at best anyway) but they do *comment* code in their nati... (more) |
— | 10 months ago |
Edit | Post #291676 | Initial revision | — | 11 months ago |
Answer | — |
A: Installing packages for, and using them with, a specific Python installation Choosing an environment for third-party libraries The short version of the answer is: Python installations don't normally share libraries because there are too many ways it could go wrong; generally each installation has its own install locations for third-party libraries; and generally each Pytho... (more) |
— | 11 months ago |
Edit | Post #291675 | Initial revision | — | 11 months ago |
Question | — |
Installing packages for, and using them with, a specific Python installation I have multiple installations of Python on my machine. I already know how to choose one to use to run for my code - and therefore, I could also solve the problem for third-party application code. However, almost all of the third-party code I work with is libraries, not applications. When I use Pip... (more) |
— | 11 months ago |
Edit | Post #291674 | Initial revision | — | 11 months ago |
Answer | — |
A: How is this code "dividing" by a string? Python allows for operators to be overloaded (the subject of a separate future Q&A). The `/` operator doesn't strictly mean division in a mathematical sense; it means whatever the operands define it to mean - but we may call the operation "division" regardless. (Specifically, we say "true division" t... (more) |
— | 11 months ago |
Edit | Post #291667 |
Post edited: copyedit for conciseness, clarity and correct use of terminology; include an explicit example instead of only citing an error message; improve title |
— | 11 months ago |
Comment | Post #291611 |
Now that I've read the self-answer, the intended scope of the question is clearer to me. I might propose an edit later. (more) |
— | 11 months ago |
Comment | Post #291618 |
I understand Pyenv as a tool for *creating or setting up* Python environments, rather than choosing between them. Have I overlooked something? I do have an upcoming question planned about venvs generally (an overview of what they are and why someone might want to use one); would information about Pye... (more) |
— | 11 months ago |
Suggested Edit | Post #291667 |
Suggested edit: copyedit for conciseness, clarity and correct use of terminology; include an explicit example instead of only citing an error message; improve title (more) |
helpful | 11 months ago |
Comment | Post #291616 |
This is meant as part of a series of upcoming canonical Q&As to cover:
* choosing which installation Pip uses
* why one might want separate Python installations at all
* how and why to use virtual environments
I prioritized this set of questions because it provides background material so ... (more) |
— | 11 months ago |
Edit | Post #291618 |
Post edited: Demote a parenthetical to a footnote; renumber other footnotes |
— | 11 months ago |
Edit | Post #291618 | Initial revision | — | 11 months ago |
Answer | — |
A: Choosing between multiple Python installations (environments) on the same computer This answer assumes only installations of the reference "CPython" implementation, as provided by the official website at https://www.python.org. Other installations - such as those provided by the Microsoft Store or by Anaconda, or alternate implementations such as PyPy or IronPython - may introd... (more) |
— | 11 months ago |
Edit | Post #291616 | Initial revision | — | 11 months ago |
Question | — |
Choosing between multiple Python installations (environments) on the same computer I have multiple installations of Python on my machine. When I run Python, what determines which installation is used? How can I control this? (more) |
— | 11 months ago |
Comment | Post #291611 |
In fact, this is **not** necessary [since Python 3.3](https://peps.python.org/pep-0420/), although this particular piece of misinformation has proven very persistent. In contemporary Python, recognition of "packages" is automatic. Adding an `__init__.py` file simply distinguishes a "regular package" ... (more) |
— | 11 months ago |
Comment | Post #291611 |
BTW, I think I have an old post on the site Meta where I laid out some possible future import Q&As. Seems like a good time for both of us to revisit that. (more) |
— | 11 months ago |
Comment | Post #291611 |
It's important to note here that the term "package" is overloaded here. For lack of better disambiguation: a *distribution* package is what you create by having a `setup.py` and/or `pyproject.toml` file, using a build backend such as Setuptools to create a "wheel" and/or "sdist", and optionally publi... (more) |
— | 11 months ago |
Comment | Post #291556 |
If anything, I'd say "locked" sounds more final than "closed".
Stack Exchange experimented with this in the past: they changed "closed" to "on hold". It didn't seem to accomplish anything on balance; it seems to have been only marginally friendlier, but also correspondingly more confusing. The cha... (more) |
— | 11 months ago |
Comment | Post #291557 |
@#8176 I think part of the issue is with describing such feedback as "private". Many people feel strongly - and it's not hard to see why - that comments made to new users ought to be open for review by others.
Another thing I've noted about this topic in the past is that the level of concern depen... (more) |
— | 11 months ago |
Comment | Post #291557 |
The closed status for questions is not normally thought of as a "space" at all, but treating it this way does make a certain amount of sense. It would be nice if there were an *actual* "workshop space", possibly. My previous proposal has been to use a separate category, with the ability to *move* que... (more) |
— | 11 months ago |
Edit | Post #291341 |
Post edited: fix code typo - `setup` was in a sub-package before Setuptools promoted it |
— | 12 months ago |
Edit | Post #291341 | Initial revision | — | 12 months ago |
Answer | — |
A: Why does `distutils` seem to be missing or broken? Isn't it part of the standard library? Understanding distutils and setuptools: the history The short version of "why does installing Setuptools fix the problem?" is that Setuptools provides its own `distutils` package, overriding anything the standard library might or might not have. When you `import setuptools` explicitly, it furtherm... (more) |
— | 12 months ago |
Edit | Post #291340 | Initial revision | — | 12 months ago |
Question | — |
Why does `distutils` seem to be missing or broken? Isn't it part of the standard library? Sometimes when I try to install a third-party library for Python, I get an error saying that either `distutils`, or some part of it like `distutils.core` or `distutils.util`, could not be found. It's shown as a `ModuleNotFoundError`, so presumably it's coming from Python when it tries to run a `setup... (more) |
— | 12 months ago |
Comment | Post #291323 |
I agree, at least superficially. When I started writing I had it in mind that "running" the script as an executable is the same sort of thing as invoking Python to run it (since it's still asking a Python runtime to evaluate the code, just the other way around). But looking at it now - especially giv... (more) |
— | 12 months ago |
Edit | Post #291323 | Initial revision | — | 12 months ago |
Answer | — |
A: How and where does Python code start running? How can I control that? Starting up Python There are several key ways to use the `python` command from the command line: `python` by itself starts a REPL that allows typing in and running Python code on the fly, one statement at a time. `python myscript.py` runs the code in `myscript.py`, assuming it's in the cur... (more) |
— | 12 months ago |
Comment | Post #291322 |
Reference questions on Stack Overflow that inspired this question:
* [Why do people write `#!/usr/bin/env python` on the first line of a Python script?](//stackoverflow.com/q/2429511)
* [How do I make a python script executable?](//stackoverflow.com/q/27494758)
* [`./xx.py: line 1: import: command... (more) |
— | 12 months ago |
Comment | Post #291322 |
This question is intended as a canonical that gathers the important, overlapping ideas from several Stack Overflow questions. The goal is to create a clear overview of Python's model for starting the execution of code.
The question is notably **not** about:
* `import`ing code (except to the ext... (more) |
— | 12 months ago |
Edit | Post #291322 | Initial revision | — | 12 months ago |
Question | — |
How and where does Python code start running? How can I control that? Suppose I have some code in a file `myscript.py` like: ``` def myfunction(): print("Test") ``` What steps do I need to take in order to make `myfunction` run? That is to say: how do I get Python to run `myscript.py`; and from there, how do I choose `myfunction` as the starting point for ... (more) |
— | 12 months ago |
Comment | Post #291286 |
What I meant was that I assume that systemd already has kernel level access and therefore doesn't have to do anything special in order to escalate other processes. But thinking about it further, that doesn't sound right - far too easily exploitable. (more) |
— | 12 months ago |
Edit | Post #291286 |
Post edited: misc typos |
— | about 1 year ago |
Edit | Post #291286 | Initial revision | — | about 1 year ago |
Answer | — |
A: Privilege escalation from Python like from systemd Generallly (assuming no exploit is found) it's not possible to escalate the privileges of an already running process, except via code that itself has kernel level access (running in ring 0 - this is presumably how `systemd` is able to do it). But from your own Python program running in user-land (as ... (more) |
— | about 1 year ago |
Comment | Post #291265 |
There seem to be many separate questions here. Please start by trying to make functions to implement the *individual* rules that you have in mind, and testing them. Then, the requirements for those rules need to be clearer for anyone to be able to help with them. For example, how should we know which... (more) |
— | about 1 year ago |
Comment | Post #291089 |
My take is that it failed partly because they lost interest, but mostly because the staff are so far out of touch with the community that they didn't properly understand what they were proposing to implement nor why it would be helpful. So, *the staff conception* of the idea was fundamentally flawed,... (more) |
— | about 1 year ago |