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 |
|---|---|---|---|---|---|---|---|---|---|
What is the best way to store a list of functions? | 39,259,411 | <p>I need to store a large numbers of functions rules in Python (around 100000 ), to be used after....</p>
<pre><code>def rule1(x,y) :...
def rule2(x,y): ...
</code></pre>
<p>What is the best way to store, manage those function rules instance into Python structure ? </p>
<p>What about using Numpy dtype=np.object arr... | 0 | 2016-08-31T21:37:52Z | 39,259,476 | <p>When you use those rules, you're going to have to reference them <em>somehow</em>. If your example is a hint of the naming convention, then go with a list. Calling them in sequence would be easy via <code>map</code> or in a loop.</p>
<pre><code>rules = [rule1, rule2, ...]
for fn in rules:
fn(arg1, arg2) # this... | 1 | 2016-08-31T21:43:24Z | [
"python"
] |
Porting a python 2 code to Python 3: ICMP Scan with errors | 39,259,570 | <pre><code>import random
import socket
import time
import ipaddress
import struct
from threading import Thread
def checksum(source_string):
sum = 0
count_to = (len(source_string) / 2) * 2
count = 0
while count < count_to:
this_val = ord(source_string[count + 1]) * 256 + ord(source_string[c... | 2 | 2016-08-31T21:52:13Z | 39,262,694 | <pre><code>import random
import socket
import time
import ipaddress
import struct
from threading import Thread
def checksum(source_string):
sum = 0
count_to = (len(source_string) / 2) * 2
count = 0
while count < count_to:
this_val = source_string[count + 1] * 256 + source_string[count]
... | 1 | 2016-09-01T04:24:16Z | [
"python",
"python-2.7",
"python-3.x"
] |
Scrapy indexing in order | 39,259,612 | <p>I'm currently creating a cutsom webcrawler with Scrapy and try to index the fetched content with Elasticsearch.
Works fine until as of now, but I'm only capable of adding content to the search index in the order the crawler filters html tags.
So for example with</p>
<pre><code>sel.xpath("//div[@class='article']/h2/... | 0 | 2016-08-31T21:55:49Z | 39,261,738 | <p>I guess you could solve the issue with something like this:</p>
<pre><code># Select multiple targeting nodes at once
sel_raw = '|'.join([
"//div[@class='article']/h2",
"//div[@class='article']/h3",
# Whatever else you want to select here
])
for sel in sel.xpath(sel_raw):
# Extract the texts for late... | 1 | 2016-09-01T02:20:03Z | [
"python",
"html",
"xpath",
"scrapy"
] |
PyQt QSortFilterProxyModel index from wrong model passed to mapToSource? | 39,259,659 | <p>I want to get the integer stored in <code>[(1, 'cb'), (3, 'cd'), (7, 'ca'), (11, 'aa'), (22, 'bd')]</code> when I select the drop down auto complete item. </p>
<p>Because I used a QSortFilterProxyModel, when using down key to select the item, the index is from the proxy model.</p>
<p>I read in the documentation th... | 2 | 2016-08-31T21:59:40Z | 39,260,260 | <p>paste the correct code here for reference</p>
<pre><code>from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import re
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
class MyModel(QStandardItemModel):
def __init__(self, parent=None):
super(MyModel, self).__init__(parent)
... | 0 | 2016-08-31T22:54:57Z | [
"python",
"autocomplete",
"pyqt",
"qsortfilterproxymodel",
"qcompleter"
] |
Python - Facebook Open Graph API Error: An active access token must be used to query information about the current user | 39,259,687 | <p>I am trying to fetch the details of a facebook page. For ex: <a href="https://graph.facebook.com/rio2016/posts?access-token=xxxxx" rel="nofollow">https://graph.facebook.com/rio2016/posts?access-token=xxxxx</a>. Now I generated a token in graph API explorer. If I use that token in Graph API explorer then I am able to... | 0 | 2016-08-31T22:02:36Z | 39,261,063 | <p>Thank you. Finally I figured out the error in the code. Now I can fetch data with GET requests.</p>
<p>Revised Code:</p>
<pre><code>def fb_crawler():
key = 'xyz'
parameters = {'access_token': key}
r = requests.get('https://graph.facebook.com/rio2016/posts', params = parameters)
result = r.json()
</... | 0 | 2016-09-01T00:38:47Z | [
"python",
"facebook",
"facebook-graph-api"
] |
Multiple print functions in list comprehension | 39,259,743 | <p>The goal of this post is to put multiple print functions throughout a list comprehension to visually understand what's happening within. </p>
<p>Important notes:</p>
<ul>
<li>This <strong>should not</strong> be used for anything other than educational purposes and trying to understand code. </li>
<li>If you are us... | 2 | 2016-08-31T22:07:46Z | 39,259,826 | <p>I think you shouldn't running debug code inside list comprehensions, that said, if you wanted to do so, you could wrap your code inside a function like this:</p>
<pre><code>from __future__ import print_function
def foo(x, y):
print('looping through', x, 'then', y)
if x == y:
print('success', x, y)... | 3 | 2016-08-31T22:15:45Z | [
"python",
"python-2.7",
"python-3.x",
"for-loop",
"list-comprehension"
] |
Multiple print functions in list comprehension | 39,259,743 | <p>The goal of this post is to put multiple print functions throughout a list comprehension to visually understand what's happening within. </p>
<p>Important notes:</p>
<ul>
<li>This <strong>should not</strong> be used for anything other than educational purposes and trying to understand code. </li>
<li>If you are us... | 2 | 2016-08-31T22:07:46Z | 39,259,997 | <p>List comprehension was introduced with <a href="https://www.python.org/dev/peps/pep-0202/" rel="nofollow">PEP 202</a> which states:</p>
<blockquote>
<p>It is proposed to allow conditional construction of list literals
<strong>using for and if clauses.</strong> They would nest in the same way for loops
and if... | 1 | 2016-08-31T22:30:14Z | [
"python",
"python-2.7",
"python-3.x",
"for-loop",
"list-comprehension"
] |
Multiple print functions in list comprehension | 39,259,743 | <p>The goal of this post is to put multiple print functions throughout a list comprehension to visually understand what's happening within. </p>
<p>Important notes:</p>
<ul>
<li>This <strong>should not</strong> be used for anything other than educational purposes and trying to understand code. </li>
<li>If you are us... | 2 | 2016-08-31T22:07:46Z | 39,260,152 | <p>You need to evaluate your <code>print</code> function, but the return value isn't useful since it's always <code>None</code>. You can use <code>and</code>/<code>or</code> to combine it with another expression.</p>
<pre><code>comp = [(x,y) for x in [1,2,3] for y in [3,1,4] if (print('looping through',x,'then',y) or ... | 2 | 2016-08-31T22:45:06Z | [
"python",
"python-2.7",
"python-3.x",
"for-loop",
"list-comprehension"
] |
Regular Expression to match "\\r" | 39,259,751 | <p>I'm having trouble writing a regex that matches these inputs: <br>
1.<code>\\r</code><br>
2.<code>\\rSomeString</code>
<br>
I need a regex that matches <code>\\r</code></p>
| 0 | 2016-08-31T22:08:03Z | 39,259,790 | <p>Escape the back slashes twice. String's interpret <code>\</code> as a special character marker.</p>
<p>Use <code>\\\\r</code> instead. <code>\\</code> is actually interpreted as just <code>\</code>.</p>
<p>EDIT: So as per the comments you want any string that starts with <code>\\r</code> with any string after it. ... | 6 | 2016-08-31T22:12:29Z | [
"python",
"regex"
] |
Regular Expression to match "\\r" | 39,259,751 | <p>I'm having trouble writing a regex that matches these inputs: <br>
1.<code>\\r</code><br>
2.<code>\\rSomeString</code>
<br>
I need a regex that matches <code>\\r</code></p>
| 0 | 2016-08-31T22:08:03Z | 39,260,378 | <p>A literal backslash in Python can be matched with <code>r'\\'</code> (note the use of the raw string literal!). You have two literal backslashes, thus, you need 4 backslashes (in a raw string literal) before <code>r</code>. </p>
<p>Since you may have any characters after <code>\\r</code>, you may use</p>
<pre><cod... | 1 | 2016-08-31T23:09:16Z | [
"python",
"regex"
] |
Regular Expression to match "\\r" | 39,259,751 | <p>I'm having trouble writing a regex that matches these inputs: <br>
1.<code>\\r</code><br>
2.<code>\\rSomeString</code>
<br>
I need a regex that matches <code>\\r</code></p>
| 0 | 2016-08-31T22:08:03Z | 39,273,397 | <p>You can fine-tune your <em>regular expressions</em> on-line, e.g. at <a href="https://regex101.com/#python" rel="nofollow">this site</a>.</p>
| 0 | 2016-09-01T13:52:01Z | [
"python",
"regex"
] |
How do I display thread/process Id in Python PDB? | 39,259,805 | <p>In Python, is there a way to display thread/process ID while debugging using PDB?</p>
<p>I was looking at <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">https://docs.python.org/2/library/pdb.html</a> but could not find anything related to it?</p>
| 1 | 2016-08-31T22:13:57Z | 39,266,060 | <pre><code>(pdb) import os,threading; os.getpid(), threading.current_thread().ident
</code></pre>
<p>If you need to do this often, it would be convenient to add an alias in your <code>.pdbrc</code> file:</p>
<pre><code>alias tid import os,threading;; p os.getpid(), threading.current_thread().ident
</code></pre>
| 1 | 2016-09-01T08:08:54Z | [
"python",
"pdb"
] |
'method' object is not iterable from calling splitlines from a read method | 39,259,819 | <p>Currently trying to setup my setup.py file for pip installation or simply python setup.py develop installation, however when I run the code, it faults saying that the method is not iterable, regarding to my read function.</p>
<p>The code is as follows for setup.py</p>
<pre><code>from setuptools import setup, find_... | -3 | 2016-08-31T22:15:17Z | 39,260,031 | <p>This line is missing the call parens you need:</p>
<pre><code>packages=find_packages,
</code></pre>
<p>Change it to:</p>
<pre><code>packages=find_packages(),
</code></pre>
| 1 | 2016-08-31T22:33:21Z | [
"python",
"django"
] |
How to get "clean" match results in Python | 39,259,830 | <p>I am a total noob, coding for the first time and trying to learn by doing.
I'm using this:</p>
<pre><code>import re
f = open('aaa.txt', 'r')
string=f.read()
c = re.findall(r"Guest last name: (.*)", string)
print "Dear Mr.", c
</code></pre>
<p>that returns </p>
<pre><code>Dear Mr. ['XXXX']
</code></pre>
<p>I was... | 0 | 2016-08-31T22:16:01Z | 39,259,856 | <p>You need to take the first item in the list</p>
<pre><code>print "Dear Mr.", c[0]
</code></pre>
| 0 | 2016-08-31T22:18:29Z | [
"python",
"regex",
"python-2.7",
"match"
] |
How to get "clean" match results in Python | 39,259,830 | <p>I am a total noob, coding for the first time and trying to learn by doing.
I'm using this:</p>
<pre><code>import re
f = open('aaa.txt', 'r')
string=f.read()
c = re.findall(r"Guest last name: (.*)", string)
print "Dear Mr.", c
</code></pre>
<p>that returns </p>
<pre><code>Dear Mr. ['XXXX']
</code></pre>
<p>I was... | 0 | 2016-08-31T22:16:01Z | 39,259,890 | <p>Yes use <code>re.search</code> if you only expect one match:</p>
<pre><code>re.search(r"Guest last name: (.*)", string).group(1)`
</code></pre>
<p>findall is if you expect multiple matches. You probably want to also add <code>?</code> to your regex <code>(.*?)</code> for a non-greedy capture but you also probably ... | 0 | 2016-08-31T22:21:58Z | [
"python",
"regex",
"python-2.7",
"match"
] |
Creating a more consistant, randomly generated, world space for a text-based RPG | 39,259,846 | <p>Currently, I can create a randomized world within a 2-D array. However, I feel it is too random. Here is the class I'm currently working with:</p>
<p><code>from random import randint, choice, randrange</code></p>
<pre><code>class WorldSpace(object):
def __init__(self, row, col, world_array):
self.row =... | 2 | 2016-08-31T22:17:46Z | 39,260,480 | <p>Fixed:</p>
<ol>
<li>Sometimes your <code>a</code> is bigger than your <code>b</code> and forest is not generated.</li>
<li>All your forests tend to be at the left side of map.</li>
</ol>
<p>Inline comments are added for changed lines.</p>
<pre><code>def modify_world(self, autogen):
if autogen is True:
... | 0 | 2016-08-31T23:21:18Z | [
"python",
"arrays",
"python-2.7",
"oop"
] |
Make telnet communication using python | 39,259,858 | <p>It is my first question here :D</p>
<p>I have to send some commands from my personal computer (Linux-Red Hat) to a server (Robot Controller). I saw that the controller have a Ethernet protocol that allows sending commands using telnet communication.</p>
<p>My question: is it possible to make telnet connection, sen... | 0 | 2016-08-31T22:18:33Z | 39,260,021 | <p>In python they have telnetlib, which allows telnet communication. I'm pretty sure that this is what you're looking for. You can find the docs at <a href="https://docs.python.org/2/library/telnetlib.html" rel="nofollow">https://docs.python.org/2/library/telnetlib.html</a> Here is a basic way to logon to a windows ser... | 1 | 2016-08-31T22:32:40Z | [
"python",
"telnet",
"ethernet"
] |
Python language/syntax usage | 39,259,859 | <p>New to python but ran into something I don't understand. The following line of code:</p>
<pre><code>diff = features[0:] - test[0] # <- this is what I don't get
</code></pre>
<p>is used thusly:</p>
<pre><code>x = diff[i]
</code></pre>
<p>to return the element-wise difference between <code>features[i]</cod... | 1 | 2016-08-31T22:18:49Z | 39,259,974 | <p><code>feature</code> appears to be a <a href="http://www.numpy.org/" rel="nofollow">Numpy</a> array. Numpy arrays 'broadcast' scalar operations to the whole array.</p>
<pre><code>import numpy as np
asd = np.full([10,10], 10, np.int64)
asd /= 5
print asd # prints a 10x10 array of 2s
</code></pre>
| 2 | 2016-08-31T22:28:11Z | [
"python"
] |
Python language/syntax usage | 39,259,859 | <p>New to python but ran into something I don't understand. The following line of code:</p>
<pre><code>diff = features[0:] - test[0] # <- this is what I don't get
</code></pre>
<p>is used thusly:</p>
<pre><code>x = diff[i]
</code></pre>
<p>to return the element-wise difference between <code>features[i]</cod... | 1 | 2016-08-31T22:18:49Z | 39,259,984 | <p>the answer depends on what <code>features[0:]</code> and <code>test[0]</code> evaluate to.
if <code>test[0]</code> is a number and <code>features[0:]</code> is a numpy array, then you may be using numpy to subtract a number from each element in a list: </p>
<pre><code>>>> import numpy
>>> array ... | 3 | 2016-08-31T22:29:06Z | [
"python"
] |
cx_Oracle ignores order by clause | 39,259,912 | <p>I've created complex query builder in my project, and during tests stumbled upon strange issue: same query with the same plan produces different results on different clients: cx_Oracle ignores order by clause, while Oracle SQLDeveloper Studio process query correctly, however in both cases order by present in both pl... | 2 | 2016-08-31T22:23:36Z | 39,260,412 | <p>I don't see an <code>ORDER BY</code> clause that would affect the ordering of the results of the query. In SQL, the only way to guarantee the ordering of a result set is to have an <code>ORDER BY</code> clause for the outer-most <code>SELECT</code>.</p>
<p>In almost all cases, an <code>ORDER BY</code> in a subquer... | 4 | 2016-08-31T23:13:16Z | [
"python",
"sql",
"oracle",
"cx-oracle"
] |
Using regex to select html content | 39,259,989 | <p>I have a file with several instances of rows with this structure:</p>
<pre><code><tr>
<td style="width:25%;">
<span class="results_title_text">DUNS:</span> <span class="results_body_text"> 012361296</span>
</td>
... | 0 | 2016-08-31T22:29:24Z | 39,260,413 | <p>Use a positive lookbehind. Since positive look(ahead|behind)s aren't included in the resulting match, they come very handy in parsing stuff at specific locations.</p>
<pre><code>(?<=<span class="results_title_text">\w*DUNS:\w*</span>\w*)<span class="results_body_text">\w*[\u0000-\uFFFF]*\w*<... | 0 | 2016-08-31T23:13:18Z | [
"python",
"html",
"regex",
"data-cleaning"
] |
Using regex to select html content | 39,259,989 | <p>I have a file with several instances of rows with this structure:</p>
<pre><code><tr>
<td style="width:25%;">
<span class="results_title_text">DUNS:</span> <span class="results_body_text"> 012361296</span>
</td>
... | 0 | 2016-08-31T22:29:24Z | 39,265,429 | <p>Using pyparsing to process HTML allows you to gloss over things like unexpected whitespace, extra/missing attributes, tags in upper or lower case. Assuming you have read your HTML source into a variable <code>html</code>, this pyparsing code will extract the target value:</p>
<pre><code>from pyparsing import makeHT... | 0 | 2016-09-01T07:35:12Z | [
"python",
"html",
"regex",
"data-cleaning"
] |
Rename a particular instance in multiple files with the file name? | 39,260,133 | <p>I had to create about 500 copies of a xml file in the directory, which I managed to get done. As a part of the next problem is that I want to rename particular text in the file. How can I go about doing it?</p>
<p>This is what I have:
1000.xml, 1001.xml, 1002.xml...</p>
<p>1000.xml:</p>
<pre><code><?xml versio... | -2 | 2016-08-31T22:43:28Z | 39,260,362 | <p>After deciphering your question I see you want to change actual content in the xml file i.e the id or some other node's text to the name of the file so use an xml parser like <a href="http://lxml.de/" rel="nofollow"><em>lxml</em></a></p>
<pre><code>from glob import iglob
import lxml.etree as et
for fle in iglob("... | 2 | 2016-08-31T23:07:48Z | [
"python",
"bash",
"perl"
] |
Rename a particular instance in multiple files with the file name? | 39,260,133 | <p>I had to create about 500 copies of a xml file in the directory, which I managed to get done. As a part of the next problem is that I want to rename particular text in the file. How can I go about doing it?</p>
<p>This is what I have:
1000.xml, 1001.xml, 1002.xml...</p>
<p>1000.xml:</p>
<pre><code><?xml versio... | -2 | 2016-08-31T22:43:28Z | 39,263,222 | <p>Try your sed command in a loop-</p>
<pre><code>for i in {1000..1500} #or whatever your maximum number is
do
sed -i "s/1000/"$i"/g" "$i".xml
done
</code></pre>
| 1 | 2016-09-01T05:21:37Z | [
"python",
"bash",
"perl"
] |
Rename a particular instance in multiple files with the file name? | 39,260,133 | <p>I had to create about 500 copies of a xml file in the directory, which I managed to get done. As a part of the next problem is that I want to rename particular text in the file. How can I go about doing it?</p>
<p>This is what I have:
1000.xml, 1001.xml, 1002.xml...</p>
<p>1000.xml:</p>
<pre><code><?xml versio... | -2 | 2016-08-31T22:43:28Z | 39,269,104 | <p>You've tagged it <code>perl</code> so here's how I'd do it:</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
#iterate the files.
foreach my $xml_file ( glob "*.xml" ) {
#regex match the number for the XML.
my ( $file_num ) = $xml_file =~ m/(\d+).xml/;
#create an XML::Twig, an... | 3 | 2016-09-01T10:28:53Z | [
"python",
"bash",
"perl"
] |
Adding default parameter that is object to a function that is inside a class | 39,260,134 | <p>I am trying to make a applet for mate-panel in linux . I have to modules <code>Window.py</code> and <code>Applet.py</code>. I get this error: </p>
<pre><code>Traceback (most recent call last):
File "./Applet.py", line 37, in WindowButtonsAppletFactory
WindowButtonsApplet(applet)
File "./Applet.py", line 23, in Wind... | 2 | 2016-08-31T22:43:34Z | 39,261,926 | <p>You're missing the reference to <code>self</code> in:</p>
<pre><code>def win_close(Window,Timestamp=DTimestamp):
Window.close(Timestamp)
</code></pre>
<p>as a result an <code>WindowActions</code> instance is passed which doesn't define a close method and your actual selected window is passed to <code>Timestamp... | 1 | 2016-09-01T02:46:57Z | [
"python",
"python-3.x",
"gtk3",
"pygobject",
"wnck"
] |
Scrapy not executing in the correct order | 39,260,143 | <p>I am currently working on a web-crawler that is supposed to visit a list of websites in a directory, visit the sites' CSS stylesheets, check for an @media tag (a basic way of checking for responsive design, I know there are other corner cases to consider), and print all websites that do not use responsive design to ... | 0 | 2016-08-31T22:44:13Z | 39,266,767 | <p>I skimed through and couldn't help but make this work. This is fully cleaned up code.
Very little has changed in terms of logic.
What it does right now is:</p>
<ol>
<li>Connect to the website</li>
<li>Get all categories</li>
<li>Get all websites from categories</li>
<li>Connect to first page of every website</li>
... | 1 | 2016-09-01T08:45:37Z | [
"python",
"css",
"web",
"scrapy",
"web-crawler"
] |
Allure with Pytest: no decorators for Title and Description | 39,260,159 | <p>I did try to use these decorators in a test, but the compiler have issues because the decorators for both the Title and Description are not recognized.</p>
<p>I did use</p>
<pre><code>@allure.feature("feature1")
@allure.story("story1")
</code></pre>
<p>Without issues, but </p>
<pre><code>@allure.description("tes... | 1 | 2016-08-31T22:45:41Z | 39,268,514 | <p>author of <code>allure-python</code> here.</p>
<p>You are right, there are no such decorators as <code>description</code> or <code>title</code>.
The reason is <code>allure-python</code> collects test title and description from the <code>pytest</code>'s native means -- for bare python tests the are collected from te... | 1 | 2016-09-01T10:02:42Z | [
"python",
"allure"
] |
Flask-WTF: CSRF token missing | 39,260,241 | <p>What seemed like a simple bug - a form submission that won't go through due to a "CSRF token missing" error - has turned into a day of hair pulling. I have gone through every SO article related to Flask or Flask-WTF and missing CSRF tokens, and nothing seems to be helping. </p>
<p>Here are the details:</p>
<p>Fo... | -1 | 2016-08-31T22:52:44Z | 39,262,931 | <p>I figured it out. It appears to be a cookie/session limit (which probably beyond Flask's control) and a silent discarding of session variables when the limit is hit (which seems more like a bug).</p>
<p>Here's an example:</p>
<p><strong>templates/hello.html</strong></p>
<pre><code><p>{{ message|safe }}<... | 1 | 2016-09-01T04:55:45Z | [
"python",
"session",
"flask",
"wtforms",
"flask-wtforms"
] |
Faster RCNN:libcudart.so.7.0: cannot open shared object file: No such file or directory | 39,260,247 | <p>I get the following error when I run the demo from <a href="https://github.com/rbgirshick/py-faster-rcnn/tree/master" rel="nofollow">https://github.com/rbgirshick/py-faster-rcnn/tree/master</a> and all the other steps before demo has been done successfully:</p>
<pre><code>mona@pascal:~/computer_vision/py-faster-rcn... | -1 | 2016-08-31T22:53:05Z | 39,260,794 | <p>While not a neat solution, I ended up changing the paths to use CUDA 7.0. For whatever reason, seems Faster RCNN currently is not compatible with CUDA 7.5 on Ubuntu 14.04. On Ubuntu 15.10 I had it work with CUDA7.5 with the same exact settings!!!!</p>
| 1 | 2016-09-01T00:02:01Z | [
"python",
"cuda",
"shared-libraries",
"caffe",
"cudnn"
] |
Faster RCNN:libcudart.so.7.0: cannot open shared object file: No such file or directory | 39,260,247 | <p>I get the following error when I run the demo from <a href="https://github.com/rbgirshick/py-faster-rcnn/tree/master" rel="nofollow">https://github.com/rbgirshick/py-faster-rcnn/tree/master</a> and all the other steps before demo has been done successfully:</p>
<pre><code>mona@pascal:~/computer_vision/py-faster-rcn... | -1 | 2016-08-31T22:53:05Z | 39,290,077 | <p>Try This: Worked for me.</p>
<pre><code>export LD_LIBRARY_PATH=/usr/local/cuda/lib64/
</code></pre>
| 0 | 2016-09-02T10:22:12Z | [
"python",
"cuda",
"shared-libraries",
"caffe",
"cudnn"
] |
getting http debug info | 39,260,276 | <p>I'm going through Dive into Python3. When I get to the chapter on http web services section 14.4, I can't seem to duplicate the following output in the python3 shell. Here's what the sample code looks like:</p>
<pre><code>from http.client import HTTPConnection
HTTPConnection.debuglevel = 1
from urllib.request imp... | 1 | 2016-08-31T22:55:56Z | 39,260,376 | <p>The final command should not give any output, what you probably want is:</p>
<pre><code>print(response.read())
</code></pre>
<p>Further, as I wrote in the comments above:
urllib got deprecated in Python3, you should use urllib2, see: docs.python.org/2/library/urllib.html </p>
| 1 | 2016-08-31T23:09:11Z | [
"python",
"python-3.x",
"urllib",
"http.client"
] |
Inspecting Python Objects | 39,260,407 | <p>I am looking at a code given to me by a co-worker who no longer works with us.</p>
<p>I have a list variable called rx.</p>
<pre><code>>> type(rx)
type 'list'
</code></pre>
<p>When I go to look inside rx[0] I get this:</p>
<pre><code>>> rx[0]
<Thing.thing.stuff.Rx object at 0x10e1e1c10>
</cod... | -2 | 2016-08-31T23:12:41Z | 39,260,637 | <p>Start with <a href="https://docs.python.org/3/library/functions.html#help" rel="nofollow">help</a>: <code>help(rx[0])</code></p>
<pre><code># example python object
class Employee:
"""Common base class for all employees."""
empCount = 0
help(Employee)
</code></pre>
<p>Output:</p>
<pre><code>Help on class... | 0 | 2016-08-31T23:42:39Z | [
"python",
"object",
"indexing"
] |
Input to a three dimensional array in python | 39,260,427 | <p>I'm new at coding in python and I was wondering if there is some way I can transcript this code in C to python:</p>
<pre><code>for (K=1; K<3; K++)
for (I=0; I<3; I++)
for (J=0; J<7; J++){
printf("Year: %d\tProvince: %d\tMonth: %d: ", K, I, J);
scanf("%f", &A[I][J][K]... | 0 | 2016-08-31T23:15:14Z | 39,261,012 | <p>you could use numpy. example assuming you want float64s. change types add needed </p>
<pre><code>import numpy as np
arr = np.empty([2, 2, 6], np.float64)
for k in range(2):
for i in range(2):
for j in range(6):
print("Year: " + str(k) + " Province: " + str(i) + " Month: " + str(j) + ": ")
... | 0 | 2016-09-01T00:31:29Z | [
"python",
"c",
"arrays",
"input"
] |
Input to a three dimensional array in python | 39,260,427 | <p>I'm new at coding in python and I was wondering if there is some way I can transcript this code in C to python:</p>
<pre><code>for (K=1; K<3; K++)
for (I=0; I<3; I++)
for (J=0; J<7; J++){
printf("Year: %d\tProvince: %d\tMonth: %d: ", K, I, J);
scanf("%f", &A[I][J][K]... | 0 | 2016-08-31T23:15:14Z | 39,281,712 | <p>If you want to do that in just standard, native python this should work:</p>
<pre><code>import pprint # To display "3d array" in a recognizable format
A = [[[0 for _ in range(2)] for _ in range(2)] for _ in range(6)]
for k in range(2):
for i in range(2):
for j in range(6):
print("Year: {0}... | 0 | 2016-09-01T22:18:28Z | [
"python",
"c",
"arrays",
"input"
] |
Check if a string contains all words of another string in the same order python? | 39,260,436 | <p>I want to check if a string contains all of the substring's words and retains their order; at the moment I am using the following code; However it is very basic, seems inefficient and likely there is a much better way of doing it. I'd really appreciate if you could tell me what a more efficient solution would be. So... | 0 | 2016-08-31T23:16:04Z | 39,260,527 | <p>if you just want to check whether there is a word contain in other string, no need to check all. You just need to find one and return true.<br>
when you check the item set is faster O(1)(average)</p>
<pre><code>a = "I believe that the biggest castle in the world is Prague Castle "
b = "the biggest castle"
def chec... | -1 | 2016-08-31T23:27:49Z | [
"python",
"string",
"python-2.7",
"substring"
] |
Check if a string contains all words of another string in the same order python? | 39,260,436 | <p>I want to check if a string contains all of the substring's words and retains their order; at the moment I am using the following code; However it is very basic, seems inefficient and likely there is a much better way of doing it. I'd really appreciate if you could tell me what a more efficient solution would be. So... | 0 | 2016-08-31T23:16:04Z | 39,260,537 | <p>Let's define your <code>a</code> string and reformat your <code>b</code> string into a regex:</p>
<pre><code>>>> a = "I believe that the biggest castle in the world is Prague Castle "
>>> b = r'\b' + r'\b.*\b'.join(re.escape(word) for word in "the biggest castle".split(' ')) + r'\b'
</code></pre>
... | 1 | 2016-08-31T23:28:58Z | [
"python",
"string",
"python-2.7",
"substring"
] |
Check if a string contains all words of another string in the same order python? | 39,260,436 | <p>I want to check if a string contains all of the substring's words and retains their order; at the moment I am using the following code; However it is very basic, seems inefficient and likely there is a much better way of doing it. I'd really appreciate if you could tell me what a more efficient solution would be. So... | 0 | 2016-08-31T23:16:04Z | 39,260,663 | <p>You can simplify your search by passing the index of the previous match + 1 to <em>find</em>, you don't need to slice anything:</p>
<pre><code>def check(main, sub_split):
ind = -1
for word in sub_split:
ind = main.find(word, ind+1)
if ind == -1:
return False
return True
a = ... | 2 | 2016-08-31T23:45:42Z | [
"python",
"string",
"python-2.7",
"substring"
] |
How to pass data to scrapinghub? | 39,260,455 | <p>I'm trying to run a scrapy spider on scrapinghub, and I want to pass in some data. I'm using their API to run the spider:</p>
<p><a href="http://doc.scrapinghub.com/api/jobs.html#jobs-run-json" rel="nofollow">http://doc.scrapinghub.com/api/jobs.html#jobs-run-json</a></p>
<p>They have an option for <code>job_settin... | 1 | 2016-08-31T23:18:42Z | 39,261,783 | <p>This <code>job_settings</code> shall be merged directly into the <a href="http://doc.scrapy.org/en/latest/topics/settings.html" rel="nofollow">Scrapy settings</a>, with a higher precedence (of <code>40</code>, IIRC).</p>
<p>The Scrapy settings could be accessed via a <code>.settings</code> attribute of a spider ins... | 3 | 2016-09-01T02:25:31Z | [
"python",
"scrapy",
"scrapinghub"
] |
AttributeError: 'ErrorbarContainer' object has no attribute 'set_ylim' | 39,260,561 | <p>I am plotting the results of some experiments with error bars. I'd like to be able to set the y limit in the case of results with extreme outliers that aren't interesting. This code:</p>
<pre><code>axes = plt.errorbar(feature_data[feature_data.num_unique[feature_of_interest] > 1].index, chi_square_y, yerr=chi_sq... | -1 | 2016-08-31T23:32:10Z | 39,309,727 | <p>Simply use the <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.ylim" rel="nofollow">matplotlib.pyplot.ylim()</a> function.</p>
<p>Your example is not self-contained, so I cannot check that the below code actually works, but at least the mentioned error will be fixed:</p>
<pre><code>plt.errorba... | 3 | 2016-09-03T17:47:24Z | [
"python",
"matplotlib"
] |
AttributeError: 'ErrorbarContainer' object has no attribute 'set_ylim' | 39,260,561 | <p>I am plotting the results of some experiments with error bars. I'd like to be able to set the y limit in the case of results with extreme outliers that aren't interesting. This code:</p>
<pre><code>axes = plt.errorbar(feature_data[feature_data.num_unique[feature_of_interest] > 1].index, chi_square_y, yerr=chi_sq... | -1 | 2016-08-31T23:32:10Z | 39,346,791 | <p>Since this is a bounty question I'll try to get a bit into more detail here. </p>
<p><code>plt.errorbar</code> does not return an Axes object (which has the <code>set_ylim</code> method), but rather a collection of <code>(plotline, caplines, barlinecols)</code>. I suspect you may have expected the Axes object since... | 1 | 2016-09-06T10:29:54Z | [
"python",
"matplotlib"
] |
Generate a normal distribution of dates within a range | 39,260,616 | <p>I have a date range - say between <code>1925-01-01</code> and <code>1992-01-01</code>. I'd like to generate a list of <code>x</code> dates between that range, and have those <code>x</code> dates generated follow a 'normal' (bell curve - see image) distribution.</p>
<p>There are many many answers on stackoverflow ab... | 0 | 2016-08-31T23:39:35Z | 39,262,071 | <p>As per @sascha's comment, a conversion from the dates to a time value does the job:</p>
<pre><code>#!/usr/bin/env python3
import time
import numpy
_DATE_RANGE = ('1925-01-01', '1992-01-01')
_DATE_FORMAT = '%Y-%m-%d'
_EMPIRICAL_SCALE_RATIO = 0.15
_DISTRIBUTION_SIZE = 1000
def main():
time_range = tuple(time.m... | 1 | 2016-09-01T03:05:37Z | [
"python",
"date",
"numpy",
"gaussian",
"normal-distribution"
] |
Is there a way to apply decorators to Python data structures? | 39,260,619 | <p>From what I got so far, decorators applies to callables(functions and classes).
Wondering if there is a way to apply a decorator to a dictionary?(It can be any data structure, in fact).
The problem I try to solve goes along the following lines:
I have a lot of dictionaries which, from time to time, might be valid or... | 1 | 2016-08-31T23:40:04Z | 39,260,668 | <p>Decorators, to my knowledge, can only be applied to callables (functions, classes etc.)</p>
<p>If I was in your place, I'd probably separate the logic to decide between valid/invalid in its own function.</p>
| 0 | 2016-08-31T23:46:22Z | [
"python"
] |
Is there a way to apply decorators to Python data structures? | 39,260,619 | <p>From what I got so far, decorators applies to callables(functions and classes).
Wondering if there is a way to apply a decorator to a dictionary?(It can be any data structure, in fact).
The problem I try to solve goes along the following lines:
I have a lot of dictionaries which, from time to time, might be valid or... | 1 | 2016-08-31T23:40:04Z | 39,261,880 | <p>you could cobble something together with properties and decorators:</p>
<pre><code>def valid(func):
return property(lambda self: func(self))
def invalid(func):
return property(lambda self: False)
class A:
@valid
def dict1(self):
return dict(a=4, b=5)
@invalid
def dict2(self):
... | 0 | 2016-09-01T02:39:09Z | [
"python"
] |
Python: Is it possible to skip values in tuple assignment? | 39,260,653 | <p>I have a function which splits string in two parts at first encountered colon (skipping parts enclosed in brackets). This function returns tuple of three elements: index where the colon was encountered, part before colon and part after colon:</p>
<pre><code>def split_on_colon(str):
colon_ptr = find_separator(st... | 0 | 2016-08-31T23:44:54Z | 39,260,685 | <p>You can use the <code>_</code>, which is used to store unwanted values. Your statement will look like this:</p>
<pre><code>_, func, args = split
</code></pre>
| 1 | 2016-08-31T23:48:49Z | [
"python"
] |
Python: Is it possible to skip values in tuple assignment? | 39,260,653 | <p>I have a function which splits string in two parts at first encountered colon (skipping parts enclosed in brackets). This function returns tuple of three elements: index where the colon was encountered, part before colon and part after colon:</p>
<pre><code>def split_on_colon(str):
colon_ptr = find_separator(st... | 0 | 2016-08-31T23:44:54Z | 39,260,742 | <p>The best way for refusing of consuming extra memory is to handle this within your function. You can use a flag as an argument for your function then based on this flag you can decide to return 2 or 3 items.</p>
<pre><code>def split_on_colon(my_str, flag):
colon_ptr = find_separator(my_str, 0, ':')
if flag:
... | 2 | 2016-08-31T23:54:36Z | [
"python"
] |
Why am I unable to join this thread in python? | 39,260,728 | <p>I am writing a multithreading class. The class has a <code>parallel_process()</code> function that is overridden with the parallel task. The data to be processed is put in the <code>queue</code>. The <code>worker()</code> function in each thread keeps calling <code>parallel_process()</code> until the <code>queue</co... | 3 | 2016-08-31T23:52:46Z | 39,260,844 | <p>This statement may lead to errors:</p>
<pre><code>while not self.queue.empty():
pkg = self.queue.get()
</code></pre>
<p>With multiple threads pulling items from the queue, there's no guarantee that <code>self.queue.get()</code> will return a valid item, even if you check if the queue is empty beforehand. Here ... | 2 | 2016-09-01T00:08:35Z | [
"python",
"multithreading"
] |
Why am I unable to join this thread in python? | 39,260,728 | <p>I am writing a multithreading class. The class has a <code>parallel_process()</code> function that is overridden with the parallel task. The data to be processed is put in the <code>queue</code>. The <code>worker()</code> function in each thread keeps calling <code>parallel_process()</code> until the <code>queue</co... | 3 | 2016-08-31T23:52:46Z | 39,260,919 | <p>@Brendan Abel identified the cause. I'd like to suggest a different solution: <code>queue.join()</code> is usually a Bad Idea too. Instead, create a unique value to use as a sentinel:</p>
<pre><code>class Parallel:
_sentinel = object()
</code></pre>
<p>At the end of <code>__init__()</code>, add one sentinel... | 2 | 2016-09-01T00:18:37Z | [
"python",
"multithreading"
] |
Web2py comparing part of a request.vars element | 39,260,734 | <p>I have a form with a table with rows containing SELECTs with _names with IDs attached, like this:</p>
<pre><code>TD_list.append(TD(SELECT(lesson_reg_list, _name='lesson_reg_' + str(student[4]))))
</code></pre>
<p>When the form is submitted I want to extract both the student[4] value <em>and</em> the value held by ... | 0 | 2016-08-31T23:53:35Z | 39,295,714 | <p>In Python, when slicing, the ending index is <em>excluded</em>, so your two slices should be <code>0:10</code> and <code>0:11</code>. To simplify, you can also use <code>.startswith</code> for the first one:</p>
<pre><code>for item in request.vars:
if item.startswith('lesson_reg'):
enrolment_id = int(it... | 0 | 2016-09-02T15:14:35Z | [
"python",
"variables",
"request",
"substring",
"web2py"
] |
Is Spark's KMeans unable to handle bigdata? | 39,260,820 | <p>KMeans has several parameters for its <a href="http://spark.apache.org/docs/latest/api/python/pyspark.mllib.html?highlight=kmeans#pyspark.mllib.clustering.KMeans.train" rel="nofollow">training</a>, with initialization mode is defaulted to kmeans||. The problem is that it marches quickly (less than 10min) to the firs... | 5 | 2016-09-01T00:05:51Z | 39,304,813 | <p>I think the 'hanging' is because your executors keep dying. As I mentioned in a side conversation, this code runs fine for me, locally and on a cluster, in Pyspark and Scala. However, it takes a lot longer than it should. It is almost all time spent in k-means|| initialization.</p>
<p>I opened <a href="https://issu... | 3 | 2016-09-03T08:20:45Z | [
"python",
"apache-spark",
"bigdata",
"k-means",
"apache-spark-mllib"
] |
Alembic not handling column_types.PasswordType : Flask+SQLAlchemy+Alembic | 39,260,850 | <p><strong>Background</strong></p>
<p>I'm trying to use a PostgreSQL back-end instead of Sqlite in this <a href="https://github.com/frol/flask-restplus-server-example" rel="nofollow">Flask + RESTplus server example</a>.</p>
<p>I faced an issue with the PasswordType db column type. In order to make it work, I had to c... | 2 | 2016-09-01T00:09:32Z | 39,276,707 | <p>I see that you are having a new migration <code>99b329343a41_.py</code> (it doesn't exist in my Flask-RESTplus-example-server). Please, review your new migration and <strong>remove</strong> everything related to PasswordType. It is a bug in SQLAlchemy-Utils, which doesn't play nice with Alembic: <a href="https://git... | 1 | 2016-09-01T16:35:39Z | [
"python",
"postgresql",
"flask-sqlalchemy",
"alembic",
"passlib"
] |
Using Pandas dataframes to write to complex format layout | 39,260,884 | <p>I am trying to create a file which has a very specific format, which means it is very difficult for me to operate and save with pandas alone.</p>
<p>Consider this:</p>
<pre><code>FILE = open('writeFileTest' + ".trc", "w")
# Print header information
FILE.write('A\tB\tC\n')
FILE.write('\t\tD\tE\tF\tG\n')
</code></p... | 1 | 2016-09-01T00:14:05Z | 39,261,339 | <p>You could open the file, write the header manually and then dump the data frame. Try this:</p>
<pre><code>import pandas as pd
import numpy as np
data = np.random.randint(0,10, (4,6))
df = pd.DataFrame(data, columns=list('abcdef'))
header1 = 'A\tB\tC\t\t\t\n'
header2 = '\t\tD\tE\tF\tG\n'
with open('./out.tsv','w... | 2 | 2016-09-01T01:21:39Z | [
"python",
"pandas"
] |
Python3 failing big division? | 39,260,903 | <p>Straight to the point...</p>
<p>By using a website like <a href="http://www.javascripter.net/math/calculators/100digitbigintcalculator.htm" rel="nofollow">this</a></p>
<p>I can perform the division</p>
<pre><code>52186717924906310443177153231901480277334060673504069433827878535462769136594116478314105387030290844... | -3 | 2016-09-01T00:16:35Z | 39,260,942 | <pre><code> Python 3.4.4 |Continuum Analytics, Inc.| (default, Feb 16 2016, 09:54:04) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
>>> a = 521867179249063104431771532319014802773340606735040694338278785354627691365941164783141053870302908448... | 4 | 2016-09-01T00:21:31Z | [
"python"
] |
Serializers and ViewSets inheritance of PostgreSQL multitable models? | 39,260,904 | <p>My environment is based on Django 1.10 & PostgreSQL 9.5 and;</p>
<p>I have a childtable which inherits from a parenttable. For each, I have a Django model class, ChildModel and ParentModel respectively:</p>
<pre><code>class ParentModel(models.Model):
id = models.AutoField(primary_key=True)
owner = mod... | 0 | 2016-09-01T00:16:46Z | 39,263,694 | <p>It isn't inheritance, but you can do this like:</p>
<pre><code>class ChildModelSerializer(ParentModelSerializer):
class Meta:
model = ChildModel
fields = ParentModelSerializer.Meta.fields + ['name', 'abbreviation']
</code></pre>
<p>That's how I do it.</p>
| 0 | 2016-09-01T05:59:17Z | [
"python",
"django",
"postgresql",
"django-models",
"django-rest-framework"
] |
Adding a check list and remove from list in Python | 39,260,914 | <p>So the instruction for the assignment is this</p>
<blockquote>
<p>Print a simple set of instructions which will offer users a choice of
keys to open a door.</p>
</blockquote>
<p>So the goals that I think will accomplish this is.</p>
<blockquote>
<p>make an inventory [rainbow keys]</p>
<p>print the inve... | -1 | 2016-09-01T00:17:47Z | 39,260,970 | <p>Without having more information about your error checking, I can't be sure I'm solving the problem. However, I would think that you want to maintain a simple list of keys, such as:</p>
<pre><code>door_key_inv = ["red", "yellow", "paisley-print chartreuse"]
</code></pre>
<p>You start the list as <strong>[]</strong... | 0 | 2016-09-01T00:25:52Z | [
"python",
"list",
"python-2.7"
] |
Adding a check list and remove from list in Python | 39,260,914 | <p>So the instruction for the assignment is this</p>
<blockquote>
<p>Print a simple set of instructions which will offer users a choice of
keys to open a door.</p>
</blockquote>
<p>So the goals that I think will accomplish this is.</p>
<blockquote>
<p>make an inventory [rainbow keys]</p>
<p>print the inve... | -1 | 2016-09-01T00:17:47Z | 39,261,013 | <p>You're super close. You can just initialize an empty list to store the inventory. When someone guesses a key you just append it to the list. Of course we will check to see if the guessed key is already in the inventory, and if it is, we won't add it.</p>
<pre><code>keepGuess = True
correctKey = "red"
inventory = [... | 0 | 2016-09-01T00:31:37Z | [
"python",
"list",
"python-2.7"
] |
download stock price history from yahoo finance with python 3.5 | 39,260,918 | <p>I am currently seeking a way to load multiple years of stock price history from yahoo finance. I will have a 100+ ticker symbols and I will be downloading data from 1985 to current date. I want the Open, High, Low, Close, Adj Close, Volume loaded into individual DataFrames (pandas) with name of the data frame named ... | 0 | 2016-09-01T00:18:32Z | 39,261,236 | <p>You can use the <code>pandas_datareader</code> module to download the data that you want if it is available on yahoo. You can <code>pip install</code> it or install it any other way you prefer.</p>
<p>The following is a sample script that gets the data for a small list of symbols:</p>
<pre><code>from pandas_datare... | 3 | 2016-09-01T01:05:38Z | [
"python"
] |
Opening file in python using open() using "/" or r'filepath' gives error | 39,261,134 | <p>All I'm trying to is open a file to read</p>
<pre><code>file1 = open (r"C:\Users\Javier\Downloads\BodyFat.txt", "r" )
</code></pre>
<p>I get the error message:</p>
<pre><code>OSError: [Errno 22] Invalid argument: '
\u202aC:\\Users\\Javier\\Downloads\\BodyFat.txt'
</code... | -1 | 2016-09-01T00:51:12Z | 39,261,253 | <p>Replace </p>
<pre><code>file1 = open ("C:/Users/Javier/Downloads/BodyFat.txt", "r" )
</code></pre>
<p>with</p>
<pre><code>file1 = open ("/Users/Javier/Downloads/BodyFat.txt", "r" )
</code></pre>
<p>Python is looking for a directory, and <code>C:</code> is not being recognized as one.</p>
| -1 | 2016-09-01T01:07:40Z | [
"python",
"file"
] |
How can tkinter open with file directory of specific folder (also containing .py script) on any system? | 39,261,178 | <p>In other words if I pass off the folder to someone containing a .txt and .py, and the script is run on their machine from this folder, how can I ensure the file dialog will open with this folder to select the .txt without knowing the absolute path? Referring to <code>initialdir=</code>??</p>
<pre><code>from tkinter... | 0 | 2016-09-01T00:57:51Z | 39,270,250 | <p>You should use the <code>os</code> module and <code>os.getcwd()</code> to find the current working directory of the .py file</p>
<pre><code>import os
from tkinter import filedialog
import tkinter as tk
root = tk.Tk()
root.withdraw()
root.filename = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select f... | 0 | 2016-09-01T11:24:32Z | [
"python",
"tkinter"
] |
Ensure list of dicts has a dict with key for each key in list | 39,261,233 | <p>Context:
I'm using an Ajax call to return some complex JSON from a python module. I have to use a list of keys and confirm that a list of single-item dicts contains a dict with each key.</p>
<p>Example:</p>
<pre><code>mylist=['this', 'that', 'these', 'those']
mydictlist=[{'this':1},{'that':2},{'these':3}]
</code>... | 0 | 2016-09-01T01:05:29Z | 39,261,307 | <p>The most straightforward way is to iterate over both the containers and check:</p>
<pre><code>for key in mylist:
if not any(key in dic for dic in mydictlist):
print key, "missing"
</code></pre>
<p>However, if you have a lot of keys and/or dictionaries, this is not going to be efficient: it iterates ove... | 0 | 2016-09-01T01:16:19Z | [
"python"
] |
Ensure list of dicts has a dict with key for each key in list | 39,261,233 | <p>Context:
I'm using an Ajax call to return some complex JSON from a python module. I have to use a list of keys and confirm that a list of single-item dicts contains a dict with each key.</p>
<p>Example:</p>
<pre><code>mylist=['this', 'that', 'these', 'those']
mydictlist=[{'this':1},{'that':2},{'these':3}]
</code>... | 0 | 2016-09-01T01:05:29Z | 39,261,309 | <p>Simple code is to convert your search list to a set, then use differencing to determine what you're missing:</p>
<pre><code>missing = set(mylist).difference(*mydictlist)
</code></pre>
<p>which gets you <code>missing</code> of <code>{'those'}</code>.</p>
<p>Since the named <code>set</code> methods can take multipl... | 2 | 2016-09-01T01:16:47Z | [
"python"
] |
Ensure list of dicts has a dict with key for each key in list | 39,261,233 | <p>Context:
I'm using an Ajax call to return some complex JSON from a python module. I have to use a list of keys and confirm that a list of single-item dicts contains a dict with each key.</p>
<p>Example:</p>
<pre><code>mylist=['this', 'that', 'these', 'those']
mydictlist=[{'this':1},{'that':2},{'these':3}]
</code>... | 0 | 2016-09-01T01:05:29Z | 39,281,164 | <p>The pandas package is a great way to handle list of dicts problems. It takes all the keys and makes them column headers, values with similar keys populate the same column.</p>
<p>Check this out:</p>
<pre><code>import pandas as pd
mydictlist=[{'this':1},{'that':2},{'these':3}]
# Convert data to a DataFrame
df = p... | 0 | 2016-09-01T21:31:08Z | [
"python"
] |
Flask session variable not persisting between requests | 39,261,260 | <p>Using the app below and Flask 0.11.1, I navigated to the routes associated with the following function calls, with the given results: </p>
<ul>
<li>create(): '1,2,3' # OK</li>
<li>remove(1) : '2,3' # OK</li>
<li>remove(2) : '1,3' # expected '3'</li>
<li>maintain(): '1,2,3' # expected '1,3' or '3'</li>
<... | 0 | 2016-09-01T01:08:36Z | 39,261,335 | <p>Flask uses a <a href="https://github.com/wklken/pyutils/blob/master/dict/CallbackDict.py" rel="nofollow">CallbackDict</a> to track modifications to sessions.</p>
<p>It will only register modifications when you set or delete a key. Here, you modify the values in place, which it will not detect. Try this:</p>
<pre><... | 0 | 2016-09-01T01:21:01Z | [
"python",
"session",
"flask"
] |
Flask session variable not persisting between requests | 39,261,260 | <p>Using the app below and Flask 0.11.1, I navigated to the routes associated with the following function calls, with the given results: </p>
<ul>
<li>create(): '1,2,3' # OK</li>
<li>remove(1) : '2,3' # OK</li>
<li>remove(2) : '1,3' # expected '3'</li>
<li>maintain(): '1,2,3' # expected '1,3' or '3'</li>
<... | 0 | 2016-09-01T01:08:36Z | 39,261,342 | <p>From <a href="http://flask.pocoo.org/docs/0.11/api/#flask.session.modified" rel="nofollow">the doc</a>:</p>
<blockquote>
<p>Be advised that modifications on mutable structures are not picked up automatically, in that situation you have to explicitly set the [<code>modified</code> attribute] to <code>True</code> y... | 0 | 2016-09-01T01:21:47Z | [
"python",
"session",
"flask"
] |
Unable to run a basic GraphFrames example | 39,261,370 | <p>Trying to run a simple GraphFrame example using pyspark.</p>
<p>spark version : 2.0</p>
<p>graphframe version : 0.2.0</p>
<p>I am able to import graphframes in Jupyter:</p>
<pre><code>from graphframes import GraphFrame
GraphFrame
graphframes.graphframe.GraphFrame
</code></pre>
<p>I get this error when I try and... | 1 | 2016-09-01T01:25:36Z | 39,262,445 | <p>Make sure that your PYSPARK_SUBMIT_ARGS is updated to have "--packages graphframes:graphframes:0.2.0-spark2.0" in your kernel.json ~/.ipython/kernels//kernel.json.</p>
<p>You probably already looked at the following <a href="https://developer.ibm.com/clouddataservices/2016/07/15/intro-to-apache-spark-graphframes/" ... | 0 | 2016-09-01T03:52:25Z | [
"python",
"apache-spark",
"pyspark",
"jupyter",
"graphframes"
] |
Count the number of objects OpenCV - Python | 39,261,378 | <p>This is my first project in Python(3.5.1) and OpenCV (3), so I'm sorry for my mistakes.
I've some pictures like these ones:
<a href="https://s12.postimg.org/ox8gw5l8d/gado.jpg" rel="nofollow">https://s12.postimg.org/ox8gw5l8d/gado.jpg</a></p>
<p>I need to count how many white objects has on this image. I tried to i... | 0 | 2016-09-01T01:26:32Z | 39,263,052 | <p>Probably you will end up in wrong count if you continue working on this image. Perform some pre-processing operations such as morphological operations to remove noise and also to separate the object from each other. After this make use of "findcontours" an inbuilt opencv function. Then read the size of "findcontours... | 2 | 2016-09-01T05:06:49Z | [
"python",
"opencv"
] |
Count the number of objects OpenCV - Python | 39,261,378 | <p>This is my first project in Python(3.5.1) and OpenCV (3), so I'm sorry for my mistakes.
I've some pictures like these ones:
<a href="https://s12.postimg.org/ox8gw5l8d/gado.jpg" rel="nofollow">https://s12.postimg.org/ox8gw5l8d/gado.jpg</a></p>
<p>I need to count how many white objects has on this image. I tried to i... | 0 | 2016-09-01T01:26:32Z | 39,273,744 | <p>I'm getting very close to the answer, I believe I just need to change some parameters according to the image.
If someone needs something on this regard, this is my code:</p>
<pre><code># Standard imports
import cv2
import numpy as np;
# Read image
im = cv2.imread("C:/opencvTests/original.jpg", cv2.IMREAD_GRAYSCALE... | 0 | 2016-09-01T14:06:53Z | [
"python",
"opencv"
] |
How to wait until all threads are ready before start them | 39,261,387 | <p>I have this working script:</p>
<pre><code>import socket, threading
def loop():
global threads
get_host = "GET " + url + " HTTP/1.1\r\nHost: " + url + "\r\n"
accept = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, de... | 0 | 2016-09-01T01:27:57Z | 39,262,113 | <p>Maybe you need some notification mechanics. I think you should try event object like below snippet: </p>
<pre><code>import threading
import time
event=threading.Event()
def main_thread():
time.sleep(10)
event.set() # notify, enable worker thread run
def worker_thread():
event.wait()
print threadi... | 0 | 2016-09-01T03:10:29Z | [
"python",
"multithreading",
"python-3.x"
] |
Writing to a file doesn't work if pywinauto throw an exception | 39,261,482 | <p>I'm new in Python so can not definitely say where the problem is: in PyWinAuto or in my knowledge of Python.</p>
<p>I run the next script Windows (Python 3.5.2):</p>
<pre><code>#!/usr/bin/env python3
import os
import sys
import pywinauto
def testLicenseForm():
app = pywinauto.Application().Start('Calc.exe')
... | 0 | 2016-09-01T01:42:25Z | 39,265,616 | <p><code>f.write</code> doesn't guarantee writing the data until you close the file (<code>f.close()</code>) or do <code>f.flush()</code>. But I'd recommend you the following way:</p>
<pre><code>with open('R:\Temp\diagnostic\log.errors', 'w') as f:
f.write('Exception raised')
</code></pre>
<p>This context manager... | 0 | 2016-09-01T07:45:32Z | [
"python",
"windows",
"fwrite",
"pywinauto"
] |
Emulating namespaces in Python | 39,261,496 | <p>I understand that Python has what it calls "namespaces", but I'm looking to write some code along the lines of <code>security.crypto.hash.md5("b")</code> and such. JavaScript doesn't have namespaces, but their behavior can be replicated using object notation:</p>
<pre><code>var stdlib = {
math: {
consta... | 1 | 2016-09-01T01:43:48Z | 39,261,591 | <p>If all you're after is the dot notation, you can always create classes? See <a href="http://stackoverflow.com/questions/3576596/is-it-a-good-idea-to-using-class-as-a-namespace-in-python">Is it a good idea to using class as a namespace in Python</a>.</p>
| 1 | 2016-09-01T01:58:29Z | [
"python",
"namespaces"
] |
Webbrowser() reading through a text file for URLS | 39,261,609 | <p>I am trying to write a script to automate browsing to my most commonly visited websites. I have put the websites into a list and am trying to open it using the <code>webbrowser()</code> module in Python. My code looks like the following at the moment:</p>
<pre><code>import webbrowser ... | 0 | 2016-09-01T02:00:17Z | 39,261,692 | <p>You have two main problems. </p>
<p>The first problem you have is that you are using <code>readline</code> and not <code>readlines</code>. <code>readline</code> will give you the first line in the file, while <code>readlines</code> gives you a list of your file contents. </p>
<p>Take this file as an example: </p>
... | 1 | 2016-09-01T02:13:00Z | [
"python",
"python-2.7",
"python-webbrowser"
] |
Webbrowser() reading through a text file for URLS | 39,261,609 | <p>I am trying to write a script to automate browsing to my most commonly visited websites. I have put the websites into a list and am trying to open it using the <code>webbrowser()</code> module in Python. My code looks like the following at the moment:</p>
<pre><code>import webbrowser ... | 0 | 2016-09-01T02:00:17Z | 39,261,698 | <p>You're not reading the file properly. You're only reading the first line. Also, assuming you were reading the file properly, you're still trying to open <code>list</code>, which is incorrect. You should be trying to open <code>line</code>.</p>
<p>This should work for you:</p>
<pre><code>import webbrowser
with ope... | 0 | 2016-09-01T02:13:53Z | [
"python",
"python-2.7",
"python-webbrowser"
] |
Uninstall Python 3.5.2 from Redhat Linux | 39,261,624 | <p>Linux is already preinstalled with Python 2.7, however I installed Python 3.5.2 thinking that I need it but actually I don't. So I want to safely and completely remove it from the system, how can I do it? </p>
<p>I previously installed Python 3.5.2 using the commands below</p>
<pre><code>wget https://www.python.or... | 0 | 2016-09-01T02:02:49Z | 39,261,660 | <p>There should be <code>uninstall</code> script but python really does not have it. If you didn't change any options from the firstplace( i mean config and make) you can do this one </p>
<p>//<em>be careful with</em> <strong>-rf</strong>//</p>
<pre><code>sudo rm -rf /usr/local/bin/python3* /usr/local/bin/pydoc3 /usr... | 0 | 2016-09-01T02:08:17Z | [
"python",
"linux",
"redhat",
"uninstall",
"package-management"
] |
Yield both items and callback request in scrapy | 39,261,636 | <p>Disclaimer: I'm pretty new to both Python and Scrapy.</p>
<p>I'm trying to get my spider to gather urls from the start url, follow those gathered urls and both:</p>
<ol>
<li>scrape the next page for specific items (and eventually return them)</li>
<li>gather more specific urls from the next page and follow these u... | 3 | 2016-09-01T02:04:49Z | 39,267,248 | <p>There are 2 levels of your problem.<br></p>
<p><strong>1.</strong> Bio url is not available with JS disabled. Turn off JS in your browser and check this page:
<a href="https://votesmart.org/candidate/126288/derek-stanford" rel="nofollow">https://votesmart.org/candidate/126288/derek-stanford</a></p>
<p>You should s... | 1 | 2016-09-01T09:06:48Z | [
"python",
"callback",
"scrapy"
] |
wxpython toolbar not shown in os x | 39,261,653 | <p>I have a python script for GUI using wxpython. It works perfectly fine in Windows, however, when I run the script in OS X, the toolbar is now shown (I installed wxpython from its official website and used the cocoa version, and I am using OS X 10.10 and python 2.7). Following is the part of the code regarding the to... | 1 | 2016-09-01T02:07:22Z | 39,277,524 | <p>What is <code>self</code> in this code? Toolbars are a little different on OSX, and and can be a bit tricky, so there may be some issues if <code>self</code> is not a <code>wx.Frame</code> or a class derived from <code>wx.Frame</code>. This is because the native toolbars are actually part of the frame rather than ... | 0 | 2016-09-01T17:24:13Z | [
"python",
"wxpython"
] |
How to get index of a cell in QTableWidget? | 39,261,734 | <p>I created a table widget and added a contextmenu to it. When I right click the cell,I want to get a file directory and put it into the cell. I've got the directory and pass it to a variable, but i failed to display it in the cell,because I can't get the index of the cell.How to get index of a cell in QTableWidget? I... | 0 | 2016-09-01T02:19:19Z | 39,262,128 | <p>hahaha, I find the mistake!</p>
<pre><code>x = self.tableWidget.currentRow
y = self.tableWidget.currentColumn
</code></pre>
<p>replace these two lines</p>
<pre><code>x = self.tableWidget.currentRow()
y = self.tableWidget.currentColumn()
</code></pre>
<p>then it works.</p>
| 0 | 2016-09-01T03:12:48Z | [
"python",
"pyqt5",
"qtablewidget"
] |
Iterating Through Lists (index out of range) | 39,261,811 | <p>Quick summary of what I am creating: It is a game in which an alien spaceship bounces around the screen (like the dell logo/loading screen) with a certain boundary so that it stays near the top of the screen. Near the bottom of the screen there is a player ship that has to click to shoot the enemy space invaders sty... | 0 | 2016-09-01T02:29:52Z | 39,262,705 | <p>The problem you are seeing is due to the way that <code>for</code> loops work in Python. They iterate through the contents of the list, not the list indexes. As mentioned in the comments, you <em>could</em> fix the error by simply doing <code>for i in range(len(statusList))</code>, but I want to suggest that you rat... | 2 | 2016-09-01T04:26:16Z | [
"python",
"python-3.x",
"pygame"
] |
How to fire a custom (python) service and continue in powershell using ansible? | 39,261,819 | <p>I am trying to start a python service in a windows host using ansible. I have tried using both Start-Job and Start-Process as follows. But I am not able to get the exact results.</p>
<p>Using Start-Job</p>
<pre><code>Start-Job -ScriptBlock {Start-Process C:\Users\voiceqa\ansitest\Scripts\python.exe C:\Users\voiceq... | 0 | 2016-09-01T02:30:28Z | 39,277,521 | <p>It's tricky to do in the currently-released versions of Ansible. Even if you managed to background the tasks via <code>raw:</code> (which is possible with some hoop-jumping), WinRM won't let the command complete until all the processes exit (WinRM runs everything under a Windows job object). You have to escape the j... | 1 | 2016-09-01T17:24:07Z | [
"python",
"powershell",
"ansible",
"ansible-playbook"
] |
How do I unload a istance of a class in python | 39,261,906 | <p>Ok I think it better to give an example on why I would want to do this.
Say I had a game.
There are some objects that are enemeys
these enemeys have a class that is running (health, weapons, ect)
If a player kills a enemy I want to unload that enemeys data from the game (removing the enemys instance of the class) Ho... | 0 | 2016-09-01T02:43:11Z | 39,262,344 | <p>It's not clear what you are asking. But I am guessing it is one of the following:</p>
<ul>
<li>You are from a C background where objects are allocated and freed and Python is your first Garbage Collected language. If you remove all references to it (e.g. remove it from the list of sprites or whatnot). Garbage colle... | 1 | 2016-09-01T03:40:52Z | [
"python",
"class"
] |
How can I get a list of all permutations of two column combination based on another column's value? | 39,261,932 | <p>My end goal is to create a <a href="https://bl.ocks.org/mbostock/4062045" rel="nofollow">Force-Directed graph</a> with d3 that shows clusters of users that utilize certain features in my applications. To do this, I need to create a set of "links" that have the following format (taken from the above link):</p>
<pre>... | 1 | 2016-09-01T02:47:34Z | 39,263,113 | <p>I would look at making some tuples out of your dataframe and then using something like <code>itertools.permutations</code> to create all the permutations, and then from there, craft your dictionaries as you need:</p>
<pre><code>import itertools
allUserPermutations = {}
groupedByUser = df.groupby('USER_ID')
for k,... | 1 | 2016-09-01T05:11:48Z | [
"python",
"pandas"
] |
MinGW or Cygwin for Python development on Windows? | 39,261,962 | <p>I am using vanilla Python 3.x on Windows, using Pycharm as IDE.</p>
<p>Although this is working; I need to install different packages and modules; and I did notice that windows has no pip, from what I can tell.</p>
<p>I am familiar with Python on Linux, and most of the time it is a matter of use pip to install new... | 1 | 2016-09-01T02:51:23Z | 39,262,364 | <p>In Pycharms you also have access to a terminal in which you can run <code>pip install</code> on. <a href="https://www.jetbrains.com/help/pycharm/2016.1/working-with-embedded-local-terminal.html" rel="nofollow">Check this link out</a></p>
| 1 | 2016-09-01T03:43:15Z | [
"python",
"cygwin",
"mingw"
] |
MinGW or Cygwin for Python development on Windows? | 39,261,962 | <p>I am using vanilla Python 3.x on Windows, using Pycharm as IDE.</p>
<p>Although this is working; I need to install different packages and modules; and I did notice that windows has no pip, from what I can tell.</p>
<p>I am familiar with Python on Linux, and most of the time it is a matter of use pip to install new... | 1 | 2016-09-01T02:51:23Z | 39,262,887 | <p>I'd comment with this if I had the rep to do so, as it fails to stay within the scope of your question. I'm guessing you've heard of <a href="https://www.continuum.io/downloads" rel="nofollow">Anaconda</a> but using <code>conda</code> and many commands associated with it, you can manage packages and virtual environm... | 0 | 2016-09-01T04:50:06Z | [
"python",
"cygwin",
"mingw"
] |
OSError: [Errno 78] Function not implemented Flask-Assets | 39,261,974 | <p>I get the following error when accessing a URL with Flask-Assets which is supposed to render and minify css. </p>
<pre><code>ERROR 2016-09-01 02:45:00,096 app.py:1587] Exception on /SomeFile [GET]
Traceback (most recent call last):
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1988, in wsgi_... | 0 | 2016-09-01T02:53:03Z | 39,818,969 | <p>This seems to be a problem with <code>flask-assets</code> and Google App Engine because GAE disallows file creation at run-time.</p>
<p>Possible duplicate of: <a href="http://stackoverflow.com/questions/17150096/gae-flask-webassets-throws-an-expection-on-extends-base-html">GAE: Flask/webassets throws an expection o... | 0 | 2016-10-02T16:10:15Z | [
"python",
"flask-assets"
] |
Removing duplicates without set() | 39,262,034 | <p>I have a .txt file of IPs, Times, Search Queries, and Websites accessed. I used a for loop to break them up into respective indices of a list, I then placed all these lists, into a larger list. </p>
<p>When printed it may look like this...</p>
<pre><code>['4.16.159.114', '08:13:37', 'french-english dictionary', 'h... | 2 | 2016-09-01T03:00:08Z | 39,262,109 | <p>Use a dict, with the query as the key and the entire list as the value. Something like this (untested):</p>
<pre><code>sweet = {}
for line in f:
...
query = lbreak[2]
if query not in sweet:
sweet[query] = lbreak
</code></pre>
<p>If you wanted the last instance of each query instead of the fir... | 1 | 2016-09-01T03:09:49Z | [
"python",
"duplicates"
] |
Removing duplicates without set() | 39,262,034 | <p>I have a .txt file of IPs, Times, Search Queries, and Websites accessed. I used a for loop to break them up into respective indices of a list, I then placed all these lists, into a larger list. </p>
<p>When printed it may look like this...</p>
<pre><code>['4.16.159.114', '08:13:37', 'french-english dictionary', 'h... | 2 | 2016-09-01T03:00:08Z | 39,262,127 | <p>Add <code>lbreak[2]</code> to a set, only append line that <code>lbreak[2]</code> not in the set, something like:</p>
<pre><code>sweet = []
seen = set()
for line in f:
x = line.split(" ")
lbreak = x[0].split("\t")
if lbreak[2] not in seen:
sweet.append(lbreak)
seen.add(lbreak[2])
<... | 3 | 2016-09-01T03:12:38Z | [
"python",
"duplicates"
] |
Combining Indices of Two Sorted Lists to Form a Third SuperSorted List | 39,262,084 | <p>I have two lists <code>['AAPL', 'MMM', 'AMAT']</code> and <code>['AMAT', 'AAPL', 'MMM']</code> and I want to create a third list based on the positions of each string in its respective list.</p>
<p>For example:
<code>AAPL</code> ranks 1st + 2nd = total 3, <code>MMM</code> ranks 2nd and 3rd = total 5, <code>AMAT</c... | 0 | 2016-09-01T03:07:23Z | 39,262,136 | <p>Just take one and do sort it by cumulative position.</p>
<pre><code>>>> a, b = ['AAPL', 'MMM', 'AMAT'], ['AMAT', 'AAPL', 'MMM']
>>> sorted(a, key=lambda x: a.index(x) + b.index(x))
['AAPL', 'AMAT', 'MMM']
</code></pre>
| 1 | 2016-09-01T03:13:42Z | [
"python",
"list"
] |
Combining Indices of Two Sorted Lists to Form a Third SuperSorted List | 39,262,084 | <p>I have two lists <code>['AAPL', 'MMM', 'AMAT']</code> and <code>['AMAT', 'AAPL', 'MMM']</code> and I want to create a third list based on the positions of each string in its respective list.</p>
<p>For example:
<code>AAPL</code> ranks 1st + 2nd = total 3, <code>MMM</code> ranks 2nd and 3rd = total 5, <code>AMAT</c... | 0 | 2016-09-01T03:07:23Z | 39,262,163 | <p>You can use a dictionary in order to save the items with sum of their indices, then create the expected list based on indices:</p>
<pre><code>>>> from collections import defaultdict
>>>
>>> d = defaultdict(int)
>>>
>>> for (ind1, j), (ind2, t) in zip(enumerate(a), enum... | 4 | 2016-09-01T03:16:26Z | [
"python",
"list"
] |
why this function get wrong result at some larger variable value | 39,262,094 | <p>I'm using gnu scientific library(gsl) to define <em>parabolic cylinder U function</em>. <a href="http://mathworld.wolfram.com/ParabolicCylinderFunction.html" rel="nofollow">Here</a> is the definition of this U function. But there is a little difference between my definition and the Mathworld's, cause I want to use ... | 1 | 2016-09-01T03:08:27Z | 39,262,433 | <p>You can get <code>pbdv</code> source code from <a href="https://github.com/scipy/scipy/blob/master/scipy/special/specfun/specfun.f" rel="nofollow">specfun scipy code</a>
Look for <code>SUBROUTINE PBDV</code>, if you not understand fortran, you can convert it to C via <a href="http://www.netlib.org/f2c" rel="nofollow... | 0 | 2016-09-01T03:51:06Z | [
"python",
"c",
"gsl"
] |
Tkinter bind widgets below a rectangle widget to a mouse event | 39,262,191 | <p>I hope I am explaining the problem correctly.
My example below is able to move two images defined on a canvas. The problem is that I want a rectangle, also defined on the canvas, on top of the images. When I do that using .tag_raise, the event triggered by mouse drag is triggered by the rectangle, not the images. <... | 1 | 2016-09-01T03:19:54Z | 39,263,169 | <p>I don't know a <code>tkinter</code> specific way to do this, however, you can try to get the coordinates of the closest image and play with them. Like this:</p>
<pre><code>import Tkinter as tk # for Python2
import PIL.Image, PIL.ImageTk
win = tk.Tk()
canvas = tk.Canvas(win, height = 500, width = 500)
#Create a re... | 2 | 2016-09-01T05:17:01Z | [
"python",
"user-interface",
"canvas",
"tkinter",
"tkinter-canvas"
] |
Rolling standard deviation with Pandas, and NaNs | 39,262,195 | <p>I have data that looks like this:</p>
<pre><code>1472698113000000000 -28.84
1472698118000000000 -26.69
1472698163000000000 -27.65
1472698168000000000 -26.1
1472698238000000000 -27.33
1472698243000000000 -26.47
1472698248000000000 -25.24
1472698253000000000 -25.53
1472698283000000000 ... | 1 | 2016-09-01T03:20:35Z | 39,262,557 | <p>If you are doing something like</p>
<p><code>df.rolling(5).std()</code></p>
<p>and getting</p>
<pre><code>0 NaN NaN
1 NaN NaN
2 NaN NaN
3 NaN NaN
4 5.032395e+10 1.037386
5 5.345559e+10 0.633024
6 4.263215e+10 0.967352
7 3.510698e+10 0.822879
... | 1 | 2016-09-01T04:06:36Z | [
"python",
"pandas",
"influxdb",
"standard-deviation"
] |
Is my adaptation of point-in-polygon (jordan curve theorem) in python correct? | 39,262,210 | <p><strong>Problem</strong></p>
<p>I recently found a need to determine if my points are inside of a polygon. So I learned about <a href="https://sidvind.com/wiki/Point-in-polygon:_Jordan_Curve_Theorem" rel="nofollow">this</a> approach in C++ and adapted it to python. However, the C++ code I was studying isn't quite r... | 4 | 2016-09-01T03:22:37Z | 39,266,511 | <p>You've misunderstood what the <code>x1</code> and <code>x2</code> values in the linked C++ code are for, and that misunderstanding has caused you to pick inappropriate variable names in Python. Both of the variables contain <code>x</code> values, so <code>temp_y</code> is a very misleading name. Better names might b... | 3 | 2016-09-01T08:32:41Z | [
"python",
"python-3.x",
"polygon",
"intersection",
"points"
] |
Order Model by Dependent Field | 39,262,417 | <p>I have 2 models, PlayerPick and Game. PlayerPick has a foreign key to the game model, showing which game the pick is for. If I want to order all of the picks by the game time, what would be the best way to do so? Is there a way to automatically add the gameTime field to the player pick model? Please see the code bel... | 0 | 2016-09-01T03:49:25Z | 39,262,710 | <pre><code>class PlayerPick(models.Model):
player_profile = models.ForeignKey('PlayerProfile')
team = models.ForeignKey(Game)
class Game(models.Model):
team1 = models.ForeignKey('Team', related_name="game_set_team1")
team2 = models.ForeignKey('Team', related_name="game_set_team2")
time = models.Dat... | 0 | 2016-09-01T04:26:43Z | [
"python",
"django",
"order",
"field",
"models"
] |
request.get python url-path instead of query argument passing in | 39,262,434 | <p>I am trying to pass in parameters into my REST API get request, like this:</p>
<p><code>parameters = {'key':value}</code></p>
<p><code>response = requests.get('some url', params= parameters)</code></p>
<p>but the API that I am using uses a url-path instead of a query argument. I want it like:</p>
<p><code>/api/r... | 0 | 2016-09-01T03:51:12Z | 39,262,503 | <p>you can try like this :
you need is a url /api/resource/parametervalue </p>
<pre><code>response = requests.get('some url'+'/'parameters)//url/api/resource/parametervalue it's a url
response = requests.get('some url',params)//url/api/resource?params it't a url with params
</code></pre>
| 0 | 2016-09-01T03:59:41Z | [
"python",
"rest",
"api",
"get"
] |
request.get python url-path instead of query argument passing in | 39,262,434 | <p>I am trying to pass in parameters into my REST API get request, like this:</p>
<p><code>parameters = {'key':value}</code></p>
<p><code>response = requests.get('some url', params= parameters)</code></p>
<p>but the API that I am using uses a url-path instead of a query argument. I want it like:</p>
<p><code>/api/r... | 0 | 2016-09-01T03:51:12Z | 39,267,513 | <p>The <code>params</code> optional argument will prepend a <code>?</code> before the query string as defined in the source code <a href="https://github.com/kennethreitz/requests/blob/master/requests/models.py#L69" rel="nofollow" title="here">here</a>.</p>
<p>You're better off modifying the URL before you call <code>r... | 0 | 2016-09-01T09:18:15Z | [
"python",
"rest",
"api",
"get"
] |
Installing cuDNN for Theano without root access | 39,262,468 | <p>Can I install <a href="https://developer.nvidia.com/cudnn" rel="nofollow">cuDNN</a> locally without root access ?</p>
<p>I don't have root access to a linux machine I am using (the distro is openSuse), but I have CUDA 7.5 already installed. </p>
<p>I am using Theano and I need cuDNN to improve the speed of the op... | 0 | 2016-09-01T03:55:49Z | 39,275,036 | <p>You could copy the entire CUDA SDK to your home and tell Theano and others that they should use your local copy of CUDA by adding/modifying these environment variables in your <code>~/.bashrc</code></p>
<pre><code>export CUDA_ROOT=~/program/cuda-7.5
export CUDA_HOME=~/program/cuda-7.5
export PATH=${CUDA_HOME}/bin:$... | 1 | 2016-09-01T15:03:14Z | [
"python",
"linux",
"gpu",
"theano-cuda"
] |
PyCharm - always show inspections | 39,262,493 | <p>PyCharm displays little bars on the scroll bar for things like code warnings. This feature is called "inspection".</p>
<p>If you move the mouse cursor over a bar, it shows a preview of the code annotated with the inspection.</p>
<p>I find this really fiddly, and I'd actually like full inspection notices to be disp... | 3 | 2016-09-01T03:58:42Z | 39,416,640 | <p>According to <a href="https://www.jetbrains.com/help/pycharm-edu/3.0/inspection-tool-window.html" rel="nofollow">this PyCharm's documentation</a> there seems to be an <em>Inspection Tool Window</em> which <em>displays inspection results on separate tabs.</em>.</p>
<p>You can access the tool window through menu <str... | 1 | 2016-09-09T17:13:47Z | [
"python",
"ide",
"pycharm",
"lint"
] |
Preserve quotes and also add data with quotes in Ruamel | 39,262,556 | <p>I am using Ruamel to preserve quote styles in human-edited YAML files.</p>
<p>I have example input data as:</p>
<pre><code>---
a: '1'
b: "2"
c: 3
</code></pre>
<p>I read in data using:</p>
<pre><code>def read_file(f):
with open(f, 'r') as _f:
return ruamel.yaml.round_trip_load(_f.read(), preserve_quo... | 2 | 2016-09-01T04:06:33Z | 39,263,202 | <p>In order to preserve quotes (and literal block style) for string scalars, ruamel.yaml¹—in round-trip-mode—represents these scalars as <code>SingleQuotedScalarString</code>, <code>DoubleQuotedScalarString</code> and <code>PreservedScalarString</code>. The class definitions for these very thin wrappers c... | 2 | 2016-09-01T05:20:26Z | [
"python",
"ruamel.yaml"
] |
Pandas plot sharex=False does not behave as expected | 39,262,630 | <p>I am trying to plot histograms of a couple of series from a dataframe. Series have different maximum values:</p>
<pre><code>df[[
'age_sent', 'last_seen', 'forum_reply', 'forum_cnt', 'forum_exp', 'forum_quest'
]].max()
</code></pre>
<p>returns:</p>
<pre><code>age_sent 1516.564016
last_seen 986.7900... | 3 | 2016-09-01T04:15:56Z | 39,275,085 | <p>The <code>sharex</code> (most likely) just falls through to mpl and sets if the panning / zooming one axes changes the other.</p>
<p>The issue you are having is that the same bins are being used for all of the histograms (which is enforced by <a href="https://github.com/pydata/pandas/blob/master/pandas/tools/plotti... | 2 | 2016-09-01T15:05:06Z | [
"python",
"pandas",
"matplotlib"
] |
How I can either deny a login or registration a user based on current session | 39,262,664 | <p>How can I deny or redirect an active user to the logged-in screen?</p>
<p>I want, user only can access pages when current session allows the access. </p>
<p>Is this can be done directly in the HTML code or only in views ?</p>
| 0 | 2016-09-01T04:21:07Z | 39,262,946 | <p>If I understand you correctly, you mean that the user shouldn't see the login and signup links (maybe in the topbar). This can be done in the template as:</p>
<pre><code>{% if user.is_authenticated %}
<!-- show logout link/button -->
{% else %}
<!-- show login and signup links/buttons -->
{% endif %}
</... | 0 | 2016-09-01T04:56:51Z | [
"python",
"html",
"django",
"redirect",
"views"
] |
How can I add a constant percentage to each wedge of a pie chart using matplotlib | 39,262,783 | <p>Code snippet looks like this</p>
<pre><code>#df is dataframe with 6 rows, with each row index being the label of the sector
plt.pie(df.iloc[:,0], labels= df.index) #plot the first column of dataframe as a pie chart
</code></pre>
<p>It generates a pie chart like this:</p>
<p><a href="http://i.stack.imgur.com/z9PX... | 2 | 2016-09-01T04:36:33Z | 39,265,862 | <blockquote>
<p>I want to make each sector have a minimum value of 10 degree</p>
</blockquote>
<p>Solving this for the general case is difficult and requires further definition. This introduces a skew into the results, and to decide between different algorithms, you'd need to specify a metric defining how close is s... | 2 | 2016-09-01T07:58:24Z | [
"python",
"pandas",
"matplotlib"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.