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 list |
|---|---|---|---|---|---|---|---|---|---|
Using python thread as a plain object | 39,053,520 | <p>If i define a python thread extending threading.Thread class and overriding run I can then invoke run() instead of start() and use it in the caller thread instead of a separate one.</p>
<p>i.e.</p>
<pre><code>class MyThread(threading.thread):
def run(self):
while condition():
do_something()... | 0 | 2016-08-20T11:18:19Z | 39,053,622 | <p>There will be no difference in the behavior of <code>run</code> when you're using the <code>threading.Thread</code> object, or an object of a <code>threading.Thread</code>'s subclass, or an object of any other class that has the <code>run</code> method:</p>
<blockquote>
<p><code>threading.Thread.start</code> star... | 1 | 2016-08-20T11:31:10Z | [
"python",
"multithreading"
] |
Using python thread as a plain object | 39,053,520 | <p>If i define a python thread extending threading.Thread class and overriding run I can then invoke run() instead of start() and use it in the caller thread instead of a separate one.</p>
<p>i.e.</p>
<pre><code>class MyThread(threading.thread):
def run(self):
while condition():
do_something()... | 0 | 2016-08-20T11:18:19Z | 39,112,405 | <p>I looked into the <a href="https://hg.python.org/cpython/file/3.5/Lib/threading.py" rel="nofollow">code implementing threading.Thread</a> class in cpython 3. The init method simply assigns some variables and do not do anything that seems related to actually create a new thread. Therefore we can assume that it should... | 0 | 2016-08-23T23:55:23Z | [
"python",
"multithreading"
] |
cannot import pandas after conda update, Missing required dependencies ['numpy'] | 39,053,553 | <p>I have been using pandas for a long while now, and wanted to use this functionality. Realizing I was in a prior version I typed <code>conda update pandas</code> into my command line.</p>
<p>Now, when I go into python and try to import pandas I see the following:</p>
<pre><code>C:\Users\%USER%>python
Python 2.7.... | 1 | 2016-08-20T11:21:58Z | 39,054,124 | <p>Thankfully conda understands revisions.</p>
<pre><code>C:\>conda list --revisions
</code></pre>
<p>Will give you your list of revisions. Find the one prior to the most recent that broke stuff.</p>
<p>For me it was revision 6, so I typed:</p>
<pre><code>C:\>conda install --revision 6
</code></pre>
<p>I am ... | 0 | 2016-08-20T12:25:31Z | [
"python",
"pandas",
"numpy",
"conda"
] |
open selected rows with pandas using "chunksize" and/or "iterator" | 39,053,628 | <p>I have a large csv file and I open it with pd.read_csv as it follows:</p>
<pre><code>df = pd.read_csv(path//fileName.csv, sep = ' ', header = None)
</code></pre>
<p>As the file is really large I would like to be able to open it in rows</p>
<pre><code>from 0 to 511
from 512 to 1023
from 1024 to 1535
...
from 512*n... | 2 | 2016-08-20T11:31:44Z | 39,053,748 | <blockquote>
<p>How can I read only rows from 512*n to 512*(n+1)?</p>
</blockquote>
<pre><code>df = pd.read_csv(fn, header=None, skiprows=512*n, nrows=512)
</code></pre>
<p>You can do it this way (and it's pretty useful):</p>
<pre><code>for chunk in pd.read_csv(f, sep = ' ', header = None, chunksize = 512):
# ... | 2 | 2016-08-20T11:45:37Z | [
"python",
"pandas"
] |
Python multiprocessing infinite loops | 39,053,656 | <p>I want to process simultaneously a function three times which contains an infinite loop.</p>
<p>My code:</p>
<pre><code>import multiprocessing
def worker(numbers):
while True:
print numbers
if __name__ == '__main__':
nums = ["1","2","3"]
for i in nums:
p = multiprocessing.Process(targ... | 2 | 2016-08-20T11:35:01Z | 39,055,167 | <p>As per rawing's comment, instead of passing the function object to the <code>target</code> keyword argument, you are directly calling it and are passing its return value, which never returns since it's an infinite loop.</p>
<p>Try this:</p>
<pre><code>import multiprocessing
_MAX_ITERATIONS = 10
def worker(number... | 2 | 2016-08-20T14:23:32Z | [
"python",
"multithreading",
"parallel-processing",
"multiprocessing"
] |
Something going wrong while making my progress bar in GUI | 39,053,666 | <p>After I succeeded in making a progress bar in console, I thought about upgrading the program to GUI. </p>
<p>This is my code: </p>
<pre><code>from tkinter import *
class Progress(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.value = 1
self.end... | 0 | 2016-08-20T11:36:07Z | 39,053,874 | <p>Look at this code:</p>
<pre><code>def startprogress(self):
while self.value <= self.endvalue:
root.after(100, self.updateprogress)
</code></pre>
<p>This is an infinite loop. I hope I don't need to explain why.</p>
<p>What you probably wanted to do is this:</p>
<pre><code>def startprogress(self):
... | 2 | 2016-08-20T11:58:48Z | [
"python",
"tkinter"
] |
check the width and height of an image | 39,053,681 | <p>i am trying to check the width and height of an image in a directory by using python . the directory consist of two folders and each folder there are pictures want to check the width and height to resize them if they are not matched. here is my code:</p>
<pre><code>def Resize(imageFolder, factor_1, factor_2):
... | -3 | 2016-08-20T11:37:20Z | 39,054,813 | <pre><code>for (pth, dirs, files) in os.walk(imageFolder):
for fileName in files:
image = Image.open(fileName)
with Image.open(os.path.join(pth, fileName)) as image:
image_size = image.size
</code></pre>
<p>You need provide the absolute path of the file as well like above.</p>
<p>Also ... | 1 | 2016-08-20T13:44:18Z | [
"python",
"python-2.7",
"image-processing"
] |
How to check if the lines in two files are included in each other | 39,053,697 | <p>I am new to python have got a problem with comparison of two files and get the output in Boolean form. I have seen few recommendations here, but due to less application knowledge I think I couldn't get still. These two permission related text files need to be compared</p>
<p>1ST text file :perm.txt</p>
<pre><code>... | 1 | 2016-08-20T11:38:56Z | 39,061,382 | <p>If you only need a fast and quick string comparison, why don't you use hashing (md5/sha1)?</p>
<p>Sort the lines, then use something like this:</p>
<pre><code>import md5
m1 = md5.md5(file1_str)
m2 = md5.md5(file2_str)
if m1.hexdigest() == m2.hexdigest():
....
else:
....
</code></pre>
| 1 | 2016-08-21T06:18:23Z | [
"python"
] |
How to check if the lines in two files are included in each other | 39,053,697 | <p>I am new to python have got a problem with comparison of two files and get the output in Boolean form. I have seen few recommendations here, but due to less application knowledge I think I couldn't get still. These two permission related text files need to be compared</p>
<p>1ST text file :perm.txt</p>
<pre><code>... | 1 | 2016-08-20T11:38:56Z | 39,061,684 | <p>The function </p>
<pre><code>get_line_set = lambda f_name: set([l.strip() for l in open(f_name, 'r')])
</code></pre>
<p>Creates a <a href="https://docs.python.org/2/library/sets.html" rel="nofollow"><code>set</code></a> of the lines of <code>f_name</code>.</p>
<p>Now you can just use </p>
<pre><code>get_line_set... | 1 | 2016-08-21T07:04:54Z | [
"python"
] |
How to check if the lines in two files are included in each other | 39,053,697 | <p>I am new to python have got a problem with comparison of two files and get the output in Boolean form. I have seen few recommendations here, but due to less application knowledge I think I couldn't get still. These two permission related text files need to be compared</p>
<p>1ST text file :perm.txt</p>
<pre><code>... | 1 | 2016-08-20T11:38:56Z | 39,061,934 | <p>one way to do this is below:</p>
<pre><code>f1 = open('perm.txt', 'rb')
f2 = open('op3.txt', 'rb')
f1_lines = f1.readlines()
f2_lines = f2.readlines()
f1.close()
f2.close()
overall_compare_result = True
fo = open('out1.txt', 'w')
for each in f1_lines:
if each in f2_lines:
fo.write(each.strip() + ' True\... | 0 | 2016-08-21T07:38:25Z | [
"python"
] |
Improving the performance of repetitive groupby operations | 39,053,734 | <p>I have a DataFrame with MultiIndex which is basically a binary matrix:</p>
<pre><code>day day01 day02
session session1 session2 session3 session1 session2 session3
0 1 0 0 0 0 0
1 0 0 1 1 ... | 3 | 2016-08-20T11:44:15Z | 39,054,362 | <p>Assuming a regular data format (equal number of days and sessions across each row), here's a NumPy based approach using <code>np.unique</code> with the output having their indexes in sorted order -</p>
<pre><code># Extract array
a,b = df.columns.levels
arr = df.values.reshape(-1,len(a),len(b))
# Get session counts... | 1 | 2016-08-20T12:50:48Z | [
"python",
"pandas",
"numpy"
] |
Django error SiteProfileNotAvailable | 39,053,745 | <p>Im installed django-userena with django 1.9.7,
<a href="https://github.com/bread-and-pepper/django-userena" rel="nofollow">https://github.com/bread-and-pepper/django-userena</a>
step by step ,why I'm I getting this error?</p>
<p>Thanks
settings.py</p>
<pre><code>INSTALLED_APPS = [
'userena',
'guardian',
'easy_thum... | 0 | 2016-08-20T11:45:16Z | 39,054,132 | <p>As mentioned in the <a href="http://django-userena.readthedocs.io/en/latest/installation.html#id2" rel="nofollow">docs</a> you need to create a Site object (see <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/sites/" rel="nofollow">Sites Framework</a>) either from admin panel or shell or via fixture and ... | 0 | 2016-08-20T12:26:30Z | [
"python",
"django",
"django-users"
] |
How to set a clicking clock in a pygame window | 39,053,817 | <pre><code>#!/usr/bin/python
# -*- coding: utf-8 -*-
import pygame
import sys
import datetime
import time
class TextPicture(pygame.sprite.Sprite):
def __init__(self, speed, location):
pygame.sprite.Sprite.__init__(self)
now = datetime.datetime.now()
text = now.strftime("%H:%M:%S")
... | 0 | 2016-08-20T11:52:03Z | 39,054,676 | <p>You could do it by using <a href="http://www.pygame.org/docs/ref/time.html#pygame.time.set_timer" rel="nofollow"><code>pygame.time.set_timer()</code></a> to make "tick events" be generated which cause the clock's image to be updated when encountered in the event processing loop.</p>
<p>To make implementing this eas... | 2 | 2016-08-20T13:27:53Z | [
"python",
"python-2.7",
"pygame-clock"
] |
how to select a radio button in selenium python? | 39,053,899 | <pre><code><ul>
<li>
<label class="checkbox">
<input checked="checked" id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="0" />
... | 0 | 2016-08-20T12:01:35Z | 39,053,988 | <p>You are using find_elements.... which returns a list. Use findelement or getelement which returns one element(i got no idea abt python functions). Or else use an index 0 to findelements. it is saying it is trying yo find a click method on a list which it aint got</p>
| 0 | 2016-08-20T12:10:40Z | [
"python",
"selenium",
"selenium-webdriver"
] |
how to select a radio button in selenium python? | 39,053,899 | <pre><code><ul>
<li>
<label class="checkbox">
<input checked="checked" id="fechapublicacion" name="fechapublicacion" onclick="javascript: filtrarListado(&#39;fechapublicacion&#39;, this);" type="radio" value="0" />
... | 0 | 2016-08-20T12:01:35Z | 39,054,046 | <p>Actually <code>find_elements</code> returns list that's why you are in trouble, you should try using <code>find_element</code> instead as below :-</p>
<pre><code>browser.find_element_by_id("fechapublicacion").click()
</code></pre>
<p>Or if you want to use <code>find_elements</code>, You should try using index in r... | 2 | 2016-08-20T12:17:00Z | [
"python",
"selenium",
"selenium-webdriver"
] |
How to get more usable error messages from ansible-playbook? | 39,054,099 | <p><code>ansible-playbook</code> gives me errors that look like this:</p>
<pre><code>fatal: [test.example.com]: FAILED! => {"changed": false, "cmd": "./manage.py migrate --noinput
--pythonpath=/srv/virtualenv/myapp/bin/python3", "failed": true, "msg": "\n:stderr: Traceback (most recent call last):\n File \"./manag... | 0 | 2016-08-20T12:23:15Z | 39,055,930 | <p>Ansible allows you to control its output by using <a href="http://docs.ansible.com/ansible/developing_plugins.html#callbacks" rel="nofollow">callback plugins</a> and provides a few optional callbacks <a href="https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback" rel="nofollow">out of the box</a... | 1 | 2016-08-20T15:42:46Z | [
"python",
"ansible"
] |
How to get more usable error messages from ansible-playbook? | 39,054,099 | <p><code>ansible-playbook</code> gives me errors that look like this:</p>
<pre><code>fatal: [test.example.com]: FAILED! => {"changed": false, "cmd": "./manage.py migrate --noinput
--pythonpath=/srv/virtualenv/myapp/bin/python3", "failed": true, "msg": "\n:stderr: Traceback (most recent call last):\n File \"./manag... | 0 | 2016-08-20T12:23:15Z | 39,056,816 | <p>Increase the verbosity. Add <code>-vvvv</code> at the end of ansible-playbook command. It will set the verbosity to 4 and that much logs are good enough most of the time.</p>
| 1 | 2016-08-20T17:17:23Z | [
"python",
"ansible"
] |
Level-Wise Sorting of Series in Pandas | 39,054,107 | <p>I have a dataframe called mydf</p>
<pre><code>mydf
</code></pre>
<p><a href="http://i.stack.imgur.com/atOtv.png" rel="nofollow"><img src="http://i.stack.imgur.com/atOtv.png" alt="enter image description here"></a></p>
<p>I performed below operation and it is then converted into a series.</p>
<pre><code>mydf.grou... | 1 | 2016-08-20T12:24:00Z | 39,056,119 | <p>Unfortunately everything I came up with requires double grouping/sorting. Suppose we have a DataFrame</p>
<pre><code>import pandas as pd
import numpy as np
import random
d = pd.DataFrame({'type': ['actor']*5+['actress']*5,
'name' : [random.choice(['a', 'b', 'c']) for i in range(10)]})
d
n... | 0 | 2016-08-20T16:01:00Z | [
"python",
"python-3.x",
"sorting",
"pandas",
"series"
] |
Tkinter custom create buttons | 39,054,156 | <p>can tkinter custom buttons from a image or icon
like this
<a href="http://i.stack.imgur.com/pOTbI.png" rel="nofollow"><img src="http://i.stack.imgur.com/pOTbI.png" alt="enter image description here"></a></p>
<p><a href="http://i.stack.imgur.com/nqNRA.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/nqNRA.jpg... | -2 | 2016-08-20T12:28:42Z | 39,057,406 | <p>It's possible!</p>
<p>If you check out the <a href="http://effbot.org/tkinterbook/button.htm" rel="nofollow">button documentation</a>, you can use an image to display on the button.</p>
<p>For example:</p>
<pre><code>from tkinter import *
root = Tk()
button = Button(root, text="Click me!")
img = PhotoImage(file... | 1 | 2016-08-20T18:25:11Z | [
"python",
"button",
"tkinter",
"python-3.5",
"ttk"
] |
How to override Django-CMS templates | 39,054,370 | <p>settings.py</p>
<pre><code>from .ENV import BASE_DIR, ENV_VAR
# SECURITY WARNING: don't run with debug turned on in production!
# False if not in os.environ
DEBUG = ENV_VAR('DEBUG', default=False)
# SECURITY WARNING: keep the secret key used in production secret!
# If not found in os.environ will raise Improperly... | 0 | 2016-08-20T12:51:35Z | 39,099,777 | <p>First off, if it redirects you to the login page, that'll most likely be because there isn't any content yet. Based on the question, I'm assuming this is a new installation with no pages, so you'd need to login, create your pages, and then you should get it to load without the admin redirect.</p>
<p>In terms of ove... | 1 | 2016-08-23T11:21:52Z | [
"python",
"django",
"django-cms"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,054,460 | <pre><code>a=[{'time':3},{'time':4},{'time':5}]
b = []
cumsum = 0
for e in a[::-1]:
cumsum += e['time']
b.insert(0, {'exp':e['time'], 'cumsum':cumsum})
print(b)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code>[{'exp': 3, 'cumsum': 12}, {'exp': 4, 'cumsum': 9}, {'exp': 5, 'cumsum': 5}]
</code></pre>
... | 6 | 2016-08-20T13:04:33Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,054,556 | <p>Try this,</p>
<pre><code>cumsum_list = np.cumsum([i['time'] for i in a][::-1])[::-1]
for i,j in zip(a,cumsum_list):
i.update({'cumsum':j})
</code></pre>
<p><strong>Result</strong></p>
<pre><code>[{'cumsum': 12, 'time': 3}, {'cumsum': 9, 'time': 4}, {'cumsum': 5, 'time': 5}]
</code></pre>
<p><strong>Efficien... | 1 | 2016-08-20T13:15:27Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,054,557 | <p>Using <code>pandas</code>:</p>
<pre><code>In [4]: df = pd.DataFrame([{'time':3},{'time':4},{'time':5}])
In [5]: df
Out[5]:
time
0 3
1 4
2 5
In [6]: df['cumsum'] = df.ix[::-1, 'time'].cumsum()[::-1]
In [7]: df
Out[7]:
time cumsum
0 3 12
1 4 9
2 5 5
In [8]: df.col... | 0 | 2016-08-20T13:15:40Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,054,593 | <p>Here's another approach using <code>pandas</code> -</p>
<pre><code>df = pd.DataFrame(a)
df.columns = ['exp']
df['cumsum'] = (df[::-1].cumsum())[::-1]
out = df.T.to_dict().values()
</code></pre>
<p>Sample input, output -</p>
<pre><code>In [396]: a
Out[396]: [{'time': 3}, {'time': 4}, {'time': 5}]
In [397]: out
Ou... | 0 | 2016-08-20T13:18:59Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,054,943 | <p>Try this:</p>
<pre><code>a = [{'time':3},{'time':4},{'time':5}]
df = pd.DataFrame(a).rename(columns={'time':'exp'})
df["cumsum"] = df['exp'][::-1].cumsum()
df.to_dict(orient='records')
</code></pre>
<p>Dicts are not ordered.</p>
<pre><code> [{'cumsum': 12, 'exp': 3}, {'cumsum': 9, 'exp': 4}, ... | 1 | 2016-08-20T13:58:21Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
How to find cumulative sum of items in a list of dictionaries in python | 39,054,413 | <p>I have a list which is like</p>
<pre><code>a=[{'time':3},{'time':4},{'time':5}]
</code></pre>
<p>I want to get the cumulative sum of the values in reversed order like this</p>
<pre><code>b=[{'exp':3,'cumsum':12},{'exp':4,'cumsum':9},{'exp':5,'cumsum':5}]
</code></pre>
<p>What is the most efficient way to get thi... | 2 | 2016-08-20T12:56:48Z | 39,056,177 | <p>A generator based solution:</p>
<pre><code>def foo(a, var='value'):
cum=0
for i in a:
j=i[var]
cum += j
yield {var:j, 'sum':cum}
In [79]: a=[{'time':i} for i in range(5)]
In [80]: list(foo(a[::-1], var='time'))[::-1]
Out[80]:
[{'sum': 10, 'time': 0},
{'sum': 10, 'time': 1},
{'sum... | 2 | 2016-08-20T16:05:33Z | [
"python",
"pandas",
"numpy",
"dictionary",
"deque"
] |
Tensorflow: Using tf.slice to split the input | 39,054,414 | <p>I'm trying to split my input layer into different sized parts. I'm trying to use tf.slice to do that but it's not working.</p>
<p>Some sample code:</p>
<pre><code>import tensorflow as tf
import numpy as np
ph = tf.placeholder(shape=[None,3], dtype=tf.int32)
x = tf.slice(ph, [0, 0], [3, 2])
input_ = np.array([[1... | 0 | 2016-08-20T12:57:00Z | 39,054,738 | <p>You can specify one negative dimension in the <code>size</code> parameter of <code>tf.slice</code>. The negative dimension tells Tensorflow to dynamically determine the right value basing its decision on the other dimensions.</p>
<pre><code>import tensorflow as tf
import numpy as np
ph = tf.placeholder(shape=[None... | 1 | 2016-08-20T13:35:05Z | [
"python",
"tensorflow"
] |
How to split output from a list of urls in scrapy | 39,054,475 | <p>I am trying to generate a csv file for each scraped url from a list of urls in scrapy. I do understand I shall modify pipeline.py, however all my attempts have failed so far. I do not understand how I can pass the url being scraped to the pipeline and use this as name for the output and split the output accordingly.... | 1 | 2016-08-20T13:06:20Z | 39,064,519 | <p>I think you should be doing all those things in batch as a post-processing step when your crawl finishes instead of per-item but here's a draft on how you could do what you want:</p>
<pre><code>from scrapy import Spider
from scrapy.selector import Selector
from vApp.items import fItem
class VappSpider(Spider):
... | 0 | 2016-08-21T13:06:08Z | [
"python",
"scrapy"
] |
Pyspark reduceByKey on nested tuples | 39,054,489 | <p>My question is similar to <a href="http://stackoverflow.com/questions/30831530/pyspark-reducebykey-on-multiple-values">PySpark reduceByKey on multiple values</a> but with a somehow critical difference. I am new to PySpark, so I am for sure missing something obvious.</p>
<p>I have an RDD with the following structure... | 0 | 2016-08-20T13:07:15Z | 39,056,158 | <p>You shouldn't use <code>reduceByKey</code> here at all. It takes an associative and commutative function with signature. <code>(T, T) => T</code>. It should be obvious that it is not applicable when you have <code>List[Tuple[U, T]]</code> as an input and you expect <code>T</code> as an output.</p>
<p>Since it is... | 0 | 2016-08-20T16:03:52Z | [
"python",
"apache-spark",
"pyspark"
] |
How to create a list containing names of functions? | 39,054,533 | <p>I am completely new to python and programming but I am trying to learn it using more practical approach.</p>
<p>What I am trying to do is an exercise for converting different units, e.g. pounds -> kilograms, foot -> meter etc.</p>
<p>I have defined all the functions for different unit pairs:</p>
<pre><code>def kg... | 0 | 2016-08-20T13:12:03Z | 39,054,797 | <p>Because you've enclosed the function names (in the list) in quotes, they have become strings.</p>
<p>Change your list to:</p>
<pre><code>unit_list = [kg_to_g, g_to_kg, inch_to_cm, cm_to_inch,
ft_to_cm, cm_to_ft, yard_to_m, m_to_yard,
mile_to_km, km_to_mile, oz_to_g, g_to_oz,
pound_to_kg,... | 0 | 2016-08-20T13:42:05Z | [
"python",
"list",
"function"
] |
How to create a list containing names of functions? | 39,054,533 | <p>I am completely new to python and programming but I am trying to learn it using more practical approach.</p>
<p>What I am trying to do is an exercise for converting different units, e.g. pounds -> kilograms, foot -> meter etc.</p>
<p>I have defined all the functions for different unit pairs:</p>
<pre><code>def kg... | 0 | 2016-08-20T13:12:03Z | 39,054,850 | <p>I think this is what you are asking about. You should be able to store the functions in a list like this</p>
<pre><code>unit_list = [kg_to_g, g_to_kg, inch_to_cm, cm_to_inch, ft_to_cm]
</code></pre>
<p>You can then call each item in the list and give it a parameter and it should execute the function for example l... | -1 | 2016-08-20T13:48:31Z | [
"python",
"list",
"function"
] |
Performance between C-contiguous and Fortran-contiguous array operations | 39,054,539 | <p>Below, I compared performance when dealing with sum operations between C-contiguous and Fortran-contiguous arrays (<a href="http://www.visitusers.org/index.php?title=C_vs_Fortran_memory_order" rel="nofollow">C vs FORTRAN memory order</a>). I set <code>axis=0</code> to ensure numbers are added up column wise. I was s... | 10 | 2016-08-20T13:12:51Z | 39,055,449 | <p>That's expected. If you check the result of </p>
<pre><code>%timeit f.sum(axis=1)
</code></pre>
<p>it also gives similar result with the timing of <code>c</code>. Similarly, </p>
<pre><code>%timeit c.sum(axis=1)
</code></pre>
<p>is slower. </p>
<hr>
<p>Some explanation: suppose you have the following structure... | 1 | 2016-08-20T14:53:43Z | [
"python",
"numpy",
"multidimensional-array",
"scipy"
] |
Performance between C-contiguous and Fortran-contiguous array operations | 39,054,539 | <p>Below, I compared performance when dealing with sum operations between C-contiguous and Fortran-contiguous arrays (<a href="http://www.visitusers.org/index.php?title=C_vs_Fortran_memory_order" rel="nofollow">C vs FORTRAN memory order</a>). I set <code>axis=0</code> to ensure numbers are added up column wise. I was s... | 10 | 2016-08-20T13:12:51Z | 39,058,941 | <p>I think it's in the implementation of the np.sum(). For example:</p>
<pre><code>import numpy as np
A = np.random.standard_normal((10000,10000))
C = np.array(A, order='C')
F = np.array(A, order='F')
</code></pre>
<p>Benchmarking with Ipython:</p>
<pre><code>In [7]: %timeit C.sum(axis=0)
10 loops, best of 3: 101 m... | 2 | 2016-08-20T21:40:51Z | [
"python",
"numpy",
"multidimensional-array",
"scipy"
] |
Python BeautifulSoup extracting text from result | 39,054,666 | <p>I am trying to get the text from contents but when i try beautiful soup functions on the result variable it results in errors.</p>
<pre><code>from bs4 import BeautifulSoup as bs
import requests
webpage = 'http://www.dictionary.com/browse/coypu'
r = requests.get(webpage)
page_text = r.text
soup = bs(page_text, 'ht... | 1 | 2016-08-20T13:26:34Z | 39,054,750 | <p><code>soup.find_all()</code> returns a list. Since in your case, it returns only one element in the list, you can do:</p>
<pre><code>>>> type(result)
<class 'bs4.element.ResultSet'>
>>> type(result[0])
<class 'bs4.element.ResultSet'>
>>> result[0].get('content')
Coypu definiti... | 1 | 2016-08-20T13:36:14Z | [
"python",
"regex",
"beautifulsoup"
] |
Python BeautifulSoup extracting text from result | 39,054,666 | <p>I am trying to get the text from contents but when i try beautiful soup functions on the result variable it results in errors.</p>
<pre><code>from bs4 import BeautifulSoup as bs
import requests
webpage = 'http://www.dictionary.com/browse/coypu'
r = requests.get(webpage)
page_text = r.text
soup = bs(page_text, 'ht... | 1 | 2016-08-20T13:26:34Z | 39,054,965 | <p>When you only want the first or a single tag use <em>find</em>, find_all returns a <em>list/resultSet</em>:</p>
<pre><code>result = soup.find('meta', attrs={'name':'description'})["contents"]
</code></pre>
<p>You can also use a <em>css selector</em> with <em>select_one</em>:</p>
<pre><code>result = soup.select_on... | 1 | 2016-08-20T14:00:19Z | [
"python",
"regex",
"beautifulsoup"
] |
Python BeautifulSoup extracting text from result | 39,054,666 | <p>I am trying to get the text from contents but when i try beautiful soup functions on the result variable it results in errors.</p>
<pre><code>from bs4 import BeautifulSoup as bs
import requests
webpage = 'http://www.dictionary.com/browse/coypu'
r = requests.get(webpage)
page_text = r.text
soup = bs(page_text, 'ht... | 1 | 2016-08-20T13:26:34Z | 39,064,389 | <p>you need not to use findall as only by using find you can get desired output'</p>
<pre><code>from bs4 import BeautifulSoup as bs
import requests
webpage = 'http://www.dictionary.com/browse/coypu'
r = requests.get(webpage)
page_text = r.text
soup = bs(page_text, 'html.parser')
result = soup.find('meta', {'name':'... | 0 | 2016-08-21T12:50:39Z | [
"python",
"regex",
"beautifulsoup"
] |
pyqt dialog not showing a second time | 39,054,690 | <p>I have a pyqt app where I want a dialog to display when I click a menu item. If the dialog loses focus and the menu item is clicked again, it brings the dialog to the front. This is working fine so far.</p>
<p>The problem is that when the dialog is opened and then closed, clicking the menu item doesnt create/displa... | 1 | 2016-08-20T13:29:26Z | 39,056,473 | <p>There are probably several ways to do this, but here's one possibility:</p>
<pre><code>class ReadingList(QtGui.QMainWindow, mainWindow.Ui_MainWindow):
def __init__(self):
super(ReadingList, self).__init__()
self.setupUi(self)
self.actionAbout.triggered.connect(self.showAbout)
... | 0 | 2016-08-20T16:41:00Z | [
"python",
"qt",
"pyqt",
"pyqt4"
] |
Getting key of unique values in a nested dict within lists | 39,054,836 | <p>I have a dict, which contains of elements with the following structure</p>
<pre><code>{'task0': {'id': 0, 'successor':[<other elements>]}
</code></pre>
<p>Every element contains a unique id and a successor list of the mentioned elements. The can be also empty, which means, this element has no successors. </p... | 2 | 2016-08-20T13:46:33Z | 39,056,695 | <p>The obvious issue that we did not see earlier was unconditional <code>return</code> statement in your inner loop.</p>
<p>You have to return something only if it is not <code>None</code>, else other items of the list other than the first one are ignored.</p>
<p>(note I have changed <code>iteritems</code> to <code>i... | 0 | 2016-08-20T17:03:22Z | [
"python",
"dictionary",
"nested",
"iteration"
] |
Getting key of unique values in a nested dict within lists | 39,054,836 | <p>I have a dict, which contains of elements with the following structure</p>
<pre><code>{'task0': {'id': 0, 'successor':[<other elements>]}
</code></pre>
<p>Every element contains a unique id and a successor list of the mentioned elements. The can be also empty, which means, this element has no successors. </p... | 2 | 2016-08-20T13:46:33Z | 39,077,423 | <p>Based on tobias_k comment, I found an easier way to store the information.
Because every node object has a unique ID, it is enough to store these IDs only.
The index of each sublist is the index of the node, for which the successors are defined.</p>
<pre><code>successor_list = [[successors_node0], [successors_node1... | 0 | 2016-08-22T10:40:21Z | [
"python",
"dictionary",
"nested",
"iteration"
] |
Need help using regex to extract strings from json string from text (python) | 39,054,914 | <p>Hi so I'm trying to extract moderator names from a simple piece of code like this:</p>
<pre><code>{
"_links": {},
"chatter_count": 2,
"chatters": {
"moderators": [
"nightbot",
"vivbot"
],
"staff": [],
"admins": [],
"global_mods": [],
"viewers": []
}
}
</code></pre>
<p>I'... | 1 | 2016-08-20T13:55:36Z | 39,055,469 | <pre><code>moderators = list()
first = re.compile(r'moderators.*?\[([^\]]*)', re.I)
second = re.compile(r'"(.*?)"')
strings = first.findall(string)
for strings2 in strings:
moderators = moderators + second.findall(strings2)
</code></pre>
<p>This should do the trick</p>
<p>The first regular expression extracts ever... | 1 | 2016-08-20T14:55:52Z | [
"python",
"json",
"regex"
] |
How to change fields label to a specific language in django admin panel? | 39,054,923 | <p>I am using Python 3 and django 1.10. <br>
i have a model named <code>Comapny</code>. It has a field called title , i am trying to save the company title in two languages but dont wanna separate them to <code>title_en</code> and <code>title_fa</code>. i am want to save both of them using <code>Json</code> in the Comp... | 0 | 2016-08-20T13:56:30Z | 39,055,852 | <pre><code>from django.utils.translation import ugettext_lazy as _
class MyModel(models.Model):
title = models.CharField(_('mymodeltitle'), max_length=80)
</code></pre>
<p>Do a make message. Translate. Compile messages. It should be translated in the admin. </p>
<p>For translations in Django :</p>
<p><a href=... | 2 | 2016-08-20T15:34:20Z | [
"python",
"django",
"django-models",
"django-admin",
"multilingual"
] |
Processes not joining even after flushing their queues | 39,054,963 | <p>I wrote a program using the module <code>multiprocessing</code> which globally executes as follows:</p>
<ol>
<li>both a <code>simulation</code> and an <code>ui</code> processes are started.</li>
<li>the <code>simulation</code> process feeds a queue with new simulation states. If the queue is full, the simulation lo... | 0 | 2016-08-20T14:00:18Z | 39,062,761 | <p>Sounds like the issue was indeed due to some delay in pushing the data through the queue, causing the flushes to be ineffective because fired too early.</p>
<p>A simple <code>while process.is_alive(): flush_the_queues()</code> seems to do the trick!</p>
| 0 | 2016-08-21T09:27:50Z | [
"python",
"multithreading",
"queue",
"multiprocessing",
"ipc"
] |
How to save state of selenium web driver in python? | 39,054,992 | <p>I am trying to scrape this website: <a href="http://www.infoempleo.com/ofertas-internacionales/" rel="nofollow">http://www.infoempleo.com/ofertas-internacionales/</a>.
I wanted to scrape by selecting the "Last 15 days" radio button. So I wrote this code.</p>
<pre><code>browser = webdriver.Chrome('C:\Users\Junaid\Do... | 0 | 2016-08-20T14:03:33Z | 39,058,488 | <p>I have found a work around this problem. Instead of saving links to next pages in a list. I am selecting the nextPage button/element and using <code>.click()</code>. This way the <code>browser.get(url)</code> is not needed to call again and the page is not reloaded.</p>
| 0 | 2016-08-20T20:34:40Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Recursive multi shift caesar cipher - Type error (can't conc None) | 39,054,999 | <p>First time posting here, newbie to python but really enjoying what I'm doing with it. Working through the MIT Open courseware problems at the moment. Any suggestions of other similar resources?</p>
<p>My problem is with returning a recursive function that's meant to build a list of multi layer shifts as tuples wher... | 0 | 2016-08-20T14:04:20Z | 39,056,298 | <p>Below is my attempt at reworking your code to do what you want. Specific changes: dropped the range from 27 to 26 to let the loop exit naturally and return the empty <code>shifts</code> array; combined <code>a</code> and <code>shift</code> and started them at zero so an unencoded text will return <code>[(0, 0)]</co... | 0 | 2016-08-20T16:19:59Z | [
"python",
"recursion",
"caesar-cipher"
] |
Multiprocessing using shared memory | 39,055,102 | <p>Can someone provide me with sample code to share a writable array or a list among a pool of worker processes or even individually spawned processes using the multiprocessing module of python using locks? My code below spawns 2 processes of which one should print '1' and the other should print '2' to the shared array... | 0 | 2016-08-20T14:16:39Z | 39,055,967 | <p>A few issues that I found in your code. First of all, it <a href="https://docs.python.org/3.5/library/multiprocessing.html#multiprocessing-programming" rel="nofollow">seems to be a good idea</a> to pass all shared resources to child and use <code>if __name__ == '__main__'</code>. Secondly, I don't think <code>multip... | 0 | 2016-08-20T15:45:04Z | [
"python",
"arrays",
"multiprocessing",
"shared-memory"
] |
Multiprocessing using shared memory | 39,055,102 | <p>Can someone provide me with sample code to share a writable array or a list among a pool of worker processes or even individually spawned processes using the multiprocessing module of python using locks? My code below spawns 2 processes of which one should print '1' and the other should print '2' to the shared array... | 0 | 2016-08-20T14:16:39Z | 39,055,993 | <p>One potential problem with your code is that to use <code>multiprocessing</code> on Windows you need to put the code for the main process in an <code>if __name__ == '__main__':</code> block. See the <strong>Safe importing of main module</strong> subsection of the <a href="https://docs.python.org/2/library/multiproce... | 0 | 2016-08-20T15:47:35Z | [
"python",
"arrays",
"multiprocessing",
"shared-memory"
] |
Installing basemap: setup.py encounters an error | 39,055,140 | <p>I followed the rules <a href="http://matplotlib.org/basemap/users/installing.html" rel="nofollow">here</a> to install basemap step by step. But error occured at last.</p>
<p>When I typed the command: python setup.py, an erorr appears as follows:</p>
<pre><code>gddxz@ubuntu:~/Downloads/basemap-1.0.7$ python setup.p... | 0 | 2016-08-20T14:21:14Z | 39,055,536 | <p>The problem is that this command requires at least one parameter. According to the instructions you should execute <code>python setup.py install</code>.</p>
| 0 | 2016-08-20T15:02:39Z | [
"python",
"matplotlib-basemap"
] |
Installing basemap: setup.py encounters an error | 39,055,140 | <p>I followed the rules <a href="http://matplotlib.org/basemap/users/installing.html" rel="nofollow">here</a> to install basemap step by step. But error occured at last.</p>
<p>When I typed the command: python setup.py, an erorr appears as follows:</p>
<pre><code>gddxz@ubuntu:~/Downloads/basemap-1.0.7$ python setup.p... | 0 | 2016-08-20T14:21:14Z | 39,366,781 | <p>seems to have worked: 'python setup.py install'</p>
| 1 | 2016-09-07T09:57:37Z | [
"python",
"matplotlib-basemap"
] |
URLError doesn't return json body | 39,055,149 | <p>I have built a REST interface. On '400 Bad Request' it returns a json body with specific information about the error.</p>
<pre><code>(Pdb) error.code
400
</code></pre>
<p>Python correctly throws a URLError with these headers</p>
<pre><code>(Pdb) print(error.headers)
Cache-Control: no-cache
Pragma: no-cache
Conte... | 0 | 2016-08-20T14:22:01Z | 39,083,889 | <p>I found that this works the first time it is called, but does not work if called again.</p>
<p>error.read().decode('utf-8')</p>
| 0 | 2016-08-22T15:55:03Z | [
"python",
"json",
"url",
"exception"
] |
user profile of other user shows up | 39,055,156 | <p>The id of admin is <strong>1</strong> when i open the admin user at the admin panel. Likewise the id of <code>michael</code> is <strong>2</strong> but when i click the profile icon instead of showing me the profile of admin i get profile of <code>michael</code>. To get the id i have used <code>user.id</code> of the ... | 0 | 2016-08-20T14:22:43Z | 39,055,583 | <p>Just add <code>1</code> everywhere you use <code>profile_id</code></p>
<pre><code>def profile(request, profile_id):
if profile_id is "0": # Is profile_id a string or integer?
userProfile = get_object_or_404(UserProfile, pk=(profile_id+1)) # What does this do?
else:
userProfile = get_object_o... | 0 | 2016-08-20T15:06:54Z | [
"python",
"django",
"django-models",
"django-views"
] |
user profile of other user shows up | 39,055,156 | <p>The id of admin is <strong>1</strong> when i open the admin user at the admin panel. Likewise the id of <code>michael</code> is <strong>2</strong> but when i click the profile icon instead of showing me the profile of admin i get profile of <code>michael</code>. To get the id i have used <code>user.id</code> of the ... | 0 | 2016-08-20T14:22:43Z | 39,061,048 | <p>I used slug instead of id and for using slug i have used pre_save signal where slug value is taken from the username. </p>
<pre><code>def profile(request, profile_slug):
if profile_slug is None:
userprofile = get_object_or_404(UserProfile,slug=profile_slug)
else:
userprofile = get_object_or_... | 0 | 2016-08-21T05:19:02Z | [
"python",
"django",
"django-models",
"django-views"
] |
IDE recommends to decorate Django CBV methods with @staticmethod | 39,055,195 | <p>The recommendation seems to make sense because <code>self</code> isn't used in the method, but now I'm curious:</p>
<ul>
<li><p>is it an oversight of CBV's and users should manually decorate each <code>@staticmethod</code>?</p></li>
<li><p>is there already some code in Django that automagically makes all CBV method... | 1 | 2016-08-20T14:27:02Z | 39,056,113 | <p>No, you shouldn't do this. These are instance methods and need to remain so.</p>
<p>It does seem a bit odd though that you're not using any of the instance values or calling any instance methods there. Usually you would reference the URL arguments via <code>self.kwargs</code>, and call other methods such as <code>s... | 1 | 2016-08-20T16:00:38Z | [
"python",
"django",
"static-methods",
"django-class-based-views"
] |
Jupyter Notebook: Multiple notebook to one kernel? | 39,055,213 | <p>I'm doing some complicated works with Jupyter Notebook, so the notebook is very long (<a href="https://github.com/cqcn1991/Wind-Speed-Analysis" rel="nofollow">https://github.com/cqcn1991/Wind-Speed-Analysis</a>).</p>
<p>Sometimes, during the middle of the notebook, I want to do some additional analysis. Adding them... | 2 | 2016-08-20T14:29:38Z | 39,311,820 | <p>The <a href="https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/scratchpad" rel="nofollow">scratchpad</a> notebook extension sounds like exactly what you want.</p>
| 1 | 2016-09-03T22:18:54Z | [
"python",
"jupyter",
"jupyter-notebook"
] |
How to perform a tag-agnostic text string search in an html file? | 39,055,279 | <p>I'm using <a href="https://languagetool.org/" rel="nofollow">LanguageTool</a> (LT) with the --xmlfilter option enabled to spell-check HTML files. This forces LanguageTool to strip all tags before running the spell check. </p>
<p>This also means that all reported character positions are off because LT doesn't "see" ... | 0 | 2016-08-20T14:36:14Z | 39,066,521 | <p>The <code>--xmlfilter</code> option is deprecated because of issues like this. The proper solution is to remove the tags yourself but keep the positions so you have a mapping to correct the results that come back from LT. When using LT from Java, this is supported by <a href="https://github.com/languagetool-org/lang... | 1 | 2016-08-21T16:43:08Z | [
"python",
"html",
"parsing",
"tags",
"languagetool"
] |
How to perform a tag-agnostic text string search in an html file? | 39,055,279 | <p>I'm using <a href="https://languagetool.org/" rel="nofollow">LanguageTool</a> (LT) with the --xmlfilter option enabled to spell-check HTML files. This forces LanguageTool to strip all tags before running the spell check. </p>
<p>This also means that all reported character positions are off because LT doesn't "see" ... | 0 | 2016-08-20T14:36:14Z | 39,068,990 | <p>This may not be the speediest way to go, but pyparsing will recognize HTML tags in most forms. The following code inverts the typical scan, creating a scanner that will match any single character, and then configuring the scanner to skip over HTML open and close tags, and also common HTML <code>'&xxx;'</code> en... | 1 | 2016-08-21T21:21:59Z | [
"python",
"html",
"parsing",
"tags",
"languagetool"
] |
How does Python pass keyword changes values in list? | 39,055,331 | <p>I have one small program in Python. I have created list and I am passing it as function parameter. According to me it should give output as 1 2 3 4 5. But it is giving me <code>5 2 3 4 5</code> as output. If I am just writing 'pass' keyword inside for loop then it should not do anything.Then why is that changing my ... | -4 | 2016-08-20T14:40:47Z | 39,055,361 | <p>Your <code>for</code> loops sets the loop variable <code>list1[0]</code> to each value in the list <code>list1</code>. After it has finished, the loop variable contains whatever its value was in the last iteration, which in this case is <code>5</code>. If you don't want your loop to have this weird side effect, don'... | 2 | 2016-08-20T14:43:46Z | [
"python"
] |
Is searchsorted faster than get_loc to find label location in a DataFrame Index? | 39,055,530 | <p>I need to find the integer location for a label in a Pandas index. I know I can use get_loc method, but then I discovered searchsorted. Just wondering if I should use the latter for speed improvement, as I need to search for thousands of labels.</p>
| 1 | 2016-08-20T15:01:47Z | 39,055,999 | <p>It will depend on your usecase. using @ayhan's example.</p>
<p>With <code>get_loc</code> there is a big upfront cost of creating the hash table on the first lookup.</p>
<pre><code>In [22]: idx = pd.Index(['R{0:07d}'.format(i) for i in range(10**7)])
In [23]: to_search = np.random.choice(idx, 10**5, replace=False)
... | 3 | 2016-08-20T15:48:28Z | [
"python",
"pandas"
] |
Finding max value of an attribute of objects in a dictionary | 39,055,550 | <p>I have a collection of objects stored in a dictionary, and I am wanting to retrieve the maximum value of a particular attribute. The objects are cookies (think chocolate chip), and each cookie has its own temperature, heat capacity, batch number, etc. The batch number describes which set of cookies it exited the ove... | 2 | 2016-08-20T15:04:02Z | 39,055,678 | <p>You could just use max on the values:</p>
<pre><code>mx_batch = max(cookies.values(), key=operator.attrgetter('batch')).batch
</code></pre>
<p>Or just use a class attribute to keep the max:</p>
<pre><code>class Cookie:
mx = 0
def __init__(self, density, specificheat, batch):
self.rho = density
... | 1 | 2016-08-20T15:15:44Z | [
"python",
"object",
"dictionary"
] |
Finding max value of an attribute of objects in a dictionary | 39,055,550 | <p>I have a collection of objects stored in a dictionary, and I am wanting to retrieve the maximum value of a particular attribute. The objects are cookies (think chocolate chip), and each cookie has its own temperature, heat capacity, batch number, etc. The batch number describes which set of cookies it exited the ove... | 2 | 2016-08-20T15:04:02Z | 39,055,690 | <p>Here is one way to do it</p>
<pre><code># where objs is your dictionary of cookies
max(map(lambda i: objs[i].batch, objs))
</code></pre>
| 0 | 2016-08-20T15:17:40Z | [
"python",
"object",
"dictionary"
] |
Instantiate shared_ptr objects from SWIG in Python | 39,055,643 | <p>I have a <code>BaseClass</code> and some derived classes
</p>
<pre><code>#ifndef TEST_H__
#define TEST_H__
#include <iostream>
#include <memory>
class BaseClass
{
public:
virtual double eval(double x) const = 0;
};
class Square: public BaseClass
{
public:
double eval(double x) const {return x... | 1 | 2016-08-20T15:12:46Z | 39,057,504 | <p>SWIG has pretty good <a href="http://www.swig.org/Doc3.0/Library.html#Library_std_shared_ptr" rel="nofollow">support for <code>std::smart_ptr</code></a>. It all happens pretty transparently, so the changes you need to make to your .i file are just:</p>
<pre><code>%module test
%{
#define SWIG_FILE_WITH_INIT
#includ... | 1 | 2016-08-20T18:36:09Z | [
"python",
"c++",
"swig"
] |
Troubles in 3D points correpondance to 2D | 39,055,693 | <p>I made a little python script that produce some 3D points coordinates, deriving them from stereo vision (2 IR cameras).
3D coordinates are certainly correct.</p>
<p>Now I have a third RGB camera and I was given the calibration matrices (I can't verify them): K is the matrix of intrinsics and R,t are the component ... | 1 | 2016-08-20T15:17:53Z | 39,507,217 | <p>Updating: The problem seems to be this:
calibration of the two cameras (IR and RGB) were not made with the same standards, both accepted as true.</p>
| 0 | 2016-09-15T09:13:20Z | [
"python",
"computer-vision"
] |
importance of virtual environment setup for django with python | 39,055,728 | <p>I am very much new to the process of development of a web-application with django, and i came across this setting up and using virtual environment for python.
So i landed with some basic questions.</p>
<ol>
<li><p>What does this virtual environment exactly mean.</p></li>
<li><p>Does that has any sort of importance ... | 0 | 2016-08-20T15:22:07Z | 39,055,867 | <p>While I can't directly describe the experience with Django and virtual environments, I suspect its pretty similar to how I have been using Flask and virtualenv.</p>
<ol>
<li>Virtual environment does exactly what it says - where a environment is set up for you to develop your app (including your web app) that does n... | 2 | 2016-08-20T15:35:25Z | [
"python",
"django",
"virtualenv"
] |
importance of virtual environment setup for django with python | 39,055,728 | <p>I am very much new to the process of development of a web-application with django, and i came across this setting up and using virtual environment for python.
So i landed with some basic questions.</p>
<ol>
<li><p>What does this virtual environment exactly mean.</p></li>
<li><p>Does that has any sort of importance ... | 0 | 2016-08-20T15:22:07Z | 39,055,882 | <ol>
<li>A virtual environment is a way for you to have multiple versions of
python on your machine without them clashing with each other, each
version can be considered as a development environment and you can
have different versions of python libraries and modules all isolated
from one another</li>
<li><p>Yes it's ve... | 2 | 2016-08-20T15:36:38Z | [
"python",
"django",
"virtualenv"
] |
importance of virtual environment setup for django with python | 39,055,728 | <p>I am very much new to the process of development of a web-application with django, and i came across this setting up and using virtual environment for python.
So i landed with some basic questions.</p>
<ol>
<li><p>What does this virtual environment exactly mean.</p></li>
<li><p>Does that has any sort of importance ... | 0 | 2016-08-20T15:22:07Z | 39,055,884 | <ol>
<li><p>In most simple way, a virtual environment provides you a development environment independent of the host operating system. You can install and use necessary software in the /bin folder of the virtualenv, instead of using the software installed in the host machine. </p></li>
<li><p>Python development general... | 1 | 2016-08-20T15:36:53Z | [
"python",
"django",
"virtualenv"
] |
Writing list to file -- File written to not found | 39,055,783 | <p>I am using Python 3.</p>
<p>This is a script that i am in the process of writing. It asks for a name/birthday, takes that input, and appends it into a list. The list is then written to another file.</p>
<p>I have done research on this and can't find why it isn't working.</p>
<p>Here is my code:</p>
<pre><code>pr... | 0 | 2016-08-20T15:27:21Z | 39,055,918 | <p>This line:</p>
<pre><code> birthday = input("> ").upper
</code></pre>
<p>Should be:</p>
<pre><code> birthday = input("> ").upper()
</code></pre>
<p>The former assigns the <code>upper</code> function to the variable <code>birthday</code> rather than the uppercase of the input string. </p>
| 0 | 2016-08-20T15:41:13Z | [
"python",
"file",
"loops",
"python-3.x",
"user-input"
] |
Adding random numbers to a variable | 39,055,820 | <p>I'm looking for an output like this</p>
<pre><code>Computer Choice: 5
Total: 5
Continue? Yes or No
Computer Choice:2
Total: 7
</code></pre>
<p>It adds up the random numbers every time it's created. This is the part I'm trying to get to work: </p>
<pre><code> if player_bet <= Player.total_money_amount:
imp... | -2 | 2016-08-20T15:30:43Z | 39,055,862 | <p>Change <code>=+</code> to <code>+=</code>. The way you currently have it you are reassigning the variable <code>computer_total</code> to the value of <code>computer_choice</code> rather than adding them. Also, make sure to initialize <code>computer_total</code> before you start your loop. </p>
| 0 | 2016-08-20T15:35:13Z | [
"python",
"random"
] |
Adding random numbers to a variable | 39,055,820 | <p>I'm looking for an output like this</p>
<pre><code>Computer Choice: 5
Total: 5
Continue? Yes or No
Computer Choice:2
Total: 7
</code></pre>
<p>It adds up the random numbers every time it's created. This is the part I'm trying to get to work: </p>
<pre><code> if player_bet <= Player.total_money_amount:
imp... | -2 | 2016-08-20T15:30:43Z | 39,055,960 | <p>Please check the below code</p>
<pre><code>#Added intilization.
import random
computer_choice = 0
computer_total = 0
for i in range(5): #Just added to make it running. You can add you checkings here
computer_choice = random.randint(1, 5)
computer_total += computer_choice
print('Computer choice: ', co... | 0 | 2016-08-20T15:44:44Z | [
"python",
"random"
] |
Adding random numbers to a variable | 39,055,820 | <p>I'm looking for an output like this</p>
<pre><code>Computer Choice: 5
Total: 5
Continue? Yes or No
Computer Choice:2
Total: 7
</code></pre>
<p>It adds up the random numbers every time it's created. This is the part I'm trying to get to work: </p>
<pre><code> if player_bet <= Player.total_money_amount:
imp... | -2 | 2016-08-20T15:30:43Z | 39,056,061 | <p>You need to define <code>computer_total</code> outside of the loop first for it to work: </p>
<pre><code>import random
computer_total= 0
while True:
computer_choice = random.randint(1, 5) # Creates random number
computer_total += computer_choice
print('Computer choice: ', computer_choice)
print('... | 0 | 2016-08-20T15:55:48Z | [
"python",
"random"
] |
Appending grabbed frames from multiple video files into list of lists | 39,055,823 | <p>I am trying to appending a list with list of frames read from multiple video files. I have three video files,using VideoCapture class i am reading all the three files in a loop and trying to insert the read to a list. Finally I want a list of lists of frames read from the files.
for example:</p>
<p>frames from file... | 0 | 2016-08-20T15:31:07Z | 39,061,540 | <blockquote>
<p>I want the output as:[[1,2,3,4,5,6],[1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6,7,8,9,10]]</p>
</blockquote>
<p>You only have one list <code>indices=[]</code>. If you want a "list of lists of frames" you should extend your code by a second list in the for loop:</p>
<pre class="lang-py prettyprint-override"><co... | 1 | 2016-08-21T06:44:35Z | [
"python",
"list",
"opencv"
] |
"403 Forbidden" when use python urlib package to download the image | 39,055,838 | <p>i am new to urllib package.
i try to download all the images in website "<a href="http://www.girl-atlas.com/album/576545de58e039318beb37f6" rel="nofollow">http://www.girl-atlas.com/album/576545de58e039318beb37f6</a>"
the question is: when i copy the the url of an image, and pass the url to a browser, i will get an e... | -2 | 2016-08-20T15:32:23Z | 39,056,014 | <p>It is forbidden to use the URLs outside a broweser. To ensure this, browsers send always a referer, the site, from which the image is loaded. If a browser would be written in Python, this would look like this:</p>
<pre><code>import urllib.request
opener = urllib.request.URLopener()
opener.addheader('Referer', 'htt... | 0 | 2016-08-20T15:49:55Z | [
"python",
"web-crawler"
] |
How to start IPython kernel and connect using ZMQ sockets? | 39,055,839 | <p>I am working on a frontend to IPython in C++ (Qt).</p>
<p>I managed to embed Python in my application and retrieve plots and show these in my GUI. Now I want to start an IPython kernel and connect to it through ZMQ sockets.</p>
<p>I found a <a href="https://jupyter-client.readthedocs.io/en/latest/messaging.html" r... | 0 | 2016-08-20T15:32:30Z | 39,062,831 | <p>It turns out Thomas K was right. The right approach to start an IPython/Jupyter kernel in a different process is: (with python3 as example)</p>
<pre><code>import jupyter_client
kernel_manager, kernel_client = jupyter_client.start_new_kernel(kernel_name='python3')
</code></pre>
<p>When I initially tried this, I got... | 0 | 2016-08-21T09:37:29Z | [
"python",
"c++",
"qt",
"ipython",
"zeromq"
] |
How to get all the columns from id and filter to specific column? odoo9 | 39,056,108 | <p>I am getting the id of a customer by</p>
<pre><code>customer = context.get('partner_id')
print customer
#output
#6
</code></pre>
<p>Now i want to fetch all the values of all columns from <code>res.partner</code> where <code>id == 6</code></p>
<p>This will will give me many a recordset i guess </p>
<p>How do i f... | 0 | 2016-08-20T16:00:22Z | 39,056,143 | <p><strong>Old api</strong></p>
<pre><code>self.pool.get('res.partner').search(cr, uid, [('id', '=', customer)])
</code></pre>
<p>This would return a list of id's that matched the search so you have to call <code>browse</code> to actually get the records</p>
<p><strong>New api</strong></p>
<pre><code>self.env['res.... | 2 | 2016-08-20T16:02:48Z | [
"python",
"openerp",
"odoo-9"
] |
How to create a dynamic label colour in Tkinter? | 39,056,179 | <p>I'm trying to create a GUI BMI calculator for summer work.
I want to implement a feature where once you're BMI is calculated, the colour of the label changes depending on your BMI.</p>
<p>My current code reads:</p>
<pre><code>self.AnswerlabelVariable = tkinter.StringVar() #Creates a variable used later for changi... | -1 | 2016-08-20T16:05:43Z | 39,056,234 | <p>I've never used the StringVar class but whenever I wanted to change the color (or any parameter) of a Label, I'd just do it directly.</p>
<pre><code>Answerlabel['fg'] = 'black'
</code></pre>
| 1 | 2016-08-20T16:12:20Z | [
"python",
"tkinter"
] |
How to create a dynamic label colour in Tkinter? | 39,056,179 | <p>I'm trying to create a GUI BMI calculator for summer work.
I want to implement a feature where once you're BMI is calculated, the colour of the label changes depending on your BMI.</p>
<p>My current code reads:</p>
<pre><code>self.AnswerlabelVariable = tkinter.StringVar() #Creates a variable used later for changi... | -1 | 2016-08-20T16:05:43Z | 39,056,242 | <p>You need to use the <code>config()</code> method of the label to modify its <code>fg</code> and <code>bg</code> properties, like this:</p>
<pre><code>self.Answerlabel.config(fg='black', bg='blue') #Changes a labels colour
</code></pre>
| 1 | 2016-08-20T16:13:27Z | [
"python",
"tkinter"
] |
Text Based Mechanics in Python: Class, Dictionary, or List? | 39,056,208 | <p>I'm fairly new to coding in python (3) as somewhat of a hobby, but having fun playing around with some game mechanics without worrying about GUI. I'm currently working on a civilization-type text based game whose foundations lie in an old excel document. It's fairly centred on math and logic, which I think made for ... | 0 | 2016-08-20T16:09:46Z | 39,056,390 | <p>The point of a class is that it lets you create many <em>instances</em> of that class. You don't need to (and can't/shouldn't) subclass <code>Unit</code> for each unit. You simply need to <em>instantiate</em> the <code>Unit</code> class:</p>
<pre><code> archer1= Unit('archer', 0, 10, 80)
archer2= Unit('archer', 0,... | 1 | 2016-08-20T16:31:07Z | [
"python",
"text-based"
] |
Text Based Mechanics in Python: Class, Dictionary, or List? | 39,056,208 | <p>I'm fairly new to coding in python (3) as somewhat of a hobby, but having fun playing around with some game mechanics without worrying about GUI. I'm currently working on a civilization-type text based game whose foundations lie in an old excel document. It's fairly centred on math and logic, which I think made for ... | 0 | 2016-08-20T16:09:46Z | 39,056,510 | <p>For me, especially when you are creating a game, sub-classing is a really good way of writing good code. Mostly because you can implement independent features on your subclasses. For example every <code>Unit</code> may have the same movement mechanism, but an <code>Archer Unit</code> might defer in the attack proces... | 0 | 2016-08-20T16:44:56Z | [
"python",
"text-based"
] |
Python regex get substring after preceding substring match | 39,056,227 | <p>Text has no spaces, so I cannot split at all and use indexing on a list of strings.</p>
<p>The pattern I am looking for is:</p>
<p><code>check=</code></p>
<p>It is followed by a number and encoded querystring items (apache logfile) and is on every line of the file twice. I want output that gives me just what fol... | 0 | 2016-08-20T16:11:22Z | 39,056,290 | <p>Please check this code.</p>
<pre><code>import re
text = '''11.249.222.103 - - [15/Aug/2016:13:17:56 -0600] "GET /next2/120005079807?check=37593467%2CCOB&check=37593378%2CUAP&box=match&submit=Next HTTP/1.1" 500 1633 "https://mvt.squaretwofinancial.com/newmed/?button=All&submit=Submit" "Mozilla/5.0 (... | 2 | 2016-08-20T16:19:17Z | [
"python",
"regex"
] |
why it report a error RequirementParseError invalid requirement parse error at '' at sometimes when using newest paramiko 2.0.2 of python 2.7.12 | 39,056,292 | <ol>
<li><p>I use python 2.7.12 and newest paramiko 2.0.2, and run a script which ssh login many linux server concurrently.</p>
<p>sometimes it runs very well, but sometimes it will report the following weird error:</p>
<p>**no handers could be found for logger 'paramiko.transport'</p>
<p>.....</p>
<p>Exception in ... | 0 | 2016-08-20T16:19:18Z | 39,477,206 | <ol>
<li>You should <a href="http://stackoverflow.com/questions/19152578/no-handlers-could-be-found-for-logger-paramiko">set up a logger for 'paramiko.transport'</a>.</li>
<li>Have you found a solution? I have exactly the same problem when trying to connect concurrently.</li>
</ol>
| -1 | 2016-09-13T19:00:08Z | [
"python",
"paramiko"
] |
why it report a error RequirementParseError invalid requirement parse error at '' at sometimes when using newest paramiko 2.0.2 of python 2.7.12 | 39,056,292 | <ol>
<li><p>I use python 2.7.12 and newest paramiko 2.0.2, and run a script which ssh login many linux server concurrently.</p>
<p>sometimes it runs very well, but sometimes it will report the following weird error:</p>
<p>**no handers could be found for logger 'paramiko.transport'</p>
<p>.....</p>
<p>Exception in ... | 0 | 2016-08-20T16:19:18Z | 40,035,095 | <p>This workaround worked for me. Change from a </p>
<pre><code>concurrent.futures.ThreadPoolExecutor
</code></pre>
<p>to a:</p>
<pre><code>concurrent.futures.ProcessPoolExecutor
</code></pre>
<p><a href="https://github.com/couchbaselabs/mobile-testkit/issues/209#issuecomment-253708295" rel="nofollow">See full con... | 0 | 2016-10-14T04:46:46Z | [
"python",
"paramiko"
] |
How can I use a postactivate script using Python 3 venv? | 39,056,356 | <p>I'm using <code>venv</code> (used <code>pyvenv</code> to create the environment) and would like to set up environment variables here, but <code>postactivate</code> looks like a <code>virtualenv</code> thing. Can this be done with <code>venv</code>?</p>
| 0 | 2016-08-20T16:27:30Z | 39,056,653 | <p><code>venv</code> has the <code>activate</code> script which you can modify to add your environment variables.</p>
<p>I would add the variables at the bottom, making a nice comment block to clearly separate the core functionality and my custom variables.</p>
| 2 | 2016-08-20T16:58:32Z | [
"python",
"python-3.x",
"python-venv"
] |
Python 3 + Selenium: How to find this element by xpath? | 39,056,407 | <pre><code>https://www.facebook.com/friends/requests/?fcref=jwl&outgoing=1
</code></pre>
<p>I want to click "See more request" in the "friend request sent"</p>
<pre><code><div id="outgoing_reqs_pager_57b87e5793eb04682598549" class="clearfix mtm uiMorePager stat_elem _646 _52jv">
<div>
<a ... | 1 | 2016-08-20T16:33:20Z | 39,056,603 | <p>Actually here you are locating element by using partial id match, so may be this xpath is not unique and return multiple element.</p>
<p><code>find_element</code> always returns first element by matching locator, may be it's return other element which is overlayed by other element instead of desire element that's w... | 1 | 2016-08-20T16:53:48Z | [
"python",
"html",
"selenium",
"xpath"
] |
Apk file build using buildozer closes as soon as i open it | 39,056,409 | <p>I try to make a simple hello world app for android using python, kivy and buildozer.</p>
<p>my hello.py file is</p>
<pre><code>from kivy.app import App
from kivy.uix.button import Label
class Hello2App(App):
def build(self):
return Label()
if __name__=="__main__":
Hello2App().run()
</code></pre>
<... | 0 | 2016-08-20T16:33:27Z | 39,057,484 | <p>Your Python script must be named main.py. If you check the error that you are getting it would read something like "Unable to find main.py". Just try renaming the file from hello.py to main.py and build again.</p>
| 1 | 2016-08-20T18:34:36Z | [
"android",
"python",
"kivy",
"buildozer"
] |
Debug Flask(Python) web application in Visual studio code | 39,056,448 | <p>How do I configure visual studio code to debug Flask(Python) web application ?</p>
<p>For example when I set debugger on view function it should allow me to step through that function when we hit that route in browser.</p>
<p>I have already installed python extension in Visual studio code.</p>
| 0 | 2016-08-20T16:37:54Z | 39,059,501 | <p>I don't use VS for python development. However, Flask has really nice debugging option, that allows you to debug from browser. This is not a solution for VS but a workaround. </p>
<p>When you define your app pass <code>debug = true</code> parameter to enable debugging mode. Then you can debug your code from browser... | 0 | 2016-08-20T23:10:29Z | [
"python",
"vscode",
"vscode-extensions"
] |
Basic DFS space usage | 39,056,488 | <p>I have a basic question related to space usage, and I'm using DFS as an example. I'm not sure if the space usage in these few implementations are the same, or if a few actually differ. My interpretation of space usage is directly correlated to what the function allocates. <strong>Can anyone help me verify the space ... | 0 | 2016-08-20T16:42:39Z | 39,056,704 | <p><a href="https://en.wikipedia.org/wiki/DSPACE" rel="nofollow">Space complexity</a> is not determined by <em>where</em> the space gets allocated but by <em>how much</em> space (memory) is required to hold a given data structure in relation to the number of objects to be processed by an algorithm. </p>
<p>In your exa... | 1 | 2016-08-20T17:04:18Z | [
"python",
"performance",
"memory"
] |
How to make python detect audio from an application? | 39,056,494 | <p>I'm trying to make something that runs when audio is detected from a windows application. Is there any way to do this using python.</p>
<p>I'm running on python 2.7.12 but I'm willing to update if necessary. I'm also fine with detecting any sound at all coming from the computer.</p>
<p>Thanks a lot.</p>
| -2 | 2016-08-20T16:43:38Z | 39,060,479 | <p>take a look at <a href="http://python-sounddevice.readthedocs.io/en/0.3.4/#sounddevice.RawInputStream" rel="nofollow">http://python-sounddevice.readthedocs.io/en/0.3.4/#sounddevice.RawInputStream</a>
You could use this to detect audio to and from the sound card of the computer.</p>
<p>The particular class is one wa... | 0 | 2016-08-21T02:59:31Z | [
"python",
"python-2.7"
] |
How to add multiple key-value pair to Dictionary at once? | 39,056,654 | <p>I have a dictionary <code>dict</code> having some elements like:</p>
<p><code>dict={'India':'Delhi','Canada':'Ottawa'}</code></p>
<p>now I want to add multiple dictionary key-value pair to a <code>dict</code> like:</p>
<p><code>dict= {'India':'Delhi','Canada':'Ottawa','USA':'Washington','Brazil':'Brasilia','Au... | 0 | 2016-08-20T16:58:48Z | 39,056,673 | <p>You're looking for the <code>dict.update</code> method, documented <a href="https://docs.python.org/2/library/stdtypes.html#dict.update" rel="nofollow">here</a>. </p>
| 0 | 2016-08-20T17:01:06Z | [
"python"
] |
How to add multiple key-value pair to Dictionary at once? | 39,056,654 | <p>I have a dictionary <code>dict</code> having some elements like:</p>
<p><code>dict={'India':'Delhi','Canada':'Ottawa'}</code></p>
<p>now I want to add multiple dictionary key-value pair to a <code>dict</code> like:</p>
<p><code>dict= {'India':'Delhi','Canada':'Ottawa','USA':'Washington','Brazil':'Brasilia','Au... | 0 | 2016-08-20T16:58:48Z | 39,056,679 | <p>Use <code>update()</code> method. </p>
<pre><code>d= {'India':'Delhi','Canada':'Ottawa'}
d.update({'USA':'Washington','Brazil':'Brasilia','Australia':'Canberra'})
</code></pre>
<p>PS: Naming your dictionary as <code>dict</code> is a horrible idea. It replaces the built in <code>dict</code>.</p>
| 0 | 2016-08-20T17:01:30Z | [
"python"
] |
Python selenium "about:blank&utm_content=firstrun" error | 39,056,722 | <p>I've being trying so hard to figure out what's going on with my code, but I couldn't help.
Whenever I run my program I got this error in the picture bellow.
I'm using python 3.4.4 and selenium last version of it.
<br><br>
Windows 10</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys i... | 3 | 2016-08-20T17:06:21Z | 39,060,403 | <p>You didn't mention what your FF version is, I assume it's one of the latest. Anyways you need to use FF below 47 or time to switch to MarionetteDriver </p>
<p>here is some useful information <a href="http://stackoverflow.com/questions/37693106/selenium-2-53-not-working-on-firefox-47">Selenium 2.53 not working on Fi... | 3 | 2016-08-21T02:41:22Z | [
"python",
"selenium",
"selenium-webdriver"
] |
TypeError: context must be specified" in zmq unpickling | 39,056,746 | <p>I am trying to create a very simple chat. Using the PyZMQ library. And since sockets are not threadsafe I am using two sockets and one thread running on each. One checking for incoming messages, and one to send messages. </p>
<p>But my program is giving me, error messages:</p>
<pre><code> Traceback (most recent... | 0 | 2016-08-20T17:09:47Z | 39,057,197 | <p>These are processes not threads. The problem occurs because in the background Python has to send a copy of your <code>Communication</code> object to the child process. However, your object contains socket objects that cannot be serialised. Use <code>threading</code> and the <code>Thread</code> object in place of <co... | 1 | 2016-08-20T18:01:21Z | [
"python",
"multithreading",
"sockets",
"chat",
"pyzmq"
] |
TypeError: context must be specified" in zmq unpickling | 39,056,746 | <p>I am trying to create a very simple chat. Using the PyZMQ library. And since sockets are not threadsafe I am using two sockets and one thread running on each. One checking for incoming messages, and one to send messages. </p>
<p>But my program is giving me, error messages:</p>
<pre><code> Traceback (most recent... | 0 | 2016-08-20T17:09:47Z | 39,057,473 | <p>Fully working version below. I made a few changes:</p>
<ol>
<li>I used threads instead of processes, as suggested by @Dunes.</li>
<li>I combined <code>client.py</code> and <code>server.py</code> into a single <code>app.py</code> with a "role" parameter. (This was just to avoid a lot of duplicate code.)</li>
<li>I h... | 1 | 2016-08-20T18:33:21Z | [
"python",
"multithreading",
"sockets",
"chat",
"pyzmq"
] |
How to make a POST with ajax just like the form submit? | 39,056,749 | <p>I'm trying to send a POST request to my python (Google App Engine) server using Ajax just the way we do from a form submit, but it's not working.</p>
<p>This is my HTML:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://ajax.googleapis.com/aja... | 0 | 2016-08-20T17:10:04Z | 39,070,536 | <p>You should return the response as a JSON object:</p>
<pre><code>class MainHandler(Handler):
def get(self):
self.render('image.html')
def post(self):
import json
url = self.request.get('url')
response_dict = {
'message': 'Yay, I did it!',
'url': url ... | 0 | 2016-08-22T02:11:21Z | [
"javascript",
"jquery",
"python",
"ajax",
"google-app-engine"
] |
No module named 'matplotlib.pylot' | 39,056,880 | <p>I had installed Python 3.5 from anaconda distribution.</p>
<pre><code>C:\Users\ananda>python
Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
</code></pre>
<p>I am importing mat... | 0 | 2016-08-20T17:24:02Z | 39,057,358 | <p>Your attempt to install <code>matplotlib</code> seems right, but the submodule you're looking for is called <code>pyplot</code>.</p>
<p>Just try:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> # No ImportError or similar, everything is fine
</code></pre>
<p>If you still get an error, jus... | 1 | 2016-08-20T18:19:44Z | [
"python",
"matplotlib",
"jupyter"
] |
Bokeh: run callback on plot init? | 39,056,886 | <p>I have the majority of my calculations for an interactive chloropeth graph done through callbacks on various attached widgets.</p>
<p>Can we run a callback on plot initiation? This could be accomplished by constructing a refresh/init button and attaching an initiating callback to it, but this still requires pushing... | 0 | 2016-08-20T17:24:19Z | 39,070,711 | <p>As of Bokeh <code>0.12.1</code> this is an open feature request:</p>
<p><a href="https://github.com/bokeh/bokeh/issues/4272" rel="nofollow">https://github.com/bokeh/bokeh/issues/4272</a></p>
<p>As a workaround, you might try adding a timeout callback with a very short interval:</p>
<pre><code>curdoc().add_timeout... | 0 | 2016-08-22T02:45:05Z | [
"python",
"bokeh"
] |
Xml write twice the same thing | 39,056,914 | <p>i'm looking to solve this problem.
When i try to write into the xml file , it writes twice the same thing.</p>
<p>It's the code:</p>
<pre><code> def writeIntoXml(fileName, tagElement, textElement):
tree = ET.ElementTree(file = fileName)
root = tree.getroot()
newElement = ET.SubElement(root, tagElem... | 0 | 2016-08-20T17:27:35Z | 39,057,107 | <p>Note that <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.SubElement" rel="nofollow">ET.SubElement()</a> appends the element automatically. You are adding the element twice, first in <code>SubElement()</code>, next in <code>append()</code>. </p>
<p>You should use either j... | 0 | 2016-08-20T17:51:07Z | [
"python",
"xml",
"python-3.x",
"xml-parsing"
] |
wxPython : Creating a soundboard with panels | 39,057,105 | <p>I am making a quick and dirty soundboard using the wxPython package and was wondering how to go by implementing a scroll-list of sounds to play. </p>
<p>Here is a picture of what I am trying to convey:
<a href="http://i.imgur.com/av0E5jC.png" rel="nofollow">http://i.imgur.com/av0E5jC.png</a></p>
<p>and here is m... | 0 | 2016-08-20T17:50:49Z | 39,057,220 | <p>Just removed the text widget, replaced by a listbox, and hooked a callback on item click, slightly elaborate: when clicking, it finds the position of the item, retrieves the label name and fetches the filename in the dictionary
(we want to play a .wav file with a path, but not necessarily display the full filename)<... | 0 | 2016-08-20T18:03:08Z | [
"python",
"wxpython"
] |
Ignore raising exception to the caller in python 3 | 39,057,162 | <p>How can I ignore a certain exception to be raised to the caller in python 3?</p>
<p><strong>Example:</strong></p>
<pre><code>def do_something():
try:
statement1
statement2
except Exception as e:
# ignore the exception
logging.warning("this is normal, exception is ignored")
... | 1 | 2016-08-20T17:57:07Z | 39,057,779 | <p>There's no need to do this in Python <code>3</code>, <code>sys.exc_clear()</code> was removed because Python doesn't store the last raised exception internally as it did in Python 2:</p>
<p>For example, in Python 2, the exception is still kept alive when inside a function:</p>
<pre><code>def foo():
try:
... | 0 | 2016-08-20T19:08:36Z | [
"python",
"python-3.x",
"exception-handling",
"pep"
] |
Converting value to key from dictionary | 39,057,167 | <p>I have a txt file with the following text:</p>
<pre><code>water=45
melon=8
apple=35
pineapple=67
I=43
to=90
eat=12
tastes=100
sweet=21
it=80
watermelon=98
want=70
</code></pre>
<p>and I have another file with the following text:</p>
<pre><code>I want to eat watermelon
it tastes sweet pineapple
</code><... | 1 | 2016-08-20T17:57:56Z | 39,057,631 | <p>Please check this code.</p>
<pre><code>import re
f = open(r'C:\Users\dinesh_pundkar\Desktop\val.txt','r')
val_dict = {}
for line in f:
k, v = line.strip().split('=')
val_dict[k.strip()] = v.strip()
f.close()
print val_dict
h = open(r'C:\Users\dinesh_pundkar\Desktop\str_txt.txt','r')
str_list = []
for li... | 1 | 2016-08-20T18:50:37Z | [
"python",
"python-2.7",
"python-3.x"
] |
Why doesn't ulimit -t kill a process sleeping beyond the limit with time.sleep? | 39,057,299 | <p>I am trying to limit the CPU usage of one python script using <code>ulimit -t</code>. The script contains one <code>time.sleep()</code> statement and it is not killed after the specified time limit. Here is the simplified python script named <code>test.py</code>:</p>
<pre><code>import time
while True:
time.sl... | 0 | 2016-08-20T18:12:49Z | 39,057,470 | <p><code>ulimit -t</code> sets the <em>CPU</em> time limit. While your program is sleeping it doesn't use any CPU time, so that time doesn't count. It will only occupy a few CPU cycles to go to sleep again, that's why it's not killed.</p>
<p>You can't specify a real time limit using ulimit.</p>
| 3 | 2016-08-20T18:33:13Z | [
"python",
"ulimit"
] |
Error received while converting a .txt in to .csv file for plotting two columns | 39,057,315 | <p>I have four columns in a .txt file and I want to convert in into .csv and then plot two of the columns. my code is the following : </p>
<pre><code>import pandas as pd
import numpy as np
from sys import argv
from pylab import *
import csv
script, filename = argv
txt = open(filename)
print "Here's your file %r:" ... | 0 | 2016-08-20T18:14:37Z | 39,057,448 | <p>Your command line syntax is incorrect.</p>
<p>You are passing a text file to python instead of a valid python script by calling <code>python N56_mass.txt csv_flash.py</code></p>
<p>Try instead,</p>
<pre><code>python csv_flash.py N56_mass.txt
</code></pre>
| 1 | 2016-08-20T18:30:57Z | [
"python",
"csv",
"pandas"
] |
Error received while converting a .txt in to .csv file for plotting two columns | 39,057,315 | <p>I have four columns in a .txt file and I want to convert in into .csv and then plot two of the columns. my code is the following : </p>
<pre><code>import pandas as pd
import numpy as np
from sys import argv
from pylab import *
import csv
script, filename = argv
txt = open(filename)
print "Here's your file %r:" ... | 0 | 2016-08-20T18:14:37Z | 39,057,455 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>delim_whitespace</code></a> to handle whitespaces as delimiters:</p>
<pre><code>dataframe = pd.read_csv("N56_mass.txt", delim_whitespace=True, usecols=columns_to_keep)
</code></pre>
| 1 | 2016-08-20T18:31:54Z | [
"python",
"csv",
"pandas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.