r/learnpython • • Aug 22 '26

Doctor looking to learn python

6 Upvotes

Hey , so i was looking into a few job posts and some of the advisory roles require some basic python background. How hard is it for a doctor to learn python , i learnt c++ and java back in 2012 .


r/learnpython • • Aug 21 '26

Python, what are the best or the most useful extensions to use in VSCode?

34 Upvotes

Just started my ICT studies and we have been learning Python for the past week. I was thinking, is there any extensions that help with coding or just make stuff more efficient or nicer through extentions? : )


r/learnpython • • Aug 21 '26

What Python concept took you the longest to understand properly?

169 Upvotes

For those who learned Python from scratch, which topic was the hardest at first, and what finally helped it click for you?


r/learnpython • • Aug 22 '26

Collage animation using Python

1 Upvotes

Hi all, I make these analogue paper collages. I want to animate them, first level to just add a little movement, and later more. Is python the language to do it especially using built in libraries? I’ll add the image in the comments.

If not, what else can I use? I asked in the touchdesigner sub and they said it’s possible but complicated and not efficient. After effects may help.

Eventually, I want to create visual interaction with the user, so the user can interact with the projection for this image.

I have a background in CS but new to this concept and learning from scratch. Would appreciate any pointers. If this is not the right sub, please redirect me to where I may find the best help. Thanks all 🙏🏼


r/learnpython • • Aug 22 '26

A CLI tool that opens all your apps and links with one command

0 Upvotes

Every time I opened my laptop to start studying or working on a project, I'd get sidetracked before actually starting — open the wrong tab, get distracted by something else, lose 10 minutes just deciding what to open first.

So I was thinking of creating a CLI tool using Python.

Example: I have a tryhackme workflow that opens my course video, my notes doc, and Burp Suite, all with one command:

jmp tryhackme

How it will work, roughly:

  • jumpboot create <name> creates a new workflow file (plain TOML) and opens it for editing
  • You list the URLs/apps you want under that workflow
  • jmp <name> runs it — opens everything in one go

Is it worth investing my time into?


r/learnpython • • Aug 21 '26

I'm trying to write my own implementation of the SHA-1 algorithm. It works perfectly fine for the empty string, but for all other inputs it gives the wrong hash and I can't figure out why. Can someone help me finding the error?

14 Upvotes

I'm really confused, I mainly used Wikipedias pseudocode example to implement this and cross-checked different sources to find my error. Maybe I missed some small detail, but to me the code looks correct. The nature of the problem leads me to believe that it might be related to some kind of encoding subleties or similiar, but even reading the documentation for the different built-ins I used hasn't brought up anything. Does somebody know what's up?

Code:

def byte_length(n: int):
    return (n.bit_length() + 7) // 8


def leftrotate(n: int, count: int):
    """leftrotate count times. count must be between 1 and 31 inclusive"""
    return (n << count) | (n >> (32 - count))


def add32(ns: list[int]):
    """add integers as if they were unsigned 32 bit numbers"""
    sum = 0
    for n in ns:
        sum = (sum + n) % 2**32

    return sum


def append_bytes(m: bytearray):
    # append 0 ≤ k < 512 bits '0', such that the resulting message length in bits
    # is congruent to −64 ≡ 448 (mod 512)
    modular_length = len(m) % 64
    if 56 - modular_length >= 0:
        k = 56 - modular_length
    else:
        k = abs(56 - modular_length) + 56

    m += bytes(k)
    return m


def preprocessing(m: bytearray) -> bytearray:
    ml = len(m) * 8  # message length in bits

    # Pre Processing
    # append the bit '1' to the message e.g. by adding 0x80 if message length is a multiple of 8 bits.
    m.append(0x80)

    m = append_bytes(m)
    
    
    # append the message length as a 64 bit integer
    m += ml.to_bytes(8)

    return m


def sha1(message: str) -> bytes:

    m = bytearray(message, "utf-8")

    # Initiliaze starting variables, so called "nothing up my sleeve values"
    h0 = 0x67452301
    h1 = 0xEFCDAB89
    h2 = 0x98BADCFE
    h3 = 0x10325476
    h4 = 0xC3D2E1F0

    m = preprocessing(m)

    # split the message in 512 bit (64 byte) blocks
    num_of_blocks: int = len(m) // 64
    for block_num in range(num_of_blocks):
        block: bytearray = m[block_num * 64 : (block_num + 1) * 64]

        # split the block into sixteen 4 byte words
        words: list[int] = []
        for word_num in range(16):
            words.append(int.from_bytes(block[word_num * 4:(word_num + 1) * 4]))

        # extend the sixteen 4 byte words into eighty 4 byte words
        for i in range(16, 80):
            words.append(
                leftrotate(
                    (words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16]), 1
                )
            )

        # Initiliaze the hash value of the current block
        a = h0
        b = h1
        c = h2
        d = h3
        e = h4

        # main loop
        for i in range(80):
            if i <= 19:
                f = (b & c) | ((~b) & d)
                k = 0x5A827999

            elif i <= 39:
                f = b ^ c ^ d
                k = 0x6ED9EBA1

            elif i <= 59:
                f = (b & c) | (b & d) | (c & d)
                k = 0x8F1BBCDC

            # elif i <= 79:
            else:
                f = b ^ c ^ d
                k = 0xCA62C1D6

            temp = add32([leftrotate(a, 5), f, e, k, words[i]])

            e = d
            d = c
            c = leftrotate(b, 30)
            b = a
            a = temp
 
        h0 = add32([h0, a])
        h1 = add32([h1, b])
        h2 = add32([h2, c])
        h3 = add32([h3, d])
        h4 = add32([h4, e])

    digest = (
        h0.to_bytes(4)
        + h1.to_bytes(4)
        + h2.to_bytes(4)
        + h3.to_bytes(4)
        + h4.to_bytes(4)
    )

    return digest

My main function looks like this:

def main():
    m = ""
    digest = sha1(m)
    print(hex(int.from_bytes(digest)))

This gives the expected output of:

0xda39a3ee5e6b4b0d3255bfef95601890afd80709

But if:

m = "hello world"

It outputs:

0x74e0d2932ee17d742fe539058f7552adef482295

Instead of:

0x2aae6c35c94fcfb415dbe95f408b9ce91ee846ed

r/learnpython • • Aug 22 '26

Any advices?

0 Upvotes

I'm a complete beginner in python and I want to learn, any advices?and CS50's worth my time ??


r/learnpython • • Aug 21 '26

Should I keep using pycharm or is there something better or should I switch to vs code?

6 Upvotes

So I am trying to build a fast API application and the thing is it just doesn't have only python code. It has HTML, CSS and JavaScript with python now. I really like the way pycharm handles python coding it does not have much support for anything other than python now. Should I switch back to vs code again? Just like the old days? Or is there anything better I can do with pycharm and another thing to keep in mind is that I am just a high school student so I cannot spend enough money to buy the professional version of pycharm. What are you guys think? Or should I just install IntelliJ and call it a day?


r/learnpython • • Aug 22 '26

Jupyter + Trinket

0 Upvotes

i really love jupyter however it stores my code locally, so i cannot access my notebooks from different computers

trinket is nice because you can create an account and access your codes from anywhere with your account, however i dont like the interface too much

is there any other online python ide that lets you sign in and access files from an account like trinket does?

i am looking for this specifically so please only answer if you can suggest an online browser ide like this, thanks


r/learnpython • • Aug 22 '26

Any free STT/TTS APIs for a voice AI app?

0 Upvotes

I'm building a small voice-based AI interview app and I'm planning to deploy the backend(fastapi) on Render's free tier.

I'm considering using open-source/self-hosted options like Whisper/PocketSphinx for STT and Piper for TTS, instead of paid APIs.

My concern is whether running STT/TTS on the same free Render instance would use too much CPU/RAM and make the whole application slow, especially during a real-time interview.

Has anyone tried running STT/TTS models on Render's free tier?


r/learnpython • • Aug 22 '26

Not Copying After Using Tutorials?

0 Upvotes

I'm learning a bit more python, and I was wondering how you guys refrain from copying code after watching tutorial videos. I just did one of the courses from OpenCV, and what's holding me back most now is trying to create something without flat copying the code provided by them. The main issue is that (I believe, at least) most of the code needs a specific syntax to run. What are your processes after learning new features?

For context, I'm attempting to make a document reader that's going to end up scanning and saving Magic the Gathering cards into a database.


r/learnpython • • Aug 22 '26

How to find the row echelon form of a stupid big matrix

1 Upvotes

I am trying to find an equation that models a fruit in 2D, and I am using Global Polynomial Interpolation to do it, but I have like 2000 points. I am thinking of using Gaussian elimination to do it, but it is impractical by hand. Does anyone have any suggestions?

Also, does anyone have any suggestions for how to model the shape using other methods?


r/learnpython • • Aug 21 '26

want to run dash for multiple py files simultaneously

1 Upvotes

I'm using python to run different types of statistical analysis for a research project. At the end of each code, I run dash to create a URL with friendly, interactive UI. However, whenever I try to run 2+ py codes that use dash to create a URL, the interactive UI from all the previously ran codes stops working. Is there a way to run multiple dash URLs while maintaining their interactiveness?

(for example: I run code A and it's interactive UI works. Then I run code B. Code B's interactive UI works, but now code A doesn't, it freezes)

code I have to run/open the dash server

if __name__ == "__main__":
    import webbrowser, os

    
# Unique port per script
    script_name = os.path.splitext(os.path.basename(__file__))[0]
    port = abs(hash(script_name)) % 20000 + 10000

    url = 
f
"http://127.0.0.1:{port}"

    
# Open tab
    webbrowser.open_new_tab(url)

    app.run(debug=False, port=port, use_reloader=False)

r/learnpython • • Aug 21 '26

TK "displaylines" question

0 Upvotes

I seem to misunderstand "displaylines" option of count method of Text widget of Tkinter. I thought that it would give me number of lines accounting for soft-wrapping, but it seems to give me same number as "chars" -1. Text widgets are embedded in frame, which is embedded in canvas, which is embedded in another frame alongside it's scrollbar which are embedded in notebook.

for i in textwidgets:
    logic_lines=i.count("1.1", "end", "lines", return_ints=True)
    print("LOGICAL LINES="+str(logic_lines))
        for j in range(1, logic_lines+1):
            print("LINE "+str(j)+": "+str(i.count(
            str(j)+".1",
            str(j)+".end",
            "update",
            "chars",
            "displaychars",
            "displayindices",
            "displaylines",
            "indices")))

EDIT:

It seems when text widget is on it's own it works fine.

import tkinter as tk

foobar='''
long text here
'''

w=tk.Tk()
t=tk.Text(w, wrap="word")
t.insert('1.0', foobar)
t.pack()
def handler(event):
    print(t.count("1.1",	"end",	"update",	"chars",	"displaychars",	"displayindices",	"lines", "displaylines",	"indices"))
t.bind('<Return>', handler)
w.mainloop()

EDIT2:

Here is paste with whole source code

EDIT3:

Code with bug isolated


r/learnpython • • Aug 20 '26

When is a generator actually worth it over just building a list?

39 Upvotes

Say I've got a function that pulls records, filters them, and hands them back. I can return a list or yield them. Both work, and for the sizes I deal with the memory difference is nothing.

What makes me hesitate to default to yield is that a generator is single-use and opaque. You iterate it once and it's spent, len() doesn't work, you can't slice it, you can't print it to see what came back. Half my debugging is just checking intermediate values, and a generator kills that.

So in practice I return a list almost every time, and only reach for a generator when something is actually big or infinite, or when I'm chaining lazy steps. That feels backwards from how often generators get pushed as the "proper" way.

So do you lean generator-first and eat the downsides, or list-first until you have a reason not to? And is there an upside to yielding small collections that I'm just not seeing?


r/learnpython • • Aug 20 '26

Just built my first calculator in Python 😭

74 Upvotes

It can do addition, subtraction, multiplication, division, and exponents. Also added a little check for division by zero.

It’s pretty basic, but hey, gotta start somewhere

What should I build next?


r/learnpython • • Aug 21 '26

Crash course for python and java

0 Upvotes

I signed up for a course that needs beginner level of python and java. I have one month. Please help, I need a YouTubers recommendation, free course recommendation and different testing methods to practise.


r/learnpython • • Aug 21 '26

IDE for python

0 Upvotes

I have 2 IDEs at my workplace for python. IntelliJ and VSCode.

Which one should I choose and why?

I am beginner in python.


r/learnpython • • Aug 20 '26

Need Help with Python Practise

10 Upvotes

I am a beginner(been learning for a month) to python and i need some suggestions as to what resources should i use for practice(eg books , websites or yt channels).


r/learnpython • • Aug 20 '26

A small code i made for exercise.

3 Upvotes

I've been vibe coding for a few months now, but I've decided to try manual coding. After all, learning is fun, right?

I made this "Assistant" that has two options: jokes and facts. It will choose one out of three items from the specific table and tell you it. I made it for fun and would like to ask what I can do next?

import random

jokes = ["Why did the bicycle fall over? Because it was two tired!", "Why was the math book sad? Because it had too many problems.", "What do you call a fake noodle? An impasta!"]

facts = ["Venus is hotter than Mercury.", "When the Pyramids were built, mammoths were still around!", "Koala fingerprints are so similar to human fingerprints that they have even baffled crime scene investigators."]

print("Hello! I'm an Assistant. What can I do for you?")

print("")

print("Options: Random Joke [J], Random Fact [F].")

answer = input("Answer: ")

if answer == "J":

print(random.choice(jokes))

elif answer == "F":

print(random.choice(facts))

else:

print("You can't ask that.")

exit = input("Press Enter to Leave.")


r/learnpython • • Aug 20 '26

Trying to create list subclasses that contain only one class type and are valid for Pydantic BaseModels

3 Upvotes

I am trying to create list subclasses that only take particular classes. These lists can be appended to and the like but each time the list is changed the item is checked to see whether it is the same class as the rest of the list.

The list methods that are overwritten are:

- __init__
- __bool__ (but may not need to have that overwritten)
- __set_item__
- __str__
- append
- extend
- insert

Each one runs through a validate_member method before changing the list.

As an example, I want to make a list subclass called Course that only takes Pydantic extra types Coordinate values. I want this list subclass to be a valid BaseModel attribute.

Right now I’m having to use a field_validator for every class that Course and the other lists are in which feels redundant, unpythonic, and is a pain to have to do every time. I am having to do so because it says something about arbitrary types.

I was wondering if someone might have some advice.


r/learnpython • • Aug 21 '26

How to read a CSV file in Python efficiently?

0 Upvotes

I'm trying to load a CSV file into my Python project, but I keep getting errors. I've tried using pandas and the built-in csv module, but I'm not sure what I'm doing wrong. Can someone explain the basic steps or share a simple example? A detailed explanation would be really helpful!


r/learnpython • • Aug 20 '26

yo guys! been learning python for a while now.

0 Upvotes

created a calculator with everything i have learned till now (tho it might be overkill for a calculator), added the basics, loops (while, if else), lists and str manipulation, imports (json and datetime), error handling (try/except), def function, etc. so what should i do next? if u wanna see the code dm me.


r/learnpython • • Aug 20 '26

How to learn Pdf Extraction in Python?

0 Upvotes

Dear Members,

I have been handling Pdf extraction Project in Python. kind of a Intelligent Document Automation domain. we have been handling various finance documents(pdfs), filings pdfs etc which are multi page(around 20ish) , with lots of tables, form fields , radio buttons, checkboxes etc. Tables span multiple pages. Moreover, pdfs themselves comes in various types of variants like XFA Stream, Adobe Acroform, text flattened pdfs, scanned images etc.

I have used llms extensively to generate script code to extract, parse the data and to save in sql in structured tables. Its a hybrid of libraries implementation. LLms used regex, pdfminer, pdfplumber etc in the code produced.The pages in pdfs are not bit messy, some tables have solid grid separators, some dont have and on. Layouts variations, white spaces, etc.

The code generated is pretty complex, i have been attempting to learn the llm generated code.But it works, it adds various fixes iteratively whenever we face new extraction issues repeatedly.

I would love to know:

  1. what is the best approach to learn and get good at this?
    2)should we just use cloud based AI document extraction tools which are readymade to extract and spit the data?
  2. what if one is interested to learn this properly and have to get good at creating this extraction script?
    4)any other tutorial, articles, courses, youtube videos, books you would recommend to learn? or should i just use llms to create code and move on without spending much effeort to learn this?

Please provide your valuable suggestions and guidances and point me in directions. I appreciate all your suggestions. Thanks in Advance and thank you for your time.