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
SQLAlchemy - calculate a default value during instance creation

Hi all,


I'm creating the following table.
I would like to automatically populate the value for createdAt from the period DateTime + a time delta from duration in seconds. (I want to avoid doing this in my PGCRs instantiation).

So this would look like, outside the DB table:

createdAt = period + datetime.timedelta(seconds=duration)


Here is my model for reference:

class PGCRs(SurrogatePK, Model):
"""
A table to store a list of players PGCR's.
PGCR's are linked back to user via 1 to many relationship.
"""

tablename = "pgcrs"
instanceId = Column(db.Integer, nullable=False, default=666)
duration = Column(db.Integer, nullable=False, default=666)
period =

/r/flask
https://redd.it/lj94uh
How to embed a simple-prompt ipython?

How ca I pass the --simple-prompt argument in IPython.embed()?

If I add to my code

from IPython import embed ; embed()

This drops me into a standard ipython which causes issues for me, while a simple prompt version would work OK.

Thank you!

/r/IPython
https://redd.it/ljk9t1
Why you should use Django in 2021

Building a backend for a web application is tricky. It involves selecting a language that you are comfortable with and then picking a web framework built on top of that language to avoid writing things from scratch.

There are a ton of web frameworks out there, each designed to address specific needs. The Django web framework addresses all of those needs to a reasonable extent and hence it is preferred by companies like Spotify and Instagram.

## What is Django?

Fun fact: Django was named after the jazz guitarist *Django Reinhardt*.

Django is an open source web framework built on top of python. The primary purpose of Django is to enable super fast development of backend applications. 

A backend application is nothing but an interface to a database meant for reading the data models and presenting it to a user in a form that they understand. It is also responsible for creation of new entries in the database and updating existing data.

Why use a web framework?

If one has to do this from scratch here is what will happen. First you will realise that raw SQL queries would have to be written to manipulate the database and this stops scaling pretty quickly.

You might then resort to

/r/django
https://redd.it/ljgpqn
We made a tool to prevent merge conflicts before they even happen - GitHub app + VSCode extension, would love feedback from the Python community

Hi everyone, I’m Kiril and together with my co-founder we are building developer tools we wish existed.

Our og idea was building a new version control system (and we do have it bootstrapped), but now we are making tools that are easier to be plugged into an existing workflow.

We built two tools we heard from other devs might be cool:

​

A plugin for VSCode that detects in real time if your \_local\_ and even \_uncommitted\_ code conflicts with other on your team. Check it out here [http://getsturdy.com/](http://getsturdy.com/)

A Pull Request bot that will write a comment in the PR if it conflicts with other PRs https://getsturdy.com/changelog

The thinking there is by giving early heads up about conflicts, people can make more informed decisions (eg. pull latest code, work on another file, coordinate with colleagues etc.)

The tool installs as a GitHub app and similar to a CI tool it requests access to code to do it’s job (responding to web hooks and continuously making checks).

The VSCode plugin is open source https://github.com/sturdy-dev/sturdy-vscode and we would like to have the backend open source too, as soon as we clean up the code.

I would be super thankful for any feedback the community might

/r/Python
https://redd.it/ljlj8e
Is sqlalchemy pagination work for 100k rows?

I have a sql returning about 100k rows.
I want to use bootstrap table with sorting to display all the rows.
Is sqlalchemy able to do so ?

If not,What is the optimal number of rows?

/r/flask
https://redd.it/ljq7kq
QR code that is also a quine

I recently found out you can generate QR codes with Python, so I made a quine out of it. The source code is located here.

/r/Python
https://redd.it/ljv23e
Best strategy for building out user auth and user profile?

Hi all,

I’m creating an 'Instagram style' photo blog, the content of which will only be accessible to authenticated users. Of course, this involves building user accounts.

To date, I’ve solely been using my user model, which extends AbstractBaseUser, for auth and profile details. So far, this has been fine. However, I'm now beginning to add more and more profile-related attributes and I'm considering whether it might be worth it to split the models up, perhaps into separate apps and transfer all non-auth/non-account attributes currently on the user model (eg. profile name, profile pic, followers etc) over to the profile model. Therefore keeping the user model solely for authentication (and likely authorisation) purposes.

Essentially, then, I’m questioning the pros and cons of strategies. I’ve had a good read online (found Vitor Freitas' write up particularly helpful - link for anyone else with a similar question) and it seems like the best option is to create a Profile model with OneToOneField to the custom auth model.

However, before I go and break up my models, does anyone with experience have any related advice? Is creating separate models for auth and profile the standard approach? Does this approach make scaling easier in the long run?

A final

/r/djangolearning
https://redd.it/lk16iy
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code!

/r/Python
https://redd.it/lk0sdi
[D] Machine Learning - WAYR (What Are You Reading) - Week 106

This is a place to share machine learning research papers, journals, and articles that you're reading this week. If it relates to what you're researching, by all means elaborate and give us your insight, otherwise it could just be an interesting paper you've read.

Please try to provide some insight from your understanding and please don't post things which are present in wiki.

Preferably you should link the arxiv page (not the PDF, you can easily access the PDF from the summary page but not the other way around) or any other pertinent links.

Previous weeks :

|1-10|11-20|21-30|31-40|41-50|51-60|61-70|71-80|81-90|91-100|101-110|
|----|-----|-----|-----|-----|-----|-----|-----|-----|------|-------|
|[Week 1](https://www.reddit.com/4qyjiq)|[Week 11](https://www.reddit.com/57xw56)|[Week 21](https://www.reddit.com/60ildf)|[Week 31](https://www.reddit.com/6s0k1u)|[Week 41](https://www.reddit.com/7tn2ax)|[Week 51](https://reddit.com/9s9el5)|[Week 61](https://reddit.com/bfsx4z)|[Week 71](https://reddit.com/d7vno3)|[Week 81](https://reddit.com/f1f0iq)|[Week 91](https://reddit.com/hlt38o)|[Week 101](https://reddit.com/k81ywb)|||||||||
|[Week 2](https://www.reddit.com/4s2xqm)|[Week 12](https://www.reddit.com/5acb1t)|[Week 22](https://www.reddit.com/64jwde)|[Week 32](https://www.reddit.com/72ab5y)|[Week 42](https://www.reddit.com/7wvjfk)|[Week 52](https://reddit.com/a4opot)|[Week 62](https://reddit.com/bl29ov)|[Week 72](https://reddit.com/de8h48)|[Week 82](https://reddit.com/f8fs6z)|[Week 92](https://reddit.com/hu6zq9)|[Week 102](https://reddit.com/kh27nx)||
|[Week 3](https://www.reddit.com/4t7mqm)|[Week 13](https://www.reddit.com/5cwfb6)|[Week 23](https://www.reddit.com/674331)|[Week 33](https://www.reddit.com/75405d)|[Week 43](https://www.reddit.com/807ex4)|[Week 53](https://reddit.com/a8yaro)|[Week 63](https://reddit.com/bqlb3v)|[Week 73](https://reddit.com/dkox1s)|[Week 83](https://reddit.com/ffi41b)|[Week 93](https://reddit.com/iaz892)|[Week 103](https://reddit.com/kpsxtc)||
|[Week 4](https://www.reddit.com/4ub2kw)|[Week 14](https://www.reddit.com/5fc5mh)|[Week 24](https://www.reddit.com/68hhhb)|[Week 34](https://www.reddit.com/782js9)|[Week 44](https://reddit.com/8aluhs)|[Week 54](https://reddit.com/ad9ssz)|[Week 64](https://reddit.com/bw1jm7)|[Week 74](https://reddit.com/dr6nca)|[Week 84](https://reddit.com/fn62r1)|[Week 94](https://reddit.com/ijjcep)|[Week 104](https://reddit.com/kzevku)||
|[Week 5](https://www.reddit.com/4xomf7)|[Week 15](https://www.reddit.com/5hy4ur)|[Week 25](https://www.reddit.com/69teiz)|[Week 35](https://www.reddit.com/7b0av0)|[Week 45](https://reddit.com/8tnnez)|[Week 55](https://reddit.com/ai29gi)|[Week 65](https://reddit.com/c7itkk)|[Week 75](https://reddit.com/dxshkg)|[Week 85](https://reddit.com/fvk7j6)|[Week 95](https://reddit.com/is5hj9)|[Week 105](https://reddit.com/l9lvgs)||
|[Week 6](https://www.reddit.com/4zcyvk)|[Week 16](https://www.reddit.com/5kd6vd)|[Week 26](https://www.reddit.com/6d7nb1)|[Week 36](https://www.reddit.com/7e3fx6)|[Week 46](https://reddit.com/8x48oj)|[Week 56](https://reddit.com/ap8ctk)|[Week 66](https://reddit.com/cd7gko)|[Week 76](https://reddit.com/e4nmyk)|[Week 86](https://reddit.com/g4eavg)|[Week 96](https://reddit.com/j0xr24)||
|[Week 7](https://www.reddit.com/52t6mo)|[Week 17](https://www.reddit.com/5ob7dx)|[Week 27](https://www.reddit.com/6gngwc)|[Week 37](https://www.reddit.com/7hcc2c)|[Week 47](https://reddit.com/910jmh)|[Week 57](https://reddit.com/auci7c)|[Week 67](https://reddit.com/cj0kyc)|[Week 77](https://reddit.com/eb4lxk)|[Week 87](https://reddit.com/gcx3uf)|[Week 97](https://reddit.com/j9cbfs)||
|[Week 8](https://www.reddit.com/53heol)|[Week 18](https://www.reddit.com/5r14yd)|[Week 28](https://www.reddit.com/6jgdva)|[Week 38](https://www.reddit.com/7kgcqr)|[Week 48](https://reddit.com/94up0g)|[Week 58](https://reddit.com/azjoht)|[Week 68](https://reddit.com/cp1jex)|[Week 78](https://reddit.com/ehbfst)|[Week 88](https://reddit.com/glm6sv)|[Week 98](https://reddit.com/jhzz9v)||
|[Week
Deploying tensorflow linear classifier pretrained model to web server using Flask

Hi,

I'm having an issue with deployment of a Flask app that uses a tensorflow model to make predictions on data provided by a user.

The code works fine in a local environment, but fails silently when pushed to my web server.

The code I'm using is functionally the same as the code in this tutorial: https://www.tensorflow.org/tutorials/estimator/linear

This is the output locally: https://gyazo.com/041dacfa584832f109cbf5b1fd09f0a8

edit: on the web server it simply can't load any pages. They seem to timeout - no internal server error or anything.


Which normally means a function can't be found.

​

It seems to be silently failing - I can't find a log in my ubuntu machine being useful to me.

/r/flask
https://redd.it/lk13ng
Deploying Flask app using Procfile and .env file with Postgres

I am trying to deploy my Flask app to a VPS installed with Dokku. I don't have much knowledge in regards to Docker deployment, but Dokku seems to pull it all together using Herokuish. However, I am having some difficulties pushing my app to my Dokku instance.

My directory/file structure looks a little something like this:

.env
run.py
Procfile
requirements.txt
config.py
spotifyproject
init.py

└───api
│ │
spotifyhandler.py
│ │ spotifyclient.py
│ │ spotifyauth.py

└───user (user login/signup routes & db handling)

└───models (user & like models)

└───profile (routes for displaying content from /api)

Then in some of the files:

# Procfile
web: gunicorn spotifyproject:run

# spotify
project/init.py


/r/flask
https://redd.it/ljz3u1
For any pandas users, I just finished adding a full UI for merging & stacking dataframes to free pandas visualizer

​

Merging & Stacking in D-Tale 1.35.0

I recently added the ability to merge & stack (vertically concatenate) dataframes in my open-source Pandas Dataframe Visualizer, D-Tale

Feel free to play with the demo here

This recording is a demo of the new "Merge & Stack" feature of D-Tale. You'll see the following:

Editing of parameters to either a pandas merge or stack (vertical concatenation) of dataframes (and viewing examples from the pandas documentation)
Selection of dataframes & viewing the data within them after selection
Uploading of additional dataframes from an excel file
Viewing python code snippets & resulting data from a merge or stack

D-Tale is available on both pypi & conda:

`pip install dtale`
conda install dtale -c conda-forge

Please let me know if theres anything else I can do to make this functionality better and support open-source by tossing your star on the repo. Thanks!

/r/Python
https://redd.it/lk69l1
Should I use Django for this project?

Hi all. I'm decent at python, decent at html (neither one is my job, programming is a hobby and eventually maybe more). I keep using programming to build things I actually use. Here's my website I plan to make, I'd like to get a quick "Yes, do this in Django" or "oh god no, thats not what this is for, go use XYZ".

​

I'm teaching a class for 6 months, all online. I want to build a website for the class. My initial thought is

​

Google to login (nearly everyone has this). can't get past the landing page without being logged in. I'm being paid separately(not by each person), so if extra people join it doesn't really matter.

Landing page with a bit of "this is what is here"

each week of the class has its own page, like a blog post.

each post has

\- required reading

\- link to the zoom meeting. This would go dark after class is done for the week

\- link to the YouTube recording. This would be added after the video is uploaded.

\- An email the instructor (me) form.

\- Link to the practice test for that chapter.

\--- I need a testing

/r/djangolearning
https://redd.it/lk6hpq