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
How do you keep a script running continuously?

I know how to run a script once in Django, for example using Requests to download a web page and then display something to the user.

However, how would I go about having a script get the web page every X seconds? Would I need an additional VM or other resources to keep that script running at all times?

/r/django
https://redd.it/cc69m2
WTForms and __init__ method

Is it possible to add an \_\_init\_\_ method to a form class?

I wanted this part:

form.client.choices = [(c.id, c.name) for c in ClientModel.query.all() ]

to be implemented when the form initialises, which makes more sense than doing it on the server file. Unless there is a different approach.

I basically just want the server file to have :

form = myForm()

Is this possible?

Thank you! :)

/r/flask
https://redd.it/ccaoyi
TIL: Python3.6 supports underscores in numeric literals (PEP515)

For reference [https://www.python.org/dev/peps/pep-0515/#id26](https://www.python.org/dev/peps/pep-0515/#id26):

>>> 1_234_567 == 1234567
True
>>>

/r/Python
https://redd.it/cc8jpp
[R] "We also 3D-print our adversarial objects and perform physical experiments to illustrate that such vulnerability exists in the real world" - Adversarial Objects Against LiDAR

Abstract:

>Deep neural networks (DNNs) are found to be vulnerable against adversarial examples, which are carefully crafted inputs with a small magnitude of perturbation aiming to induce arbitrarily incorrect predictions. Recent studies show that adversarial examples can pose a threat to real-world security-critical applications: a "physical adversarial Stop Sign" can be synthesized such that the autonomous driving cars will misrecognize it as others (e.g., a speed limit sign). However, these image-space adversarial examples cannot easily alter 3D scans of widely equipped LiDAR or radar on autonomous vehicles. In this paper, we reveal the potential vulnerabilities of LiDAR-based autonomous driving detection systems, by proposing an optimization based approach LiDAR-Adv to generate adversarial objects that can evade the LiDAR-based detection system under various conditions. We first show the vulnerabilities using a blackbox evolution-based algorithm, and then explore how much a strong adversary can do, using our gradient-based approach LiDAR-Adv. We test the generated adversarial objects on the Baidu Apollo autonomous driving platform and show that such physical systems are indeed vulnerable to the proposed attacks. We also 3D-print our adversarial objects and perform physical experiments to illustrate that such vulnerability exists in the real world.

​

Website: [https://sites.google.com/view/lidar-adv](https://sites.google.com/view/lidar-adv)

Paper: [https://arxiv.org/abs/1907.05418](https://arxiv.org/abs/1907.05418)

/r/MachineLearning
https://redd.it/ccc7p4
[D] Are there any legal issues with training machine learning models on copyrighted content?

Say that I purchased some books/movies/research papers/whatever, and used that data to train machine learning models, and then made some money off those models. Are there any legal issues to this?

What if the model generated content that was very similar to the copyrighted content? Any legal issues there?

/r/MachineLearning
https://redd.it/cc76us
Text to Speech for Voices from YouTube Videos

Thought I'd share here a project that I've been recently working on, which is being able to synthesize voices like that of Elon Musk, Donald Trump, Obama...etc, using YouTube clips as sample audio:

[**Text to Speech from voices in YouTube clips**](https://www.youtube.com/watch?v=6bFN2YkN6bo)

​

TLDR/W; You can generate fairly decent audio of other voices using \~15 minutes of audio and about 1.5 hrs of training time (using transfer learning from a base model). Examples in the first 2 minutes of the video.

​

Future work: text to video, possibly other base models to transfer from besides a british female voice, or maybe have a base model that is created from many voices to start with.

​

Anyway, hope you enjoy.

/r/Python
https://redd.it/ccehfk
I made a (poor) simulation of the "raid" on area-51

[https://github.com/JackTGarland/Area51](https://github.com/JackTGarland/Area51)


It creates a ini on first run that is customizable, it's not great, but I am enjoying this meme to much to sit back in the UK doing nothing.

/r/Python
https://redd.it/cci7bh
Not sure if this the right place to ask this. I would like to know if there is anyone who has developed an ecommerce site for the African continent. Which payment gateway did you use, since stripe is not available in Africa.



/r/django
https://redd.it/ccf6o8
[D] Dislike/Disinterest of Machine Learning: rant

This is just my personal opinion/rant of what I inherently dislike about ML and neural networks after working on a research project involving a CNN for little under a year and feeling very frustrated with where it is going. Not claiming to be an expert or professional in the field.

​

**#1: Machine learning is frustrating to code/improve on:**

​

I find the coding of machine learning for a neural network (at least at my level when you are only really applying already existing layers/activation functions) to be very unsatisfying to progress through due to the nature of it. When you are solving a normal coding problem I feel like you can get creative with dealing with problems/issues that occur with your algorithm, as you progress through solving the problem (In my case getting high classification accuracy), but the solution offered by machine learning tends to be a sort of black box where it simply works at a certain percent for whatever rhyme or reason. I feel like the time I put into improving my classification accuracy is not proportional to the rate at which it improves and is more factored by chance than anything. For example I spent weeks changing the shape and

/r/MachineLearning
https://redd.it/cc7dfi
Update on Comprehensive Python Cheatsheet

I apologize for submitting links that were already posted yesterday, but I would like to highlight a few things that were added since my last submission 5 months ago:

* [ABCs](https://gto76.github.io/python-cheatsheet/#type) explained with two tables.
* Table of different ways to format floats in [Format](https://gto76.github.io/python-cheatsheet/#format) section.
* In-depth explanation of [Datetime](https://gto76.github.io/python-cheatsheet/#datetime) module.
* Much extended [Class](https://gto76.github.io/python-cheatsheet/#class) section (property, dataclass, slots).
* Section on [Iterable Duck Types](https://gto76.github.io/python-cheatsheet/#iterableducktypes).
* [Metaprograming](https://gto76.github.io/python-cheatsheet/#metaprograming) section has two diagrams that nicely show relations among root classes 'object' and 'type'.

Also I would like to thank everyone who helped in any way. It was because of this subreddit that the project became so popular. I think I'm finally happy with it and will be moving on to other pet projects.

Ps: Only glaring hole that remains and I gave up on is a section about asyncio module. Maybe it will be added in the future.

/r/Python
https://redd.it/ccftbj
Examples of professional and scalable flask API codebases?

I would really like to see some examples of well-written open source code bases in flask so I can see how they handle various things. Specifically looking for some REST APIs. Preferably something done by a professional team of developers.

Anyone got some good examples?

/r/flask
https://redd.it/ccjl34
Graphql and Django

Hi all, what's your take on graphql support in python, particularly graphene-django. Is the tech mature enough for use by large projects? Any large companies/large projects using it? Do you still need DRF if using GraphQl in your Django project?

/r/django
https://redd.it/cckr5z
Clarification over a simple Django Architecture

Hello Pythoners!

I recently started out with Django framework (I come from Laravel) and I find it really cool, although I have encountered some points where I really need some kind of clarification to check if I am doing it wrong and / or if everyone has the same concerns. Here are some of them:

1. Environment variables on production: good old Laravel has a file, .env, where you can store the variables both in development and in production. Django has only the setting.py file which will get deployed along with the other files and whose content we defintely do not want to show. Now, what is your approach in dealing with this on production? I found a package, django-environ, although to me was kinda hard to configure. What's your favourite approach?
2. Frontend architecture: I have built a simple invoice app, where a user can create an invoice through various forms and then simply generate a pdf with the inserted data. My front end is made simply of django templates, stored in templates/ folder (same level of manage.py), and all of them extend a layout (index.html) in which are injected the bundle of .js and .css coming from Webpack, whose folder is

/r/django
https://redd.it/ccno58
WTForm and indefinite amount of inputs

I tried scouring the documentation, but I couldn't find any way to have an indefinite amount of fields. ideally, I want the user to be able to hit a little "plus" icon on the front end, and another input will appear. (example: form input for a menu; you can hit the plus sign to create a new input for a new menu item.) Then when the form is submitted, each value is placed into an array. Is this possible in flask and WTForm? Thanks in advance!

/r/flask
https://redd.it/ccljrk
I just made the most 50/50 script ever: it selects and opens random image URLs from 4chan (returns NSFW results like half of the time)

It's fun to run! Cause you *really* never know what's going to pop up. Run at your own risk though, cause it can return anything from cute kitten pictures, to not-unseeable NSFL pictures

#!/usr/bin/python3
#*************************************************************************************************************************
#IMPORTANT
#Don't remove the time.sleeps; which are in place to comply with 4chan's API rule of 'no more than 1 request per second'
#https://github.com/4chan/4chan-API
#
#This script selects a random images from 4chan, and opens them in web browser
#Requires the 'requests' module
#*************************************************************************************************************************

import requests,random,json,time,webbrowser

#Returns [ random image URL, random image's thread URL ]
def r4chan():
#List of 4chan boards
boards = ['a','c','w','m','cgl','cm','n','jp','vp','v','vg','vr','co','g','tv','k','o','an','tg','sp','asp','sci','int','out','toy','biz','i','po','p','ck','ic','wg','mu','fa','3','gd','diy','wsg','s','hc','hm','h','e','u','d','y','t','hr','gif','trv','fit','x','lit','adv','lgbt','mlp','b','r','r9k','pol','soc','s4s']

#Select a board
board = random.choice(boards)

#Request board catalog, and get get a list of threads on the board; then sleeping for 1.5 seconds
threadnums = list()


/r/Python
https://redd.it/ccrh6o
I also made a bot using PyAutoGUI and reading process memory

Since people are sharing their bots I wanted to show mine too! It's for the game Ragnarok Online, although I've only used it on a certain private server that has bot protections in place which prohibit the use of conventional bots. Feel free to ask any questions :)

https://gfycat.com/playfullinedjohndory

Edit: The reason I created this bot was to see if I could circumvent the bot protection and get into some reverse engineering.

Source (careful... it's a mess): https://github.com/frosenek/ro-bot

/r/Python
https://redd.it/ccq1yj