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
Does MyPy have any shortcomings in its typing versus a traditional statically typed language?

I'm really impressed that they managed to capture all the possibilities of Python's type system and put it into a comprehensive syntax. Once you bring in concepts like generics and polymorphism into play in a language, types can get pretty complicated. How does MyPy compare to a statically-typed language like C++ or C#? Are there any holes or flaws?

/r/Python
https://redd.it/5juo74
matplotlib plots freeze when trying to close in ipython 5.0, on El Capitan.

I am running python 2.7.10 and just installed ipython 5.0. When I create a simple plot using matplotlib and then try to close it, the figure just hangs. Anyone else experiencing this? Pretty shitty release if I can't even plot anything anymore.

/r/IPython
https://redd.it/4s2yrc
Computational Statistics in Python — A comprehensive review
http://people.duke.edu/~ccc14/sta-663/index.html

/r/JupyterNotebooks
https://redd.it/48xrb8
Where to ask questions about IPython nbextensions?

I am trying to debug an IPython nbextension, and I need to put a hook in that runs at the later of the following events:

- when the nbextension is loaded
- when the notebook metadata is loaded

I can't seem to figure this out. Where is the best place to ask questions like this?

/r/IPython
https://redd.it/4ryk6t
How do you automate your life with python?

What nifty little script did you write to save some time using python?

For me:

I gathered some libraries and did a script that downloads youtube videos (from a link of a direct video or several from a playlist), and when it is done it converts every file to mp3, then it uploads to dropbox and get the direct link of every mp3

For now it does just that. But I'll add some code to make it use the direct link to feed my podcast rss on HuffDuffer.

I use this to download entire classes that are available online and listen while I commute

/r/Python
https://redd.it/5jv3db
What are some of the most extensive projects you have seen?

I am a college student and I'm thinking about doing a side project and looking for some inspiration.

I'm looking forward to devote 5-6 months of time to a good, extensive project. Ideas?

/r/Python
https://redd.it/5jwfng
JWT support without the jwt rest plugin?

I'm looking for a nice jwt package for a django app that is using graphql. Ideally i'd rather not need to use the popular jwt plugin for the rest framework. Any advice?

/r/django
https://redd.it/5juz6r
Can anyone help me and copy the stylesheet/subcategories-thing from /r/askscience to my subreddit r/kitricks?

I don't know the 101 of how to do it and it would be cool to have subcategories by colors for easy picking.

you can be admin. it's gonna be f cool when it will be fille up!

/r/Python
https://redd.it/5jwp2s
Creating a CallbackURL to consume a Webhook POST Request (Update and Thanks!)

Hi guys,

A few weeks ago I asked a question about creating a callback url for a webhook [(Original Post Here)](https://www.reddit.com/r/django/comments/5ftsy6/how_do_i_create_a_callback_url_to_consume_a/) and I wanted to give a shoutout to those of you who helped me figure it out.

/u/Niicodemus - for putting it in layman's terms for me and for the bit about ngrok. At the time I did not have my website hosted so I wouldn't have been able to test it locally without the ngrok tip. It was super easy to set up if anyone has questions.

/u/spookylukey - for diving into Trello docs a bit and helping me understand the HEAD request

and /u/vitorfs's article showed me the general layout and walked me through verifying the IP addresses from trello.

So thank you to everyone who commented, I learned a lot from your help and I'm much more comfortable doing this kind of thing again in the future. For those of you curious (and to help those who have similar questions in the future) here is my code. This is all it takes to get it set up. *Comments and feedback welcome*

**Pip Requirements**
requests
ipaddress

**urls.py**

from django.conf.urls import include, url
from django.contrib import admin

from trello.views import list_webhook

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^trelloCallbacks/', list_webhook, name='trello_webhook'),
]


**trello/views.py**

from django.http import HttpResponse, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt

from ipaddress import ip_address, ip_network
import json

from .utils import add_label_to_card

list_before = '<a_trello_list_id>'
list_after = '<another_trello_list_id>'


def check_request_from_trello(forwarded_for):
client_ip_address = ip_address(forwarded_for)
print(client_ip_address)
whitelist = [
"107.23.104.115",
"107.23.149.70",
"54.152.166.250",
"54.164.77.56",
]

for valid_ip in whitelist:
if client_ip_address in ip_network(valid_ip):
print("Request from Trello IP")
break
else:
print("Request from Unknown IP")
return False

return True


@csrf_exempt
def list_webhook(request):
if request.method == "HEAD":
return HttpResponse("OK")

forwarded_for = u'{}'.format(request.META.get('HTTP_X_FORWARDED_FOR'))
if not check_request_from_trello(forwarded_for):
return HttpResponseForbidden("Access Denied, not from Trello")

obj = request.body.decode("utf-8")
data = json.loads(obj)
action = data["action"]

if not action["type"] == "updateCard":
print("Different Action Type")
return HttpResponse(status=200)

if "idList" not in action["data"]["old"]:
print("Card Didn't Move")
return HttpResponse(status=200)

card_id = action["data"]["card"]["id"]
if add_label_to_card(card_id):
print("Added Label")

return HttpResponse(status=200)


**utils.py**

import requests

def add_label_to_card(card_id):
endpoint = "https://api.trello.com/1/cards/"
endpoint += card_id
endpoint += '/labels'
params = {
"name": "logged",
"key": APP_KEY,
"token": TOKEN,
"color": "green"
}

r = requests.post(endpoint, params=params)
if r.status_code == 200:
return True
return r



/r/django
https://redd.it/5jtg26
very basic python question

can some one please give me the most basic explanation for the following:

Variables
Strings
White Space

Also, Im learning off the book "python crash course" by eric matthes, (great book so far) any way trying to use concatenation to compose a message and the store that message in a variable the book says my line of code should look like the following:

message = "Hello, " + full_name.title() + "!"
print(message)
I keep getting invalid syntax for the "!"

I know this is so very basic, and i was going to skip right over it, till i ran into the problem again but i felt like i might as well, figure out what im doing wrong before moving on. Thanks for the help

#noob

/r/Python
https://redd.it/5jxdkj
favicon not showing

Hello I have in the head of my base template.
<link rel="icon" href="{% static "images/favicon.ico" %}" />
This is where my favicon.ico is located it's 16x16, I can access the image in my browser by going to http://127.0.0.1:8000/static/images/favicon.ico.

I've also tried
<link rel="icon" href="/static/images/favicon.ico" />
and just putting favicon in the root directory still nothing.

Also, It seems only to attempt loading the favicon the first time I start the test server every day, I only see the GET favicon.ico 404 my first run. I have the cache disabled so I thought this might force it to look again but I don't think it is. Thank you.

/r/djangolearning
https://redd.it/5jrvly
Logic gates in python

Can logic gates be used in python language and if yes then how does it work? Like examples.

/r/Python
https://redd.it/5jxp8e