Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
I made a thing

/r/django
https://redd.it/1cthmj8
Friday Daily Thread: r/Python Meta and Free-Talk Fridays

# Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

## How it Works:

1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

## Guidelines:

All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.

## Example Topics:

1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟

/r/Python
https://redd.it/1ctrpwz
Folks who know the internals: Where does operator precedence "happen"?

Hey! Messing around with instaviz, cool library, highly recommend. You can visualize a function's bytecode as well as AST and some other stuff.

i entered this:

def f():
x = 1 + 2 - 102
return x


I was expecting the AST nodes for 1 + 2 - 10**2 to be rearranged somehow, with 10**2 being moved to the left hand of the expression, because exponents get evaluated before addition/subtraction. but no! just looks like this:


... (more tree up here)

BinOp

| \\ \\

BinOp Sub BinOp
| \\ \\ / |

/r/Python
https://redd.it/1ctwi8z
GeoEntropy: A Python Package for Computing Spatial/Geometric Entropy

What the project does:
GeoEntropy is a Python package designed to compute various entropy measures for spatial data represented in matrices (numpy arrays).

Target audience:
Scientists.

Alternatives:
GeoEntropy is inspired by the R package SpatEntropy by L. Altieri, D. Cocchi, and G. Roli.

You can find the source code here (github.com) and the package description also on pypi.org.

/r/Python
https://redd.it/1cty1zx
pip time machine

https://github.com/nevakrien/time\_machine\_pip

this is a fairly simple project barely anything to it but I think its promising
the idea is to put pip in a time machine so it can not use package versions that were made after the project is made.

I am doing this by proxiying pypi and cutting out the newer versions.

initial tests show that pip respects the proxy and works like you would expect

/r/Python
https://redd.it/1cte019
The Smartest Person In The World - a competitive logic web game written in Flask

Hi all, I've recently released a project I have been working on for a few months to learn how to build a website from scratch in Flask: https://www.the-smartest-person-in-the-world.com/ . It's a series of 36 logic minigames where you can only interact with the games through numbers. Each game awards a point, and there is a global leaderboard.

I had already created some basic APIs and UIs using Flask, but never a fully fledged project, hosted online with a proper domain. Well, using Flask was a pleasure!
The integration with DBs through flask_sqlalchemy was very smooth, the handling of data between the client and server through the session object was extremely intuitive, just like if I was working with a regular Python dict.

To deploy the site, I used pythonanywhere.com which has some nice tutorials to host Flask projects out of the box. It has a free tier which is already great for playing around with your project and actually seeing it on the internet. I used the cheapest tier (5$/month) to use a proper domain name and get 2 workers to serve the website.
It has been up for 5 days and has received 7k unique visitors. It now has

/r/flask
https://redd.it/1ctkvsl
Independent lambda functions and Django

Hi all, I’ve tried researching this question but I can’t seem to find an answer so any help appreciated!

Background:

I currently have multiple Lambda functions that gather data from various sources and save them to a s3 bucket (currently as parquet). All are on cron schedules and deployed to aws.

At the same time I’m creating a Django app to use this data as part of a larger crud app. Am using RDS (MySQL)

I want to update the lambdas to save the data directly to the RDS in the format of the Django models.

Can I insert the data directly to RDS independent of Django or do I need to somehow integrate Django models to the lambda?

Or any other suggestions feel free to raise!

Thanks 😊



/r/django
https://redd.it/1ctvush
Trying to Publish my Flask API on Postman

I'm trying to publish my Flask API on Postman but I'm not sure if I need to host the API on a hosting service before I can do that. Most tutorials I've seen are not working on the localhost so I'm not sure how to go about it.
I know this is supposed to be on the postman sub-reddit, but the sub-reddit is not active

/r/flask
https://redd.it/1cu37d6
Homoiconic Python Code

Homoiconic, what does it mean? In simple terms, homoiconic code is when code is treated as data and can be manipulated as you would data. This means the code can be changed, new functions and variables added, the code can generate new code or even examine and modify its own structure and behavior all while it is running. That’s why homoiconic languages like Lisp are so powerful. But what if we can make a homoiconic python code, where the code and the data are one and the same and can be modified in the same way?

This guide does a good job in trying to explain how you would create a python version of the “Lisp in Lisp” code which would give you access to all those homoiconic features that Lisp brags of like the macro systems, the expressiveness and flexibility, the metaprogramming etc. while still using python. What do you guys think of this?

/r/Python
https://redd.it/1cu2bpv
sjvisualizer: a python package to animate time-series data

What the project does: data animation library for time-series data. Currently it supports the following chart types:

* Bar races
* Animated Pie Charts
* Animated Line Charts
* Animated Stacked Area Charts
* Animated (World) Maps

You can find some simple example charts here: [https://www.sjdataviz.com/software](https://www.sjdataviz.com/software)

It is on pypi, you can install it using:

`pip install sjvisualizer`

It is fully based on TkInter to draw the graph shapes to the screen, which gives a lot of flexibility. You can also mix and match the different chart types in a single animation.

Target audience: people interested in data animation for presentations or social media content creation

Alternatives: I only know one alternative which is bar-chart-race, the ways sjvisualizer is better:

* Smoother animation, bar-chart-race isn't the quite choppy I would say
* Load custom icons for each data category (flag icons for countries for example)
* Number of supported chart types
* Mix and match different chart types in a single animation, have a bar race to show the ranking, and a smaller pie chart showing the percentages of the whole
* Based on TkInter, easy to add custom elements through the standard python GUI library

Topics to improve (contributions welcome):

* Documentation
* Improve built in screen recorder, performance takes a hit when using the built in screen recorder
*

/r/Python
https://redd.it/1cu4epm
Custom MultiInput Model Field by Extending the JSONField in Django

Hi all,

I'm trying to create a custom field for volume made up of 4 parts (length, width, height and units). I'm thinking that extending the models.JSONField class makes the most sense.

Does anyone have any experience with doing this or another suggestion on how to achieve the same result?

I've implemented what I think is correct. However, I keep getting this error:

`TypeError: Field.__init__() got an unexpected keyword argument 'encoder'`

Below are the relevant project files.

inventory/models.py

from django.db import models
from tpt.fields import VolumeField

class Measurement(models.Model):
volumne = VolumeField()

tpt/fields.py

from django.db import models
from tpt import forms

class VolumeField(models.JSONField):
description = 'Package volume field in 3 dimensions'

def __init__(self, length=None, width=None, height=None, units=None, *args, **kwargs):

self.widget_args = {


/r/djangolearning
https://redd.it/1ctmhu0
The best Python CLI library, arguably.

What My Project Does

https://github.com/treykeown/arguably

arguably makes it super simple to define complex CLIs. It uses your function signatures and docstrings to set everything up. Here's how it works:

Adding the `@arguably.command` decorator to a function makes it appear on the CLI.
If multiple functions are decorated, they'll all be set up as subcommands. You can even set up multiple levels of subcommands.
The function name, signature, and docstring are used to automatically set up the CLI
Call arguably.run() to parse the arguments and invoke the appropriate command

A small example:

#!/usr/bin/env python3
import arguably

@arguably.command
def somefunction(required, notrequired=2, others: int, option: float = 3.14):
"""
this function is on the command line!

Args:
required: a required argument
not_required: this one isn't required, since it has a default value
others: all the other positional arguments go here


/r/Python
https://redd.it/1cu6toc
MySQLdb.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)") when I try to access my Flask CRUD app on Ubuntu server with nginx and gunicorn

Inside an Ubuntu server, I have my codebase for my flask CRUD app as well as a mysql database

Here's the code I am running to integrate the database to my flask app:

from flask_mysqldb import MySQL

app.config['MYSQL_HOST'\] = 'localhost'

app.config['MYSQL_USER'\] = 'root'

app.config['MYSQL_PASSWORD'\] = 'new_password'

app.config['MYSQL_DB'\] = 'crud'

mysql = MySQL(app)


When I try to run, the app locally on the ubuntu server, using the line python3 flaskappmysql.py, there seems to be no problem AT ALL.

However, when I access it thru the hosted IP address 172.xx.xxx.xxx, I get this kind of error:

MySQLdb.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

What do I need to do to fix this problem? I provided correct mysql credentials and can't seem to diagnose what's wrong.

/r/flask
https://redd.it/1cube0z
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

/r/Python
https://redd.it/1cuk3zp
Paying gig: need someone to write a python script for a public art project.

If you are available for a couple of hours of script creation and editing let me know. Shouldn’t take much longer as it a simple project using a raspberry pi, a button on a GPIO board, and a microphone.

Details: This is one giant game of telephone.
Essentially, someone leaves a message and the next person that hears the message replies to it, and the game continues.

When a user picks up the phone (depresses a button) they will hear instructions on what to do. then the most recent message is played and a
'beep' noise indicating it's time for them to record their response. They then hang up the phone and the process starts over.

This process is run through a raspberry pi using python script and a telephone that has a microphone to record the audio and a speaker to play the audio back. It utilizes a GPiO board for for a button that acts as the phone receiver.


All audio messages are saved to the raspberry pi storage. Only the most recent message is played back to the newest user.

/r/Python
https://redd.it/1cujgwk
Mastering Python: 7 Strategies for Writing Clear, Organized, and Efficient Code

Optimize Your Python Workflow: Proven Techniques for Crafting Production-Ready Code

Link

/r/Python
https://redd.it/1cuqmmh
How to Prevent Overlapping Async Tasks When Using APScheduler with asyncio in Python?

I'm using APScheduler to schedule jobs that call various webhook functions asynchronously. However, I'm encountering an issue where overlapping tasks cause errors, particularly the Task got Future attached to a different loop error. This happens because APScheduler jobs might run at the same time, leading to multiple async tasks being scheduled on different event loops.



import asyncio
import logging
import traceback

channeltowebhooks = {
"channelA": "webhookurlA",
"channel
B": "webhookurlB",
"channelC": "webhookurlC",
}

async def webhook
funcA(webhookurl, args):
async with aiohttp.ClientSession() as session:
await webhook.send(content=args.get("message))

async def webhookfuncB(webhookurl, args):
pass

async def webhook
funcC(webhookurl, args):
pass

def callwebhook(channelname, args):


/r/django
https://redd.it/1cuts96
My first 2 flask sites

Been building sites with flask

https://youcodeme.com
https://chatgod.co.uk

YouCodeMe my company I’ve been setting up as I’m wanting to try earn some money by making websites for small local businesses.

ChatGod is a site I’ve been building alongside YouCodeMe to not only have something to showcase on the main site as a portfolio, but also because I wanted to make this app for a long time just for fun and figured it could generate me something, even if it’s just peanuts.

It’s an Artifical Intelligence chatbot that ‘can answer any question’. So you can ask it what you are wearing and it will actually tell you. Or ask who the person sitting next to you is, and it can tell you. There’s some real trickery going on to make it actually work, it’s not pervasive in any way. All my friends and family that I’ve used it on have all been super thrown with it and asking how does it know lol so I’m really excited to be able to release the full version once I’m sure everything is perfect ready to go.

The sites at the moment are for the most part incomplete. But full versions are already on my local system. I’m just perfecting and

/r/flask
https://redd.it/1cv0x5n