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 |
|---|---|---|---|---|---|---|---|---|---|
Adding counter/index to a list of lists in Python | 39,865,305 | <p>I have a list of lists of strings:</p>
<pre><code>listBefore = [['4', '5', '1', '1'],
['4', '6', '1', '1'],
['4', '7', '8', '1'],
['1', '2', '1', '1'],
['2', '3', '1', '1'],
['7', '8', '1', '1'],
['7', '9', '1', '1'],
... | 1 | 2016-10-05T04:10:15Z | 39,865,457 | <p>Iterate over the parent list with <code>enumerate()</code> to get counter (used as <code>i</code> in the below example) along with list element. In the sublist, insert the <code>i</code> at the middle of sublist using <code>list.insert(index, value)</code> method.
<em>Note:</em> The value of counter i.e. <code>i</co... | 2 | 2016-10-05T04:28:49Z | [
"python",
"list"
] |
Adding counter/index to a list of lists in Python | 39,865,305 | <p>I have a list of lists of strings:</p>
<pre><code>listBefore = [['4', '5', '1', '1'],
['4', '6', '1', '1'],
['4', '7', '8', '1'],
['1', '2', '1', '1'],
['2', '3', '1', '1'],
['7', '8', '1', '1'],
['7', '9', '1', '1'],
... | 1 | 2016-10-05T04:10:15Z | 39,865,459 | <p>You should learn about <code>enumerate</code>, it lets you iterate over the list with two iterators - one (<code>str_list</code> in this case<code>) holds the current item in the list, and the other (</code>i`) holds it's index in the list.</p>
<pre><code>for i,str_list in enumerate(listBefore):
listBefore[i] = s... | 0 | 2016-10-05T04:29:01Z | [
"python",
"list"
] |
Adding counter/index to a list of lists in Python | 39,865,305 | <p>I have a list of lists of strings:</p>
<pre><code>listBefore = [['4', '5', '1', '1'],
['4', '6', '1', '1'],
['4', '7', '8', '1'],
['1', '2', '1', '1'],
['2', '3', '1', '1'],
['7', '8', '1', '1'],
['7', '9', '1', '1'],
... | 1 | 2016-10-05T04:10:15Z | 39,866,143 | <pre><code>>>> data = [['4', '5', '1', '1'],
['4', '6', '1', '1'],
['4', '7', '8', '1'],
['1', '2', '1', '1'],
['2', '3', '1', '1'],
['7', '8', '1', '1'],
['7', '9', '1', '1'],
['2', '4', '3', '1']]
>>> print [row[:len... | 0 | 2016-10-05T05:37:01Z | [
"python",
"list"
] |
when using from file import function, how can the importing file be modified to give a desired output without modifying the imported file? | 39,865,345 | <p>File 1</p>
<pre><code>def multiply():
x = raw_input('enter the number')
y = x*4
</code></pre>
<p>File 2</p>
<pre><code>from file1 import multiply
</code></pre>
<p>how do i make the value of <code>x = 4</code> and hence the result <code>(4*4) = 16</code> without user input being implemented when running <... | 0 | 2016-10-05T04:15:14Z | 39,866,061 | <p>There is a straightforward albeit hackey way of achieving what you want. I recommend against it. It is fundamentally a poor design choice, but here it is:</p>
<pre><code>def multiply():
x = int(raw_input())
print x * 4
import sys
import io
def force_stdin(f, force_input):
stdin = sys.stdin
sys.stdi... | 2 | 2016-10-05T05:30:41Z | [
"python",
"python-2.7"
] |
Django - 'RawQuerySet' object has no attribute 'all' | 39,865,349 | <p>I got this error message if i'm using SQL statement to populate data in dropdown.</p>
<p>Error message</p>
<pre><code>'RawQuerySet' object has no attribute 'all'
</code></pre>
<p>Model.py</p>
<pre><code>@python_2_unicode_compatible # only if you need to support Python 2
class FacebookAccount(models.Model):
... | 0 | 2016-10-05T04:15:39Z | 39,866,120 | <p>As the first comment says it seems like you are calling all() on queryset. You dont have to call .all() after executing raw sql queries, if you are assigning that to a variable since that variable already includes all objects fetched by your query. </p>
<pre><code>In [6]: t = Team.objects.raw('SELECT * FROM core_te... | 0 | 2016-10-05T05:35:30Z | [
"python",
"django"
] |
How to store aggregation pipeline in mongoDB? | 39,865,416 | <p>I am developing a rule engine using MongoDB and Python. I want to store Rules in MongoDB in a Rule database "myrulesdb" and want to use it to run aggregation pipeline on a different collection. Rule saved in MongoDB is</p>
<pre><code>{
"_id" : ObjectId("57f46e843166d426a20d5e08"),
"Rule" : "[{\"$match\":{\"Name.Fir... | 1 | 2016-10-05T04:23:19Z | 39,867,844 | <p>I don't know why you are doing this but the culprit here is the value of the <code>Rule</code> field which is string. If you try a little debuging with the <code>print()</code> function your will see that <code>type(pipe)</code> yields <code><class 'str'></code></p>
<p>You can fix this by loading the value us... | 0 | 2016-10-05T07:27:44Z | [
"python",
"mongodb",
"rule-engine"
] |
Setting value of Select in html | 39,865,542 | <p>I am generating this html from python and 2% is the value of the field so it is what should be shown but I am baffled as to why it doesn't work as I expect. I have tried so many permutations and figure it is something so simple. Please Help. I don't necessarily want to use the selected option in the <code><opt... | 1 | 2016-10-05T04:39:07Z | 39,865,564 | <p>Are you mean this? put your value on <code><option></code>, not <code><select></code>. And see whats double quote on last <code><option></code></p>
<pre><code> <select name="discount">
<option value="10%">10%</option>
<option value="9%">9%</option>
... | 1 | 2016-10-05T04:42:20Z | [
"python",
"html"
] |
Setting value of Select in html | 39,865,542 | <p>I am generating this html from python and 2% is the value of the field so it is what should be shown but I am baffled as to why it doesn't work as I expect. I have tried so many permutations and figure it is something so simple. Please Help. I don't necessarily want to use the selected option in the <code><opt... | 1 | 2016-10-05T04:39:07Z | 39,865,603 | <p>If you want to selected 2% value then your dropdown should be like this : </p>
<pre><code><select name="discount">
<option value="10%">10%</option>
<option value="9%">9%</option>
<option value="8%">8%</option>
<option value="7%">7%</opti... | 2 | 2016-10-05T04:45:35Z | [
"python",
"html"
] |
Setting value of Select in html | 39,865,542 | <p>I am generating this html from python and 2% is the value of the field so it is what should be shown but I am baffled as to why it doesn't work as I expect. I have tried so many permutations and figure it is something so simple. Please Help. I don't necessarily want to use the selected option in the <code><opt... | 1 | 2016-10-05T04:39:07Z | 39,865,621 | <p>Add a selected attribute to the item. You also had a stray quotation mark on the last <code><option></code></p>
<pre><code><select name="discount">
<option>10%</option>
<option>9%</option>
<option>8%</option>
<option>7%</option>
<opt... | 1 | 2016-10-05T04:47:43Z | [
"python",
"html"
] |
Setting value of Select in html | 39,865,542 | <p>I am generating this html from python and 2% is the value of the field so it is what should be shown but I am baffled as to why it doesn't work as I expect. I have tried so many permutations and figure it is something so simple. Please Help. I don't necessarily want to use the selected option in the <code><opt... | 1 | 2016-10-05T04:39:07Z | 39,865,636 | <p><strong>Description</strong> Use the following HTML for your query. </p>
<pre><code> <select name="discount">
<option value="10%">10%</option>
<option value="9%">9%</option>
<option value="8%">8%</option>
<option value="7%">7%</o... | 0 | 2016-10-05T04:49:17Z | [
"python",
"html"
] |
Setting value of Select in html | 39,865,542 | <p>I am generating this html from python and 2% is the value of the field so it is what should be shown but I am baffled as to why it doesn't work as I expect. I have tried so many permutations and figure it is something so simple. Please Help. I don't necessarily want to use the selected option in the <code><opt... | 1 | 2016-10-05T04:39:07Z | 39,871,369 | <p>Here is what worked for me and thanks to Brian</p>
<pre><code> <body onload="myfield=document.getElementsByName('discount')[0].value='2%'">
<select name="discount">
<option value="10%">10%</option>
<option value="9%">9%</option>
<option value="8%... | 0 | 2016-10-05T10:20:17Z | [
"python",
"html"
] |
sentiment analysis joint list | 39,865,557 | <p>im doing the sentiment analysis with scikit-learn python, now I'm using the nltk to do the words lemmatization in order to increase processing speed, for example:</p>
<p>I get the following arrays after nltk processing:</p>
<pre><code>array([ ['Really', 'a', 'terrible', 'course', u'lecture', u'be', 'so', 'boring',... | 1 | 2016-10-05T04:41:04Z | 39,869,881 | <p>You would do:</p>
<pre><code>second_array = [' '.join(each) for each in first_array]
</code></pre>
<p>Alternatively you can tell <code>sklearn.CountVectorizer</code> to just use your tokens:</p>
<pre><code>vect = CountVectorizer(preprocessor=lambda x: x, tokenizer=lambda x: x)
X = vect.fit_transform(first_array)
... | 0 | 2016-10-05T09:12:24Z | [
"python",
"arrays",
"scikit-learn"
] |
variables formatting using python script | 39,865,625 | <p>I'm having issues formatting my variables. My PORT1 and PORT2 are not working properly. I'm getting syntax errors. What I'm doing wrong. Thank you for the inputs.</p>
<pre><code>import socket
import os
import netifaces
NICS = netifaces.interfaces()
PORT1 = NICS[1]
PORT2 = NICS[2]
os.system("nmcli con add type team... | -1 | 2016-10-05T04:48:18Z | 39,865,651 | <p>Your problem that you are trying to append string <code>master team0</code> but you didn't wrap that in quotes also there one more closing bracket than opening ones</p>
<p>I thin this is what it should be</p>
<pre><code>os.system("nmcli con add type team-slave con-name team0-port1 ifname {} master team0".format(PO... | 2 | 2016-10-05T04:50:42Z | [
"python"
] |
WxPython's ScrolledWindow element collapses to minimum size | 39,865,870 | <p>I am using a Panel within a Frame to display images (the GUI need to switch between multiple panels and hence the hierarchy). As images should be displayed in native size I used ScrolledWindow as the panel parent. The scrolls do appear and work, but it causes the Panel to collapse to minimum size and it needs to be ... | 0 | 2016-10-05T05:13:05Z | 39,871,909 | <p>You're calling <code>Fit()</code>, so you're explicitly asking the panel to fit its contents, but you don't specify the min/best size of this contents anywhere (AFAICS, there is a lot of code here, so I could be missing something).</p>
<p>If you want to use some minimal size for the panel, just set it using <code>S... | 1 | 2016-10-05T10:47:09Z | [
"python",
"wxpython",
"wxwidgets"
] |
pattern.match with regex not working | 39,865,885 | <pre><code>import re
def test(stest):
pattern = re.compile(r'/product\/(.*?)/i')
result = pattern.match(stest)
if result:
print result.group()
else:
print "Doesn't match"
test('product/WKSGGPC104/GGPC-The-Paladin')
</code></pre>
<p>When I run the coding as the above, I will get "Doesn'... | 1 | 2016-10-05T05:14:29Z | 39,865,962 | <p>A couple of issues with your code.<br>
First, there was no <code>/</code> in the beginning, second, you provide the modifiers <strong>after</strong> the call:</p>
<pre><code>import re
def test(stest):
pattern = re.compile(r'product/([^/]+)'. re.IGNORECASE)
result = pattern.match(stest)
if result:
... | 1 | 2016-10-05T05:21:54Z | [
"python",
"regex"
] |
pattern.match with regex not working | 39,865,885 | <pre><code>import re
def test(stest):
pattern = re.compile(r'/product\/(.*?)/i')
result = pattern.match(stest)
if result:
print result.group()
else:
print "Doesn't match"
test('product/WKSGGPC104/GGPC-The-Paladin')
</code></pre>
<p>When I run the coding as the above, I will get "Doesn'... | 1 | 2016-10-05T05:14:29Z | 39,866,133 | <p>You are using string literals but still escaping the \ in your string.</p>
| 0 | 2016-10-05T05:36:32Z | [
"python",
"regex"
] |
How to understand numpy's combined slicing and indexing example | 39,866,043 | <p>I am trying to understand numpy's combined slicing and indexing concept, however I am not sure how to correctly get the below results from numpy's output (by hand so that we can understand how numpy process combined slicing and indexing, which one will be process first?):</p>
<pre><code>>>> import numpy as... | 0 | 2016-10-05T05:29:20Z | 39,866,514 | <p><code>a[:,j][0]</code> is equivalent to <code>a[0,j]</code> or <code>[0, 1, 2, 3][j]</code> which gives you <code>[[2, 1], [3, 3]])</code></p>
<p><code>a[:,j][1]</code> is equivalent to <code>a[1,j]</code> or <code>[4, 5, 6, 7][j]</code> which gives you <code>[[6, 5], [7, 7]])</code></p>
<p><code>a[:,j][2]</code> ... | 0 | 2016-10-05T06:06:56Z | [
"python",
"arrays",
"numpy",
"indexing"
] |
How to understand numpy's combined slicing and indexing example | 39,866,043 | <p>I am trying to understand numpy's combined slicing and indexing concept, however I am not sure how to correctly get the below results from numpy's output (by hand so that we can understand how numpy process combined slicing and indexing, which one will be process first?):</p>
<pre><code>>>> import numpy as... | 0 | 2016-10-05T05:29:20Z | 39,866,515 | <p>Whenever you use an array of indices, the result has the <em>same shape as the indices</em>; for example:</p>
<pre><code>>>> x = np.ones(5)
>>> i = np.array([[0, 1], [1, 0]])
>>> x[i]
array([[ 1., 1.],
[ 1., 1.]])
</code></pre>
<p>We've indexed with a 2x2 array, and the result i... | 1 | 2016-10-05T06:07:04Z | [
"python",
"arrays",
"numpy",
"indexing"
] |
sympy - symbolically solve equations with float power | 39,866,051 | <p>Using sympy, I define the symbols,</p>
<pre><code>a, b, c = sympy.symbols(['a', 'b', 'c'])
</code></pre>
<p>Then, when I try to solve the following system of equations,</p>
<pre><code>sympy.solve([sympy.Eq(b - a**2.552 - c), sympy.Eq(a, 2)])
</code></pre>
<p>I get the solution,</p>
<pre><code>[{b: c + 5.8644670... | 3 | 2016-10-05T05:30:01Z | 39,866,932 | <p>I don't know why but <code>rational=False</code> helps</p>
<pre><code>sympy.solve([sympy.Eq(b - a**2.552 - c), sympy.Eq(b, 2)], rational=False)
</code></pre>
<p>see: <a href="http://stackoverflow.com/questions/17087629/sympy-hangs-when-trying-to-solve-a-simple-algebraic-equation">sympy hangs when trying to solve a... | 4 | 2016-10-05T06:34:06Z | [
"python",
"sympy"
] |
Django admin login returns Forbidden 403 CSRF verification failed. Request aborted | 39,866,056 | <p>Pretty new to Django. Working through a second project following the Polls tutorial on Django website. Previous effort went well, albeit simple. This time around encountering problems accessing admin login.</p>
<p>I have created a superuser and using those credentials, when I try to login to <code>http://127.0.0.1:... | 0 | 2016-10-05T05:30:24Z | 39,866,348 | <p>You are setting <code>SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')</code>
Remove this line and see if that solves your issue. If you are enabling https <code>csrf will work only as per the specifications of https</code>. There is a possibility that you are enabling https and serving your website fro... | 0 | 2016-10-05T05:54:50Z | [
"python",
"django"
] |
Django admin login returns Forbidden 403 CSRF verification failed. Request aborted | 39,866,056 | <p>Pretty new to Django. Working through a second project following the Polls tutorial on Django website. Previous effort went well, albeit simple. This time around encountering problems accessing admin login.</p>
<p>I have created a superuser and using those credentials, when I try to login to <code>http://127.0.0.1:... | 0 | 2016-10-05T05:30:24Z | 39,880,781 | <p>I have no clue why this is the answer, but I went in and updated my Django to the current release. For whatever reason this solved the problem...</p>
<pre><code>pip install --upgrade django==1.10.2
</code></pre>
| 0 | 2016-10-05T17:59:15Z | [
"python",
"django"
] |
Programmatically enable/disable Bluetooth profiles | 39,866,179 | <p>I'm running Rasbian Jessie Lite on Raspberry Pi 3 with a USB/Bluetooth dongle (blueZ) 5.4.</p>
<p>The <code>/etc/bluetooth/main.conf</code> has Class = 0x0c0408.
I have a Qt5 application which enables the Bluetooth device and accepts any incoming pairing requests.</p>
<p>I can successfully connect from my smartph... | 0 | 2016-10-05T05:40:24Z | 40,034,928 | <p>Enabling and disabling any profile/service in Bluez can be done using sdptool command. If you want to enable any profile/service you can use:</p>
<p><code>sdptool add A2SRC</code></p>
<p>In the same way to disable any service/profile you can use:</p>
<pre><code>sdptool del A2SRC
</code></pre>
<p>More info can be... | 1 | 2016-10-14T04:28:22Z | [
"python",
"linux",
"bluetooth",
"a2dp",
"hfp"
] |
django makemigrations to rename field without user input | 39,866,339 | <p>I have a model with CharField named <em>oldName</em>. I want to rename the field to <em>newName</em>. </p>
<p>When I run <em>python manage.py makemigrations</em>, I get a confirmation request <strong>"Did you rename model.oldName to model.newName (a CharField)? [y/N]"</strong></p>
<p>However, I want to run the who... | 0 | 2016-10-05T05:54:01Z | 39,866,780 | <p>Use </p>
<pre><code>script_or_command < <(yes y)
</code></pre>
<p>But I'm not sure this will work for multiple input prompts.</p>
| 0 | 2016-10-05T06:24:27Z | [
"python",
"django",
"rename",
"makemigrations"
] |
In Python, is it possible to skip a certain part of a for loop? | 39,866,378 | <p>so I attempted to add some code to my working product(A triangle maker) where you can add some text to the middle of the triangle if the program allows so. So far I've added the text with the correct amount of x's and indents but the program still outputs the original middle line of x's. For example Triangle(3, "M")... | 0 | 2016-10-05T05:57:17Z | 39,867,065 | <p>I am not sure of how how your code works, but I tweaked it until it returned the result I expected. Also, I made small changes to parts that were a bit ugly. This should do what you want:</p>
<pre><code>def Triangle(height, text):
number_of_x2 = (height - len(text)) / 2
if not height % 2:
print "Please enter a... | 0 | 2016-10-05T06:42:48Z | [
"python",
"loops"
] |
From JSON file to Numpy Array | 39,866,713 | <p>I have a MongoDB collection, which, when imported to Python via PyMongo, is a dictionnary in Python.
I am looking to transform it into a Numpy Array.</p>
<p>For instance, if the JSON file looks like this :</p>
<pre><code>{
"_id" : ObjectId("57065024c3d1132426c4dd53"),
"B" : {
"BA" : 14,
"B... | 0 | 2016-10-05T06:20:17Z | 39,870,755 | <p>The <a href="https://pypi.python.org/pypi/flatdict" rel="nofollow">flatdict</a> module can sometimes be useful when working with mongodb data structures. It will handle flattening the nested dictionary structure for you:</p>
<pre><code>columns = []
for d in data:
flat = flatdict.FlatDict(d)
del flat['_id']
... | 1 | 2016-10-05T09:50:54Z | [
"python",
"arrays",
"json",
"mongodb",
"numpy"
] |
From JSON file to Numpy Array | 39,866,713 | <p>I have a MongoDB collection, which, when imported to Python via PyMongo, is a dictionnary in Python.
I am looking to transform it into a Numpy Array.</p>
<p>For instance, if the JSON file looks like this :</p>
<pre><code>{
"_id" : ObjectId("57065024c3d1132426c4dd53"),
"B" : {
"BA" : 14,
"B... | 0 | 2016-10-05T06:20:17Z | 39,870,771 | <p>Assuming you've successfully loaded that JSON into Python, here's one way to create the Numpy array you want. My code has a minimal definition of <code>ObjectId</code> so that it won't raise a NameError on <code>ObjectId</code> entries. </p>
<pre><code>sorted(d["B"].items())]
</code></pre>
<p>produces a list of (k... | 1 | 2016-10-05T09:51:33Z | [
"python",
"arrays",
"json",
"mongodb",
"numpy"
] |
TypeError at /myapp/hello/ hello() takes exactly 2 arguments (1 given) | 39,866,858 | <p>ecomstore/settings.py</p>
<pre><code>INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'uploader',
'myapp',
)
</code></pre>
<p>ecomstore/urls.py</p>
<p... | 0 | 2016-10-05T06:29:43Z | 39,866,949 | <p>You're missing quotes it should be:</p>
<pre><code>include('myapp.urls')
</code></pre>
<p>That or import myapp (which is not imported on your urls.py)</p>
| 0 | 2016-10-05T06:35:11Z | [
"python",
"django"
] |
Python: Insert into a postGreSQL table using python by passing parameters | 39,866,900 | <p>I have two lists:</p>
<pre><code>columns = ['id','name','address']
data = ['1,'John','LA'','2,'Jessica','TX'']
</code></pre>
<p>I have a table schema with the same columns as above and I am unable to insert data into the table using psycopg2 connections when I pass the values and column names as parameters.</p>
<... | 0 | 2016-10-05T06:32:10Z | 39,866,986 | <p><code>INSERT</code> needs columns and values in <code>()</code> so you need <code>INSERT INTO test (%s) VALUES (%s)</code></p>
<p>see: <a href="http://www.w3schools.com/sql/sql_insert.asp" rel="nofollow">http://www.w3schools.com/sql/sql_insert.asp</a></p>
| 0 | 2016-10-05T06:37:48Z | [
"python",
"sql",
"insert",
"psycopg2"
] |
Python PyInstaller Tkinter Button Tied to Messagebox Does Nothing | 39,866,976 | <p>I have a tiny button with a question mark in my app. When clicked, it displays the doc string from a function in my app which helps to explain what the app does.</p>
<p>The problem is, I build a single .exe using pyinstaller and this question mark button does nothing when clicked.</p>
<p><strong>Recreation Steps</... | 2 | 2016-10-05T06:37:14Z | 39,877,519 | <p>Line 3 below is the solution. I needed to import the <code>tkinter.messagebox</code> module explicitly.</p>
<pre><code>import tkinter as tk
from tkinter import ttk
import tkinter.messagebox
''' pyinstaller.exe --onefile --windowed run.py '''
def someotherfunction():
'''
This is some message that I
want to a... | 0 | 2016-10-05T15:01:23Z | [
"python",
"tkinter",
"messagebox",
"pyinstaller"
] |
Pandas: get first 10 elements of a series | 39,867,061 | <p>I have a data frame with a column <code>tfidf_sorted</code> as follows:</p>
<pre><code> tfidf_sorted
0 [(morrell, 45.9736796), (football, 25.58352014...
1 [(melatonin, 48.0010051405), (lewy, 27.5842077...
2 [(blues, 36.5746634797), (harpdog, 20.58669641...
3 [(lem, 35.1570832476), (rottensteiner, 30.8800...
... | 3 | 2016-10-05T06:42:42Z | 39,867,338 | <p>IIUC you can use:</p>
<pre><code>from itertools import chain
#flat nested lists
a = list(chain.from_iterable(df['tfidf_sorted']))
#sorting
a.sort(key=lambda x: x[1], reverse=True)
#get 10 top
print (a[:10])
</code></pre>
<p>Or if need top 10 per row add <code>[:10]</code>:</p>
<pre><code>df['tfidf_sorted'] = df... | 1 | 2016-10-05T06:59:19Z | [
"python",
"list",
"python-2.7",
"pandas",
"indexing"
] |
Codenvy. "The system is out of resources. Please contact your system admin." | 39,867,141 | <p><img src="http://i.stack.imgur.com/8dkRU.jpg" alt="enter image description here"></p>
<p>Don't understand this error, while creating python slack.</p>
| -1 | 2016-10-05T06:47:48Z | 39,867,188 | <p>Someone seem to have had a similar question and got some help here:
<a href="https://groups.google.com/a/codenvy.com/forum/#!topic/codenvy/N1OE5BgfZNk" rel="nofollow">https://groups.google.com/a/codenvy.com/forum/#!topic/codenvy/N1OE5BgfZNk</a></p>
<blockquote>
<p>"Can you run the following please?</p>
</blockquo... | 0 | 2016-10-05T06:50:35Z | [
"python",
"codenvy"
] |
Codenvy. "The system is out of resources. Please contact your system admin." | 39,867,141 | <p><img src="http://i.stack.imgur.com/8dkRU.jpg" alt="enter image description here"></p>
<p>Don't understand this error, while creating python slack.</p>
| -1 | 2016-10-05T06:47:48Z | 39,894,018 | <p>Is this happening at beta.codenvy.com? Or on your own downloaded Codenvy system? You can also file an issue at <a href="https://github.com/codenvy/codenvy/issues" rel="nofollow">https://github.com/codenvy/codenvy/issues</a> where support and engineers hang out.</p>
| 0 | 2016-10-06T10:50:00Z | [
"python",
"codenvy"
] |
Codenvy. "The system is out of resources. Please contact your system admin." | 39,867,141 | <p><img src="http://i.stack.imgur.com/8dkRU.jpg" alt="enter image description here"></p>
<p>Don't understand this error, while creating python slack.</p>
| -1 | 2016-10-05T06:47:48Z | 39,897,308 | <p>This particular issue happens when you are running your own private Codenvy system and the underlying hardware is out of memory / CPU to give to users. So while the user gets this message, its an indication that the system administrator needs to add additional physical nodes to the cluster. I am going to open an iss... | 0 | 2016-10-06T13:26:05Z | [
"python",
"codenvy"
] |
Need to mock a non test method in Django | 39,867,259 | <p>I have a test class just like the one below: </p>
<pre><code>@mock.patch('myapp.apps.mytask1.views.image_processing.apply_async')
class SortAPITestCase(APITestCase):
def hit_scan("""some args"""):
scan_uri = 'some url'
data = 'some data'
resp = self.client.post(scan_uri, data=data)
... | 1 | 2016-10-05T06:55:10Z | 39,867,949 | <p>This has nothing to do with the method being outside of the test; Python makes no such distinction. However your syntax for mocking is consult wrong: you need to reference the thing you want to mock via a Python module path, not a file path.</p>
<pre><code> @mock.patch('path.something.file.apply_async')
</code></pr... | 0 | 2016-10-05T07:32:29Z | [
"python",
"django",
"unit-testing",
"celery",
"django-celery"
] |
Celery - [Errno 111] Connection refused when celery task is triggered using delay() | 39,867,380 | <p>I have two application servers(both having the django application). Both have celery worker running. RabbitMQ server is set up on a third different server.</p>
<p>When any of the test task is being executed from any of the two application's servers through shell using <code>delay()</code>, they get executed fine. <... | 0 | 2016-10-05T07:01:37Z | 39,884,285 | <p>I'd say start adding some extra logging calls before calling delay on server2 just to make sure your celery config is correct when running it as a webserver (as opposed to the manage.py shell instance). It sounds like some startup script for gunicorn / uwsgi / apache / magic isn't loading some variable needed to act... | 0 | 2016-10-05T21:51:22Z | [
"python",
"django",
"python-2.7",
"rabbitmq",
"celery"
] |
Parsing Weather XML with Python | 39,867,385 | <p>I'm a beginner but with a lot of effort I'm trying to parse some data about the weather from an .xml file called "weather.xml" which looks like this:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Weather>
<locality name="Rome" alt="21">
<situation temperature="18°C" temperatureF="... | 1 | 2016-10-05T07:01:56Z | 39,868,130 | <p>It is because "description" and "lastUpdate" are not attributes but child nodes of the "situation" node.</p>
<p>Try:</p>
<pre><code>d = entry_situation[0].getElementsByTagName("description")[0]
print "Description: %s" % d.firstChild.nodeValue
</code></pre>
<p>You should use the same method to access the "situatio... | 1 | 2016-10-05T07:43:11Z | [
"python",
"xml",
"minidom"
] |
Assign Jinja2 block variable from for loop in view | 39,867,462 | <p>How would I replace the the hard coded '<code>python</code>' with <code>snippet['language']</code> from a for loop in my view?</p>
<pre><code>{% highlight 'python', lineno='inline' -%}
{{snippet['code']}}
{% endhighlight %}
</code></pre>
| 0 | 2016-10-05T07:05:53Z | 39,869,400 | <p>You can simply put your variable in place of the hardcoded string like this:</p>
<pre><code>{% set lang = 'python' %}
{% highlight lang %}
from fridge import Beer
glass = Beer(lt=500)
glass.drink()
{% endhighlight %}
</code></pre>
<p>You haven't showed us your for-loop, but in principle you can do the same t... | 0 | 2016-10-05T08:50:15Z | [
"python",
"flask",
"jinja2"
] |
How to enable a button when some text is entered in tkinter entry widget? | 39,867,526 | <p>Currently i have a scenario where buttons are disabled.Now i want to enable the buttons when some input is entered by the user in tkinter entry widget.</p>
<p>Please suggest.</p>
<p>Thanks!</p>
| -2 | 2016-10-05T07:08:58Z | 39,867,661 | <p>You can <code>bind()</code> function to <code>Entry</code> which will be executed when user press <code><Key></code>.</p>
<p>See <code>bind()</code> and <code><Key></code> in <a href="http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm" rel="nofollow">Events and Binding</a></p>
| 2 | 2016-10-05T07:16:20Z | [
"python",
"tkinter"
] |
How to enable a button when some text is entered in tkinter entry widget? | 39,867,526 | <p>Currently i have a scenario where buttons are disabled.Now i want to enable the buttons when some input is entered by the user in tkinter entry widget.</p>
<p>Please suggest.</p>
<p>Thanks!</p>
| -2 | 2016-10-05T07:08:58Z | 39,868,465 | <p>You can follow this <a href="http://stackoverflow.com/questions/19148242/tkinter-entry-widget-is-detecting-input-text-possible">question</a> and as @Furas said you can bind function to Entry, something like this</p>
<pre><code>from Tkinter import Tk, Entry
root = Tk()
frame = Frame(root) #"frame" represents the... | 0 | 2016-10-05T08:01:07Z | [
"python",
"tkinter"
] |
How to test a FileField in Django REST Framework | 39,867,672 | <p>I have this serializer which I am trying to test:</p>
<pre><code>class AttachmentSerializer(CustomModelSerializer):
order = serializers.PrimaryKeyRelatedField()
file = FileField()
class Meta:
model = Attachment
fields = (
'id',
'order',
'name',
... | 0 | 2016-10-05T07:17:02Z | 39,869,073 | <p>The thing is that you pass an opened file to the APIClient / APIRequestFactory, not to the view itself. The Django request will wraps the file to an <a href="https://docs.djangoproject.com/en/1.10/ref/files/uploads/#uploaded-files" rel="nofollow"><code>UploadedFile</code></a> which is what you should use.</p>
| 0 | 2016-10-05T08:35:16Z | [
"python",
"django",
"serialization",
"django-rest-framework"
] |
Embed a file line by line in Combo Box in Python Qt | 39,867,697 | <p>I am having a situation in which I have to fill <code>Combo Box</code> with data available in a file. Mine approach is</p>
<pre><code>self.cmbBusListBox.addItem("Select ..")
lines = [line.rstrip('\n') for line in open('i2coutput.cfg')]
for line in lines:
self.cmbBusListBox.addItem(line)
self.cmbBu... | 0 | 2016-10-05T07:18:35Z | 39,867,982 | <p><code>No module named Py4</code> but there is one named <code>PyQt4</code>:</p>
<pre><code>from PyQt4 import QtGui, QtCore
</code></pre>
<p>It's just a typo in import statement and has nothing with combobox populating.</p>
| 0 | 2016-10-05T07:34:13Z | [
"python",
"linux",
"pyqt4"
] |
Getting good accuracy but very low precision for classification task on an unbalanced dataset | 39,867,753 | <p>I have an unbalanced dataset , where the positive class is about 10,000 entries and the negative class is some 8,00,000 entries. I am trying a simple scikit's LogisticRegression model as a base line model, with class_weight='balanced' (hopefully unbalanced problem should be solved?).</p>
<p>However, I am getting an... | 0 | 2016-10-05T07:22:11Z | 39,871,424 | <p>I think I understand what is going on.</p>
<p>Consider a dummy classifier that would return the majority class for each sample of your data set. For an unbalanced set like yours it seems pretty fair (let's call your positive class <em>class 1</em> and the negative one <em>class 0</em>). The classifier would have an... | 0 | 2016-10-05T10:22:58Z | [
"python",
"python-2.7",
"scikit-learn"
] |
How to replace a value in specific cell of a csv file? | 39,868,100 | <p>I want to make a python script which has a counter that replaces the current value of a specific cell in a CSV file. </p>
<p>My code is : </p>
<pre><code>with open(ctlLst[-1], 'rb') as csvfile:
csvReader = csv.reader(csvfile)
csvReader.next()
for row in csvReader:
if row[6]>counter:
... | 1 | 2016-10-05T07:41:10Z | 39,871,965 | <p>Most probably it's a good idea to write while reading/parsing to save memory</p>
<pre><code>with open('out.csv', 'wb') as outfile:
with open(ctlLst[-1], 'rb') as csvfile:
csvReader = csv.reader(csvfile)
csvWriter = csv.writer(outfile)
csvReader.next()
for row in csvReader:
row[6] = int(row[6... | 0 | 2016-10-05T10:49:45Z | [
"python",
"csv"
] |
How to replace a value in specific cell of a csv file? | 39,868,100 | <p>I want to make a python script which has a counter that replaces the current value of a specific cell in a CSV file. </p>
<p>My code is : </p>
<pre><code>with open(ctlLst[-1], 'rb') as csvfile:
csvReader = csv.reader(csvfile)
csvReader.next()
for row in csvReader:
if row[6]>counter:
... | 1 | 2016-10-05T07:41:10Z | 39,872,398 | <p>got it...</p>
<pre><code> rowData=[]
with open(ctlLst[-1], 'rb') as csvfile:
csvReader = csv.reader(csvfile)
for row in csvReader:
rowData.append(row)
rowData[1][6]=int(rowData[1][6])-counter
print ("new Row data count is " + str(rowData[1][6]))
</code></pre>
<p>thank's </p>
| -1 | 2016-10-05T11:11:59Z | [
"python",
"csv"
] |
How to git fetch using gitpython? | 39,868,114 | <p>I am looking for a equivalent way to fetch in gitpython</p>
<pre><code>git fetch --quiet --all
</code></pre>
<p>How can I perform git fetch in python?</p>
| 1 | 2016-10-05T07:42:14Z | 39,868,183 | <p>The <a href="http://gitpython.readthedocs.io/en/stable/reference.html?highlight=Fetch#module-git.remote" rel="nofollow"><code>fetch</code> method</a> is equivalent to issuing <code>git fetch</code>. Accordingly, you can fetch all your remotes by iterating and fetching each individually:</p>
<pre><code>repo = git.Re... | 3 | 2016-10-05T07:46:02Z | [
"python",
"git",
"gitpython"
] |
How to plot a task schedule with matplotlib | 39,868,191 | <p>I have three lists of tuples containing start time, finish time and column allocation for different tasks. I want to plot these lists into a schedule in the following way: <a href="http://i.stack.imgur.com/hIBjR.png" rel="nofollow"><img src="http://i.stack.imgur.com/hIBjR.png" alt="enter image description here"></a>... | 0 | 2016-10-05T07:46:24Z | 39,870,178 | <p><a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.bar" rel="nofollow"><code>axes.bar</code></a> allows you to specify left position, height, and bottom coordinates of each bar, as well as a common width for all bars. Seems like a good fit for your problem.</p>
| 0 | 2016-10-05T09:25:40Z | [
"python",
"python-2.7",
"matplotlib",
"plot"
] |
Cpp compilation from python fail but not in the shell | 39,868,209 | <p>I have a <code>cpp</code> file that compiles fine with <code>g++</code> by using the shell:</p>
<pre><code>extern "C"{
#include <quadmath.h>
}
inline char* print( const __float128& val)
{
char* buffer = new char[128];
quadmath_snprintf(buffer,128,"%+.34Qe", val);
return buffer;
}
int main(){
... | 3 | 2016-10-05T07:47:38Z | 39,868,750 | <p>When you open a shell a whole of stuff is silently initialized for you, and most important for your issue, environment variables are set. What you most likely miss is the definition of <code>LIBRARY_PATH</code>, which is the variable used by the linker to look for libraries matching the ones you instruct it to link ... | 3 | 2016-10-05T08:16:44Z | [
"python",
"c++",
"g++"
] |
scikit-learn package successfully updated, but continues to use/show old version | 39,868,413 | <p>I just got access to a new server which has Python 2.7 and some packages already installed. However, I need the newest version of scikit-learn (0.18.0). </p>
<p>I tried to pip-upgrade the package, which returns the following affirmative message <code>Successfully installed scikit-learn Cleaning up...</code></p>
<p... | 0 | 2016-10-05T07:58:12Z | 39,879,221 | <p>Hi I was in the same situation as you, in order to get the correct version of sklearn, before importing it,
I added this line to my code:</p>
<pre><code>import sys
sys.path.insert(0, '/home/your_user_name/.local/lib/python2.7/site-packages/')
</code></pre>
<p>I am not quite sure about the path part, but basically ... | 1 | 2016-10-05T16:24:26Z | [
"python",
"scikit-learn",
"pip"
] |
How to merge key values within dictionaries if they have a common key-value pair? | 39,868,437 | <p>I have a list of dictionaries,</p>
<pre><code>list = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
</code></pre>
<p>How do I make it so that the output looks like this:</p>
<pre><code>outputL... | 0 | 2016-10-05T07:59:38Z | 39,868,866 | <pre><code>lists = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
hostnames = set([d['hostname'] for d in lists])
outputlist= list()
for hostname in hostnames:
od = {
'hostname': host... | 2 | 2016-10-05T08:23:27Z | [
"python",
"list",
"dictionary",
"merge"
] |
How to merge key values within dictionaries if they have a common key-value pair? | 39,868,437 | <p>I have a list of dictionaries,</p>
<pre><code>list = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
</code></pre>
<p>How do I make it so that the output looks like this:</p>
<pre><code>outputL... | 0 | 2016-10-05T07:59:38Z | 39,868,914 | <p>Here is one way:</p>
<pre><code>inputList = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
outputList = {}
for d in inputList:
od = outputList.setdefault(d['hostname'], {})
od.setdefaul... | 1 | 2016-10-05T08:26:05Z | [
"python",
"list",
"dictionary",
"merge"
] |
How to merge key values within dictionaries if they have a common key-value pair? | 39,868,437 | <p>I have a list of dictionaries,</p>
<pre><code>list = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
</code></pre>
<p>How do I make it so that the output looks like this:</p>
<pre><code>outputL... | 0 | 2016-10-05T07:59:38Z | 39,868,998 | <p>You can use below code:</p>
<pre><code>list_1 = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
out_list = []
for each_dict in list_1:
if out_list:
for out_dict in out_list:
if out_dict... | 0 | 2016-10-05T08:30:36Z | [
"python",
"list",
"dictionary",
"merge"
] |
How to merge key values within dictionaries if they have a common key-value pair? | 39,868,437 | <p>I have a list of dictionaries,</p>
<pre><code>list = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
</code></pre>
<p>How do I make it so that the output looks like this:</p>
<pre><code>outputL... | 0 | 2016-10-05T07:59:38Z | 39,869,020 | <pre><code>from collections import defaultdict
lst = [
{'hostname': 'a', 'ipaddr':'abcde'},
{'hostname': 'a', 'ipaddr':'fghijkl'},
{'hostname': 'a', 'ipaddr':'bbbbbb'},
{'hostname': 'b', 'ipaddr':'xxxx'}
]
d = defaultdict(list)
for item in lst:
d[item['hostname']].append(item['ipaddr'])
output =... | 0 | 2016-10-05T08:32:06Z | [
"python",
"list",
"dictionary",
"merge"
] |
Combining elements of a list if condition is met | 39,868,527 | <p>I have some python code, with its final output being a list:</p>
<pre><code>['JAVS P 0 060107084657.30', '59.41 0 S', ' CEY P 0 060107084659.39', '03.10 0 S', 'CADS P 0 060107084703.67', 'VISS P 0 060107084704.14']
</code></pre>
<p>Now, I would like to join the lines, that do not start with sta (JAVS, CEY, CADS, V... | 2 | 2016-10-05T08:05:07Z | 39,868,748 | <p>You can use the <a href="https://docs.python.org/2/library/itertools.html" rel="nofollow"><code>pairwise</code> recipe from <code>itertools</code></a> to itertate through your data in pairs.</p>
<pre><code>import itertools
mydata = [
[u'JAVS P 0 060107084657.30'],
['59.41 0 S'],
[u' CEY P 0 06010708465... | 0 | 2016-10-05T08:16:40Z | [
"python"
] |
Combining elements of a list if condition is met | 39,868,527 | <p>I have some python code, with its final output being a list:</p>
<pre><code>['JAVS P 0 060107084657.30', '59.41 0 S', ' CEY P 0 060107084659.39', '03.10 0 S', 'CADS P 0 060107084703.67', 'VISS P 0 060107084704.14']
</code></pre>
<p>Now, I would like to join the lines, that do not start with sta (JAVS, CEY, CADS, V... | 2 | 2016-10-05T08:05:07Z | 39,870,031 | <p>Here is a simple loop assuming <code>mydata</code> is non-empty.</p>
<pre><code>#!/usr/bin/env python
mydata = [
[u'JAVS P 0 060107084657.30'],
['59.41 0 S'],
[u' CEY P 0 060107084659.39'],
['03.10 0 S'],
[u'CADS P 0 060107084703.67'],
[u'VISS P 0 060107084704.14'],
]
prefixes = (u'JAVS', ... | 0 | 2016-10-05T09:18:45Z | [
"python"
] |
How to calculate metrics for one particular column from other columns in Pandas? | 39,868,547 | <p>I have a dataset where I need to calculate metrics related to each person on a dataset. For example, I have a dataframe with data that looks like this</p>
<pre><code>id name age task_date task_venue money_earned
1 John 25 2016-05-01 A 100
2 Jane 28 2016-05-12 A ... | 0 | 2016-10-05T08:06:12Z | 39,868,627 | <p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.aggregate.html" rel="nofollow"><code>aggregate</code></a> metrics like for colu... | 2 | 2016-10-05T08:10:50Z | [
"python",
"pandas",
"optimization",
"data-analysis",
"data-science"
] |
scrapy xpath can't get values | 39,868,615 | <p>I have a website and i would like to save two span element value.</p>
<p>This is the relevant part of my html code:</p>
<pre class="lang-html prettyprint-override"><code><div class="box-search-product-filter-row">
<span class="result-numbers" sth-bind="model.navigationSettings.showFilter">
&l... | 0 | 2016-10-05T08:10:03Z | 39,869,333 | <p>You forgot <code>@</code> in your xpath <code>"/span[class='result']/text()"</code>. Furthermore the span you are looking for is not a 1st level child so you need to use <code>.//</code> instead of <code>/</code>. See:
<a href="http://i.stack.imgur.com/xPxff.png" rel="nofollow"><img src="http://i.stack.imgur.com/xPx... | 1 | 2016-10-05T08:46:49Z | [
"python",
"xpath",
"scrapy",
"scrapy-spider"
] |
scrapy xpath can't get values | 39,868,615 | <p>I have a website and i would like to save two span element value.</p>
<p>This is the relevant part of my html code:</p>
<pre class="lang-html prettyprint-override"><code><div class="box-search-product-filter-row">
<span class="result-numbers" sth-bind="model.navigationSettings.showFilter">
&l... | 0 | 2016-10-05T08:10:03Z | 39,869,427 | <p>This will work for you </p>
<p><strong>EDIT:</strong></p>
<pre><code>from scrapy.spiders import Spider
from scrapy.selector import Selector
class MySpdier(Spider):
name = "list"
allowed_domains = ["example.com"]
start_urls = [
"https://www.example.com"]
def parse(self, response):
... | 0 | 2016-10-05T08:51:37Z | [
"python",
"xpath",
"scrapy",
"scrapy-spider"
] |
How to add sqlalchemy.exc.IntegrityError as side effect to mock objects? | 39,868,682 | <p>I am testing a function that needs a mock object. This object might raise IntegrityError so I am adding this error as side effect to the mock object </p>
<pre><code>def test_(self, mock_object):
mock_object.side_effect = IntegrityError
</code></pre>
<p>This is somehow not correct as it raises an exception ... | 0 | 2016-10-05T08:13:27Z | 39,868,889 | <p>Just build a one-line function raising an integrity error, and adds that as the side-effect:</p>
<pre><code>x = Mock()
def b():
raise IntegrityError('Mock', 'mock', 'mock')
x.side_effect = b
x()
</code></pre>
| 1 | 2016-10-05T08:24:52Z | [
"python",
"unit-testing",
"python-mock"
] |
Concatenate list Object to cypher | 39,868,743 | <p>I am using Neo4j Bolt Driver and executing few queries where I have to check the node in a list of id's.</p>
<p>Query:</p>
<pre><code>MATCH (n)-[r]->(m) WHERE ID(n) in [1,2,3,4] RETURN n,r,m
</code></pre>
<p>Doing the same with python fails:</p>
<pre><code>l = [1,2,3,4]
query = 'MATCH (n)-[r]->(m) WHERE ID... | 1 | 2016-10-05T08:16:27Z | 39,868,919 | <p>Your <code>list</code> is not of type String (str). As there is no natural way of concatenation of <code>int</code> and <code>str</code>, you're getting this error.</p>
<p>Making <code>list</code> string like <code>list = '[1,2,3,4]'</code> would help.</p>
<p>Btw <code>list</code> is a reserved keyword in python.... | 1 | 2016-10-05T08:26:16Z | [
"python",
"neo4j",
"cypher"
] |
Concatenate list Object to cypher | 39,868,743 | <p>I am using Neo4j Bolt Driver and executing few queries where I have to check the node in a list of id's.</p>
<p>Query:</p>
<pre><code>MATCH (n)-[r]->(m) WHERE ID(n) in [1,2,3,4] RETURN n,r,m
</code></pre>
<p>Doing the same with python fails:</p>
<pre><code>l = [1,2,3,4]
query = 'MATCH (n)-[r]->(m) WHERE ID... | 1 | 2016-10-05T08:16:27Z | 39,876,915 | <p>If you're using a driver, you should be using a parameter for this, which avoids all of the string mangling and stringification problems (which are explicitly recommended against):</p>
<pre><code>query = 'MATCH (n)-[r]->(m) WHERE ID(n) in {id_list} RETURN n,r,m'
params = {'id_list': [1, 2, 3, 4]}
session.run(sta... | 1 | 2016-10-05T14:36:25Z | [
"python",
"neo4j",
"cypher"
] |
Minimizing the sum of 3 variables subject to equality and integrality constraints | 39,868,762 | <p>I am working on a programming (using Python) problem where I have to solve the following type of linear equation in 3 variables:</p>
<p>x, y, z are all integers.</p>
<p>Equation example: <code>2x + 5y + 8z = 14</code></p>
<p>Condition: <code>Minimize x + y + z</code></p>
<p>I have been trying to search for an a... | 3 | 2016-10-05T08:17:09Z | 39,868,807 | <p>Any triple <em>(x, y, z)</em>, with <em>z = (14 - 2x - 5y) / 8</em>, satisfies your constraint. </p>
<p>Note that <em>x + y + (14 - 2x - 5y) / 8</em> is unbounded from below. This function decreases when each of <em>x</em> and <em>y</em> decrease, with no finite minimum.</p>
| 3 | 2016-10-05T08:20:05Z | [
"python",
"algorithm",
"linear-programming",
"integer-programming"
] |
Minimizing the sum of 3 variables subject to equality and integrality constraints | 39,868,762 | <p>I am working on a programming (using Python) problem where I have to solve the following type of linear equation in 3 variables:</p>
<p>x, y, z are all integers.</p>
<p>Equation example: <code>2x + 5y + 8z = 14</code></p>
<p>Condition: <code>Minimize x + y + z</code></p>
<p>I have been trying to search for an a... | 3 | 2016-10-05T08:17:09Z | 39,869,034 | <p>From your first equation:</p>
<p>x = (14 - 5y - 8x) / 2</p>
<p>so, you now only need to minimize</p>
<p>(14 - 5y - 8z) / 2 + y + z</p>
<p>which is</p>
<p>(14 - 3y - 6z) / 2</p>
<p>But we can ignore the ' / 2' part for minimization purposes.</p>
<p>Presumably, there must be some other constraints on your probl... | 0 | 2016-10-05T08:33:03Z | [
"python",
"algorithm",
"linear-programming",
"integer-programming"
] |
Minimizing the sum of 3 variables subject to equality and integrality constraints | 39,868,762 | <p>I am working on a programming (using Python) problem where I have to solve the following type of linear equation in 3 variables:</p>
<p>x, y, z are all integers.</p>
<p>Equation example: <code>2x + 5y + 8z = 14</code></p>
<p>Condition: <code>Minimize x + y + z</code></p>
<p>I have been trying to search for an a... | 3 | 2016-10-05T08:17:09Z | 39,869,597 | <p>I do not know any general fast solution for n variables, or not using hit & trail loops. But for the given specific equation <code>2x + 5y + 8z = 14</code>, there maybe some shortcut based on observation.</p>
<p>Notice that the range is very small for any possible solutions: </p>
<p><code>0<=x<=7</code... | 0 | 2016-10-05T09:00:03Z | [
"python",
"algorithm",
"linear-programming",
"integer-programming"
] |
Minimizing the sum of 3 variables subject to equality and integrality constraints | 39,868,762 | <p>I am working on a programming (using Python) problem where I have to solve the following type of linear equation in 3 variables:</p>
<p>x, y, z are all integers.</p>
<p>Equation example: <code>2x + 5y + 8z = 14</code></p>
<p>Condition: <code>Minimize x + y + z</code></p>
<p>I have been trying to search for an a... | 3 | 2016-10-05T08:17:09Z | 39,888,287 | <p>Another tool to solve this type of problems is <a href="http://scip.zib.de" rel="nofollow">SCIP</a>. There is also an easy to use Python interface available on GitHub: <a href="https://github.com/SCIP-Interfaces/PySCIPOpt" rel="nofollow">PySCIPOpt</a>.</p>
<p>In general (mixed) integer programming problems are very... | 0 | 2016-10-06T05:38:45Z | [
"python",
"algorithm",
"linear-programming",
"integer-programming"
] |
Increment slice object? | 39,868,870 | <p>Is it possible to change the values in a python slice object?</p>
<p>For example, if I have </p>
<pre><code>slice(0,1,None)
</code></pre>
<p>How would I, in effect, add 1 to the start and end values and so convert this to:</p>
<pre><code>slice(1,2,None)
</code></pre>
| 1 | 2016-10-05T08:23:41Z | 39,868,968 | <p>Not exactly elegant, but it works:</p>
<pre><code>>>> s1 = slice(0,1,None)
>>> s2 = slice(s1.start + 1, s1.stop + 1, s1.step)
>>> s2
slice(1, 2, None)
>>>
</code></pre>
| 3 | 2016-10-05T08:29:12Z | [
"python",
"slice"
] |
Is there a way to get the labels of running GTK applications? | 39,868,883 | <p>I am trying to extract labels of widgets of running GTK applications. I tried using GtkParasite but I have no idea how to get it working in my python program.</p>
<p>I want to be able to get the widgets and their labels of a gtk application that is running on my computer. It means that if I run gedit on my system t... | 2 | 2016-10-05T08:24:34Z | 39,870,918 | <p>You probably should use accessibility libraries - those are tools that allow eg. screen readers to read GUI labels for visually impaired users. On Linux, <a href="https://en.wikipedia.org/wiki/Assistive_Technology_Service_Provider_Interface">at-spi2</a> seems to be the de-facto standard.</p>
<p>For Python, take loo... | 5 | 2016-10-05T09:58:18Z | [
"python",
"python-2.7",
"gtk",
"pygtk",
"gtk3"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,869,632 | <p>I get the feeling that this question is designed with the expectation that you would initially instinctively do it the way you have. However, I believe there's a slightly different approach that would be faster.</p>
<p>You can produce all the numbers that contain the number 13 yourself, without having to loop throu... | 5 | 2016-10-05T09:01:52Z | [
"python"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,869,693 | <p>I think this can be solved via recursion:</p>
<pre><code>ans(n) = { ans([n/2])^2 - ans([n/2]-1)^2 }, if n is even
ans(n) = { ans([n/2]+1)*ans([n/2]) - ans([n/2])*ans([n/2]-1) }, if n is odd
</code></pre>
<p>Base Cases:</p>
<ul>
<li><code>ans(0)</code> = 1</li>
<li><code>ans(1)</code> = 10</li>
</ul>
<p>It's impl... | 4 | 2016-10-05T09:04:17Z | [
"python"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,869,878 | <p>This a P&C problem. I'm going to assume 0 is valid string and so is 00, 000 and so on, each being treated distinct from the other.</p>
<p>The total number of strings not containing 13, of length N, is unsurprisingly given by:</p>
<pre><code>(Total Number of strings of length N) - (Total number of strings of le... | 3 | 2016-10-05T09:12:20Z | [
"python"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,870,385 | <p>In fact this question is more about math than about python.
For N figures there is 10^N possible unique strings. To get the answer to the problem we need to subtract the number of string containing "13".
If string starts from "13" we have 10^(N-2) possible unique strings. If we have 13 at the second possition (e.i.... | 2 | 2016-10-05T09:34:14Z | [
"python"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,871,874 | <p>Let <code>f(n)</code> be the number of sequences of length n that have no "13" in them, and <code>g(n)</code> be the number of sequences of length n that have "13" in them.</p>
<p>Then <code>f(n) = 10^n - g(n)</code> (in mathematical notation), because it's the number of possible sequences (<code>10^n</code>) minus... | 2 | 2016-10-05T10:45:03Z | [
"python"
] |
Unlucky number 13 | 39,868,990 | <p>I came accorss this problem <a href="http://qa.geeksforgeeks.org/4344/the-unlucky-13" rel="nofollow">Unlucky number 13! </a> recently but could not think of efficient solution this.</p>
<h3>Problem statement :</h3>
<p>N is taken as input. </p>
<blockquote>
<p>N can be very large 0<= N <= 1000000009</p>
</... | 5 | 2016-10-05T08:30:24Z | 39,879,256 | <p>Thanks to L3viathan's comment now it is clear. The logic is beautiful.</p>
<p>Let's assume <code>a(n)</code> is a number of strings of <code>n</code> digits without "13" in it. If we know all the good strings for <code>n-1</code>, we can add one more digit to the left of each string and calculate <code>a(n)</code>.... | 2 | 2016-10-05T16:26:24Z | [
"python"
] |
\MongoDB\BSON\Regex in aggregation pipeline - Convert regex from Python to PHP | 39,868,993 | <p>I'm trying to match some input parameters in my API call using the newer Regex library in PHP, but it's not working so far. I'm using string interpolation to achieve this, but its returning any results. Here is my code:</p>
<pre><code>$regex = new \MongoDB\BSON\Regex ("^{$this->device_id}:", 'i');
$pipeline = [... | 0 | 2016-10-05T08:30:29Z | 39,869,209 | <p>The original code in the question is actually correct - I found that the problem wasn't in this part of my pipeline, but further downstream.</p>
| 0 | 2016-10-05T08:41:29Z | [
"php",
"python",
"regex",
"mongodb",
"aggregate"
] |
re.sub: non-greedy doesn't work as expected | 39,869,136 | <p>I have the following code in ipython. I expect it to remove the beginning "ab" since .*? is a non-greedy one. But why it remove all the way up to the last b?</p>
<pre><code> In [15]: b="abcabcabc"
In [16]: re.sub(".*?b","",b)
Out[16]: 'c'
</code></pre>
| 1 | 2016-10-05T08:37:58Z | 39,869,265 | <p>That is because, by default, <code>re.sub()</code> will search and replace all occurrences </p>
<pre><code>>>> import re
>>> b="abcabcabc"
>>> re.sub(".*?b","",b)
'c'
>>> re.sub("^.*?b","",b)
'cabcabc'
>>> re.sub(".*?b","",b, count=1)
'cabcabc'
>>> re.sub(".*?b"... | 3 | 2016-10-05T08:44:06Z | [
"python",
"regex"
] |
re.sub: non-greedy doesn't work as expected | 39,869,136 | <p>I have the following code in ipython. I expect it to remove the beginning "ab" since .*? is a non-greedy one. But why it remove all the way up to the last b?</p>
<pre><code> In [15]: b="abcabcabc"
In [16]: re.sub(".*?b","",b)
Out[16]: 'c'
</code></pre>
| 1 | 2016-10-05T08:37:58Z | 39,869,413 | <p>The <em>python</em> <a href="https://docs.python.org/3/library/re.html#re.sub" rel="nofollow">docs</a> says:</p>
<blockquote>
<p>The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, <strong>all occurrences will be replac... | 1 | 2016-10-05T08:51:06Z | [
"python",
"regex"
] |
Error Capturing specific bounds | 39,869,219 | <p>hello python comunity,</p>
<p>How do I stop this from looping?</p>
<pre><code>error33 = int(2)
while error33 > 1:
while True:
try:
survivalrateforjuveniles = float(input("Please enter the survival rate for poomen"))##Float input is being used as
... | -1 | 2016-10-05T08:41:45Z | 39,869,517 | <p>This works...</p>
<pre><code>error33 = 2
while error33 > 1:
while True:
try:
survivalrateforjuveniles = float(input("Please enter the survival rate for poomen\n"))
break
except ValueError:
print("Please enter a nu... | -2 | 2016-10-05T08:55:45Z | [
"python",
"error-handling"
] |
iItertools.product with variable validation | 39,869,423 | <p>I have this form of list</p>
<pre><code>data = [
[
{'name': 's11', 'class': 'c1'}, {'name': 's12', 'class': 'c2'}
],
[
{'name': 's21', 'class': 'c2'}, {'name': 's22', 'class': 'c2'}
],
[
{'name': 's31', 'class': 'c1'}, {'name': 's32', 'class': 'c1'}
]
]
</code></pre>
<p>by using the <... | 0 | 2016-10-05T08:51:33Z | 39,869,749 | <pre><code>from itertools import chain, combinations, product
result = [
(a, b) for a, b
in chain.from_iterable(product(*l) for l in combinations(data, 2))
if a['class'] == b['class']
]
</code></pre>
| 1 | 2016-10-05T09:06:59Z | [
"python",
"list",
"dictionary",
"itertools"
] |
iItertools.product with variable validation | 39,869,423 | <p>I have this form of list</p>
<pre><code>data = [
[
{'name': 's11', 'class': 'c1'}, {'name': 's12', 'class': 'c2'}
],
[
{'name': 's21', 'class': 'c2'}, {'name': 's22', 'class': 'c2'}
],
[
{'name': 's31', 'class': 'c1'}, {'name': 's32', 'class': 'c1'}
]
]
</code></pre>
<p>by using the <... | 0 | 2016-10-05T08:51:33Z | 39,869,825 | <p>Almost the same as @skovorodkin posted.</p>
<pre><code>from itertools import product, chain
data = [
[{'name': 's11', 'class': 'c1'}, {'name': 's12', 'class': 'c2'}],
[{'name': 's21', 'class': 'c2'}, {'name': 's22', 'class': 'c2'}],
[{'name': 's31', 'class': 'c1'}, {'name': 's32', 'class': 'c1'}]
]
out... | 0 | 2016-10-05T09:10:26Z | [
"python",
"list",
"dictionary",
"itertools"
] |
update numpy array where not masked | 39,869,524 | <p>My question is twofolded</p>
<p>First, lets say I've two numpy arrays, that are partially masked</p>
<pre><code>array_old
[[-- -- -- --]
[10 11 -- --]
[12 14 -- --]
[-- -- 17 --]]
array_update
[[-- 5 -- --]
[-- -- 9 --]
[-- 15 8 13]
[-- -- 19 16]]
</code></pre>
<p>How to get create a new array, where al... | 2 | 2016-10-05T08:56:17Z | 39,869,892 | <p>Use <code>a[~b.mask] = b.compressed()</code>.</p>
<p><code>a[~b.mask]</code> selects all the values in <code>a</code> where <code>b</code> is not masked. <code>b.compressed()</code> is a flattened array with all the non-masked values in <code>b</code>.</p>
<p>Example:</p>
<pre><code>>>> a = np.ma.masked_... | 5 | 2016-10-05T09:12:45Z | [
"python",
"arrays",
"numpy"
] |
AxesSubplot' object has no attribute 'get_xdata' error when plotting OHLC matplotlib chart | 39,869,546 | <p>I am trying to make a OHLC graph plotted with matplotlib interactive upon the user clicking on a valid point. The data is stored as a pandas dataframe of the form</p>
<pre><code>index PX_BID PX_ASK PX_LAST PX_OPEN PX_HIGH PX_LOW
2016-07-01 1.1136 1.1137 1.1136 1.1106 1.1169 1.1072
2016-07-04 1.... | 0 | 2016-10-05T08:57:32Z | 39,875,387 | <p>First of all, <code>candlestick2_ohlc</code> appears to create and return a tuple of a <code>matplotlib.collections.LineCollection</code> instance, and a <code>matplotlib.collections.PolyCollection</code> instance. </p>
<p>We need to make each of these instances pickable, before we do anything else. </p>
<p>If you... | 0 | 2016-10-05T13:31:02Z | [
"python",
"pandas",
"matplotlib",
"graph",
"interactive"
] |
Reportlab + SimpleDocTemplate + Table - create QR code with text - multiple pages | 39,869,671 | <p>I'm using Reportlab to create a pdf file that can span across multiple pages with the following format:</p>
<p>QR code + h1 paragraph + 2-3 lines of text</p>
<p>We need to support a dynamic number of elements with the format I described above.</p>
<p>I was thinking of using a Table inside a SimpleDocTemplate but ... | 0 | 2016-10-05T09:03:25Z | 39,873,267 | <p>This snippet is not fully working, but it could help you, for start </p>
<pre><code>class StandardReport:
def __init__(self,):
self.doc = BaseDocTemplate(destinationPath , showBoundary = 0, leftMargin=0.7*cm, rightMargin=0.7*cm, topMargin=0.7*cm, bottomMargin=0.7*cm, pagesize=A4)
self.simpleFrame = Frame(s... | 0 | 2016-10-05T11:54:51Z | [
"python",
"barcode",
"reportlab"
] |
Disable checkbox in django admin if already checked | 39,869,681 | <p>I have a simple but problematic question for me. How can I disable checkbox, if input is already filled/checked? I must disable some fields after first filling them. Thank you for all your ideas.</p>
<p>Sierran</p>
| 0 | 2016-10-05T09:03:50Z | 39,869,931 | <p>There is no built-in solution to this problem, if you want the fields to display dynamically you will always need a custom javascript/ajax solution! You might be able to hack the admin view and template to conditionally show/not show widgets for a field, but if you want to do it dynamically based on user behaviors i... | 0 | 2016-10-05T09:14:44Z | [
"python",
"django",
"django-admin"
] |
sqlalchemy need back_populates? | 39,869,793 | <p>When I try SQLAlchemy Relation Example following this guide: <a href="http://docs.sqlalchemy.org/en/rel_1_0/orm/basic_relationships.html#one-to-many" rel="nofollow">Basic Relationship Patterns</a></p>
<p>I have this code</p>
<pre><code>#!/usr/bin/env python
# encoding: utf-8
from sqlalchemy import create_engine
fr... | 1 | 2016-10-05T09:08:57Z | 39,870,250 | <p>If you use <code>backref</code> you don't need to declare the relationship on the second table.</p>
<pre><code>class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relationship("Child", backref="parent")
class Child(Base):
__tablename__ = 'child'
id = C... | 0 | 2016-10-05T09:28:53Z | [
"python",
"sqlalchemy"
] |
Add content to iframe with BeautifulSoup | 39,869,888 | <p>Let say I have the following iframe</p>
<pre><code> s=""""
<!DOCTYPE html>
<html>
<body>
<iframe src="http://www.w3schools.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
"""
</code></pre>
<p>I want to replace... | 2 | 2016-10-05T09:12:37Z | 39,873,342 | <p>This will work for you to replace the <code>iframe</code> tag content.</p>
<pre><code>s="""
<!DOCTYPE html>
<html>
<body>
<iframe src="http://www.w3schools.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
"""
from Beautifu... | 0 | 2016-10-05T11:58:27Z | [
"python",
"iframe",
"beautifulsoup"
] |
Add content to iframe with BeautifulSoup | 39,869,888 | <p>Let say I have the following iframe</p>
<pre><code> s=""""
<!DOCTYPE html>
<html>
<body>
<iframe src="http://www.w3schools.com">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
"""
</code></pre>
<p>I want to replace... | 2 | 2016-10-05T09:12:37Z | 39,875,046 | <p>Simply set the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#string" rel="nofollow"><code>.string</code> property</a>:</p>
<pre><code>from bs4 import BeautifulSoup
data = """
<!DOCTYPE html>
<html>
<body>
<iframe src="http://www.w3schools.com">
<p>Your browse... | 2 | 2016-10-05T13:16:56Z | [
"python",
"iframe",
"beautifulsoup"
] |
Python equivalence of R's match() for indexing | 39,869,958 | <p>So i essentially want to implement the equivalent of R's match() function in Python, using Pandas dataframes - without using a for-loop. </p>
<p>In R match() returns a vector of the positions of (first) matches of its first argument in its second. </p>
<p>Let's say that I have two df A and B, of which both include... | 2 | 2016-10-05T09:15:46Z | 39,870,277 | <p>You can use first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow"><code>drop_duplicates</code></a> and then <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <... | 2 | 2016-10-05T09:30:01Z | [
"python",
"pandas",
"indexing",
"match"
] |
Python equivalence of R's match() for indexing | 39,869,958 | <p>So i essentially want to implement the equivalent of R's match() function in Python, using Pandas dataframes - without using a for-loop. </p>
<p>In R match() returns a vector of the positions of (first) matches of its first argument in its second. </p>
<p>Let's say that I have two df A and B, of which both include... | 2 | 2016-10-05T09:15:46Z | 39,870,451 | <p>This gives all the indices that are matched (with python's 0 based indexing):</p>
<pre><code>import pandas as pd
df1 = pd.DataFrame({'C': ['a','b']})
print df1
C
0 a
1 b
df2 = pd.DataFrame({'C': ['c','c','b','b','c','b','a','a']})
print df2
C
0 c
1 c
2 b
3 b
4 c
5 b
6 a
7 a
match = df2['C'].... | 1 | 2016-10-05T09:37:56Z | [
"python",
"pandas",
"indexing",
"match"
] |
Python equivalence of R's match() for indexing | 39,869,958 | <p>So i essentially want to implement the equivalent of R's match() function in Python, using Pandas dataframes - without using a for-loop. </p>
<p>In R match() returns a vector of the positions of (first) matches of its first argument in its second. </p>
<p>Let's say that I have two df A and B, of which both include... | 2 | 2016-10-05T09:15:46Z | 39,871,039 | <p>You can also simulate the same behavior using <a href="http://pandas.pydata.org/pandas-docs/stable/comparison_with_r.html#match" rel="nofollow"><code>pd.match</code></a>:</p>
<pre><code>s1 = A['C']
print(s1)
#0 a
#1 b
#Name: C, dtype: object
s2 = B['C']
print(s2)
#0 c
#1 c
#2 b
#3 b
#4 c
#5 ... | 0 | 2016-10-05T10:03:34Z | [
"python",
"pandas",
"indexing",
"match"
] |
Django filter queryset by timedelta | 39,870,014 | <p>What could be nice way to filter devices which response was later than, for example, 500 seconds?</p>
<p>So assume my model:</p>
<pre><code>class Device(models.Model):
last_response = models.DateTimeField(null=True, blank=True)
</code></pre>
<p>My best move was:</p>
<pre><code>from django.utils import timezo... | 0 | 2016-10-05T09:18:03Z | 39,870,114 | <pre><code>from django.utils import timezone
from datetime import timedelta
Device.objects.filter(last_response__lte=timezone.now()-timedelta(seconds=500))
</code></pre>
| 2 | 2016-10-05T09:22:26Z | [
"python",
"django"
] |
Splitting strings - for a calculation | 39,870,251 | <p>I want to create a calculator with several functions. When the user inputs something such as "ADD3, DIVIDE4" it will output the answer. So I believe I will have to split the string to work on each part individually.
So far all I can find is</p>
<pre><code> numb= input("What is your first numb")
calc = input... | -2 | 2016-10-05T09:28:56Z | 39,870,328 | <p>Loop through calc Items. In the loop use a Switch case to find out the Operation and do the calculation. </p>
<p>edit: refer to this <a href="https://www.pydanny.com/why-doesnt-python-have-switch-case.html" rel="nofollow">link</a> for switch case implementation in python.</p>
| 1 | 2016-10-05T09:31:52Z | [
"python",
"string",
"split"
] |
Splitting strings - for a calculation | 39,870,251 | <p>I want to create a calculator with several functions. When the user inputs something such as "ADD3, DIVIDE4" it will output the answer. So I believe I will have to split the string to work on each part individually.
So far all I can find is</p>
<pre><code> numb= input("What is your first numb")
calc = input... | -2 | 2016-10-05T09:28:56Z | 39,870,508 | <p>You could do something like this:</p>
<pre><code>numb = input("What is your first numb")
calc = input("What is your calculation")
ops = calc.split(', ')
for op in ops:
if op.lower().startswith('add'):
number = float(op[3:])
numb += number
elif op.lower().startswith('sub'):
number = ... | 0 | 2016-10-05T09:40:22Z | [
"python",
"string",
"split"
] |
How to strip line breaks from BeautifulSoup get text method | 39,870,290 | <p>I have a following output after scraping a web page</p>
<pre><code> text
Out[50]:
['\nAbsolute FreeBSD, 2nd Edition\n',
'\nAbsolute OpenBSD, 2nd Edition\n',
'\nAndroid Security Internals\n',
'\nApple Confidential 2.0\n',
'\nArduino Playground\n',
'\nArduino Project Handbook\n',
'\nArduino Workshop\n',
'\nArt... | -2 | 2016-10-05T09:30:29Z | 39,870,343 | <p>Just like you would <a href="https://docs.python.org/3/library/stdtypes.html#str.strip" rel="nofollow"><code>strip</code></a> any other string:</p>
<pre><code>text = []
for name in web_text:
a = name.get_text().strip()
text.append(a)
</code></pre>
| 1 | 2016-10-05T09:32:38Z | [
"python",
"beautifulsoup"
] |
How to strip line breaks from BeautifulSoup get text method | 39,870,290 | <p>I have a following output after scraping a web page</p>
<pre><code> text
Out[50]:
['\nAbsolute FreeBSD, 2nd Edition\n',
'\nAbsolute OpenBSD, 2nd Edition\n',
'\nAndroid Security Internals\n',
'\nApple Confidential 2.0\n',
'\nArduino Playground\n',
'\nArduino Project Handbook\n',
'\nArduino Workshop\n',
'\nArt... | -2 | 2016-10-05T09:30:29Z | 39,870,364 | <p>You can use <a class='doc-link' href="http://stackoverflow.com/documentation/python/196/comprehensions/737/list-comprehensions#t=201610050931583559832">list comprehension</a>:</p>
<pre><code>stripedText = [ t.strip() for t in text ]
</code></pre>
<p>Which outputs:</p>
<pre><code>>>> stripedText
['Absolut... | 0 | 2016-10-05T09:33:29Z | [
"python",
"beautifulsoup"
] |
How to strip line breaks from BeautifulSoup get text method | 39,870,290 | <p>I have a following output after scraping a web page</p>
<pre><code> text
Out[50]:
['\nAbsolute FreeBSD, 2nd Edition\n',
'\nAbsolute OpenBSD, 2nd Edition\n',
'\nAndroid Security Internals\n',
'\nApple Confidential 2.0\n',
'\nArduino Playground\n',
'\nArduino Project Handbook\n',
'\nArduino Workshop\n',
'\nArt... | -2 | 2016-10-05T09:30:29Z | 39,874,799 | <p>Rather than calling <code>.strip()</code> explicitly, use the <code>strip</code> argument:</p>
<pre><code>a = name.get_text(strip=True)
</code></pre>
<p>This would also remove the extra whitespace and newline characters in the children texts if any.</p>
| 0 | 2016-10-05T13:05:32Z | [
"python",
"beautifulsoup"
] |
MQTT Paho Python Client subscriber, how subscribe forever? | 39,870,394 | <p>Try to simple subscribe without disconnect to a Mosquitto broker to get all messages from devices that are publishing data in a specific topic, save them in a BD and Post them to a php that do "staff".</p>
<p>Here is my subscribe.py</p>
<pre><code>import paho.mqtt.client as mqtt
from mqtt_myapp import *
topic="to... | 0 | 2016-10-05T09:34:43Z | 39,874,223 | <p>If your code in the method "on_message" throws an exception and you do not catch it, you will be disconnected.
Try uncommenting all statements except the print statements. Probably one of the following statements is throwing an exception.</p>
<pre><code> save_to_db(msg)
post_data(msg.payload,value)
</code></pre>
| 0 | 2016-10-05T12:39:18Z | [
"python",
"mqtt",
"mosquitto",
"paho"
] |
Django Factory Boy iterate over related parent | 39,870,398 | <p>I have a project with Clients, Draftschedules, LineItems and Servers.</p>
<ul>
<li><p>Each client has a single DraftSchedule, each Draftschedule has many Lineitems</p></li>
<li><p>Each Client has many Servers</p></li>
<li><p>Each LineItem has a Single Server</p></li>
</ul>
<p><a href="http://i.stack.imgur.com/JPRI... | 0 | 2016-10-05T09:35:05Z | 39,870,916 | <p>You could try using a <a href="http://factoryboy.readthedocs.io/en/latest/reference.html#id6" rel="nofollow">lazy_attribute_sequence</a> :</p>
<pre><code>@factory.lazy_attribute_sequence
def servers(obj, seq):
all_servers = obj.draftschedule.client.servers.all()
nb_servers = all_servers.count()
return a... | 1 | 2016-10-05T09:58:15Z | [
"python",
"django",
"fixtures",
"factory-boy"
] |
PyQt wake main thread from non-QThread | 39,870,577 | <p>I have a PyQt application that receives information from an external source via callbacks that are called from threads that are not under my control and which are not <code>QThread</code>. What is the correct way to pass such information to the main thread, without polling? Particularly, I want to emit a Qt signal s... | 1 | 2016-10-05T09:42:38Z | 39,882,191 | <p>I would handle it the same way I would if you were just polling an external device or library. Create a separate worker thread that handles the callback, and emits an signal to the main GUI thread.</p>
<pre><code>class Worker(QObject):
data_ready = pyqtSignal(object, object)
def callback(self, *args, **k... | 0 | 2016-10-05T19:30:46Z | [
"python",
"multithreading",
"qt",
"pyqt",
"qthread"
] |
PyQt wake main thread from non-QThread | 39,870,577 | <p>I have a PyQt application that receives information from an external source via callbacks that are called from threads that are not under my control and which are not <code>QThread</code>. What is the correct way to pass such information to the main thread, without polling? Particularly, I want to emit a Qt signal s... | 1 | 2016-10-05T09:42:38Z | 39,901,464 | <p>The default connection type for signals is <a href="http://doc.qt.io/qt-4.8/qt.html#ConnectionType-enum" rel="nofollow">Qt.AutoConnection</a>, which the docs describe thus:</p>
<blockquote>
<p>If the signal is emitted from a different thread than the receiving
object, the signal is queued, behaving as Qt::Queue... | 1 | 2016-10-06T16:42:21Z | [
"python",
"multithreading",
"qt",
"pyqt",
"qthread"
] |
Matplotlib - How to plot a high resolution graph? | 39,870,642 | <p>I've used matplotlib for plotting some experimental results (discussed it in here: <a href="http://stackoverflow.com/questions/39676294/looping-over-files-and-plotting-python/" title="Looping over files and plotting (Python)">Looping over files and plotting</a>. However, saving the picture by clicking right ... | 2 | 2016-10-05T09:45:40Z | 39,870,740 | <p>You can use <a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.savefig" rel="nofollow"><code>savfig()</code></a> to export to an image file:</p>
<pre><code>plt.savefig('filename.png')
</code></pre>
<p>In adittion, you can specify the <code>dpi</code> arg to some scalar value, for example:<... | 0 | 2016-10-05T09:50:20Z | [
"python",
"matplotlib"
] |
Matplotlib - How to plot a high resolution graph? | 39,870,642 | <p>I've used matplotlib for plotting some experimental results (discussed it in here: <a href="http://stackoverflow.com/questions/39676294/looping-over-files-and-plotting-python/" title="Looping over files and plotting (Python)">Looping over files and plotting</a>. However, saving the picture by clicking right ... | 2 | 2016-10-05T09:45:40Z | 39,870,761 | <p>You can save your graph as svg for a lossless quality:</p>
<pre><code>import matplotlib.pylab as plt
x = range(10)
plt.figure()
plt.plot(x,x)
plt.savefig("graph.svg")
</code></pre>
| 1 | 2016-10-05T09:51:12Z | [
"python",
"matplotlib"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.