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 |
|---|---|---|---|---|---|---|---|---|---|
Python: How to read csv file with different separators? | 39,485,848 | <p>This is the first line of my txt.file</p>
<pre><code>0.112296E+02-.121994E-010.158164E-030.158164E-030.000000E+000.340000E+030.328301E-010.000000E+00
</code></pre>
<p>There should be 8 columns, sometimes separated with '-', sometimes with '.'. It's very confusing, I just have to work with the file, I didn't genera... | 3 | 2016-09-14T08:30:33Z | 39,486,193 | <p>As i said in the comments, it is not a case of multiple separators, it is just a fixed width format. <code>Pandas</code> has a method to read such files. try this:</p>
<pre><code>df = pd.read_fwf(myfile, widths=[12]*8)
print(df) # prints -> [0.112296E+02, -.121994E-01, 0.158164E-03, 0.158164E-03.1, 0.000000E+00... | 3 | 2016-09-14T08:48:57Z | [
"python",
"csv",
"pandas"
] |
Python: How to read csv file with different separators? | 39,485,848 | <p>This is the first line of my txt.file</p>
<pre><code>0.112296E+02-.121994E-010.158164E-030.158164E-030.000000E+000.340000E+030.328301E-010.000000E+00
</code></pre>
<p>There should be 8 columns, sometimes separated with '-', sometimes with '.'. It's very confusing, I just have to work with the file, I didn't genera... | 3 | 2016-09-14T08:30:33Z | 39,486,509 | <p>A possible solution is the following:</p>
<pre><code>row = '0.112296E+02-.121994E-010.158164E-030.158164E-030.000000E+000.340000E+030.328301E-010.000000E+00'
chunckLen = 12
for i in range(0, len(row), chunckLen):
print(row[0+i:chunckLen+i])
</code></pre>
<p>You can easly extend the code to handle more general ... | 1 | 2016-09-14T09:05:23Z | [
"python",
"csv",
"pandas"
] |
Python: How to read csv file with different separators? | 39,485,848 | <p>This is the first line of my txt.file</p>
<pre><code>0.112296E+02-.121994E-010.158164E-030.158164E-030.000000E+000.340000E+030.328301E-010.000000E+00
</code></pre>
<p>There should be 8 columns, sometimes separated with '-', sometimes with '.'. It's very confusing, I just have to work with the file, I didn't genera... | 3 | 2016-09-14T08:30:33Z | 39,486,552 | <p>As stated in comments, this is likely a list of numbers in scientific notation, that aren't separated by anything but simply glued together.
It could be interpreted as:</p>
<pre><code>0.112296E+02
-.121994E-010
.158164E-030
.158164E-030
.000000E+000
.340000E+030
.328301E-010
.000000E+00
</code></pre>
<p>or as </p>... | 4 | 2016-09-14T09:08:05Z | [
"python",
"csv",
"pandas"
] |
crontab to run python file if not running already | 39,485,918 | <p>I want to execute my python file via crontab only if its down or not running already. I tried adding below entry in cron tab but it does not work</p>
<pre><code>24 07 * * * pgrep -f test.py || nohup python /home/dp/script/test.py & > /var/tmp/test.out
</code></pre>
<p>test.py works fine if i run <code>pgre... | 2 | 2016-09-14T08:34:09Z | 39,569,235 | <p>cron may be seeing the <code>pgrep -f test.py</code> process as well as the <code>test.py</code> process, giving you the wrong result from <code>pgrep</code>.<br>
Try the command without the <code>-f</code>, this should just look for an occurrence of <code>test.py</code> or replace <code>-f</code> with <code>-o</cod... | 0 | 2016-09-19T09:03:20Z | [
"python",
"crontab"
] |
crontab to run python file if not running already | 39,485,918 | <p>I want to execute my python file via crontab only if its down or not running already. I tried adding below entry in cron tab but it does not work</p>
<pre><code>24 07 * * * pgrep -f test.py || nohup python /home/dp/script/test.py & > /var/tmp/test.out
</code></pre>
<p>test.py works fine if i run <code>pgre... | 2 | 2016-09-14T08:34:09Z | 39,571,561 | <h3>pgrep -f lists itself as a false match when run from cron</h3>
<p>I did the test with a <code>script.py</code> running an infinite loop. Then</p>
<pre class="lang-sh prettyprint-override"><code>pgrep -f script.py
</code></pre>
<p>...from the terminal, gave <strong><em>one</em></strong> pid, <code>13132</code> , ... | 0 | 2016-09-19T11:01:02Z | [
"python",
"crontab"
] |
crontab to run python file if not running already | 39,485,918 | <p>I want to execute my python file via crontab only if its down or not running already. I tried adding below entry in cron tab but it does not work</p>
<pre><code>24 07 * * * pgrep -f test.py || nohup python /home/dp/script/test.py & > /var/tmp/test.out
</code></pre>
<p>test.py works fine if i run <code>pgre... | 2 | 2016-09-14T08:34:09Z | 39,571,775 | <p>It is generally a good idea to check whether the application is running or not within the application rather than checking from outside and starting it. Managing the process within the process rather than expecting another process to do it.</p>
<ol>
<li>Let the cron run the application always</li>
<li>At the start ... | 3 | 2016-09-19T11:10:46Z | [
"python",
"crontab"
] |
Unbound Local Error when Assigning to Function Arg | 39,485,935 | <pre><code>def make_accumulator(init):
def accumulate(part):
init = init + part
return init
return accumulate
A = make_accumulator(1)
print A(2)
</code></pre>
<p>gives me:-</p>
<pre><code>Traceback (most recent call last):
File "make-accumulator.py", line 8, in <module>
print A(... | 0 | 2016-09-14T08:35:04Z | 39,486,074 | <p>That's because during parsing the inner function when Python sees the assignment <code>init = init + part</code> it thinks <code>init</code> is a local variable and it will only look for it in local scope when the function is actually invoked.</p>
<p>To fix it add <code>init</code> as an argument to <code>accumulat... | 1 | 2016-09-14T08:43:15Z | [
"python",
"function",
"python-3.x",
"scope",
"python-2.x"
] |
Unbound Local Error when Assigning to Function Arg | 39,485,935 | <pre><code>def make_accumulator(init):
def accumulate(part):
init = init + part
return init
return accumulate
A = make_accumulator(1)
print A(2)
</code></pre>
<p>gives me:-</p>
<pre><code>Traceback (most recent call last):
File "make-accumulator.py", line 8, in <module>
print A(... | 0 | 2016-09-14T08:35:04Z | 39,486,169 | <pre><code>>>> def make_accumulator(init):
... def accumulate(part):
... return init + part
... return accumulate
...
>>> make_accumulator(1)
<function accumulate at 0x7fe3ec398938>
>>> A(2)
3
</code></pre>
<p>Since you declare <code>init</code> inside accumulate, Pyt... | 1 | 2016-09-14T08:47:27Z | [
"python",
"function",
"python-3.x",
"scope",
"python-2.x"
] |
pandas read_csv with pound sign in column headers | 39,485,976 | <p>I need to read data from a tab-delimited file where the 1st row contains column headers but the 1st character of that row is a pound sign/octothorpe/hastag <code>#</code>.</p>
<p>The data look like this:</p>
<pre><code>FILE_CONTENTS = """\
# year-month-day spam eggs
1956-01-31 11 21
1985-03-20 12 22
1940... | 0 | 2016-09-14T08:37:15Z | 39,485,977 | <p>This gives the desired <code>DataFrame</code></p>
<pre><code>from io import StringIO
import pandas as pd
FILE_CONTENTS = """\
# year-month-day spam eggs
1956-01-31 11 21
1985-03-20 12 22
1940-11-22 13 23
"""
df = pd.read_csv(StringIO(FILE_CONTENTS), delim_whitespace=True, escapechar='#')
df.columns = ... | 0 | 2016-09-14T08:37:15Z | [
"python",
"python-3.x",
"pandas"
] |
pandas read_csv with pound sign in column headers | 39,485,976 | <p>I need to read data from a tab-delimited file where the 1st row contains column headers but the 1st character of that row is a pound sign/octothorpe/hastag <code>#</code>.</p>
<p>The data look like this:</p>
<pre><code>FILE_CONTENTS = """\
# year-month-day spam eggs
1956-01-31 11 21
1985-03-20 12 22
1940... | 0 | 2016-09-14T08:37:15Z | 39,488,155 | <p>You still have to shift the column names by a single position to the left to account for the empty column getting created due to the removal of <code>#</code> char. </p>
<p>Then, remove the extra column whose values are all <code>NaN</code>.</p>
<pre><code>def column_cleaning(frame):
frame.columns = np.roll(fr... | 0 | 2016-09-14T10:29:09Z | [
"python",
"python-3.x",
"pandas"
] |
Inconsistent behaviour when importing my own module in Python 2.7 | 39,485,982 | <p>I have created a module, it's sitting in its own folder with an <code>__init__.py</code> and four files that contain my classes.</p>
<p>When doing <code>from MyPackage import *</code> I'm getting the modules that I have written into the <code>__all__</code> statement in my <code>__init__.py</code> just as expected.... | 1 | 2016-09-14T08:37:54Z | 39,486,219 | <p><code>__all__</code> determines what names are <em>exported</em> from that module. However in order to export them you would need to import them in the first place, which you haven't.</p>
| 1 | 2016-09-14T08:50:09Z | [
"python",
"python-2.7",
"module"
] |
Scraping ajax page with Scrapy? | 39,486,224 | <p>I'm using Scrapy for scrape data from this page</p>
<blockquote>
<p><a href="https://www.bricoetloisirs.ch/magasins/gardena" rel="nofollow">https://www.bricoetloisirs.ch/magasins/gardena</a></p>
</blockquote>
<p>Product list appears dynamically.
Find url to get products</p>
<blockquote>
<p><a href="https://ww... | 0 | 2016-09-14T08:50:20Z | 39,486,396 | <p>As far as i know websites use JavaScript to make Ajax calls.<br>
when you use <code>scrapy</code> the page's JS dose not load.</p>
<p>You will need to take a look at <a href="http://selenium-python.readthedocs.io/" rel="nofollow">Selenium</a> for scraping those kind of pages.</p>
<p>Or find out what ajax calls are... | 0 | 2016-09-14T08:58:44Z | [
"python",
"ajax",
"scrapy"
] |
Scraping ajax page with Scrapy? | 39,486,224 | <p>I'm using Scrapy for scrape data from this page</p>
<blockquote>
<p><a href="https://www.bricoetloisirs.ch/magasins/gardena" rel="nofollow">https://www.bricoetloisirs.ch/magasins/gardena</a></p>
</blockquote>
<p>Product list appears dynamically.
Find url to get products</p>
<blockquote>
<p><a href="https://ww... | 0 | 2016-09-14T08:50:20Z | 39,487,265 | <p>I believe you need to send an additional request just like a browser does. Try to modify your code as follows:</p>
<pre><code># -*- coding: utf-8 -*-
import scrapy
from scrapy.http import Request
from v4.items import Product
class GardenaCoopBricoLoisirsSpider(scrapy.Spider):
name = "Gardena_Coop_Brico_Loisi... | 0 | 2016-09-14T09:41:58Z | [
"python",
"ajax",
"scrapy"
] |
Scraping ajax page with Scrapy? | 39,486,224 | <p>I'm using Scrapy for scrape data from this page</p>
<blockquote>
<p><a href="https://www.bricoetloisirs.ch/magasins/gardena" rel="nofollow">https://www.bricoetloisirs.ch/magasins/gardena</a></p>
</blockquote>
<p>Product list appears dynamically.
Find url to get products</p>
<blockquote>
<p><a href="https://ww... | 0 | 2016-09-14T08:50:20Z | 39,490,622 | <p>I solve this.</p>
<pre><code># -*- coding: utf-8 -*-
import scrapy
from v4.items import Product
class GardenaCoopBricoLoisirsSpider(scrapy.Spider):
name = "Gardena_Coop_Brico_Loisirs_py"
start_urls = [
'https://www.bricoetloisirs.ch/magasins/gardena'
]
def parse(self, response):... | 0 | 2016-09-14T12:35:52Z | [
"python",
"ajax",
"scrapy"
] |
Recognition of a sound (a word) with machine learning in python | 39,486,341 | <p>I'm preparing an experiment, and I want to write a program using python to recognize certain word spoken by the participants.</p>
<p>I searched a lot about speech recognition in python but the results are complicated.(e.g. CMUSphinx).</p>
<p>What I want to achieve is a program, that receive a sound file (contains ... | 0 | 2016-09-14T08:56:07Z | 39,486,898 | <p>I've written such program in text recognition. I can tell you if you chose to "teach" your program manually you will have a lot of work think about the variation in voice due to accents etc. </p>
<p>You could start <a href="https://wiki.python.org/moin/PythonInMusic" rel="nofollow">looking for a sound analyzer here... | 0 | 2016-09-14T09:25:30Z | [
"python",
"audio",
"machine-learning"
] |
calculate avg response time from multiple curl commands using python | 39,486,482 | <p>I am trying to do a load testing of my web server using curl command.</p>
<p>I am able to run multiple curl commands, but now I also want to calculate the avg response time from all the curl command which were executed </p>
<pre><code>from functools import partial
from multiprocessing.dummy import Pool
from subpro... | 0 | 2016-09-14T09:03:48Z | 39,487,374 | <p>Instead of relying to <code>call</code> you could create separate function executed by <code>imap</code>. Then you could use <a href="https://docs.python.org/3.5/library/subprocess.html#subprocess.Popen" rel="nofollow"><code>Popen</code></a> that allows you to communicate with the child process. The example below wr... | 1 | 2016-09-14T09:48:00Z | [
"python",
"curl"
] |
Google maps API to extract company details | 39,486,794 | <p>I am trying to extract the details displayed when you search for a company name on google maps. As shown in the image below:</p>
<p><img src="http://i.stack.imgur.com/LwWBf.png" alt="Google maps search results"></p>
<p>I tired the <code>http://maps.google.com/maps/api/geocode/json?address=</code> this gives only t... | -1 | 2016-09-14T09:20:23Z | 39,487,354 | <p>The URL you mentioned is a <a href="https://developers.google.com/maps/documentation/geocoding/start" rel="nofollow">Google Geocoding API</a>, for company details you should use <strong>places</strong> method from <a href="https://developers.google.com/places/web-service/details" rel="nofollow">Google Places API</a>... | 0 | 2016-09-14T09:46:58Z | [
"python",
"google-maps-api-3"
] |
How to fit an ellipse contour with 4 points? | 39,486,869 | <p>I have 4 coordinate points. Using these 4 points I want to fit an ellipse, but seems like the requirement for cv2.fitellipse() is a minimum of 5 points. Is there any way to get around this and draw a countour with just 4 points?</p>
<p>How does fitellipse draw a contour when cv2.CHAIN_APPROX_SIMPLE is used, which g... | 0 | 2016-09-14T09:24:00Z | 39,488,635 | <p>Four points aren't enough to fit an ellipse without ambiguity (don't forget that a general ellipse can have arbitrary rotation). You need at least five to get an exact solution or more to fit in a least square manner. For a more detailed explanation I found <a href="https://sarcasticresonance.wordpress.com/2012/05/1... | 1 | 2016-09-14T10:53:17Z | [
"python",
"opencv",
"image-processing"
] |
How to fit an ellipse contour with 4 points? | 39,486,869 | <p>I have 4 coordinate points. Using these 4 points I want to fit an ellipse, but seems like the requirement for cv2.fitellipse() is a minimum of 5 points. Is there any way to get around this and draw a countour with just 4 points?</p>
<p>How does fitellipse draw a contour when cv2.CHAIN_APPROX_SIMPLE is used, which g... | 0 | 2016-09-14T09:24:00Z | 39,494,238 | <p>If you take a look at the equation for ellipses:</p>
<p><a href="http://i.stack.imgur.com/EkEHr.gif" rel="nofollow"><img src="http://i.stack.imgur.com/EkEHr.gif" alt="enter image description here"></a></p>
<p>and the homogenous representation:</p>
<p><a href="http://i.stack.imgur.com/ehVZY.gif" rel="nofollow"><im... | 0 | 2016-09-14T15:24:44Z | [
"python",
"opencv",
"image-processing"
] |
Scrapy installed, but won't recognized in the command line | 39,486,965 | <p>I installed Scrapy in my python 2.7 environment in windows 7 but when I trying to start a new Scrapy project using <code>scrapy startproject newProject</code> the command prompt show this massage</p>
<pre><code>'scrapy' is not recognized as an internal or external command,
operable program or batch file.
</code></p... | 0 | 2016-09-14T09:28:15Z | 39,487,077 | <p><a href="http://doc.scrapy.org/en/1.1/intro/install.html#intro-install-platform-notes" rel="nofollow">Scrapy should be in your environment variables</a>. You can check if it's there with the following in windows:</p>
<pre><code>echo %PATH% # To print only the path
set # For all
</code></pre>
<p>or</p>
<pre><code... | 1 | 2016-09-14T09:34:10Z | [
"python",
"python-2.7",
"scrapy",
"scrapy-spider"
] |
Scrapy installed, but won't recognized in the command line | 39,486,965 | <p>I installed Scrapy in my python 2.7 environment in windows 7 but when I trying to start a new Scrapy project using <code>scrapy startproject newProject</code> the command prompt show this massage</p>
<pre><code>'scrapy' is not recognized as an internal or external command,
operable program or batch file.
</code></p... | 0 | 2016-09-14T09:28:15Z | 39,510,766 | <p>See the <a href="http://doc.scrapy.org/en/1.1/intro/install.html" rel="nofollow">official documentation</a> or stackoverflow <a class='doc-link' href="http://stackoverflow.com/documentation/scrapy/2099/introduction-to-scrapy/22896/creating-a-project#t=201609151211472059058">documentation</a>.</p>
<ul>
<li><strong>S... | 0 | 2016-09-15T12:13:35Z | [
"python",
"python-2.7",
"scrapy",
"scrapy-spider"
] |
Matplotlib: misaligned colorbar ticks? | 39,486,999 | <p>I'm trying to plot data in the range 0-69 with a bespoke colormap. Here is an example:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
colors = [(0.9, 0.9, 0.9), # Value = 0
(0.3, 0.3, 0.3), # Value = 9
(1.0, 0.4, 0.4... | 1 | 2016-09-14T09:30:29Z | 39,567,623 | <p>The simplest way to solve my problem was to set <code>vmax</code> in the definition of the mappable:</p>
<pre><code>ax = plt.imshow(data, cmap=cmap, interpolation='nearest', vmax=max_val + 1)
</code></pre>
<p>It was being set at <code>max_val</code> because the Colorbar class has the call <code>mappable.autoscale_... | 0 | 2016-09-19T07:31:25Z | [
"python",
"matplotlib",
"colorbar"
] |
How to prevent Django's label_tag function from escaping the label? | 39,487,079 | <p>Example:</p>
<pre><code>>>> example.label
&#x3bb;<sub>blabla</sub>
>>> example.label_tag()
[...]&amp;#x3bb;&lt;blabla&gt;[...]
</code></pre>
<p>Even calling <code>mark_safe(example.label)</code> before <code>label_tag()</code> does not prevent Django from escaping the ... | 1 | 2016-09-14T09:34:12Z | 39,487,162 | <p>Try this:</p>
<pre><code> from HTMLParser import HTMLParser
h = HTMLParser()
unescaped = h.unescape(example.label_tag())
print unescaped
</code></pre>
| 1 | 2016-09-14T09:37:26Z | [
"python",
"django"
] |
How to prevent Django's label_tag function from escaping the label? | 39,487,079 | <p>Example:</p>
<pre><code>>>> example.label
&#x3bb;<sub>blabla</sub>
>>> example.label_tag()
[...]&amp;#x3bb;&lt;blabla&gt;[...]
</code></pre>
<p>Even calling <code>mark_safe(example.label)</code> before <code>label_tag()</code> does not prevent Django from escaping the ... | 1 | 2016-09-14T09:34:12Z | 39,487,288 | <p>There is a comment in the <a href="https://github.com/django/django/blob/2ced2f785d5aca0354abf5841d5449b7a49509dc/django/forms/boundfield.py#L135" rel="nofollow">code for <code>label_tag</code></a></p>
<pre><code>Wraps the given contents in a <label>, if the field has an ID attribute.
contents should be 'mark... | 1 | 2016-09-14T09:43:20Z | [
"python",
"django"
] |
How to prevent Django's label_tag function from escaping the label? | 39,487,079 | <p>Example:</p>
<pre><code>>>> example.label
&#x3bb;<sub>blabla</sub>
>>> example.label_tag()
[...]&amp;#x3bb;&lt;blabla&gt;[...]
</code></pre>
<p>Even calling <code>mark_safe(example.label)</code> before <code>label_tag()</code> does not prevent Django from escaping the ... | 1 | 2016-09-14T09:34:12Z | 39,488,587 | <p>You have to mark the label as safe when you define the field.</p>
<pre><code>class MyForm(forms.Form):
example = forms.Field(label=mark_safe('&#x3bb;<sub>blabla</sub>'))
</code></pre>
<p>Example:</p>
<pre><code>>>> f = MyForm({'example': 'foo'})
>>> str(f)
'<tr><th&... | 0 | 2016-09-14T10:50:44Z | [
"python",
"django"
] |
How to send email from python | 39,487,103 | <p>My Code</p>
<pre><code>import smtplib
import socket
import sys
from email.mime.text import MIMEText
fp = open("CR_new.txt", 'r')
msg = MIMEText(fp.read())
fp.close()
you = "[email protected]"
me = "[email protected]"
msg['Subject'] = 'The contents of %s' % "CR_new.txt"
msg['From'] = you
msg['To'] = me
s = smtplib.SM... | 0 | 2016-09-14T09:35:12Z | 39,487,885 | <p>This code will help you to send the email.
You just need to provide your email-id password.</p>
<p>The most important note is: don't give file name as email.py.</p>
<pre><code>import socket
import sys
import smtplib
EMAIL_TO = ["[email protected]"]
EMAIL_FROM = "[email protected]"
EMAIL_SUBJECT = "Test Mail... "
msg... | 0 | 2016-09-14T10:13:40Z | [
"python",
"email"
] |
How to send email from python | 39,487,103 | <p>My Code</p>
<pre><code>import smtplib
import socket
import sys
from email.mime.text import MIMEText
fp = open("CR_new.txt", 'r')
msg = MIMEText(fp.read())
fp.close()
you = "[email protected]"
me = "[email protected]"
msg['Subject'] = 'The contents of %s' % "CR_new.txt"
msg['From'] = you
msg['To'] = me
s = smtplib.SM... | 0 | 2016-09-14T09:35:12Z | 39,497,595 | <p>I would suggest using a package like <a href="https://github.com/kootenpv/yagmail" rel="nofollow">yagmail</a>, rather than trying to figure out how to get smtplib to work. Disclaimer: I'm the maintainer of yagmail.</p>
<p>Code would look like:</p>
<pre><code>import yagmail
yag = yagmail.SMTP(host="127.0.0.1")
yag.... | 0 | 2016-09-14T18:48:07Z | [
"python",
"email"
] |
Using matplotlib to solve Point in Polygone | 39,487,194 | <p>I am looking for an algorithm to check if a point is within a polygon or not.</p>
<p>I am currently using mplPath and contains_point() but it doesn't seem to work in some cases.</p>
<p>EDIT 16 Sept 2016:</p>
<p>Okay so I imporved my code by simply checking if the point where also on the edges. I still have some i... | 0 | 2016-09-14T09:39:15Z | 39,513,209 | <p>If doing it the long way isn't bad, you could go off of the principle: <strong>a point is inside a polygon if number of intersections is odd and similarly outside if number of intersections is even</strong>. Here's some sloppy python i put together with the test case you gave above.</p>
<pre class="lang-python pret... | 0 | 2016-09-15T14:06:02Z | [
"python",
"algorithm",
"python-2.7",
"matplotlib",
"point-in-polygon"
] |
Using matplotlib to solve Point in Polygone | 39,487,194 | <p>I am looking for an algorithm to check if a point is within a polygon or not.</p>
<p>I am currently using mplPath and contains_point() but it doesn't seem to work in some cases.</p>
<p>EDIT 16 Sept 2016:</p>
<p>Okay so I imporved my code by simply checking if the point where also on the edges. I still have some i... | 0 | 2016-09-14T09:39:15Z | 39,530,141 | <p>Okay so I finally managed to get it done using shapely instead.</p>
<pre><code>#for PIP problem
import matplotlib.path as mplPath
import numpy as np
#for plot
import matplotlib.pyplot as plt
import shapely.geometry as shapely
class MyPoly(shapely.Polygon):
def __init__(self,points):
super(MyPoly,self).... | 0 | 2016-09-16T11:15:01Z | [
"python",
"algorithm",
"python-2.7",
"matplotlib",
"point-in-polygon"
] |
create a dynamic two dimensional array in python (loop) | 39,487,235 | <p>i am trying to create a two-dimensional array in python..In my php i have this code: </p>
<pre><code>$i = 1;
$arr= array();
foreach($mes as $res){
$arr[$i]->type = $res->item;
$arr[$i]->action = $res->title;
$i++
}
</code></pre>
<p>how can i make that code in python? i ... | 0 | 2016-09-14T09:40:40Z | 39,487,314 | <p>A <em>list comprehension</em> with nested dictionaries is a simple way to do this:</p>
<pre><code>arr = [{'type': res['item'], 'action': res['title']} for res in mes]
</code></pre>
<hr>
<p>The first item (and others similarly by changing the index) in <code>arr</code> can then be accessed with:</p>
<pre><code>ar... | 0 | 2016-09-14T09:44:44Z | [
"python"
] |
how to use variables in where clause of orientdb query using python | 39,487,454 | <p>code</p>
<pre><code>import pyorient
# create connection
client = pyorient.OrientDB("localhost", 2424)
# open databse
client.db_open( "Apple", "admin", "admin" )
requiredObj = client.command(" select out().question as qlist,out().seq as qseq,out().pattern as pattern,out().errormsg as errormsg from chat where a... | -2 | 2016-09-14T09:52:09Z | 39,488,543 | <p>You could use this command</p>
<pre><code>requiredObj = client.command("select from chat where name='%s'" % "chat 1");
</code></pre>
<p>or </p>
<pre><code>requiredObj = client.command("select from chat where name='%s' and room='%s'" % ("chat 1","1"));
</code></pre>
<p>Hope it helps</p>
| 0 | 2016-09-14T10:48:27Z | [
"python",
"orientdb"
] |
Python list concatenation with strings into new list | 39,487,507 | <p>Im looking for the best way to take a list of stirngs, generate a new list with each item from the previous list concatenated with a specific string.</p>
<p><strong>Example sudo code</strong></p>
<pre><code>list1 = ['Item1','Item2','Item3','Item4']
string = '-example'
NewList = ['Item1-example','Item2-example','It... | 1 | 2016-09-14T09:54:43Z | 39,487,525 | <p>If you want to create a list, a list comprehension is usually the thing to do.</p>
<pre><code>new_list = ["{}{}".format(item, string) for item in list1]
</code></pre>
| 5 | 2016-09-14T09:55:22Z | [
"python"
] |
Python list concatenation with strings into new list | 39,487,507 | <p>Im looking for the best way to take a list of stirngs, generate a new list with each item from the previous list concatenated with a specific string.</p>
<p><strong>Example sudo code</strong></p>
<pre><code>list1 = ['Item1','Item2','Item3','Item4']
string = '-example'
NewList = ['Item1-example','Item2-example','It... | 1 | 2016-09-14T09:54:43Z | 39,487,557 | <p>Use string concatenation in a list comprehension:</p>
<pre><code>>>> list1 = ['Item1', 'Item2', 'Item3', 'Item4']
>>> string = '-example'
>>> [x + string for x in list1]
['Item1-example', 'Item2-example', 'Item3-example', 'Item4-example']
</code></pre>
| 3 | 2016-09-14T09:56:40Z | [
"python"
] |
Python list concatenation with strings into new list | 39,487,507 | <p>Im looking for the best way to take a list of stirngs, generate a new list with each item from the previous list concatenated with a specific string.</p>
<p><strong>Example sudo code</strong></p>
<pre><code>list1 = ['Item1','Item2','Item3','Item4']
string = '-example'
NewList = ['Item1-example','Item2-example','It... | 1 | 2016-09-14T09:54:43Z | 39,487,899 | <p>concate list item and string </p>
<pre><code>>>>list= ['Item1', 'Item2', 'Item3', 'Item4']
>>>newList=[ i+'-example' for i in list]
>>>newList
['Item1-example', 'Item2-example', 'Item3-example', 'Item4-example']
</code></pre>
| 1 | 2016-09-14T10:14:34Z | [
"python"
] |
Python list concatenation with strings into new list | 39,487,507 | <p>Im looking for the best way to take a list of stirngs, generate a new list with each item from the previous list concatenated with a specific string.</p>
<p><strong>Example sudo code</strong></p>
<pre><code>list1 = ['Item1','Item2','Item3','Item4']
string = '-example'
NewList = ['Item1-example','Item2-example','It... | 1 | 2016-09-14T09:54:43Z | 39,487,941 | <p>An alternative to list comprehension is using <code>map()</code>:</p>
<pre><code>>>> map(lambda x: x+string,list1)
['Item1-example', 'Item2-example', 'Item3-example', 'Item4-example']
</code></pre>
<p>Note, <code>list(map(lambda x: x+string,list1))</code> in Python3.</p>
| 2 | 2016-09-14T10:17:40Z | [
"python"
] |
How to stop bokeh server? | 39,487,574 | <p>I do use bokeh to plot sensor data live on the local LAN. Bokeh is started from within my python application using popen: <code>Popen("bokeh serve --host=localhost:5006 --host=192.168.8.100:5006", shell=True)</code></p>
<p>I would like to close bokeh server from within the application. However, I cannot find anythi... | 1 | 2016-09-14T09:57:29Z | 39,487,949 | <p>Without knowing bokeh and assuming that you use Python >= 3.2 or Linux, you could try to kill the process with <code>SIGTERM</code>, <code>SIGINT</code> or <code>SIGHUP</code>, using <a href="https://docs.python.org/3/library/os.html#os.kill" rel="nofollow"><code>os.kill()</code></a> with <a href="https://docs.pytho... | 0 | 2016-09-14T10:17:58Z | [
"python",
"bokeh"
] |
How to write numpy arrays to .txt file, starting at a certain line? numpy version 1.6 | 39,487,605 | <p>At: <a href="http://stackoverflow.com/questions/39483774/how-to-write-numpy-arrays-to-txt-file-starting-at-a-certain-line">How to write numpy arrays to .txt file, starting at a certain line?</a></p>
<p>People helped me to solve my problem - this works for numpy Version 1.7 or later. Unfortunatelly I have to use the... | 2 | 2016-09-14T09:58:38Z | 39,488,326 | <p>You write your header first, then you dump the data.
Note that you'll need to add the <code>#</code> in each line of the header as <code>np.savetxt</code> won't do it.</p>
<pre><code>time = np.array([0,60,120,180])
operation1 = np.array([12,23,68,26])
operation2 = np.array([100,123,203,301])
header='#Filexy\n#time ... | 2 | 2016-09-14T10:37:19Z | [
"python",
"numpy"
] |
Cassandra Python Driver Error callback shows No error | 39,487,752 | <p>I'm right now performing load tests on an API endpoint that saves data into cassandra. In general it works well, but when I perform async insert operations I get the following messages on the error callback:</p>
<pre><code>ERROR:root:Query '<BatchStatement type=UNLOGGED, statements=382, consistency=ONE>' fail... | 0 | 2016-09-14T10:06:03Z | 39,491,691 | <p>So I found out the issue.</p>
<p>It is a client side error of the type <code>OperationTimedOut</code>. You can find it in here:</p>
<p><a href="https://github.com/datastax/python-driver/blob/1fd961a55a06a3ab739a3995d09c53a1b0e35fb5/cassandra/__init__.py" rel="nofollow">https://github.com/datastax/python-driver/blo... | 0 | 2016-09-14T13:25:11Z | [
"python",
"cassandra",
"datastax"
] |
how to wrap automatically functions from certain file | 39,487,769 | <p>It's a well known fact there are many ways to get a function name using python standard library, here's a little example:</p>
<pre><code>import sys
import dis
import traceback
def get_name():
stack = traceback.extract_stack()
filename, codeline, funcName, text = stack[-2]
return funcName
def foo1():... | 1 | 2016-09-14T10:07:03Z | 39,488,868 | <p>A solution could be to use <code>globals()</code> for getting information about currently defined objects. Here is a simple wrapper function, which replaces the functions within the given globals data by a wrapped version of them:</p>
<pre><code>import types
def my_tiny_wrapper(glb):
def wrp(f):
# crea... | 1 | 2016-09-14T11:05:10Z | [
"python",
"python-2.7",
"python-3.x",
"introspection"
] |
how to wrap automatically functions from certain file | 39,487,769 | <p>It's a well known fact there are many ways to get a function name using python standard library, here's a little example:</p>
<pre><code>import sys
import dis
import traceback
def get_name():
stack = traceback.extract_stack()
filename, codeline, funcName, text = stack[-2]
return funcName
def foo1():... | 1 | 2016-09-14T10:07:03Z | 39,489,697 | <p>Here's the solution I was looking for:</p>
<pre><code>import inspect
import time
import random
import sys
random.seed(1)
def foo1():
print("Foo0 processing")
def foo2():
print("Foo2 processing")
def foo3():
print("Foo3 processing")
def wrap_functions_from_this_file():
def wrapper(f):
... | 0 | 2016-09-14T11:49:19Z | [
"python",
"python-2.7",
"python-3.x",
"introspection"
] |
How to get the defining class from a method body? | 39,487,829 | <p>I have two classes:</p>
<pre><code>class A:
def foo(self):
print(<get the defining class>)
class B(A):
pass
</code></pre>
<p>Now, I need to replace <code><get the defining class></code> by a code such that this:</p>
<pre><code>a = A()
b = B()
a.foo()
b.foo()
</code></pre>
<p>produces... | 0 | 2016-09-14T10:10:08Z | 39,488,947 | <p>The simplest way to do this is by using the functions qualified name:</p>
<pre><code>class A:
def foo(self):
print(self.foo.__qualname__[0])
class B(A):
pass
</code></pre>
<p>The qualified name consists of the class defined and the function name in <code>cls_name.func_name</code> form. <code>__qua... | 2 | 2016-09-14T11:09:27Z | [
"python",
"class",
"python-3.x",
"methods"
] |
How to get the defining class from a method body? | 39,487,829 | <p>I have two classes:</p>
<pre><code>class A:
def foo(self):
print(<get the defining class>)
class B(A):
pass
</code></pre>
<p>Now, I need to replace <code><get the defining class></code> by a code such that this:</p>
<pre><code>a = A()
b = B()
a.foo()
b.foo()
</code></pre>
<p>produces... | 0 | 2016-09-14T10:10:08Z | 39,489,750 | <p>I'm assuming that you don't want to hard-code this logic into each function, since you could do so trivially in your example code.</p>
<p>If the <code>print</code> statement is always the first statement of the methods for which you want this behaviour, one possible solution would be to use a decorator.</p>
<pre><... | -1 | 2016-09-14T11:51:27Z | [
"python",
"class",
"python-3.x",
"methods"
] |
Google Cloud Platform - Datastore - Python ndb API | 39,487,831 | <p>I recently started working with the Google Cloud Platform, more precisely, with the ndb-Datastore-API. I tried to use following tutorial (<a href="https://github.com/GoogleCloudPlatform/appengine-guestbook-python.git" rel="nofollow">https://github.com/GoogleCloudPlatform/appengine-guestbook-python.git</a>) to get us... | 2 | 2016-09-14T10:10:14Z | 39,734,086 | <p>Based on your <code>tweet.py</code> and <code>app.yaml</code>, I can see the 2 things that may be the reason you cannot yet use <strong>tweepy</strong> in your Python application. For the sake of being through, I'll document the complete process.</p>
<h2>Acquire tweepy library</h2>
<p>As <strong>Tweepy</strong> i... | 1 | 2016-09-27T20:50:40Z | [
"python",
"google-app-engine",
"google-cloud-platform",
"google-cloud-datastore"
] |
Django authentication and permissions | 39,487,857 | <p>I posted a question on SO regarding Django authentication and permissions even though it's already there. My question is ,</p>
<p>I have a backend ready with a lot of views, models and serializers from DRF. Now I want to apply authentication to my app and create RESTful apis that are consumed at the front-end. So t... | 0 | 2016-09-14T10:12:17Z | 39,490,638 | <p>Django uses table <code>auth_user</code> to save user and password</p>
<p>Django has an API to check <code>is_authenticated</code></p>
<hr>
<p>Django rest framework uses table <code>authtoken_token</code> </p>
<p>Django rest framework has an API <code>rest_framework.authtoken.views.obtain_auth_token</code> for t... | 0 | 2016-09-14T12:37:04Z | [
"python",
"django",
"django-rest-framework"
] |
Django authentication and permissions | 39,487,857 | <p>I posted a question on SO regarding Django authentication and permissions even though it's already there. My question is ,</p>
<p>I have a backend ready with a lot of views, models and serializers from DRF. Now I want to apply authentication to my app and create RESTful apis that are consumed at the front-end. So t... | 0 | 2016-09-14T10:12:17Z | 39,492,849 | <blockquote>
<p>How does authentication work? Does Django create different model tables for each of its user?</p>
</blockquote>
<p>No, Django does not create different model tables for each of its users. The users itself are stored as entry in the <code>User</code>-Model. So to have data for each user you have to ad... | 0 | 2016-09-14T14:21:14Z | [
"python",
"django",
"django-rest-framework"
] |
Interactive/Animated scatter plotting with matplotlib | 39,487,901 | <p>I want to animate the scatter plot based on the actual timestamp from the csv file (see below). I'm not so good with matplotlib and I know of the animation function and the ion()-function but I'm not sure how to implement it.
I read <a href="http://stackoverflow.com/questions/32268532/animate-a-scatterplot-with-pypl... | 0 | 2016-09-14T10:14:42Z | 39,505,892 | <p>The quickest way to animate on the same axis is to use interactive plots, <code>plt.ion</code></p>
<pre><code>import pandas as pd
import matplotlib.pyplot as plt
start_time = 86930.00
end_time = 86934.00
df = pd.read_csv('Data.csv', delimiter=',')
fig, ax = plt.subplots(1,1)
plt.ion()
plt.show()
for timestamp i... | 1 | 2016-09-15T07:59:51Z | [
"python",
"pandas",
"matplotlib"
] |
Django database objects not displaying | 39,487,918 | <p>I keep getting <code><QuerySet [<Member: - >]></code> whenever I try to display all objects within a model class through <code>Member.objects.all()</code> in the shell.</p>
<p>This is my code, note that the Book class is displaying them correctly when I call all objects, but the Member class does not:<... | 0 | 2016-09-14T10:16:03Z | 39,488,224 | <p>You are just creating some variables. You have to assign to the attributes of the object you created and actually save it.</p>
<pre><code>from dashboard.models import Member
a = Member()
a.Name = 'xxx'
a.Surname = 'xxx'
a.Mailadres = 'xxxxxxx'
a.Birth = 'xx-xx-xxxx'
a.Leerlingnummer = 'xxxxxxxxx'
a.save()
</code></... | 0 | 2016-09-14T10:32:53Z | [
"python",
"django",
"database",
"shell",
"object"
] |
Which errors to catch when a module doesn't document all of its errors? (plistlib) | 39,488,045 | <p>TL;DR: What kind of errors to catch when a module doesn't document all of its errors?</p>
<p><strong>Scenario</strong>:</p>
<p>I'm trying to read a series of <a href="https://en.wikipedia.org/wiki/Property_list" rel="nofollow">property lists</a> using <a href="https://docs.python.org/2/library/plistlib.html" rel="... | 2 | 2016-09-14T10:22:17Z | 39,488,221 | <p>If you can't do any better, then <code>except Exception:</code> avoids catching <code>KeyboardInterrupt</code> or <code>SystemExit</code>.</p>
<p>It does however catch <code>StopIteration</code> and <code>GeneratorExit</code>. Possibly you can safely move down to catching <code>StandardError</code> (which excludes ... | 2 | 2016-09-14T10:32:36Z | [
"python",
"python-2.7",
"error-handling",
"try-catch",
"plist"
] |
Odoo 9 report Task error | 39,488,049 | <p>I want create report from Project > Task.</p>
<p>When try load data from table <strong>account_analytic_line</strong> </p>
<p><a href="http://i.stack.imgur.com/9CBL1.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/9CBL1.jpg" alt="enter image description here"></a></p>
<p>get this error</p>
<p>"'project.ta... | 0 | 2016-09-14T10:22:44Z | 39,702,943 | <p>Its timesheet_ids not timesheets_ids. Just a spell mistake.</p>
| 0 | 2016-09-26T12:32:52Z | [
"python",
"openerp",
"odoo-9"
] |
Python Class instantiation: What does it mean when a class is called without accompanying arguments? | 39,488,061 | <p>I am trying to understand some code that I have found on github. Essentially there is a class called "HistoricCSVDataHandler" that has been imported from another module. In the main method this class is passed as a parameter to another class "backtest". </p>
<p>How can a class name that does not represent a instant... | 2 | 2016-09-14T10:23:45Z | 39,488,142 | <p>A link to the code would be useful, but in python you can pass uninstantiated objects around like this just fine. i.e.:</p>
<pre><code>def f(uninst_class, arg):
return uninst_class(arg)
</code></pre>
| 0 | 2016-09-14T10:28:14Z | [
"python",
"class"
] |
Python Class instantiation: What does it mean when a class is called without accompanying arguments? | 39,488,061 | <p>I am trying to understand some code that I have found on github. Essentially there is a class called "HistoricCSVDataHandler" that has been imported from another module. In the main method this class is passed as a parameter to another class "backtest". </p>
<p>How can a class name that does not represent a instant... | 2 | 2016-09-14T10:23:45Z | 39,488,194 | <p>Think of python variables as labels, you can label a class (no instance), its like giving an alias to that class.</p>
<pre><code>>>> class A(): pass
>>> A
<class __builtin__.A at 0x000001BE82279D08>
>>> b = A
>>> b
<class __builtin__.A at 0x000001BE82279D08>
>>&... | 0 | 2016-09-14T10:31:26Z | [
"python",
"class"
] |
Python Class instantiation: What does it mean when a class is called without accompanying arguments? | 39,488,061 | <p>I am trying to understand some code that I have found on github. Essentially there is a class called "HistoricCSVDataHandler" that has been imported from another module. In the main method this class is passed as a parameter to another class "backtest". </p>
<p>How can a class name that does not represent a instant... | 2 | 2016-09-14T10:23:45Z | 39,488,252 | <p>This is a technique called <a href="https://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow"><em>dependency injection</em></a>. A class is an object just like any other, so there's nothing wrong with passing it as an argument to a function and then calling it inside the function.</p>
<p>Suppose I want to ... | 2 | 2016-09-14T10:34:26Z | [
"python",
"class"
] |
Asterisk AMI incoming calls returns no calls | 39,488,128 | <p>I have the following function with the aim is to get incoming calls from my Python web interface from the Asterisk server.</p>
<pre><code>def fetch_events(event, manager):
with app.app_context():
if event.name == 'CoreShowChannel':
id = event.message['accountcode']
data = {
'us... | -1 | 2016-09-14T10:27:36Z | 39,496,453 | <p>You should use (listen) 'Newexten' event and extract 'context' from that event ,and then look up if the calls come from incoming context if it true ,then use other variables from that event. Don't use action 'CoreShowChannel' because it will list current active channels.</p>
| 0 | 2016-09-14T17:32:45Z | [
"python",
"asterisk"
] |
Asterisk AMI incoming calls returns no calls | 39,488,128 | <p>I have the following function with the aim is to get incoming calls from my Python web interface from the Asterisk server.</p>
<pre><code>def fetch_events(event, manager):
with app.app_context():
if event.name == 'CoreShowChannel':
id = event.message['accountcode']
data = {
'us... | -1 | 2016-09-14T10:27:36Z | 39,504,488 | <p>When someone call the Asterisk example incoming call to trunk num ,Asterisk fired 'Newexten' event. The data structure of that event is:</p>
<pre><code>`{ event: 'Newexten',
privilege: 'call,all',
channel: 'SIP/NameOfyourSIPprovider-0000ae7d',//channel that will be bridged
channelstate: '0',
channelstat... | 0 | 2016-09-15T06:37:10Z | [
"python",
"asterisk"
] |
Import CSV to pandas with two delimiters | 39,488,163 | <p>I have a CSV with two delimiters (<code>;</code>) and (<code>,</code>) it looks like this:</p>
<pre><code>vin;vorgangid;eventkm;D_8_lamsoni_w_time;D_8_lamsoni_w_value
V345578;295234545;13;-1000.0,-980.0;7.9921875,11.984375
V346670;329781064;13;-960.0,-940.0;7.9921875,11.984375
</code></pre>
<p>I want to import it ... | 2 | 2016-09-14T10:29:23Z | 39,488,190 | <p>first read CSV using <code>;</code> as a delimiter:</p>
<pre><code>df = pd.read_csv(filename, sep=';')
</code></pre>
<p><strong>UPDATE:</strong></p>
<pre><code>In [67]: num_cols = df.columns.difference(['vin','vorgangid','eventkm'])
In [68]: num_cols
Out[68]: Index(['D_8_lamsoni_w_time', 'D_8_lamsoni_w_value'], ... | 3 | 2016-09-14T10:31:10Z | [
"python",
"csv",
"pandas",
"delimiter",
"csv-import"
] |
Import CSV to pandas with two delimiters | 39,488,163 | <p>I have a CSV with two delimiters (<code>;</code>) and (<code>,</code>) it looks like this:</p>
<pre><code>vin;vorgangid;eventkm;D_8_lamsoni_w_time;D_8_lamsoni_w_value
V345578;295234545;13;-1000.0,-980.0;7.9921875,11.984375
V346670;329781064;13;-960.0,-940.0;7.9921875,11.984375
</code></pre>
<p>I want to import it ... | 2 | 2016-09-14T10:29:23Z | 39,488,230 | <p>You can use parameter <code>converters</code> in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> and define custom function for spliting:</p>
<pre><code>def f(x):
return [float(i) for i in x.split(',')]
#after testing replace io.Stri... | 1 | 2016-09-14T10:33:04Z | [
"python",
"csv",
"pandas",
"delimiter",
"csv-import"
] |
Import CSV to pandas with two delimiters | 39,488,163 | <p>I have a CSV with two delimiters (<code>;</code>) and (<code>,</code>) it looks like this:</p>
<pre><code>vin;vorgangid;eventkm;D_8_lamsoni_w_time;D_8_lamsoni_w_value
V345578;295234545;13;-1000.0,-980.0;7.9921875,11.984375
V346670;329781064;13;-960.0,-940.0;7.9921875,11.984375
</code></pre>
<p>I want to import it ... | 2 | 2016-09-14T10:29:23Z | 39,489,834 | <p>Asides from the other fine answers here, which are more pandas-specific, it should be noted that Python itself is pretty powerful when it comes to string processing. You can just place the result of replacing <code>';'</code> with <code>','</code> in a <a href="https://docs.python.org/2/library/stringio.html" rel="n... | 2 | 2016-09-14T11:55:07Z | [
"python",
"csv",
"pandas",
"delimiter",
"csv-import"
] |
Dumping pickle is not working with rb+ | 39,488,237 | <p>Why pickle file is not modified? But after I uncomment the line it works?</p>
<pre><code>with open(PATH, "rb+") as fp:
mocks_pickle = pickle.load(fp)
mocks_pickle['aa'] = '123'
# pickle.dump(mocks_pickle, open(PATH, 'wb'))
pickle.dump(mocks_pickle, fp)
</code></pre>
| 0 | 2016-09-14T10:33:47Z | 39,488,510 | <p>You need to seek to the beginning of the file with <code>fp.seek(0)</code> before dumping the object.</p>
<p>If you don't seek you append the new pickle to the end of the file.
And when you <code>pickle.load</code> from the file you only get the first there is in the file.</p>
<pre><code>with open(PATH, "rb+") as ... | 1 | 2016-09-14T10:46:41Z | [
"python",
"pickle"
] |
total size of new array must be unchanged | 39,488,282 | <p>I have two arrays x1 and x2, both are 1*14 arrays i am trying to zip them up and then perform reshape.</p>
<p>The code is as below ;</p>
<pre><code>x1
</code></pre>
<p>Out[122]: array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])</p>
<pre><code>x2
</code></pre>
<p>Out[123]: array([1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2,... | 1 | 2016-09-14T10:35:35Z | 39,488,393 | <p>I would assume you're on Python 3, in which the result is an array with a <code>zip</code> object. </p>
<p>You should call <code>list</code> on the <em>zipped</em> items:</p>
<pre><code>X = np.array(list(zip(x1, x2))).reshape(2, len(x1))
# ^^^^
print(X)
# [[1 1 2 3 3 2 1 2 5 8 6 6 5 7]
# [5 6 6 7 7 1 8... | 1 | 2016-09-14T10:40:39Z | [
"python",
"arrays",
"numpy",
"reshape"
] |
total size of new array must be unchanged | 39,488,282 | <p>I have two arrays x1 and x2, both are 1*14 arrays i am trying to zip them up and then perform reshape.</p>
<p>The code is as below ;</p>
<pre><code>x1
</code></pre>
<p>Out[122]: array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])</p>
<pre><code>x2
</code></pre>
<p>Out[123]: array([1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2,... | 1 | 2016-09-14T10:35:35Z | 39,488,397 | <p>You are on Python 3, so <code>zip</code> is evaluated lazily. </p>
<pre><code>>>> np.array(zip(x1,x2))
array(<zip object at 0x7f76d0befe88>, dtype=object)
</code></pre>
<p>You need to iterate over it:</p>
<pre><code>>>> np.array(list(zip(x1, x2))).reshape(2, len(x1))
array([[1, 1, 2, 3, 3,... | 3 | 2016-09-14T10:40:52Z | [
"python",
"arrays",
"numpy",
"reshape"
] |
total size of new array must be unchanged | 39,488,282 | <p>I have two arrays x1 and x2, both are 1*14 arrays i am trying to zip them up and then perform reshape.</p>
<p>The code is as below ;</p>
<pre><code>x1
</code></pre>
<p>Out[122]: array([1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])</p>
<pre><code>x2
</code></pre>
<p>Out[123]: array([1, 3, 2, 2, 8, 6, 7, 6, 7, 1, 2,... | 1 | 2016-09-14T10:35:35Z | 39,488,686 | <p><code>np.array</code> isn't recognizing the generator created by <code>zip</code> as an iterable. It works fine if you force conversion to a list first:</p>
<pre><code>from array import array
import numpy as np
x1 = array('i', [1, 2, 3, 1, 5, 6, 5, 5, 6, 7, 8, 9, 7, 9])
x2 = array('i', [1, 3, 2, 2, 8, 6, 7, 6, 7, 1... | 1 | 2016-09-14T10:56:00Z | [
"python",
"arrays",
"numpy",
"reshape"
] |
Correct way to implement placeholder variables (PEP8) | 39,488,284 | <p>I run into the problem of needing placeholder variables a lot. I try to code according to PEP8, and always follow it, also i am using PyCharm which notifies me about mistakes. Currently i use <code>_</code> as i have seen this in a lot of online codes, but i guess it is wrong as i still got the warnings. What is the... | 0 | 2016-09-14T10:35:37Z | 39,488,361 | <p>Ignore the warnings if you know they are harmless. They are warnings, not errors or exceptions. If you know what you are doing, ignore or suppress the warnings!</p>
| 2 | 2016-09-14T10:38:59Z | [
"python",
"python-3.x",
"pep8"
] |
Python: Reproduce Splinter/ Selenium Behaviour for Testing a Website That Uses Javascript | 39,488,311 | <p>I have a bot which interacts with a website using Splinter and Selenium. The website uses Javascript and updates in real time. The bot works well 90% of the time, but due to random events it will sometimes raise an Exception. It is very hard for me to debug these events, by the time I am in the debugger the website ... | -2 | 2016-09-14T10:36:40Z | 39,672,863 | <p>Closest thing you can do is to take screen shots of web page on various events. You will have to use EventFiringWebDriver. Whichever even you want to take screen shot call <code>screen_shot</code> function there.</p>
<pre><code>from selenium.webdriver.support.events import EventFiringWebDriver
from selenium.webdriv... | 0 | 2016-09-24T05:26:06Z | [
"javascript",
"python",
"selenium",
"splinter"
] |
Why does Python's C3 MRO depend on a common base class? | 39,488,324 | <p>When I read about Python's C3 method resolution order, I often hear it reduced to "children come before parents, and the order of subclasses is respected". Yet that only seems to hold true if all the subclasses inherit from the same ancestor.</p>
<p>E.g.</p>
<pre><code>class X():
def FOO(self):
return ... | 2 | 2016-09-14T10:37:11Z | 39,488,453 | <p>All classes in Python 3 have a common base class, <code>object</code>. You can omit the class from the <code>class</code> definition, but it is there unless you already indirectly inherit from <code>object</code>. (In Python 2 you have to explicitly inherit from <code>object</code> to even have the use of <code>supe... | 2 | 2016-09-14T10:43:41Z | [
"python",
"multiple-inheritance",
"method-resolution-order"
] |
pandas read_sql with parameters and wildcard operator | 39,488,380 | <p>I am trying to retrieve data from sql through python with the code:</p>
<pre><code>query = ("SELECT stuff FROM TABLE WHERE name like %%(this_name)s%")
result = pd.read_sql(query,con=cnx,params={'this_name':some_name})
</code></pre>
<p>The code above works perfectly when I don't have to pass the wildcard operator %... | 1 | 2016-09-14T10:39:55Z | 39,490,030 | <p>Consider concatenating the wildcard operator, <code>%</code>, to passed in value:</p>
<pre><code>query = ("SELECT stuff FROM TABLE WHERE name LIKE %(this_name)s")
result = pd.read_sql(query,con=cnx, params={'this_name': '%'+ some_name +'%'})
</code></pre>
| 1 | 2016-09-14T12:06:38Z | [
"python",
"sql",
"pandas",
"wildcard"
] |
Create API key in AWS API Gateway from AWS Lambda using boto3 | 39,488,456 | <p>I am using an AWS Lambda function to create an API key using Boto3. </p>
<p>Testing locally with the following is successful:</p>
<pre><code>import boto3
client = boto3.client('apigateway')
response = client.create_api_key(
name='test_user_from_boto',
description='This is the description',
enabled=Tr... | 0 | 2016-09-14T10:44:00Z | 39,495,821 | <p>The difference here can be attributed to different versions of the AWS SDK in your Lambda environment vs your development environment.</p>
<p>In newer versions of the SDK, the API key value is omitted from certain responses as a security measure. You can retrieve the API Key value via a separate call to <a href="ht... | 1 | 2016-09-14T16:50:41Z | [
"python",
"amazon-web-services",
"aws-lambda",
"aws-api-gateway",
"boto3"
] |
unable to open excel document using Python through openpyxl | 39,488,501 | <p>I'm new to Python, so sorry if this is annoyingly simple. I'm trying to simply open an excel document using this,</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>impo... | 0 | 2016-09-14T10:46:15Z | 39,488,728 | <p>you incorrectly invoke the load_workbook function</p>
<p><code>wb = openpyxl.load_workbook('C:\Users\ my file location here.xlsx') #with my real location</code></p>
<p>you should use just load_workbook</p>
<p><code>wb = load_workbook('C:\Users\ my file location here.xlsx') #with my real location</code></p>
| -1 | 2016-09-14T10:57:59Z | [
"python",
"excel"
] |
unable to open excel document using Python through openpyxl | 39,488,501 | <p>I'm new to Python, so sorry if this is annoyingly simple. I'm trying to simply open an excel document using this,</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>impo... | 0 | 2016-09-14T10:46:15Z | 39,488,744 | <p>1) Try this first.</p>
<pre><code>import openpyxl
wb = openpyxl.load_workbook('C:\Users\ my file location here.xlsx')
type(wb)
</code></pre>
<p>2) else put your .py file in the same directory where .xlsx file is present and change code in .py as shown below.</p>
<pre><code>import openpyxl
wb = openpyxl.load_workb... | 0 | 2016-09-14T10:58:29Z | [
"python",
"excel"
] |
unable to open excel document using Python through openpyxl | 39,488,501 | <p>I'm new to Python, so sorry if this is annoyingly simple. I'm trying to simply open an excel document using this,</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>impo... | 0 | 2016-09-14T10:46:15Z | 39,489,719 | <p>Could there be an issue with how the modules are installed?</p>
<p>As this isn't working, I tried to use the xlrd module.</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"><... | 0 | 2016-09-14T11:50:15Z | [
"python",
"excel"
] |
unable to open excel document using Python through openpyxl | 39,488,501 | <p>I'm new to Python, so sorry if this is annoyingly simple. I'm trying to simply open an excel document using this,</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>impo... | 0 | 2016-09-14T10:46:15Z | 39,540,900 | <p>It sounds like you want to open the file <em>in Excel</em>. That is, you want to launch the Excel application, and have the file open in that application. OpenPyXL and xlrd are not designed to do this. In fact, they are specifically designed for working with the files when you can't or don't want to launch Excel. (F... | 0 | 2016-09-16T22:24:17Z | [
"python",
"excel"
] |
Use of timestamp or datetime object for colorcoding of a scatterplot? | 39,488,506 | <p>I do have a list of data: </p>
<pre><code>a = [[Timestamp('2015-01-01 15:00:00', tz=None), 53.0, 958.0],
[Timestamp('2015-01-01 16:00:00', tz=None), 0.0, 900.0],
[Timestamp('2015-01-02 11:00:00', tz=None), 543.0, 820.0], .....]
</code></pre>
<p>My goal is to plot the second element of each list entry vs.... | 0 | 2016-09-14T10:46:29Z | 39,490,991 | <pre><code>a = [[pd.Timestamp('2015-01-01 15:00:00', tz=None), 53.0, 958.0],
[pd.Timestamp('2015-01-01 16:00:00', tz=None), 0.0, 900.0],
[pd.Timestamp('2015-01-02 11:00:00', tz=None), 543.0, 820.0]]
df = pd.DataFrame(a).add_prefix('Col_')
df
</code></pre>
<p><a href="http://i.stack.imgur.com/Gw5X8.png" re... | 0 | 2016-09-14T12:54:42Z | [
"python",
"pandas",
"matplotlib"
] |
pip: How to deal with different python versions to install Flask? | 39,488,603 | <p>I have different versions of Python installed on my Ubuntu machine (2.7.11, 2.7.12, 3.5). I would like to install Flask on the 2.7.12 as it used by Apache. </p>
<p>I have three pip{version} in my PATH which are: pip, pip2, and pip2.7. How do I know which one is for which python version. </p>
<p>I have already read... | 0 | 2016-09-14T10:51:20Z | 39,488,693 | <p>You can find it out by trying to run this: <code>pip --version</code>. Output will be something like this: <code>pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)</code>. This way we can see that it is for <code>python2.7</code> in my case.</p>
| 0 | 2016-09-14T10:56:23Z | [
"python",
"python-2.7",
"pip"
] |
pip: How to deal with different python versions to install Flask? | 39,488,603 | <p>I have different versions of Python installed on my Ubuntu machine (2.7.11, 2.7.12, 3.5). I would like to install Flask on the 2.7.12 as it used by Apache. </p>
<p>I have three pip{version} in my PATH which are: pip, pip2, and pip2.7. How do I know which one is for which python version. </p>
<p>I have already read... | 0 | 2016-09-14T10:51:20Z | 39,488,765 | <p><a href="http://flask.pocoo.org/docs/0.11/installation/#virtualenv" rel="nofollow">You should always create virtualenvs for your projects</a>. You can create one like</p>
<pre><code>virtualenv -p <path/to/python2.7.12> <path/to/new/virtualenv/>
</code></pre>
<p>inside that virtualenv <code>pip</code> a... | 1 | 2016-09-14T10:59:33Z | [
"python",
"python-2.7",
"pip"
] |
why python's pickle is not serializing a method as default argument? | 39,488,675 | <p>I am trying to use pickle to transfer python objects over the wire between 2 servers. I created a simple class, that subclasses <code>dict</code> and I am trying to use pickle for the marshalling:</p>
<pre><code>def value_is_not_none(value):
return value is not None
class CustomDict(dict):
def __init__(sel... | 3 | 2016-09-14T10:55:40Z | 39,491,671 | <p><code>pickle</code> is loading your dictionary data <em>before</em> it has restored the attributes on your instance. As such the <code>self.cond</code> attribute is not yet set when <code>__setitem__</code> is called for the dictionary key-value pairs.</p>
<p>Note that <code>pickle</code> will never call <code>__in... | 2 | 2016-09-14T13:24:18Z | [
"python",
"dictionary",
"lambda",
"pickle"
] |
GtkToolButton are disabled by default in glade3 + pygtk | 39,488,717 | <p>I've created a simple app skeleton in python 2.7 using pyGtk and Glade (3.16.1) on Ubiuntu 14.04 LTS.
I've added a ToolBar and some buttons, but the gtkToolButton are always disabled. How can I enable them from Glade? </p>
<p><a href="http://i.stack.imgur.com/ABmjQ.png" rel="nofollow"><img src="http://i.stack.imgur... | 0 | 2016-09-14T10:57:29Z | 39,660,685 | <p>GtkToolbars are not very straightforward to use. You have to create a corresponding action. This is a simple example of how to use them:</p>
<p>The glade file:</p>
<pre><code><interface>
<requires lib="gtk+" version="3.16"/>
<object class="GtkWindow" id="window">
<property name="can_fo... | 0 | 2016-09-23T12:23:01Z | [
"python",
"toolbar",
"pygtk",
"gtk3",
"glade"
] |
Parent constructor called by default? | 39,488,875 | <p>I have the following example from python <code>page_object</code> docs:</p>
<pre><code> from page_objects import PageObject, PageElement
from selenium import webdriver
class LoginPage(PageObject):
username = PageElement(id_='username')
password = PageElement(name='password')
login = PageE... | 1 | 2016-09-14T11:05:27Z | 39,489,022 | <p>The <code>__init__</code> method is just a method and as such python performs the same kind of lookup for it as other methods. If class <code>B</code> does not define a method/attribute <code>x</code> then python looks up it's base class <code>A</code> and so on, until it either finds the attribute/method or fails.<... | 1 | 2016-09-14T11:14:12Z | [
"python",
"oop",
"selenium",
"selenium-webdriver"
] |
Django user_passes_test usage | 39,488,991 | <p>I have a function-based view in Django:</p>
<pre><code>@login_required
def bout_log_update(request, pk):
...
</code></pre>
<p>While it's protected from people who aren't logged in, I need to be able to restrict access to this view based on:
1. The user currently logged in
2. Which user created the object (referred... | 0 | 2016-09-14T11:12:03Z | 39,490,140 | <p>You can achieve this quite easily with a custom decorator <a href="https://docs.djangoproject.com/en/1.10/_modules/django/contrib/auth/decorators/#user_passes_test" rel="nofollow">based on <code>user_passes_test</code> source</a>:</p>
<pre><code>def my_user_passes_test(test_func, login_url=None, redirect_field_name... | 1 | 2016-09-14T12:11:29Z | [
"python",
"django"
] |
Cannot import from package in same namespace tree until pkg_resources has been imported | 39,489,027 | <p>I have a strange problem that I somehow cannot reproduce separately, yet it shows up in production code, and of course the production code cannot be shared publically.</p>
<p>I have two packages, for argument's sake <code>ns.server</code> and <code>ns.protobuf</code>, where the latter implements protobuf specific e... | 0 | 2016-09-14T11:14:34Z | 39,489,265 | <p>Ugh, second question I self-answer in as many days. I had a stale egg-info directory lying around in <code>lib/python2.7/site-packages</code>, from a previous install where I accidentally neglected to pass -e (development mode) to pip. Completely clearing everything and reinstalling fixed it.</p>
| 0 | 2016-09-14T11:26:16Z | [
"python",
"python-2.7",
"pkg-resources"
] |
Interpolating elements of a color matrix on the basis of some given reference elements | 39,489,089 | <p>This is more or less a follow up question to <a href="http://stackoverflow.com/questions/39485178/two-dimensional-color-ramp-256x256-matrix-interpolated-from-4-corner-colors?noredirect=1#comment66289716_39485178">Two dimensional color ramp (256x256 matrix) interpolated from 4 corner colors</a> that was profoundly an... | 5 | 2016-09-14T11:18:00Z | 39,506,280 | <p>First some questions to better clarify your problem:</p>
<ul>
<li>what kind of interpolation you want: linear/cubic/other ?</li>
<li>What are the points constrains? for example will there be alway just single region encapsulated by these control points or there could be also points inside? </li>
</ul>
<p>For the ... | 5 | 2016-09-15T08:22:20Z | [
"python",
"numpy",
"image-processing",
"matrix",
"scipy"
] |
Interpolating elements of a color matrix on the basis of some given reference elements | 39,489,089 | <p>This is more or less a follow up question to <a href="http://stackoverflow.com/questions/39485178/two-dimensional-color-ramp-256x256-matrix-interpolated-from-4-corner-colors?noredirect=1#comment66289716_39485178">Two dimensional color ramp (256x256 matrix) interpolated from 4 corner colors</a> that was profoundly an... | 5 | 2016-09-14T11:18:00Z | 39,545,478 | <p>I'm here again (a bit late, sorry,I just found the question) with a fairly short solution using <code>griddata</code> from <code>scipy.interpolate</code>. That function is meant to do precisely what you want : interpolate values on a grid from just a few points. The issues being the following : with that you won't ... | 1 | 2016-09-17T10:02:07Z | [
"python",
"numpy",
"image-processing",
"matrix",
"scipy"
] |
gnuplot: the "sum [<var> = <start>:<end>] <expression>" strategy | 39,489,107 | <p>In the following script, I would like to plot <code>y(x)</code>:</p>
<p><a href="http://i.stack.imgur.com/LrUF9.png" rel="nofollow"><img src="http://i.stack.imgur.com/LrUF9.png" alt="enter image description here"></a></p>
<p>and this function <code>u(x)</code>:</p>
<p><a href="http://i.stack.imgur.com/KiqoI.png" ... | 0 | 2016-09-14T11:18:54Z | 39,489,728 | <p>In fact, what is actually plotted as <code>u(x)</code> is just <code>6*y(x)</code>, you can check that if you replace in your script the line</p>
<pre><code>plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"
</code></pre>
<p>with</p>
<pre><code>plot 6*y(x) with line lt -1 lw 1 lc 1 title "y(x)"
</code></pre>
<p>th... | 1 | 2016-09-14T11:50:36Z | [
"python",
"sum",
"gnuplot"
] |
How can I check how much of a path exists in python | 39,489,111 | <p>Let's say on my filesystem the following directory exists:</p>
<pre><code>/foo/bar/
</code></pre>
<p>In my python code I have the following path:</p>
<pre><code>/foo/bar/baz/quix/
</code></pre>
<p>How can I tell that only the <code>/foo/bar/</code> part of the path exists? </p>
<p>I can walk the path recursivel... | 2 | 2016-09-14T11:19:10Z | 39,489,433 | <p>I don't actually get your requirements as whether you want every path to be checked or upto some specific level.But for simple sanity checks you can just iterate through the full path create the paths and check the sanity.</p>
<pre><code>for i in filter(lambda s: s, sample_path.split('/')):
_path = os.path.join(_... | 1 | 2016-09-14T11:35:44Z | [
"python",
"path",
"directory"
] |
How can I check how much of a path exists in python | 39,489,111 | <p>Let's say on my filesystem the following directory exists:</p>
<pre><code>/foo/bar/
</code></pre>
<p>In my python code I have the following path:</p>
<pre><code>/foo/bar/baz/quix/
</code></pre>
<p>How can I tell that only the <code>/foo/bar/</code> part of the path exists? </p>
<p>I can walk the path recursivel... | 2 | 2016-09-14T11:19:10Z | 39,489,473 | <p>Well, I think the only way is to work recursively... Though, I would work up the directory tree. The code isn't too hard to implement:</p>
<pre><code>import os
def doesItExist(directory):
if not os.path.exists(directory):
doesItExist(os.path.dirname(directory)
else:
print "Found: " + direct... | 0 | 2016-09-14T11:37:52Z | [
"python",
"path",
"directory"
] |
How can I check how much of a path exists in python | 39,489,111 | <p>Let's say on my filesystem the following directory exists:</p>
<pre><code>/foo/bar/
</code></pre>
<p>In my python code I have the following path:</p>
<pre><code>/foo/bar/baz/quix/
</code></pre>
<p>How can I tell that only the <code>/foo/bar/</code> part of the path exists? </p>
<p>I can walk the path recursivel... | 2 | 2016-09-14T11:19:10Z | 39,489,505 | <p>No easy function in the standard lib but not really a difficult one to make yourself.</p>
<p>Here's a function that takes a path and returns only the path that does exist.</p>
<pre><code>In [129]: def exists(path):
...: if os.path.exists(path): return path
...: return exists(os.path.split(path)[0... | 4 | 2016-09-14T11:39:22Z | [
"python",
"path",
"directory"
] |
How can I check how much of a path exists in python | 39,489,111 | <p>Let's say on my filesystem the following directory exists:</p>
<pre><code>/foo/bar/
</code></pre>
<p>In my python code I have the following path:</p>
<pre><code>/foo/bar/baz/quix/
</code></pre>
<p>How can I tell that only the <code>/foo/bar/</code> part of the path exists? </p>
<p>I can walk the path recursivel... | 2 | 2016-09-14T11:19:10Z | 39,489,512 | <p>I think a simple <code>while</code> loop with <code>os.path.dirname()</code> will suffice the requirement</p>
<pre><code>path_string = '/home/moin/Desktop/my/dummy/path'
while path_string:
if not os.path.exists(path_string):
path_string = os.path.dirname(path_string)
else:
break
# path_strin... | 1 | 2016-09-14T11:39:50Z | [
"python",
"path",
"directory"
] |
Issue with pie chart matplotlib - startangle / len() | 39,489,150 | <p>I have a script which creates a pie chart based on CSV files. My problem started when I was reading a CSV that had only one row (e.g. <code>percent = [100]</code>). Is there any limitation of using a pie chart, where is will not show 100% for only one item? It seems that the error is related to either the <code>star... | -2 | 2016-09-14T11:21:01Z | 39,490,979 | <p>Change the <code>explode</code> parameter to a <code>list</code>:</p>
<pre><code>percent = [100]
explode = [0]
plt.pie(percent, explode=explode, ...)
</code></pre>
<p>If you have more values, you can use a <code>tuple</code>, but with one value <code>(int)</code> is seen as an integer:</p>
<pre><code>>>>... | 1 | 2016-09-14T12:54:16Z | [
"python",
"matplotlib",
"charts"
] |
How to scrape real time streaming data with Python? | 39,489,168 | <p>I was trying to scrape the number of flights for this webpage <a href="https://www.flightradar24.com/56.16,-49.51" rel="nofollow">https://www.flightradar24.com/56.16,-49.51</a></p>
<p>The number is highlighted in the picture below:
<a href="http://i.stack.imgur.com/Zvsmf.png" rel="nofollow"><img src="http://i.stack... | 0 | 2016-09-14T11:22:10Z | 39,489,328 | <p>The problem with your approach is that the page first loads a view, then performs regular requests to refresh the page. If you look at the network tab in the developer console in Chrome (for example), you'll see the requests to <a href="https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77... | 5 | 2016-09-14T11:30:16Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
How to scrape real time streaming data with Python? | 39,489,168 | <p>I was trying to scrape the number of flights for this webpage <a href="https://www.flightradar24.com/56.16,-49.51" rel="nofollow">https://www.flightradar24.com/56.16,-49.51</a></p>
<p>The number is highlighted in the picture below:
<a href="http://i.stack.imgur.com/Zvsmf.png" rel="nofollow"><img src="http://i.stack... | 0 | 2016-09-14T11:22:10Z | 39,489,711 | <p>So based on what @Andre has found out, I wrote this code:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import time
def get_count():
url = "https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77,-47.71&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&... | 2 | 2016-09-14T11:49:53Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Text Classification for multiple label | 39,489,197 | <p>I doing Text Classification by Convolution Neural Network. I used health documents (ICD-9-CM code) for my project and I used the same model as <a href="http://www.wildml.com/2015/12/implementing-a-cnn-for-text-classification-in-tensorflow/" rel="nofollow">dennybritz</a> used but my data has 36 labels. I used one_hot... | 0 | 2016-09-14T11:23:23Z | 39,520,251 | <p>The label encoding seems correct. If you have multiple correct labels, <code>[1 0 1 0 ... 1]</code> looks totally fine. The loss function used in Denny's <a href="http://www.wildml.com/2015/12/implementing-a-cnn-for-text-classification-in-tensorflow/" rel="nofollow">post</a> is <code>tf.nn.softmax_cross_entropy_with... | 1 | 2016-09-15T20:57:47Z | [
"python",
"machine-learning",
"tensorflow",
"text-classification"
] |
How to debug / correctly setup git-multimail | 39,489,274 | <p>I would like to use <a href="https://github.com/git-multimail/git-multimail" rel="nofollow">git-multimail</a> as post receive hook in one of my git repositories (no gitolite used). Unfortunately, I cannot get it work, and I have hardly any experience using Python.</p>
<h2>What I did so far:</h2>
<ol>
<li>I added t... | 2 | 2016-09-14T11:26:46Z | 39,494,389 | <p>OK guys, the error was probably as little as it could be. I did just one very little mistake in the post receive hook file: The <code>sys.exit(1)</code> command is not indented.</p>
<p>So, the WRONG version from my question:</p>
<pre><code>try:
environment = git_multimail.GenericEnvironment(config=config)
exce... | 0 | 2016-09-14T15:31:23Z | [
"python",
"git",
"githooks",
"post-receive-email"
] |
How to validate if a user input is both a float and with a given range in Python? | 39,489,400 | <p>I'm trying to validate a user input to check if it is both a number (float) and within a range (0-1). I have used Try except to check if the input is a float as below:</p>
<pre><code>while True:
try:
rate=input(": ")
rate=float(rate)
break
except ValueError:
print("That was ... | 0 | 2016-09-14T11:34:07Z | 39,489,500 | <p>You can consider using <code>try-except-else</code> in the following manner:</p>
<pre><code>min_val = 1
max_val = 10
while True:
rate = input(": ")
try:
rate = float(rate)
except ValueError:
print("That was not a valid numerical value, please try again")
else:
if min_val <... | 3 | 2016-09-14T11:39:08Z | [
"python",
"python-3.x"
] |
Access m2m relationships on the save method of a newly created instance | 39,489,539 | <p>I'd like to send emails (only) when Order instances are created. In the email template, I need to access the m2m relationships. Unfortunatly, its seems like the m2m relations are ont yet populated, and the itemmembership_set.all() method returns an empty list.</p>
<p>Here is my code:</p>
<pre><code>class Item(mode... | 0 | 2016-09-14T11:41:01Z | 39,503,978 | <p>Some of the comments suggested using signals. While you can use signals, specifically the <code>m2m_changed</code> signal, this will always fire whenever you modify the m2m fields. As far as I know, there is no way for the sender model (in your sample, that is <code>ItemMembership</code>) to know if the associated <... | 1 | 2016-09-15T05:55:18Z | [
"python",
"django",
"django-models",
"m2m"
] |
Python Selenium get image name from website | 39,489,612 | <p>I am trying to scrape a website for my project, but i'm having trouble with scrapping image names via Selenium from this <a href="http://comparefirst.sg/wap/productsListEvent.action?prodGroup=whole&pageAction=prodlisting" rel="nofollow">website</a></p>
<p><a href="http://i.stack.imgur.com/CR0l6.png" rel="nofoll... | 1 | 2016-09-14T11:45:17Z | 39,489,693 | <p>Why not use <a href="http://selenium-python.readthedocs.io/locating-elements.html" rel="nofollow">find_element_by_class_name</a> ?</p>
<pre><code>feature_icon = result.find_element_by_class_name("prod-feature-icon")
</code></pre>
<p>However it's worth noting that the object with this class name is actually a <code... | 2 | 2016-09-14T11:49:06Z | [
"python",
"selenium"
] |
Encoding / formatting issues with python kafka library | 39,489,649 | <p>I've been trying to use the <a href="http://kafka-python.readthedocs.io/en/master/index.html" rel="nofollow">python kafka</a> library for a bit now and can't get a producer to work.</p>
<p>After a bit of research I've found out that kafka sends (and I'm guessing expects as well) an additional 5 byte header (one 0 b... | 1 | 2016-09-14T11:46:52Z | 39,491,227 | <p>Since you are reading with BinaryDecoder and DatumReader, if you send the data in the reverse(using DatumWriter with the BinaryEncoder as encoder), your messages will be fine, I suppose. </p>
<p>Something like this:</p>
<p><strong>Producer</strong></p>
<pre><code>from kafka import KafkaProducer
import avro.schema... | 0 | 2016-09-14T13:05:22Z | [
"python",
"apache-kafka",
"python-kafka"
] |
Encoding / formatting issues with python kafka library | 39,489,649 | <p>I've been trying to use the <a href="http://kafka-python.readthedocs.io/en/master/index.html" rel="nofollow">python kafka</a> library for a bit now and can't get a producer to work.</p>
<p>After a bit of research I've found out that kafka sends (and I'm guessing expects as well) an additional 5 byte header (one 0 b... | 1 | 2016-09-14T11:46:52Z | 39,536,659 | <p>I'm able to have my python producer sending messages to Kafka-Connect with Schema-Registry:</p>
<pre><code>...
import avro.datafile
import avro.io
import avro.schema
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='kafka:9092')
with open('schema.avsc') as f:
schema = avro.schema.Pars... | 0 | 2016-09-16T16:57:58Z | [
"python",
"apache-kafka",
"python-kafka"
] |
Why won't the list delete function delete spaces? | 39,489,793 | <pre><code>string = "hello world i'm a new program"
words_length = []
length = 21
</code></pre>
<p>I'm using <code>re.split</code> to produce a list of words and spaces:</p>
<pre><code>words = re.split('\w', string)
</code></pre>
<p>so: </p>
<pre><code>words = ['hello', ' ', 'world', ' ', 'i', "'", 'm', ' ', 'a', '... | -1 | 2016-09-14T11:53:19Z | 39,489,912 | <p>You are <em>skipping indices</em> because you are deleting characters from your list.</p>
<p>Each time you delete a character, everything to the <em>right</em> of that character shifts up one step to the left, and their index goes down by one. But your <code>x</code> index still goes up by one so now you are refere... | 3 | 2016-09-14T11:59:31Z | [
"python",
"list",
"python-3.x",
"for-loop"
] |
Counting Characters in a varible python | 39,489,897 | <p>i am trying to create a program to print a line of text a certain amount of times, i want to limit the amount of letters in the first text entry and i cant figure out how.</p>
<p>code: </p>
<pre><code># Hello World Script 2.0
import random
**------------------------------------------------
#i want to limit the am... | 0 | 2016-09-14T11:58:34Z | 39,490,015 | <p>You could check the length of the string with the function len().</p>
<pre><code>import random
**------------------------------------------------
#i want to limit the amount of characters, how?
------------------------------------------------**
print("What do you want to be printed?(Max 20 Characters)")
var0 = inpu... | 0 | 2016-09-14T12:05:32Z | [
"python",
"variables"
] |
How to find column values which contains unique value in another column from same dataframe? | 39,489,909 | <p>I have a dataframe: </p>
<pre><code> Id name value
0 1 aaa x
1 2 aaa y
2 3 aaa z
3 4 ddd t
4 5 ddd t
5 6 fff j
6 7 ggg m
7 8 ggg n
</code></pre>
<p>I want to find only those rows whose names are duplicate and for these duplicate rows the values are different.</p>
<p><strong>Expe... | 1 | 2016-09-14T11:59:25Z | 39,490,027 | <p>This line of code will count the number of values by name:</p>
<pre><code>df.groupby('name')['value'].transform(pd.Series.nunique)
Out[8]:
0 3
1 3
2 3
3 1
4 1
5 1
6 2
7 2
</code></pre>
<p>Note that I use <code>.transform(pd.Series.nunique)</code> rather than simply <code>.nunique()</code> ... | 1 | 2016-09-14T12:06:30Z | [
"python",
"pandas",
"dataframe"
] |
How to connect Android app to python-socketio backend? | 39,489,919 | <p>I am currently running a Python SocketIO server that connects perfectly to my JavaScript Client. I am using the <a href="http://socket.io/blog/native-socket-io-and-android/" rel="nofollow">socketio android example chat app</a> to write the Android code, it worked perfectly with a NodeJS server but when I change over... | 1 | 2016-09-14T11:59:44Z | 39,489,994 | <p>I downloaded the SocketIO python library from <a href="https://github.com/miguelgrinberg/python-socketio" rel="nofollow">Github</a></p>
<p>I modified the example code like this:</p>
<pre><code>import socketio
import eventlet
import eventlet.wsgi
from flask import Flask, render_template
sio = socketio.Server()
app... | 1 | 2016-09-14T12:04:20Z | [
"android",
"python",
"flask",
"socket.io"
] |
How to break conversation data into pairs of (Context , Response) | 39,489,933 | <p>I'm using Gensim Doc2Vec model, trying to cluster portions of a customer support conversations. My goal is to give the support team an auto response suggestions.</p>
<p><strong>Figure 1:</strong> shows a sample conversations where the user question is answered in the next conversation line, making it easy to extrac... | 14 | 2016-09-14T12:00:31Z | 39,599,388 | <p>To train a model I would start by concatenating consecutive sequences of messages. What I would do is, using the timestamps, concatenate the messages without any message in between from the other entity.</p>
<p>For instance:</p>
<pre><code>Hello
I have a problem
I cannot install software X
... | 5 | 2016-09-20T16:30:32Z | [
"python",
"text-mining",
"doc2vec",
"gensym"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.