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 |
|---|---|---|---|---|---|---|---|---|---|
Iterate over every black square of a "chessboard" | 38,171,902 | <p>I'd like to iterate over every other element of a <code>m</code>-by-<code>n</code> "chessboard", i.e.,</p>
<pre><code>l = []
for i in range(m):
for j in range(n):
if (i+j) % 2 == 0:
l.append(something(i, j))
</code></pre>
<p>I'm using an explicit loop here, but for speed would rather use ... | -6 | 2016-07-03T16:21:22Z | 38,171,920 | <p>Well, list comprehension is just like your nested <code>for</code> loop, except that this is done <em>within</em> the list brackets:</p>
<pre><code>my_list = [something(i, j) for i in range(m) for j in range(n) if (i + j) % 2 == 0]
</code></pre>
<p>More generally, for <code>n</code> nested loops, you can use <a hr... | 2 | 2016-07-03T16:22:58Z | [
"python",
"loops"
] |
Iterate over every black square of a "chessboard" | 38,171,902 | <p>I'd like to iterate over every other element of a <code>m</code>-by-<code>n</code> "chessboard", i.e.,</p>
<pre><code>l = []
for i in range(m):
for j in range(n):
if (i+j) % 2 == 0:
l.append(something(i, j))
</code></pre>
<p>I'm using an explicit loop here, but for speed would rather use ... | -6 | 2016-07-03T16:21:22Z | 38,172,567 | <p>As I understand it, you would like an explicit expression for the x and y coordinates of the black squares on the 'chess board', so that you don't have to evaluate the boolean for every square. Here is an implementation of my solution (for a 2-dimensional board):</p>
<pre><code>import numpy as np
# 'Chess board' d... | 0 | 2016-07-03T17:31:28Z | [
"python",
"loops"
] |
GenericForeignKey objects in list view | 38,171,998 | <p>I am using a third-party app (<a href="https://github.com/bitmazk/django-review" rel="nofollow">https://github.com/bitmazk/django-review</a>) to generate reviews for my model via a generic foreign key.</p>
<pre><code>class Store(models.Model):
bio = models.CharField(max_length=255, null=True, blank=True)
fu... | 1 | 2016-07-03T16:31:49Z | 38,172,621 | <p><code>django-review</code> uses Django's <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/contenttypes/" rel="nofollow"><code>contenttypes</code></a> and <a href="https://micropyramid.com/blog/understanding-genericforeignkey-in-django/" rel="nofollow">generic foreign keys</a> to create database records for... | 0 | 2016-07-03T17:37:21Z | [
"python",
"django",
"generic-foreign-key"
] |
How to fit a set of data with two different functions | 38,172,052 | <p>I am trying to fit a set of data with a step function. But it doesn't work. To make it simple, here is what I am trying to do. </p>
<p>I have a set of data. From x=0 to x=y, the curve follows a x^2. From x=y to x=100, it is 0. </p>
<p>The idea is to find the best fit so that I have a value for y. It doesn't work b... | 0 | 2016-07-03T16:37:01Z | 38,440,674 | <p>The exception you got is because of <code>c[x<y] = a*(x-y)**2</code>. left side has 323 values and right side has 710 values. This is because of the condition <code>x < y</code> that should be also on the right side:</p>
<pre><code>import numpy as np
from scipy.optimize import curve_fit
a = 5
y = 47
xdata =... | 0 | 2016-07-18T15:30:56Z | [
"python"
] |
Get company name from a Google Finance page with Python | 38,172,071 | <p>I would like to print the company name from the Google Finance page, using the div class appbar-snippet-primary. The code I am usng returns none or []. Wasn't able to get to the span tag containing the company name using beautifulsoup. </p>
<pre><code>html = urlopen('https://www.google.com/finance?q=F')
soup = B... | 0 | 2016-07-03T16:38:23Z | 38,172,290 | <h2>It's a class, not an ID</h2>
<p>The element you're interested in looks like this</p>
<pre><code><div class="appbar-snippet-primary">
<span>Ford Motor Company</span>
</div>
</code></pre>
<p>So it's a <code>div</code> with <code>class="appbar-snippet-primary"</code>, not <code>id="appba... | 1 | 2016-07-03T17:02:47Z | [
"python",
"class",
"beautifulsoup",
"google-finance"
] |
Get company name from a Google Finance page with Python | 38,172,071 | <p>I would like to print the company name from the Google Finance page, using the div class appbar-snippet-primary. The code I am usng returns none or []. Wasn't able to get to the span tag containing the company name using beautifulsoup. </p>
<pre><code>html = urlopen('https://www.google.com/finance?q=F')
soup = B... | 0 | 2016-07-03T16:38:23Z | 38,172,808 | <p>The value is not dynamically generated by Javascript, it is in the source, all you need to do is add a <em>user-agent</em> and use the correct tag name, the following example using requests gets what you want:</p>
<pre><code>from bs4 import BeautifulSoup
import requests
head = {"User-Agent":"Mozilla/5.0 (X11; Lin... | 0 | 2016-07-03T18:00:14Z | [
"python",
"class",
"beautifulsoup",
"google-finance"
] |
What is the equivalent of a Swift completion block in Python? | 38,172,180 | <p>In Swift we can write a function with a completion block like this:</p>
<pre><code>func thisNeedsToFinishBeforeWeCanDoTheNextStep(completion: () -> ()) {
print("The quick brown fox")
completion()
}
</code></pre>
<p>And then when we call it, we can put something inside of that block to execute once it's ... | 1 | 2016-07-03T16:51:25Z | 38,172,320 | <p>Python considers functions as objects, meaning you can pass them around (like in Swift, although I'm less familiar with the implementation details in Swift). You can't specify a type in the parameter, of course, since you can't do that with anything in Python, but that's okay. The implementation would look like:</p>... | 1 | 2016-07-03T17:05:26Z | [
"python",
"swift"
] |
Join two csv files with pandas/python without duplicates | 38,172,215 | <p>I would like to concatenate 2 csv files. Each CSV file has the following structure:</p>
<p>File 1</p>
<p><code>id,name,category-id,lat,lng
4c29e1c197,Area51,4bf58dd8d,45.44826958,9.144208431
4ede330477,Punto Snai,4bf58dd8d,45.44833354,9.144086353
51efd91d49,Gelateria Cecilia,4bf58dd8d,45.44848931,9.144008735</code... | 0 | 2016-07-03T16:54:57Z | 38,173,560 | <p>One way to solve this problem is to just use df.drop_duplicates() after you have concatenated the two DataFrames. Additionally, drop_duplicates has an argument "keep", which allows you to specify that you want to keep the last occurrence of the duplicates. </p>
<pre><code>full_df = pd.concat([df1,df2])
unique_df = ... | 1 | 2016-07-03T19:22:49Z | [
"python",
"csv",
"pandas"
] |
Join two csv files with pandas/python without duplicates | 38,172,215 | <p>I would like to concatenate 2 csv files. Each CSV file has the following structure:</p>
<p>File 1</p>
<p><code>id,name,category-id,lat,lng
4c29e1c197,Area51,4bf58dd8d,45.44826958,9.144208431
4ede330477,Punto Snai,4bf58dd8d,45.44833354,9.144086353
51efd91d49,Gelateria Cecilia,4bf58dd8d,45.44848931,9.144008735</code... | 0 | 2016-07-03T16:54:57Z | 38,174,499 | <p>I could resolve this problemen with the next code:</p>
<pre><code>import pandas as pd
df1=pd.read_csv("file1.csv")
df2=pd.read_csv("file2.csv")
df_final=pd.concat([df1,df2]).drop_duplicates(subset=['id','category_id','lat','lng']).reset_index(drop=True)
print(df_final.shape)
df_final2=df_final.drop_duplicates(su... | 0 | 2016-07-03T21:28:41Z | [
"python",
"csv",
"pandas"
] |
Pytest blocks pyside code from execution | 38,172,229 | <p>I have a main window with buttons, labels etc. </p>
<p>I have a sample script with test functions. </p>
<p>I have a pytest fixture to get current executed test function name. </p>
<p><strong>I want to print that current test function name to a label in the main window.</strong></p>
<hr>
<p>This is my code to ge... | 0 | 2016-07-03T16:56:52Z | 38,192,728 | <p>Solved the problem. The issue was that pyside run in 1 main thread. Any other process that runs at that moment will freeze pyside. So the solution was to seperate the call for pytest in a thread. </p>
| 0 | 2016-07-04T22:02:20Z | [
"python",
"user-interface",
"pyside",
"py.test"
] |
Float to Fraction conversion in Python | 38,172,252 | <p>While doing exercise on the topic of float type to Fraction type conversion in Python 3.52, I found the difference between the two different ways of conversion.</p>
<p>The first method is:</p>
<pre><code>>>> from fractions import Fraction
>>> x = 1232.23
>>> f = Fraction(*x.as_integer_ra... | 3 | 2016-07-03T16:58:55Z | 38,172,286 | <p>This is actually a pretty good question. The reason behind the different results is that <code>x</code> is not truly <code>1232.23</code> because there is no exact float representation for <code>1232.23</code>, so the fractional representation of the nearest float representation of <code>1232.23</code> is <code>2709... | 2 | 2016-07-03T17:02:32Z | [
"python",
"floating-point",
"type-conversion",
"fractions"
] |
Float to Fraction conversion in Python | 38,172,252 | <p>While doing exercise on the topic of float type to Fraction type conversion in Python 3.52, I found the difference between the two different ways of conversion.</p>
<p>The first method is:</p>
<pre><code>>>> from fractions import Fraction
>>> x = 1232.23
>>> f = Fraction(*x.as_integer_ra... | 3 | 2016-07-03T16:58:55Z | 38,172,289 | <p>Yet again it's because floating point numbers aren't stored in base-10 (decimal), but in base-2 (binary).</p>
<p>A number that is finite length in base-10 might be a repeating decimal in base-2. And because floats are a fixed size, that repeating decimal gets truncated, resulting in inaccuracies.</p>
<p>When you ... | 4 | 2016-07-03T17:02:40Z | [
"python",
"floating-point",
"type-conversion",
"fractions"
] |
QObject:Cannot create children for a parent that is in different thread.Parent is QTextDocument,parent's thread is QThread,current thread is QThread | 38,172,325 | <p>I am new to python threading and Pyside. I am working on making a communication between two computers but could not create a thread on receiving side
Here is server code</p>
<pre><code>from PySide import QtCore, QtGui
import sys
import receiver
import os
from socket import *
import thread
class mainWindow(QtGui.QM... | 0 | 2016-07-03T17:05:59Z | 38,193,976 | <p>In your code, you should only create a thread for the client, not the server. For the server, simply create a while loop within the "listener" method to wait for "data" as such:</p>
<pre><code>while 1:
(data, addr) = UDPSock.recvfrom(buf)
if data:
self.textEdit.setText(data)
UDPSock.close()... | 0 | 2016-07-05T01:23:32Z | [
"python",
"multithreading",
"pyside",
"python-multithreading"
] |
How to Transfer the "Common" Columns between Two CSV Files | 38,172,342 | <p>I am fairly new to programming and want to code this program that transfer the common columns between <code>file1.csv</code> and <code>file2.csv</code></p>
<p><strong>Input:</strong></p>
<p><code>file1.csv</code> looks like this:</p>
<pre><code>ID,Nickname,Gender,SubjectPrefix,SubjectFirstName,Whatever1A,Whaterve... | 0 | 2016-07-03T17:08:10Z | 38,172,650 | <p>Welcome to programming. Let me introduce you to the amazing <a href="http://pandas.pydata.org/" rel="nofollow">pandas library</a>.</p>
<p>Off the top of my head, here's something that will solve your problem. (I'm not saying its efficient! So for large datasets it might be a problem)</p>
<pre><code>import pandas a... | 1 | 2016-07-03T17:41:28Z | [
"python",
"csv",
"for-loop",
"pandas",
"dictionary"
] |
How to Transfer the "Common" Columns between Two CSV Files | 38,172,342 | <p>I am fairly new to programming and want to code this program that transfer the common columns between <code>file1.csv</code> and <code>file2.csv</code></p>
<p><strong>Input:</strong></p>
<p><code>file1.csv</code> looks like this:</p>
<pre><code>ID,Nickname,Gender,SubjectPrefix,SubjectFirstName,Whatever1A,Whaterve... | 0 | 2016-07-03T17:08:10Z | 38,175,344 | <p>Thanks <a href="http://stackoverflow.com/questions/38172342/how-to-transfer-the-common-columns-between-two-csv-files">Wboy</a> for your contribution, your input was really useful.</p>
<p>I was able to find a solution to the problem using Pandas library. Here is the code:</p>
<pre><code>import pandas as pd
# rea... | -1 | 2016-07-03T23:51:42Z | [
"python",
"csv",
"for-loop",
"pandas",
"dictionary"
] |
How to make a POST request to a Django Rest Framework API in in Volley? | 38,172,359 | <p>Here is a simple http request that I make to my Django Rest Framework based API through Postman.
<a href="http://i.stack.imgur.com/ZeDaG.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZeDaG.png" alt="enter image description here"></a></p>
<p>I send 4 simple parameters <code>name</code>, <code>phone</code>,... | 1 | 2016-07-03T17:10:12Z | 38,172,428 | <p>You have to add <code>getParams()</code> method ( after the getHeaders() method ) send the data to server.</p>
<pre><code>{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("n... | 0 | 2016-07-03T17:17:57Z | [
"android",
"python",
"django",
"rest",
"android-volley"
] |
python urlopen 403 inspite of URL being accessible via browsers | 38,172,360 | <p>..Hi folks ..the following URL <a href="https://www.nseindia.com/products/dynaContent/equities/indices/historicalindices.jsp?toDate=30-06-2016&fromDate=29-06-2016&indexType=NIFTY%2050" rel="nofollow">https://www.nseindia.com/products/dynaContent/equities/indices/historicalindices.jsp?toDate=30-06-2016&fr... | 0 | 2016-07-03T17:10:25Z | 38,178,871 | <p>just added this additional line in the headers </p>
<pre><code> hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
</code></pre>
<... | 0 | 2016-07-04T07:15:57Z | [
"python",
"urlopen"
] |
Create FlowMap in Python OpenCV | 38,172,370 | <p>Updated question:</p>
<p>Would anyone be able to point me in the direction of any material that could help me to plot an optical flow map in python? Ideally i want to find something that provides a similar output to the video shown here: <a href="http://study.marearts.com/2014/04/opencv-study-calcopticalflowfarneba... | 1 | 2016-07-03T17:11:16Z | 38,277,010 | <p>I do not know how to change the behaviour of matplotlib quiver plots, but I'm sure it is possible. </p>
<p>An alternative is to create a function to draw lines on top of the original image, based on the calculated optical flow. The following code should achieve this:</p>
<pre><code>def dispOpticalFlow( Image,Flo... | 0 | 2016-07-09T00:13:03Z | [
"python",
"opencv",
"matplotlib",
"motion-detection",
"opticalflow"
] |
Set all classes within package as class attributes | 38,172,379 | <p>Given the following package structure:</p>
<pre><code>master.py
models/
__init__.py
model1.py
model2.py
model3.py
</code></pre>
<p>where each model*.py file contains one or more classes, how can I create a class in master.py that dynamically imports each of those classes and sets it as an attribute of itse... | 2 | 2016-07-03T17:12:05Z | 38,172,700 | <p>Well... I don't think it's the <em>best</em> way to do this â I would personally prefer to handle all the imports manually. But I'll assume you have your reasons and answer your question anyway.</p>
<p>First of all, you'll need the <code>models</code> to be a module, so add a file <code>models/__init__.py</code>... | 0 | 2016-07-03T17:46:54Z | [
"python",
"class",
"python-import"
] |
Try Except in 'for' loop - Python | 38,172,382 | <p>I made a 'guess the number'game, but I wanted to add input validation so the user can only guess an integer. Here is my code, I appreciate any suggestions. I am using python 3.</p>
<pre><code>import random
print('Hello, what is your name?')
name = input()
print('It is nice to meet you ' + name + '.')
secretNumber =... | -1 | 2016-07-03T17:12:31Z | 38,172,422 | <pre><code>def input_int(prompt=">",error_msg="That is not an int!"):
while True:
try:
return int(input(prompt))
except ValueError:
print(error_msg)
x = input_int("Please Enter an Int:","Wrong Answer!")
print x,x**2
</code></pre>
<p>you can abstract this further</p>... | 2 | 2016-07-03T17:17:13Z | [
"python",
"python-3.x"
] |
Try Except in 'for' loop - Python | 38,172,382 | <p>I made a 'guess the number'game, but I wanted to add input validation so the user can only guess an integer. Here is my code, I appreciate any suggestions. I am using python 3.</p>
<pre><code>import random
print('Hello, what is your name?')
name = input()
print('It is nice to meet you ' + name + '.')
secretNumber =... | -1 | 2016-07-03T17:12:31Z | 38,172,423 | <p>Here is a better way to do this with input validation </p>
<pre><code>import random
name = raw_input('Hello, what is your name?')
print('It is nice to meet you ' + name + '.')
secretNumber = random.randint(1, 20)
print('Well ' + name + ', I am thinking of a number between 1 and 20')
for guessTaken in range(1, 7):
... | 1 | 2016-07-03T17:17:19Z | [
"python",
"python-3.x"
] |
Try Except in 'for' loop - Python | 38,172,382 | <p>I made a 'guess the number'game, but I wanted to add input validation so the user can only guess an integer. Here is my code, I appreciate any suggestions. I am using python 3.</p>
<pre><code>import random
print('Hello, what is your name?')
name = input()
print('It is nice to meet you ' + name + '.')
secretNumber =... | -1 | 2016-07-03T17:12:31Z | 38,172,444 | <pre><code>for guessTaken in range(1, 7):
guess = 0
while guess < 1 or guess > 20:
print('Take a guess.')
try:
guess = int(input())
except ValueError:
print("Guess must be a number.")
else:
if guess < 1 or guess > 20:
pr... | 1 | 2016-07-03T17:19:03Z | [
"python",
"python-3.x"
] |
Calculator created with Python | 38,172,431 | <p>I'm new here in this "world".
I tried to create a calculator with Python,here's the code.
When I try to run it,IDLE gives me errors,can you help me,please? :D</p>
<p>Header 1</p>
<pre><code>print("Options")
print("Type 'add' to add two numbers")
print("Type'subtract' to subtract two numbers")
print("Type'multiply'... | -4 | 2016-07-03T17:18:04Z | 38,172,603 | <p>Try this (you don't have loop so use exit() rather than break, also use the right operators for add, divide, sub-struct, multiply. </p>
<pre><code>from __future__ import division # to support division
print("Options")
print("Type 'add' to add two numbers")
print("Type'subtract' to subtract two numbers")
print("Typ... | 0 | 2016-07-03T17:35:09Z | [
"python"
] |
Calculator created with Python | 38,172,431 | <p>I'm new here in this "world".
I tried to create a calculator with Python,here's the code.
When I try to run it,IDLE gives me errors,can you help me,please? :D</p>
<p>Header 1</p>
<pre><code>print("Options")
print("Type 'add' to add two numbers")
print("Type'subtract' to subtract two numbers")
print("Type'multiply'... | -4 | 2016-07-03T17:18:04Z | 38,172,604 | <pre><code>if user_input == 'quit':
#break
pass
</code></pre>
| -1 | 2016-07-03T17:35:24Z | [
"python"
] |
Calculator created with Python | 38,172,431 | <p>I'm new here in this "world".
I tried to create a calculator with Python,here's the code.
When I try to run it,IDLE gives me errors,can you help me,please? :D</p>
<p>Header 1</p>
<pre><code>print("Options")
print("Type 'add' to add two numbers")
print("Type'subtract' to subtract two numbers")
print("Type'multiply'... | -4 | 2016-07-03T17:18:04Z | 38,173,694 | <p>The problem is the break statement here:</p>
<pre><code>if user_input == "quit":
break
</code></pre>
<p>You can only use a break statement within a while and/or for loop.
The solution is to replace the break statement with print() or exit() instead. </p>
<p>For your program to be more effective (and to be ab... | 0 | 2016-07-03T19:39:36Z | [
"python"
] |
Sort Pandas Dataframe on two columns with one column values repeating in sequence | 38,172,474 | <p>My input dataframe have two columns:</p>
<pre><code>df
c1 c2
0 a 8
1 a 3
2 b 2
3 c 1
4 b 10
5 c 8
6 a 10
7 c 7
</code></pre>
<p>I want to sort the above dataframe so that the values in column 'c1' appears in sequence (abcabcac) and their corresponding column 'c2' values in ascending (or d... | 1 | 2016-07-03T17:22:13Z | 38,172,801 | <pre><code>df.assign(c3 = df.groupby('c1')['c2'].rank()).sort_values(['c3', 'c1']).drop('c3', axis=1)
Out[21]:
c1 c2
1 a 3
2 b 2
3 c 1
0 a 8
4 b 10
7 c 7
6 a 10
5 c 8
</code></pre>
<p>This creates a new column <code>c3</code> that has the rank of each letter (with respect to c2) to use in sor... | 3 | 2016-07-03T17:59:09Z | [
"python",
"pandas"
] |
Browser not displaying POST data PHP? | 38,172,480 | <p>I have written a program to send data from python to PHP.
The python code is as follows:</p>
<pre><code>import urllib2, urllib
mydata=[('one','Check'),('two','Mate')] #The first is the var name the second is the value
mydata=urllib.urlencode(mydata)
path='http://localhost/index.php' #the url you want to POST ... | 1 | 2016-07-03T17:23:28Z | 38,172,573 | <p>By default Python is sending as <code>GET</code> request.</p>
<p>You need to specify it as a <code>POST</code> request.</p>
<pre><code>req=urllib2.Request('POST', path, mydata)
</code></pre>
| 0 | 2016-07-03T17:31:58Z | [
"php",
"python"
] |
What is faster, `if x` or `if x != 0`? | 38,172,499 | <p>I was wondering, what code runs faster? For example, we have variable x:</p>
<pre><code>if x!=0 : return
</code></pre>
<p>or</p>
<pre><code>if x: return
</code></pre>
<p>I tried to check with timeit, and here are results:</p>
<pre><code> >>> def a():
... if 0 == 0: return
...
>>> def b():
... | 3 | 2016-07-03T17:25:06Z | 38,172,713 | <p>This is too hard to show in a comment: there's more (or less ;-) ) going on here than any of the comments so far noted. With <code>a()</code> and <code>b()</code> defined as you showed, let's go on:</p>
<pre><code>>>> from dis import dis
>>> dis(b)
2 0 LOAD_CONST 0 (Non... | 13 | 2016-07-03T17:48:55Z | [
"python"
] |
Iterating through rows in .txt and looping each "15 rows" | 38,172,501 | <p>I have a problem with my python script. I can't find a way to do a calculation for the first 15 rows only, then for the second 15 rows only, then for the third 15 rows only... The rows come from a txt file.</p>
<pre><code>with open('/Users/sammtt/data/test2.txt','r') as f:
for line in nonblank_lines(f):
print(m... | 1 | 2016-07-03T17:25:14Z | 38,172,540 | <p>You could use this <a href="https://docs.python.org/3/library/itertools.html#itertools-recipes" rel="nofollow">recipe</a> for <a href="https://docs.python.org/3/library/itertools.html" rel="nofollow"><code>itertools</code></a> from the standard library:</p>
<pre><code>from itertools import zip_longest
def grouper(... | 2 | 2016-07-03T17:28:58Z | [
"python",
"list",
"stream",
"rows"
] |
Iterating through rows in .txt and looping each "15 rows" | 38,172,501 | <p>I have a problem with my python script. I can't find a way to do a calculation for the first 15 rows only, then for the second 15 rows only, then for the third 15 rows only... The rows come from a txt file.</p>
<pre><code>with open('/Users/sammtt/data/test2.txt','r') as f:
for line in nonblank_lines(f):
print(m... | 1 | 2016-07-03T17:25:14Z | 38,172,630 | <p>You can use <code>itertools.groupby</code> on an integer division:</p>
<pre><code>>>> from itertools import groupby
>>> f = range(0, 100)
>>> for i, g in groupby(f, key=lambda x: x//15):
... print(list(g))
...
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[15, 16, 17, 18, 19, 20,... | 0 | 2016-07-03T17:39:15Z | [
"python",
"list",
"stream",
"rows"
] |
cookiecutter command not found after installing with pip | 38,172,539 | <p>I want to use cookiecutter to start a django project but for some reason cookiecutter cannot be found. </p>
<p>What I did was:</p>
<pre><code>pip install cookiecutter
</code></pre>
<p>After that:</p>
<pre><code>cookiecutter https://github.com/pydanny/cookiecutter-django
</code></pre>
<p>Then I get the error mes... | 0 | 2016-07-03T17:28:57Z | 38,175,134 | <p>I'm sorry but it appears you're mixing things up.</p>
<ol>
<li>Because <code>sudo apt-get install cookiecutter</code> installs something
called cookiecutter doesn't mean it is the same cookiecutter from
pip. In fact, they have nothing in common. One is a cookie cutter for python, and the other is for django.</li>
<... | 1 | 2016-07-03T23:11:21Z | [
"python",
"django",
"cookiecutter-django"
] |
How I can use Kivy (Python) camera | 38,172,543 | <p>I try to use uix.camera widget and show some wideo from my web-camera.
I looked into the documentation and try to use this simply code. But it's just show me a white creen withoud any video (I enabled playing).
What I'm doing wrong?
Maybe some useful docs\tutorial exist (because from official documentation I under... | 1 | 2016-07-03T17:29:04Z | 38,172,780 | <p>It seems like you need to set <code>resolution=[x, y]</code> property besides <code>play=True</code>, because the default one doesn't work.</p>
| 0 | 2016-07-03T17:56:49Z | [
"python",
"camera",
"kivy"
] |
Separate pdf to pages using pdfminer | 38,172,601 | <p>I am trying to extract a pdf page by page and store the results in a dictionary as follows:</p>
<pre><code>from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO impor... | 0 | 2016-07-03T17:34:51Z | 40,130,100 | <p>This should work.
</p>
<pre><code>from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from cStringIO import StringIO
import os
def set_interpreter():
rsrcmgr = PDFResourceMa... | 0 | 2016-10-19T11:24:56Z | [
"python",
"pdfminer"
] |
match web url with python regex | 38,172,610 | <p>I am trying to extra web links from web content with Python regex. here's my python script</p>
<pre><code>webUrlList = re.findall(r"(?<=<a href=\").+(.html|/)(?=\")", content)
print webUrlList
</code></pre>
<p>and the matched webUrlList is like: </p>
<pre><code>['/', '.html', '/', '/', '/', '/',...]
</code... | 0 | 2016-07-03T17:36:29Z | 38,172,657 | <p>Use a html parser like <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup</a>:</p>
<pre><code>soup = BeautifulSoup(content, "html.parser")
print([a["href"] for a in soup.find_all("a", href=True)])
</code></pre>
<p>Don't use a regex to parse <a href="http://stackoverflow.... | 1 | 2016-07-03T17:42:01Z | [
"python",
"regex"
] |
match web url with python regex | 38,172,610 | <p>I am trying to extra web links from web content with Python regex. here's my python script</p>
<pre><code>webUrlList = re.findall(r"(?<=<a href=\").+(.html|/)(?=\")", content)
print webUrlList
</code></pre>
<p>and the matched webUrlList is like: </p>
<pre><code>['/', '.html', '/', '/', '/', '/',...]
</code... | 0 | 2016-07-03T17:36:29Z | 38,172,849 | <p>If you're only parsing for links, and you're familiar with the content you will be parsing, the following regex should help you accomplish what you're after and is pretty safe.</p>
<pre><code>regex = re.compile(r'href="([^"]+)')
results = re.findall(regex, <CONTENT-HERE>)
</code></pre>
<ul>
<li><code>href="<... | 2 | 2016-07-03T18:04:50Z | [
"python",
"regex"
] |
unable to import scitools python | 38,172,774 | <p>I have just installed scitools-0.8 and I'm trying to import it using <code>from scitools.std import *</code></p>
<p>but I get an error message saying</p>
<blockquote>
<p>ImportError: No module named oldnumeric.mlab </p>
<p>numpy import filed!</p>
<p>see doc of scitools.numpytools module for how to choo... | 0 | 2016-07-03T17:56:00Z | 38,173,328 | <p>The version of <code>scitools</code> you are using is ancient. Try cloning <a href="https://github.com/hplgit/scitools" rel="nofollow">this repo</a> and running <code>[sudo] python setup.py install</code>. The version number is 0.9.0, but some bug fixes have been pushed to the repo since its release. I just did this... | 2 | 2016-07-03T18:58:14Z | [
"python",
"python-2.7",
"scitools"
] |
Airplay Remote control HTTP request | 38,172,856 | <p>I use Airplay with a Raspberry Pi, so I installed Sharply-sync.
It work perfectly but I want to control the music of my iPhone which is emitting music with airplay.
I saw this page to do this: <a href="http://nto.github.io/AirPlay.html#audio-remotecontrol" rel="nofollow">http://nto.github.io/AirPlay.html#audio-remo... | -1 | 2016-07-03T18:05:25Z | 38,173,937 | <p>Just use requests module. Check sample code below.</p>
<pre><code>import requests
headers = {'Host': 'starlight.local.' , 'Active-Remote': 1986535575}
url = "http://192.168.x.xx:5000//ctrl-int/1/pause"
requests.get(url, headers=headers)
</code></pre>
<p>For more details please check the documentation for the modul... | 0 | 2016-07-03T20:14:33Z | [
"python",
"http",
"request",
"raspberry-pi",
"airplay"
] |
Plot vertical lines from datapoints to zero axis in python | 38,172,903 | <p>I want to plot vertical lines from each point of my dataset to the zero axis. At the moment plot looks like this:</p>
<pre><code>values = [0.0, 0.2, 0.0, 0.4, 1.4, 0.5]
times = [1, 4, 10, 12, 14, 20]
plt.plot(values,times,'o')
plt.show()
</code></pre>
<p>How to plot the vertical lines? I found in the documentatio... | 0 | 2016-07-03T18:10:06Z | 38,172,940 | <p>You can plot an arbitrary line from <code>c1 = [x1, y1]</code> to <code>c2 = [x2, y2]</code> using <code>plt.plot(c1, c2)</code>. So to plot these lines you can just do</p>
<pre><code>xcoords = [0.22058956, 0.33088437, 2.20589566]
for xc in xcoords:
plt.plot([xc, 0], [xc, Y-VALUE])
</code></pre>
| 2 | 2016-07-03T18:13:58Z | [
"python",
"matplotlib",
"plot"
] |
Plot vertical lines from datapoints to zero axis in python | 38,172,903 | <p>I want to plot vertical lines from each point of my dataset to the zero axis. At the moment plot looks like this:</p>
<pre><code>values = [0.0, 0.2, 0.0, 0.4, 1.4, 0.5]
times = [1, 4, 10, 12, 14, 20]
plt.plot(values,times,'o')
plt.show()
</code></pre>
<p>How to plot the vertical lines? I found in the documentatio... | 0 | 2016-07-03T18:10:06Z | 38,173,494 | <p><code>axvline</code> has a paramater <code>ymax</code> that adjusts percent of the yrange, until which vline should last. In case when y axis is <strong>tight</strong>, the solution could be like this:</p>
<pre><code>for i in range(len(times)):
plt.axvline(values[i], ymax=float(times[i]) / max(times), color='b'... | 2 | 2016-07-03T19:14:28Z | [
"python",
"matplotlib",
"plot"
] |
How to split a number in python and add them | 38,172,924 | <p>I'm working on a lucky name numbers game, and I am able to get the number from the name by running it through a custom-made function, but I cannot seem to add them together.</p>
<p>My code so far:</p>
<pre><code>num = 0
def main():
name = input('Please enter your name: ')
for letter in name:
if le... | -5 | 2016-07-03T18:12:36Z | 38,173,138 | <p><code>getDigitSum</code> is a function that takes in one parameter, <code>num</code> that it does some calculation with and returns a number.</p>
<p>You not only are not passing in any arguments to it, but also not storing its return value anywhere.</p>
<p>Replace <code>getDigitSum()</code> with something like <co... | 1 | 2016-07-03T18:33:34Z | [
"python"
] |
How to split a number in python and add them | 38,172,924 | <p>I'm working on a lucky name numbers game, and I am able to get the number from the name by running it through a custom-made function, but I cannot seem to add them together.</p>
<p>My code so far:</p>
<pre><code>num = 0
def main():
name = input('Please enter your name: ')
for letter in name:
if le... | -5 | 2016-07-03T18:12:36Z | 38,173,146 | <p>Several obvious errors to this one:</p>
<ol>
<li><p>You aren't saving num after each for-loop run through. Since you called <code>getDigitSum(num)</code> with no arguments, there should be an error. Even if it did work (aka you changed the <code>getDigitSum()</code> to <code>getDigitSum(num)</code>, it will still f... | 0 | 2016-07-03T18:35:08Z | [
"python"
] |
Python: Can't convert 'tuple' object to str implicitly | 38,172,934 | <p>I'm trying to get my code to store messages within txt file using json. Each time a new message comes in, it will add the new message to the array.</p>
<p>The structure will be</p>
<pre><code>{
"Messages": {
"Test Contact 2": {
"0": "\"Message 1"
},
"Test Contact 1": {
"0": "\"Message 1\"... | 0 | 2016-07-03T18:13:35Z | 38,172,975 | <p>In your exception handler, you're adding <code>exc.args</code> to a string. The args attribute <a href="https://docs.python.org/3/library/exceptions.html#BaseException.args" rel="nofollow">is a tuple</a>, which can't be converted to a string implicitly. You could...</p>
<pre><code> # print it seperately
prin... | 1 | 2016-07-03T18:16:53Z | [
"python",
"json"
] |
How can I change an attribute value in the DOM using Selenium and Python | 38,172,977 | <p>I'm trying to navigate through a website using Python and Selenium and I've run into an issue that I can't figure out how to solve (assuming it's even possible!)</p>
<pre><code><select id="uniqueid" autocomplete="off" value="10">
<option selected="selected" value="10">10</option>
<option va... | 0 | 2016-07-03T18:17:18Z | 38,174,442 | <p>You can try this but understand that the site may not be OK with you sending whatever for a value. It may still limit the value to 100, etc.</p>
<p>The Javascript part just takes the element you passed it and sets the value to whatever you pass in, e.g. "300".</p>
<pre><code>select = driver.find_element_by_id("uni... | 1 | 2016-07-03T21:21:30Z | [
"javascript",
"python",
"selenium",
"selenium-webdriver"
] |
Conditional regex in python | 38,172,998 | <p>I want to match a string if the firstline of the string contains the given "sub" string. Is this possible in python using a oneliner regex ? </p>
<pre><code>string="abcd - testing xxx
foo bar
end"
</code></pre>
<p>if firstline of string contains:</p>
<pre><code>"abcd - testing"
</code></pre>
<p>Match the whole ... | -5 | 2016-07-03T18:18:54Z | 38,173,058 | <p>Use this: </p>
<pre><code>string = """abcd - testing xxx
foo bar
end"""
sub = "abcd - testing"
def match(string, sub):
return string if sub in string.splitlines()[0] else ''
print match(string, sub)
</code></pre>
<ul>
<li><code>splitlines()</code> will split your main string into lines </li>
<li><code>[0... | 0 | 2016-07-03T18:24:19Z | [
"python",
"regex",
"conditional"
] |
Conditional regex in python | 38,172,998 | <p>I want to match a string if the firstline of the string contains the given "sub" string. Is this possible in python using a oneliner regex ? </p>
<pre><code>string="abcd - testing xxx
foo bar
end"
</code></pre>
<p>if firstline of string contains:</p>
<pre><code>"abcd - testing"
</code></pre>
<p>Match the whole ... | -5 | 2016-07-03T18:18:54Z | 38,173,489 | <p><a href="http://i.stack.imgur.com/EbIH3.png" rel="nofollow"><img src="http://i.stack.imgur.com/EbIH3.png" alt="enter image description here"></a></p>
<p>This will work.</p>
<pre><code>^.*abcd - testing.*\n(?:.*\n?)+$
</code></pre>
| 0 | 2016-07-03T19:13:47Z | [
"python",
"regex",
"conditional"
] |
Python function replacing part of variable | 38,173,080 | <p>I am writing a code for a project in particle physics (using pyroot).</p>
<p>In my first draft, I use the following line </p>
<pre><code>for i in MyTree:
pion.SetXYZM(K_plus_PX, K_plus_PY, K_plus_PZ,K_plus_MM)
</code></pre>
<p>This basically assigns to the pion the values of variables in the parenthesis... | -2 | 2016-07-03T18:26:40Z | 38,325,488 | <p>To access class attributes from string variables you can use python's <code>getattr</code>:</p>
<pre><code>import ROOT
inputfile = ROOT.TFile.Open("somefile.root","read")
inputtree = inputfile.Get("NameOfTTree")
inputtree.Print()
# observe that there are branches
# K_plus_PX
# K_plus_PY
# K_plus_PZ
# K_plus_MM
# K_... | 1 | 2016-07-12T09:53:23Z | [
"python",
"pyroot"
] |
Flask - SQLAlchemy : Code to check the username and password | 38,173,114 | <p>I am doing a Flask-login system(by not using inbuilt LoginManager).
I have a query to check the username and password which is :</p>
<pre><code> query = s.query(Users).filter(Users.email.in_([POST_email]), Users.password.in_([POST_PASSWORD]) )
result = query.first()
</code></pre>
<p>This query is not working. It ... | -2 | 2016-07-03T18:30:56Z | 38,207,011 | <p>Try this code</p>
<pre><code>query = s.query(Users).filter(Users.email==POST_USERNAME, Users.password==POST_PASSWORD)
</code></pre>
| 0 | 2016-07-05T15:12:37Z | [
"python",
"login",
"flask",
"sqlalchemy"
] |
Scraping- Error: No JSON object could be decoded | 38,173,119 | <p>So i'm trying to scrape the table on this page for educational purposes: <a href="https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016" rel="nofollow">https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/... | 0 | 2016-07-03T18:31:37Z | 38,173,152 | <p>You're printing an object, you need to call <code>text</code> attribute . Response object don't have a json attribute . </p>
<pre><code>result = requests.get(url)
print result.text
</code></pre>
<p>If you want to get a json result, you will need to parse the result which is a string and convert it to a dict, and t... | 1 | 2016-07-03T18:35:57Z | [
"python",
"json",
"python-2.7",
"web-scraping",
"python-requests"
] |
Python : Cannot access list element even though it exists | 38,173,175 | <p>I'm trying to write a code to extract data from a website using <strong>Python</strong> and its <em>urllib2</em> and <em>BeautifulSoup</em> libraries.</p>
<p>I tried iterating over the rows of the desired table and then storing the data in each row specified in "td" into a list variable row_data. Event though I can... | -1 | 2016-07-03T18:39:06Z | 38,173,239 | <p>You're getting this error because your list has no elements, <code>row.find_all("td")</code> can't find anything, you either have to check your html structure or use the <code>select</code> method .</p>
<p><code>select()</code> return all elements slected via a CSSS selector, it's pretty powerful, your code will be... | 0 | 2016-07-03T18:47:21Z | [
"python",
"beautifulsoup",
"urllib2"
] |
Python : Cannot access list element even though it exists | 38,173,175 | <p>I'm trying to write a code to extract data from a website using <strong>Python</strong> and its <em>urllib2</em> and <em>BeautifulSoup</em> libraries.</p>
<p>I tried iterating over the rows of the desired table and then storing the data in each row specified in "td" into a list variable row_data. Event though I can... | -1 | 2016-07-03T18:39:06Z | 38,173,243 | <p>Your output shows that at least one of the rows is <em>empty</em>:</p>
<pre><code>[]Traceback (most recent call last):
^^
</code></pre>
<p>That <code>[]</code> is an empty list, the output was produced by your <code>print row_datas</code> line. Normally I'd expect there to be a newline between that and the <code>T... | 2 | 2016-07-03T18:47:40Z | [
"python",
"beautifulsoup",
"urllib2"
] |
Import media on python gives Import Error | 38,173,198 | <p>Here is the piece of code:</p>
<pre><code>from PIL import Image
from pygraphics import media
toy_story = media.Movie()
</code></pre>
<p>I get the following error:</p>
<pre><code>ImportError: No module named 'Image'
</code></pre>
<p>If I comment out the <code>from pygraphics import media</code> line it works. Bu... | 2 | 2016-07-03T18:41:45Z | 38,173,335 | <p>In your terminal, run <code>python3 -m pip install <module_name></code>. <code>pip</code> has likely installed the module for python2, which you can verify by running <code>help("modules")</code> in python2 and python3. Running <code>pip -V</code> will also tell you which version of Python <code>pip</code> is ... | 0 | 2016-07-03T18:59:05Z | [
"python",
"python-imaging-library",
"python-import",
"python-module"
] |
How to ensure fixture getting loaded only once for all testcases in django 1.9? | 38,173,200 | <p>I'm working on test cases for my project where I've to use fixture for data. The fixture is quite big (around 20 MB) for entire project. Since the project involves multiple apps so I want that the fixture gets loaded only once when I run tests. Specifying fixtures on each test cases as well as using keepdb flag is n... | 0 | 2016-07-03T18:41:57Z | 38,188,168 | <h2>Speed up fixture loading.</h2>
<p>First you need the fixture as a CSV. If you already have a CSV serializer installed, you are in luck. Or connect with psql or pgadmin and create a CSV dump and skip the next bit. </p>
<p>To create a CSV from your existing fixture, just one of your tests, with the -k flag to mana... | 0 | 2016-07-04T15:29:13Z | [
"python",
"django",
"unit-testing",
"testing"
] |
curl works fine, except if I call it with subprocess | 38,173,230 | <p>I have a curl that looks a bit like this:</p>
<pre><code>curl -1 -X POST --user "xxx:yyy" -d "status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical" "https://api.bitbucket.org/1.0/reposit... | 6 | 2016-07-03T18:46:23Z | 38,174,204 | <p>I can't answer your question about using the <code>curl</code> command in <code>subprocess</code>, but it might work if you just call <code>os.system</code> Like this:</p>
<pre><code>import os
os.system ("curl -1 -X POST --user \"xxx:yyy\" -d \"status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A654... | 1 | 2016-07-03T20:48:52Z | [
"python",
"curl",
"https"
] |
curl works fine, except if I call it with subprocess | 38,173,230 | <p>I have a curl that looks a bit like this:</p>
<pre><code>curl -1 -X POST --user "xxx:yyy" -d "status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical" "https://api.bitbucket.org/1.0/reposit... | 6 | 2016-07-03T18:46:23Z | 38,174,228 | <p>The only point of having a shell, in this scenario, is to split your string into a set of arguments.</p>
<p>Thing is, you don't need anything to do that for you -- you can do it more accurately and consistently yourself!</p>
<pre><code>subprocess.call([
'curl',
'-1',
'-X', 'POST',
'--user', 'xxx:yyy',
'... | 1 | 2016-07-03T20:51:18Z | [
"python",
"curl",
"https"
] |
curl works fine, except if I call it with subprocess | 38,173,230 | <p>I have a curl that looks a bit like this:</p>
<pre><code>curl -1 -X POST --user "xxx:yyy" -d "status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical" "https://api.bitbucket.org/1.0/reposit... | 6 | 2016-07-03T18:46:23Z | 38,177,988 | <p>If this is useful please upvote Andrae's answer, it set me on the right path.</p>
<p>looking at the error message:</p>
<pre><code>curl: (1) Protocol "https not supported or disabled in libcurl
</code></pre>
<p>see <code>"https</code> is the problem, <code>https</code> on the other hand works fine.</p>
<p>The iss... | 0 | 2016-07-04T06:18:23Z | [
"python",
"curl",
"https"
] |
Problems installing module for python 3.5 | 38,173,340 | <p>Here is a possible duplicate of: <a href="http://stackoverflow.com/questions/35261468/how-to-use-pip-with-python3-5-after-upgrade-from-3-4">How to use pip with python3.5 after upgrade from 3.4?</a>
I'm a newbie to the Python world. I was hoping someone might point me in the right direction.</p>
<p><strong>My curren... | 1 | 2016-07-03T18:59:33Z | 38,173,357 | <p><code>sudo apt-get install python3-pip</code> can only ever install <code>pip</code> into the system-provided Python version.</p>
<p>You'll need to get pip for Python 3.5. Python 3.5 comes with a module for this, called <a href="https://docs.python.org/3/library/ensurepip.html" rel="nofollow"><code>ensurepip</code>... | 2 | 2016-07-03T19:00:53Z | [
"python",
"ubuntu",
"pip",
"python-3.5"
] |
Conditional statements not working properly | 38,173,409 | <p>I wrote this script in python to send data over serial communication to my Arduino UNO. It uses the OpenCV library to process a binary image and takes decisions based on the position of the detected object.</p>
<p>Here's the script:- </p>
<pre><code>import numpy as np
import cv2
import serial
ser = serial.Serial('... | 0 | 2016-07-03T19:06:06Z | 38,173,898 | <p>Okay I figured it out. Putting what I did here, for people who are curious and for those who need help.</p>
<p>It was probably the Arduino, autoresetoverserialcomm, for some reason the Arduino auto-resets whenever you send a value over the serial comm to the Arduino from a computer, not from the Serial port (obviou... | 0 | 2016-07-03T20:06:59Z | [
"python",
"opencv",
"image-processing",
"arduino-uno",
"pyserial"
] |
Displaying images from url in tkinter | 38,173,526 | <p>As title says, I want to display image from url, without downloading. My code so far:</p>
<pre><code>from bs4 import BeautifulSoup as soup
from tkinter import *
import urllib.parse
from PIL import Image, ImageTk
import io
website = "http://www.porcys.com/review/"
openWebsite = soup(urllib.request.urlopen(website),... | 0 | 2016-07-03T19:19:10Z | 38,175,814 | <p><a href="http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm" rel="nofollow">http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm</a>
provides an explanation.</p>
<blockquote>
<p>When you add a PhotoImage or other Image object to a Tkinter widget,
you must keep your own reference to the i... | 1 | 2016-07-04T01:26:04Z | [
"python",
"tkinter",
"python-3.5"
] |
How to resolve "chromedriver executable needs to be in PATH" error when running Selenium Chrome using virtualenv within PyDev? | 38,173,541 | <p>Short:</p>
<p>Having read <strong>Controlling the Browser with the selenium Module</strong> at <a href="https://automatetheboringstuff.com/chapter11" rel="nofollow">https://automatetheboringstuff.com/chapter11</a>, I am trying to run the Selenium Chrome driver in a virtual environment from PyDev. I have managed to... | 4 | 2016-07-03T19:20:59Z | 38,191,211 | <p>Not sure if this is the best thing to do, but I have found something that seems to work: I have added to my interpreter the already available variable named PATH, and I have edited that variable's value to include the relative path to my project's virtual environment's <code>bin</code> directory (ie, the directory w... | 1 | 2016-07-04T19:32:26Z | [
"python",
"selenium",
"virtualenv",
"pydev",
"selenium-chromedriver"
] |
How to resolve "chromedriver executable needs to be in PATH" error when running Selenium Chrome using virtualenv within PyDev? | 38,173,541 | <p>Short:</p>
<p>Having read <strong>Controlling the Browser with the selenium Module</strong> at <a href="https://automatetheboringstuff.com/chapter11" rel="nofollow">https://automatetheboringstuff.com/chapter11</a>, I am trying to run the Selenium Chrome driver in a virtual environment from PyDev. I have managed to... | 4 | 2016-07-03T19:20:59Z | 39,921,189 | <p>If all attempts to put chromedriver in your PATH fail, you can also hand the executable path to webdriver.Chrome() like so:</p>
<pre><code>chromedriver_loc = '/path/to/chromedriver'
driver = webdriver.Chrome(executable_path=chromedriver_loc)
</code></pre>
<p>This was my eventual solution when trying to run chromed... | 0 | 2016-10-07T15:45:43Z | [
"python",
"selenium",
"virtualenv",
"pydev",
"selenium-chromedriver"
] |
Python Numpy generate coordinates for X and Y values in a certain range | 38,173,572 | <p>I am trying to generate an array of coordinates that will lie on an image.
The image being used is a 640x480 pixel frame. I have been able to make an array of all the <strong>x</strong> and <strong>y</strong> points that I wish to use. I am trying to plot small circles at each of these points just for visualization ... | 3 | 2016-07-03T19:23:58Z | 38,173,681 | <p>You can generate all the possible combinations with numpy's <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.mgrid.html" rel="nofollow">mgrid</a>:</p>
<pre><code>>>> py, px = np.mgrid[5:480:5, 5:640:5]
>>> points = np.c_[py.ravel(), px.ravel()]
>>> points
array([[ 5, ... | 3 | 2016-07-03T19:37:57Z | [
"python",
"arrays",
"numpy",
"coordinates"
] |
Python Numpy generate coordinates for X and Y values in a certain range | 38,173,572 | <p>I am trying to generate an array of coordinates that will lie on an image.
The image being used is a 640x480 pixel frame. I have been able to make an array of all the <strong>x</strong> and <strong>y</strong> points that I wish to use. I am trying to plot small circles at each of these points just for visualization ... | 3 | 2016-07-03T19:23:58Z | 38,173,704 | <p>You can use <code>itertools.product</code> which will basically return all possible combinations of the provided lists. See this code for an example:</p>
<pre><code>import numpy as np
import itertools
Xpts=[5, 10, 15, 20, 25, 30, 35]
Ypts=[5, 10, 15]
Points = np.array(list(itertools.product(Xpts, Ypts)))
</code><... | 3 | 2016-07-03T19:41:04Z | [
"python",
"arrays",
"numpy",
"coordinates"
] |
Python Numpy generate coordinates for X and Y values in a certain range | 38,173,572 | <p>I am trying to generate an array of coordinates that will lie on an image.
The image being used is a 640x480 pixel frame. I have been able to make an array of all the <strong>x</strong> and <strong>y</strong> points that I wish to use. I am trying to plot small circles at each of these points just for visualization ... | 3 | 2016-07-03T19:23:58Z | 38,173,765 | <p>Inspired by <a href="http://stackoverflow.com/a/38073913/3293881"><code>this solution</code></a> and with focus on performance, you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html" rel="nofollow"><code>np.meshgrid</code></a> as well -</p>
<pre><code>X2D,Y2D = np.meshgrid(Ypt... | 1 | 2016-07-03T19:48:14Z | [
"python",
"arrays",
"numpy",
"coordinates"
] |
Python Numpy generate coordinates for X and Y values in a certain range | 38,173,572 | <p>I am trying to generate an array of coordinates that will lie on an image.
The image being used is a 640x480 pixel frame. I have been able to make an array of all the <strong>x</strong> and <strong>y</strong> points that I wish to use. I am trying to plot small circles at each of these points just for visualization ... | 3 | 2016-07-03T19:23:58Z | 38,173,767 | <p>People have already suggested numpy.mgrid and itertools. Use them.</p>
<p>However, for the sake of education, Python provides us with a powerful concept known as "list comprehension". You can obtain the Cartesian product by running:</p>
<pre><code>[(a,b) for a in range(5, 485, 5) for b in range(5, 645, 5)]
</code>... | 1 | 2016-07-03T19:48:22Z | [
"python",
"arrays",
"numpy",
"coordinates"
] |
Python function divisible | 38,173,573 | <p>stuck on this exercise. </p>
<p>INSTRUCTIONS </p>
<blockquote>
<p>First, def a function called <code>cube</code> that takes an argument called
<code>number</code>. Don't forget the parentheses and the colon!</p>
<p>Make that function return the cube of that number (i.e. that number
multiplied by itself ... | -3 | 2016-07-03T19:24:03Z | 38,173,586 | <p>Try this :</p>
<pre><code>def cube(number):
return number * number * number
</code></pre>
<p>x ** y means x ^y (x raised to the power y) . Using that, you can also do :</p>
<pre><code>def cube(number):
return number ** 3
</code></pre>
| 1 | 2016-07-03T19:25:44Z | [
"python"
] |
Python function divisible | 38,173,573 | <p>stuck on this exercise. </p>
<p>INSTRUCTIONS </p>
<blockquote>
<p>First, def a function called <code>cube</code> that takes an argument called
<code>number</code>. Don't forget the parentheses and the colon!</p>
<p>Make that function return the cube of that number (i.e. that number
multiplied by itself ... | -3 | 2016-07-03T19:24:03Z | 38,173,597 | <p>Try this: </p>
<pre><code>def cube(number):
return number ** 3
</code></pre>
<p>Super simple. <code>**</code> is the exponentiation operator, not the multiplication operator.</p>
| 1 | 2016-07-03T19:26:52Z | [
"python"
] |
Python function divisible | 38,173,573 | <p>stuck on this exercise. </p>
<p>INSTRUCTIONS </p>
<blockquote>
<p>First, def a function called <code>cube</code> that takes an argument called
<code>number</code>. Don't forget the parentheses and the colon!</p>
<p>Make that function return the cube of that number (i.e. that number
multiplied by itself ... | -3 | 2016-07-03T19:24:03Z | 38,173,599 | <p><code>number ** number ** number</code> isn't the cube of <code>number</code>, rather it is the 3rd <a href="https://en.wikipedia.org/wiki/Tetration" rel="nofollow">tetration</a> of number. </p>
<p>In your cube function, you could use <code>math.pow</code> if you're going to need other math functions or simply <cod... | 2 | 2016-07-03T19:27:02Z | [
"python"
] |
Python function divisible | 38,173,573 | <p>stuck on this exercise. </p>
<p>INSTRUCTIONS </p>
<blockquote>
<p>First, def a function called <code>cube</code> that takes an argument called
<code>number</code>. Don't forget the parentheses and the colon!</p>
<p>Make that function return the cube of that number (i.e. that number
multiplied by itself ... | -3 | 2016-07-03T19:24:03Z | 38,173,601 | <p><code>**</code> is not the multiplication operator, it's the power operator. Your <code>cube</code> function actually returns x<sup>x<sup>x</sup></sup>, not xxx. You should use the <code>*</code> (multiplication) operator instead:</p>
<pre><code>def cube(number):
return number * number * number
# Here ---... | 1 | 2016-07-03T19:27:12Z | [
"python"
] |
python multiline string in a column to row in csv | 38,173,625 | <p>Need some idea on how to handle this scenario in python
i am using python version 3.5.2</p>
<p>And i am 2 days old in python skills.</p>
<p>I have a csv file with a multiline string in a column</p>
<p>Example: I have 3 column and the 3rd column contains multiline strings</p>
<p><strong>what i have</strong></p... | 0 | 2016-07-03T19:29:08Z | 38,173,858 | <p>The following example code can expand a line of your csv file to multiple lines.</p>
<pre><code>line = ["AppZok", "wendy1", "car one\n bike two\n jeep one"]
def expand_column(line, col):
new_rows = map(lambda p: p.strip().split(" "), line[col].split("\n"))
return map(lambda row: line[:col] + row + line[col... | 0 | 2016-07-03T20:01:22Z | [
"python",
"csv"
] |
python multiline string in a column to row in csv | 38,173,625 | <p>Need some idea on how to handle this scenario in python
i am using python version 3.5.2</p>
<p>And i am 2 days old in python skills.</p>
<p>I have a csv file with a multiline string in a column</p>
<p>Example: I have 3 column and the 3rd column contains multiline strings</p>
<p><strong>what i have</strong></p... | 0 | 2016-07-03T19:29:08Z | 38,174,329 | <p>Newline characters in CSV are valid characters, there is no escape sequence for them. You need to interpret those literal <code>\n</code> strings as delimiters. Then split the values and build out your rows.</p>
<pre><code>import csv
with open(inpath, 'r') as infile,\
open(outpath, 'w', newline='') as outfil... | 0 | 2016-07-03T21:05:17Z | [
"python",
"csv"
] |
Updating a Label widget in Kivy | 38,173,661 | <p>I have a Label on Kivy defined in KV like this:</p>
<pre><code>Label:
id: vol
text: '[color=#3333ff]Volume: {0:8.2f}[/color]'
markup: True
size_hint_x: 0.2
</code></pre>
<p>Every few seconds, I update it with code that look like this: </p>
<pre><code>self.vol.text = self.vol.text.format(tick['volu... | 0 | 2016-07-03T19:34:40Z | 38,174,335 | <p>Once the first replacement has taken place, there is no replacement field left to take the updated value. Instead, try something like this:</p>
<pre><code>self.vol.text = '[color=#3333ff]Volume: {0:8.2f}[/color]'.format(tick['volume'])
</code></pre>
<p>If you want, you can subclass <code>Label</code> and add a cus... | 1 | 2016-07-03T21:06:07Z | [
"python",
"kivy",
"kivy-language"
] |
Pyalgotrade - AttributeError: 'SequenceDatasSeries' object has no attribute 'getHighDataSeries' | 38,173,724 | <p>I'm using pyalgotrade to write a trading algo. I got the error above and can't seem to fix it. I'm trying to use the "SLOW STOCHASTIC", any help on solving this error and getting the slow stochastic to work is greatly appreciated:</p>
<p>Error:</p>
<pre><code>C:\Users\...\Desktop>python bobo.py
Traceback (most ... | 0 | 2016-07-03T19:43:32Z | 38,190,886 | <p>Try this:</p>
<pre><code>self.__stoch = indicator.STOCH(feed[instrument],fastk_period,slowk_period,slowd_period)
</code></pre>
<p>The stochastic oscillator is expecting a bar dataseries, not a regular one.</p>
| 0 | 2016-07-04T19:04:10Z | [
"python",
"error-handling",
"attributes",
"ta-lib",
"pyalgotrade"
] |
Why does pyro4 fail to locate nameserver under 127.0.1.1 but succeed with 127.0.0.1? | 38,173,834 | <p>I am trying to run a pyro4 server with a custom event loop on a Raspberry Pi running Raspbian 8 (jessie). When I create a nameserver using the hostname obtained from socket.gethostname(), specifically 'raspberrypi', my client script cannot find the nameserver. When I use 'localhost' as the hostname, my client script... | 1 | 2016-07-03T19:58:42Z | 38,174,615 | <p>Pyro's name server lookup relies on two things:</p>
<ul>
<li>broadcast lookup</li>
<li>direct lookup by hostname/ip-address</li>
</ul>
<p>The first is not available when you're using the loopback adapter to bind the name server on (loopback doesn't support broadcast sockets). So we're left with the second one.
The... | 0 | 2016-07-03T21:45:59Z | [
"python",
"pyro"
] |
Python Parser for programming beginner (german umlaute needed) | 38,173,838 | <p>I was hoping someone could give me some feedback on the following package:</p>
<p><a href="http://infohost.nmt.edu/tcc/help/pubs/pyparsing/pyparsing.pdf" rel="nofollow">Pyparsing</a></p>
<p>I want to write a python program that takes as input a .txt file, and as output some kind of structured data in .csv or even ... | 1 | 2016-07-03T19:59:19Z | 38,173,914 | <p>On page 46 of your documentation is the section 7.15.printables: All the printable non-whitespace character. These are listed:</p>
<pre><code>>>> len(pp.printables)
94
>>> print pp.printables
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-
./:;<=>?@[\]^_`{|}~
... | 1 | 2016-07-03T20:09:32Z | [
"python",
"parsing",
"pyparsing"
] |
Python to excel, openpyxl and file format not valid | 38,173,861 | <p>The following is a simple snippet to open a .xlsm file, write a few values to it with python, and save it. </p>
<pre><code>import openpyxl
from openpyxl import load_workbook
def toExcel():
wb = load_workbook(filename="C:\\Users\\Mark\\Documents\\Test.xlsm")
ws = wb.worksheets[0]
ws.cell(row=1, column=1... | 1 | 2016-07-03T20:02:12Z | 38,173,913 | <p>From here: <a href="https://openpyxl.readthedocs.io/en/default/tutorial.html#saving-to-a-file" rel="nofollow">https://openpyxl.readthedocs.io/en/default/tutorial.html#saving-to-a-file</a></p>
<blockquote>
<p>Note</p>
<p>The following will fail:</p>
</blockquote>
<pre><code>>>> wb = load_workbook('d... | 1 | 2016-07-03T20:09:17Z | [
"python",
"openpyxl"
] |
How do I pass in an argument to decorators? | 38,173,899 | <p>Currently I am trying to use a <code>login_required</code> decorator to take in wether the the url endpoint is an API, to determine the return. But currently, it is giving me an error that it is overriding a function. But I have no idea what it is overriding.</p>
<p>Here is my decorators file <a href="https://githu... | -1 | 2016-07-03T20:07:13Z | 38,174,497 | <p>You decorator works alright, here is a Demo:</p>
<pre><code>>>> from functools import wraps
>>>
>>> def p(api=False):
def decorator(f):
@wraps(f)
def decorated_f(*args, **kwargs):
print(api)
return f(*args, **kwargs)
return decorated_f
... | 1 | 2016-07-03T21:28:21Z | [
"python",
"flask"
] |
How can I improve the speed my python script? | 38,173,908 | <p>I wrote this really nice python code that will go through a whole list of name or words and stuff and then filters some things and then saves them, but then
I had a big issue and that was the speed, I tryed to fix the issue by doing somethings, but it didn't make any different. So is there a way to improve the spee... | 0 | 2016-07-03T20:08:45Z | 38,173,962 | <p>What you're trying to do, making permutations of a wordlist is simply expensive.</p>
<p>However 2 tips:</p>
<h2>Be careful with system</h2>
<p>system, much like in C, has a lot of overhead. In the innerloop it gets called a lot of times. This will seriously slow it down.</p>
<pre><code>for word in words:
... | 0 | 2016-07-03T20:17:01Z | [
"python",
"python-2.7"
] |
How can I improve the speed my python script? | 38,173,908 | <p>I wrote this really nice python code that will go through a whole list of name or words and stuff and then filters some things and then saves them, but then
I had a big issue and that was the speed, I tryed to fix the issue by doing somethings, but it didn't make any different. So is there a way to improve the spee... | 0 | 2016-07-03T20:08:45Z | 38,173,966 | <p>Calling <code>clear</code> for every word slows down your program dramatically. Remove these calls. Your program is IO bound, so speeding it up, means speeding up writing. Use a SSD. Use sets instead of lists:</p>
<pre><code>#!/usr/bin/env python
import os
import sys
def generate(lst, save):
with open(lst, 'r'... | 1 | 2016-07-03T20:17:35Z | [
"python",
"python-2.7"
] |
Python 3.5 BytesIO error | 38,173,918 | <p>I am making a project all in python 2.7 but it started to give some errors to me on the final parts since the documentation is in python 3.5. So i am changing everything to python 3.5, but it is giving me a error because of bytesIO. Can you help me to understand why, and what should i do? The error is coming from de... | 0 | 2016-07-03T20:10:42Z | 38,177,060 | <p>As I mentioned on my comment, <a href="https://docs.python.org/3/library/io.html#io.BytesIO" rel="nofollow"><code>BytesIO</code></a> requires <a href="https://docs.python.org/3/glossary.html#term-bytes-like-object" rel="nofollow"><code>byte-like object</code></a>.</p>
<p>Demo:</p>
<pre><code>>>> from io i... | 0 | 2016-07-04T04:39:16Z | [
"python",
"python-2.7",
"python-3.x",
"bytesio"
] |
Python 3.5 BytesIO error | 38,173,918 | <p>I am making a project all in python 2.7 but it started to give some errors to me on the final parts since the documentation is in python 3.5. So i am changing everything to python 3.5, but it is giving me a error because of bytesIO. Can you help me to understand why, and what should i do? The error is coming from de... | 0 | 2016-07-03T20:10:42Z | 38,177,064 | <p>For Python 3, just change <code>BytesIO</code> to <code>StringIO</code>. Python 3 strings are Unicode strings instead of byte strings, and <code>__repr__</code> should return a Unicode string in Python 3.</p>
<p>If you try to return a bytes object like some other answers suggest, you will get:</p>
<pre><code>Type... | 1 | 2016-07-04T04:40:01Z | [
"python",
"python-2.7",
"python-3.x",
"bytesio"
] |
Using infinite scroll with Django Rest Framework? | 38,173,984 | <p>I am creating a REST API using Django Rest Framework. The API will serve large amount of data and I want to use infinite scrolling on the page. I would like to use Angular for the frontend. I am not sure how to serve the data such that not all data has to be sent once but only when the user scrolls down.</p>
<p>I a... | 2 | 2016-07-03T20:20:58Z | 38,185,442 | <p>You should give <a href="http://www.django-rest-framework.org/api-guide/pagination/#cursorpagination" rel="nofollow">CursorPagination</a> a try.
I don't know exactly whether it's infinite or not but it's definitively for huge sets.</p>
| 0 | 2016-07-04T13:01:48Z | [
"python",
"django",
"rest",
"django-rest-framework",
"infinite-scroll"
] |
Using infinite scroll with Django Rest Framework? | 38,173,984 | <p>I am creating a REST API using Django Rest Framework. The API will serve large amount of data and I want to use infinite scrolling on the page. I would like to use Angular for the frontend. I am not sure how to serve the data such that not all data has to be sent once but only when the user scrolls down.</p>
<p>I a... | 2 | 2016-07-03T20:20:58Z | 38,218,402 | <p>Create a ListAPIView subclass</p>
<pre><code>from rest_framework import pagination, generics
class CompanyPagination(pagination.PageNumberPagination):
page_size = 20 # the no. of company objects you want to send in one go
# Assume url for this view is /api/v1/companies/
class CompanyListView(generics.ListAPI... | 0 | 2016-07-06T07:27:55Z | [
"python",
"django",
"rest",
"django-rest-framework",
"infinite-scroll"
] |
Python selenium send_keys not working | 38,173,985 | <p>I am using selenium to scarp twitter(not using the api's just practicing seleinum) which require login when it coms to following page, am using the following code to locate the login input fields and then send the username and password string: </p>
<pre><code>from selenium import webdriver
from selenium.webdriver.c... | 1 | 2016-07-03T20:21:02Z | 38,174,567 | <p>Instead of sending the ENTER key, just click on the Log in button. Also, your XPath is kinda brittle. I would use a more specific one or you can use the CSS selectors below.</p>
<pre><code>driver.find_element_by_css_selector("#page-container input.email-input").send_keys(username);
driver.find_element_by_css_select... | 1 | 2016-07-03T21:38:11Z | [
"python",
"selenium",
"web-scraping"
] |
Sorting from multiple loops | 38,174,105 | <p>I have 7 different loops grabbing information from different places in the same format but as they're coming from different areas the data is muddled up.</p>
<pre><code>for event in soup.find('dual').find_all('event'):
print event
for event in soup.find('int').find_all('event'):
print event
</code></pre>
<p>I w... | -2 | 2016-07-03T20:36:20Z | 38,174,611 | <pre><code>master_list = []
for event in soup.find('dual').find_all('event'):
master_list.append(event)
for event in soup.find('int').find_all('event'):
master_list.append(event)
for event in soup.find('whatever').find_all('event'):
master_list.append(event)
print sorted(event)
</code></pre>
<p>You may... | 0 | 2016-07-03T21:45:28Z | [
"python",
"sorting"
] |
Python recursion with yield and return in nested dictionary | 38,174,116 | <p>I'm trying to learn the use of yield and return in recursive function. I've a nested dictionary where I'm searching for a particular value.</p>
<p>When using "yield", the following function runs fine and returns the found value successfully:</p>
<pre><code>def findvalue (value, document):
if isinstance (docume... | 0 | 2016-07-03T20:37:41Z | 38,174,271 | <p>I believe you can change this:</p>
<pre><code>for result in valuefind(value, v):
if result is not None:
return result
</code></pre>
<p>To this:</p>
<pre><code>return valuefind(value, v)
</code></pre>
| 0 | 2016-07-03T20:57:56Z | [
"python",
"python-3.x",
"dictionary",
"recursion"
] |
explain to me like i'm five: record to network stream, raspberry pi python script | 38,174,139 | <p><a href="http://picamera.readthedocs.io/en/release-1.10/recipes1.html#recording-to-a-network-stream" rel="nofollow">http://picamera.readthedocs.io/en/release-1.10/recipes1.html#recording-to-a-network-stream</a> </p>
<p>^this is an example code snipped found in the raspberry pi camera documentation website. </p>
<p... | -3 | 2016-07-03T20:40:49Z | 38,174,235 | <p>A network stream flows between a source and a destination. </p>
<p>For the bit before 'however, this recipe' the destination server side runs where you want to capture rhe network stream. You save the serverside script to your pc or laptop and run it there. The source client side runs on your pi.</p>
<p>For the bi... | 1 | 2016-07-03T20:51:58Z | [
"python",
"camera",
"raspberry-pi"
] |
Group dataframe and get sum AND count? | 38,174,155 | <p>I have a dataframe that looks like this:</p>
<pre><code> Company Name Organisation Name Amount
10118 Vifor Pharma UK Ltd Welsh Assoc for Gastro & Endo 2700.00
10119 Vifor Pharma UK Ltd Welsh IBD Specialist Group, 169.00
10120 Vifor Pharma UK Ltd West Midlands AHSN ... | 1 | 2016-07-03T20:42:43Z | 38,174,164 | <p>try this:</p>
<pre><code>In [110]: (df.groupby('Company Name')
.....: .agg({'Organisation Name':'count', 'Amount': 'sum'})
.....: .reset_index()
.....: .rename(columns={'Organisation Name':'Organisation Count'})
.....: )
Out[110]:
Company Name Amount Organisation Count
0 Vifor Pha... | 1 | 2016-07-03T20:44:23Z | [
"python",
"pandas"
] |
Gstreamer dynamically change source before EOS | 38,174,156 | <p>I'm trying to create a dynamic pipeline with Gstreamer 1.8.2 and Python 3.5. The goal is to be able to playback some video and change it at EOS, achieving gapless playback in a way similar to using about-to-finish of playbin.</p>
<p>My idea is filesrc -> decodebin -> queue -> videosink, then place a probe on decode... | 1 | 2016-07-03T20:42:52Z | 38,185,187 | <p>Well what can I tell you - use concat or videomixer/audiomixer (I prefer concat way) .. you do not need any custom solutions :)</p>
<p>Concat does exactly what you want it switches to another source upon EOS of current source.. <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-plugins/htm... | 2 | 2016-07-04T12:48:36Z | [
"python",
"gstreamer"
] |
Hashing a generator expression | 38,174,211 | <p>Apparently python will allow me to hash a generator expression like <code>(i for i in [1, 2, 3, 4, 5])</code></p>
<pre><code>>>> hash(i for i in [1, 2, 3, 4, 5])
8735741846615
</code></pre>
<p>On closer inspection however, this hash value is always the same no matter what generator I put into it!</p>
<pr... | 4 | 2016-07-03T20:49:29Z | 38,174,273 | <p>The hash value is presumably based on the object identity, not its contents. You're probab;y seeing that result because you're not storing the generators, so they're garbage collected and their ids are re-used. Here are some other examples that show it's not just a single hash all the time:</p>
<pre><code>>>... | 3 | 2016-07-03T20:58:12Z | [
"python",
"hash",
"generator"
] |
Hashing a generator expression | 38,174,211 | <p>Apparently python will allow me to hash a generator expression like <code>(i for i in [1, 2, 3, 4, 5])</code></p>
<pre><code>>>> hash(i for i in [1, 2, 3, 4, 5])
8735741846615
</code></pre>
<p>On closer inspection however, this hash value is always the same no matter what generator I put into it!</p>
<pr... | 4 | 2016-07-03T20:49:29Z | 38,174,390 | <p>Python <code>object</code> allows hash and equality: <code>hash(object())</code>.</p>
<p>The 'unhashtable type' is a <em>purposeful restriction</em> on core <em>mutable collections</em> (ie. <code>list</code>) <em>with a defined content-equality comparison</em> because this avoids some common programming errors. Mo... | 0 | 2016-07-03T21:13:54Z | [
"python",
"hash",
"generator"
] |
Hashing a generator expression | 38,174,211 | <p>Apparently python will allow me to hash a generator expression like <code>(i for i in [1, 2, 3, 4, 5])</code></p>
<pre><code>>>> hash(i for i in [1, 2, 3, 4, 5])
8735741846615
</code></pre>
<p>On closer inspection however, this hash value is always the same no matter what generator I put into it!</p>
<pr... | 4 | 2016-07-03T20:49:29Z | 38,174,405 | <p>So there are two questions here actually:</p>
<ol>
<li>Why do generators have a hash, when e.g. lists do not? </li>
<li>Why do you always get the same hash?</li>
</ol>
<p>For 2, the answer is simple: In this case, hash is based on the object's <code>id</code>. Since you don't actually store the object, its memory ... | 5 | 2016-07-03T21:17:05Z | [
"python",
"hash",
"generator"
] |
Hashing a generator expression | 38,174,211 | <p>Apparently python will allow me to hash a generator expression like <code>(i for i in [1, 2, 3, 4, 5])</code></p>
<pre><code>>>> hash(i for i in [1, 2, 3, 4, 5])
8735741846615
</code></pre>
<p>On closer inspection however, this hash value is always the same no matter what generator I put into it!</p>
<pr... | 4 | 2016-07-03T20:49:29Z | 38,174,604 | <blockquote>
<p><strong>generator expression</strong> </p>
<p>An expression that returns an iterator</p>
</blockquote>
<p>If iterators are <em>hashable</em>, generator expressions should not be an exception. Iterators are <em>stateful</em>, not sure about <em>mutable</em>. Or would <em>stateful</em> mean <em>mu... | 0 | 2016-07-03T21:44:59Z | [
"python",
"hash",
"generator"
] |
Can't log in to admin site in Django | 38,174,216 | <p>I was working through the polls tutorial and everything was fine until I tried to log in to the admin site; it just said </p>
<blockquote>
<p>"Please enter the correct username and password for a staff account. Note that both fields may be case-sensitive."</p>
</blockquote>
<p>So I Googled the issue and tried ev... | 0 | 2016-07-03T20:49:44Z | 38,182,423 | <p>I guess you would have created this user through other ways and not <code>python manage.py createsuperuser</code></p>
<p>This happens when you have two authentication systems. ie.,. you might have django inbuilt authentication and (for example) DRF token based authentication. </p>
<p>To login to the backend(django... | 0 | 2016-07-04T10:26:21Z | [
"python",
"django"
] |
Iterating through keys and values of dictionaries without staircase like structure | 38,174,237 | <p>Is there a way, and if so could someone show me how to get the same result in <code>conf</code> as the code below, without having to do that long staircase like structure for iterating through both keys and values of the two dictionaries? </p>
<pre><code>conf = 0
def dist(instr):
return {x:instr.count(x)/float... | 0 | 2016-07-03T20:52:05Z | 38,174,369 | <p>If all you need is <em>matching</em> keys, just look up the key in the other dictionary:</p>
<pre><code>d1 = dist('as')
for k, v in dist('aass').items():
if k in d1:
conf += 1.5 if d1[k] == v else .5
</code></pre>
<p>You could also create the set intersection of the dictionary keys; in Python 2 you'd u... | 4 | 2016-07-03T21:09:13Z | [
"python"
] |
Python OpenCV plot circles at a list of centre coordinates | 38,174,256 | <p>I have been able to generate a list of coordinates that i would like to use as the centres of mulltiple small circles that i would like to plot on an image.</p>
<p>I am able to plot circles at individual points but have not been able to find the correct syntax for plotting circles at all of the centres. The coordin... | 1 | 2016-07-03T20:55:06Z | 38,174,384 | <p>Does this work:</p>
<pre><code>for point in Points:
cv2.circle(frame1, points, 1,(0,0,255))
</code></pre>
| 0 | 2016-07-03T21:13:14Z | [
"python",
"arrays",
"opencv",
"plot",
"circle"
] |
Python OpenCV plot circles at a list of centre coordinates | 38,174,256 | <p>I have been able to generate a list of coordinates that i would like to use as the centres of mulltiple small circles that i would like to plot on an image.</p>
<p>I am able to plot circles at individual points but have not been able to find the correct syntax for plotting circles at all of the centres. The coordin... | 1 | 2016-07-03T20:55:06Z | 38,189,321 | <p>I managed to find the answer with help from Joel using the following code:</p>
<pre><code> for point in Points:
cv2.circle(frame1,tuple(point),1,(0,0,255))
</code></pre>
| 0 | 2016-07-04T16:49:44Z | [
"python",
"arrays",
"opencv",
"plot",
"circle"
] |
GAE datastore restore stops with The API call urlfetch.Fetch() took too long to respond and was cancelled | 38,174,380 | <p>I am following this guide <a href="https://cloud.google.com/appengine/docs/python/console/datastore-backing-up-restoring#restoring_data_to_another_app" rel="nofollow">https://cloud.google.com/appengine/docs/python/console/datastore-backing-up-restoring#restoring_data_to_another_app</a>
on how to backup data in one G... | 0 | 2016-07-03T21:12:36Z | 38,234,646 | <p>Your urlfetch.Fetch() is taking too long (greater than 60 seconds) to respsond and so it is timing out. Here is an article about it <a href="https://cloud.google.com/appengine/articles/deadlineexceedederrors" rel="nofollow">https://cloud.google.com/appengine/articles/deadlineexceedederrors</a></p>
<p>One solution i... | 0 | 2016-07-06T22:11:45Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
How can I collect this data from a div using Selenium and Python | 38,174,490 | <p>I have been using Selenium and Pyton to scrape a webpage and I am having difficulty collecting data that I want out of a div that has the following structure:</p>
<pre><code><div class="col span_6" style="margin-left: 12px;width: 47% !important;">
<div class="MainGridRow">
<span class="MainGrid... | 1 | 2016-07-03T21:27:40Z | 38,174,647 | <p>One way would be to get the the enclosing div i.e the grandparent and pull the spans from that:</p>
<pre><code>h = """<div class="col span_6" style="margin-left: 12px;width: 47% !important;">
<div class="MainGridRow">
<span class="MainGridcolumn1">Heading1</span>
<span class="Ma... | 0 | 2016-07-03T21:50:52Z | [
"python",
"html",
"selenium",
"xpath",
"selenium-webdriver"
] |
Why am I receiving IndexError: list index out of range line 37? | 38,174,513 | <p>I wrote this code to get name, student number and score and then find maximum, report and remove, but I have a problem with remove that I cannot eradicate that. When I run , I get IndexError: list index out of range line on line 37, although I cannot find what it the problem.</p>
<pre><code>c=0
x=[]
y=[]
z=[]
"""o=... | -1 | 2016-07-03T21:30:56Z | 38,174,740 | <p>I think it might be because when you are deleting items, you are not breaking once an item has been deleted. Then, when you get to the end of the list(s) that use to have N elements, you only have N-1 elements left.</p>
<p>Add a break after:</p>
<pre><code>for i in range(len(x)):
if p==z[i]:
x.pop(i)
... | 1 | 2016-07-03T22:05:17Z | [
"python"
] |
What would be the best nearest-neighbor algortihm to use for this application? | 38,174,556 | <p>I have been classifying multiple objects in a sequence of video frames by taking the the list of ordered centroids of each object in the previous frame and computing the euclidean distance to each set of centroids in the current frame and then taking the minimum distance between a set of points as being the same obj... | 0 | 2016-07-03T21:37:00Z | 38,274,572 | <p>As I knew, your main question is to optimize algorithm and get better result from classification. In classification problem, depending on your dataset, it is better to try different algorithm with different parameter(for example in NN, try different Nearest Neighbor Number of point or different algorithm like KNN wi... | 0 | 2016-07-08T20:04:05Z | [
"python",
"image-processing",
"computer-vision",
"classification",
"pattern-recognition"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.