Skip to main content

New answers tagged

2 votes

Python program that iterates over audio files with a progress bar interface

I notice you are using uv to invoke the script: $ uv run audio_convert.py Instead of doing this, make your script a proper package and install it as a tool. Just ...
InSync's user avatar
  • 459
2 votes

Python program that iterates over audio files with a progress bar interface

progress library for audio_file in get_audio_files(source): ... got an acceptable display with rich Ok, sure, that's one ...
J_H's user avatar
  • 42.1k
3 votes

Python program that iterates over audio files with a progress bar interface

To decouple the UI (here: a console) from the background processes - this could be easier than you think with event-oriented programming. For example, I use the blinker lib in Flask but also outside ...
Kate's user avatar
  • 8,293
2 votes

Python program that iterates over audio files with a progress bar interface

Overview The code layout is really good, and you used meaningful names for functions and variables. I especially like the docstrings and type hints. I agree with your desire to separate the progress-...
toolic's user avatar
  • 15.7k
6 votes
Accepted

Split flap clock stepper code

Quick thoughts Logging You have explicitly said you are using Micropython, and that must be the reason why you did not use the logging module. There are lightweight alternatives though (Google search),...
Kate's user avatar
  • 8,293
8 votes

Split flap clock stepper code

Follow Useful PEP8 Style Guide Suggestions For example: Add docstrings for each module and "public" functions. Either in the function docstring, or a function comment or type hints let ...
Booboo's user avatar
  • 3,456
4 votes

Split flap clock stepper code

The first thing I see missing from your .py files is ... Documentation The PEP 8 style guide recommends adding docstrings for classes and functions. You can also ...
toolic's user avatar
  • 15.7k
5 votes

Split flap clock stepper code

A few notes: There are no documentation comments. You have one case of inconsistent indentation. Not a big deal. It's unusual to have your from machine import Pin ...
Chris's user avatar
  • 4,329
1 vote

Sorting Algorithm Visualizer with Pygame

UX When I run the code, the GUI window appears. However, information is clipped at the left and right edges of the screen, and I can not resize the window with my mouse. I also suspect information is ...
toolic's user avatar
  • 15.7k
1 vote

Solve a system of linear equations with Gauss algorithm

I somewhat doubt that the original poster is still around, but for posterity: 700 lines is too long for such a program. It's too hard-coded (a, b, ...), and not flexible enough - it only supports up ...
Reinderien's user avatar
  • 71.1k
2 votes

Solve a system of linear equations with Gauss algorithm

Not only are names like a1 and b2 non-descriptive, but they all of these objects should probably be in lists or dictionaries ...
Chris's user avatar
  • 4,329
2 votes

Heat Diffusion Equation Solver

Here are some general coding style suggestions. Portability I'm not a big fan of fancy Unicode characters in source code, like the green checkmark in the print line....
toolic's user avatar
  • 15.7k
2 votes

Solve a system of linear equations with Gauss algorithm

UX When I run the code, the GUI title has the acronym "LGS". It would be helpful to spell out the acronym somewhere in the window. Also, I do not know what I should enter into each field. ...
toolic's user avatar
  • 15.7k
2 votes

Heat Diffusion Equation Solver

I don't have much to say about numeric stability of code I can't run, as there's usually a lot of experimentation needed. broadcast ...
J_H's user avatar
  • 42.1k
0 votes

A tabbed calculator with tkinter

Portability I get a syntax error when I run the code: NameError: name 'my_subtraction' is not defined In all_tabs.py, this line ...
toolic's user avatar
  • 15.7k
3 votes

Calculation of liquid propellant nozzles

I don't really understand any of this, so I can only speak as a programmer, but the code looks good and fairly well structured. Naming conventions make sense in plain English even to an outsider. If ...
Kate's user avatar
  • 8,293
2 votes
Accepted

Calculation of liquid propellant nozzles

Overview The code layout is good, and you used meaningful names for classes, functions and variables. It seems like the code is already structured for future enhancements. Long lines There are a ...
toolic's user avatar
  • 15.7k
0 votes

Finding a sequence of xors to change a to b

Here are some general coding style suggestions. UX When I run the code, it sits there waiting for input, but I have no idea what I should type at the prompt. Instead of a bare ...
toolic's user avatar
  • 15.7k
8 votes

Finding a sequence of xors to change a to b

You can improve the performance by using an \$O(1)\$ algorithm. Turn all the bits on. ...
Peilonrayz's user avatar
  • 44.5k
2 votes

Timer with input, sound and flashing

Portability When I copy the code out of the question and try to run it, I get syntax errors due to indentation. Perhaps your indentation mixes single spaces with tab characters on the same line, and ...
toolic's user avatar
  • 15.7k
1 vote

Iterating over symmetric matrix

I have a symmetric matrix, and I want to loop over its elements Well... no. You only want to loop over its lower triangle (equivalent to its upper triangle), and there are more direct ways: ...
Reinderien's user avatar
  • 71.1k
2 votes

Web-scraping bountied questions from Stack Exchange sites

Here are some general coding style suggestions. Portability These lines are not legal Python syntax: ...
toolic's user avatar
  • 15.7k
1 vote

Primality test in Python

A commentary on the style of smallestr and control flow. ...
Chris's user avatar
  • 4,329
1 vote

Calculation of Correlation Time

Here are some general coding style suggestions. Unused code This variable is set but never used: start_time = time.time() It can be deleted, which means this line ...
toolic's user avatar
  • 15.7k
4 votes

MCMC Metropolis Hastings for German Tank Puzzle

A lot needs to change for this to be an efficient Monte Carlo simulation. All use of the uniform stats object should be removed. It's really slow, and that's ...
Reinderien's user avatar
  • 71.1k
2 votes

Tic-Tac-Toe using minimax algorithm

Let's look at a few stylistic things we could do to your code. In terminal, check_board has a nested loop that replicates the ...
Chris's user avatar
  • 4,329
2 votes

Iterating over symmetric matrix

It's not clear whether you need to iterate over these values just once, or in several different places in the code. If the latter, then you probably want to encapsulate the logic in a reusable ...
Toby Speight's user avatar
  • 88.3k
1 vote

Iterating over symmetric matrix

Simpler Overall, the code is easy to understand as it is written. However, there is no need for the continue statement if you change the ...
toolic's user avatar
  • 15.7k
1 vote

Web scraping data from website using Selenium

Portability When I run the code, I get a syntax error on lines like this: ...
toolic's user avatar
  • 15.7k
5 votes

Python calculator application

Initial Problems I had some difficulty running your code as since gettext.translate seems to be looking for a .mo file according to my Python 3.12 source and you ...
Booboo's user avatar
  • 3,456
3 votes

Python calculator application

Documentation Code needs documentation, and the PEP 8 style guide recommends adding docstrings for classes and functions. There should also be a docstring at the top of each file to summarize its ...
toolic's user avatar
  • 15.7k
2 votes

Two solutions to LeetCode 127 Word Ladder

...
Chris's user avatar
  • 4,329
1 vote

Two solutions to LeetCode 127 Word Ladder

Here are some general coding style suggestions. Comments Remove all commented-out code to reduce clutter: ...
toolic's user avatar
  • 15.7k
1 vote

Snake game in pygame with varying velocity

Imports The import lines should precede all executable code; move the init call: ...
toolic's user avatar
  • 15.7k
1 vote

Breadth First Search Block Puzzle

UX When I run the code with the -h argument, I get a vague error message ...
toolic's user avatar
  • 15.7k
3 votes

Prime factorization for integers with up to 9-digit long prime factors

I would look up the pollard-rho algorithm. It doesn’t involve any higher mathematics, so you can implement it yourself. If a number n has a prime factor p, that prime factor can be found in about sqrt(...
gnasher729's user avatar
  • 2,970
1 vote

Tic-Tac-Toe using minimax algorithm

Layout Lines like this: if terminal(board): return utility(board), count+1 are typically split into 2 lines: ...
toolic's user avatar
  • 15.7k
7 votes

Find the smallest semiprime satisfying a bunch of conditions

To do this a lot faster: You want to know whether say nine numbers are all primes. The obvious way of checking this is to test if the first number is prime, if it is prime then check the second number ...
gnasher729's user avatar
  • 2,970
2 votes

Lisp expression parser

Let's avoid some repetition by defining a list of sample cases and then looping over that. ...
Chris's user avatar
  • 4,329
1 vote

Lisp expression parser

Overview The code layout is good, and you used meaningful names for many of the functions and variables. Well done. Here are some minor coding style suggestions. Documentation It's great that your ...
toolic's user avatar
  • 15.7k
5 votes

Find the smallest semiprime satisfying a bunch of conditions

repr repr_a = str(a) I found repr_a a confusing name for this, given that we didn't call ...
J_H's user avatar
  • 42.1k
7 votes

Find the smallest semiprime satisfying a bunch of conditions

As you only use isprime and factorint from sympy it would clean up your code to just import ...
Chris's user avatar
  • 4,329
7 votes

Find the smallest semiprime satisfying a bunch of conditions

any other feedback is welcome too Here are some general coding style recommendations. Documentation The PEP 8 style guide recommends adding a docstring at the top of the code to describe its purpose. ...
toolic's user avatar
  • 15.7k
2 votes

Allowing a user to draw their own avatar in Turtle

Documentation The PEP 8 style guide recommends adding docstrings for functions and at the top of the code. For example, summarize the purpose of the code: ...
toolic's user avatar
  • 15.7k
2 votes

Writing a table of national park data

Portability I realize this question was posted many years ago when Python version 2.x was prevalent, but now that it is deprecated, consider porting to 3.x. All that is needed is to add parentheses ...
toolic's user avatar
  • 15.7k
7 votes

Number-guessing game on command line

I enjoyed playing the game! There are a few suggestions I would like to make that would make the code more maintainable and possibly improve the user's experience. Don't Repeat Yourself (DRY) Your ...
Booboo's user avatar
  • 3,456
6 votes

Number-guessing game on command line

This is a good first question and a good first coding attempt! Layout Conventionally the imports are placed at the top of the file, before any other statements: ...
toolic's user avatar
  • 15.7k
2 votes

Google drive backup robot

Tools You could run code development tools to automatically find some style issues with your code. ruff recommends splitting imports onto separate lines: ...
toolic's user avatar
  • 15.7k
3 votes
Accepted

Polars crosstable between two variables in a dataframe

Just some notes about your Polars usage: Selectors There is also a dedicated cs.first() selector which may read nicer. You can "invert" the selection in ...
jqurious's user avatar
  • 146
3 votes

Translate between Tcl and Python lists

There are a few ways the to_tcl function can be streamlined. ...
Chris's user avatar
  • 4,329

Top 50 recent answers are included