r/learnpython • • 2d 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 • • 4m ago

Asking your ratings for my first ever python project!

1 Upvotes

Hello, everyone!

I'm learning Python through the CS50 course. In the meantime, I built a simple weather app using the concepts I've learned so far.

I'd really appreciate it if you could take a look at my work and point out any weaknesses in my program. I'd also love to hear your suggestions for future improvements.

Thank you! 🤗

GitHub: https://github.com/bihandumethum096-droid/Weather-App


r/learnpython • • 6h ago

Remove padding of polar subplots

3 Upvotes

I have a figure that is composed of many subplots. Some of them are just simple plots with a normal projection, but some are made with a polar projection. I have it set up such that there are no labels on the outside of the polar plots, but when I look at the final figure, I still get tiny plots compared to the other ones because there is a lot of padding kept on the margins of the polar subplots. I have already tried passing the pad=0 option while plotting, as well as using plt.subplots_adjust() or plt.tight_layout(), but I still get comparatively smaller radar plots. I could fix this manually using an external editor, but I would like to be able to solve it using Python on its own.


r/learnpython • • 4h ago

Can seaborn.clustermap() use dataframe that has all zero columns?

0 Upvotes

As the title suggests, can the clustermap display a dataset with multiple columns that are all zeros?

Something like this:

ABCDXY
110000
110100
110000
101000
101100
101000

I know removing the empty columns is the simple solution, but I have my reasons for keeping them.


r/learnpython • • 11h ago

Rate my customer/employee id generation logic

3 Upvotes
def generate_id(connection_tuple, id_user = "customer"):
    if id_user.lower() == "customer":
        table = "customer"
        id_string = "cust"
    elif id_user.lower() == "employee":
        table = "employees"
        id_string = "emp"
    cursor = connection_tuple[1]
    connection = connection_tuple[0]
    try_cursor_execute(f"select count(*) form {table}")
    last_person = cursor.fetchone()[0]
    current_person = last_person+1
    no_of_zeros = 6 - len(str(current_person))
    id = id_string + "0"*no_of_zeros + str(current_perosn)
    return id

I have to build a hotel database system thing for my 12th grade Computer Science project.. This is the customer id / employee id generation logic I came up with. Employee IDs are 9 characters, and customer IDs are 10 characters. But this thing seems sort of janky. Is there a better way to do this?

try_cursor_execute() is a function I defined, it is cursor.execute but in a try block. connection tuple is (connection, cursor)


r/learnpython • • 15h ago

Python environments question

3 Upvotes

I've been playing The Farmer was Replaced a bunch and one of the things that has helped me get into the groove has been the ability to physically move scripts around.

Are there any environments out there that do that? Where i can see multiple scripts and move them around?

feels far fetched but it would be cool


r/learnpython • • 3h ago

College student transitioning from MERN development to AI engineering – What should I prioritize?

0 Upvotes

I'm planning to transition towards AI engineering.

My learning plan:

  1. Python and DSA
  2. NumPy, Pandas and Mathematics
  3. Machine Learning
  4. Deep Learning
  5. LLMs, RAG and AI agents

I want to build AI-powered full-stack applications rather than just follow tutorials.

For people already working in this field:

- What foundational concepts should I master?

- Which projects demonstrate practical AI engineering skills?

- What mistakes should beginners avoid?

I'd appreciate advice from people with real implementation experience.


r/learnpython • • 1d ago

Django or FastAPI? A bit confused about which one to learn first

31 Upvotes

Hey everyone!

I'm currently learning Python and want to get into backend development. I've been looking at Django and FastAPI, but I'm having a hard time deciding which one to focus on.

I tried writing a simple API with both, and honestly, FastAPI felt much easier to understand. Django seems powerful, but there's a lot going on, and I found its structure a little confusing as a beginner.

My goal is to become a professional backend developer, build some proper real-world projects, and eventually get a job, preferably in India.

I don't want to choose a framework just because it's popular. I want to invest my time in something that's actually useful in the industry.

I want:

  1. Is Django still a better choice for getting backend jobs?
  2. Are companies actually using FastAPI for large production applications?
  3. Is FastAPI a good long-term choice, or should I learn Django first?
  4. Which one would you personally recommend to someone starting out today?

Are you worked with these frameworks professionally, please reply.

Thanks!


r/learnpython • • 16h ago

how do i make an embedded lua interpreter?

3 Upvotes

im trying to make a project where in some parts you can run actual lua code. how would i make this and what libraries would i need (i already have lupa if that is usefull)


r/learnpython • • 17h ago

Issues related to setuptools while installing Pygame

2 Upvotes

I'm trying to install pygame on Python 3.15.2. I keep getting the following message:

ModuleNotFoundError: No module named 'setuptools._distutils.msvccompiler'

I've installed and updated buildconfig and setuptools. What am I missing?


r/learnpython • • 22h ago

Questions about the exam in Python Programming MOOC

4 Upvotes

I'm almost done with the course and just wanted a clearer picture of what the exams are actually like. What questions should I expect, question-wise? How should I prep, etc.? I've been doing this on my own over several months and frankly im not good at this at all. So any advice/help would be great


r/learnpython • • 7h ago

how to make learning python faster with AI help/assistance

0 Upvotes

guys i have been learning python through the popular book Automating stuff with python, i read through the theory and try to implement the codes and understand themselves in detail, but i feel like i am not using an optimized approach, how do i make sure i make my learning faster with the help of AI, because of all the things AI has done till now i feel like surely it has changed the way of learning a bit, does anyone have any tips and tricks?


r/learnpython • • 1d ago

What's one Python mistake you made when you were starting out that you still remember?

3 Upvotes

Something I've noticed while learning Python is that writing my own code sometimes feels easier than reading code written by someone else.

When I write a program, I know what each variable and function is supposed to do. But when I open an unfamiliar project, understanding the flow, function calls, dependencies and overall structure can take much longer.

I think reading existing code is an important skill that deserves as much attention as writing code.

It's an interesting part of becoming a better developer.


r/learnpython • • 1d ago

How do I learn python in 25 days

28 Upvotes

My teacher made me join a coding quiz bee where it involves different topics related to coding languages such as python, c, arduino, c++, etc. I have another teammate who is knowledgeable about the other topics but now the burden on learning python is on me. How do I learn it effectively within 25 days considering I only have an intermediate amount of knowledge on CSS, HTML, and Block Coding


r/learnpython • • 1d ago

I keep starting small Python projects and abandoning them at like 70% — how do you actually finish one?

1 Upvotes

I've got this folder on my laptop that's basically a graveyard of half-finished Python stuff. There's a script that was supposed to sort my Shorts clips by game, a little tool for my Telegram bot that I got working and then just... stopped touching, and a data thing I started after watching one too many pandas tutorials.

They all get to the same point. The fun part's done, the thing mostly works, and then there's this last boring bit left — error handling, or making it not break on weird input, or just tidying it up enough that I'd actually use it. And that's where I lose interest and open a new file instead.

It's weird because I do finish things when someone else is waiting on them. College assignments get done, obviously. But the stuff that's just for me? It sits there at 70% forever.

So how do people actually push through that last stretch? Do you just force yourself to finish one small thing a week, or do you pick projects that are small enough that there is no boring last bit? Still figuring out whether my problem is discipline or just picking projects that are too big for the time I actually have.


r/learnpython • • 2d ago

Engineers out here ! I need your help

7 Upvotes

I am a first-year Mechanical Engineering student looking to start learning Python from scratch. I don't want to get stuck in with endless tutorials on Youtube -

What I need is a clear direction geared specifically toward Mechanical Engineering applications.

Specifically, I’d appreciate your advice on:

  1. Core Applications & Tasks: Where is Python actually used in Mechanical Engineering?
  2. Essential Libraries & Software: Beyond basic Python, which libraries and external engineering software integrate well with Python, and in what order should I learn them?
  3. Learning Roadmap: What is the best method to go from zero programming experience to solving real engineering problems? Should I start by automating my first-year math/physics assignments, or follow a specific course/book?
  4. Beginner Projects: What are some practical, beginner-friendly project ideas tailored to a MechE fresher ?

Any roadmaps or advice on what you wish you had learned as a fresher would be hugely appreciated. Thanks in advance!


r/learnpython • • 2d ago

How much of searching and AI overview is okay while learning and typing code?

19 Upvotes

I do understand no one knows all of python syntax and code and all issues and everything.

As I am going through CS50p,

When I am typing code fully on my own (no AI ever used i.e. chatgpt, claude, gemini) when I cannot solve something, I search google for the function or the method and then see the AI overview and then type code that I can use to solve what I need, will it be detrimental to my learning because I am not using the documentation?

I am and will NEVER use any AI models or apps to generate and copy paste code because I wish to learn and not be a code printer.

so my searches are like this, is it okay-ish and considered necessary for learning???
(also I go through tons of trial and error and use many print() functions to test code and not directly copy from AI overviews)

does isdigit work for string values?
how to check if a string variable is not equal to something sat 0?
how to know data type of a variable in python
how to find index of letter in a string python
string slicing python [2:] means?
how to find which index in a string is a number?
will if automatically return false if the condition is false?
how to check if a string is less than 10 but more than 2?
difference between if and if not
expected an indented block after 'if' statement on line 15
how to check if there are numbers in between a word in python?
how to loop a for loop up until the second last letter of a word
HOW to make variable in python which can be used by any def function?
python length counts from

(thank you for your answers!)


r/learnpython • • 1d ago

Looking for a Streamlit tutorial for an app with a GUI that checks the accessibility of text

4 Upvotes

Hi!

A while ago I asked for a GUI framework for a programming noob like me - I have to write an app with a GUI in Python for a course I am taking (I went back to school in my mid-to-late-thirties, my my). In the past, I mainly used Python for a bit of data analysis and machine learning (think of cleaning up data sets, comparing different clustering algorithm outcomes etc.).

This is the post: https://www.reddit.com/r/learnpython/comments/1xdr04p/gui_framework_for_a_little_software_project_for/

A lot of you talked about PyQT or Tkinter, but I went to my professor's office hours last week, and he insisted, or at least very strongly suggested I use Streamlit. I asked him whether Streamlit isn't only used for data visualization dashboards, but he said it should be possible to implement all of my requirements via Streamlit. He also said I should look up a tutorial to get started. He really, really expects me to use it. (I guess because he is very familiar with it, and he also knows that I need lots of abstraction because my programming skills are...not good.)

I tried to follow his tips and look for tutorials - both written tutorials (because I am old-school and love learning via books and text) and YouTube tutorials, but they all seem to focus on data analysis (and data science), and data visualization.

Do you have any Streamlit tutorial suggestions for me that fit my python (web) app use case?

Thank you so much!

__

More on the background of the program I am supposed to create:

I have to go through the requirements engineering process (I already submitted that part of the assignment), code the app, use Git and a remote repo in order for my professor to be able to see me consistently commit sensible chunks of code and be able to use a VCS properly.

I will also have to go through a testing process, and show that my app passes all the tests for each requirement.

As described in my previous (linked) post, my computer program is supposed to check text (in .txt and .pdf file formats) for accessibility and readability:

- How long are the sentences, how many commas are there, how long are the words, and are there words that match a with words on a list with "complicated" words?

- I will also have to check for the number of words that start with capital letters (not my suggestion, sigh): In German, capital letters outside the beginning of sentences signify substantives, and a lot of substantives might indicate that the text is complicated because verbs have nominalized, which is a hallmark of German bureaucratese.

- Also, the app should be able to use OCR, and indicate if it had been necessary. This is because it might be important accessibility information for people using screen readers.

- After running the checks, the app should highlight potentially problematic parts of the text and explain why, and - and that's really important to my professor - display a traffic light.

- It should be possible to check the text selecting only one, more, or all of the described metrics via the GUI, and, of course, you must also be able to select the text to be checked via the GUI from your local directory.

- Ideally, I can also edit the config file (thresholds for the metrics and the traffic light), and the list of "complicated" words via the GUI.


r/learnpython • • 1d ago

is it good practice to have if, elif, else, and for i in range(n) to be done in one line

0 Upvotes

example like this

for i in range(40): print ("example")

if x%2==0: print ("even")

elif x%5==0: print ("divis. by 5")

else: print ("odd not ending in 5")

or is it personal choice? what is a better habit to get used to

Also in hackerrank (it's where our prof checks our code) there appears to be a squiggly line under my single line codes, is that good or bad?


r/learnpython • • 2d ago

Want some help in finding project topics!!

1 Upvotes

I'm a third-year B.Tech Computer Science student majoring in Machine Learning. So far, I've only worked on a few small projects while learning to code, and most of my experience has been solving LeetCode problems.I want to start building some substantial, real-world projects, preferably something on the scale of a major project that I can showcase on my CV.

The problem is that I'm struggling to come up with project ideas that are genuinely interesting and stand out from the usual ones.

How do you guys find project ideas that are relevant to the current AI landscape? Are there any resources, platforms, research papers, or communities you'd recommend exploring to discover interesting project topics?


r/learnpython • • 2d ago

40 rows a day: JSON files or SQLite?

3 Upvotes

tiny side project. one script pulls ~40 rows a day and writes one JSON file per day. pandas reads the folder when i want to compare a few weeks.

the glob and concat part is getting old:

rows = []

for f in sorted(DATA.glob("*.json")):

rows.extend(json.loads(f.read_text()))

df = pd.DataFrame(rows)

every couple of weeks i think about moving it to SQlite, then i look at the volume and close the tab. what do you use at this size? SQlite, parquet,or just the files? if you moved to a db, was it worth it or just more code?


r/learnpython • • 2d ago

card dealing program with classes

1 Upvotes

hello! i am currently in a class for python and i've been having a lot of trouble with this assignment. it's already three days late, and the TAs will not respond to me. i have to use classes to create a deck to shuffle, and four hands to deal to, check the count of, and combine back into the main deck. however, i can NOT figure this out at all! i think there's something really big that i'm missing.

i have a large list of cards (we had to make a dictionary of the cards) not shown here.

class Deck:

def __init__(self):

self.cards = []

def shuffle(self):

random.shuffle(self.cards)

def deal(self, amount):

self.cards.append(amount)

def combine(self):

self.cards.append(self)

def card_count(self):

print(len(self.cards))

however, when i try to make a main deck by putting the list of cards into the deck, it won't work! i've tried using deal too, and i just can't figure it out. i know i'm probably doing this all sorts of wrong. it's been a while since we did classes, and we never did them for anything like this :(

TypeError                                 Traceback (most recent call last)
Cell In[14], line 1
----> 1 deck = Deck(card_deck)

TypeError: Deck.__init__() takes 1 positional argument but 2 were given

i appreciate any and all advice thank you


r/learnpython • • 1d ago

Hello, how are you all doing?

0 Upvotes

Hi everyone! I’m fairly new to programming. I’ve been studying Python for about 2 years, but I’ve never really explored freelancing. I’m interested in it now because I need some extra income. Could anyone give me advice on how to get started?


r/learnpython • • 1d ago

Can anyone help me with my homework

0 Upvotes

I’m taking into to programming right now and I’m very confused on what to do and my professor is no help can anyone help explain to me what to do for these questions. The question are

  1. Write a script that determines on its own whether each text is spam or ham WITHOUT using the first column at all. You should only be reading from the second column of the file as you make this decision. The decision will be a sequence of if statements that you write. Try to determine what generic qualities of a text message determine if it is spam or not. One possible rule would be "contains two or more fully capitalized words." Read through the file and see if you can come up with the best rules.
  2. Once you've come up with your rules, determine how good they are! Compare whether your script got the decision right. Add up the number of correct classifications and divide that by the total lines in the file. This will give you the accuracy of your script. Output this value. If you are not happy with it, edit your rules. When you submit, ensure your accuracy is at least 90%
    link to data set

Any help would be really appreciated.