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.
15,595 questions
-5
votes
0
answers
51
views
unet type Segmentation Model training extremely slow
I am trying to implement unet++ for the next day wildfire dataset, but my training process became extremely slow on colab free gpu. I wonder if there is any bug in my code that I am not aware of. ...
5
votes
5
answers
920
views
Function in Python that encrypts and decrypts, taking string to list and the other way around
I'm new on Python, so I'm looking at these YouTube videos of Python projects to practice, and I saw this one of a Password Manager with encryption, but the encryption part couldn't use password, ...
5
votes
4
answers
402
views
Absolute-path Python function taking as argument a path relative to the directory of a script (.py) or Jupyter notebook (.ipynb) file
I'm currently still in the early stages of learning Python and Jupyter notebooks, and I wanted to ask if the following code for returning absolute paths relative to the directory of a script (...
5
votes
3
answers
540
views
Ping sweep of IP subnets
I made a ping sweep for the first time, and I want to do better. What do you think that I might be missing?
...
-5
votes
0
answers
38
views
Analyze a directory recursively what file types (file extensions) they contain [closed]
Aim
My aim is to analyze a (big) (sub)directory and just find out what file extensions all files have there (recursively).
Additionally, these conditions apply:
I am on Windows, but I could use WSL ...
9
votes
2
answers
603
views
Find the nearest school to you
I have created a text-based program that finds the nearest school using your coordinates.
The CSV DataFrame is available through LimeWire.
I'd like to know how I can improve it.
...
5
votes
2
answers
235
views
Transform dataset coordinates from Lambert Conformal Conic projection to WGS84
I am trying to convert a dataset which has a Lambert Conformal Conic projection to the classic WGS 84 with Python. Unfortunately, the dataset does not have a defined EPSG code, but the general ...
5
votes
3
answers
597
views
News API in Python - Take II
From my previous post, I tried to take into account all of the nice answers made by Kate, Chris, J_H, Booboo and mudskipper
Changes made
In short, I attempted to apply all of the following:
API key ...
8
votes
5
answers
1k
views
News API in Python
Why I made it
I’m building a voice assistant and thought it would be great if it could deliver news updates.
What it does
It cleans up the user’s query, determines whether it refers to a news category ...
4
votes
2
answers
269
views
Create Frame Widget with Pygame
I developed two custom UI components with Pygame: a Button widget and a Frame widget. After placing the Button inside the Frame, I encountered an issue with the Button’s collision detection.
...
5
votes
4
answers
486
views
Substitute patterns with values from lists
I was looking at a Stack Overflow question and got somewhat carried away with improving the solution, well beyond the scope of that question.
In summary, we have a string such as
...
6
votes
3
answers
656
views
ASCII-based Lightweight Browser with Clippy-Style Helper in Python (Updated)
This question used to contain a mistake in the code, so I had to debug and reformat it. This is the correct version.
Why I made it
A friend and I wanted to make a lightweight browser, since our ...
1
vote
2
answers
128
views
ASCII-based Lightweight Browser with Clippy-Style Helper in Python [duplicate]
Note that this is the original version which has not been formatted to comply to PEP-8 and contains an error in the code. Please visit the updated version instead to post answers, comments and/or cast ...
7
votes
3
answers
819
views
Optimizing real-time ASCII playback in Python when each frame is fetched as a PNG via GET
Why I made it
I wrote this script for one simple purpose: to Rickroll my friends.
How it works
This is the workflow:
It fetches a .png frame from a PHP endpoint on a website I own. The frame number ...
4
votes
2
answers
690
views
Unicode-based platformer game in Python (Updated)
I already asked this question, but the script I provided was not compliant to PEP-8, so I rewrote the script for better readability.
I'm making a platformer game called Uni where this small character ...
6
votes
3
answers
1k
views
Unicode-based platformer game in Python
I'm making a platformer game called Uni where this small character has to go as high as possible, in which the player constantly has to choose between jumping (W) going left or right (A-D) climbing ...
3
votes
5
answers
648
views
List folders with size
This code below aim to listing all folders in one directory and get size of each in byte. It uses only pathlib module for that.
...
0
votes
0
answers
66
views
Сreating a digital twin of the enterprise
I am creating a program to create digital twins of enterprises. I am using the Simpy framework for this purpose.
I'm creating a universal system that can model almost any enterprise, but I have a ...
2
votes
3
answers
1k
views
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
I am working on this LeetCode problem where I have to count the minimum number of operations to make all elements in an array equal to zero 3542. Minimum Operations to Convert All Elements to Zero
...
7
votes
3
answers
793
views
Custom Error Exception Class in Python
I've written a class to handle my custom errors in Python. The idea is to simplify raising exception with custom messages, all you should do is raise the class and pass it a message.
Everything in the ...
4
votes
1
answer
229
views
Use z3py to solve one logic constraint puzzle
I decided to practice by modeling some simple, hand-solvable problems using z3py. Below is an example:
...
4
votes
3
answers
87
views
Optimizing DataFrame iteration when generating large hierarchical text files
I have a custom object which stores dataframes in memory given a certain hierarchy, and I want to store this data in a file while maintaining the hierarchy. This hierarchy involved parents, children, ...
8
votes
3
answers
134
views
Test to ensure CGI can be invoked on a local server
I am writing tests for legacy software which has a dependency on CGI scripts on a remote machine.
Mocking the dependency would entail modifying the code under test, which is a thing I cannot do at the ...
6
votes
2
answers
505
views
Tilemap implemented in pygame
This code requires:
tile map exported as .csv file
tile set as .png
knowing tile size
knowing the rows and cols of the tile set .png
For example, this tileset has 2 rows and 6 cols
...
8
votes
3
answers
2k
views
Replacement for "make" in Python
I'm working on a replacement for make written in Python. Instead of a Makefile, you create a Wormfile.py. This file gets imported dynamically and a Context object ...
3
votes
4
answers
2k
views
Python project to scrape webpages and build text datasets for ML purposes
Context
I'm returning to Python development after a break and actively learning AI/ML. As part of my learning journey, I'm building a dozen pet projects to strengthen my skills. This is my first ...
6
votes
3
answers
982
views
Moving ball simulation within a donut
How do I optimise my code more?
The goal is to have my code work with more than 200 moving balls, but that takes forever right now and doesn't look smooth at all. Furthermore, I can't get the sizing ...
3
votes
1
answer
76
views
Managing a global backend/device state when making a deep learning framework
I have been making a deep learning framework modelled after Pytorch in pure Python. I have made good progress but my framework is currently not seamless to use because the end user of the framework ...
11
votes
5
answers
921
views
Python program that iterates over audio files with a progress bar interface
I have a utility that updates, transcodes and renames audio files. Previously I used a function that simply yielded every file that was a good match (based on file extension).
As some tasks can take ...
10
votes
4
answers
669
views
Split flap clock stepper code
I've built a Split Flap Clock, and the code has grown quite a lot, and although it does work in its current state, I am wondering if it could be cleaned up.
The whole thing runs on an ESP32 and is ...
2
votes
2
answers
110
views
Heat Diffusion Equation Solver
I'm implementing a numerical solver for the 1D diffusion (heat) equation using an iterative method. The initial temperature distribution is a Gaussian profile, which should theoretically smooth out ...
4
votes
2
answers
510
views
Finding a sequence of xors to change a to b
I'm resolving a problem from CodeForces: C. Beautiful XOR. This is what the code is supposed to do:
You have two numbers a and b.
You must transform a into b using XOR operations (...
2
votes
2
answers
115
views
Calculation of liquid propellant nozzles
I'm calculating the injectors, and I've added the complete calculation code and tested it using pytest. Can you suggest a better way to structure the code so that I ...
6
votes
2
answers
640
views
Python calculator application
What do you think about my calculator application in Python? Are there any hidden bugs that I haven't noticed yet? Let me know about them.
Note: to be able to run this program you need first to ...
9
votes
4
answers
812
views
Find the smallest semiprime satisfying a bunch of conditions
The purpose of this code is to find the smallest semiprime \$s = a b\$ satisfying a bunch of conditions stated in the Math.SE question What is the smallest "prime" semiprime?. The conditions ...
6
votes
2
answers
462
views
Number-guessing game on command line
I am just starting coding, and this is my attempt at the famous number-guessing game. Any and all feedback and criticism is greatly appreciated.
...
4
votes
4
answers
1k
views
10
votes
4
answers
1k
views
Yet Another Python Weather Visualizer using Open-Meteo
As a personal project to build my portfolio, I've created a simple weather app that displays temperature, precipitation, and wind for any given city. This is my first time building a GUI using ...
7
votes
3
answers
469
views
Polars crosstable between two variables in a dataframe
I wrote a function that computes the cross tabulation between two variables in a polars dataframe.
It supports absolute values, row percentages, column percentages ...
5
votes
5
answers
1k
views
Check whether a binary tree is symmetric
I implemented a recursive solution that compares the left and right subtree in mirrored fashion. It works for my test cases, but I would like to know if there are any best practices that would make ...
4
votes
1
answer
224
views
CSV TimeSheet Calculator
This program takes in a CSV timesheet for my current job, groups the hours worked by employee then outputs it to a txt file. I used a simple GUI with tkinter and ...
5
votes
4
answers
2k
views
A function that opens a CSV file
I'm working on a project that requires me to open CSV files. It must check that the file is open and then return it to main. I've written a function to do so and would like to know how it looks, if ...
8
votes
4
answers
1k
views
Python implementation of core fundamentals to calculate math arithmetic
This program takes a user input to choose which calculation method they'd like to use, then uses a separate module and the math library to perform said calculation.
I'd like some feedback as to how ...
6
votes
5
answers
723
views
Basic word search puzzle generator
This is code for a basic word search puzzle generator (also "wordsearch"). The code:
Creates a 10 x 10 grid of letters.
Words are hidden somewhere in the grid, horizontally or vertically.
...
8
votes
3
answers
761
views
Github actions workflow for release and publishing to PyPI using uv
I have a Github actions workflow that on pushing a tag does the following for a python package:
Creates a Github release using the tag version.
Publishes the package to PyPI.
The package build and ...
6
votes
3
answers
682
views
Interactive simple calculator as a first project. As of now it handles arithmetic, linear and quadratic calculations
This is my very first personal project. I'd like to know what I can improve in this code, with reference to optimization and efficiency.
Here's the code:
...
5
votes
2
answers
282
views
10
votes
3
answers
2k
views
A Rubik's Cube game in Python
I implemented this Rubik's Cube game in Python, using Canvas and Context2d for user interaction. This was mainly an exercise in &...
5
votes
2
answers
415
views
Wordsearch Generator (Tracking Success/Failure)
I'm creating a wordsearch generator that takes a list of words and outputs a 10x10 grid (2D array) of letters. This is roughly how it works:
loop over words
use boolean ...
4
votes
1
answer
807
views
Using AI agent to solve the N-puzzle
I have just written this code here. The code is about creating a (local LLM based) AI agent to solve the N puzzle. I should stress that I am the one who wrote the code, and I did not use AI to write ...