Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

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 #291768 Post edited:
hide examples because they aren't strictly necessary to describe the problem; add some colour
6 months ago
Edit Post #291769 Post edited:
6 months ago
Edit Post #291769 Initial revision 6 months ago
Answer A: Why can't I use a library I just installed with Pip?
Problems like this occur, fundamentally, because there is more than one Python installation on the system, and the system is configured in a way that `pip` installs for a different Python than the one that `python` runs. This problem can be addressed by either: using a virtual environment ru...
(more)
6 months ago
Edit Post #291768 Initial revision 6 months ago
Question Why can't I use a library I just installed with Pip?
I tried installing `package-installation-test`[^1] using Pip, and it appeared to be successful. But I can't use it as advertised, either by itself or by importing it from my code: Failed attempts ```bash $ pip install package-installation-test Collecting package-installation-test Using c...
(more)
6 months ago
Edit Post #291757 Initial revision 6 months ago
Question Is my question a duplicate? What now?
As part of a general effort to produce basic Q&As for Python, recently I've been focused on issues related to starting up an interpreter and running the code - so, questions about setting up an environment with third-party libraries, figuring out an entry point for the code, and so forth. In parti...
(more)
6 months ago
Comment Post #291752 Oh, I was so busy making inter-related Q&As in my own style that I forgot about that one. I feel like this one should be considered a duplicate....
(more)
6 months ago
Edit Post #291756 Post edited:
6 months ago
Edit Post #291756 Post edited:
6 months ago
Edit Post #291756 Post edited:
6 months ago
Edit Post #291756 Initial revision 6 months ago
Answer A: Reinstall old Python libraries after update
> Every time I run a program I'm used to, I get a bunch of import errors, and have to reinstall the dependencies. As you're presumably aware, the fundamental problem is that each Python installation is treated as its own separate environment, with its own suite of third-party libraries. Since ther...
(more)
6 months ago
Comment Post #291323 I guess you're aware, but I've split away content from this answer according to my plan now. If the downvote was yours, please feel free to re-evaluate.
(more)
6 months ago
Edit Post #291755 Initial revision 6 months ago
Answer A: How can I access and use command-line arguments in Python?
At startup, Python loads the `sys` standard library module (without waiting for any code to `import` it) and sets up several useful values. Among these is sys.argv, which stores command-line arguments for the script. This is a plain list of strings, one per token on the command line (as in other prog...
(more)
6 months ago
Comment Post #291753 Thanks for the heads-up. I may come back and edit in some references to that. I do plan on having a separate Q&A later to cover the use of `__main__.py` as a module filename.
(more)
6 months ago
Edit Post #291753 Post edited:
add link now that related question exists
6 months ago
Edit Post #291754 Initial revision 6 months ago
Question How can I access and use command-line arguments in Python?
In many other programming languages, the execution of code starts in a specifically named function (such as `main`) which is expected to have a specific signature, which allows that function to receive arguments from the command line. For example, we may write `int main(int argc, char argv)` in C ...
(more)
6 months ago
Edit Post #291753 Initial revision 6 months ago
Answer A: Understanding the `if __name__ == '__main__':` idiom
Whenever Python loads code from a `.py` file, that code gets its own namespace for global variables - so they're not truly global, but per-file values. (When you look at an `import`ed module "from outside", those global variables are the attributes of the `module` object. Thus, when `module.py` has `...
(more)
6 months ago
Edit Post #291323 Post edited:
move content about `if __name__ == '__main__':` to a new Q&A
6 months ago
Edit Post #291752 Initial revision 6 months ago
Question Understanding the `if __name__ == '__main__':` idiom
I've seen many examples of Python scripts that include a line that says: ```python if name == 'main': ``` Sometimes the following block contains a bunch of code, but other times it just makes a single function call (like `main()`), or some variant along the lines of ```python import sys ...
(more)
6 months ago
Edit Post #291748 Initial revision 6 months ago
Answer A: Regex to get text outside brackets
First, we need to define some semantics. While it may not matter for your actual inputs, I propose that it should be valid for the output elements - the parts of the text found outside of brackets - to be empty strings. For example, if two bracketed parts are adjacent, like `onetwofour`, then a resul...
(more)
6 months ago
Edit Post #291676 Post edited:
Shorten slightly by referring to newly created Q&A. (There is probably more redundancy that can be eliminated here.)
6 months ago
Edit Post #291743 Initial revision 6 months ago
Answer A: Understanding Virtual Environments for Python
Why The most important ideas behind virtual environments are: 1. Since there is a separate `site-packages`, you can isolate the dependencies of your project. This is especially important for testing and development, since you can more easily verify what your project's dependencies actually are....
(more)
6 months ago
Edit Post #291616 Post edited:
add tag
6 months ago
Edit Post #291740 Initial revision 6 months ago
Question Understanding Virtual Environments for Python
Several times now, I've seen advice in tutorials, setup/install instructions for Python-based projects, etc. to use a virtual environment to keep things organized and make it simpler to manage the code. It sounds like this means having yet another installation of Python on my computer. Does it rea...
(more)
6 months ago
Comment Post #291738 Of course it's entirely possible to set up an installer that installs both Python itself and your own Python code. There are even [tools to help with that](https://pynsist.readthedocs.io/en/latest/). But I wanted to focus this Q&A on approaches that involve a seamless user experience, where users don...
(more)
6 months ago
Edit Post #291739 Post edited:
6 months ago
Edit Post #291739 Post edited:
6 months ago
Edit Post #291739 Initial revision 6 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)
6 months ago
Edit Post #291738 Initial revision 6 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)
6 months ago
Edit Post #291737 Initial revision 6 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)
6 months ago
Edit Post #291736 Initial revision 6 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)
6 months ago
Edit Post #291323 Post edited:
rm content that will be moved to a separate Q&A
6 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)
6 months ago
Edit Post #291676 Initial revision 6 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)
6 months ago
Edit Post #291675 Initial revision 6 months ago