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
Mildly Interesting: The source for the Zen of Python completely violates the Zen of Python

For those that don't know, the Zen of Python is an easter egg included with the language:

>>> import this

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain,

/r/Python
https://redd.it/azuq9g
Job execution, celery + flask

Hi,

I need your advices about python jobs execution. I'm working with ad platforms and i have several job with are independant python project which do stuff as data extraction ( from ad platform ) and data insertion ( to my databases ). Thoses jobs take around 30 minutes each. Each time i want to run a job, i clone it from github, install a virtualenv and the requirements. Then i run the job and keep the logs. But now i'll need to expose them trought an API.I was wondering using celery with flask but i saw no one executing job by cloning from github + install venv + requiremenst and at the end delete the job folder.
Am i doing something wrong ?
Does anyone had the same experience ?
Thanks for reading

/r/Python
https://redd.it/b05c20
Knitty: Jupyter+Pandoc+IDE power in plain Python/Julia/R/any-kernel-lang. Pandoc filter and Atom/Hydrogen friendly literature programming

[**Knitty**](https://github.com/kiwi0fruit/knitty) is a Pandoc filter and [Atom/Hydrogen](https://atom.io/packages/hydrogen)-friendly reproducible report generation tool via Jupyter, Pandoc and Markdown (fork of the [Stitch](https://github.com/kiwi0fruit/knitty/blob/master/docs/stitch.md) that is a [Knitr](http://yihui.name/knitr/)-[RMarkdown](http://rmarkdown.rstudio.com)-like library in Python). Insert python code (or other Jupyter kernel code) *to the Markdown document* **or write in plain Python/Julia/R with block-commented Markdown** and have code's results in the Pandoc output document.

Knitty is an important part of the [Best Python/Jupyter/PyCharm experience + report generation with Pandoc filters](https://github.com/kiwi0fruit/pandoctools/blob/master/docs/best_python_jupyter_pycharm_experience.md) (see there why writing in plain Python/Julia/R is great) but actually

Knitty is language agnostic and can be used with any Jupyter kernel. Can be used independently of Pandoctools and with any IDE of choise. So I guess it deserves a separate post. By the way: Atom/Hydrogen is also language agnostic. You can also try **VS Code** interface to Jupyter from [**vscode-python**](https://github.com/Microsoft/vscode-python) instead of Atom/Hydrogen. I highly recommend to try to think about ipynb as merely an output format like pdf instead of main format or intermediate format (albeit ipynb is great for presenting narrative interactively and it can even [be much more](https://github.com/kiwi0fruit/misc/blob/master/src/pdf_and_word_killer.md)).

[**knitty repo**](https://github.com/kiwi0fruit/knitty).


### P.S.

[Knitty vs. Knitpy](https://github.com/kiwi0fruit/knitty/issues/1) joke.

/r/JupyterNotebooks
https://redd.it/b06wvq
How do you separate the Django environment variables, and which ones do you use?

I did a tutorial that I can not remember which one, where some of the settings were in an .env file. I also do not remember which settings were there.

​

By the way, how do you separate some of the settings, like secret key and database? It's a good idea for me to do something like:

.env

source .env // in a linux terminal

​

And inside env file, contain something like

EXPORT DATABASE = 'database settings in a json format here'

​

And then use the .environ and json loads to get these values?

​

If not, how do you do this, more specifically, in a professional environment?

​

EDIT: I used python-decouple, which also uses an .env file or settings.ini, and from what I've seen, it (and others who do this work) will automatically search the file in the project root directory and do things automatically. But from what I've seen, they use it as environment variables, but they search the file directly, instead of exporting to the linux environment and then searching for them.

/r/djangolearning
https://redd.it/azzxeg
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/b087td
Status of r/djangolearning common repository

I have seen a few different posts on r/djangolearning regarding creating a common respository for learning purposes. Is there one currently being used? If not, I would love to create one and take charge of managing it.

/r/djangolearning
https://redd.it/azy60d
Use cases of Django on Kubernetes

I was curious if anyone knew of good use cases of Django on Kubernetes. It seems a little "heavy" for a microservice compared to a microframework like Flask but maybe there are ways to work around that fact.

/r/django
https://redd.it/b08l5y
Does your work require mathematical knowledge?

I found a Django work for beginner today, but when I went to the site to apply for the job, first it is necessary to do several tests to reach a minimum score to make the interest available in the works.

​

One is about finding the greatest common divisor between two numbers, okay, that's not difficult, but it's been a long time since I studied math and I do not remember how I do it.

​

There were also other questions involving math. I can not speak much more because I only had 3 questions available so far.

​

Anyway, what do you think of that? Do you use this knowledge in your work with Django?

/r/django
https://redd.it/b0diqr
Help with dynamically creating <img> tags using Vue/javascript in Flask application

I'm currently working with on a Flask + Vue/js application. So far, it's been fairly easy importing images into the project by writing `<img src= "{url_for('static', filename='images/image_name.png') }"` in the html file.

&#x200B;

However, now I need dynamically load x copies of an image at runtime. The technique above (written in javascript) isn't working (as I should have known from the 'static' retrieval method).

&#x200B;

Advice?

/r/flask
https://redd.it/b0dbtp
Redirecting URLs on Deployed Flask Apps

I'm using PythonAnywhere to host a Flask app. I've redirected my app homepage to a domain I brought which should work (waiting on DNS records to update). How would I go about making sure the other pages such as [www.test.com/page2](https://www.test.com/page2) redirects correctly?

/r/flask
https://redd.it/b0da9o
How to print name to screen when button clicked?

Hi, I'm trying to print the name to the same screen when a user enters a name and clicks the submit button. I'm getting error: hello() missing 1 required positional argument: 'greeting\_id'


Any help would be great, here's my code:


Views.py

from django.shortcuts import render
from django.http import HttpResponse
from .models import Greeting


# create hello view

def hello(request, greeting_id):
if request.method == 'POST':
if request.POST['firstname']:
greeting = models.Greeting()
greeting.firstname = request.POST['firstname']
greeting.save()
obj = models.Greeting.objects.get(pk=greeting_id)


/r/django
https://redd.it/b0e4y1
Machine Learning Resume Generator With Python, TextGenRnn and AWS

I was like one of you folks once, trying to think how to write a resume before I started working as a full-stack dev at a place I love. Over the years I have obsessed about how to make it easy for every one to build their resume. Using some AI magic, I ended up creating a site (a side project) that allows you to create a resume for free. Here’s the link: [https://thisresumedoesnotexist.com/](https://thisresumedoesnotexist.com/)

I've used [https://github.com/minimaxir/textgenrnn/tree/master/textgenrnn](https://github.com/minimaxir/textgenrnn/tree/master/textgenrnn) to generate the text by feeding it data scraped from various resources. My script runs in a "while true" loop and generates a new resume every 3-4 seconds. Resume is then saved to S3 and the same resume is loaded via CloudFront for all users.

I plan to make it more and more awesome, like you add your name and designation and it fills up your resume. But, I thought it would be nice to get a feedback from you folks and see if I can add the to my to-do for the side project.

I’d the following thoughts on why I started working on it:

\- I knew a guy who got a job at Google, who previously couldn’t get a job at an IT

/r/Python
https://redd.it/b099zl
Question about examsheet model

Hi,

I would like to ask more advanced users how to create examsheet object in Django by correct way? Lets say examsheet must contains Questions and Answers so should we create 3 models with manytomany relations ship like Examsheet, Question, Answer or it's not correct?

/r/django
https://redd.it/b0kh4y
Dynamic redirects in Flask

I am building a platform for use in my office. The general idea is that outside freelancers can submit queries about projects. The queries are approved by an in-house project manager and sent to the client for an answer. The project managers then re-approve the answers for view by the external freelancers.

I have pages for adding, editing and answering queries. However, I am having trouble with redirects after the forms are submitted. I have two choices, I can either have a direct redirect path stored in my return statement (such as a main project dashboard). Otherwise, I can use request.referrer to redirect to the previous page. As links for these options can appear on multiple pages for convenience, redirecting to a specific page is a bit confusing to the user.

I run into problems using wtforms and form validators. If a form fails validation, request.referrer becomes the page the user is currently on, and fixing the form errors and re-submitting brings them back to the current page, not the page they clicked the link to add, edit, or answer the query.

Is there any way to prevent request.referrer from updating on failed form submission, or a way to store the value of

/r/flask
https://redd.it/b0mbb0