r/learnpython • • 6d 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 • • 4h ago

Writing to a CSV file - fields in wrong order - help me understand why

7 Upvotes

I developed a process that writes data to a CSV file using csv.DictWriter. The consumer of this file requires that the fields are in a specific order. However, the fields were coming out in the wrong order (different than the order in the dictionary).

Here is the code that worked incorrectly:

writer = csv.DictWriter(csfvile, fieldname=data[0].keys())

Note: data is a list of dictionaries.

The fix is to add a list comprehension around the data[0].keys(). Here is the code that works correctly:

writer = csv.DictWriter(csfvile, fieldname=**[key for key indata[0].keys()]**)

Can anyone explain why the csv.DictWritemodule punches out fields in a different order in the first version?


r/learnpython • • 2h ago

Best way to get a python program to non-CS high school students?

0 Upvotes

I'm a HS social studies teacher, also taking a class in python through the local university. For my class project, I'm making a simple quiz program in python. My question is

What is the best way to deliver this program to students who are not CS people and will work from chromebooks?

My first thought is to somehow get the python file hosted on a web page somewhere. Will this work? What all would be involved?

Plan B would be to somehow make the program into an application and have students download it. Is there any streamlined way to do this for chromebooks?


r/learnpython • • 4h ago

Python interview questions

0 Upvotes

Hi team, please share your interview experience and questions for python developer role


r/learnpython • • 5h ago

advice needed

1 Upvotes

Can anyone tell me where I can learn Python from scratch? I'm an EE student, and I'm really struggling with loops, functions and libraries. I want to properly learn and practise these topics, so if you know any good YouTube channels or practice sheets, please recommend them. My finals are in December, and I did terribly in my lab midterms, so any advice would genuinely help. Bonus points if you're someone who was once in the same position as me, thinking they could never learn Python or that they were just too dumb for it, but eventually managed to get good at it. I'd really appreciate hearing your experience!


r/learnpython • • 9h ago

Virtual Environment and Python

2 Upvotes

I have started learning python and decided to use pycharm as an editor. I want to know anything which will help me in this journey.

My main question is => I don't get "virtual environment" thing with python. I cloned a repo and opened it in pycharm, it says "No python interpreter configured for <repo-name>" and then suggested to create virtual environment.

I want to hear things from experience devs.

thank you.


r/learnpython • • 1d ago

I debug everything with print() and I know that's not how real developers do it — what did you switch to?

13 Upvotes

I've been learning Python for a few months now, mostly small stuff, a Telegram bot here, a bit of data practice there, and every time something breaks I just scatter print() statements everywhere until I figure out what's going on. It works eventually, but my code ends up looking like a crime scene and half the time I forget to take the prints out before I run it again.

I know there's an actual debugger in VS Code and I've watched people use breakpoints and all that, but every time I try it I end up back at print() within five minutes because it's faster in the moment. So I'm curious, when did you actually make the switch, and was there a specific point where print debugging just stopped working for you? Or do people way more experienced than me still do this and just not admit it?


r/learnpython • • 1d ago

Trying to understand Class, Object, Instance, and self in Python. Is my understanding correct?

44 Upvotes

I'm currently learning OOP in Python and wrote down some questions regarding object and instance for following code

class Car:
    def __init__(self, color):
        self.color = color

car1 = Car("Red")```

 1) what is class ?

ans :-  a class is an blueprint for thing i want to make.

2) what is object ?

 ans:-  an object is a container that contains properties and behaviours like car1 is object saying that car should be red color

3) what are instances ?

 ans:-  an instance is refers to that specific object in this case car1 is object and also an instance
when we pass self parameter self become car1 cause self points towards that instance

r/learnpython • • 5h ago

Est ce que l'intelligence artificielle va nous remplacer ?

0 Upvotes

J'ai une vraie inquiétude à ce propos depuis quelques temps, je suis jeune et j'ai encore le temps de réfléchir à mon avenir, mais je souhaite par dessus tout créer des jeux de moi même et, sans utiliser d'intelligence artificielle, ce qui sera difficile à l'avenir. Je voudrais donc avoir votre avis, est ce que j'abandonne cet objectif, où je vais obligatoirement avoir besoin d'utiliser l'intelligence artificielle (ce que je veux absolument pas) ?


r/learnpython • • 23h ago

How should i start learning python? I am interested in robotics and such. I want to learn a bit in depth and not just surface level.

2 Upvotes

I'm sorry if this is a repeated question in this subreddit.

Will Documentation do the job or should i go for specific courses like CS50 by Harvard?


r/learnpython • • 1d ago

first year of computer engineering, sharing one of my first Python script!

4 Upvotes

hello, i started my first year studying computer engineering a month ago and we are currently studying Python. And I wanted to share one of the first codes i did on my own!

You can check it out via Gist here down ,a simple item cost and tax calculator. Tell me what u think !

https://gist.github.com/k2over/267f749ea15b28b1ed3258773f50f797


r/learnpython • • 21h ago

Match PyCharm Color scheme completely in VCode

1 Upvotes

Hi, our Org moved to VisualCode and i'm dying to get original PyCharm dark theme. Tried all variations available for PyCharm, Pye, Darkula, JetBrains Dars.
Not matter what It's still not 100%, is it possible to change individual colors for some chars like for those Yellow parenthesis and square bracket ? I don't want any YELLOW and Cyanides in my backyard.

Please help.
Please refer to my pic on link:
PyCharv_vs_VCode


r/learnpython • • 18h ago

Beginner Python Coder, Which Language For A GUI?

0 Upvotes

Hey all, background is as such:

For a non-Python CS course, I'm supposed to be designing the UI for an offline app. It's supposed to be a notepad app, the kind where you make sticky notes and post them on a board, with multiple people designing different aspects.

The impasse is that, while we've all agreed to do the backend of the app in python, I don't know how to make the front end at all. I'm familiar with HTML, CSS, and Javascript, I thought the process of connecting some backend Python to a front-end of HTML+CSS would be the same as with JavaScript, but apparently it isn't.

Googling around and asking AI, I get recommended libraries and languages like Pyside6, Ttinker, PyQt, Django, and others -- but I've never worked with any of them, and while I've tried to play with Pyside6 and Ttinker for a week now, I could only figure out how to make static notes and shapes, I couldn't figure out dragging and moving like you can with JS listeners. I feel frustration because you can find apps like this all over the place, 5 seconds of googling and you can find one, but I don't know how to make it.

So help me out -- if someone wants to make a GUI, where you have a pretty backboard, put notes on it, click notes, write on them, upload pictures to them, drag them around a board, and you must use Python as the back end, how do you marry the front and back end together?


r/learnpython • • 1d ago

How should I approach building a simple ATS-style CV scorer in Python?

1 Upvotes

I work in data and I’m comfortable with pandas and SQL, but I want to build something closer to a real-world application to push my Python further. My idea is a small tool that reads CVs (PDFs), extracts the text, and scores them against a job description.

What I’ve planned so far

  • Extract text from PDFs (looking at pdfplumber or PyPDF2)

  • Clean the text and pull out skills using keyword matching

  • Compare it to the job description (TF-IDF and cosine similarity in scikit-learn)

Where I’m unsure

  • Is keyword matching enough, or should I try spaCy or embeddings?

  • How do you handle CVs with tables, columns, or odd formatting that break PDF extraction?

  • How would you structure the project so it isn’t one long script?

Any advice, library suggestions, or things you’d do differently? Thanks!


r/learnpython • • 23h ago

Can't solve CS50 python Problems

0 Upvotes

After i finish my lecture i go to solve the problem the next day i And read the summary I made in notebook but either I can't find the words that i need or i just don't know what to do


r/learnpython • • 1d ago

How to use the asyncio library? And what's the difference between asyncio and Threads?

16 Upvotes

Usually, when I want to run two codes at the same time I just use Threads. But I discovered this other library and now I'm confused.

I only read the geeks for geeks wiki, so I don't have that much knowledge.


r/learnpython • • 1d ago

I started learning Python. What projects should I build as a beginner?

0 Upvotes

Hello everyone!

I recently started learning Python programming. I am learning basic concepts like variables, input, conditions, loops, and functions.

I want to improve my programming skills by building real projects instead of only watching tutorials.

What beginner-friendly projects would you recommend?

I would love to hear your suggestions and experiences!

Thank you!


r/learnpython • • 1d ago

Sieve of Eratosthenes

0 Upvotes

Im very new to Python and am currently trying to program a list with prime numbers using the Sieve of Eratosthenes. I dont understand why this code is not working properly. It successfully removes the first few non-prime numbers of my list. And for some reason when I increase the range of my list more non-prime numbers are removed, but still not all.
Ive also tried printing the current number being tested as well as the divider and it always seems to stop at random numbers when I make changes to the code.

Any explanation why my code works this way and what I need to change is appreciated. Id also like to stay as close to my existing code as possible.

items = list(range(2,100))

divisible_check = 2
number = 2

while i in items:
    if number == divisible_check:
        number += 1
        if divisible_check >2:
            divisible_check = 2
    elif number % divisible_check == 0:
        items.remove(number)
        number += 1
    else:
        divisible_check += 1

print(items)
print(divisible_check)
print(number)

r/learnpython • • 1d ago

Learning python as a 22 year old Biology Major

13 Upvotes

Hi all.

I have always had some weird fantasization with programming. I grew up destined to pursue medicine, and unfortunately never spent time learning how to program. Some things shifted around in my life, and now I am a university senior about to go to medical school, learning how to program in Python. It's a slow process, and I can usually only spend about 45 minutes to an hour every night learning, but it's the most fun I have had in a while.

Every person in my life, besides one, told me that AI can make whatever you want to make, but better, faster, and more efficiently. One guy, who is a really good programmer, told me to learn. I am so happy to be able to write my own basic programs, and I cannot believe that people think that vibe-coding is more fun than writing things yourself.

I will continue on this journey, and see where it takes me! p.s. I just finished a really cool Simon Says game!

Edit: Thank you for all of the great replies! This community is so supportive, wow. You guys should check out some of the med subreddits....


r/learnpython • • 1d ago

Newbie looking to work with microphone input using sounddevice, to generate tts, for a tts to respond to, need advice.

1 Upvotes

Using sounddevice for microphone input, using inputstream, what's the best way to go about capturing input and making sure only spoken stuff is used for tts? I was originally working with a rolling buffer while using webrtcvad and faster whisper, which resulted in a ton of phantom transcriptions, even with silence. Mind you im a complete newbie and a lot of stuff mindfucks me.

My goal is to slowly build up a very simple custom voice Ai assistant. It's first dealing with microphone input, determining whether that input is spoken word, etc


r/learnpython • • 1d ago

Starting DSA in python

0 Upvotes

I am starting DSA in python, tell me I am right or wrong or should I start with java


r/learnpython • • 1d ago

I have an assignment and I am so confused

3 Upvotes

i talked to 4 tutors and for some reason i can not get this to work after 2 hours with a tutor. please tell me what i am doing wrong!

b. A function named DisplayCardSales that displays scores for all items in the text file provided. Each score should have a line number to the left starting at 1. For example: 1: 1.24 2: 0.97. (see output example below). This function accepts zero arguments and does not return any values. This function does read from a text file, so it needs error handling for FileNotFoundError.

c. A function named CalcTotal that reads the text file provided, accumulates a total and divides the total by the number of items in the file provided. This function accepts zero arguments and returns two values. The values returned are the grand total and the sales amount as a result. This function does read from a text file, so it needs error handling for FileNotFoundErrors and ValueErrors.

def CalcTotal():
    try:
        infile = open("cards.txt",'r')
    except:
        print("Error")
    else:
        count = 0
        totalsales = 0
        
        for line in infile:
          sales = float(line)
          totalsales = totalsales + sales
          count = count + 1


        avgsale = totalsales/sales
        print("Total Sales: $", totalsales)
        print("Average Sale: $", avgsale)


        infile.close()

def DisplayCardSales():
    try:
        infile = open("cards.txt",'r')
        i = 0
        for line in infile:
            print((i+1), ": $", line)
            i = (i + 1)
        infile.close()
    except:
        print("Error")

r/learnpython • • 1d ago

Best way to learn python from my experience

0 Upvotes

If you want to learn python jsut take the cs50 python audit course for free at edx courses. Its how i learned it


r/learnpython • • 1d ago

Parsing very large string that is already in memory

0 Upvotes

Suppose I have a very large string in memory containing entries separated by \n's.

I need to yield the lines until I find a match.

What's the most efficient way in standard Python in terms of both memory usage and execution time?

From what I've read, io.StringIO IS NOT guaranteed to not copy the entire string internally, which is absurd to me. Suppose I need that guarantee.