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 |
|---|---|---|---|---|---|---|---|---|---|
Get most informative features from very simple scikit-learn SVM classifier | 39,095,116 | <p>I tried to build the a very simple SVM predictor that I would understand with my basic python knowledge. As my code looks so different from this <a href="http://stackoverflow.com/questions/30017491/problems-obtaining-most-informative-features-with-scikit-learn">question</a> and also this <a href="http://stackoverflo... | 0 | 2016-08-23T07:38:07Z | 39,097,242 | <p>From all feature set, the set of variables which produces the lowest values for square of norm of vector must be chosen as variables of high importance in order</p>
| 0 | 2016-08-23T09:21:36Z | [
"python",
"scikit-learn",
"svm"
] |
Creating another chapter in python game | 39,095,258 | <p>I am creating a game from some code which I got from another question on here and I need help creating another chapter after I kill the bear with sword. How and where do I insert the <strong>goto command</strong> to start working on another chapter. Also if you have any advice or comments that would also be helpful.... | -6 | 2016-08-23T07:46:04Z | 39,096,191 | <p>I think if you carry on down this route, you wont need to add many more rooms/scenarios before the code becomes unmanageable. It will also contain a lot of almost duplicated code to do with presenting the numbered options, reading the response, and presenting the outcome (mostly it seems unpleasant death.....).</p>
... | 3 | 2016-08-23T08:34:33Z | [
"python"
] |
Override __repr__ or pprint for int | 39,095,294 | <p>Is there any way of changing the way a <code>int</code>-type object is converted to string when calling <code>repr</code> or <code>pprint.pformat</code>, such that</p>
<pre><code>repr(dict(a=5, b=100))
</code></pre>
<p>will give <code>"{a: 0x5, b: 0x64}"</code> instead of <code>"{a: 5, b: 100}"</code>?</p>
<p>I s... | 1 | 2016-08-23T07:47:46Z | 39,096,085 | <p><code>int</code> is a builtin type and you can't set attributes of built-in/extension types (you can not override nor add new methods to these types). You could however subclass <code>int</code> and override the <code>__repr__</code> method like this:</p>
<pre class="lang-py prettyprint-override"><code> class In... | 2 | 2016-08-23T08:29:34Z | [
"python",
"python-3.x",
"built-in"
] |
Override __repr__ or pprint for int | 39,095,294 | <p>Is there any way of changing the way a <code>int</code>-type object is converted to string when calling <code>repr</code> or <code>pprint.pformat</code>, such that</p>
<pre><code>repr(dict(a=5, b=100))
</code></pre>
<p>will give <code>"{a: 0x5, b: 0x64}"</code> instead of <code>"{a: 5, b: 100}"</code>?</p>
<p>I s... | 1 | 2016-08-23T07:47:46Z | 39,096,331 | <p>You should be able to monkey patch the <code>pprint</code> module to have integers print the way you want, but this isn't really a good approach.</p>
<p>If you're just looking for a better representation of integers for debugging, IPython has its own pretty printer that is easily customizable through its <a href="h... | 1 | 2016-08-23T08:40:36Z | [
"python",
"python-3.x",
"built-in"
] |
finding the average of values in a column that matches the condition in pythonic way | 39,095,324 | <p>suppose i have the data like this</p>
<pre><code>mpg cylinder
14 4
26 6
45 4
20 4
23 8
21 8
</code></pre>
<p>and my output should be like this</p>
<pre><code>cylinder 4= 14+45+20/3
</code></pre>
<p>and so on</p>
<pre><code>dataset=[]
f= open('auto-mpg-data.csv')
csv_f=csv.reader(f)
for row i... | -5 | 2016-08-23T07:49:35Z | 39,095,534 | <p>Calculating an average from a condition is easy with <code>sum</code> and <code>len</code> after using a list comprehension to filter. For example, to calculate the average <code>mpg</code> where there are four <code>cylinders</code>, you could do:</p>
<pre><code>mpg4cylinder = [m for m, c in zip(mpg, cylinder) if ... | 0 | 2016-08-23T08:01:17Z | [
"python",
"csv"
] |
How to create a singleton class that implements an abstract class, without getting into metaclass conflict? | 39,095,392 | <p>I've read a bunch of useful information on SO as well as the article at <a href="http://www.phyast.pitt.edu/~micheles/python/metatype.html" rel="nofollow">http://www.phyast.pitt.edu/~micheles/python/metatype.html</a></p>
<p>However, I think I still did not find the answer. Hence a new question.</p>
<p>I'm creating... | 2 | 2016-08-23T07:52:55Z | 39,289,901 | <p>Instead of resorting to a metaclass to register your singletons, you can do that on the Base class for your hierarchy - just put the singleton logic on the <code>__new__</code> method instead. That way, you don't have to change the metaclass just due to this aditional behaviors, and abc.metaclasses will just work.</... | 0 | 2016-09-02T10:13:11Z | [
"python",
"python-3.x",
"singleton",
"abstract"
] |
Addition and multiplication of python using single coefficient | 39,095,435 | <p>I would like to add and multiply polynomials using python .
For example, if the Question is: </p>
<pre><code>addpoly([(4,3),(3,0)],[(-4,3),(2,1)])
[(2, 1),(3, 0)] (answer)
</code></pre>
<p>my Code:</p>
<pre><code>def addpoly( x, y):
min_len = min( len(x), len(y))
return x[: -min_len] + y[: -min_len] + [ x[i] + ... | 0 | 2016-08-23T07:55:39Z | 39,095,771 | <p>The simplest way is to convert your polynomial into a <code>dict</code> with <code>power -> coefficient</code> items:</p>
<pre><code>In [1]: p1 = [(4,3),(3,0)]
In [2]: p2 = [(-4,3),(2,1)]
In [3]: from collections import Counter
In [4]: p1_c = Counter(dict((degree, coef) for (coef, degree) in p1))
In [5]: p2_... | 0 | 2016-08-23T08:12:42Z | [
"python",
"python-3.x"
] |
How can i use variable when i used def function [Python] | 39,095,439 | <p>I have small problem. When I make a new function with <code>def</code>, I want change <code>i</code> on the end of function according to some variable. Example:</p>
<pre><code>import time
i = 2
def Happy_1():
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)... | -3 | 2016-08-23T07:56:00Z | 39,095,482 | <p>You can use:</p>
<pre><code>locals()["Happy_" + i]()
</code></pre>
<p>or </p>
<pre><code>globals()["Happy_" + i]()
</code></pre>
<p><code>locals()["Happy_" + i]</code> will get the function from the locals, and the final <code>()</code> will call the function.</p>
| 0 | 2016-08-23T07:58:34Z | [
"python",
"python-3.x"
] |
How can i use variable when i used def function [Python] | 39,095,439 | <p>I have small problem. When I make a new function with <code>def</code>, I want change <code>i</code> on the end of function according to some variable. Example:</p>
<pre><code>import time
i = 2
def Happy_1():
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)... | -3 | 2016-08-23T07:56:00Z | 39,095,581 | <pre><code>import time
i = 2
def Happy_1():
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday dear Paul")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)
print("END")
def Happy_2():
print("Happy Brithday ... | 0 | 2016-08-23T08:03:27Z | [
"python",
"python-3.x"
] |
How can i use variable when i used def function [Python] | 39,095,439 | <p>I have small problem. When I make a new function with <code>def</code>, I want change <code>i</code> on the end of function according to some variable. Example:</p>
<pre><code>import time
i = 2
def Happy_1():
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)... | -3 | 2016-08-23T07:56:00Z | 39,095,798 | <p>I'm pretty sure others are missing the obvious solution here.</p>
<pre><code>def happy(i):
names = ['Paul', 'Peter']
...
print('Happy birthday to {}'.format(names(i)))
</code></pre>
| 2 | 2016-08-23T08:13:38Z | [
"python",
"python-3.x"
] |
How can i use variable when i used def function [Python] | 39,095,439 | <p>I have small problem. When I make a new function with <code>def</code>, I want change <code>i</code> on the end of function according to some variable. Example:</p>
<pre><code>import time
i = 2
def Happy_1():
print("Happy Brithday to you")
time.sleep(1)
print("Happy Brithday to you")
time.sleep(1)... | -3 | 2016-08-23T07:56:00Z | 39,095,834 | <p>Thanks @ Daniel Roseman for pointing this.</p>
<p><strong>Zen of Python - Simple is better than complex.</strong></p>
<p>Please check this code.</p>
<ul>
<li>Function Happy takes one argument. So no need to write two functions.</li>
</ul>
<p></p>
<pre><code>import time
i = 2
def Happy(i):
if i == 1:
... | 0 | 2016-08-23T08:15:42Z | [
"python",
"python-3.x"
] |
group clusters of numbers in array | 39,095,536 | <p>I have an array like:</p>
<pre><code>A = [1,3,8,9,3,7,2,1,3,9,6,8,3,8,8,1,2]
</code></pre>
<p>And I want to count the number of "entry clusters" that are <code>>5</code>. In this case the result should be <code>4</code>, because:</p>
<pre><code>[1, 3, (8,9), 3, (7), 2, 1, 3, (9,6,8), 3, (8,8), 1, 2]
</code></p... | 3 | 2016-08-23T08:01:21Z | 39,095,826 | <p>You could use the <code>groupby</code> function from <code>itertools</code>.</p>
<pre><code>from itertools import groupby
A = [1,3,8,9,3,7,2,1,3,9,6,8,3,8,8,1,2]
result = [tuple(g) for k, g in groupby(A, lambda x: x > 5) if k]
print(result)
# [(8, 9), (7,), (9, 6, 8), (8, 8)]
print(len(result))
# 4
</code></p... | 5 | 2016-08-23T08:15:31Z | [
"python",
"arrays",
"group",
"cluster-computing"
] |
ImportError: No module named phpoob.bank | 39,095,559 | <pre><code>lcl
|
|----|
|----enterprise
|----phpoob
|----|----|
|----|----'bank.py'
|----|
|----'__init__.py'
|----'module.py'
</code></pre>
<p>this is my file structure</p>
<p><code>__init__.py</code>--></p>
<pre><code>from module import LCLModule
__all__ = ['LCLModule']
</code></pre>
<p><code>module.py</code>--><... | 0 | 2016-08-23T08:02:33Z | 39,098,530 | <p>Looks like you are using Python 2.x. Folder <code>phpoob</code> is not treated as Python module. That's why you can't import <code>phpoob.bank</code>.</p>
<p><strong>Solution #1:</strong> Create empty file <code>phpoob/__init__.py</code> After that you will be able to import <code>phpoob</code> and import any file ... | 0 | 2016-08-23T10:22:50Z | [
"python",
"importerror"
] |
Why IMAP4.select() shows more number of mails than present in inbox | 39,095,727 | <p>IMAP4.select() returns more number of mails than present in inbox of gmail.</p>
<pre><code>def login_credentials():
db = MySQLdb.connect("192.168.140.38","admin_newsletter","zxax5575","admin_newsletter" )
cursor = db.cursor()
sql="SELECT email, password FROM readmail_account"
cursor.execute(sql)
... | 0 | 2016-08-23T08:10:39Z | 39,096,282 | <p>The <code>select()</code> function returns count of all the messages.</p>
<blockquote>
<p>Select a mailbox. Returned data is the count of messages in mailbox (EXISTS response). The default mailbox is 'INBOX'. If the readonly flag is set, modifications to the mailbox are not allowed.</p>
</blockquote>
<p>What you... | 0 | 2016-08-23T08:38:49Z | [
"python",
"imap",
"imaplib"
] |
coloring issue - combination of open cv with matplotlib legend | 39,095,745 | <p>I'm currently trying to create a legend manually for several rectangles drawn in an image. But I get confused with the coloring.</p>
<pre><code> color_step = 255/(len(contours)+1)
patch =[]
for cnt_idx, cnt in enumerate(contours):
cnt_color = color_step * (cnt_idx+1)
cv2.rectangle(img,(c... | 2 | 2016-08-23T08:11:33Z | 39,146,009 | <p>The problem was caused by the imshow function itself, as it normalizeses the result before showing the image.
setting of vmax and vmin helped</p>
| 0 | 2016-08-25T12:57:45Z | [
"python",
"opencv",
"matplotlib"
] |
I'm trying to know how I can use 'extent' in matplotlib to make my background image look decent | 39,095,784 | <p>No matter what values I change it's always distorting it, or it's too far on the left.</p>
<p>Here's an example:</p>
<p><img src="http://i.stack.imgur.com/HDRPt.png" alt="Plot with background image"></p>
<pre><code>barchart = pd.read_csv('barchart.csv')
df = pd.DataFrame(barchart)
var1 = df['col1'].head(7).tolist... | 2 | 2016-08-23T08:13:14Z | 39,107,584 | <p>From the documentation,</p>
<blockquote>
<p>extent : scalars (left, right, bottom, top), optional, default: None</p>
<p>The location, in data-coordinates, of the lower-left and upper-right corners. If None, the image is positioned such that the pixel centers fall on zero-based (row, column) indices.</p>
</bl... | 0 | 2016-08-23T17:39:52Z | [
"python",
"matplotlib"
] |
How can I evaluate a View context variable as a Template variable in Django? | 39,095,793 | <p>I'd like to pass a context variable from a view into my template to direct what the template should display.</p>
<p>I have a context list variable <code>column_headers</code> that dictates the number of columns in a list page table, along with the header text that should be used.</p>
<pre><code>context['column_lis... | 0 | 2016-08-23T08:13:29Z | 39,095,967 | <p>I think <a href="https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/" rel="nofollow">custom tags or filters</a> would be a solution</p>
<p>e.g.: the following</p>
<pre><code>@register.filter
def settings_value(name):
return getattr(settings, name, "")
</code></pre>
<p>could be used in the templ... | 0 | 2016-08-23T08:22:58Z | [
"python",
"django",
"django-templates",
"django-views"
] |
How can I evaluate a View context variable as a Template variable in Django? | 39,095,793 | <p>I'd like to pass a context variable from a view into my template to direct what the template should display.</p>
<p>I have a context list variable <code>column_headers</code> that dictates the number of columns in a list page table, along with the header text that should be used.</p>
<pre><code>context['column_lis... | 0 | 2016-08-23T08:13:29Z | 39,096,013 | <p>Did you try to do it in this way? Or maybe you don't have option for that:</p>
<pre><code># Python script
context['column_list'] = [
_('Animal'),
_('Owner'),
_('Reason'),
_('Time'),
_('Vet'),
_('Status')
]
context['cell_vars'] = [
'patient',
'client',
'reason',
'start_time',... | 0 | 2016-08-23T08:25:24Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Fast conversion of Java array to NumPy array (Py4J) | 39,095,994 | <p>There are some nice examples how to convert NumPy array to Java array, but not vice versa - how to convert data from Java object back to NumPy array. I have a Python script like this:</p>
<pre><code> from py4j.java_gateway import JavaGateway
gateway = JavaGateway() # connect to the JVM
my_java... | 1 | 2016-08-23T08:24:19Z | 39,726,480 | <p>I've had a similar issue, just trying to plot spectral vectors (Java arrays) I got from the Java side via py4j.
Here, the conversion from the Java Array to a Python list is achieved by the list() function. This might give some clues as how to use it to fill NumPy arrays ...</p>
<pre><code>vectors = space.getVectors... | 0 | 2016-09-27T13:50:19Z | [
"java",
"python",
"numpy",
"py4j"
] |
How to Sort list of list as per user input? | 39,096,075 | <p>I want to sort list of list according to the user input.</p>
<pre><code>output = [[1,2],[3,4],[5,6],[7,8]] # input
# ^ ^ ^ ^
# A B C D
A = output[0] ; B = output[1] ; C = output[2] ; D = output[3] # initialization
userin = input('Enter sequence')
seq_list = userin.split('... | 1 | 2016-08-23T08:29:07Z | 39,096,281 | <p>EDIT:
I've re-written the <code>output</code> variable as a dictionary using the stated letters as keys. Then it uses a list comprehension on <code>seq_list</code> to access the dictionary in the order the user has supplied.</p>
<pre><code>output = {"A": [1,2], "B": [3,4],"C": [5,6],"D": [7,8]}
userin = input('Ente... | 0 | 2016-08-23T08:38:48Z | [
"python",
"list"
] |
How to Sort list of list as per user input? | 39,096,075 | <p>I want to sort list of list according to the user input.</p>
<pre><code>output = [[1,2],[3,4],[5,6],[7,8]] # input
# ^ ^ ^ ^
# A B C D
A = output[0] ; B = output[1] ; C = output[2] ; D = output[3] # initialization
userin = input('Enter sequence')
seq_list = userin.split('... | 1 | 2016-08-23T08:29:07Z | 39,096,324 | <p>It would be easier to make user input numbers instead of letters. However, if you want to stick to letters you can just map them in a dictionary. My example approach looks like this:</p>
<pre><code>output = [[1,2],[3,4],[5,6],[7,8]]
output_dict = {i:elem for i, elem in enumerate(output)}
user_input = input('Enter s... | 0 | 2016-08-23T08:40:24Z | [
"python",
"list"
] |
How to Sort list of list as per user input? | 39,096,075 | <p>I want to sort list of list according to the user input.</p>
<pre><code>output = [[1,2],[3,4],[5,6],[7,8]] # input
# ^ ^ ^ ^
# A B C D
A = output[0] ; B = output[1] ; C = output[2] ; D = output[3] # initialization
userin = input('Enter sequence')
seq_list = userin.split('... | 1 | 2016-08-23T08:29:07Z | 39,096,349 | <p>You can use a dictionary comprehension and the <code>zip</code> function to convert your <code>output</code> list of lists into a dict of lists.</p>
<pre><code>output = [[1, 2], [3, 4], [5, 6], [7, 8]]
d = {c: u for c, u in zip('ABCD', output)}
print(d)
userin = 'B,C,D,A'
seq_list = [d[c] for c in userin.split(','... | 1 | 2016-08-23T08:41:26Z | [
"python",
"list"
] |
int input with a string and a variable | 39,096,337 | <p>I'm somewhat new to python and am working on an assignment with a friend for school.
We wanted to ask for a swimmer's name, followed by asking what time they managed to achieve.
We wanted the program to work like this:</p>
<pre><code>Name = input('Input swimmers name: ')
Time = int(input('What time did',Name,'achi... | 0 | 2016-08-23T08:41:00Z | 39,096,376 | <p>You have to pass a single string to <code>input</code>, you can do it by first concatenating your 3 strings:</p>
<pre><code>Time = int(input('What time did' + Name + 'achieve? ')
</code></pre>
<p>BTW: "achieve" with an "e" ;-)</p>
| 3 | 2016-08-23T08:43:00Z | [
"python",
"input"
] |
int input with a string and a variable | 39,096,337 | <p>I'm somewhat new to python and am working on an assignment with a friend for school.
We wanted to ask for a swimmer's name, followed by asking what time they managed to achieve.
We wanted the program to work like this:</p>
<pre><code>Name = input('Input swimmers name: ')
Time = int(input('What time did',Name,'achi... | 0 | 2016-08-23T08:41:00Z | 39,096,437 | <p>You can also use %s for concatenation </p>
<pre><code>Time = int(input('What time did %s achive? ' % Name ))
</code></pre>
| 2 | 2016-08-23T08:45:35Z | [
"python",
"input"
] |
How do I add the path to a directory to the environment variables using python | 39,096,384 | <p>I want to know if it is possible to add the path to a directory to the environment variables permanently using python. I have seen other questions that relate to mine but the answers there only add the path temporarily,I want to know if there's a way to add it permanently</p>
| 0 | 2016-08-23T08:43:07Z | 39,096,747 | <p>While using bash add this
<code>~/.bashrc</code>
<code>export PYTHONPATH="${PYTHONPATH}:/Home/dev/path</code></p>
<p>Make sure the directory you point to has at the topmost <code>init.py</code> file in your directory structure</p>
| 1 | 2016-08-23T09:00:08Z | [
"python",
"environment-variables"
] |
Loop until a specific user input is received in Python | 39,096,424 | <p>Hello Im doing a assessment for school. Im quite a newbie to python and I really have no idea on how to loop this</p>
<pre><code> achieved=50 #predefined variables for grade input
merit=70
excellence=85
max=100
import re #imports re an external modeule which defines re
studentfname = input("Input Student firs... | -7 | 2016-08-23T08:45:07Z | 39,096,498 | <p>You just loop it</p>
<pre><code>achieved=50 #predefined variables for grade input
merit=70
excellence=85
max=100
import sys
import re #imports re an external modeule which defines re
while(1):
studentfname = input("Input Student first name in lowercase")
if any( [ i>'z' or i<'a' for i in studentfna... | 0 | 2016-08-23T08:48:35Z | [
"python",
"loops"
] |
Loop until a specific user input is received in Python | 39,096,424 | <p>Hello Im doing a assessment for school. Im quite a newbie to python and I really have no idea on how to loop this</p>
<pre><code> achieved=50 #predefined variables for grade input
merit=70
excellence=85
max=100
import re #imports re an external modeule which defines re
studentfname = input("Input Student firs... | -7 | 2016-08-23T08:45:07Z | 39,096,523 | <p>To answer your question what you need is to loop until a given input is given.
So you would use:</p>
<pre><code>while True: # infinite loop
user_input = raw_input("Want to continue? ")
if user_input == "No":
break # stops the loop
else:
# do whatever computations you need
</code></pr... | 2 | 2016-08-23T08:50:03Z | [
"python",
"loops"
] |
How to know size of python module? | 39,096,604 | <p>When I install the module using <code>pip install module_name</code>, I am able to see the size of either wheel or the package.</p>
<p>so the question is, is it possible to know just the size of each module?</p>
<p>something like this.</p>
<pre><code>import pip
for dist in pip.get_installed_distributions():
... | 1 | 2016-08-23T08:53:42Z | 39,096,975 | <pre><code>import os
import pip
def calc_container(path):
total_size = 0
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
for dist in pip.get_installed_distributions():... | 1 | 2016-08-23T09:10:22Z | [
"python"
] |
How to know size of python module? | 39,096,604 | <p>When I install the module using <code>pip install module_name</code>, I am able to see the size of either wheel or the package.</p>
<p>so the question is, is it possible to know just the size of each module?</p>
<p>something like this.</p>
<pre><code>import pip
for dist in pip.get_installed_distributions():
... | 1 | 2016-08-23T08:53:42Z | 39,099,602 | <p>I know this is vague but this is what I wanted:</p>
<pre><code>import re
import requests
import json
def regexsubstring(s, p):
p = re.compile(p, flags=re.IGNORECASE)
return p.search(s)
def wf(data,path,mode):
with open(path, mode, encoding='utf-8') as out:
out.write(data)
return
import... | 0 | 2016-08-23T11:12:33Z | [
"python"
] |
Django error: unsupported operand type(s) for *: 'NoneType' and 'float' | 39,096,659 | <p><br>I have some problem with my code. I was looking have to solve it, but I didn't find similar problem. I want to multiple and then sum some field values, but I get error from a title. Have to solve this problem? I suppose that is problem with data type, but I don't know how to define equation. Please help me.</p>
... | 0 | 2016-08-23T08:56:17Z | 39,096,786 | <p>The order of the arguments in the error message corresponds to the code:</p>
<p><code>'NoneType' and 'float'</code> <=> <code>self.priceNoTax*self.tax</code></p>
<p><code>self.priceNoTax</code> has not been initialised, or if you loaded this from the database then it contained <code>NULL</code>. You can verify ... | 0 | 2016-08-23T09:01:45Z | [
"python",
"django"
] |
Raspberry Pi 3 Python and Opencv for facial recognition | 39,096,755 | <p>I am receiving this message when trying to execute script whether in virtual environment or a normal Python shell. </p>
<pre><code>File "/home/pi/facesample1.py", line 10, in <module>
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-21... | 0 | 2016-08-23T09:00:24Z | 39,097,751 | <p>Your <code>image</code> variable is apparently not a 3 or 4 channel image.
Thus, <code>cvtColor()</code> is unable to transform it to grayscale.</p>
<p>Check <code>image.shape</code> and see that it returns something with the right dimensions (i.e. a 3D array with last dimension 3 or 4).</p>
<p>It is also quite po... | 0 | 2016-08-23T09:45:43Z | [
"python",
"c++",
"opencv",
"raspberry-pi3"
] |
what is the Tensorflow batch size when you use high-level API tf.contrib.learn.DNNClassifier | 39,096,757 | <pre><code>def binaryClassify_DNN(units,steps,trainingFilePath,testingFilePath,modelPath):
# Data sets
# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=trainingFilePath,target_dtype=np.float)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=testingFilePath,ta... | 0 | 2016-08-23T09:00:27Z | 39,096,855 | <p>I am sorry i should have looked into source code before posting</p>
<pre><code>def fit(self, x=None, y=None, input_fn=None, steps=None, batch_size=None,
monitors=None, max_steps=None):
"""Trains a model given training data `x` predictions and `y` targets.
Args:
x: Matrix of shape [n_samples, n_features...]... | 0 | 2016-08-23T09:04:55Z | [
"python",
"neural-network",
"tensorflow",
"deep-learning"
] |
Python : How should I send data values to web-server and get result using python? | 39,096,775 | <p>I am trying to get the output page once we submit input on this page. <a href="http://batblob.com" rel="nofollow">http://batblob.com</a>
Below is my code but it is giving me the html code of same page rather than of output page.
I am on Python 2.7, Please suggest me how should I get there.
Thank you in advance.</p... | 0 | 2016-08-23T09:01:12Z | 39,096,950 | <p>In this case the data you want is already in your <strong>r</strong> variable. I would assume the following will get what you are after.</p>
<pre><code>import requests
from BeautifulSoup import BeautifulSoup
url = 'http://batblob.com'
form = {
'bitadd':'anybitcoinaddress',
'submit': 'submit',
}
# Post for... | 0 | 2016-08-23T09:09:23Z | [
"python",
"python-requests"
] |
Python XML DOM collecting elements data | 39,096,799 | <p>I was trying to retrieve some info of an XML tag with python, my achieve is to have a dictionary wich saves for each situation tag id, all child data, but I don´t know how to deal with the fact that extract data from text nodes , thanks.</p>
<p><strong>My code:</strong></p>
<pre><code>from xml.dom.minidom import ... | 0 | 2016-08-23T09:02:35Z | 39,102,441 | <p>Here is the way which allow me to collect data from childs, thanks</p>
<pre><code>import xml.etree.ElementTree as ET
from xml.dom.minidom import *
import requests
print("GETTING XML...")
resp = requests.get('http://infocar.dgt.es/datex2/dgt/SituationPublication/all/content.xml', stream = True) #XML that I need
i... | 0 | 2016-08-23T13:21:19Z | [
"python",
"xml"
] |
Python XML DOM collecting elements data | 39,096,799 | <p>I was trying to retrieve some info of an XML tag with python, my achieve is to have a dictionary wich saves for each situation tag id, all child data, but I don´t know how to deal with the fact that extract data from text nodes , thanks.</p>
<p><strong>My code:</strong></p>
<pre><code>from xml.dom.minidom import ... | 0 | 2016-08-23T09:02:35Z | 39,119,543 | <p>I came to this code, is it what you were looking for?</p>
<pre><code>def getText(element):
return element.data.encode('utf-8').strip()
def getPayLoad(dom):
attrs = ['confidentiality', 'informationStatus', 'situationRecordCreationReference', 'situationRecordCreationTime', 'situationRecordVersion', 'situati... | 1 | 2016-08-24T09:34:51Z | [
"python",
"xml"
] |
Call Javascript from python | 39,096,901 | <p>I am looking for a way to call a js function from a python function. I am coming to you because I also need my js function to use DOM, so pyv8 for example is not a solution.. Do you guys have any idea? Is it even possible?</p>
<p>Thanks in advance.</p>
| 1 | 2016-08-23T09:06:48Z | 39,097,009 | <p>According to <a href="http://stackoverflow.com/a/30537286/6353933">http://stackoverflow.com/a/30537286/6353933</a>,</p>
<pre><code>import js2py
js = """
function escramble_758(){
var a,b,c
a='+1 '
b='84-'
a+='425-'
b+='7450'
c='9'
document.write(a+c+b)
}
escramble_758()
""".replace("document.write", "return ")
re... | 2 | 2016-08-23T09:11:48Z | [
"javascript",
"python"
] |
Call Javascript from python | 39,096,901 | <p>I am looking for a way to call a js function from a python function. I am coming to you because I also need my js function to use DOM, so pyv8 for example is not a solution.. Do you guys have any idea? Is it even possible?</p>
<p>Thanks in advance.</p>
| 1 | 2016-08-23T09:06:48Z | 39,097,157 | <p>PyExecJS seems to be a good option.</p>
<pre><code>>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
['red', 'yellow', 'blue']
>>> ctx = execjs.compile("""
... function add(x, y) {
... return x + y;
... }
... """)
>>> ctx.call("add", 1, 2)
3
</code... | 1 | 2016-08-23T09:17:25Z | [
"javascript",
"python"
] |
Pandas dataframe pivot table and grouping | 39,096,924 | <p>I have a DataFrame which I made into a pivot table, but now I want to order the pivot table so that common values based on a particular column are aligned beside each other. For e.g. order DataFrame so that all common countries align to same row:</p>
<pre><code>data = {'dt': ['2016-08-22', '2016-08-21', '2016-08-22... | 2 | 2016-08-23T09:08:02Z | 39,097,046 | <p>You can use:</p>
<pre><code>df_pivot = df.set_index(['dt','country']).stack().unstack([0,2]).reset_index()
print (df_pivot)
dt country 2016-08-22 2016-08-21
number number
0 fr 20.0 10.0
1 uk 10.0 12.0
2 usa NaN 21.0
#change first value of M... | 1 | 2016-08-23T09:13:22Z | [
"python",
"pandas",
"dataframe",
"alignment",
"pivot"
] |
Is there any shorter way to write this method? | 39,096,933 | <p>I have a list in python that should look like this for example:</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
</code></pre>
<p>I wrote this function, but can this be done in the easier way?</p>
<pre><code>def checkCardCommands(line):
if line[0] == '0' or line[0] == '1':
if line[1] == '0' or line[1] ... | -2 | 2016-08-23T09:08:32Z | 39,097,029 | <p>You could write it as something like:</p>
<pre><code>def checkCardCommands(line):
return (len(line) == 5
and line[0] in ['0', '1']
and line[1] in ['0', '1', 'None']
and line[2] in ['0', '1', 'None']
and line[3] in ['R', 'L']
and line[4] in ['0', '1'])
</code></pre>
| 7 | 2016-08-23T09:12:32Z | [
"python",
"list"
] |
Is there any shorter way to write this method? | 39,096,933 | <p>I have a list in python that should look like this for example:</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
</code></pre>
<p>I wrote this function, but can this be done in the easier way?</p>
<pre><code>def checkCardCommands(line):
if line[0] == '0' or line[0] == '1':
if line[1] == '0' or line[1] ... | -2 | 2016-08-23T09:08:32Z | 39,097,034 | <pre><code>def checkcards():
return line[0] in ['0','1'] and line[1] in ['0','1','None'] and line[2] in ['0','1','None'] and line[3] in ['R','L'] and line[4] in ['0','1'] and len(line)==5
</code></pre>
<p>'None' is a string, None is an object type. make sure you know which one you want to use. </p>
| 1 | 2016-08-23T09:12:51Z | [
"python",
"list"
] |
Is there any shorter way to write this method? | 39,096,933 | <p>I have a list in python that should look like this for example:</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
</code></pre>
<p>I wrote this function, but can this be done in the easier way?</p>
<pre><code>def checkCardCommands(line):
if line[0] == '0' or line[0] == '1':
if line[1] == '0' or line[1] ... | -2 | 2016-08-23T09:08:32Z | 39,097,108 | <pre><code>def check(line):
spec = [
['0', '1'],
['0', '1', 'None'],
['0', '1', 'None'],
['R', 'L'],
['0', '1']
]
return len(line) == len(spec) and all(ln in spc for ln, spc in zip(line, spec))
</code></pre>
<p>Shorter, and way more readable and maintainable.</p>
| 4 | 2016-08-23T09:15:05Z | [
"python",
"list"
] |
Is there any shorter way to write this method? | 39,096,933 | <p>I have a list in python that should look like this for example:</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
</code></pre>
<p>I wrote this function, but can this be done in the easier way?</p>
<pre><code>def checkCardCommands(line):
if line[0] == '0' or line[0] == '1':
if line[1] == '0' or line[1] ... | -2 | 2016-08-23T09:08:32Z | 39,097,207 | <p>If your validations are not too complicated you could write some validation helpers yourself:</p>
<pre><code>#!/usr/bin/env python3
# coding: utf-8
def validate(schema, seq):
"""
Validates a given iterable against a schema. Schema is a list
of callables, taking a single argument returning `True` if the... | 4 | 2016-08-23T09:19:43Z | [
"python",
"list"
] |
Is there any shorter way to write this method? | 39,096,933 | <p>I have a list in python that should look like this for example:</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
</code></pre>
<p>I wrote this function, but can this be done in the easier way?</p>
<pre><code>def checkCardCommands(line):
if line[0] == '0' or line[0] == '1':
if line[1] == '0' or line[1] ... | -2 | 2016-08-23T09:08:32Z | 39,097,456 | <p>The following code will help in case of dynamic list to be checked.</p>
<pre><code>line = ['0', '1', '0', 'R', '1']
check_list = [
['0', '1'],
['0', '1', 'None'],
['0', '1', 'None'],
['R', 'L'],
['0', '1']
]
def check():
for l, item in enumerate(line):
if not item in check_list[l]:
... | 1 | 2016-08-23T09:31:02Z | [
"python",
"list"
] |
Removing django default permissions from auth models | 39,096,973 | <p>guys im trying to remove default django permissions i'll never use in my project but with no success. When I make migration it states that migration is made with success but there's no effect, like it skipped the function. I'm pretty sure code is ok because i tested it in shell. Any ideas?
Here's code for migration:... | 0 | 2016-08-23T09:10:19Z | 39,097,371 | <p>Django's permessions are generated with <code>post_migrate</code> signal. This means even if you delete them in migration they will be regenerated after migration completes. </p>
<p>Here is code from django</p>
<pre><code># django/contrib/auth/apps.py
from django.apps import AppConfig
from django.contrib.auth.chec... | 0 | 2016-08-23T09:27:24Z | [
"python",
"django",
"migration"
] |
writing in a text file with [ ] python | 39,097,004 | <p>I am trying to write in a text file with braces. </p>
<pre><code>output.write("{}\t{}\t{}\t{}\t{}\t".format(student_iD,user_id,First_name, Last_name,Other_name))
output.write("\n")
</code></pre>
<p>it writes in the text file with out the braces. What should I add such that I get something like this:</p>
<pre><cod... | -3 | 2016-08-23T09:11:35Z | 39,097,044 | <p>Surround those braces with <code>[]</code></p>
<pre><code>output.write("[{}]\t[{}]\t[{}]\t[{}]\t[{}]\t".format(student_iD,user_id,First_name, Last_name,Other_name))
output.write("\n")
</code></pre>
| 0 | 2016-08-23T09:13:18Z | [
"python",
"python-2.7"
] |
writing in a text file with [ ] python | 39,097,004 | <p>I am trying to write in a text file with braces. </p>
<pre><code>output.write("{}\t{}\t{}\t{}\t{}\t".format(student_iD,user_id,First_name, Last_name,Other_name))
output.write("\n")
</code></pre>
<p>it writes in the text file with out the braces. What should I add such that I get something like this:</p>
<pre><cod... | -3 | 2016-08-23T09:11:35Z | 39,097,075 | <p>As simple as that:</p>
<pre><code>output.write("[{}]\t[{}]\t[{}]\t[{}]\t[{}]\t".format(...)
</code></pre>
<p>Or place the brackets around the variable names themselves without changing the format string. Then you'll be printing lists, and each of them will consist of only one value.</p>
<pre><code>output.write("{... | 0 | 2016-08-23T09:14:08Z | [
"python",
"python-2.7"
] |
writing in a text file with [ ] python | 39,097,004 | <p>I am trying to write in a text file with braces. </p>
<pre><code>output.write("{}\t{}\t{}\t{}\t{}\t".format(student_iD,user_id,First_name, Last_name,Other_name))
output.write("\n")
</code></pre>
<p>it writes in the text file with out the braces. What should I add such that I get something like this:</p>
<pre><cod... | -3 | 2016-08-23T09:11:35Z | 39,097,426 | <p>My code</p>
<pre><code>output = open('/home/vipul/Desktop/test_data.txt', 'a')
output.write("[{}]\t[{}]\t[{}]\t[{}]\t[{}]\t".format(222,2222,'test', 'test','test'))
output.write("\n")
</code></pre>
<p>output I got:
[222] [2222] [test] [test] [test] </p>
<p>Its working. If you get error paste your ou... | 0 | 2016-08-23T09:29:27Z | [
"python",
"python-2.7"
] |
Switch Alternative in python | 39,097,072 | <p>Am trying this small piece of code which can be alternative for switch. But i get weired Error.</p>
<pre><code>def main(x):
x = x.split(' ')
return {'Function1' : Function1(x),
'Function2' : Function2(x),
}[x[0]]
def Function1(x):
var1 = x[0]
var2 = x[1]
def Function2(x):... | 0 | 2016-08-23T09:14:08Z | 39,097,143 | <p>Your code doesn't work at all. You always call the functions when you define the dict. You should keep the callable in the dict and call the result.</p>
<pre><code>def main(x):
x = x.split(' ')
func = {'Function1' : Function1,
'Function2' : Function2,
}[x[0]]
return func(x[1])
</c... | 3 | 2016-08-23T09:16:52Z | [
"python",
"python-2.7"
] |
Switch Alternative in python | 39,097,072 | <p>Am trying this small piece of code which can be alternative for switch. But i get weired Error.</p>
<pre><code>def main(x):
x = x.split(' ')
return {'Function1' : Function1(x),
'Function2' : Function2(x),
}[x[0]]
def Function1(x):
var1 = x[0]
var2 = x[1]
def Function2(x):... | 0 | 2016-08-23T09:14:08Z | 39,097,204 | <p>What you really should do is use a string of <code>if/elif/else</code> statements:</p>
<pre><code>if x == 1:
Function1()
elif x == 2:
Function2()
else:
Function3()
</code></pre>
| 0 | 2016-08-23T09:19:39Z | [
"python",
"python-2.7"
] |
Switch Alternative in python | 39,097,072 | <p>Am trying this small piece of code which can be alternative for switch. But i get weired Error.</p>
<pre><code>def main(x):
x = x.split(' ')
return {'Function1' : Function1(x),
'Function2' : Function2(x),
}[x[0]]
def Function1(x):
var1 = x[0]
var2 = x[1]
def Function2(x):... | 0 | 2016-08-23T09:14:08Z | 39,097,293 | <p>The code block</p>
<pre><code> return {'Function1' : Function1(x),
'Function2' : Function2(x),
}[x[0]]
</code></pre>
<p>is evaluated first as</p>
<pre><code> return {'Function1' : Function1(x),
'Function2' : Function2(x),
}
</code></pre>
<p>Evaluating this will actually call... | 1 | 2016-08-23T09:24:03Z | [
"python",
"python-2.7"
] |
How to give a user a single session extra permission in Django | 39,097,148 | <h1>Background</h1>
<p>We have a service where a django super admin can login and view all the users in a specific org, and this super admin can "log in" in the place of that user. Ie suppose we have</p>
<pre><code>super admin = joe
users = mike, abe, tony
</code></pre>
<p>then joe can log into an org, see mike, abe... | 0 | 2016-08-23T09:17:03Z | 39,103,612 | <p>enter <a href="https://github.com/arteria/django-hijack" rel="nofollow">https://github.com/arteria/django-hijack</a></p>
<p>for example django-hijack add extra flag to session for checking is user hijacked <a href="https://github.com/arteria/django-hijack/search?utf8=%E2%9C%93&q=is_hijacked_user" rel="nofollow"... | 0 | 2016-08-23T14:11:47Z | [
"python",
"django",
"django-models",
"django-admin",
"django-authentication"
] |
Python write edited NaNs in variable to .csv | 39,097,337 | <p>I'm trying to convert <code>NULL</code> values in a .csv to <code>NaN</code> and then save a file with these edits. <code>f</code> in the code below has the <code>NaN</code>values in the correct location in the data. However, I am unable to save this as a .csv. the error is printed below the code.</p>
<pre><code>#t... | 0 | 2016-08-23T09:25:37Z | 39,097,615 | <p><a href="https://docs.python.org/3/library/csv.html#csv.csvwriter.writerows" rel="nofollow"><code>csv.writer.writerows()</code></a> expects a sequence of sequences (a sequence of row objects), which a <code>pandas.DataFrame</code> is not, as it returns a sequence of column names when iterated over:</p>
<pre><code>I... | 1 | 2016-08-23T09:39:01Z | [
"python",
"python-2.7",
"csv",
null
] |
Html page cannot show properly in PyQt Qwebview | 39,097,359 | <p>I use PyQt4(4.11 version) and Python2.7 </p>
<p>I would like to embedded html page in pyqt GUI by using Qwebview ,
the html were generated from plotly offline,simply contains bar chart graph like this:
<a href="http://i.stack.imgur.com/7RlhS.png" rel="nofollow">bar chart</a></p>
<pre><code>self.webView = QtWebKit.... | 0 | 2016-08-23T09:26:53Z | 39,114,343 | <p>Both Qt4 (which you're using with PyQt4) and QtWebKit are unmaintained. </p>
<p>You'll also get a webkit which is probably around 4 years old. Such an old webkit version will struggle with modern web content (apart from the obvious security and stability issues).</p>
<p>I'd recommend to upgrade at least to PyQt5/Q... | 0 | 2016-08-24T04:17:36Z | [
"python",
"html",
"pyqt",
"plotly"
] |
Check if variable is set in multiple scripts | 39,097,416 | <p>I have a python module with lots of python scripts in, I want to read these scripts and check if a variable is set.</p>
<p>I'm currently reading the files line by line, but as the scripts i'm reading are in python i'm guessing there is a better way?</p>
<pre><code>for filename in glob.glob(os.path.join(my_path, '*... | 3 | 2016-08-23T09:28:56Z | 39,098,330 | <p>Here's a working example for your question:</p>
<pre><code>import glob
import inspect
import os
import sys
import importlib
def get_classes(module):
def pred(c):
if inspect.isclass(c) and hasattr(c, "countrys"):
return True
return False
for value in inspect.getmembers(module, ... | 1 | 2016-08-23T10:13:30Z | [
"python"
] |
How to render tables in django-datatable-view? | 39,097,427 | <p>I can't figure out how to render an editable table using <code>Django-datatable-view</code>. I want to create a table exactly like this: <a href="http://django-datatable-view.appspot.com/x-editable-columns/" rel="nofollow">http://django-datatable-view.appspot.com/x-editable-columns/</a> from model <code>City</code> ... | 1 | 2016-08-23T09:29:32Z | 39,101,030 | <pre><code>{% block content %}
{% if instances %}
<table class='datatable'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
</tr>
{% for row in instances %}
<... | -1 | 2016-08-23T12:19:28Z | [
"python",
"django",
"datatable",
"html-table"
] |
How to render tables in django-datatable-view? | 39,097,427 | <p>I can't figure out how to render an editable table using <code>Django-datatable-view</code>. I want to create a table exactly like this: <a href="http://django-datatable-view.appspot.com/x-editable-columns/" rel="nofollow">http://django-datatable-view.appspot.com/x-editable-columns/</a> from model <code>City</code> ... | 1 | 2016-08-23T09:29:32Z | 39,713,780 | <p>As the first step, try to run the example project that is buried in:</p>
<pre><code>django-datatable-view/datatableview/tests/example_project/example_project/example_app
</code></pre>
<p>To do this, follow the <a href="https://github.com/pivotal-energy-solutions/django-datatable-view#documentation-and-live-demos" ... | 0 | 2016-09-26T23:16:50Z | [
"python",
"django",
"datatable",
"html-table"
] |
python3 script to compress directory and dynamically name the archive | 39,097,509 | <p>I am trying to write a python 3 script that will compress the contents of a directory <code>/home/pi/results</code> and copy it to another folder <code>/home/pi/backups</code>.<br>
I need to be able to run this script multiple times and each time, the resulting archive is named something based on the previous archiv... | 2 | 2016-08-23T09:33:44Z | 39,097,614 | <pre><code>import os
latest_file = sorted(os.listdir('/home/pi/backups'))[-1]
</code></pre>
<p>This should give you the latest file name. The next one could be figured out from this name.</p>
| 1 | 2016-08-23T09:38:58Z | [
"python",
"python-3.x"
] |
python3 script to compress directory and dynamically name the archive | 39,097,509 | <p>I am trying to write a python 3 script that will compress the contents of a directory <code>/home/pi/results</code> and copy it to another folder <code>/home/pi/backups</code>.<br>
I need to be able to run this script multiple times and each time, the resulting archive is named something based on the previous archiv... | 2 | 2016-08-23T09:33:44Z | 39,097,634 | <p>Maybe use timestamp? Then you will know at the first sight which specific backup you're looking for.</p>
<pre><code>import datetime
date = datetime.datetime.utcnow().isoformat()
filename = 'backup-{}.tgz'.format(date)
filepath = os.path.join(backupdir, filename)
tar=tarfile.open(filepath, "w:gz")
tar.... | 0 | 2016-08-23T09:40:01Z | [
"python",
"python-3.x"
] |
python3 script to compress directory and dynamically name the archive | 39,097,509 | <p>I am trying to write a python 3 script that will compress the contents of a directory <code>/home/pi/results</code> and copy it to another folder <code>/home/pi/backups</code>.<br>
I need to be able to run this script multiple times and each time, the resulting archive is named something based on the previous archiv... | 2 | 2016-08-23T09:33:44Z | 39,097,830 | <p>You could try a filtering/counting approach:</p>
<pre><code># we set the path, and the word key that we are looking for
path = '/home/user/backups'
word_key = 'backup-'
# we count the occurrences and generate a new filename from it
backups_count = len(filter(lambda x : word_key in x, os.listdir(path)))
filename = ... | 0 | 2016-08-23T09:49:16Z | [
"python",
"python-3.x"
] |
python3 script to compress directory and dynamically name the archive | 39,097,509 | <p>I am trying to write a python 3 script that will compress the contents of a directory <code>/home/pi/results</code> and copy it to another folder <code>/home/pi/backups</code>.<br>
I need to be able to run this script multiple times and each time, the resulting archive is named something based on the previous archiv... | 2 | 2016-08-23T09:33:44Z | 39,098,251 | <p>Use <a href="https://docs.python.org/2/library/glob.html" rel="nofollow">glob</a> to get a list of backups that already exist<br>
Use <code>max()</code> with <a href="http://stackoverflow.com/questions/18296755/python-max-function-using-key-and-lambda-expression">custom key</a> to find the last one<br>
Use <a href="... | 0 | 2016-08-23T10:09:37Z | [
"python",
"python-3.x"
] |
Bioinformatics : Programmatic Access to the BacDive Database | 39,097,529 | <p>the resource at "BacDive" - ( <a href="http://bacdive.dsmz.de/" rel="nofollow">http://bacdive.dsmz.de/</a>) is a highly useful database for accessing bacterial knowledge, such as strain information, species information and parameters such as growth temperature optimums. </p>
<p>I have a scenario in which I have a s... | 0 | 2016-08-23T09:34:51Z | 39,098,473 | <p>Here is the solution...</p>
<pre><code>import re
import urllib
from bs4 import BeautifulSoup
def get_growth_temp(url):
soup = BeautifulSoup(urllib.urlopen(url).read())
no_hits = int(map(float, re.findall(r'[+-]?[0-9]+',str(soup.find_all("span", class_="searchresultlayerhits"))))[0])
if no_hits > 1 ... | 2 | 2016-08-23T10:20:35Z | [
"python",
"database",
"webpage",
"bioinformatics"
] |
Deployment on Google App Engine - Django, Vagrant, Ansible | 39,097,545 | <p>I want to deploy <code>Django</code> project on <code>google app engine</code></p>
<p>Following are the current situations.</p>
<ol>
<li>I have a code on <code>GITHUB</code></li>
<li><code>Djnago</code> project has setup using <code>Vagrant</code>, <code>Ansible</code>, <code>VirtualBox</code></li>
</ol>
<p>I am ... | -5 | 2016-08-23T09:35:32Z | 39,097,936 | <p>Your question is a bit too generic as it stands - making it here rather than comment for clarity.</p>
<p>If you're talking about deploying to GAE (Google App Engine) then most likely you cannot re-use your Ansible scripts as you've been writing for vagrant. As it may be possible to use Ansible to deploy on GAE, mos... | 0 | 2016-08-23T09:54:45Z | [
"python",
"django",
"google-app-engine",
"vagrant",
"ansible"
] |
Django Rest Framework Without Database | 39,098,008 | <p>I'm trying to setup a simple API using Django Rest Framework, the problem is that my API does not have any database but the framework won't work without database setting.</p>
<p>Here is my Django Rest Framework configuration in <code>settings.py</code>:</p>
<pre class="lang-python prettyprint-override"><code>INSTA... | 1 | 2016-08-23T09:58:14Z | 39,098,104 | <p>You don't have any option. <code>DATABASES</code> dict should be in <code>settings.py</code>. You can use this:</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
</code></pre>
| 0 | 2016-08-23T10:03:13Z | [
"python",
"django",
"django-rest-framework"
] |
Django Rest Framework Without Database | 39,098,008 | <p>I'm trying to setup a simple API using Django Rest Framework, the problem is that my API does not have any database but the framework won't work without database setting.</p>
<p>Here is my Django Rest Framework configuration in <code>settings.py</code>:</p>
<pre class="lang-python prettyprint-override"><code>INSTA... | 1 | 2016-08-23T09:58:14Z | 39,098,414 | <p>[not tested] maybe you could use a dummy backend. I see there's one from django:</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
</code></pre>
| 0 | 2016-08-23T10:17:41Z | [
"python",
"django",
"django-rest-framework"
] |
Django Rest Framework Without Database | 39,098,008 | <p>I'm trying to setup a simple API using Django Rest Framework, the problem is that my API does not have any database but the framework won't work without database setting.</p>
<p>Here is my Django Rest Framework configuration in <code>settings.py</code>:</p>
<pre class="lang-python prettyprint-override"><code>INSTA... | 1 | 2016-08-23T09:58:14Z | 39,098,512 | <p>If you are really forced to use a database but you don't want to, you can use <code>:memory:</code> with the SQLite backend, like this:</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
</code></pre>
<p>This uses an in-memory database,... | 1 | 2016-08-23T10:21:59Z | [
"python",
"django",
"django-rest-framework"
] |
Django Rest Framework Without Database | 39,098,008 | <p>I'm trying to setup a simple API using Django Rest Framework, the problem is that my API does not have any database but the framework won't work without database setting.</p>
<p>Here is my Django Rest Framework configuration in <code>settings.py</code>:</p>
<pre class="lang-python prettyprint-override"><code>INSTA... | 1 | 2016-08-23T09:58:14Z | 39,101,018 | <p>The actual cause of the problem is that DRF trys to add a <code>user</code> attribute to the <code>request</code>. Briefly mentioned in the documentation, the mechanism is as follows:</p>
<blockquote>
<p><strong><a href="http://www.django-rest-framework.org/api-guide/authentication/#how-authentication-is-determin... | 1 | 2016-08-23T12:19:05Z | [
"python",
"django",
"django-rest-framework"
] |
Firebase: limited and secure service access from Pyrebase? | 39,098,190 | <p>When using Firebase's server API, you can provide additional <code>databaseAuthVariableOverride</code> section to limit access of the service account, as described <a href="https://firebase.google.com/docs/database/server/start#authenticate-with-limited-privileges" rel="nofollow">in the docs</a>. I wanted to use <a ... | 0 | 2016-08-23T10:07:18Z | 39,102,831 | <p>There is no difference in the security rules between an auth.uid that you've set using <a href="https://firebase.google.com/docs/database/server/start#authenticate-with-limited-privileges" rel="nofollow">Authenticate with limited privileges</a> or one that is determined by <a href="https://firebase.google.com/docs/a... | 1 | 2016-08-23T13:38:42Z | [
"python",
"firebase",
"firebase-database",
"firebase-security"
] |
AttributeError: 'NoneType' object has no attribute 'group' Can't Parse (Python) | 39,098,278 | <p>I am getting the following error when I am trying to parse "bloomberg" out of the self.web_url. type of self.web_url is unicode, so I am assuming that might be the reason why. However, I do not know how to implement type conversions if necessary or what to do</p>
<pre><code>self.web_url = "http://www.bloomberg.com"... | 1 | 2016-08-23T10:11:05Z | 39,098,351 | <p>You are missing a <code>/</code> in <code>start</code>:</p>
<pre><code>start = 'http://www.'
</code></pre>
<p>Also note that, the <code>.</code> has a special meaning in Regex, its a Regex token that will match any single character, not literal <code>.</code>. You need to escape it to make it literal i.e. <code>\.... | 1 | 2016-08-23T10:14:13Z | [
"python",
"regex",
"python-2.7"
] |
AttributeError: 'NoneType' object has no attribute 'group' Can't Parse (Python) | 39,098,278 | <p>I am getting the following error when I am trying to parse "bloomberg" out of the self.web_url. type of self.web_url is unicode, so I am assuming that might be the reason why. However, I do not know how to implement type conversions if necessary or what to do</p>
<pre><code>self.web_url = "http://www.bloomberg.com"... | 1 | 2016-08-23T10:11:05Z | 39,098,561 | <p>You get the error because there is no match. Your pattern is incorrect since it matches a single <code>/</code>, while there are 2 <code>/</code>s after <code>http:</code>. You need to fix the pattern as heemayl suggests or use an alternative <code>urlparse</code> based solution to get the <code>netloc</code> part, ... | 1 | 2016-08-23T10:24:26Z | [
"python",
"regex",
"python-2.7"
] |
Override numpy.random to use cudamat | 39,098,284 | <p>I have a programm that uses np.random many times. Now I wan't the user to pass an argument <code>gpu=True/False</code>. How can I override np.random to return <code>cm.CUDAMatrix(np.random.uniform(low=low, high=high, size=size))</code> without ending in a recursion?
Or is there a better way to use cudamat with small... | 0 | 2016-08-23T10:11:19Z | 39,098,650 | <pre><code>class FeedForwardNetwork():
def __init__(self, input_dim, hidden_dim, output_dim, dropout=False, dropout_prop=0.5, gpu=True):
np.random.seed(1)
self.input_layer = np.array([])
self.hidden_layer = np.array([])
self.output_layer = np.array([])
self.input_dim = input_dim
sel... | 1 | 2016-08-23T10:27:58Z | [
"python",
"numpy",
"cudamat"
] |
Inherit namedtuple from a base class in python | 39,098,452 | <p>Is it possible to produce a <code>namedtuple</code> which inherits from a base class? </p>
<p>What I want is that <code>Circle</code> and <code>Rectangle</code> are <code>namedtuple</code>s and are inherited from a common base class ('Shape'):</p>
<pre><code>from collections import namedtuple
class Shape:
def... | 1 | 2016-08-23T10:19:27Z | 39,098,966 | <p>You can try this:</p>
<pre><code>class Circle(Shape, namedtuple('Circle', 'x y radius')):
pass
</code></pre>
<p>(You should consider adding <a href="https://docs.python.org/3/reference/datamodel.html#slots" rel="nofollow"><code>__slots__</code></a> to all your three classes to save memory and for sightly fast... | 1 | 2016-08-23T10:42:44Z | [
"python",
"inheritance",
"namedtuple"
] |
Lambda function translation | 39,098,549 | <p>I have been struggling with a piece of python code that i can not make sense of.
It's about a nested lambda function that looks like this:</p>
<pre><code>lambda l: lambda x: x[0] in [None if not i.object else i.object.key for i in l]
</code></pre>
<p>I have tried to translate it and i came up with this but i do no... | 1 | 2016-08-23T10:23:36Z | 39,098,827 | <p><strong>Step 1:</strong></p>
<pre><code>def f1(l):
def f2(x):
xs = [None if not i.object else i.object.key for i in l]
return x[0] in xs
return f2
</code></pre>
<p><strong>Step 2:</strong></p>
<pre><code>def f1(l):
def f2(x):
xs = []
for i in l:
if not i.obj... | 2 | 2016-08-23T10:36:29Z | [
"python",
"lambda"
] |
Lambda function translation | 39,098,549 | <p>I have been struggling with a piece of python code that i can not make sense of.
It's about a nested lambda function that looks like this:</p>
<pre><code>lambda l: lambda x: x[0] in [None if not i.object else i.object.key for i in l]
</code></pre>
<p>I have tried to translate it and i came up with this but i do no... | 1 | 2016-08-23T10:23:36Z | 39,101,969 | <p>The accepted answer from @citaret is fine but one aspect of this hasn't been made clear so far and that is - why is it we have a function in a function, why not just have <code>f1(l, x)</code>?</p>
<p>The answer is that the function is likely used as an input to another function which takes exactly 1 argument and t... | 1 | 2016-08-23T13:00:13Z | [
"python",
"lambda"
] |
Splitting numbers between zeroes into separate lists in Python | 39,098,583 | <p>I'm not getting anywhere with google, as I don't think I can formulate this into a search query well.</p>
<p>I have this list:</p>
<pre><code>a = [0.0, 0.0, 0.0, 23.1, 23.1, ... , 23.1, 0.0, ... , 0.0, 34.5, ..., 34.5, 0.0, 0.0, 0.0]
</code></pre>
<p>I'd like to make it into this:</p>
<pre><code>asplit = [[23.1... | -1 | 2016-08-23T10:25:22Z | 39,098,881 | <p>To get the first elements of all consecutive runs of non-zero numbers in the list <code>a</code>, you can use</p>
<pre><code>from itertools import groupby
result = [next(vals) for k, vals in groupby(a, bool) if k]
</code></pre>
<p>Edit: Code adapted to match the updated question.</p>
| 3 | 2016-08-23T10:38:45Z | [
"python"
] |
Splitting numbers between zeroes into separate lists in Python | 39,098,583 | <p>I'm not getting anywhere with google, as I don't think I can formulate this into a search query well.</p>
<p>I have this list:</p>
<pre><code>a = [0.0, 0.0, 0.0, 23.1, 23.1, ... , 23.1, 0.0, ... , 0.0, 34.5, ..., 34.5, 0.0, 0.0, 0.0]
</code></pre>
<p>I'd like to make it into this:</p>
<pre><code>asplit = [[23.1... | -1 | 2016-08-23T10:25:22Z | 39,098,920 | <p>Here's a possible solution for the original question:</p>
<pre><code>import itertools
a = [0.0, 0.0, 0.0, 23.1, 23.2, 0.0, 0.0, 0.0, 34.5, 34.6, 0.0, 0.0, 0.0]
b = [list(x[1]) for x in itertools.groupby(a, lambda x: x == 0) if not x[0]]
print(b)
</code></pre>
<p>And here's the solution if you don't want to have d... | 2 | 2016-08-23T10:40:40Z | [
"python"
] |
Splitting numbers between zeroes into separate lists in Python | 39,098,583 | <p>I'm not getting anywhere with google, as I don't think I can formulate this into a search query well.</p>
<p>I have this list:</p>
<pre><code>a = [0.0, 0.0, 0.0, 23.1, 23.1, ... , 23.1, 0.0, ... , 0.0, 34.5, ..., 34.5, 0.0, 0.0, 0.0]
</code></pre>
<p>I'd like to make it into this:</p>
<pre><code>asplit = [[23.1... | -1 | 2016-08-23T10:25:22Z | 39,099,179 | <p>another solution but without itertools
<strong>EDIT:</strong> As Op changed the question quite a bit, here another solution to fit OPs needs</p>
<pre><code># init the loop
i = 0
asplit = []
last = None
while i < len(a)-1:
# add non-zero number, that is new
cand = a[i]
if cand != last and cand != 0.0... | 1 | 2016-08-23T10:53:18Z | [
"python"
] |
Splitting numbers between zeroes into separate lists in Python | 39,098,583 | <p>I'm not getting anywhere with google, as I don't think I can formulate this into a search query well.</p>
<p>I have this list:</p>
<pre><code>a = [0.0, 0.0, 0.0, 23.1, 23.1, ... , 23.1, 0.0, ... , 0.0, 34.5, ..., 34.5, 0.0, 0.0, 0.0]
</code></pre>
<p>I'd like to make it into this:</p>
<pre><code>asplit = [[23.1... | -1 | 2016-08-23T10:25:22Z | 39,114,866 | <p>You may achieve it using <code>set</code>. Since, order of number is to be preserved, you can do:</p>
<pre><code> >>> my_list = [23.1, 23.1, 23.1, 0.0, 0.0, 34.5, 34.5, 0.0, 0.0, 0.0]
>>> seen = set()
>>> seen_add = seen.add
>>> [[x] for x in my_list if x and not (x in seen o... | 3 | 2016-08-24T05:10:58Z | [
"python"
] |
Celery and Flask in same docker-compose | 39,098,668 | <p>I'm trying to use <code>docker-compose</code> to spawn my Flask/Celery/Redis services.</p>
<p>Here's my <code>docker-compose.yml</code>:</p>
<pre><code>flask:
build: .
command: "python3 app.py"
ports:
- '5000:5000'
links:
- redis
volumes:
- .:/usr/src/app:ro
celery:
... | 5 | 2016-08-23T10:28:58Z | 39,101,944 | <p>Solved my problem. I eventually figured out I could get a command prompt on the Docker image:</p>
<pre><code>docker build -t <image name> .
docker run -it <image name> /bin/bash
</code></pre>
<p>Then trying to run <code>celery</code> within the container revealed the problem:</p>
<pre><code>root@4a6ed... | 2 | 2016-08-23T12:59:05Z | [
"python",
"docker",
"redis",
"celery",
"docker-compose"
] |
Replacing a conditional with the negative (i.e. using not) causes error with pythons re.sub method | 39,098,761 | <p>I'm trying to replace all characters in a string that windows doesn't like in a file path (such as <code>%$£^</code>) with an empty string, using <code>re.sub</code>. When I use this:</p>
<pre><code> import string
import re
name= '*example -name_with^additional£$characters'
for j in name:
i... | 1 | 2016-08-23T10:32:49Z | 39,098,841 | <p>The issue arises because you are trying to <code>re.sub</code> with <code>*</code> pattern, and it is an invalid regex pattern since you cannot quantify nothing (empty location).</p>
<p>Use a simple <code>replace</code>:</p>
<pre><code>import string
name= '*example -name_with^additional£$characters'
for j in name... | 1 | 2016-08-23T10:36:56Z | [
"python",
"regex",
"string"
] |
Pandas: condition to string | 39,098,970 | <p>I have dataframe and I want to delete string from dataframe, if some column contain <code>avito</code> and doesn't contain <code>telefony</code>.
I can write condition</p>
<p><code>df1 = df[~df.url.str.contains(r"avito")]</code> </p>
<p>but I don't know how can I add condition with <code>telefony</code>
data:</p>
... | -1 | 2016-08-23T10:43:11Z | 39,099,620 | <p>You want to compound your boolean conditions and negate it:</p>
<pre><code>In [18]:
df[~(df['url'].str.contains('avito') & ~df['url'].str.contains('telefony'))]
Out[18]:
url
0 avito.ru/mytischi/telefony/sim_karty_s_nulevym...
2 avito.ru/moskva/telefony/blackbe... | 2 | 2016-08-23T11:13:41Z | [
"python",
"pandas"
] |
How to write CSV files into XLSX using Python Pandas? | 39,099,008 | <p>I have several .csv files and I want to write them into one .xlsx file as spreadsheets.</p>
<p>I've loaded these .csv files into Pandas.DataFrame using following code:</p>
<pre><code>df1 = pandas.read_csv('my_file1.csv')
df2 = pandas.read_csv('my_file2.csv')
......
df5 = pandas.read_csv('my_file5.csv')
</code></pr... | 0 | 2016-08-23T10:44:49Z | 39,099,084 | <p>you can write Dataframes to CSV file and open it with Excel.</p>
<p>Use to_csv method to write it to a file.</p>
<pre><code>df1.to_csv(path_to_file)
</code></pre>
<p>You can read more here:</p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html" rel="nofollow">http://p... | -1 | 2016-08-23T10:48:43Z | [
"python",
"csv",
"pandas",
"spreadsheet",
"xlsx"
] |
How to write CSV files into XLSX using Python Pandas? | 39,099,008 | <p>I have several .csv files and I want to write them into one .xlsx file as spreadsheets.</p>
<p>I've loaded these .csv files into Pandas.DataFrame using following code:</p>
<pre><code>df1 = pandas.read_csv('my_file1.csv')
df2 = pandas.read_csv('my_file2.csv')
......
df5 = pandas.read_csv('my_file5.csv')
</code></pr... | 0 | 2016-08-23T10:44:49Z | 39,099,338 | <p>With recent enough pandas use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html" rel="nofollow"><code>DataFrame.to_excel()</code></a> with an existing <code>ExcelWriter</code> object and pass sheet names:</p>
<pre><code>from pandas.io.excel import ExcelWriter
import panda... | 1 | 2016-08-23T11:00:32Z | [
"python",
"csv",
"pandas",
"spreadsheet",
"xlsx"
] |
Pycharm SqlAlchemy autocomplete not working | 39,099,117 | <p>I'm using SQLAlchemy and Pycharm, but PyCharm can't see methods of SQLAlchemy for autocomplete function.</p>
<p>Code:</p>
<pre><code>from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.sq... | 2 | 2016-08-23T10:50:12Z | 39,103,583 | <p>PyCharm (or any other IDE) can't find most methods (<code>query()</code>, <code>add()</code>, <code>commit()</code> etc) as they are not defined in <code>flask_sqlalchemy.SQLAlchemy</code> class. SQLAlchemy methods are added to <code>flask_sqlalchemy.SQLAlchemy</code> objects dynamically during initialization. You c... | 0 | 2016-08-23T14:10:35Z | [
"python",
"autocomplete",
"sqlalchemy",
"pycharm",
"flask-sqlalchemy"
] |
In Python, how do I select the columns of a dataframe satisfying a condition on the number of NaN? | 39,099,143 | <p>I hope someone could help me. I'm new to Python, and I have a dataframe with 111 columns and over 40 000 rows. All the columns contain NaN values (some columns contain more NaN's than others), so I want to drop those columns having at least 80% of NaN values. How can I do this?</p>
<p>To solve my problem, I tried t... | 0 | 2016-08-23T10:51:45Z | 39,099,887 | <p>You could do this:</p>
<pre><code>filt = df.isnull().sum()/len(df) < 0.8
df1 = df.loc[:, filt]
</code></pre>
| 2 | 2016-08-23T11:26:58Z | [
"python",
"apply",
null
] |
In Python, how do I select the columns of a dataframe satisfying a condition on the number of NaN? | 39,099,143 | <p>I hope someone could help me. I'm new to Python, and I have a dataframe with 111 columns and over 40 000 rows. All the columns contain NaN values (some columns contain more NaN's than others), so I want to drop those columns having at least 80% of NaN values. How can I do this?</p>
<p>To solve my problem, I tried t... | 0 | 2016-08-23T10:51:45Z | 39,100,029 | <p>You want to achieve two things. First, you have to find the indices of all columns which contain at most 80% <code>NaN</code>s. Second, you want to discard them from your <code>DataFrame</code>.</p>
<p>To get a <code>pandas</code> <code>Series</code> indicating whether a row should be discarded by doing, you can do... | 2 | 2016-08-23T11:32:50Z | [
"python",
"apply",
null
] |
Pandas reduce number of categorical variables | 39,099,217 | <p>New to pandas I want to perform something similar to <a href="http://stackoverflow.com/questions/39066382/reduce-number-of-levels-for-large-categorical-variables?noredirect=1#comment65482577_39066382">Reduce number of levels for large categorical variables</a> (binning of categorical variables in order to reduce the... | 0 | 2016-08-23T10:55:00Z | 39,099,960 | <p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow"><code>value_counts</code></a> with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a>, where is condition w... | 1 | 2016-08-23T11:30:08Z | [
"python",
"pandas",
"categorical-data",
"binning"
] |
Is it safe to inject context into a eventlet thread like this? | 39,099,325 | <p>I need to inject thread level context information for logging and debugging purposes. I've been told that this is potentially unsafe.</p>
<pre><code>greenthread = worker_pool.spawn(run_worker, args, handle_result)
# this logging_context attribute will be accessed by the logging library
greenthread.__dict__['logging... | 3 | 2016-08-23T10:59:42Z | 39,119,196 | <p>I agree, "safe/unsafe" is for obsessed parents. As programmers we can define expectancy for troubles in a much more strict and useful way.</p>
<ul>
<li>That approach works now, so while eventlet and greenlet versions are locked, it will work and everything is great.</li>
<li>You're changing Greenthread attributes a... | 1 | 2016-08-24T09:17:26Z | [
"python",
"multithreading",
"logging",
"eventlet"
] |
In python, apply path (URL) of unknown length to a JSON object | 39,099,591 | <p>Given paths (<em>foos</em>) of unknown length, and associated values (<em>bars</em>):</p>
<pre><code>foo1 = '/path/key1'
foo2 = '/path/node1/key2'
bar1 = 'value1'
bar2 = 'value2'
</code></pre>
<p>How can I recursively map these to a json structure, for example using python's json module? The above would become:</... | 0 | 2016-08-23T11:12:08Z | 39,100,568 | <p>To get a recursive dictionary, you can use this helper class</p>
<pre><code>class RecursiveDict(dict):
def __missing__(self, attr):
db = RecursiveDict()
super(RecursiveDict, self).__setitem__(attr, db)
return db
def __setitem__(self, attr, value):
if isinstance(attr, (tuple,... | 2 | 2016-08-23T11:59:36Z | [
"python",
"json",
"dictionary",
"recursion"
] |
Confused how to extract value from a list of dictionaries | 39,099,608 | <pre><code>diction_a = {'x': {'zebra':'white', 'raptors':'bosh', 'teams' : [{'a': 0, 'b': '123456', 'c': 1, 'd': 'xuix'}, {'a': 0, 'b': '234567', 'c': 1, 'd': 'lebron?', 'owner': 'heat'}, {'a': 0, 'b': '7890324', 'c': 1, 'd': 'durant'}, ..{many more with similar format}]
</code></pre>
<p>So I'm given diction_a as the... | -2 | 2016-08-23T11:12:56Z | 39,100,145 | <p>You should confirm first your data structure is correct, here's a working example using exactly your code:</p>
<pre><code>diction_a = {
'x': {
'zebra': 'white',
'raptors': 'bosh',
'teams': [
{
'a': 0,
'b': '123456',
'c': 1,
... | -1 | 2016-08-23T11:38:38Z | [
"python",
"python-3.x",
"dictionary"
] |
Confused how to extract value from a list of dictionaries | 39,099,608 | <pre><code>diction_a = {'x': {'zebra':'white', 'raptors':'bosh', 'teams' : [{'a': 0, 'b': '123456', 'c': 1, 'd': 'xuix'}, {'a': 0, 'b': '234567', 'c': 1, 'd': 'lebron?', 'owner': 'heat'}, {'a': 0, 'b': '7890324', 'c': 1, 'd': 'durant'}, ..{many more with similar format}]
</code></pre>
<p>So I'm given diction_a as the... | -2 | 2016-08-23T11:12:56Z | 39,100,665 | <pre><code>print [val['b'] for x in diction_a.values() for val in x['teams'] ]
</code></pre>
<p>Input : </p>
<pre><code>diction_a = {'x': {'zebra':'white', 'raptors':'bosh','teams' : [{'a': 0, 'b': '123456', 'c': 1, 'd': 'xuix'}, {'a': 0, 'b': '234567', 'c': 1, 'd': 'lebron?', 'owner': 'heat'},{'a': 0, 'b': '78903... | 0 | 2016-08-23T12:03:53Z | [
"python",
"python-3.x",
"dictionary"
] |
Openerp Schdular execute at once | 39,099,616 | <p>I have created scheduled task and in local-host the scheduler with the function is working fine. In server I set Number of Calls=10, Interval Unit = Minutes and Interval Number = 1 </p>
<p>The issue is when the server start after the particular upgrades , after only one minute the Number of Calls shows as 0 instead... | 0 | 2016-08-23T11:13:26Z | 39,138,344 | <p>The problem you're having is with <code>Repeat missed</code></p>
<p>When you set it to True, it means that missed actions that were missed when the server was done should be executed when the server restarts, so if the server was down for at least 10 minutes, when you restart it all the actions that were missed dur... | 1 | 2016-08-25T06:41:09Z | [
"python",
"openerp",
"openerp-7"
] |
Generate different name of text file at every hit | 39,099,766 | <p>I have an endpoint hosted in ec2 machine. This endpoint has a piece of code that has to generate a text file.<br>
I want that if multiple people are hitting this endpoint, then this snippet should generate different text file name for each of them.</p>
<p>I tried using md5 hash in Python. but unable to append this ... | -1 | 2016-08-23T11:21:23Z | 39,099,849 | <p>You try to open <code>name.txt</code>, where you should try to open <code>name</code>.</p>
<p>It is also not very often seen that you assign the <code>open()</code> value to sys.stdout. Better to use a variable of your own (<code>fp</code>, <code>stream</code>) instead.</p>
| 1 | 2016-08-23T11:24:59Z | [
"python",
"md5"
] |
Storing tweets in MongoDB using pymongo | 39,099,914 | <p>I am trying to save tweets directly from <code>Twitter</code> into <code>MongoDB</code> for retrieval later, but I keep getting error messages with regards to <code>json</code>. Someone please help! Here is the sample codes with error messages.</p>
<pre><code>searcher = keywordSearcher('','','') ## this is an objec... | 0 | 2016-08-23T11:28:15Z | 39,100,778 | <p>Your <code>searcher.getTwitterComment</code> returns a dictionary and not json. </p>
<p>That is why you get this error, <code>json.load()</code> is already called probably. </p>
| 1 | 2016-08-23T12:09:26Z | [
"python",
"mongodb"
] |
Storing tweets in MongoDB using pymongo | 39,099,914 | <p>I am trying to save tweets directly from <code>Twitter</code> into <code>MongoDB</code> for retrieval later, but I keep getting error messages with regards to <code>json</code>. Someone please help! Here is the sample codes with error messages.</p>
<pre><code>searcher = keywordSearcher('','','') ## this is an objec... | 0 | 2016-08-23T11:28:15Z | 39,100,789 | <p>The error message indicates you are trying to <code>load</code> a dictionary object. This means you already have a dictionary object. I'm not sure what the point of the <code>json.load</code> would be even if it did work. </p>
<p>So you can probably just do:</p>
<pre><code>py_dict = searcher.getTwitterComment("Oly... | 1 | 2016-08-23T12:10:07Z | [
"python",
"mongodb"
] |
Updating global object from python threads/processes | 39,099,938 | <p>I'm trying to access a global dict from different threads. A complete example is below:</p>
<pre><code>results = {0: 'pass'}
def checkResult(thread_num, result_map):
while(True):
results[thread_num] = 'fail'
print('Thread results : '+str(results))
time.sleep(5)
multiprocessing.Process(... | 0 | 2016-08-23T11:29:12Z | 39,102,788 | <p>What you need is parallel access to a global object which can be done by using threads instead of processes. All threads share the same adressspace which means, they have access to the same refereces.
(also instead of using a dict with integer-keys, you could use a list)</p>
<p>If you're using unique "thread number... | 1 | 2016-08-23T13:36:21Z | [
"python",
"multithreading"
] |
Define custom function in selenium python | 39,099,961 | <p>How I can define custom function and then use it in test function, it works when I run single test case but don't work when I run multiple test cases.</p>
<pre><code>class AlphaTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)... | 0 | 2016-08-23T11:30:12Z | 39,102,045 | <p>You could use <code>unittest.setUpClass()</code> to instantiate a class level <code>driver</code> instance. Similarly you can use <code>tearDownClass()</code> to clean up class level variables if required. </p>
<p>Since <code>setUpClass()</code> and <code>tearDownClass()</code> will only be run once inside your Te... | 0 | 2016-08-23T13:03:29Z | [
"python",
"selenium"
] |
How do I count number of tabs in screenshot using OpenCV houghlines? | 39,100,020 | <p>I am trying to count number of tabs in screenshot using OpenCV. I first cropped my image to limit to chrome tabs. Then I used edge detection, Canny algorithm to find edges in chrome. Then I am using Houghlines to find number of tabs, but I am not getting the required ouput through Houghlines. Below is my code and o... | 0 | 2016-08-23T11:32:19Z | 39,104,369 | <p>Very interesting:D
A really simple solution would be to binarize your image and to define a line in the upper area of the image and get the gray values. Then you could count the intersections. Here is an example:
<a href="http://i.stack.imgur.com/40O9Z.png" rel="nofollow"><img src="http://i.stack.imgur.com/40O9Z.pn... | 4 | 2016-08-23T14:47:57Z | [
"python",
"opencv",
"image-processing",
"edge-detection",
"hough-transform"
] |
How to capture value of dropdown widget in bokeh python? | 39,100,095 | <p>The official documentation of bokeh 0.12.1 in the link give the below code for creating a dropdown. </p>
<p><a href="http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/widgets.html#userguide-interaction-widgets" rel="nofollow">http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/widgets.html#use... | 0 | 2016-08-23T11:36:24Z | 39,100,521 | <p>If you set on_change e.g. as follows:</p>
<pre><code>dropdown.on_change('value', function_to_call)
</code></pre>
<p>one can access the value of the selected item in <code>function_to_call</code> as follows:</p>
<pre><code>def function_to_call(attr, old, new):
print dropdown.value
</code></pre>
<p>For this to... | 2 | 2016-08-23T11:56:44Z | [
"python",
"plot",
"widget",
"data-visualization",
"bokeh"
] |
How to improve python import speed? | 39,100,391 | <p>This question has been asked many times on SO (for instance <a href="http://stackoverflow.com/q/16373510/2612235">here</a>), but there is no real answer yet.</p>
<p>I am writing a short command line tool that renders templates. It is frigged using a Makefile: </p>
<pre><code>i = $(wildcard *.in)
o = $(patsubst %.i... | 0 | 2016-08-23T11:50:33Z | 39,100,537 | <p>You could use <a href="https://docs.python.org/2/library/glob.html" rel="nofollow"><code>glob</code></a> to perform that actions with the files you need.</p>
<pre><code>import glob
in_files=glob.glob('*.in')
out_files=glob.glob('*.out')
</code></pre>
<p>Thus, you process all the files in the same script, instead... | 0 | 2016-08-23T11:58:00Z | [
"python",
"performance",
"python-import"
] |
How to improve python import speed? | 39,100,391 | <p>This question has been asked many times on SO (for instance <a href="http://stackoverflow.com/q/16373510/2612235">here</a>), but there is no real answer yet.</p>
<p>I am writing a short command line tool that renders templates. It is frigged using a Makefile: </p>
<pre><code>i = $(wildcard *.in)
o = $(patsubst %.i... | 0 | 2016-08-23T11:50:33Z | 39,100,627 | <p>It seems quite clear where the problem is, right now you got:</p>
<p><code>cost(file) = 1.2s = 60ms + 1040ms</code>, which means:</p>
<p><code>cost(N*files) = N*1.2s</code></p>
<p>now, why don't you change it to become:</p>
<p><code>cost1(files) = 1040ms + N*60ms</code></p>
<p>that way, theorically processing 1... | 0 | 2016-08-23T12:02:12Z | [
"python",
"performance",
"python-import"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.