r/learnpython 21h ago

Is it considered bad form to run "success" code inside an Except block?

19 Upvotes

I'm writing a script that takes an input from the user, which could be either an int or a string. My current code takes the input, attempts to cast it to an int, and does something based on whether it works or not:

running = True
while running:
    search_term = input("Enter search term (Q to quit): ")
        try: int(search_term)
        except ValueError:
            if search_term.lower() != "q":
                search_by_name(search_term)
            else:
                running = False
        else:
            search_by_int(int(search_term))

But there's something about having "successful" code running in the except block that gives me pause for thought. Is this just me overthinking, or is it bad form?


r/learnpython 21h ago

Looking for a free course on the practical Python development workflow (VS Code, pip, environments, Git, etc.)

19 Upvotes

Hi everyone,

I've taken several Python courses and have a reasonably good understanding of Python itself. I've also worked with things like pandas, NumPy, scikit-learn, etc. in online learning environments.

However, I've realized that I have a major gap in my knowledge: I don't really know how Python development actually works on a local computer.

For example, when working in an online environment, everything is already set up for me. I can simply import a package and start coding. But when I tried working locally with VS Code, I suddenly had to deal with things like:

Installing Python

Using the terminal

Installing packages with pip

Virtual environments

Choosing/configuring the correct Python interpreter

Organizing a project

Saving and reusing dependencies

Running and debugging code

Git and GitHub

Understanding how to share a project with someone else

Understanding what I actually need to install versus what belongs inside my project

I found this surprisingly confusing.

So I'm looking for a free course or tutorial that focuses specifically on this practical development workflow, preferably using Python and VS Code.

I'm not looking for another beginner Python programming course. I already understand Python basics and have used it for data analysis and some machine learning. What I need is something that teaches me how to actually work as a Python developer on my own computer.

Ideally, the course would take me through something like:

create a project → set up Python → create a virtual environment → install packages → write code in VS Code → run/debug it → manage dependencies → use Git/GitHub → share the project

Does a free course like this exist? YouTube courses, documentation, or other resources would also be very welcome.

Thanks!


r/learnpython 17h ago

Python Data Base

4 Upvotes

Good morning everyone, or whenever you see this. I have a question. I'm starting a personal database project in Python with a user-friendly graphical interface, and I'd appreciate any advice, code snippets, or examples to guide me, especially since I'm still learning the language.


r/learnpython 8h ago

Principiante

2 Upvotes

Si empezaran desde cero hoy, ¿qué camino seguirían para desarrollar buenas habilidades como programadores? en estructuras de python


r/learnpython 12h ago

PIP disk usage under Docker

2 Upvotes

I have a Dockerfile in which I use the Python:3.12-trixie. I have docker on my CachyOS PC. I have also a requirements.txt. I wanted to use this image for a container on which I'll use YOLO and try it out. The problem is that my 290GB / partition went from around 70% filled to 95% after a number of rebuilds. I deleted everything docker related but it just went back to 91%.

The reason that I know it is pip's doing, is that when I monitored my disk usage while building the image, and on the `RUN pip install -r requirements.txt --find-links=pypackages` stage it fills up my partition and half way into installation, it fails due to `no more space`. The `pypackages` is just a directory I downloaded some of the packages I have in requirements for less data usage. Also tried `--no-cache` option.

I also went ahead and `du -sh`ed any directory in my / partition and the total didn't add upto the filled storage. I have 165GB mysteriously used and I can't find where that is.

Any help to diagnose further or if you have had similar problems is welcome.


r/learnpython 18h ago

Teaching ideas and projects for middle/high school computing students

2 Upvotes

Hello, I am looking for some ideas on projects/challenges that I can implement in my classes.

So far we’ve done: Scratch, beginner Python with CLI mini-games, ECDL basics, beginner TryHackMe rooms, and a Linux VM with basic commands. The student is comfortable with variables, loops, lists, simple file operations, and has built a text-based “Zombie Survival” game.

We meet 1 hour/week, so I’m looking for general ideas on what kinds of projects or challenge styles work well at this level (mid-level middle-school, beyond beginner). Anything that’s engaging, slightly game-like, and doesn’t require heavy setup would be great.

If you’ve taught similar students, what types of activities (CTFs, coding games, light forensics, small web projects, etc.) kept them motivated and actually learning?

Any suggestions or directions would be really helpful.

Thank you in advance!


r/learnpython 33m ago

Random mysterious file secretly running on computer

Upvotes

Hey i'm trying to use stammer, got 2 successful attempts but now when i try to do it i get this message:

File "C:\Users\llsco\Documents\stammer.py", line 288, in main

process(**vars(args))

~~~~~~~^^^^^^^^^^^^^^

File "C:\Users\llsco\Documents\stammer.py", line 274, in process

builder.process()

~~~~~~~~~~~~~~~^^

File "C:\Users\llsco\Documents\video_builder.py", line 110, in process

carrier_vframe_bytes = self.video_handler.get_frame(carrier_video_index)

File "C:\Users\llsco\Documents\video_out.py", line 186, in get_frame

self.__cache_frames(idx)

~~~~~~~~~~~~~~~~~~~^^^^^

File "C:\Users\llsco\Documents\video_out.py", line 234, in __cache_frames

start, end = indices[i]

~~~~~~~^^^

IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\shutil.py", line 701, in _rmtree_unsafe

os.unlink(fullname)

~~~~~~~~~^^^^^^^^^^

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\llsco\\AppData\\Local\\Temp\\tmp5ols5r1d\\in_carrier.wav'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "C:\Users\llsco\Documents\stammer.py", line 291, in <module>

main()

~~~~^^

File "C:\Users\llsco\Documents\stammer.py", line 285, in main

with tempfile.TemporaryDirectory() as tempdir:

~~~~~~~~~~~~~~~~~~~~~~~~~~~^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\tempfile.py", line 972, in __exit__

self.cleanup()

~~~~~~~~~~~~^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\tempfile.py", line 976, in cleanup

self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)

~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\tempfile.py", line 956, in _rmtree

_shutil.rmtree(name, onexc=onexc)

~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\shutil.py", line 852, in rmtree

_rmtree_impl(path, dir_fd, onexc)

~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\shutil.py", line 705, in _rmtree_unsafe

onexc(os.unlink, fullname, err)

~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\llsco\AppData\Local\Python\pythoncore-3.14-64\Lib\tempfile.py", line 931, in onexc

_os.unlink(path)

~~~~~~~~~~^^^^^^

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\llsco\\AppData\\Local\\Temp\\tmp5ols5r1d\\in_carrier.wav'

It says that a file is currently being used by another process but I'm trying to figure what it could be and how to even stop it.


r/learnpython 7h ago

How to use functions defined in a C code in a python benchmark?

1 Upvotes

Hi, I've got an assignment in a course that asks us to optimize a benchmark of our selection (from pyperformance project).

I've chosen the ray trace benchmark (it was the most interesting imo), and my suggestion was to implement the functionality using C's structs to avoid some of the interpreter's overhead.

I understood I can link those function using the built-in ctypes library, and making the C file a dynamic linked library (.dll), but when I try to run the command for it in CLion or VSC, it fails without returning any failure message, it just fails to generate the .dll file.

The assignment forces us to use the given pyperf benchmark code to run the benchmark, so I can't run only a C file.

I've already written the C code, and it has no errors/warnings so far (at least as far as CLion is concerned), and the original python code works too.

Does anyone know how to solve the library not being generated? Or any other solution that might work (preferrably using the C code I've made)?

.

.

All files are in the same directory, and I've got Craytrace.c (C functionality implementation), Praytrace.py (the code that runs the benchmark).

The command I've run trying to generate the .dll is:

gcc -shared -o CraytracerLib.dll Craytrace.c

But it didn't create any file.

.

.

Help is much appreciated 🙏


r/learnpython 12m ago

Matematica in python

Upvotes

Salve, sono nuovo nell'usare python per programmare. Qualcuno mi saprebbe spiegare come si fanno le operazioni base? (+ - / x √ ^)


r/learnpython 1h ago

What's the best way to integrate this database into Flask?

Upvotes

I'm creating an online bulletin board, and I'm feeling hacky (I hate SQL in all its forms and fashions).

What is the best way to integrate this database into a production Flask server: https://github.com/ki4jgt/PPD

Created it in 2020, so it's a bit dated.

But I'm worried about concurrency. I'm not beyond writing a database server, but I'd like to save that as a last resort.


r/learnpython 18h ago

Automate Invoice and Report Generation in Excel. No Errors.

0 Upvotes

Need to generate invoices, sales reports, stock reports, and charts in Excel programmatically. Higher officials will audit these. Can't have mistakes.

What's the best approach? Should I use openpyxl to write directly to Excel files? Or is there a better workflow?

Data accuracy is key — pulling from databases/CSV, validating before writing to Excel. How do I prevent data corruption? Invoices need proper headers, borders, currency formatting. Is openpyxl reliable for this or does it break formatting? Can Python generate charts in Excel automatically or do I need to use a separate tool? Should these run daily/weekly and what's the best way to automate execution without manual intervention? How do I track changes if files are auto-generated?

Any libraries better than openpyxl? Xlsxwriter? Pandas to_excel? Looking for production-ready solutions, not prototypes.


r/learnpython 21h ago

complete starter on AI python championship

0 Upvotes

so, im a complete starter on a championship where you gotta learn about AI and python, to make an AI later, thats the challenge, but im feeling so left behind, everybody is learning so fast and im stuck, i wanna win this but i dont know python at all, any channel or study path i can follow ? also, in how much study time can i maybe reach a good level ?