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
Has there ever been a proposal for a zero-argument form of `slice()`?

I'm studying Pandas multi-indexing, which uses `slice(None)` [in some spots](https://pandas.pydata.org/docs/user_guide/advanced.html#using-slicers) and it seems ugly so I started wondering the title.

e.g.

dfmi.loc["A1", (slice(None), "foo")]

vs

dfmi.loc["A1", (slice(), "foo")]

Obviously, five extra keystrokes is not a big deal and this is a relatively niche usage, but I don't see any logical reason [`slice`](https://docs.python.org/3/library/functions.html#slice) shouldn't have a zero-argument form. I mean, the syntactic form, `:` doesn't have any value attached to it, so why should the callable form?

As of now, it mostly follows [`range`](https://docs.python.org/3/library/functions.html#func-range)'s signature, requiring either `stop` or `start, stop, step`.

---

**Edit:** NVM, I just realized you can use a convenience object like Pandas [`IndexSlice`](https://pandas.pydata.org/docs/reference/api/pandas.IndexSlice.html), which gives you syntactic sugar for this ***and*** more complicated indexing.

>>> idx = pd.IndexSlice
>>> idx[:]
slice(None, None, None)
>>> idx[:, ...]
(slice(None, None, None), Ellipsis)

Thus:

dfmi.loc["A1", (idx[:], "foo")]
# or
dfmi.loc["A1", idx[:, "foo"]]

All `IndexSlice` does is expose `__getitem__`:

> class _IndexSlice:
> def __getitem__(self, arg):
> return

/r/Python
https://redd.it/1ew3kvm
dont know how to fix it Errno 2

hello guys
im some kind of self-taught-programming-student (or whatever) like probably yall have been and im stucked AGAIN with something i rly dont know how to fix.

this problem ocurred when i was starting to practice django framework, reading the documentation and watching some videos to help me.

but then, this happened

https://preview.redd.it/kp4pv3k76ijd1.png?width=694&format=png&auto=webp&s=b0cc328f00079cbef08d3c3e5f7d6845ca302935

and the reason idk how to fix it is because there actually IS a file named manage in that folder/directory as you guys can see

https://preview.redd.it/acsq6dhe6ijd1.png?width=798&format=png&auto=webp&s=f6f08f7a6e781191ea51c803fb76bb980028d5dc

can someone help a rookie? D:

/r/djangolearning
https://redd.it/1evml07
Do you guys hardcode your backend auth?

So, I'm working on this non-profit project and have just finished the login and registration pages and APIs. I still need to deal with JWT and enhance security. My question is whether you guys hardroll the backend or do u use services like Firebase. However, Firebase is quite expensive, and since it's a non-profit project, I don't have enough funds to support it (I'm using SQLite for the db 💀). I don't anticipate having more than 5,000 users, and I find SQLite easy to use and flexible for starting out. If the user base grows, I can migrate to another database.

/r/flask
https://redd.it/1ew849q
Deployment (venv)

Can I upload my flask app in a virtual environment to the server? I'm only finding tutorials that setup python app in cpanel seperately. If someone knows a tutorial that shows how to upload the venv folder only and get it running (if it's even possible), that would be cool, thanks!

/r/flask
https://redd.it/1ewbbpw
The most upvoted open issue on matplotlib: "plot and scatter should allow marker to be a list"

I always find it kind of amazing where on the surface trivial issues in huge libraries can be open after many years. Today I encountered another one:

* [matplotlib#11155: plot and scatter should allow marker to be a list](https://github.com/matplotlib/matplotlib/issues/11155)

What the user wants is very simple: Just being able to input a list of markers, like you input a list of colors or a list of sizes, to give every point another marker.

Implementation wise, that proved a lot more difficult due to matplotlib's internal handeling of markers, labels and other stuff. Interesting read!

/r/Python
https://redd.it/1ewdf88
Expert Django Dev roadmap!!

I have experience in web development more than 3 years. I have worked on following things
1. DRF, for creating RESTful APIs for web and mobile.
2. Celery for running asynchronous tasks.
3. Celery beat for scheduling cron jobs.
4. Authentication with JWT and session.
5. Deployed app to AWS EC2, using Nginx, Gunicorn..etc.
6. Template rendering, Emails, ..etc.

Can I consider myself as Senior in Django. What should I learn next.?

/r/django
https://redd.it/1ew7gsw
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions 🐍

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/1ewh8fl
Troubleshooting Cloudflare Interception and API Request Failures in Python

I've encountered an issue when making POST requests to certain endpoints using Python's requests library. Cloudflare is intercepting these requests, resulting in a 403 Forbidden error. For endpoint A, I've successfully bypassed Cloudflare using the curl_cffi library. However, endpoint B fails even with curl_cffi, resulting in a connection timeout or SSL handshake error instead of the previous 403.



To clarify:

1. This isn't the typical Cloudflare Challenge Page scenario. The error occurs directly upon POST requests to the API endpoint.

2. All required headers and payload are correctly included in the requests.

3. The original request headers don't contain any Cloudflare-specific parameters; these only appear in the response headers.



I'm seeking advice on how to troubleshoot and resolve this issue, particularly for endpoint B. Any insights into potential workarounds or debugging strategies would be appreciated.

/r/Python
https://redd.it/1ewoldw
[P] Illustrated book to learn about Transformers & LLMs

I have seen several instances of folks on this subreddit being interested in long-form explanations of the inner workings of Transformers & LLMs.

This is a gap my twin brother and I have been aiming at filling for the past 3 1/2 years. Last week, we published “[Super Study Guide: Transformers & Large Language Models](https://superstudy.guide/transformers-large-language-models/)”, a 250-page book with more than 600 illustrations aimed at visual learners who have a strong interest in getting into the field.

This book covers the following topics in depth:

* **Foundations**: primer on neural networks and important deep learning concepts for training and evaluation.
* **Embeddings**: tokenization algorithms, word embeddings (word2vec) and sentence embeddings (RNN, LSTM, GRU).
* **Transformers**: motivation behind its self-attention mechanism, detailed overview on the encoder-decoder architecture and related variations such as BERT, GPT and T5, along with tips and tricks on how to speed up computations.
* **Large language models**: main techniques to tune Transformer-based models, such as prompt engineering, (parameter efficient) finetuning and preference tuning.
* **Applications**: most common problems including sentiment extraction, machine translation, retrieval-augmented generation and many more.

(In case you are wondering: this content follows the same vibe as the Stanford illustrated study guides we had shared on this subreddit 5-6 years ago about

/r/MachineLearning
https://redd.it/1ew1hws
Python's Preprocessor - a deep dive into custom codecs

Here's a short blog post I wrote about Python's barely known yet insanely powerful preprocessing capabilities through the use of custom codecs: https://pydong.org/posts/PythonsPreprocessor/

You can find some examples in https://github.com/Tsche/magic\_codec - please feel free to star the repository if you like these shenanigans :)

/r/Python
https://redd.it/1ewqecv
Looking for a 3D library

Is there a package to transform a moving cam's output into a 3D model of the surroundings?

I have seen a video, a long time ago, of a guy coding something like this live, and plugging a video of his dashcam to model his neighbourhood. But I can't find it.

I want to make a model of my backyard.

/r/Python
https://redd.it/1ewveft
Django Rest Framework Vs Flask Vs Fast Api? which one for Api creation as a Django dev?

in my last post,i asked about Django rest framework and alot of people talked about how its bloated and stuff

you should learn something else


i dont have time to experiment so i want a single answer,which one is the best one to get a job as a Django dev?

/r/flask
https://redd.it/1ewu9md
flask server

Hey guys! Started learning python a couple months back. Made a little chatbot as a project. it got some features like live weather updates, joke of the day and currency conversions.

i wanted to make this chatbot into an interactive website so my friends can interact with it as well. However besides a little HTML, my knowledge on web dev is poor. What should be my next steps to make it into a website?

I tried connecting my backend and front end using a flask server, but when i import my chatbot into my flask server, it starts behaving like the chatbot instead of a web server. Would really appreciate all the advice and ideas

Thanks!

/r/flask
https://redd.it/1ewwldc
Interview with Sean Law, creator of STUMPY

I interviewed Sean Law about STUMPY, a library for performant time series data mining. STUMPY efficiently computes something called the matrix profile, which is a vector that represents the distances between all subsequences within a time series and their nearest neighbors. It's been downloaded over 9 million times and is used for a variety of data mining tasks.

/r/Python
https://redd.it/1ex34ec
Holy f*** this is hard

Flask is by far the hardest thing I've ever done. It's a bit discouraging to hear people say that it's super easy and you should be able to pick it up in a couple days.

I've been going at it for a month and I'm still struggling. Granted I haven't put that many hours in yet (in absolute hours), but still I feel like I should've come a lot further than I have given the hours that I've put in.

Learning HTML+CSS+JS was a breeze. This flask/backend thing is another dimension. If something goes wrong you're donezo.

Flask giving you so much choice and options is also a blessing and a curse I feel like. It's almost like you have to learn mutliple ways to do things just to understand code others produce. Whereas for django (I'd imagine) it's mostly just 1 way of doing things.

/r/flask
https://redd.it/1ex9xdd
inject xss to me

Source code: https://github.com/IdanHajbeko/inject\_xss\_to\_me

website: https://unified-first-rooster.ngrok-free.app/

What My Project Does

My Python application hosts a website where people can post XSS injections freely. Do whatever you want with it.

Target Audience
Anyone from someone who wants to see the mess that will be there, to someone who will try to inject and destroy the site, to a Python developer who just wants to see how the website works.

/r/flask
https://redd.it/1exg64u
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

/r/Python
https://redd.it/1exb4w8
Axios give network error when I try to request to flask in reactnative

This is my app config in flask:

from flask import Flask
from flaskcors import CORS
from flask
sqlalchemy import SQLAlchemy
from dotenv import loaddotenv
from flask
session import Session
from flaskbcrypt import Bcrypt
import os
import redis

load
dotenv()

class ApplicationConfig():
SECRETKEY = os.environ["SECRETKEY"]

SQLALCHEMYDATABASEURI = "sqlite:///database.db"
SQLALCHEMYTRACKMODIFICATIONS = False
SQLALCHEMYECHO = True

SESSION
TYPE = "redis"
SESSIONPERMANENT = False
SESSION
USESIGNER = True
SESSION
REDIS = redis.fromurl("redis://127.0.0.1:6379")


app = Flask(name)
app.config.from
object(ApplicationConfig)
bcrypt = Bcrypt(app)


/r/flask
https://redd.it/1exh3pl
uv: Unified Python packaging

https://astral.sh/blog/uv-unified-python-packaging

This is a new release of uv that moves it beyond just a pip alternative. There's cross platform lock files, tool management, Python installation, script execution and more.

/r/Python
https://redd.it/1ex6n9k
[R] HiRED: Attention-Guided Token Dropping for Efficient Inference of High-Resolution Vision-Language Models in Resource-Constrained Environments
https://arxiv.org/pdf/2408.10945

/r/MachineLearning
https://redd.it/1exhg0f