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.

Posts by Karl Knechtel‭

45 posts
66%
+2 −0
Q&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 anythin...

posted 26d ago by Karl Knechtel‭  ·  edited 26d ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A 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 sho...

1 answer  ·  posted 26d ago by Karl Knechtel‭  ·  last activity 26d ago by Karl Knechtel‭

70%
+5 −1
Q&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 sta...

posted 30d ago by Karl Knechtel‭

Answer
77%
+5 −0
Q&A 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 my_function(): print("Test") What steps do I need to take in order to make my_function run? That is to say: how do I get Python to ...

2 answers  ·  posted 30d ago by Karl Knechtel‭  ·  last activity 10d ago by Monica Cellio‭

66%
+2 −0
Q&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 i...

posted 1mo ago by Karl Knechtel‭  ·  edited 1mo ago by Karl Knechtel‭

Answer
71%
+3 −0
Q&A How can I manage multiple consecutive strings in a buffer (and add more later)?

The fundamental problem here is that it is already ambiguous where the "end" of the data in the buffer is. Strings can be empty (have zero length as reported by strlen); as such, buffer could equal...

posted 2mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A How can I manage multiple consecutive strings in a buffer (and add more later)?

This question is inspired by If I have a char array containing strings with a null byte (\0) terminating each string, how would I add another string onto the end? on Stack Overflow. Suppose I have...

2 answers  ·  posted 2mo ago by Karl Knechtel‭  ·  last activity 20d ago by Lundin‭

Question c string
75%
+4 −0
Meta Don't close questions for lack of detail/confusion

No. Terms like "too generic", "unclear", "too broad", "off topic" are absolutely not euphemisms for "stupid question, go away". They mean what they say; and when they are used Somewhere Else, mult...

posted 2mo ago by Karl Knechtel‭

Answer
71%
+3 −0
Q&A Open file in script's own folder

Theory Relative paths are relative to the current working directory of the Python process. This can be checked from within Python using the os.getcwd function and set using the os.chdir function. ...

posted 4mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Q&A How can I provide additional information when raising an exception?

The raise statement in Python accepts either an Exception class or an instance of that class. When used with a class, Python will create and raise an instance by passing no arguments to the constru...

posted 4mo ago by Karl Knechtel‭

Answer
66%
+2 −0
Code Reviews Detecting balanced parentheses in Python

Command-line timing Rather than using separate code for timing, I tried running the timeit module as a command-line tool. I wrote initial versions of the implementations based on the OP and hkotsu...

posted 4mo ago by Karl Knechtel‭

Answer
60%
+1 −0
Code Reviews JSON log formatter

PEP 8 Four-space indentation is the community standard. There are many strategies for wrapping long lines; I have found that it's often best to just use temporary variables to avoid wrapping lines...

posted 4mo ago by Karl Knechtel‭

Answer
71%
+3 −0
Q&A How to troubleshoot ModuleNotFoundError?

Root cause ModuleNotFoundError is a kind of ImportError. It occurs when Python code tries to use an absolute import, but can't find the named module - just as the name suggests. (Failed relative i...

posted 4mo ago by Karl Knechtel‭  ·  edited 4mo ago by Karl Knechtel‭

Answer
75%
+4 −0
Q&A What does "namespace" mean?

A well-known easter egg in Python displays some ideas about writing good Python code, credited to Tim Peters (one of the core developers). This question is about the last: Namespaces are one hon...

2 answers  ·  posted 6mo ago by Karl Knechtel‭  ·  last activity 6mo ago by Olin Lathrop‭

77%
+5 −0
Q&A Does Python have a "ternary operator" (conditional evaluation operator like "?:" in other languages)?

How to do it Yes, Python has an equivalent operator. However, it's spelled with keywords rather than punctuation, and it uses a different order of operands. It looks like: condition_value if some...

posted 6mo ago by Karl Knechtel‭

Answer
66%
+4 −1
Q&A Does Python have a "ternary operator" (conditional evaluation operator like "?:" in other languages)?

Sometimes code needs to assign (or otherwise use) a value that depends on some condition. The naive approach is to use explicit branching, which in Python would look like: if some_condition(): ...

2 answers  ·  posted 6mo ago by Karl Knechtel‭  ·  last activity 6mo ago by matthewsnyder‭

Question python syntax
83%
+8 −0
Q&A Git-ignoring files with special characters in their names, especially newlines

My actual motivation is to understand the semantics of the .gitignore file syntax in precise detail, for a program which is expected to emulate them as accurately as possible. However, while coming...

1 answer  ·  posted 6mo ago by Karl Knechtel‭  ·  last activity 6mo ago by Peter Taylor‭

Question git linux gitignore
83%
+8 −0
Q&A Why are list comprehensions written differently if you use `else`?

These two uses of if are different The if at the end of a list comprehension syntax: [num for num in hand if num != 11] is a filter; its purpose is to decide whether or not the resulting list ...

posted 7mo ago by Karl Knechtel‭  ·  edited 6mo ago by Karl Knechtel‭

Answer
71%
+3 −0
Q&A Understanding mutable default arguments in Python

Possible justifications It may make sense to use a mutable default argument in the following situations: For simplicity Consider for example an argument that should be some kind of mapping, wher...

posted 8mo ago by Karl Knechtel‭

Answer
75%
+4 −0
Q&A Understanding mutable default arguments in Python

Workarounds Avoiding mutation Because problems are only caused by actually mutating the default argument, the simplest way to avoid problems is to... not do that. Pythonic code obeys command-quer...

posted 8mo ago by Karl Knechtel‭  ·  edited 6mo ago by Karl Knechtel‭

Answer
80%
+6 −0
Q&A Understanding mutable default arguments in Python

Terminology "Mutable default argument" means exactly what the individual words would suggest: it's an argument which is supplied as the default value for that parameter, which also is mutable. To ...

posted 8mo ago by Karl Knechtel‭  ·  edited 8mo ago by Karl Knechtel‭

Answer
84%
+9 −0
Q&A Understanding mutable default arguments in Python

Consider this code example: def example(param=[]): param.append('value') print(param) When example is repeatedly called with an existing list, it repeatedly appends to the list, as ...

4 answers  ·  posted 8mo ago by Karl Knechtel‭  ·  last activity 6mo ago by matthewsnyder‭

71%
+3 −0
Meta Handling common wrong approaches and misguided motivations for basic technique questions

Background This is inspired to some extent by https://software.codidact.com/posts/289597 . I'm trying to provide a large amount of content (gradually!) that novices (mainly to Python) will find u...

1 answer  ·  posted 8mo ago by Karl Knechtel‭  ·  last activity 8mo ago by Lundin‭

71%
+3 −0
Meta Are questions about (abstract) algorithms and datastructures considered on-topic?

As the author, this is my defense. Design and modeling are on-topic The site topicality documentation explicitly includes "Software design, architecture, or modeling" as on topic. There doesn't s...

posted 8mo ago by Karl Knechtel‭

Answer
60%
+1 −0
Q&A Optimized representation for sets?

First store the universe of potential elements as a sequence, then encode each set as an unsigned integer interpreted as follows: if the 1s bit in binary is set (1), the set contains the 0th elemen...

posted 8mo ago by Karl Knechtel‭

Answer