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
1answer
474 views

Data sync between Model and View in MVC pattern

I have a question about MVC pattern, concerning the controller part. Most of the program I happen to write are basically spreadsheet like. They are written in C/GTK+ and Python3/Qt5/Tkinter but share ...
0
votes
1answer
57 views

Method grouping other methods of the same family and how to call any of these separately

Worse title ever but I don't really know how to describe my scenario in a line... So I have a method that wraps the calls of a many methods of the same nature. Once any of these methods have finished,...
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
1answer
230 views

Using methods specific to a subclass

I came across this SESE page: What is a proper use of downcasting? (for C#) -- and it talks about when to downcast, and the possible downsides to it. In Python sub classes are slightly different ...
1
vote
2answers
145 views

Should I write integration test that test my code with real-network servers, before I start writing my code?

I am trying to write integration tests for a client-server app. The client app runs on a user's machine and connects to the server app running on a specific Windows server, network-serverA. The ...
3
votes
5answers
793 views

Fastest way to find all numbers with digits

I have a huge set of over a million numbers of variable lengths. ['773', '2267', '8957251', '170597519', '373590109', '982451707', '999999937', ......] Now given a bunch of digits, say 3 and 7, I ...
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 ...
-4
votes
1answer
524 views

Python variable in bytes

By theory please correct me if I am wrong, it says that an int can take upto max 4 bits in case of number 9. I haven't coded it low level languages but I assume that the datatype int in c and python ...
2
votes
1answer
49 views

How do I approach polyglot plugins for asynchrous python applications?

I've been looking at ways to let my app's users write plugins for it. However, to give them more options, I decided to implement a polyglot plugin system. From the engineering perspective there are ...
-1
votes
2answers
112 views

OOP Design Choices in a Web App

I am about to start coding for a school project that requires me to demonstrate good OO practices in a web app. Now, I have built a few web apps and have never felt the need to define my own classes ...
5
votes
4answers
407 views

I order my Python imports by name length. Does this make any sense?

First of all, yes I'm aware of PEP8 and the alphabetical method. I do sort my imports first by the PEP8 recommendation: standard library imports related third party imports local ...
2
votes
1answer
105 views

Maintainable way for keeping objects in memory

I am trying to figure out the best way to keep objects in memory without having them scattered everywhere within the code. For example: I have a PyQT menu system which interacts with objects. ...
2
votes
1answer
701 views

Enum or reference table when dealing with maps

I am storing information about Widgets in my database, and each Widget has one (non-unique) transformation function associated with it. My problem is how to associate Widgets with their transformation ...
1
vote
2answers
251 views

Representing a structure/tuple type with Hindley Milner Type Inference

I'm writing a really simple interpreted object oriented programming language with a C-like syntax. I've been looking into type inference and I've found a few implementations of the 'Hindley-Milner ...
1
vote
1answer
114 views

How do I deal with projects within projects in python?

Note I realise this could be subjective question to answer, but I don't expect an answer in the form of "Do this and everything will work out". I am aware there will probably be some decisions to be ...
6
votes
1answer
1k views

best way to install local package into docker image

I have a python package that I wrote and I want to use it within multiple docker builds. However, I can't just install my local package situated outside of Dockerfile folder. And I don't want to ...
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 ...
0
votes
0answers
80 views

Best software architecture for a PC application with a number of short and long running tasks

This is probably going to expose my lack of software experience but I'm looking for advice on a suitable software architecture and mechanisms (threads etc.) by which I can achieve the following... (...
4
votes
1answer
2k views

How are queues made thread-safe in Python

I admit this was asked to me in interview a long time ago, but I never bothered to check it. The question was simple, how does Python make Queue thread-safe? My answer was, because of Interpreter ...
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 ...
1
vote
2answers
644 views

How should I handle error codes from an external XML API?

Problem I have a Python library which sends XML requests to an external API. If an issue occurs, the API responds with an error containing an error code and description with error details. These ...
-2
votes
3answers
292 views

Reasoning behind custom class Exception

I am learning Python and when I learned that we can build Custom classes for exception, I got into a confusion of Why ? for example1 : class MyException(Exception): def __init__(self, error): ...
0
votes
2answers
180 views

Actions that can have individual cooldowns or a “group” cooldown

I'm creating a game (well, a plugin) where each player has a list of skills, each of which has an unique type object, each of which has a list of actions that need to be ran when a player executes his ...
1
vote
2answers
79 views

Function that manipulates collection and return the same type

I was just wondering this while programming in python. If I have a function foo which take a collection (list or tuple, perhaps set etc.) and manipulates on its elements somehow, e.g. filter, trim, ...
1
vote
2answers
59 views

__init__ arguments differ from object attributes

Is the following class definition a good design? class Myclass: def __init__(self,num1,num2): self.complicated_tree = __class__.object_creator(num1,num2) @classmethod def ...
3
votes
1answer
729 views

Python and JavaScript integration for offline use

I'm a first timer here so let me know if I should post this question in a different forum! I have a python program that takes in user input but is only useful when you're offline, I wanted to make ...
0
votes
2answers
3k views

Name and code to space between lines/paragraphs

I’m seeking a term and possibly the code behind what would help me implement that term in Python. I have been working on a text-based Python journaling application. When I want to review my ...
1
vote
1answer
148 views

What are the most effective ways to manage rot in your platform's dependencies?

I have a couple of inactive Pinax sites at different versions (0.9.x and 0.7.x). These both started with two common features: While the version of Pinax was the most recent to have a (nonempty) ...
2
votes
1answer
69 views

Organizing helper operations in your SW project, if there are very few helper functions

I have a Python project where I have a few classes that model various thing I'm considering (e.g., a car class, a driver class and a street class) and then I have a single helper function that does a ...
2
votes
1answer
207 views

How can the reusability of Python code be measured and quantified?

For example, let's assume we have a class that is imported three times from other classes. This would lead to a reusability of three. However, as there might be functions that are called only once, it ...
2
votes
4answers
554 views

What is the benefit of short readable code if you only see functions and classes on the outside?

Last years I made myself familiar with Python and Haskell. I am surprised and impressed about the short and readable code you can write in these 2 languages, especially in comparison to languages like ...
0
votes
1answer
190 views

Should I produce output with yield or stream.write in Python 3?

I am working on a Python 3 program that will among other things write data to text files in a number of formats. I have one function per format, generating the data to be written. I see two possible ...
-5
votes
2answers
584 views

Looking For Information about coloring/highlighting output text in python

one of the first modules I’m working on in a python program I’m putting together is a journal. I’m getting comfortable using the print function, but for this project it would be great if i Could ...
2
votes
2answers
2k views

Which approach for integrating Python code into a mainly Scala application did you use a second time because it was successful? [closed]

I have a mainly Scala application and I am interested in approaches to integrating Python code into this application in a way that is proven by you personally to be successful. In this context ...
0
votes
1answer
73 views

Is there a normal way to program a CLI script that overrides default parameters in python

If I've got a script that uses a config file (or defaults to a generic config file) that calls another module which needs the config file passed to it as a parameter should I always File 1 (the ...
0
votes
1answer
121 views

Django Project for REST endpoints and client view

I have a project where I will be creating certain data models, and managing them. I also want to provide functionality to external clients to access and modify this database. So the question is around ...
-2
votes
1answer
49 views

Methods of namedtuple not listed by dir()

In 8.3. collections — Container datatypes — Python 3.6.4rc1 documentation, it specify 5 methods of namedtuple. namedtuple_methods = {'_fields', '_make', '_replace', '_asdict', '_source'} ...
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 ...
-2
votes
1answer
332 views

apart of using Numpy/Scipy/Pandas, how can I vectorize code in python

I would like to vectorize some operations in arrays that are not actually available in ndarray or pandas dataframes/series, such as comparing element-wise two arrays/series/frame of similar shape, one ...
1
vote
1answer
104 views

Countermeasure for having the coordinate grid upside down?

So I'm using pygame to create a simple top-down shooter game, and I'm doing lots of angle calculations from the top-down perspective. Let's use a simple arrow and a ball as an example, I want the red ...
3
votes
1answer
479 views

Python local function definitions: is name hiding bad practice?

Is it seen as bad practice to try to hide local functions in Python? The intention not to clutter the global namespace with second rank or common function names may stand against ... er... some ...
3
votes
1answer
217 views

Should I rename variables that are already constants in my own library?

I'm writing a high level wrapper around the Python socket.socket object. Specifically, I want to do this for IPv4 TCP sockets (though it would be useful to be able to expand the library later with ...
1
vote
2answers
214 views

How to loosely couple chained algorithms

I have a search algorithm that is used in conjunction with a machine learning algorithm. I separated the two because I wanted to be able to swap out search algorithms on the fly. However, the coupling ...
0
votes
2answers
140 views

(AI) algorithm to optimize input parameters

Background information I am building a program that plays checkers as good as possible. It already plays pretty well but the goal is to improve it even more. This can be done by adding new methods ...
1
vote
2answers
579 views

Is a god class still bad practice if it is used with mixins?

Every description I have read about god classes considers them to be an anti-pattern and a bad practice. Most descriptions I have read about mixins considers them to be acceptable in some cases. If ...
28
votes
5answers
9k views

When to use a dictionary vs tuple in Python

The specific example in mind is a list of filenames and their sizes. I can't decide whether each item in the list should be of the form {"filename": "blabla", "size": 123}, or just ("blabla", 123). A ...
2
votes
1answer
115 views

Is it Pythonic to have a module named `functions`?

I have a Django project. All the apps are separated nicely. Each apps often have functions that are used across the apps. Currently I place them in module named wrappers (for wrapping django/built-in/...
1
vote
5answers
3k views

Why are Python sets and dictionaries not ordered by default?

I understand the difference between ordered and unordered sets, and I understand why for many purposes, we don't need ordered sets. But all set operations are still possible on ordered sets, and sets ...
0
votes
1answer
243 views

Decoupling god objects

As a 3rd-party, I'm writing a program to interface with a webservice. The problem I've run into is that some classes end up being as commonly used as ints/strings (e.g. User), so I need to be careful ...
2
votes
4answers
336 views

Is creating really small utility functions a bad idea? [duplicate]

Recently, I've been talking with a friend about the code I've written. The code looked something like: import json def save_data(destination, data): with open(destination, 'w') as out: json....