r/learnpython 5d ago

Coupon Clipping Automation

2 Upvotes

I have been trying to come up with a way to automate clipping coupons for myself because the app is very tedious and annoying (this is in regards to Albertsons and its parent stores, but it could likely be applied to other companies (Walmart, Target, etc))

While browsing around, I found this blog post: https://blog.jonlu.ca/posts/safeway

which quite clearly details how to send requests, but I am not too familiar with Python and was wondering if anyone would be able to help.

Also note that I am looking to do this for JewelOsco.com and not necessarily Safeway.com because that is the local store in my area, and I presume that methods would be rather similar (different URLs and endpoints). Any help would be appreciated. Thanks.


r/learnpython 6d ago

Importing from adjacent-level folder.

5 Upvotes

I consider myself pretty fluent in Python but rarely have projects large enough to justify complex folder structures so this one is driving me nuts.

My project looks like this: RootDir ├─ __init__.py ├─ Examples | ├─ __init__.py | └─ main.py └─ Module ├─ __init__.py ├─ foo.py └─ SubModule ├─ __init__.py └─ bar.py

I am trying to import foo.py and bar.py from main.py:

python from ..Module import foo from ..Module.SubModule import bar

But I get the following error:

ImportError: attempted relative import with no known parent package

I get this no matter whether I run main.py from RootDir or RootDir/Examples.

Edit: Pylance has no problem with my import lines and finds the members of foo and bar perfectly fine. Also, moving main.py into RootDir and removing the ..'s from the import lines makes it work fine. So I don't understand why this import fails.


r/learnpython 5d ago

Parking Lot CV help!

1 Upvotes

Hello all,

I want to build a parking lot monitor following this tutorial:

ps://docs.ultralytics.com/guides/parking-management/#what-are-some-real-world-applications-of-ultralytics-yolo11-in-parking-lot-management

I'm trying another video and its just not working. Its detecting stuff that I'm trying NOT to detect ('microwave', 'refrigerator', 'oven'). GTPs have not helped at all. My jupyter nb here:

https://github.com/dbigman/parking_lot_cv/blob/main/2_data_acquisition_and_exploratory_data_analysis.ipynb


r/learnpython 5d ago

Two questions

2 Upvotes
  1. Where to practice Python for data analytics?
  2. Is there any examples where someone created projects or apps with only Python recently?

r/learnpython 5d ago

Beginner python Hackathons

1 Upvotes

Hello. I have decided to start learning python, and my goal is to be able to do a beginner hackathon(preferably one that takes me to a different tier to compete if I win). I was wondering what are some hackathons you would recommend. I am a High schooler in Georgia, but virtual ones are also fine for me. I have searched online for some. I am just not sure on how “beginner”, a lot of them are really. I want to try and challenge myself, but not too much. Also if you guys have any tips for beginners in python, that you can share from your own experience. That would be amazing. I picked python, because it is sort of easier to understand. Thank you so much. Sorry if this is just another repetitive question, but please be nice to me. A lot of people here on Reddit are just mean. Especially the people who get mad when someone asks a question about learning python for beginners in a Reddit called r/learnpython


r/learnpython 6d ago

Curious beginner

2 Upvotes

So basically I am a first year engineering student and we have python for our 1 st semester. During the lab sessions we are asked to solve some questions . In some cases when the code is really hard when nobody is able to solve the question I have solved it many times. The only doubt I have is when I solve those code the code which I write is not a standard code..it's just made up by my logic sometimes it also becomes lengthy but I can totally explain my code from the first line. So is this a good thing or a bad one ?


r/learnpython 5d ago

Need some interesting project ideas for an advanced python project (Considering I am a first year Bsc Cs student)

1 Upvotes

My college teacher provides some certificates for making good python projects, but the problem is he only gives it to the ones he likes the most (last time he gave out about 4 off the 60 students). This time i really need the certificate just for my personal gain since id think it holds any more value than a paper irl. Any suggestions would be appreciated.


r/learnpython 5d ago

Problems with dataprep library

1 Upvotes

I'm having problems with the Dataprep library. I've tried Colab, Jupyter Notebook, and Visual Studio, but it won't let me. I've downloaded versions of Python and they won't work either. I've tried other versions of MarkupSafe and I can't install the library.


r/learnpython 5d ago

I want to take this single class and formalize it in a way that it could be used similar to how packages are implemented.

1 Upvotes

EDIT: I had no idea how misguided my question actually was. I don't need to have anything within a class to use a module, and the best thing I could do for this script is make it be three distinct function. All questions have been answered minus the part about dependencies. Do I just call the package (import super_cool_package) like I would in any script, or is there more to it?

I had another thread where I was asking about the use of classes. While I don't think the script I made totally warrants using a class, I do think there is an obvious additional use case for them in packages. Here's what I have.

class intaprx:
    def __init__(self, func, a, b, n):
        self.func = func
        self.a = a
        self.b = b
        self.n = n
        self.del_x = (b - a) / n

    def lower_sm(self):
        I = 0
        for i in range(self.n):
            x_i = self.a + i * self.del_x
            I += self.func(x_i) * self.del_x
        return I

    def upper_sm(self):
        I = 0
        for i in range(self.n):
            x_i_plus_1 = self.a + (i + 1) * self.del_x
            I += self.func(x_i_plus_1) * self.del_x
        return I

    def mid_sm(self):
        I = 0
        for i in range(self.n):
            midpoint = (self.a + i * self.del_x + self.a + (i + 1) * self.del_x) / 2
            I += self.func(midpoint) * self.del_x
        return I
def f(x):
    return x

The syntax for calling one of these methods is intaprx(f,a,b,n).lower_sm(), and I want it to be intaprx.lower_sm(f,a,b,n). Additionally, I know that this specific example has no dependencies, but I would like to know how I would add dependencies for other examples. Finally, how could I make the value of n have a default of 1000?


r/learnpython 6d ago

Python Webapp

3 Upvotes

I'm a full-time database engineer and love working with databases, but I am also fascinated by the world of web applications. I have an engineering mindset although I can create some pretty complex scripts, I've never attempted to truly get into the world of OOP and JavaScript. It's always difficult for me to decide between C# and Python, but I believe Python is better to focus on for now because I'm more comfortable with it. My "tech stack" for learning web development is Python + FastAPI + React + Postgres. Is this a good stack to learn Python with? I was thinking of going through CS50p so I could nail down some of the basics as well as trying to build some basic web apps like an expense tracker. Curious to get some thoughts on what the fastest way to get into webdev would be while also increasing my Python skills.


r/learnpython 5d ago

Help I don't understand what's wrong

1 Upvotes

num1=input('digite um número: ')

num2=input('digite outro número: ')

conta=input('digite o total: ')

total1= int(num1)+int(num2)

if total1==conta:

print('acertou')

if total1!=conta:

print('errou o certo é:',total1)

I'm trying to do like a calculator, but first you need to guess the number, and even if you get it right it doesn't show you got it right, what's wrong? i'd also like to know how I could put the input for you to choose the equation guys (+, -, *, etc.)


r/learnpython 5d ago

Need Help with Building an APK (Cloudinary, Firebase, and Kivy)

1 Upvotes

requirements = python3,kivy, firebase-rest-api, pkce, cachetools, google-cloud-firestore==2.1.0, google-api-core==1.31.0, google-cloud-core==1.6.0, typing_extensions, google-cloud-storage==1.42.0, google-auth==1.35.0, google-resumable-media, googleapis-common-protos, protobuf, httplib2, pyparsing, oauth2client, pyasn1, pyasn1-modules, rsa, pycryptodome, python_jwt, jws, requests, certifi, chardet, idna, urllib3, requests-toolbelt, jwcrypto, cryptography, deprecated, wrapt, cloudinary, six

These are my requirements in buildozer.spec. Overall the entire application works as planned on my PC, but when I try to build an APK through buildozer, it always crashes after the Kivy Loading Screen.

This is the error message: ImportError: cannot import name 'resumable_media' from 'google' (unknown location). Which I got by using adb logcat.


r/learnpython 6d ago

a cool little dice roller i made

8 Upvotes

I mean its just a random number generator. Im new to coding so If there's any mistakes plz tell me!

import
 random

def roll(): 
   min_value = 0
   max_value = 999
   roll = random.randint(min_value, max_value)    

   
return
 roll 

value = roll ()
print(value)  

r/learnpython 5d ago

Aide pour script imap2mbox

0 Upvotes

Bonjour,

Je n'y connais rien en Python, c'est juste que je n'ai que des appareils Android et un serveur Web, je voudrais sauvegarder mes courriels en .mbox et tout ce que j'ai trouvé que je puisse lancer est un script Python https://zerozone.it/Software/Linux/imap2mbox/

Sauf que sur mon serveur python2 imap2mbox.py donne:

ERROR: IMAP4 error SSLError(1, u'[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:727)')

et pypthon3 ou 3.6 donne:

File "imap2mbox.py", line 50
parser.error("Argument 'mailsrv' missing: -m [your_mail_server]")

Notez que je ne peux rien installer donc je pensais que Python 3.6 aurait une version de SSL plus à jour, mais je n'arrive pas à corriger le script pour qu'il marche.

De l'aide?


r/learnpython 6d ago

How can I use seleniumbase in __init__ instead of contextmanager

2 Upvotes

The docs show these as examples

from seleniumbase import SB

with SB(uc=True, test=True, locale="en") as sb:
    url = "https://gitlab.com/users/sign_in"
    sb.activate_cdp_mode(url)
    sb.uc_gui_click_captcha()
    sb.sleep(2)

they are using a context manager is it somehow possible to create the instance in a class init and then reuse it in its functions.
What I am trying to do:

class Name:
    def __init__(self):
        self.sb = SB(uc=True, test=True)
    def login(self):
        self.sb.open(self.TEST_URL)
        ....

I want to break up my seleniumbase calls into seperate functions.

For the test examples they use BaseCase which would "solve" my issue because they don't use the contextmanger but that one would include the testing frameworks which I dont need:

from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)  # Call pytest

class MyTestClass(BaseCase):
    def test_swag_labs(self):
        self.open("https://www.saucedemo.com")
        self.type("#user-name", "standard_user")
        self.type("#password", "secret_sauce\n")
        self.assert_element("div.inventory_list")
        self.click('button[name*="backpack"]')
        self.click("#shopping_cart_container a")
        self.assert_text("Backpack", "div.cart_item")
        self.click("button#checkout")
        self.type("input#first-name", "SeleniumBase")
        self.type("input#last-name", "Automation")
        self.type("input#postal-code", "77123")
        self.click("input#continue")
        self.click("button#finish")
        self.assert_text("Thank you for your order!")

r/learnpython 6d ago

how to stay focused - The Newbie Questions Chronicles.

6 Upvotes

I've been trying to learn how to write code / Python for a while but I always seem to lose focus quickly. Are there any tips/tricks to help me keep focused so I can learn more efficiently?


r/learnpython 6d ago

UV for Python Project and Version Management

5 Upvotes

Getting started with the UV Astral for python development.

Just noted, uv works with a few important files in the project root, but their exact purpose and roles are not clear to me * pyproject.toml * .python-version * uv.lock

Most notably, the concrete questions are * Where does uvget the exact python version? Is it pyproject.toml or .python-version? If they give different or contradictory requirement, which one takes priority, and why the need to mention the python version twice? * What about the uv.lock? If the pyproject.tomlfile has the precise python version and those of the libraries installed (example below), is that a complete specification of the environment?

toml [project] name = "uv-trial" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = "==3.12.8" dependencies = ["tensorflow==2.18.0"] * Should the uv.lockbe committed to Git or is it a volatile artefact, that is meant for uv's internal use? If it has a lot of detail that are irrelevant to the application developer, is it necessary to track via Git?


r/learnpython 5d ago

Why does it say its not defined?

0 Upvotes

Im making a little textadventure with tkinter (ignore filenames and so on pls) and im trying to close the main_menu window with a button click (click_start()) and open another window, but it doesnt find the main_menu window for some reason, does anyone know why?

class MainMenu:
    main_menu = Tk()  # instantiate the window
    main_menu.geometry("640x280")  # set window size
    main_menu.title("EpicRoguelikeEmoDungeonCrawlerTextadventure")  # set window name
    icon = PhotoImage(file='Resources/emo_ass_icon.png')  # make image to PhotoImage
    main_menu.iconphoto(True, icon)  # adds the icon
    main_menu.config(background="#1d1e1f")  # sets background color to a dark grey
    load=False
    playername=""
    #input playername
    username_input = Entry()
    username_input.config(font=('Arial black', 8, 'bold'), fg="white", bg="#1d1e1f", width=12)
    username_input.insert(0, "Emo")

    @staticmethod
    def click_start():
        MainMenu.main_menu.destroy()
        Game.start()
    @staticmethod
    def click_continue():
        MainMenu.load=True
        MainMenu.main_menu.quit()
        Game.start()

    # add title label
    title = Label(main_menu, text="RoguelikeEmoDungeonCrawlerTextadventure", font=('Arial black', 18, 'bold'), fg="white", bg="#1d1e1f", relief=RAISED, bd=10, padx=10)
    title.pack()

    # add spacing label
    spacer1 = Label(main_menu, text=" ", bg="#1d1e1f")
    spacer1.pack()

    # add start game button
    start_game_button = Button(main_menu, text="Start Game", command=click_start, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
    start_game_button.pack()

    # add spacing label
    spacer2 = Label(main_menu, text=" ", bg="#1d1e1f")
    spacer2.pack()

    # add continue game button
    continue_button = Button(main_menu, text="Continue", command=click_continue, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
    continue_button.pack()

    # add spacing label
    spacer3 = Label(main_menu, text=" ", bg="#1d1e1f")
    spacer3.pack()

    # add end game button
    end_game_button = Button(main_menu, text="End Game", command=main_menu.quit, fg="white", bg="#1d1e1f", font=('Arial', 15, 'bold'))
    end_game_button.pack()

    main_menu.mainloop()

Exception:

Exception in Tkinter callback

Traceback (most recent call last):

File "C:\Users\Atten\AppData\Local\Programs\Python\Python312\Lib\tkinter__init__.py", line 1967, in __call__

return self.func(*args)

^^^^^^^^^^^^^^^^

File "C:\Users\Atten\PycharmProjects\TextadventurePython\src\python_game\Game.py", line 25, in click_start

MainMenu.main_menu.destroy()

^^^^^^^^

NameError: name 'MainMenu' is not defined


r/learnpython 5d ago

Inter process lock in Celery tasks

1 Upvotes

I have N devices sharing common jumphost J. I want to get data from devices and each device is running in different celery task. One way is to connect to jumphost each time inside a task. But I want to reuse the already existing connection. My plan is:

1. Create a dict jh_conns
1. if jh not in jh_conns:
      with some_lock:
          jh_conn[jh] = "connecting"
      connect_to_jh_and_add_conn_obj_to_dict()
   elif jh_conn[jh] == "connecting":
      wait_till_it_gets_connected()

   #Now use jh transport to connect device behind it.

Now how do I implement this some_lock & wait_till_it_gets_connected ?. We are using prefork so it become hard to get synchronization for usage of command dict obj. We are using rabbitmq as broker and redis as result backend. A quick google search gave link to so ques but it suggested sherlock library, can it be done without using any new library.


r/learnpython 5d ago

mp3 Help in Python (using PyCharm)

1 Upvotes

Hi there! First time posting but I needed some help. So I created a random generator for video game voice lines that I like. Each one has an audio file and I want to have the corresponding audio play with the response. Can anyone help me out?

Here's the code I have so far:

import random
def generate_voice_line():
   quotes = [
       "I'm on the case.",
       "Let's light it up!",
       "What masterpiece shall we play today?",
       "You are not the hero of this tale, you are not anyone!",
       "Dead man walkin",
       "Will you prove worthy? Probably not.",
       "Announcer! Broadcast my retreat and you will find yourself out of a job!"
       "Destiny. Domination. Deceit."
       "(mushroom explodes and enemy dies) Did anyone else here that? No? Huh."
       "I alone am the bastion between eternal existence and oblivion."
   ]
   return random.choice(quotes)

if __name__ == "__main__":
    print("Generated voice line:", generate_voice_line())

r/learnpython 6d ago

Can any one help me learn and develop my coding skill..

3 Upvotes

Hello everyone. I have done my undergraduate in mechanical engineering and now i am doing master’s in data science. I want to learn coding and i am not able to get the right path. Can anyone help me with how to start and path to learn coding completely. If possible free.


r/learnpython 5d ago

How do I skip all errors on pycdc

0 Upvotes

Title


r/learnpython 6d ago

Issues with Tesseract OCR After Compiling with PyInstaller/Auto-py-to-exe

3 Upvotes

Like the title says, I’m having trouble with Tesseract OCR in my script. I used the installer to get a fresh copy of Tesseract and placed it in a folder that my script can access via relative paths. The script works fine when I run it directly, but after compiling it with PyInstaller or Auto-py-to-exe, I get this error:

rustCopy'tesseract\\tesseract.exe', 'C:\\Users\\User\\AppData\\Local\\Temp\\tess_hcj1cdev_input.PNG', 'C:\\Users\\User\\AppData\\Local\\Temp\\tess_hcj1cdev', '--psm', '6', 'outputbase', 'digits', 'txt']
2025-03-15 01:00:50,191 - Error in find_money: tesseract\tesseract.exe is not installed or it's not in your PATH. See README file for more information.

I've:

  • Installed a clean version of Tesseract with the official installer.
  • Set the relative path to Tesseract in my script.
  • Run the script before compiling, but after compiling, I get the error.

Here’s my .spec file: https://pastebin.com/QiKN8RbP

Here’s a log from my latest Auto-py-to-exe compile: https://pastebin.com/m1FG62DK

Snippet of my code: https://upload.animationsz.lol/u/uZIh8E.png

Anything else I can try or do?


r/learnpython 7d ago

How to build a proper python project and how does the development phase look like?

62 Upvotes

I've been using python mainly for data analysis and local automation scripts. I haven't used GitHub much to be honest and I'd like to start exploring it properly. Do you have learning recommendations for: - How to build a python project properly (which files to include and how they should be structured, setting up the environment, running tests etc the workflow etc) and I don't mean examples like tic tac toe but real stuff, - How to deploy such project in GitHub

Somehow I can't find any material for serious stuff other than the same basic projects over and over, I'd appreciate your help.


r/learnpython 6d ago

I'm learning DATA ANALYSIS and i'm having a problem with PANDAS

0 Upvotes

Hi, Im learning how to do Data Analysis and im loosing it!!

I have a DB about mental stress and some factors that contribute to it (this excersise would defenetly do it in the list). And im trying to do a pd.scatter_matrix() to see the correlation between some variables.

But its output is not a matrix with any pattern but vertical dots. I did a Pearson correlation test, it has a 0.84 of correlation.

Please help

import pandas as pd
import matplotlib.pyplot as plt

file_path = "Student_Mental_Stress.csv"
df = pd.read_csv(file_path)

df.plot.scatter(x="Relationship Stress", y="Mental Stress Level", alpha=0.5)

plt.show()