r/learnpython • • 3d ago

Ask Anything Monday - Weekly Thread

1 Upvotes

Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread

Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.

* It's primarily intended for simple questions but as long as it's about python it's allowed.

If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.

Rules:

  • Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
  • Don't post stuff that doesn't have absolutely anything to do with python.
  • Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.

That's it.


r/learnpython • • 1h ago

Equivalent of PyCharm debugger in VSCode?

4 Upvotes

Once you dig a little, the PyCharm debugger reveals how powerful it is!

I simply love that you can run code line by line, step into functions and out.

Just discovered the "view breakpoints" and "mute breakpoint" buttons to toggle on/off inline breakpoints. Combined with breakpoint(), you can run your program as normal, have it trigger the debugger on breakpoint() without messing with the inline breakpoints you left for later.

It's probably the best and clearest debugger I've seen this far!

Problem is, we use several languages at work and tools that integrate with VSCode.

I'm wondering if there is an equivalent to this experience in VSCode?


r/learnpython • • 3h ago

Is there any way to play audio in Python without using external libraries or winsound?

4 Upvotes

I wanted to play audio in Python, so I started looking for modules that were already installed, it means ones that wouldn't require an internet connection to install (for example Pygame)

I found winsound but the problem is that it will only play audio on Windows and no in other OS

It seemed more convenient not to have to install external libraries to test Python capabilities within the existing environment (such as using Tkinter instead of game engines)

Unfortunately many audio libraries and modules were removed in 3.13 (i'm using 3.14)


r/learnpython • • 1h ago

pythagoras tree

2 Upvotes

I made code for one "branch" of the Pythagoras tree, and I have no idea how to make the full tree. Can someone help? My code:

from turtle import*
x=100
while True:
    for i in range (4):
        fd(x)
        rt(90)
    rt(90)
    fd(x)
    lt(45)
    xNaDwa= x*x/2
    y= xNaDwa**0.5
    x=y

r/learnpython • • 2h ago

How to solve python problems?

2 Upvotes

This may be a dumb questions, but I do not get how to write code. For some context, I am taking a scientific computing course in my uni, I am a physics major, so most of the coding we do pertains to some kinda physics/math related problem. I know how to do the math on its own but I don't get how to translate it into code. When I see a problem I don't even know how to start it.
For example:

Write a function my_cubic_spline_flat(x, y, X), where x and y are arrays containing experimental data points, and X is an array. Assume that x and X are in ascending order and have unique elements. The output argument, Y, should be an array, the same size as X, where Y[i] is the cubic spline interpolation of X[i]. However, instead of the constraints we introduced before, 𝑆′1(𝑥_1)=0 and 𝑆′𝑛−1(𝑥_𝑛)=0.

When I see that, I do not know what to do. Like I know how to write functions and stuff, but not the actual code that goes inside the function.

Any advice is appreciated! :)


r/learnpython • • 26m ago

Is This Backend Stack Worth Betting On For 0 YOE in India

0 Upvotes

Been worrying for a long time and not sure if I'm doing the right thing. Its been stressing me for a while the uncertainty and blackbox-ness of the industry.

Python, SQL, FastAPI, SQLAchemy, pydantic, alembic, git, GitHub Actions (possibly later), Docker, pytest, async, jwt (possibly oauth and rate limiting later), postgres, render, htmx + jinja2

After multiple switches and exploration in Java, Flutter, Rust which I was exploring. PyQT+plotly+ReportLab, pandas+sklearn, and sentence-transformer+faiss which I was working on project, I finally panicked and switched to web dev choosing this stack.

How reliable is this or its too small and low probability market?

0 YOE, but still learning

2025 graduate normal college

I have been worrying a lot lately that I have become calm from it.

What do you think? I'm thinking from first job perspective atleast.

I can add AI elements like API integration or other concepts I came across RAG and ML model development later. But for now this is the thing.


r/learnpython • • 30m ago

Is This Backend Stack Worth Betting On For 0 YOE in India

1 Upvotes

Been worrying for a long time and not sure if I'm doing the right thing. Its been stressing me for a while the uncertainty and blackbox-ness of the industry.

MAIN ISSUE:

I was already working on building end to end applications but was unsure if I can actually find the job with a designated role that matches the stack. The issue is if the stack itself is niche and hard to find jobs or bit uneven for fresher roles.

Stack: Python, SQL, FastAPI, SQLAchemy, pydantic, alembic, git, GitHub Actions (possibly later), Docker, pytest, async, jwt (possibly oauth and rate limiting later), postgres, render, htmx + jinja2

After multiple switches and exploration in Java, Flutter, Rust which I was exploring. PyQT+plotly+ReportLab, pandas+sklearn, and sentence-transformer+faiss which I was working on project, I finally panicked and switched to web dev choosing this stack.

How reliable is this or its too small and low probability market?

0 YOE, but still learning

2025 graduate normal college

I have been worrying a lot lately that I have become calm from it.

What do you think? I'm thinking from first job perspective atleast.

I can add AI elements like API integration or other concepts I came across RAG and ML model development later. But for now this is the thing.

Is there something off or its alright? Like I can improve or cut my stack to fit a market role more specifically. By cutting I mean lean to learn first or more robustly to look for one role like API dev then Backend and later add devops parts type.


r/learnpython • • 4h ago

Relearning coding, no gen AI?

2 Upvotes

Note: I am not here to debate generative AI ethics.

I haven’t coded in a while and can’t think of a project to work on, so I was hoping for a course I could take to refresh my knowledge that would not delve into generative ai. Any suggestions? I’d really like to find something that just doesn’t talk about it at all, as I’m sick of having to set up a cognitive filter to ignore it myself.

I’m aware I could find a book written before ~2022 but I thrive under a “class learning” structure and like learning on the go.


r/learnpython • • 13h ago

How do you keep a small open-source package maintained over time?

7 Upvotes

I recently published my first package on PyPI. It works and has tests and CI, but I've never maintained anything long term. For those of you with packages people actually use:

  • How to determine which features should be in a patch and which in a small release. And when to upgrade to 1.0?
  • How to ensure that your dependencies and GitHub actions are up-to-date without it becoming tedious. For example, is Dependabot or Renovate (or another tool) used?
  • Should dependencies be version locked or not?
  • How much time do you allocate to this? And how do you manage it if you are particularly busy?

All good practice and common errors are really appreciated!


r/learnpython • • 23h ago

6 weeks into learning python and a friend keeps telling me to switch to go for backend

7 Upvotes

6 weeks in, about an hour most nights. function, loops, dicts, just started classes. i want to end up doing backend work and was about to pay for a structured python course but a friend who writes go at work keeps saying python is a detour and i should switch now before i get too deep. i don't want to restart every time someone has an opinion but i also don't want to burn months on the wrong things. so do i stay or switch??


r/learnpython • • 14h ago

Append key and value list to another value list of a different dict...

1 Upvotes

I have a problem that I need to solve, and I've been working on this for too long to care about doing it another way.

I have a dict with keys that I need to split into different sections. For example: I need keys 1-3, 4-6, 7-9 to go into section 1, 2, 3 etc, which have their own keys in another dictionary (Code below)

sectioned = {'1': {}, '2': {}, '3': {}}
unsectioned = {'key1': [value1, value2, value3], 'key2': [value1, value2, value3], 'key3': [value1, value2, value3], 'key4': [value1, value2, value3], 'key5': [value1, value2, value3], 'key6': [value1, value2, value3], 'key7': [value1, value2, value3], 'key8': [value1, value2, value3], 'key9': [value1, value2, value3]}

I want to move these to make:

sectioned = {'1': {'key1': [value1, value2, value3], 'key2': [value1, value2, value3], 'key3': [value1, value2, value3]}, '2': {'key4': [value1, value2, value3], 'key5': [value1, value2, value3], 'key6': [value1, value2, value3]}, '3': {'key7': [value1, value2, value3], 'key8': [value1, value2, value3], 'key9': [value1, value2, value3]}}

How would I do this? I've tried a few things using 'for' statements, but I can't get it quite right...


r/learnpython • • 9h ago

Does anyone play high level sudoku?

0 Upvotes

Hi,

I'm trying to make a very advanced sudoku player in python.

However, it generates sudokus far too slowly. Can someone help me? (I'll only share source code once someone says yes)


r/learnpython • • 23h ago

Hot write "Not A, unless B" in Boolean Algebra?

2 Upvotes

I have a rather complex row selection mission at hand.

To select the rows I want, I have to use two lists of keywords. One contains words that I want (kw_Y), and the other contains words I don't want (kw_N). I originally used this simply to collect the rows that have the wanted information, but now I need to do some comparison analysis with rest of the data.

I need to select rows "that don't have the kw_Y terms, unless they have kw_N terms". Or as Google put it: "No A unless B" (meaning A is false except when B is true) translates to ¬A unless B, or ¬A ∨ B (logically equivalent to B → A, "if B then A").

Boolean logic has never been my strongest point. What would this be in Python?

Codes:

good_stuff = dataframe[kw_Y & ~kw_N] #Yes these masks, not just lists. Algebra is the focus.

bad_stuff = dataframe[kw_N & ~kw_Y] #didn't select enough rows

bad_stuff2 = dataframe[~kw_Y] #I realized this removes rows that contain stuff I now want. 

all_bad_stuff = dataframe[???]

r/learnpython • • 2d ago

Learning Python at 37 and I can read code fine but can't write 10 lines without the lesson open

216 Upvotes

37, learning Python in the evenings for about 3 months. I can read other people's code and follow every lesson, but the moment I close the lesson and try to write something small on my own, like a script to rename my photos, I'm stuck after a few lines. I did a free intro course before this and hit the same wall, so this time I'm paying for something structured. What made writing code on your own start to click?


r/learnpython • • 23h ago

What exactly i've should learn to automation and script building?

1 Upvotes

Hey guys, my english is very bad but i think you can understand!

I have a good knowledge in java development and linux fundamentals, but lately i have searching ways to be more efficient in my personal projects, and python always appears in very different cases.

To be more specifically, i love build my own programs and create some terminal apps.

So, how can i learn python without watching insane playlists with 40 minutes / video, just using previous knowledge!


r/learnpython • • 1d ago

one parse function per store in my scraper, normal?

8 Upvotes

every grocery store my deals script checks has its own parse function. one keeps specials in a table, one in cards, one only fills in after the js runs so that one needs playwright. main picks one with an if/elif on the url

it works.. until a store redesigns and its function quietly returns an empty list for a week

how do you keep new stores from being near copies​


r/learnpython • • 1d ago

At what point did Python finally click for you as a beginner?

1 Upvotes

I've recently started learning Python and have covered variables, loops, functions, lists and dictionaries. I also started building a simple banking system to put what I've learned into practice.

I can understand most of the code when reading it, but writing everything from scratch is a different challenge.

For those who started with absolutely no programming background, at what point did you become confident enough to build something independently?

Did you finish a course first or just keep building small projects until things started clicking?

Would love to hear about your experiences and anything you wish you had done differently as a beginner.


r/learnpython • • 1d ago

How to not clobber a class when inheriting

0 Upvotes

I wrote a visitor to extract some datas via the ast

class VariableFinder(ast.NodeTransformer):
    """ Visitor pattern impl."""
    def __init__(self, find_object:str, find_method:str):
        """ 
        filter for only method calls that match find_object.find_method 
        store the line number and store the value or args passed to the call
        """
        self.find_method = find_method
        self.find_object = find_object
        self.found = []
...

And it struck me this is not C++, so how do we stop ourselves accidentally blatting/clobbering over ast.NoteTransformer attributes? I'm missing something and my searches are all indicating that the visitor pattern is frowned upon. Is there an alternative way to do these safely?


r/learnpython • • 1d ago

For learning Python

0 Upvotes

I have been learning Python for over a year now. I have already finished Eric Matthes's book, "Python Crash Course." Are there any other books similar to "Python Crash Course"—specifically ones that focus on project-based learning, like the three projects featured at the end of that book? In other words, what other books are there that allow you to learn by building projects?

(N.B. This is not a promotional post)


r/learnpython • • 2d ago

Basically, if main

9 Upvotes

In Python, when you run your program in another folder, we add this, but I don't understand why. What's the point of doing this? If someone could explain it in a simplified way, I'd appreciate it.


r/learnpython • • 1d ago

Little fun code I put together:)

0 Upvotes

Edit: I fixed the last line in the program, just had an issue when pasting it and didn't think when I filled it back in. Thank you guys for letting me know!

Hi! So I've been learning code for a little while now and lately, I've been getting more ideas for little programs to put together. They're not really useful in practical sense, but they're still fun exercises and ways to challenge myself while I'm still learning and understanding the basics.

I just thought this one would be fun to share because it took me a second to figure out the best way to have both lists be printed at the same time. Honestly though, I don't know why I didn't think of just doing a function right away though HSDH

The basic idea of the program is to generate a full breakfast by randomly choosing an entree and a side to go with it!

import random

entree_list = ["eggs", "cereal", "waffles", "oatmeal"]

side_dish = ["hashbrowns", "toast", "orange", "banana", "yogurt"]

def breakfast_run():
    print("Get someeeeeee")
    print(random.sample(entree_list, k=1))
    print("and")
    print(random.sample(side_dish, k=1))

breakfast_run()

r/learnpython • • 1d ago

Help Help!!!

1 Upvotes

Title: How should I get started with AI, and which direction should I focus on?

I am currently a PhD student in environmental science, but I want to transition into AI. My CS background is still weak, and I am currently learning Python and basic math.

There are so many directions—LLMs, agents, computer vision, robotics, AI for Science, etc.—that I am not sure where to focus.

If you were starting from my position today, what would you learn first, and which AI direction would you recommend focusing on for the next 6–12 months?

My goal is to eventually become capable of doing real AI research or engineering work, not just using AI tools.


r/learnpython • • 1d ago

Trying to import a file into Thonny

2 Upvotes

Trying to import a rom file to convert to bytes and then mod, but the game title has "of" in it, so it returns as a syntax error. I guess the IDE thinks I'm trying to write an if statement? Anyway, google wasn't helpful, so i came here.
Code below
import Breath of Fire II (USA) - Copy.sfc


r/learnpython • • 2d ago

What exactly is uv? Why other programming languages like C++ doesn't needs it

36 Upvotes

Hello, im a c++ programmer and after installing some tools made in python with pipx. For context, pipx uses uv, i had this question. I'm not the smartest progammer on earth and i couldn't understand why Python needs a separate environment for dependencies.

I never such tool like that as a c++ programmer (i don't know if it's what im thinking, but in C++ some devs install the dependencies inside de project dir so u just "cmake" it. uv is like this?). I'm kinda new to programming, so if someone can explain it to me, i'd be very grateful!

Sorry if this question sounds too beginner. I really couldn't understand this tool and curiosity is stronger than me...

Thanks! (and also, uv does more than separating environments, right?)