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.

3
votes
0answers
768 views

Structuring a multi-language project?

I'm working on a project which involves writing code for multiple devices, each in its own language (in particular, Arduino and Python). I want to contain the entire project in a single directory, but ...
3
votes
0answers
507 views

The Python module-as-singleton hack

I've seen (and once used) this idiom a few times in Python: # At the end of a module: if __name__ == '__main__': main() # or whatever your entry point looks like, this line isn't important else: ...
2
votes
0answers
52 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 ...
2
votes
0answers
73 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 ...
2
votes
0answers
87 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 | +-------+--------+ ...
2
votes
0answers
62 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'...
2
votes
0answers
80 views

Software design strategy for a machine learning tool that outputs a subset of the text input (Information Extraction)?

Let's say I have thousands of pdfs that are each about 30k words written in conversational English. In each of the pdfs there is a name / names of a person/people who snowboard. There are also many ...
2
votes
0answers
577 views

Python and C++ repository structure

I'm refactoring the directory structure of a large Python repo that has a few dozen C and C++ files littered throughout. Is there a suggested architecture for a Python package that contains C/C++ code ...
2
votes
0answers
42 views

How would I identify a gap in a set of curve data, and get its value?

I have a set of 2-D data (x,y) and it produces a set of curves, and sometimes the set of curves do not overlap, and there is a distinct separation between the groups of curves, how would I identify ...
2
votes
0answers
656 views

Calculating the multiplicative inverse of a number in a Galois field

I was told to come here from Stack Overflow because I was "looking for an algorithm". I'm trying to implement it in Python, but there is nowhere on the net that gives a straightforward way for ...
2
votes
0answers
969 views

How to Use Python as a “Macro” runner for a C# Application

I am working on an application that the user may wish to automate some features of (but we don't know what at the moment) I would like to provide them some kind of scripting interface so they can play ...
2
votes
0answers
773 views

How does the Zope Component Architecture (ZCA) relate to Service Component Architecture (SCA)?

I'm very new to the principle of Service Component Architecture and Zope in general, but the more I look, the more ZCA seems to be a good solution for a certain class of problems I often encounter. I ...
2
votes
0answers
611 views

Gevent - Make blocking calls non-blocking

I have the blocking code shown below. Is calling monkey.patch_all() enough/optimal to make it non-blocking? Does Gevent handle iterations like these? # front page def front_page(): database = ...
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'...
1
vote
0answers
100 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
37 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 ...
1
vote
0answers
247 views

Putting UnitofWork handler in the Request Model for DDD with Clean architecture?

I'm rearchitecting a system in Python, using SQLAlchemy for the data mapping layer, and the Zope Component Architecture for dependency injection and interface declaration. I am in the process of ...
1
vote
0answers
342 views

How to utilize Fat Models practice for Django and Django Rest Framework

I would like to know how experienced programmers and software engineers balance usage of Django's fat models approach against DRF views. In practice, my experience revolves around configuring DRF ...
1
vote
0answers
658 views

How to improve detection of Probalistic Hough-Lines-Transform?

I'm trying to detect a clock hand in a video of an analogue display and extract the value it points to. I'm using Python with OpenCV for this. What I essentially do is: I'm using a Gaussian Blur to ...
1
vote
0answers
79 views

Should I pull the language data files of a project from a GitHub repository?

I am currently in a dilemma. I am thinking about downloading a JSON file from a GitHub repo to replace local files. The local files are stored in a folder named lang, which is stored in the project ...
1
vote
0answers
76 views

How does the FOSS exception for MySQL connectors apply to code written in PHP or Python?

I have looked all over and can't find clear answers to the following: If I write code in PHP or Python that uses GPL MySQL connectors for PHP or Python - which license applies to my code? That of PHP ...
1
vote
0answers
1k views

Python inheritance/import - parent file imported modules, should child import too or thru parent?

My apology if this question is already answered & accessible through search - not quite sure how to phrase this particular query. So, here's scenario & question: File a.py imports several ...
1
vote
0answers
212 views

Does PyPy or Jython run untrusted Python 3 code more secure while still being fast?

I know that one can not securely restrict normal CPython's capabilities to properly run foreign code without allowing it to access some builtins like open() or allowing other kinds of I/O. So I ...
1
vote
0answers
52 views

How do I minimize the number of database queries in a GeoJson API (of countries, and smaller areas) with custom data?

The general version of the question is above - a a little more detail, I am using Django Rest Framework, but am happy for answers to be dealing with the problem in abstract. So, I have data with ~200 ...
1
vote
0answers
98 views

How to re-use a very small Python utility across different applications?

I have a very small utility that has proven itself very handy across a multitude of applications. The utility itself is less than 50 lines of code and is its own Python module, and a number of ...
1
vote
0answers
156 views

How can I improve my websocket server's structure/flow?

I'm building a websocket server in python and I've hit a block regarding my program's flow and structure. Here's what I'm doing at the moment. The program creates a instance of 'server' and listens ...
1
vote
0answers
66 views

Writing a container that treats nearly-identical images as the same

I want to create a mapping in Python that will use images as keys, but treat similar (but not identical) images as the same key. I have an approach for deciding which images are similar enough: I ...
1
vote
0answers
1k views

Calculating uncompressed file size without uncompressing file in zlib

I am writing a python program which parses zip (currently only zlib, using DEFLATE compression) files and verifies the correctness of their headers and data. One of the things I'm trying to achieve is ...
1
vote
0answers
148 views

Code structure with MongoDB in python

I am new to MongoDB and python. I know how to make basic use of pymongo in order to manipulate documents. I am having trouble finding how to create some structure or governance in what gets inside ...
1
vote
0answers
41 views

Finding the largest bundle of flagged points

I am currently working to develop a program that takes in an array of 4 columns and around 200,000 rows. Each column represents x, y, z (coordinates), and a flag denoting whether or not this point is ...
1
vote
0answers
254 views

Need to add websocket support to a single page that's running a wsgi service

Current setup. I have a legacy ERP system (Thoroughbred) and i then have several in house applications (CRM, WMS) and a website that interact with it via an xml server and straight ODBC connections. ...
1
vote
0answers
82 views

Improve communication between controller and trackers in a Twitter fetcher tool using RabbitMQ or Apache Flume

I've been working for a time with some researches developing a tool to fetch tweets from Twitter and process them in some way. The first prototype "worked" but became a pain as we used sockets to ...
1
vote
0answers
4k views

Best practices to parse a log file using Python

I'm writing a Python tool to parse a log file from game server. The log file is of format: ms:classname::id::method::arg1::arg2.... There are a lot of classes, and a lot of methods for each class, ...
1
vote
0answers
673 views

Why does pkg_resources not find bloom in my virtualenv?

I'm trying to hack on the ROS bloom build system (https://github.com/ros-infrastructure/bloom). After I've made some edits, I build it and install it to a virtualenv to test using python setup.py ...
1
vote
0answers
112 views

Inheritance and constricted referencing

Let's say I have BaseA and BaseB classes. BaseB can have to several references of BaseA instances. Now, we have two other classes, DerivedA and DerivedB that respectively inherit from BaseA and BaseB. ...
0
votes
0answers
10 views

what's the proper way to interpret SREM results from REDIS

Background I am writing a REST API that exposes a method that allows the caller to delete a resource from the REDIS database. Because I'm using a SET, when you try to do an SREM, it will just return ...
0
votes
0answers
112 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())...
0
votes
0answers
453 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
120 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
0answers
55 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 ...
0
votes
0answers
216 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 ...
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 ...
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 ...
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
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. ...
0
votes
0answers
143 views

Single .exe or two? VB.NET Userform and Python Data Analysis Script

I am wondering about integrating a Windows Form written in VB.NET with a python program saved as a single exe. I have been doing data science in python for a while but have no exposure to creating ...
0
votes
0answers
21 views

Dataframe function applied multiple times to different columns

I currently extract a data frame from CSV and create dummy variables for categorical columns. This seems to work fine, but looking for a way to improve my code readability. I thought of having a set ...
0
votes
0answers
33 views

Software design implementation - Is it possible to pass a word2vec model as input to a neural net?

I am trying to use a neural net for information extraction. I want to extract a specific human name (name of the person / persons with cancer) from a document that may have many names. I have ...