pythondaily | Образование

Telegram-канал pythondaily - Python Daily

1102

Daily Python News Question, Tips and Tricks, Best Practices on Python Programming Language Find more reddit channels over at @r_channels

Подписаться на канал

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

If you could go back and give your beginner Django self one piece of advice, what would it be?

For the seasoned Django developers out there - as you look back on your own journey, what's one insight or lesson you wish you had known when you were just starting out?

I'm a junior Flutter developer who is excited to dive into backend development with Django. As someone new to the field, I'm keen to learn from the experienced Django developers in this community.

Looking back, is there anything in particular you would have approached differently in learning and using the Django framework? What's one piece of advice you wish you could give your beginner self?

I'm especially interested in any insights on:

- Key concepts or techniques that were game-changers in your Django journey

- Resources (books, tutorials, projects) you found invaluable as a beginner

- Common beginner pitfalls to avoid or best practices to adopt early on

- Aspects of Django that were challenging to grasp at first but clicked later on

/r/django
https://redd.it/1ew0i59

Читать полностью…

Python Daily

trying to set up a virtual environment on a linux and windows machine multiple times but failed.

i have a flask project (can't share the github repo because it is private) and I've tried setting it up on my fedora linux machine. the os by default had python 3.12 and I can't remove it because some core packages depend on it. I'm trying to set up a project with pipenv and after I run pipenv install, I get multiple resolution failures and in the error logs, I see that it is picking up some resolverdotpy files from my python3.12 directory.
i have tried specifying the python version as pipenv --python 3.8 install, but no luck. what can I do?

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

Читать полностью…

Python Daily

Making a windows desktop app using pygame: how bad of an idea is it?

I haven't found anyone asking this question, everything seems suitable to make nice desktop apps but I found no mentions of anyone doing it so I'm assuming it's a bad idea but I have no clue why that would be the case

/r/Python
https://redd.it/1evv8no

Читать полностью…

Python Daily

I Created the Definitive AUTOMATIC Shiny Hunter for Pokémon BDSP in Python

What My Project Does: Hey everyone! I am Dinones! I coded a Python program using object detection that lets my computer hunt for shiny Pokémon on my physical Nintendo Switch while I sleep. So far, I’ve automatically caught shiny Pokémon like Giratina, Dialga or Azelf, Rotom, Drifloon, all three starters, and more in Pokémon BDSP. Curious to see how it works? Check it out! The program is available for everyone! Obviously, for free; I'm just a student who likes to program this stuff in his free time :)

The games run on a Nintendo Switch (not emulated, a real one). The program gets the output images using a capture card, then, it process them to detect whether the pokemon is shiny or not (OpenCV). Finally, it emulates the joycons using bluetooth (NXBT) and control the Nintendo.

I also want to know what do you think about it: Is it fair to use it in singleplayer? And multiplayer?

Target Audience: All Pokémon BDSP gamers.
Comparison: As far as I know, nobody did this before.

📽️ Youtube: https://www.youtube.com/watch?v=84czUOAvNyk
🤖 Github: https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter

/r/Python
https://redd.it/1evng2g

Читать полностью…

Python Daily

Checks before deploying an app

I know of CSRF for forms and debug set to false and allowed hosts to my domain name. is there anything more? specially security wise.

/r/django
https://redd.it/1ev6xf1

Читать полностью…

Python Daily

Django project links.

I’ve been doing django for couple of weeks. Gained basic knowledge now I want to test it and learn advance concepts by doing and tinkering. Can you guys please provide me some git repo based on django projects?Tnx…

/r/django
https://redd.it/1evp5mh

Читать полностью…

Python Daily

I made a Spotify Genre Tracker with the goal of broadening my music taste.

# What My Project Does


Recently I've noticed that I spend way too much time listening to the same playlists/genres over and over again so with the goal of expanding my music knowledge I've decided to make this program that keeps track of the listening time for all the genres in Spotify.

It works by having two threads, one for the cli and user input and another that constantly pings the Spotify API for the currently playing song and keeps track of the listening time in an sqlite database.


# Target Audience

This project is meant for anyone that has a hard time finding new music genres to listen to. It is by no means production ready but if I see people enjoy it I might setup a website for it and make it public.


# Comparison

As far as I'm aware there aren't any projects like this one. The one's available out there keep track of all your stats but none give you a set goal or have the option to track the listening time for a given genre.

Any comments/recommendations are welcome. Hope it helps someone learn more about music!

Here's the repo for anyone that wants to check it

/r/Python
[
https://redd.it/1evbgzb

Читать полностью…

Python Daily

Any good tutorials on Django channels ?

Can anybody tell me or suggest any tutorials or methods that you used to study django channels

/r/djangolearning
https://redd.it/1evam2q

Читать полностью…

Python Daily

How do I make my application interactive while being able to bundle my JavaScript

So far my Django app was just basic CRUD but now my front end displays a form and the form has a table. With a button I can delete rows and add rows. This might sound simple but I’m horribly lost. I want to use the JavaScript to populate the form, even when the template is populated by Django. But now how to I pass values from Django to the front end so my JavaScript can use it. Do I have to check if a variable is set in local storage or something?

/r/django
https://redd.it/1euzrsy

Читать полностью…

Python Daily

applying for job

I've been working as a Django developer for a year, and I'm considering applying for a new position elsewhere. However, I'm not sure if there are any specific things I should learn or know by now. What skills and knowledge should I have at this point, and what kind of interview questions can I expect with my level of experience?

/r/django
https://redd.it/1ev1347

Читать полностью…

Python Daily

[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 Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

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

Читать полностью…

Python Daily

Question about transforming code into a web application

Good morning. I had written a large Python code (>500 lines) for a project, and was trying to make a self serve web application for this in Flask. I got the "hello world" and stuff down in flask, but now I am having trouble understanding how to move forward...do I simply copy paste my code into the main() function in app.py? Because I tried a test code like that (Just one input and an output) and the website didn't display anything.

Tl;dr: Trying to make a massive python code into a Flask web app, did the "hello world" code, not sure how to proceed.

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

Читать полностью…

Python Daily

Why Signals are bad?

I went through some blogs, talking about optimizing performance of Django application and almost every blog mentioned avoid using signals. But none of the authors explained why.

/r/django
https://redd.it/1evvaeu

Читать полностью…

Python Daily

I built a Python Front End Framework

This is the first real python front end framework you can use in the browser, it is nammed PrunePy :

https://github.com/darikoko/prunepy

# What My Project Does

The goal of this project is to create dynamic UI without learning a new language or tool, with only basic python you will be able to create really well structured UI.

It uses Pyscript and Micropython under the hood, so the size of the final wasm file is bellow 400kos which is really light for webassembly !

PrunePy brings a global store to manage your data in a crentralised way, no more problems to passing data to a child component or stuff like this, everything is accessible from everywhere.

# Target Audience

This project is built for JS devs who want a better language and architecture to build the front, or for Python devs who whant to build a front end in Python.

# Comparison

The benefit from this philosophy is that you can now write your logic in a simple python file, test it, and then write your html to link it to your data.

With React, Solid etc it's very difficult to isolate your logic from your html so it's very complex to test it, plus you are forced to test your

/r/Python
https://redd.it/1evuzem

Читать полностью…

Python Daily

Pro tips for matplotlib figures to really feel right in LaTeX publications

I wrote up some tips that I think will help academics, or anybody else who happens to use matplotlib to make figures that end up in LaTeX documents. A long time ago I was a layout/typography nerd, so I've been trained to be anal, hence the tips below!
https://duetosymmetry.com/code/latex-mpl-fig-tips/

/r/Python
https://redd.it/1evp7ip

Читать полностью…

Python Daily

Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

/r/Python
https://redd.it/1evnvtp

Читать полностью…

Python Daily

Local to Live Question

I'm considering starting a bigger project than I'm used to. I've flipped through a lot of tutorials but haven't found a solid answer to a question I have.

Most of my projects have just been php and sql based. I just have the files on a webhost and it's live.

Can I do that with Django? It seems like a way different process to go live with Django. I was considering starting with a Django boilerplate.

/r/django
https://redd.it/1evd7gh

Читать полностью…

Python Daily

Hype About .NET

Microsoft puts in their landing page that .NET-based web servers can handle 7 million requests making it the fastest web server out there. What is your opinion on this? Personally, I'm attracted towards it, however the development experience is pure shit compared to Python (not talking about writing actual program, but about setting up environments, hot reloading, memory consumption etc.).


Why Django is underperforming except for the reason that Python is an interpreted language? Can me make it match the speed of .NET?



PS: Django is the best framework out there that provides the right balance between abstraction and ease-of-use and its my most favorite framework.

/r/django
https://redd.it/1ev7kux

Читать полностью…

Python Daily

Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1euvt6o

Читать полностью…

Python Daily

D Self-Promotion Thread

Please post your personal projects, startups, product placements, collaboration needs, blogs etc.

Please mention the payment and pricing requirements for products and services.

Please do not post link shorteners, link aggregator websites , or auto-subscribe links.

--

Any abuse of trust will lead to bans.

Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

--

Meta: This is an experiment. If the community doesnt like this, we will cancel it. This is to encourage those in the community to promote their work by not spamming the main threads.

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

Читать полностью…

Python Daily

Posting user uploads to Cloudflare Images

I'm working on an app, and (for the first time ever) I'm allowing users to upload image files to Cloudflare Images.

Is the best (and safest) option to:

1. add a file input on the front end (inside a form),
2. submit the form,
3. save the file locally in a temp folder,
4. post the file to Cloudflare Images with a Celery task,
5. and then delete the local file?

Is there a safe and secure way to do it from the front-end instead of having to do all the file saving/deleting on every request?

/r/django
https://redd.it/1eupm7f

Читать полностью…
Подписаться на канал