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 ...
0
votes
2answers
1k views

Python - best way to have interdependent variable in a class

Newbie Python questions: I want to model something that can have a several inter-connected instance variables and if I set one, I want to recalculate the others. Any can be set. E.g. a circle - each ...
-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 ...
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 --...
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
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 ...
15
votes
5answers
7k views

Algorithm for flattening overlapping ranges

I am looking for a nice way of flattening (splitting) a list of potentially-overlapping numeric ranges. The problem is very similar to that of this question: Fastest way to split overlapping date ...
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 ...
-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
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 ...
8
votes
1answer
2k views

Making API calls with celery

I'm designing a system for a client where the requirements are: they upload a JSON file (one object/line) make a call to an API with the JSON object as the payload record the state (success/failure) ...
70
votes
5answers
123k views

Is Python Interpreted or Compiled?

This is just a wondering I had while reading about interpreted and compiled languages. Ruby is no doubt an interpreted language since the source code is processed by an interpreter at the point of ...
-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 ...
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 ...
75
votes
6answers
93k views

Single quotes vs double quotes [closed]

I just started a job where I'm writing Python after coming from a Java background, and I'm noticing that other developers tend to quote strings using single quotes ('') instead of double quotes (""). ...
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
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
1answer
672 views

How to pass complex ORM objects to background workers?

I've been wondering something about how we pass complex ORM objects to background workers — in my case, Django models and Celery, but this could apply to any similar background processing framework. ...
0
votes
1answer
101 views

MongoDB mapreduce

I'm new to programming and mongoDB and learning as I go, I'm attempting a mapreduce on a dataset using mongoDB. So far I've converted the csv to json and imported it into a mongoDB using compass. In ...
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 ...
10
votes
3answers
1k views

How should private dependency links be handled in setup.py

At work we use a private pypi server. This pypi server is specified as a dependency link: ... from setuptools import setup config = ConfigParser.ConfigParser() rc = os.path.join(os.path.expanduser('~...
1
vote
1answer
400 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 ...
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(...
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
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 ...
2
votes
1answer
108 views

Optimal Simplification of Transposition Products

I am looking to take a product of a large number of transpositions, and boil it down to a smaller number of products. I have the following code, and would like some input on efficient ways to boil ...
1
vote
3answers
731 views

Better to use Global Variable or Coroutine in general?

Is it better to store state in a global variable or in a coroutine, specifically in Python? I don't understand the best practice here. For example, consider a simple Flask script: from flask import ...
3
votes
1answer
610 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' ...
-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 ...
6
votes
2answers
2k views

How does a symbol table relate to a namespace?

The official tutorial uses the term symbol table in a few places where I would expect the term namespace. 1. Defining functions The execution of a function introduces a new symbol table used for ...
0
votes
1answer
816 views

How to distribute a project with all its dependencies?

We are developing a system for a customer that does not want to allow installation of packages from outside repositories. The project is in Python and defines its dependencies via setuptools; most of ...
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 ...
165
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 ...
-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 ...
4
votes
2answers
346 views

Method object creation in Python data model

I've been reading the article on the data model of Python on its Reference website, and have been confused about this part: When the attribute is a user-defined method object, a new method object ...
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 ...
4
votes
2answers
4k views

When should I worry about freeing objects from memory in Python?

I've been reading a few different guides and tutorials, as I am interested in learning some best practices of programming. I was reading the How to be a Programmer guide, and there is a section about ...
19
votes
6answers
7k views

Best practices in comment writing and documentation

Commenting nowadays is easier than ever. In Java, there are some nice techniques for linking comments to classes, and Java IDEs are good at making comment shells for you. Languages like Clojure even ...
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 ...
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 ...
6
votes
1answer
494 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 ...
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
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
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) ...
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 ...
1
vote
1answer
126 views

Logging an application in Python

Recently I have worked in a small standalone Python console application and have inherited some code from another team. Although some of us have written small Python scripts in the past, none of us ...
104
votes
10answers
76k views

Why is Python used for high-performance/scientific computing (but Ruby isn't)?

There's a quote from a PyCon 2011 talk that goes: At least in our shop (Argonne National Laboratory) we have three accepted languages for scientific computing. In this order they are C/C++, ...
17
votes
4answers
1k views

Is the benefit of the IO monad pattern for handling side effects purely academic?

Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me. My (limited) understanding of functional programming is that state/side effects ...
2
votes
3answers
763 views

How much should I break up my unit tests?

I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). ...