Questions tagged [python]
Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.
2,030 questions
0votes
0answers
31views
API design for precomputation cache [closed]
In my numeric code library I have a function totient_sum that depends on an expensive one-time precomputation totsum_range = [...], then different calls to totient_sum(n) are quick. There are several ...
4votes
2answers
428views
Control flow and communication with two separate frontends (maybe with exceptions)?
I am trying to write a backend for use with a completely text based UI for one shot operations (eg. python scriptname arg, executes that argument and exits) and a GUI using the curses library for some ...
3votes
1answer
192views
How to manage working directory in interactive development environments like Jupyter Notebook?
I'm having trouble with managing the working directory in Jupyter Notebook. For example, I have a .py script that requires me to change the working directory to its directory to run it properly. I've ...
0votes
2answers
193views
How to implement a server application that can reload configuration without restart
I have a game server implemented in Python to which clients can connect and play against each other. I'd like to be able to reload configuration from a config file without restarting the server (as ...
5votes
0answers
245views
In a python project, when should you use __init__.py, __main__.py, and just normal .py?
Say I am making a pdf editor app with the following structure: ├── main.py ├── 📂 drawing_functions/ ├── 📂 util/ ├── 📂 GUI/ └── 📂 document_handling/ Each of these folders have a collection of ...
5votes
5answers
503views
How to test for performance regression?
I am working on a refactor on a certain package (I can give details if asked). The package involves a clever lazy evaluation of a sort of nested sequence of arithmetic operations. If the numerical ...
0votes
1answer
182views
Best practice when declaring imports with different execution contexts in python?
Say I have a Python project that looks like this: project/ ├── package/ │ ├── __init__.py │ ├── module1.py └── main.py I would like package/ to be self-contained, though it is called from main.py....
5votes
2answers
660views
Why did Python designers decide not to declare vars? [closed]
In Python when you want a local variable, you just assign to it x = 10. In most modern languages you declare local vars (regardless of type): JavaScript: let/const/var Swift: let/var Kotlin: val/var ...
1vote
2answers
382views
Should an API client class be reusable?
For an API client I am working on, I was wondering, whether the main class should be reusable. This question basically boils down to: should the HTTP client be instantiated in __init__ or __enter__/...
0votes
0answers
45views
Simple packaging for multi-file/module Python deployments
I'm working on a Python codebase which we are trying to improve the modularity of. Both the top level scripts and the modules that they depend on are all in one main repo. We have another repo which ...
-3votes
2answers
3kviews
Is it better practice to set default values for optional argparse arguments?
I mention python's argparse as an example but this would apply to any CLI argument parser library for any language. Just generally speaking, at a high level, if there are a lot of optional arguments ...
0votes
1answer
257views
Separation of concerns between business layer, data layer and presentation layer without losing information
I'm developing an api in Fast API using sqlalchemy to manage my ORM classes and operations with the database. I'm dealing with some design decisions to have my classes as little coupled as possible ...
0votes
2answers
601views
Explain why it's bad to use a middleware to coat error messages as exceptions
We manage a backend application behind a FastAPI REST controller with multiple endpoints. A member of our team decided to use a middleware on the application which parses the body of the response for ...
2votes
1answer
131views
A Design Pattern for a component which both writes to and reads from an ordered event log
I am searching for a good design for a set of components I am writing for a system. I believe it is very likely there is a Design Pattern, or set of Design Patterns, which could be combined to solve ...
15votes
4answers
4kviews
What side-effects, if any, are okay when importing a python module?
Generally, modules should not have side effects. However, in a lot of cases, the side-effects are hard to avoid or may be desirable. There are also popular packages with on-import side-effects. Which ...