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
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

​

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
What is the standard(ish) way to make a library configurable?

We have an internal library that we want to make open-source, so we are trying to normalize its structure and workflows. This library has several configuration options that are currently split between hard-coded values and some environment variables, and we want to change it to have all the fields read from an hierarchical path:

* Get it from an environment variables.
* If it's not there - get it from a config file in the project directory.
* If it's not there - get it from a config file in the home directory.
* If it's not there - use the library's defaut.

Is there any standard way to do it? Tools like Flake8 read their configuration [from various files](http://flake8.pycqa.org/en/2.6.0/config.html#per-project), in various formats, but we want to have a single way to configure our project.

/r/Python
https://redd.it/awunwn
Django and lists..

Hello!

I have been stuck for a while now with this problem. I would need to create a list of lists for each of my users.User's then could select a some of their lists and input numbers there. I will later use these numbers to show a graph of the selected list.

PS I am pretty new to django so detailed answers would be good. Dont know all the little things yet.. Thanks already!

/r/django
https://redd.it/ax0lfs
Facebook Pixel Conversion Tracking + Flask Template Rendering

So I set my Facebook pixel to track when a page contains for example 'pay' in the URL, but the tracking doesn't seem to be working. I think its because the "pay" route doesn't actually render a template you see, it just redirects the user to an initial page that has its own /intro_page URL (which does render a template, where I could put the pixel code)

I am curious as to what the best approach here is.

I dont wanna double track conversions, so is there any way I can check if it's the first time they've visited?

/r/flask
https://redd.it/ax0ec6
Handling url_for parameters with flask.

Hey guys. I'm trying to handle some url_for parameters with flask.

I have a page that has a big table of parameters, and then a link that gets made at the end of each row.

For example:

<a href="{ url_for('test', test_type=test_select[4], service_type=test_select[3], test_level='80') }">Test</a>

However, when I take the link, the parameters are in the website URL.

I'm not finding great information online. Do I need to add @app.route options to handle these?

Thanks for the help! :)

EDIT: A little more specifics. Normally I have something like this:

@app.route('/test')
def test:
return(render_template(test.html, parameters and stuff))

I want my test route to also be able to handle a different return if it gets some parameters from a url_for link. I hope that makes sense. I will be around to try to clarify as much as I can!

/r/flask
https://redd.it/awuu1q
A 4YO's first python program!

Today, I taught my 4 year old cousin to write her first python program. Within a few minutes of explaining to her, she learnt to open the terminal, start python and write code (shown in the image). While explaining to her as to why we need to put parentheses and quotations, I told her that computers are dumb and that they don't understand us unless we follow some rules (syntax). She wrote down "cows have eight legs" to see how the computer responds to it. To her surprise, when the computer printed out the same, she yelled "Computers are really dumb, it says a cow has 8 legs!". It was bedtime by then and she said goodnight and would learn more programming tomorrow.

&#x200B;

Edit: image

https://i.redd.it/8srpe2iw22k21.png

/r/Python
https://redd.it/ax4gl3
Free Django Book Released

Hello r/django!

I wanted to share that my beta version of my full stack web development book is now live.

You can check it out on my website: [http://www.codexplore.io/books/crash-course/](http://www.codexplore.io/books/crash-course/)

The Github is here: [https://github.com/codexplore-io/crash-course-django](https://github.com/codexplore-io/crash-course-django)

This is just the "Beta version", so I am open to suggestions if anybody has them. I am using this book as an experiment in "open source publishing", so we shall see how it goes.

I am working on building a programming education website that allows anybody to learn how to program. There are many like it, but I truly believe that people learn much differently, so as many different explanations out there will make it easier for those to learn. Feel free to subscribe to learn more about what we are doing in the next couple of months as we are actively expanding across content mediums. We are going to be putting together a podcast as well, so if you have anyone in mind you would love to hear interviewed in the realm of STEM in general (or specifically Django), PM me or send us a contact on our website at [http://www.codexplore.io/contact](http://www.codexplore.io/contact).

&#x200B;

Please follow us on Twitter if you find our information useful: [https://twitter.com/codexplore\_io](https://twitter.com/codexplore_io)

&#x200B;

Any feedback on the book, website or company.

/r/django
https://redd.it/ax3hd5
OTP/Two factor authentication on Django?

I'm trying to add two factor authentication to my project, but the libriaries i found for Django have very little docs and i don't understand how to implement it into my own project. Is there an example, a tutorial or a widely used library i can follow to make my own implementation?

/r/django
https://redd.it/axd9nc
Update datapoint in Postgress

Hi! I'm new to flask and Postgres. I want to update a column based on user input. Should I create a separate get and post methods or use my existing ones?

&#x200B;

I want to update the count of an existing entry.

&#x200B;

@app.route('/')
def get_exams():
# fetching from the database
session = Session()
exam_objects = session.query(Exam).all()

# transforming into JSON-serializable objects
schema = ExamSchema(many=True)
exams = schema.dump(exam_objects)

# serializing as JSON
session.close()
return jsonify(exams.data)


@app.route('/', methods=['POST'])
def add_exam():
# mount exam object
posted_exam = ExamSchema(only=('title', 'description', 'count'))\
.load(request.get_json())
exam = Exam(**posted_exam.data, created_by="HTTP post request")

# persist exam
session = Session()
session.add(exam)
session.commit()

# return created exam
new_exam = ExamSchema().dump(exam).data
session.close()
return jsonify(new_exam), 201

&#x200B;

/r/flask
https://redd.it/axgl8j
[P] Ever wondered how to use your trained sklearn/xgboost/lightgbm models in production? We developed a simple library which turns your models into native code (Python/C/Java)

Imagine that you trained your super accurate model using your favorite tools (Python/sklearn/xgboost/etc.) and now the time has come to deploy your model to production for the greater good.

But consider the following scenarios:

* What if your production environment has no Python runtime?
* What if your model should make instantaneous predictions right on a microcontroller device without sending data to a remote server?
* What if prediction speed is a concern too?

This where m2cgen comes in handy. It's a library that generates Java/Python/C code from trained ML models.

Check it out: https://github.com/BayesWitnesses/m2cgen/


/r/MachineLearning
https://redd.it/axdirb
[AF] sqlalchemy password authetication failed for user "USERNAME". Confused as to what password is being used here.

Hi, so I am trying to get the backend for my website running using postgres alongside Flask. I have the following URI:

"postgresql://username:password@localhost/websitename"

So the problem being presented to me is the password. Do I have to input my actual linux system password into the password field or the postgresql password. I'm sure it's the latter however if that were the case I'd then need to find out how to gain access to this password as I do not remember setting one. Any help is greatly appreciated.

/r/flask
https://redd.it/aximdk
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


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