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

learn more… | top users | synonyms (1)

0
votes
0answers
6 views

Do I have to use pattern recognition to build this function? (python)

I want to make a software which can screenshot frames which contain subtitles. I have solved the screenshot part. In order to solve the subtitle detection part, my first thought is to monitor an area ...
1
vote
0answers
47 views

When using PyPy, is it still prudent to optimize the source Python code?

In Django Rest Framework there is a built-in class Foo that is more featured/bloated than what I require. I've written a custom class Bar that does only what I require. I imagine that PyPy would take ...
0
votes
0answers
27 views

Creating a class factory typish RPG system with SQLAlchemy support

My game will have a class hierarchy like this: Player: int level int xp list[Skill] skills Skill: str name int level int max_level Each player to join the server will get an ...
0
votes
1answer
44 views

Best way to import a large module to use in different modules

I have a python module dataProcessor.py which initialises a large amount of data into memory (approximately 3GB) I want to use this module in different processes which are running simultaneously. ...
0
votes
1answer
61 views

Assigning instance variables in function called by __init__ vs. function called from __init__

If I need to have a function do some processing in order to initialize multiple of the object's variable (I'm having a hard time coming up with a simple example that doesn't seem weird). Which of the ...
2
votes
2answers
354 views

Efficiency considerations: nested loop vs recursion

I would consider myself an intermediate Python programmer. One of my recent challenges was creating a list of all possible solutions to a given Countdown problem. Without getting into too much detail,...
0
votes
0answers
67 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 ...
0
votes
0answers
26 views

Maximizing the sum of edges in an undirected graph

Our graph is transitive and bidirectional. We are given m distinct edges to add to the graph. We define m_k to be the degree sum (over all vertices) after adding a given edge m_i. We then define the ...
4
votes
0answers
48 views

What is the best way to store and manage client <> server <> server and back session information and authorisation?

I have scenario, where I have javascript front-end connected using AJAX communicating with Django-Rest-Framework backend. Users authenticate using JWT tokens. Backend is acting as chatbot and ...
1
vote
1answer
79 views

How to define and share a JSON schema between the front-end and back-end of an application?

We have a mobile app that accepts input into some fields, formalises them as a JSON document and then sends it to the back-end for processing. We want to agree on a schema for this document that can ...
0
votes
2answers
53 views

Scheduling of parallel I/O-bound tasks (Backup solution)

I want to implement a backup solution in Python where a Backup-Server initiates backups on a number of virtual and physical servers (one server = one backup task). Disregarding the details of the ...
2
votes
1answer
63 views

Architecture of app with two independedt interfaces (web, touch screen)

I am going to build raspberry pi based device which reads data from sensor bus (serial port), analyzes it and present it on touch screen. Touch screen will be also used for configuration. Device ...
0
votes
1answer
19 views

Django: caching properties for non-changing entries

I am wondering if it is a good idea to do the following: I have a Django model (which is related to a migration, therefore it has a database entry) with a bunch of properties. Accessing these are ...
1
vote
3answers
81 views

Options for the RESTFul approach for follow and unfollowing

I'm looking at implementing a new RESTFul call where a User can follow/unfollow a generic 'thing' item, but I need to know the best or common approach below, 1 or 2? 1) A GET or POST on the ...
0
votes
2answers
87 views

Critique on design principle and validity of such in general

I was hoping you could give some feedback on an idea I had for designing functions. I am trying to think of a unifying principle for choosing what functions should return. The specific project is ...
1
vote
1answer
49 views

How to detect end of queue in a parallelized web crawler?

Let's say I want to program a parallelized web crawler which has a shared FIFO queue (multi consumer/multi producer). The queue only contains URLs. How do I detect the end of the queue? A worker ...
-2
votes
0answers
48 views

How to code properties of an array in Python

I am trying to code a generic 'n' integer array that fulfills certain properties. One of these properties (for example), is that if I select a number between 0 and 'n' and place this into the array, ...
0
votes
0answers
29 views

Flask application - pluggable by user-uploadable code

Imagine an installation of this Flask software F by an adminstrator A. A can use F's core functionality to create interactive HTML5 forms (you could imagine surveys) with text, images, radio buttons, ...
0
votes
1answer
37 views

Relating to design and runtime - is it better to parallelize smaller sub-tasks or bundled tasks?

I'm programming a small web scraper in python which I want to speed up by parallelizing things. The scraper is crawling URLs whereby a single URL can represent an 'item' or an 'index'. An index in ...
1
vote
2answers
70 views

Commercial usage of AGPLv3 python web framework

There's shuup django based e-commerce web-framework which is licensed AGPL-3.0 I would like to use it in my commercial project, which ultimately means that I'll want to modify a thing or two in the ...
0
votes
2answers
76 views

Using “intermediate variables” to abbreviate long dict entries

Sometimes I come across the situation that I have some data in a nested dict with rather long key-names (sometimes unavoidable for one reason or another). some_dict = {'not_too_short_key_one': {'...
4
votes
2answers
81 views

Is there any good/fundamental reason that Python classvars, and JavaScript prototype inheritance, don't mutate the parent on assignment?

In Python, if you have a classvar, it's accessible from an instance, but if you set the variable on the instance it doesn't actually change the classvar, rather it assigns a new name which shadows the ...
0
votes
3answers
146 views

Definition of Generic function

1) Below is a python function summation, that can perform sum of cubes/squares/.., similar operations. def identity(k): return k def cube(k): return pow(k, 3) def square(k): return ...
-1
votes
1answer
58 views

Is it good approach to collecting all logs in memory of a request and dump once?

What I want to Achieve ? I want to dump all logs in a single line which got collected during a request. Why I am doing this? General approach, i.e. logger.info(), dumps log in file at same time ...
2
votes
1answer
79 views

Documenting variables in a Python module

I am writing a Python module that uses Numpy. I am trying to follow the Numpy docstring format. In many of my functions, the same parameters show up. It seems repetitive to explain what they are in ...
0
votes
0answers
97 views

Optimizing a client-server visualization that runs out of memory

I have a visualization (shader-based) that I'm running in a Chrome browser. Recently I've been running out of memory after periodically refreshing the pool of data from the server, or if I make the ...
4
votes
2answers
167 views

How can I avoid both objects A and B using class C (or is it unavoidable)?

I have the following setup: An object A running as a separate service with its own address (implemented via Pyro package in Python). An object B running as a separate service with its own address. ...
0
votes
1answer
43 views

Recommended way to organize and build multiple services for App Engine Flexible Environment with custom runtime

When deploying to Flexible Environment using the default runtime (e.g. python), we just need to specify different app.yaml files with different entrypoint: values. But what would the 'best practice' ...
1
vote
1answer
69 views

Refactor settings module to settings object (python)

I have a small python application (about 6000 loc), where I keep my settings in a seperate module, settings.py. As the application grew, I started to add tests. Now after having more and more tests, ...
2
votes
0answers
57 views

Nested imports vs. two separate import statements?

Consider these two styles of code that accomplish the same thing: Nested imports common.models from django.db.models import * class SmallAutoField(fields.AutoField): def db_type(self, ...
1
vote
2answers
114 views

How to complete a task in two seperate 'else' statements while maintaining DRY [duplicate]

What is the best way to implement the following code without having the same code duplicated in two different blocks, but while maintaining efficiency and readability? if (expression1): if (...
-4
votes
1answer
133 views

Detect if code is C

I am currently using Python to write a compiler manager. I have to detect whether given source code is C, even if the code has a few syntax errors. I am currently using the file's extension to tell, ...
0
votes
0answers
55 views

What should I consider while architecturing a loosely coupled modular application?

Introduction For some background, I am trying to architecture an application for my startup. My application is divided in 3 separate git projects, details are as follows. Backend API written using ...
3
votes
0answers
69 views

API design: stream objects vs. functions vs. messages

I'm designing API for a python library that accepts asynchronous input and produces asynchronous output: various signals come in, and various signals are generated in response (there's no one-to-one ...
0
votes
0answers
37 views

PSFL compatibility with Apache, LGPL, BSD, MIT

Description I start with a simple real case example: the foo.py, my secondary module: import bar #third-party package that use a license (see under) class Interface: #do something (see below) ...
0
votes
0answers
47 views

Importing functions from modules in Python and JS

In Python importing just one function makes no performance benefit as pointed out in this question. However, in JavaScript things are completely different, or at least I often see people do it and say ...
0
votes
1answer
69 views

Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)

I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub. It is reasonable to make a base class like GitIntegration to handle ...
9
votes
3answers
519 views

Sometimes private functions are simply yet-to-be-extracted internal units of functionality. So why not test them?

Sometimes private functions of a module or class are simply yet-to-be-extracted internal units of functionality, which might deserve their own tests. So why not test them? We will write tests for them ...
1
vote
2answers
287 views

How many types of polymorphism are there in the Python language?

I just read an article by Luca Cardelli and he explained types of polymorphism which are: The article is named On Understanding Types, Data Abstraction, and Polymorphism. Types of Polymorphism ...
0
votes
2answers
110 views

What is the best/most Pythonic way to mock a private function?

Consider a module with a 'public' function which looks something like this: def func(arg): val = _generate_something(arg) _do_something(val) As you can see this is a 'void function'. Its ...
1
vote
4answers
161 views

Comparing objects with tolerance

The following code says that c1 == c2 and c2 == c3, but c1 != c3. TOL = 0.11 class C: def __init__(self, x): self.x = x def __eq__(self, other): return abs(self.x - other.x) ...
21
votes
4answers
3k views

Functional style exception handling

I've been told that in functional programming one is not supposed to throw and/or observe exceptions. Instead an erroneous calculation should be evaluated as a bottom value. In Python (or other ...
3
votes
1answer
109 views

Why was the warning about % formatting toned down in newer Python docs?

The Python 3.1.5 docs refer to the % style formatting as "Old String Formatting Operations" and provide this warning that it may be removed: Note: The formatting operations described here are ...
4
votes
3answers
171 views

How to DRY with calls to a database to execute?

I'm writing a python app that instructs a database to perform various processing instructions on partitioned tables. The processing can take long enough that there might be a timeout, so I surround my ...
8
votes
4answers
328 views

Class decorators in Python: practical use cases

I am looking for practical and non-synthetic use cases of Python class decorators. So far, the only case which made sense to me is registering a class in a publisher-subscriber system, e.g. plugins or ...
4
votes
2answers
192 views

How should I name functions that return values in Python?

I'm confused about choosing names for my functions in Python. Sometimes Python built-in functions are imperative such as: print function and string method find. Sometimes they aren't such as: len its ...
4
votes
3answers
268 views

Is it reasonable to write worse debug code in order to improve production code?

The title pretty much speaks for itself, but I'll provide the current decision I am facing. I am migrating python code towards the use of generators. The current code looks like this: ... l = ...
3
votes
1answer
141 views

Where do you put the “main function” of a Python app?

Suppose you are developing a Python standalone application (not a library). Would you make it a Python package? Or just files next to each other? If you would make it a package, what would be the "...
0
votes
1answer
163 views

Using singletons in Python (Django)

I was suggested to define a singleton in Python in the following way: class Controller: pass # ... controller = Controller() However, this way, controller cannot be replaced with a derived ...
0
votes
1answer
63 views

Error checking design question (python & MVC)

Which is better as a design perspective? An object that gets initialized and then checks to see if the parameters passed to it are valid before destroying itself (so in __init__) or Check to see if ...