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
Does the data persist in a redis database?

I am going to be using rabbitmq as a message broker and Redis as results backend for a flask app. I signed up for redis labs and on the free version, you get 30 MB of storage.

The use case will be pulling data from some api's on data.gov and then loading the data into a website asynchronously. The data that is pulled isn't that large, maybe ~few hundred kB. However, over time I could max out my limit. Or does redis(labs) only keep that data for a certain period of time and then it get's deleted?

/r/flask
https://redd.it/8cab9h
TIL that starting from 3.7 dicts are officially ordered

Since 3.6 [dicts preserve order because of the new “compact” representation](https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew36-compactdict) but it was just an implementation detail and we were told not to rely on it.

But in 3.7 dicts **officially** became ordered:

> Performing `list(d)` on a dictionary returns a list of all the keys used in the dictionary, **in insertion order**

(from https://docs.python.org/3.7/tutorial/datastructures.html#dictionaries)

TBH, I'm not sure that this is a good idea. I can see a number of problems with this change in future:

1. Now people will start relying on the order of elements in a dict and if Python developers want to change the implementation in future they will **have to** preserve the order as well.
2. It forces developers of other Python interpreters to implement this feature as well even if it will cost them some additional work or decrease performance.
3. It makes `collections.OrderedDict` redundant which could lead to confusion.

What do you think about this decision? Why do you think they made it?

/r/Python
https://redd.it/8cf4rf
Database design (lots of columns / fields)

I currently have a model that has over 100 fields on it. I'm not sure the best way on how to optimise this. The options i've thought of so far:

1. Keep as is and use `Model.objects.only('field1', 'field2')` with each query i make
2. Have a main model then have a 2nd "Data" model that one to ones with the main model then query the extra data that way.
3. Convert a lot of the columns to be able to be stored in a single PSQL JSON column, i'm not sure if this causes filter / index issues down the lines as a decent amount of the columns are indexable.

Is there another option that is better than any of these 3 or which of the 3 would give me the most flexibility going forward?

Edit**

My data is coming from an external source which looks like: https://gist.github.com/dan-gamble/fac2becbd56dc6fe88f281a64823a2f4

Some of the keys i don't need so they got dropped, the Nation / League / Club all are FK's to another object. The rest is currently stored on a `Player` model. The columns that have a value assigned to them are stats and can be filtered on.

/r/django
https://redd.it/8cfr2q
Updating Plotly Version in Python

I am having trouble trying to update to the latest Plotly version of 2.5.1. I have tried using the methods below in terminal for my Mac, but whenever I check Jupyter, my version is still 2.3.0.

pip install plotly==2.5.1


pip install plotly --upgrade

/r/IPython
https://redd.it/8cgqfq
How do I join a model after using `.objects.values()`?

I'm making a custom Django `manage.py` command. Here is the part of it relevant to my question.

Model = apps.get_model(app_label="my_app", model_name="MyModel")
x = Model.objects.values(*options["fields"].split('|')):


I want to join `Model` with another model, `SomeOtherModel`. `Model` has a foreign key field named `fk` that connects to the primary key for `SomeOtherModel`. How do I modify my code above to join `Model` with `SomeOtherModel`? Or should I join before running `objects.values()`?

/r/django
https://redd.it/8chxuj
Python for Good

I wanted to let everyone know about Python for Good, a Python event that is happening in the Portland, Oregon area. Put simply, we get a bunch of pythonistas (along with anyone else interested in doing good) and we gather for a long weekend (Thurs - Sun) of using our awesome skills to build apps for social and civic good organizations. Our theme for this year is children and families and some of the places we'll be helping this year include a homeless shelter, numerous organizations that help children, and many more amazing and worthwhile organizations.

The event is all inclusive, meaning that we stay in university dorms, all the food is provided and we have pretty great internet too. Our days are filled with hacking and our evenings are full of excellent camaraderie -- playing boardgames, video games, karaoke, werewolf, cards and lots of excellent socializing!

We are excited to announce that we're going to be once again holding the event at Reed College from July 26th to the 29th.

You can find more information about this years' event here: http://pythonforgood.org/attend Here is a list of the most frequently asked questions here: http://pythonforgood.io/faq

I'd be delighted to answer any questions.

Happiness,

Sean (and the Python for Good team)

/r/Python
https://redd.it/8ciq36
Solid examples using *args and **kwargs

I have seen these in various snippets of code. I am looking for some really good use case examples.

/r/Python
https://redd.it/8ci7qw
Flask-Restful API Help? POST method is not allowed

Hi,

I created a Flask-Restful API but when creating a post method like so

class Create(Resource):
def post(self):
etc etc

api.add_resource(Create,api/Create)

It errors out saying the method is not allowed.. but it works when I have something like this

@app.route("/signup/<username>,<password>", methods = ['GET', 'POST'])
def signup(username, password):

Can anybody assist? How do I allow the POST method using the first method?


/r/flask
https://redd.it/8chql1
New stable release of PySolFC — an open-source collection of over 1,000 card Solitaire/Mahjong games

[PySolFC](http://pysolfc.sourceforge.net/) is a free and open-source collection of over 1,000 card Solitaire and Mahjong games with many features and solver/analysis tools. It is almost [20 years old](http://solitaire.vegard2.net/pysol.html), and the current development efforts are concentrated on [the GitHub repository](https://github.com/shlomif/PySolFC).

The PySolFC developers are happy to announce a new stable release, 2.2.0, of PySolFC (the last one was in distant 2009!). Among the new features are:

* Compatibility with both Python 3.x and Python 2.7.
* Support for the Kivy user-interface toolkit, for Android devices and other systems.
* A Microsoft Windows binary installer.
* Support for dealing all [Freecell Pro deals](http://fc-solve.shlomifish.org/faq.html#what_are_ms_deals) by specifying "ms100000", or similar, as the seed.
* Support for the [Black Hole and All in a Row solver](http://www.shlomifish.org/open-source/projects/black-hole-solitaire-solver/) was added.
* Test suite and [CI](https://en.wikipedia.org/wiki/Continuous_integration) have been added to the repository.
* The code now passes [flake8](https://pypi.python.org/pypi/flake8) validation.

You can find [download links](https://sourceforge.net/projects/pysolfc/files/PySolFC/) for current Windows, source code, and Android versions.
Packages for Linux/BSD/etc. distributions and operating systems should be made
available soon from the downstream packagers.

Future plans:

* Vector-based fully scalable cards and graphics
* Large-scale cardsets for HD displays
* An online, WWW-based version

If you want to help, we need:

* Programmers
* Graphic designers who would help with improving the app’s look
* People to help with documentation and translations
* People who would spread the word
* Testers / QA people
* Monetary donations - see [this page](http://www.shlomifish.org/meta/how-to-help/)

We will gladly answer any questions!

Remember that apart from this thread you can also contact us using the [FOSS Card Games group](https://groups.google.com/forum/#!forum/foss-card-games), and using the ##pysol chat room on [Freenode](http://freenode.net/) (note the double octothorpe/hash-sign/pound-sign).

A final note is that while we are using GitHub for version control, and accept
pull requests and issue reports, we are still hosting the main site and the
downloads on SourceForge.net. See [the explanation](https://www.reddit.com/r/Python/comments/8237i3/help_is_needed_in_preparing_a_windows_binary/dv84xxu/)
for details.


/r/Python
https://redd.it/8cnoou
How can I dynamically change the file extension in a relative link from IPYNB to HTML when downloading a notebook as HTML?

I currently have a line inside a notebook (File1.ipynb):

[File 2](File2.ipynb)

When downloading both the files as HTML, this link is hard-coded, and hence when I click on the link in the generated *File1.html*, it can't find the file, because it refers to ipynb and not to html.

I could try:

* using sed to replace all occurrences of ipynb with html
* hard-coding html inside the notebook, which will prevent me from using the links when I'm editing the notebook.
But, is there an alternative?

Is there, perhaps, a way to specify two links inside the notebook such that if the browser fails to find the first one, it'll try the second? I tried searching for such a method. I couldn't find it.

/r/IPython
https://redd.it/8ct3ia
jQuery/AJAX get Request format?

I've got a post request working pretty well

$.post('/discount', {
time_left: distance / 60000,
ban_id: id
})

So say for example, with my get request, all I want to do is actually grab some data from Python Flask, namely in my /discount route I have a variable named d_code which is my discount code. All I simply want to do is grab this variable and in the function of the GET request, I want to change the innerHTML of a paragraph just to show the discount code.

Fairly simple, but I don't really understand how to do the get request correctly.


Bonus: Do you think a flask app with gunicorn can handle 10k-100k users a day? Hosted on Heroku.


/r/flask
https://redd.it/8crflf
[R] Multimodal Unsupervised Image-to-Image Translation

/r/MachineLearning
https://redd.it/8cram8