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.

Filter by
Sorted by
Tagged with
1
vote
2answers
130 views

Choosing between DI (without container) and Composition

I'm working on a classes that are designed to read a defined file format; said format is comprised of 2 separate files (FileA and FileB). For ease of use, the format is referred to as the FileA format,...
2
votes
0answers
34 views

Update class member gradually [duplicate]

Consider the following: import typing class MyClass(object): def __init__(self): self.my_member: typing.Optional[dict] = None def update_member(self): self.my_member = {} ...
-1
votes
1answer
53 views

Efficiently keep different data structures synchronised - tree, list of objects

Problem description I have a pet project to translate TEI XML to standoff JSON and back: https://github.com/standoff-nlp/standoffconverter and I am currently thinking about a rewrite/restructuring. ...
2
votes
2answers
102 views

How can I efficiently make changes to a large module without having to re-run every time?

When making changes to larger modules in Python, this is my current (inefficient) process: Make needed change to code Run program to test (using pdb - python3 -m pdb path/to/script.py Program will ...
3
votes
4answers
210 views

When to have ID of instance as an instance field vs. decoupled?

Let's say I have a class called ValueSpec with these immutable instance fields: min_value: int max_value: int description: string Each instance of ValueSpec is uniquely named. This unique name is ...
1
vote
4answers
475 views

Loose coupling in Python

While I know this is the tight coupling example: class User: def __init__(self): pass def get_status(self): api_client = APIClient() status = api_client....
6
votes
6answers
501 views

How to modify object properties?

I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this public static string GetTimeOfDay() { DateTime time = ...
3
votes
2answers
223 views

What is the rationale for making certain methods for data types static?

In C#, for instance, there are static methods for telling if a string is null or empty, finding an element in an array, clearing an array, etc. However there's an instance method for replacing ...
-4
votes
1answer
97 views

Better way to process huge files

I have a huge csv file and I have to process that file and do some data manipulation. Right now I'm reading/loading the file in buffer and then doing the data processing work. I find this approach ...
0
votes
1answer
94 views

What are the benefits of not checking function arguments in python?

I'm trying to understand what are the benefits of the fact that python defaults to not checking function arguments. For example: from some_module import my_function my_function(some_argument) # ...
1
vote
2answers
90 views

Trying to figure out the optimal selection based on a set of rules

Background: We have software that displays different products to the user Problem: With a given set of rules, determine which is the primary product we should show the user. These are images. We are ...
0
votes
0answers
154 views

Python circular dependency

I have two classes AST and ASTNode for working with some tree-like data. Both these classes have networkx graph as a field and a node id (integer). For AST this id refers to the root of a tree. These ...
1
vote
2answers
87 views

add function to input of builtin python logger

For simplicity, assume my application logs only dictionaries. I want to add a step to Python logging for my application to prevent logging any dictionary with the key password, i.e., def clean_log(...
2
votes
1answer
113 views

Converter implementation in Python: class versus module?

I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more. Stubs look something like this, with ir ...
15
votes
1answer
4k views

Is it possible/advisable to combine unit testing and integration testing?

I've built a Python script that consists of about 20 functions that extract data from MySQL via .sql files (I'm currently trying to learn SQLAlchemy ORM), do something to it and then put it back in ...
1
vote
1answer
97 views

When modules written in different languages interact, is exchanged data always serialized?

I have module written in Python and I would like to write function in e.g. Go but problem is that data needed for computations is often more than 100MB. My question is: is data always serialized and ...
-4
votes
1answer
117 views

What things should you consider when porting software from python to c++?

Suppose you have written a prototype for an application in python, now you want to rewrite it in c++ for speed reasons and to make a real software out of it. What are things to consider before ...
-2
votes
1answer
64 views

How the basic structure of a simple messaging app works?

How the messaging apps works? What is the Basic algorithm of it? I tried the following method to make a messaging app. I enters message Message converts to a text file Text text file uploads to the ...
-3
votes
2answers
456 views

Should I use Flask w/ Javascript OR a Javascript UI that calls a Flask / Connexion API?

I recently wrote a data management tool in Python & SQLAlchemy. Now, I need to put a web UI on it. While I want to start small, there is some need for interactivity, like drag and drop in tables, ...
0
votes
1answer
93 views

Is dynamically hiding specific parts of the input data passed to a function pythonic?

I have a design question regarding "dynamic information hiding" vs static typing. I have for the following python code class RuleInput: attr1 = ... atrr2 = ... ... def ...
2
votes
1answer
103 views

Strictly only importing modules in subdirectories: is this a good rule?

I'm making my 1st official project. It's written in Python, is open-sources, and I'd like people to be able to freely and easily fork and modify the code. The project name is "shelf" and the ...
-3
votes
1answer
81 views

Sharing data among websites

I manage one middle sized website that uses Flask and PostgresSQL on the backend and some JS with Angular and Jinja2 templates on the fronted. Now we're going to create a second website that will be ...
1
vote
5answers
234 views

When to extract boolean conditions into their own function?

I commonly use a boolean condition/variable when it's something too big or complicated and takes too much space by itself inside ifs - basically to avoid repeatability and thus improve readability. E....
0
votes
2answers
73 views

User-friendly parameter parsing from yaml

Problem I have designed an evaluation tool (in python) and need some help to make it more user friendly. The tool requires ~100 (nested) parameters, which it gets from a yaml file and stores ...
-4
votes
1answer
53 views

Keeping JSON in database

I'm trying to create web app(flask or django-rest) that would scrape some data and save it to JSON so that it can be viewed in the frontend (VueJS). I'm wondering if it is better to save the scraped ...
-4
votes
1answer
40 views

Dynamically assign attributes to objects from outside

In python the following code works perfectly fine. class Table: pass table = Table() table.fruits = ["apple", "orange"] But as soon as we check it out with some kind of ...
-4
votes
1answer
66 views

Should I use interfaces in Python (so my code will be more testable and following good practices)?

I've never coded in Python. In languages like C# or Java a lot of people write interfaces for (almost) every class so the code can be more easily testable (by implementing IoC) or other reasons and is ...
-1
votes
1answer
49 views

Preventing name collision between user-defined modules within a framework

I'm a contributor to a framework that's designed for producing synthetic data. The system allows the end-user to create custom data generators and load them into the framework. Currently we store the ...
-5
votes
1answer
232 views

Is it possible to derive a test suite to achieve 100% path coverage? [closed]

Here is an example with the function: Examining this I believe that it is possible to achieve 100% path coverage. My understanding of path coverage is that you need to design test cases such that ...
7
votes
3answers
207 views

Is a subclass Liskov Substitutable if it disallows the same invocation of the constructor in the child as in the parent?

Say, I have two classes: class FTPClient: def __init__(self, host, port): self._client = FTPDriver(host, port) ... class FTPSClient(FTPClient): def __init__(self, host, port, ...
1
vote
0answers
220 views

Approach to setup multi-tenant RabbitMQ workers in Python

I'm migrating my current application to multi-tenant setup. Now I've multiple rabbitmq workers to process async job, publish and consume integration events, and other stuffs. I'm planning to use ...
6
votes
5answers
542 views

Is it a good idea to start a function with a bunch of assert statements?

Sometimes when I look at other people's code I see functions that make a bunch of assumptions about the inputs but do not explicitly assert their assumptions. For example, look at the code below: def ...
-1
votes
2answers
143 views

When should I use a database instead of a list? [duplicate]

New to Python and all things database related. Wondering when I should consider using a database and why? I have what is essentially a list of objects that is around 30000 lines long. I'm developing a ...
0
votes
1answer
1k views

What is the space complexity of a Python dictionary?

If python dictionaries are essentially hash tables and the length of hashes used in the python dictionary implementation is 32 bits, that would mean that regardless of the number of key-value pairs ...
-1
votes
1answer
45 views

Resolving Dependencies and Incompatibilities Deterministically

Problem Description I'm working in Python and I've been having a problem designing something to handle the following (abstracted) system: I have some objects (lets call them Nodes) that can be in ...
0
votes
1answer
121 views

Mixing IoC container use with “poor mans” DI

I'm finding the use of IoC containers to be quite the shift in my application design, and its for the better. I'm using a framework called injector that aims to mimic (albeit not entirely) the Guice ...
1
vote
2answers
87 views

Best way to enforce variable has certain values using enum in Python

I have a string variable named status in my code that can take on three values "Starting", "In-progress", and "Complete". A friend of mine said it was good practice to enforce that status has one of ...
-4
votes
1answer
59 views

Question about the tutorial purgatory in coding path

Dear all the programmers and overflow friend, First, I want to say thank you to stack overflow users for helping me finish 20% of my PhD project since last year (using python to draw some technical ...
4
votes
3answers
186 views

Approach for updating status of a function

When I call a function, I want to receive updates when the function reaches some milestones: def do_something(): start_with_something() # update for x in iterate_something(): # ...
1
vote
0answers
34 views

Optimal package structure - Command Line Interface

I have an ongoing project where the directory structure currently is a mess (github Directory) and I would like to strucure it to eventully create a python package out of it. Below I have outlined a ...
-3
votes
1answer
55 views

What is the rule for making functions private in Python modules?

I was wondering what's the principle behind it, and whether I should treat all functions from module that are not used anywhere else at the time as private, and mark them with underscore prefix so ...
0
votes
1answer
43 views

What's a proper way to call a chain of methods that modify an instance attribute?

I've got an Algorithm class whose responsibility is to find if a given word is in a list of words. As part of doing that, the algorithm first has to lowercase the words, remove punctuation, and ...
4
votes
2answers
726 views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
-1
votes
2answers
75 views

Is it possible to have a function executed when a specific exception is raised anywhere in the program?

I want to add some custom retry logic to the AWS sdk (but this isn't specifically about that). So whenever it throws a specific network exception it waits and tries again and whenever it throws a ...
-2
votes
1answer
58 views

Designating a pin header and a GPIO

I have an Acconeer XB112 breakout board and an XM112 radar module. It all works just fine per the Acconeer documentation and tutorials. Now I want to modify some of the code to output to a GPIO. ...
1
vote
1answer
43 views

Scraper in separate repo from visualization component?

Let me explain my thoughts about architecture of the project I'm working on. The project code repository consist of: Scrapy component - of course it serves to scrape data, process it and calculate ...
-1
votes
2answers
90 views

How to Maintain Rarely Used Scripts

I come across the need to do a lot of one time scripts (related to API evaluations, data extraction, experiments etc.) that have the potential only to be used very rarely in the future. These could be ...
-2
votes
1answer
71 views

Depending on fairly big modules to do just a simple operation

So I have a website which does a bunch of different stuff, more importantly, it allows the user to upload videos. Now unfortunately videos are a bit annoying as they need a poster img to display ...
2
votes
1answer
111 views

Python: Return or update object

Firstly I am new to Software Engineering and my last question was closed. I am doing my best to ask relevant questions and improve. If you are going to down vote my question I'd really appreciate if ...
-4
votes
1answer
71 views

Is it better (from a maintenance perspective) to dynamically construct complex SQL queries using Jinja or String concatenation? [closed]

Two possibilities. Which is better, with respect to readability, maintenance and clean code: SQL injection can be disregarded. Constructing complex parameterized sql queries using python string ...

1 2
3
4 5
36