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
2answers
108 views

How can I integrate Python code with c# code? [on hold]

I want to integrate code python (hierarchical clustering algorithm) with code C#. (The idea of ​​the project is to divide similar people and put them into classes using the algorithm. We use language ...
-2
votes
0answers
14 views

How can I customise loss functions in scikit-learn library?

How can I use customised loss functions in scikit-learn? For example, instead of using mean squared value, I want to use mean squared value multiplied by the true value of the sample? I have used the ...
-2
votes
0answers
27 views

Python static type checking and related libraries such as mypy. Do you or your team uses it? [closed]

Seeing function annotations and static type syntax introduced into Python3. I was curious to know how many developers using Python has found a need to use static typing style in their project. If ...
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
1answer
16 views

WebApp for ETL with visual mapping - read csv and map it to data model

a few years ago I wrote a python script for reading CSV, handling the headers, filtering data, renaming stuff via RegEx...bascially to do various ETL stuff. This was done using a exhaustive ...
2
votes
2answers
106 views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
-1
votes
1answer
64 views

Making the REST API to act as a playlist

Imagine the application I am building as a normal media playlist (Video / Music). On the client side, I select the files I want to play (Files are located on server), and I send its paths to the ...
-2
votes
0answers
15 views

Server/Agent web application design question

I am trying to develop an web app that will connect to an agent that will be downloaded and installed on a client. I want to be able to send remote commands to the agent Perform some operation on ...
0
votes
2answers
165 views

How compatible are data science notebooks with clean architecture?

Clean architecture decouples an app's core from the presentation/UI layer. The UI is just a plugin, replaceable (eg, web-based to desktop) without impacting the core. Many data science apps mix code,...
0
votes
1answer
42 views

Abstracting a set of services behind a common interface

Yay or nay? I have several related but separate services that are to be run in different processes. They execute a particular task unique to the service. Their call signature is similar, but the name ...
2
votes
2answers
69 views

Designing a Python API with defaults

I'm designing an API for a Python library. The user will create objects with several parameters. In most cases, the user will either leave these at their default values or will set them globally, for ...
27
votes
6answers
2k views

Turning a personal Python project into a releasable library

I'm an academic rather than a programmer, and I have many years' experience writing Python programs for my own use, to support my research. My latest project is likely to be useful to many others as ...
1
vote
3answers
153 views

How can I resolve this **kwargs antipattern?

I am a hobbyist programmer, working on a much more complex Python project than I've attempted before, which is in the form of a Python library. I find that I'm often passing **kwargs around (as ...
-2
votes
0answers
29 views

How to an fit sklearn model across many dataframes in parallel

I have a trained (e.g. fitted) machine learning model from sklearn in python. The model was fit using a fairly small dataset (~200,000 points) so I could easily fit the training data on a single ...
-2
votes
0answers
25 views

What is batch / batch size in neural networks? [migrated]

I have some problems with understanding of batch concept and batch size. I messed something up. First i start it consider based on convolutional neural network I heard two versions: 1. When batch ...
3
votes
3answers
297 views

What is the safe way of using keyword-only arguments?

Keyword-only arguments are arguments that can only be supplied to a function by keyword. In Python they are defined by a single asterisk in a function's signature. For example: >>> def foo(...
3
votes
1answer
111 views

Why would CPython logging use a Lock for each handler rather than one Lock per Logger?

While developing my own logging library, I studied the source code of the standard logging module of CPython. One of its features is that handlers are thread-safe. One can write logs to a file from ...
-1
votes
2answers
28 views

“private methods” vs method out of class in a python module

I have a module with the class Foo. Foo has three methods: The constructor(__init__()) An error handling method (_error_handler()) The method that actually does something. (run()) Then, I have a ...
3
votes
3answers
139 views

refactoring function to have a robust design

i am having a simple app example here: say i have this piece of code which handles requests from user to get a list of books stored in a database. from .handlers import all_books from flask import ...
1
vote
1answer
79 views

How to organize my test functions?

I'm writing a software application of a few thousand lines of code (in Python), and in order to keep the whole thing together, slowly but certainly the need for unit tests (and later, other types of ...
0
votes
2answers
43 views

Setting up data for integration tests: using SQL queries or APIs calls

We a have test repo outside of the app repo and we can generate data by either having direct SQL queries or through API calls (http requests). We've been entertaining the idea of switching over to ...
0
votes
1answer
92 views

What determines the internal order of a Python set?

When I read about sets in Python, it is always mentioned that they return items in an arbitrary/random order. What exactly causes this "randomness"?
-1
votes
1answer
23 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) ...
1
vote
2answers
58 views

Building a plugins-based code in Python

I have a program which perform different actions depending on the plugins that are passed. For example, python main.py -m foo -m bar will perform the actions of foo and bar. The structure of the ...
1
vote
2answers
72 views

CLI tool with overloadded structure

I have a python CLI tool that my department uses to process some excel file aided by a yaml. I tried to diagram a basic work flow here: Step 1: User downloads a xlsx, puts it in a file, runs tool --...
-1
votes
1answer
80 views

Would I need a web framework if the app is running locally and not in the net?

I need to make an Employee Payroll application and the client specifically stated that the application will run on their computer locally and will not be hosted anywhere in the internet. I can code ...
0
votes
1answer
128 views

Is Java-like restrictiveness OK Python style?

Good Pythonic style is much looser than Java's uptight restrictiveness: In Java, good style means private on methods wherever possible, all fields encapsulated, type declarations, defined ...
0
votes
1answer
64 views

Making execution of Python script fool-proof beyond adding shebang

Assume that a Python package (available via PyPI) is too difficult for novice users to utilize. Specifically, typing python2 path_to_package/start_GUI.py in the command line, which opens a TKinter GUI,...
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 ...
1
vote
1answer
115 views

What are the potential dangers of using this kind of reflection cheat in Python?

In a program I'm working on, I need to do a substantial amount of real-time reflection in order to maintain a list of known "attributes" throughout the program structure (for use by a sort of "virtual ...
-2
votes
1answer
75 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 ...
0
votes
1answer
64 views

Python deployment to corporate shared filesystem

We are developing some Python applications (mostly CLI) for use only internally in the company. Hundreds of machines on which the applications may run. Instead of installing the apps on each machine, ...
-1
votes
1answer
36 views

How do I test my python package (for distributing) for different versions of python?

I have made a small library/application that I intend to distribute. However I want to find out what versions of python can handle my script ? Given that there are many minor and micro versions and ...
1
vote
2answers
117 views

Dependency injection in a loop?

Suppose I have a loop (in Python syntax): xml = "<x>...</x>" for i in arr: j = f(x) # some complex computation obj = Class(i, j) xml = obj.run(xml) Does it make sense to use ...
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 ...
1
vote
2answers
156 views

DRY or not to DRY in SDK

I'm making contribution to an opensource project by one of the leading hypervisor providers and I have noticed that there is awfully lot of repetition. Below is what I mean by it, imagine that they ...
-2
votes
1answer
150 views

Possible motivation of having a minimal main function as in CPython source code?

I was recently looking through the CPython source code and noticed something rather intriguing: /* Minimal main program -- everything is loaded from the library */ #include "Python.h" #include "...
0
votes
1answer
93 views

Should I access the backend directly or through an API layer?

Please allow me to ask my question using an example where we have a database with flight data and I want to make a web app where users can search, select, and book a flight. I wrote some classes ...
2
votes
1answer
24 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 ...
-1
votes
1answer
94 views

How to ensure separation and inward dependencies between architectural layers in Python?

Suppose a large-scale project is being developed in Python 3.7. Some layered architecture is chosen: "clean architecture", "onion" or "hexagonal". The Dependency rule in it only allows inward-...
5
votes
2answers
298 views

How to maintain a low dependency version of a project?

I am not as technically skilled as most people asking here. I use git to backup my own work to an online repository, but I rarely use it in collaboration, and don't know much more than the basic ...
1
vote
1answer
66 views

Create and implement new encoding

I'm working on a project with huge files that contain only the set {[0-9],.}. Encoding in UTF-8 or ASCII make huge files. I wonder if I could find a way to encode in only 4 bits (make those file 16 ...
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())...
-2
votes
1answer
175 views

Calculating longest trip [closed]

I have been stuck on this question for some time. Could you guys direct me or point me to the right direction for solving this problem ? We would like to encourage passengers to experience the joy of ...
2
votes
1answer
235 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 ...
-2
votes
1answer
75 views

Delegation pattern in Python: is it unpopular? Is it considered not Pythonic?

As a Ruby/Rails person, I often deal with method delegation. It's often convenient to delegate a method to a composed object or a constant. Ruby even has a def_delegator helper method to easily build ...
0
votes
1answer
70 views

How to properly decouple the service layer from the user interface layer, if the service layer needs to interact with the user?

In my program, I have a long-running function from which I would like to interact with the user for various reasons: Giving status updates ("Downloading file /foo/bar.png") Displaying warnings ("File ...
0
votes
1answer
112 views

Parameters vs Specialized functions

Trying to figure out which structure is cleaner between using a specialized function or using parameters to accomplish the same thing (see code example below). Essentially, I can reduce the number of ...
1
vote
3answers
91 views

Python - Proper way to call a function within a class based on a certain argument passed on

Let me illustrate with an example. Say I want to create a class Returns that generates the returns of a stock for example. Returns can be arithmetic or logarithmic, and I want to be able to choose at ...
-1
votes
2answers
77 views

How should docstrings be used in modules with one class?

When authoring OOP code, sometimes you have a file that only contains one class, and nothing else. PEP8 says that all modules and all classes should have docstrings outlining what they do. But in ...