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.

1
vote
1answer
90 views

Is it good style to have a class that only stores data for abstraction?

I have written a webscraper in Python that grabs data from ~10 different websites (they have confirmed that this is ok). Most of the websites are a little bit different, but the general idea of ...
0
votes
2answers
512 views

How can I create a Python microservice on AWS that both accepts REST connections and processes SQS messages?

Background: I'm working on a new project at work that will run in AWS. We're trying to use a modern microservice architecture and take advantage of cloud technology, but we don't have much experience ...
4
votes
1answer
195 views

Should code be written to stay consistent with the unidiomatic API style of a library?

I'm currently using the wxPython library to construct a GUI. One interesting aspect of the library I've noticed is that it uses CamelCase notation to write method names, as opposed to the snake_case ...
2
votes
1answer
305 views

What is the difference between a man page and --help for a Python script?

I'm currently developing some Standard Operation Procedures for the company I work for. I'm starting with the very small examples; like scripts. There are currently several scripts being written in ...
2
votes
2answers
2k views

Is it really correct to declare all instance attributes in __init__

According to Pycharm (and thus assume according by PEP) i should state all instance attributes directly inside __init__. In my case it does not seem suitable to me. I have something like: class ...
0
votes
1answer
305 views

Can I explain Classes and Objects without the full stack of OOP concepts?

I've been teaching Python to someone that was new to programming; and so far, so good. Now, I'm about to teach Classes and Objects. However, I still think it's too soon for the whole OOP concept, plus ...
0
votes
1answer
124 views

What's the most idiomatic way to make a collection of enum.Enum in Python?

I have an Enum in Python that looks something like this: import enum class Color(enum.Enum): red = 'red' blue = 'blue' yellow = 'yellow' puce = 'puce' chartreuse = 'chartreuse' ...
2
votes
2answers
218 views

What is the proper structure for maintaining single page python scripts

I am a self-taught programmer, and started my job as a PHP developer,in a small company. I then got some work to write python script. I didn't have any senior with proper Python experience. So I ...
1
vote
1answer
333 views

Using lambdas to simulate python generators in java

I am currently dealing with an app that has several classes which are used to compare files in various formats (xls, csv, xml, html, pdf...). They are all implementing an interface that is defined ...
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 ...
5
votes
3answers
256 views

Paradigm for handling list of things or single elements

Very often when coding in Python (or any language where type is not specified) I run into the following problem: I want to write a function that can accept either a thing, or a container of such ...
0
votes
2answers
271 views

Dynamically choose whether to use __slots__ in a class

I've got a generic container class: from typing import Container, Generic, TypeVar, NamedTuple import sys fixed_typing = (sys.version_info >= (3, 6, 2) or (3, 5, 3) <= sys....
-2
votes
1answer
426 views

Choosing the right architecture for my web application

I've started working on my web application and I'm stuck at the design stage. I cannot decide which web technologies would be the most suited to this project. Let me explain what I want to achieve: 1)...
4
votes
2answers
191 views

What algo/design pattern do i need to keep limited time series data constantly updated?

I'm a hobbyist coder; never worked professionally. I am not looking for anyone to write code for me, but I need to know how to approach this problem and, perhaps, ideas for further research. This ...
-2
votes
1answer
182 views

How to determine the behavior of complicated source code quickly? [duplicate]

I am interested in zcash (https://github.com/zcash/zcash) and the theory behind it. Therefore, I download the source codes of zcash to trace it. The codes comprise C++,python and shell scripts. How ...
1
vote
1answer
996 views

What is the difference between the solution that uses defaultdict and the one that uses setdefault?

In Think Python the author introduces defaultdict. The following is an excerpt from the book regarding defaultdict: If you are making a dictionary of lists, you can often write simpler code using ...
0
votes
2answers
105 views

How do interpreters and VM print?

While direct Language-Assembly compilers generate the code required to perform specific task for the given platform, how do interpreters do it? Abstract example The following pseudo-code... printf("...
-1
votes
1answer
480 views

Why are we using mutable collections but immutable strings

In three popular platforms I'm familar with(.NET, java, python) strings are immutable but lists are by default mutable. In all languages there is some functional support(linq, streams, list ...
3
votes
1answer
406 views

Revealing Module Pattern for Python?

Javascript has a pattern for creating private functions called JavaScript's Revealing Module Pattern. It hides your functions in a closure that returns an object modified to provide access to the ...
1
vote
1answer
77 views

Making control flow explicit through printing instead of using comments?

I would have the opinion and good practices in script programming about using print statements to materialize the control flow (I usually use an anchor mark, then the name of the function just entered,...
0
votes
1answer
2k views

Comparing Two JSON Files In O(n)

I've got a scenario where I need to compare two JSON files and override one if the values are different. These JSONs also include arrays (i.e. [) My approach is to traverse one JSON to dictionary O(n)...
0
votes
1answer
243 views

Automated Hotfix Release with Semantic Versioning based off of Master Branch

I have a Python script that lives in my CI pipeline that is responsible for publishing branches and tags, publishing AAR's to our Maven Artifactory, uploading Javadoc, etc. We used to follow a ...
1
vote
3answers
951 views

Avoiding two if statements for same condition with common code in between [closed]

This is a problem I run into often, and am looking for the best solution. I will have code like this (python): def func(var, opt): if opt: var = var.set_opt(opt) result = var....
0
votes
2answers
310 views

Load JSON immediately for SPA instead of AJAX? (Python=>AngularJS)

I have access to a Response object in my python backend for returning HTML pages, etc. I can declare headers, content-type, etc. Instead of re-engineering the Python to use something like Django/...
-1
votes
1answer
93 views

How should I handle an object that has copies of another object?

I really hope this is a good place to ask this since the answers might be subjective, but here it my problem: This is probably irrelevant, but I'm working with Python and Django here. I have the ...
-1
votes
1answer
276 views

The pythonic way: replacing interfaces with ducktyping vs inheritence

tldr: I have consumer-like classes that require a number of pieces of information to do their job. It's an "all or nothing" kind of thing: the "producers" providing them with data need to provide all ...
0
votes
2answers
181 views

How to query database effectively with the same program millions times

I got a proprietary software (something like a DMS system) to process the documents in file system. The software provide very limited API to manipulate the contents of the documents in DMS but it ...
-1
votes
1answer
403 views

similarity measure between millions of documents [closed]

I have millions of documents(close to 100 million), each document has fields such as skills, hobbies, certification and education. I want to find similarity between each document along with a score. ...
-2
votes
2answers
982 views

Unit Testing a dictionary result

I often read that each unit tests should test one logical 'thing'. What do I do when the return value of a function is a dictionary? Usually I equality check the entire dictionary against an ...
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 ...
0
votes
2answers
721 views

Threads - When to use barrier?

Using python syntax, threading.Barrier(NUM_THREADS) establishes a control point and all participating threads block until all of the participating “parties” have reached that point. It lets threads ...
-1
votes
1answer
261 views

How would I integrate python code into Ruby code?

For instance, if I wanted to make a game which used a Python main file, but have another file with Ruby methods on it, how would I call those methods individually? Secondly, how could I make a Ruby ...
-1
votes
1answer
308 views

How to write a loose Python interface where subclasses can add extra data?

Here are two object makers I made: def make_assassination(i): neighbors = [] def test(graph): for n in graph.neighbors(i): neighbors.append(n) ...
4
votes
2answers
239 views

Design of multi-test function to validate a string

Assume that I wish to perform an action on a string (e.g., print the string) if, and only if, the string first passes several tests. The tests are diverse (and may even be complex functions themselves)...
3
votes
3answers
752 views

Are we overlooking bad effects of global state in this design?

I’ve read the answers to Why is Global State so Evil?, and I think the negative consequences do not apply in this situation. However, that’s what everyone says just before they get hit by a falling ...
2
votes
1answer
1k views

When to use coroutine over generator?

Pipeline processing of data can be done either, using generators only Example generator in pipeline: def grep(source, pattern=None): patternObject = re.compile(pattern) for line in source: ...
2
votes
1answer
205 views

ORM Classes and Separation of Concerns

I am using Python's peewee ORM to map my relational database, but I'm noticing that my models are starting to get bloated and I also seem to be violating separation of concerns. For example, my User ...
16
votes
4answers
5k views

Why coroutines are back? [closed]

Most of the groundwork for coroutines occurred in the 60s/70s and then stopped in favor of alternatives(e.g., threads) Is there any substance to the renewed interest in coroutines that has been ...
2
votes
2answers
338 views

Is “A programmer-defined type.” a right definition of “class” in Python?

In Think Python 2e "class" is defined as "A programmer-defined type. A class definition creates a new class object." But isn't a built-in type considered a class too? Using Python 3.4.0, the ...
1
vote
1answer
280 views

What is an indexer?

The C# docs have a page on indexers, which appears to use "indexer" to refer to the construct required to enable instances of a class to be accessed via square bracket notation. Indexers allow ...
1
vote
1answer
812 views

Python class naming: nested classes or composed names?

I encountered a scenario where I cannot decide on which is the best (or worst) naming strategy. The context is the following: a bracket (as in a tournament) made up of nodes, where is node is made up ...
5
votes
2answers
197 views

Stating Python version in repository when using pyenv-virtualenv

I came to know about virtualenv and pyenv a while ago, and used them separately for a while. Recently, while investigating best practices and tools for Python development I found pyenv-virtualenv. I ...
-2
votes
2answers
172 views

Why does Python have both “match” and “search”?

Python's re.match does exactly the same thing as re.search except it appends a \A at the beginning of the pattern (meaning match only at the beginning of the string). What is the point of having a ...
-1
votes
1answer
952 views

Multi platform GUI with a python/C++ core

I am aware of the existence of several threads on the topic, but I am looking for fresh hand-on experience, that I was unable to find. I have an application written in C++ (core, linear algebra and ...
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
3answers
239 views

Is isinstance a good way of identifying the type of an object?

I have a bunch of classes inheriting from Violation. These subclasses model violations to different rules: UsedTimeslot, TeamConstraint, etc... I need to check what kind of violation happened in ...
0
votes
1answer
66 views

Redesign factory to throw error on load time instead of on execution time

I am using a factory pattern to get objects that shouldn't be instantiated other than the factory class. These objects are of type ViolationType, which represent violations on a set of rule. Here is ...
1
vote
4answers
4k views

Dynamic dispatch from a string (Python)

Lets assume I have a string for a class name (or part of a class name), and I have implementation somewhere. All I want, is to be able to get an instance of a class with the name in the variable. For ...
0
votes
1answer
312 views

Instantiate a class from a config file. Where should the parse function go?

I have a class in python that is instantiated from the values of a (json) config file. I was wondering what is the best practise to do that (if there is a best practise and is not just a matter of ...
0
votes
1answer
851 views

Create object inside a method

Let's say my object needs to use an API to communicate with a device. The API call that I need is Api.do_something(). What would be the best way to solve this assuming that I need to call it only ...