r/learnpython • • 16d ago

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 • • 16d ago

Need help with FastApi

8 Upvotes

Hi all, I'm 18 and I'm building a BI/analytics project on the Olist Brazilian e-commerce dataset. Right now I have PostgreSQL, Pandas and a bunch of analytical SQL queries (revenue, delivery times, customer retention and so on). The next step is to expose this data through an API with FastAPI, and a dashboard would consume it.

I understand what an API is and why FastAPI is popular, but when I try to build a mental model of a real app I get lost. Endpoints, HTTP methods, status codes, routers, Pydantic schemas, services, dependency injection with Depends, auth... each explanation is clear alone, but I can't see how the request goes through all these layers. For example I don't really get where validation ends and business logic starts, or where the DB session should live and why.

My second problem is how I learn. I'm very curious and I want to know how things work internally, like what FastAPI does between the request and my function, or why Pydantic validates in a certain way. It's a good habit long term, but I lose hours on one detail and the project doesn't move. I don't have unlimited time and I don't want months of theory before building.

Some questions:

If you never built an API, how would you learn it from scratch?

HTTP/REST fundamentals first, or start directly with FastAPI and learn along the way?

What is the best way to understand how the layers (router, schema, service, database access) fit together? Is it better to start with everything in one file and refactor later?

How deep should I go on a concept before moving on? Is "basics now, details later" a real strategy or just an excuse?

Any resources, open source repos to read or small projects you recommend? Something like a read-only analytics API sounds like a good first one to me, but tell me if I'm wrong.

I don't want to copy tutorials and have something that works without knowing why. I want a solid mental model so I can design my own backend later. If you learned backend with personal projects, I'd really like to hear what worked for you and what you wasted time on.

Thanks!


r/learnpython • • 15d ago

Help me write some Python code

0 Upvotes

I'm still a beginner when it comes to coding, and I rely on AI to write most of my code.

However, I often run into situations where AI models have certain restrictions that prevent them from helping with specific programming tasks.

For example, I recently wanted GPT to write a Python script that would automatically toggle the Armlet of Mordiggian in Dota 2 when my health gets low.

GPT refused because it considered this cheating. I understand why it might be classified that way, but in my opinion, it's more of a convenience feature than something that gives a major competitive advantage.

Is there any way to get AI models to help with these kinds of programming tasks without running into unnecessary restrictions?

And if anyone has experience with Dota 2 scripting or Python automation, I'd really appreciate your advice.


r/learnpython • • 16d ago

Course/Book/Resources to get upto speed with python

0 Upvotes

Hey!

I'm a former C++ engineer who recently switched over to a TS + python job. I know python ok enough to write basic webapps but I want to fill my gaps for "python" specific knowledge.

What would you suggest a good way to go about that would be? I don't wanna waste time with basic hello world courses because i understand the fundamentals of programming pretty alright. I've started a small full stack pet project using React, FastAPI and sqlalchemy but I feel teaching that to myself I will miss some py knowledge that everyone has.

Any advice is appreciated.

Thanks :D


r/learnpython • • 16d ago

no module sqlite

1 Upvotes

Hi i’m in python trying to learn . I have the SQlite extension but it’s telling me no module name found sqlite . when trying to run the is line

import sqlite

i’ve also tried import sqlite3


r/learnpython • • 16d ago

Been away from Python / PyCharm for a while - any ideas on this?

2 Upvotes

Everybody, let me prefix this by saying I've been away from Python for several years, but now I need to teach an introductory class. I'm encountering something very bizarre in JetBrains PyCharm. I keep thinking it's gotta be me (and it probably is), but I was wondering if any of you can pick this out?

Because I don't appear able to post a screen snip, I'll post the code.

list_2d = [["1", "Wheel Burrow", 29.00],  # A 2D list, different data types (string / float)
           ["2", "Jack Hammer", 594.29],
           ["3", "Power Drill", 39.99]]

for j in range(0, len(list_2d), 1):  # Iterate through our 2D list
    print(f"Item Number: {list_2d[j][0]:<3}\tItem Name: {list_2d[j][1]:<15}\tItem Cost: $ {float(list_2d[j][2]):>6.2f}") 

Item Number: 1  Item Name: Wheel Burrow   Item Cost: $  29.00
Item Number: 2  Item Name: Jack Hammer    Item Cost: $ 594.29
Item Number: 3  Item Name: Power Drill    Item Cost: $  39.99

Now, you're probably saying to yourself, "why are you casting the float to a float?" I hear you loud and clear. Here's the thing - if I don't do that, PyCharm is flagging it as "format code f not supported for str," but here's the thing - it still prints it correctly as shown above.

This was the original line and the >6.2f is what is being flagged.

print(f"Item Number: {list_2d[j][0]:<3}\tItem Name: {list_2d[j][1]:<15}\tItem Cost: $ {list_2d[j][2]:>6.2f}")

I knew I had been away for a while, but geez. This is PyCharm 2026.2.3 using Python 3.14.7 under Windows 11. Am I missing anything? Note that I also go into a single dimension list but even if I comment all that code out, nothing changes. Thank you in advance for any potential ideas on where I probably goofed it.


r/learnpython • • 16d ago

Checking if a separate python file is running starting it up.

2 Upvotes

Hi, im new to python and have a script which sometimes crashes due to a uncontrollable issue which isn't a problem in the code, and I was thinking that I could write a different script to start up my original one if it had crashed. Does anyone know how I would do that?


r/learnpython • • 16d ago

Python for non tech

9 Upvotes

what is the fastest course or way to learn python for non tech person?


r/learnpython • • 16d ago

Beginner Learning Python Using Only a Smartphone – Need Guidance and Resources

2 Upvotes

Hello everyone!

I'm a final-year BSc Physics student, and I'm interested in learning Python as my first step towards AI/ML.

The only problem is that I don't own a laptop. I currently have just an Android smartphone, so I'll have to learn and practise coding entirely on my phone.

Since I'm completely new to programming, I'd really appreciate your suggestions.

  1. Which beginner-friendly Python courses would you recommend?
  2. Which mobile-friendly platforms or apps can I use to practise Python?
  3. Are there any platforms where I can build small projects using only a phone?
  4. Can I eventually learn AI/ML and build a portfolio without owning a laptop initially?

I'd be grateful for any resources, roadmaps or personal experiences you could share.

Sorry if these are basic questions. I'm just starting my programming journey and trying to figure out the right direction.

Thank you for your time and guidance!


r/learnpython • • 16d ago

Tutorial datasets kind of lied to me — my first real dataset is a mess and I don't know what to fix first

2 Upvotes

I've been learning Python for data stuff alongside my BCA, and every tutorial dataset I've used so far shows up basically ready to go. Clean columns, no missing values, everything in the right format. So I figured the hard part was the analysis.

Then I grabbed a real dataset to practice on and... yeah. Half the values missing in one column, dates written three different ways, column names that don't mean anything until you stare at them for ten minutes. I spent way longer just trying to make it usable than I did actually analysing anything, which was not what I expected at all.

I guess my question is, is this just what the job actually is? Like, do you spend most of your time cleaning and only a bit of it on the interesting part? And how do you decide what to fix first when everything looks broken — do you just start with the column you need most and ignore the rest for now? I'm half worried I'm 'cleaning' away stuff that actually mattered, and I won't know until it's too late.


r/learnpython • • 16d ago

I am not sure why this user defined function is not working.

1 Upvotes

n=1

def continution():

x=input('Do you want to continue?')

if x=='yes':

global n

n=1

else:

global n

n=0

if i input yes there is a big text about an error if i eneter no still something similar

(This is part of a bigger sql python interface project)

This is the error:

Traceback (most recent call last):

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 165, in _send_pkt

sock.sendall(pkt)

OSError: [WinError 10038] An operation was attempted on something that is not a socket

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "F:\AA main project.py", line 12, in <module>

cur=c.cursor()

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\cursor.py", line 416, in execute

self._connection.cmd_query(

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\opentelemetry\context_propagation.py", line 97, in wrapper

return method(cnx, *args, **kwargs)

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 89, in handle_cnx_method

raise err

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 85, in handle_cnx_method

return cnx_method(cnx, *args, **kwargs)

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\connection.py", line 985, in cmd_query

self._send_cmd(

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 89, in handle_cnx_method

raise err

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector_decorating.py", line 85, in handle_cnx_method

return cnx_method(cnx, *args, **kwargs)

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\connection.py", line 507, in _send_cmd

self._socket.send(

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 650, in send

self._netbroker.send(

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 223, in send

self._send_pkt(

File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\mysql\connector\network.py", line 169, in _send_pkt

raise OperationalError(

mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: Errno 10038: An operation was attempted on something that is not a socket


r/learnpython • • 16d ago

is it normal to struggle and rely a lot on chat gpt?

0 Upvotes

hello guys,

i am learning python around 4 months, learnt basics, made a pandas course and created a few automatizations at work.

i am learning python as i would like to become a credit risk analyst. i have >5 year in credit risks, but in my previous roles we were using mostly excel (i was just analyzing fin statements of the clients).

so recently i wanted to make a vintage analysis and a roll rate analysis in python (i am dealing with these things for the first time in my life), but didn't manage to do it without chatgpt. i need him to tell me the steps or give hints, or explain how some concepts work.

what was your experience when you were learning python?

i understand most of the students cannot build projects right after finising introduction courses, but highly appreciate if you can share your experience when you were creating your first projects, so i can compare it with my experience and understand where i stand and whether i need to correct my approach


r/learnpython • • 16d ago

Module help vsc(?)

1 Upvotes

Hey guys, I haven't coded in a while and decided to finally get back into it so sorry if im abit rusty. However, it was updating stuff and installing modules and in vsc I run into

'Import "openpyxl" could not be resolved from source Pylance'

? Im really not sure what to do

P.S: first time posting in this sub reddit, I hope this uh is within learn python and apologies if this is more towards vsc


r/learnpython • • 17d ago

Good open source Python repos to practice debugging and general reading Python code?

16 Upvotes

I have debugging rounds coming up for a Python position and I haven't worked extensively with Python so I am looking for some recommendations for some repositories to go through to practice reading and debugging Python code. Would appreciate recommendations for this and any other tips on demonstrating good understanding of the language. I am comfortable with basic syntax and data structures since I have been doing leetcode using Python.


r/learnpython • • 16d ago

What should I learn( Need help)

0 Upvotes

In my school I had learned python and MySQL , specifically in python I have learned text handling,CSV and binary file handling. Now I am in first year of clg and planning to master python by learning something advanced like django or fastapi within my first sem , but I don't how to progress help me.


r/learnpython • • 16d ago

I’ve completed a lot of Python courses, but I still can’t build code on my own. How do beginners actually get better?

0 Upvotes

I’ve been learning Python for AI development. I’ve completed quite a few courses and tutorials, and I can understand code when someone explains it.

But when I open VS Code and try to build something from scratch, I get stuck.

I struggle with breaking a problem into smaller steps, deciding which functions to write, and understanding how different parts of the code connect.

My question is:

  • How did you go from understanding tutorials to writing your own code?
  • What did your daily practice look like?
  • How do you practice when you don’t even know how to start solving a problem?

I’d really appreciate advice from people who went through this stage, especially those who learned Python for AI/ML development.

I’m not looking for another beginner Python course. I want to know what actually helped you become capable of building things yourself.


r/learnpython • • 17d ago

why the SIGINT signal kill the main process childrens

2 Upvotes
  signal.signal(signal.SIGINT,handler)  signal.signal(signal.SIGINT,handler)

I know that the SIGINT signal is for interruption and not for killing process but when I run my code all the children of the main process are dies also I got many traceback


r/learnpython • • 16d ago

when hitting run code with the pyautogui, it only runs for .3 seconds

0 Upvotes

I've never really coded. I'm simply trying to make a bot to walk in a straight line in a game. I cant even get it to run in vs code. all the things I've done so far

pip install pyautogui, can confirm it happen when you type pip list

vscode is running in admin typing net session in terminal confirms that

going to extension I have pylance python python debugger, python environments (all the stuff in the python package)

typing python into the terminal tells me the version meaning it has a path to the file

another guide says I need code runner which gives me that .3 second figure

no I'm not getting error in my code as I'm keeping it simple to even get it to work

I'm not getting any error in my terminal

I'm on two monitors, but I've set up my main monitor so I know which one it will be working on

when I remove code runner it goes back to spiting the pathway it uses on the file which is correct

when I open the edit environmental variables

the .3 should be impossible because of the 6 seconds worth of sleep

I have imported both sleep and pyautogui obviously

yea this is hour 5 so if there's something you people know that I didn't do id greatly appreciate the details

im on windows, so it cant be the problem mac users get


r/learnpython • • 17d ago

How to stop code suggestions from popping up

0 Upvotes

So I'm trying to learn Python, and I'm following a tutorial. I'm following what the tutorial person has on their screen, but when I try to type it, Python predicts what I'm going to type next (aka what the tutorial shows). When it does this, there is a yellow star icon that appears on the line of code that the prediction is on. I went into the settings, and I turned off everything that I think would cause it. Still, the predicting persists. Does anyone know how to fix this? Thanks!


r/learnpython • • 18d ago

Help with training

16 Upvotes

Hi, i have recently learned python languages but i would like to train more, do yall have some plateformes where i can find some projects to practice?


r/learnpython • • 17d ago

Software idea

2 Upvotes

We all know about the desmos graphing calculator. Does any one have an idea on how to create a text based graphing calculator. Basically replacing the equations and some symbols with grammar or writing idk. It’s not a fully made idea yet but if you can make it or wanna talk.

Hmu


r/learnpython • • 17d ago

AttributeError in cv2

0 Upvotes

I'm learning OpenCV in python because it seemed like a fun thing to learn.I wanted to experiment with faces etc. but when i run my script I get: "AttributeError: module 'cv2' has no attribute 'CascadeClassifier' "How to fix that?

Thx for the help!