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

Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

2
votes
1answer
47 views

Why doesn't Python3 optimise variables assignments

I just read this SE question about parameter optimisation. I wondered if Python3 bytecode compilation does the same optimisation and this appeared not to be the case: >>> def f(a): return 2*...
-1
votes
1answer
22 views

How to read user input and at the same time execute periodic commands

How would I go about prompting user-input, while at the same time running timers, to periodically execute automatic functions. Pseudo-code to illustrate: while true { if input() OR timer(10) ...
-2
votes
1answer
74 views

Can i be two places at once in python cycle

I'm doing this in python, in case that changes anything. I'm trying to make a lamp/bit go 1-0-1-0 until the user says "okay" the "okay" should indicate that the user has found the lamp/Bit IRL. Now ...
2
votes
0answers
64 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
1answer
23 views

An approach to send the contents of a file on the server to the client in real-time

I have a relatively simple front in good ol' JQuery, that makes a POST Request to a Flask Python web server, that runs a Python script using the subprocess module. Here's the whole route for ...
0
votes
0answers
77 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())...
2
votes
1answer
155 views

Convince people not to use an “end-of-life” Python 3.X version

Context At my company, we have a major Python package which is written in Python 2. We are now planning to migrate it to Python 3 (we don't care about keeping it Python 2 compatible). I am a junior ...
0
votes
0answers
119 views

Compute and assign value to an attribute during class instantiation python

I am new to OOPs and don't have software engineering/computer science background. I am trying to define a class where I want to compute and assign a instance attributes under def __init__(): as ...
2
votes
1answer
86 views

Is it considered bad form to call `next` on the input sequence of a list comprehension?

I want to extract lines from a stream that are preceded by the character L. The list comprehension below does the job, but calls next on the stream inside the comprehension in a way I've never seen ...
162
votes
23answers
22k views

Programming cleanly when writing scientific code

I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical ...
0
votes
2answers
97 views

What is list of arrays in python?

I read in the Python time complexity page: A deque (double-ended queue) is represented internally as a doubly linked list. (Well, a list of arrays rather than objects, for greater efficiency.) Both ...
2
votes
3answers
223 views

Should I test the debug branch of my code in a unit test?

Lets say I have a function that gets a list of what files to send that are later send over a socket to some other pc. Now usually I keep track of what files have been sent and don't send these files ...
1
vote
1answer
287 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
0answers
268 views

Project structure with git submodules with common dependencies

I have two (and more in the future) Python projects that I'd like to package into a global package in order to import its modules and use them in another external projects in the future. This is how ...
0
votes
2answers
86 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 ...
-3
votes
1answer
325 views

UML Class Diagram for python flask application

I have developed a web-application using python's Flask framework and MySQL for my software engineering project assignment. My Instructor asked us to submit UML diagrams for the Project, I was able to ...
5
votes
1answer
140 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
387 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 ...
2
votes
1answer
237 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
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 ...
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 ...
0
votes
1answer
153 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 ...
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
181 views

MySQL linter: Letting an installed python package Integrate with a user-written python module

I'm working on a new style of database migration system that is coming along nicely. There is one last aspect of it that I want to finish, which is to enable MySQL linting. For background, this is a ...
0
votes
2answers
93 views

Efficiently computing and storing global state

I am working on a graph problem which is special in the sense that the nodes are computed only when required. This is because the graph is so huge that the entire graph won't fit in memory. So, in my ...
0
votes
2answers
262 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....
1
vote
1answer
927 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 ...
-1
votes
1answer
274 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
1answer
192 views

Convenience vs Decoupling/Composition

Let's say I have a small CD burning library written in Python, with a CD class and a Burner interface + implementation classes: # Module cd.py class CD: def __init__(self): self.folders = [] ...
-3
votes
2answers
144 views

How to name the parameter that holds `next` middleware in the chain?

I am writing an implementation of middleware chain in Python. Here is how a middleware function looks like: async def logger(ctx, next): print(f"Started doing stuff with {ctx}") await next() ...
3
votes
2answers
551 views

What is the right time to go for Code Refactoring, not optimization?

I've been working on a Python(Django)/JavaScript(AngularJS) based application for some time now.(I learnt all of these on the way, had previously been a Java only programmer)and have hit moments where ...
2
votes
2answers
335 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
0answers
630 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 ...
69
votes
7answers
15k views

How bad of an idea is it to use Python files as configuration files?

I've always used JSON files for configuration of my applications. I started using them from when I coded a lot of Java, and now I'm working mainly on server-side and data science Python development ...
7
votes
3answers
3k views

Why hasn't Python been optimized like modern Javascript implementations?

Modern Javascript implementations like V8 (Chrome), SpiderMonkey (Firefox), and Chakra (IE/Edge) all have JIT compilation, and a number of other optimizations to improve performance. Why doesn't ...
0
votes
2answers
421 views

Is extension of an abstract parent class with an abstract child class bad design?

Is it bad design to have an abstract class inherit from another abstract class? I have a single base node (class BaseNode) and 3 possible child node types (Sink, Process, and Source). Is the ...
1
vote
1answer
405 views

Pattern for subclass overload with different arguments

I'm in the process of writing an bidirectional, asynchronous socket server and server handler. The base handler class I'm working off of is as follows: class BaseAsyncSocketHandler: async def ...
2
votes
1answer
488 views

Custom language with mixed markup and Python, parsing in Python

I need a system for creating Python subclasses in a simple manner, and I was thinking of using a (custom) config language similar to json, xml, etc. Here's the initial structure I thought of (one ...
-2
votes
1answer
73 views

Python Syntax Format

Since I am new to programming, I just want to understand the format the built-in functions is represented in the documentations. This is the one from python bytearray ([source[, encoding[,errors]]])...
0
votes
2answers
693 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. ...
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 ...
3
votes
1answer
110 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 ...
7
votes
1answer
420 views

API design: stream objects vs. functions vs. messages

I'm designing API for a python library that accepts asynchronous input and produces the asynchronous output: various signals come in, and various signals are generated in response (there's no one-to-...
3
votes
2answers
4k 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 ...
1
vote
1answer
69 views

Is it possible to make this grouped permutation algorithm more efficient?

The following program starts with hundreds of permutations and shrinks them down to a small result set. Furthermore, I am only looking for the first valid result. What techniques can I use to make ...
8
votes
2answers
4k 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 ...
0
votes
2answers
9k views

Extract a number after a particular string

I have a string "series[Episode 37]-03th_July_2010-YouTube" and I want to extract the number which comes directly after 'Episode' (eg: 37 from Episode 37)the position of 'Episode 37' may not be fixed ...
1
vote
1answer
389 views

Suggestions for best design pattern for unittesting Excel readin in Pandas

When I read about unittests I keep reading that I shouldn't rely on external resources, but in some cases I would like to test reading in Excel files so I can be confident this portion of my code is ...
2
votes
1answer
2k views

Using Python, what's an effective way to wrap a command line utility?

I want to write a Python application that "wraps" a command line utility, passing through all parameters intact, except for the parameters that I choose to modify. I imagine there's an easy way to do ...
0
votes
1answer
1k views

How does one “secure” a python CLI-based application? [duplicate]

I have to provide a Python CLI-based program to one of my clients. I will give him both the compiled version (using py2exe or something simillar) of the application and the source code. The ...