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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

-2
votes
0answers
18 views

Protect my Python code [on hold]

I have been working on a Python code for the last 6 months in my small company. Once it is finished I wonder if there is a way to protect my Python code for been redistribute without permission or ...
-3
votes
0answers
29 views

PyLint/PyFlakes from WITHIN a program? [on hold]

Odd situation is that I can't shell out to run a linter. Yet, I'd love to run one. So, I'm left with trying to invoke the linter from within the script I want to lint. Something like this: import ...
-2
votes
0answers
49 views

OOP in Computer vision project

I am trying to understand how object oriented programming works. Until now I used functional programming in a computer vision software but while the project is growing, I realized it's limitations (...
1
vote
4answers
192 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
101 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
60 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
79 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
125 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 ...
-3
votes
0answers
80 views

Doubt about design

I'm designing a simple software. I have a database class and another file to handle the algorithm. Algorithm work with Event objects. My doubt is about changing information between database and ...
-1
votes
0answers
24 views

Steps needed to convert XML (with industry specification) into python usable HDF5 (containing pandas and metadata)

I have been wandering stack exchange websites to figure out which one should I ask this question on. I hope I am right to post this here. I have over 5gb XML data files stored on hard disk. These ...
-4
votes
1answer
47 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()) ...
-2
votes
0answers
75 views

What is the time complexity of python's print function? [duplicate]

Is the time complexity of printing a number (print(1)) same as printing a list of n objects or a string.
1
vote
1answer
23 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 ...
-2
votes
0answers
48 views

How to combine a bunch of get statements into a method? [migrated]

I have the following code and I don't like how get statements looks like. Is it possible to somehow move it out into a separate method? I want to make a method more readable. params = ...
0
votes
2answers
221 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
43 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
76 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
109 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
54 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
80 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
109 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
70 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
131 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
70 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, ...
152
votes
23answers
21k 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
48 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
41 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
144 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
126 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 ...
0
votes
1answer
128 views

Break up django monolith into microservices

We currently have a big Django web application: all data is centrally managed by the webapp, via models backed by Postgres. We want to offer access to the data in a more decentralized way, and the ...
1
vote
4answers
188 views

What is the technical term for the modifiers that come after a command?

For instance: python3 -m What is the technical term for the "-m" ? And, where can I find a list of these "modifiers" that correspond to a command? Then, how would I find out what each of these "-...
3
votes
1answer
158 views

Does adding values to a dictionary in the constructor violate that “a constructor shouldn't do work”?

Some what of a followup to this question. Suppose I have a Player class with a dictionary call attributes that holds the Health and Mana of the player. In this example, I'll use Python, but my ...
2
votes
3answers
217 views

Should I test the debug branch of my code in a unit test?

Lets say I have a function that gets a list of what files to send that are later send over a socket to some other pc. Now usually I keep track of what files have been sent and don't send these files ...
-2
votes
1answer
26 views

Auto test with random keys from dict with added values equal to a certain number

I have a list (23 items) of choices and I've transformed it into a dictionary in order to have a value for each choice. I need to select 3 random choices from that dictionary each time I run the test ...
0
votes
1answer
92 views

Organizing Python functions into a module or class

I'm working on a module for clustering algorithms, clustering.py. I noticed several functions in the module only pertain to the mean shift algorithm, so I thought it might make sense to group them ...
0
votes
0answers
54 views

Preferred way to implement protobuf-based classes in Python?

I'm working on a distributed application that will use protocol buffers as it's core interface definition language. While am amazed how pleasant protobufs are to work with in a networking context I'm ...
1
vote
0answers
97 views

Making java code usable from other programming/scripting language

We are "extending" a product developed by a third party and working with them on that. There's a small problem though. They have some functions (written in java) that they use in their Android mobile ...
1
vote
0answers
34 views

Manage several procedures

I have a software project which grows rapidly in an unexpected way, many customers request similar tasks but with slightly different needs and parameters. I start to dislike my current code structure ...
-2
votes
2answers
148 views

How does a dynamic array access work?

In C if i declare int x[4] Which tells me its an integer array with each array element size fixed of size 4. So after initialization when I access x[3] : address of array +element size which is 2 *...
1
vote
1answer
44 views

Installing mixed technology desktop application

What are the options for installing an application which uses batch files, python, excel and proprietary software? I developed a command line shell to run fast, repeatable traffic simulations largely ...
0
votes
0answers
73 views

Django Fat Models: Where should I put model creation logic?

I'm reading Two Scoops of Django 1.11. At 7th chapter it introduces "fat models". It says that best practice is to put a big part of logic into the model and keep views as thin as possible, but then ...
-4
votes
2answers
61 views

minimalistic software modeling standard as a replacement for UML

I've been using UML 2.x for several years and it really worked for Object-Oriented languages like C# and Java especially when the software was big enough to be considered an enterprise-level system. ...
-2
votes
1answer
36 views

What Is the Best (Conventional) Way to Format Code for PyQt5

I was looking into PyQt5 for one of my side-projects and would really like to get to learn it better. However, I wasn't sure how to correctly format the code. I've seen tutorials do class definitions ...
1
vote
1answer
196 views

Does creating a list in the constructor violate the guideline that a constructor shouldn't do work?

I was reading these pages (1,2,3), but I'm still unsure if this violates the guideline. I have the following data being read from a website: Date: July 13, 2018 Type: Partial Solar Eclipse Location:...
0
votes
1answer
57 views

Displaying periodic simulations via web interface

The gist of my problem is that I'm trying to make a basic simulation for periodically collected data. More specifically, given the position of a radio antenna, the RF patterns would be simulated ...
1
vote
1answer
76 views

How can I model unknown and an unknown number of attributes on an object?

My example might be slightly contrived, because I've modified it so that the project isn't recognizable by my employer. I'm a newer developer at a very small company. We have an object - Posts - that ...
-4
votes
5answers
231 views

I learnt a languge suppose (Java). I also know python. I want to write a simple app. Is there any way to run both language same Time?

I had been learning python and i know Java. if i were to write a simple program, can i write both programming language in one document or compiler? I got into this problem because if i cannot merge ...
5
votes
3answers
326 views

Better conditional debugging pattern?

Given the need to log only in debug mode the easiest way would be to use if conditions: def test(x, debug=False): if debug: print(x) # ...Some more code if debug: print("...
0
votes
1answer
224 views

Should a Python property decorator be used without a setter or deleter?

I have a class that contains an object (set in this case). The set is modified by the standard function operators __add__ and __sub__, but I also want to explicitly expose a method of getting this ...
-3
votes
1answer
132 views

Web GUI for Python scripts

I have several but independent computer vision pipelines which were original planned to run by a user via a cmd (task1 -> script_1.py, task2 -> script_2.py and so on). All pipelines share some code (...