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
My first Python program :) (I'm hooked)

So, Python was on my list of things to teach myself after I took a C++ course this spring (I regret that, should have taken Python or Java).

So, I am proud of this stupid little dice roller because I evolved it from a basic "This rolls two dice" to "How many do you want to roll?" with input validation. Yay me.

#my first Python program.
#I chose this one to compare to a similar program made
in C++

import random
import time

roll = "yes"
numDice = 0


print("This program will roll as many dice as you need.")
time.sleep(1) #this makes the program pause a bit

print("\nWould you like to roll?")
roll = input()

#input validation to make sure they type yes (y) or no
(no)
while roll != "yes" and roll != "y" and roll != "no" and roll
!= "n":
print("\nType yes (or 'y') or no (or 'n') to roll.")
roll = input()

while roll == "yes" or roll == "y":
print("\nHow many dice do you want to roll?")
numDice = int(input())

print("\nRolling...")
time.sleep(2) #again, a pause

print("\nYou got: ")

for i in range(0, numDice): #this iterates as many times
as the user wants
print(random.randint(1,6)) #generates the random
numbers between 1-6

print("\nRoll again?")
roll = input()

#input validation again
while roll != "yes" and roll != "y" and roll != "no" and
roll != "n":
print("\nType yes or no.")
roll = input()


print("\nThanks for using my program!")

input()


/r/Python
https://redd.it/6hmq58
[AF] Deploying flask on cPanel without "Setup Python App".

I am trying to deploy a flask app to a server provided by my school. It uses cPanel. Most of the help I found online involved using a cPanel software called "Setup Python App" however this is not available on my cPanel account. What follows is what I have learned from the web.

My app looks like this:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
return 'Hello World!'

if __name__ == '__main__':
app.run()

I have put my application in a the cgi-bin directory under home/user/public_html along with a .cgi file containing the following code

#!/home/user/miniconda3/python #I installed python here because i did not have access to /bin
from wsgiref.handlers import CGIHandler
from test import app

CGIHandler().run(app)

I have also added a .htaccess file in the /home/user/public_html directory with the following code:

Options +ExecCGI
AddHandler cgi-script .py

All of the above files have 755 permissions.

When I go to my domain, i get a 403 error and the website says:

> **Forbidded**
>
> You don't have permission to access / on this server.
>
> Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Sorry for the novel. I don't have much experience with this so i don't know what parts are important enough to put in the post.

Any help you can give me would be greatly appreciated. Thanks.

/r/flask
https://redd.it/7i23md
[Discussion] Juergen Schmidhuber: Critique of Turing Award for Drs. Bengio & Hinton & LeCun

I saw this [tweet](https://twitter.com/SchmidhuberAI/status/1276058162974666753) from Schmidhuber today:

*ACM lauds the awardees for work that did not cite the origins of the used methods. I correct ACM's distortions of deep learning history and mention 8 of our direct priority disputes with Bengio & Hinton.*

His new article: http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html

**Abstract.** ACM's 2018 A.M. Turing Award was about *deep learning* in artificial neural networks. ACM lauds the awardees for work based on algorithms and conceptual foundations first published by other researchers whom the awardees failed to cite (see [Executive Summary](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#exec) and Sec. [I](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#I), [V](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#V), [II](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#II), [XII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XII), [XIX](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XIX), [XXI](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XXI), [XIII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XIII), [XIV](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XIV), [XX](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XX), [XVII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XVII)). ACM explicitly mentions "astonishing" deep learning breakthroughs in 4 fields: [(A) speech recognition](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#A), [(B) natural language processing](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#B), [(C) robotics](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#C), [(D) computer vision](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#D), as well as "powerful" new deep learning tools in 3 fields: [(VII) medicine, astronomy, materials science](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#VII). Most of these breakthroughs and tools, however, were directly based on the results of my own labs in the past 3 decades (e.g., Sec. [A](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#A), [B](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#B), [C](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#C), [D](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#D), [VII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#VII), [XVII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XVII), [VI](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#VI), [XVI](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XVI)). I correct ACM's distortions of deep learning history (e.g., Sec. [II](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#II), [V](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#V), [XX](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XX), [XVIII](http://people.idsia.ch/~juergen/critique-turing-award-bengio-hinton-lecun.html#XVIII)) and also mention 8 of our direct priority disputes with Bengio & Hinton (Sec.

/r/MachineLearning
https://redd.it/hfi3hz
Files inside my Static folder are not being found when running on server.

I am having issues relating the Django documentation for settings up the static path ways to how my project is set up.

I am using a Droplet on Digital Ocean that is setup to use Django 3.1, Gunicorn, and Nginx to run my project and the static files load locally but throw a 404 error on the droplet server. I feel like I've tried every combination of STATIC_URL, STATIC_ROOT, and STATICFILES_DIRS i can think of and I've copied the static files using "collectstatic" so I'm pretty desperate for suggestions.

This is the path in the actual server to the static path I copied my project too:

**/home/django/django_project/django_project/static**

I've tried setting my variables to this setup:

STATIC_URL = '/static/' # I've tried this too: 'django_project/django_project/static/'
STATIC_ROOT = "/var/www/static/" #'/static/'

STATICFILES_DIRS = [
os.path.join(BASE_DIR, '/static'), #I've tried 'django_project/static' with and without the back slash at the end
]

No matter what I try the static assets cannot be found:



/r/djangolearning
https://redd.it/iggkpx
Updating Figure Display in Jupyter

Hello /r/IPython

​

I'm not sure if this is the right place to ask this, but the jupyter subreddit doesn't seem very active. Anywho, I'm trying grabbing images from webcam and doing some processing on it, and I want the output from the code block to update, maybe redrawing the figure/axis so that the newer image shows. Here's what I have:

```
plt.ion()
webcam = init_cam() #sets resolution and stuff
fig, ax = plt.subplots(1)
axim = ax.imshow(tFrame) #Show some pre-grabbed image

while True:
frame = get(webcam) #gets image from webcam
axim.set_data(frame)
plt.show(block=False)
#plt.pause(1) #I've tried with and without pauses
```

And long story short, it doesn't update the figure and appears to only show the first frame. Am I doing something wrong? Is there another way to do this? Any help would be appreciated!

/r/IPython
https://redd.it/k8a6nx
How to access an authenticated user object in forms.py

In: `forms.py`

`from .models import User, User_asset_period_setting`

class UserAssetForm(forms.Form):
#need to filter by current logged in authenticated user
user_asset_choice = forms.ModelMultipleChoiceField(
queryset=User_asset_period_s etting.objects.all().order_by('asset_id')).filter(User.???#I want to access current logged in user id here)


I've tried making the request available in \`forms.py\` to no avail yet. The obvious solution is to just make a custom form in html, but I'd like to use Django's forms functionality if possible!

I refuse to believe there isn't away to do this!

/r/django
https://redd.it/opxtqf
Cnverting a Liststring into a Listlist...

Hello everyone, first post ever... can someone point me in the right direccion? I need to format the firt list into the same format as the second one. Python

print(incorrentformatlist)
'AsKh', '2sAc', '7hQs',...........

print(correctformatlist)
['As', 'Kh', '2s', 'Ac', '7h', 'Qs',..............]

\#I tried:

for h in incorrect_format_list:

split_lines = h.split(", ")

\#but the print output is this:

'AsKh'
'2sKh'
'7hQs'
... #rather than what i need: ['As', 'Kh', '2s', 'Ac', '7h', 'Qs'..............]

/r/Python
https://redd.it/10fvovh