title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Binary search in a Python list | 38,346,013 | <p>I am trying to perform a binary search on a list in python. List is created using command line arguments. User inputs the number he wants to look for in the array and he is returned the index of the element. For some reason, the program only outputs 1 and None. Code is below.
Any help is extremely appreciated. </p>
... | -2 | 2016-07-13T08:09:48Z | 38,346,428 | <p>In Python2 and Python3 you can use <a href="https://docs.python.org/3/library/bisect.html" rel="nofollow">bisect</a> as written in the comments.
Replace your search with the following</p>
<pre><code>from bisect import bisect_left
def search(alist, item):
'Locate the leftmost value exactly equal to item'
i ... | 1 | 2016-07-13T08:29:29Z | [
"python",
"python-2.7"
] |
Binary search in a Python list | 38,346,013 | <p>I am trying to perform a binary search on a list in python. List is created using command line arguments. User inputs the number he wants to look for in the array and he is returned the index of the element. For some reason, the program only outputs 1 and None. Code is below.
Any help is extremely appreciated. </p>
... | -2 | 2016-07-13T08:09:48Z | 38,346,630 | <p>The reason you aren't getting correct result is because in every recursive call your code is sending sliced array. So the array length keeps reducing. Ideally you should work out a way to send original array and work with only start, end indices.</p>
| 0 | 2016-07-13T08:39:01Z | [
"python",
"python-2.7"
] |
Binary search in a Python list | 38,346,013 | <p>I am trying to perform a binary search on a list in python. List is created using command line arguments. User inputs the number he wants to look for in the array and he is returned the index of the element. For some reason, the program only outputs 1 and None. Code is below.
Any help is extremely appreciated. </p>
... | -2 | 2016-07-13T08:09:48Z | 38,347,202 | <p>Well, there are some little mistakes in your code. To find them, you should either use a debugger, or at least add traces to understand what happens. Here is your original code with traces that make the problems self evident:</p>
<pre><code>def search(list, target):
min = 0
max = len(list)-1
avg = (min+max)/2... | 2 | 2016-07-13T09:05:25Z | [
"python",
"python-2.7"
] |
Can't get VideoCapture property as the property identifier are not defined | 38,346,018 | <p>I am trying to process frames in a video file, and to know what is the current frame position in the video.</p>
<pre><code>cap = cv2.VideoCapture('Videos/IMG_2483.MOV')
print("Position : %d" % cap.get(cv2.CV_CAP_PROP_POS_MSEC))
</code></pre>
<p>I keep getting this error : </p>
<pre><code>AttributeError: 'module' ... | 1 | 2016-07-13T08:10:04Z | 38,346,145 | <p>It seems that <code>CV_CAP_PROP_POS_MSEC</code> is deprecated in your installed version of Opencv, Change it to <code>cv2.CAP_PROP_POS_MSEC</code>. Works good for me on Opencv 3.1</p>
| 0 | 2016-07-13T08:15:28Z | [
"python",
"opencv"
] |
Print the login shell of the current user in Python | 38,346,046 | <p>How can i print the login shell of the current user in Python. </p>
<p>Can i do this with the OS module from Python & with the getlogin() function?
Can someone give me a hint to solve this problem.</p>
| 0 | 2016-07-13T08:10:54Z | 38,346,193 | <p>You can use <code>os.environ</code> and print out <code>SHELL</code> variable as follows:</p>
<pre><code>from os import environ
print(environ['SHELL'])
</code></pre>
| 1 | 2016-07-13T08:18:14Z | [
"python"
] |
Find maximum value in dictionary of lists | 38,346,068 | <p>How do I find the <em>maximum value of the lists</em> in a <em>dictionary of lists</em> without using a loop? My dictionary looks like:</p>
<pre><code>data = {'key1': list1, 'key2': list2, ... 'keyn': listn}
</code></pre>
<p>if I use:</p>
<pre><code>m = max(data.iterkeys(), key=lambda k: data[k])
</code></pre>
<... | 0 | 2016-07-13T08:11:56Z | 38,346,160 | <p>Iterate through the items in each list in a generator expression:</p>
<pre><code>m = max(i for v in data.values() for i in v)
</code></pre>
| 2 | 2016-07-13T08:16:13Z | [
"python",
"python-2.7",
"dictionary"
] |
Find maximum value in dictionary of lists | 38,346,068 | <p>How do I find the <em>maximum value of the lists</em> in a <em>dictionary of lists</em> without using a loop? My dictionary looks like:</p>
<pre><code>data = {'key1': list1, 'key2': list2, ... 'keyn': listn}
</code></pre>
<p>if I use:</p>
<pre><code>m = max(data.iterkeys(), key=lambda k: data[k])
</code></pre>
<... | 0 | 2016-07-13T08:11:56Z | 38,346,185 | <pre><code>myDict = {'key1': [1,2,3], 'key2': [4,5,6]}
maxValue = max((max(myDict[key]) for key in myDict))
</code></pre>
<p>output: <code>6</code></p>
<p>if your new to python, here is a much readable way of how Moses Koledoye did it:</p>
<pre><code>for v in myDict.values():
for i in v:
m = i if i > ... | 1 | 2016-07-13T08:18:01Z | [
"python",
"python-2.7",
"dictionary"
] |
Find maximum value in dictionary of lists | 38,346,068 | <p>How do I find the <em>maximum value of the lists</em> in a <em>dictionary of lists</em> without using a loop? My dictionary looks like:</p>
<pre><code>data = {'key1': list1, 'key2': list2, ... 'keyn': listn}
</code></pre>
<p>if I use:</p>
<pre><code>m = max(data.iterkeys(), key=lambda k: data[k])
</code></pre>
<... | 0 | 2016-07-13T08:11:56Z | 38,348,013 | <p>You can find the maximum value like this. With out using any loop.</p>
<pre><code>max(max(data.values()))
</code></pre>
<p>But this answer is valid when the all values are iterable. </p>
<pre><code>In [1]: myDict = {'key1': [1,2,3], 'key2': [4,5,6]}
In [2]: max(max(myDict.values()))
Out[1]: 6
</code></pre>
| 0 | 2016-07-13T09:42:06Z | [
"python",
"python-2.7",
"dictionary"
] |
to merge two dictionaries in python with common keys and min values | 38,346,216 | <p>I have two dictionaries</p>
<pre><code>dict1[1]={ 'a':3 , 'b':2 , 'c':1 , 'd':5 }
dict1[2]={ 'a':2 , 'd':2 ,'e':2 }
</code></pre>
<p>Now i want to merge them with common keys and minimum value of the common keys, as after merging dict1[1] and dict1[2]</p>
<pre><code>aftermerging={'a':2 , 'd':2}
</code></pre>
<p>... | -1 | 2016-07-13T08:19:48Z | 38,346,288 | <p>You can use a <em>dictionary comprehension</em> that takes items from one dictionary if the keys exist in the other, and then apply <code>min</code> to the values of both:</p>
<pre><code>d = { 'a':3 , 'b':2 , 'c':1 , 'd':5 }
c = { 'a':2 , 'd':2 ,'e':2 }
r = {k: min(v, d[k]) for k,v in c.items() if k in d}
print(r)
... | 2 | 2016-07-13T08:23:08Z | [
"python",
"python-2.7",
"dictionary"
] |
to merge two dictionaries in python with common keys and min values | 38,346,216 | <p>I have two dictionaries</p>
<pre><code>dict1[1]={ 'a':3 , 'b':2 , 'c':1 , 'd':5 }
dict1[2]={ 'a':2 , 'd':2 ,'e':2 }
</code></pre>
<p>Now i want to merge them with common keys and minimum value of the common keys, as after merging dict1[1] and dict1[2]</p>
<pre><code>aftermerging={'a':2 , 'd':2}
</code></pre>
<p>... | -1 | 2016-07-13T08:19:48Z | 38,346,289 | <p>Using dict comprehension and set operations:</p>
<pre><code>{k:min(dict1[k],dict2[k]) for k in dict1.viewkeys() & dict2}
</code></pre>
| 1 | 2016-07-13T08:23:15Z | [
"python",
"python-2.7",
"dictionary"
] |
to merge two dictionaries in python with common keys and min values | 38,346,216 | <p>I have two dictionaries</p>
<pre><code>dict1[1]={ 'a':3 , 'b':2 , 'c':1 , 'd':5 }
dict1[2]={ 'a':2 , 'd':2 ,'e':2 }
</code></pre>
<p>Now i want to merge them with common keys and minimum value of the common keys, as after merging dict1[1] and dict1[2]</p>
<pre><code>aftermerging={'a':2 , 'd':2}
</code></pre>
<p>... | -1 | 2016-07-13T08:19:48Z | 38,346,423 | <pre><code>dict1 = {}
dict1[1]={ 'a':3 , 'b':2 , 'c':1 , 'd':5 }
dict1[2]={ 'a':2 , 'd':2 ,'e':2 }
aftermerging = { x:min(dict1[1][x],dict1[2][x]) for x in set(dict1[1]) & set(dict1[2]) }
print aftermerging
>> {'a':2 , 'd':2}
</code></pre>
| 0 | 2016-07-13T08:29:19Z | [
"python",
"python-2.7",
"dictionary"
] |
to merge two dictionaries in python with common keys and min values | 38,346,216 | <p>I have two dictionaries</p>
<pre><code>dict1[1]={ 'a':3 , 'b':2 , 'c':1 , 'd':5 }
dict1[2]={ 'a':2 , 'd':2 ,'e':2 }
</code></pre>
<p>Now i want to merge them with common keys and minimum value of the common keys, as after merging dict1[1] and dict1[2]</p>
<pre><code>aftermerging={'a':2 , 'd':2}
</code></pre>
<p>... | -1 | 2016-07-13T08:19:48Z | 38,351,252 | <p>Here is a solution for your question <strong>To merge two dictionaries in python with common keys and min values.</strong></p>
<p>I am going to split this problem into two parts.</p>
<p>1) Find the common keys.</p>
<p>2) Use those common keys to find the common key min value.</p>
<p><strong>Find the common keys<... | 0 | 2016-07-13T12:04:00Z | [
"python",
"python-2.7",
"dictionary"
] |
Using Scrapy's LinkExtractor | 38,346,296 | <p>I'm trying to extract all links from a page using Scrapy, but am struggling to use the LinkExtractor. I've tried the following:</p>
<pre><code>import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from Funda.items import FundaItem
class FundaSpider(scrapy.Spider... | 0 | 2016-07-13T08:23:36Z | 38,346,564 | <p>Why would you think it would contain only links? </p>
<p>I think you are misunderstanding the <code>CrawlSpider</code> and the <code>rule</code> argument. Within <code>rule</code> you actually specify crawling logic rather than parsing logic. Parsing is being handled in the function specified the <code>callback</co... | 1 | 2016-07-13T08:36:19Z | [
"python",
"scrapy"
] |
To find the disparity map for an stereo image pair | 38,346,338 | <p>Please look into the following error and give me a solution. The code talks about stereo matching.</p>
<p>Results: display the disparity map</p>
<pre><code>import numpy as np
import cv2
imgL=cv2.imread('C:\Users\harsha\Desktop\stereo vision\images_stereo_1\cam2_object3.jpg')
imgR=cv2.imread('C:\Users\harsha\Deskt... | -1 | 2016-07-13T08:25:34Z | 38,348,165 | <p>If you had only looked at your error, you would have seen that you are not passing a valid <code>disptype</code>.</p>
<p>Change </p>
<pre><code>disp=stereo.compute(imgL,imgR,disptype=cv2.CV_8UC1)
</code></pre>
<p>to </p>
<pre><code>disp=stereo.compute(imgL,imgR,disptype=cv2.CV_32F)
</code></pre>
| 0 | 2016-07-13T09:49:14Z | [
"python",
"python-2.7",
"opencv",
"image-processing"
] |
How to specify port number using mysql-connector-python (error 2003) | 38,346,392 | <p>I am trying to connect via SSH to a MySQL server from my local Windows machine. The SSH connection works fine, but I am unable to connect to the MySQL server when running the following Python script:</p>
<pre><code>import mysql.connector
import sys
import time
import paramiko
host = 'remote-ssh-host'
i = 1
while ... | 0 | 2016-07-13T08:27:48Z | 38,346,950 | <p>The problem is that your ssh and MySQL connections are completely separated. In order for your MySQL connection to work through ssh, you need to <strong>tunnel</strong> the MySQL connection through the ssh one.</p>
<p>The <a href="http://stackoverflow.com/questions/30188796/connecting-to-mysql-database-via-ssh">fir... | 0 | 2016-07-13T08:53:58Z | [
"python",
"mysql",
"ssh",
"mysql-connector-python"
] |
Control the verbosity of Flask's tests | 38,346,405 | <p>I'm running tests for my Flask app from Bash using <code>python manage.py test</code>. In addition to failures and errors, the console prints out</p>
<pre><code> test_name (test_file.TestClass) ... ok
</code></pre>
<p>for every single test. That's super annoying when you have a lot of tests. How can I control t... | 0 | 2016-07-13T08:28:27Z | 38,347,573 | <p>@jonrsharpe was right. I didn't realize that the project was using Flask-Script, which I guess is the reason for the manage.py file. Flask-Script calls unittest with a default verbosity. I reduced the default verbosity and that culled the extra output. </p>
| 0 | 2016-07-13T09:21:57Z | [
"python",
"flask"
] |
Django Generic View form_valid Cannot set values on a ManyToManyField which specifies an intermediary model | 38,346,485 | <p>I have three Tables in a many-to-many-relationship, a Product table, a Server table and an intemediary table to link the two objects together. </p>
<p>Each Server can have many products, and each product can be associated with more than one server.</p>
<p>Here are my models</p>
<pre><code>#/myapp/models.py
class... | 1 | 2016-07-13T08:32:35Z | 38,347,442 | <p>The traceback shows that the error is occurring when you call <code>super()</code> in the <code>form_valid</code> method. </p>
<pre><code>File "/home/jwe/piesup2/reports/views.py" in form_valid
182. return super(ServerCreateView, self).form_valid(form)
</code></pre>
<p>You are already saving the form in... | 1 | 2016-07-13T09:16:08Z | [
"python",
"django",
"many-to-many"
] |
Get Resolution for each Render Layer | 38,346,542 | <p>I want to get the Rendering Resolution for each Renderlayer in my Maya Project. I am using Maya 2016 with SP 5.</p>
<p>I know that you can get the Resolution of the current selected Renderlayer with the following commands:</p>
<pre><code>width = maya.cmds.getAttr("defaultResolution.width")
height = maya.cmds.getAt... | 0 | 2016-07-13T08:35:32Z | 38,350,893 | <p>you could try evalDeferred() command.</p>
<pre><code>def test():
renderlayers = cmds.ls(type="renderLayer")
for layer in renderlayers:
print layer
#select the render layer
cmds.editRenderLayerGlobals(crl=layer)
#get resolution values
... | 1 | 2016-07-13T11:48:21Z | [
"python",
"maya"
] |
Compare two words (full name) to an article text in Python | 38,346,551 | <p>Given a list of Full Names (First + Surname), how do your find the frequency that the names come up in a Text Article?</p>
<p>I am trying to find an efficient way of comparing the 'First Name' and 'Surname' of a person to a body of text. In this situation the body of text is a News Article and the names are of Aust... | 1 | 2016-07-13T08:35:59Z | 38,347,123 | <p>try this : </p>
<pre><code>[x for x in politicianName if x in article and x is not'']
</code></pre>
<p>Input : </p>
<pre><code>politicianName = open("politicianName.txt").read().split('\n')
article = 'Jacinta Allan this is an articletext scraped with urllib2'
</code></pre>
<p>Out put :</p>
<pre><code>['Jacinta... | 0 | 2016-07-13T09:01:53Z | [
"python",
"string",
"python-2.7",
"web-scraping"
] |
Compare two words (full name) to an article text in Python | 38,346,551 | <p>Given a list of Full Names (First + Surname), how do your find the frequency that the names come up in a Text Article?</p>
<p>I am trying to find an efficient way of comparing the 'First Name' and 'Surname' of a person to a body of text. In this situation the body of text is a News Article and the names are of Aust... | 1 | 2016-07-13T08:35:59Z | 38,347,331 | <p>How about just splitting it altogether?</p>
<p><code>politicianName = [v for i in open("politicianName.txt").read().split('\n') for v in i.split()]</code></p>
<p>And then try the following</p>
<pre><code>article = 'Jacinta Allan this is an articletext scraped with urllib2'
getNames(article)
article = 'Allan, Jac... | 0 | 2016-07-13T09:11:38Z | [
"python",
"string",
"python-2.7",
"web-scraping"
] |
Data not appearing in database after form submission | 38,346,574 | <p>I have created an HTML form trying to do simple registration.</p>
<p>The problem is that after clicking submit button no error appears but when I chech database the data from fields is not there.</p>
<p>signup.html</p>
<pre><code><form action="\polls\Registration" method="POST">
<div class=... | 0 | 2016-07-13T08:36:55Z | 38,350,678 | <p>[SOLVED]
What I did is that I created a model to handle form processing.I also used modelForm instead of forms. For anyone having same issue check <a href="https://docs.djangoproject.com/en/1.9/topics/forms/" rel="nofollow">this</a></p>
| 0 | 2016-07-13T11:38:16Z | [
"python",
"django",
"python-2.7"
] |
Debuggin with pdb within a conda environment | 38,346,577 | <p>I'm developing in python inside a Conda environment. All the packages I add to the environment can be imported successfully when running the "python" binary created under the environment. However, when trying to debug with pdb any of my python scripts I would get ImportError for the very same packages.</p>
<p>For e... | 0 | 2016-07-13T08:37:00Z | 38,374,776 | <p>Copy <code>pdb</code> executable to your environment, and set the shebang (first line) from <code>#!/usr/bin/python</code> to <code>#!/usr/bin/env python</code>. If you want this to be the default behavior for any environment (including the system pdb), you can change the shebang only in <code>/usr/bin/pdb</code>.</... | 0 | 2016-07-14T12:52:20Z | [
"python",
"anaconda",
"pdb"
] |
Inline expression using for and if loops | 38,346,621 | <p>Here is the question:</p>
<pre><code>input = array([ 0. , 0.5, 1. , 1.5])
</code></pre>
<p>Required output: any value <code>> 1</code> should be set to <code>1</code></p>
<pre><code>array([ 0. , 0.5, 1. , 1])
</code></pre>
<p>My current program</p>
<pre><code>import numpy as np
input = np.arange... | 0 | 2016-07-13T08:38:45Z | 38,346,710 | <pre><code>output = [1 if i > 1 else i for i in input]
</code></pre>
<p>It's called <a href="http://www.pythonforbeginners.com/basics/list-comprehensions-in-python" rel="nofollow">list comprehension</a></p>
<p>This create a new list that populate (conceptually) like this:</p>
<pre><code>output = []
for i in input... | 0 | 2016-07-13T08:42:31Z | [
"python",
"python-3.x"
] |
Execute a function every certain time without counting the time of execution of the function | 38,346,633 | <p>I need execute since an specific time a function every certain interval of time. </p>
<p>For example if the begining time is 00:00:00 and the the interval is 5 seconds then I need that the times of execution of this function are:</p>
<pre><code>00:00:00
00:00:05
00:00:10
00:00:15
...
23:59:55
</code></pre>
<p>As... | 0 | 2016-07-13T08:39:09Z | 38,346,741 | <p>I believe that you are better off relying on the OS to do the scheduling than on Python. It will be simplier to have a simple script with a single function and then use crontab (if using Linux) or Windows Task Scheduler to schedule the execution.</p>
<p>One of the reasons to prefer the OS approach is robustness. Fo... | 3 | 2016-07-13T08:43:57Z | [
"python",
"timer",
"scheduled-tasks"
] |
Component not appearing in Tkinter Python interface | 38,346,640 | <p>I just start developping in Python to do some interface with Tkinter.
There is so many way to do an interface, so I would like to know if the structure of my code is correct.
Also, I can run my script without error. But, it didn't show me the label ,Hello, world".</p>
<p>Can you explain me what is wrong ?</p>
<pre... | -1 | 2016-07-13T08:39:23Z | 38,346,745 | <p>Your Frame (<code>class MyFrame</code>) is never packed. Use <code>self.pack()</code> inside your init to display it or pack it inside your main before calling mainloop on it. </p>
<p>The rest looks okay so far.</p>
<p>As you are using tkinter (so python3) i personally would consider using </p>
<p><code>"some tex... | 2 | 2016-07-13T08:44:06Z | [
"python",
"tkinter",
"interface"
] |
Can I search a slice of a string in Python but keep the index relative to the original string? | 38,346,667 | <p>I have a large string. I regularly have to search only parts of this string, but I do need to now where in the large string the bits found in the slices are found. </p>
<p>Is there a way to use a 'mask' on a string? That is</p>
<pre><code>original = 'This is a mock-up large string'
a_slice = original[10:23]
a_slic... | 3 | 2016-07-13T08:40:37Z | 38,346,718 | <p><code>str.find</code> takes option arguments as to where to start/end the search, eg:</p>
<pre><code>original = 'This is a mock-up large string'
o = original.find('o', 10, 23)
# 11
</code></pre>
<p>From the docs:</p>
<blockquote>
<p>find(...)</p>
<pre><code>S.find(sub [,start [,end]]) -> int
Return the low... | 6 | 2016-07-13T08:42:54Z | [
"python",
"regex",
"string",
"standard-library"
] |
Can I search a slice of a string in Python but keep the index relative to the original string? | 38,346,667 | <p>I have a large string. I regularly have to search only parts of this string, but I do need to now where in the large string the bits found in the slices are found. </p>
<p>Is there a way to use a 'mask' on a string? That is</p>
<pre><code>original = 'This is a mock-up large string'
a_slice = original[10:23]
a_slic... | 3 | 2016-07-13T08:40:37Z | 38,347,049 | <p>Like requested, if you want to use finditer (which returns an iterator of Match-objects):</p>
<pre><code>>>> import re
>>> original = 'This is a mock-up large string'
>>> p = re.compile('o')
>>> for match in p.finditer(original, 10, 23):
... print match.pos
10
</code></pre>
<p>... | 1 | 2016-07-13T08:58:44Z | [
"python",
"regex",
"string",
"standard-library"
] |
time slice on second level of multiindex | 38,346,668 | <p>pandas allows for cool slicing on time indexes. For example, I can slice a dataframe <code>df</code> for the months from Janurary 2012 to March 2012 by doing:</p>
<pre><code>df['2012-01':'2012-03']
</code></pre>
<p>However, I have a dataframe <code>df</code> with a multiindex where the time index is the second le... | 5 | 2016-07-13T08:40:41Z | 38,346,697 | <p>Use <code>pd.IndexSlice</code></p>
<pre><code>df.loc[pd.IndexSlice[:, '2001-01':'2001-3'], :]
</code></pre>
<p><a href="http://i.stack.imgur.com/6bch2.png"><img src="http://i.stack.imgur.com/6bch2.png" alt="enter image description here"></a></p>
| 5 | 2016-07-13T08:41:54Z | [
"python",
"pandas",
"multi-index",
"datetimeindex"
] |
pywinauto to get MessageBox message content | 38,346,783 | <p>I've googled but did not find the answer.
In <strong>python 2.7, Windows</strong>, it is easy to get TextBox content or MessageBox title by</p>
<pre><code>app.Dialog.Edit.WindowText()
app.Dialog.WindowText()
</code></pre>
<p>But I cannot figure out how to get the message content, as in the pic:
<a href="http://i.s... | 0 | 2016-07-13T08:45:57Z | 38,347,175 | <p>It's not an edit box. Use the following:</p>
<pre><code> app.Dialog.Static1.WindowText()
</code></pre>
<p>or</p>
<pre><code> app.Dialog.Static2.WindowText()
</code></pre>
<p>if message box contains an icon (it would be matched as <code>Static1</code>).</p>
| 1 | 2016-07-13T09:03:59Z | [
"python",
"windows",
"ui-automation",
"messagebox",
"pywinauto"
] |
How to iterate for loop in django python template | 38,346,842 | <p>I am currently creating a template and I want to iterate a list however this is going to be tricky because I would like to display only 5 items per line then the next items will go to the next line. I would Like the display an image between every 5 items.</p>
<p>this is my list:</p>
<pre><code> myList = [{'id':... | 0 | 2016-07-13T08:48:34Z | 38,346,954 | <p>You need to use the <a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#divisibleby" rel="nofollow">divisibleby</a> filter</p>
<pre><code>{% if forloop.counter0|divisibleby:5 %}
</code></pre>
| 1 | 2016-07-13T08:54:07Z | [
"python",
"django",
"templates"
] |
How to iterate for loop in django python template | 38,346,842 | <p>I am currently creating a template and I want to iterate a list however this is going to be tricky because I would like to display only 5 items per line then the next items will go to the next line. I would Like the display an image between every 5 items.</p>
<p>this is my list:</p>
<pre><code> myList = [{'id':... | 0 | 2016-07-13T08:48:34Z | 38,347,100 | <p>You can use <code>divisibleby</code> like this:
{% for a in myList %}</p>
<pre><code><a href="{{a.image}}">{{a.id}}</a>
{% if forloop.counter0|divisibleby:5 %}
<img src="{{a.image}}">
{% endif %}
{% endfor %}
</code></pre>
<p><a href="https://docs.djangoproject.com/en/dev/ref/templates/bui... | 1 | 2016-07-13T09:00:47Z | [
"python",
"django",
"templates"
] |
Tensorflow - feeding examples with different length | 38,346,983 | <p>Each of my training examples is a list with different length.
I am trying to find a way to feed those examples into the graph.
Below is my attempt to do so by creating a list whose elements are placeholders with unknown dimensions.</p>
<pre><code>graph2 = tf.Graph()
with graph2.as_default():
A = list ()
for... | 1 | 2016-07-13T08:55:37Z | 38,355,747 | <p>From the documentation of <code>tf.placeholder</code>:</p>
<blockquote>
<p><strong>shape</strong>: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.</p>
</blockquote>
<p>You need to write <code>shape=None</code> instead of <code>shape=[None, None]</c... | 0 | 2016-07-13T15:20:22Z | [
"python",
"tensorflow"
] |
How to "install" a python program? | 38,347,050 | <p>this is a pretty basic question but I'm not really finding any answer, maybe my keywords are wrong...</p>
<p>I've been programming in Python for a little while now and I made a few scripts that are good enough to be deployed in the department where I am working. So... Am I going to have to make everyone install Pyt... | 0 | 2016-07-13T08:58:44Z | 38,347,178 | <p>Python official docs have a lot of info about this.</p>
<p>For 3.x.x <a href="https://docs.python.org/2/distutils/builtdist.html" rel="nofollow">Setup script</a></p>
<p>For 2.7.x <a href="https://docs.python.org/2/distutils/builtdist.html" rel="nofollow">Built dist</a></p>
| 0 | 2016-07-13T09:04:03Z | [
"python"
] |
How to "install" a python program? | 38,347,050 | <p>this is a pretty basic question but I'm not really finding any answer, maybe my keywords are wrong...</p>
<p>I've been programming in Python for a little while now and I made a few scripts that are good enough to be deployed in the department where I am working. So... Am I going to have to make everyone install Pyt... | 0 | 2016-07-13T08:58:44Z | 38,347,333 | <p>It's possible to create a module, as if it's intended for pip, that you do not publish on PyPI, but allow people to install locally.</p>
<p>For example, observe this project on GitHub: <a href="https://github.com/pyjokes/pyjokes" rel="nofollow">pyjokes</a>. It's available on PyPI so you can pip install it. But you ... | 3 | 2016-07-13T09:11:39Z | [
"python"
] |
Fetching objects in complex through relationship Django | 38,347,150 | <p>I have been trying numerous things to solve the following in Django object filtering but thus no luck.</p>
<p>Utalizing a primary key for an individual, I would like to build an object list of all their milestones. </p>
<p>My models are laid out as such:</p>
<pre><code>TEAM MEMBER -- owns many tasks through -->... | 0 | 2016-07-13T09:03:04Z | 38,347,295 | <p>You need to use multiple double.underscore steps. Actual code depends on your exact model and field names.
Something like:
<code>Milestones.objects.filter(task__owner__teammember__id=1)</code></p>
| 1 | 2016-07-13T09:09:55Z | [
"python",
"django",
"django-models"
] |
Fetching objects in complex through relationship Django | 38,347,150 | <p>I have been trying numerous things to solve the following in Django object filtering but thus no luck.</p>
<p>Utalizing a primary key for an individual, I would like to build an object list of all their milestones. </p>
<p>My models are laid out as such:</p>
<pre><code>TEAM MEMBER -- owns many tasks through -->... | 0 | 2016-07-13T09:03:04Z | 38,347,884 | <p>I you want to get milestone data for a particular member , you can get it by defining the fields in value queryset as follows:</p>
<pre><code>TeamMember.objects.filter(id=1).values
('task__milestone','owner__task__milestone',
'task__milestone__expected_date','task__milestone__name')
</code></pre>
<p>I did not test... | 0 | 2016-07-13T09:36:49Z | [
"python",
"django",
"django-models"
] |
Python MNE: how to compute continuous wavelets? | 38,347,224 | <p>The <a href="http://martinos.org/mne/stable/generated/mne.time_frequency.cwt_morlet.html#mne.time_frequency.cwt_morlet" rel="nofollow">Python MNE API</a> says I should compute continuous wavelets by</p>
<pre><code>mne.time_frequency.cwt_morlet(X, sampling_frequency, frequencies_of_interest)
</code></pre>
<p>Howeve... | 0 | 2016-07-13T09:06:38Z | 38,634,090 | <p>As the documentation says, this function operates on NumPy arrays, not on instances of Raw. This means you have to get the data out of the Raw object. You can use the <code>get_data()</code> method for that:</p>
<pre><code>mne.time_frequency.cwt_morlet(X.get_data(), X.info['sfreq'], frequencies_of_interest)
</code>... | 0 | 2016-07-28T10:44:48Z | [
"python"
] |
StandardScaler on list with matrix as list element | 38,347,225 | <p>I have a List with patients. Each patient has a (n x m) matrix with values.</p>
<p><a href="http://i.stack.imgur.com/epksU.png" rel="nofollow"><img src="http://i.stack.imgur.com/epksU.png" alt="enter image description here"></a></p>
<p>Now I want to normalize the data over all patients with mean/std using the Stan... | 0 | 2016-07-13T09:06:39Z | 38,347,599 | <p>Suppose you have an array of patient data matrices like this:</p>
<pre><code>my_patient_data_X
</code></pre>
<p>Then you can do this:</p>
<pre><code>my_patient_data_X = [StandardScaler().fit_transform(X) for X in my_patient_data_X]
</code></pre>
<p>Would this achieve what you want?</p>
| 1 | 2016-07-13T09:23:30Z | [
"python",
"matrix",
"scikit-learn",
"scaling"
] |
How can I force my leastsq function from scipy.optimize to be superior than each data points | 38,347,262 | <p>I am currently trying to calculate a function to fit some data points using leastsq method from <code>scipy.optimize</code>.</p>
<p>The function I'm looking for is something like <code>f(x) = A * cos(b*x + c)</code>, with A, b, c the parameters i would to know.</p>
<p>My code is so far:</p>
<pre><code>def residua... | 1 | 2016-07-13T09:08:33Z | 38,352,471 | <p>One approach is to formulate your problem from scratch as a constrained optimization problem and solve it via, e.g., scipy.optimize.minimize.</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize
# data set
x = np.arange(-8, 9)
y = np.array([0.060662282, 0.25381372, ... | 2 | 2016-07-13T12:58:41Z | [
"python",
"numpy",
"optimization",
"scipy"
] |
Cannot find plot function in GPy library (python) | 38,347,340 | <p>I am using the <a href="https://github.com/SheffieldML/GPy" rel="nofollow" title="GPy">GPy</a> library in Python 2.7 to perform Gaussian Process regressions. I started by following the tutorial notebooks provided in the GitHub page. </p>
<p>Sample code : </p>
<pre><code>import numpy as np
import matplotlib.pyplot ... | 4 | 2016-07-13T09:12:01Z | 38,416,159 | <p>The plotting library gets "injected" in GPy/GPy/plotting/__init__.py's <a href="https://github.com/SheffieldML/GPy/blob/v1.0.9/GPy/plotting/__init__.py#L36" rel="nofollow"><code>inject_plotting()</code></a>. Here the line for <code>plot()</code>:</p>
<pre><code> from ..core import GP
...
GP.plot = gpy_p... | 2 | 2016-07-16T22:17:25Z | [
"python",
"python-2.7"
] |
How to keep matplotlib plots alive after process ends | 38,347,483 | <p>Comrades, </p>
<p>I have a function that should generate some matplotlib plots and then terminate. I want the plots to remain after it terminates.</p>
<ul>
<li>If I set interactive mode on, the plot appears, does not block, and then disappears when my function terminates. I don't want this.</li>
<li>If I set int... | 0 | 2016-07-13T09:18:01Z | 38,348,961 | <p>It should work, but yours is behaving as if show() is not blocking. Try adding plt.ioff() as in the below. </p>
<pre><code>from multiprocessing import Process
import matplotlib.pyplot as plt
import numpy as np
def plot_graph():
plt.plot(np.random.randn(10))
plt.show()
plt.ioff()
p = Process(target=plot_gr... | 0 | 2016-07-13T10:23:03Z | [
"python",
"matplotlib",
"plot"
] |
how to write my AWS lambda function? | 38,347,594 | <p>I am new to AWS lambda function and i am trying to add my existing code to AWS lambda. My existing code looks like :</p>
<pre><code>import boto3
import slack
import slack.chat
import time
import itertools
from slacker import Slacker
ACCESS_KEY = ""
SECRET_KEY = ""
slack.api_token = ""
slack_channel = "#my_test_cha... | 0 | 2016-07-13T09:23:06Z | 38,348,084 | <p>You have to make a zipped package consisting of your python script containing the lambda function and all the modules that you are importing in the python script. Upload the zipped package on aws.</p>
<p>Whatever module you want to import, you have to include that module in the zip package. Only then the import sta... | 2 | 2016-07-13T09:44:35Z | [
"python",
"python-2.7",
"amazon-web-services",
"aws-lambda",
"boto3"
] |
how to write my AWS lambda function? | 38,347,594 | <p>I am new to AWS lambda function and i am trying to add my existing code to AWS lambda. My existing code looks like :</p>
<pre><code>import boto3
import slack
import slack.chat
import time
import itertools
from slacker import Slacker
ACCESS_KEY = ""
SECRET_KEY = ""
slack.api_token = ""
slack_channel = "#my_test_cha... | 0 | 2016-07-13T09:23:06Z | 38,348,114 | <p>You receive an error because AWS lambda does not have any information about a module called slack. </p>
<p>A module is a set of .py files that are stored somewhere on a computer.
In case of lambda, you should import all your libraries by creating a deployment package.</p>
<p>Here is an another question that descri... | 1 | 2016-07-13T09:46:29Z | [
"python",
"python-2.7",
"amazon-web-services",
"aws-lambda",
"boto3"
] |
Selecting every alternate group of n columns - NumPy | 38,347,664 | <p>I would like to select every nth group of n columns in a numpy array. It means that I want the first n columns, not the n next columns, the n next columns, not the n next columns etc. </p>
<p>For example, with the following array and <code>n=2</code>:</p>
<pre><code>import numpy as np
arr = np.array([[1, 2, 3, 4... | 2 | 2016-07-13T09:26:24Z | 38,348,200 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.mod.html" rel="nofollow"><code>modulus</code></a> to create ramps starting from <code>0</code> until <code>2n</code> and then select the first <code>n</code> from each such ramp. Thus, for each ramp, we would have first <code>n</code> as ... | 3 | 2016-07-13T09:50:38Z | [
"python",
"arrays",
"numpy"
] |
How would python recognise if a string is in the right format? (LLNN.LLL) | 38,347,666 | <p>I am trying to write a program that would check if the letters and numbers in a string are in the right order, and the example I am using to write it is a car registration plate. Is it possible to check if the letters and numbers in a string correspond to a format of where they are in relation to each other?</p>
<p... | -1 | 2016-07-13T09:26:30Z | 38,347,875 | <p>You should have a look at <a href="https://docs.python.org/2/library/re.html" rel="nofollow">regular expressions</a></p>
<p>For example number plates in my country are 3 letters and 3 numbers (ABC-123) so the regex string would be <code>([a-zA-Z]{3})-([0-9]{3})</code></p>
<p>You can use <a href="http://pythex.org/... | 2 | 2016-07-13T09:36:24Z | [
"python",
"string"
] |
How would python recognise if a string is in the right format? (LLNN.LLL) | 38,347,666 | <p>I am trying to write a program that would check if the letters and numbers in a string are in the right order, and the example I am using to write it is a car registration plate. Is it possible to check if the letters and numbers in a string correspond to a format of where they are in relation to each other?</p>
<p... | -1 | 2016-07-13T09:26:30Z | 38,347,967 | <p>I try to give an answer but it is likely that this is not what you want:</p>
<pre><code>import re
string1 = "(LLNN.LLL)"
string2 = "(abcdefgh)"
reg = re.compile(r'\([LN]{4}\.[LN]{3}')
print bool(re.match(reg, string1))
print bool(re.match(reg, string2))
</code></pre>
<p>This matches all the strings that consist of... | 0 | 2016-07-13T09:40:11Z | [
"python",
"string"
] |
How would python recognise if a string is in the right format? (LLNN.LLL) | 38,347,666 | <p>I am trying to write a program that would check if the letters and numbers in a string are in the right order, and the example I am using to write it is a car registration plate. Is it possible to check if the letters and numbers in a string correspond to a format of where they are in relation to each other?</p>
<p... | -1 | 2016-07-13T09:26:30Z | 38,348,042 | <p>this code takes the registration something like xjk649 and tests it, and prints when its false:</p>
<pre><code>iReg = input('Registration: ')
test = ''
for i in range(0,len(iReg)-3):
if 'abcdefghijklmnopqrstuvwxyz'.find(iReg[i]) != -1:
print('succes first three charracters')
else:
test = 'W... | 0 | 2016-07-13T09:42:57Z | [
"python",
"string"
] |
Have a class have access to a parameter from another class | 38,347,773 | <p>I have two classes, <code>classA</code> and <code>classB</code>. <code>classA</code> has an attribute named <code>image</code> that contains data that is changing all the time. I want to be able to have an instance of <code>classB</code> that when I call a method on this instance, it can access <code>self.image</cod... | -3 | 2016-07-13T09:31:45Z | 38,348,031 | <p>There are two problems with your code:</p>
<ol>
<li><p><code>analysis</code> is a variable local to the <code>classA.__init__</code> and <code>classA.doingstuff</code> functions. If you wish to re-use it in other functions, you should define it as an attribute: <code>self.analysis = classB(self)</code>.</p></li>
<l... | 1 | 2016-07-13T09:42:33Z | [
"python",
"oop"
] |
Recursively replacing items in a list with items of a different list | 38,347,827 | <p>I've implemented the exact same functionality with recursions, I also want a version without recursion as Python has a recursion limit and there are problems while sharing data.</p>
<pre><code>sublist2 = [{'nothing': "Notice This"}]
sublist1 = [{'include':[sublist2]}]
mainlist = [{'nothing': 1}, {'include':[sublis... | 1 | 2016-07-13T09:34:08Z | 38,348,487 | <p>Instead of using recursion, you just look at the nth element and change it in place until it doesn't need any further processing.</p>
<pre><code>sublist2 = [{'nothing': "Notice This"}]
sublist1 = [{'include':[sublist2]}]
mainlist = [{'nothing': 1}, {'include':[sublist1, sublist2]},
{'nothing': 2}, {'in... | 2 | 2016-07-13T10:02:32Z | [
"python",
"list",
"dictionary"
] |
Python - Searching JSON | 38,347,855 | <p>I have JSON output as follows:</p>
<pre><code>{
"service": [{
"name": ["Production"],
"id": ["256212"]
}, {
"name": ["Non-Production"],
"id": ["256213"]
}]
}
</code></pre>
<p>I wish to find all ID's where the pair contains "Non-Production" as a name.</p>
<p>I was thinking along the lines of runnin... | 0 | 2016-07-13T09:35:34Z | 38,347,974 | <p>Here you go:</p>
<pre><code>data = {
"service": [
{"name": ["Production"],
"id": ["256212"]
},
{"name": ["Non-Production"],
"id": ["256213"]}
]
}
for item in data["service"]:
if "Non-Production" in item["name"]:
print(item["id"])
</code></pre>
| 1 | 2016-07-13T09:40:40Z | [
"python",
"json"
] |
Python - Searching JSON | 38,347,855 | <p>I have JSON output as follows:</p>
<pre><code>{
"service": [{
"name": ["Production"],
"id": ["256212"]
}, {
"name": ["Non-Production"],
"id": ["256213"]
}]
}
</code></pre>
<p>I wish to find all ID's where the pair contains "Non-Production" as a name.</p>
<p>I was thinking along the lines of runnin... | 0 | 2016-07-13T09:35:34Z | 38,348,221 | <p>Whatever I see <code>JSON</code> I think about functionnal programming ! Anyone else ?!
I think it is a better idea if you use function like concat or flat, filter and reduce, etc.</p>
<p>Egg one liner:</p>
<pre><code>[s.get('id', [0])[0] for s in filter(lambda srv : "Non-Production" not in srv.get('name', []), da... | 0 | 2016-07-13T09:51:33Z | [
"python",
"json"
] |
python- behave: generate step functionality throws list index out of range | 38,347,861 | <p>this is my first question here, so any tips on improvement on that are welcome :)</p>
<p>I am figuring out how to write tests using: Sublime Text 3, python, and behave.</p>
<p>What works now is that my feature file is recognised: has all the right colours, as far as I can tell.</p>
<p>Now next I want to generate ... | 0 | 2016-07-13T09:35:48Z | 38,424,257 | <p>On the "Getting Started" page of the Sublime plugin Behave Toolkit's <a href="http://behavetoolkit.readthedocs.io/en/latest/gettingstarted.html" rel="nofollow">documentation</a>, the very first thing it talks about is setting up your project's directory, <em>then opening it in Sublime.</em> You are getting this erro... | 0 | 2016-07-17T17:55:15Z | [
"python",
"sublimetext3",
"python-behave"
] |
Dictionary in list in dictionnary with Python | 38,347,965 | <p>For a project, I have a dictionary in a list itself in a dictionary.
But I don't know how print the last dictionary...</p>
<blockquote>
<pre><code>dic = {
"Serial" : "test"
"servers":
[
"url" : "http://foo.com"
"service" : #it's this I want to print
{
"url" : "http://servi... | -3 | 2016-07-13T09:40:06Z | 38,348,111 | <p>change your dictionary to </p>
<pre><code>dic = {"Serial" : "test","servers":[{"url" : "http://foo.com","service" :{"url" : "http://service1.com","expected_code" : 200}}]}
</code></pre>
<p>then <code>dic['servers'][0]['service']</code> will give you desired output</p>
| 0 | 2016-07-13T09:46:09Z | [
"python",
"python-2.7"
] |
Dictionary in list in dictionnary with Python | 38,347,965 | <p>For a project, I have a dictionary in a list itself in a dictionary.
But I don't know how print the last dictionary...</p>
<blockquote>
<pre><code>dic = {
"Serial" : "test"
"servers":
[
"url" : "http://foo.com"
"service" : #it's this I want to print
{
"url" : "http://servi... | -3 | 2016-07-13T09:40:06Z | 38,348,331 | <p>Your list is not valid.</p>
<p>Try something like that :</p>
<pre><code>dic = {"Serial" : "test", "servers" : [{"url" : "http://foo.com", "service" : {"url" : "http://service1.com", "expected_code" : 200}}]}
</code></pre>
<p>And then you will be able to print your last dict :</p>
<pre><code>dic['servers'][0]['se... | 0 | 2016-07-13T09:55:16Z | [
"python",
"python-2.7"
] |
Moving a bound ZMQ socket to another process | 38,348,268 | <p>I have a Python program which spawns several other Python programs as subprocesses. One of these subprocesses is supposed to open and bind a ZMQ publisher socket, such that other subprocesses can subscribe to it.</p>
<p>I cannot give guarantees about which tcp ports will be available, so when I bind to a random por... | 0 | 2016-07-13T09:52:58Z | 38,349,487 | <h2>The simplest is to create a logic for a pool-of-ports manager<br><sub> ( rather avoid attempts to share / pass <code>ZeroMQ</code> sockets to / among other processes ) </sub></h2>
<p>One may create a persistent, a-priori known, <strong><code>tcp://A.B.C.D:8765</code></strong>-transport-class based <strong><code>.b... | 1 | 2016-07-13T10:46:48Z | [
"python",
"sockets",
"zeromq"
] |
Is it possible to overwrite existing data in .xlsx file with openpyxl? | 38,348,272 | <p>Say I want to update som data in example1.xlsx.
Is this possible to do using openpyxl without having to save it as a new file?</p>
| -1 | 2016-07-13T09:53:08Z | 38,349,211 | <p>As far as I can tell you can open a workbook with openpyxl, modify some data, then save the workbook in place:</p>
<pre><code>wb = openpyxl.load_workbook('path\\to\\workbook.xlsx')
c = wb['Sheet1']['A1']
c.value = 'hello'
wb.save('path\\to\\workbook.xlsx')
</code></pre>
<p>If you're saying that your workbook is to... | 1 | 2016-07-13T10:33:44Z | [
"python",
"excel",
"python-2.7",
"python-3.x",
"openpyxl"
] |
OpenCV Python: find contours/edges/rectangle in an image | 38,348,322 | <p>I am using Python2.7.12 and OpenCV 3.0.0-rc1</p>
<p>I am working on a Text Recognition project.</p>
<p>This is what I got right now.
<a href="http://i.stack.imgur.com/FTfki.png" rel="nofollow">Original iamge after findContour, line 34</a></p>
<p>As you can see, the image contains a lot of 'boxes', in which there ... | 0 | 2016-07-13T09:54:57Z | 38,350,603 | <p>You are only getting the outermost contour because you specified <code>cv2.RETR_EXTERNAL</code>. To get all the contours of the image, you should call the method like this:</p>
<pre><code>cv2.findContours(thresh.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
</code></pre>
<p>Take a look at <a href="http://docs.op... | 0 | 2016-07-13T11:35:21Z | [
"python",
"opencv",
"computer-vision",
"ocr",
"tesseract"
] |
Can't seem to retrieve stripe charge using python | 38,348,373 | <p>I have the following python code to create a charge in stripe.</p>
<pre><code>a_charge = stripe.Charge.create(
amount=cents,
currency="usd",
source=token,
description="my_description",
application_fee=application_fee,
stripe_account=teacher_stripe_id
)
</code></pre>
<p>This succeeds (I think), because it shows up... | 3 | 2016-07-13T09:56:56Z | 38,348,757 | <p>Why do you need to do <code>stripe.Charge.retrieve(a.charge.id)</code> immediately after creating the charge while you already have the data within <code>a_charge</code>?</p>
<p>It is possible that data are cached and/or broadcasted to multiple servers/databases. Newly created data may then take a few seconds to be... | 1 | 2016-07-13T10:13:22Z | [
"python",
"django",
"stripe-payments"
] |
Can't seem to retrieve stripe charge using python | 38,348,373 | <p>I have the following python code to create a charge in stripe.</p>
<pre><code>a_charge = stripe.Charge.create(
amount=cents,
currency="usd",
source=token,
description="my_description",
application_fee=application_fee,
stripe_account=teacher_stripe_id
)
</code></pre>
<p>This succeeds (I think), because it shows up... | 3 | 2016-07-13T09:56:56Z | 38,354,799 | <p>The code you're using here is creating a charge directly on a connected Stripe account. This is covered in Stripe's documentation <a href="https://stripe.com/docs/connect/payments-fees#charging-directly" rel="nofollow">here</a>.</p>
<p>Since the charge is on a connected account, it doesn't exist on your own Stripe ... | 1 | 2016-07-13T14:40:14Z | [
"python",
"django",
"stripe-payments"
] |
Can't seem to retrieve stripe charge using python | 38,348,373 | <p>I have the following python code to create a charge in stripe.</p>
<pre><code>a_charge = stripe.Charge.create(
amount=cents,
currency="usd",
source=token,
description="my_description",
application_fee=application_fee,
stripe_account=teacher_stripe_id
)
</code></pre>
<p>This succeeds (I think), because it shows up... | 3 | 2016-07-13T09:56:56Z | 38,354,844 | <p>The reason the charge retrieval call fails is because the charge was created on a different account.</p>
<p>When you create the charge:</p>
<pre><code>a_charge = stripe.Charge.create(
amount=cents,
currency="usd",
source=token,
description="my_description",
application_fee=application_fee,
stripe_acco... | 3 | 2016-07-13T14:42:17Z | [
"python",
"django",
"stripe-payments"
] |
ModelForm in Django fails to receive data | 38,348,402 | <p>I have a ModelForm that all the fields are required as I want to. When I render this form in HTML, I provide all the data needed in those fields, I click submit but my form fails on is_valid validation and when I print the errors, every single input returns the following error: "This field is required."</p>
<p>The ... | 0 | 2016-07-13T09:58:45Z | 38,348,442 | <p>You've set a prefix on the form in the POST block, for some reason, but not in the GET case. So the fields are rendered without a prefix, but on submission the form is looking for fields with a prefix.</p>
<p>There doesn't seem to be any reason to use a prefix at all here; remove it.</p>
| 2 | 2016-07-13T10:00:36Z | [
"python",
"django",
"forms"
] |
Find matching items in nested list | 38,348,461 | <p>I'm trying to match a list of items to another list of items of a different dimension and print an element from the second list if the item is matched. For example:</p>
<pre><code>stlist=['6', '3', '4', '2', '5', '1']
ndlist=[['Tom', '1'], ['Joh', '2'], ['Sam', '3'], ['Tommy','4'], ['Nanni', '5'], ['Ron', '6']]
</c... | 1 | 2016-07-13T10:01:31Z | 38,372,834 | <p>Try to rearrange your for loops:</p>
<pre><code>for element in stlist:
for sublist in ndlist:
if element in sublist[1]:
print (sublist[0])
</code></pre>
<p>Also, the if statement should maybe be like this: <code>if element == sublist[1]:</code> or else the element '1' would be found in some... | 2 | 2016-07-14T11:20:45Z | [
"python",
"matching"
] |
Find matching items in nested list | 38,348,461 | <p>I'm trying to match a list of items to another list of items of a different dimension and print an element from the second list if the item is matched. For example:</p>
<pre><code>stlist=['6', '3', '4', '2', '5', '1']
ndlist=[['Tom', '1'], ['Joh', '2'], ['Sam', '3'], ['Tommy','4'], ['Nanni', '5'], ['Ron', '6']]
</c... | 1 | 2016-07-13T10:01:31Z | 38,373,799 | <p>You could use <a href="https://docs.python.org/2/library/functions.html#sorted" rel="nofollow"><code>sorted</code></a> and a custom sort key (a Lambda function) to do this:</p>
<pre><code>>>> [i[0] for i in sorted(ndlist, key = lambda x:stlist.index(x[1]))]
['Ron', 'Sam', 'Tommy', 'Joh', 'Nanni', 'Tom']
</... | 1 | 2016-07-14T12:07:06Z | [
"python",
"matching"
] |
Find matching items in nested list | 38,348,461 | <p>I'm trying to match a list of items to another list of items of a different dimension and print an element from the second list if the item is matched. For example:</p>
<pre><code>stlist=['6', '3', '4', '2', '5', '1']
ndlist=[['Tom', '1'], ['Joh', '2'], ['Sam', '3'], ['Tommy','4'], ['Nanni', '5'], ['Ron', '6']]
</c... | 1 | 2016-07-13T10:01:31Z | 38,614,591 | <p>Instead of nesting loops or sorting you could also create a mapping with one linear run through <code>ndlist</code> and then use another linear run through <code>stlist</code> to build the result list:</p>
<pre><code>mapping = dict((b, a) for a, b in ndlist)
result = [mapping[x] for x in stlist]
print(result)
</cod... | 0 | 2016-07-27T13:38:14Z | [
"python",
"matching"
] |
How to set a thread specific environment variable in Python? | 38,348,556 | <p>I want to create two (or more) threads and in each of them to execute a different external program, let's say <code>aaa</code> and <code>bbb</code>. These external programs need libraries located in different directories, let's say in <code>/aaalib</code> and <code>/bbblib</code>, so I have to set the environment va... | 2 | 2016-07-13T10:05:28Z | 38,348,758 | <p>you can try using <code>subprocess</code> module and do something like this:</p>
<pre class="lang-py prettyprint-override"><code>import subprocess
import os
env = os.environ.copy()
env['LD_LIBRARY_PATH'] = '/aaalib'
aaa_process = subprocess.Popen(['aaa'], env=env)
env = os.environ.copy()
env['LD_LIBRARY_PATH'] = ... | 1 | 2016-07-13T10:13:22Z | [
"python",
"multithreading",
"environment-variables"
] |
How to set a thread specific environment variable in Python? | 38,348,556 | <p>I want to create two (or more) threads and in each of them to execute a different external program, let's say <code>aaa</code> and <code>bbb</code>. These external programs need libraries located in different directories, let's say in <code>/aaalib</code> and <code>/bbblib</code>, so I have to set the environment va... | 2 | 2016-07-13T10:05:28Z | 38,348,764 | <p>A threads cannot have its own environment variables, it always has those of its parent process. You can either <a href="http://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a-modified-environment">set the appropriate values when you create the subprocesses for your external programs</a> or use sep... | 0 | 2016-07-13T10:13:38Z | [
"python",
"multithreading",
"environment-variables"
] |
How to set a thread specific environment variable in Python? | 38,348,556 | <p>I want to create two (or more) threads and in each of them to execute a different external program, let's say <code>aaa</code> and <code>bbb</code>. These external programs need libraries located in different directories, let's say in <code>/aaalib</code> and <code>/bbblib</code>, so I have to set the environment va... | 2 | 2016-07-13T10:05:28Z | 38,348,899 | <p>First of all I guess threads stay in the same environment so I advice you to use <code>multiprocessing</code> or <code>subprocess</code> library to handle processes and not threads.
in each process function you can change the environment freely and independently from the parent script </p>
<p>each process should ha... | 0 | 2016-07-13T10:19:25Z | [
"python",
"multithreading",
"environment-variables"
] |
How to set a thread specific environment variable in Python? | 38,348,556 | <p>I want to create two (or more) threads and in each of them to execute a different external program, let's say <code>aaa</code> and <code>bbb</code>. These external programs need libraries located in different directories, let's say in <code>/aaalib</code> and <code>/bbblib</code>, so I have to set the environment va... | 2 | 2016-07-13T10:05:28Z | 38,349,331 | <p>Using the wonderful <a href="https://plumbum.readthedocs.io/en/latest/#" rel="nofollow">plumbum</a> library:</p>
<pre><code>from plumbum import local
with local.env(LD_LIBRARY_PATH = '/aaalib'):
execute_external_program()
</code></pre>
<p>See <a href="https://plumbum.readthedocs.io/en/latest/local_machine.html... | 0 | 2016-07-13T10:39:17Z | [
"python",
"multithreading",
"environment-variables"
] |
Pandas: Apply function to set of groups | 38,348,567 | <p><strong>I have the following problem:</strong> </p>
<p>Given a 2D dataframe, first column with values and second giving categories of the points, I would like to compute a k-means dictionary of the means of each category and assign the centroid that the group mean of a particular value is closest to as a new column... | 0 | 2016-07-13T10:05:53Z | 38,464,740 | <p>You can achieve it by the following:</p>
<pre><code>import pandas as pd
import numpy as np
from scipy.cluster.vq import kmeans2
k = 4
raw_data = np.random.randint(0,100,size=(100, 4))
f = pd.DataFrame(raw_data, columns=list('ABCD'))
df = pd.DataFrame(f, columns=['A','B'])
groups = df.groupby('A')
means_data_frame... | 0 | 2016-07-19T17:18:36Z | [
"python",
"pandas"
] |
df.loc to remove whole row based on condition | 38,348,733 | <p>Quick question,</p>
<p>How would I adapt </p>
<pre><code>df2.loc[df2['A'] ==0, 'B'] = np.NaN
</code></pre>
<p>To change to the whole row, aka B,C etc become np.Nan
Without a for loop as this would take too long</p>
<p>Many thanks</p>
| 0 | 2016-07-13T10:12:32Z | 38,348,962 | <p>If you want every column including 'A':</p>
<pre><code>df.loc[df['A'] == 0, :] = np.NaN
</code></pre>
<p>If you want every column from 'B' onwards,</p>
<pre><code>df.loc[df['A'] == 0, 'B':] = np.NaN
</code></pre>
<p>More generally, if 'A' isn't the first column:</p>
<pre><code>df.loc[df['A'] == 0, df.columns.dr... | 3 | 2016-07-13T10:23:06Z | [
"python",
"dataframe"
] |
Exchanging datas between two threads in Python | 38,348,747 | <p>I'm trying to exchange simple data between two threads in two separated modules and I can't find the better way to do it properly</p>
<p>here is my architecture :
I have a main script which launch my two threads : </p>
<pre><code>from core.sequencer import Sequencer
from gui.threadGui import ThreadGui
t1 = Thread... | 1 | 2016-07-13T10:12:57Z | 38,348,925 | <p>From your description <a href="https://docs.python.org/2/library/threading.html#event-objects" rel="nofollow">Event object</a> looks like the most reasonable solution:</p>
<pre><code>class Sequencer(Thread):
def __init__(self, button_pressed_event):
Thread.__init__(self)
self._event = button_pr... | 2 | 2016-07-13T10:21:00Z | [
"python",
"multithreading",
"flask"
] |
loop over a list in a certain pattern | 38,348,977 | <p>I want to iterate over a list that looks like
list=[1,2,3,4,5,6]
my iteration pattern should looks like this:</p>
<pre><code>outer loop/ inner loop
1, / 2, 3,4,5,6
2, /3, 4, 5, 6
3, /4, 5, 6
4, /5, 6
5, /6
</code></pre>
<p>pseudocode </p>
<pre><code>list1=[1,2,3,4,5,6]
list2 = ... | -1 | 2016-07-13T10:23:50Z | 38,349,285 | <p>You don't need to copy the list.
And calling it <code>list</code> is a bad idea.</p>
<p>This will do what you want (nearly apart from whitespace in the output):</p>
<pre><code>l = [1, 2, 3, 4, 5, 6]
for i in range(0, len(l)-1):
print l[i],', /',','.join(map(str, l[i+1:]))
</code></pre>
| 1 | 2016-07-13T10:37:08Z | [
"python"
] |
loop over a list in a certain pattern | 38,348,977 | <p>I want to iterate over a list that looks like
list=[1,2,3,4,5,6]
my iteration pattern should looks like this:</p>
<pre><code>outer loop/ inner loop
1, / 2, 3,4,5,6
2, /3, 4, 5, 6
3, /4, 5, 6
4, /5, 6
5, /6
</code></pre>
<p>pseudocode </p>
<pre><code>list1=[1,2,3,4,5,6]
list2 = ... | -1 | 2016-07-13T10:23:50Z | 38,349,492 | <p>The idea to use two loops was good, but <code>list2[-1:]</code> only keeps the last element. To fix that, you would have to do this: <code>list2 = list2[1:]</code> or <code>list2.pop()</code>.</p>
<p>But these are inefficient, because they create a new copy of the list at each iteration of the outer loop. I suggest... | 1 | 2016-07-13T10:46:59Z | [
"python"
] |
loop over a list in a certain pattern | 38,348,977 | <p>I want to iterate over a list that looks like
list=[1,2,3,4,5,6]
my iteration pattern should looks like this:</p>
<pre><code>outer loop/ inner loop
1, / 2, 3,4,5,6
2, /3, 4, 5, 6
3, /4, 5, 6
4, /5, 6
5, /6
</code></pre>
<p>pseudocode </p>
<pre><code>list1=[1,2,3,4,5,6]
list2 = ... | -1 | 2016-07-13T10:23:50Z | 38,349,514 | <p>The code you posted doesn't achieve what you are aiming for. Rather, use something like this:</p>
<pre><code>In [3]: my_list = [1,2,3,4,5,6]
In [4]: for i,e1 in enumerate(my_list[:-1]):
...: for e2 in my_list[i+1:]:
...: print(e1,e2)
...:
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 ... | 1 | 2016-07-13T10:47:50Z | [
"python"
] |
loop over a list in a certain pattern | 38,348,977 | <p>I want to iterate over a list that looks like
list=[1,2,3,4,5,6]
my iteration pattern should looks like this:</p>
<pre><code>outer loop/ inner loop
1, / 2, 3,4,5,6
2, /3, 4, 5, 6
3, /4, 5, 6
4, /5, 6
5, /6
</code></pre>
<p>pseudocode </p>
<pre><code>list1=[1,2,3,4,5,6]
list2 = ... | -1 | 2016-07-13T10:23:50Z | 38,350,542 | <p>I think the most efficient way (both in performance and in time spent programming) to get the values you want is by using <code>itertools.combinations</code> from the Python standard library to produce the pairs of values with a single loop:</p>
<pre><code> for i, j in itertools.combinations(list1, 2):
print(i... | 3 | 2016-07-13T11:32:44Z | [
"python"
] |
How to divide all the elements in a list together | 38,349,363 | <p>For example:</p>
<pre><code>a = [1,2,3,4,5,6]
</code></pre>
<p>I want to do:</p>
<pre><code>1/2/3/4/5/6
</code></pre>
<p>I have tried using the <code>operator.div</code> function but it doesn't seem to give the correct result. By the way, I am fairly new to python.</p>
| 4 | 2016-07-13T10:40:50Z | 38,349,397 | <p>You can use <a href="https://docs.python.org/3/library/functools.html#functools.reduce" rel="nofollow"><code>reduce</code></a>. </p>
<blockquote>
<p>Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value.</p>
</blockquote>
<p>The ... | 6 | 2016-07-13T10:42:30Z | [
"python",
"list"
] |
How to divide all the elements in a list together | 38,349,363 | <p>For example:</p>
<pre><code>a = [1,2,3,4,5,6]
</code></pre>
<p>I want to do:</p>
<pre><code>1/2/3/4/5/6
</code></pre>
<p>I have tried using the <code>operator.div</code> function but it doesn't seem to give the correct result. By the way, I am fairly new to python.</p>
| 4 | 2016-07-13T10:40:50Z | 38,349,427 | <p>You can use <a href="https://docs.python.org/2/library/functions.html#reduce" rel="nofollow"><code>reduce()</code></a> and <code>operator.truediv</code>:</p>
<pre><code>>>> a = [1,2,3,4,5,6]
>>> from operator import truediv
>>>
>>> reduce(truediv, a)
0.001388888888888889
</code>... | 6 | 2016-07-13T10:43:38Z | [
"python",
"list"
] |
How to divide all the elements in a list together | 38,349,363 | <p>For example:</p>
<pre><code>a = [1,2,3,4,5,6]
</code></pre>
<p>I want to do:</p>
<pre><code>1/2/3/4/5/6
</code></pre>
<p>I have tried using the <code>operator.div</code> function but it doesn't seem to give the correct result. By the way, I am fairly new to python.</p>
| 4 | 2016-07-13T10:40:50Z | 38,349,585 | <p>Why not just use a loop?</p>
<pre><code>>>> a = [1,2,3,4,5,6]
>>> i = iter(a)
>>> result = next(i)
>>> for num in i:
... result /= num
...
>>> result
0.001388888888888889
>>> 1/2/3/4/5/6
0.001388888888888889
</code></pre>
| 4 | 2016-07-13T10:50:49Z | [
"python",
"list"
] |
Python ElementTree does not like colon in name of processing instruction | 38,349,579 | <p>The following code:</p>
<pre><code>import xml.etree.ElementTree as ET
xml = '''\
<?xml version="1.0" encoding="UTF-8"?>
<testCaseConfig>
<?LazyComment Blah de blah/?>
<testCase runLimit="420" name="d1/n1"/>
<testCase runLimit="420" name="d1/n2"/>
</testCaseConfig>... | 1 | 2016-07-13T10:50:37Z | 38,350,076 | <pre><code><?xml version="1.0" encoding="UTF-8"?>
<testCaseConfig xmlns:Blah="http://www.w3.org/TR/html4/">
<?LazyComment:Blah de blah/?>
<testCase runLimit="420" name="d1/n1"/>
<testCase runLimit="420" name="d1/n2"/>
</testCaseConfig xmlns:Blah="http://www.w3.org/TR/html... | 0 | 2016-07-13T11:12:55Z | [
"python",
"xml",
"parsing",
"elementtree"
] |
Python ElementTree does not like colon in name of processing instruction | 38,349,579 | <p>The following code:</p>
<pre><code>import xml.etree.ElementTree as ET
xml = '''\
<?xml version="1.0" encoding="UTF-8"?>
<testCaseConfig>
<?LazyComment Blah de blah/?>
<testCase runLimit="420" name="d1/n1"/>
<testCase runLimit="420" name="d1/n2"/>
</testCaseConfig>... | 1 | 2016-07-13T10:50:37Z | 38,387,158 | <p>According to the W3C Extensible Markup Language 1.0 Specifications under <a href="https://www.w3.org/TR/REC-xml/#sec-common-syn" rel="nofollow">Common Syntactic Constructs</a>: </p>
<blockquote>
<p>The Namespaces in XML Recommendation [XML Names] assigns a meaning to
names containing colon characters. Therefore... | 1 | 2016-07-15T02:51:10Z | [
"python",
"xml",
"parsing",
"elementtree"
] |
uwsgi --reload refuses incoming connections | 38,349,603 | <p>I am trying to setup a uwsgi-hosted app such that I get graceful reloads with uwsgi --reload but I am obviously failing. Here is my test uwsgi setup:</p>
<pre><code>[admin2-prod]
http = 127.0.0.1:9090
pyargv = $* --db=prod --base-path=/admin/
max-requests = 3
listen=1000
http-keepalive = 1
pidfile2 =admin.pid
add-h... | 2 | 2016-07-13T10:51:42Z | 38,352,536 | <p>Your exceptions happens when uwsgi process cant accept connections obviously... So, your process have to wait until server restarted - you can use loop with timeout in except block to properly handle this situation. Try this:</p>
<pre><code>import httplib
import socket
import time
connection = httplib.HTTPConnecti... | 0 | 2016-07-13T13:01:45Z | [
"python",
"tcp",
"uwsgi"
] |
uwsgi --reload refuses incoming connections | 38,349,603 | <p>I am trying to setup a uwsgi-hosted app such that I get graceful reloads with uwsgi --reload but I am obviously failing. Here is my test uwsgi setup:</p>
<pre><code>[admin2-prod]
http = 127.0.0.1:9090
pyargv = $* --db=prod --base-path=/admin/
max-requests = 3
listen=1000
http-keepalive = 1
pidfile2 =admin.pid
add-h... | 2 | 2016-07-13T10:51:42Z | 38,368,915 | <p>you are managing both the app and the proxy in the same uWSGI instance, so when you reload the stack you are killing the frontend web server too (the one you start with the 'http' option).</p>
<p>You have to split the http router in another uWSGI instance, or use nginx/haproxy or similar. Once you have two differen... | 0 | 2016-07-14T08:15:38Z | [
"python",
"tcp",
"uwsgi"
] |
How correctly use a hook in a Wagtail admin? | 38,349,635 | <p>I'm trying to insert my own css into a wagtail admin page. </p>
<p>Сonsidering the answer <a href="https://groups.google.com/forum/#!topic/wagtail/DYeTygB_F-8" rel="nofollow">https://groups.google.com/forum/#!topic/wagtail/DYeTygB_F-8</a> I use hook <code>insert_editor_css</code>. I've created <code>wagtail_hooks.... | 0 | 2016-07-13T10:53:20Z | 38,350,285 | <p>You need to:</p>
<ol>
<li>Ensure that your app was added to the <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#installed-apps" rel="nofollow"><code>INSTALLED_APPS</code></a> setting.</li>
<li>Ensure that your project imports <code>wagtail_hooks.py</code>. You can just put <code>print</code> somewhere ... | 1 | 2016-07-13T11:21:38Z | [
"python",
"django",
"wagtail"
] |
how to release 'orphan' opencv videowriter | 38,349,643 | <p>I wrote a function that generates a video output using opencv and videowriter</p>
<p>I am calling this function from scripts within my spyder/ipython ide. during debugging, the function is still faulty and sometimes it aborts without releasing the videofile. I tried to implement try/exception but there are still in... | 1 | 2016-07-13T10:53:50Z | 38,350,154 | <p>As it is, your code gives an error. You have to specify <code>result = np.ones((100,100), dtype = np.uint8)</code> for it to run. Otherwise you get a failed OpenCV assertion.</p>
<p>And I can delete the videos without any problem (I'm using Python IDLE), even without closing the console.</p>
| 0 | 2016-07-13T11:16:07Z | [
"python",
"opencv"
] |
RemovedInDjango19Warning - isn't in an application in INSTALLED_APPS | 38,349,652 | <p>I am getting the following error when importing the models module in Django.</p>
<pre><code>/Users/markcollier/Documents/Adapt/Taboo/TabooAPI/env/lib/python2.7/site-packages/django/contrib/contenttypes/models.py:161: RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't declar... | 0 | 2016-07-13T10:54:04Z | 38,350,434 | <p>According to the error message you posted, the problem is not with your own app but with <code>django.contrib.django.contenttypes.models.ContentType</code> - and googling for this exact error message shows you're not the first having this issue. </p>
<p>Since contenttypes is in your installed apps, the problem come... | 1 | 2016-07-13T11:28:34Z | [
"python",
"django",
"django-rest-framework"
] |
convert em-dash to hyphen in python | 38,349,700 | <p>I'm converting csv files into python Dataframe. And in the original file, one of the column has characters em-dash. I want it replaced by hyphen "-".</p>
<p>Partial original file from csv:</p>
<pre><code> NoDemande NoUsager Sens IdVehicule NoConduteur HeureDebutTrajet HeureArriveeSurSite H... | 1 | 2016-07-13T10:56:43Z | 38,351,507 | <p><code>u'\u2014'</code> (EM DASH) can not be encoded in latin1/iso-8859-1, so that value can not appear in a properly encoded latin1 file.</p>
<p>Possibly the files are encoded as windows-1252 for which <code>u'\u2014'</code> can be encoded as <code>'\x97'</code>.</p>
<p>Another problem is that the CSV file apparen... | 2 | 2016-07-13T12:16:59Z | [
"python",
"csv",
"pandas",
"unicode",
"iso-8859-1"
] |
Why does `str.format()` ignore additional/unused arguments? | 38,349,822 | <p>I saw <a href="http://stackoverflow.com/a/22152693/2505645">"Why doesn't join() automatically convert its arguments to strings?"</a> and <a href="http://stackoverflow.com/a/22152693/2505645">the accepted answer</a> made me think: since</p>
<blockquote>
<p>Explicit is better than implicit.</p>
</blockquote>
<p>an... | 11 | 2016-07-13T11:02:07Z | 38,350,141 | <p>Ignoring un-used arguments makes it possible to create arbitrary format strings for arbitrary-sized dictionaries or objects.</p>
<p>Say you wanted to give your program the feature to let the end-user change the output. You document what <em>fields</em> are available, and tell users to put those fields in <code>{...... | 10 | 2016-07-13T11:15:41Z | [
"python",
"string",
"python-3.x",
"string-formatting"
] |
how to limit GET,POST access to resources using customize user type in tastypie | 38,349,947 | <p>I have extended Django default 'User' model for add new user type field. user type categories are <strong>user</strong>, <strong>admin</strong> and <strong>viewer</strong>.
And i want to implement RESTapi for this using tastypie and give permission to access that api based on user type.
for example Admin users hav... | 2 | 2016-07-13T11:07:31Z | 38,605,584 | <p>First, write Your own authentication class. In this class check if user is <strong>viewer</strong>. If yes, return False.</p>
<pre><code>class MyAuthentication(BasicAuthentication):
def is_authenticated(self, request, **kwargs):
is_authenticated = super(MyAuthentication, self).is_authenticated(request, ... | 0 | 2016-07-27T06:45:11Z | [
"python",
"django",
"tastypie"
] |
SparkContext Error - File not found /tmp/spark-events does not exist | 38,350,249 | <p>Running a Python Spark Application via API call -
On submitting the Application - response - Failed
SSH into the Worker</p>
<p>My python application exists in </p>
<pre><code>/root/spark/work/driver-id/wordcount.py
</code></pre>
<p>Error can be found in </p>
<pre><code>/root/spark/work/driver-id/stderr
</code><... | 0 | 2016-07-13T11:20:04Z | 38,350,483 | <p><code>/tmp/spark-events</code> is the location that Spark store the events logs. Just create this directory in the master machine and you're set.</p>
<pre><code>$mkdir /tmp/spark-events
$ sudo /root/spark-ec2/copy-dir /tmp/spark-events/
RSYNC'ing /tmp/spark-events to slaves...
ec2-54-175-163-32.compute-1.amazonaws.... | 3 | 2016-07-13T11:30:40Z | [
"python",
"amazon-web-services",
"apache-spark",
"amazon-ec2",
"pyspark"
] |
django: redirect issue logout functionlaity | 38,350,290 | <p>I want to redirect user to a specific website <code>example.com</code> after <code>logout</code></p>
<p>I have added following code in app's <code>urls.py</code></p>
<pre><code>urlpatterns = [
url(r'^logout', 'django.contrib.auth.views.logout', {'next_page': 'https://www.example.com/'}),
]
</code></pre>
<p... | 0 | 2016-07-13T11:21:52Z | 38,351,055 | <p>You should add a <code>name</code> to your url pattern.</p>
<pre><code>urlpatterns = [
url(r'^logout', 'django.contrib.auth.views.logout', name='logout'),
]
</code></pre>
<p>As an aside, using the string <code>'django.contrib.auth.views.logout'</code> is deprecated. You should import the view instead. For... | 0 | 2016-07-13T11:54:58Z | [
"python",
"django",
"authentication",
"redirect",
"logout"
] |
How to convert SDO_GEOMTRY in GeoJSON | 38,350,314 | <p>I work with sqlalchemy and geoalchemy and will convert my results in geojson.
With the normal way like this :</p>
<pre><code>print json.dumps([dict(r) for r in connection.execute(query)])
</code></pre>
<p>it is not possible because cx_Oracle.Objets not serializable!
I can have access through the separate attribut... | 0 | 2016-07-13T11:22:49Z | 38,400,232 | <p>This is using the (as yet unreleased) version of cx_Oracle which supports binding of objects and other more advanced uses of objects. Using the sample provided with cx_Oracle for demonstrating the insertion of geometry, the following code will transform the object created in that way into JSON. The ObjectRepr() func... | 0 | 2016-07-15T15:45:47Z | [
"python",
"oracle",
"sqlalchemy",
"geoalchemy"
] |
Need python 2.7+ but default on system is 2.6 | 38,350,391 | <p>I downloaded some tools which use python scripts to work. It seems I need python 2.7+ to be able to run the scripts, the default installed is 2.6 and I am getting this error:</p>
<pre><code>AttributeError: 'module' object has no attribute 'check_output'
</code></pre>
<p>So, I downloaded and installed python 2.7, h... | -2 | 2016-07-13T11:26:35Z | 38,350,659 | <p>It is probably not a good idea to change the default python interpreter unless you know what you are doing. You could try aliasing the python command.</p>
<pre><code>alias python="python2.7"
</code></pre>
<p>To revert just type <code>unalias python</code></p>
| 1 | 2016-07-13T11:37:20Z | [
"python",
"linux",
"python-2.7"
] |
Need python 2.7+ but default on system is 2.6 | 38,350,391 | <p>I downloaded some tools which use python scripts to work. It seems I need python 2.7+ to be able to run the scripts, the default installed is 2.6 and I am getting this error:</p>
<pre><code>AttributeError: 'module' object has no attribute 'check_output'
</code></pre>
<p>So, I downloaded and installed python 2.7, h... | -2 | 2016-07-13T11:26:35Z | 38,350,703 | <p>do this: </p>
<blockquote>
<p>which python <br/>
/usr/bin/python <br/></p>
<p>ls -l /usr/bin/python <br/>
/usr/bin/python -> python2.7</p>
</blockquote>
<p>so you just need to update /usr/bin/python link to point to your python 2.7, just remember if you use centos YUM package manager, it is linked to py... | 0 | 2016-07-13T11:39:22Z | [
"python",
"linux",
"python-2.7"
] |
Need python 2.7+ but default on system is 2.6 | 38,350,391 | <p>I downloaded some tools which use python scripts to work. It seems I need python 2.7+ to be able to run the scripts, the default installed is 2.6 and I am getting this error:</p>
<pre><code>AttributeError: 'module' object has no attribute 'check_output'
</code></pre>
<p>So, I downloaded and installed python 2.7, h... | -2 | 2016-07-13T11:26:35Z | 38,350,723 | <p>I'm guessing your scripts has </p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>as hash-bang.</p>
<p>Change the first line of your scripts to</p>
<pre><code>#!/usr/bin/env python2.7
</code></pre>
<p>given that python 2.7 indeed is available on the system.</p>
<p>This way, when you run the scripts from the... | 1 | 2016-07-13T11:40:13Z | [
"python",
"linux",
"python-2.7"
] |
Need python 2.7+ but default on system is 2.6 | 38,350,391 | <p>I downloaded some tools which use python scripts to work. It seems I need python 2.7+ to be able to run the scripts, the default installed is 2.6 and I am getting this error:</p>
<pre><code>AttributeError: 'module' object has no attribute 'check_output'
</code></pre>
<p>So, I downloaded and installed python 2.7, h... | -2 | 2016-07-13T11:26:35Z | 38,356,626 | <p>? CentOS 6 ?</p>
<p><code>python27</code> is available : <a href="http://vault.centos.org/6.5/SCL/x86_64/python27/" rel="nofollow">http://vault.centos.org/6.5/SCL/x86_64/python27/</a></p>
| 0 | 2016-07-13T16:03:04Z | [
"python",
"linux",
"python-2.7"
] |
Compressing text string with existing compression header | 38,350,675 | <p>I wish to compress a given string with a pre-existing header retrieved from an already compressed file in an archive (a local file header). </p>
<p>I have attempted to look at <a href="http://www.zlib.net/" rel="nofollow">zlib</a> and while their compression/decompressing works nicely I can not find an option to se... | 2 | 2016-07-13T11:38:07Z | 38,356,380 | <p>What you want to do is more complicated than you think. However the code has already been written. Look at <a href="https://github.com/madler/zlib/blob/master/examples/gzlog.h" rel="nofollow">gzlog.h</a> and <a href="https://github.com/madler/zlib/blob/master/examples/gzlog.c" rel="nofollow">gzlog.c</a> in the <a hr... | 1 | 2016-07-13T15:50:35Z | [
"python",
"compression",
"zlib"
] |
plotting multiple column from excel with matplotlib | 38,350,739 | <p>I have data which looks like :</p>
<pre><code>sites mp1 mp2
ry99 0.66 0.54
ry98 0.71 0.54
ry97 0.58 0.45
ry96 0.65 0.55
</code></pre>
<p>I have the list below in an excel file and I would like to plot the second and third column against the first one, all in the same graph using matpl... | -1 | 2016-07-13T11:40:41Z | 38,350,902 | <p>This is my code which should solve your problem :</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
arr = np.genfromtxt('file', delimiter=' ', dtype=None, names =['sites','mp1','mp2'], skip_header=1)
x = np.arange(4)
plt.xticks(x, arr['sites'])
plt.plot(x, arr['mp1'])
plt.plot(x, arr['mp2'])
... | 0 | 2016-07-13T11:48:42Z | [
"python",
"excel",
"numpy",
"matplotlib"
] |
Python mysql.connector InternalError: Unread result found when close cursor | 38,350,816 | <p>I want to read part of result from cursor and then close it without reading all result. <code>cursor.close()</code> raises <code>InternalError: Unread result found.</code> Is it possible to close cursor without iterating through all result or using <strong>buffer option</strong>?</p>
<p>Update:</p>
<p>My query get... | 0 | 2016-07-13T11:44:26Z | 38,351,885 | <p>It would appear that you need:</p>
<pre><code>cursor = conn.cursor(buffered=True,dictionary=true)
</code></pre>
<p>in order to abandon a resultset mid-stream. </p>
<p>Full disclosure, I am a mysql dev, not a python dev. </p>
<p>See the Python Manual Page <a href="https://dev.mysql.com/doc/connector-python/en/con... | 1 | 2016-07-13T12:34:22Z | [
"python",
"mysql",
"mysql-connector-python"
] |
Using sudo su command with touch command to create file with other user permission | 38,350,863 | <p>I want to run a command with a specific users permission in a Python script.</p>
<pre><code>import os
os.subprocess("sudo su user; cd <directory_path> ; touch test", shell=True)
</code></pre>
<p>The test file here is not created with the ownership of the user I use with sudo su.</p>
<p>I also tried the ... | -1 | 2016-07-13T11:46:55Z | 38,351,013 | <p>You're spawning a new shell with the way you're calling <code>sudo su</code> or <code>sudo -i</code>, and the new shell isn't passed the <code>cd;touch</code>.</p>
<p>You probably want something along the lines of </p>
<pre><code>sudo -u user touch <dir>/test
</code></pre>
<p>(which behaves slightly differe... | 1 | 2016-07-13T11:53:32Z | [
"python",
"shell",
"sudo"
] |
Unique indexing of a dataframe pandas | 38,350,928 | <p>I have to merge data from several excel file and make a data frame. When i do that the index of the rows in the dataframes are not unique as shown below,</p>
<pre><code> a
0 green
1 blue
2 red
0 orange
1 black
2 yellow
</code></pre>
<p>Here i am trying to merge 2 different excel files. One with the d... | 0 | 2016-07-13T11:49:49Z | 38,351,113 | <p>If <code>df</code> is your final <code>dataframe</code> you can do:</p>
<pre><code>In [6]: df.reset_index(drop=True)
Out[6]:
a
0 green
1 blue
2 red
3 orange
4 black
5 yellow
</code></pre>
| 2 | 2016-07-13T11:57:24Z | [
"python",
"pandas",
"indexing",
"dataframe"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.