New answers tagged python
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 ...
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 ...
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 ...
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-...
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),...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
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. ...
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
...
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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:
...
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:
...
1
vote
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 ...
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 ...
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 ...
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 ...
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 ...
1
vote
Web scraping data from website using Selenium
Portability
When I run the code, I get a syntax error on lines like this:
...
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 ...
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 ...
2
votes
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:
...
1
vote
Snake game in pygame with varying velocity
Imports
The import lines should precede all executable code; move the init call:
...
1
vote
Breadth First Search Block Puzzle
UX
When I run the code with the -h argument, I get a vague error message
...
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(...
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:
...
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 ...
2
votes
Lisp expression parser
Let's avoid some repetition by defining a list of sample cases and then looping over that.
...
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 ...
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 ...
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 ...
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.
...
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:
...
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 ...
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 ...
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:
...
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:
...
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 ...
3
votes
Translate between Tcl and Python lists
There are a few ways the to_tcl function can be streamlined.
...
Top 50 recent answers are included
Related Tags
python × 15574python-3.x × 5185
performance × 2367
beginner × 2007
python-2.x × 1234
algorithm × 1209
programming-challenge × 1045
numpy × 755
object-oriented × 727
pandas × 598
game × 550
strings × 490
web-scraping × 429
time-limit-exceeded × 397
tkinter × 357
parsing × 323
csv × 304
django × 303
hash-map × 295
random × 253
pygame × 246
recursion × 245
file-system × 237
regex × 234
reinventing-the-wheel × 225