title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How do I turn a repeated list element with delimiters into a list? | 38,483,118 | <p>I imported a CSV file that's basically a table with 5 headers and data sets with 5 elements. </p>
<p>With this code I turned that data into a list of individuals with 5 bits of information (list within a list):</p>
<pre><code>import csv
readFile = open('Category.csv','r')
categoryList = []
for row in csv.reader(re... | 1 | 2016-07-20T13:46:50Z | 38,483,249 | <p>Not really clear about your structure but if c is a string seperated by : within then try </p>
<blockquote>
<p>list(c.split(':'))</p>
</blockquote>
<p>Let me know if it solved your problem </p>
| 0 | 2016-07-20T13:52:38Z | [
"python",
"list",
"csv"
] |
How do I turn a repeated list element with delimiters into a list? | 38,483,118 | <p>I imported a CSV file that's basically a table with 5 headers and data sets with 5 elements. </p>
<p>With this code I turned that data into a list of individuals with 5 bits of information (list within a list):</p>
<pre><code>import csv
readFile = open('Category.csv','r')
categoryList = []
for row in csv.reader(re... | 1 | 2016-07-20T13:46:50Z | 38,483,286 | <p>The solution you suggested is feasible. You just don't need to do it after you read the file. You can do it while taking it as a input in the first place.</p>
<pre><code>for row in csv.reader(readFile):
row[2] = row[2].split(":") # Split element 2 of each row before appending
categoryList.append(row)
</code... | 1 | 2016-07-20T13:54:08Z | [
"python",
"list",
"csv"
] |
How do I turn a repeated list element with delimiters into a list? | 38,483,118 | <p>I imported a CSV file that's basically a table with 5 headers and data sets with 5 elements. </p>
<p>With this code I turned that data into a list of individuals with 5 bits of information (list within a list):</p>
<pre><code>import csv
readFile = open('Category.csv','r')
categoryList = []
for row in csv.reader(re... | 1 | 2016-07-20T13:46:50Z | 38,483,385 | <p>Assume that you have a row like this:</p>
<pre><code>row = ["foo", "bar", "1:2:3:4:5", "baz"]
</code></pre>
<p>To convert item <code>[2]</code> into a sublist, you can use</p>
<pre><code>row[2] = row[2].split(":") # elements can be assigned to, yawn.
</code></pre>
<p>Now the row is <code>['foo', 'bar', ['1', '2... | 0 | 2016-07-20T13:58:32Z | [
"python",
"list",
"csv"
] |
Import a list of words, dont wanna do it all over again in the code | 38,483,121 | <p>I don't want to post too much code, but I have code for an assignment done, the problem with my code is that every time I run a method called <code>findchildren</code>, it imports my list every time. So I tried to change my code, and my <code>findchildren</code> is working, it's currently looking like this:</p>
<pr... | 1 | 2016-07-20T13:47:08Z | 38,484,551 | <p>Your goal is to find if there exists a path from <code>start</code> to <code>stop</code> where a path is described as words who have length two permutations overlapping.</p>
<p>I think your code would be better organized as a graph and a function that operates on this graph. It would eliminate all of your problems:... | 1 | 2016-07-20T15:21:22Z | [
"python"
] |
Can't uninstall Django app | 38,483,204 | <p>I can't uninstall Django app. I've removed every occurence of the application in my code, removed all models and urls. Then, I removed parts of app from <code>settings.py</code> but it raises error when I remove them for <code>settings.py</code>.</p>
<p>It has probably something to do with migrations but I don't ge... | 0 | 2016-07-20T13:50:42Z | 38,483,842 | <p>There was a problem with migrations files which contained uninstalled app's referencies. </p>
<p>This is probably not a best way to do that but it worked:</p>
<ol>
<li>I backuped all migrations from all applications (to be able to do rollback)</li>
<li>Removed all migrations</li>
<li>makemigrations and migrate</li... | 0 | 2016-07-20T14:19:11Z | [
"python",
"django",
"django-apps"
] |
How can I replace 1s in a binary array with natural numbers, maintaining the position of 0s? | 38,483,254 | <p>I'm using Numpy and SciPy. I have two arrays, the first of which is binary, the second a consecutive range of natural numbers from <code>a</code> to <code>b</code> e.g.</p>
<pre><code>mask = np.array([1, 1, 1, 1, 0, 0, 1, 0]) # length of 8, with 5 ones and 3 zeros
vals = np.array([2, 3, 4, 5, 6, 7, 8, 9]) # length ... | 1 | 2016-07-20T13:52:52Z | 38,483,322 | <p>Here's one way:</p>
<pre><code>In [15]: result = np.zeros_like(vals)
In [16]: result[mask > 0] = vals[:mask.sum()]
In [17]: result
Out[17]: array([2, 3, 4, 5, 0, 0, 6, 0])
</code></pre>
| 2 | 2016-07-20T13:55:34Z | [
"python",
"arrays",
"numpy",
"scipy"
] |
How can I replace 1s in a binary array with natural numbers, maintaining the position of 0s? | 38,483,254 | <p>I'm using Numpy and SciPy. I have two arrays, the first of which is binary, the second a consecutive range of natural numbers from <code>a</code> to <code>b</code> e.g.</p>
<pre><code>mask = np.array([1, 1, 1, 1, 0, 0, 1, 0]) # length of 8, with 5 ones and 3 zeros
vals = np.array([2, 3, 4, 5, 6, 7, 8, 9]) # length ... | 1 | 2016-07-20T13:52:52Z | 38,483,401 | <p>Here is a one liner, though I must say it is not an optimized way and not very elegant. But you can examine it for practice purposes. </p>
<pre><code>a = [1, 1, 1, 1, 0, 0, 1, 0]
b = [2, 3, 4, 5, 6, 7, 8, 9]
c = [b[sum(a[:i])] if a[i] else 0 for i in range(len(a))]
print c
# Gives [2, 3, 4, 5, 0, 0, 6, 0]
</code><... | 2 | 2016-07-20T13:59:45Z | [
"python",
"arrays",
"numpy",
"scipy"
] |
Python - opposite of __contains__ | 38,483,274 | <p><strong>GENERAL QUESTION</strong></p>
<p>I was wondering if there exists a Python opposite to <code>__contains__</code> (i.e., something like <code>__notcontains__</code>).</p>
<p><strong>MY EXAMPLE</strong></p>
<p>I need it for the following piece of code:</p>
<pre><code>df_1 = df[(df.id1 != id1_array) | (df.id... | 2 | 2016-07-20T13:53:42Z | 38,483,417 | <p>EDIT: I didn't notice this was using panda's specifically. My answer may not be accurate. </p>
<p>Generally, the magic functions (anything with __'s before and after) are not meant to be called directly. In this case, __contains__ is referenced by using the <code>in</code> keyword.</p>
<pre><code>>>> a = ... | 2 | 2016-07-20T14:00:27Z | [
"python",
"python-2.7",
"pandas",
"dataframe"
] |
Python - opposite of __contains__ | 38,483,274 | <p><strong>GENERAL QUESTION</strong></p>
<p>I was wondering if there exists a Python opposite to <code>__contains__</code> (i.e., something like <code>__notcontains__</code>).</p>
<p><strong>MY EXAMPLE</strong></p>
<p>I need it for the following piece of code:</p>
<pre><code>df_1 = df[(df.id1 != id1_array) | (df.id... | 2 | 2016-07-20T13:53:42Z | 38,483,500 | <p>To answer how to do this in pure pandas you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a> and use the negation operator <code>~</code> to invert the boolean series:</p>
<pre><code>df_1 = df[(df.id1 != id1_array) | (df.id2.isin(id... | 3 | 2016-07-20T14:03:44Z | [
"python",
"python-2.7",
"pandas",
"dataframe"
] |
Python - opposite of __contains__ | 38,483,274 | <p><strong>GENERAL QUESTION</strong></p>
<p>I was wondering if there exists a Python opposite to <code>__contains__</code> (i.e., something like <code>__notcontains__</code>).</p>
<p><strong>MY EXAMPLE</strong></p>
<p>I need it for the following piece of code:</p>
<pre><code>df_1 = df[(df.id1 != id1_array) | (df.id... | 2 | 2016-07-20T13:53:42Z | 38,483,503 | <p>No there is no <code>__notcontains__</code> method or similar. When using <code>x not in y</code>, the method <code>__contains__</code> is actually used, as shown bellow:</p>
<pre><code>class MyList(list):
def __contains__(self, x):
print("__contains__ is called")
return super().__contains__(x)
... | 2 | 2016-07-20T14:03:47Z | [
"python",
"python-2.7",
"pandas",
"dataframe"
] |
Error: Failed to enable GUI event loop integration for 'qt' while importing pandas | 38,483,517 | <p>I use PyCharm Pro 2016.1.4 and pandas 18.1. I'm running into an issue whenever I import pandas. It happened after I updated PyCharm Pro (from 2016.1.3) and IPython 5.</p>
<p>Here's what the console shows me when I start it and then import pandas: </p>
<pre><code>C:\Anaconda2\python.exe "C:\Program Files (x86)\JetB... | 0 | 2016-07-20T14:04:16Z | 39,664,828 | <p>It has to do with Qt DLL version conflicts. I was able to get it working by doing
<code>conda update --all</code></p>
<p>This seems to have fixed a missing dependancy: I see a copy of QtCore4.dll in C:\Anaconda3\Library\bin and C:\Anaconda3\Library\lib that weren't there before.</p>
<p>Based on the research below... | 0 | 2016-09-23T15:47:50Z | [
"python",
"qt",
"pandas"
] |
Python: opencv (cv2) image slicing not working? | 38,483,554 | <p>I've got an image loaded in grayscale via <code>img = cv2.imread("myimg.jpg", 0)</code>.</p>
<p>Examining the value of <code>img</code> after loading, it's an <code>ndarray</code> that looks like this:</p>
<pre><code>[[53,53,58,...,62,66,70],
[52,52,57,...,68,68,90],
...,
[80,80,80,...,91,92,91],
[81,82,80,...... | 0 | 2016-07-20T14:05:54Z | 38,483,799 | <p>You are trying to split your array while supplying top = 337 and bottom = 271. Numpy works the other way around. Try to split it like this: <code>img[bottom:top, left:right]</code> or just invert the values of <code>top</code> and <code>bottom</code> so that you have <code>img[a:b, c:d]</code> with <code>a < b</c... | 0 | 2016-07-20T14:17:18Z | [
"python",
"opencv",
"numpy",
"imread"
] |
python socket server with java client - socket.error: [Errno 32] Broken pipe | 38,483,555 | <p>I'm trying to send commands to a rasberry pi using a python based socket server, where the server will get various string command, do something and then wait for the next command.</p>
<p>I have a socket server written in python running on a raspberry pi:</p>
<pre><code>import socket
HOST = '' # Symbolic name me... | 0 | 2016-07-20T14:05:56Z | 38,483,793 | <p><strong>errno.32 is: Broken pipe(the broken pipe error occurs if one end of the
TCP socket closes connection(using disconnect) or gets killed and the other</strong></p>
<p>In you java client, you send some data and close the socket right away which may cause the result.I am not familiar with java.But here is two th... | 1 | 2016-07-20T14:17:04Z | [
"java",
"python",
"sockets"
] |
Fast way to select from numpy array without intermediate index array | 38,483,570 | <p>Given the following 2-column array, I want to select items from the second column that correspond to "edges" in the first column. This is just an example, as in reality my <code>a</code> has potentially millions of rows. So, ideally I'd like to do this as fast as possible, and without creating intermediate results... | 2 | 2016-07-20T14:06:44Z | 38,483,618 | <p>I am afraid if you are looking to do this in a vectorized way, you can't avoid an intermediate array, as there's no built-in for it.</p>
<p>Now, let's look for vectorized approaches other than <code>nonzero()</code>, which might be more performant. Going by the same idea of performing differentiation as with the or... | 0 | 2016-07-20T14:08:39Z | [
"python",
"arrays",
"performance",
"numpy"
] |
Fast way to select from numpy array without intermediate index array | 38,483,570 | <p>Given the following 2-column array, I want to select items from the second column that correspond to "edges" in the first column. This is just an example, as in reality my <code>a</code> has potentially millions of rows. So, ideally I'd like to do this as fast as possible, and without creating intermediate results... | 2 | 2016-07-20T14:06:44Z | 38,484,412 | <p>Ok actually I found a solution, just learned about <code>np.fromiter</code>, which can build a numpy array based on a generator:</p>
<pre><code>d = np.fromiter((a[i+1,1] for i,(x,y) in enumerate(zip(a[1:,0],a[:-1,0])) if x!=y), int)
</code></pre>
<p>I think this does it, generates a numpy array without any interme... | 0 | 2016-07-20T14:43:18Z | [
"python",
"arrays",
"performance",
"numpy"
] |
Fast way to select from numpy array without intermediate index array | 38,483,570 | <p>Given the following 2-column array, I want to select items from the second column that correspond to "edges" in the first column. This is just an example, as in reality my <code>a</code> has potentially millions of rows. So, ideally I'd like to do this as fast as possible, and without creating intermediate results... | 2 | 2016-07-20T14:06:44Z | 38,485,931 | <p>I think what you are looking for is called the convolution operation. The np.convolve function does this. Convolve function in most of the libraries is optimised not to include any loops and using cython and blas(I think its the same with numpy, although I haven't seen the code). It is evidently much faster than all... | 0 | 2016-07-20T16:26:13Z | [
"python",
"arrays",
"performance",
"numpy"
] |
Fast way to select from numpy array without intermediate index array | 38,483,570 | <p>Given the following 2-column array, I want to select items from the second column that correspond to "edges" in the first column. This is just an example, as in reality my <code>a</code> has potentially millions of rows. So, ideally I'd like to do this as fast as possible, and without creating intermediate results... | 2 | 2016-07-20T14:06:44Z | 38,487,956 | <p>If memory efficiency is your concern, that can be solved as such: The only intermediate of the same size-order as the input data can be made of type bool (a[1:,0] != a[:-1, 0]); and if your input data is int32, that is 8 times smaller than 'a' itself. You can count the nonzeros of that binary array to preallocate th... | 0 | 2016-07-20T18:15:58Z | [
"python",
"arrays",
"performance",
"numpy"
] |
depth recognation with opencv2 | 38,483,591 | <p>I cannot fetch a correct disparity map from a couple simple images, as shown below:</p>
<h3>LEFT</h3>
<p><a href="http://i.stack.imgur.com/TtLut.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/TtLut.jpg" alt="LEFT"></a></p>
<h3>RIGHT</h3>
<p><a href="http://i.stack.imgur.com/3pKvf.jpg" rel="nofollow"><img... | 0 | 2016-07-20T14:07:46Z | 38,487,658 | <h2>Question 1</h2>
<p>You seem to have forgotten to rectify your images from a stereo calibration procedure.</p>
<h2>Question 2</h2>
<p>The distance between two cameras is called <em>Baseline</em>. In general, the bigger the baseline, the better the accuracy at a distance is, with a sacrifice on field of view. The ... | 0 | 2016-07-20T18:00:21Z | [
"python",
"image",
"opencv",
"image-processing"
] |
Django, apache-wsgi - server is serving /js and /css but cannot serve images | 38,483,597 | <p>Static catalog structure:</p>
<pre><code>website
--css
--js
--images
--landinpage.png
</code></pre>
<p>Apache access log:
</p>
<pre><code>"GET /static/website/js/jquery.js HTTP/1.1" 200"
"GET /static/website/images/landinpage.png HTTP/1.1" 404
</code></pre>
<p></p>
<p>HTML code:</p>
<pre><code><code>
... | 0 | 2016-07-20T14:07:58Z | 38,487,854 | <p><strong>If static server apache2:</strong></p>
<p>in <em>settings.py</em> add static dir</p>
<pre><code>STATIC_ROOT = os.path.join(BASE_DIR, 'static')
</code></pre>
<p>collect static to dir</p>
<pre><code>manage.py collectstatic
</code></pre>
<p>in apache conf add path</p>
<pre><code>Alias /static/ /var/www/st... | 0 | 2016-07-20T18:10:30Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
Append numpy array into an element | 38,483,650 | <p>I have a Numpy array of shape (5,5,3,2). I want to take the element (1,4) of that matrix, which is also a matrix of shape (3,2), and add an element to it -so it becomes a (4,2) array.
The code I'm using is the following:</p>
<pre><code>import numpy as np
a = np.random.rand(5,5,3,2)
a = np.array(a, dtype = object) #... | 1 | 2016-07-20T14:10:08Z | 38,484,079 | <p>The problem here, is that you try to assign to a[2][3]
Make a new array instead.</p>
<pre><code>new_array = np.append(a[2][3],np.array([[1.0,1.0]]),axis=0)
</code></pre>
| 0 | 2016-07-20T14:29:24Z | [
"python",
"arrays",
"numpy",
"multidimensional-array"
] |
Append numpy array into an element | 38,483,650 | <p>I have a Numpy array of shape (5,5,3,2). I want to take the element (1,4) of that matrix, which is also a matrix of shape (3,2), and add an element to it -so it becomes a (4,2) array.
The code I'm using is the following:</p>
<pre><code>import numpy as np
a = np.random.rand(5,5,3,2)
a = np.array(a, dtype = object) #... | 1 | 2016-07-20T14:10:08Z | 38,484,492 | <p>In an array of <code>object</code>, any element can be indeed an array (or any kind of object).</p>
<pre><code>import numpy as np
a = np.random.rand(5,5,3,2)
a = np.array(a, dtype=object)
# Assign an 1D array to the array element ``a[2][3][0][0]``:
a[2][3][0][0] = np.arange(10)
a[2][3][0][0][9] # 9
</code></pre>
... | 1 | 2016-07-20T14:46:29Z | [
"python",
"arrays",
"numpy",
"multidimensional-array"
] |
Append numpy array into an element | 38,483,650 | <p>I have a Numpy array of shape (5,5,3,2). I want to take the element (1,4) of that matrix, which is also a matrix of shape (3,2), and add an element to it -so it becomes a (4,2) array.
The code I'm using is the following:</p>
<pre><code>import numpy as np
a = np.random.rand(5,5,3,2)
a = np.array(a, dtype = object) #... | 1 | 2016-07-20T14:10:08Z | 38,486,220 | <p>Make sure you understand what you have produced. That requires checking the shape and dtype, and possibly looking at the values</p>
<pre><code>In [29]: a = np.random.rand(5,5,3,2)
In [30]: b=np.array(a, dtype=object)
In [31]: a.shape
Out[31]: (5, 5, 3, 2) # a is a 4d array
In [32]: a.dtype
Out[32]: dtype('f... | 1 | 2016-07-20T16:41:34Z | [
"python",
"arrays",
"numpy",
"multidimensional-array"
] |
Making lists of the nth items of different lists in a dictionary | 38,483,710 | <p>I have embedded dictionaries within a list of lists such as this one :</p>
<pre><code>X = \
[
[
{'the_geom': (999,999), 1: [111,112,113], 2: [121,122,123]},
{'the_geom': (998,998), 1: [211,212,213], 2:[221,222,223]}
],
[
{'the_geom': (997,997), 1: [1111,1112,1113, 1114], 2: [1121... | -1 | 2016-07-20T14:12:40Z | 38,484,112 | <p>You can do it this way:</p>
<pre><code>new_x = []
for item in X:
new_inner_item = []
for inner_item in item:
new_inner_item.append({
'the_geom': inner_item['the_geom'],
'values': [list(a) for a in zip(*[v for k,v in inner_item.items() if k != 'the_geom'])]
})
new_... | 1 | 2016-07-20T14:30:53Z | [
"python",
"dictionary",
"list-comprehension"
] |
Making lists of the nth items of different lists in a dictionary | 38,483,710 | <p>I have embedded dictionaries within a list of lists such as this one :</p>
<pre><code>X = \
[
[
{'the_geom': (999,999), 1: [111,112,113], 2: [121,122,123]},
{'the_geom': (998,998), 1: [211,212,213], 2:[221,222,223]}
],
[
{'the_geom': (997,997), 1: [1111,1112,1113, 1114], 2: [1121... | -1 | 2016-07-20T14:12:40Z | 38,484,122 | <p>It can be written in one line, but it is easier to understand when the formatting is parallel to the original question. It handles the case where there are multiple keys in the inner dict (eg. keys other than 1 and 2).</p>
<pre><code>XX = \
[
[
{
'the_geom': col['the_geom'],
'val... | 0 | 2016-07-20T14:31:07Z | [
"python",
"dictionary",
"list-comprehension"
] |
Making lists of the nth items of different lists in a dictionary | 38,483,710 | <p>I have embedded dictionaries within a list of lists such as this one :</p>
<pre><code>X = \
[
[
{'the_geom': (999,999), 1: [111,112,113], 2: [121,122,123]},
{'the_geom': (998,998), 1: [211,212,213], 2:[221,222,223]}
],
[
{'the_geom': (997,997), 1: [1111,1112,1113, 1114], 2: [1121... | -1 | 2016-07-20T14:12:40Z | 38,484,355 | <p>You can use zip together with list comprehension:</p>
<pre><code>[
[
{ 'the_geom':dict['the_geom'],
'values':zip(*[dict[i+1] for i in range(len(dict)-1)])
}
for dict in list
]
for list in X
]
</code></pre>
| 0 | 2016-07-20T14:40:42Z | [
"python",
"dictionary",
"list-comprehension"
] |
Making lists of the nth items of different lists in a dictionary | 38,483,710 | <p>I have embedded dictionaries within a list of lists such as this one :</p>
<pre><code>X = \
[
[
{'the_geom': (999,999), 1: [111,112,113], 2: [121,122,123]},
{'the_geom': (998,998), 1: [211,212,213], 2:[221,222,223]}
],
[
{'the_geom': (997,997), 1: [1111,1112,1113, 1114], 2: [1121... | -1 | 2016-07-20T14:12:40Z | 38,484,421 | <p>Ugly variable names but it works:</p>
<pre><code>XX=[]
for x in X:
xx=[]
for i in x:
ii={}
ii['the_geom']=i['the_geom']
ii['values']=[]
for indx in range(0,len(i[1])):
pair=[]
for j in range(1,len(i)):
pair.append(i[j][indx])
... | 0 | 2016-07-20T14:43:56Z | [
"python",
"dictionary",
"list-comprehension"
] |
Making lists of the nth items of different lists in a dictionary | 38,483,710 | <p>I have embedded dictionaries within a list of lists such as this one :</p>
<pre><code>X = \
[
[
{'the_geom': (999,999), 1: [111,112,113], 2: [121,122,123]},
{'the_geom': (998,998), 1: [211,212,213], 2:[221,222,223]}
],
[
{'the_geom': (997,997), 1: [1111,1112,1113, 1114], 2: [1121... | -1 | 2016-07-20T14:12:40Z | 38,484,532 | <pre><code>res1= [[{'the_geom':y['the_geom'],'values':[[y[1][i],y[2][i]] for i in range(3)]} for y in z] for z in X]
</code></pre>
<p>Output :</p>
<pre><code>[[{'values': [[111, 121], [112, 122], [113, 123]], 'the_geom': (999, 999)}, {'values': [[211, 221], [212, 222], [213, 223]], 'the_geom': (998, 998)}], [{'values... | 0 | 2016-07-20T15:20:09Z | [
"python",
"dictionary",
"list-comprehension"
] |
Python commandline parameter not raising error if argument is wrongly used | 38,483,792 | <p>I have the following Python code that has 1 command line optional parameter (<code>c</code>) that has an argument and 2 options (<code>a</code> and <code>b</code>) that do not have an argument:</p>
<pre><code>import sys, getopt
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.... | 0 | 2016-07-20T14:17:04Z | 38,484,082 | <p>checking the size of sys.argv (the list of argument supplied when calling the script) can help you checking that : </p>
<pre><code>import sys
import getopt
def main(argv):
inputfile = ''
outputfile = ''
opts, args = getopt.getopt(argv, "abc:", ["csvfile="])
for opt, arg in opts:
print "Raw... | 1 | 2016-07-20T14:29:34Z | [
"python",
"command-line",
"arguments",
"optional-parameters"
] |
How to use datetime instance as a timestamp in postgresql? | 38,483,817 | <p>I want to create postgresql function (<code>CREATE FUNCTION</code>) with PL/Python.</p>
<p>How do I convert from python <code>datetime</code> object to postgresql <code>timestamp</code> object in procedure?</p>
| 1 | 2016-07-20T14:18:01Z | 38,486,628 | <p>Tell the <code>prepare</code> method the type of the parameter value, a <code>timestamp</code>, then pass a <code>datetime</code> value to the <code>execute</code> method: </p>
<pre><code>create or replace function pytest()
returns timestamp as $$
from datetime import datetime
plan = plpy.prepare('select $... | 0 | 2016-07-20T17:03:57Z | [
"python",
"postgresql"
] |
fatal: bad revision 'HEAD-1 on revert | 38,483,908 | <p>I want to revert my last commit on a public branch with the commit being pushed up. I wanted to use revert to show what I did wrong and I reverted it, but following <a href="https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/commit-level-operations" rel="nofollow">https://www.atlassian.com/... | 0 | 2016-07-20T14:22:10Z | 38,485,375 | <p>To consolidate the answer to this question: The reason why you've received an error is due to syntax error.</p>
<p>The correct instruction would be</p>
<pre><code>git revert HEAD~1
</code></pre>
<p>instead</p>
<pre><code>git revert HEAD-1
</code></pre>
| 1 | 2016-07-20T15:59:00Z | [
"python",
"git"
] |
Basic auth with Django not working | 38,483,937 | <p>I'm having trouble using basic auth with django, here's my config:</p>
<pre><code>MIDDLEWARE_CLASSES = [
'request_id.middleware.RequestIdMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
... | 0 | 2016-07-20T14:23:25Z | 38,485,536 | <p>Django <strong>does not</strong> support Basic HTTP auth by itself, what <code>django.contrib.auth.backends.RemoteUserBackend</code> actually does is described in the docs.</p>
<blockquote>
<p>With this setup, RemoteUserMiddleware will detect the username in
request.META['REMOTE_USER'] and will authenticate and... | 2 | 2016-07-20T16:05:42Z | [
"python",
"django",
"basic-authentication",
"http-basic-authentication"
] |
ubuntu python cron job stops without error | 38,483,943 | <p>I have an amazon instance that is running my site. I recently tried to set up a cron job and it just stops without throwing any error or anything halfway through the task.</p>
<p><code>crontab -l</code> shows</p>
<pre><code>30 13 * * 1,2,3,4,5,6 /home/ubuntu/.virtualenvs/testprep/bin/python /home/ubuntu/web/testpr... | 0 | 2016-07-20T14:23:41Z | 38,616,992 | <p>Okay, the issue was actually in my django <code>settings.py</code> file. The database was just an <code>sqlite</code> database with a relative path. Apparently when running the code from a cron job, it needs an absolute path. So changing the code to this fixed the issue:</p>
<pre><code>import os
BASE_DIR = os.path.... | 0 | 2016-07-27T15:13:09Z | [
"python",
"django",
"cron"
] |
Title using matplotlib and pandas - python | 38,483,963 | <p>Any idea why my script below places the title so far from the graphs/subplots? Is it possible to specify the font size of the title?</p>
<pre><code>df = pandas.read_csv('data.csv', delimiter=',',
index_col=0,
parse_dates=[0], dayfirst=True,
... | -1 | 2016-07-20T14:24:26Z | 38,484,158 | <p>You'll have to use <code>matplotlib</code> to edit the font size, as pandas does not allow passing for font sizes or similar, unfortunately (afaik).</p>
<p>try this:</p>
<pre><code>ax = df.plot()
ax.set_title('Graph', fontsize=20) # or size, alternatively
</code></pre>
<p>Essentially, <code>pandas.DataFrame.plot... | 1 | 2016-07-20T14:32:07Z | [
"python",
"pandas",
"matplotlib"
] |
How to make a terminal console (terminal emulator) in PyQt5? | 38,484,032 | <p>I am building an application in Python, with a graphical user interface in PyQt5. I need to insert some sort of "Terminal Console" in the application. The user can start a batch file by clicking a button, and should see the output appear in a text field.</p>
<p>At this moment, I use the following approach. When the... | 2 | 2016-07-20T14:27:44Z | 38,540,008 | <p>In your code <code>p.wait()</code> is the point of synchronization with the opened process. After that line the external process is finished. So you need to read <code>p.stout</code> in a loop <strong>before</strong> that line. Check the following example:</p>
<pre><code>#!/usr/bin/env python2
from subprocess impor... | 1 | 2016-07-23T08:58:47Z | [
"python",
"python-3.x",
"batch-file",
"pyqt5",
"terminal-emulator"
] |
get data from octave script execution using oct2py (python3) | 38,484,116 | <p>I'm trying to execute some <code>Matlab</code> scripts (not a function definition) from <code>Python 3</code> using <code>oct2py</code> module. </p>
<p>Those scripts (a large amount) contains a very extended definition to read a specific ASCIII files (contained in the same directory). </p>
<p>I do not know how to ... | 1 | 2016-07-20T14:30:58Z | 38,543,580 | <p>Assuming your script places the results on the (virtual) octave workspace, you can simply attempt to access the workspace.</p>
<p>Example:</p>
<pre><code>%% In file myscript.m
a = 1
b = 2
</code></pre>
<p>Python code:</p>
<pre><code>>>> octave.run('myscript.m')
>>> vars = octave.who(); vars
[u'... | 0 | 2016-07-23T15:48:23Z | [
"python",
"matlab",
"octave"
] |
Doc2Vec model Python 3 compatibility | 38,484,117 | <p>I trained a doc2vec model with Python2 and I would like to use it in Python3.</p>
<p>When I try to load it in Python 3, I get : </p>
<pre><code>Doc2Vec.load('my_doc2vec.pkl')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 0: ordinal not in range(128)
</code></pre>
<p>It seems to be related ... | 2 | 2016-07-20T14:31:00Z | 38,486,065 | <p>Answering my own question, this <a href="http://stackoverflow.com/questions/33596082/load-gensim-word2vec-computed-in-python-2-in-python-3?rq=1">answer</a> worked for me.</p>
<p>Here are the steps a bit more details :</p>
<ol>
<li>download gensim source code, e.g clone from repo</li>
<li><p>in gensim/utils.py, edi... | 1 | 2016-07-20T16:33:27Z | [
"python",
"python-3.x",
"pickle",
"gensim",
"doc2vec"
] |
System of equations in sympy with symbolic output | 38,484,174 | <p>Is it possible to solve a system of equations(linear or non linear) with sympy where the output is symbolic?</p>
<p>Example:</p>
<pre><code> 1. f_m = a0 + a1*(-dx) + a2*(-dx)^2
2. f_c = a0
3. f_p = a0 + a1*(dx) + a2*(dx)^2
</code></pre>
<p>Solve for a2. </p>
<p>By the Mathematica command </p>
<p>Solve the s... | 1 | 2016-07-20T14:32:47Z | 38,484,721 | <p>This is a fundamental operation in Sympy, you should study the documention.
Just to get you started:</p>
<pre><code>import sympy as sp
f_m, f_c, f_p = sp.var('f_m, f_c, f_p')
a0, a1, a2 = sp.var('a0:3')
dx = sp.var('dx')
eq1 = sp.Eq(f_m, a0 + a1*(-dx) + a2*(-dx)**2)
eq2 = sp.Eq(f_c, a0)
eq3 = sp.Eq(f_p, a0 + a1*... | 2 | 2016-07-20T15:29:38Z | [
"python",
"wolfram-mathematica",
"sympy",
"symbolic-math"
] |
Cannot connect to ssh via python | 38,484,179 | <p>so I just setted up a fresh new raspberry pi and I want it to communicate with python using ssh from my computer to my ssh server, the pi.. I first try to connect using putty and it work, I could execute all the commands I wanted, then I tried using librarys such as Paramiko, Spur and they didn't work.</p>
<p>Spur ... | 0 | 2016-07-20T14:33:10Z | 38,484,228 | <p>You need to accept the host key, similarly to what is shown <a href="https://iliaselmatani.wordpress.com/2014/04/16/spur/" rel="nofollow">here</a></p>
<pre><code>import spur
shell = spur.SshShell("192.168.1.114",
"pi",
"raspberry",
missing_host_ke... | 0 | 2016-07-20T14:35:25Z | [
"python",
"ssh"
] |
django-mptt raises 'NoneType' object has no attribute 'tree_id' when saving node | 38,484,192 | <p><img src="https://cloud.githubusercontent.com/assets/5443029/16989577/6ffb8ac2-4e9d-11e6-9b1f-749177230c84.png" alt="screen shot 2016-07-20 at 17 06 39"></p>
<p>Environment: python 2.7.10, Django 1.9.1, django-mptt 0.8.4</p>
<pre><code># models.py
class Foo(MPTTModel):
parent = TreeForeignKey('self', null=True... | 0 | 2016-07-20T14:33:39Z | 38,495,831 | <blockquote>
<p>It seems that setting parent_id does not reset parent in any way,
resp. parent isn't dynamically loaded from the database just because
the underlying id field has some value.</p>
</blockquote>
<p><a href="https://github.com/django-mptt/django-mptt/issues/428" rel="nofollow">https://github.com/dja... | 0 | 2016-07-21T05:48:53Z | [
"python",
"django",
"django-mptt"
] |
Slicing a dataframe based on range of time | 38,484,207 | <p>I am new to Pandas. I have a set of Excel data read into a dataframe as follows:</p>
<pre><code>TimeReceived A B
08:00:01.010 70 40
08:00:01.050 80 50
08:01:01.100 50 20
08:01:01.150 40 30
</code></pre>
<p>I want to compute the average for columns A & B based on time intervals of 100 ms.
T... | 0 | 2016-07-20T14:34:14Z | 38,498,512 | <p>If you have a<code>DatetimeIndex</code> you can then use <code>resample</code> to up or down sample your data to a new frequency. This will introduce <code>NaN</code> rows where there are gaps but you can drop these using <code>dropna</code>:</p>
<pre><code>df.resample('100ms').mean().dropna()
</code></pre>
| 0 | 2016-07-21T08:08:53Z | [
"python",
"pandas",
"dataframe"
] |
How to stop Twisted callback? | 38,484,221 | <p>I wrote a callback function using twisted Now my question is when websocket connection dropped I need to stop this callback. </p>
<pre><code>def sendBack(self, payload):
# find correct way to identify connection dropped now using wasnotcl...
if self.wasNotCleanReason:
# stop this callback
self.s... | 0 | 2016-07-20T14:35:08Z | 38,486,185 | <p>You can <code>cancel</code> it...</p>
<pre><code>callID = reactor.callLater(delay, self.sendBack, payload=payload)
if self.wasNotCleanReason:
callID.cancel()
</code></pre>
<p><code><a href="http://twistedmatrix.com/documents/10.1.0/core/howto/time.html" rel="nofollow">ref</a></code></p>
| 1 | 2016-07-20T16:40:05Z | [
"python",
"twisted",
"autobahn",
"twisted.web",
"twisted.internet"
] |
How to Google in Python Using urllib or requests | 38,484,268 | <p>What is the proper way to Google something in Python 3? I have tried <code>requests</code> and <code>urllib</code> for a Google page. When I simply <code>res = requests.get("https://www.google.com/#q=" + query)</code> that doesn't come back with the same HTML as when I inspect the Google page in Safari. The same hap... | 1 | 2016-07-20T14:37:18Z | 38,484,545 | <p>In python, if you do not specify the user agent header in http requests manually, python will add for you by default which can be detected by Google and may be forbidden by it.</p>
<p>Try the following if it can help.</p>
<pre><code>import urllib
yourUrl = "post it here"
headers = {'User-Agent':'Mozilla/5.0 (Windo... | 0 | 2016-07-20T15:20:56Z | [
"python",
"python-3.x",
"request",
"urllib",
"google-search"
] |
Error AttributeError: 'NoneType' object has no attribute 'title' -> due to an empty class | 38,484,275 | <p>I am looping through an xpath getting all the bold text that has the class black.</p>
<p>this then gets the title within the bold class. This works fine until I have come across one the is blank inside.</p>
<p>Using the below code how can i edit it to remove/skip the class's that contain no data?</p>
<pre><code>o... | 0 | 2016-07-20T14:37:28Z | 38,484,321 | <p>Just add a filter to your list comprehension:</p>
<pre><code>out = [b.text.title() + "##" + b.xpath("./following::text()[1]")[0].lstrip(",")
for b in div.xpath(".//b[@class='black']")
if b.text]
</code></pre>
<p>The <code>if b.text</code> ensures there is a truthy (non-empty or not <code>None</code>... | 0 | 2016-07-20T14:39:27Z | [
"python",
"xpath"
] |
Pandas DatetimeIndex converting dates to 1970 | 38,484,277 | <p>I have recently faced a similar problem (<a href="http://stackoverflow.com/questions/38201666/pandas-datetimeindex-from-mongodb-isodate">answered here</a>) whereby conversion of a date to a pandas <a href="http://pandas.pydata.org/pandas-docs/stable/api.html#datetimeindex" rel="nofollow">DatetimeIndex</a> and subseq... | 2 | 2016-07-20T14:37:35Z | 38,486,494 | <p>The accepted answer of your other question works for me (Python 3.5.2, Pandas 0.18.1):</p>
<pre><code>print(frame.set_index([frame.ID, frame.index]))
# Events ID
# ID
# 1 2008-01-01 00:00:00-05:00 1 1
# 1970-01-01 00:00:00-05:00 ... | 1 | 2016-07-20T16:56:35Z | [
"python",
"datetime",
"pandas",
"dataframe",
"python-datetime"
] |
Pandas DatetimeIndex converting dates to 1970 | 38,484,277 | <p>I have recently faced a similar problem (<a href="http://stackoverflow.com/questions/38201666/pandas-datetimeindex-from-mongodb-isodate">answered here</a>) whereby conversion of a date to a pandas <a href="http://pandas.pydata.org/pandas-docs/stable/api.html#datetimeindex" rel="nofollow">DatetimeIndex</a> and subseq... | 2 | 2016-07-20T14:37:35Z | 38,487,216 | <pre><code>frame = frame.reset_index()
frame = frame.set_index([frame.ID, frame.index])
print frame
index Events ID
ID
1 0 2008-01-01 00:00:00-05:00 1 1
1 2008-01-02 00:00:00-05:00 2 1
2 2008-01-03 00:00:00-05:00 3 1
3... | 1 | 2016-07-20T17:37:10Z | [
"python",
"datetime",
"pandas",
"dataframe",
"python-datetime"
] |
How to tell when a QTableWidgetItem is being modified | 38,484,452 | <p>I'm writing an app in Python with the <em>PySide</em> library. I have a <code>QTableWidget</code> that gets updated about every second. The thing is, I want to be able to change the data manually, and I thought that if I could find out whether or not the user is changing the data in the cell, then I could just preve... | 1 | 2016-07-20T14:44:44Z | 38,486,018 | <p>In Qt Document:</p>
<p><strong>void QTableWidget::itemChanged(QTableWidgetItem * item)<br>
This signal is emitted whenever the data of item has changed.</strong></p>
<p>Hope this will help you.</p>
<p>Edit:</p>
<p>QTableWidget uses a default itemdelegate(QItemDelegate instance) which has createEditor method and ... | 1 | 2016-07-20T16:30:45Z | [
"python",
"qt",
"pyqt",
"pyside"
] |
How to tell when a QTableWidgetItem is being modified | 38,484,452 | <p>I'm writing an app in Python with the <em>PySide</em> library. I have a <code>QTableWidget</code> that gets updated about every second. The thing is, I want to be able to change the data manually, and I thought that if I could find out whether or not the user is changing the data in the cell, then I could just preve... | 1 | 2016-07-20T14:44:44Z | 38,487,194 | <p>Generally, you would handle this situation with the use of <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qitemdelegate.html" rel="nofollow"><code>QItemDelegates</code></a>, which allow you to control what cells are editable by the user, what types of controls they are given to edit the cells, and you can catch the... | 1 | 2016-07-20T17:36:09Z | [
"python",
"qt",
"pyqt",
"pyside"
] |
.join for possible empty Queue in python | 38,484,535 | <p>I'm trying to implement a <code>Queue</code> processing thread in python as follows:</p>
<pre><code>from queue import Queue
from threading import Thread
import sys
class Worker(Thread):
def __init__(self, queue):
# Call thread constructor
self.queue = queue
def run(self):
while... | 1 | 2016-07-20T15:20:26Z | 38,484,756 | <p>You can give <code>Queue.get</code> a timeout and use a stop event:</p>
<pre><code>from Queue import Queue, Empty
from threading import Thread, Event
import sys
class Worker(Thread):
def __init__(self, queue, stop):
# Call thread constructor
self.queue = queue
self.stop = stop
s... | 1 | 2016-07-20T15:30:44Z | [
"python",
"multithreading",
"python-3.x",
"blockingqueue"
] |
Have a list of dicts need to write csv file in python | 38,484,646 | <p>I need to ouput a list of dicts in python to a csv file. But I wanted to split them by filename. I have a list of dicts that looks like this:</p>
<pre><code>{'Filename': 'F:\\Desktop\\Metadata\informationtechnologies1.pdf',
'DESCRIPTION': [u'This is a test sentence.'],
'NAME': [u'This is a test name'],
'PER... | 0 | 2016-07-20T15:26:25Z | 38,486,017 | <p>What you show is not a csv file but a plain text file.</p>
<p>Assuming your requirements are:</p>
<ul>
<li>if a directory contains the key <code>Filename</code> print on first line the key, a colon, a space and the value</li>
<li>for all other key, value items in the directory, first print a line with the key foll... | 0 | 2016-07-20T16:30:43Z | [
"python",
"python-2.7",
"csv",
"dictionary"
] |
Calculate Number of Last Week in Isocalendar Year | 38,484,950 | <p>I am writing a script to grab files from a directory based on the week number in the filenames. I need to grab files with week N and week N+1 in the filenames. </p>
<p>I have the basics down, but am now struggling to figure out the rollover for new years (the file format uses the isocalendar standard). Isocalend... | 0 | 2016-07-20T15:39:36Z | 38,485,086 | <p>Why not just use <code>(datetime.now() + timedelta(days=7)).isocalendar()[1]</code> rather than calculating it from the current week number at all?</p>
| 1 | 2016-07-20T15:45:13Z | [
"python"
] |
Python interpreter does not show in Pycharm | 38,485,010 | <p>When I run <code>Pycharm</code> and select new project, there is no interpreter for me to select (please see the screenshot below), so what should I do and how do I fix this, please? I have installed Python 3.5.1 version on my Windows 7.</p>
<p>Thanks!</p>
<p><img src="http://i.stack.imgur.com/gxb00.jpg" alt="inte... | -1 | 2016-07-20T15:42:32Z | 38,485,184 | <p>You can click right "Gear" icon in setting dialog, then select "Add local" add Python interpreter</p>
| 0 | 2016-07-20T15:50:14Z | [
"python",
"python-3.x",
"pycharm"
] |
Python pafy global not working across a function-call boundary | 38,485,103 | <p>Okay, I was trying to make a simple script to download youtube videos using <a href="http://pythonhosted.org/Pafy/" rel="nofollow"><code>pafy</code></a>. Currently I have a problem with the global variable <code>video</code> which I use to store what <code>pafy.new('url')</code> returns. Here's the two functions I u... | 1 | 2016-07-20T15:46:06Z | 38,491,155 | <p>Found the problem in this line:</p>
<pre><code>video.getbest(preftype="mp4").download(quiet=True, filepath=dir_path);
</code></pre>
<p>This:</p>
<pre><code>video.getbest(preftype="mp4")
</code></pre>
<p>actually returned a <code>NoneType</code> object since it didn't contain any <code>mp4</code> stream. So, it's... | 0 | 2016-07-20T21:27:51Z | [
"python",
"python-3.x",
"attributes",
"global-variables",
"instance"
] |
Python cx_oracle variables | 38,485,112 | <pre><code>try:
for row in data:
id = row[0]
name= row[1]
b.execute("INSERT INTO NAME (NUMBER, NAME, ID) VALUES (1, %s, %s)" %(name, id))
conn.commit()
except: #rest code
</code></pre>
<p>I can not add values to the database (as much as I understand it is because of the <strong>name</strong> variable),... | 0 | 2016-07-20T15:46:40Z | 38,504,872 | <p>Use bind variables instead. Do not use %s and put the parameter directly in the string as this leads to possible SQL injection, not to mention quoting issues. This method permits passing any legal value without having to worry about such things!</p>
<pre><code>try:
for row in data:
id = row[0]
n... | 2 | 2016-07-21T12:55:29Z | [
"python",
"database",
"oracle",
"variables",
"cx-oracle"
] |
Creating xml request using urllib2 | 38,485,119 | <p>I need to create request to access to the XML services, it should be processed through a HTTP. Ass says in documentation I have to send "4 associated parameters and this parameters will work as identification and will provide the request". This parameters should look like strings:</p>
<pre><code>"codes=12345"
"use... | 0 | 2016-07-20T15:47:02Z | 38,485,244 | <p>Try this:</p>
<pre><code>from urllib import urlencode
from urllib2 import urlopen
args = {'codes':'12345','user':'user12345','password':'pass12345','partner':'part12345'}
conn = urlopen(url,urlencode(args))
data = conn.read()
conn.close()
print(data)
</code></pre>
| 1 | 2016-07-20T15:52:53Z | [
"python",
"urllib2"
] |
Access violation exception Oculus VR DK2 | 38,485,122 | <p>This python code raises vioaltion access error(last line):</p>
<pre><code>import time
from ovrsdk import *
ovr_Initialize()
hmd = ovrHmd_Create(0)
hmdDesc = ovrHmdDesc()
ovrHmd_GetDesc(hmd, byref(hmdDesc))
</code></pre>
<p>Error:</p>
<pre><code> File "D:\Georgy2\mypyscripts\ovr01.py", line 12, in <module>... | 1 | 2016-07-20T15:47:10Z | 38,491,292 | <p>What Oculus runtime version do you have installed? The import statement and the calls you're making make it look as if you're using <a href="https://github.com/wwwtyro/python-ovrsdk" rel="nofollow">this</a> library, but that hasn't been updated in two years. I'm not sure it will even work with a DK2 compatible run... | 2 | 2016-07-20T21:38:38Z | [
"python",
"oculus"
] |
Python, BeautifulSoup - Extracting part of a string | 38,485,167 | <p>I'm working on a side project to see if I can predict the wins on a website, however this is one of the first times I've used BeautifulSoup and I'm not entirely sure on how to cut a string down to size. </p>
<p>Here is the code, I basically want to grab the information that holds where it crashed.</p>
<pre><code>f... | 1 | 2016-07-20T15:49:34Z | 38,485,197 | <p>Find the <code>Crashed At</code> label by text and get the <em>next sibling</em>:</p>
<pre><code>soup = BeautifulSoup(html, "html.parser")
for section in soup.findAll('div', {"class":"row panel radius"}):
crashPoint = section.find("b", text="Crashed At: ").next_sibling.strip()
print(crashPoint) # prints 1... | 2 | 2016-07-20T15:50:52Z | [
"python",
"beautifulsoup"
] |
Form autosubmit on radio/checkbox action (Python Flask) | 38,485,217 | <p>I currently am working on a dashboard tool. here I use Python to go through a dataframe, and create filters based on the data. I have the following code as an example output:</p>
<pre><code><form name="FormYear" method="post">
<div class="panel">
<div id="checkboxes">
<div class="fi... | 0 | 2016-07-20T15:51:36Z | 38,506,676 | <p>You can use <a href="https://pythonhosted.org/Flask-Sijax/" rel="nofollow">Flask-Sijax</a>, it helps you add <a href="https://pypi.python.org/pypi/Sijax" rel="nofollow">Sijax</a> support to your Flask applications. Sijax is an easy to use AJAX library.</p>
<pre><code>@flask_sijax.route(app, '/hello')
def hello():
... | 0 | 2016-07-21T14:15:06Z | [
"jquery",
"python",
"forms",
"flask",
"submit"
] |
Plotting scatter graph with marginal histograms with Python seaborn 0.7 | 38,485,252 | <p>I have some python code that plotted a scatter graph with marginal histograms. This worked fine with seaborn 0.5 and still does work if I go back to this version. However, I'd like to get it to work with 0.7!</p>
<p>I don't use python often and mainly only use scripts set up by others that I adjust slightly.</p>
<... | 0 | 2016-07-20T15:53:38Z | 39,910,484 | <p><code>seaborn lmplot ax</code> will show you that <code>lmplot</code> returns you a <code>figure-level</code> instead of <code>axes-level</code>. So in order to manage <code>lmplot</code> use <code>FacetGrid</code>.</p>
<p><code>FacetGrid</code> will plot on different variables that you states in different graphs.<... | 0 | 2016-10-07T06:06:27Z | [
"python",
"scatter-plot",
"seaborn"
] |
tkinter.TclError: invalid command name "table" | 38,485,253 | <p>Okay, first of all I don't know what is the actual problem here so I couldn't come up with a more accurate title. Maybe some of you can edit it to make it accurate</p>
<p>The following is the minimalised code to reproduce the problem I'm having.</p>
<pre><code>from traybar import SysTrayIcon
from cal import Calend... | 1 | 2016-07-20T15:53:40Z | 38,486,162 | <p>TkTableCalendar requies the tktable module, which you have installed in lib-tk (3rd party modules usually go into lib/site-packages) as indicated by this part of the traceback.</p>
<pre><code>File "C:\Python27\lib\lib-tk\tktable.py", line 118, in __init__
Tkinter.Widget.__init__(self, master, 'table', kw)
</code></... | 1 | 2016-07-20T16:38:51Z | [
"python",
"multithreading",
"tkinter",
"tcl",
"tktable"
] |
Run a certain function according to a dictionary value in Python | 38,485,263 | <p>I built a script which runs a certain function according to a specific condition, the thing is I am sure there is a smarter way to do this.</p>
<p>The current code I have is:</p>
<pre><code>list_of_dicts= [{'brand':'a', 'url':'b'}, [{'brand':'b', 'url':'b'}]
for element in list_of_dicts:
if element['brand'] =... | 0 | 2016-07-20T15:54:14Z | 38,485,389 | <p>Functions are objects too (sorta...) and so you can just connect the <code>brand</code> key to a function like this:</p>
<pre><code>list_of_dicts= [{'brand':function_a, 'url':'b'}, [{'brand':function_b, 'url':'b'}]
</code></pre>
<p>and then just grab the function with the key:</p>
<pre><code>for element in list_o... | 2 | 2016-07-20T15:59:24Z | [
"python",
"dictionary",
"functional-programming"
] |
Run a certain function according to a dictionary value in Python | 38,485,263 | <p>I built a script which runs a certain function according to a specific condition, the thing is I am sure there is a smarter way to do this.</p>
<p>The current code I have is:</p>
<pre><code>list_of_dicts= [{'brand':'a', 'url':'b'}, [{'brand':'b', 'url':'b'}]
for element in list_of_dicts:
if element['brand'] =... | 0 | 2016-07-20T15:54:14Z | 38,485,531 | <p>You can create a separate <code>dict</code> storing the functions from where you can then retrieve the appropriate function with brand:</p>
<pre><code>list_of_dicts= [{'brand':'a', 'url':'b'}, {'brand':'b', 'url':'b'}]
def function_a(url):
print('A ' + url)
def function_b(url):
print('B ' + url)
funcs = ... | 2 | 2016-07-20T16:05:28Z | [
"python",
"dictionary",
"functional-programming"
] |
Reconstruct vector field from python dictionary keyed by nested tuple | 38,485,307 | <p>There's a dictionary in the following form:</p>
<pre><code>vector_dict = {((3, 4), 2): 4678,
((0, 2), 1): 0,
...
}
</code></pre>
<p>The tuple nested in the tuple corresponds to xy-coordinates. The next part is an integer with possible values n= 0, 1, 2, 3 representin... | 1 | 2016-07-20T15:56:00Z | 38,485,806 | <p>Check out the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html" rel="nofollow">Series constructor</a> to load the data from a <code>dict</code>. Then you can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unstack.html" rel="nofollow"><code>unstack</code>... | 1 | 2016-07-20T16:19:59Z | [
"python",
"pandas",
"dictionary",
"nested",
"tuples"
] |
How do I force these ttk apps to resize when I resize the window? | 38,485,410 | <p>I have comments in a number of places where I've tried to use the columnconfigure or rowconfigure methods to cause the windows to resize, but none of it seems to be working. I can also take out mainloop() and my program runs exactly the same. This leads me to believe I'm perhaps not calling/using mainloop correctly.... | 0 | 2016-07-20T16:00:19Z | 38,485,756 | <p>You place <code>self.mainframe</code> in the root window, but you never give any rows and columns in the root window a weight. You also never explicitly create a root window, though that isn't contributing to the problem. Also, <code>"all"</code> isn't a valid row or column. </p>
<p>The first step is to get your m... | 0 | 2016-07-20T16:17:11Z | [
"python",
"tkinter",
"ttk"
] |
Iterate throughout different python files as variable | 38,485,605 | <p>I wonder how to invoke python files as variable. imagine that <code>i</code> is the name of one file </p>
<p>obviously the example doesn't work but it shows a case. every file has the same class structure</p>
<pre><code>for i in test:
'%d'.ClassName.method(variables) %(i,)
</code></pre>
| -3 | 2016-07-20T16:09:07Z | 38,487,320 | <p>The question could have been clearer but I think I know what you are asking. You have a bunch of values (in this case the file names) which you want to use as variables. I had a similar requirement previously, but in my case I had to use the string as a method name.</p>
<pre><code>method = getattr(self, "add_rule_%... | 0 | 2016-07-20T17:43:23Z | [
"python",
"python-2.7",
"python-3.x"
] |
entry points from setup.py not working | 38,485,654 | <p>I am trying to get an entry point to run my flask application.</p>
<p>I think its due to the directory structure:</p>
<pre><code>my_app
- __init__.py
- app.py
- setup.py
- etc..
</code></pre>
<p>My setup.py file:</p>
<pre><code>from setuptools import setup, find_packages
import os.path
def read_requir... | 0 | 2016-07-20T16:11:52Z | 38,498,662 | <p>I just ended up putting all the flask app files into a sub directory inside the project root directory. fixed it nicely.</p>
<pre><code>/project
- setup.py
/flask_app
- __init__.py
- app.py
</code></pre>
| 0 | 2016-07-21T08:15:23Z | [
"python",
"flask",
"setuptools",
"setup.py"
] |
Python - Find sequence of same characters | 38,485,735 | <p>I'm trying to use regex to match sequences of one or more instances of the same characters in a string. </p>
<p>Example : </p>
<pre><code>string = "55544355"
# The regex should retrieve sequences "555", "44", "3", "55"
</code></pre>
<p>Can I have a few tips?</p>
| 0 | 2016-07-20T16:16:06Z | 38,485,787 | <p>You can do this easily without regex using <a href="https://docs.python.org/3.4/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a>:</p>
<pre><code>>>> from itertools import groupby
>>> s = '55544355'
>>> [''.join(g) for _, g in groupby(s)]
['555', ... | 1 | 2016-07-20T16:18:53Z | [
"python",
"regex"
] |
Python - Find sequence of same characters | 38,485,735 | <p>I'm trying to use regex to match sequences of one or more instances of the same characters in a string. </p>
<p>Example : </p>
<pre><code>string = "55544355"
# The regex should retrieve sequences "555", "44", "3", "55"
</code></pre>
<p>Can I have a few tips?</p>
| 0 | 2016-07-20T16:16:06Z | 38,485,895 | <p>You can use <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow"><code>re.findall()</code></a> and the <code>((.)\2*)</code> regular expression:</p>
<pre><code>>>> [item[0] for item in re.findall(r"((.)\2*)", string)]
['555', '44', '3', '55']
</code></pre>
<p>the key part is insid... | 3 | 2016-07-20T16:24:21Z | [
"python",
"regex"
] |
Python - Find sequence of same characters | 38,485,735 | <p>I'm trying to use regex to match sequences of one or more instances of the same characters in a string. </p>
<p>Example : </p>
<pre><code>string = "55544355"
# The regex should retrieve sequences "555", "44", "3", "55"
</code></pre>
<p>Can I have a few tips?</p>
| 0 | 2016-07-20T16:16:06Z | 38,486,393 | <p>Probably not the best option here, but for the sake of variety, how about this logic:</p>
<pre><code>>>> def f(s):
l = []
c = s[0]
for x in s:
if x in c:
c += x
continue
l.append(c)
c = x
l.append(c)
... | 0 | 2016-07-20T16:50:43Z | [
"python",
"regex"
] |
How to set the algorithm to barrier when use CPLEX in PuLP | 38,485,745 | <p>I use 'prob.solve(CPLEX())' to call CPLEX in PuLP.</p>
<p>However, I am wondering how to use barrier algorithm here to get a more non-zero solution.</p>
<p>Thanks.</p>
| -1 | 2016-07-20T16:16:21Z | 38,491,858 | <p>I'm not a PuLP expert, but it looks like this is possible (however, I'm not sure how reliable it is). There is a <a href="https://groups.google.com/forum/#!topic/pulp-or-discuss/gx1KTAH2SAE" rel="nofollow">hint</a> here about how you can set CPLEX parameters using the CPLEX DLL shared library. I believe this is ou... | 0 | 2016-07-20T22:24:12Z | [
"python",
"cplex",
"pulp"
] |
Create a secure unsubscribe link for emails sent with Flask | 38,485,798 | <p>I want to generate an unsubscribe link that a user can click when receiving an email to unsubscribe that address. I don't want to just include the email in the link because a user could edit the link to unsubscribe someone else. Most emails I see generate some sort of token and the site knows how to match the toke... | 1 | 2016-07-20T16:19:41Z | 38,486,112 | <p>Flask includes the library <a href="https://pythonhosted.org/itsdangerous/" rel="nofollow">itsdangerous</a> which is used to generate tokens by securely signing serialized data.</p>
<p>For each email, generate a token with the email to be unsubscribed, and create an <code>unsubscribe</code> route that accepts and d... | 2 | 2016-07-20T16:36:21Z | [
"python",
"email",
"flask"
] |
How convert output tensor to one-hot tensor? | 38,485,905 | <p>I need to calculate loss from the softmax output vs target.
My target is like [0,0,1] and output is [0.3,0.3,0.4]
For the purpose, prediction is correct. But a cost function of below type doesn't account for this kind of accuracy</p>
<pre><code>self._output = output = tf.nn.softmax(y)
self._cost = cost = tf.reduce_... | 0 | 2016-07-20T16:24:47Z | 38,486,938 | <p>The typical loss function used for comparing two probability distributions is called <a href="https://en.wikipedia.org/wiki/Cross_entropy" rel="nofollow">cross entropy</a>. TensorFlow has the <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/nn.html#softmax_cross_entropy_with_logits" rel="nofollow">t... | 1 | 2016-07-20T17:20:48Z | [
"python",
"tensorflow"
] |
Parsing XML from CZI image data | 38,485,916 | <p>I have the following XML file, where I want to extract the values for the key: <strong>Information|Image|S|Scene|Shape|Name</strong> using python, e.g. ElementTree.</p>
<p>I already tried various things, but I always get stuck. Any help is really appreciated.</p>
<p>Sebi</p>
<p>Here is some code I tried out alrea... | 0 | 2016-07-20T16:25:33Z | 38,498,939 | <p>As an assumption maybe You did not use NameSpaces to find an Element.
I tried to get keys and values from OriginalMetadata . </p>
<pre><code>import xml.etree.ElementTree as ET
tree = ET.fromstring(initial_string)
# Define NameSpace
name_space = "{http://www.openmicroscopy.org/Schemas/SA/2015-01}"
origin_meta_datas... | 1 | 2016-07-21T08:28:27Z | [
"python",
"xml"
] |
Docker Mac Beta and container connecting to host ports? | 38,485,943 | <p>I currently use PyCharm (Actually IntelliJ) and have been using Kitematic with VirtualBox support.</p>
<p>I have a container connecting to the host (which is a virtual machine) to do remote debugging.</p>
<p>The issue is when I try to use Docker Mac Beta, the container doesn't seem to be able to access any specifi... | 0 | 2016-07-20T16:26:58Z | 38,489,454 | <p>I think the problem is that you need to expose port 15001.</p>
<p>Try adding to Dockerfile</p>
<p>EXPOSE 15001</p>
| 0 | 2016-07-20T19:40:59Z | [
"python",
"osx",
"intellij-idea",
"docker",
"docker-compose"
] |
Docker Mac Beta and container connecting to host ports? | 38,485,943 | <p>I currently use PyCharm (Actually IntelliJ) and have been using Kitematic with VirtualBox support.</p>
<p>I have a container connecting to the host (which is a virtual machine) to do remote debugging.</p>
<p>The issue is when I try to use Docker Mac Beta, the container doesn't seem to be able to access any specifi... | 0 | 2016-07-20T16:26:58Z | 38,890,044 | <p>Create a host-based loopback device and then use a remote_host alternative (like in xdebug) to configure your container to connect back to that host ( on the port ), this will solve your issue as it does for PHP ( same issue ). We had the same case when switching from dockertoolbox to docker for mac. See a configura... | 0 | 2016-08-11T07:32:22Z | [
"python",
"osx",
"intellij-idea",
"docker",
"docker-compose"
] |
Interactive Slider using Bokeh | 38,486,119 | <p>I'm trying to use a bokeh interactive slider to modify the contents of a plot, similar the example <a href="http://bokeh.pydata.org/en/latest/docs/user_guide/interaction.html#customjs-for-widgets" rel="nofollow" title="Bokeh Docs">here</a>. I have a two nested lists <code>x</code> and <code>y</code>.</p>
<p>I simpl... | 0 | 2016-07-20T16:36:46Z | 39,150,823 | <p>Instead of having a slider changing the index of the data to be plotted, you could define two <code>ColumnDataSource</code>s: <strong><em><code>source_visible</code></em></strong> and <strong><em><code>source_available</code></em></strong> where the first one holds the data that is currently being shown in the plot ... | 0 | 2016-08-25T16:53:56Z | [
"javascript",
"python",
"jupyter-notebook",
"bokeh"
] |
Dict List Continues to Overwrite - What am I doing wrong? | 38,486,144 | <p>I haven't had this problem before and have been trying to troubleshoot it for a while now but can't seem to figure out the issue (tried a variety of things including creating copies, deep copies, and appending to DataFrame).</p>
<p>Basically, I'm trying to loop through a list, create a dictionary and append that di... | 1 | 2016-07-20T16:37:59Z | 38,486,173 | <p>Change:</p>
<pre><code>bigram_values_dict_list.append(bigram_values_dict)
</code></pre>
<p>to:</p>
<pre><code>bigram_values_dict_list.append(bigram_values_dict.copy())
</code></pre>
<p>In that way, you are <em>appending</em> a copy of your dictionary to the list, so future modifications of the dictionary will no... | 2 | 2016-07-20T16:39:21Z | [
"python",
"python-3.x",
"pandas",
"dictionary",
"data-analysis"
] |
PyAutoGui click permissions error | 38,486,151 | <p>I have a very strange problem that I haven't seen happen in python before. </p>
<p>I have a script that works flawlessly on one pc and when I try to use it on another my defined function fails. </p>
<p>I'm using PyAutoGUI to automate some processes. </p>
<pre><code>import csv
import pyautogui
pyautogui.PAUSE = 0... | 0 | 2016-07-20T16:38:09Z | 38,574,348 | <p>So it turns out this was due to a permissions error on this machine. Due to it being a business computer the user didn't have admin rights. This caused clicks to be registered and then immediately triggered a WinError 5 exception. I solved this by adding another exception to my try block. "except PermissionError: pa... | 0 | 2016-07-25T17:49:19Z | [
"python",
"windows",
"pyautogui"
] |
Sum datetime differences based on column value | 38,486,170 | <p>I have a dataframe that looks like:</p>
<pre><code> field1 field2 field3
time
t1 1 1 1
t2 1 1 0
t3 2 3 1
t4 3 3 0
t5 1 2 0
</code></pre>
<p>Times are in the form <code... | 1 | 2016-07-20T16:39:13Z | 38,534,266 | <p>Managed to get it, in case anyone else runs into something remotely similar. Still not sure if it's optimal, but it feels better than what I was doing.</p>
<p>I changed the original dataframe to include the time as a column, and just use integer indices.</p>
<pre><code>def create_time_deltas(dataframe):
# add ... | 0 | 2016-07-22T19:49:19Z | [
"python",
"pandas"
] |
How do I send an email from python using outlook web access? | 38,486,372 | <p>I need to send an email in python if my job fails, however due to company polices, I am only allowed to use the Outlook Web Access. How can I connect to Outlook Web Access from python to send an email?</p>
| 0 | 2016-07-20T16:49:44Z | 38,486,473 | <p>I can't take credit for this but I can lead you to a possible solution.</p>
<p>Here's the link: <a href="http://win32com.goermezer.de/content/view/227/192/" rel="nofollow">http://win32com.goermezer.de/content/view/227/192/</a>
Here's the code</p>
<pre><code>import win32com.client
s = win32com.client.Dispatch("Map... | 0 | 2016-07-20T16:55:20Z | [
"python",
"email",
"outlook",
"outlook-web-app"
] |
First Business Date of Month Python | 38,486,427 | <p>How do I determine the first business date of the month in python? the program I am writing is drip fed dates each loop and I need to be able to get a true/false.</p>
<p>I found that you can get last working business day with:</p>
<pre><code>import pandas as pd
pd.date_range("2014-01-14", periods=1, freq='BM')
</c... | -1 | 2016-07-20T16:52:51Z | 38,486,598 | <p>This uses the U.S. Federal Holiday calendar. It uses a list comprehension to go through every first weekday of the month between the <code>start_date</code> and <code>end_date</code>, and then increments the day if it falls on a U.S. Federal Holiday or on a weekend until a valid business date is found.</p>
<pre><c... | 2 | 2016-07-20T17:02:24Z | [
"python",
"date"
] |
First Business Date of Month Python | 38,486,427 | <p>How do I determine the first business date of the month in python? the program I am writing is drip fed dates each loop and I need to be able to get a true/false.</p>
<p>I found that you can get last working business day with:</p>
<pre><code>import pandas as pd
pd.date_range("2014-01-14", periods=1, freq='BM')
</c... | -1 | 2016-07-20T16:52:51Z | 38,486,737 | <p>I think by this you can get first buisness date of the month using <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases" rel="nofollow"><code>BMS</code></a>:</p>
<pre><code>In[82]:pd.date_range('1/1/2000', '12/1/2000', freq='BMS')
Out[82]:
DatetimeIndex(['2000-01-03', '2000-02-01', ... | 2 | 2016-07-20T17:10:14Z | [
"python",
"date"
] |
Get HTML table into pandas Dataframe, not list of dataframe objects | 38,486,477 | <p>I apologize if this question has been answered elsewhere but I have been unsuccessful in finding a satisfactory answer here or elsewhere.</p>
<p>I am somewhat new to python and pandas and having some difficulty getting HTML data into a pandas dataframe. In the pandas documentation it says .read_html() returns a lis... | 0 | 2016-07-20T16:55:31Z | 38,486,953 | <p>From <a href="http://pandas.pydata.org/pandas-docs/version/0.17.1/io.html#io-read-html" rel="nofollow">http://pandas.pydata.org/pandas-docs/version/0.17.1/io.html#io-read-html</a>, "read_html returns a list of DataFrame objects, even if there is only a single table contained in the HTML content".</p>
<p>So <code>d... | 0 | 2016-07-20T17:21:55Z | [
"python",
"pandas",
"dataframe",
"html-parsing"
] |
WTForm "OR" conditional validator? (Either email or phone) | 38,486,527 | <pre><code>class ContactForm(Form):
name = StringField('Name',
validators=[DataRequired(), Length(max=255)])
email = StringField('Email',
validators=[Optional(), Email(), Length(max=255)])
phone = StringField('Phone number',
validators=[Optional(), ... | 0 | 2016-07-20T16:58:31Z | 38,486,740 | <p>You can create a <code>validate</code> method on the form and do some manual checking. Something like this might get you started.</p>
<pre><code>class MyForm(Form):
name = StringField('Name',
validators=[DataRequired(), Length(max=255)])
email = StringField('Email',
va... | 0 | 2016-07-20T17:10:17Z | [
"python",
"flask",
"wtforms",
"flask-wtforms"
] |
Interpolating a straight line on a log-log graph (NumPy) | 38,486,528 | <p>Iâm using a program on a Raspberry Pi that measures the voltage across a probe within salt water to calculate the salinity of the water. The relationship is not linear but becomes a fairly straight line when a power trend line is plotted on a log-log plot. This means that the probes could be calibrated using only ... | 2 | 2016-07-20T16:58:31Z | 38,493,425 | <p>How about </p>
<pre><code>import numpy as np
import scipy
import scipy.interpolate
import matplotlib.pyplot as plt
def log_interp1d(x, y, kind='linear'):
"""
Returns interpolator function
"""
log_x = np.log10(x)
log_y = np.log10(y)
lin_int = scipy.interpolate.interp1d(log_x, log_y, kind=ki... | 0 | 2016-07-21T01:30:36Z | [
"python",
"numpy",
"interpolation",
"loglog"
] |
How to natively increment a dictionary element's value? | 38,486,601 | <p>When working with Python 3 dictionaries, I keep having to do something like this:</p>
<pre><code>d=dict()
if 'k' in d:
d['k']+=1
else:
d['k']=0
</code></pre>
<p>I seem to remember there being a native way to do this, but was looking through the documentation and couldn't find it. Do you know what this is?<... | 5 | 2016-07-20T17:02:31Z | 38,486,696 | <p>This is the use case for <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict"><code>collections.defaultdict</code></a>, here simply using the <code>int</code> callable for the default factory. </p>
<pre><code>>>> from collections import defaultdict
>>> d = defaultdi... | 11 | 2016-07-20T17:07:32Z | [
"python",
"python-3.x",
"dictionary"
] |
How to natively increment a dictionary element's value? | 38,486,601 | <p>When working with Python 3 dictionaries, I keep having to do something like this:</p>
<pre><code>d=dict()
if 'k' in d:
d['k']+=1
else:
d['k']=0
</code></pre>
<p>I seem to remember there being a native way to do this, but was looking through the documentation and couldn't find it. Do you know what this is?<... | 5 | 2016-07-20T17:02:31Z | 38,490,783 | <p>Take note that you can always remove the clutter from the <code>if</code> stamemt by using it in an expression:</p>
<pre><code>d['k'] = d['k'] + 1 if 'k' in d else 0
</code></pre>
| 0 | 2016-07-20T21:01:31Z | [
"python",
"python-3.x",
"dictionary"
] |
TypeError: func1() missing 1 required positional argument: 'self' | 38,486,718 | <p>Im pretty new to python and one of the harder things I'm having to learn is how to properly use self. My understanding is in the methods we should use self. However I have the following class with a method and Im getting a type error saying saying I'm missing the positional argument self.</p>
<pre><code>class examp... | 2 | 2016-07-20T17:08:47Z | 38,486,772 | <p>The function you defined as <code>func1</code> is a <a href="https://docs.python.org/3/tutorial/classes.html#method-objects" rel="nofollow">method</a>. Which needs to be used on an instance of that class. Such as,</p>
<pre><code>abc = example() # We create the instance
abc.func1() # This is how you call a method.
... | 1 | 2016-07-20T17:11:58Z | [
"python",
"python-3.x"
] |
TypeError: func1() missing 1 required positional argument: 'self' | 38,486,718 | <p>Im pretty new to python and one of the harder things I'm having to learn is how to properly use self. My understanding is in the methods we should use self. However I have the following class with a method and Im getting a type error saying saying I'm missing the positional argument self.</p>
<pre><code>class examp... | 2 | 2016-07-20T17:08:47Z | 38,486,773 | <p>I'm not expert in python but please try below it may help you,</p>
<pre><code>class example():
list1 = ['a','b','c','d']
list2 = ['1','2','3','4']
def func1(list1, list2):
i = 1
for item in list1:
print(list1)
print(list2[i])
i +=1
func1(list1=... | -1 | 2016-07-20T17:11:58Z | [
"python",
"python-3.x"
] |
TypeError: func1() missing 1 required positional argument: 'self' | 38,486,718 | <p>Im pretty new to python and one of the harder things I'm having to learn is how to properly use self. My understanding is in the methods we should use self. However I have the following class with a method and Im getting a type error saying saying I'm missing the positional argument self.</p>
<pre><code>class examp... | 2 | 2016-07-20T17:08:47Z | 38,486,891 | <p>If you're trying to call <code>func1</code> outside of the class:</p>
<pre><code>class Example():
def func1(self, list1, list2):
i = 0
for item in list1:
print(item)
print(list2[i])
i +=1
list1 = ['a','b','c','d']
list2 = ['1','2','3','4']
a = Example()
a.fun... | 0 | 2016-07-20T17:17:40Z | [
"python",
"python-3.x"
] |
the correct way to input images for testing the tensorflow model | 38,486,763 | <p>I have been trying to test the fcn implementation <a href="https://github.com/MarvinTeichmann/tensorflow-fcn/blob/master/test_fcn32_vgg.py" rel="nofollow">posted here</a>. The only thing I changed is the way for setting up the input images for test against the model. My modification is marked with red curve in the f... | 1 | 2016-07-20T17:11:33Z | 38,487,183 | <p>As the error indicates, the types of values that you can use as feeds are Python scalars, strings, lists or numpy arrays. What you are trying to use as feed is <code>img1</code>, the output of <code>tf.image.decode_png</code>, which is of type <code>tf.Tensor</code>. Hence the error. You have two options :</p>
<p>1... | 0 | 2016-07-20T17:35:25Z | [
"python",
"image-processing",
"tensorflow"
] |
What is a python recipe and how do i run it? | 38,486,785 | <p>I am new to Python and I came across a useful piece of code (Python recipe) <a href="http://code.activestate.com/recipes/475157-disk-dumper/" rel="nofollow">here</a> that I want to run. </p>
<p>I tried installing Python 3.5 and running it using the "python.exe scriptname.py" format but that lands me into syntax err... | 0 | 2016-07-20T17:12:33Z | 38,486,836 | <p>Your guess was right, <code>python scriptname.exe</code> is the way to go. However this script is for a much older version of Python (2.7), you'll need to fix some syntax issues like <code>print(...)</code> instead of <code>print ...</code> to make it run on Python 3.5.</p>
| 3 | 2016-07-20T17:14:55Z | [
"python",
"recipe"
] |
What is a python recipe and how do i run it? | 38,486,785 | <p>I am new to Python and I came across a useful piece of code (Python recipe) <a href="http://code.activestate.com/recipes/475157-disk-dumper/" rel="nofollow">here</a> that I want to run. </p>
<p>I tried installing Python 3.5 and running it using the "python.exe scriptname.py" format but that lands me into syntax err... | 0 | 2016-07-20T17:12:33Z | 38,486,895 | <p>Python recipe comes from here
<strong>The O'Reilly Python Cookbook</strong></p>
<p>Its only a fancy name for algorithms that come in use frequently in daily life solved in python coding language.</p>
| 2 | 2016-07-20T17:18:04Z | [
"python",
"recipe"
] |
Python Radio Button Not Showing Up? | 38,486,864 | <p>I'm follow a GUI through Python tutorial on YouTube, and I cannot get the radio buttons show up in the message box and it works fine for the author of the video. I get no error message, is there a piece of my code that is incorrect or what am I doing wrong? </p>
<pre><code>#create radio buttons; input equal to a va... | -2 | 2016-07-20T17:16:26Z | 38,486,933 | <p>You need to correct these two lines by adding braces () at the end of the lines:</p>
<pre><code>radio1 = Radiobutton(app, text="I'm feeling good", value="I'm feeling good", variable = dayStatus, command=beenClicked).pack()
radio1 = Radiobutton(app, text="I'm feeling crummy", value="I'm feeling crummy", variable = d... | 0 | 2016-07-20T17:20:42Z | [
"python",
"user-interface",
"tkinter",
"radio-button"
] |
regex of extracting html from path | 38,486,950 | <p>I'm new to Regex.
I need to extract 2 things from a directory path.
../path_to_html/myhtmlpage.html?additional_args_or_url</p>
<p>how can i get the name of the html?
eg.myhtmlpage</p>
<p>and how can i get the entire url?
eg.myhtmlpage.html?video_url=www.google.com/video</p>
<p>Thank you very much!</p>
| -1 | 2016-07-20T17:21:43Z | 38,487,090 | <p>Here you go:</p>
<pre><code>import re
url = "/path_to_html/myhtmlpage.html?video_url=www.google.com/video"
# Name
print re.findall(r'/(\w+)\.html', url)[0]
# Entire url
print re.findall(r'/(\w+\.html.*)', url)[0]
</code></pre>
<p>This prints:</p>
<pre><code>myhtmlpage
myhtmlpage.html?video_url=www.google.com/vide... | 0 | 2016-07-20T17:30:08Z | [
"python",
"regex"
] |
Python random list generation | 38,486,967 | <p>I'm looking at a little challenge which requires me to </p>
<p>1.create a function which generates a random lists of size 2 (a list in which it's two elements are randomly generated letters). </p>
<p>2.create a function which scores how well a randomly generated list compares to another pre-defined list, so typica... | -2 | 2016-07-20T17:22:52Z | 38,487,033 | <p>Use a variable count which you increase incrementally per run and when count % 1000 = 0 and count > 0 print the highest score that you got from the iterations possibly saved into a global variable.</p>
| 1 | 2016-07-20T17:26:27Z | [
"python",
"list",
"random"
] |
Python random list generation | 38,486,967 | <p>I'm looking at a little challenge which requires me to </p>
<p>1.create a function which generates a random lists of size 2 (a list in which it's two elements are randomly generated letters). </p>
<p>2.create a function which scores how well a randomly generated list compares to another pre-defined list, so typica... | -2 | 2016-07-20T17:22:52Z | 38,487,048 | <p>Could you define a variable called maximum such that:</p>
<pre><code>if score > maximum:
maximum = score
</code></pre>
<p>?</p>
| 1 | 2016-07-20T17:27:23Z | [
"python",
"list",
"random"
] |
Python random list generation | 38,486,967 | <p>I'm looking at a little challenge which requires me to </p>
<p>1.create a function which generates a random lists of size 2 (a list in which it's two elements are randomly generated letters). </p>
<p>2.create a function which scores how well a randomly generated list compares to another pre-defined list, so typica... | -2 | 2016-07-20T17:22:52Z | 38,487,100 | <p>What you need is the basic definition of max function. A value which is equal to the first score, then assigned to the new score if a better score is achieved.</p>
<pre><code>if new_score > max_score:
max_score = new_score
</code></pre>
<p>And to your suggestion, my experience in this shows that applying my... | 1 | 2016-07-20T17:30:44Z | [
"python",
"list",
"random"
] |
XML remove nodes with no attributes or children | 38,487,043 | <p>I have an xml file loaded, from which I want to remove elements that have no attributes or children, I'm trying to achieve something like this:</p>
<pre><code>for child in root.find('targetElement'):
print(child)
if(len(child.attrib) < 1 and len(child) < 1):
root.remove(child)
</code></pre>
<... | 0 | 2016-07-20T17:26:57Z | 38,487,112 | <p>You need to remove a node from its parent, not from the root. </p>
<p>The following code works for <code>lxml.etree</code>:</p>
<pre><code>from lxml import etree as ET
root = ET.parse('yourfile.xml')
for child in root.iterfind('targetElement'):
if(len(child.attrib) < 1 and len(child) < 1):
chil... | 0 | 2016-07-20T17:31:29Z | [
"python",
"xml",
"python-3.x",
"elementtree",
"xml.etree"
] |
Show fullscreen webpage in 5 seconds then close window (python) | 38,487,066 | <p>I want to make a python script that opens up a local html file in browser and after 5 seconds close that window.</p>
<p>I've tried the self.close() method and if I add "time.sleep()" it will only delay the display of the web content</p>
<p>Here's my code (I'm a newbie so, sorry for that)</p>
<pre><code>import sys... | 0 | 2016-07-20T17:28:37Z | 38,489,154 | <p>Use a single-shot timer (the interval is in milliseconds):</p>
<pre><code>class Window(QWidget):
def __init__(self, url, dur):
...
view.setHtml(html)
QTimer.singleShot(dur * 1000, self.close)
</code></pre>
| 0 | 2016-07-20T19:23:18Z | [
"python",
"pyqt4",
"qapplication"
] |
Looping over columns and column values for subsetting pandas dataframe | 38,487,074 | <p>I have a dataframe as follows
<code>df</code>:</p>
<pre><code> ID color finish duration
A1 black smooth 12
A2 white matte 8
A3 blue smooth 20
A4 green matte 10
B1 black smooth 12
B2 white matte 8
B3 blue smooth
B4 green 10
C1 black ... | 0 | 2016-07-20T17:29:04Z | 38,517,728 | <p>Not quite sure of your needs, but consider permuting your lists with a list comprehension to avoid the nested loops and use a dictionary of data frames. Possibly the <code>scorecalc()</code> apply function can be adjusted to fit your needs:</p>
<pre><code>colorlist = list(df['color'].unique())
finishlist = list(df[... | 1 | 2016-07-22T03:33:24Z | [
"python",
"pandas",
"for-loop"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.