As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
0 votes
0 answers
37 views

Python script for a Timeline widget for an audio player

I used to use the Tkinter scale widget for this, but it is limited in several ways. So I made a custom Timeline with the Canvas widget, which makes a more dynamically changeable Timeline. ...
Willem van Houten's user avatar
1 vote
1 answer
67 views

Protecting functions from empty DataFrames

Pandas likes to throw cryptic errors when you feed its functions with empty DataFrames saying nothing that would help you to identify the root cause. In order to ...
t3chb0t's user avatar
  • 44k
1 vote
1 answer
94 views

Mapping pandas' Series to dataclasses

I've got something really simple this time where I'm mapping pandas' Series to dataclasses with a oneliner helper function (as ...
t3chb0t's user avatar
  • 44k
9 votes
2 answers
1k views

Check validity of string, used return False too often? (CS50 plates.py)

Firstly, yes I'm a beginner. The code does function correctly but it looks ugly and I'm unsure if it is easily readable. I think my issue is the fact I've used 'return False' 5 times in a single ...
DW98's user avatar
  • 91
1 vote
1 answer
53 views

Rewritten Python script to split Insyde H2O firmware files

I’ve recently tried to update my Lenovo laptop’s firmware without installing Windows. I haven’t done it yet, but during their research someone on Matrix linked me to this page (original source, ...
schuelermine's user avatar
1 vote
3 answers
302 views

Get list of dates that are the last day each month in a date range

What is a good way to get rid of these if/elif/else inside the for loop? How you would improve readability of it? ...
Pabluez's user avatar
  • 113
2 votes
1 answer
88 views

How to better write this Python String manipulation

The following code creates a list of questions and options from a multiline string. ...
Kjobber's user avatar
  • 23
-1 votes
1 answer
62 views

Graph function in console

I created a program for drawing graphs of functions and want to hear ideas on "how to improve this program", because I'm only starting to write programs in Python. Would be very good to hear ...
Максим's user avatar
1 vote
0 answers
24 views

Storing multiple PyTorch tensors of different shapes with names that are not known by advance

I need to create a container for instances of torch.Tensor of different shapes, where I can call them by their name. It is a use case for a dict except that: I don't want to rely on the heavy syntax ...
Xiiryo's user avatar
  • 111
4 votes
3 answers
192 views

Fully-functioning chess game in Python

This post is in succession to this question. I have implemented all functionalities like castling, en-passant, pawn promotion etc. 50 move rule and 3-move repetition is pending. I would like my code ...
RandomCoder59's user avatar
2 votes
0 answers
39 views

Transfer data from a PLC on remote server into MQTT

Newbie here. I want to write a code that can open an SSH Tunnel for a remote server, then read out the data from a PLC and transfers it in JSON format via MQTT. This is my code, but I don't think this ...
mijki's user avatar
  • 21
3 votes
0 answers
34 views

TestAssignment class that checks for certain Git repository conditions

TestAssignment is a Python class designed to check certain conditions in a Git repository. It has several methods that check for the existence of required files, the initialization of a Git repository,...
Beki's user avatar
  • 31
3 votes
1 answer
53 views

Cancelling function execution with a ContinuationError

Although throwing excptions for control flow is a controversial topic there are some quite popular examples of using this anti-pattern like C#'s async routines throwing the ...
t3chb0t's user avatar
  • 44k
1 vote
1 answer
90 views

Create a list of all words in a string, the length of a word preceding it if even

...
Light's user avatar
  • 49
2 votes
1 answer
95 views

Making a game using python and pygame

I am making a game using python and pygame and as my game started to grow, in some of my classes the number of instance variables started to get big. Like in the settings class is like this: ...
Ake's user avatar
  • 123
0 votes
1 answer
58 views

Poetry Web Scraping in Python [closed]

I have a script that obtains urls that lead to a specific poem. This code current works and uses multiprocessing pools. I currently am getting restricted or blocked by some way from the website that I ...
watrgoat's user avatar
1 vote
1 answer
46 views

Counting Ads in webpage using XPath and EasyList in Python

I have the following the function the retrieves a given webpage and returns the number of adverts that are on the page using a shortened version of EasyList (17,000 rules). Using multiprocessing, this ...
Nathan Hoy's user avatar
0 votes
1 answer
39 views

HTTP scraper for Python Package

I'm trying to make my first Python package as a learning experience. There's a lot of things that I suspect I am doing poorly, but this post is specifically about my HttpRequest class. I made this ...
jtb's user avatar
  • 185
2 votes
1 answer
37 views

URL link scraper and analyser

I recently wrote a testing tool (called plink) for retrieving all the links from a website (and then retreiving links from the linked pages, and so on). Essentially,...
Jessica's user avatar
  • 818
8 votes
2 answers
431 views

Fourier Series of a given function

This is a very simple code that expresses a function in terms of Trigonometric Fourier Series and generates a animation based on the harmonics. I would like to know some ways to improve the ...
Lipe's user avatar
  • 83
4 votes
2 answers
203 views

Test generator I made for practice

Made this generator to practice using imports from other modules and better readability for coding. What could I have done better and what did I do wrong? File called test_generator.py ...
Beginner's user avatar
  • 129
-1 votes
1 answer
72 views

Optimize this Python Code

See the following equation: I have made the following code for it: ...
Murilo's user avatar
  • 99
1 vote
0 answers
46 views

Search Stack Overflow and GitHub for code in a specified language

This code is designed to scrape Stack Overflow and GitHub, pulling information based on a user-specified programming language and processing the data into a format for AI learning. It uses a number of ...
Robert3737's user avatar
0 votes
1 answer
65 views

Optimize system of equation function organizer with memory bottleneck in python

The Code So i have the following function that just gathers a system of equations so it can be input into the standard solvers of scipy ...
Klaus3's user avatar
  • 123
1 vote
1 answer
140 views

password crack dictionary

I am very new to coding and I just jumped in and am trying some things. I have been using the following code to create a password dictionary to crack wifi passwords with brute force but it will take a ...
Dustin Keith's user avatar
3 votes
1 answer
64 views

A simple web scraper for nature.com news articles

I have created a simple web scraper that fetches news article previews from nature.com and saves each article to a file containing the article preview text. I am learning independently, so I would ...
razzleDazzle's user avatar
4 votes
4 answers
544 views

Built a function to search a dictionary using key or value

I'm building an error handler which handles different kinds of errors arranged hierarchically. As part of that, I need a way to figure out what errors to send a recipient based on what their ...
mankand007's user avatar
3 votes
2 answers
162 views

Reduce a list by filtering out repeated elements

I want to reduce a list to its sequence. Or I could say I want to remove duplicate neighbors in a list. This Python code does what I want. ...
buhtz's user avatar
  • 207
0 votes
0 answers
36 views

Object oriented programming design pattern in python

I have classes subclassing from sqlalchemy.orm.DeclarativeBase class, I want to implement a class to be used as a (crud manager) : a class with crud methods that ...
Moad Ennagi's user avatar
0 votes
0 answers
57 views

Python script that parses GOG .hashdb files

I have some .hashdb files with names like goggame\-\d{10}\.hashdb in the installation folders in some of the games I have, and I want to extract information from ...
Ξένη Γήινος's user avatar
0 votes
2 answers
92 views

Find the shortest distance between two letters

I've been tasked with finding the distance between two letters in the alphabet. Below is my solution. My main concerns are if there is any shorter way to do this, and if there are any edge cases I'm ...
Linny's user avatar
  • 9,832
1 vote
1 answer
34 views

Fixing math library functions in Black-Scholes options pricing model

I've amended a code for the Black-Scholes formula for European pricing options found here at the bottom of the page and fixed the math functions accordingly. Unlike the code on the website, mine has ...
Jessie's user avatar
  • 113
2 votes
1 answer
120 views

Finite difference estimation of partial derivatives for arbitrary grids in python

I am currently working on testing some codes on python to solve differential equations by finite differences, but some problems and equations i am dealing with are: Too big to keep manually writing ...
Klaus3's user avatar
  • 123
0 votes
0 answers
49 views

Choose and locate a word in PDF

This code searches helps to choose a word and locate the word in a PDF, by highlighting it, and drawing a box around it. I found problem with the border of the rectangle, as it's thickness cannot be ...
hexapod's user avatar
1 vote
0 answers
59 views

Generic[type[Enum], Protocol[DataFrame]] Dataset with mapped to enum types

Below is my solution for managing multiple DataFrames, in an abstract enough way that it may apply to objects outside of a pandas.DataFrame hence the ...
Jason Leaver's user avatar
2 votes
0 answers
71 views

Snake game with constant time complexity algorithm

https://github.com/speedrun-program/constant_time_snake_game Memory efficient snake game with O(1) algorithm for snake movement and bug placement. Three grids are used: a grid representing the game ...
my_stack_exchange_account's user avatar
4 votes
1 answer
123 views

A simple stock exchange app

I've struggled to make a small stock project for almost 5 hours (biggest one so far). The project is simple: I've chosen a stock (Tesla in my case) and I've decided to get a message on my phone with ...
biscuit_delicious's user avatar
3 votes
1 answer
157 views

Calculate overlap of two datetime objects

I would like to find out how much time lays in between 22.00 and 6.00 o’clock for a given event per day. So if the event start at 21.00 and ends at 23.59 the result would be 1.59. For a start at 22.00 ...
kiaora's user avatar
  • 31
4 votes
2 answers
832 views

Mini project #2: Guessing a number loop

...
Uncharted's user avatar
  • 119
7 votes
2 answers
324 views

Mini project #1: Weight Converter

The goal of this program is to convert the given weight of the user LBS or KG into the opposite of what they used ex: 180lbs will convert to kg ...
Uncharted's user avatar
  • 119
4 votes
1 answer
62 views

number-guessing game - 1 through 30

I created this python number-guessing game and I have two concerns with it. The code works as intended with no flaws; however, I'm not too fond of the way I wrote it. It is messy, unorganized, and all ...
Andrea A. Venti Fuentes's user avatar
2 votes
1 answer
63 views

pygame bullet spawner

I am currently making a game for myself and i have a lot of code in a function which does almost the exact same thing with some minor differences. I was wondering if there is an way to optimize this ...
Fnzz's user avatar
  • 23
1 vote
1 answer
47 views

Python script for get minimum product price having maximum reviews

Technical task. user visits amazon.com website user fills out a search field with the product name and activates search ==> a page with search results is displayed. user looks for the product ...
lr_lennok's user avatar
1 vote
2 answers
61 views

UI of a text-based game with simple print statements

I am writing a simple text adventure in python that will eventually have the capability of running other text adventures within it, but my code is all over the place and the UI is terrible. What are ...
PeakMars's user avatar
1 vote
0 answers
187 views

Object detection YOLO v1 loss function implementation with Python 3 and TensorFlow 2.x

About the code Object detection YOLO v1 loss function implementation with Python + TensorFlow 2.x. It based on the Pytorch implementations below and re-implemented with TensorFlow based on my ...
mon's user avatar
  • 111
2 votes
1 answer
78 views

Update an Excel master workbook with values from new workbook

I have a master .xlsx file on which other spreadsheets depend. Each week, I export a new .xlsx file (from MRP) that may or may not be the same as the master. The columns are always identical. Rows may ...
Tee Mothy's user avatar
1 vote
0 answers
54 views

USACO Silver "Wormhole Sort" solver

I'm struggling a bit with a USACO silver question using python, http://usaco.org/index.php?page=viewproblem2&cpid=992. The question provides an unsorted list of numbers (cows) and a number of ...
Luke's user avatar
  • 11
2 votes
2 answers
104 views

DDD architecture pattern

I'm trying to understand the DDD architecture pattern. I wrote a simple project in which I tried to use DDD arch. Here are my doubts after implementing it: Does it make sense to use an ORM for a DDD ...
Minipami's user avatar
4 votes
1 answer
150 views

decorator to execute sqlite statement

I'd like to wrap all my sqlite statement functions with a decorator which collects the statement and the lists of values I will inject in place of placeholders in my statement (to avoid sql injection)....
FTG's user avatar
  • 95
3 votes
0 answers
97 views

System to automatically login to my university's Wi-Fi network using HTTP request

What is this? My university's Wi-Fi network requires students to visit a specific URL and login to the network before we can use the actual internet. This project replicates that same process by ...
eccentricOrange's user avatar