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 to create choices based on file contents

I have a json object, where I would like each of the entries in the json file to be options choosable by the user, such that the user can select multiple options and those choices can be saved somewhere, can someone point me in the right direction?

Thanks

/r/django
https://redd.it/av2kjc
Build a Data Analysis Library from Scratch in Python

Hey All,

[Build a Data Analysis Library from Scratch in Python](https://www.youtube.com/playlist?list=PLVyhfExBT1XDTu-oocI3ttl_OPhulAJOp) is a course I've developed to help those looking for a long, comprehensive project that will teach advanced Python and basic software development. It seems that there is a lack of these types of projects for those who possess the fundamentals of Python, but haven't put together a complete project.

The end result is a library called Pandas Cub which is built to mimic the pandas library. There are 40 steps with nearly 100 pre-written unit tests that must be passed in order to complete the project. The project not only teaches advanced Python but environment setup, test-driven development, and developing code outside of a Jupyter Notebook. The project can also be [found on GitHub](https://github.com/tdpetrou/pandas_cub).

I hope its useful and if you have critical feedback please let me know.

/r/Python
https://redd.it/av0awc
Geodjango OSMWidget coordinates are wrong.

I'm using an OSMWidget for my PointField(). I had already set my initial coordinates to 120, 14 but when I retrieve the values from my widget I get values around 13468873 and 1639089.

Also I am not saving any (spatial?) objects to my db because I want to stick to one db but I do need the coordinates as Decimal values to measure distances in the future.

Is there a way to convert widget values into standard coordinates?

/r/django
https://redd.it/av86my
[Django + javascript] Sending Post (submit) after given time

Hello r/django \- I am very new to django and javascript so I would appreciate any comments!

I am building a website where users can take math exams for free. The way my website works is very simple - a user writes down an answer (or chooses from a radio button) and clicks on the next button for the next question. Clicking on the next button also sends a POST request to my django views where I save the user's answer in my database.

Everything was working fine until I added a timer in javascript (when the exam time is over, the user is directed to the home page). Since the 'next' button was never clicked, the answer to the last question the user was working on is not saved. I would like to figure out a way to have my javascript code send a POST request to my django views when the timer is over.

​

I would appreciate any help. Thank you!

/r/django
https://redd.it/avb7r1
Intercooler.js vs Stimulus.js vs Vue.js in Django

I'm mainly working on websites that have **little to to medium** interactions with the user, and i'm looking for ways to add JS to my sites without complicating things. SPA are out of the question since the sites needs to be SEO friendly. When i say interactions i mean stuff like upvote / downvote events, adding interactive tables and charts, popups with dynamic content and stuff like that.

​

* **Intercooler.js** \- Seems like the best candidate for Django at the moment but it feels incomplete.
* **Stimulus.js** \- Also seems nice, but it lacks a proper documentation with good examples. It also looks like its mostly meant for Ruby on Rails (?).
* **Vue.js** \- Is really clean and simple, but it seems like including it in Django templates can get messy for larger projects.
* **Nuxt.js** \- Is probably the best solution overall but it has a full separation of backed and fronted. This one requires a full dedication because i need to master both vue.js and nuxt.js to properly use it.

​

Besides pure JS, what do you guys use for this kind of projects?

​

​

/r/django
https://redd.it/avbv0p
Data getting reset on a singleton model

So I'm using a singleton class to save settings like google analytics id, keys related to third party services etc and other data that are static but may need to be updated via frontend.

But apparently, the data is getting reset almost every 2 weeks.

This is my mode

from django.db import models
from django.core.cache import cache

class SingletonModel(models.Model):

class Meta:
abstract = True

def set_cache(self):
cache.set(self.__class__.__name__, self)

def save(self, *args, **kwargs):
self.pk = 1
super(SingletonModel, self).save(*args, **kwargs)
self.set_cache()

def delete(self, *args, **kwargs):
pass

@classmethod
def load(cls):


/r/django
https://redd.it/avazuz
Getting the url from an incoming request?

There are two Flask services, each running on a different port on localhost. Service A is a routing service that receives commands from a server and routes them to the appropriate instance of the Service B. There will eventually be hundreds of instances of Service B, each in its own docker container, so when it starts up, I want it to let Service A know where it is running.

I've created an endpoint in service A '/register' that accepts a post request, but I can't figure out how to get the host and port number dynamically.

request.remote_addr just gives me '127.0.0.1'

request.environ.get('REMOTE_PORT') returns 60702, which is NOT the port I'm running it on (9999).

Alternatively, is there a way in a Flask app to dynamically retrieve the URL and Port that the app itself is running on? Because then Service B could just put its own url in the request json.

Sorry if I wasn't clear enough, but I'm beating my head against the wall here

/r/flask
https://redd.it/av51ig
This media is not supported in your browser
VIEW IN TELEGRAM
gitir - Download a single directory/folder from a GitHub repo

/r/Python
https://redd.it/avbaow
[P] Open source machine learning platform for developers

Hi all,

We recently open sourced the first version of our machine learning platform. My friend and I started getting into machine learning engineering a little over a year ago, and we were frustrated by how hard it was to get a simple machine learning application up and running on cloud infrastructure. We felt like we were spending way too much time configuring data pipelines, managing dependencies, and solving common problems like applying the same data transformations at training and inference time. Our project automates a lot of the underlying infrastructure work to help developers avoid dealing with the same challenges we had to.

We’d love to hear your feedback!

[https://github.com/cortexlabs/cortex](https://github.com/cortexlabs/cortex)

/r/MachineLearning
https://redd.it/av7o14
Jinja vs Flask Files - Which is best?

I'm still very new to Flask and Jinja.


If I use an API that returns a JSON object that I want to display via render\_template; is it best to pass the entire JSON object to the template and handle it in Jinja, or should I only pass the parts of the JSON object to Jinja.


Or does it not matter? Is there no real benefit to either approach?

/r/flask
https://redd.it/av8lv8
[P] Decision Tree Regressors for stock price data

Decided to play a bit with scikit-learn and adapted a previous project. Turns out decision tree regressor recalibrated on a rolling basis works pretty well (systematic) out-of-sample (on a return perspective) for stock price data

Suggestions / opinions anyone? Returns about 10%/year during the last 19 years

It's open-source - [https://github.com/LongOnly/Quantitative-Notebooks/blob/master/DecisionTreeRegression.ipynb](https://github.com/LongOnly/Quantitative-Notebooks/blob/master/DecisionTreeRegression.ipynb)

(NBViewer for you mobile users - [https://nbviewer.jupyter.org/github/LongOnly/Quantitative-Notebooks/blob/master/DecisionTreeRegression.ipynb](https://nbviewer.jupyter.org/github/LongOnly/Quantitative-Notebooks/blob/master/DecisionTreeRegression.ipynb))

/r/MachineLearning
https://redd.it/avefa3
This media is not supported in your browser
VIEW IN TELEGRAM
Django Jet admin interface 2.0 is now compatible with any stack with SQL database

/r/Python
https://redd.it/avgmiq
Tip on speeding up subqueries

I'm creating a site that works a lot like Reddit in all intents and purposes, and I've gotten my queries pretty well tuned in with prefetch_related and select_related for getting lists of posts and comments. The one thing I can't seem to speed up is setting up a users vote on a post or if he has saved or not ( like on reddits front page, it shows a red arrow if you've already voted).

In my app, I have the field 'user_vote' and 'user_saved' as Serializer method fields. This requires a query for each post (25 paginated) like post.votes.filter(pk=user.id). This brings the response into to the 3 second range.

I've toyed with caching the votes, but this still means the first time loading the page incurs the initial db lookup, and the caching speedup will only work the next time the user loads the same posts or posts (assuming that will even happen).

Any suggestions? Thanks.

/r/django
https://redd.it/avfraz
How would you convince (higher) management to invest in Python skills in 2019?

hi, i'm tasked to provide a 45 min presentation next week on the subject: **why should our company invest in Python capabilities these days?**

Target audience is senior management of a global technical advisory firm, without any Python skills at all, who need to be convinced to invest time and $$ for upskilling its engineers. I was thinking about presenting some stats and facts of Python adoption rate over the last years and how python is substituting incumbent analytics tools like Matlab. I think, funny / anecdotical facts, pictures or even short videos work best to convey this message.

* What are, in your opinion, the top three arguments to highlight?
* Which resources would recommend to refer to ? Like studies, YouTube video's, slides, pictures....

Appreciate your input!

​

https://i.redd.it/sdgymxa0z2j21.jpg

​

/r/Python
https://redd.it/avbnna
Most frequently mentioned words in the top 1000 StackOverflow questions tagged #Python [x-post /r/DataArt]

/r/flask
https://redd.it/avh5ri
[P] PyTorch under the hood

I made available some slides about a presentation from PyData Montreal called **"PyTorch under the hood"**, for those who are interested in knowing more about how PyTorch works, here is the link to the slide deck:

https://speakerdeck.com/perone/pytorch-under-the-hood


/r/MachineLearning
https://redd.it/avfoso
My first Python turtle race game built on incredible app on android - Pydroid3

/r/Python
https://redd.it/avk9va