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
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
[P] Looking for Research Collaborators!

Hey! Some buddies and I are starting an organization for AI research collaboration, and we're looking for members. We currently have six figures of funding and several deep learning experts on our team. Our goal is to work together to do what we otherwise couldn't alone, and produce research/products that are valuable to a lot of people. We can provide technical and moral support as well as huge amounts of TPUv3 compute for research projects.

​

If you're interested, shoot me a message with your background/experience as well as what you're interested in working on. We're open to all ideas, but we're especially interested in research directions that can benefit society. There are no qualifications; we're just looking for people who are passionate about AI and are willing to put in work to publish research and build technology that is valuable to the world. We're also looking for co-founders and mentors!

​

We look forward to hearing from all of you!

/r/MachineLearning
https://redd.it/cct6no
Another minimalistic python figure in a recently accepted publication

/r/Python
https://redd.it/ccvcqb
This media is not supported in your browser
VIEW IN TELEGRAM
Knowing some MatLab and some basic Java, I want to master Python. This is my first project. Pretty pleased with the result!

/r/Python
https://redd.it/cctgti
Give me your feedback

I created a simple NASA image Search engine using Django. Tell me what you think and give me your constructive criticism.

​

[https://nasaimagesearch109.herokuapp.com/?p=sun](https://nasaimagesearch109.herokuapp.com/?p=sun)

/r/django
https://redd.it/ccyiyo
How to use python to measure average word/phrase occurence per amount of time in a csv?

Note; complete beginner to python

I have a csv spreadsheet with tweets and the date of tweets.

I'd like to generate a second spreadsheet from that spreadsheet that shows, not a list of the most frequently used words, but a list of words that are prioritized by highest average occurrence per, say, 10 days.

But I don't want to select a subset of the data and say "Give me the average occurrence of these words in these specific 10 days" - I want it to spit out an average of *all* word/phrase occurrences per 10-day intervals.

E.g. "The word "climate change" has been mentioned 4 times in the past 10 days but, over all the years of data, on average, it has been mentioned 1 time per 10 days"

Then I'd like it to prioritize by the highest average.

Is that possible to achieve? If so, what modules or fields or tools should I explore further? Any specific suggestions of what to do also welcome.

I'm essentially trying to prioritize by the 'steepest slopes'

/r/pystats
https://redd.it/ccw2mt
Best way to implement user settings Django/React

Hi. I'm thinking what would be the best approach with user settings - let's say I would like to give users an option to set timezone in which time should be displayed, so every user would be able to set one however he/she likes. I'm thinking about one-to-one relation between user model and settings model, but what's next? How to pass it from backend? All I could think of was to create custom middleware that would fetch serialized settings and send it to frontend with every request, but not sure if it's the best idea, query database for settings every time user reload/click the link on the website. Do you have any better ideas? Or seen something like this in some project? Every input would be valuable.

/r/django
https://redd.it/ccsq1h
Learn Python 3: From Beginner to Professional 2019
https://www.youtube.com/watch?v=jE2HLArCS38

/r/flask
https://redd.it/cd1kfe
Model creation. Multiple IDs all have same description and text. There is no ArrayField. How should I do this?

App functionality (simplified): Person enters order ID, webpage spits out a list of products ordered with product description, and some text for each product. This text is a checklist for factory workers who assemble the product.

I'm getting the product_IDs for the order from the WooCommerce API, they are stored in an array.

I need to create the Django Model. I think I can shove all this in 1 Model without needing foreign keys?

WooCommerce variations (product in different color/size) have a different ID than the parent product, but they should all have the same product name and instruction text as the parent.

eg productIDs between 100 and 200 all are "Shoe X" and they should all have the same text (for example: put red laces in, put blue insole in, glue on a black sole, get that type box to put them in).

What's the best way to put this in a Model so that I can loop over the product_id array and get the matching description and text, but don't have to enter all 800+ IDs in a separate table row?



PK | product_shop_ids| product_description| the_text
---|---|----|----
0 | 0 up to 125| Shoe X| checklist for Shoe X
1 | 126-140 |

/r/django
https://redd.it/cd3rqp
How would I minify all my pages.

Hi, I'm getting fairly close to publishing.

Most of my pages can be made 20% or so smaller by minifying them.

​

Would it be worth it to minify my content, and if so. how?

​

I have looked into doing it with nginx (as I will use it as a proxy with gunicorn) but I'm wondering if there is a more Django way of doing it?

​

Thanks.

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