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 |
|---|---|---|---|---|---|---|---|---|---|
How to manage different labels in a bar chart, taking data from a text file? | 40,002,896 | <p>I'm new in using matplotlib, so I'm having some problems. I must create a bar chart with different labels, for each website that I have.
The file is like the following:</p>
<pre><code>1001 adblock 12
1001 badger 11
1001 disconnect 15
1001 ghostery 15
1001 nottrack 14
1001 origin 15
1001 policy 16
1001 ultimate 14
4... | 0 | 2016-10-12T15:46:36Z | 40,003,947 | <p>Let's assume that you have read the websites into 8 different datasets (adblock, badger, disconnect, etc). You can then use the logic below to plot each series and show their labels on a legend. </p>
<pre><code>import numpy
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
#this is your number of datasets
x... | 0 | 2016-10-12T16:41:29Z | [
"python",
"matplotlib"
] |
How to manage different labels in a bar chart, taking data from a text file? | 40,002,896 | <p>I'm new in using matplotlib, so I'm having some problems. I must create a bar chart with different labels, for each website that I have.
The file is like the following:</p>
<pre><code>1001 adblock 12
1001 badger 11
1001 disconnect 15
1001 ghostery 15
1001 nottrack 14
1001 origin 15
1001 policy 16
1001 ultimate 14
4... | 0 | 2016-10-12T15:46:36Z | 40,008,433 | <p><code>seaborn</code> does this neatly:</p>
<pre><code>from pandas import read_csv
from matplotlib.pyplot import show
from seaborn import factorplot
fil = read_csv('multi_bar.txt', sep=r'\s*', engine='python', header=None)
fil.columns=['site','type','value']
factorplot(data=fil, x='site', y='value', hue='type', ki... | 0 | 2016-10-12T21:11:55Z | [
"python",
"matplotlib"
] |
pandas: How to format timestamp axis labels nicely in df.plt()? | 40,002,953 | <p>I have a dataset that looks like this:</p>
<pre><code> prod_code month items cost
0 040201060AAAIAI 2016-05-01 5 572.20
1 040201060AAAKAK 2016-05-01 164 14805.19
2 040201060AAALAL 2016-05-01 13465 14486.07
</code></pre>
<p>Doing <code>df.dtypes</code> shows that the <code... | 2 | 2016-10-12T15:49:48Z | 40,003,927 | <p>If you set the dates as index, the x-axis should be labelled properly:</p>
<pre><code>df[df.bnf_code=='040201060AAAIAI'][['month', 'cost']].set_index('month').plot()
</code></pre>
<p>I have simply added <code>set_index</code> to your code.</p>
| 2 | 2016-10-12T16:40:01Z | [
"python",
"pandas",
"matplotlib"
] |
How to elegantly create a pyspark Dataframe from a csv file and convert it to a Pandas Dataframe? | 40,003,021 | <p>I'm having a CSV file which I want to read into an RDD or DataFrame. This is working so far, but if I collect the data and convert it into a pandas DataFrame for plotting the table is "malformed".</p>
<p>Here is how I read the CSV file:</p>
<pre><code>NUMERIC_DATA_FILE = os.path.join(DATA_DIR, "train_numeric.csv")... | 1 | 2016-10-12T15:53:29Z | 40,004,222 | <h2>Setting a schema for your PySpark DataFrame</h2>
<p>Your PySpark DataFrame does not have a schema assigned to it. You should replace your code with the snippet below:</p>
<pre><code>from pyspark.sql.types import *
NUMERIC_DATA_FILE = sc.textFile(os.path.join(DATA_DIR, "train_numeric.csv"))
# Extract the header l... | 0 | 2016-10-12T16:55:46Z | [
"python",
"pandas",
"pyspark"
] |
Why does __slots__ = ('__dict__',) produce smaller instances? | 40,003,067 | <pre><code>class Spam(object):
__slots__ = ('__dict__',)
</code></pre>
<p>Produces instances smaller than those of a "normal" class. Why is this?</p>
<p>Source: <a href="https://twitter.com/dabeaz/status/785948782219231232" rel="nofollow">David Beazley's recent tweet</a>. </p>
| 5 | 2016-10-12T15:55:31Z | 40,003,530 | <p>To me, it looks like the memory savings come from the lack of a <code>__weakref__</code> on the instance.</p>
<p>So if we have:</p>
<pre><code>class Spam1(object):
__slots__ = ('__dict__',)
class Spam2(object):
__slots__ = ('__dict__', '__weakref__')
class Spam3(object):
__slots__ = ('foo',)
class E... | 7 | 2016-10-12T16:18:18Z | [
"python",
"class",
"python-3.x"
] |
Create List without similar crossovers | 40,003,094 | <p>I am trying to build a list of length = 120, which shall include 4 numbers.
The tricky thing is that the numbers shall not appear in a row and each number should occur exactly to the same amount.</p>
<p>This is my script. </p>
<pre><code>import random
List = [1,2,3,4]
seq_CG = random.sample(List,len(List))
for i i... | 2 | 2016-10-12T15:57:14Z | 40,003,830 | <p>A slightly naive approach is to have an infinite loop, then scrunch up duplicate values, using <code>islice</code> to cap the total required output, eg:</p>
<pre><code>from itertools import groupby
from random import choice
def non_repeating(values):
if not len(values) > 1:
raise ValueError('must ha... | 2 | 2016-10-12T16:35:11Z | [
"python",
"python-2.7",
"open-sesame"
] |
Create List without similar crossovers | 40,003,094 | <p>I am trying to build a list of length = 120, which shall include 4 numbers.
The tricky thing is that the numbers shall not appear in a row and each number should occur exactly to the same amount.</p>
<p>This is my script. </p>
<pre><code>import random
List = [1,2,3,4]
seq_CG = random.sample(List,len(List))
for i i... | 2 | 2016-10-12T15:57:14Z | 40,020,074 | <p>Here are a couple of solutions. </p>
<p>The first algorithm maintains an index <code>idx</code> into the sequence and on each call <code>idx</code> is randomly modified to a different index so it's impossible for a yielded value to equal the previous value. </p>
<pre><code>from random import randrange
from itertoo... | 3 | 2016-10-13T11:45:49Z | [
"python",
"python-2.7",
"open-sesame"
] |
How do I complete this function? | 40,003,197 | <p>For your assignment you must write a compare function that returns 1 if a > b , 0 if a == b , and -1 if a < b . The user must be prompted for the values of a and b. The compare function must have arguments for a and b. To demonstrate your compare function, you must call the compare function three times, once for ... | -1 | 2016-10-12T16:02:26Z | 40,003,389 | <p>For asking user for an input</p>
<ul>
<li>Use <code>input</code> function if you are using Python 3 </li>
<li>Use <code>raw_input</code> function for Python 2.x</li>
</ul>
<p>Convert the input into integer since the input values will be string.</p>
<p>Then call the compare function and get the value returned from... | 0 | 2016-10-12T16:11:51Z | [
"python"
] |
How do I complete this function? | 40,003,197 | <p>For your assignment you must write a compare function that returns 1 if a > b , 0 if a == b , and -1 if a < b . The user must be prompted for the values of a and b. The compare function must have arguments for a and b. To demonstrate your compare function, you must call the compare function three times, once for ... | -1 | 2016-10-12T16:02:26Z | 40,003,506 | <p>Here is a menu driven solution that will run three times as desired.</p>
<pre><code> def compare(a,b):
if (a == b):
return 0
elif (a > b):
return 1
else:
return -1
counter =0
while counter < 3:
response=raw_input("Enter a Value for a and b [e.g. (4,5) ] : ")
... | 0 | 2016-10-12T16:17:20Z | [
"python"
] |
Calling script in standard project directory structure (Python path for bin subdirectory) | 40,003,221 | <p>I am experimenting with putting my Python code into the standard directory structure used for deployment with <code>setup.py</code> and maybe PyPI. for a Python library called mylib it would be something like this:</p>
<pre><code>mylibsrc/
README.rst
setup.py
bin/
some_script.py
mylib/
__init.py__
... | 1 | 2016-10-12T16:03:37Z | 40,021,910 | <p>The simplest way is to use <code>setuptools</code> in your <code>setup.py</code> script, and use the <code>entry_points</code> keyword, see the documentation of <a href="http://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation" rel="nofollow">Automatic Script Creation</a>.</p>
<p>In more... | 1 | 2016-10-13T13:07:18Z | [
"python",
"setup.py"
] |
how to create auto increment field in odoo 9 | 40,003,289 | <p>In my model, I want to create auto increment field, I 've tried to follow some tuts unfortunately all tutorials just working in odoo 8 to under.
I just follow instruction from some threat in odoo 9 in this link
<a href="http://stackoverflow.com/questions/39266106/auto-increment-internal-reference-odoo9">auto increm... | 1 | 2016-10-12T16:07:03Z | 40,003,443 | <p>Try with following code.</p>
<p>Replace <em>create</em> method with</p>
<pre><code>@api.model
def create(self, vals):
vals['sequence_id'] = self.env['ir.sequence'].get('comben.cashadvance')
return super(cashadvance, self).create(vals)
</code></pre>
<p>Replace <em>xml</em> file with</p>
<pre><code><?xm... | 1 | 2016-10-12T16:14:48Z | [
"python",
"python-2.7",
"openerp",
"odoo-9"
] |
Redirect subprocess.Popen stderr to console | 40,003,301 | <p>I am executing a make command using subprocess.Popen. But when the make fails I do not get the exact error from make and th escript just continues to run. How do I get the script to stop and show the console exactly the output of the make command</p>
<pre><code>def app(self, build, soc, target):
command = "make... | 0 | 2016-10-12T16:07:58Z | 40,004,630 | <p>Could you try replacing:</p>
<pre><code>subprocess.Popen(command.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
</code></pre>
<p>with:</p>
<pre><code>p = subprocess.Popen(command.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print p.communicate()
print ... | 2 | 2016-10-12T17:19:05Z | [
"python"
] |
Redirect subprocess.Popen stderr to console | 40,003,301 | <p>I am executing a make command using subprocess.Popen. But when the make fails I do not get the exact error from make and th escript just continues to run. How do I get the script to stop and show the console exactly the output of the make command</p>
<pre><code>def app(self, build, soc, target):
command = "make... | 0 | 2016-10-12T16:07:58Z | 40,004,792 | <p>If you want the make output to actually go to the console, don't use <code>subprocess.PIPE</code> for stdout/stderr. By default, the called process will use the Python process's stdout/stderr handles. In that case, you can use the <code>subprocess.check_call()</code> function to raise a <code>subprocess.CalledProc... | 0 | 2016-10-12T17:27:28Z | [
"python"
] |
How can I replace all occurrences of a substring using regex? | 40,003,311 | <p>I have a string, <code>s = 'sdfjoiweng%@$foo$fsoifjoi'</code>, and I would like to replace <code>'foo'</code> with <code>'bar'</code>. </p>
<p>I tried <code>re.sub(r'\bfoo\b', 'bar', s)</code> and <code>re.sub(r'[foo]', 'bar', s)</code>, but it doesn't do anything. What am I doing wrong?</p>
| 0 | 2016-10-12T16:08:14Z | 40,003,366 | <p>You can replace it directly:</p>
<pre><code>>>> import re
>>> s = 'sdfjoiweng%@$foo$fsoifjoi'
>>> print re.sub('foo','bar',s)
sdfjoiweng%@$bar$fsoifjoi
</code></pre>
<p>It will also work for more occurrences of <code>foo</code> like below:</p>
<pre><code>>>> s = 'sdfjoiweng%@$f... | 3 | 2016-10-12T16:10:36Z | [
"python",
"regex"
] |
How can I replace all occurrences of a substring using regex? | 40,003,311 | <p>I have a string, <code>s = 'sdfjoiweng%@$foo$fsoifjoi'</code>, and I would like to replace <code>'foo'</code> with <code>'bar'</code>. </p>
<p>I tried <code>re.sub(r'\bfoo\b', 'bar', s)</code> and <code>re.sub(r'[foo]', 'bar', s)</code>, but it doesn't do anything. What am I doing wrong?</p>
| 0 | 2016-10-12T16:08:14Z | 40,003,398 | <blockquote>
<p><code>re.sub(r'\bfoo\b', 'bar', s)</code></p>
</blockquote>
<p>Here, the <code>\b</code> defines <a href="http://www.regular-expressions.info/wordboundaries.html" rel="nofollow">the word boundaries</a> - positions between a word character (<code>\w</code>) and a non-word character - exactly what you ... | 2 | 2016-10-12T16:12:26Z | [
"python",
"regex"
] |
How can I replace all occurrences of a substring using regex? | 40,003,311 | <p>I have a string, <code>s = 'sdfjoiweng%@$foo$fsoifjoi'</code>, and I would like to replace <code>'foo'</code> with <code>'bar'</code>. </p>
<p>I tried <code>re.sub(r'\bfoo\b', 'bar', s)</code> and <code>re.sub(r'[foo]', 'bar', s)</code>, but it doesn't do anything. What am I doing wrong?</p>
| 0 | 2016-10-12T16:08:14Z | 40,003,531 | <p>You can use replace function directly instead of using regex.</p>
<pre><code>>>> s = 'sdfjoiweng%@$foo$fsoifjoifoo'
>>>
>>> s.replace("foo","bar")
'sdfjoiweng%@$bar$fsoifjoibar'
>>>
>>>
</code></pre>
| 2 | 2016-10-12T16:18:23Z | [
"python",
"regex"
] |
Extracting particular data with BeautifulSoup with span tags | 40,003,342 | <p>I have this structure.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="one" class="tab-pane active">
<div class="item-content">
<a hre... | 0 | 2016-10-12T16:09:23Z | 40,004,347 | <p>You could try that:</p>
<pre><code>from bs4 import BeautifulSoup
soup = BeautifulSoup(source, "html.parser")
div1 = soup.find("div", { "class" : "item-labels" }).findAll('span', { "class" : "item-manufacturer" })
div2 = soup.find("div", { "class" : "item-labels" }).findAll('span', { "class" : "item-title" })
div3 ... | 1 | 2016-10-12T17:02:21Z | [
"python",
"html",
"web-scraping",
"beautifulsoup"
] |
Matching multiple patterns in a string | 40,003,362 | <p>I have a string that looks like that:</p>
<pre><code>s = "[A] text [B] more text [C] something ... [A] hello"
</code></pre>
<p>basically it consists of <code>[X] chars</code> and I am trying to get the text "after" every <code>[X]</code>.</p>
<p>I would like to yield this dict (I don't care about order):</p>
<pr... | 1 | 2016-10-12T16:10:21Z | 40,003,541 | <blockquote>
<p>Expected output: <code>mydict = {"A":"text, hello", "B":"more text", "C":"something"}</code></p>
</blockquote>
<pre><code>import re
s = "[A] text [B] more text [C] something ... [A] hello"
pattern = r'\[([A-Z])\]([ a-z]+)'
items = re.findall(pattern, s)
output_dict = {}
for x in items:
if x[... | 1 | 2016-10-12T16:18:41Z | [
"python",
"regex"
] |
Matching multiple patterns in a string | 40,003,362 | <p>I have a string that looks like that:</p>
<pre><code>s = "[A] text [B] more text [C] something ... [A] hello"
</code></pre>
<p>basically it consists of <code>[X] chars</code> and I am trying to get the text "after" every <code>[X]</code>.</p>
<p>I would like to yield this dict (I don't care about order):</p>
<pr... | 1 | 2016-10-12T16:10:21Z | 40,003,571 | <p>Not sure if this is quite what you're looking for but it fails with duplicates</p>
<pre><code>s = "[A] hello, [C] text [A] more text [B] something"
results = [text.strip() for text in re.split('\[.\]', s) if text]
letters = re.findall('\[(.)\]', s)
dict(zip(letters, results))
{'A': 'more text', 'B': 'something'... | 3 | 2016-10-12T16:19:59Z | [
"python",
"regex"
] |
Matching multiple patterns in a string | 40,003,362 | <p>I have a string that looks like that:</p>
<pre><code>s = "[A] text [B] more text [C] something ... [A] hello"
</code></pre>
<p>basically it consists of <code>[X] chars</code> and I am trying to get the text "after" every <code>[X]</code>.</p>
<p>I would like to yield this dict (I don't care about order):</p>
<pr... | 1 | 2016-10-12T16:10:21Z | 40,003,902 | <p>Here's a simple solution:</p>
<pre class="lang-or-tag-here prettyprint-override"><code>#!/usr/bin/python
import re
s = "[A] text [B] more text [C] something ... [A] hello"
d = dict()
for x in re.findall(r"\[[^\]+]\][^\[]*",s):
m = re.match(r"\[([^\]*])\](.*)",x)
if not d.get(m.group(1),0):
#Key do... | 0 | 2016-10-12T16:38:54Z | [
"python",
"regex"
] |
PEP8 error in import line: E501 line too long | 40,003,378 | <p>I have a python import string. PEP8 linter show to me E501 error <code>line too long (82 > 79 characters)</code>:</p>
<pre><code>from tornado.options import define, options, parse_config_file, parse_command_line
</code></pre>
<p>Solution with two line seems weird to me:</p>
<pre><code>from tornado.options impo... | 2 | 2016-10-12T16:11:13Z | 40,003,478 | <p>Put your imported names in parentheses, letting you span multiple lines:</p>
<pre><code>from tornado.options import (
define,
options,
parse_config_file,
parse_command_line,
)
</code></pre>
<p>Using one line per name has the added advantage that later edits to the list of names imported reduce line... | 5 | 2016-10-12T16:16:05Z | [
"python",
"coding-style",
"pep8"
] |
PEP8 error in import line: E501 line too long | 40,003,378 | <p>I have a python import string. PEP8 linter show to me E501 error <code>line too long (82 > 79 characters)</code>:</p>
<pre><code>from tornado.options import define, options, parse_config_file, parse_command_line
</code></pre>
<p>Solution with two line seems weird to me:</p>
<pre><code>from tornado.options impo... | 2 | 2016-10-12T16:11:13Z | 40,003,519 | <p>See <a href="https://www.python.org/dev/peps/pep-0328/" rel="nofollow">PEP 328</a> for your options. Parentheses are probably the way to go.</p>
| 1 | 2016-10-12T16:17:44Z | [
"python",
"coding-style",
"pep8"
] |
PEP8 error in import line: E501 line too long | 40,003,378 | <p>I have a python import string. PEP8 linter show to me E501 error <code>line too long (82 > 79 characters)</code>:</p>
<pre><code>from tornado.options import define, options, parse_config_file, parse_command_line
</code></pre>
<p>Solution with two line seems weird to me:</p>
<pre><code>from tornado.options impo... | 2 | 2016-10-12T16:11:13Z | 40,003,609 | <p>You should write it the way you think is more readable.. the 80 column limit was put in place for old style terminals that did not support re-sizing, which itself was for legacy support of terminal only computers where the monitor was only 80 chars wide. See: <a href="https://www.python.org/dev/peps/pep-0008/#a-fool... | 0 | 2016-10-12T16:22:24Z | [
"python",
"coding-style",
"pep8"
] |
How to capture the prints of a python script being executed from another python script? | 40,003,483 | <p>I have 2 scripts <code>script1.py</code> and <code>script2.py</code> in the same folder ,script1.py calls script2.py using Popen(See code below for details),issue is that the prints coming from script2.py is not being captured in script1.py,<code>print output</code> and <code>print error</code> doesn't print a thing... | 1 | 2016-10-12T16:16:19Z | 40,004,066 | <p><strong>Edited answer based on comments</strong></p>
<p>Looks like after the edits you made to the original question, Your code is working correctly.
I just put <code>output=</code> in front of print statement to check that.</p>
<pre><code>import subprocess
from subprocess import Popen, PIPE, STDOUT
def func1 ():
... | 3 | 2016-10-12T16:47:43Z | [
"python",
"popen"
] |
How to capture the prints of a python script being executed from another python script? | 40,003,483 | <p>I have 2 scripts <code>script1.py</code> and <code>script2.py</code> in the same folder ,script1.py calls script2.py using Popen(See code below for details),issue is that the prints coming from script2.py is not being captured in script1.py,<code>print output</code> and <code>print error</code> doesn't print a thing... | 1 | 2016-10-12T16:16:19Z | 40,004,373 | <p>your script is in fact working as intended. You likely are expecting a traceback to be printed to stderr of your subprocess, but that's not how <code>sys.exit()</code> works.</p>
<h3>script1.py</h3>
<pre class="lang-python prettyprint-override"><code>import subprocess
from subprocess import Popen, PIPE, STDOUT
def... | 1 | 2016-10-12T17:03:41Z | [
"python",
"popen"
] |
Web in python that interacts with linux | 40,003,543 | <p>Is there a way to make web in python (mixed with <code>html/php</code>) that interacts with PC (<code>linux</code> OS) ?</p>
<p>As example: you click button in webpage and It sends command to PC (<code>linux</code>) that activates another <code>python</code> script, but not in web format (example: I push button 'RU... | -3 | 2016-10-12T16:18:45Z | 40,003,875 | <p>Yes, it is possible. Here is one way to do it.</p>
<pre><code>#!/usr/bin/env python
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def root():
return '''
<html><body><form action="/run" method="post">
<input type="submit" value="Run Python Sc... | 3 | 2016-10-12T16:37:29Z | [
"php",
"python",
"linux"
] |
python pandas, trying to find unique combinations of two columns and merging while summing a third column | 40,003,559 | <p>Hi I will show what im trying to do through examples:
I start with a dataframe like this:</p>
<pre><code>> pd.DataFrame({'A':['a','a','a','c'],'B':[1,1,2,3], 'count':[5,6,1,7]})
A B count
0 a 1 5
1 a 1 6
2 a 2 1
3 c 3 7
</code></pre>
<p>I need to find a way to get all the unique ... | 3 | 2016-10-12T16:19:14Z | 40,003,588 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with aggregating <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.sum.html" rel="nofollow"><code>sum</code></a>:</p>
<pre><code>print (d... | 4 | 2016-10-12T16:21:14Z | [
"python",
"pandas",
"group-by",
"sum",
"aggregate"
] |
Python telnet client | 40,003,572 | <p>Everyone, hello!</p>
<p>I'm currently trying to use Telnetlib (<a href="https://docs.python.org/2/library/telnetlib.html" rel="nofollow">https://docs.python.org/2/library/telnetlib.html</a>) for Python 2.7 to communicate with some external devices.</p>
<p>I have the basics set up:</p>
<pre><code>import sys
import... | 2 | 2016-10-12T16:20:02Z | 40,054,951 | <p>Seems like you want to connect to external device once and print a message each time you see a specific string.</p>
<pre><code>import sys
import telnetlib
tn_ip = "0.0.0.0"
tn_port = "23"
tn_username = "xxxxx"
tn_password = "xxxx"
searchfor = "Specificdata"
def telnet():
try:
tn = telnetlib.Telnet(tn... | 0 | 2016-10-15T04:28:38Z | [
"python",
"telnet",
"telnetlib"
] |
Python3, PyQt5: QProgressBar updating makes actual task very slow | 40,003,598 | <p>I am using Python 3.5, PyQt5 on OSX and I was wondering if there was a possibility to update the QProgressBar without slowing down the whole computing work.
Here was my code and if I did just the task without the progressbar update it was soo much faster!! </p>
<pre><code>from PyQt5.QtWidgets import (QWidget, QProg... | 1 | 2016-10-12T16:22:02Z | 40,005,253 | <p>There are three things slowing the code down:</p>
<ol>
<li>Printing to stdout is very expensive - especially when you do it 500,000 times! On my system, commenting out <code>print(i,j)</code> roughly halves the time <code>doAction</code> takes to run.</li>
<li>It's also quite expensive to call <code>processEvents</... | 0 | 2016-10-12T17:54:49Z | [
"python",
"python-3.x",
"signals",
"pyqt5",
"qprogressbar"
] |
subprocess permission denied | 40,003,813 | <p>I was looking into how python can start other programs on windows 10, I was on stack overflow and someone said that:</p>
<pre><code>import subprocess
subprocess.call(['C:\\Users\Edvin\Desktop', 'C:\\Example.txt'])
</code></pre>
<p>should do it, so I changed the locations so it is specific to me and there was an er... | 0 | 2016-10-12T16:33:49Z | 40,003,957 | <p>The thing is that you're trying to launch your desktop as a program. With a text file as an argument.</p>
<p>This is not allowed because you're not allowed to execute the desktop (because it can't be executed).</p>
<pre><code>subprocess.call(["command here", "arguments here"])
</code></pre>
<p>if it's an <code>ex... | 2 | 2016-10-12T16:41:51Z | [
"python",
"windows",
"permissions",
"subprocess",
"python-3.5"
] |
How to compile python with PyInstaller in Linux | 40,003,821 | <p>I am using <code>Python 3.5.2</code> , <code>PyQt 5.7</code> , <code>PyInstaller 3.2</code> and I'm in Linux</p>
<p>I can compile file.py with : <code>pyinstaller file.py</code></p>
<p>but when I run the binary file in Build folder it returns:</p>
<p><code>Error loading Python lib '/home/arash/build/file/libpytho... | 2 | 2016-10-12T16:34:24Z | 40,005,521 | <p>If this is just about the location of that .so; see here:</p>
<pre><code>/usr/lib/python3.5 $ find . -name "*.so" | grep libpython
./config-3.5m-x86_64-linux-gnu/libpython3.5.so
./config-3.5m-x86_64-linux-gnu/libpython3.5m.so
</code></pre>
<p>Another way to find it would be by running </p>
<pre><code>> locate ... | 1 | 2016-10-12T18:09:24Z | [
"python",
"linux",
"python-3.x",
"pyqt",
"pyinstaller"
] |
How to compile python with PyInstaller in Linux | 40,003,821 | <p>I am using <code>Python 3.5.2</code> , <code>PyQt 5.7</code> , <code>PyInstaller 3.2</code> and I'm in Linux</p>
<p>I can compile file.py with : <code>pyinstaller file.py</code></p>
<p>but when I run the binary file in Build folder it returns:</p>
<p><code>Error loading Python lib '/home/arash/build/file/libpytho... | 2 | 2016-10-12T16:34:24Z | 40,005,728 | <p>the binary file is in the <code>dist</code> folder not <code>build</code> folder</p>
| 0 | 2016-10-12T18:21:31Z | [
"python",
"linux",
"python-3.x",
"pyqt",
"pyinstaller"
] |
quicksort algorithm as WIKIPEDIA says in python | 40,003,839 | <p>In Wikipedia, there is a pseudo-code of quicksort algorithm:</p>
<p>So I tried to implement in python, but it does not sort anything.</p>
<pre><code>def partition(A,lo,hi):
pivot = A[hi]
i=lo
#Swap
for j in range(lo,len(A)-1):
if (A[j] <= pivot):
val=A[i]
A[i]=A[j... | 0 | 2016-10-12T16:35:32Z | 40,003,950 | <p>It doesn't throw an error or print anything because there is no main program to run anything. You indented what should be the main program, so that is now part of the <strong>quicksort</strong> function.</p>
<p>Also, this code <em>does</em> throw an error, because you left a comment in what you posted. I'll clean... | 2 | 2016-10-12T16:41:35Z | [
"python",
"algorithm",
"quicksort",
"wikipedia"
] |
Find characters in a text | 40,003,849 | <p>I want to create a python script which finds an expression in a text.
If it succeeds, then print 'expression found'.</p>
<p>My text file is named "file_id_ascii"; it comes from a link named "clinical_file_link".</p>
<pre><code> import csv
import sys
import io
file_id_ascii =
io.open(clinical_file_link, '... | 0 | 2016-10-12T16:35:53Z | 40,003,967 | <pre><code>if 'http://tcga.nci/bcr/xml/clinical/acc/' \
in open('clinical_file_link.txt').read():
print "true"
</code></pre>
<p>... works if your file has small content</p>
| 2 | 2016-10-12T16:42:19Z | [
"python",
"xml",
"csv",
"parsing"
] |
Find characters in a text | 40,003,849 | <p>I want to create a python script which finds an expression in a text.
If it succeeds, then print 'expression found'.</p>
<p>My text file is named "file_id_ascii"; it comes from a link named "clinical_file_link".</p>
<pre><code> import csv
import sys
import io
file_id_ascii =
io.open(clinical_file_link, '... | 0 | 2016-10-12T16:35:53Z | 40,003,979 | <p>It doesn't work because you are not parsing the XML.
Check this <a href="http://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python">thread</a> for more info about parsing XML.</p>
<p>If it is indeed a text file you might edit it like this:</p>
<pre><code>if acc in open(clinical_file_link.txt).read():... | 1 | 2016-10-12T16:43:16Z | [
"python",
"xml",
"csv",
"parsing"
] |
How to take set multiple variables using argparse, both required and optional variables? | 40,003,858 | <p>How do you deal with multiple inputs via <code>argparse</code>, especially when there are default inputs and optional inputs?</p>
<p>Within my script <code>file.py</code>, users must input two parameters, which I have in a list</p>
<pre><code>parameters_list = [parameter1, parameter2, parameter3]
parameter1 = "" ... | 0 | 2016-10-12T16:36:52Z | 40,004,040 | <p>One method is to parse out the parameters as comma separated values.</p>
<pre><code>import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--parameters',nargs='*',help="input program parameters")
args,unknown = parser.parse_known_args()
if(unknown):
print("Do not use spaces!")
sys.... | 1 | 2016-10-12T16:46:06Z | [
"python",
"argparse",
"optional"
] |
How to take set multiple variables using argparse, both required and optional variables? | 40,003,858 | <p>How do you deal with multiple inputs via <code>argparse</code>, especially when there are default inputs and optional inputs?</p>
<p>Within my script <code>file.py</code>, users must input two parameters, which I have in a list</p>
<pre><code>parameters_list = [parameter1, parameter2, parameter3]
parameter1 = "" ... | 0 | 2016-10-12T16:36:52Z | 40,004,305 | <p>I would just define separate parameters for each:</p>
<pre><code>p = ArgumentParser()
p.add_argument("arg1")
p.add_argument("arg2")
p.add_argument("arg3", default=5, nargs='?')
</code></pre>
<p>and require calls like</p>
<pre><code>$ python file.py 3 2
$ python file.py 3 2 6
</code></pre>
| 2 | 2016-10-12T17:00:01Z | [
"python",
"argparse",
"optional"
] |
Can't extract individual fields from scapy packet | 40,003,923 | <p>I've been experimenting with scapy and Python 3 and I want to use the ARP protocol to find mac addresses of computers on the network. This is my code:</p>
<pre><code>>>> packet = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=IP_OF_HOST))
</code></pre>
<p>Then to extract the data from this packet I used the ... | 0 | 2016-10-12T16:39:55Z | 40,005,821 | <p>It has to do with the difference between the functions srp(), and srp1() (Those being for network layer 2, for layer 3 you would use sr() and sr1() respectively).</p>
<p>srp() sends the packet, and saves all packets, whether they are answered or not. To get say the source MAC address I'd do this:</p>
<pre><code>an... | 0 | 2016-10-12T18:26:37Z | [
"python",
"python-3.x",
"attributes",
"scapy",
"arp"
] |
Finding the difference image between multiple images | 40,003,929 | <p>I've taken multiple screenshots from a webcam on my campus and I have taken the average of the 300 screenshots and it gives me an image with many ghostly people. I am trying to figure out how to get the difference image between the images so that I can change the differences to red to show is more clearly. I just ne... | 1 | 2016-10-12T16:40:06Z | 40,004,731 | <p>There are tons of ways to do this, but I will first keep closest to what you currently have. Then I will show a more compact way.</p>
<pre><code>import os, os.path, time
import matplotlib.pyplot as mplot
from PIL import Image
import numpy as np
files=os.listdir('./images')
print files
image=[]
for file in files:... | 1 | 2016-10-12T17:24:00Z | [
"python",
"image",
"numpy",
"difference"
] |
Wrong Behaviour doing tests on Django | 40,003,985 | <p>I'm having problems to do test on Django. I've been reading the documentation <a href="https://docs.djangoproject.com/en/1.10/topics/testing/tools/#testing-responses" rel="nofollow">of the responses</a> and I can't do the same as they explain on the documentation.</p>
<p>When I get the response, I only have access ... | 0 | 2016-10-12T16:43:36Z | 40,004,116 | <p>The remote authentication url expects the credentials as headers, but your local login view expects them as <code>POST</code> data. Your test passes the credentials as headers to your local view.</p>
<p>As a result, the form is passed an empty dictionary (<code>request.POST</code> contains no actual data), and the ... | 1 | 2016-10-12T16:50:04Z | [
"python",
"django",
"django-testing"
] |
pyad: Installs fine, but says it can't find adbase | 40,004,147 | <p>This has me pretty confused. I've installed pyad using pip and everything seems fine:</p>
<pre><code>C:\WINDOWS\system32>pip install pyad
Collecting pyad
Using cached pyad-0.5.16.tar.gz
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python35\lib\site-packages (from pyad)
Requirement... | 0 | 2016-10-12T16:51:51Z | 40,004,427 | <p>That's a bug on pyad part. They're importing adbase as if it were a standalone module or package, and that's why it does not work. The proper way to fix this would be to change the import to an absolute import <code>from pyad.adbase import ...</code> or relative <code>from .adbase import ...</code>.</p>
<p>However,... | 0 | 2016-10-12T17:06:30Z | [
"python",
"pip"
] |
Getting started with Regular Expressions | 40,004,211 | <p>I'm trying to simply play with regular expressions in the console, but I can't.</p>
<p>What am I doing wrong? I'm on python 3.5 I think.</p>
<p>First I tried to use <code>.replace</code> on a string object. </p>
<p>then I imported the <code>re</code> module, but even that didn't work with <code>re.sub</code></p>
... | -1 | 2016-10-12T16:54:54Z | 40,004,444 | <p>The problem is that you are trying to use regular expressions in string replaces - string replace does <strong>not</strong> support regular expressions for that you need to import and use the re or regex library.</p>
<pre><code>>>> import re
>>> m = "555.555.5555"
>>> >>> mm = re... | 2 | 2016-10-12T17:07:30Z | [
"python",
"regex",
"python-3.x",
"console"
] |
Is there python for 64bit instead of 32bit? | 40,004,277 | <p>Is there python for 64bit instead of 32bit?</p>
<p>Can't find it on downloads page on python.org</p>
<p>Thankyou</p>
| -6 | 2016-10-12T16:58:39Z | 40,004,338 | <p>Take a few steps further back, it's right in front of your nose so that's why you can't see it.</p>
<p><a href="https://www.python.org/downloads/release/python-352/" rel="nofollow">https://www.python.org/downloads/release/python-352/</a></p>
| 0 | 2016-10-12T17:01:50Z | [
"python"
] |
Is there python for 64bit instead of 32bit? | 40,004,277 | <p>Is there python for 64bit instead of 32bit?</p>
<p>Can't find it on downloads page on python.org</p>
<p>Thankyou</p>
| -6 | 2016-10-12T16:58:39Z | 40,004,383 | <p>Check <a href="https://www.python.org/downloads/release/python-352/" rel="nofollow">THIS</a> page. Depends on the OS as @birryree mentioned. There ARE 64bit editions</p>
| 1 | 2016-10-12T17:04:23Z | [
"python"
] |
Is there python for 64bit instead of 32bit? | 40,004,277 | <p>Is there python for 64bit instead of 32bit?</p>
<p>Can't find it on downloads page on python.org</p>
<p>Thankyou</p>
| -6 | 2016-10-12T16:58:39Z | 40,004,398 | <p>Check out the <a href="https://www.python.org/downloads/windows/" rel="nofollow">python downloads webpage for Windows</a>. It has the latest versions of Python as x86 and x86-64, which is the 64-bit version. </p>
<p>If you're looking for the Mac version, just look <a href="https://www.python.org/downloads/mac-osx/"... | 0 | 2016-10-12T17:05:06Z | [
"python"
] |
Is there python for 64bit instead of 32bit? | 40,004,277 | <p>Is there python for 64bit instead of 32bit?</p>
<p>Can't find it on downloads page on python.org</p>
<p>Thankyou</p>
| -6 | 2016-10-12T16:58:39Z | 40,004,433 | <p>If you are on windows, choose the x86-<strong>64</strong> option for your desired release on this page.</p>
<p><a href="https://www.python.org/downloads/windows/" rel="nofollow">https://www.python.org/downloads/windows/</a> </p>
| 1 | 2016-10-12T17:06:59Z | [
"python"
] |
Is there any way to cancel UrlRequest in Kivy? | 40,004,431 | <p>Is there any way to cancel UrlRequest in Kivy?</p>
<pre><code>def got_url(req, result):
print(result)
req = UrlRequest('http://httpbin.org/delay/2', got_url) # Request lasts 2 seconds
def my_callback(dt):
print('Request cancelled.')
# sort of req.cancel()
Clock.schedule_once(my_callback, 1) # But som... | 2 | 2016-10-12T17:06:53Z | 40,030,697 | <p>Afaik there's no other way except <code>UrlRequest.timeout</code>, which could translate to politely wait and close any harmful stuff safely. It uses <code>Thread</code> which may and may not be dangerous. Even more if e.g. packaged into exe or other form of binary where it could create a lock because something brok... | 1 | 2016-10-13T20:48:33Z | [
"python",
"kivy"
] |
is it possible to list all blocked tornado coroutines | 40,004,443 | <p>I have a "gateway" app written in <code>tornado</code> using <code>@tornado.gen.coroutine</code> to transfer information from one handler to another. I'm trying to do some debugging/status testing. What I'd like to be able to do is enumerate all of the currently blocked/waiting coroutines that are live at a given mo... | 2 | 2016-10-12T17:07:29Z | 40,005,951 | <p>You talk about ioloop <code>_handlers</code> dict maybe. Try to add this in periodic callback:</p>
<pre><code>def print_current_handlers():
io_loop = ioloop.IOLoop.current()
print io_loop._handlers
</code></pre>
<p><strong>update</strong>: I've checked source code and now think that there is no simple way ... | 2 | 2016-10-12T18:34:44Z | [
"python",
"tornado"
] |
is it possible to list all blocked tornado coroutines | 40,004,443 | <p>I have a "gateway" app written in <code>tornado</code> using <code>@tornado.gen.coroutine</code> to transfer information from one handler to another. I'm trying to do some debugging/status testing. What I'd like to be able to do is enumerate all of the currently blocked/waiting coroutines that are live at a given mo... | 2 | 2016-10-12T17:07:29Z | 40,006,626 | <p>No there isn't, but you could perhaps create your own decorator that wraps gen.coroutine, then updates a data structure when the coroutine begins.</p>
<pre><code>import weakref
import functools
from tornado import gen
from tornado.ioloop import IOLoop
all_coroutines = weakref.WeakKeyDictionary()
def tracked_cor... | 1 | 2016-10-12T19:14:40Z | [
"python",
"tornado"
] |
python changefig() takes exactly 2 arguments (1 given) | 40,004,506 | <p>I am writing a program which is supposed to give me data of a chart when i click certain buttons.
So this is the program as far as I am right now, I still have to connect the last 4 buttons but the first one works, but now there is another problem: I used to have a chart displayed as i clicked on "One Plot" but sinc... | 0 | 2016-10-12T17:11:03Z | 40,005,010 | <p>In <code>class Main</code>, you are calling <code>changefig</code> function as <code>self.mplfigs.itemClicked.connect(self.changefig)</code>.</p>
<p>But function definition of <code>changefig</code> is <code>def changefig(self, item):</code> which expects two arguments - <code>self</code> and <code>item</code>.</p>... | 0 | 2016-10-12T17:40:42Z | [
"python",
"arguments"
] |
Why does bytearray_obj.extend(bytes) differ from bytearray_obj += bytes? | 40,004,517 | <p>Just saw (and enjoyed) the video of Brandon Rhodes talking on PyCon 2015 about bytearrays.</p>
<p>He said that <code>.extend</code> method is slow, but <code>+=</code> operation is implemented differently and is much more efficient. Yes, indeed:</p>
<pre><code>>>> timeit.timeit(setup='ba=bytearray()', stm... | 3 | 2016-10-12T17:11:48Z | 40,005,377 | <blockquote>
<p>What is the reason of having two ways of extending a bytearray?</p>
</blockquote>
<ul>
<li>An operator is not chainable like function calls, whereas a method is.</li>
<li>The <code>+=</code> operator cannot be used with nonlocal variables.</li>
<li>The <code>+=</code> is slightly faster</li>
<li><cod... | 0 | 2016-10-12T18:01:14Z | [
"python"
] |
Python Pandas: Group by and count distinct value over all columns? | 40,004,595 | <p>I have df</p>
<pre><code> column1 column2 column3 column4
0 name True True NaN
1 name NaN True NaN
2 name1 NaN True True
3 name1 True True True
</code></pre>
<p>and I would like to Group by and count distinct... | 0 | 2016-10-12T17:16:12Z | 40,004,637 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a> for <code>Series</code> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.groupby.html" rel="nofollow"><code>Series.groupby</code></a> with... | 2 | 2016-10-12T17:19:20Z | [
"python",
"pandas",
"count",
"unique",
"distinct"
] |
yes or no loop (TypeError: 'NoneType' object is not iterable) error | 40,004,620 | <p>I'm trying to implement a yes / no / retry, but I am getting this error: 'NoneType' object is not iterable. I assume the issue is the function (def izberiEkipo() is not returning what it's suppose to.</p>
<pre><code>def izberiEkipo():
m = set(['m'])
p = set(['p'])
while False:
if reply in m... | -1 | 2016-10-12T17:18:01Z | 40,004,724 | <p>Your assumption is correct: as given, your upper function returns nothing. You've disabled the loop with a <strong>False</strong> entry condition: it won't run at all. The only <strong>return</strong> in the function is inside that loop.</p>
<p>Thus, all that routine does is to create two sets of a single charact... | 0 | 2016-10-12T17:23:53Z | [
"python"
] |
Moviepy OSError Exec format error - Missing Shebang? | 40,004,639 | <p>I am attempting to use MoviePy with Python 3.2.3 on Raspian.
I have installed it (for Python 2.7, 3.2 and 3.5... long story) and the line</p>
<pre><code>from moviepy.editor import *
</code></pre>
<p>works fine.
When I try</p>
<pre><code>clip = VideoFileClip("vid.mov")
</code></pre>
<p>which is the most basic com... | 1 | 2016-10-12T17:19:27Z | 40,005,275 | <p>Manually download ffmpeg, then before running your Python code, do</p>
<pre><code>export FFMPEG_BINARY=path/to/ffmpeg
</code></pre>
<p>at the shell/terminal prompt.</p>
<p>As far as I can tell from <a href="https://github.com/imageio/imageio/blob/master/imageio/plugins/ffmpeg.py#L48" rel="nofollow">the source</a>... | 2 | 2016-10-12T17:56:04Z | [
"python",
"linux",
"python-3.x",
"raspberry-pi",
"moviepy"
] |
how to go the start of file in python? | 40,004,672 | <p>I am new to python and I am learning some basic file reading stuff. I am trying to read a file and count the number of new lines and also print lines that start with 'From: ' .</p>
<p>This is the code I have for that:</p>
<pre><code>fhand = open('mbox.txt')
count = 0
for line in fhand:
count = count + 1
... | 0 | 2016-10-12T17:21:06Z | 40,004,712 | <pre><code>file.seek(0)
</code></pre>
<p><a href="https://docs.python.org/3.5/tutorial/inputoutput.html" rel="nofollow">Seek()</a> takes an argument that goes back to that "byte" so 0 byte will go back to the start of the file. </p>
| 1 | 2016-10-12T17:23:15Z | [
"python"
] |
how to go the start of file in python? | 40,004,672 | <p>I am new to python and I am learning some basic file reading stuff. I am trying to read a file and count the number of new lines and also print lines that start with 'From: ' .</p>
<p>This is the code I have for that:</p>
<pre><code>fhand = open('mbox.txt')
count = 0
for line in fhand:
count = count + 1
... | 0 | 2016-10-12T17:21:06Z | 40,004,713 | <p>Try this out :</p>
<pre><code>with open('mbox.txt') as f:
count = 0
for l in f.readlines():
count += 1
if l.startswith('From: '):
print l
</code></pre>
<p>To get back to start of file use <code>seek(0)</code></p>
| 0 | 2016-10-12T17:23:22Z | [
"python"
] |
Using R or Python plot worldmap with countries from simple list colored | 40,004,689 | <p>I have the list of countries :</p>
<pre><code>("Albania", "Algeria", "Anguilla", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belgium", "Belize", "Benin", "Bermuda", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Br... | 1 | 2016-10-12T17:21:53Z | 40,004,867 | <p>This line might work:</p>
<pre><code>map("world", fill=TRUE, col="white", bg="lightblue", ylim=c(-60, 90), mar=c(0,0,0,0))
</code></pre>
<p>Also this is a good website to look at: <a href="https://www.r-bloggers.com/r-beginners-plotting-locations-on-to-a-world-map/" rel="nofollow">https://www.r-bloggers.com/r-begi... | 2 | 2016-10-12T17:32:35Z | [
"python",
"plot",
"rworldmap"
] |
What optimisations are done that this code completes quickly? | 40,004,692 | <p>I was solving a problem I came across, what is the sum of powers of 3 from 0 to 2009 mod 8.</p>
<p>I got an answer using pen and paper, and tried to verify it with some simple python</p>
<pre><code>print(sum(3**k for k in range(2010)) % 8)
</code></pre>
<p>I was surprised by how quickly it returned an answer. My ... | -1 | 2016-10-12T17:22:01Z | 40,004,744 | <p>No fancy optimizations are responsible for the fast response you observed. Computers are just a lot faster in absolute terms than you expected.</p>
| 1 | 2016-10-12T17:24:32Z | [
"python",
"python-3.x",
"optimization"
] |
What optimisations are done that this code completes quickly? | 40,004,692 | <p>I was solving a problem I came across, what is the sum of powers of 3 from 0 to 2009 mod 8.</p>
<p>I got an answer using pen and paper, and tried to verify it with some simple python</p>
<pre><code>print(sum(3**k for k in range(2010)) % 8)
</code></pre>
<p>I was surprised by how quickly it returned an answer. My ... | -1 | 2016-10-12T17:22:01Z | 40,004,749 | <p>None, it's just not a lot of computation for a computer to do. </p>
<p>Your code is equivalent to:</p>
<pre><code>>>> a = sum(3**k for k in range(2010))
>>> a % 8
4
</code></pre>
<p><code>a</code> is a 959-digit number - it's just not a large task to ask of a computer.</p>
<p>Try sticking two z... | 3 | 2016-10-12T17:24:45Z | [
"python",
"python-3.x",
"optimization"
] |
What optimisations are done that this code completes quickly? | 40,004,692 | <p>I was solving a problem I came across, what is the sum of powers of 3 from 0 to 2009 mod 8.</p>
<p>I got an answer using pen and paper, and tried to verify it with some simple python</p>
<pre><code>print(sum(3**k for k in range(2010)) % 8)
</code></pre>
<p>I was surprised by how quickly it returned an answer. My ... | -1 | 2016-10-12T17:22:01Z | 40,004,855 | <p>The only optimization at work is that each instance of <code>3**k</code> is evaluated using a number of multiplications proportional to the number of bits in <code>k</code> (it does <em>not</em> multiply 3 by itself <code>k-1</code> times).</p>
<p>As already noted, if you boost 2010 to 20100 or 201000 or ..., it wi... | 2 | 2016-10-12T17:31:51Z | [
"python",
"python-3.x",
"optimization"
] |
Is it possible using Tensorflow to create a neural network for input/output mapping? | 40,004,703 | <p>I am currently using tensorflow to create a neural network, that replicates the function of creating a certain output given an input. </p>
<p>The input in this case is a sampled audio, and the audio is generating MFCC features. Know for each file what the corresponding MFCC feature, is, but aren't sure how i should... | 0 | 2016-10-12T17:22:43Z | 40,016,293 | <p>Neural networks could be use for classification tasks or regression tasks. In <a href="http://www.kdnuggets.com/2016/09/urban-sound-classification-neural-networks-tensorflow.html/2" rel="nofollow">tutorial</a>, the author wants to classify sounds into 10 different categories. So the neural networks have 10 output ne... | 0 | 2016-10-13T08:47:12Z | [
"python",
"tensorflow",
"supervised-learning"
] |
Keras Custom Scaling Layer | 40,004,706 | <p>For my work, I need to make a layer, that has only single weight, that will multiply the data in the current layer by some trained value. Is there a way to do this?</p>
<p>Or change the merge layer, which will be able to make a weighted average of input layers.
Thanks</p>
| 0 | 2016-10-12T17:22:46Z | 40,008,115 | <p>Try Lambda layer</p>
<pre><code>model.add(Lambda(lambda x: x *MyValue))
</code></pre>
<p><a href="https://keras.io/layers/core/#lambda" rel="nofollow">https://keras.io/layers/core/#lambda</a></p>
| 0 | 2016-10-12T20:50:00Z | [
"python",
"machine-learning",
"keras"
] |
In python how can I call a function using an imported module | 40,004,738 | <p>I have this module that calls main() function:</p>
<pre><code>## This is mymodules ##
def restart():
r = input('Do you want to build another configuration file?\n1. Yes\n2. No\n')
if r == '1':
main()
elif r == '2':
os.system('pause')
</code></pre>
<p>The main() i... | 0 | 2016-10-12T17:24:09Z | 40,004,984 | <p>For a code as simple as this one you could simply pass the <code>main</code> function as an argument to the restart function.</p>
<p>E.g.</p>
<pre><code>def restart(function):
r = input('Do you want to build another configuration file?\n1. Yes\n2. No\n')
if r == '1':
function()
elif r == '2':
... | 2 | 2016-10-12T17:39:05Z | [
"python",
"function",
"import",
"module"
] |
How to fix "bad handshake" SSLErrors when utilizing python requests | 40,004,748 | <p>I'm trying to get access to the BambooHR API (<a href="https://www.bamboohr.com/api/documentation/login.php" rel="nofollow">documentation here</a>), but I receive the following error</p>
<pre><code> params = {
'user': username,
'password': password,
'api_token': api_key}
url = 'https:... | 0 | 2016-10-12T17:24:43Z | 40,004,934 | <p>You try by setting verify=False, use this option if you are using self-signed certificates.</p>
<p><code>r = requests.get(url, params=params, verify=False)</code></p>
<p>More info <a href="http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification" rel="nofollow">http://docs.python-requests.org... | 0 | 2016-10-12T17:36:11Z | [
"python",
"api",
"openssl",
"python-requests"
] |
Encrypt in python and decrypt in Java with AES-CFB | 40,004,858 | <p>I am aware of a question very similar to this (<a href="http://stackoverflow.com/questions/10440777/how-do-i-encrypt-in-python-and-decrypt-in-java">How do I encrypt in Python and decrypt in Java?</a>) but I have a different problem.</p>
<p>My problem is, I am not able to decrypt in Java correctly. Despite using the... | 1 | 2016-10-12T17:32:01Z | 40,006,920 | <p>The <a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Feedback_.28CFB.29" rel="nofollow">Cipher Feedback (CFB) mode of operation</a> is a family of modes. It is parametrized by the segment size (or register size). PyCrypto has a default <a href="https://github.com/dlitz/pycrypto/blob/v2.6.... | 0 | 2016-10-12T19:34:40Z | [
"java",
"python",
"encryption",
"pycrypto",
"cfb-mode"
] |
pandas: get the value of the index for a row? | 40,004,871 | <p>I have a dataframe:</p>
<pre><code> cost month para
prod_code
040201060AAAIAI 43 2016-01-01 0402
040201060AAAIAJ 45 2016-02-01 0402
040201060AAAIAI 46 2016-03-01 0402
040201060AAAIAI 41 2016-01-01 0402
040201060AAAIAI 48 2016-02-01 0402
</code></pre>
<p>How can I ite... | 3 | 2016-10-12T17:33:00Z | 40,004,924 | <p>use this to iterate over any value <code>df.ix[row_value,col_value]</code> for finding the column index use this function</p>
<pre><code>def find_column_number(column_name):
x=list(df1.columns.values)
print column_name
col_lenth= len(x)
counter=0
count=[]
while counter<col_lenth:
... | 1 | 2016-10-12T17:35:44Z | [
"python",
"pandas"
] |
pandas: get the value of the index for a row? | 40,004,871 | <p>I have a dataframe:</p>
<pre><code> cost month para
prod_code
040201060AAAIAI 43 2016-01-01 0402
040201060AAAIAJ 45 2016-02-01 0402
040201060AAAIAI 46 2016-03-01 0402
040201060AAAIAI 41 2016-01-01 0402
040201060AAAIAI 48 2016-02-01 0402
</code></pre>
<p>How can I ite... | 3 | 2016-10-12T17:33:00Z | 40,004,947 | <pre><code>for i, row in df.iterrows():
</code></pre>
<p>returns a <code>Series</code> for each row where the <code>Series</code> name is the <code>index</code> of the row you are iterating through. you could simply do</p>
<pre><code>d = { 'prod_code': ['040201060AAAIAI', '040201060AAAIAJ', '040201060AAAIAI', '040201... | 2 | 2016-10-12T17:36:55Z | [
"python",
"pandas"
] |
Hashlib MemoryError in Python 3.5 but not in 2.7 | 40,004,963 | <p>I've been porting a set of Python 2.7 scripts to Python 3.5 so that I can use some libraries that aren't available in 2.7, but I'm getting MemoryError from this code that worked previously:</p>
<pre><code>import hashlib, functools
sha2h = hashlib.sha256()
with open('/path/to/any/file', 'rb') as f:
[sha2h.up... | 0 | 2016-10-12T17:37:44Z | 40,005,048 | <p>On Python 3, you need to set <code>b''</code> instead of <code>''</code> as the sentinel value for the <code>iter</code> call:</p>
<pre><code>iter(functools.partial(f.read, 256), b'')
</code></pre>
<p>You also really shouldn't be using a list comprehension for side effects like this, but if you're porting existing... | 0 | 2016-10-12T17:43:04Z | [
"python",
"python-3.x",
"hashlib",
"functools"
] |
MongoDB collection chain | 40,004,988 | <p>I have a problem that I need to solve. Currently my code works with one collection where I create a cursor for one collection of builds. It looks like this:</p>
<pre><code>from pymongo import MongoClient
from itertools import chain
db = MongoClient('10.39.165.193', 27017)['mean-dev']
cursor = db.collection1.find()... | 0 | 2016-10-12T17:39:12Z | 40,015,554 | <p>One way to solve this is to write your own <code>JoinedCursor</code> class such as this:</p>
<pre><code>class JoinedCursor:
def __init__(self, db, collection1, collection2, limit=None, sort_on=None, order=1):
self.limit = limit
self.sort_on = sort_on
self.order = order
self.curso... | 0 | 2016-10-13T08:08:34Z | [
"python",
"mongodb",
"pymongo"
] |
character detection and crop from an image using opencv python | 40,005,055 | <p>I have a project in which I have to detect Bengali numbers from image. I decided to do an experiment like numbers with spaces and without spaces. My python program can detect all number from with spaces image.</p>
<p>The problem occurred when I gave image without spaces. It couldn't cut number smoothly like the pre... | 0 | 2016-10-12T17:43:13Z | 40,034,372 | <p>Unfortunately I didn't notice that when I cut rectangle portion I added x:x+h instead of x:x+w. That's the main problem. After modifying that the program worked fine. sorry.</p>
| 0 | 2016-10-14T03:15:49Z | [
"python",
"opencv",
"ocr",
"opencv-contour"
] |
AttributeError: module âxgboostâ has no attribute âXGBRegressorâ | 40,005,093 | <p>I am trying to run xgboost using spyder python but keep getting this error
<strong>AttributeError: module âxgboostâ has no attribute âXGBRegressorâ</strong></p>
<p>Here is the code</p>
<pre><code>import xgboost as xgb
xgb.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True,
... | 0 | 2016-10-12T17:45:13Z | 40,025,007 | <p>Since your <code>dir</code> call is missing basically everything, my suspicion is that wherever you're starting your script from has an <code>xgboost</code> subfolder with an empty <code>__init__.py</code> in it that is being found first by your <code>import</code>.</p>
| 0 | 2016-10-13T15:21:15Z | [
"python",
"machine-learning",
"regression",
"xgboost"
] |
Make an array class using dictionaries only | 40,005,203 | <p>I am a student who is new to python. I am trying to define an array class below which uses a dictionary as its only member variable. I am assuming that Python implements dictionaries as the only structured type (i.e., there is no array, list, tuple, etc.).</p>
<p>I am facing difficulty in coding such a program.</p>... | 0 | 2016-10-12T17:51:55Z | 40,005,466 | <p>There are quite a few issues with your class definition:</p>
<ul>
<li><code>array</code> is already a data structure: better to rename using the proper Python class-naming conventions (<code>MyClass</code>).</li>
<li>You cannot overload function definitions: better to use an unpacking operator (<code>*</code>) to e... | 1 | 2016-10-12T18:06:39Z | [
"python",
"dictionary"
] |
Weird UTF-8 one-liner interpreter bug | 40,005,226 | <p>So, I have this unholy abomination of a program:</p>
<pre><code>print((lambda raw, name_file: ((lambda start_time, total, lines, names: ((lambda parsed: ('\n'.join(str(10*(parsed[0][name]+parsed[1][name]/2)/total).ljust(6) + name for name in names)))(list(map(lambda x: __import__("collections").Counter(x), map(lamb... | 1 | 2016-10-12T17:53:07Z | 40,005,542 | <p>The bug is in your expectation of what the default source file encoding is.
It is only UTF-8 when you're using Python 3.x (I checked, 3.5 parses the abomination without problems)</p>
<p>Python 2.x defaults to ASCII so add an encoding comment as first line in this abomination and you're good to go</p>
<pre><code># ... | 1 | 2016-10-12T18:11:27Z | [
"python",
"python-3.x",
"utf-8",
"character-encoding"
] |
Weird UTF-8 one-liner interpreter bug | 40,005,226 | <p>So, I have this unholy abomination of a program:</p>
<pre><code>print((lambda raw, name_file: ((lambda start_time, total, lines, names: ((lambda parsed: ('\n'.join(str(10*(parsed[0][name]+parsed[1][name]/2)/total).ljust(6) + name for name in names)))(list(map(lambda x: __import__("collections").Counter(x), map(lamb... | 1 | 2016-10-12T17:53:07Z | 40,005,594 | <p>Characters themselves do not have an encoding - it does not make sense to say a character is UTF-8. UTF-8 is just one of many encodings that can be used to represent a character. You do have non-ASCII characters in your program, and based on the error, the source file is being saved in an encoding other than UTF-8. ... | 0 | 2016-10-12T18:14:19Z | [
"python",
"python-3.x",
"utf-8",
"character-encoding"
] |
socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted | 40,005,251 | <p>i am trying to make a server-client md5 decription
the server sends how many cores he have(cpu)
and the client slices him th range for multiproccesing
(brute force)
but the server throws me the "socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted" ... | 0 | 2016-10-12T17:54:36Z | 40,005,441 | <p>You're creating your server socket in the module scope so as soon as the module is imported, it is created and bound to (0.0.0.0, 2345).</p>
<p>Multiprocessing will cause the module to be (re)imported in the new process it creates, so that process will immediately try to create the same server socket on port 2345 a... | 0 | 2016-10-12T18:05:01Z | [
"python",
"sockets",
"multiprocessing",
"md5"
] |
Optimization of for loop in python | 40,005,264 | <p>I am executing the following code for different time stamps and each will have close to one million records. It took more than one hour for one date and I have the data for a total of 35 dates.</p>
<p>Is there a way to optimize this code?</p>
<pre><code>def median(a, b, c,d,e):
I=[a,b,c,d,e]
I.sort()
r... | 1 | 2016-10-12T17:55:29Z | 40,005,585 | <p>I'm guessing that your <code>df</code> is a Pandas <code>DataFrame</code> object. Pandas has built-in functionality to compute rolling statistics, including a rolling median. This functionality is available via the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.rolling.html" rel="nofoll... | 4 | 2016-10-12T18:13:58Z | [
"python",
"loops",
"pandas",
"for-loop",
"optimization"
] |
Optimization of for loop in python | 40,005,264 | <p>I am executing the following code for different time stamps and each will have close to one million records. It took more than one hour for one date and I have the data for a total of 35 dates.</p>
<p>Is there a way to optimize this code?</p>
<pre><code>def median(a, b, c,d,e):
I=[a,b,c,d,e]
I.sort()
r... | 1 | 2016-10-12T17:55:29Z | 40,006,321 | <p>A nice tool for profiling python code performance line by line is <a href="https://github.com/rkern/line_profiler" rel="nofollow">kernprof</a>.</p>
| 0 | 2016-10-12T18:56:31Z | [
"python",
"loops",
"pandas",
"for-loop",
"optimization"
] |
How to concatenate two columns and update the csv in python? | 40,005,265 | <p>In Excel, I would be able to use something like this:</p>
<pre><code>=CONCATENATE(A1," ",B1)
</code></pre>
<p>(User flood fill's this down the spreadsheet, and then simply deletes A and B, lastly you move results to A)</p>
<p>End Result is expected to have A and B columns merged into one column (A) and separated... | 0 | 2016-10-12T17:55:32Z | 40,005,472 | <p>You're calling <code>writerow</code> twice in that loop. I don't think you want that - writing the merged columns and then the others separately? No.</p>
<p>You can simply join the merged columns to the <em>start</em> of the rows, and <em>slice off</em> the old rows:</p>
<pre><code>wtr.writerow([r[0] + ' ' + r[1]]... | 1 | 2016-10-12T18:07:02Z | [
"python",
"csv"
] |
How to concatenate two columns and update the csv in python? | 40,005,265 | <p>In Excel, I would be able to use something like this:</p>
<pre><code>=CONCATENATE(A1," ",B1)
</code></pre>
<p>(User flood fill's this down the spreadsheet, and then simply deletes A and B, lastly you move results to A)</p>
<p>End Result is expected to have A and B columns merged into one column (A) and separated... | 0 | 2016-10-12T17:55:32Z | 40,005,520 | <p>So every row you're reading from (and writing to) csv is a list, right? So take another step or two and create the list you want, then write it.</p>
<p>e.g.</p>
<pre><code>import csv
with open('test.csv') as f:
reader = csv.reader(f)
with open('output.csv', 'w') as g:
writer = csv.writer(g)
... | 0 | 2016-10-12T18:09:23Z | [
"python",
"csv"
] |
What can you do with a PyDictValues_Type? | 40,005,285 | <p>While trying to convert some Python/C API code to work in both 2 & 3, I found that, given the following Python</p>
<pre><code>DICT = { ⦠}
class Example(object):
ITEMS = DICT.values()
</code></pre>
<p>and then calling <code>PyObject_GetAttrString(an_example, "ITEMS")</code> would yield a <code>PyObject</c... | 0 | 2016-10-12T17:56:26Z | 40,005,713 | <p>Basically just <code>iter</code> (<code>PyObject_GetIter</code> in the C API).</p>
<p>There are technically other operations, like <code>==</code> (inherited from <code>object</code>, uninteresting), <code>len</code> (but you'd call that on the dict instead of making a values view if you wanted that), and <code>in<... | 1 | 2016-10-12T18:20:36Z | [
"python",
"python-2.7",
"python-3.4",
"python-c-api"
] |
What can you do with a PyDictValues_Type? | 40,005,285 | <p>While trying to convert some Python/C API code to work in both 2 & 3, I found that, given the following Python</p>
<pre><code>DICT = { ⦠}
class Example(object):
ITEMS = DICT.values()
</code></pre>
<p>and then calling <code>PyObject_GetAttrString(an_example, "ITEMS")</code> would yield a <code>PyObject</c... | 0 | 2016-10-12T17:56:26Z | 40,005,727 | <p>In Python 2, <code>dict.values()</code> returns a list, but in Python 3, it's a view of dictionary values. The equivalent in Python 2.7 is <a href="https://docs.python.org/2/library/stdtypes.html#dictionary-view-objects" rel="nofollow"><code>dict.viewvalues()</code></a>.</p>
<p>In particular views are not sequences... | 1 | 2016-10-12T18:21:21Z | [
"python",
"python-2.7",
"python-3.4",
"python-c-api"
] |
Selenium - Difficulty finding input element on page (Python) | 40,005,293 | <p>I am having trouble finding a search bar on a webpage that I am trying to automate. I have tried a couple approaches but being rather new to selenium, I am not sure what more advanced locating options there are.</p>
<p>Breakdown::
The following is an section of code with the search bar element (corresponding to inp... | 2 | 2016-10-12T17:57:11Z | 40,005,541 | <p>try with <code>driver.page_source</code> and then use beautifulSoup to find the element.</p>
| -2 | 2016-10-12T18:11:13Z | [
"python",
"selenium"
] |
Selenium - Difficulty finding input element on page (Python) | 40,005,293 | <p>I am having trouble finding a search bar on a webpage that I am trying to automate. I have tried a couple approaches but being rather new to selenium, I am not sure what more advanced locating options there are.</p>
<p>Breakdown::
The following is an section of code with the search bar element (corresponding to inp... | 2 | 2016-10-12T17:57:11Z | 40,005,639 | <p>If you are getting <code>NoSuchElementException</code> as your provided exception, There could be following reasons :-</p>
<ul>
<li><p>May be when you are going to find element, it would not be present on the <code>DOM</code>, So you should implement <a href="http://selenium-python.readthedocs.io/waits.html#explici... | 3 | 2016-10-12T18:16:10Z | [
"python",
"selenium"
] |
Fast optimization of "pathological" convex function | 40,005,320 | <p>I have a simple convex problem I am trying to speed up the solution of. I am solving the argmin (<em>theta</em>) of</p>
<p><img src="http://latex.codecogs.com/gif.latex?-%5Csum_%7Bt%3D1%7D%5E%7BT%7D%5Clog%281%20+%20%5Cboldsymbol%7B%5Ctheta%27%7D%20%5Cboldsymbol%7Br_t%7D%29" alt="eq"></p>
<p>where <em>theta</e... | 1 | 2016-10-12T17:58:21Z | 40,006,227 | <p>I believe the issue is that it is possible for <code>theta</code> to be such that the <code>log</code> argument becomes negative. It seems that you have identified this issue, and have <code>goalfun</code> return the tuple <code>(100,100*ones(N))</code> in this case, apparently, as a heuristic attempt to suggest the... | 2 | 2016-10-12T18:51:09Z | [
"python",
"numpy",
"scipy",
"mathematical-optimization",
"cvxopt"
] |
Python script to run docker | 40,005,397 | <p>Flow of the python script:</p>
<ul>
<li>I want to run docker image from python script. </li>
<li>After running docker image, I need to execute a shell script which creates a tar file inside docker container.</li>
<li>I need to copy that tar file to host machine from docker container.</li>
<li>and then python script... | 0 | 2016-10-12T18:02:17Z | 40,005,799 | <p>This is probably the sequence of commands you want (borrowing from <a href="http://stackoverflow.com/a/38308399/2404152">this answer</a>):</p>
<pre><code>docker create --name tmp -it ubuntu14.04_64:latest
docker start tmp
docker exec tmp tar czvf tmp.tgz etc/os-release
docker stop tmp
docker cp tmp:tmp.tgz tmp.tgz
... | 1 | 2016-10-12T18:25:16Z | [
"python",
"python-2.7",
"docker",
"docker-compose",
"dockerpy"
] |
Python script to run docker | 40,005,397 | <p>Flow of the python script:</p>
<ul>
<li>I want to run docker image from python script. </li>
<li>After running docker image, I need to execute a shell script which creates a tar file inside docker container.</li>
<li>I need to copy that tar file to host machine from docker container.</li>
<li>and then python script... | 0 | 2016-10-12T18:02:17Z | 40,029,242 | <p>If you want to run a script in a container you should create a <code>Dockerfile</code> which contains that script. An example might look something like this:</p>
<pre><code>FROM ubuntu14.04_64:latest
COPY ./script.sh /code/script.sh
CMD /code/script.sh -o /target/output.tar.gz
</code></pre>
<p>Then your python scr... | 1 | 2016-10-13T19:20:03Z | [
"python",
"python-2.7",
"docker",
"docker-compose",
"dockerpy"
] |
Django django.test Client post request | 40,005,411 | <p>Working on hellowebapp.com</p>
<p>Please help test valid form post using Django test client post request?</p>
<pre><code>response = self.client.post('/accounts/create_thing/', { 'name': dummy_thing.name, 'description': dummy_thing.description, })
</code></pre>
<p>Here's the TestCase Code Snippet:</p>
<pre><code>... | 0 | 2016-10-12T18:03:09Z | 40,008,078 | <p>This happens because you have <code>OneToOneField</code>, since that your every new <code>Thing</code> must be connected to <code>User</code> that wasn't picked before. So because you already had <code>dummy_thing</code> with <code>dummy_user</code> as <code>User</code>, you can't save new <code>Thing</code> instanc... | 1 | 2016-10-12T20:48:01Z | [
"python",
"django",
"django-models",
"django-forms",
"django-views"
] |
Why does my object move in the wrong direction | 40,005,470 | <p>I have a made a simple program which is meant to move a ball left and right horizontally within a canvas. The user will use the left and right keys to move the ball accordingly by 5 pixels a time. If the x coordinate of the ball is less than 40 or more than 240 then it will do nothing.</p>
<pre><code>try:
... | 0 | 2016-10-12T18:06:47Z | 40,005,571 | <p>According to the <a href="http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.move-method" rel="nofollow">Tkinter Canvas documentation</a>, the second argument to the <code>move</code> method, <code>dx</code>, is an offset. Try calling it like</p>
<pre><code>game_area.move(ball, -5, 4)
</code></pre>
<p>Then yo... | 2 | 2016-10-12T18:13:14Z | [
"python",
"canvas",
"tkinter",
"coordinates"
] |
Python Warm / Cold Declaring Variable outside while loop | 40,005,523 | <p>I'm writing a simple warmer / colder number guessing game in Python.</p>
<p>I have it working but I have some duplicated code that causes a few problems and I am not sure how to fix it.</p>
<pre><code>from __future__ import print_function
import random
secretAnswer = random.randint(1, 10)
gameOver = False
attemp... | 0 | 2016-10-12T18:09:44Z | 40,005,688 | <p>There doesn't seem to be a need to ask the user before you enter the loop... You can just check if guesses = 1 for the first guess...</p>
<pre><code>gameOver=False
guesses = 0
while not gameOver:
guesses += 1
getUserInput
if guesses = 1 and userInput != correctAnswer:
print "try again!"
chec... | 1 | 2016-10-12T18:18:46Z | [
"python",
"while-loop"
] |
Paramiko Buffer issue | 40,005,531 | <p>I have a problem of buffer using paramiko, I found the same question <a href="http://stackoverflow.com/q/12486623/2662302">here</a> and one of the solutions states that:</p>
<blockquote>
<p>Rather than using .get(), if you just call .open() to get an SFTPFile
instance, then call .read() on that object, or just ... | 0 | 2016-10-12T18:10:24Z | 40,006,130 | <p>Here is a working example that fetches copies a test file on your local machine. The file is much smaller than 1 GIG but gives the general plan.</p>
<pre><code>import paramiko
import os
import shutil
import time
import getpass
# get params
user = getpass.getuser()
pwd = getpass.getpass("Enter password: ")
bufsize ... | 1 | 2016-10-12T18:44:48Z | [
"python",
"csv",
"paramiko"
] |
Why will my build_heap method not stop running? | 40,005,591 | <p>I have written a class for a <code>MinHeap</code> class and created a <code>build_heap</code> method. Whenever I call the <code>build_heap</code> function the program continues to run unless I keyboard interrupt it. The heap appears to built when I interrupt the function call, but I am curious as to why the function... | 2 | 2016-10-12T18:14:06Z | 40,006,405 | <p>The problem is <code>perc_down()</code> never returns when <code>build_help()</code> call it. This is because the condition <code>(index * 2) <= self.current_size</code> never changes and is always <code>True</code> because it's not affected by any of the statements within the <code>while</code> loop.</p>
<p>Wit... | 1 | 2016-10-12T19:01:36Z | [
"python",
"heap",
"interrupt"
] |
Count number of tabs open in Selenium Python | 40,005,611 | <p>How do I count number of tabs are being opened in Browser by using Python Selenium?</p>
| 0 | 2016-10-12T18:15:09Z | 40,005,827 | <blockquote>
<p>How do I count number of tabs are being opened in Browser by using Python Selenium?</p>
</blockquote>
<p>Since provided <a href="http://sqa.stackexchange.com/questions/9553/counting-the-number-of-browser-windows-opened-by-selenium">link answer</a> doesn't have any answer in python, you can get the co... | 0 | 2016-10-12T18:26:56Z | [
"python",
"selenium",
"count",
"tabs"
] |
Please tell me why this deadlocks: Reading and writing from Paramiko exec_command() file-like objects -- ChannelFile.close() does not work | 40,005,673 | <pre><code>import paramiko, threading
def Reader(src):
while True:
data = src.readline()
if not data: break
print data
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect("172.17.0.2", username="test", password="test")
stdin, stdout, ... | 0 | 2016-10-12T18:17:43Z | 40,011,587 | <p>The probblem is in <code>stdin.close()</code>. According to Paramiko's doc (v1.16):</p>
<blockquote>
<p><strong>Warning:</strong> To correctly emulate the file object created from a socketâs <code>makefile()</code> method, a <code>Channel</code> and its <code>ChannelFile</code> should be able to be closed or ga... | 2 | 2016-10-13T03:00:58Z | [
"python",
"paramiko"
] |
How to get current user from a Django Channels web socket packet? | 40,005,701 | <p>I was following this tutorial: <a href="https://blog.heroku.com/in_deep_with_django_channels_the_future_of_real_time_apps_in_django" rel="nofollow">Finally, Real-Time Django Is Here: Get Started with Django Channels</a>.</p>
<p>I wanted to extend the app by using Django User objects instead of the <code>handle</cod... | 3 | 2016-10-12T18:19:38Z | 40,007,005 | <p>You can get access to a <code>user</code> and <code>http_session</code> attributes of your <code>message</code> by changing the decorators in <code>consumers.py</code> to match the docs:</p>
<blockquote>
<p>You get access to a userâs normal Django session using the <code>http_session decorator</code> - that giv... | 2 | 2016-10-12T19:40:41Z | [
"python",
"django",
"sockets",
"session",
"django-channels"
] |
Posting file to Flask with cURL returns 400 error | 40,005,703 | <p>I want to post a file using cURL to a Flask view. However, I get a 400 error in response. Why does the command below fail?</p>
<pre><code>@app.route('/deploy/partial', methods=['POST'])
def postfile():
try:
file = request.files['file']
filename = secure_filename(file.filename)
file.save... | -1 | 2016-10-12T18:19:58Z | 40,015,377 | <p>I got the </p>
<p>Unexpected error: .newcls'></p>
<p>after I accidentally renamed request.form['name'] to request.form['ame']
(note the wrong 'ame') while my form field is
name = StringField(...)</p>
<p>I changed request.form['ame'] to request.form['name'] and the error disappeared, i.e. flask works</p>
<p>Not s... | 0 | 2016-10-13T07:59:03Z | [
"python",
"curl",
"flask"
] |
How does sp_randint work? | 40,005,795 | <p>I am doing hyperparameter optimisation of Random Forest classifier. I am planning to use RandomSearchCV. </p>
<p>So by checking the available code in Scikit learn: What does sp_randint do?
Does it randomly take a value from 1 to 11? Can it be replaced by other function?</p>
<pre><code> from scipy.stats import r... | 1 | 2016-10-12T16:10:17Z | 40,005,796 | <p><a href="http://scikit-learn.org/0.17/modules/generated/sklearn.grid_search.RandomizedSearchCV.html" rel="nofollow"><code>sklearn.grid_search.RandomizedSearchCV</code></a> can get a <code>param_distributions</code> parameter, mapping parameters to random distributions supporting the <code>rvs</code> method.</p>
<p>... | 2 | 2016-10-12T17:29:15Z | [
"machine-learning",
"python",
"optimization",
"scikit-learn",
"scipy"
] |
Create a new column based on several lookup tables in Python Pandas | 40,005,854 | <p>I have a large pandas dataframe (<code>df_orig</code>) and several lookup tables (also dataframes) that correspond to each of the segments in <code>df_orig</code>.</p>
<p>Here's a small subset of <code>df_orig</code>:</p>
<pre><code>segment score1 score2
B3 0 700
B1 0 120
B1 400 950... | 2 | 2016-10-12T18:28:51Z | 40,006,129 | <p>If you are ok with sorting the DataFrames ahead of time, then you can replace your loop example with the new <a href="http://pandas.pydata.org/pandas-docs/version/0.19.0/whatsnew.html#whatsnew-0190-enhancements-asof-merge" rel="nofollow">asof join in pandas 0.19</a>:</p>
<pre><code># query
df_b5 = df_orig.query('se... | 1 | 2016-10-12T18:44:45Z | [
"python",
"python-2.7",
"pandas"
] |
How can I implement something similar to `value_counts()` in a groupby? | 40,005,993 | <p>Suppose I had the following data</p>
<pre><code>Orchard Tree
1 Apple
2 Peach
1 Peach
3 Apple
</code></pre>
<p>How could I group by <code>orchard</code> and show how many times each tree occurs in the orchard? The result would look like</p>
<pre><code>Tree Apple Pea... | 2 | 2016-10-12T18:36:58Z | 40,006,056 | <p>Is <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow">pivot_table()</a> what you want?</p>
<pre><code>In [48]: df
Out[48]:
Orchard Tree
0 1 Apple
1 2 Peach
2 1 Peach
3 3 Apple
In [49]: df.pivot_table(index='Orchard', columns='... | 3 | 2016-10-12T18:40:04Z | [
"python",
"pandas",
"dataframe"
] |
How can I implement something similar to `value_counts()` in a groupby? | 40,005,993 | <p>Suppose I had the following data</p>
<pre><code>Orchard Tree
1 Apple
2 Peach
1 Peach
3 Apple
</code></pre>
<p>How could I group by <code>orchard</code> and show how many times each tree occurs in the orchard? The result would look like</p>
<pre><code>Tree Apple Pea... | 2 | 2016-10-12T18:36:58Z | 40,006,329 | <p>Let's not forget good ol' <code>value_counts</code><br>
Just have to make sure to reduce to <code>Tree</code> after the <code>groupby</code></p>
<pre><code>df.groupby('Orchard').Tree.value_counts().unstack(fill_value=0)
</code></pre>
<p><a href="https://i.stack.imgur.com/Gl9ZY.png" rel="nofollow"><img src="https:/... | 3 | 2016-10-12T18:56:52Z | [
"python",
"pandas",
"dataframe"
] |
How can my user upload an image to email to me [Django] | 40,006,013 | <p>I've got a simple website for a Screenprinting company built using Django 1.10 and Python 3.5.2, but I am having issues with my "Get a Quote" page.</p>
<p>The idea is a user can go to www.example.com/quote/ and they are presented with a form. Here they put in their Name, Email Address, a Brief Message, and most imp... | 0 | 2016-10-12T18:38:02Z | 40,006,373 | <p>A file is not in the <code>request.POST</code> attribute, it is in <code>request.FILES</code>. Your <code>views.py</code> should look like this:</p>
<pre><code>def quote(request):
form = QuoteForm(request.POST, request.FILES)
if form.is_valid():
...
uploaded_image = request.FILES.getlist('up... | 0 | 2016-10-12T19:00:04Z | [
"python",
"django",
"email",
"upload",
"imagefield"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.