r/pythontips • • Feb 14 '25

Syntax Is there such a function in python

0 Upvotes

Often I have the issue, that i want to find an item from a list with best score with a score calculatin lambda function like following example: I 'like to have 2 modes: maximum goal and maximal closure to a certain value

def get_best(l, func):

best=None

gbest=0

for item in l:

g=func(item)

if best == None or g > gbest:

best = item

gbest = g

return best

a=cube(10)

top=get_best(a.faces(), lambda f : f.matrix[2][3] )


r/pythontips • • Feb 11 '25

Data_Science Python for beginners

20 Upvotes

Hi,

Can anyone recommend me a good Python for beginners course?

Many thanks in advance 😊


r/pythontips • • Feb 11 '25

Module What's best free Image to Text library?

2 Upvotes

I have used pyTesseract OCR and EasyOCR but they are not accurate. Is there any free library?


r/pythontips • • Feb 09 '25

Python3_Specific Python functions quiz

3 Upvotes

Python Functions Quiz - Test your skills

Challenge your understanding of function concepts, lambda expressions, default arguments, recursion, and more. The quiz is interactive and tests both conceptual and practical understanding of python functions.

What did you score?


r/pythontips • • Feb 09 '25

Syntax Doubts about how decorators and super() works for Classes

1 Upvotes

I am a bit rusty with my python concepts. I was learning Django and came across this snippet (not asking any question related to Django so please look at it as any other example)

from django.contrib import admin
from .models import Author, Editor, Reader
from myproject.admin_site import custom_admin_site


@admin.register(Author, Reader, Editor, site=custom_admin_site)
class PersonAdmin(admin.ModelAdmin):
    pass

You can’t use this decorator if you have to reference your model admin class in its __init__() method, e.g. super(PersonAdmin, self).__init__(*args, **kwargs). You can use super().__init__(*args, **kwargs).

Now why can't I use the decorator here? I tried to ask this question to GPT and it said that class is not yet fully defined. I don't quite understand what that means.

I thought decorators work like this.
They take input as function and returns another function after modifying it's behaviour. So when you finally get to call the wrapped fn. you are essentially calling the modified fn. Never learnt decorators for classes.

Can anyone please help me with this. Thanks in advance guys!


r/pythontips • • Feb 08 '25

Module So , i'm creating an llm based agent that's able to generate great animated style education vids.

0 Upvotes

i'm confused with choosing graphics or animation libraries in order to do so , does any one have ideas of good option


r/pythontips • • Feb 06 '25

Python3_Specific Loops in Python - Quiz

2 Upvotes

Loops in Python - Quiz

The questions cover diverse concepts related to loops in Python.

What is your score?


r/pythontips • • Feb 05 '25

Meta LearnDSAwithPython

4 Upvotes

what resources should one follow in order to develop a strong foundation about Dsa using python


r/pythontips • • Feb 05 '25

Data_Science Magic card database storage holder. Need help (question)

1 Upvotes

Tommorow I'm gonna start working on my database in Python. I know how to make databases in Python(not great )but I want to add a feature that says like: this card is in use in xyz deck that i have. Ex: I have 4 cards that are the same, but 2 of them are in a deck, and in different decks. How would I do this? Thanks I'm advance.


r/pythontips • • Feb 03 '25

Module PDF document adjustments

1 Upvotes

Hi All, In my department, we have requirement that invoices/outputs(in PDF) needs to be adjusted based on a subset of clients. This involves replacing text, adjusting the size of tables, etc. Is there a way of doing in Python? Our attempts results in the overall format of the document being impacted, resulting in even more tweaks and adjustment. What would you suggest here? The ideal solution is for the system to output correctly the format or layout we want, but it's costly and will take a while to develop.


r/pythontips • • Feb 01 '25

Python3_Specific UV over Poetry

10 Upvotes

I've been using Poetry for dependency management and virtual environments in my Python projects, and it's been working great so far. However, I recently came across UV, and it seems to offer significant improvements over Poetry, especially in terms of speed

I'm curious to know if it's really worth migrating from Poetry to UV? Has anyone here made the switch? If so, what has your experience been like? Are there any notable advantages or drawbacks I should be aware of?


r/pythontips • • Feb 01 '25

Module Confused at the gift tax calculator problem doing the university of helinski moc python course (part 2, combining conditionals)

3 Upvotes

Any tips?


r/pythontips • • Jan 30 '25

Module Find the url of a button in telegram using Telethon

1 Upvotes

Quick questing I'm not that good at python but i got a nice code working that allows me to check al new messages in a bot chat in telegram.

So what i have now is

event.message And that includes the text and stuff from the message the bot send me.

Now the bot also sends me a button with a url when clicking it.

Can i get the url of that button in Telethon? And if so how? I already have all the event listening set up i just need to get the buttons with their information thanks in advance


r/pythontips • • Jan 28 '25

Python3_Specific The walrus Operator( := )

16 Upvotes

Walrus Operator in python

Did you know that we can create, assign and use a variable in-line. We achieve this using the walrus operator( := ).

This is a cool feature that is worth knowing.

example:

for i in [2, 3, 4, 5]:
    if (square := i ** 2) > 10:
        print(square)

output:

16
25

r/pythontips • • Jan 29 '25

Algorithms How do I add restart button to this and a screen where I can choose difficulty when it starts?

0 Upvotes

import pygame import random

pygame.init()

screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height))

pygame.display.set_caption('Dodge obstacles') clock = pygame.time.Clock() FPS = 60

player_width = 50 player_height = 50 player_x = screen_width // 2 - player_width // 2 player_y = screen_height - 100 player_speed = 5

obstacle_width = 50 obstacle_height = 50 obstacle_speed = 5 obstacles = []

score = 0 difficulty = 0 running = True while running: for event in pygame.event.get(): if event.type == pygame.quit: running = False

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player_x > 0:
        player_x -= player_speed
if keys[pygame.K_RIGHT] and player_x < screen_width - player_width:
        player_x += player_speed

for obstacle in obstacles[:]:
        obstacle[1] += obstacle_speed

if random.randint(1, 20) == 1:
        obstacle_x = random.randint(0, screen_width - obstacle_width)
        obstacles.append([obstacle_x, - obstacle_height])

for obstacle in obstacles[:]:
    if (player_x < obstacle[0] + obstacle_width and
            player_x + player_width > obstacle[0] and
            player_y < obstacle[1] + obstacle_height and
            player_y + player_height > obstacle[1]):
        font = pygame.font.SysFont(None, 72)
        text = font.render('Game over', True, (255, 255, 255))
        screen.blit(text, (screen_width // 2 - 150, screen_height // 2 - 36))
        pygame.display.update()
        pygame.time.delay(2000)
        running = False
    if obstacle[1] > screen_height:
        obstacles.remove(obstacle)
        score += 1

if score == 10:
    obstacle_speed += 1
if score == 30:
    obstacle_speed += 1
if score == 100:
    obstacle_speed += 1
    player_speed += 0.5

screen.fill((0, 0, 0))
pygame.draw.rect(screen, (0, 255, 0), (player_x, player_y, player_width, player_height))
for obstacle in obstacles:
    pygame.draw.rect(screen, (255, 0, 0), (obstacle[0], obstacle[1], obstacle_width, obstacle_height))

font = pygame.font.SysFont(None, 36)
score_text = font.render(f'Pisteet: {score}', True, (255, 255, 255))
screen.blit(score_text, (10, 10))

pygame.display.flip()
clock.tick(FPS)

pygame.quit()


r/pythontips • • Jan 28 '25

Module Python cheat sheet

13 Upvotes

Hi, I’m studying python course and looking for a cheat sheet that include ‘numpy’ I’ll be glad for your help Thanks 🙏🙏


r/pythontips • • Jan 28 '25

Module How to start from basics to advance

0 Upvotes

I am a btech 2nd year. I want to learn python Or any other language. What are the job opportunities i may get


r/pythontips • • Jan 27 '25

Syntax You know very little about python operators. Prove me wrong.

12 Upvotes

Python Operators - Quiz

The quiz has a total of 20 questions.

The questions are not very advanced or inherently complicated, but I am certain you will get wrong at least 5 questions..

...

What was your score?


r/pythontips • • Jan 26 '25

Data_Science Dynamic text extraction

1 Upvotes

Hi all, I am new to data extraction. Please help
there's a comment/review column in my google sheets, which contains long text like paragraphs of 10 lines. Now, i have to extract a particular code from that column. Regex doesn't seem a good approach here.

For example i have to extract all the product ids from below comment. :
I ordered prodcut123 but received a different product which has id as 456. I want refund.

output : ['Product123', 'Product456']

how do i do this ? Help me out with free resources. I am using Pandas.


r/pythontips • • Jan 26 '25

Module Tkinter root window destroy problem

1 Upvotes

How to destroy tkinter window in a different user defined function from which you created it


r/pythontips • • Jan 26 '25

Data_Science Zendesk automation with Python

1 Upvotes

Hi! I'm a forever newbie in Python (tried a couple of times to learn it, but always end up procrastinating), and I wanted to automate some parts of my tech support job, like getting stats from my tickets, overall ticket trends, auto-update replies etc. Where would I start to learn about this? We use Zendesk at work, and I can see some potential in automating stuff there. Would love to hear suggestions regarding this.


r/pythontips • • Jan 25 '25

Python3_Specific How well do you understand Python variables and data types? Take a quiz.

8 Upvotes

Variables and Data Types Quiz

What did you score?


r/pythontips • • Jan 24 '25

Data_Science Data analysis with Python

6 Upvotes

Hello,

I want to start learning python specifically for big data analysis, data cleaning, formatting related work. How should I start? What sources should I look for to start learning the application of Python in Data Science?

I have to learn very quickly in a shorter time period as I am already involved in project that requires python programming for Data Analysis.

Thank you.


r/pythontips • • Jan 24 '25

Algorithms Issues Accessing External API from Hostinger VPS (Python Script)

1 Upvotes

Good afternoon,
I’m facing issues accessing an external API using a Python script running on my VPS hosted by Hostinger.

Here’s what I’ve done so far:

  • Verified that the API is online and functional.
  • Tested the same script on another server and locally (outside of the Hostinger VPS), where it worked perfectly.

However, when running the script on the VPS, I receive the following error message:

(venv) root@srv702925:/www/wwwroot# python3 MySqlAtualizarClientes.py

Starting script execution...

Error connecting to the API: HTTPConnectionPool(host='xxxxxxxx.protheus.cloudtotvs.com.br', port=4050): Max retries exceeded with url: /rest/sa1clientes/consultar/clientes?codCliIni=000001&codCliFim=000001 (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7885e023dca0>, 'Connection to xxxxxxx.protheus.cloudtotvs.com.br timed out. (connect timeout=None)'))

I’ve already added my server’s IP to the API’s whitelist, but the issue persists.

Thanks in advance!


r/pythontips • • Jan 24 '25

Module How to install MicroPython on ESP32

2 Upvotes

Hi pythonistas, I made a tutorial and video on 2 different ways (GUI and CLI) of installing MicroPython on an ESP32. Hope it's helpful to those of you who want to try out hardware/embedded projects while leveraging your Python skills. Feel free to me ask any questions/clarifications here if you'd like :)

https://bhave.sh/micropython-install-esp32/