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

0
votes
3answers
38 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 ...
-1
votes
0answers
8 views

Deployment options for Flask application

I have developed an web application using Flask, where the user uploads a file, which gets processed by some Matlab scripts using the Matlab python engine. I would like to deploy this application to ...
-1
votes
0answers
15 views

Split list of strings so that there is one value per column

I have the following list of strings: ['0001097081', '0001380712', '0000857171', "0001310094', '0001251570", '0001140472', '0000909950', '0001076462', "0001016546', '0000820464", '0001050112',...
0
votes
1answer
103 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
56 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 ...
0
votes
0answers
39 views

implementing CSMA in Python

I am struggling to implement this concept correctly, so basically the concept in there is that a global time is ongoing, and each stations randomly transmit data in any slot (so I have to create a ...
0
votes
1answer
58 views

How to write a database management library to interop with C++ and Python? [closed]

We have a C++ application (.NET GUI) that outputs a lot of runtime data. We're building a Python app to crunch and display all of this data. Right now, we're trying to determine the best way to manage ...
1
vote
1answer
90 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 ...
0
votes
1answer
46 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
votes
0answers
15 views

AppJar and Tkinter are both tools for GUI architecture on Python. What are the differences between the two?

Most of the question is in the title, but I can explain further. I want to make a simple Python application with a GUI, and I think of using AppJar or Tkinter. What are the differences and what do you ...
1
vote
2answers
111 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 ...
-2
votes
0answers
12 views

How to set SQLAlchemy dialect? [migrated]

How do I tell SQLAlchemy which dialect I want to use? Context: I want to store one attribute of my class as a JSON object, and run queries on it using SQLAlchemy. Here is the attribute: ...
0
votes
1answer
62 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
33 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
31 views

Using the API provided by a class internally

I've implemented a class with a __getitem__ method to allow users to access some data by its key in a dict-like way, i.e. obj["key"]: class A: def __init__(self): self.data = [] def ...
0
votes
0answers
63 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 ...
-1
votes
0answers
16 views

Encode text fields into grid layout vectors?

So, I am asking for suggestions for this situation. I have implemented a machine learning model (VAE). I am using this model to regenerate grid layouts that are represented by images. I am using this ...
-2
votes
1answer
38 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 ...
0
votes
1answer
36 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
238 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
13 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
71 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 ...
0
votes
1answer
91 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....
0
votes
3answers
54 views

Looking for best practices of storing configurations that will be read/write frequently

I'm writing a couple small python scripts to do tasks and act as 'bots' in some applications that will all read/write things for configuration and some very low-level logging of information; Whats the ...
0
votes
0answers
32 views

Calling other methods in unit test [duplicate]

I was learning about test driven development and came across unit testing. I have few questions regarding testing a class containing several methods; assuming i consider each of these methods a unit ...
0
votes
0answers
43 views

Want to change my batch code into a fully fledged program

So I've forked a project from Github here -> https://github.com/Defirence/CSGO-Ping-Tester and I want to find out if there's any way to "convert" this code into say a program, I did try and mess ...
1
vote
4answers
227 views

Unit testing Markov chain code

What are the best ways to unit test code that outputs random sequences satisfying specific conditions, such as Markov chains? Let's be specific. There are two natural things to test: That the ...
2
votes
1answer
104 views

Traversing over two similar object structures using a pattern

Let's say I have an Object Structure like this that I import data into from a source: Reporting: Body: ReportingEntity: DocSpec Reports[]: ConstEntities[] DocSpec ...
0
votes
2answers
85 views

Design of a Python “service” using multiprocessing and threading

Due to the Global Interpreter Lock, multithreading in Python does not affect parallelism. This limitation is avoided in the multiprocessing library by spawning new processes instead. But threading ...
2
votes
2answers
101 views

Appropriate way to handle timezone for embedded/IoT devices

I am writing some data collection software (in python) that will transmit data to the cloud. I am including a timestamp (using the standard datetime module included with python) in the data record so ...
0
votes
2answers
129 views

Question on open polymorphism (motivation - output data to diff file types)

Let's say I have some class, and within instances of that class I want to be able to output certain data to various file types e.g. CSV, SQL, PDF, etc. The simplest way is just a series of if ...
-4
votes
1answer
49 views

What's the `__version_info__ ` function in a PyPi package?

What's the __version_info__ function? I am reading a open source library uritemplate, I found: __version__ = '3.0.0' __version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit()) ...
1
vote
1answer
28 views

Workflow for contributing to Python libraries under virtualenv

Let's say that I want to contribute to thislib, which is a Python library that is available as a Git repository. Several applications, such as thislib_app utilize this library, and I want to ...
0
votes
2answers
235 views

Why do Python developers pass special strings to functions instead of defined symbols? [closed]

Is there a reason why Python developers (both maintainers of Python itself and authors of modules) tend to pass special strings as arguments to functions instead of defining symbols for the same ...
0
votes
1answer
47 views

Creating data files inside a package

I'd like to deploy my code to a web server as a package. There Python is subprocessed and scripts are executed. These scripts use data files. But in case a file is needed and it doesn't exist, it ...
0
votes
0answers
169 views

Using a Boolean to cancel thread

I asked a similar question to this on SO, but after re-reading it this morning, I realized it wasn't clear what I'm asking. So I narrowed down my problem and realized it was about a pattern instead of ...
0
votes
0answers
115 views

Elegant ways to handle if(bool1 or bool2): expr if (bool1) if (bool2)

Is there any way to handle the following situation more elegantly: if sources or statuses: must_bool_query = [] bool_query['filter'] = { 'bool': { 'must': must_bool_query ...
0
votes
2answers
58 views

Referencing custom Python modules and data files

I'd want to deploy my Python code and relevant static files such that only a copy of a folder is needed. That is, all the paths inside are relative. The release is to a web server, which calls scripts ...
2
votes
1answer
82 views

Is it considered bad form to call `next` on the input sequence of a list comprehension?

I want to extract lines from a stream that are preceded by the character L. The list comprehension below does the job, but calls next on the stream inside the comprehension in a way I've never seen ...
0
votes
1answer
119 views

When doing oop in python where should I add the logger

When doing oop in python where should I add the logger. Should I add it: before the class Rocket(): and give it a file global scope or after the class Rocket():  and give it a class scope. Syntax ...
2
votes
1answer
75 views

How to design a parents evening scheduling algorithm

I am working on a project to create a school parents evening booking system. This system needs to be able to generate the best order of appointments based on availability of teachers and the priority ...
3
votes
3answers
254 views

Changing large number of if-elif-else statements to use underlying structure

I have a function that looks something like this: function_name(step, ... , typ): if typ == 'some type of calc method': if step == 1: do_me_at_step_1(...) elif step ...
-1
votes
2answers
85 views

How to choose the most suitable solution for a problem given some choices?

To ilustrate my main concern let's start by considering a "trivial" typical problem, data filtering & parsing coming from a process and dumping the information onto something {gui console, file, ...
159
votes
23answers
22k views

Programming cleanly when writing scientific code

I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical ...
0
votes
0answers
51 views

How to ensure that a group of python scripts runs everywhere?

I would like to arrange my code into a clean tree style and make my code run on other machines. However, I encountered so many ImportError and FileNotFoundError that I believe my fundamental coding ...
2
votes
0answers
47 views

Packages, a controller class, and coupling vs cohesion

So I'm building my first application, in Python, and some issues have cropped up because of the lack of interfaces (I.e. explicit type declaration) My design involves several homebrew packages, and I'...
1
vote
3answers
336 views

Better to use Global Variable or Coroutine in general?

Is it better to store state in a global variable or in a coroutine, specifically in python? I don't understand best practice here. As an example consider a simple flask script. from flask import ...
0
votes
1answer
245 views

Best practices for calling multiple APIs and manipulating data before showing it to user?

I am building a web application that makes use of multiple API's (Google Maps, Weather APIs, and more). I am using Python + Flask on the backend, and Javascript (probably with React, I have not ...