Useful Python tricks
So, I saw a while ago somebody posted a thread asking for ways that people have used python to automate their lives or just make it easier in general. Most of the replies as can be expected involved making tasks at work easier etc, which don't really apply to someone like me who doesn't have an office job or anything similar.
So, what are some cool uses for python for maybe younger people or just people without office jobs in general? It would be fun to find a project to work on or something that I can use python for in my daily life but as far as I'm aware i can't really think of anything that I need automated.
Thanks!
/r/Python
https://redd.it/awb9v5
So, I saw a while ago somebody posted a thread asking for ways that people have used python to automate their lives or just make it easier in general. Most of the replies as can be expected involved making tasks at work easier etc, which don't really apply to someone like me who doesn't have an office job or anything similar.
So, what are some cool uses for python for maybe younger people or just people without office jobs in general? It would be fun to find a project to work on or something that I can use python for in my daily life but as far as I'm aware i can't really think of anything that I need automated.
Thanks!
/r/Python
https://redd.it/awb9v5
reddit
r/Python - Useful Python tricks
0 votes and 2 comments so far on Reddit
pydis - A redis clone in Python 3 to disprove some falsehoods about performance
https://github.com/boramalper/pydis
/r/Python
https://redd.it/awav6k
https://github.com/boramalper/pydis
/r/Python
https://redd.it/awav6k
GitHub
GitHub - boramalper/pydis: A redis clone in Python 3 to disprove some falsehoods about performance.
A redis clone in Python 3 to disprove some falsehoods about performance. - boramalper/pydis
Pipenv and Poetry are both in the weeds - what can we do to help?
I discovered that neither project has merged a PR in roughly a month. Meanwhile, PR's and Issues are flowing in much faster than they're getting resolved. Intrigued by this, I checked dependency/package managers in other languages, and didn't see the same problems (Python/Conda, Rust/Cargo, Ruby/Bundler, Node/npm).
I think this is a big issue. It doesn't just mean that bugs aren't getting fixed, but that they're not accepting help from the community.
Is it a matter of the project owners needing to delegate more? I.e., one person, or a tiny group, is responsible for all decisions? Is there something that we, the stakeholders -- who aren't the maintainers -- can do to help?
\-----
Source: I used my opensource repocheck app to collect the data. E.g.:
* [Analysis: Pipenv](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fpypa%2Fpipenv) score: **1.6** out of 10
* [Analysis: Poetry](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fsdispater%2Fpoetry) score: **2.8** out of 10
* [Analysis: Conda](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fconda%2Fconda) score: 6.4 out of 10
* [Analysis: Ruby Bundler](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fbundler%2Fbundler) score: 7.0 out of 10
/r/Python
https://redd.it/awbr99
I discovered that neither project has merged a PR in roughly a month. Meanwhile, PR's and Issues are flowing in much faster than they're getting resolved. Intrigued by this, I checked dependency/package managers in other languages, and didn't see the same problems (Python/Conda, Rust/Cargo, Ruby/Bundler, Node/npm).
I think this is a big issue. It doesn't just mean that bugs aren't getting fixed, but that they're not accepting help from the community.
Is it a matter of the project owners needing to delegate more? I.e., one person, or a tiny group, is responsible for all decisions? Is there something that we, the stakeholders -- who aren't the maintainers -- can do to help?
\-----
Source: I used my opensource repocheck app to collect the data. E.g.:
* [Analysis: Pipenv](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fpypa%2Fpipenv) score: **1.6** out of 10
* [Analysis: Poetry](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fsdispater%2Fpoetry) score: **2.8** out of 10
* [Analysis: Conda](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fconda%2Fconda) score: 6.4 out of 10
* [Analysis: Ruby Bundler](https://repocheck.com/#https%3A%2F%2Fgithub.com%2Fbundler%2Fbundler) score: 7.0 out of 10
/r/Python
https://redd.it/awbr99
reddit
r/Python - Pipenv and Poetry are both in the weeds - what can we do to help?
14 votes and 4 comments so far on Reddit
What are some well designed PyQT apps?
I’m looking for some design inspiration / best practices for developing a PyQT app.
/r/Python
https://redd.it/awavhh
I’m looking for some design inspiration / best practices for developing a PyQT app.
/r/Python
https://redd.it/awavhh
reddit
r/Python - What are some well designed PyQT apps?
11 votes and 2 comments so far on Reddit
Your migrations are bad and you should feel bad
https://djrobstep.com/talks/your-migrations-are-bad-and-you-should-feel-bad
/r/django
https://redd.it/awcisv
https://djrobstep.com/talks/your-migrations-are-bad-and-you-should-feel-bad
/r/django
https://redd.it/awcisv
reddit
r/django - Your migrations are bad and you should feel bad
10 votes and 4 comments so far on Reddit
Django Object Persistence
Hey guys, so here's the issue I'm facing: I have a function that interpolates datasets via a scipy object. Generating these datasets takes ~7 seconds each time.
I don't have a database for the object and can't find a reliable way to just call the function one time and use its dicts repeatedly.
How can I store this object/keep persistence so that I can call it for a view function? Trying to lower the amount of time that it takes to run functions for users.
Thanks
/r/django
https://redd.it/awas61
Hey guys, so here's the issue I'm facing: I have a function that interpolates datasets via a scipy object. Generating these datasets takes ~7 seconds each time.
I don't have a database for the object and can't find a reliable way to just call the function one time and use its dicts repeatedly.
How can I store this object/keep persistence so that I can call it for a view function? Trying to lower the amount of time that it takes to run functions for users.
Thanks
/r/django
https://redd.it/awas61
reddit
r/django - Django Object Persistence
4 votes and 12 comments so far on Reddit
VPython : [Moon Orbiting Earth] : A Physics Demonstration
Here's a neat example I made of the Moon orbiting around the Earth! I originally wrote the code in a Jupyter notebook, but I converted it so that it could run in the Trinket IDE (i.e. GlowScript), which is far better at handling the 3D animations. Some of the physical assumptions made include:
* C.o.M. located at the center of the Earth
* Earth remains positionally fixed
* No G.R. induced orbital precession
​
Personally, I think the trinket version I converted from Jupyter is the cooler of the two. I added the ability to change the point of view of the camera in trinket during the orbit using keyboard commands:
​
s : system \\ e : earth \\ m : moon
​
Please find below the link for the trinket animation (DM for source code) and underneath the source code for a Jupyter notebook.
​
\---- Enjoy!! ----
​
<> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>
Trinket link: [https://ballinpicard.trinket.io/sites/moon-orbits-earth](https://ballinpicard.trinket.io/sites/moon-orbits-earth)
<> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>
Jupyter Notebook Code (put in one cell block
/r/IPython
https://redd.it/awcju5
Here's a neat example I made of the Moon orbiting around the Earth! I originally wrote the code in a Jupyter notebook, but I converted it so that it could run in the Trinket IDE (i.e. GlowScript), which is far better at handling the 3D animations. Some of the physical assumptions made include:
* C.o.M. located at the center of the Earth
* Earth remains positionally fixed
* No G.R. induced orbital precession
​
Personally, I think the trinket version I converted from Jupyter is the cooler of the two. I added the ability to change the point of view of the camera in trinket during the orbit using keyboard commands:
​
s : system \\ e : earth \\ m : moon
​
Please find below the link for the trinket animation (DM for source code) and underneath the source code for a Jupyter notebook.
​
\---- Enjoy!! ----
​
<> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>
Trinket link: [https://ballinpicard.trinket.io/sites/moon-orbits-earth](https://ballinpicard.trinket.io/sites/moon-orbits-earth)
<> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <> <>
Jupyter Notebook Code (put in one cell block
/r/IPython
https://redd.it/awcju5
trinket.io
Moon Orbits Earth by ballinpicard
Moon Orbits Earth by ballinpicard - powered by trinket.io
Is it better to use multiple ForeignKey in an intermediate table than using ManyToManyField?
I read some codes that choose to use multiple ForeignKey(s) and its own table instead of using ManyToManyField.
1. What do you think?
2. In what situation do you choose to use multiple ForeignKey(s) and its own table instead of ManyToManyField?
Thanks.
/r/django
https://redd.it/awgt3q
I read some codes that choose to use multiple ForeignKey(s) and its own table instead of using ManyToManyField.
1. What do you think?
2. In what situation do you choose to use multiple ForeignKey(s) and its own table instead of ManyToManyField?
Thanks.
/r/django
https://redd.it/awgt3q
reddit
r/django - Is it better to use multiple ForeignKey in an intermediate table than using ManyToManyField?
0 votes and 2 comments so far on Reddit
Best tutorial for machine learning?
I recently finished learning python and have been coding a lot in it lately. I wanted to do some machine learning and was wondering how to go about teaching myself how to do it. What are your suggestions? Should I even teach myself machine learning yet?
/r/Python
https://redd.it/awie4e
I recently finished learning python and have been coding a lot in it lately. I wanted to do some machine learning and was wondering how to go about teaching myself how to do it. What are your suggestions? Should I even teach myself machine learning yet?
/r/Python
https://redd.it/awie4e
reddit
r/Python - Best tutorial for machine learning?
0 votes and 8 comments so far on Reddit
Jupyter Kernel Gateway 2.2.0 and NB2KG 0.5.0 are available
https://groups.google.com/forum/#!topic/jupyter/i513ryU3rm8
/r/IPython
https://redd.it/awinbx
https://groups.google.com/forum/#!topic/jupyter/i513ryU3rm8
/r/IPython
https://redd.it/awinbx
I just built my portfolio in Django and NES.css
http://www.scheding.com.au/
/r/django
https://redd.it/awfzs7
http://www.scheding.com.au/
/r/django
https://redd.it/awfzs7
Post request not working with Inline formset
I'm trying to create an Inline formset where I can create an event and have all the bookings show within that event in the /admin.
I've managed to build it but I'm having issues getting the form data to show in the /admin. As if the form, in the front-end, isn't doing anything.
[See admin section here.](https://i.postimg.cc/L5bgnY7D/asdasdasdasd.png) Notice that no data is in "*C EVENT BOOKINGS*"
The console log says a POST request was submitted but no actual data is going into my model. No 4** or 5** errors.
See code below.
Worth noting that I had to add "default=None, null=False," in my C Event Form Model. Wouldn't let me migrate or submit to form otherwise. Not really sure what it does and is very likely part of the issue.
**Admin.py**
from django.contrib import admin
from .models import *
# Register your models here.
class CEventBookingsInline(admin.TabularInline):
model = CEventBookings
list_display = ('full_name', 'email', 'phone_number', 'adult_tickets', 'children_tickets')
class CEventAdmin(admin.ModelAdmin):
/r/djangolearning
https://redd.it/awhkbd
I'm trying to create an Inline formset where I can create an event and have all the bookings show within that event in the /admin.
I've managed to build it but I'm having issues getting the form data to show in the /admin. As if the form, in the front-end, isn't doing anything.
[See admin section here.](https://i.postimg.cc/L5bgnY7D/asdasdasdasd.png) Notice that no data is in "*C EVENT BOOKINGS*"
The console log says a POST request was submitted but no actual data is going into my model. No 4** or 5** errors.
See code below.
Worth noting that I had to add "default=None, null=False," in my C Event Form Model. Wouldn't let me migrate or submit to form otherwise. Not really sure what it does and is very likely part of the issue.
**Admin.py**
from django.contrib import admin
from .models import *
# Register your models here.
class CEventBookingsInline(admin.TabularInline):
model = CEventBookings
list_display = ('full_name', 'email', 'phone_number', 'adult_tickets', 'children_tickets')
class CEventAdmin(admin.ModelAdmin):
/r/djangolearning
https://redd.it/awhkbd
postimg.cc
asdasdasdasd — Postimage.org
The Guide to DeepLearning with Tensorflow and Keras - The Beginning
https://www.nintyzeros.com/2019/03/tensorflow-for-beginners-deeplearning.html
/r/Python
https://redd.it/awke51
https://www.nintyzeros.com/2019/03/tensorflow-for-beginners-deeplearning.html
/r/Python
https://redd.it/awke51
NintyZeros
NintyZeros: The Guide to DeepLearning with Tensorflow and Keras - The Beginning
Tensorflow tutorial for beginners. This post will help you start with deep learning using tensorflow and keras.
This post covers basic of tensorflow.
This post covers basic of tensorflow.
Can't generate new instance of a random hash unless restarting server
Hello,
​
While working on my email verification functionality on my website I noticed an odd bug.
​
In my User model, for when I register a new user I have the following line of code.
\`email\_verification\_hash = db.Column(db.String(40), default = hashlib.md5(os.urandom(32)).hexdigest())\`
​
In theory, for every new user a random hash should generate.
​
but what I noticed was no matter how many users I register, that hash remains the same for every new user, UNLESS I shut down the server restart it and then make a new user, then only after that will the next user have a unique hash different from the one before it; that is of course unless i make another user under that same server instance for which itll be the same as the one before.
​
For example:
Server Started: Server Instance A:
Register User Bob: Bob.hash = 54050
Register User Tom: Tom.hash = 54050
Register User Admin: Admin.hash = 54050
​
Server Turned Off, Restarted: Server Instance B
Register User Greg: Greg.hash = 10383
Register User Tom: Tom.hash = 10383
Register User Admin: Admin.hash = 10383
​
Server Turned Off, Restarted: Server Instance C
Register User Greg: Greg.hash = 5859860
Register User Tom: Tom.hash = 5859860
Register User Admin: Admin.hash = 5859860
​
​
All I want is for every new user to have a random and unique hash without
/r/flask
https://redd.it/awo87c
Hello,
​
While working on my email verification functionality on my website I noticed an odd bug.
​
In my User model, for when I register a new user I have the following line of code.
\`email\_verification\_hash = db.Column(db.String(40), default = hashlib.md5(os.urandom(32)).hexdigest())\`
​
In theory, for every new user a random hash should generate.
​
but what I noticed was no matter how many users I register, that hash remains the same for every new user, UNLESS I shut down the server restart it and then make a new user, then only after that will the next user have a unique hash different from the one before it; that is of course unless i make another user under that same server instance for which itll be the same as the one before.
​
For example:
Server Started: Server Instance A:
Register User Bob: Bob.hash = 54050
Register User Tom: Tom.hash = 54050
Register User Admin: Admin.hash = 54050
​
Server Turned Off, Restarted: Server Instance B
Register User Greg: Greg.hash = 10383
Register User Tom: Tom.hash = 10383
Register User Admin: Admin.hash = 10383
​
Server Turned Off, Restarted: Server Instance C
Register User Greg: Greg.hash = 5859860
Register User Tom: Tom.hash = 5859860
Register User Admin: Admin.hash = 5859860
​
​
All I want is for every new user to have a random and unique hash without
/r/flask
https://redd.it/awo87c
reddit
r/flask - Can't generate new instance of a random hash unless restarting server
0 votes and 1 comment so far on Reddit
Celery and Python 3.X. Has anyone had any success?
Hi all,
I'm building a new web app whilst following the (excellent) course on Flask web apps by Nick Janetakis. I'm following his tutorial but at the same time am building my own app, piece by piece as I learn.
In doing this I'm trying to use newer tools. For example, I want to use Python 3.x for future proofing the app, but I have an issue where Celery and Python 3.X won't want to work together.
Just checking in if anyone has had any success with getting a Python 3.x to work with any Celery versions or am I resigned to falling back to Python 2.x?
Thanks a tonne...
/r/Python
https://redd.it/awoahu
Hi all,
I'm building a new web app whilst following the (excellent) course on Flask web apps by Nick Janetakis. I'm following his tutorial but at the same time am building my own app, piece by piece as I learn.
In doing this I'm trying to use newer tools. For example, I want to use Python 3.x for future proofing the app, but I have an issue where Celery and Python 3.X won't want to work together.
Just checking in if anyone has had any success with getting a Python 3.x to work with any Celery versions or am I resigned to falling back to Python 2.x?
Thanks a tonne...
/r/Python
https://redd.it/awoahu
reddit
r/Python - Celery and Python 3.X. Has anyone had any success?
0 votes and 2 comments so far on Reddit
I wanted to learn Django, so I made a little pastebin app!
https://luculia.org
/r/Python
https://redd.it/awp6in
https://luculia.org
/r/Python
https://redd.it/awp6in
luculia.org
Luculia · Home
A simple, elegant text-hosting service.
[D] How long are we from: Voice Style Transfer | Voice to Voice, Male to Female, Adding and Removing Accents, & Swapping Vocalists in Music
I'm coming over from /r/MediaSynthesis with the titular question. I'm well aware of previous experiments, but I'm eagerly awaiting future developments in this field of media manipulation.
I've played around with sex-changing voice changers in the past, and the common limitation among all of them is that there is nothing being done besides raising or dropping the pitch, and this doesn't lead to a believable effect since gendered speaking patterns exist in most societies. Without accounting for differences in cadences, you merely wind up with voices that sound like chipmunks or homosexual demons. This requires neural networks, but I haven't found many good ones.
In comes GANs. What's more, GANs might also allow for some creative applications, such as [musical style transfer](https://www.youtube.com/watch?v=YQAupr7JxNY). My go-to theoretical examples are "TLC's *Waterfalls*, but as a barbershop quartet", The Beatles' *I Am The Walrus*, but as an opera", and "Black Sabbath's *Iron Man*, but with Justin Bieber".
Even 2 years ago, I'd have said this was many decades out, but now I'm not so sure. I feel I could say "We'll see something like this by 2029" and then someone demonstrates the exact same thing within 6 months. I say this because it's exactly what happened
/r/MachineLearning
https://redd.it/awmjm8
I'm coming over from /r/MediaSynthesis with the titular question. I'm well aware of previous experiments, but I'm eagerly awaiting future developments in this field of media manipulation.
I've played around with sex-changing voice changers in the past, and the common limitation among all of them is that there is nothing being done besides raising or dropping the pitch, and this doesn't lead to a believable effect since gendered speaking patterns exist in most societies. Without accounting for differences in cadences, you merely wind up with voices that sound like chipmunks or homosexual demons. This requires neural networks, but I haven't found many good ones.
In comes GANs. What's more, GANs might also allow for some creative applications, such as [musical style transfer](https://www.youtube.com/watch?v=YQAupr7JxNY). My go-to theoretical examples are "TLC's *Waterfalls*, but as a barbershop quartet", The Beatles' *I Am The Walrus*, but as an opera", and "Black Sabbath's *Iron Man*, but with Justin Bieber".
Even 2 years ago, I'd have said this was many decades out, but now I'm not so sure. I feel I could say "We'll see something like this by 2029" and then someone demonstrates the exact same thing within 6 months. I say this because it's exactly what happened
/r/MachineLearning
https://redd.it/awmjm8
YouTube
TimbreTron: A WaveNet(CycleGAN(CQT(Audio))) Pipeline for Musical Timbre Transfer
Project Page: https://www.cs.toronto.edu/~huang/TimbreTron/index.html
arXiv Paper: https://arxiv.org/abs/1811.09620
arXiv Paper: https://arxiv.org/abs/1811.09620
PSA: Check your ALLOWED_HOSTS
I've seen a huge uptick in malicious entities trying to gain access across my django sites over the past 48 hours or so. Maybe it's just at my servers, but I suspect these attacks are widespread. This is a good time to verify that your production settings are not:
ALLOWED_HOSTS=['*']
(Edit: Also, while I'm at it, you should ALWAYS have **DEBUG=False** in production, and never commit your **SECRET_KEY** to git/svn)
If you're new to django, [Security in Django](https://docs.djangoproject.com/en/2.1/topics/security/) is the relevant docs page for this topic.
/r/django
https://redd.it/awqdtf
I've seen a huge uptick in malicious entities trying to gain access across my django sites over the past 48 hours or so. Maybe it's just at my servers, but I suspect these attacks are widespread. This is a good time to verify that your production settings are not:
ALLOWED_HOSTS=['*']
(Edit: Also, while I'm at it, you should ALWAYS have **DEBUG=False** in production, and never commit your **SECRET_KEY** to git/svn)
If you're new to django, [Security in Django](https://docs.djangoproject.com/en/2.1/topics/security/) is the relevant docs page for this topic.
/r/django
https://redd.it/awqdtf
Django Project
Security in Django | Django documentation
The web framework for perfectionists with deadlines.
Help with query: how to filter objects based on boolean attribute on model with ForeignKey to that object?
Have a User Profile model with OneToOneField to User and given profiles:
`profiles = Profile.objects.filter(has_car=True, user__age__gt=30)`
Now want to only show profiles where user has verified EmailAddres in Allauth. I think a given User can have multiple EmailAddresses that are verified.
class EmailAddress(models.Model):
user = models.ForeignKey(allauth_app_settings.USER_MODEL)
email = models.EmailField(unique=app_settings.UNIQUE_EMAIL)
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
So how can I filter profiles to only show users where user has at least one EmailAddress with verified=True? Obviously one way would be to just iterate over profiles:
profile_set = []
for profile in profiles:
if profile.user.emailaddress_set.first().verified:
profile_set.add(profile)
This just is inefficient, especially for thousands of profiles. Any suggestions? Thanks all.
/r/django
https://redd.it/aws4rd
Have a User Profile model with OneToOneField to User and given profiles:
`profiles = Profile.objects.filter(has_car=True, user__age__gt=30)`
Now want to only show profiles where user has verified EmailAddres in Allauth. I think a given User can have multiple EmailAddresses that are verified.
class EmailAddress(models.Model):
user = models.ForeignKey(allauth_app_settings.USER_MODEL)
email = models.EmailField(unique=app_settings.UNIQUE_EMAIL)
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
So how can I filter profiles to only show users where user has at least one EmailAddress with verified=True? Obviously one way would be to just iterate over profiles:
profile_set = []
for profile in profiles:
if profile.user.emailaddress_set.first().verified:
profile_set.add(profile)
This just is inefficient, especially for thousands of profiles. Any suggestions? Thanks all.
/r/django
https://redd.it/aws4rd
reddit
r/django - Help with query: how to filter objects based on boolean attribute on model with ForeignKey to that object?
0 votes and 0 comments so far on Reddit
I recorded a 6-part series on DataClasses, explaining all the important concepts. Have you started using dataclasses yet?
https://www.youtube.com/watch?v=2CvzoNPSOHg&list=PLyb_C2HpOQSAQe8VOY9FbZXR_OLhaNpi4
/r/Python
https://redd.it/awr1go
https://www.youtube.com/watch?v=2CvzoNPSOHg&list=PLyb_C2HpOQSAQe8VOY9FbZXR_OLhaNpi4
/r/Python
https://redd.it/awr1go
YouTube
Dataclasses in Python (Part-1) | Introduction
Welcome the first video of the series "Dataclasses in Python".
This video gives a brief overview of the scenarios where we may need dataclasses and how to use them in the simplest way possible.
Type hinting in Python: https://www.youtube.com/watch?v=1psWpWml_VE…
This video gives a brief overview of the scenarios where we may need dataclasses and how to use them in the simplest way possible.
Type hinting in Python: https://www.youtube.com/watch?v=1psWpWml_VE…