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
Make your voice heard. Take the 2019 Developer Survey now

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
votes
2answers
509 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
46 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
212 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
81 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
81 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
220 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
60 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
92 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
242 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 ...
6
votes
3answers
519 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
1k 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
451 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 (...
2
votes
1answer
51 views

Functional tests for SVN management script

I have a Python script which is responsible for updating SVN repository (in a nutshell) and checking it. Now I'd like to write some functional tests for the script. To check whether SVN update has ...
1
vote
2answers
188 views

Implementing interfaces vs using a base class

I am writing an application in python. The part I am little confused about is providing a little structure to my code. This is the basic requirement of my web application. I have these different ...
1
vote
1answer
110 views

Python Class vs File level variables

I have the following class: import Radar class Domain(Radar): URL = 'https://mxtoolbox.com/DNSLookup.aspx' ADDRESS_KEYS = ('mailing_address', 'city_name', 'state_name', 'zip_code', ...
1
vote
1answer
310 views

How are list elements accessed in python internally?

Like if I want to access an array element in C it's implemented like this: For example: If a = {0, 1, 2, 3} is an array if I want to access index number 2 I will write a[2] and the formula that is ...
1
vote
2answers
81 views

Selecting test cases to run by checking what's changed

Problem: If running all test cases takes too long, I manually specify a subset of tests to run while developing. But when I finally push to CI, it can happen that I broke some other tests or a ...
2
votes
1answer
97 views

Calendar scheduling: home field constraints

I am working on a round-robin scheduling algorithm for sports. The goal of the algorithm is to schedule all given games across different weeks, in the given fields and given game times. These are ...
0
votes
0answers
109 views

Is it a valid OOP design for Python?

I have following class design (not exact but you can get the idea): WRITE_METHODS = ('POST', 'PATCH') class CanPOST(BasePermission): def has_permission(self, request, view): return ...
0
votes
0answers
49 views

Make functionality in Python

I’m building a Browser for matplotlib graphs G={g_1, g_2, ..., g_n} in Python, and I want Browser to be agnostic about the contents of the graphs.   I’ve also got a Parser that generates G from raw ...
-4
votes
1answer
88 views

How do I know a product is in the “will_expire” state? [closed]

I am developing a software system and in it there are time-measured products. The customer buys the product for a period of time, such as one month. If the user does not list their products everyday, ...
2
votes
2answers
109 views

How to implement Strategy pattern for combined behaviours

Strategy pattern solves the necessity of applying a certain algorithm/behaviour depending on the object's type itself. So you can iterate over a bunch of similar objects and call the same function ...
0
votes
2answers
89 views

Difference between interaction log and “debug” or “application” log

Let's say I need two logs coming out of my application. One is for debugging issues and making sure the application runs correctly and the other is used for user statistics and general analysis of the ...
0
votes
4answers
166 views

Magic __init__ and regular init methods in a python class

Is naming a regular method init only confusing or is it an error? class A: def __init__(self, x): self.x = x def init(self, y): self.y = y**2 def reset(self): ...
10
votes
4answers
637 views

Good code style to introduce data checks everywhere?

I have a project that is sufficiently large in size that I can't keep every aspect in my head any more. I'm dealing with a number of classes and functions in it, and I'm passing data around. With ...
3
votes
2answers
234 views

Should complex return objects be wrapped in a helper class?

In refactoring some code I found a helper method get_records_from_file that has a complex return signature: class RecordDefinition: def __init__(self): self.foo = None self.bar = ...
1
vote
1answer
1k views

Efficient multiple substrings search

I have many substrings(2-5 words each) which I would like to search in some text of about 40-50 words length. What is the most efficient way to flag matching substrings. Currently I am simply using: ...
0
votes
1answer
420 views

How to document kwargs in Sphinx style?

I'm wondering how I can document **kwargs in Python using sphinx dostring style. For example I have the following method and I want to document more details about kwargs. def get(self, url=None, **...
2
votes
1answer
92 views

Calendar scheduling: wait time between games

I am working on a sports scheduling algorithm with several different constraints, one (two) of them being a minimum and/or maximum wait time between games. Of the same team, that is. So if Team Blue ...
4
votes
2answers
294 views

Running untrusted python code safely

I've seen a couple other posts about people trying to run untrusted user inputted code into a eval or exec statement. My implementation checks the code before hand for any import statements, makes ...
0
votes
1answer
149 views

“Base Python” vs “System Python”

I've been using this term with a loose understanding as heard in the phrases "uses base python", "built on base python" that basically suggests a python project that only depends externally on Python ...
-5
votes
2answers
80 views

Python: How can I move files without changing import statements?

I've been writing some code which makes use of the 'import' statement to include code from other parts of the project and during the course of development I've had the need to restructure some of the ...
1
vote
4answers
1k views

How to avoid bidirectional class and module dependencies

To give some context, I'm using python. We have the following package structure: /package_name /request.py # defines class Request /response.py # defines class Response Let also assume ...
2
votes
2answers
702 views

Proving Two Zip file are identical

I migrated some files from one Version Control System to another. I have to prove that content are identical (between source and destination, denote 1 , 2). There are a few zips files (lets call them ...
5
votes
1answer
144 views

Split ORM module without creating cyclic imports or side-effects

Preface I have an ORM library for a relational real estate database. The used framework is peewee. The library contains ~60 models, each representing a distinct table. The models represent a (pre-...
1
vote
1answer
400 views

Enforce strict naming of multiple arguments

I have some questionnaire data in CSV files for different projects. I created a function that takes a specific subset of columns and calculates aggregated values. The problem is that across these ...
1
vote
1answer
109 views

Should I containerize Python 'job' scripts?

We have a python scheduling solution which, at the moment dynamically loads python modules to run each job in a separate process. The jobs are pretty heavy containing some Tensorflow models which ...
2
votes
0answers
50 views

How to interface with very badly written code in Python? [duplicate]

I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to ...
3
votes
1answer
565 views

python callback function with arguments bad practice?

I wrote a listener class that executes a programmer specified callback. The msg is provided as a callback argument. I realized that a programmer using the class will need to look at my code to see ...
-1
votes
2answers
74 views

Should I add fields or use inheritence in this case?

Houses and cars have almost nothing in common for instance "number of rooms" and "gearbox". But if you live in an RV then I suppose it makes sense to have both. My problem is that I have a main data ...
0
votes
0answers
97 views

What is the rationale behind unidemensional vectors in scientific languages?

In MATLAB a vector is a matrix of shape n×1 and length n. In Julia (which has been influenced by MATLAB) and Python's NumPy, on the contrary, there exist pure unidimensional vectors that have shape n ...
0
votes
2answers
2k views

What is more efficient: Reading and parsing a large JSON file, or large CSV file?

I plan on using Scrapy to crawl a local website for a LOT of data and store it in a file. Then I plan to parse that file and put some of the data in a SQL database. Will my computer use less CPU and ...
0
votes
0answers
57 views

Best practices for initially populating a database?

I am writing software that processes packets. Each packet consists of a number of Items, and packets of the same type have the same Items. I have created a database schema such that there is a ...
0
votes
0answers
51 views

Smartest way to setup testing in Python/Django

So I am about to start my final traineeship as starting Software Engineer (and Tester in this case) but I am in a bit of a pickle. The company has developped their own CMS system with Python/Django. ...
4
votes
3answers
2k views

Does it make sense to use string constants in Python instead of string literals as keys?

There is a dictionary in my class with informative, short string constants as keys that identify certain parts of the solution, like "velocity", "death_star_power_output". My colleague suggested that ...
0
votes
1answer
59 views

Uncertainly importing modules with Python

I'm developing a module that should be able to interact with other modules such as numpy or PIL. To accept parameters and test if, for example, a parameter is an numpy.ndarray, I'd need to import ...
2
votes
1answer
245 views

Speech to text - action - text to speech: architecture/logic. Is there a better way to build my robo-player?

I have decided to start a personal project using Python since I have used it for several years now and I would like to know if the approach that I have considered is good or not. Description It's ...
-2
votes
2answers
2k views

Algorithm for scheduling shifts

I am trying to write a program to help scheduling shifts for the employees of a small business. There are 28 shifts that needs to be assigned to 28 employees (so this means that each person gets a ...
0
votes
2answers
174 views

When is it not Pythonic to use properties instead of a method that doesn't take arguments?

It's widely agreed that Python's properties are not merely a kludge for working around the past mistake of exposing of publicly exposing data members. But then when is it not Pythonic to use a ...
0
votes
1answer
73 views

Is raising an unrelated exception for convenience acceptable? [duplicate]

Let's say I have a function that returns a dataset. First it tries to read it and if that fails it is requested from an API and then written: def get_dataset(): try: df = pd.read_csv('...