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'm being followed by an army of spammy Python accounts on Twitter. What's going on?

Over the last few days a number of suspicious looking accounts have started to follow me on twitter. They all pretend to be some sort of generic Python related account. Yet they all have more or less the same bio and all tweets link to very suspicious websites.

I've blocked and reported all of them, but more and more are coming and I'm seeing legitimate Python accounts following some of them, probably without double checking.

Did anyone else notice this? Does anyone have an idea of what's going on? Should I report this to twitter and if yes how?

Here's a list of the accounts I've seen so far if someone want's to check them out. **Be careful with clicking any of the links in their tweets and bio!**

* [@learn_pythonx](https://www.twitter.com/learn_pythonx)
* [@python_codecs](https://www.twitter.com/python_codecs)
* [@PythonCodeademy](https://www.twitter.com/PythonCodeademy)
* [@The_PythonTutor](https://www.twitter.com/The_PythonTutor)
* [@Python_Codingz](https://www.twitter.com/Python_Codingz)
* [@Python_4coders](https://www.twitter.com/Python_4coders)
* [@Learn_Python_2z](https://www.twitter.com/Learn_Python_2z)
* [@python_0toHero](https://www.twitter.com/python_0toHero)
* [@ThePythonTutor_](https://www.twitter.com/ThePythonTutor_)
* [@python_4coder](https://www.twitter.com/python_4coder)
* [@Python\_Master_](https://www.twitter.com/Python_Master_)
* [@Python_programz](https://www.twitter.com/Python_programz)
* [@pythonbeginner_](https://www.twitter.com/pythonbeginner_)
* [@PythonsTraining](https://www.twitter.com/PythonsTraining)
* [@LearnsPython](https://www.twitter.com/LearnsPython)
* [@PythonDailyNews](https://www.twitter.com/PythonDailyNews)
* [@python_news_4u](https://www.twitter.com/python_news_4u)
* [@python\_academy_](https://www.twitter.com/python_academy_)
* [@pythonmaster_](https://www.twitter.com/pythonmaster_)
* [@PythonDev_AtoZ](https://www.twitter.com/PythonDev_AtoZ)
* [@LearnPython_toZ](https://www.twitter.com/LearnPython_toZ)
* [@Python_AtoZ](https://www.twitter.com/Python_AtoZ)
* [@Python4Tutorial](https://www.twitter.com/Python4Tutorial)

/r/Python
https://redd.it/7wl2hc
I made a Mastermind like game

Hi

This is my first code ever so please be kind. I just finished some online tutorial and wanted to test what I remembered from it. Thank you in advance for your time.

#game mastermind
#code breaking game

#X = not in phrase
#O = in phrase and in the right place
#A = in phrase but at the wrong place

import random

print('Mastermind !')

maxnumber=input('Input your maximum number between 4 and 9 (9 being the hardest) : ')

phrase = [random.randint(1,int(maxnumber))]
for x in range(3):
a = random.randint(1,int(maxnumber))
while a in phrase:
a = random.randint(1,int(maxnumber))
phrase.append(a)

playerphrase= 0000
counter = 0

maxcounter=input('How many turns do you want to give yourself (3 is not doable 4 is hard and it gets easier

/r/Python
https://redd.it/k1fmq5
Here is how i made a 2D game using Python Matplotlib

Im only few month into learning Python and i was wondering if i could make a game with it. I didnt know about any libraries created specifically for developing games at the time, so i asked an AI if i could somehow make a code that opens and plays GIF animations. AI came up with a function that opens GIFs as matplotlib plots. I added a condition that if 'space' button is pressed, the animation stops and the last frame number is saved into a variable, and then the value of the variable determines what happens next. This whole game is built around this simple algorithm.

showcase: https://youtu.be/ZAXlaOWMgfM

source code: https://drive.google.com/drive/folders/1bKV4\_AdCgnW40A8B1kFkFYryIuTE44A6?usp=share\_link

icon

​

QTE

/r/Python
https://redd.it/11szlvk
I have some questions about wtf-forms, when using flask wtf forms what exactly is {{ form.username }} equal to in the html? I assume it just gives the "input type=".

Here is an example of the form.

class RegistrationForm(FlaskForm):

username = StringField('username',validators=
[
DataRequired(message='Username is required'),
Length(min=2, max=25 , message='Must be between 2 and 25 characters'),
check_if_username_not_in_db
])

Also how would I implement the code without validation errors ?

​

For more details here is an example.

I am just using args as a placeholder normally I would just add the variables.

def some_func(*args)
#code
raise ValidationError('Please include a capital letter in the password field')  

Would I just go

def some_func(*args)
#code
render_template(register.html, 'validationerror='Please include a capital letter in the password field')

and then just go in the register.html

{% if validationerror %}
{{ validationerror }}


/r/flask
https://redd.it/1bs01eu
How do I add a new entry to my many to many related table in Django?

I have two models Course and Educators. Course has 3 fields course\_name, course\_educators and course\_past\_educators which link Educators to Courses by many to many. I want to write a function so that whenever a new entry is added to course\_educators that entry will be copied over to course\_past\_educators.

#models.py
#code for Educators model
class Educators(models.Model):
educator_name=models.CharField(max_length=20,default=None)
educator_img = models.ImageField(upload_to='educators_img',default=None)

#code for Courses model
class Course(models.Model):
course_name = models.CharField(max_length=100)
course_educators=models.ManyToManyField(Educators, related_name='current_educators', default=None, blank=True)
course_past_educators=models.ManyToManyField(Educators, related_name='past_educators', default=None, blank=True)

#views.py
#This is the function I wrote so that entries into course_past_educators are automatically added when course_educators is added with another entry.
u/receiver(m2m_changed, sender=Course.course_educators.through)
def create_past_educator_on_add(sender, instance, action, reverse, model, pk_set, **kwargs):
if action == 'post_add' and reverse is False:


/r/djangolearning
https://redd.it/1cq2j42
Master the python logging module

As a consultant I often find interesting topics that could warrent some knowledge sharing or educational content.
To satisfy my own hunger to share knowledge and be creative I've started to create videos with the purpose of free education for junior to medior devs.

My first video is about how the python logging module works and hopes to demystify some interesting behavior.

Hope you like it!

https://youtu.be/A3FkYRN9qog?si=89rAYSbpJQm0SfzP


/r/Python
https://redd.it/1eyn4n7
New fastest HTML parser

Hello there, I've created a python bindings to html c library reliq.

https://github.com/TUVIMEN/reliq-python

It comes in pypi packages that are compiled for windows, x86 aarch64 armv7 linux, and macos.

# What My Project Does

It provides a HTML parser with functions for traversing it.

Unfortunately it doesn't come with standardized selector language like css selectors or xpath (they might get added in the future). Instead it comes with it's own, which you can read about in the main lib (full documentation is in a man page).

Code example can be seen here.

# Target Audience

This project has been used for many professional projects e.g. forumscraper, 1337x-scraper, blu-ray-scraper, all of which are scrapers, and thats it's main use.

# Comparison

You can see benchmark with other python libraries here.

For anyone wondering where does the speed and memory efficiency come from - it creates parsed structure in reference to original html string provided. If html string changes, entire structure has to be reparsed to match it.

This comes with limitation unique only to this library - although possible, any functions changing html structures aren't implemented. This however is useful only for browsers ;)

/r/Python
https://redd.it/1lganqg
iommi 7.15.1 released

The biggest new feature is the new debug tool "code finder" which makes it super easy to find the code you want to modify in complex pages with many templates. There's a tiny demo in the docs: https://docs.iommi.rocks/dev_tools.html#code-finder In your real project it would jump into the IDE at the file and line of the closest `{% if/for/trans %}` tag.

Other changes:

* Support GeneratedField
* Debug menu should preserves GET parameters for profile/SQL trace/code finder
* Main menu: http urls should also be counted as external
* Main menu: dynamic submenus
* Main menu: M.icon can be a callable
* Fix EditTable delete button for dynamically added rows
* Fixed re-rendering not added rows when validation errors occur in new rows
* Ability to pass arbitrary kwargs to `object.save` in edit/create forms cleanly
* EditTable new row handling now done via AJAX, making it much more powerful
* Many more minor bug fixes
* Many documentation improvements

https://github.com/iommirocks/iommi

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