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
[P] Deep reinforcement Learning course: Q-learning article and DQN with Doom notebook are published

Hello, I'm currently writing a series of free articles about Deep Reinforcement Learning, where we'll learn the main algorithms (from Q* learning to PPO), and how to implement them in Tensorflow.

The second article is published, it's about Q-learning and we'll learn to **implement a Q-learning algorithm with Numpy and OpenAI Gym.**

**Q-learning article**: https://medium.freecodecamp.org/diving-deeper-into-reinforcement-learning-with-q-learning-c18d0db58efe

Moreover, the third article (Deep Q Learning with Doom) will be published **this week**, but the implementation of a Doom playing agent with Tensorflow **is already published.**

**Doom Deep Q agent**: https://github.com/simoninithomas/Deep_reinforcement_learning_Course/blob/master/DQN%20Doom/Deep%20Q%20learning%20with%20Doom.ipynb

Let me know what you think! What architectures you want and any feedback.

**The Syllabus**: https://simoninithomas.github.io/Deep_reinforcement_learning_Course/

**Introduction to Reinforcement Learning**: https://medium.freecodecamp.org/an-introduction-to-reinforcement-learning-4339519de419

Thanks!


/r/MachineLearning
https://redd.it/8beohl
Documenting a Django Rest Framework API

I'm using DRF for the first time to create a read-only API. It all works fine, but I'm trying to work out how to automatically generate some documentation for it.

I've got a Swagger UI page up and running using [django-rest-swagger](https://marcgibbons.com/django-rest-swagger/), which is OK... but some of my API endpoints have optional GET arguments and I can't see any way to document those in a nice way. I can mention them in comments on my DRF Views, but I thought there'd be a way to format them nicely, maybe have them appear as fields in the Swagger UI, like `lookup_url_kwarg`s do.

I'm going round in circles, reading the DRF [Documenting your API documentation](http://www.django-rest-framework.org/topics/documenting-your-api/), all the third-party tools they mention there, laborious workarounds like [this](https://github.com/m-haziq/django-rest-swagger-docs#advance-usage)...

Does anyone have a good, thorough example of how to nicely document a DRF API?

/r/django
https://redd.it/8b9kjo
How to properly implement a button to change state.

In a project I'm working on I'd like to have a button that would change an object's state from one to another

For example

`MyObject.approved = True`

Right now I'm using a button wrapped inside form tags with a csrf_token tag, is this the way to do it or is there another one?



/r/djangolearning
https://redd.it/8biczy
How does Jupyter find modules?

I'm trying to troubleshoot an issue where my Jupyter Notebook can't find an installed module, but documentation on this is sparse. How do I specify where any given instance of Jupyter Notebook looks for modules?

A possibly related question: When I use `jupyter --path`, I see a listing of directories under the "data" heading. Is this where Jupyter looks for modules, and if so, what file do I edit to change it?

/r/IPython
https://redd.it/8biqq7
Jupyter background data storage is confusing

For example:

> from abc import xyz as 123 # creates alias 123 for xyz

Then I delete the code above, replace it with the code below and rerun the cell.

> from abc import xyz

Nonetheless, alias 123 remains functional as it stored in memory and is only erased if you restart the kernel.

This leads to confusion (or forces you to keep track of more things) when you run the code after making edits - some errors are not raised because their dependencies (such as 123) are stored an remain accessible.

Also, all variables (even those defined within a function) are global.

My intuition is that these differences (from normal ide coding environment) will result in confusion and I want to turn of this feature; however, it might be the case that I am misusing Jupyter and these features are in fact advantageous. If so, can you please educate me?

Thank you very much

Edit: formating

/r/IPython
https://redd.it/8blldv
Tips on understanding Django sessions.

So I've been learning and using Django for a while now. Recently I was in need of using Django's session framework but to be honest I still don't fully understand it. And when it comes to Django's documentation I find it a bit to technical for my understanding. Is there anyone that knows a good source that explains using the session framework?

/r/djangolearning
https://redd.it/8bl3kr
How to create widgets within same row?

I'm trying to a column of different widgets but can't seem to find anything like it.

For clarity: https://imgur.com/a/7L1q0

/r/IPython
https://redd.it/8blu3z
How to undo migration after pip uninstalling 3rd party package

So I pip installed the django-axes package today. Migrated the migrations that came with it. Then it turned out that the package installed was missing the needed "backends.py" file for some reason. I copied the one on the git repo and dropped it into the installed package folder and it gave me another error.

So I pip uninstalled the whole thing. But looking into my PostgreSQL database, the two tables (axes_accessattempt and axes_accesslog) created by the django-axes migrations are still there.

How is this type of situation handled normally? Just run a SQL command to drop those 2 tables manually? I already have some data in the database, so I don't want to mess it up inadvertently further.

Also, is it normal for a pip install package to be missing vital files?

Thanks.

/r/django
https://redd.it/8bpekc
Python's Pandas in C++

I have implemented a C++ library with similar interface and functionality to Pandas at https://github.com/hosseinmoein/DataFrame. It still lacks a lot of functionalities which I will add gradually. I appreciates your constructive criticisms and suggestions.

/r/Python
https://redd.it/8bq5js
[AF] Handling nested dictionaries with standard python requests library

Hey /r/flask,

I recently got my first [Flask webapp](http://www.asosquery.com/) hosted, and built a relatively simple API around it. It's driven by a very large database full of open meteorological surface observations (more info on the `/about` page), and right now I'm able to query the API with the following sample code (a separate script written for testing):

import requests
import json

r = requests.get('http://www.asosquery.com/api/v1/stations?state=PA&lat={"gt": 39, "lt": 50}')
content = json.loads(r)

This returns JSON-encoded information regarding all [ASOS stations](http://www.nws.noaa.gov/ost/asostech.html) with a latitude greater than 39.00 N and less than 50.00 N. A SQLAlchemy query of the MySQL database is dynamically generated based on the arguments in the `GET` request.

However, I would like to be able to do something like this, following an example on the [requests package documentation](http://docs.python-requests.org/en/master/user/quickstart/#passing-parameters-in-urls):

import requests # standard python requests package
import json

payload = {
'state': 'PA',
'lat': {
'gt': 39,
'lt': 50
}
}

r = requests.get('http://www.asosquery.com/api/v1/stations', params=payload)
content = json.loads(r)

This exercise fails each time. In the Flask route `/api/v1/stations`, I've tried printing the request made to the server like this:

from flask import request

@app.route('/api/v1/stations', methods=['GET'])
def get_stations():
print(request)
print(request.args)
# -- do the query stuff here -- #
return jsonify(query_results)

But, the output (prior to a raised error) is not as I expected it to be:

# print(request) prints:
<Request 'http://localhost:5000/api/v1/stations?lat=lt&lat=gt&state=PA' [GET]>
# print(request.args) prints:
ImmutableMultiDict([('lat', 'lt'), ('lat', 'gt'), ('state', 'PA')])

I've tried encoding the `payload` as JSON with the following:

r = requests.get('http://www.asosquery.com/api/v1/stations', params=json.dumps(payload), headers={'Content-Type': 'application/json'})

but execution of that code prints the following in from the flask route:

# print(request) prints:
<Request 'http://localhost:5000/api/v1/stations?{"state": "PA", "lat": {"gt": 39, "lt": 50}}' [GET]>
# print(request.args) prints:
ImmutableMultiDict([('{"state": "PA", "lat": {"gt": 39, "lt": 50}}', '')])

Here, I don't really understand why the `requests.args` is formatted like that... The information in the `key` is pretty much what I expect it to be, but the blank `value` is throwing me for a loop. I could probably handle that by just processing the information in the `key`, but that's going to require an extra level of complexity I'd like to be able to avoid.

Anybody know a good workaround? Am I handling the greater-than, less-than functionality in the best way possible?

Thank you in advance to all who offer some insight.

/r/flask
https://redd.it/8bsh8h