Django manage.py sync_db crash when creating superuser

When I try to create an initial database for my Django app using manage.py syncdb, it crashes at the point where I'm about to create the super user, after entering the email address: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/getpass.py", line 114, in fallback_getpass stacklevel=2)getpass.GetPassWarning: Can not control echo on the terminal.What I've tried to solve this:Skipping the creation of the super user during syncdb and run the createsupercommand. This appears to solve the problem as there is a superuser created however it's imp...

Looping svg rectangles from database

I am reading svg rectangles from a databse using python, I don't know if this is the right way, as it seems I am hardcoding, this because I want each rectangle to change colours in my css style sheet. Is there a better way to call these rectangles rather than using ifs and elifs because if I have 100 rectangles, what is the better way to do it. I have added my stylesheet aswellfor row in c: box_x = ((row[3]-row[1])/2 + row[1] - 0.25) box_y = ((row[4]-row[2])/2 + row[2] - 0.25) move1 = box_y * 2 try1 = row[1] * 2 if row[0] == 1: print('<rect id= rectangle1 class= ...

How can I call a method stored in a variable?

If I have a class Foo with the method method1, is there a way to store this method in a variable before instantiation, which I then could call after this class is instantiated? For example: class Foo: def method1(self, arg): print(self, arg)# something like this variable, but which can be called with instantiated class func = Foo.method1foo = Foo()foo.func(1) # I want to call it in a similar way to this In python, there is no real distinction between functions and methods - a method is merely a function defined in a class.For us, this means that the function s...

More elegant way to separate a list of dict(s) based on a value from an identical key in each dict in a class

I get a return of a list of dict(s), from a program, that have the same key in each dict, I would like to set a class attribute list based on the :value in each. The dict list can have multiple same values[ {"key":"value"}, {"key":"differentvalue"}, {"key":"value"}, {"key":"newValue"}, {"key":"newValue"}]now i have a class like this `class DynamicAttributesFromDict: def __init__(self, listed): for i in range(len(listed)): name = listed[i]["key"] p = getattr(self, name, []) p.append(listed[i]) setattr(s...

Map some Fields of Dictionaries in a List

I have a list of dicts, what is the input. Some of the fields are HTML-encoded.[ { CONTENT:"<title>ABC</title>", bla: "Text", x: "<span>Test</span>" }, { CONTENT:"<b>def</b>", bla: "32", x:"<div><b>Test</b></div>" }, ... ]The list fields contains the fields to be transformed using an HTML-Stripper _strip:fields = ["x", "CONTENT"]What is the best way to map the value of these fields, in this case CONTENT and x, to _strip(CONTENT) respective _strip(x).My curren...

Fastest way to read data separated by white space in Python

I have some data that is separated by white space from which I want to extract certain columns. In the past I have always used something like the following in Python, in which I have removed the non-essentials:for line in open(f,'r'): l = line.split() print " ".join(l[1:3])I'm wondering though whether this is the fastest way to do this. If I compare to another software package (written in C) that reads the same data, my code is significantly slower. Is this simply because I/O in C is faster or am I writing suboptimal code? When you directly iterate over a file, the...

awk (or sed/python) skipping rows to renumber a column

I need help renumbering elements. I have an input file like the small sample below (nodes and elements could be in the 1000's). I need a code that skips down past all the nodes and starts with the first element, and at that point I need to add an integer to all the elements. IE: element 658 = 1658, 659=1659, etc.... Everything needs to be outputted into a new file, the only differences is the renumbering of the elements. I tried doing this with the awk command, code below, cannot quite get it. Can someone help? Is python or sed better? Thanks*NODE, NSET=Nvolc 1,6.1062266...

how to get an exact directory through os.walk in python

I have a directory that contains directories like /sample1, /sample10, /sample11 etc.when I am using os.walk to access all of them one by one, I am facing some difficulties.for root, dirs, files in os.walk(mypath): if 'sample1' in root: print rootnow, this returns all root /sample1, /sample10, /sample11 etc. as 'sample1' is there for all directories. how can I obtain only sample1 directory ?may be regex would be good but I dont know how to use it. Test for equality: if root == "sample1": … [XXX]

Using scipy.integrate.complex_ode instead of scipy.integrate.ode

I am trying to use complex_ode method instead of ode method in scipy.integrate. The help page for complex_ode does not provide example, so I may have done something wrong.This code works properly with scipy.integrate.ode:from scipy.integrate import odey0, t0 = [1.0j, 2.0], 0def f(t, y, arg1): return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]def jac(t, y, arg1): return [[1j*arg1, 1], [0, -arg1*2*y[1]]]r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True)r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0)t1 = 10dt = 1while r.successful() and...

ODE placement in an ODE system give different results

I have the following code:def multirk4(funcs, x0, y0, step, xmax): n = len(funcs) table = [[x0] + y0] f1, f2, f3, f4 = [0]*n, [0]*n, [0]*n, [0]*n while x0 < xmax: y1 = [0]*n for i in range(n): f1[i] = funcs[i](x0, y0) for j in range(n): y1[j] = y0[j] + (0.5*step*f1[j]) for i in range(n): f2[i] = funcs[i]((x0+(0.5*step)), y1) for j in range(n): y1[j] = y0[j] + (0.5*step*f2[j]) for i in range(n): f3[i] = funcs[i]((x0+(0.5*step)), y1) for j in range(n): y1[j] = y0[j] + (step*f3[j]) for i in range(n): f4[i] ...

Combinations without repeat and ordering matters or Permutations of array elements

For a 1D NumPy array, I am looking to get the combinations without the same elements being repeated in a combination. The order is important. So, [a,b] and [b,a] would be two distinct combinations. Since we don't want repeats, [a,a] and [b,b] aren't valid combinations. For simplicity, let's keep it to two elements per combination. Thus, the output would be a 2D NumPy array with 2 columns.The desired result would be essentially same as itertools.product output except that we need to mask out the combinations that are repeated. As such, we can solve it for a sample case, lik...

APScheduler - ImportError: No module named 'apscheduler'

I don't know why I get this error: ImportError: No module named 'apscheduler'.I tried to install the older version with:sudo pip uninstall apscheduler and then sudo pip install apscheduler==2.1.2 but this doesn't worked for me.Here's my code: import os ,subprocessfrom apscheduler.schedulers.blocking import BlockingSchedulerdef scheduled_job(): sync_to_drive=subprocess.check_output(["./gdrive", "sync", "upload", "--keep-local", "/home/pi/Documents"], cwd="/home/pi/Downloads") print (sync_to_drive)sched = BlockingScheduler()sched.add_job(scheduled_job, "interval", seco...

Creating an Iterative function instead of Recursive in python

def sum(root): if root.children == []: return root.value else: temp = 0 for n in root.children: temp += sum(n) temp+= root.value return tempI got my function to work recursively and am trying to figure out an easy way to do it iteratively. I just am trying to find guidance as to if I would be using a while loop or what. Use a queue or stack; take an element from your queue or stack, add the value to the running total, add any children to the queue or stack, then process the next element. Use a while loop that ends when you...

Cleaning Data: Replacing Current Column Values with Values mapped in Dictionary

I have been trying to wrap my head around this for a while now and have yet to come up with a solution. My question is how do I change current column values in multiple columns based on the column name if criteria is met???I have survey data which has been read in as a pandas csv dataframe:import pandas as pddf = pd.read_csv("survey_data")I have created a dictionary with column names and the values I want in each column if the current column value is equal to 1. Each column contains 1 or NaN. Basically any column within the data frame ending in '_SA' =5, '_A' =4, '_NO' =3, ...

Uploading a file with AJAX, Python, and CGI

I'm having a very odd problem uploading an image with Python and AJAX. If I don't use AJAX, it works perfectly, but if I don't, I get a: ValueError: Invalid boundary in multipart form: b''Note that I would like to do this without an iFrame, which according to this post and this Mozilla post is possible.The AJAX (Condensed)var formData = new FormData()formData.append("upload", form.upload.files[0]);var xmlhttp=new XMLHttpRequest();xmlhttp.open("POST","/cgi-bin/uploadPic.py", true);xmlhttp.setRequestHeader("Content-type","multipart/form-data");xmlhttp.send(formData);The HTML...

Bing API Web Search Python

I'm trying to create a search bot which uses Bing Web Search API but I'm facing an issue.subscription_key = API_KEYassert subscription_keysearch_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"search_term = "Sayam Kanwar"import requestsheaders = {"Ocp-Apim-Subscription-Key" : subscription_key}params = {"q": search_term, "textDecorations":True, "textFormat":"HTML"}response = requests.get(search_url, headers=headers, params=params)response.raise_for_status()search_results = response.json()print search_results["webPages"]["value"]Output:ScreenshotNow, I want to ex...

Page 1 of 2220  |  Show More Pages:  Top Prev Next Last