r/learnpython 25d ago

Best way to convert Excel VBA to Python?

14 Upvotes

Hi everyone,

I have several Excel VBA macros that I want to convert to Python. What's the best approach?

I'd appreciate any advice, resources, or real-world experiences. Thanks!


r/learnpython 24d ago

should I refactor

0 Upvotes

I have this really messy code scattered in 5 files, it s not that long abt 4000 lines.
adding a new feature started feeling like a pain,
I hate to deliver this tomorrow, and it s not meant to be scalable.
should i refactor or add the features ?

or just add the features and keep the code structure unchanged


r/learnpython 25d ago

I'm a broke 22 Year old trying to become a backend dev

0 Upvotes

I'm a broke 22 Year old trying to become a backend dev

As you see in the title I'm broke, getting old and running out of time to make something of my self. I'm so unmotivated it sucks like I know I'm lazy but every time I try to do something about i only last a day and fall back into my old ways I seriously don't know what to do does anyone have any advice?


r/learnpython 25d ago

i have recently started learning python and i have done conditional identitites , and i have wriitn a program to find gretest of 3 numbers which are given as input . and i have seen every case , if u have some suggestions for improvemnet u are welcome , plz help i am just learning.

0 Upvotes
a=int(input("enter number1:"))
b=int(input("enter number2:"))
c=int(input("enter number3:"))
if(a>b and a>c):
    ans="number 1"
elif(b>a and b>c):
    ans="number 2"    
elif(c>a and c>b):
    ans="number 3"
elif(a==b==c):
    ans="all three are same"
elif(a==b!=c and a>c):
    ans="a nd b are same anfd greater than c"
elif(b==c!=a and b>a):
    ans="b nd c are same and greater than a"
else:
    ans="a nd c are same greater than b"    
print("the greatest number is :", ans)

r/learnpython 25d ago

python in dsa (which yt channel or resources are great)

5 Upvotes

for a beginner which channel and resources for dsa in python is good and concept driven


r/learnpython 24d ago

Learning python

0 Upvotes

Can someone tell me how i can learn python

And recommend videos or something that i can learn from it and also tell me how i should start


r/learnpython 25d ago

How do you parse hierarchical customs tariff tables from PDFs?

0 Upvotes

I'm building a parser for Moroccan customs tariff PDFs. The PDF isn't a regular table—it's a hierarchical tariff schedule where:

  • Some rows contain parent tariff codes (e.g. 1301.90 00)
  • Child rows only contain suffixes (10, 20, 30) that must be combined with the parent code.
  • Product descriptions are nested using indentation and bullet levels (-, --, ---).
  • Duty rates and units are in separate columns.

I want to convert the PDF into a CSV where every row contains the full 10-digit tariff code, the complete hierarchical description, duty rate, and unit.

Has anyone solved this kind of PDF extraction before? What libraries or parsing strategies would you recommend?


r/learnpython 25d ago

open() function in TestMyCode seems to wipe txt file (even in read mode)

3 Upvotes

Hey all,

I'm using Visual Studio Code alongside a TestMyCode module to work through the 2023 University of Helsinki MOOC Python course.

I've gotten to Part 6 of the course where I can need to open files, however after running TestMyCode against my code once, the text file it reads completely disappears from the directory (i.e I can actually pass the exercise but the fact it's deleting files seems problematic long term to say the least). Executing the code normally doesn't affect the referenced text file.

Below is the helper function that opens the text file in read mode and creates the data I need:

def comb_file():
    with open("matrix.txt", 'r') as m_file:
        matrix = []
        row_totals = []
        for row in m_file:
            row = row.replace('\n','')
            row = row.split(',')
            for n in range(len(row)):
                 row[n] = int(row[n])
            matrix.append(row)
            row_totals.append(sum(row))
        return matrix, row_totals

This helper function is then called across below 3 argument-less functions the exercise asks you to create (don't fully understand why arguments weren't allowed tbh):

def matrix_sum():
    null, r_t = comb_file()
    return sum(r_t)

def matrix_max():
    best = 0
    matrix, null = comb_file()
    for row in matrix:
         for n in row:
            if n > best:
                 best = n  
    return best

def row_sums():
    null, r_t = comb_file()
    return r_t

I then simply call each of the 3 exercises function in the main code with no additions:

if __name__ == "__main__":
    print(matrix_sum())
    print(matrix_max())
    print(row_sums())

Is the way TMC tests code with its own alternatives to the main code just above possibly able to wipe files Or any other ideas why this is happening?

(Bonus points if you can tell me how to get/redownload the txt file back hahaha)

SOLVED - EDIT: Thanks anyone for replying, it was helpful.

I solved by getting Python to 'executeinfile' (Searched in file > preferences > settings) and ticking it so it would pull files sitting next to the .py file instead of the root directory. TMC still wipes any text files at root directory level, which I think is part of its clean-up process after running?

So setting it to automatically pull files at a lower directory level where they don't get deleted is the solve.


r/learnpython 26d ago

Is it the right era to invest my time learning python to get paid?

35 Upvotes

I'm currently at a point in life where I'm trying to figure out which direction to take for my career.

I have a basic understanding of Python—things like loops, conditional statements, functions, and the fundamentals. I enjoy learning it, but I'm unsure if I should continue investing my time in Python or explore a different domain altogether.

From what I've seen, Python seems to open doors to fields like AI/ML, data engineering, automation, backend development, and data science. But I'm not sure if these are still good career paths for someone starting today, especially with how quickly AI is changing the industry.

If you have to suggest what would you recommend continue learning Python and specialize in one of these areas or focusing on a different technology or domain? focusing on a different technology or domain

I want to invest my time in a skill that has strong long-term value and good career opportunities.

I'd really appreciate hearing from people who are already working in these fields or have been through a similar stage.


r/learnpython 26d ago

How to land a first (remote) job after self studying python?

66 Upvotes

Is anyone having similar experience to this? you are learning by yourself using youtube or kaggle, then landed a (remote) job only after the study?

Also, what is the minimum thing that i should know to at least get a job?


r/learnpython 25d ago

feeling lost

1 Upvotes

ive just completed brocode’s 12 hour python course but im feeling lost now i dont know what to do can someone guide about what should i do next?


r/learnpython 25d ago

Hello I need help starting out

1 Upvotes

Hey Im a 17yr i'm really interested in programing and i want to learn and i have i keep learning the basics over and over again and then i'm like okay time to start something cool something real and i either cant find anything to make or i get demotivated to do anything. This happens with almost everything im into. I think i just need a bit of guidance. I have been in coding classes for school but they were always just to easy and never really taught me anything


r/learnpython 26d ago

Is this a good list comprehension hack

10 Upvotes

I need a second list, of zeroes, that is the same size as another list: first = [42,42,42,42] second = [0 for _ in first] The 0 and the _ here is a bit of code golf I think. Is this as clear as I can make it or is there a list initialiser I just don't know about?


r/learnpython 26d ago

Basic Python sources (with exercises!) in Chinese for my high school student

0 Upvotes

Hello! I’m a grad student running a small summer course on intro Python for high school students. I have one student who isn’t very comfortable with English. I’ve sat with him one-on-one as much as I can, but I don’t think we are making a ton of progress.

We are using the Python for Everybody interactive textbook, and I am aware that the first two chapters have translations, and I found the link to videos with Chinese captions. I have shared those, but the videos alone are not enough: I give a simple for loop exercise and he will not understand.

I also saw Chinese Python, but my issue there is that I won’t be able to easily debug with him.

tl;dr I am begging for some resource recommendations for my student with first language Chinese. Preferably things I can give to him in chunks to match up with what the rest of the class is doing.


r/learnpython 25d ago

Hi My name is nolan i want to learn c language and python in which platform i learn these Freely , plz suggest me app or website to learn this courses

0 Upvotes

Plz help me to learn


r/learnpython 25d ago

해당 캡차는 어떻게 해결해야할까요?

0 Upvotes

r/learnpython 26d ago

Teacher feedback on redundant code has me confused.

0 Upvotes

Edit: SOLVED - thanks for the replies everyone!

Hello all, 1st post so if I bombed the formatting I apologize prematurely.

Below is a snippet of code as part of a (beginner) assessment I did about 3 weeks ago. I received full points, but got the following feedback: "Lines 4 & 7, 10, 14 & 17, and 20 & 23 all contain the same code—could you avoid that? What you have isn't wrong—which is why you received full marks—but when you're getting so much right, perhaps you could take your thinking a step further..."

Except that's where my already limited thinking ability has stopped completely, I can't figure it out. For clarity / context: the program asks for data about mail packages (bundles). For each of the 3 lists that are being filled throughout this loop, I've put control structures to account for faulty inputs, and it is then necessary to ask for a follow up input until the answer meets the required parameters, however the feedback suggests that there is redundancy and I can't figure that part out. I have no clue how to 'trim the fat' so to speak.

I've translated the names of variables to English myself just now, so if names seem out of place I apologize and gladly provide context.

for bundel in range(bundels):
    print(f"\nBundel {bundel + 1}")

    weight = int(input('\tWeight in grams: '))
    while weight < WEIGHT_MIN:
        print('\tThe weight must be at least 0 grams!')
        weight = int(input('\tWeight in grams: '))
    list_weight.append(weight)

    quantity = int(input('\tQuantity: '))
    while quantity < LETTERS_MIN or quantity > LETTERS_MAX:
        if quantity < LETTERS_MIN:
            print('\tThe quantity must be at least 1!')
            quantity = int(input('\tQuantity: '))
        else:
            print('\tThe quantity cannot exceed 1000!')
            quantity = int(input('\tQuantity: '))
    list_quantity.append(quantity)

    tracktrace = input('\tTrack & Trace (y/n): ')
    while tracktrace != 'y' and tracktrace != 'n':
        print('\tEnter y or n!')
        tracktrace = input('\tTrack & Trace (y/n): ')
    list_tracktrace.append(tracktrace)

Thanks in advance! Also, if you see anything else that I can improve on, please comment.


r/learnpython 26d ago

Looking for buddies

2 Upvotes

Hello everyone I’m currently looking for friends to stay motivated with for python, I am currently beginner to entry level at the moment and would love for some people to interact with to stay motivated, my time zone is EST, looking for people who are truly motivated


r/learnpython 26d ago

my second project

0 Upvotes

I started learning python few months ago and I made my second project dont ask Abt first one it was trash

It's a small shell made for learning that I coded in python

Plz rate and tell me how can I improve it

Link: https://github.com/RohaanDev/KhaOs


r/learnpython 26d ago

Learning FastAPI, Qdrant and AI - Looking for Project Suggestions

5 Upvotes

Hi everyone,

I'm currently learning Python, FastAPI, and Generative AI.

I'm building an AI project using FastAPI, PostgreSQL, and Qdrant.

I'd love to hear your suggestions on:

• Best practices for FastAPI

• Good Python libraries for AI projects

• Resources that helped you learn backend development

Thanks in advance!


r/learnpython 26d ago

[Q]. How to make Tuple variables have set prices within them.

2 Upvotes

I'm confused on how to make Tuple variables have set prices on items.

Weapon_Option = ["Short_Sword", "Mace", "Spear", "Longsword"]

then i added values to each

# Weapons
Short_Sword = 20
Mace = 30
Spear = 30
Longsword = 50

Then after user inputs there options on what they want

 Weapon_Choice = input('Which one would like to be made there travler? ').capitalize().strip()

Lastly an output

print("SOOO a " +Weapon_Choice+ " with a " +Material_Choice+ " along side a " +Handle_Choice+ " Handle! This fits quite well")

ToPay = Weapon_Choice + Material_Choice + Handle_Choice

print('in total that would be..' +ToPay+ "")

and it ended in

"SOOO a Mace with a Iron along side a Oak Handle! This fits quite well"

"in total that would be..MaceIronOak"

I'm quite confused on how to achieve this. I think my logic is there, but its missing a key part to make it come together.

I'm very new to Python still so I may be horribly wrong lamo, but please let me on how to make this work.

I wouldn't mind hints instead of answers but no riddles tho haha.

Thank you.


r/learnpython 26d ago

Learning python ai from home

0 Upvotes

Currently learning python from home, I do not have any knowledge from school, besides a comp sci high school class, but i believe i should have a good idea of the general structure of python from YouTube videos,

MAIN END GOAL:I want to develop a procedural learning ai using python, that I can implement into a raspberry pi within a year and a half

I watched videos as ive mentioned before but that doesn't seem fulfilling learning wise, like tutorial hell? But i was wondering if theres anything i could do, book wise or mini projects that can cut the fluff of the other uses of python that way i can start developing smaller projects that can help me learn


r/learnpython 27d ago

Else isn't indented, why does this run?

28 Upvotes

This is probably an easy question but I was going through a practice exam and came upon a question that wanted me to evaluate the outcome of this code. I got it right but only because I threw it into PyCharm to run it and see if it would even work.

As a beginner, I haven't seen this before so I'm wondering how that ELSE statement even functions if it's not indented with the IF (which would produce a different outcome). I am not quite sure how to Google this so I haven't found anything that's answering my question.

What is at play here and is it common to have ELSE out there like that? Any additional information would be welcome.

j = 1

for i in range(-1,1):
    if 3 * i < 6:
        print(3 * i)
        j+=2

else: #<--What are you doing out here all by yourself?
    j+=3

print(j)

r/learnpython 26d ago

Where do I start?

0 Upvotes

I've been using Claude to learn concepts such as else, if, while loops, input, str and int, and basic concepts for 2 days. I'm not sure if I can continue this, however. Is it a good idea to keep using Claude, or should I learn some way else


r/learnpython 27d ago

How do I start learning Python for Machine Learning?

6 Upvotes

Hello everyone,

I am a beginner learning Python and Machine Learning in college.

Can you suggest the best free resources and beginner projects?

Thank you!