Python

use custom model with django python-social-auth

I don’t want to add social auth user in default user table of django. I’ve made a custom model for same. I referred to python-social-auth and Django, replace UserSocialAuth with custom model but I’m unable to do so. I also don’t want to create default tables like social_auth_association , social_auth_code, social_auth_nonce, social_auth_usersocialauth. Please explain how can I achieve this. …
Read more

run linux grep command from python subprocess

I know there are posts already on how to use subprocess in python to run linux commands but I just cant get the syntax correct for this one. please help. This is the command I need to run… /sbin/ifconfig eth1 | grep “inet addr” | awk -F: ‘{print $2}’ | awk ‘{print $1}’ Ok this is what I have at…
Read more

python: setup stages for dev, test and prod

I am working on a personal project using python. Currently I am using nose for unit testing and there is a python file for storing all the settings, like files’ paths, db config, etc. Because the application will connect to a database, I hope when I do unit testing, the database used and the files the application reads/writes are not…
Read more

My code fails, need assistance

So basically I have tried to fix my code as bezt I can but I am stil getting an error at the start of the program. Any help would be appreciated. The code: import os import random # imports the random module, to generate the words import time # imports the time module, used for the countdown print(“Welcome to the…
Read more

Design-Help Python Variable DataStructure List/Dict/Tuple

after trying out different approaches with list and dict, searching around etc. without success, I could need some help designing a little data structure in Python… Probably very easy for experienced python coders but I could not figure out the right syntax, yet. In pseudo code I want a data structure like that: [Name_str] (Week_Str, anyValue) (Week_str, anyValue) (Week_str, anyValue)…
Read more

What does `*` do when use it to extract a list on python 3? [duplicate]

This question already has an answer here: What does ** (double star) and * (star) do for Python parameters? 7 answers Fox example, I have a script like this: a = [‘test1’, ‘test2’, ‘test3’] num = [2, 5] print(*a) print(pow(*num)) when I run it, the output is this: test1 test2 test3 32 So I think that * will extract a…
Read more

Python Elements Quiz *Help* [on hold]

Ok, This is really bothering me. Cant seem to get this to work. Any help appreciated, Cheers! I’m currently getting loads of errors, saying its wrong when theoretically to me it all seems fine… list1 = [“Potassium”, “Lead”, “Gold”, “Hydrogen”, “Lithium”, “Oxygen”]; list2 = [“K”, “Pb”, “Au”, “H”, “Li”, “O”]; def elements_quiz(): print(“Welcome to the Elements Quiz!”) print(“”) questions =…
Read more

"Flask-login" Cookie created but app not behaving as required?

I am trying to get user to login and then redirect them to ‘/user’ and maintain session using flask-login. Login function: @app.route(‘/login’,methods=[‘GET’,’POST’]) def login(): if(request.method == ‘POST’): userid = request.form[’email’].encode(‘utf-8’) passwd = request.form[‘password’].encode(‘utf-8’) user = User(userid,passwd) if user: login_user(user,force=True) return redirect(url_for(‘user’)) else: return redirect(url_for(‘main’)) else: return redirect(url_for(‘main’)) My user function has header of @login_required and the code is: @app.route(‘/user’, methods=[‘GET’])…
Read more