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.

0
votes
0answers
26 views

Maintaining data: Unprocessed data, processed data, and results from processed data

I have built a python process which automates some portion of handling support tickets in Salesforce. I use selenium to extract all open support tickets and stores them in an archive. From that list,...
1
vote
0answers
92 views

Implementing an iterator vs. looping over a list

I want to loop over a number of rows in a database and I have implemented an object in order to access the rows. Now when using this object I am not sure about the best practice. Implementing an ...
-3
votes
0answers
70 views

Why is Python an “interpreted language”? [duplicate]

Why aren't compilers for Python common? And why interpreters for C aren't common either? Assuming that a compiled-to-machine-code Python program runs faster, why aren't Python compilers common? After ...
0
votes
2answers
206 views

Exceptions versus guard clauses

I'm trying to get my head around Python exceptions. I've read quite a bit on the topic but can't get clear answers to some questions. In particular, I'm still not sure whether to use exceptions or ...
0
votes
1answer
30 views

Should i use a separate droplet(DO) for the API?

I have a little app(PHP) that uses data from a third party. That data is processed constantly and saved into a database. And now i want to create a RESTful API to allow access to that data. Should i ...
0
votes
1answer
45 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 ...
0
votes
0answers
56 views

Generating fake number for a 25 digit PII number in a file containing millions of rows

I have to expose some sensitive data containing a PII column that has a 25 digit number. Rest of the columns aren't PII data. This is done such that the data can be safely shared to the larger ...
-3
votes
1answer
138 views

Why constructor inheritance is not supported in Python? [closed]

Consider the case where I have the following classes, class A: def __init__(self): print("Class A") class B(A): def __init__(self): print("Class B") b = B() The expected ...
0
votes
2answers
104 views

How can we make a UML diagram (or something similar) for a project which doesn't contains classes (like non object oriented)?

I am working on a python project and I didn't use classes but created different modules and added functions in them. Now I need to draw a diagram to describe the project/application for a paper. I ...
-1
votes
1answer
240 views

What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
5
votes
2answers
16k views

Can python and php work together?

I am having a mobile app created for ios. The developers built the app in php. The app requires an algorithm so I found another programmer to develop it. The algorithm programmer built the algorithm ...
1
vote
2answers
63 views

Unit conversion of input to/output of public functions/methods

The question/s I'm working on a small scientific Python package. Many of the public methods it is going to offer will have to deal with dimensional input. A wavelength, for example, which could be ...
128
votes
1answer
145k views

Python file naming convention?

I've seen this part of PEP-8 https://www.python.org/dev/peps/pep-0008/#package-and-module-names I'm not clear on whether this refers to the file name of a module/class/package. If I had one example ...
0
votes
3answers
97 views

Options for parsing input that will include math

I'm working on a program that takes in user input which often includes things like math.sqrt(), imaginary numbers, multiplication, division, and similar (basically, standard math plus imaginary ...
0
votes
0answers
8 views

Attempted “__set__” operation on ASN.1 schema object [migrated]

I'm currently using IronPython to execute Python code in my .NET project. The issue, however, is that I am receiving an error: Attempted "__set__" operation on ASN.1 schema object This is the C# ...
-2
votes
0answers
34 views

How to Evaluate the Best Tech for a Project [duplicate]

I hope this question isn't too subjective for SE, but I feel that a precise answer or approach can be given. First off, I have spent some time researching this issue but I am posting the question ...
10
votes
3answers
3k views

In Python 3.4+, why should I use namedtuple over SimpleNamespace when not using dict, they seem very similar

At one point or another you might come over functions with a lot of arguments. Sometimes it makes sense to combine some of the arguments into super-arguments. I've often done this with dicts, but now ...
0
votes
1answer
52 views

How do I save user data in a file and populate the GUI/Software based on that file?

So I'm developing a GUI that consists of many widgets such as checkbox, buttons, radio-buttons, combo-box using Python Qt5. This GUI is to perform some calcualtion based on user choices. I'm trying to ...
1
vote
1answer
27 views

Setup pipeline to analyze data stored in web app DB

Background: So there is a (Ruby) web app with a production Postgres DB (hosted in the cloud) I would like to run some machine learning algorithms in a Python setting on the production data and (...
1
vote
2answers
88 views

Architecture for RESTful API and a web admin

I am trying to build a RESTful API (using Flask) that will be later consumed by a mobile application. I also have a requirement to build a Web Admin. The Web Admin will have functionality that will ...
0
votes
1answer
25 views

Most readable way of generic views placement

What are your suggestions on placing many generic views? Let's consider a classic situation where I have many generic views for CRUD for given models. What is the best way to place them in views.py? ...
1
vote
1answer
144 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())...
1
vote
1answer
20 views

Django - should I create related objects immediately or on demand?

Let's say you have a ForeignKey MyModel.related_model and this related_model has all fields either null=True or default=something. Like User.userprofile which I use on several places in my project. ...
47
votes
4answers
53k views

Should I pass in filenames to be opened, or open files?

Suppose I have a function that does things with a text file - for example reads from it and removes the word 'a'. I could either pass it a filename and handle the opening/closing in the function, or ...
-1
votes
2answers
101 views

How would you design the abstraction/class(es)/component(s) of a third-party service/api used in your application?

Lets say you were designing a Twitter client for people with people could see tweets and post tweets? How would you design the twitter api abstraction? Many of the api wrappers I've seen feature an ...
1
vote
0answers
44 views

Extensible / Plugin Architecture in Python - overwriting methods deep in the inheritance tree?

Current situation I'm developing a test-framework in python for end-to-end tests for a large ERP application. The AUT (application under test = ERP system) is structured in modules and provides a lot ...
0
votes
2answers
105 views

Which is better approach - using subprocess vs communicating over socket?

I have been working on a python project for sometime which has been structured in following manner: We have a function like this: def execute_cmd(cmd): (out, err) = subprocess.Popen(cmd)....
7
votes
2answers
2k views

best way to install local package into docker image

I have a python package that I wrote and I want to use it within multiple docker builds. However, I can't just install my local package situated outside of Dockerfile folder. And I don't want to ...
-1
votes
1answer
106 views

time complexity for 3 foor loops different leangth [duplicate]

I have this method arr // input new_ seq = [] for i in arr: new_seq.append(i) __new_seq = [x for i, x in enumerate(arr) if x not in new_seq] for j in __new_seq: new_seq.append(j) ...
2
votes
3answers
308 views

How to deal with configuration files that are becoming too complex

There is a db with tables of genes. And these genes would need to be annotated based on the client's needs. So if a gene matches condition x, then add a new column y and value z to that gene. Every ...
0
votes
0answers
34 views

Neural Networks object creation from OOP perspective [duplicate]

Let's say that I have a class representing the Neural Network. The neural network is composed of three bigger units: a subpart_1, subpart_2 and subpart_3, being called in such a way, that the output ...
7
votes
3answers
3k views

Why is the _replace method of Python namedtuple classes protected?

In the section Method Names and Instance Variables, the Python Style Guide (aka PEP 0008) says, "Use one leading underscore only for non-public methods and instance variables." Why then, does the ...
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) ...
2
votes
1answer
193 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 ...
0
votes
1answer
40 views

Combining web app and CLI to python package

I'm writing a program in Python that has two different entry points. There's a CLI that processes some data and needs to be installed to run hourly on a server, this populates a database. There's also ...
1
vote
1answer
67 views

How to avoid confusion with possible referenced before assignment when it won't be (Python) [closed]

I have some code equivalent to this: state = True if xyz: state = False try: value = foo() except: handle_exception() state = False if state: bar(value) On the last line it will ...
0
votes
1answer
128 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 ...
2
votes
1answer
1k 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
127 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
411 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 ...
8
votes
4answers
5k views

Pattern for requests with long response times?

We are currently maintaining a homegrown python "web server" where generating the response for some requests can take a very long time mostly due to heavy computations - these requests are basically ...
-3
votes
1answer
91 views

Pythonic way of writing `for my_var in my_iterable` [closed]

A very common pattern in python is: for something in ['an', 'iterable']: func(something) I almost always see the iterable as a list (like in this example), but it could very well be a tuple, set,...
2
votes
1answer
111 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 ...
-4
votes
4answers
123 views

Creating one function for multiple purposes vs multiple functions for one purpose each [closed]

I have one function that is used to compute distances of an object in 3 different ways. Is one of the following two methods considered better practice: Creating 3 different functions, one each for ...
15
votes
6answers
3k views

How to implement float hashing with approximate equality

Let's say we have the following Python class (the problem exists in Java just the same with equals and hashCode) class Temperature: def __init__(self, degrees): self.degrees = degrees ...
48
votes
4answers
31k views

Why do iterators in Python raise an exception?

Here's the syntax for iterators in Java (somewhat similar syntax in C#): Iterator it = sequence.iterator(); while (it.hasNext()) { System.out.println(it.next()); } Which makes sense. Here's the ...
0
votes
0answers
38 views

Querying the domain model

Background: I am working on a document classifier which needs to classify document based on some keywords. The list of keywords and the category is provided as the configuration parameter. The ...
0
votes
0answers
70 views

Should I repeat unnecessary else condition? [duplicate]

I would like to know what the best way is for dealing with a situation where I repeatedly check a condition within a function using an if-elif-else chain, and if the condition is else, I raise an ...
3
votes
1answer
663 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' ...
4
votes
2answers
3k views

Which approach for integrating Python code into a mainly Scala application did you use a second time because it was successful? [closed]

I have a mainly Scala application and I am interested in approaches to integrating Python code into this application in a way that is proven by you personally to be successful. In this context ...