Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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. ...

-5
votes
0answers
43 views

“# empty” comment in blank __init__.py [on hold]

This may be part of a coding style. What are the benefits to having __init__.py like this # empty as opposed to blank __init__.py?
1
vote
0answers
40 views

CLI tool with overloadded structure

I have a python CLI tool that my department uses to process some excel file aided by a yaml. I tried to diagram a basic work flow here: Step 1: User downloads a xlsx, puts it in a file, runs tool --...
-1
votes
1answer
76 views

Would I need a web framework if the app is running locally and not in the net?

I need to make an Employee Payroll application and the client specifically stated that the application will run on their computer locally and will not be hosted anywhere in the internet. I can code ...
0
votes
1answer
119 views

Is Java-like restrictiveness OK Python style?

Good Pythonic style is much looser than Java's uptight restrictiveness: In Java, good style means private on methods wherever possible, all fields encapsulated, type declarations, defined ...
0
votes
1answer
60 views

Making execution of Python script fool-proof beyond adding shebang

Assume that a Python package (available via PyPI) is too difficult for novice users to utilize. Specifically, typing python2 path_to_package/start_GUI.py in the command line, which opens a TKinter GUI,...
2
votes
0answers
42 views

Data processing pipeline design for processing data

I have a use case for which I need to build a data processing pipeline Customer contact leads data coming from different data sources like csv, data base, api has to be first mapped to a universal ...
1
vote
1answer
110 views

What are the potential dangers of using this kind of reflection cheat in Python?

In a program I'm working on, I need to do a substantial amount of real-time reflection in order to maintain a list of known "attributes" throughout the program structure (for use by a sort of "virtual ...
-2
votes
0answers
45 views

What algorithm should I use to create an automatic sport calendar feature? [closed]

I have in mind to create (I would like to do it with python) an algorithm that automatically creates palimpsest for a sport basketball (sould works for every sport anyway) tournament. I would like to ...
-2
votes
1answer
73 views

Can i be two places at once in python cycle

I'm doing this in python, in case that changes anything. I'm trying to make a lamp/bit go 1-0-1-0 until the user says "okay" the "okay" should indicate that the user has found the lamp/Bit IRL. Now ...
-2
votes
0answers
41 views

Passing member variable as argument into member function vs. some other alternative [C++ & Python] [duplicate]

In a Python class, say it's called some_class that I have written, it contains a member function some_function(self,u) that takes in some argument u. This class also contains a member variable u. I ...
0
votes
1answer
54 views

Python deployment to corporate shared filesystem

We are developing some Python applications (mostly CLI) for use only internally in the company. Hundreds of machines on which the applications may run. Instead of installing the apps on each machine, ...
-1
votes
1answer
31 views

How do I test my python package (for distributing) for different versions of python?

I have made a small library/application that I intend to distribute. However I want to find out what versions of python can handle my script ? Given that there are many minor and micro versions and ...
1
vote
2answers
108 views

Dependency injection in a loop?

Suppose I have a loop (in Python syntax): xml = "<x>...</x>" for i in arr: j = f(x) # some complex computation obj = Class(i, j) xml = obj.run(xml) Does it make sense to use ...
2
votes
0answers
64 views

Python3: How to change the design of a class hierarchy to improve access to objects there buried?

I asked this question already at stackoverflow together with a serialization related part and at codereview for the design part only. Since the design related part receives no answers or comments on ...
0
votes
0answers
15 views

How are regular expressions used in Python-Django confurls? [migrated]

In django, you are supposed to point the root URLconf at the URLconf of your app. You do this by using the 'url' function/module from Django which uses a regular expression as its first argument. In ...
1
vote
2answers
151 views

DRY or not to DRY in SDK

I'm making contribution to an opensource project by one of the leading hypervisor providers and I have noticed that there is awfully lot of repetition. Below is what I mean by it, imagine that they ...
-2
votes
1answer
143 views

Possible motivation of having a minimal main function as in CPython source code?

I was recently looking through the CPython source code and noticed something rather intriguing: /* Minimal main program -- everything is loaded from the library */ #include "Python.h" #include "...
0
votes
1answer
90 views

Should I access the backend directly or through an API layer?

Please allow me to ask my question using an example where we have a database with flight data and I want to make a web app where users can search, select, and book a flight. I wrote some classes ...
2
votes
1answer
23 views

An approach to send the contents of a file on the server to the client in real-time

I have a relatively simple front in good ol' JQuery, that makes a POST Request to a Flask Python web server, that runs a Python script using the subprocess module. Here's the whole route for ...
-1
votes
1answer
74 views

How to ensure separation and inward dependencies between architectural layers in Python?

Suppose a large-scale project is being developed in Python 3.7. Some layered architecture is chosen: "clean architecture", "onion" or "hexagonal". The Dependency rule in it only allows inward-...
5
votes
2answers
293 views

How to maintain a low dependency version of a project?

I am not as technically skilled as most people asking here. I use git to backup my own work to an online repository, but I rarely use it in collaboration, and don't know much more than the basic ...
1
vote
1answer
60 views

Create and implement new encoding

I'm working on a project with huge files that contain only the set {[0-9],.}. Encoding in UTF-8 or ASCII make huge files. I wonder if I could find a way to encode in only 4 bits (make those file 16 ...
0
votes
0answers
72 views

Does the fact that random.sample(seq, 1)[0] === random.choice(seq) mean that both functions should have the same precondition on seq?

I've read https://bugs.python.org/issue33098, which is about the following behavior of Python 3 a = {'1': 42, '2': 84} # keys are str on purpose, c.f. the issue import random random.choice(a.keys())...
-2
votes
1answer
120 views

Calculating longest trip [closed]

I have been stuck on this question for some time. Could you guys direct me or point me to the right direction for solving this problem ? We would like to encourage passengers to experience the joy of ...
2
votes
1answer
155 views

Convince people not to use an “end-of-life” Python 3.X version

Context At my company, we have a major Python package which is written in Python 2. We are now planning to migrate it to Python 3 (we don't care about keeping it Python 2 compatible). I am a junior ...
-2
votes
1answer
66 views

Delegation pattern in Python: is it unpopular? Is it considered not Pythonic?

As a Ruby/Rails person, I often deal with method delegation. It's often convenient to delegate a method to a composed object or a constant. Ruby even has a def_delegator helper method to easily build ...
0
votes
1answer
58 views

How to properly decouple the service layer from the user interface layer, if the service layer needs to interact with the user?

In my program, I have a long-running function from which I would like to interact with the user for various reasons: Giving status updates ("Downloading file /foo/bar.png") Displaying warnings ("File ...
0
votes
1answer
98 views

Parameters vs Specialized functions

Trying to figure out which structure is cleaner between using a specialized function or using parameters to accomplish the same thing (see code example below). Essentially, I can reduce the number of ...
0
votes
0answers
52 views

Request for a service that takes a long time to execute

I'd like to train neural networks by making HTTP requests, which in turn train the model. Now, this might take a while with fetching data, processing, training and evaluating the network. I was ...
1
vote
3answers
90 views

Python - Proper way to call a function within a class based on a certain argument passed on

Let me illustrate with an example. Say I want to create a class Returns that generates the returns of a stock for example. Returns can be arithmetic or logarithmic, and I want to be able to choose at ...
-1
votes
2answers
70 views

How should docstrings be used in modules with one class?

When authoring OOP code, sometimes you have a file that only contains one class, and nothing else. PEP8 says that all modules and all classes should have docstrings outlining what they do. But in ...
0
votes
1answer
92 views

MongoDB mapreduce

I'm new to programming and mongoDB and learning as I go, I'm attempting a mapreduce on a dataset using mongoDB. So far I've converted the csv to json and imported it into a mongoDB using compass. In ...
1
vote
2answers
113 views

Why should imports be made at the beginning

Why is it considered good style to do all imports in a python application at the beginning, even if what is imported is used only once? I have been programming only shorter pieces of software for a ...
6
votes
5answers
757 views

Why is unit testing private methods considered as bad practice?

Context: I am currently working on a small project in Python. I commonly structure my classes with some public methods that are documented but mainly deal with the high level concepts (what a user of ...
0
votes
1answer
145 views

Why isn't there a static initializer in Python?

The equivalent of static { // Code here } does not exist in Python by default. The closest thing, while being "Pythonic", seems to be to create a decorator and do the initialization there such ...
-2
votes
1answer
65 views

Python API Design for workload automation software

I want to expose APIs in python for my workload automation software. I have a Job class as defined/outlined below. Instance of this job class represents a particular Job run. Job can have multiple ...
1
vote
1answer
117 views

Logging an application in Python

Recently I have worked in a small standalone Python console application and have inherited some code from another team. Although some of us have written small Python scripts in the past, none of us ...
-1
votes
1answer
50 views

Calculating time an object stays in a state

I use Python sqlalchemy to store my model in a MySql database. One of my objects has a 'state' field (for simplicity let's assume there are two states: AVAILABLE and UNAVAILABLE). There are ...
29
votes
1answer
3k views

When developing a system by myself, should I use microservices?

I'm beginning a new project at work, and will likely be nearly the sole developer on the project, though one or two other developers will need to integrate existing applications or simple scripts into ...
1
vote
2answers
116 views

When using an ORM when should I sacrifice performance for convenience?

I work with SQL Alchemy a lot and, as a "lazy programmer", I enjoy the convenience it offers. But the "diligent programmer" in me often worries about optimisation and the performance of the queries ...
-1
votes
1answer
64 views

Passing messages through a chain of containers in python

When I write python code for simulations, I often end up with the following situation: I have a class describing the general environment which contains a list of instances of a class that describes ...
2
votes
0answers
60 views

Separate business logic from ORM models in SQLAlchemy

I have a Flask application with tens of complex models, almost all of them related to each other. A simple pseudo-schema of some of them: +----------------+ | FoodGroup | +-------+--------+ ...
0
votes
0answers
66 views

Is subclassing the way to go if I just want to add one method?

My question is Python-specific. Let's say I am working with an object from a Python third-party library. The object takes some arguments and generates HTML content. The object also has a save method ...
-2
votes
1answer
43 views

Practices for setuptools-less usage in python

The general and pretty much standard way of packaging a python distribution is to use setup.py, however I've seen an approach where the code is not installed, it's just invoked as a script, and any ...
-1
votes
1answer
47 views

How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your application?

Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I've seen feature an ...
3
votes
3answers
252 views

Chess: Efficiently deciding whether a check mate has been made

This question addresses building a Chess engine. I've done just that, and in my humble opinion quite elegantly. But I'm missing my ending conditions. Here are some pseudopython functions that I use. ...
1
vote
0answers
27 views

Identify specific methods and their parameters in source code

I have two source code files (one in java and the other in python). Certain methods in the java file have references to the python file using the PythonInterpreter, e.g. execfile("hello.py"); or it'...
0
votes
0answers
18 views

Design of a schema parser in order to validate files according to that schema?

I am trying to parse files written in the EXPRESS data modeling language. These files are used to define data structures of files used for the exchange of product manufacturing data. In my case, this ...
0
votes
1answer
154 views

What is a proper way to structure a Python project consisting of smaller packages that have shared code?

I have been debating this question internally for a few weeks now and I keep coming up short in finding a good answer to the question. I feel an example would be more descriptive than just talking ...
-1
votes
1answer
141 views

Battery level prediction model

I have the idea of develop a model that predicts the battery charge level of my system for now until the following 5 days. The battery is charged using a solar panel. I am writing my code in Python 2....