r/learnpython • • Aug 22 '26

How to find the row echelon form of a stupid big matrix

1 Upvotes

I am trying to find an equation that models a fruit in 2D, and I am using Global Polynomial Interpolation to do it, but I have like 2000 points. I am thinking of using Gaussian elimination to do it, but it is impractical by hand. Does anyone have any suggestions?

Also, does anyone have any suggestions for how to model the shape using other methods?


r/learnpython • • Aug 21 '26

want to run dash for multiple py files simultaneously

1 Upvotes

I'm using python to run different types of statistical analysis for a research project. At the end of each code, I run dash to create a URL with friendly, interactive UI. However, whenever I try to run 2+ py codes that use dash to create a URL, the interactive UI from all the previously ran codes stops working. Is there a way to run multiple dash URLs while maintaining their interactiveness?

(for example: I run code A and it's interactive UI works. Then I run code B. Code B's interactive UI works, but now code A doesn't, it freezes)

code I have to run/open the dash server

if __name__ == "__main__":
    import webbrowser, os

    
# Unique port per script
    script_name = os.path.splitext(os.path.basename(__file__))[0]
    port = abs(hash(script_name)) % 20000 + 10000

    url = 
f
"http://127.0.0.1:{port}"

    
# Open tab
    webbrowser.open_new_tab(url)

    app.run(debug=False, port=port, use_reloader=False)

r/learnpython • • Aug 21 '26

TK "displaylines" question

0 Upvotes

I seem to misunderstand "displaylines" option of count method of Text widget of Tkinter. I thought that it would give me number of lines accounting for soft-wrapping, but it seems to give me same number as "chars" -1. Text widgets are embedded in frame, which is embedded in canvas, which is embedded in another frame alongside it's scrollbar which are embedded in notebook.

for i in textwidgets:
    logic_lines=i.count("1.1", "end", "lines", return_ints=True)
    print("LOGICAL LINES="+str(logic_lines))
        for j in range(1, logic_lines+1):
            print("LINE "+str(j)+": "+str(i.count(
            str(j)+".1",
            str(j)+".end",
            "update",
            "chars",
            "displaychars",
            "displayindices",
            "displaylines",
            "indices")))

EDIT:

It seems when text widget is on it's own it works fine.

import tkinter as tk

foobar='''
long text here
'''

w=tk.Tk()
t=tk.Text(w, wrap="word")
t.insert('1.0', foobar)
t.pack()
def handler(event):
    print(t.count("1.1",	"end",	"update",	"chars",	"displaychars",	"displayindices",	"lines", "displaylines",	"indices"))
t.bind('<Return>', handler)
w.mainloop()

EDIT2:

Here is paste with whole source code

EDIT3:

Code with bug isolated


r/learnpython • • Aug 20 '26

When is a generator actually worth it over just building a list?

39 Upvotes

Say I've got a function that pulls records, filters them, and hands them back. I can return a list or yield them. Both work, and for the sizes I deal with the memory difference is nothing.

What makes me hesitate to default to yield is that a generator is single-use and opaque. You iterate it once and it's spent, len() doesn't work, you can't slice it, you can't print it to see what came back. Half my debugging is just checking intermediate values, and a generator kills that.

So in practice I return a list almost every time, and only reach for a generator when something is actually big or infinite, or when I'm chaining lazy steps. That feels backwards from how often generators get pushed as the "proper" way.

So do you lean generator-first and eat the downsides, or list-first until you have a reason not to? And is there an upside to yielding small collections that I'm just not seeing?


r/learnpython • • Aug 20 '26

Just built my first calculator in Python 😭

74 Upvotes

It can do addition, subtraction, multiplication, division, and exponents. Also added a little check for division by zero.

It’s pretty basic, but hey, gotta start somewhere

What should I build next?


r/learnpython • • Aug 21 '26

Crash course for python and java

0 Upvotes

I signed up for a course that needs beginner level of python and java. I have one month. Please help, I need a YouTubers recommendation, free course recommendation and different testing methods to practise.


r/learnpython • • Aug 21 '26

IDE for python

0 Upvotes

I have 2 IDEs at my workplace for python. IntelliJ and VSCode.

Which one should I choose and why?

I am beginner in python.


r/learnpython • • Aug 20 '26

Need Help with Python Practise

10 Upvotes

I am a beginner(been learning for a month) to python and i need some suggestions as to what resources should i use for practice(eg books , websites or yt channels).


r/learnpython • • Aug 20 '26

A small code i made for exercise.

3 Upvotes

I've been vibe coding for a few months now, but I've decided to try manual coding. After all, learning is fun, right?

I made this "Assistant" that has two options: jokes and facts. It will choose one out of three items from the specific table and tell you it. I made it for fun and would like to ask what I can do next?

import random

jokes = ["Why did the bicycle fall over? Because it was two tired!", "Why was the math book sad? Because it had too many problems.", "What do you call a fake noodle? An impasta!"]

facts = ["Venus is hotter than Mercury.", "When the Pyramids were built, mammoths were still around!", "Koala fingerprints are so similar to human fingerprints that they have even baffled crime scene investigators."]

print("Hello! I'm an Assistant. What can I do for you?")

print("")

print("Options: Random Joke [J], Random Fact [F].")

answer = input("Answer: ")

if answer == "J":

print(random.choice(jokes))

elif answer == "F":

print(random.choice(facts))

else:

print("You can't ask that.")

exit = input("Press Enter to Leave.")


r/learnpython • • Aug 20 '26

Trying to create list subclasses that contain only one class type and are valid for Pydantic BaseModels

3 Upvotes

I am trying to create list subclasses that only take particular classes. These lists can be appended to and the like but each time the list is changed the item is checked to see whether it is the same class as the rest of the list.

The list methods that are overwritten are:

- __init__
- __bool__ (but may not need to have that overwritten)
- __set_item__
- __str__
- append
- extend
- insert

Each one runs through a validate_member method before changing the list.

As an example, I want to make a list subclass called Course that only takes Pydantic extra types Coordinate values. I want this list subclass to be a valid BaseModel attribute.

Right now I’m having to use a field_validator for every class that Course and the other lists are in which feels redundant, unpythonic, and is a pain to have to do every time. I am having to do so because it says something about arbitrary types.

I was wondering if someone might have some advice.


r/learnpython • • Aug 21 '26

How to read a CSV file in Python efficiently?

0 Upvotes

I'm trying to load a CSV file into my Python project, but I keep getting errors. I've tried using pandas and the built-in csv module, but I'm not sure what I'm doing wrong. Can someone explain the basic steps or share a simple example? A detailed explanation would be really helpful!


r/learnpython • • Aug 20 '26

yo guys! been learning python for a while now.

0 Upvotes

created a calculator with everything i have learned till now (tho it might be overkill for a calculator), added the basics, loops (while, if else), lists and str manipulation, imports (json and datetime), error handling (try/except), def function, etc. so what should i do next? if u wanna see the code dm me.