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
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
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
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
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
I just built my portfolio in Django and NES.css
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
Can't generate new instance of a random hash unless restarting server

Hello,

&#x200B;

While working on my email verification functionality on my website I noticed an odd bug.

&#x200B;

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())\`

&#x200B;

In theory, for every new user a random hash should generate.

&#x200B;

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.

&#x200B;

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

&#x200B;

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

&#x200B;

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

&#x200B;

&#x200B;

All I want is for every new user to have a random and unique hash without

/r/flask
https://redd.it/awo87c
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
[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
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
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
Raw SQL usage in Django

Hi everyone.
As we know, django orm each release has a good performance improvement and nice feature until now.

I just need your opinion, when you decide to use raw SQL?
Personally, I never use raw SQL due to orm is more maintainable to me.

/r/django
https://redd.it/awusjs
A Python utility for analyzing a given solution to the Einstein field equations.

I wanted to share with the community an open source python package I had been developing since November. It is called Spacetime Engine.

[github.com/spacetimeengineer/spacetimeengine](https://github.com/spacetimeengineer/spacetimeengine)

My name is Michael. I am a physicist who works as an engineer. My story is that in October 2018 I was preparing to submit my first physics publication, which reviewed a particular cosmological model that I had been working with for some time. I was at the point where I had completed all of my research and was fully prepared. The only problem was that at the time I felt concerned that I may have made some mistakes which went unnoticed, so I decided to write a computer algebra software to check the veracity of my solutions so that I could feel confident in my results. After using this new utility, I realized I had made some fairly significant errors in my approach, and so the software apparently did it’s job. At first I was quite frustrated because I had put a significant amount of time into this solution, but I realized I had a new ability to correct my own errors and expand upon what I already knew. I was now able to study

/r/Python
https://redd.it/awtry9
Any tutorial or guide for Social Authentication using django rest-auth and vuejs?

I'm trying to implement social app authentication using vuejs as front end but since it's the first time I'm doing it and am also not so familiar with vuejs, can anyone guide me through the process? Thank you all in advance. I've managed to implement rest-auth properly but now that I'm using the front end, I'm kind of lost and don't know

&#x200B;

I have not been able to find a lot of helpful content to guide me. This is the first time I'm dealing with APIs in general. Any help would be appreciated. Thanks.

/r/django
https://redd.it/awwp7q
How to make scripts usable by non CLI users

I think this is a common problem for developers who like to create great CLI applications. How do you make it usable by your grandpa? Or by anyone whom the functionality of the script is useful but won't ever pop up a cli and type those commands.

Let's say I have a script that would do a simple task. Something that I could probably run as:

```
$ ./script --file /home/my/file.txt
```

Only ways I could think of how non CLI users can use this are the following:

* make a GUI - everyone knows a GUI and knows how to use a file chooser.
* wrap your python script in an executable (bat file maybe) and provide user prompts for the filename (they'd need to type in really long names though!).
* enforce restrictions with your script - i.e. rename file to this and that before using, must be executed from this directory etc.

Any other ideas besides those?

I'm usually working with web so I have little knowledge of making native GUI applications with Python. I'm also seeking recommendation on how I should go about this:

* build my own GUI - this looks nice https://pypi.org/project/PySimpleGUI/
* try out this awesome project https://github.com/chriskiehl/Gooey, although bummer that it only supports `argparse`


I'm

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