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 used Python to make NLP analyses of a bunch of Twitter influencers, here's what I did and what I've learned so far

I'm personally curious what people Tweet about. I tweet a lot about Python, AI (specifically NLP), football, and random updates about my life like when I went to the store for milk last week and came back with everything but milk. I also find Elon Musk's Twitter hilarious. Like how does this man have time to run multiple businesses and pick fights on Twitter? I don't know. With a combination of my interest in NLP, Twitter, and seeing if I can leverage Twitter influencers to get Twitter famous, I created this project on how to use NLP to analyze a bunch of Twitter influencers.

I picked seven Twitter influencers I found to be either interesting or just ones that I want to be like and started analyzing their Tweets. The Twitter users I picked are:

Elon Musk for the reasons above. He Tweets a lot about Tesla (no surprise) and NFTs (kind of surprising)
Bill Gates because I want to know what he's up to, he's rich and reads a bunch of books and looks like he's trying to personally feel better about his ruthless takeover of the software industry in the 80s and 90s by now being nice guy Bill

/r/Python
https://redd.it/s6a2yt
Extension to Write Docstring using AI

https://reddit.com/link/s6bs22/video/kseliy1ppac81/player

You can install the extension on the VSCode store or check it out on GitHub.

Full disclosure: I developed the extension and am looking for constructive feedback. The biggest problem with it currently is that the code only describes "what" the code does instead of "why". Developing better language parsing and models for that.

/r/Python
https://redd.it/s6bs22
Retrieving data from a form without pressing the submit button

I want to have a form that requests the user for a name that will be used to save a file. The thing is I can't use a submit button for flask because at the same time I need to call a javascript function which I'm doing through a normal html button class.

Is there any way to to retrieve data from a flask string field even if it hasn't been submitted? Or is there another solution?

Thank you.

/r/flask
https://redd.it/s5v31t
Tuesday Daily Thread: Advanced questions

Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.

If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/s6izar
SQLAlchemy changes class names

Hey guys,

Working on a project and noticed something strange. When I create my class using 2 capital letters as the first letters of the word, sqlalchemy translates that to 2 words with an underscore in my database. No problem, but what I did notice is that now for me to refer to the classes through foreign keys, I also have to refer to the classes with underscores!!! wth?? check it out

class MasterFoods(db.Model):id = db.Column(db.Integer, primary_key=True)



class MyFoods(db.Model):
id = db.Column(db.Integer, primary_key=True)
food_id = db.Column(db.Integer, db.ForeignKey('master_foods.id'), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

​

If I use MasterFoods.id in my foreign key relationship, it breaks. Is this a bug or is this intentional? If it is intentional, what the intention?

/r/flask
https://redd.it/s6vk5s
Red Mail 0.2: Next Generation Email Sender

Hi all,

I recently managed to release 0.2.0 of Red Mail: https://github.com/Miksus/red-mail, an email sender that is super easy to use but packed with advanced features like attachments, embedded images, plots etc.

I open-sourced this project about two weeks ago and back then I thought I'll make a small post and move on. However, I received so much positive feedback from you so I decided to polish this to be 100 % complete (instead of 95 % complete as it was). I was delighted that I managed to create something useful and something that help others with their projects.

For those who missed the post, a quick introduction to what's Red Mail. It's an email sending library that aims to solve all your problems regarding sending emails in Python. It's super easy to use and it has bunch of features like:

[send emails with attachments](https://red-mail.readthedocs.io/en/latest/tutorials/attachments.html#attachments) (supports paths, bytes, Pandas dataframes, etc.)
send emails with embedded images or Matplotlib plots
[send emails with embedded (prettified) tables](https://red-mail.readthedocs.io/en/latest/tutorials/body_content.html#embedded-tables)
send templated/parametrized emails (using Jinja)
[send to regular receivers, cc (carbon copy) or bcc (blind carbon copy)](https://red-mail.readthedocs.io/en/latest/tutorials/sending.html#send-cc-bcc)
it also has Gmail preconfigured and a guide for it so anyone can send emails from Python

A quick example:



/r/Python
https://redd.it/s6si3d
When is it appropriate to use DRF viewsets.Viewset?

In your experience, when is it appropriate to use DRF Generics and when is it appropriate to use DRF viewsets.Viewset? For example, let's say we have to build a CRUD REST API. The data is complicated enough that you have to use multiple models and multiple nested serializers and therefore rule out ModelViewSets. Since this is a full CRUD API, would you prefer to use viewsets.Viewset? Or would you build two separate classes using generics.ListCreateAPIView and generics.RetrieveUpdateDestroyAPIView? How would you decide?

/r/django
https://redd.it/s6y0d1
Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/s7bwqe
Build ML Products using Python

Hey, I'm Merve from Hugging Face, an Open-Source Company working in the democratization of responsible Machine Learning. 👋

We want to reduce the barrier of entry for everyone willing to learn about machine learning and how to create awesome products with ML. Our recent initiative in Open-Source is called "Tasks", we curated use cases, tutorials, models, datasets and more to help you in your path in building ML products. 🙌🏼

You can get started with learning here. You can also use hf.co/tasks shortcut. Any feedback is much appreciated 🤗

/r/Python
https://redd.it/s6y0c0
P I trained every single SOTA from 2021 and accidentally got a silver medal on Kaggle

!(https://i.ibb.co/gwpJXBm/lb.png)


I trained every single SOTA model from 2021 and accidentally got a silver medal on an image classification competition on Kaggle recently (Pawpularity Contest).

> Here If you are interested

The idea was to train every SOTA and then Nuke the leaderboard with 10 Billion parameters ensemble of ensembles.
Some ensembles were also supplemented a bit with catboost 2nd stage model just for the "why not".

Outline of the approach: https://i.ibb.co/McJ39mW/image-nuke.png

This stunt was done mainly for the purpose me catching up with the current most recent SOTA vision papers.

I seriously didn't try to compete on the leaderboard and never had the intention of releasing a public notebook that actually gets a silver medal.
This came as a complete surprise to me!
Hope the solution will be useful for many others in the future.

If you got any questions or feedback, I'll be more than happy to discuss them!

/r/MachineLearning
https://redd.it/s6spou
problem with finding npm while trying to install django-tailwind with python venv

I have a django project that uses virtual environment and I tried to install django tailwind. Unfortunately I cannot run this command and this is the error that I get:

​

python manage.py tailwind install

​

CommandError: It looks like node.js and/or npm is not installed or cannot be found.

Visit https://nodejs.org to download and install node.js for your system.

If you have npm installed and still getting this error message, set NPMBINPATH variable in settings.py to match path of NPM executable in your system.

Example: NPMBINPATH = "/usr/local/bin/npm"

Then I have set the NPM_BIN_PATH as told (NPM_BIN_PATH = "E:/Program Files/nodejs/node_modules/npm/bin" or other variations like bin/npm or /nodejs), but still the error remains the same. I have set PATH variable in my system to both /nodejs and /npm/bin as well.

Does that have to do anything with the fact that I'm using virtual environment? How can I make this command work? Or maybe should I look for other ways of using tailwind with django I know cdn can work, but it is not recommended in production, so I wanted to try this way instead.

django-tailwind docs

/r/djangolearning
https://redd.it/s7chy0
Why do you use Django?

I have been using Django for many years. But I always feel it's kind of old technology. It's good for a static website. But it's not the ideal tool to develop a modern interactive website. The front end (template) depends on other technologies like javascript, jQuery or probably more recent tools like htmx and alpine. I just feel Django needs improvement on its front end (template). Do you have the same feeling?

/r/django
https://redd.it/s7hzo2
Can't get flask to trigger from IFTTT

I have a simple python script on a raspberry pi. Its supposed to turn on my computer when I do a Google home command. The problem is that computers outside the network can't access it. The connection always times out. I forwarded the port necessary and I have a static ip and nothing. Any assistance would be highly appreciated. (If you need more info just ask)

/r/flask
https://redd.it/s7mrvv
Switch from SQLite?

I’ve had an issue where, using Replit to host my website and its SQLite database, programmatic changes to the database weren’t being saved. I use the built-in sqlite3 library. The advice I received from this subreddit (https://www.reddit.com/r/flask/comments/psdjhq/programmaticchangesnotbeingsaved/) was that SQLite doesn’t work well with an ephemeral file system like Replit so I should find a service where I can use a different SQL flavour, like MySQL or postgreSQL.

My site has a background routine that scrapes another site to update my database. I used sqlite3.Connection.create_function to register a function in the database to be called as a callback function from a TRIGGER AFTER INSERT ON action.

Would this set-up still work if I moved away from SQLite? If not, how can I achieve the same functionality with a different flavour of SQL?

More generally, can you recommend a resource where I can learn how to switch from SQLite to another SQL flavour?

Alternatively, is there a service that can host an SQLite database without the problem I’ve encountered on Replit? This would be my preference really, to save having to make major changes to my program.

/r/flask
https://redd.it/s7mb8y
Docker: where should i put manage.py commands (migrations, statics etc)? Dockerfile? Entrypoint? External?

As title says.

\- dockerfile - running things like migrations and statics gen with every build

\- entrypoint script - running migrations and statics during every container restart - afterall they wont be refreshed if nothing changed

\- external 'docker exec' commands - running them on demand manually and/or with some pipelines tool

What is the best practice? I dont like the last one because it is prone to human error (forgetting). First seems to not always work. Entrypoint script works well but is it good idea?

/r/django
https://redd.it/s7mf1k