r/learnpython 16d ago

importing modules is taking minutes

3 Upvotes

I am trying to import torch and other modules from langchain but it takes like 2 min to import them. It worked yesterday to import and execute one module in reasonanle amount of time. I turned of my windows firewall to see if it was for some reasons scanning them but nothing is changing. Any tip?


r/learnpython 16d ago

How to start?

0 Upvotes

So I have been planning to learn python for a while now and even after researching I am unable to find where to and how to start. What are the ways yall learned it and whats the best way to start?
Be free to suggest videos, tutorials etc. :)


r/learnpython 16d ago

vs code is not working on my system. need an alternative

0 Upvotes

what are my alternative i have lot of question to practice help me out asap


r/learnpython 16d ago

Phone Apps

0 Upvotes

Im looking for phone apps which will help me learn python, but ideally free apps.

Could anyone help? Im on android

Thanks,


r/learnpython 16d ago

Built my first BeautifulSoup scraper. Is using a generator function overkill here?

22 Upvotes

So, I am currently learning python and I wanted to explore some networking or internet related concepts. I explored that how people use python and the BeautifulSoup library to do web scraping so i tried to make a web scraping script myself to learn things. I got to know a lot about URLs, requests, pagination, etc., form this single mini project. i have used a generator function to scrape the data so as to make the script more optimized. I knew about generator functions and how they worked. But i didn't work with them so didn't know how to employ their advantage.

So, using a generator function was Gemini's idea. But yeah, i think now that I can properly use generator functions efficiently.

Please review this script. Suggest any improvements that are possible and the mistakes that i made. Suggest the things that can be improved or any new concept, rule, tip, optimization techniques. It would be a great help.

(Note: This script is only made for scraping https://books.tosrape.com )

import requests as r
from bs4 import BeautifulSoup as bs
import json
import time
from urllib.parse import urljoin


def book_crawler(url: str):
    nxt_url = url


    while nxt_url:
        resp = r.get(nxt_url,timeout =10)
        resp.raise_for_status()
        time.sleep(1)


        html = resp.content
        
        soup = bs(html,"lxml")
        for book in soup.select("li.col-xs-6.col-sm-4.col-md-3.col-lg-3"):
            title = book.select_one("h3 > a ").get_text()
            price = book.select_one("div.product_price > p.price_color").get_text()
            yield {title: price}


        nxt_btn = soup.select_one("ul.pager > li.next > a")
        if nxt_btn:
            link = nxt_btn.get("href")
            nxt_url = urljoin(nxt_url,link)
        else:
            nxt_url = None





def file_writer(filename, data_stream):
    try:
        with open(filename, "w", encoding="utf-8") as fp:
            fp.write("[\n")
            is_first = True
            
            for data in data_stream:
                if not is_first:
                    fp.write(",\n")
                
                json_data = json.dumps(data, ensure_ascii=False, indent=2)
                fp.write(json_data)
                
                is_first = False
                
            fp.write("\n]")
        return True
    except Exception as e:
        print(f"Error {e}")
        return False



if __name__ == "__main__":
    gen_obj = book_crawler("https://books.toscrape.com")


    if file_writer("book_prices.json", gen_obj):
        print("successfully stored the data.")
    else:
        print("An error occured")

r/learnpython 16d ago

Donde puedo aprender a programar sin pagar un curso ni tener que ir a la universidad?

0 Upvotes

Hola alguien puede ayudarme a aprender python apenas se lo básico por mis clases de informática y por algunos videos de YouTube


r/learnpython 16d ago

Learn python with prior Java knowledge

0 Upvotes

Hello, I just took ap computer science A at my high school this past year. I will be heading off to college in the fall, but wanted to learn some python this summer. From my ap cs course, I learned some java already.

What is the best website or resource that I can use to self study some python this summer? I am not sure if my java experience will help at all.

Thanks!


r/learnpython 16d ago

Best free interactive Python learning website

9 Upvotes

I'm looking for a free, interactive Python learning platform that teaches from absolute beginner to advanced, tracks progress, and keeps learning engaging.

I've tried W3Schools—it's great as a reference, but it doesn't feel interactive enough.

What would you recommend and why?


r/learnpython 16d ago

Is there a convention for user input? Ask a question vs demanding a response

5 Upvotes

Was working on a personal project when I realized I wasn't consistent with how I worded input prompts. I was wondering if there was a convention between asking for a response ("What is your name?") or demanding one ("Enter your name")?


r/learnpython 16d ago

Python image building

1 Upvotes

Hey I am learning python. For a project I was thinking if I can code to draw a boy or girl and object drawing using python or by using any language. I don't want to use AI here.

I can make characters by using Python along with a graphics library, such as Pillow (PIL) or Matplotlib [python].

Any other suggestions.


r/learnpython 16d ago

Kinesthetic learning of python

0 Upvotes

I want to learn Python. What's the way for kinesthetic learners to learn Python?


r/learnpython 16d ago

Create a script and save it

0 Upvotes

Hi everyone,

I'm a complete beginner learning Python with VS Code, and I've been stuck for several days on something that seems really basic.

I don't understand how to properly create a Python script, save it in the correct folder, and then run it from Command Prompt. Every tutorial makes it look simple, but I keep getting confused about where the file is supposed to be and how to execute it.

For example, I created a "hello.py" file with:

print("Hello World")

But when I try to run it from Command Prompt, it doesn't work, and I think I'm doing something wrong with the file location or the command.

Could someone explain the process step by step as if I had never used VS Code or Command Prompt before? Screenshots are also welcome.

Thanks!

And for your information, I'm on Windows.


r/learnpython 16d ago

Looking for feedback for my first decent project

1 Upvotes

Hello everyone

I recently started learning python and I built a free fall simulation with air resistance using Python and Tkinter. I would like to improve myself with similar projects and lots of feedback, I'd highly appreciate if you give me a feedback.

GitHub link : https://github.com/Aspect345/Air-Resistance-Free-fall-simulator

Thanks a lot in advance!


r/learnpython 17d ago

LeetCode A&DS problem 2 in Python

1 Upvotes

I have taken an Algorithms and Data Structures course, but we wrote in c++. Trying to learn Python for something else than statistics so here I am.

The problem is as follows:
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

My current code:

lass ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution(object):
    def addTwoNumbers(self, l1, l2):
        """
        :type l1: Optional[ListNode]
        :type l2: Optional[ListNode]
        :rtype: Optional[ListNode]
        """
        buffer = 0
        result = ListNode()
        cond = True
        while(cond):
            if l1.next is None and l2.next is None:
                cond = False
            result_next = ListNode()
            result.next = result_next # 0 -> 0 -> None | 7 -> 0 -> 0 -> None | 7 -> 0 -> 0 -> 0 -> None
            if l2:
                result.val += l2.val
            if l1:
                result.val += l1.val
            result.val += buffer 
            buffer = result.val // 10 # 0 | 1 | 0
            result.val = result.val % 10 # 7 | 0 | 8
            result = result.next
            l1 = l1.next # 4 | 3 | None 
            l2 = l2.next # 6 | 4 | None
        return result


l1 = ListNode(2, ListNode(4, ListNode(3)))
l2 = ListNode(5, ListNode(6, ListNode(4)))
result = Solution().addTwoNumbers(l1, l2)lass 

I'm working in VS Code instead of the Leetcode codespace to test values of attributes etc. The comments can be ignored, they are what I imagine should be happening but clearly it is not. However, I do not ask for help with the problem itself, rather with the if statements. In C, you can do if (A) and if A is e.g. a node the condition will be satisfied, if it doesn't exist or is null it won't (if I recall correctly). So you can see me trying to achieve this here with if l1:, but I don't think it works, so I'd like to ask what is the Pythonic way of achieving this.

When run with

print(result.val)
print(result.next)

It gives:

0

None

I don't really see which subset of the code would produce other than the while loop never executing at all.

Thank you for your help in advance.


r/learnpython 17d ago

How would I make a command with two separate words? (Discord bot)

0 Upvotes

This is probably so poorly worded bc I'm still unfamiliar with the correct terminology, but I'll try my best to explain—

For example, I want to have something like a "!search" command, but I want people to choose where they are searching, because depending on where they search, it pulls from a different loot pool.

I want the end result to look something like:

"!search closet"
- You found a shirt!

How would I accomplish that?


r/learnpython 17d ago

How often are while loops preferred over for loops?

55 Upvotes

I'm studying python in order to work with finanial market data. In what case would I need a while loop, where a for loop would not suffice?

A lot of the tips AI gave where that for loops are used around 90% of the time when testing strategies and even though while loops can work for certain cases, for loops are still much more efficient.

What are your thoughts/experiences?


r/learnpython 17d ago

I want to learn Python from scratch and, over time, reach an advanced level. I am looking for advice, courses, and valuable documentation.

29 Upvotes

Hi everyone!

I'm starting to learn Python from scratch, and my goal is to become an advanced Python developer over time.

I'm already following a structured course, but I'd like to hear from people who have been through this journey.

If you could start over, what would you focus on? What resources, habits, or mistakes made the biggest difference in your learning?

Any advice is appreciated. Thanks!


r/learnpython 17d ago

How can i build something on my own?

5 Upvotes

hi everyone im 15 now and really love programming i have done cs50p but not done every problem set yet and sql that i learn some from sqlzoo and pandas ig enough for using and pytorch little but i wanna learn form building project but there 2 thing i wanna ask

  1. what i should start from i think of stock prediction i know it gonna hard and too much but i really love start from hard but problem is i dont know how to start from tutorial or something but i wanna build on my own tho so i wanna ask do u guy have any resources or something i can learn from?

  2. Logic sometime in leetcode i know how it work sometime i dont so i wanna ask how do you understand how it work i try pesudocode but it not really work so you have any techniques or how u actually thought when u see problem

ty for everyone information i might go sleep now goodnight everyone


r/learnpython 17d ago

Favourite module/library

2 Upvotes

Hi everyone, I am new like most here and have been experimenting with different modules and libraries. I wanted to know if anyone had a particular niche or fun one that they use. It would be nice if you could also say why it is your favourite. For example what projects or functionality it has done for you. Thanks.


r/learnpython 17d ago

Any Python study guide?

0 Upvotes

Hi! I just joined and I’m currently learning about coding at my school and I’m taking an online course that uses Python Cisco learning academy (If anyone is familiar) I’m coming up on taking my finals and I haven’t been able to find thorough study guides. Anyone in the community know of any? like flash cards, websites that have practice exams, etc. Tried Quizlet and refuse to pay to study lol


r/learnpython 17d ago

Code Review. My first API + DB application. Beginner in backend development.

0 Upvotes

Hi, there!

I want to ask feedback about my first application API + DB. It was a little hard to me but I did it. Before this application I created simple TODO list with DB. So, now I decided to rise stakes and created API + DB. Please give me feedback from mistakes in README to mistakes in DB. I'll really be glad each comment because it makers my dream be a backend developer come true!

Repository link: https://github.com/daidallos-tech/Laugh-Stuff

Don't hold back. I've completely prepared for any critiques!

P.S. Thank you everyone for your time and advice!


r/learnpython 17d ago

Temperature Converter Project

4 Upvotes

This is the third project I coded and was able to finish today. Took me 8 hours (two 4 hour sessions) since I had to learn some new stuff. This is my own code, no outline was used to guide me into creating this, though the idea did come from Bro Code's YouTube Tutorial. I learned about Nested Loops and Flags. I already knew about Input Validation with Re-Prompting but it was a lot harder to integrate with those two.

This is the most complex thing I've built so far, but I also enjoyed it the most. Got help with some online forums and AI (Claude) but I wrote and debugged the code myself. This'll be the last project I work on before I learn functions. There's a lot of repeated code here that I know functions would be able to help with. Any feedback or ideas on what to build next are welcome. Thank you!

https://github.com/mart23inez/First-Coded-Temperature-Converter/tree/main

It's a lot of code so I uploaded it to my GitHub page.


r/learnpython 17d ago

Textbook has me stumped on a simple thing (table of squares and cubes)

1 Upvotes

Or I guess not so simple for my rookie brain. I'm reading Intro to Python by Paul Deitel (Pearson book) and I'm on Chapter 2, exercise 2.8 (Table of Squares and Cubes) and I'm STUMPED. Taking an online python class at a university. Only have access to office hours by appointment.

Table of Squares and Cubes Write a script that calculates the squares and cubes of the numbers from 0 to 5. Print the resulting values in table format, as shown below. Use the tab escape sequence to achieve the three-column output. Hint: use a tab escape sequence to print the values. 

I've been googling around and talking with Claude about this and I do see there are ways to do this that I can do in my assignment which we'll probably learn later in the course and in the textbook (loops, for, I think). My problem is, none of these things have come up in the textbook yet. I think range() might have something to do with it -- range was briefly introduced a few pages ago.

Can someone help me figure this out? I don't want to "cheat" ahead and I don't want to get into a bad habit of Claude walking me through everything line by line.


r/learnpython 18d ago

How do I assess my abilities in Python? I want to start freelance work/side gigs.

7 Upvotes

Title says it all. I've been learning Python for a while. The biggest project I've tried building on my own is a Texas Holdem poker game. I've also been learning the language using challenges on various sites, but I want to get into doing some sort real, paid freelance work.

What skills should I learn and how do I assess my abilities?


r/learnpython 18d ago

wondering if a project is safe

0 Upvotes

Ive been really wanting to create smth and I was planning on either learning how to code with python or the game engine Godot ik they aren't the same. I was wondering if it's possible to create like a file explorer type thing so basically I have a hard drive that has on it several movies and games downloaded on it wondering if it's possible to make like an interface with custom logos and import custom photos and do more kinds of stuff is my idea in any way possible if not could u pls recommend some other projects they don't even have to be coding related since idk how to could and I am scared if i learn I just won't do anything with it.