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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Error while plotting contour in Matplotlib | 38,261,513 | <p>I have <code>X coordinates</code> ,<code>Y coordinates</code> and <code>Zcoordinates</code>, each stored in an array with <code>n x 1 . (n rows,1 column)</code> .The contour plot in <code>Matplotlib</code> allows to plot only if <code>"*X and Y must both be 2-D with the same shape as Z, or they must both be 1-D su... | 0 | 2016-07-08T07:50:05Z | 38,261,736 | <p>The way I know is to evaluate z over a grid, composed of x and y:</p>
<pre><code>X, Y = np.meshgrid(x, y)
plt.plot(X, Y, z)
z = <evaluate over X, Y>
plt.contour(X, Y, z)
plt.show()
</code></pre>
<p><a href="http://matplotlib.org/examples/pylab_examples/contour_demo.html" rel="nofollow">This</a> explains it a... | 0 | 2016-07-08T08:02:24Z | [
"python",
"python-2.7",
"numpy",
"matplotlib",
"plot"
] |
Error while plotting contour in Matplotlib | 38,261,513 | <p>I have <code>X coordinates</code> ,<code>Y coordinates</code> and <code>Zcoordinates</code>, each stored in an array with <code>n x 1 . (n rows,1 column)</code> .The contour plot in <code>Matplotlib</code> allows to plot only if <code>"*X and Y must both be 2-D with the same shape as Z, or they must both be 1-D su... | 0 | 2016-07-08T07:50:05Z | 38,261,986 | <p>Contour expects gridded data. This matplotlib tutorial explains it perfectly:
<a href="http://matplotlib.org/examples/pylab_examples/griddata_demo.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/griddata_demo.html</a>.
Also see <a href="http://stackoverflow.com/questions/18764814/make-contour-of-s... | 0 | 2016-07-08T08:16:54Z | [
"python",
"python-2.7",
"numpy",
"matplotlib",
"plot"
] |
How to show Qt.Tool window with minimize/maximize windows controls? | 38,261,526 | <p>I have...</p>
<pre><code>class ToolWindow(QtWidgets.QMainWindow):
"""Generic window to be used as non-modal tool
Usage:
tool_win = ToolWindow()
layout = QtWidgets.QHBoxLayout()
button = QtWidgets.QPushButton('hello')
layout.addWidget(button)
tool_win.setup(layout)
... | 1 | 2016-07-08T07:51:11Z | 38,275,284 | <p>You should be able to just use the <code>QMainWindow</code> class without any flags. As long as the <em>tool window</em> is a child of the primary application window, it will stay on top of it (but not windows from other applications, like it would if you set the "Window Stays On Top" flag).</p>
<p>You'll need to ... | 0 | 2016-07-08T20:56:03Z | [
"python",
"qt",
"pyqt",
"pyside",
"pyqt5"
] |
Why for numpy.sum buiding new generator is faster than using just range? | 38,261,534 | <p>This surprises me a bit. I've been testing performances.</p>
<pre><code>In [1]: import numpy as np
In [2]: %timeit a = np.sum(range(100000))
Out[2]: 100 loops, best of 3: 16.7 ms per loop
In [3]: %timeit a = np.sum([range(100000)])
Out[3]: 100 loops, best of 3: 16.7 ms per loop
In [4]: %timeit a = np.sum([i for ... | 0 | 2016-07-08T07:51:30Z | 38,261,708 | <p>Running the same code, I get these results (Python 3.5.1):</p>
<pre><code>%timeit a = sum(range(100000))
100 loops, best of 3: 3.05 ms per loop
%timeit a = sum([range(100000)])
>>> TypeError: unsupported operand type(s) for +: 'int' and 'range'
%timeit a = sum([i for i in range(100000)])
100 loops, best ... | 2 | 2016-07-08T08:00:55Z | [
"python",
"python-3.x",
"numpy"
] |
Inaccurate search result from Google place API (Geocoding) | 38,262,099 | <p>i am trying to geocode some addresses in the Philippines but when I do my search through the Google APIs, I only get very inaccurate results (10kms away from the point I am looking for while maps.google.com provides much better results with approximately few hundred meters error).</p>
<p>After reading other posts h... | 0 | 2016-07-08T08:23:56Z | 38,262,273 | <p>Have you tried to use web service api? If the web service api it's more precise you can use a json-parser in your application.</p>
<p><a href="https://developers.google.com/places/web-service/search" rel="nofollow">https://developers.google.com/places/web-service/search</a></p>
| 0 | 2016-07-08T08:34:57Z | [
"python",
"google-maps",
"google-maps-api-3",
"google-places-api",
"google-geocoding-api"
] |
Inaccurate search result from Google place API (Geocoding) | 38,262,099 | <p>i am trying to geocode some addresses in the Philippines but when I do my search through the Google APIs, I only get very inaccurate results (10kms away from the point I am looking for while maps.google.com provides much better results with approximately few hundred meters error).</p>
<p>After reading other posts h... | 0 | 2016-07-08T08:23:56Z | 39,166,842 | <p>Looks like you're using <a href="https://developers.google.com/places/web-service/search#PlaceSearchRequests" rel="nofollow">Nearby Search</a> when you should be using <a href="https://developers.google.com/places/web-service/search#TextSearchRequests" rel="nofollow">Text Search</a>. I'm linking the Places API web s... | 0 | 2016-08-26T12:53:46Z | [
"python",
"google-maps",
"google-maps-api-3",
"google-places-api",
"google-geocoding-api"
] |
Probability of next day being specific values using Python Pandas | 38,262,132 | <p>Using the following dataframe as an example, which specifies different directions for a stock market day. What are the most Pythonic approaches for capturing stats showing what is the most likely day type that will follow each individual day?</p>
<p>So in this example df we have simple day types listed as 'Down','U... | 1 | 2016-07-08T08:26:23Z | 38,263,224 | <p>Yes it is possible. First you can create a second column which contains for each day what happens on the next day (and off course you drop the last row):</p>
<pre><code>rng['day2'] = rng['day_direction'].shift(-1)
rng = rng.iloc[:-1]
day_direction day2
2014-04-02 Down Down
2014-04-03 Dow... | 1 | 2016-07-08T09:26:29Z | [
"python",
"pandas"
] |
Efficient way to aggregate on dates in pandas groupby | 38,262,185 | <p>When performing a groupby on dates (as <code>object</code>), I realized it was way less efficient than on <code>int</code>. Here is an example:</p>
<pre><code>df = pd.DataFrame({'id1':[1,1,1,1,2,2,2,3,3,3],'id2':[10,20,30,10,20,30,10,20,30,10],'value':[123,156,178,19,354,26,84,56,984,12],
'date':... | 2 | 2016-07-08T08:29:46Z | 38,262,327 | <p>Changing the dtype to <code>datetime</code> gives comparable perf for me:</p>
<pre><code>In [86]:
df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d')
df
Out[86]:
date id1 id2 value
0 2015-01-12 1 10 123
1 2014-09-27 1 20 156
2 2014-10-14 1 30 178
3 2010-11-26 1 10 ... | 1 | 2016-07-08T08:37:49Z | [
"python",
"pandas",
"aggregate"
] |
What's wrong with this implementation of a heap? | 38,262,188 | <p>my insert method is not correct and I don't know why.
my min method errors with not "builtin_function or object not subscriptable" </p>
<p>I think that my conceptual understanding of heaps is OK. But its fracking frustrating when actually writing it down :(</p>
<pre><code>class Heap:
def __init__(self):
... | -4 | 2016-07-08T08:30:07Z | 38,262,381 | <p>The line <code>self.array.index(value)</code> in <code>insert</code> is dangerous. What happens if you do an insert of a value that already exists in the heap? You should use <code>len(self.array)</code> instead (you're appending to the array, so it'll be the last element).</p>
<p>Similarly, in <code>min</code>, yo... | 0 | 2016-07-08T08:41:08Z | [
"python",
"heap"
] |
Exit gracefully at EOF | 38,262,230 | <p>I am trying to parse a file, in which there is a part always present, and the past part is optional. </p>
<pre><code>for line in finp:
# This part is always present
for _ in range(int(ldata[2])):
sdata = finp.readline()
tdos.write(sdata)
#This part may or may not be present
for i i... | 1 | 2016-07-08T08:32:34Z | 38,262,263 | <p>Give <code>next()</code> a default to return:</p>
<pre><code>next(finp, None)
</code></pre>
<p>When given a second argument, <code>next()</code> will <em>catch</em> a <code>StopIteration</code> exception and return that second argument instead.</p>
<p>The alternative is to catch the <code>StopIteration</code> you... | 4 | 2016-07-08T08:34:14Z | [
"python",
"eof"
] |
get() for default values in Pandas Series, using position | 38,262,232 | <p>Is there a way in Pandas to get a default value, when accessing a row by position? I am aware of the <code>.get()</code> function, but that works when searching by index.</p>
<p>Below is what I want to do. The DataFrame:</p>
<pre><code>In [24]: df
Out[24]:
col1
idx
20 A
21 B
22 C
23 D
24 E
... | 0 | 2016-07-08T08:32:44Z | 38,262,623 | <p>Would something like this be considered cleaner:</p>
<pre><code>df['new_index'] = np.arange(df.shape[0])
df = df.set_index('new_index')
df['col1'].get(2, 'the_default_value')
</code></pre>
<p>If the original index is required, then, it may be useful to use multi-index</p>
<pre><code>df['new_index'] = np.arange(d... | 0 | 2016-07-08T08:54:34Z | [
"python",
"pandas"
] |
get() for default values in Pandas Series, using position | 38,262,232 | <p>Is there a way in Pandas to get a default value, when accessing a row by position? I am aware of the <code>.get()</code> function, but that works when searching by index.</p>
<p>Below is what I want to do. The DataFrame:</p>
<pre><code>In [24]: df
Out[24]:
col1
idx
20 A
21 B
22 C
23 D
24 E
... | 0 | 2016-07-08T08:32:44Z | 38,274,618 | <p>Ok, I got another answer:</p>
<pre><code>n = 2
df['col1'].get(df.index[n] if n < df.shape[0] else None, 'hi')
</code></pre>
<p>So, use get with positional values into the index...</p>
| 0 | 2016-07-08T20:07:10Z | [
"python",
"pandas"
] |
How to remove error in the following code? | 38,262,466 | <pre><code>n=int(raw_input())
w=set(map(int,raw_input().split()))
N=int(raw_input())
L=list()
for i in range(N):
w=raw_input()
L.append(w)
for i in range(N):
x=[]
x=L[i].split()
#print x[0]
if (x[0]=='pop'):
w.pop()
elif (x[0]=='remove'):
w.remove(int(x[1]))
elif (x[0]==... | -2 | 2016-07-08T08:45:38Z | 38,262,532 | <p>Replace the code:</p>
<pre><code>for i in range(N):
w=raw_input()
L.append(w)
</code></pre>
<p>which rebinds the name "w" to a string, with this:</p>
<pre><code>for i in range(N):
z=raw_input()
L.append(z)
</code></pre>
<p>which leaves the name "w" bound to a set.</p>
| 4 | 2016-07-08T08:49:46Z | [
"python",
"python-2.7",
"set"
] |
Find the points with the steepest slope python | 38,262,544 | <p>I have a list of float points such as <code>[x1,x2,x3,x4,....xn]</code> that are plotted as a line graph. I would like to find the set of points where the slope is the steepest. </p>
<p>Right now, Im calculating the difference between a set of points in a loop and using the <code>max()</code> function to determine ... | 0 | 2016-07-08T08:50:03Z | 38,262,884 | <p><code>Numpy</code> has a number of tools for working with arrays. For example, you could:</p>
<pre><code>import numpy as np
xx = np.array([x1, x2, x3, x4, ...]) # your list of values goes in there
print(np.argmax(xx[:-1] - xx[1:])) # for all python versions
</code></pre>
| 3 | 2016-07-08T09:08:58Z | [
"python"
] |
Find the points with the steepest slope python | 38,262,544 | <p>I have a list of float points such as <code>[x1,x2,x3,x4,....xn]</code> that are plotted as a line graph. I would like to find the set of points where the slope is the steepest. </p>
<p>Right now, Im calculating the difference between a set of points in a loop and using the <code>max()</code> function to determine ... | 0 | 2016-07-08T08:50:03Z | 38,262,907 | <p>Assuming <code>points</code> is the list of your values, you can calculate the differences in a single line using:</p>
<pre><code>max_slope = max([x - z for x, z in zip(points[:-1], points[1:])])
</code></pre>
<p>But what you gain in compactness, you probably lose in readability.</p>
<p>What happens in this list ... | 3 | 2016-07-08T09:10:19Z | [
"python"
] |
List comprehensions | 38,262,591 | <p>I have a <code>for</code> loop for outputting values into a list. </p>
<p>This is my output:</p>
<pre><code>[[23, 34, 34] [34,21,34,56] [21,3,5,67]]
</code></pre>
<p>Below is my code that works for the above output: </p>
<pre><code>y_train = ([[word2index[w] for w in sent[1:]] for sent in tokenized_sentences]).
... | -4 | 2016-07-08T08:52:51Z | 38,265,244 | <pre><code>for x in y_train:
x.append(element)
</code></pre>
<p>example:</p>
<pre><code>>>> listOfLists = [[1,2], [2,3], [4,5]]
>>> for x in listOfLists:
... x.append(2)
>>> listOfLists
[[1, 2, 2], [2, 3, 2], [4, 5, 2]]
</code></pre>
| -1 | 2016-07-08T11:11:33Z | [
"python"
] |
How to save output of elif to a csv file in python? | 38,262,637 | <pre><code>import csv
with open("input.csv") as f:
d1 = [row[0] for row in csv.reader(f)]
for x in d1:
if 0<=int(x)<30:
print("0<=x<30".format(x))
elif 40<=int(x)<120:
print("40<=x<120")
</code></pre>
<p>My code is shown above, and I am trying to save the output in a... | -2 | 2016-07-08T08:55:28Z | 38,262,755 | <p>You just reopen with csv.writer like so:</p>
<pre><code>d2 = csv.writer(f)
d2.writerow(x)
</code></pre>
<p>and read the documentation linked by @Eduard Daduya !!!!!!</p>
| 1 | 2016-07-08T09:01:30Z | [
"python"
] |
How to save output of elif to a csv file in python? | 38,262,637 | <pre><code>import csv
with open("input.csv") as f:
d1 = [row[0] for row in csv.reader(f)]
for x in d1:
if 0<=int(x)<30:
print("0<=x<30".format(x))
elif 40<=int(x)<120:
print("40<=x<120")
</code></pre>
<p>My code is shown above, and I am trying to save the output in a... | -2 | 2016-07-08T08:55:28Z | 38,264,001 | <p>Just add <code>open('output.csv', 'w').write("40<=%s<120"%(x))</code> after your print statement in the <code>elif</code> section.</p>
| 0 | 2016-07-08T10:06:42Z | [
"python"
] |
Error on Python serial import | 38,262,930 | <p>When I try to import the serial I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "C:\Documents and Settings\eduardo.pereira\workspace\thgspeak\tst.py", line 7, in <module>
import serial
File "C:\Python27\lib\site-packages\serial\__init__.py", line 27, in <module>... | 2 | 2016-07-08T09:11:15Z | 38,263,083 | <p>The version of pySerial that you're using is trying to call a <a href="https://github.com/pyserial/pyserial/commit/5a39b8897bbadb4b4e6da38a0cb557522bac3e1a" rel="nofollow">function</a> that's only available in Windows Vista, whereas you're running Windows XP.</p>
<p>It might be worth experimenting with using an old... | 3 | 2016-07-08T09:18:50Z | [
"python",
"pyserial"
] |
Error on Python serial import | 38,262,930 | <p>When I try to import the serial I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "C:\Documents and Settings\eduardo.pereira\workspace\thgspeak\tst.py", line 7, in <module>
import serial
File "C:\Python27\lib\site-packages\serial\__init__.py", line 27, in <module>... | 2 | 2016-07-08T09:11:15Z | 39,675,704 | <p>Older versions seem unavailable. But, this worked for me (assuming nanpy version 3.1.1):</p>
<ol>
<li>open file \lib\site-packages\serial\serialwin32.py</li>
<li>delete methods <code>_cancel_overlapped_io()</code>, <code>cancel_read()</code>, <code>cancel_write()</code> in lines 436-455 nearly at the botton of the ... | 2 | 2016-09-24T11:16:02Z | [
"python",
"pyserial"
] |
Adding django action to installed app | 38,262,939 | <p>Is there any nice way add custom action to installed app admin? I don't want to subclass admin form. Also i don't want to modify original app code. Maybe contributing to class would work? Is it good in this case?</p>
| -3 | 2016-07-08T09:11:44Z | 38,263,072 | <p>It is easy to add custom admin actions, just dealing update with queryset like so: </p>
<pre><code>class CustomerAdmin(admin.ModelAdmin):
list_display = ['name', 'age', 'status']
actions = ['change_name_action']
def change_name_action(self, request, queryset):
queryset.update(status='gold')
... | 1 | 2016-07-08T09:18:05Z | [
"python",
"django"
] |
Adding django action to installed app | 38,262,939 | <p>Is there any nice way add custom action to installed app admin? I don't want to subclass admin form. Also i don't want to modify original app code. Maybe contributing to class would work? Is it good in this case?</p>
| -3 | 2016-07-08T09:11:44Z | 38,263,998 | <p>Solved, but not sure if it's proper way. </p>
<pre><code>def send_newsletter(modeladmin, request, queryset):
#do stuff
from djangocms_blog.admin import PostAdmin
setattr(PostAdmin, 'actions', [send_newsletter])
</code></pre>
| 0 | 2016-07-08T10:06:29Z | [
"python",
"django"
] |
sentiwordnet scoring with python | 38,263,039 | <p>I have been working on a research in relation with twitter sentiment analysis. I have a little knowledge on how to code on Python. Since my research is related with coding, I have done some research on how to analyze sentiment using Python, and the below is how far I have come to:
1.Tokenization of tweets
2. POS tag... | 0 | 2016-07-08T09:16:53Z | 38,263,475 | <p>It's a little unclear as to what exactly your question is. Do you need a guide to using Sentiwordnet? If so check out this link,</p>
<p><a href="http://www.nltk.org/howto/sentiwordnet.html" rel="nofollow">http://www.nltk.org/howto/sentiwordnet.html</a></p>
<p>Since you've already tokenized and POS tagged the words... | 0 | 2016-07-08T09:40:21Z | [
"python",
"nltk",
"senti-wordnet"
] |
sentiwordnet scoring with python | 38,263,039 | <p>I have been working on a research in relation with twitter sentiment analysis. I have a little knowledge on how to code on Python. Since my research is related with coding, I have done some research on how to analyze sentiment using Python, and the below is how far I have come to:
1.Tokenization of tweets
2. POS tag... | 0 | 2016-07-08T09:16:53Z | 38,263,519 | <p>For Positive and Negative sentiments, first you need to give training and have to train the model. for training model you can use SVM, thiers open library called LibSVM you can use it. </p>
| 0 | 2016-07-08T09:42:32Z | [
"python",
"nltk",
"senti-wordnet"
] |
OpenERP v7 on_change function returns number instead of value | 38,263,065 | <pre><code> def onchange_product_id(self, cr, uid, ids, product_id, context=None):
val = {
'name': product_id,
}
return {'value': val}
<field name="product_id" on_change="onchange_product_id(product_id, context)"/>
<field name="name"/>
</code></pre>
<p>I have the value in one... | 1 | 2016-07-08T09:17:51Z | 38,263,624 | <p>You need to do something like ,</p>
<pre><code>def onchange_product_id(self, cr, uid, ids, product_id, context=None):
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
val = {
'name': product and product.name or '',
}
return {'value': val}
</code></pre... | 2 | 2016-07-08T09:48:20Z | [
"python",
"openerp",
"openerp-7"
] |
cusolver library not found | 38,263,085 | <p>I am trying to use skcuda in my python code but whenever i want to use it, it rises the following exception:</p>
<pre><code>Traceback (most recent call last):
File "/home/rohola/Projects/Python/wordnetwork/s.py", line 6, in <module>
from skcuda import cusolver
File "/home/rohola/anaconda3/lib/python3.4/si... | 0 | 2016-07-08T09:19:04Z | 38,296,830 | <p>I finally found a solution to my problem. Firstly, i searched for libcusolver.so with</p>
<pre><code>locate libcusolver.so
</code></pre>
<p>and then changed the following code in cusolver.py from:</p>
<pre><code>_libcusolver = ctypes.cdll.LoadLibrary(_libcusolver_libname)
</code></pre>
<p>to:</p>
<pre><code>_li... | 1 | 2016-07-10T22:01:53Z | [
"python",
"cuda",
"scikits"
] |
cusolver library not found | 38,263,085 | <p>I am trying to use skcuda in my python code but whenever i want to use it, it rises the following exception:</p>
<pre><code>Traceback (most recent call last):
File "/home/rohola/Projects/Python/wordnetwork/s.py", line 6, in <module>
from skcuda import cusolver
File "/home/rohola/anaconda3/lib/python3.4/si... | 0 | 2016-07-08T09:19:04Z | 39,782,876 | <pre><code>import ctypes
a = ctypes.cdll.LoadLibrary( "/usr/local/cuda-8.0/targets/x86_64-linux/lib/libcusolver.so" )
</code></pre>
<p>gets me </p>
<pre><code>OSError: /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcusolver.so: undefined symbol: GOMP_critical_end
</code></pre>
<p>which seems to be a yet unsolved is... | 1 | 2016-09-30T02:45:31Z | [
"python",
"cuda",
"scikits"
] |
Pickle Security Risk for Personal Use | 38,263,132 | <p>I am currently working on a small rpg to learn object oriented programming. I have got a nice little game and I was looking into implementing a "save" option to it.</p>
<p>I had a look online and came across this <a href="http://inventwithpython.com/blog/2012/05/03/implement-a-save-game-feature-in-python-with-the-s... | 0 | 2016-07-08T09:21:47Z | 38,263,173 | <p>No, there is no real risk if you are using this to <em>locally</em> store data.</p>
<p>That's because if a hacker can alter the files on your disk, you have far bigger problems; the hacker has already compromised your system. The user of your program can't be seen as a risk here, they already can run their own Pyth... | 2 | 2016-07-08T09:23:53Z | [
"python",
"security",
"save",
"pickle"
] |
Get Excel to display "Now" as text | 38,263,149 | <p>I'm running a python script that reads a value from the screen and compares it to a value read from an excel spreadsheet.
The problem I'm running into is that the value on the screen is: Now</p>
<p>On the excel sheet, when I have a cell with Now, the value it returns is "Now 2016-07-08 11:18" which causes the compa... | -1 | 2016-07-08T09:22:39Z | 38,271,305 | <p>Delete the current content, format the Excel cell as Text, and enter "Now" in the cell. If you are using POI, make sure the the cell type is string. That should fix it.</p>
| 0 | 2016-07-08T16:17:03Z | [
"python",
"excel",
"selenium"
] |
"Radial grids must be strictly positive" error on radar chart | 38,263,313 | <p>Whilst plotting my complex radar chart, I am getting the error "radial grids must be strictly positive", but all of the values and ranges I have used in my radar chart are all positive. Can someone tell me why I am getting this error, and what I can do to fix it? The code I have used is below:-</p>
<pre><code>impor... | -1 | 2016-07-08T09:31:03Z | 38,271,917 | <p>Hi this is great time to learn some debugging skills. The first thing you'll want to do when confronted with an error like this is localize it in your code. Fortunately python does this for you with the traceback. These tracebacks can at times be super intimidating but on closer inspection start to make a little mor... | 1 | 2016-07-08T16:52:47Z | [
"python",
"python-2.7",
"matplotlib",
"data-visualization",
"radar-chart"
] |
Sending email from python3.4 using smtplib | 38,263,379 | <p>Hi I am trying to send an email through python. I use this code to send:</p>
<pre><code> server = smtplib.SMTP(host='send.one.com',port=465)
server.starttls()
server.login(USER, PASS)
text = msg.as_string()
server.sendmail(mailFrom, mailTo, text)
server.quit()
</code></pre>
<p>but I get an ... | 0 | 2016-07-08T09:34:57Z | 38,269,011 | <p>For everyone else that use one.com for your email and you want to connect to theire SMTP server thene I found out that they use SSL, and that was why my code did't work the proper way to do it is as follow:</p>
<pre><code>server = smtplib.SMTP_SSL(host='send.one.com',port=465)
server.login(USER, PASS)
text = msg.as... | 0 | 2016-07-08T14:21:20Z | [
"python",
"python-3.4",
"smtplib"
] |
Print on the same line; mantain until replaced by new string | 38,263,433 | <p>I want to write a function that will output a message on a console line. The message should remain until I don't call the same function again with a new message. At that point, the new message should appear on the same line of the old message replacing it. </p>
<pre><code>import sys
from time import sleep
def prin... | 0 | 2016-07-08T09:37:57Z | 38,263,516 | <p><code>sys.stdout.flush</code> does not clear the line - it clears the buffer (in other words prints everything on the line). What you can do is print a long string of <code>\b</code> to clear the current line, but it won't go back over newlines either. Try:</p>
<pre><code>sys.stdout.write('\b'*100)
sys.stdout.write... | 1 | 2016-07-08T09:42:28Z | [
"python"
] |
Print on the same line; mantain until replaced by new string | 38,263,433 | <p>I want to write a function that will output a message on a console line. The message should remain until I don't call the same function again with a new message. At that point, the new message should appear on the same line of the old message replacing it. </p>
<pre><code>import sys
from time import sleep
def prin... | 0 | 2016-07-08T09:37:57Z | 38,263,653 | <p>If it's okay to use the print statement you can obtain the desired result in python 3.x by:</p>
<pre><code>print("Message " + my_message + "\r", end='')
</code></pre>
<p>or append an comma in python 2:</p>
<pre><code>print "Message " + my_message + "\r",
</code></pre>
<p>So you can basically do:</p>
<pre><code>... | 0 | 2016-07-08T09:49:49Z | [
"python"
] |
Print on the same line; mantain until replaced by new string | 38,263,433 | <p>I want to write a function that will output a message on a console line. The message should remain until I don't call the same function again with a new message. At that point, the new message should appear on the same line of the old message replacing it. </p>
<pre><code>import sys
from time import sleep
def prin... | 0 | 2016-07-08T09:37:57Z | 38,263,690 | <p>You can alos just clear the console with following code before calling print with updated message. However if you have other lines with information in console you would have to reprint them all as well.</p>
<pre><code>os.system('cls' if os.name=='nt' else 'clear')
</code></pre>
| 0 | 2016-07-08T09:51:48Z | [
"python"
] |
(cv2,capture) object is not callable | 38,263,444 | <p>Basically, this code will detect object's motion in the scene. When the motion is detected, a red rectangle frame will track the object's motion. But, I added a new function into the code which is frame differencing. In general it is thresholding. When i run the code it says:"cv2.capture" object is not callable.</p>... | 1 | 2016-07-08T09:38:21Z | 38,263,487 | <p>You can't call the <code>capture</code> object, but you can read from it by calling its <code>read</code> method. Changing your frame return code to:</p>
<pre><code>ret, current_frame = self.capture.read()
</code></pre>
<p>Should fix this.</p>
<p><strong>Edit</strong>:</p>
<p>The two lines:</p>
<pre><code>ret, ... | 0 | 2016-07-08T09:41:00Z | [
"python",
"python-2.7",
"opencv"
] |
Anaconda PyPi Installation | 38,263,499 | <p>I'm trying to install a package not build in conda on Python 3.5 but founded on PyPi: <em>"Seasonal"</em></p>
<p><a href="https://pypi.python.org/pypi/seasonal" rel="nofollow">https://pypi.python.org/pypi/seasonal</a></p>
<p>So I think I just have to do that : </p>
<pre><code>conda skeleton pypi seasonal
conda b... | 0 | 2016-07-08T09:41:28Z | 38,263,739 | <p>If you can find it on PyPi, then you can simply do this:</p>
<pre><code>pip install seasonal
</code></pre>
<p>Since you have <code>conda</code> installed, <code>pip</code> called here is actually calling anaconda's <code>pip</code>. Thus it will automatically handle install path etc.</p>
| 0 | 2016-07-08T09:54:40Z | [
"python",
"package",
"anaconda",
"conda"
] |
make pip ignore an existing wheel | 38,263,682 | <p>If a <code>.whl</code> is available online, <code>pip</code> always installs it rather than compiling from source. However, for some specific module, the wheel happened to be compiled for the next processor generation and doesn't run on a specific machine.</p>
<p>If I command it to just download the package, then i... | 0 | 2016-07-08T09:51:29Z | 38,263,887 | <p>Try using</p>
<pre><code>pip install <package> --no-binary :all:
</code></pre>
<hr>
<p>You can find this option (and the values it takes) in <code>pip install --help</code>.</p>
<p>There's also the <code>--no-use-wheel</code> option, but that is deprecated in favour of the above.</p>
| 3 | 2016-07-08T10:01:49Z | [
"python",
"pip",
"python-wheel"
] |
How to speed up nested for loops in Python | 38,263,789 | <p>I have the following Python 2.7 code:</p>
<pre><code>listOfLists = []
for l1_index, l1 in enumerate(L1):
list = []
for l2 in L2:
for l3_index,l3 in enumerate(L3):
if (L4[l2-1] == l3):
value = L5[l2-1] * l1[l3_index]
list.append(value)
break... | 1 | 2016-07-08T09:57:22Z | 38,266,234 | <p>@Rogalski is right, you definitely need to rethink the algorithm (at least try to). </p>
<p>But if you can't find a better algorithm, I think you could speed up a bit by some tricks while still using nested loops. Note that I will treat L* lists as some global variables, which I don't need to pass to every function... | 3 | 2016-07-08T12:06:18Z | [
"python",
"for-loop",
"nested"
] |
How to speed up nested for loops in Python | 38,263,789 | <p>I have the following Python 2.7 code:</p>
<pre><code>listOfLists = []
for l1_index, l1 in enumerate(L1):
list = []
for l2 in L2:
for l3_index,l3 in enumerate(L3):
if (L4[l2-1] == l3):
value = L5[l2-1] * l1[l3_index]
list.append(value)
break... | 1 | 2016-07-08T09:57:22Z | 38,278,606 | <p>Since you said <code>the readability is not important as long as it speeds up the code</code>, this is how you do the trick:</p>
<pre><code>[[L5[l2 - 1] * sl1 for sl1, l3 in zip(l1, L3)
for l2 in L2 if L4[l2 - 1] == l3]
for l1 in L1]
</code></pre>
<p>This code is 25% faster than for loop. But trust me I will... | 1 | 2016-07-09T05:13:16Z | [
"python",
"for-loop",
"nested"
] |
How to speed up nested for loops in Python | 38,263,789 | <p>I have the following Python 2.7 code:</p>
<pre><code>listOfLists = []
for l1_index, l1 in enumerate(L1):
list = []
for l2 in L2:
for l3_index,l3 in enumerate(L3):
if (L4[l2-1] == l3):
value = L5[l2-1] * l1[l3_index]
list.append(value)
break... | 1 | 2016-07-08T09:57:22Z | 38,401,964 | <p>The following code is a combination of both @spacegoing and @Alissa, and yields the fastest results:</p>
<pre><code>L3_dict = {l3:l3_index for l3_index,l3 in enumerate(L3)}
list_of_lists = [[L5[l2 - 1] * l1[L3_dict[L4[l2-1]]]
for l2 in L2]
for l1 in L1]
</code></pre>
<p>Thank you both @spacegoing and @Aliss... | 0 | 2016-07-15T17:25:55Z | [
"python",
"for-loop",
"nested"
] |
Adding Namespaces to a DOM Element python | 38,263,798 | <p>I want to produce this xml file with <code>python</code> and <code>minidom</code>:</p>
<pre><code><xml vesion="1.0" encoding="utf-8?>
<package name="Operation" xmlns="http://www.modelIL.eu/types-2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.modelIL.eu/types-2.0... | 1 | 2016-07-08T09:57:50Z | 38,282,996 | <p><em>Full disclosure: I do not use minidom for XML, I use <a href="http://lxml.de/" rel="nofollow">lxml</a> and on top of that I do not use XML that often, so I hope my answer will be useful.</em></p>
<blockquote>
<p>One might expect that by setting an attribute with a particular namespace, there would not be any ... | 1 | 2016-07-09T14:46:32Z | [
"python",
"dom",
"namespaces",
"xml-namespaces",
"minidom"
] |
Python: Sqlalchemy messing up pyinstaller? | 38,263,837 | <p>I am trying to package my program using pyinstaller. The code runs fine on windows, and uses SqlAlchemy, OpenCV and pyodbc packages. </p>
<p>I ran pyinstaller to create the executable and tried to run it. I'm getting an error:</p>
<pre><code>ImportError: No module named ConfigParser
</code></pre>
<p>now, I reran ... | 0 | 2016-07-08T09:59:37Z | 38,345,576 | <p>So, I figured it out. To an extent.<br>
Seems like pyInstaller doesn't deal with SWIG files that well.</p>
<p>In <code>sqlalchemy.utils</code> there's a file called <code>compat.py</code>. It is there to make the module compatible with all versions of python. </p>
<p>for example, in python2.x, there's <code>Confi... | 0 | 2016-07-13T07:46:07Z | [
"python",
"opencv",
"sqlalchemy",
"pyinstaller"
] |
pandas.DataFrame.loc , Labeling data in new column | 38,263,994 | <p>I have got a pandas dataframe like this: </p>
<pre><code> ranking
1 4.33
2 1.34
3 3.76
..
</code></pre>
<p>And I would like to create this: </p>
<pre><code> ranking label
1 4.33 2
2 1.34 0
3 3.76 1
..
</code></pre>
<p>So a ranking <code>< 3.5</code> leads to a label of <... | 1 | 2016-07-08T10:06:23Z | 38,264,097 | <p>You need:</p>
<pre><code>df['label'] = df.ranking.where(df.ranking > 3.4999, 0)
df.ix[(df.label > 3.4999) & (df.label < 4.2499), 'label'] = 1
df.ix[df.label > 4.2499, 'label'] = 2
print (df)
ranking label
1 4.33 2.0
2 1.34 0.0
3 3.76 1.0
</code></pre>
| 1 | 2016-07-08T10:10:14Z | [
"python",
"csv",
"pandas",
"dataframe",
"rank"
] |
pandas.DataFrame.loc , Labeling data in new column | 38,263,994 | <p>I have got a pandas dataframe like this: </p>
<pre><code> ranking
1 4.33
2 1.34
3 3.76
..
</code></pre>
<p>And I would like to create this: </p>
<pre><code> ranking label
1 4.33 2
2 1.34 0
3 3.76 1
..
</code></pre>
<p>So a ranking <code>< 3.5</code> leads to a label of <... | 1 | 2016-07-08T10:06:23Z | 38,264,133 | <p>You need to use bitwise <code>&</code> instead of <code>and</code>. The conditions must be grouped by <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow">parantheses</a>.</p>
<p>However, a better way would be to use <a href="http://pandas.pydata.org/pandas-docs/st... | 4 | 2016-07-08T10:12:51Z | [
"python",
"csv",
"pandas",
"dataframe",
"rank"
] |
KNN classifier not working in python on raspberrypi | 38,263,995 | <p>I am writing a KNN classifier taken from <a href="http://machinelearningmastery.com/tutorial-to-implement-k-nearest-neighbors-in-python-from-scratch/" rel="nofollow">here</a> for character recognition from accelerometer and gyroscopic data.But, the below functions are not working correctly and prediction is not happ... | -2 | 2016-07-08T10:06:23Z | 38,265,560 | <p>I could see from your data that number of samples is very less that no. of features, that may affect the accuracy of prediction and the number of samples need to be very high. You can't expect to predict everything correctly, algorithms have their own accuracies. Try to check the correctness of this code by using an... | 0 | 2016-07-08T11:31:03Z | [
"python",
"raspberry-pi",
"knn"
] |
I can not understand, graphite support udp, why do we need statsd | 38,264,081 | <p>Graphite can user TCP and UDP lisen,why graphite default use TCP not UDP.Whether statsd is superfluous?</p>
| -2 | 2016-07-08T10:09:36Z | 38,378,771 | <p>StatsD also does aggregation of metrics. For example, you can send it 1000s of timing events and then every flush interval (default 10 seconds) it will calculate summary statistics for that timer including mean, upper, lower, count, count per second etc. Therefore I would argue that StatsD is not superfluous as it h... | 0 | 2016-07-14T15:50:30Z | [
"python",
"node.js",
"monitor",
"graphite",
"statsd"
] |
Cant find version or use pip using python27 command line | 38,264,090 | <p>I have been looking for the past hour regarding installing modules using. It says that python27 comes with pip, However when I type <code>python -m pip install --upgrade pip wheel setuptools</code> into the command line I just get the error <code>NameError: Name 'python' is not defined.</code> I cant even enter <cod... | 0 | 2016-07-08T10:10:02Z | 38,264,328 | <p>I think you have to set PATH in environment variable for python command to work.If you're on windows follow this:</p>
<p>My Computer > Properties > Advanced System Settings > Environment Variables >
Then under system variables create a new Variable name PATH.Under value type your python installation directory whic... | 2 | 2016-07-08T10:23:02Z | [
"python",
"windows",
"python-2.7",
"pip",
"kivy"
] |
Why is index_queryset called every time from search view in django-Haystack? | 38,264,103 | <p>I have followed the <a href="http://django-haystack.readthedocs.io/en/v2.4.1/tutorial.html#handling-data" rel="nofollow">Getting Starting - Django Haystack</a> example, swapping out their model for mine.
In search_indexes.py, the method index_queryset has the comment "Used when the entire index for model is updated... | 0 | 2016-07-08T10:10:43Z | 38,266,546 | <p>This is intended behaviour - it is the docstring that is wrong. The function <code>index_queryset</code> basically returns the queryset that Haystack will use to obtain the search results (as well as to index documents).</p>
<p>You say:</p>
<blockquote>
<p>The method itself gets all the objects from the database... | 0 | 2016-07-08T12:22:24Z | [
"python",
"django",
"django-haystack"
] |
Extracting part of a multi-line string using a regular expression | 38,264,151 | <p>I am trying to extract the below line from a multi-line string:</p>
<pre><code>eth6.36 Link encap:Ethernet HWaddr A0:36:9F:5F:24:EE \r\n inet addr:36.36.36.10 Bcast:36.36.36.255 Mask:255.255.255.0\r\n inet6 addr: fe80::a236:9fff:fe5f:24ee/64
</code></pre>
<p>When I try to extract just <code... | 2 | 2016-07-08T10:13:46Z | 38,264,325 | <p>Use <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow"><code>findall</code></a> with <a href="https://docs.python.org/2/library/re.html#re.M" rel="nofollow"><code>multiline</code></a> instead. You also need a quantifier for <code>\s</code>.</p>
<pre><code>>>> re.findall(r'(eth6.3... | 0 | 2016-07-08T10:22:55Z | [
"python",
"regex"
] |
Extracting part of a multi-line string using a regular expression | 38,264,151 | <p>I am trying to extract the below line from a multi-line string:</p>
<pre><code>eth6.36 Link encap:Ethernet HWaddr A0:36:9F:5F:24:EE \r\n inet addr:36.36.36.10 Bcast:36.36.36.255 Mask:255.255.255.0\r\n inet6 addr: fe80::a236:9fff:fe5f:24ee/64
</code></pre>
<p>When I try to extract just <code... | 2 | 2016-07-08T10:13:46Z | 38,264,326 | <p><a href="https://docs.python.org/2/library/re.html#re.match" rel="nofollow"><code>re.match</code></a> matches from the beginning of the string. Use <a href="https://docs.python.org/2/library/re.html#re.search" rel="nofollow"><code>re.search</code></a> instead as it matches anywhere in the string:</p>
<pre><code>>... | 1 | 2016-07-08T10:22:56Z | [
"python",
"regex"
] |
Extracting part of a multi-line string using a regular expression | 38,264,151 | <p>I am trying to extract the below line from a multi-line string:</p>
<pre><code>eth6.36 Link encap:Ethernet HWaddr A0:36:9F:5F:24:EE \r\n inet addr:36.36.36.10 Bcast:36.36.36.255 Mask:255.255.255.0\r\n inet6 addr: fe80::a236:9fff:fe5f:24ee/64
</code></pre>
<p>When I try to extract just <code... | 2 | 2016-07-08T10:13:46Z | 38,264,391 | <p>You want this, There was a mistake in the formation of regex</p>
<pre><code>import re
test = 'ifconfig eth6.36\r\neth6.36 Link encap:Ethernet HWaddr A0:36:9F:5F:24:EE \r\n inet addr:36.36.36.10 Bcast:36.36.36.255 Mask:255.255.255.0\r\n inet6 addr: fe80::a236:9fff:fe5f:24ee/64 Scope:Link\r\n ... | 1 | 2016-07-08T10:26:23Z | [
"python",
"regex"
] |
Using GAE instances and GCE VM mixed | 38,264,297 | <p>I am building a news aggregator app, and the backend can be separated (mostly) in two logical parts:</p>
<ol>
<li>Crawling, information extraction, parsing, clustering, storing... </li>
<li>Serving the user requests</li>
</ol>
<p>What I would like to do is:
a) create a heavy Google Compute Engine VM Instance to do... | 1 | 2016-07-08T10:21:25Z | 38,275,596 | <p>Another option you should explore is <a href="https://cloud.google.com/appengine/docs/flexible/" rel="nofollow">App Engine Flexible</a>. <em>(disclaimer, I work at Google on App Engine)</em></p>
<p>We allow you to build an App Engine application that has multiple modules. Those modules will run on GCE virtual mach... | 3 | 2016-07-08T21:23:53Z | [
"python",
"google-app-engine",
"google-compute-engine",
"google-cloud-platform",
"google-cloud-datastore"
] |
Freeswitch originate | 38,264,381 | <p>I'm using Freeswitch 1.6 ESL and when I place a call using API and remote IP Address I get: </p>
<p><strong>NO_ROUTE_DESTINATION</strong></p>
<pre><code>2016-07-08 06:24:13.381491 [DEBUG] switch_core_state_machine.c:296 No Dialplan on answered channel, changing state to HANGUP
</code></pre>
<p>It works fine If Im... | -1 | 2016-07-08T10:26:04Z | 38,264,499 | <p>From <a href="https://www.mail-archive.com/freeswitch-users@lists.freeswitch.org/msg15454.html" rel="nofollow">https://www.mail-archive.com/freeswitch-users@lists.freeswitch.org/msg15454.html</a> the issue was the space between & and park().</p>
| 0 | 2016-07-08T10:32:07Z | [
"python",
"sip",
"freeswitch"
] |
My Python number guessing game | 38,264,447 | <p>I have been trying to make a number guessing game for Python and so far it has altogether gone quite well. But what keeps bugging me is that it resets the number on every guess so that it is different, but I want it to stay the same and then people can take a while guessing it.</p>
<pre><code>import os
import time
... | 0 | 2016-07-08T10:29:18Z | 38,264,512 | <p>Since you have <code>number2 = int(randint(1,99))</code> inside your <code>while</code> cycle, then you create a new number each time. Put that line outside the <code>while</code> and the number will remain the same until someone guesses it</p>
| 3 | 2016-07-08T10:33:06Z | [
"python"
] |
My Python number guessing game | 38,264,447 | <p>I have been trying to make a number guessing game for Python and so far it has altogether gone quite well. But what keeps bugging me is that it resets the number on every guess so that it is different, but I want it to stay the same and then people can take a while guessing it.</p>
<pre><code>import os
import time
... | 0 | 2016-07-08T10:29:18Z | 38,264,624 | <p>Also, no need to import <code>from random import randint</code> everytime you need <code>randint()</code>. Put it at the top next to <code>import time</code></p>
| 0 | 2016-07-08T10:38:59Z | [
"python"
] |
My Python number guessing game | 38,264,447 | <p>I have been trying to make a number guessing game for Python and so far it has altogether gone quite well. But what keeps bugging me is that it resets the number on every guess so that it is different, but I want it to stay the same and then people can take a while guessing it.</p>
<pre><code>import os
import time
... | 0 | 2016-07-08T10:29:18Z | 38,264,784 | <p>There are a lot of things wrong with your code : the <code>import</code> statement should be at the beginning, and there is much duplicated code, which makes it hard to read.</p>
<p><strong>Your problem comes from the fact that <code>number2 = int(randint(1,99))</code> is called at each cycle of the <code>while</co... | 2 | 2016-07-08T10:48:42Z | [
"python"
] |
New variable for each group - pandas | 38,264,474 | <p>I love R. But now I need pandas.
In R I can do:</p>
<pre><code>data %>% group_by(sym) %>% mutate(s = mean(price))
</code></pre>
<p>Its not aggregation ! Its a new variable different for each group.
I try everything in pandas - "group by" want to aggregate or split my data ! I only want to calculate new varia... | -2 | 2016-07-08T10:30:52Z | 38,265,479 | <p>We can try</p>
<pre><code>import pandas as pd
data['s'] = data['price'].groupby(data['sym']).transform('mean')
print(data)
# price sym s
#0 125 A 129.000000
#1 133 A 129.000000
#2 50 B 77.333333
#3 62 B 77.333333
#4 120 B 77.333333
</code></pre>
<p>Or as @MaxU mention... | 2 | 2016-07-08T11:26:09Z | [
"python",
"pandas"
] |
Modifiying global variables with multiprocessing | 38,264,584 | <p>I want to modify a list by appending to it items generated by some functions that work in parallel. Something like this:</p>
<pre><code>import multiprocessing
my_list=[]
def f(x):
global my_list
my_list.append(x)
for i in range(6):
p = multiprocessing.Process(target=f, args=(i,))
jobs.append(p)
... | 1 | 2016-07-08T10:36:41Z | 38,264,963 | <p>I think you need to use the data structures defined in the multiprocessing module rather than standard lists: <a href="https://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">https://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes</a></p>
| 1 | 2016-07-08T10:57:11Z | [
"python",
"global-variables",
"multiprocessing"
] |
Python control output positions in terminal/console | 38,264,588 | <p>This is a question for python language, and the terminal/console applies to Unix-like systems. It would be great if the solution is platform independent but that is not required.</p>
<p>The scenario is when the program keeps printing lines to terminal. However, among the many lines to print, some of them are specia... | 0 | 2016-07-08T10:36:55Z | 38,264,693 | <p>For a Windows terminal try the <a href="http://effbot.org/zone/console-handbook.htm" rel="nofollow">console module</a> For unix the <a href="https://docs.python.org/3/library/curses.html" rel="nofollow">curses module</a> would do.</p>
<p>This is how you do it on Windows.</p>
<pre><code>c = Console.getconsole()
c.t... | 2 | 2016-07-08T10:43:02Z | [
"python"
] |
Python control output positions in terminal/console | 38,264,588 | <p>This is a question for python language, and the terminal/console applies to Unix-like systems. It would be great if the solution is platform independent but that is not required.</p>
<p>The scenario is when the program keeps printing lines to terminal. However, among the many lines to print, some of them are specia... | 0 | 2016-07-08T10:36:55Z | 38,264,714 | <p>It sounds like you want to use a curses library, which handles text based UIs on Unix systems. There's a module for it in python's standard library:</p>
<p><a href="https://docs.python.org/2/library/curses.html#module-curses" rel="nofollow">https://docs.python.org/2/library/curses.html#module-curses</a></p>
<p>How... | 0 | 2016-07-08T10:44:06Z | [
"python"
] |
Django valueError when using query_params | 38,264,632 | <p>I am trying to setup an API using Django. In my views.py, I have this endpoint:</p>
<pre><code>@api_view()
def update_label(request):
user_id = request.query_params['user_id']
date = datetime.strptime(request.query_params['date'], '%Y-%m-%dT%H:%M:%S.%f')
label_name = request.query_params['label_name']
... | 0 | 2016-07-08T10:39:28Z | 38,265,003 | <p>Can you try</p>
<pre><code>import json
json.loads(<query string value>)
</code></pre>
| 1 | 2016-07-08T10:58:57Z | [
"python",
"django",
"django-rest-framework"
] |
Django valueError when using query_params | 38,264,632 | <p>I am trying to setup an API using Django. In my views.py, I have this endpoint:</p>
<pre><code>@api_view()
def update_label(request):
user_id = request.query_params['user_id']
date = datetime.strptime(request.query_params['date'], '%Y-%m-%dT%H:%M:%S.%f')
label_name = request.query_params['label_name']
... | 0 | 2016-07-08T10:39:28Z | 38,306,340 | <p>The issue was quite sneaky, it was due to Gunicorn caching some files. In the old versions of <code>views.py</code>, I had <code>value = int(request.query_params['value'])</code>. When I updated the code Gunicorn was still answering using the outdated cached files, hence the failure to cast a string into an int. I r... | 0 | 2016-07-11T11:56:20Z | [
"python",
"django",
"django-rest-framework"
] |
Python context manager to decorator (and inversely) | 38,264,864 | <p>I would like to have:</p>
<pre><code># Simple example, one could replace try/except by any other nested construct
def mycontextmanager_generator(foo):
try:
yield
except:
print 'bar'
 raise
mycontextmanager = build_contextmanager(mycontextmanager_generator)
mydecorator = build_decora... | 0 | 2016-07-08T10:52:11Z | 38,270,466 | <p>You can easily achieve what you need by combining the class that <code>contextmanager</code> uses to manage its contexts (<code>_GeneratorContextManager</code>) and the <code>ContextDecorator</code> class. eg.</p>
<pre><code>from contextlib import ContextDecorator, _GeneratorContextManager
from functools import wra... | 1 | 2016-07-08T15:32:45Z | [
"python",
"decorator",
"yield",
"contextmanager"
] |
Python context manager to decorator (and inversely) | 38,264,864 | <p>I would like to have:</p>
<pre><code># Simple example, one could replace try/except by any other nested construct
def mycontextmanager_generator(foo):
try:
yield
except:
print 'bar'
 raise
mycontextmanager = build_contextmanager(mycontextmanager_generator)
mydecorator = build_decora... | 0 | 2016-07-08T10:52:11Z | 38,271,295 | <p>A simpler to understand solution than Dunes' one, albeit not taking advantage of <code>ContextDecorator</code> double-syntax.</p>
<pre><code>import contextlib
import functools
def handler():
try:
yield
except:
print 'bar'
my_contextmanager = contextlib.contextmanager(handler)
def my_dec... | 0 | 2016-07-08T16:16:40Z | [
"python",
"decorator",
"yield",
"contextmanager"
] |
Write numpy.ndarray with Russian characters to file | 38,264,881 | <p>I try to write <code>numpy.ndarray</code> to file.
I use</p>
<pre><code>unique1 = np.unique(df['search_term'])
unique1 = unique1.tolist()
</code></pre>
<p>and next try
1)</p>
<pre><code>edf = pd.DataFrame()
edf['term'] = unique1
writer = pd.ExcelWriter(r'term.xlsx', engine='xlsxwriter')
edf.to_excel(writer)
wri... | 2 | 2016-07-08T10:52:38Z | 38,266,903 | <p>The second example should work if you encode the strings as utf8. </p>
<p>The following works in Python2 with a utf8 encoded file:</p>
<pre><code># _*_ coding: utf-8
import pandas as pd
edf = pd.DataFrame()
edf['term'] = ['foo', 'bar', u'ÑÑÑÑком']
writer = pd.ExcelWriter(r'term.xlsx', engine='xlsxwriter'... | 0 | 2016-07-08T12:37:56Z | [
"python",
"excel",
"numpy",
"pandas",
"utf-8"
] |
Heat Map of Spatial Data in Python | 38,264,887 | <p>Im am writing a Python Code. My dataset is composed of three columns, the firs two are the coordinates, and the third is a heat estimation</p>
<pre><code> X Y heat
0 497935.000000 179719.000000 0.048428
1 497935.000000 179719.000000 0.029399
2 497935.000000 17... | 0 | 2016-07-08T10:52:54Z | 38,265,706 | <p>From the <a href="http://pandas.pydata.org/pandas-docs/stable/visualization.html#visualization-scatter" rel="nofollow">documentation</a>:</p>
<blockquote>
<p>The keyword c may be given as the name of a column to provide colors for each point:</p>
</blockquote>
<pre><code>In [64]: df.plot.scatter(x='a', y='b', c=... | 2 | 2016-07-08T11:39:15Z | [
"python",
"pandas",
"spatial",
"heatmap"
] |
Python saving list changes | 38,264,915 | <pre><code>list = []
while True:
list.append(input())
print(list)
</code></pre>
<p>this allows me to add whatever I want to this list. However, Is there a way that I can keep the changes to the list so that when I run the program later all of the things I previously wrote will be on the list? </p>
<p>EDIT: If... | 0 | 2016-07-08T10:54:21Z | 38,265,076 | <p>You can use <code>json</code> here.</p>
<pre><code>import json
try:
list = json.load(open("database.json"))
except:
list = []
while True:
try:
list.append(input())
print(list)
except KeyboardInterrupt:
json.dump(list, open('database.json', 'w'))
</code></pre>
<p>This stores ... | 1 | 2016-07-08T11:02:37Z | [
"python",
"list",
"save"
] |
Python saving list changes | 38,264,915 | <pre><code>list = []
while True:
list.append(input())
print(list)
</code></pre>
<p>this allows me to add whatever I want to this list. However, Is there a way that I can keep the changes to the list so that when I run the program later all of the things I previously wrote will be on the list? </p>
<p>EDIT: If... | 0 | 2016-07-08T10:54:21Z | 38,265,081 | <p>You would need a persistence layer i.e a file system, database, <code>pickle</code>, <code>shelve</code> etc. where you can store the data present in <code>list</code> once the program has terminated. When you re-run your program, make sure it loads from the same persistence store, without initializing it to <code>[... | 0 | 2016-07-08T11:02:58Z | [
"python",
"list",
"save"
] |
Python saving list changes | 38,264,915 | <pre><code>list = []
while True:
list.append(input())
print(list)
</code></pre>
<p>this allows me to add whatever I want to this list. However, Is there a way that I can keep the changes to the list so that when I run the program later all of the things I previously wrote will be on the list? </p>
<p>EDIT: If... | 0 | 2016-07-08T10:54:21Z | 38,265,128 | <p>You need to save the list somewhere first and then load it at the start of the program. Since it's just a simple list we can just use python pickle to save it to disk like this:</p>
<pre><code>import pickle
try:
with open('list.p', 'rb') as f:
list = pickle.load(f)
except:
list = []
while True:
... | 0 | 2016-07-08T11:05:20Z | [
"python",
"list",
"save"
] |
Only first filter being checked on logger | 38,264,920 | <p>So, right now, I have a process that spawns multiple threads, each with their own instance data. I need to inject context-specific information into each of the logging statements that are called throughout the various methods inside of the derived thread class (in this case, the context-specific info is the email of... | 0 | 2016-07-08T10:54:39Z | 38,273,447 | <p>Figured it out, in case anyone ever gets stuck with something like this in the future (or maybe you wont because you're a better programmer than I am, haha)</p>
<p>For logging in Python, only one of the filters has to fail for the entire log message to be dropped. I thought it would check the filters and see if at ... | 0 | 2016-07-08T18:43:17Z | [
"python",
"multithreading",
"python-2.7",
"logging",
"filter"
] |
Merge branch coverage files python | 38,264,980 | <p>I have a multiprocessing application in python. And I am trying to get the coverage report after running my tests. I am trying to merge coverage reports but I am not able to do in a single shot.</p>
<p>Following is the issue I am facing.
My two tests have generated 4 coverage files. And when I run the command <stro... | 0 | 2016-07-08T10:58:00Z | 38,281,311 | <p>The error you are seeing will happen if you use the command line to configure coverage, like this:</p>
<pre><code>coverage run --branch --concurrency=multiprocessing myprogram.py
</code></pre>
<p>The problem is that the command line arguments aren't communicated down to the subprocesses, so the main process measur... | 0 | 2016-07-09T11:24:55Z | [
"python",
"python-2.7",
"coverage.py",
"python-coverage"
] |
Merge branch coverage files python | 38,264,980 | <p>I have a multiprocessing application in python. And I am trying to get the coverage report after running my tests. I am trying to merge coverage reports but I am not able to do in a single shot.</p>
<p>Following is the issue I am facing.
My two tests have generated 4 coverage files. And when I run the command <stro... | 0 | 2016-07-08T10:58:00Z | 39,862,071 | <p>I ran across this problem when my unit tests ran code in multiple directories. I had to add .coveragerc files in each directory to get them all to produce branch (aka arc) data. I did this by sym-linking to my main .coveragerc file.</p>
| 0 | 2016-10-04T21:29:56Z | [
"python",
"python-2.7",
"coverage.py",
"python-coverage"
] |
Create properties in class from list / attribute in __init__ | 38,264,987 | <p>I have a piece of hardware I write a class for which has multiple inputs. Each input (channel) has a name, so I created a list:</p>
<pre><code>CHANNELS = {"T0": 0, "Tend": 1, "A": 2, "B": 3, "C" : 4, "D" : 5,
"E" : 6, "F" : 7, "G" : 8, "H" : 9}
</code></pre>
<p>Now I would like to create a property to access t... | 0 | 2016-07-08T10:58:12Z | 38,265,400 | <p>I <em>think</em> this is what you want: </p>
<pre><code>class Something(object):
CHANNELS = {"T0": 0, "Tend": 1, "A": 2, "B": 3, "C": 4, "D": 5,
"E": 6, "F": 7, "G": 8, "H": 9}
def __getattr__(self, name):
"""Handle missing attributes."""
if name.startswith('read') and name... | -1 | 2016-07-08T11:21:26Z | [
"python",
"properties",
"setter",
"getter",
"setattribute"
] |
Create properties in class from list / attribute in __init__ | 38,264,987 | <p>I have a piece of hardware I write a class for which has multiple inputs. Each input (channel) has a name, so I created a list:</p>
<pre><code>CHANNELS = {"T0": 0, "Tend": 1, "A": 2, "B": 3, "C" : 4, "D" : 5,
"E" : 6, "F" : 7, "G" : 8, "H" : 9}
</code></pre>
<p>Now I would like to create a property to access t... | 0 | 2016-07-08T10:58:12Z | 38,265,892 | <p>If you really want to dynamically create functions and make them members of your class instances, you can use <code>lambda</code>:</p>
<pre><code>CHANNELS = {"T0": 0, "Tend": 1, "A": 2, "B": 3, "C" : 4, "D" : 5,
"E" : 6, "F" : 7, "G" : 8, "H" : 9}
class Foo(object):
def __init__(self):
for x in CHA... | 1 | 2016-07-08T11:50:44Z | [
"python",
"properties",
"setter",
"getter",
"setattribute"
] |
How to call a function from a module name that is assigned to a variable | 38,265,029 | <p>I am trying to call a function from a module. The module and the function have the same name, which is read at runtime using <code>raw_input()</code> and stored in a variable.</p>
<p>For example, </p>
<h3>module.py</h3>
<pre><code>def module():
print "x"
</code></pre>
<h3>run.py</h3>
<pre><code>ent="module"... | 2 | 2016-07-08T11:00:23Z | 38,265,237 | <p>As Jon mentioned, you didn't save a reference to the imported module. You need that to call its functions. To actually get to the function you can use the built-in <code>getattr</code> function. Eg,</p>
<pre><code>ent = "module"
mod = __import__(ent)
func = getattr(mod, ent)
func()
</code></pre>
<p>However, using ... | 0 | 2016-07-08T11:11:11Z | [
"python",
"function",
"module"
] |
How to 'break' if statement in Python | 38,265,056 | <p>This is a small part of my code</p>
<pre><code>def menu():
choices = ["Create a Scenario", "Load a Database", "Quit"]
m1 = eg.choicebox("What would you like to do?", "Greenfly Model Menu", choices)
if m1 == "Load a Scenario":
dbless = eg.enterbox("What is the name of your database?")
if ... | 0 | 2016-07-08T11:01:18Z | 38,265,099 | <p>Use <code>return</code> statement instead of considering <code>break</code> inside the function without loop.</p>
| 0 | 2016-07-08T11:04:02Z | [
"python",
"python-3.x"
] |
How to 'break' if statement in Python | 38,265,056 | <p>This is a small part of my code</p>
<pre><code>def menu():
choices = ["Create a Scenario", "Load a Database", "Quit"]
m1 = eg.choicebox("What would you like to do?", "Greenfly Model Menu", choices)
if m1 == "Load a Scenario":
dbless = eg.enterbox("What is the name of your database?")
if ... | 0 | 2016-07-08T11:01:18Z | 38,265,701 | <p>You can include a <code>while</code> loop so that until the input is not None, it will ask for the input:</p>
<pre><code>while dbless is None:
menu()
else: #you can remove the else and unindent the next two lines, but I'm used to do it that way
db_name = dbless + ".db"
check = os.path.isfile(db_name)
<... | 0 | 2016-07-08T11:38:45Z | [
"python",
"python-3.x"
] |
How to 'break' if statement in Python | 38,265,056 | <p>This is a small part of my code</p>
<pre><code>def menu():
choices = ["Create a Scenario", "Load a Database", "Quit"]
m1 = eg.choicebox("What would you like to do?", "Greenfly Model Menu", choices)
if m1 == "Load a Scenario":
dbless = eg.enterbox("What is the name of your database?")
if ... | 0 | 2016-07-08T11:01:18Z | 38,266,052 | <p>You shouldn't use a break statement outside a loop. Therefore you need to use the return statement. You can do that in two ways.</p>
<pre><code>if dbless is None:
menu()
return
</code></pre>
<p>or </p>
<pre><code>if dbless is None:
return menu()
</code></pre>
| 0 | 2016-07-08T11:58:09Z | [
"python",
"python-3.x"
] |
How to 'break' if statement in Python | 38,265,056 | <p>This is a small part of my code</p>
<pre><code>def menu():
choices = ["Create a Scenario", "Load a Database", "Quit"]
m1 = eg.choicebox("What would you like to do?", "Greenfly Model Menu", choices)
if m1 == "Load a Scenario":
dbless = eg.enterbox("What is the name of your database?")
if ... | 0 | 2016-07-08T11:01:18Z | 38,266,194 | <p>You can try this and it will be consistent with your logic:</p>
<pre><code>def menu():
choices = ["Create a Scenario", "Load a Database", "Quit"]
m1 = eg.choicebox("What would you like to do?", "Greenfly Model Menu", choices)
if m1 == "Load a Scenario":
dbless = eg.enterbox("What is the name of your... | 0 | 2016-07-08T12:04:24Z | [
"python",
"python-3.x"
] |
Get tweets from local host, python, pymongo | 38,265,070 | <p>I am trying this code:</p>
<pre><code>import pymongo
import json
import numpy as np
client = pymongo.MongoClient('localhost', 27017)
db = client.test
collection = db['tweets']
print ("Tweets Capturados: ", collection.count())
</code></pre>
<p>But, I get this error:</p>
<pre><code>ServerSelectionTimeoutError: lo... | 0 | 2016-07-08T11:02:09Z | 38,265,672 | <p>Are you sure MongoDB is running on your local machine? Please check whether it is up and running.
There is nothing wrong with your code.
Also that'd be useful to know which version of pymongo you're using.</p>
<blockquote>
<p>Is there a generic localhost from Twitter API that I could use?</p>
</blockquote>
<p>Ca... | 0 | 2016-07-08T11:37:18Z | [
"python",
"twitter"
] |
Get tweets from local host, python, pymongo | 38,265,070 | <p>I am trying this code:</p>
<pre><code>import pymongo
import json
import numpy as np
client = pymongo.MongoClient('localhost', 27017)
db = client.test
collection = db['tweets']
print ("Tweets Capturados: ", collection.count())
</code></pre>
<p>But, I get this error:</p>
<pre><code>ServerSelectionTimeoutError: lo... | 0 | 2016-07-08T11:02:09Z | 38,265,988 | <p>it seems you have just copied and paste the code , without installing the MongoDB<br>
The code you've provided has no connection to twitter , it just connect to local mongodb host and read a database which named tweets . <br>
if you want to read tweets you have to read the twitter documentations which have no relati... | 0 | 2016-07-08T11:55:19Z | [
"python",
"twitter"
] |
Groupby with row index operation? | 38,265,202 | <p>How can I select the rows with given row index operation (say, only even rows or only if row# % 5 == 0) in pandas?
let's say I have a dataframe with df <code>[120 rows x 10 column]</code>, and I want to create two out of it, one from even rows df1 <code>[60 rows x 10 column]</code>, and one from odd rows <code>[60 r... | 2 | 2016-07-08T11:09:03Z | 38,265,303 | <p>You can slice the dfs using normal list style slicing semantics:</p>
<pre><code>first = df.iloc[::2]
second = df.iloc[1::2]
</code></pre>
<p>So the first steps every 2 rows starting from first to last row
the second does the same but starts from row 1, the second row, and steps every 2 rows</p>
| 4 | 2016-07-08T11:14:56Z | [
"python",
"pandas",
"scipy"
] |
Groupby with row index operation? | 38,265,202 | <p>How can I select the rows with given row index operation (say, only even rows or only if row# % 5 == 0) in pandas?
let's say I have a dataframe with df <code>[120 rows x 10 column]</code>, and I want to create two out of it, one from even rows df1 <code>[60 rows x 10 column]</code>, and one from odd rows <code>[60 r... | 2 | 2016-07-08T11:09:03Z | 38,265,970 | <p>As stated already, you may use iloc</p>
<pre><code>df0 = df.iloc[::2]
df1 = df.iloc[1::2]
</code></pre>
<p>If you have a more complex selection schema you may pass a boolean vector to iloc, e.g.,</p>
<pre><code>def filter_by( idx ):
# param idx: an index
# returns True if idx%4==0 or idx%4==1
if idx%4... | 1 | 2016-07-08T11:54:32Z | [
"python",
"pandas",
"scipy"
] |
UnicodDecodeError in Binary files | 38,265,320 | <p>I've written a small sample code to try out pickle module. Faced UnicodeDecodeError in the pickle.load() statement. Writing encoding='utf-8' also has no effect.
Here's the code</p>
<pre><code>import pickle
class NewOne:
def __init__(self):
self.name = "None"
self.age = 0
def entries(self):... | 0 | 2016-07-08T11:16:19Z | 38,265,972 | <p>The main problem with your code is, that you are appending to the end of the same file every time you run the script, but loading the first three objects later on. </p>
<p>Actually, it's worse than that; You <em>should</em> be loading the first three objects, but in fact you are only loading the first one each time... | 0 | 2016-07-08T11:54:34Z | [
"python",
"python-3.x",
"binaryfiles"
] |
Census transform in python openCV | 38,265,364 | <p>I am starting to work with openCV and python in a project related with stereovision. I found this page of documentation about the Census Transform in C++ with openCV.
<a href="http://docs.opencv.org/3.1.0/d2/d7f/namespacecv_1_1stereo.html#a939dfbb1a0d1a3255749629343247bd5" rel="nofollow">link</a></p>
<p>Does anyone... | 1 | 2016-07-08T11:19:02Z | 38,269,363 | <p>I don't use openCV, and I don't know if there's an existing implementation of the Census Transform. However, it's easy enough to implement using Numpy.</p>
<p>Here's a simple demo that uses <a href="https://pillow.readthedocs.io/en/3.3.x/index.html" rel="nofollow">PIL</a> to handle loading the image and converting ... | 3 | 2016-07-08T14:39:38Z | [
"python",
"opencv"
] |
django-rest-framework-bulk BulkUpdateView outuput customization | 38,265,415 | <p>I have a model called <code>Item</code> which has an <code>FSMField</code> (of <a href="https://github.com/kmmbvnr/django-fsm" rel="nofollow">django-fsm</a>) called <code>status</code>.</p>
<pre><code>class Item(models.Model):
...
status = FSMField(choices=StatusChoices.choices, default=StatusChoices.INITIA... | 1 | 2016-07-08T11:21:57Z | 38,368,847 | <p>Here's how I achieved my objective, (in a not so elegant way though).</p>
<p>As suggested by @Kevin Brown in comments, I changed my <code>ItemStatusSerializer</code> to look like this:</p>
<pre><code>class ItemStatusSerializer(BulkSerializerMixin, serializers.ModelSerializer):
transition = serializers.CharFiel... | 0 | 2016-07-14T08:11:56Z | [
"python",
"django",
"django-rest-framework"
] |
Generate a datetime format string from timestamp | 38,265,619 | <p>I want to generate time/date <strong>format strings</strong> from the input data I got.
Is there an easy way to do this?</p>
<p>My input data looks like this:</p>
<pre><code>'01.12.2016 23:30:59,123'
</code></pre>
<p>So my code should generate the following format string:</p>
<pre><code>'%d.%m.%Y %H:%M:%S,%f'
</... | -2 | 2016-07-08T11:34:52Z | 38,266,195 | <p>use "datatime" to return the data and time. I this this will help you.</p>
<pre><code>import datetime
print datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S,%f')
</code></pre>
| 0 | 2016-07-08T12:04:25Z | [
"python",
"datetime",
"pandas",
"string-to-datetime"
] |
Generate a datetime format string from timestamp | 38,265,619 | <p>I want to generate time/date <strong>format strings</strong> from the input data I got.
Is there an easy way to do this?</p>
<p>My input data looks like this:</p>
<pre><code>'01.12.2016 23:30:59,123'
</code></pre>
<p>So my code should generate the following format string:</p>
<pre><code>'%d.%m.%Y %H:%M:%S,%f'
</... | -2 | 2016-07-08T11:34:52Z | 38,266,503 | <p>You can use <code>datetime.strptime()</code> inside <code>datetime</code> package which would return a <code>datetime.datetime</code> object.</p>
<p>In your case you should do something like:</p>
<p><code>datetime.strptime('01.12.2016 23:30:59,123', '%d.%m.%Y %H:%M:%S,%f')</code>.</p>
<p>After you have the <code>... | 0 | 2016-07-08T12:20:26Z | [
"python",
"datetime",
"pandas",
"string-to-datetime"
] |
Generate a datetime format string from timestamp | 38,265,619 | <p>I want to generate time/date <strong>format strings</strong> from the input data I got.
Is there an easy way to do this?</p>
<p>My input data looks like this:</p>
<pre><code>'01.12.2016 23:30:59,123'
</code></pre>
<p>So my code should generate the following format string:</p>
<pre><code>'%d.%m.%Y %H:%M:%S,%f'
</... | -2 | 2016-07-08T11:34:52Z | 38,268,176 | <p>you can try to use <code>infer_datetime_format</code> parameter, but be aware - <code>pd.to_datetime()</code> will use <code>dayfirst=False</code> per default</p>
<p>Demo:</p>
<pre><code>In [422]: s
Out[422]:
0 01.12.2016 23:30:59,123
1 23.12.2016 03:30:59,123
2 31.12.2016 13:30:59,123
dtype: object
In [... | 1 | 2016-07-08T13:41:16Z | [
"python",
"datetime",
"pandas",
"string-to-datetime"
] |
Generate a datetime format string from timestamp | 38,265,619 | <p>I want to generate time/date <strong>format strings</strong> from the input data I got.
Is there an easy way to do this?</p>
<p>My input data looks like this:</p>
<pre><code>'01.12.2016 23:30:59,123'
</code></pre>
<p>So my code should generate the following format string:</p>
<pre><code>'%d.%m.%Y %H:%M:%S,%f'
</... | -2 | 2016-07-08T11:34:52Z | 38,716,804 | <p>You should probably have a look here: <a href="https://github.com/humangeo/DateSense/" rel="nofollow">https://github.com/humangeo/DateSense/</a></p>
<p>From its documentation:</p>
<pre><code>>>> import DateSense
>>> print DateSense.detect_format( ["15 Dec 2014", "9 Jan 2015"] )
%d %b %Y
</code></... | 0 | 2016-08-02T09:35:27Z | [
"python",
"datetime",
"pandas",
"string-to-datetime"
] |
Is there an existing library to parse Wikpedia tables from dump? | 38,265,719 | <p>I need to extract the data from tables in a wiki dump in a somewhat convenient form, e.g. a list of lists. However, due to the format of the dump it looks sort of tricky. I am aware of the <a href="https://github.com/attardi/wikiextractor" rel="nofollow">WikiExtractor</a>, which is useful for getting clean text from... | 0 | 2016-07-08T11:40:02Z | 39,325,348 | <p>I did not manage to find a good way to parse Wikipedia tables from XML dumps. However, there seem to be some ways to do so using HTML parsers, e.g. <a href="http://wikitables.readthedocs.io/en/latest/#wikitables" rel="nofollow">wikitables</a> parser. This would require a lot of scraping unless you need to analyze on... | 0 | 2016-09-05T07:03:23Z | [
"python",
"xml-parsing",
"extract",
"wikipedia"
] |
Import Vlc module in python | 38,265,773 | <p>I am trying to create a media player using vlc and python but it throws an Error which is No module named vlc. how to fix this?</p>
| -1 | 2016-07-08T11:43:40Z | 38,265,916 | <p>I had a same issue. You should try <code>pip install vlc</code></p>
| 2 | 2016-07-08T11:52:04Z | [
"python",
"vlc"
] |
Import Vlc module in python | 38,265,773 | <p>I am trying to create a media player using vlc and python but it throws an Error which is No module named vlc. how to fix this?</p>
| -1 | 2016-07-08T11:43:40Z | 38,266,221 | <p>There is also python-vlc</p>
<p><a href="https://pypi.python.org/pypi/python-vlc/1.1.2" rel="nofollow">https://pypi.python.org/pypi/python-vlc/1.1.2</a></p>
<p>Download the .tar.gz file into your project and unzip it. Once unzipped, run:</p>
<pre><code>python setup.py install
</code></pre>
<p>This will install t... | 0 | 2016-07-08T12:05:48Z | [
"python",
"vlc"
] |
Import Vlc module in python | 38,265,773 | <p>I am trying to create a media player using vlc and python but it throws an Error which is No module named vlc. how to fix this?</p>
| -1 | 2016-07-08T11:43:40Z | 38,651,348 | <p>Install</p>
<pre><code>$ sudo pip install python-vlc
</code></pre>
<p>Then you can import the python module</p>
<pre><code>import vlc
</code></pre>
| 0 | 2016-07-29T05:49:26Z | [
"python",
"vlc"
] |
Slow or no response from read pickle file | 38,265,788 | <p>I'm working on a project that contain a webserver that handle "time" and "traffic light" parameter and save it to a pickle file and another script load the pickle and use it for mqtt client</p>
<pre><code>import pickle
import paho.mqtt.client as mqtt
from datetime import datetime, date, time
from threading import T... | 0 | 2016-07-08T11:44:16Z | 38,267,015 | <p>Without looking at it too closely, something like the below should do the job.</p>
<p>Calling <code>client.loop()</code> just processes a bit of network traffic, there is no guarantee that after it has been called all traffic will have been sent. Use <code>loop_start()</code> or <code>loop_forever()</code> dependin... | 1 | 2016-07-08T12:43:13Z | [
"python",
"python-2.7",
"pickle",
"mqtt",
"paho"
] |
Python - Let pip only search locally for extra packages | 38,265,820 | <p>Im trying to build an NSIS distributable, and this contains several packages.
One of them is <code>pyVISA-1.8</code> which needs the package <code>enum34</code> to work. </p>
<p>Now, I usually bundle all the wheels I need for the packages in the nsis script, but when I do this for <code>pyVISA</code> , (i.e tell p... | 0 | 2016-07-08T11:46:16Z | 38,300,929 | <p>The problem was that enum-0.4.6 was also installed and preceded enum34 in the path : (omn a brand new install with both packages installed:)</p>
<pre><code>C:\Users\Administrator>python -c "import enum; print enum.__path__"
Traceback (most recent call last):
File "<string>", line 1, in <module>
Attri... | 1 | 2016-07-11T07:02:45Z | [
"python",
"pip",
"nsis",
"python-wheel"
] |
Converting certain columns into different data type and filter those columns | 38,265,821 | <p>I have a data frame which looks as following,</p>
<p><a href="http://i.stack.imgur.com/c7jo5.png" rel="nofollow"><img src="http://i.stack.imgur.com/c7jo5.png" alt="enter image description here"></a></p>
<p>I need to convert those columns which are starting with Distance* into data type integer(Currently they are i... | -1 | 2016-07-08T11:46:21Z | 38,266,117 | <p>If you want to change the type of every column starting with <code>Distance</code>, you can use a loop:</p>
<pre><code>list_col = []
for col in a.columns:
if (len(col) > 8) & (col[:8] == 'Distance'):
list_col.appen(col)
a[list_col] = a[list_col].astype(int)
</code></pre>
<p>Then you create a dat... | 1 | 2016-07-08T12:00:40Z | [
"python",
"numpy",
"pandas",
"dataframe"
] |
Converting certain columns into different data type and filter those columns | 38,265,821 | <p>I have a data frame which looks as following,</p>
<p><a href="http://i.stack.imgur.com/c7jo5.png" rel="nofollow"><img src="http://i.stack.imgur.com/c7jo5.png" alt="enter image description here"></a></p>
<p>I need to convert those columns which are starting with Distance* into data type integer(Currently they are i... | -1 | 2016-07-08T11:46:21Z | 38,267,320 | <p>Note that I've renamed your first Head1 column to be Header (you have duplicate columns in your example). </p>
<p>I set up my Dataframe differently than yours, but close enough. I didn't fill out the columns that are irrelevant to the question.</p>
<p>Here's my setup code:</p>
<pre><code>import pandas as pd
df =... | 1 | 2016-07-08T12:57:46Z | [
"python",
"numpy",
"pandas",
"dataframe"
] |
Max recursion is not exactly what sys.getrecursionlimit() claims. How come? | 38,265,839 | <p>I've made a small function that will actually measure the max recursion limit:</p>
<pre><code>def f(x):
r = x
try:
r = f(x+1)
except Exception as e:
print(e)
finally:
return r
</code></pre>
<p>To know what to expect I've checked:</p>
<pre><code>In [28]: import sys
In [29]:... | 27 | 2016-07-08T11:47:43Z | 38,265,931 | <p>The recursion limit is not the limit on recursion but the maximum depth of the python interpreter stack.There is something on the stack before your function gets executed. Spyder executes some python stuff before it calls your script, as do other interpreters like ipython.</p>
<p>You can inspect the stack via metho... | 35 | 2016-07-08T11:52:47Z | [
"python",
"recursion"
] |
Max recursion is not exactly what sys.getrecursionlimit() claims. How come? | 38,265,839 | <p>I've made a small function that will actually measure the max recursion limit:</p>
<pre><code>def f(x):
r = x
try:
r = f(x+1)
except Exception as e:
print(e)
finally:
return r
</code></pre>
<p>To know what to expect I've checked:</p>
<pre><code>In [28]: import sys
In [29]:... | 27 | 2016-07-08T11:47:43Z | 38,266,011 | <p>This limit is for stack, not for the function you define. There are other internal things which might push something to stack.</p>
<p>And of course it could depend on env in which it was executed. Some can pollute stack more, some less.</p>
| 8 | 2016-07-08T11:56:28Z | [
"python",
"recursion"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.