r/learnpython • • 11h ago

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

7 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 • • 21h 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 • • 9h 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 • • 12h 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 • • 7h ago

How come randomly placed drawing don't go to the side of my canva?

1 Upvotes

Long story short, my assignement is to create a "forest". I already created many functions to draw the trees and a window with a button that allows the user to choose how many trees will be drawn in it. My biggest problem is that I'll have points deducted if the randomly placed trees touch the border. I thought just making sure that my trees coordinates where withing the range that would make them not touch the canva but fr some reason they are always a bit to much to the side and I don't know what to do, because everything I try makes them "escape" the canva. I tried to create a "formula" that'll subtract the width and height of the trees to the x and y coordinates to make sure they don't touch the border but with no success. I thank you guys for any help or advice you might be able to bring!

Here's the relevant code:

from random import*
from turtle import*
from tkinter import*
from math import*

#Screen
screen = Screen()
screen.setup(900,600)
colormode(255)
screen.bgcolor(0, 46, 122)
screen.tracer(0)
hideturtle()
master= screen.getcanvas().master 

#Functions needed to make the tree
def triangle(x,y,cote):
    penup()
    goto(x,y)
    pendown()
    begin_fill()
    colormode(255)
    color(25, 87, 5)
    for i in range(3):
        forward(cote)
        left(120)
    end_fill()
    penup()
    
def tronc(cote2):
    colormode(255)
    color(66, 33, 1)
    begin_fill()
    for i in range(2):
        forward(cote2)
        right(90)
        forward(cote2*1.5)
        right(90)
    end_fill()
    penup()
    

def sapin():
    cote= randint(10,100)
    cote_tronc= cote*0.3
#What might be the problem
    x=randint(-abs(425-cote),425-cote)#The abs() is there to make sure it stays within
    y=randint(-abs(225-ceil(cote*1.1)),225-ceil(cote*1.1))
#The coordinates are purposefully in a range smaller than the canva in an attempt
#to have them not "escape" it.
    x2 = x+cote*0.375
    penup()
    goto(x2,y)
    tronc(cote_tronc)
    deplacementX= cote*0.085
    deplacementY= cote*0.3
    for i in range(3):
        triangle(x,y,cote)
        x += deplacementX
        y += deplacementY
        cote *= 0.8

def foret(n):
    for i in range(n):
        sapin()

foret(200)

master.update()
exitonclick()

master.mainloop()

r/learnpython • • 10h ago

How to solve python problems?

1 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 • • 22h 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 • • 3h ago

any tips for learning python as a first coding language when you don't know anything about coding

0 Upvotes

i know literally nothing about coding but i wanna start, how and where? (preferably not costing money) and is python the best option to learn first? i am pretty much unsure of anything about coding at all


r/learnpython • • 5h ago

Is coddy a good place to start if I'm looking forward to build a career from scratch?

0 Upvotes

I really want to get into the programming world despite the fact that I've studied else back at school,my Ultimate goal is to get hired as a programmer from here to the next year,I heard they give you a certificate upon completing the course,is it worth anything?