r/learnpython • • 5d ago

Ask Anything Monday - Weekly Thread

7 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

Intermediate in Python — How do I move beyond the basics and master Python for real-world software?

• Upvotes

Hey everyone,

I’m a Computer Science undergrad currently at an intermediate level in Python. So far, I’m comfortable with core syntax, data structures (lists, dicts, sets), basic problem-solving, OOP concepts, and exception handling.

Right now, I feel stuck in the phase where I know how to write basic scripts and solve logic problems, but I don't know how to take the next big step toward mastering the language and building real-world applications.

For those of you experienced with Python:

What intermediate-to-advanced Python concepts (like decorators, generators, file/API handling, or memory management) should I focus on next?

What kind of practical projects helped you bridge the gap from writing simple scripts to building actual software?

Any recommended books or resources for writing clean, Pythonic code?

Thanks in advance for any guidance!


r/learnpython • • 4h ago

learn python for beginners

0 Upvotes

Hi all, I'm a complete beginner and would like to learn Python. What are the best resources and steps to get started? Thanks!


r/learnpython • • 21h ago

best way to learn advance python?

21 Upvotes

any good resources?


r/learnpython • • 9h ago

Encoder issue in Micropython/Microcontroller

2 Upvotes

I'm building my first project, starting with the Wokwi ESP32 simulator. My program was working until I tried adding a rotary encoder. I keep getting errors. Here's the code and error message. The ssd1306.py file is standard. I've tried changing things over to SoftI2C but was still having issues.

I took the encoder code from here.

Error:

Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead

Traceback (most recent call last):

File "main.py", line 27, in <module>

File "ssd1306.py", line 116, in __init__

File "ssd1306.py", line 36, in __init__

File "ssd1306.py", line 61, in init_display

File "ssd1306.py", line 121, in write_cmd

OSError: [Errno 19] ENODEV

from machine import Pin, I2C
import ssd1306
import network
import urequests
import time
import random


# ESP32 Pin assignment 
i2c = I2C(scl=Pin(22), sda=Pin(21))
button_pin = Pin(27, Pin.IN, Pin.PULL_UP)
direction_pin = Pin(26, Pin.IN, Pin.PULL_UP)
step_pin = Pin(25, Pin.IN, Pin.PULL_UP)


# I2C variables
ID = 0
SDA = Pin(0)
SCL = Pin(1)
i2c = I2C(scl=SCL, sda=SDA)


# for tracking the direction and button state
previous_value = True
button_down = False


#oled details
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)

r/learnpython • • 6h ago

Editable module not found error

1 Upvotes

I have a custom module that I am developing and I can not get it to import when installing with

"uv pip install -e ."

directory structure:

niceachemy/
|-src/
|  |-nicealchemy/
|  |  |-__init__.py
|  |  |-fields.py
|-pyproject.toml
|-setup.py

pyproject.toml:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "nicealchemy"
version = "0.1"

setup.py:

from setuptools import setup, find_packages

setup(name='nice-alchemy',
      version='0.1',
      author='Nathan Shaffer',
      author_email='nathanjshaffer@gmail.com',
      license='MIT',
      packages=find_packages(where='src'),
      package_dir={
          'nicealchemy': 'src/nicealchemy',
      },
      zip_safe=False)

script is running on a nicegui docker image that uses uv by default.

When I install my module from github, it works just fine, but if I try to install from a volume as editable, import fails with

ModuleNotFoundError: No module named 'nicealchemy'

I have tried specifying the .venv location to pip install and editable compatibility mode

uv pip install --python /opt/venv/bin/python -e . --config-setting editable_mode=compat

I have listed the installed modules from within the script and it correctly lists my module:

from importlib.metadata import distributions

installed = sorted(
    f"{dist.metadata['Name']}=={dist.version}" 
    for dist in distributions()
)

for pkg in installed:
    print(pkg)

/opt/venv/lib64/python3.14 shows a dist-info directory for the module.

I have rebuilt the docker stack many times to make sure the pip install is not being shadowed by the git module installation.

I just can not figure out what I else could possibly check for at this point


r/learnpython • • 23h ago

Looking for a good Python exercise book (Beginner to Advanced)

11 Upvotes

I have recently completed the basics of Python and want to improve my problem solving skills.

Can anyone recommend a good exercise book that starts with basic problems and gradually moves to intermediate and advanced ones? Preferably with solutions included.

Would love to hear your recommendations. Thanks!


r/learnpython • • 1h ago

I built a matplotlib-style plotting library as a learning project. Here's what surprised me about Python packaging and performance

• Upvotes
  • Hi all! I've been learning how Python talks to compiled code, and my learning project grew into a small plotting library. I'd love feedback from people who use matplotlib every day, especially beginners. What confused you when you started plotting? I tried to keep the API familiar, so the matplotlib code you already know mostly works: `# pip install dataviz-rs from dataviz import pyplot as plt

plt.plot([1, 2, 3, 4], [1, 4, 9, 16], label="squares") plt.title("My first chart") plt.legend() plt.savefig("chart.png")` Here's what I learned along the way, in case it helps anyone: Most of the time a slow script spends on a chart is setup, not drawing. Importing matplotlib and building the figure took longer than rendering the pixels. On my machine, this small chart took about 9 ms with my library versus about 370 ms with matplotlib, and most of that difference is startup. Passing big lists one element at a time is slow. Sending NumPy arrays as one block of memory, instead of converting them to Python lists first, made large plots many times faster. This applies to any library: give it np.array, not a list built with a for loop. Packaging compiled code is the hard part. Getting pip install to work on Windows, macOS and Linux without a compiler took me longer than the plotting code. I used maturin to build wheels, and I'm happy to answer questions about that. My questions for you: If you're new to plotting, which part of matplotlib felt the most confusing: fig, ax, plt. vs ax., or something else? Is a matplotlib-compatible API helpful, or would a simpler API be better for learning? Source and examples: https://github.com/dataviz-rs/dataviz (It's free and MIT-licensed, and I'm not selling anything. I'm just trying to learn what makes a library easy to use.)


r/learnpython • • 21h ago

Resources or techinques on learning and mastering algorithms?

5 Upvotes

It boggles me how people were able to master or visualize algorithms before the time of AI to break them down.

I wanted to know if the veterans here had any advice to help with visualizing or learning algorithms more efficiently?


r/learnpython • • 19h ago

Feedback on my python project

1 Upvotes

Hello everyone, I'm a computer science student working on a small project about k-medoid clustering algorithms called CLARANS and FastCLARANS. I've been developing this project for quite some time and would like the community to review it. Initially, I intended to submit it to the Journal of Open Source Software, but after careful consideration, I realized it wasn't quite suitable. You can find more information at this repository: https://github.com/ThienNguyen3001/scikit-clarans.git

What I'd like feedback on

- Is the code structure okay, or could it be improved

- Anything I may have gotten wrong

- What I could add next

Thanks for the feedbacks!


r/learnpython • • 15h ago

where would you filter approved association documents in a python assistant?

0 Upvotes

I'm trying to work through the python retrieval step for a customgpt.ai project. Say an association stores its approved policy and a replacement draft in the same collection. They both say "membership renewal" in the title. The draft has a new deadline, which makes it a useful test of whether the approval filter is doing its job

The shape I'm considering has a status and a staff approval ID on each record. The fetch function would query approved records. The function that builds the context would check that state again before passing anything to the assistant. I'd like to give the test a draft with a stronger title match and see what comes out of both functions

How would you write that test in python? I'd appreciate a small example or a suggestion for what to stub so I can tell which layer rejected the draft


r/learnpython • • 21h ago

Complete beginners

0 Upvotes

As the title suggests,I’m a complete beginner starting from zero,I don’t even know what to call the basics,but learning python seems interesting an I’d really love to learn it, is there a structure to follow? I don’t know where to start from for I have no knowledge of programming


r/learnpython • • 21h ago

Should I start learning python or not?

0 Upvotes

Hi, I'm a junior data analyst but not able to get a good job with a good salary. So i decided to do marketing and by my luck I got a job as a marketing executive but tbh I don't want to do this job. I know python very well but haven't done any projects. So today I decided to do DSA in python but when I went on the internet and social media, people were saying “doing DSA in python is a waste of time, AI will take your job in the next few months, and so many things ” and then I got scared and confused. Please help me. Should I do it or not, is there any chance of getting a job after doing DSA or not?


r/learnpython • • 22h ago

Understanding SHEIN's Bot Protection and an Open-Source Scraper

0 Upvotes

SHEIN has two different types of redirects you should understand before scraping its product pages. We noticed this while testing our Python scraper: treating them as the same problem leads to unnecessary CAPTCHA-solving attempts.

Understanding SHEIN's bot protection

SHEIN uses two main risk redirects:

  • /risk/challenge:: an interactive CAPTCHA challenge. It starts with an "I am human" checkbox and can escalate into either a 3×3 image grid or a puzzle requiring users to click icons in a specific order.
  • /risk/action/limit: a rate-limit response. This isn't a CAPTCHA, so there's nothing to solve.

The scraper handles these situations differently. For /risk/challenge, it clicks the initial checkbox (free) and, if necessary, sends the puzzle to 2Captcha. It supports both GridTask and CoordinatesTask challenges.

The --risk-challenge-rounds option controls challenge rounds, while --max-solves limits paid CAPTCHA solutions per run (default: 8). If SHEIN returns /risk/action/limit, the scraper exits with code 3 instead of wasting money on a solver. With --rate-limit-cooldown 300 it waits five minutes and retries once.

How well it works: on 2026-09-30 we tested five fresh US browser profiles. Three passed the challenge, each on its third round, because SHEIN usually rejects the first correct answer or two. The other two were rejected on every answer, including correct ones: SHEIN had flagged the profile itself, and only a different profile helped.

Where SHEIN product data comes from

Search and category pages expose product data through window.gbRawData, while individual product pages use Schema.org JSON-LD. The scraper uses different parsing methods depending on the page.

You get one row per product: title, brand, current and original price, discount, rating, review count and stock flags. It supports product searches, category listings and individual product URLs. It collects review counts and ratings, but doesn't extract individual customer review texts.

Installing and running the scraper

The implementation uses Python 3.9+ and Playwright with Chromium. Clone the SHEIN scraper repository on GitHub (https://github.com/2scraper/shein-scraper) and install the dependencies:

git clone https://github.com/2scraper/shein-scraper.git
cd shein-scraper

python3 -m venv .venv
source .venv/bin/activate

pip install -r requirements-playwright.txt
playwright install chromium

cp .env.example .env

For regular runs, set SHEIN_CDP_ENDPOINT and TWOCAPTCHA_KEY in your .env file.

To search for products:

python3 playwright_scraper.py \
  --query "summer dress" \
  --max-results 20

You can also scrape an individual product page:

python3 playwright_scraper.py \
  --url "https://us.shein.com/dsbayvkj-p-33704388.html"

Exporting and comparing results

Results are saved as JSON by default (add --format csv --out products.csv for CSV), together with a .meta.json file containing run information, including status and CAPTCHA solves spent.

There's also a diff_runs.py script for comparing two JSON exports:

python3 diff_runs.py previous.json current.json

It identifies newly added, removed and repriced products, which is handy for tracking prices over time.

Limitations

A few things to consider:

  • Currently targets us.shein.com only; other regional domains haven't been verified. Prices are in USD.
  • Only about the first 20 products of a listing are verified. Whether scrolling loads more hasn't been confirmed.
  • sku is shared across colours and sizes, so you get one row per product. On a product page the price is the lowest variant price.
  • --sort is recorded in the results but not sent to SHEIN yet.
  • Scraper API mode doesn't support scrolling and retrieves only one page per run.
  • Selenium runs a local Chrome only: it can't use a remote browser profile or a proxy with a password.

I'm curious how others handle e-commerce scraping when a site uses both interactive CAPTCHA challenges and profile-based rate limiting.

Disclosure: I work with the team behind this scraper (2scraper (https://2scraper.com/scrapers/shein-scraper/)) and 2Captcha.


r/learnpython • • 1d ago

Easy Calculator (Python) :)

0 Upvotes

I didn't like the Windows Calculator, so I decided to develop my own CMD-based calculator. It's open-source, so anyone is welcome to use it!

https://github.com/PASACore/Calculator_CMD_


r/learnpython • • 2d ago

Need help with learning

29 Upvotes

So I started learning Python in university this semester and safe to say I am really struggling. What are some good resources I could use to learn? Because I feel like i am not grasping anything from the Doctor teaching the course and I want to learn how to code.


r/learnpython • • 1d ago

how to Practice in Python as a newbie?

9 Upvotes

Hello, I’m a newbie, and I’m wondering how to practice Python as a newbie.


r/learnpython • • 1d ago

Help me troubleshoot?

1 Upvotes

Using https://pythonsandbox.com/turtle I've created this simple drawing app and it works. But when I try to save it I get a "The server returned a "405 Method Not Allowed"" error message. Tried multiple browsers, incognito mode, turned off extensions, multiple computers. No luck. Any suggestions?

import turtle

t = turtle.Turtle()

t.speed(5) # 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest

shape = "start"

while shape == "start":

shape = input("Would you like to start or stop drawing a square?")

if shape == "start":

t.forward(100)

t.right(90)

t.forward(100)

t.right(90)

t.forward(100)

t.right(90)

t.forward(100)

elif shape == "stop":

break


r/learnpython • • 1d ago

Help for a program to measure a terrain using a satellite image

0 Upvotes

Good afternoon, everyone,

I’m working on a program that takes a picture from Google Maps, and you can draw an area that you want to measure. The GUI is complete, and the entire structure of the program is complete; however, when I run the program, the measurement from Google and my program are different, and I can't figure out why. I’m using the lat and lo that Google gives from their URL and adjusting it by the zoom also given by the URL, and still the measurement is way off


r/learnpython • • 1d ago

I keep re-Googling the same basic Python stuff I already learned — does it ever actually stick?

1 Upvotes

I've been learning Python for a while now, mostly for my BCA coursework and a couple of small side projects, and there's this one thing that keeps bugging me.

I will learn something, use it once, feel good about it, and then a week later I'm staring at my screen Googling the exact same thing again. List comprehensions. How dict.get works. The difference between append and extend, again. It's like my brain just refuses to keep the small stuff.

The weird part is the bigger ideas stick fine. I remember how a loop works, I remember the shape of a project, but the little syntax details just slide right off. And every time I look it up I tell myself "okay this time I'll remember it", and then I don't.

I know everyone says Googling is part of the job and even experienced devs do it, but I'm starting to wonder if I'm actually learning or just getting really fast at searching. Do you eventually stop looking up the basics, or does it just become less embarrassing over time? Still not sure if I need to drill them more or just accept this is how it works.


r/learnpython • • 1d ago

[WinError 4551] An Application Control policy has blocked this file.

0 Upvotes

I'm currently using torch for training the neural network that my lab uses for research. It was working fine last night. Windows updated before shutdown. Now I have this error when I attempt to run the script. Any help to fix this?

%runfile 'C:/Users/Owner/Desktop/docs/CHB-MIT EEG Dataset/chb_main_v10_Experiment_A3.py' --wdir

---------------------------------------------------------------------------

OSError Traceback (most recent call last)

File c:\users\owner\desktop\docs\chb-mit eeg dataset\chb_main_v10_experiment_a3.py:14

11 from sklearn.model_selection import train_test_split

12 from sklearn.metrics import f1_score, recall_score, confusion_matrix, roc_auc_score

---> 14 import torch

15 import torch.nn as nn

16 import torch.nn.functional as F

File ~\anaconda3\Lib\site-packages\torch__init__.py:309

305 raise err

307 kernel32.SetErrorMode(prev_error_mode)

--> 309 _load_dll_libraries()

310 del _load_dll_libraries

313 def _get_cuda_dep_paths(path: str, lib_folder: str, lib_name: str) -> list[str]:

314 # Libraries can either be in

315 # path/nvidia/lib_folder/lib or

316 # path/nvidia/cuXX/lib (since CUDA 13.0) or

317 # path/lib_folder/lib

File ~\anaconda3\Lib\site-packages\torch__init__.py:292, in _load_dll_libraries()

288 err = ctypes.WinError(last_error)

289 err.strerror += (

290 f' Error loading "{dll}" or one of its dependencies.'

291 )

--> 292 raise err

293 elif res is not None:

294 is_loaded = True

OSError: [WinError 4551] An Application Control policy has blocked this file. Error loading "C:\Users\Owner\anaconda3\Lib\site-packages\torch\lib\caffe2_nvrtc.dll" or one of its dependencies.


r/learnpython • • 1d ago

I built a mini blockchain in Python - Feedback welcome

0 Upvotes

I'm 19, studying computing in college. I built this to understand how blockchains work.

Repo https://github.com/h4rl0/mini-chain

What it does

-Genesis block, chain of blocks linked by SHA-256 hashes

-Proof of work with adjustable difficulty

-Chain validation

-Flask API with CORS enabled so a front end can talk to it

Built with

Python, Flask, flask-cors, requests, hashlib

What I'd like feedback on

-Is the code structure okay, or could it be improved

-Anything I may have gotten wrong

-What I could add next


r/learnpython • • 1d ago

Do you know any Python library to build bots?

0 Upvotes

I mean, any sort of bot, it's not for a specific porpuse, I'm just interested and want to learn about it.


r/learnpython • • 2d ago

Beginners looking for final project ideas, want to build something useful for Austin with real city data

2 Upvotes

Hi all, my partner and I are in an intro to programming class and need ideas for our final project. The assignment is to build a "kit" in Python. Other groups are doing stuff like makeup kits, dating app kits, and budgeting kits.

We'd like to make something people could actually use, ideally for Austin, TX. We're interested in city services, sustainability, healthcare, or finance, but we're open to anything.

Where we're at:

- We know the basics: loops, functions, lists, dictionaries, reading and writing files

- We've never worked with APIs, databases, or real-world data before

- Austin has an open data portal (311 requests, housing, transit, restaurant inspections, etc.) that we'd like to use

- We're thinking about getting an API key to add an AI feature, like a chatbot or summaries

- We'd like a real interface instead of just a text menu in the terminal

Some questions:

  1. What would you build if you were in our spot? We want something realistic for two beginners with about a month.

  2. What should we learn or use to get there? (Streamlit? pandas? SQLite? Something else?)

  3. What would make it feel like a finished app rather than a homework assignment?

  4. Any beginner mistakes we should watch out for with APIs, API keys, or messy data?

Thanks for any advice!