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
Triggering flask-ask with html buttons

I am trying to build a flask ask demo. I want to have buttons that trigger the amazon event but each demo will be a different skill. I'm currently thinking I can have catch the post request from the front end and have that trigger the question but I don't know how to keep my intents separated for each demo.

/r/flask
https://redd.it/67tmam
Django forms/Pathing Question

Hi there. I'm attempting to modify uploaded audio content in order to satisfy IBM Watson's STT criteria, but I'm unsure what the correct way to go about this would be.

Tiny bit of context: http://dpaste.com/3WGGNM1

At that point, I'm attempting to use a subprocess to issue a sox command (audio editing) using the uploaded wav file as input. The output has the same file name as the input with some extra characters tacked on. After confirming the subprocess command works, I can't seem to path the new wav file as an argument to send to Watson.

I should also mention that there's been a small issue with wav files that are tiny (speech file containing maybe one sentence). I understand that if an upload is small enough, Django will hold it in memory, right? Can we override this without writing a whole custom storage class? If not, no biggie. The main issue is the pathing as described earlier.

/r/djangolearning
https://redd.it/683wyq
Difficulty optimizing my code..

My code seems to be running forever and it's understandable..

anyway i can make this better ?


x = [[a,b,c,d,e,f,g,h,i,j,k] for a,b,c,d,e,f,g,h,i,j,k in itertools.product(range(15),range(15),range(15),range(15),range(15),

range(15),range(15),range(15),range(15),range(15),range(15))

if (a+b+c==15) and (c+d+e+f+g == 15) and ( h+i+c==15) and (c+j+k==15)

and (a != b != c != d != e != f != g != h != j != k)]

My goal here is to get the Combinations that would interest me here only.
Yet im running through 15^11 combinations .. which would cause me to take eternity .
Anyway to go around this ?

/r/Python
https://redd.it/686fsu
Difficulty wrapping my head around structure of my app

I'd like to create a GUI that allows a user to select two photos. Then, I'd like to work with these two photos. My issue is that I'm struggling with how to split these files up.

Ideally, I'd like to have three files

- `main.py`
- `gui.py`
- `processing.py`

I want to initialize a GUI within `gui.py`; this, I have working. What I can't figure out how to do is how to get the images that are selected (browsing for a file is done in `gui.py`). I figured "I'll just make a function in `gui.py` that gets those files and returns them--from there, I'll call it in `main.py` and call the functions from `processing.py` to work on the images; however, I've run into the issue that when I press an "OK" button from `gui.py`, `main.py` has no way of knowing if that button has been pressed yet.

Meaning, if I call the function that returns the selected two images, it will error out immediately in `main.py` since nothing has been stored to those variables yet.


How do I structure this? Is it impossible to do it the way I'm describing? I know I could just do everything in a single file, but that feels dirty to me.

Thanks for any help.

/r/Python
https://redd.it/684x0v
Convoluted Python Problem

Hey everyone!

I'm running the newest release of Fedora on an XPS 13 laptop for school. While I'm not a CS student, I know enough code to make doing a lot of my assignments easier (well, sort of.) Soon, I'll be starting a computational mechanics class that uses VPython to make simulations of different phenomena.

My problem is this: VPython doesn't run natively on Linux, despite what their website may say, and the most stable, newest release, that I'll be using in class is only for Python27. So, you wonder, why it is I don't just use WINE to install Python27? For some reason, I cannot install P27 in Wine. I can download the msi, navigate to the folder, msiexec \i python27blahblahblah, and I even get the first dialogue box asking where I wish to install it. However, the 'Next' and 'OK' buttons on the dialogue box are unresponsive.

Does anyone have experience getting Python27 installed via WINE? Is there some obvious thing I am missing? What sort of workarounds should I be looking for, and what potential alternatives are there to this problem? I hope this is the right subreddit for this question, I'm a long time lurker, and I know it is pretty active.

**TLDR** MUST INSTALL PYTHON27 IN WINE SO I CAN USE VPYTHON FOR A CLASS. PYTHON27 DOESN'T WANT TO BE INSTALLED. WHAT DO?

Thanks for your time and responses.

*Edit* INB4 install Windows. No way, Jose.

/r/Python
https://redd.it/687emv
[AF] Goto URL in Flask outside app.route (no redirect)

I would like to instruct the client from the server to jump to another page. However, I am checking conditions from a socketio.on call which means I cannot redirect (as no page is being requested). I must be able to make the client go to another URL without use of client-side code for security reasons, but I can't seem to find any answers how I might go about this. Of course, I would normally just use routing but I require the session id which does not exist before the page is loaded. Is this even possible to do without requesting a page?


Thanks

/r/flask
https://redd.it/67dzwr
[D] Off-Policy A3C reinforcement learning

Hello, I have a question and hope someone can help me understand:
What exactly does prevent the A3C algorithm from beeing used off-policy?

For example, the Actor-Critic algorithm from rlcode ( https://github.com/rlcode/reinforcement-learning/blob/master/Code%202.%20Cartpole/5.%20Actor-Critic/Cartpole_ActorCritic.py ) is off-policy:
It uses a replay-memory and trains on random batches of it, just like Q-Learning does. However, it does not use n-step-reward, it trains on "Critic(Next_State) - Critic(State)"


Sure, on-policy would mean not to use any replay memory but only learning on the newest state-action-reward pairs once (that reflect the current policy).
But if that was the only difference, one could easily use A3C off-policy, right? So what exactly does prevent an off-policy variant of A3C and why is it always stated as strictly on-policy (with sophisticated extensions needed to make it off-policy, like ACER)?

Is it because of the n-step-rewards, that can only be computed correctly for following a given policy and will become "obsolete" or "wrong" if the policy has changed?
This is the only explanation I could come up with, as n-step-rewards means to follow the current policy for n-steps and then calculating the reward of the past action in strict correlation with the current policy, hence its on-policy?!

So, is the only difference between a off-policy actor-critic algorithm and A3C the lack of a replay-memory and n-step-reward calculation??


Thanks in advance

/r/MachineLearning
https://redd.it/688cm9
Help with django and MongoDB

Hi guys, I need a little bit of help. I'm a student and I got an assignment with NoSQL databases, we need to use MongoDB (we need to do a LinkedIn sort of web app). I decided to used django since I'm trying to learn it and I've been finding some issues trying to link MongoDB to my django app.

* OS: Windows 8.1
* Django version: 1.10
* MongoDB version: 3.0.4 (since I have a 32-bits laptop)

I've followed different tutorials and can't seem to get this running. I'm also using PyMongo 2.8 and Mongoengine 0.9.

* This is how I have my [settings.py](https://pastebin.com/RGLiZKQ4) file.
* The errors I'm getting is [this](https://pastebin.com/fAPwTVD8)

I'm assuming that the authentication failed because I might no me logging in correctly but this is the way I've seem in most tutorials. The 'root' user I created from mongo shell.

Sorry for the pastebin links I just don't want to make this post longer. And thank you.

@EDIT: So it results that my user 'root' doesn't exist on my testDB. I switched to admin db -> created user -> applied 'root' rolls ... I read it would give him access to all my databases it seems no, I also created another called 'admin' and gave him 'roll: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]' but it doesn't seem to work as well. Does anyone know the correct way to do this? Or this shall be done from my 'testDB' ?

/r/django
https://redd.it/686x5o
How can I force a pandas table to resize to fit something I print out?

Here is the table: https://www.dropbox.com/s/2r4vb0wuc2icwp2/table2.xlsx?dl=0

Cell code:
table2 = pd.read_excel('table2.xlsx')
display(HTML(table2.to_html(index=False)))

When I try to print out the notebook the last two columns are cut off. Any ideas on how I can format it so that won't happen? I'm printing using chrome -> print preview. I use this method because the PDF via latex just doesn't capture a very similar PDF output.

/r/IPython
https://redd.it/687ope
[AF] Using SQLAlchemy's ilike or contains operators

I'm building some simple search functionality into my site, and I'm using the `contains` operator to search my rows for some text. My query looks something like this: `User.query.filter(func.lower(User.name).contains(term))`

However, when I enter `_` or `%`, I get every single row! How can I escape these the proper way? I know I can probably just do a `.replace` on the search term but what do I replace it with? Is there an official SQLAlchemy way of doing this? Every other part of SQLAlchemy I've been exploring is really nice and polished, but apparently not this part!

/r/flask
https://redd.it/68998q
This weekend's play project

/r/Python
https://redd.it/68aifs
Creating a rest api with many to many relationships

As the title says I'm creating an API to map employees to shifts, I've got /employees and /shifts, but I'm a little confused about creating an endpoint to map the two? I was going to create another endpoint /patterns, and then pass an employee id and shift id and parameters to create a new mapping, does this sound correct? Also do I need to create a new model or serializer for this endpoint?

thanks

/r/django
https://redd.it/68bzyy
My university is thinking of teaching the engineering students python instead of matlab - How to help convince them?

Hey all

As the title suggests, the teaching committee at my university are thinking of moving from teaching undergrad engineering students python instead of matlab.

Since they've asked for some student input, can anyone think of any decent arguments to try to make the move?

biggest reason presented for keeping matlab is that matrix manipulations are easy (if you've ever tried to do FEM stuff in numpy it just makes you sad).




/r/Python
https://redd.it/68ahc5