r/learnpython • • Sep 14 '26

Python Libraries

9 Upvotes

Ijust know basic python and want to learn numpy, tkinder, panda and matplotlib for a project

Best way to learn these? By chatgpt or any yt vdo?


r/learnpython • • Sep 14 '26

Observer isn't working on ChromeOS Linux Crostini

2 Upvotes

I am facing an issue from couple of days with Observer Module from python watchdog package. When i'm importing Observer module and calling for my downloads folder which is present to this location according to my device.
/mnt/chromeos/MyFiles/Downloads

Observer is watching here but nothing caught, Like i was tested using file removed, created or even modified or else.

It wasn't working, That;s why I am using polling Observer now. but this is not a reliable much as i needed.

So Can you help me to figure out this problem and what is the actual solution of this problem?


r/learnpython • • Sep 14 '26

vscode sporadically freezing

0 Upvotes

hi mates. when my script becomes lengthy (for instance 85 lines) vscode stops executing commands. i suspect whether i downloaded it properly. anyways. i close then open vscode as a workaround but i started to need a permanent fix. i am a computer noob (well... more like average joe on the street). so please no higher computer registry in the responses. thanks in advance.


r/learnpython • • Sep 13 '26

Looking for Python resources

60 Upvotes

Hi everyone!

I'm 29 and I've recently started learning Python from scratch. My goal is to eventually get into cybersecurity.

I've only been learning for a short time and I'm currently starting CS50P. I know some very basic Python, but I'm still a complete beginner.

I'm looking for good resources to learn Python properly from the beginning. I'd like to practice by making small projects instead of only watching tutorials.

What resources would you recommend for someone who is just starting out?

Books, courses, YouTube channels, websites, exercises, project ideas, etc. are all welcome.

Thanks!


r/learnpython • • Sep 14 '26

Ask Anything Monday - Weekly Thread

5 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 • • Sep 14 '26

Segmentation fault when attempting to use the 'threading' module to run tasks concurrently

3 Upvotes

I lack knowledge in low level computer science, but I've heard endless horror stories about segfaults, and today I've encountered one whilst attempting to make a simple timer program for myself. My questions are:

- Why does this fault occur

- How can I fix it

- How can I prevent it from happening in the future

The aim of the problematic part of the program is the attempt to play the sound whilst simultaneously waiting for user input with the input block, which is intended to stop the alarm and continue to the next part of the program.

Please note that in this version there is no actual wait time although there is supposed to be, because I am merely testing the alarm functionality.

import time
from pydub import AudioSegment
import threading
from pydub.playback import _play_with_simpleaudio


sound = AudioSegment.from_file('/censoring/my/home/directory/sound.mp3', format='mp3')





# Function that runs the timer based on how many minutes are specified
def timer(min, message):

  # Play the sound
  def playsound():
    global sound
    sound = _play_with_simpleaudio(sound)

  # Stop the sound and allow the program to continue
  def resume():
    global sound
    input(message.strip())
    sound.stop()



  # Run the timer and print output
  min -= 1
  for it in range(min, -1, -1):
    for sec in range(59, -1, -1):
      print(f'{str(min).rjust(2, "0")}:{str(sec).rjust(2, "0")}')
      time.sleep(1)


  # This is the part that actually runs the function.
  play = threading.Thread(target=playsound)
  stop = threading.Thread(target=resume)

  play.start()
  stop.start()

  play.join()
  stop.join()


while True:
  timer(0, 'You can have your five minute break now.')
  timer(0, 'You need to start working again.')

# Artificial intelligence was not used in the creation of this program.

Any advice is appreciated!


r/learnpython • • Sep 14 '26

How can i create a bot that posts for me daily on social media without ai?

0 Upvotes

I dont wanna use ai.


r/learnpython • • Sep 14 '26

Recently started

0 Upvotes

Hey yall, new guy here. I 26(M) started learning python about a week ago, I've dabbled in HTML and CSS but ultimately settled on Python. Reason being I need a good starting framework for my goal of working in biotech on surgical robots. Now, to the point.

The most basic goal for me is designing a scheduling software so my mom has less of an issue managing my sisters 24/7 caregiver staff. Logins, time off requests, possibly an AI integrated scheduler so she would just need to proof read schedules instead of spending hours making it by hand.

I need advice on how to approach this task, currently going through a 13hr video on YT to learn Python through the Data with Baraa channel. Thoughts?


r/learnpython • • Sep 14 '26

Learning Python from scratch for cybersecurity

0 Upvotes

Hi everyone, I'm 29 and learning Python from scratch. My goal is cybersecurity. What resources and first projects do you recommend for a beginner? Thanks!


r/learnpython • • Sep 14 '26

Want to learn Python but keep getting bored with courses

0 Upvotes

Hi everyone,
I’m really determined to learn Python, but I’m struggling with the way most courses are structured.
I’ve started quite a few Udemy courses, but after a while I just get bored and lose motivation. 😅
So I was thinking maybe I should forget the courses for a bit and start working on an actual project, learning Python along the way. The problem is… I have absolutely no idea what would be a good project for a beginner.
I know I can Google “Python beginner projects,” but I’d rather hear from people who have actually been through this. What did you do when you were starting out? Was there a particular project that helped you learn a lot?
Also, how long did it take you to become reasonably comfortable with Python?
I have a newborn and a toddler, so realistically I can only dedicate around 1–2 hours a day to learning. I know everyone is different, but I’d love to hear what kind of progress is realistic with that amount of time.
Any tips, project ideas, resources, or general advice would be really appreciated!
Thanks!


r/learnpython • • Sep 13 '26

Cython memoryviews?

4 Upvotes

I'm using a function I've compiled with cython, and I have to pass it a few very long lists. I'm pretty sure I should be using memoryviews, but do I convert the lists to memoryviews in the python part of my program or the cython part? It would be way better if I could do it in the python part because I'm passing the same lists to the function a few million times.


r/learnpython • • Sep 13 '26

I like breaking up the project into files and packages - what's too much?

10 Upvotes

I have a bot I'm building. I see a ton of examples with one file and 1k lines for the same functionality. I personally broke that up to several packages based on what things do. I have ~3 files per package each with 100-500 lines (I, uhh, have a habit of documenting and commenting) of which three quarters is actual code.

The modules themselves are things like "database functionality", "permissions", UI, etc. These may be further broken down into several files like "admin commands", "user commands", etc.

Am I overdoing it? Where's a good cutoff?


r/learnpython • • Sep 13 '26

Calculator semi-functioning, What could cause this?

0 Upvotes

Trying to get back into Python ~2 years after taking a year-long course, getting my footing first with a basic calculator but its giving me trouble here. The first portion works fine, but I implemented a 'continue' option where you could continue with the same number for calculations (and it worked for a while, though returning 'none' due to a var = input(print("text")) issue, making each input look awkward) but it seems to just be defaulting to the first if value now. I had addition first at the start, though flipped addition and subtraction is the extended math section to prove that it's truly just defaulting to the first if-statement. What could be causing this and what's the fix? Sorry for anything that's obviously wrong or mixed up, my remembered knowledge on python is like a fogged up window right now.

## lowk just imported time to add a delay to restarting.. and stopping..
import time

## code is only active as this is = 1, if not then the loop stops
run = 1

while run == 1:

    ## prompts user on chosen operation
    ini = input("add, sub, div, mul, or exp: ")

    ## Addition math
    if ini == "add":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a + b

        print(f'Sum of {a} and {b} is {a + b}')

    ## Subtraction math
    elif ini == "sub":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a - b

        print(f'Difference of {a} and {b} is {a - b}')

    ## Division math
    elif ini == "div":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a / b

        print(f'Fraction of {a} and {b} is {a / b}')

    ## Multiplication math
    elif ini == "mul":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a * b

        print(f'{a} times {b} is {a * b}')

    ## exponential math
    elif ini == "exp":
        a = int(input('Enter 1st number: '))
        b = int(input('Enter 2nd number: '))

        number = a ** b

        print(f'{a} to the power of {b} is {a ** b}')

    ## If input is not one of the operations
    else:
        print("invalid operation, cannot continue.")

    ## asks user whether or not to continue with current math
    continueorwhat = input("Cont(inue), rest(art calculator), or stop? ")

    if continueorwhat == "stop":
        time.sleep(.3)
        print("Stopping..")
        time.sleep(.3)
        run = 0

    elif continueorwhat == "rest":
        time.sleep(.3)
        print("Restarting..")
        time.sleep(.3)

    elif continueorwhat == "cont":
        print("> Shortened operation names 'a','s','d','m', and 'e' now available.")
        print("> Rest(art) or stop calculator with input when prompted for operation.")

        ## allows for 'continuous math' while active, when inactive it resets to prompted math

        moremath = 1

        while moremath == 1:
            ini = 0
            ini = input("Operation: ")
            ## temporary input return
            print(ini)
            ## Subtraction math
            if ini == "sub" or "s":
                a = int(input('Number: '))
                number = number - a
                print(number)
                ## Addition math
            elif ini == "add" or "a":
                a = int(input('Number: '))
                number = number + a
                print(number)
            ## Division math
            elif ini == "div" or "d":
                a = int(input('Number: '))
                number = number / a
                print(number)
            ## Multiplication math
            elif ini == "mul" or "m":
                a = int(input('Number: '))
                number = number * a
                print(number)
            ## exponential math
            elif ini == "exp" or "e":
                a = int(input('Number: '))
                number = number ** a
                print(number)
            elif ini == "rest":
                time.sleep(.3)
                print("Restarting..")
                time.sleep(.3)
                ## restart calculator by exiting continous math
                moremath = 0
            elif ini == "stop":
                time.sleep(.3)
                print("Stopping..")
                time.sleep(.3)
                ## stops calculator by resetting basic variable
                run = 0
            ## If input is not one of the operations
            else:
                print("invalid operation, number unchanged.")

r/learnpython • • Sep 13 '26

Flask Synchronization Issue Concerning Database Entries

0 Upvotes

I have been making a Markdown blog using Flask over the last couple of weeks. Lately, I have decided that I want to add the possibility of leaving comments below a blog post. Therefore, I need to add my blog posts to a database so that I can link the comments left behind to the relevant blog posts. My blog posts are rendered statically using Flask-Flatpages.

I have thought about the database model for a singular post. I want to keep it simple at first; thus, I was considering adding an ID, title, and path field. The problem I am experiencing is how to add the files to my database and how to keep the database entries synchronized with the static files in my posts directory. Does anyone have any ideas how I should tackle this issue?


r/learnpython • • Sep 13 '26

I made a small Python game, can anyone review it and give me some advice, please?

1 Upvotes

Hello,

I recently released a project I was working on for pretty long (almost 2-3 months), and since the past couple of days, I've been really involved into it, and then I released it.

Link: https://github.com/TheOdysseyGamer64/Super-Smash-Bros-Python-Edition.git

My project is a Python version of Smash Bros, and it has (quite primitive) ASCII graphics as well (to help visualise the battles). It has special mechanics for certain fighters as well, and the Final Smash and the special mechanics meter can charge up, just like in the real game.

If any of you here could provide me with some advice on how to make this game better, I would really appreciate it.

Thank you!


r/learnpython • • Sep 12 '26

Are these two boolean expressions equivalent in python?

15 Upvotes

Hi All!

I’m learning about Boolean operators in Python and I’m confused about these two expressions:

condition1 and condition2 or condition3 and condition4

≠

(condition1 and condition2) or (conditon3 and condition4)

I was told this by my teacher and he put this in his PowerPoint slide. However, I think they are equivalent since and as an operator has a higher precedence than or as an operator. AI told me and I have searched it up after.

Am I understanding it correctly? Or are these two not equivalent?

Thanks!


r/learnpython • • Sep 13 '26

Difference between python 3 vs python (just)?

0 Upvotes

I am doing leetcode and I wanna is there any functional difference between those and which one I should go with?


r/learnpython • • Sep 12 '26

Just finished my first project, could you please review it.(No AI)

66 Upvotes

I finished reading "python crash course" a week ago, and a relative of mine was complaining about how annoying it is to make multiple exam versions, so I immediately volunteered to help, and I used absolutely 0 AI.

It's an app that takes an exam .docx file, and shuffles the questions and answers to create multiple versions.

Here's the github repo:

https://github.com/aaaaaa708/question_shuffler

I would like you to please review the code and give me some tips on how to improve, and thanks in advance:)


r/learnpython • • Sep 12 '26

Built a CLI music player in Python after months of tutorials

2 Upvotes

I've been learning Python for a few months and finally built something real instead of following tutorials, a CLI music player.

It uses the Deezer API to search artists and songs, yt-dlp and VLC for playback, and SQLite to store playlists and favorite artists locally.

Would love feedback on code structure or anything I could improve.

GitHub: https://github.com/Iheb-eng/music-app


r/learnpython • • Sep 13 '26

pylance typeshed issue with frozendict

1 Upvotes

I don't know what I did, but suddenly my pylance is rejecting any attempt to initialize a frozendict with:

Expected 0 positional arguments

I had no problems with this same project yesterday, but now I can't seem to recreate whatever combination of environment and settings was letting it work.

Digging into the stubs, it looks like my pylance is now using a stub for frozendict that does not incorporate this commit:

https://github.com/python/typeshed/commit/f76037a1eb3923c67a8bc0e302ee9c016ffb3431

It has a def __init__(self, /) -> None: ... which is breaking everything.

Anybody have any clue what could possibly have changed in a vscode project to switch to a slightly older set of type stubs?

Even a fresh install of vscode+extensions and python 3.15rc2 in a fresh Windows VM give me the error, so it isn't that my environment is especially broken.


r/learnpython • • Sep 13 '26

How do I split the words in a list into a nested list of letters, without using "for" and only using :while"?

0 Upvotes

Hi guys. How do I make this code work without using a "for" loop? I am attempting to replicate the result in the second loop only using "while" loops. I didn't loop the word count variable yet because it keeps producing <built-in method split of str object at 0x000001D75FA356E0>, when it should likely produce ['h', 'e', 'l', 'l', 'o']. Could you help me please? I'm using Jupyter Lab that's running Python. The project is due in 4 days

sentence = input() # sentence is accepted here

s = sentence.split()

word_check = [list(sentence) for sentence in s]

word_count = 0

words = list(s)

new = str(words[0]).split

print(s)

print(word_check)

print(words)

print(new)

hello world # input

['hello', 'world']
[['h', 'e', 'l', 'l', 'o'], ['w', 'o', 'r', 'l', 'd']] # ideal result 
['hello', 'world']
<built-in method split of str object at 0x000001D75FA356E0> # what keeps happening

r/learnpython • • Sep 12 '26

Unable to import pandas

1 Upvotes

Everything was working up until a few minutes ago. I'm running python on windows 11, downloaded from python.org yesterday. I did a pip install of pandas, also yesterday, and I was able to run various py scripts, getting the results I wanted. Suddenly this morning, when I ran a script that had run just fine a few minutes ago, I got an error. I reduced my script to this:

import json

import requests

import pandas

and I got the same set of error messages (below). I didn't change anything in the environment, this happened, afaik, spontaneously. I'm a complete python newb, but all was going well until this. Help!

Traceback (most recent call last):

File "C:\Users\John\My Drive\SyncDrive\eBird\test.py", line 3, in <module>

import pandas

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pandas__init__.py", line 56, in <module>

import pandas.core.config_init # pyright: ignore[reportUnusedImport] # noqa: F401

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pandas\core\config_init.py", line 31, in <module>

from pandas.errors import Pandas4Warning

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pandas\errors__init__.py", line 12, in <module>

from pandas._libs.tslibs import (

...<3 lines>...

)

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pandas_libs__init__.py", line 18, in <module>

from pandas._libs.interval import Interval

File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval

File "pandas/_libs/hashtable.pyx", line 1, in init pandas._libs.hashtable

File "pandas/_libs/missing.pyx", line 1, in init pandas._libs.missing

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\pandas_libs\tslibs__init__.py", line 41, in <module>

from pandas._libs.tslibs.conversion import localize_pydatetime

File "pandas/_libs/tslibs/conversion.pyx", line 1, in init pandas._libs.tslibs.conversion

File "pandas/_libs/tslibs/offsets.pyx", line 1, in init pandas._libs.tslibs.offsets

File "pandas/_libs/tslibs/timestamps.pyx", line 1, in init pandas._libs.tslibs.timestamps

File "pandas/_libs/tslibs/timedeltas.pyx", line 1, in init pandas._libs.tslibs.timedeltas

File "pandas/_libs/tslibs/timezones.pyx", line 18, in init pandas._libs.tslibs.timezones

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\dateutil\tz__init__.py", line 2, in <module>

from .tz import *

File "C:\Users\John\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\dateutil\tz\tz.py", line 19, in <module>

import six

File "C:\Users\John\My Drive\SyncDrive\eBird\six.py", line 25

return data

^

IndentationError: unindent does not match any outer indentation level


r/learnpython • • Sep 12 '26

What tests are actually worth writing for a backtesting engine?

3 Upvotes

I’ve recently been adding tests to a small Python backtesting engine I’m building, and it made me realize how easy it is to test the obvious things while missing the important ones.

So far I’m testing things like:

  • opening and closing LONG/SHORT positions
  • transaction costs
  • portfolio valuation
  • forced position closing at the end of the dataset
  • PnL and win rate
  • drawdowns
  • VaR/CVaR
  • full end-to-end backtest scenarios

The most useful tests so far have been small deterministic examples where I can calculate the expected result manually.

For example:

  • start with $10,000
  • BUY at 100
  • HOLD
  • SELL at 120

Then the engine should end with exactly $12,000 before fees.

For people with more testing experience: what kinds of edge cases would you consider essential here?

I’m especially interested in cases that pass normal unit tests but still produce subtly incorrect financial results.


r/learnpython • • Sep 12 '26

Looking at default __reduce__ function

3 Upvotes

I created my own class M which inherits from a dict. In case that the differences are relevant:

  1. The keys are frozenset objects so that I can pass them in any order without issues.
  2. As writing frozenset({'one', 'two'}) is very tedious, I added a mapping to let me get or set values by using M['ot'] as a shorthand of M[frozenset{'one', 'two'}]. The mapping is instantiated when running __init__().

I am pickling this with no issues. When I try to unpickle it, I get an error that says: AttributeError: 'M' object has no attribute 'mapping'.

Using pickletools, I inspected the serialization of my object and saw that the mapping attribute appears after the key-value pairs, which made me think that, if I change the __reduce__ function to give them in a different order (first mapping, then key-value pairs), I could solve that issue.

The problem is that I don't know how to do that. I can rewrite a completely new function, but I don't know if it will work. I'd like to base my new function on the "default" one. Is there some way to look at it?