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

Extract column values from pubsub output using apache beam in python

I am trying to extract data from the PubSub subscription using Beam and finally, once the data is extracted I want to do some transformation. Currently, it's in bytes format. I have tried multiple ...
5 votes
2 answers
125 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 ...
  • 51
-1 votes
0 answers
17 views

Python code for Timetable generation needs to be reviewed for the error [closed]

this code is to generate a time table for the school. import random class SchoolTimetable: def init(self, num_teachers, teacher_subjects, teacher_classes, periods_per_subject): self.num_teachers = ...
-4 votes
0 answers
27 views

Shrinking my pygame draft creating acceleration for sprites when a key is pressed [closed]

I did a test program that simulates acceleration of a sprite when the key is pressed the velocity increases until a max speed is reached. When no key is pressed a slow deceleration is occuring. The ...
  • 1
1 vote
1 answer
42 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, ...
-1 votes
0 answers
52 views

Using another class's methods without inheritance but type hinted otherwise [closed]

I have a class which "inherits" str's methods using the __getattr__ dunder method instead of true inheritance. For ...
  • 99
1 vote
3 answers
104 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? ...
  • 113
2 votes
1 answer
67 views

How to better write this Python String manipulation

The following code creates a list of questions and options from a multiline string. ...
  • 23
-1 votes
1 answer
47 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 ...
-4 votes
0 answers
26 views

im new to python and i was wondering why this wont add to anything over one [closed]

x = 0 if x == 0: + 1 if x>1: print (">1") else: print("nope") This is the code to the thing i am trying to program im just using a ...
-1 votes
0 answers
32 views

Implementation for Continuous Bag of Words (CBOW)

I was doing this while learning NLP and this one is so slow I found that there is build in code in word2vec library and it finished in seconds while this code took around an hour for 3 ephocs (data is ...
1 vote
0 answers
13 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 ...
  • 111
4 votes
3 answers
122 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 ...
2 votes
0 answers
18 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 ...
  • 21
3 votes
0 answers
32 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,...
  • 31
0 votes
0 answers
30 views

Solving 2D Poisson Eq with Dirichlet BC's in Python [closed]

Question: I am trying to solve the following PDE: $$ \begin{align*} u_{xx} + u_{yy} = \begin{cases} - \cos(x) \quad -\pi/2 \leq x \leq \pi/2, \\ 0 \quad \text{otherwise} \...
  • 177
1 vote
1 answer
73 views

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

...
  • 49
-1 votes
0 answers
34 views

Decorate functions such that the outer function flattens all its input arguments before passing those input arguments into the inner function [closed]

The code to review mostly at the bottom-end of this question. Use cases are located at the top-end of this question. Use Case One ...
1 vote
1 answer
76 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: ...
  • 13
0 votes
1 answer
49 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 ...
1 vote
1 answer
35 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 ...
0 votes
1 answer
36 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 ...
  • 185
2 votes
1 answer
26 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,...
  • 818
8 votes
2 answers
396 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 ...
  • 83
4 votes
2 answers
185 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 ...
  • 109
-1 votes
1 answer
64 views

Optimize this Python Code

See the following equation: I have made the following code for it: ...
  • 99
1 vote
0 answers
29 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 ...
0 votes
1 answer
62 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 ...
  • 113
1 vote
1 answer
71 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 ...
3 votes
1 answer
56 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 ...
3 votes
4 answers
530 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 ...
3 votes
2 answers
155 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. ...
  • 197
0 votes
0 answers
32 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 ...
0 votes
0 answers
46 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 ...
0 votes
2 answers
80 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 ...
  • 9,719
1 vote
1 answer
26 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 ...
  • 113
1 vote
1 answer
80 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 ...
  • 113
0 votes
0 answers
45 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 ...
1 vote
0 answers
43 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 ...
2 votes
0 answers
53 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 ...
3 votes
1 answer
118 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 ...
3 votes
1 answer
90 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 ...
  • 31
4 votes
2 answers
784 views

Mini project #2: Guessing a number loop

...
  • 119
7 votes
2 answers
289 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 ...
  • 119
4 votes
1 answer
49 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 ...
2 votes
1 answer
55 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 ...
  • 23
1 vote
1 answer
42 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 ...
1 vote
2 answers
59 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 ...
1 vote
0 answers
38 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 ...
  • 111
2 votes
1 answer
71 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 ...

1
2 3 4 5
302