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 does the upvote/downvote number on Reddit/Steck Uberflow change instantly? Is it fake clientside code?

If you upvote/downvote any post on Steck Uberflow or Reddit, you'll see the number change instantly. This doesn't seem feasible or sensible. Is it just frontend code that add or minus 1 automatically when you click the upvote/downvote button?

EDIT: I just realized this isn't a Django-related question. Sorry about that.

/r/django
https://redd.it/7dpuub
Paying for help with a Django issue?

Hey all,

I'm a Django novice/intermediate user - I have already launched a web app and I'm working on a second, slightly more complex one.

I've hit a bit of a snag with a particular issue and can't seem to find any solutions on the internet as it's very specific. I'm trying to juggle the functionality of three different django plugins and I fear the scope of what I'm trying to do is slightly above my current competencies.

Because this particular feature I want to implement is something I care for quite dearly I'm prepared to use some of my personal savings to pay someone to help me implement it, or at least to explain how I could go about implementing it myself.

Does anyone know of any good places where I could search for such a person and how much an hour or two of their time would cost?

Thanks

**EDIT** ###More details below

So basically I've got [django-filter](https://github.com/carltongibson/django-filter) set up and working correctly to filter my Product model based on various fields. The user ticks a checkbox or selects something from a dropdown and hits "Submit" on the form and everything filters/sorts correctly.

The issue I'm having is that I'd like to use AJAX so that there is no need to submit the form. The actual filtering/sorting logic is handled by `django-filter` and apparently I'd need to create an API endpoint with `django-rest-framework` so that AJAX can interact with that data.

To make matters more complicated, I'm using `django-wagtail` as a CMS which means I don't have any `views.py` or `urls.py` to work with. The only way to submit data other than HTML is by [overriding the serve() method on the actual page model](http://docs.wagtail.io/en/v1.13.1/reference/pages/model_recipes.html#overriding-the-serve-method).

I more or less know *what* needs to be done but I'm definitely lacking the skills/knowledge/experience to know exactly how to get this to work, and I can't afford to waste a week tinkering around to get it to work...

/r/django
https://redd.it/7dntaj
Will neural network work as articles classification on my website?

I have jobs aggregator which parses offers.
Jobs come from different sources and sometimes there are not relevant posts which I moderate by myself.
Right now I have more than 1000 moderated posts in the database. Can I somehow add automatic filter with neural networks or machine learning? Is there any tutorial on that topic?

I found what I need, here is a nltk guide. https://www.youtube.com/watch?v=FLZvOKSCkxY&list=PLQVvvaa0QuDf2JswnfiGkliBInZnIC4HL&index=1

/r/django
https://redd.it/7dns4f
[D] Low entry barrier is destroying deep learning reputation

For a long time now, I notice many self-proclaimed deep learning experts, wizards, and what-not. With no educational or research background in either machine or deep learning, they think they have obtained expert knowledge in deep learning just by installing tensorflow or keras and running some code from github. Then, they immediately add "deep learning expert" to their name and write tutorial blog posts or even have the nerve to offer courses and write books. Not long ago, I reviewed a book proposal about deep reinforcement learning by some two "hackers", who had no education and no work experience in either machine, deep or deep reinforcement learning, yet they felt they are already experts in it that they just had to write a book about it...

Why this bothers me?

It destroys the reputation of deep learning. Most companies have no clue how to recognize these so called "experts". The job interviewers don't have the required deep learning expertise to properly evaluate candidates and NIPS, ICML, et al. mean nothing to them. So they end up hiring the "experts". Then when inevitably their "deep learning" solutions fail, they conclude that deep learning is not working and it's nothing but a hype. As more and more companies experience this, more and more companies become skeptical about deep learning.
Already, people from the industry half-jokingly refer to AI as artificially inflated.

What do you think? Do you agree or not?
If you agree, what should we do?
Start, a deep learning hiring agency? :)


Update: When I say low entry barrier I don't mean access to education. I mean the accessibility of the material, i.e. you don't need to know much about machine or deep learning to apply it with success to well known problems. However, you do need the knowledge and the research experience to apply it on novel problems.

/r/MachineLearning
https://redd.it/7dqtby
Flask-Login issues.

I am using the Flask-Login extension( https://github.com/maxcountryman/flask-login)

I've followed the documentation pretty closely but each time I try to go to a 'login required' route it returns me to my login page even after a successful login.

I've printed my "next" variable and it always returns "login". Any suggestions?

I'm not using a DB just a list of faux users for the time being.
Hoping to eventually authenticate with Active directory, but need to get some basics of Flask-Login down first.

/r/flask
https://redd.it/7dsuxy
[AF] Generating and exporting a CSV for client side download

I’ve built a simple Flask application with number of screens for adding & editing data stored in a SQLite database. Additionally, I have a basic reporting page that pulls data from the database and displays the results in a table.

I’d like to allow the client to hit a button above the report table that downloads a CSV file containing the same data stored in the table.

I have successfully been able to create a csv file containing the correct data, but the csv file is saved to a local server directory making it inaccessible to anyone without sever access.

Are there any modules or configurations in Flask (or in python3 generally) that can allow me to achieve this goal of getting the data from the database, to a csv, to the client browser? If possible, I do not want to have to store the generated csv server side at all.

/r/flask
https://redd.it/7cz8eb
Safety precautions when running flask locally?

I have the following code running on my Raspberry Pi which I'm using as to WOL my PC, from my phone.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
'WOL Code here'
return 'not a post request'

if __name__ == '__main__':
app.run(host='0.0.0.0', port=3000)

Basically I just open up the webpage from my phone when I'm on my home network and it runs, super simple. Since this is running on my local network (so technically any device which is connected to my wifi could trigger this) are there any security precautions I need to take? I know the docs say that **"Flask's built-in server is not suitable for production"** but would that include such a simple app like this? Am I better off deploying/running it a different way? I've no plans to use this outside of my local network at the moment, if that makes any difference.

/r/flask
https://redd.it/7dvbea
Open-sourced a library that converts a Shapefile, GeoJSON, or CSV to an equal-area hexgrid cartogram. Suggestions and criticism appreciated.

I just open-source a library that outputs an equal area hexgrid SVG, given a shapefile/GeoJSON/CSV - https://github.com/LokiTechnologies/equalareacartogram. [As shown in this image](https://i.imgur.com/Da6colB.jpg), it outputs the map on the right given the map on the left as an input.

This is my first attempt at open-sourcing something, and this library is likely to contain several errors and bad practices. Would appreciate critiques and suggestions for improvement!

/r/Python
https://redd.it/7ds41t
[AF] How to render a template from a helper function?

Quick question, I need to check the existence of an object in the database in a lot of app routes, so I figured I'd just call a function which checks the said existence and returns an error template if it isn't found. However, when going to my site, 'error.html' is not rendered at all even though the bool is True. What am I missing?

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
foo()
render_template('succes.html')

def foo():
if some_bool_resulting_from_a_check:
return render_template('error.html')


/r/flask
https://redd.it/7cyion
What would be a standard modern python workflow?

I am working on linux, mainly using python for scripting and machine learning.

I am wondering if there is a standard workflow for python developers as of 2017.

Among others are these considered standard/widely used, why, and how?

* Virtual Environments / Virtual Environments Wrappers
* Alternative Interpreters / Notebooks (like ipython/jupyter)
* conda package manager and environments
* Version control
* Others...

What are you guys using ?

PS: Just found [this example](http://tdhopper.com.s3-website-us-east-1.amazonaws.com/conda/). Wondering if it is still up to date..

/r/Python
https://redd.it/7dqqu0
Is it against best practice to have multiple stylesheets?

Currently have 7 routes in my application and for each template I am inhereting a base layout and then importing a stylesheet unique to that template. Would it be a better practice to condense those style sheets into one style.css file? Or is it acceptable to use multiple?

The reason I have multiple is because some class names are identical with different attributes for each template.

/r/flask
https://redd.it/7cw8le
How to access custom setting from within main?

I am writing up a project with a file that contains some helpful functions to be used in the project. Some of these functions require access to a setting (API_KEY) that I put in `settings.py`. When I try to access this setting, I always get the following error:

AttributeError: module 'django.conf.global_settings' has no attribute 'API_KEY'

I *do* have access to *global* settings, but not the project-specific settings. E.g., in my project, I have DEBUG set to `True` and when I enter `settings.DEBUG` I am getting back `False`.

Here's the code I used to try to access it from within my file that is in the app folder (the project is called X and this is in X/Y/utils.py, where Y is the app name):


from django.conf import settings

if __name__ == "__main__":
import django
if not settings.configured:
settings.configure()
django.setup()
print(settings.API_KEY)

Note the above was written partly with the help of SO:
https://stackoverflow.com/questions/7867797/how-do-i-reference-a-django-settings-variable-in-my-models-py
https://stackoverflow.com/questions/32063881/django-python-manage-py-runserver-runtimeerror-settings-already-configured


/r/django
https://redd.it/7dye6a
[P] Fun Project: MSpaint to Terrain Map with GAN

I tried a fun little project to explore some of the possibilities of GANs and the results came out pretty good so I figured I'd share. The goal was to create a network which can take extremely simple images composed of various color regions (where each color corresponds to a particular type of terrain) and generate a realistic looking terrain map. The inputs being the sort of image an average human with no artistic ability could reasonably sketch out in MSpaint.

The GAN is based on AffineLayer's "pix2pix" code with a variety of changes. Primarily I increased the image size to 512x512 pixels and wrote completely new network structures. The generator is composed of an encoder/decoder pair which are mirrored 25 layer ResNets with skip connections between them. The generator loss was skewed strongly toward fooling the discrimintor to emphasize creating completely new terrain features rather than recreating the original image.

I used a terrain map of the entire Earth and randomly sampled 512x512 crops to generate my ground truth set. To create the seed images, these crops were quantized to a color palette of 5 colors and successive mode filters were applied to simplify the features. Each of the five colors corresponded with a different terrain type (blue - water, grey - mountains, green - forest/jungle, yellow - grassland/desert, brown - hills/badlands). In total, about 1300 image pairs were created that spanned the entire globe. The network was trained on these pairs for about 450 epochs (more or less a full day on a gtx1070) before it reached a point that I was happy with the results.

Now for the fun part: pictures. I've posted several image sets below. Each set is based on a single seed image which I drew in MSpaint with the various color regions recolored in different ways to show how the generator adapts the same image structure with different colorings. Notice how the network is able to invent features like lakes and rivers and islands. It also learned to handle the features of color regions and their transitions differently based on overall context.

https://imgur.com/a/mCJrA

https://imgur.com/a/OgY7k

https://imgur.com/a/hROZJ

https://imgur.com/a/nIYkp

Let me know if you have any questions.

/r/MachineLearning
https://redd.it/7dwj1q
Ordering of signals with m2m_changed

Hi everyone,

I've got an issue with my custom signals interacting with m2m_changed. It's frustrating because I've found little documentation on it.

I have a m2m_changed signal which triggers on any change on a specific model. I also have my own signal which should send an e-mail but unfortunately it triggers before the many-to-many field has been updated and thus giving me the wrong info to send in an e-mail.

I know it's not a good practice to rely on signal ordering but I'd really appreciate if you had any advice on this.

/r/django
https://redd.it/7dtjgf
What is the best way to install Python 3.6 on Ubuntu 16.04.1?

What is the best and most compatible way to install Python 3.6.x on Ubuntu 16.04? Should I just grab the source and install to /usr/local?

/r/Python
https://redd.it/7e08sv
I am brand spanking new to Python. Would like to know some of the best places to hang out online to get insight and just read about general things from developers. That is the best way to learn I’ve seen.



/r/Python
https://redd.it/7e0646
I want to submit code for others to use, where/how?

I am studying numpy and the function genfromtxt only works with ASCII which sucks for our utf-8 era, IMHO. So I wrote my version of the function compatible with utf-8 (not as cool as the original one but does the trick) how do I post it online for others to use and improve? I guess it should go in github, but how? Also how do I specify the version of Python and numpy there? Also my code is noob code so it could have crappy code. I tried to program it as good as I could but... You know, noobs...

/r/Python
https://redd.it/7e17g2