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
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,709
<p>First take your big-list and join it together as a string.</p> <p><code>new_list = ''.join(biglist)</code></p> <p>then you have <code>new_list = 'ABCDA12AX31CDABC'</code></p> <p>split up new_list on 'A'</p> <p><code>split_list = new_list.split('A')</code></p> <p>then you have <code>split_list = ['', 'BCD', '12'...
0
2016-07-27T16:37:25Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,719
<p>You could put the results in a dictionary with <code>'list1'</code>, <code>'list2'</code>, <code>...</code> as keys. The <code>defaultdict</code> creates a new key with an empty list every time an <code>A</code> is encountered in the list. The items followinng <code>'A'</code> are added to this list until another <c...
0
2016-07-27T16:38:06Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,749
<p>Aside from the other excellent suggestions, you could write a generator which will give you things you can enumerate over late. This could be tidier, but...</p> <pre><code>def group(stuff): item = [] for thing in stuff: if thing != 'A': item.append(thing) continue if len(item) &gt; 0: ...
1
2016-07-27T16:39:56Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,782
<p>it's can be done fairly simply with a generator</p> <pre><code>def split(biglist): last = None for x in biglist: if x == "A": if last: yield last last = [x] else: if last is None: # in case the list didn't start with 'A' las...
2
2016-07-27T16:41:37Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,800
<p>I'd probably use <code>itertools.groupby</code>:</p> <pre><code>from itertools import groupby def group_stuff(iterable, partition='A'): out = [] for k, v in groupby(iterable, key=lambda x: x != partition): if not k: out = list(v) else: out.extend(v) yield...
1
2016-07-27T16:42:36Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,851
<p>You can convert the list of characters in a string and use the split() function to divide the string at each occurrence of 'A'.</p> <pre><code>biglist = ['A','B','C','D','A','1','2','A','X','3','1','C','D','A','B','C'] lists = [list('A'+x) for x in ''.join(s).split("A") if x] </code></pre> <p>will give you a list ...
0
2016-07-27T16:45:05Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,618,966
<p>One option to use <code>groupby</code> from itertools:</p> <pre><code># create a group variable by looping through the list from itertools import groupby acc, grp = 0, [] for e in biglist: acc += (e == 'A') grp.append(acc) # split the original list by the group variable [[i[0] for i in g] for _, g in group...
0
2016-07-27T16:50:59Z
[ "python", "python-2.7" ]
I need to split a python list into several python lists but the new lists need to contain fields between certain strings
38,618,526
<p>I have a fairly large Python 2.7 list containing strings like this: </p> <pre><code>biglist = ['A','B1','C00','D','A','1','2000','A','X','3','1','C','D','A','B','C'] </code></pre> <p>I need to cut this up in several seperate lists cutted each time it finds a 'A' string in the list and then that new list contains e...
0
2016-07-27T16:27:32Z
38,619,103
<p>This will create module level variables list1, .. listn.</p> <p><strong>If it possible to use <em>list of lists</em> or <em>dict of lists</em> you should prefer other answers.</strong></p> <p>This answer base on python function <a href="https://docs.python.org/2/library/functions.html#globals" rel="nofollow"><code...
0
2016-07-27T16:58:38Z
[ "python", "python-2.7" ]
how to get value of an xml element not directly under root
38,618,778
<p>I am trying to parse an xml and get the value of <code>dir_path</code> as below,however I dont seem to get the desired output,whats wrong here and how to fix it?</p> <p><strong>input.xml</strong></p> <pre><code>&lt;?xml version="1.0" ?&gt; &lt;data&gt; &lt;software&gt; &lt;name&gt;xyz&lt;/name&gt; ...
0
2016-07-27T16:41:21Z
38,619,959
<p>Try the following:</p> <pre><code>from xml.etree import ElementTree as ET tree = ET.parse('filename.xml') item = tree.find('software/[name="abc"]/dir_path') print(item.text if item is not None else None) </code></pre>
1
2016-07-27T17:49:57Z
[ "python" ]
merging json with python
38,618,824
<p>I have following code to merge values in my json:</p> <pre><code>from jsonmerge import merge with open('env.json') as data_file: data = json.load(data_file) result2 = merge("", data.get('default_attributes')) result3 = merge(result2, data.get('normal_attributes')) result4 = merge(result3, data.get(...
1
2016-07-27T16:43:41Z
38,618,930
<p>If <code>data.get('force_override_attributes')</code> is <code>None</code> then <code>merge(result4, data.get('force_override_attributes'))</code> is <code>None</code></p> <pre><code>&gt;&gt;&gt; a = {"a":10} &gt;&gt;&gt; b = merge(a, None) &gt;&gt;&gt; print b None </code></pre> <p>What you can do is:</p> <...
2
2016-07-27T16:49:42Z
[ "python", "json", "python-2.7", "python-3.x" ]
Python package recognized in Pycharm, not in terminal
38,618,867
<p>I'm developing a Django project which imports django-imagekit; everything works fine on my Windows machine. On my Linux-Ubuntu laptop though, Pycharm recognizes the package in the editor, it's listed in the project's interpreter's packages but it's not recognized from the command line:</p> <pre><code> simon@Sim...
0
2016-07-27T16:46:17Z
38,618,956
<p>If you are using Python 3, then you should be using <code>python3 manage.py check</code>. It might be better to use a virtual environment, in which case you would activate the virtual environment before running <code>python manage.py check</code>.</p> <p>The import fails in the Python 3 shell because you have not s...
1
2016-07-27T16:50:43Z
[ "python", "django", "packages", "django-imagekit" ]
Exiting subprocess on control-D?
38,618,884
<p>I am trying to stop a server which is a subprocess when the parent process gets killed by a cntrl-D(EOF on stdin). I tried many ways including reading stdin in the subprocess but that blocks all keyboard input. Is there a way to kill the subprocess when the parent process encounters a EOF.</p> <p>Creating a subproc...
0
2016-07-27T16:47:18Z
38,619,786
<p>with @thatotherguy 's suggestion of using os.getppid(), here is the new working solution to end the child process when it is orphaned by the parent (ie. when a control-D occurs on the parent and it closes without signaling the child)</p> <pre><code>self.t = threading.Thread(target=self.server.serve_forever) self.t....
0
2016-07-27T17:40:24Z
[ "python", "linux", "subprocess" ]
Joining strings of different lengths in a loop
38,618,888
<p>I'm working on transforming a file from this format:</p> <pre class="lang-none prettyprint-override"><code># SampleNamea seq1a seq2a # SampleNameb seq1b seq2b # SampleNamec seq1c seq2c # SampelNamed seq1d seq2d </code></pre> <p>To this format:</p> <pre class="lang-none prettyprint-override"><code>...
1
2016-07-27T16:47:33Z
38,626,566
<p>InputMasterList[LineOdd] string might look like (.seq2b)  as per your new update.</p> <p>Then before before proceeding to append, do a check on InputMasterList</p> <pre><code>if '.' in InputMasterList[LineOdd]: InputMasterList[LineOdd] = InputMasterList[LineOdd].replace('.', 'NNNNN', 1) </code></pre> <p>You...
0
2016-07-28T03:24:06Z
[ "python" ]
sum up two pandas dataframes with different indexes element by element
38,618,911
<p>I have two pandas dataframes, say df1 and df2, of some size each but with different indexes and I would like to sum up the two dataframes element by element. I provide you an easy example to better understand the problem:</p> <pre><code>dic1 = {'a': [3, 1, 5, 2], 'b': [3, 1, 6, 3], 'c': [6, 7, 3, 0]} dic2 = {'c': [...
3
2016-07-27T16:48:18Z
38,618,948
<p><strong>UPDATE:</strong> much better solution from <a href="http://stackoverflow.com/questions/38618911/sum-up-two-pandas-dataframes-with-different-indexes-element-by-element/38618948#comment64623588_38618948">piRSquared</a>:</p> <pre><code>In [39]: df1 + df2.values Out[39]: a b c 0 10 12 10 1 4 1 1...
5
2016-07-27T16:50:25Z
[ "python", "numpy", "pandas", "dataframe" ]
Creating multiple runloops that share data
38,618,939
<p>I am fetching data from a server every 5 seconds updating a list. In addition I am also listening to a button press.</p> <p>So what I need are two independent loops (pulling data and listening to a physical button on a Raspberry Pi via GPIO) and both need access to a shared list.</p> <p>For just one loop I could u...
0
2016-07-27T16:50:04Z
38,619,334
<p>So, if I am understanding you correctly, the problem is that you want a button-checking loop that loops every, say, millisecond, while your server polling loop should only run every 5 seconds. Is that correct?</p> <p>The simple solution would be to just have the server polling code execute inside the faster loop ev...
0
2016-07-27T17:12:48Z
[ "python", "python-2.7", "raspberry-pi" ]
Pull out sections from XML in Python
38,618,964
<p>Please note that I have some Python experience but not a lot of deep experience so please bear with me.</p> <p>I have a very large XML file, ~100 megs, that has many, many sections and subsections. I need to pull out each subsection of a certain type (and there are a lot with this type) and write each to a differe...
0
2016-07-27T16:50:57Z
38,621,943
<p>Consider an <a href="https://www.w3.org/Style/XSL/" rel="nofollow">XSLT</a> solution with Python's third-party module, <a href="http://lxml.de/" rel="nofollow"><code>lxml</code></a>. Specifically, you <code>xpath()</code> for the length of <code>&lt;data&gt;</code> nodes and then iteratively build a dynamic XSLT scr...
-1
2016-07-27T19:48:07Z
[ "python", "xml" ]
Pull out sections from XML in Python
38,618,964
<p>Please note that I have some Python experience but not a lot of deep experience so please bear with me.</p> <p>I have a very large XML file, ~100 megs, that has many, many sections and subsections. I need to pull out each subsection of a certain type (and there are a lot with this type) and write each to a differe...
0
2016-07-27T16:50:57Z
38,622,970
<p>I think you can read in each <code>data</code> element using <code>iterparse</code> and then write it out, the following simply prints the element using the <code>print</code> function but you could of course instead write it to a file:</p> <pre><code>import xml.etree.ElementTree as ET for event, elem in ET.iterpar...
1
2016-07-27T20:51:46Z
[ "python", "xml" ]
Why is my @classmethod variable "not defined"?
38,618,985
<p>I'm currently writing code in Python 2.7, which involves creating an object, in which I have two class methods and other regular methods. I need to use this specific combination of methods because of the larger context of the code I am writing- it's not relevant to this question, so I won't go into depth.</p> <p>Wi...
0
2016-07-27T16:51:51Z
38,620,138
<p>The reason <code>General.A</code> does not get defined in the main process is that <a href="https://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.pool" rel="nofollow"><code>multiprocessing.Pool</code></a> only runs <code>General._setup</code> in the <em>sub</em>processes. This means that it w...
1
2016-07-27T18:01:26Z
[ "python", "object", "multiprocessing", "pool", "class-method" ]
Download images automatically
38,619,100
<p>I have written this piece of python code which downloads a number of images from a repository of images and saves them in specified folder. The code looks like this: </p> <pre><code>import urllib.request import cv2 import numpy as np import os def store_raw_images(): neg_images_link = 'http://image- net.org/a...
1
2016-07-27T16:58:31Z
38,619,287
<p>You have everything in one <code>try/except</code> block. Assuming <code>cv2.imwrite</code> fails but all the other lines are executed without any problems, your code will never reach <code>picnum = picnum + 1</code>. Try rearranging your code where you first increase <code>picnum</code> and check which lines actual...
1
2016-07-27T17:10:45Z
[ "python", "download", "urllib" ]
Django not updating SQLite tables properly
38,619,116
<p>I've been working on a project that involves an authentication page using Django and AngularJS. I have created an extended version of the User class and have added "company" and "phone_number" as fields.</p> <p>Here's my code for models.py:</p> <pre><code>from django.contrib.auth.models import AbstractBaseUser, Ba...
0
2016-07-27T16:59:20Z
38,619,324
<p>In <code>create_user</code>, you haven't passed any of the other arguments to the <code>self.model</code> call, so you only set the email and, later, the password. You need to pass the kwargs in there too.</p> <pre><code> account = self.model(email=self.normalize_email(email), **kwargs) </code></pre>
0
2016-07-27T17:12:29Z
[ "python", "django", "sqlite" ]
Convert Python sequence to NumPy array, filling missing values
38,619,143
<p>The implicit conversion of a Python sequence of <em>variable-length</em> lists into a NumPy array cause the array to be of type <em>object</em>.</p> <pre><code>v = [[1], [1, 2]] np.array(v) &gt;&gt;&gt; array([[1], [1, 2]], dtype=object) </code></pre> <p>Trying to force another type will cause an exception:</p> <...
12
2016-07-27T17:01:10Z
38,619,278
<p>Pandas and its <code>DataFrame</code>-s deal beautifully with missing data.</p> <pre><code>import numpy as np import pandas as pd v = [[1], [1, 2]] print(pd.DataFrame(v).fillna(0).values.astype(np.int32)) # array([[1, 0], # [1, 2]], dtype=int32) </code></pre>
9
2016-07-27T17:10:13Z
[ "python", "arrays", "numpy", "sequence", "variable-length-array" ]
Convert Python sequence to NumPy array, filling missing values
38,619,143
<p>The implicit conversion of a Python sequence of <em>variable-length</em> lists into a NumPy array cause the array to be of type <em>object</em>.</p> <pre><code>v = [[1], [1, 2]] np.array(v) &gt;&gt;&gt; array([[1], [1, 2]], dtype=object) </code></pre> <p>Trying to force another type will cause an exception:</p> <...
12
2016-07-27T17:01:10Z
38,619,333
<p>You can use <a href="https://docs.python.org/3.4/library/itertools.html#itertools.zip_longest">itertools.zip_longest</a>:</p> <pre><code>import itertools np.array(list(itertools.zip_longest(*v, fillvalue=0))).T Out: array([[1, 0], [1, 2]]) </code></pre> <p>Note: For Python 2, it is <a href="https://docs.py...
9
2016-07-27T17:12:47Z
[ "python", "arrays", "numpy", "sequence", "variable-length-array" ]
Convert Python sequence to NumPy array, filling missing values
38,619,143
<p>The implicit conversion of a Python sequence of <em>variable-length</em> lists into a NumPy array cause the array to be of type <em>object</em>.</p> <pre><code>v = [[1], [1, 2]] np.array(v) &gt;&gt;&gt; array([[1], [1, 2]], dtype=object) </code></pre> <p>Trying to force another type will cause an exception:</p> <...
12
2016-07-27T17:01:10Z
38,619,337
<pre><code>max_len = max(len(sub_list) for sub_list in v) result = np.array([sub_list + [0] * (max_len - len(sub_list)) for sub_list in v]) &gt;&gt;&gt; result array([[1, 0], [1, 2]]) &gt;&gt;&gt; type(result) numpy.ndarray </code></pre>
1
2016-07-27T17:13:02Z
[ "python", "arrays", "numpy", "sequence", "variable-length-array" ]
Convert Python sequence to NumPy array, filling missing values
38,619,143
<p>The implicit conversion of a Python sequence of <em>variable-length</em> lists into a NumPy array cause the array to be of type <em>object</em>.</p> <pre><code>v = [[1], [1, 2]] np.array(v) &gt;&gt;&gt; array([[1], [1, 2]], dtype=object) </code></pre> <p>Trying to force another type will cause an exception:</p> <...
12
2016-07-27T17:01:10Z
38,619,350
<p>Here's an almost* vectorized boolean-indexing based approach that I have used in several other posts -</p> <pre><code>def boolean_indexing(v): lens = np.array([len(item) for item in v]) mask = lens[:,None] &gt; np.arange(lens.max()) out = np.zeros(mask.shape,dtype=int) out[mask] = np.concatenate(v) ...
6
2016-07-27T17:13:39Z
[ "python", "arrays", "numpy", "sequence", "variable-length-array" ]
Convert Python sequence to NumPy array, filling missing values
38,619,143
<p>The implicit conversion of a Python sequence of <em>variable-length</em> lists into a NumPy array cause the array to be of type <em>object</em>.</p> <pre><code>v = [[1], [1, 2]] np.array(v) &gt;&gt;&gt; array([[1], [1, 2]], dtype=object) </code></pre> <p>Trying to force another type will cause an exception:</p> <...
12
2016-07-27T17:01:10Z
38,619,419
<p>Here is a general way:</p> <pre><code>&gt;&gt;&gt; v = [[1], [2, 3, 4], [5, 6], [7, 8, 9, 10], [11, 12]] &gt;&gt;&gt; max_len = np.argmax(v) &gt;&gt;&gt; np.hstack(np.insert(v, range(1, len(v)+1),[[0]*(max_len-len(i)) for i in v])).astype('int32').reshape(len(v), max_len) array([[ 1, 0, 0, 0], [ 2, 3, 4...
0
2016-07-27T17:17:50Z
[ "python", "arrays", "numpy", "sequence", "variable-length-array" ]
ValueError: need more than 1 value to unpack psychopy: haven't touched the script since it was working yesterday and am suddenly getting this error
38,619,151
<p>I recognize there are a decent amount of ValueError questions on here, but it seems none are specifically related to psychopy or my issue. I am coding an experiment from scratch on psychopy (no builder involved). Yesterday, my script was running totally fine. Today I tried running it without adding anything new or t...
-1
2016-07-27T17:01:41Z
38,619,487
<p>It looks like you're using Python2. Python3 gives a more detailed information in it's error message. The problem is that argv only contains a single value and you're trying to unpack it into two variables. <code>argv</code> contains the command line variables -- if this was running yesterday "without any changes" as...
1
2016-07-27T17:21:25Z
[ "python", "psychopy" ]
How can I upload a picture to my django app on heroku and get it to be displayed?
38,619,166
<p>I have a django application on heroku where some data is added in the admin settings. It is linked to my github. One of the things you add is a picture. It doesn't show up on the site after its uploaded. What could be the cause and solution?</p>
0
2016-07-27T17:03:01Z
38,627,826
<p>I've been running my django app in heroku for about 6 months now and I've never experienced <code>db gets reset</code> when ever I updated/deploy/push to heroku <strong>note</strong> I'm using heroku postgress for db</p>
0
2016-07-28T05:35:36Z
[ "python", "django", "database", "heroku", "web-applications" ]
Upload file with hidden input with Selenium WebDriver Python
38,619,191
<p>Html:</p> <pre><code>&lt;div id="js-cert-file" class="form-group"&gt; &lt;button id="js-ob-browse-n-upload" class="btn btn-ob browse-and-upload-onboarding-ssl-button" style=""&gt; BROWSE &amp; UPLOAD &lt;/button&gt; &lt;input id="js-cert-file" class="hidden btn btn-ob" type="file" accept=".p12, .pem, .pfx" name="fi...
0
2016-07-27T17:04:44Z
38,619,517
<p>Try to make input field visible and upload file with following code:</p> <pre><code>driver.execute_script('document.getElementById("js-cert-file").style.visibility="visible";') driver.execute_script('document.getElementById("js-cert-file").style.display="block";') driver.find_element_by_xpath('//input[@id="js-cert-...
0
2016-07-27T17:23:19Z
[ "jquery", "python", "html", "css", "selenium" ]
Many-to-Many Database design with Django
38,619,218
<p>Oftentimes a single drug can have lots of "nick names" which gets confusing. So, I'm trying to build a small Django app to help me with the issue. </p> <p>What it should do is either refer the drugs acutal name (non_proprietary_name) to its "nick name" (proprietary_name) or vice versa. </p> <p>For instance, "Aspir...
0
2016-07-27T17:06:32Z
38,619,543
<p>First your model name <code>Mediwiki</code> is not straightforward because each entry is just recording all information about a <code>Drug</code>. So just change that to <code>Drug</code> would make more sense.</p> <p>In your current design, you are using m2m fields, which indicates that one <code>proprietary_name<...
1
2016-07-27T17:24:41Z
[ "python", "django", "database", "database-design" ]
Many-to-Many Database design with Django
38,619,218
<p>Oftentimes a single drug can have lots of "nick names" which gets confusing. So, I'm trying to build a small Django app to help me with the issue. </p> <p>What it should do is either refer the drugs acutal name (non_proprietary_name) to its "nick name" (proprietary_name) or vice versa. </p> <p>For instance, "Aspir...
0
2016-07-27T17:06:32Z
38,619,684
<p>There can be many proprietary names, but no identical proprietary name can be assigned to more than one non-proprietary (generic) drug, so you need to change your relation from Many-To-Many to One-To-Many (nb. use CamelCase in class names, not underscores):</p> <pre><code>class Mediwiki(models.Model): non_propr...
1
2016-07-27T17:33:18Z
[ "python", "django", "database", "database-design" ]
How to count objects in image using python?
38,619,382
<p>I am trying to count the number of drops in this image and the coverage percentage of the area covered by those drops. I tried to convert this image into black and white, but the center color of those drops seems too similar to the background. So I only got something like the second picture. Is there any way to sol...
-5
2016-07-27T17:15:38Z
38,632,224
<p>I used the following code to detect the number of contours in the image using openCV and python. </p> <pre><code>img = cv2.imread('ba3g0.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(gray,127,255,1) contours,h = cv2.findContours(thresh,1,2) for cnt in contours: cv2.drawContours(img...
1
2016-07-28T09:24:51Z
[ "python", "image-processing" ]
How to count objects in image using python?
38,619,382
<p>I am trying to count the number of drops in this image and the coverage percentage of the area covered by those drops. I tried to convert this image into black and white, but the center color of those drops seems too similar to the background. So I only got something like the second picture. Is there any way to sol...
-5
2016-07-27T17:15:38Z
38,636,485
<p>The idea is to isolate the background form the inside of the drops that look like the background. Therefore i found the connected components for the background and the inside drops took the largest connected component and change its value to be like the foreground value which left me with an image which he inside dr...
1
2016-07-28T12:32:37Z
[ "python", "image-processing" ]
How to count objects in image using python?
38,619,382
<p>I am trying to count the number of drops in this image and the coverage percentage of the area covered by those drops. I tried to convert this image into black and white, but the center color of those drops seems too similar to the background. So I only got something like the second picture. Is there any way to sol...
-5
2016-07-27T17:15:38Z
38,672,355
<p>You can fill the holes of your binary image using <code>scipy.ndimage.binary_fill_holes</code>. I also recommend using an automatic thresholding method such as Otsu's (avaible in <code>scikit-image</code>).<a href="http://i.stack.imgur.com/nE1fZ.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/nE1fZ.jpg" alt="...
0
2016-07-30T09:23:14Z
[ "python", "image-processing" ]
Attaching event to self (canvas) tkinter
38,619,393
<p>i have created a class in python that extends the tkinter canvas. I am trying to attach an event to this canvas to handle click's within the class. It functions if i attach the event outside of the class itself but when binding within the class the click event only occur's once and then proceeds not to do anything a...
0
2016-07-27T17:16:15Z
38,619,785
<p>The problem is in this line:</p> <pre><code>self.bind("&lt;Button-1&gt;", self.callback()) </code></pre> <p>You need to connect something callable (in other words, a function) to the event. The function is referenced as <code>self.callback</code>. If you call the function (<code>self.callback()</code>) then you're...
1
2016-07-27T17:40:18Z
[ "python", "canvas", "tkinter", "tk" ]
Pandas way of getting intersection between two rows in a python Pandas dataframe
38,619,427
<p>Say I have some data that looks like below. I want to get the count of ids that have two tags at the same time.</p> <pre><code>tag id a A b B a B b A c A </code></pre> <p>What I desire the result:</p> <pre><code>tag1 tag2 count a b 2 a c 1 b c 1 </code></pre> <p>In plain python I could write pseudocode:</p> <pr...
2
2016-07-27T17:18:14Z
38,620,118
<p>Here is my attempt:</p> <pre><code>from itertools import combinations import pandas as pd import numpy as np In [123]: df Out[123]: tag id 0 a A 1 b B 2 a B 3 b A 4 c A In [124]: a = np.asarray(list(combinations(df.tag, 2))) In [125]: a Out[125]: array([['a', 'b'], ['a', 'a'], ['a'...
2
2016-07-27T18:00:04Z
[ "python", "numpy", "pandas", "dataframe" ]
alpha parameter from an alpha-stable distribution
38,619,463
<p>Considering I have a collection of data. Let's say for example they are length 100. My hypothesis say that these data follow the alpha-stable distribution. Is there a way to calculate the alpha parameter of these data? </p> <p>I would like to do that in python more specifically. All I found was that package <a href...
1
2016-07-27T17:20:08Z
38,625,671
<p><code>If I have some data that I know they follow Poisson distribution isn't it possible to calculate the λ of that distribution? (Is this possible or am I miss something from statistics theory?)</code></p> <p>Sure. Mean of Poisson is equal to <strong>λ</strong>, so compute mean of your data and try ti use it. Be...
0
2016-07-28T01:22:51Z
[ "python", "statistics", "probability", "distribution", "probability-density" ]
Google Search Web Scraping with Python
38,619,478
<p>I've been learning a lot of python lately to work on some projects at work. </p> <p>Currently I need to do some web scraping with google search results. I found several sites that demonstrated how to use ajax google api to search, however after attempting to use it, it appears to no longer be supported. Any suggest...
0
2016-07-27T17:20:57Z
38,620,894
<p>You can always directly scrape Google results. To do this, you can use the URL <code>https://google.com/search?q=&lt;Query&gt;</code> this will return the top 10 search results.</p> <p>Then you can use <a href="http://lxml.de" rel="nofollow">lxml</a> for example to parse the page. Depending on what you use, you can...
0
2016-07-27T18:46:07Z
[ "python", "python-2.7", "google-search", "google-search-api" ]
How to use PyOrient to create functions (stored procedures) in OrientDB?
38,619,508
<p>I'm trying to create an OrientDB graph database using PyOrient, and I can't find enough documentation to allow me to get Functions working. I've been able to create a function using <code>record_create</code> into the <code>ofunction</code> cluster, but although it doesn't crash, it doesn't appear to work either. He...
0
2016-07-27T17:22:32Z
38,631,949
<p>You could try something like :</p> <pre><code>code="var g=orient.getGraph();\ng.command(\\'sql\\',\\'%s\\',[urlparam]);" myFunction = "CREATE FUNCTION addURL '" + code + "' parameters [urlparam] idempotent false language javascrip" client.command(myFunction); </code></pre> <p><strong>UPDATE</strong> </p> <p>I use...
0
2016-07-28T09:12:24Z
[ "python", "stored-procedures", "orientdb", "pyorient" ]
How to use PyOrient to create functions (stored procedures) in OrientDB?
38,619,508
<p>I'm trying to create an OrientDB graph database using PyOrient, and I can't find enough documentation to allow me to get Functions working. I've been able to create a function using <code>record_create</code> into the <code>ofunction</code> cluster, but although it doesn't crash, it doesn't appear to work either. He...
0
2016-07-27T17:22:32Z
38,641,371
<p>OK, after a lot of hacking and Googling, I've got it working:</p> <pre><code>code="CREATE VERTEX URL SET id = sequence('urlseq').next(), url = :urlparam;" myFunction = 'CREATE FUNCTION addURL "' + code + '" parameters [urlparam] idempotent false language sql' client.command(myFunction) </code></pre> <p>The key her...
0
2016-07-28T15:58:53Z
[ "python", "stored-procedures", "orientdb", "pyorient" ]
Working with variable-length text in Tensorflow
38,619,526
<p>I am building a Tensorflow model to perform inference on text phrases. For sake of simplicity, assume I need a classifier with fixed number of output classes but a <em>variable-length text</em> in input. In other words, my mini batch would be a sequence of phrases but not all phrases have the same length. </p> <pre...
1
2016-07-27T17:23:41Z
38,634,226
<p>I was building a sequence to sequence translator the other day. What I did is decided to do was make it for a fixed length of 32 words (which was a bit above the average sentence length) although you can make it as long as you want. I then added a NULL word to the dictionary and padded all my sentence vectors with...
0
2016-07-28T10:50:45Z
[ "python", "string", "text", "tensorflow", "variable-length-array" ]
matching tuples in pandas and data processing
38,619,620
<p>The following is a simplified blob of my dataframe. I want to process</p> <p><a href="https://gist.github.com/ecenm/97248a1d1f6f301d662c6f238b6168df" rel="nofollow">first.csv</a></p> <pre><code>,No.,Time,Source,Destination,Protocol,Length,Info,src_dst_pair 325778,112.305107,02:e0,Broadcast,ARP,64,Who has 253.244.2...
3
2016-07-27T17:29:37Z
38,620,048
<p>Your csv file is messed up. You shouldn't have the first comma in the header, and you have an extra field in your 4th non-header row. Fixing that, you could use:</p> <pre><code>In [6]: data.groupby('src_dst_pair').Length.sum() Out[6]: src_dst_pair ('02:e0', 'Broadcast') 188 ('100.118.138.150', '41...
2
2016-07-27T17:55:40Z
[ "python", "csv", "pandas" ]
OpenCV fails to capture from more than 8 webcams on Linux
38,619,801
<p>OpenCV fails to open VideoCaptures for more than 8 webcams on Linux. Here a simple example:</p> <pre><code># "opencap.py" import cv2, sys dev = int(sys.argv[1]) cap = cv2.VideoCapture(dev) print "device %d: %s" %(dev, "success" if cap.isOpened() else "failure") </code></pre> <p>For my setup (OpenCV 2.4.11, Ubuntu...
2
2016-07-27T17:41:13Z
38,619,802
<p>The problem is caused by this line in the OpenCV source code:</p> <pre class="lang-cpp prettyprint-override"><code>#define MAX_CAMERAS 8 </code></pre> <p>Simply changing the <code>MAX_CAMERAS</code> value and rebuilding OpenCV solves the problem. The file to change is modules/highgui/src/cap_libv4l.cpp (<a href="...
4
2016-07-27T17:41:13Z
[ "python", "linux", "opencv", "limit", "webcam" ]
jquery tablesorter custom order
38,619,805
<p>I'm using this plugin on python.</p> <p>Is it possible to make it order a column by a custom sequence?</p> <p>In the <code>quality</code> column I can have only: 'low', 'mediocre', 'good', 'great' and I want ordered in that way (or reversed).</p> <p>In the <code>Name</code> column I have (by the view) a custum or...
1
2016-07-27T17:41:25Z
38,646,781
<p>Using the fork suggested in the comment I solved my problems in this way:</p> <p>My <code>script-jquery</code>:</p> <pre><code>$.tablesorter.addParser({ id: 'quality', is: function(s) { // return false so this parser is not auto detected return false; }, format: function(s) { // format your dat...
1
2016-07-28T21:08:33Z
[ "jquery", "python", "tablesorter" ]
Reference Link List Length Python?
38,619,822
<p><strong>EDIT:</strong> The terminology I was looking for was is called Cycle Detection. Thanks to @dhke for referring that in the comments.</p> <p>I'm trying to figure out a better way to process a list of indexes and what it's length is if a list has a loop in its reference. I have a function that works but it pas...
0
2016-07-27T17:42:20Z
38,619,938
<p>If you don't want extra data structures:</p> <pre><code>def tortoise_and_hare(l): tort = 0 hare = 0 count = 0 while tort != hare or count == 0: count += 1 if l[tort] == 0: return count tort = l[tort] hare = l[hare] hare = l[hare] return -1 &g...
1
2016-07-27T17:48:55Z
[ "python", "list" ]
Reference Link List Length Python?
38,619,822
<p><strong>EDIT:</strong> The terminology I was looking for was is called Cycle Detection. Thanks to @dhke for referring that in the comments.</p> <p>I'm trying to figure out a better way to process a list of indexes and what it's length is if a list has a loop in its reference. I have a function that works but it pas...
0
2016-07-27T17:42:20Z
38,619,978
<p>You can use a set to keep track of all nodes you've visited (sets have very fast membership tests). And there is absolutely no need for recursion here, a loop will do nicely:</p> <pre><code>def my_ideal_func(list): visited_nodes= set() index= 0 length= 0 while True: node= list[index] ...
1
2016-07-27T17:51:09Z
[ "python", "list" ]
Reference Link List Length Python?
38,619,822
<p><strong>EDIT:</strong> The terminology I was looking for was is called Cycle Detection. Thanks to @dhke for referring that in the comments.</p> <p>I'm trying to figure out a better way to process a list of indexes and what it's length is if a list has a loop in its reference. I have a function that works but it pas...
0
2016-07-27T17:42:20Z
38,620,006
<p>There's no need for recursion:</p> <pre><code>def link_len(l): cnt, idx = 0, 0 while not cnt or idx: cnt = cnt + 1 idx = l[idx] return cnt </code></pre> <p>This assumes the list loops back to 0.</p>
1
2016-07-27T17:53:12Z
[ "python", "list" ]
Can I somehow query all the existing tables in peewee / postgres?
38,619,833
<p>I am writing a basic gui for a program which uses Peewee. In the gui, I would like to show all the tables which exist in my database.</p> <p>Is there any way to get the names of all existing tables, lets say in a list?</p>
0
2016-07-27T17:42:59Z
38,620,529
<p>To get a list of the tables in your schema, make sure that you have established your connection and cursor and try the following:</p> <pre><code>cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public'") myables = cursor.fetchall() mytables = [x[0] for x in mytables] </code></pre...
0
2016-07-27T18:24:17Z
[ "python", "peewee" ]
Can I somehow query all the existing tables in peewee / postgres?
38,619,833
<p>I am writing a basic gui for a program which uses Peewee. In the gui, I would like to show all the tables which exist in my database.</p> <p>Is there any way to get the names of all existing tables, lets say in a list?</p>
0
2016-07-27T17:42:59Z
38,714,979
<p>Peewee has the ability to introspect Postgres, MySQL and SQLite for the following types of schema information:</p> <ul> <li>Table names</li> <li>Columns (name, data type, null?, primary key?, table)</li> <li>Primary keys (column(s))</li> <li>Foreign keys (column, dest table, dest column, table)</li> <li>Indexes (na...
1
2016-08-02T08:05:31Z
[ "python", "peewee" ]
Finding a gps location at a certain time given two points?
38,619,835
<p>If I have two known locations and a known speed, how can I calculate the current position at distance d (in km)?</p> <p>For example, given:</p> <p><strong>Two gps locations in ES4236:</strong></p> <pre><code>37.783333, -122.416667 # San Francisco 32.715, -117.1625 # San Diego </code></pre> <p>Traveling ...
0
2016-07-27T17:43:07Z
38,636,156
<p>Ok, figured I'd come back to this question and give it my best shot given that it hasn't seen any other solutions. Unfortunately I can't test code right now, but I believe there is a solution to your problem using both geopy and geographiclib. Here goes.</p> <p>From the terminal (possibly with sudo)</p> <pre><code...
0
2016-07-28T12:18:42Z
[ "python", "python-2.7", "gps", "geolocation", "coordinate-systems" ]
Problems parsing a web page in python
38,619,887
<p>I would like to parse a web page in order to retrieve some information about it (my exact problem is to retrieve all the items in this list : <a href="http://www.computerhope.com/vdef.htm" rel="nofollow">http://www.computerhope.com/vdef.htm</a>).</p> <p>However, I can't figure out how to do it.</p> <p>A lot of tut...
-1
2016-07-27T17:45:51Z
38,619,966
<p>Try using beautiful soup, it has some excellent features and makes parsing in Python extremely easy.</p> <p>Check of their documentation at <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">https://www.crummy.com/software/BeautifulSoup/bs4/doc/</a></p> <p>EDIT:</p> <p>As @mzjn point...
-1
2016-07-27T17:50:29Z
[ "python", "html", "lxml", "html5lib" ]
How to print a list of tuples without commas in Python?
38,619,902
<p>I have two lists in python.</p> <pre><code>a = [1, 2, 4, 8, 16] b = [0, 1, 2, 3, 4] </code></pre> <p>and a third list <code>c</code> that is the <code>zip</code> of them.</p> <pre><code>c = zip(a, b) </code></pre> <p>or simply I have a list of tuples like this:</p> <pre><code>c = [(1, 0), (2, 1), (4, 2), (8, 3...
0
2016-07-27T17:46:59Z
38,619,956
<pre><code>print('[%s]' % ' '.join(map(str, c))) </code></pre> <p>Prints:</p> <pre><code>[(1, 0) (2, 1) (4, 2) (8, 3) (16, 4)] </code></pre> <p>for your inputs.</p> <p>You can basically take advantage of the fact that you're using the natural string representation of the tuples and just join with a space.</p>
3
2016-07-27T17:49:48Z
[ "python", "list" ]
How to print a list of tuples without commas in Python?
38,619,902
<p>I have two lists in python.</p> <pre><code>a = [1, 2, 4, 8, 16] b = [0, 1, 2, 3, 4] </code></pre> <p>and a third list <code>c</code> that is the <code>zip</code> of them.</p> <pre><code>c = zip(a, b) </code></pre> <p>or simply I have a list of tuples like this:</p> <pre><code>c = [(1, 0), (2, 1), (4, 2), (8, 3...
0
2016-07-27T17:46:59Z
38,619,975
<p>Would it be okay to create the final result as a string?</p> <pre><code>c_no_comma = '' for element in c: c_no_comma += str(element) + ' ' c_no_comma = '[ ' + c_no_comma + ']' </code></pre>
0
2016-07-27T17:50:50Z
[ "python", "list" ]
How to print a list of tuples without commas in Python?
38,619,902
<p>I have two lists in python.</p> <pre><code>a = [1, 2, 4, 8, 16] b = [0, 1, 2, 3, 4] </code></pre> <p>and a third list <code>c</code> that is the <code>zip</code> of them.</p> <pre><code>c = zip(a, b) </code></pre> <p>or simply I have a list of tuples like this:</p> <pre><code>c = [(1, 0), (2, 1), (4, 2), (8, 3...
0
2016-07-27T17:46:59Z
38,620,061
<pre><code>print('[' + ' '.join([str(tup) for tup in c]) + ']') </code></pre> <p>Using a list comprehension to create a list of the tuples in string form. Those are then joined and the square brackets are added to make it look as you want it.</p>
3
2016-07-27T17:56:59Z
[ "python", "list" ]
Sklearn-Pandas DataFrameMapper: mapper.fit_transform gives ValueError: bad input shape (8, 2)
38,619,904
<p>I was able to replicate the example given in the <a href="https://github.com/paulgb/sklearn-pandas" rel="nofollow">Github</a> repo. However, when I tried it on my own data, I got the ValueError.</p> <p>Below is a dummy data that, which gives the same error as my real data.</p> <pre><code>import pandas as pd import...
1
2016-07-27T17:47:07Z
38,623,218
<p>You should only submit multiple arrays to a transform if it indeed takes multiple inputs (e.g. sklearn.decomposition.PCA(1) in the documentation). In your case the error ultimately comes from this line:</p> <pre><code>(['pet', 'feat4'], LabelEncoder()), </code></pre> <p>Even this does not work:</p> <pre><code>(['...
3
2016-07-27T21:08:48Z
[ "python", "pandas", "sklearn-pandas" ]
Find duplicate values in list of tuples in Python
38,619,907
<p>How do I find duplicate values in the following list of tuples?</p> <pre><code>[(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] </code></pre> <p>I want to get a list like:</p> <pre><code>[4081, 4082, 4086, 4090] </code></pre> <p>I have tried using <code>itemgetter</code> then ...
0
2016-07-27T17:47:11Z
38,620,034
<p>Haven't tested this.... (edit: yup, it works)</p> <pre><code>l = [(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] dup = [] for i, t1 in enumerate(l): for t2 in l[i+1:]: if t1[0]==t2[0]: dup.extend([t1[1], t2[1]]) print dup </code></pre>
0
2016-07-27T17:55:09Z
[ "python", "list", "tuples" ]
Find duplicate values in list of tuples in Python
38,619,907
<p>How do I find duplicate values in the following list of tuples?</p> <pre><code>[(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] </code></pre> <p>I want to get a list like:</p> <pre><code>[4081, 4082, 4086, 4090] </code></pre> <p>I have tried using <code>itemgetter</code> then ...
0
2016-07-27T17:47:11Z
38,620,038
<p>Use an ordered dictionary with first items as its keys and list of second items as values (for duplicates which created using <code>dict.setdefalt()</code>) then pick up those that have a length more than 1: </p> <pre><code>&gt;&gt;&gt; from itertools import chain &gt;&gt;&gt; from collections import OrderedDict &...
2
2016-07-27T17:55:16Z
[ "python", "list", "tuples" ]
Find duplicate values in list of tuples in Python
38,619,907
<p>How do I find duplicate values in the following list of tuples?</p> <pre><code>[(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] </code></pre> <p>I want to get a list like:</p> <pre><code>[4081, 4082, 4086, 4090] </code></pre> <p>I have tried using <code>itemgetter</code> then ...
0
2016-07-27T17:47:11Z
38,620,227
<p>As an alternative, if you want to use <code>groupby</code>, here is a way to do it:</p> <pre><code>In [1]: from itertools import groupby In [2]: ts = [(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] In [3]: dups = [] In [4]: for _, g in groupby(ts, lambda x: x[0]): ...: ...
1
2016-07-27T18:07:17Z
[ "python", "list", "tuples" ]
Find duplicate values in list of tuples in Python
38,619,907
<p>How do I find duplicate values in the following list of tuples?</p> <pre><code>[(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] </code></pre> <p>I want to get a list like:</p> <pre><code>[4081, 4082, 4086, 4090] </code></pre> <p>I have tried using <code>itemgetter</code> then ...
0
2016-07-27T17:47:11Z
38,621,510
<p>Yet another approach (without any imports):</p> <pre><code>In [896]: lot = [(1622, 4081), (1622, 4082), (1624, 4083), (1626, 4085), (1650, 4086), (1650, 4090)] In [897]: d = dict() In [898]: for key, value in lot: ...: d[key] = d.get(key, []) + [value] ...: ...: In [899]: d Out[899]: {1622: ...
0
2016-07-27T19:22:33Z
[ "python", "list", "tuples" ]
Testing Post Request Using ModelFormSet in Django
38,619,999
<p>I'm new to django and testing, so I'm not sure if there is a more simple solution to this question.</p> <p>I'm creating an assessment app with a rubric that the user can edit, submit and update. Each rubric has a preset number of row models that are connected to the rubric model via a foreign key relationship. The...
0
2016-07-27T17:52:40Z
38,620,214
<p>One approach I've used in the past, albeit not a particularly nice one, is to use the client to get the rendered form, then use something like BeautifulSoup to parse out all the form data from that and update where necessary before posting back. That way you will get all the hidden and prepopulated fields, so you ca...
0
2016-07-27T18:06:31Z
[ "python", "django", "django-forms", "django-templates" ]
Python How to concat and retrieve actual defined data?
38,620,035
<p>Ive been searching but I just cant find anything that describes my problem. Im just learning python so I might not even know how to properly phrase the question.</p> <p>Im trying to randomize a selection of defined variables, but I can not figure out how to retrieve those variables. example:</p> <pre><code>import ...
0
2016-07-27T17:55:09Z
38,620,142
<p>look at this post <a href="http://stackoverflow.com/questions/19122345/to-convert-string-to-variable-name-in-python">To convert string to variable name in python</a>, You can do what you want using exec to change strings to a variable, but this is not safe and definitely not recommended. As the post here explains yo...
1
2016-07-27T18:01:36Z
[ "python" ]
Python How to concat and retrieve actual defined data?
38,620,035
<p>Ive been searching but I just cant find anything that describes my problem. Im just learning python so I might not even know how to properly phrase the question.</p> <p>Im trying to randomize a selection of defined variables, but I can not figure out how to retrieve those variables. example:</p> <pre><code>import ...
0
2016-07-27T17:55:09Z
38,620,168
<p>The comments are correct, I just wanted to share a way to implement them. You can think of dictionaries as "look up table" where you assign a key-->value pair. There is a lot of info <a href="http://www.tutorialspoint.com/python/python_dictionary.htm" rel="nofollow">here</a></p> <pre><code>import random users = {"...
0
2016-07-27T18:03:13Z
[ "python" ]
Python How to concat and retrieve actual defined data?
38,620,035
<p>Ive been searching but I just cant find anything that describes my problem. Im just learning python so I might not even know how to properly phrase the question.</p> <p>Im trying to randomize a selection of defined variables, but I can not figure out how to retrieve those variables. example:</p> <pre><code>import ...
0
2016-07-27T17:55:09Z
38,620,183
<pre><code>import random users = [ { 'user':"usernamehere1", 'userkey':"3097fds09aj4023jr30mf2ag2" }, { 'user':"usernamehere2", 'userkey':"09asfh34907fsenk32498fgg9" }, { 'user':"usernamehere3", 'userkey':"23...
0
2016-07-27T18:04:15Z
[ "python" ]
Python How to concat and retrieve actual defined data?
38,620,035
<p>Ive been searching but I just cant find anything that describes my problem. Im just learning python so I might not even know how to properly phrase the question.</p> <p>Im trying to randomize a selection of defined variables, but I can not figure out how to retrieve those variables. example:</p> <pre><code>import ...
0
2016-07-27T17:55:09Z
38,620,433
<p>You can use this with just one dictionary:</p> <pre><code>import random users = { "usernamehere1": "3097fds09aj4023jr30mf2ag2", "usernamehere2": "09asfh34907fsenk32498fgg9", "usernamehere3": "234kn34bnero8wn34lnkjwi34" } user = random.sample(users.keys(), 1) print(user[0]) print(users[user[0]]) </cod...
0
2016-07-27T18:18:44Z
[ "python" ]
Removing documents in Gensim
38,620,124
<p>I'm using Gensim for an NLP task and currently I have a corpus which includes empty documents. I don't want to rerun my code, although that is an option, and would just like to remove the documents that don't have any content. The documents are already saved as TF-IDF corpora and was wondering if there was a way t...
0
2016-07-27T18:00:35Z
38,621,889
<p>You might try converting the corpus to a numpy matrix, like so:</p> <pre><code>numpy_matrix = gensim.matutils.corpus2dense(corpus, num_terms=number_of_corpus_features) </code></pre> <p>Then remove the appropriate columns (those with all zero entries). Then convert back to a gensim corpus to continue:</p> <pre><c...
1
2016-07-27T19:44:51Z
[ "python", "python-2.7", "nlp", "gensim" ]
Skimage Region Adjacency Graph (RAG) from quickshift segmentation
38,620,129
<p>I'm trying to create a Region Adjacency Graph from after segmenting an image using the tools in the <code>Skimage</code> package. Using the examples in the documentation I can segment an image using SLIC and create the RAG successfully.</p> <pre class="lang-py prettyprint-override"><code>from skimage import data fr...
1
2016-07-27T18:00:48Z
38,623,398
<p>Seems that this was an issue in <code>Skimage 0.11.2</code> but is fixed in version <code>0.12.3</code>.</p>
0
2016-07-27T21:21:18Z
[ "python", "python-2.7", "classification", "image-segmentation", "skimage" ]
How to import a function from python file by Boost.Python
38,620,134
<p>I am totally new to boost.python. I reviewed a lot of recommending of using boost.python to apply with python, however still not easy to understand and find a solution for me.</p> <p>What I want is to import a function or class that directly from a python "SourceFile"</p> <p>Example File: Main.cpp MyPythonClass.p...
1
2016-07-27T18:01:09Z
38,620,679
<p>Boost python is used to call cplusplus functions from a python source. Pretty much like the Perl xs module.</p> <p>If you have a function say bark() in main.cpp, you can use boost python to convert this main.cpp into a python callable module.</p> <p>Then from python script(assuming link output file is main.so):</p...
0
2016-07-27T18:32:53Z
[ "python", "c++", "boost-python" ]
How to import a function from python file by Boost.Python
38,620,134
<p>I am totally new to boost.python. I reviewed a lot of recommending of using boost.python to apply with python, however still not easy to understand and find a solution for me.</p> <p>What I want is to import a function or class that directly from a python "SourceFile"</p> <p>Example File: Main.cpp MyPythonClass.p...
1
2016-07-27T18:01:09Z
38,702,099
<p>When one needs to call Python from C++, and C++ owns the main function, then one must <em>embed</em> the Python interrupter within the C++ program. The Boost.Python API is not a complete wrapper around the Python/C API, so one may find the need to directly invoke parts of the Python/C API. Nevertheless, Boost.Pyth...
0
2016-08-01T14:59:23Z
[ "python", "c++", "boost-python" ]
Querying a list to a manytomany field in django returning more results than expected
38,620,247
<p>I wrote the following filter based off the answer provided here: <a href="http://stackoverflow.com/questions/8618068/django-filter-queryset-in-for-every-item-in-list/8637972#8637972">Django filter queryset __in for *every* item in list</a></p> <pre><code>Distinct_Alert.objects.filter(entities__in=relevant_entities,...
1
2016-07-27T18:08:17Z
38,621,726
<p>Try this:</p> <pre><code>from django.db.models import IntegerField, Case, When, F Distinct_Alert.objects.filter( alert_type=alert_type ).annotate( num_entities=Count('entities'), num_relevant_entities=Count( Case(When(entities__in=relevant_entities, then=1), default=None, ...
1
2016-07-27T19:35:56Z
[ "python", "django" ]
Smooth-filtering image border to create circular image (fourier preparation)
38,620,288
<p>I learned how to do it yet couldn't remember now, and am failing to get something useful by searching. I have an image, and would like to use this image to create a larger image of size 3x3 by simply stacking them. The border had to be smoothed so that right edge of the image translates seamlessly to the left edge o...
0
2016-07-27T18:10:31Z
38,622,716
<p>You can try the following solution:<br> Leave some overlapping area between two attached images.<br> Do linear interpolation between two images in the overlapped area.<br> Linear interpolation: h*A + (1-h)*B when h goes from 0 to 1.</p> <p>Illustration of h (replicated to create an image) for attach images horizont...
0
2016-07-27T20:35:24Z
[ "python", "matlab", "image-processing", "filtering", "convolution" ]
Smooth-filtering image border to create circular image (fourier preparation)
38,620,288
<p>I learned how to do it yet couldn't remember now, and am failing to get something useful by searching. I have an image, and would like to use this image to create a larger image of size 3x3 by simply stacking them. The border had to be smoothed so that right edge of the image translates seamlessly to the left edge o...
0
2016-07-27T18:10:31Z
38,623,608
<p>Here is a full 3x3 sample: </p> <pre><code>function Test() close all I = imread('un1vY.jpg'); I = double(I)/255; %Convert uint8 to double J = HorizFuse(I); Jtag = cat(3, J(:,:,1)', J(:,:,2)', J(:,:,3)'); %Transpose across 2'nd dimension. K = HorizFuse(Jtag); K = cat(3, K(:,...
1
2016-07-27T21:36:46Z
[ "python", "matlab", "image-processing", "filtering", "convolution" ]
Placing scraped data into a list
38,620,330
<p>I want to place the data I have scraped from my website and place it into an array for further use.</p> <pre><code>response = requests.get(url) html = response.content # Taking content from above and searching through it find certain elements with certain attributes soup = BeautifulSoup(html, "html.parser") # Loo...
-2
2016-07-27T18:13:12Z
38,620,901
<p>I used td.text.strip() in the code where it says team.append(td) and got my desired response.</p> <p>so it looks like this</p> <pre><code>team.append(td.text.strip()) </code></pre> <p>I believe I got this response because the data I was trying to append, was nested in other tags so it wasn't receiving the text fr...
0
2016-07-27T18:46:32Z
[ "python", "arrays", "parsing", "web-scraping", "beautifulsoup" ]
Calling an object method that was returned from a method as a method variable
38,620,351
<p>I have a list of things, I'll use files as an example. Each type of file needs to be processed in a different manner. I created a class, "MyFile" and rather than maintaining a giant if:elif:else: structure I created a dictionary with the file type as the key. This is stored as a class variable. </p> <pre><code>c...
1
2016-07-27T18:14:08Z
38,620,442
<p>You call it with the first argument being what you want self to be. For example:</p> <pre><code>f = MyFile("full_file_path_and_name") file_type = f.get_filetype() file_type[1](f) </code></pre> <p>This way, you can also use any other file with the function. If you want to only call the specific file with <code>file...
0
2016-07-27T18:19:25Z
[ "python", "python-3.x" ]
Calling an object method that was returned from a method as a method variable
38,620,351
<p>I have a list of things, I'll use files as an example. Each type of file needs to be processed in a different manner. I created a class, "MyFile" and rather than maintaining a giant if:elif:else: structure I created a dictionary with the file type as the key. This is stored as a class variable. </p> <pre><code>c...
1
2016-07-27T18:14:08Z
38,620,447
<p>Because those functions are declared inside a class, they have the argument <code>self</code> representing the object from that class that's calling the function. When you try to call that function separately, outside of the context of a <code>MyFile</code> object, there is no <code>self</code> variable anymore asso...
0
2016-07-27T18:19:39Z
[ "python", "python-3.x" ]
Calling an object method that was returned from a method as a method variable
38,620,351
<p>I have a list of things, I'll use files as an example. Each type of file needs to be processed in a different manner. I created a class, "MyFile" and rather than maintaining a giant if:elif:else: structure I created a dictionary with the file type as the key. This is stored as a class variable. </p> <pre><code>c...
1
2016-07-27T18:14:08Z
38,620,675
<p>When you create a <code>class</code>, the methods you define in it are <em>just functions</em>. Only when you retrieve their names from an <em>instance</em> of the class, will they be bound to that instance, producing bound methods. This is done via the <a href="https://docs.python.org/3/howto/descriptor.html" rel="...
1
2016-07-27T18:32:36Z
[ "python", "python-3.x" ]
Python Qualtrics Data
38,620,374
<p>So, I am pulling data from the Qualtrics v3 API, and would like to pull the data every night. How could I pull all of the data one night and come back the next night and pull all of the new data. There is a parameter that the survey responds with called "lastModified" which is the last modified date.</p> <p>Here is...
0
2016-07-27T18:15:27Z
38,621,548
<p>I think you want to use responseexports instead surveys. Save the last response id retrieved each day. Then, you can use the lastResponseId parameter to specify where to start pulling the new data.</p>
0
2016-07-27T19:25:01Z
[ "python", "qualtrics" ]
What is this line of Theano doing?
38,620,387
<p>I don't understand if we are iterating over y as it appears what is being done with the values in y? Are they part of T.log? Are they added, multi, idk somehow combined with p_y_given_x? </p> <pre><code>result = -T.mean(T.log(p_y_given_x)[T.arange(y1.shape[0]), y1]) print ("result1", result.eval()) print("_______...
0
2016-07-27T18:16:12Z
38,620,882
<p>I don't have enough reputation to comment so I'll post this as an answer.</p> <p>Quoting verbatim from <a href="http://deeplearning.net/tutorial/logreg.html" rel="nofollow">here</a></p> <pre><code>y.shape[0] is (symbolically) the number of rows in y, i.e., number of examples (call it n) in the minibatch T.arange(y...
1
2016-07-27T18:44:55Z
[ "python", "neural-network", "theano" ]
Shape of numpy array comparison with empty list
38,620,429
<p>I have some problems understanding how python/numpy is casting array shapes when comparing to an empty list - which as far as I understand - is an implicit (element wise) comparison with False.</p> <p>In the following example the shape decreases by one in the last dimension, if it is not greater than 1.</p> <pre><...
0
2016-07-27T18:18:23Z
38,620,665
<p>This is ordinary broadcasting at work. When you do</p> <pre><code>z = N.zeros((2,2,1)) z == [] </code></pre> <p><code>[]</code> is interpreted as an array of shape <code>(0,)</code>, and then the shapes are broadcast against each other:</p> <pre><code>(2, 2, 1) vs (0,) </code></pre> <p>Since <code>(0,)</code>...
2
2016-07-27T18:32:07Z
[ "python", "arrays", "list", "numpy" ]
Updating sqlite3 dababase from tkinter frame
38,620,457
<p>I am trying to update my sqlite3 database with this function but I can't seem the pass the parameters correctly. Person is picked up by a selection that is made in the tkinter frame manually.</p> <pre><code>def updateContact(): person = select.get(ACTIVE) conn.execute("UPDATE Table set NAME =? WHERE NAME = ...
0
2016-07-27T18:20:02Z
38,620,555
<p>Just pass parameters in a <em>single non-nested tuple</em>:</p> <pre><code>conn.execute("UPDATE Table set NAME = ? WHERE NAME = ?", (nameVar.get(), person)) </code></pre>
0
2016-07-27T18:25:55Z
[ "python", "tkinter", "sqlite3", "labels" ]
json.dumps \u escaped unicode to utf8
38,620,471
<p>I came from this <a href="http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence">old discussion</a>, but the solution didn't help much as my original data was encoded differently:</p> <p>My original data was already encoded in unicode, I need to output as UTF-...
-1
2016-07-27T18:20:54Z
38,620,562
<p>You <em>have</em> UTF-8 JSON data:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; data = {'content': u'\u4f60\u597d'} &gt;&gt;&gt; json.dumps(data, indent=1, ensure_ascii=False) u'{\n "content": "\u4f60\u597d"\n}' &gt;&gt;&gt; json.dumps(data, indent=1, ensure_ascii=False).encode('utf8') '{\n "content": "\xe4...
3
2016-07-27T18:26:09Z
[ "python", "unicode", "encoding", "utf-8" ]
Python regex split into characters except if followed by parentheses
38,620,637
<p>I have a string like <code>"F(230,24)F[f(22)_(23);(2)%[+(45)FF]]"</code>, where each character except for parentheses and what they enclose represents a kind of instruction. A character can be followed by an optional list of arguments specified in optional parentheses.</p> <p>Such a string i would like to split the...
3
2016-07-27T18:30:01Z
38,620,713
<blockquote> <p>I am aware that this is likely caused by Python's re.split having been designed not to split on a zero length match</p> </blockquote> <p>You can use the <code>VERSION1</code> flag of the <a href="https://pypi.python.org/pypi/regex" rel="nofollow"><code>regex</code> module</a>. Taking <a href="http://...
2
2016-07-27T18:34:57Z
[ "python", "regex", "string", "split" ]
Python regex split into characters except if followed by parentheses
38,620,637
<p>I have a string like <code>"F(230,24)F[f(22)_(23);(2)%[+(45)FF]]"</code>, where each character except for parentheses and what they enclose represents a kind of instruction. A character can be followed by an optional list of arguments specified in optional parentheses.</p> <p>Such a string i would like to split the...
3
2016-07-27T18:30:01Z
38,620,749
<p>You can use <code>re.findall</code> to find out all single character optionally followed by a pair of parenthesis:</p> <pre><code>import re s = "F(230,24)F[f(22)_(23);(2)%[+(45)FF]]" re.findall("[^()](?:\([^()]*\))?", s) ['F(230,24)', 'F', '[', 'f(22)', '_(23)', ';(2)', '%', '[', '+(45)', 'F', 'F', ']',...
2
2016-07-27T18:36:36Z
[ "python", "regex", "string", "split" ]
Python regex split into characters except if followed by parentheses
38,620,637
<p>I have a string like <code>"F(230,24)F[f(22)_(23);(2)%[+(45)FF]]"</code>, where each character except for parentheses and what they enclose represents a kind of instruction. A character can be followed by an optional list of arguments specified in optional parentheses.</p> <p>Such a string i would like to split the...
3
2016-07-27T18:30:01Z
38,621,966
<p>Another solution. This time the pattern recognize strings with the structure <strong>SYMBOL[(NUMBER[,NUMBER...])]</strong>. The function <code>parse_it</code> returns <em>True</em> and the tokens if the string match with the regular expression and <em>False</em> and empty if don't match.</p> <pre><code>import re de...
1
2016-07-27T19:49:27Z
[ "python", "regex", "string", "split" ]
SQLAlchemy - Postgres: using with_entities for querying JSON element
38,620,657
<p>I am trying to query for a field in JSON column (Postgres):</p> <pre><code>class MyTable(Base): __tablename__ = 'my_table' data = Column(JSONB) </code></pre> <p>Query:</p> <pre><code>my_query = session.query(MyTable).limit(10).with_entities(MyTable.data['rule']).all() </code></pre> <p>I get no error, bu...
0
2016-07-27T18:31:34Z
38,622,690
<p>The addition of <code>label()</code> method solved the issue for me:</p> <pre><code>my_query = session.query(MyTable).limit(10). \ with_entities(MyTable.data['rule'].label('rule')).all() </code></pre>
0
2016-07-27T20:34:27Z
[ "python", "json", "postgresql", "sqlalchemy" ]
A fast numpy way to find index in array where cumulative sum becomes greater?
38,620,741
<p>Basically, the <em>logic</em> of my problem is:</p> <pre><code>running_sum = my_array.cumsum() greater_than_threshold = running_sum &gt; threshold index = greater_than_threshold.searchsorted(True) </code></pre> <p>That is: Find the first index for which the cumulative sum of entries in <code>my_array</code> is abo...
1
2016-07-27T18:36:13Z
38,621,125
<p>EDIT: This method is slower than using NumPy's <code>searchsorted</code> and <code>cumsum</code>, see user2357112's comments and <code>timeit</code> test.</p> <p><code>cumsum</code> will calculate cumulative sums for the entire array. Instead, just iterate over the array yourself:</p> <pre><code>running_sum = 0 fo...
0
2016-07-27T18:58:48Z
[ "python", "arrays", "numpy" ]
Count iterations in while loop
38,620,745
<p>Is there a way in Python to automatically add an iteration counter to a while loop?</p> <p>I'd like to remove the lines <code>count = 0</code> and <code>count += 1</code> from the following code snippet but still be able to count the number of iterations and test against the boolean <code>elapsed &lt; timeout</code...
5
2016-07-27T18:36:25Z
38,620,976
<p>The cleanest way is probably to convert this to an infinite <code>for</code> loop and move the loop test to the start of the body:</p> <pre><code>import itertools for i in itertools.count(): if time.time() - start &gt;= timeout: break ... </code></pre>
6
2016-07-27T18:50:51Z
[ "python", "python-2.7", "loops" ]
Count iterations in while loop
38,620,745
<p>Is there a way in Python to automatically add an iteration counter to a while loop?</p> <p>I'd like to remove the lines <code>count = 0</code> and <code>count += 1</code> from the following code snippet but still be able to count the number of iterations and test against the boolean <code>elapsed &lt; timeout</code...
5
2016-07-27T18:36:25Z
38,621,012
<p>You could instead move the while loop to a generator and use <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a>:</p> <pre><code>import time def iterate_until_timeout(timeout): start = time.time() while time.time() - start &lt; timeout: yi...
3
2016-07-27T18:52:45Z
[ "python", "python-2.7", "loops" ]
Django passing JSON data to static getJSON/Javascript
38,620,816
<p>I am trying to grab data from my models.py and serialize it into a JSON object within my views.py. </p> <p><strong>Models.py:</strong></p> <pre><code>class Platform(models.Model): platformtype = models.CharField(max_length=25) </code></pre> <p><strong>Views.py:</strong></p> <pre><code>def startpage(request)...
1
2016-07-27T18:40:54Z
38,621,448
<p>Main html render + json data</p> <pre><code>import json from django.shortcuts import render def startpage(request): platforms = Platform.objects.select_related().values('platformtype') return render(request, 'Main.html', {'platforms_as_json': json.dumps(list(platforms)),}) </code></pre> <p>in template </p...
1
2016-07-27T19:19:04Z
[ "javascript", "jquery", "python", "mysql", "django" ]
matplotlib/python - How to draw a plot like this? mean ± 3*standard deviation
38,620,828
<p>I want a picture like this: <a href="http://i.stack.imgur.com/d3ddl.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/d3ddl.jpg" alt="enter image description here"></a></p> <p>The upper and lower limit of x axis is given and is much larger/smaller than the given data.</p> <p>All plot I find is only ± 1*stan...
1
2016-07-27T18:41:32Z
38,621,678
<p>not sure I understand exactly what you are trying. Check out this example if it does something similar to what you want?</p> <pre><code>import numpy as np import matplotlib.pyplot as plt #create random data data=np.random.random(100) std=np.std(data) #display the individual data points plt.scatter(data,np.zeros(d...
1
2016-07-27T19:32:42Z
[ "python", "matplotlib", "plot" ]
Flask Git Enoent Spawn Error
38,620,842
<p>I'm trying to deploy a flask application to Heroku. I'm following the steps on the website to deploy my app using the heroku toolbelt. I'm able to execute the command</p> <pre><code>git init </code></pre> <p>but when I try to use</p> <pre><code>heroku git:remote -a bcamarketplace </code></pre> <p>I get the follo...
0
2016-07-27T18:42:30Z
38,621,697
<p>It might be that you haven't added a git remote for the app. Try running this:</p> <pre><code>git remote add heroku git@heroku.com:your-app-name-here.git </code></pre> <p>Then proceed as you were. </p>
0
2016-07-27T19:34:05Z
[ "python", "git", "heroku", "flask" ]
Converting a pandas dataframe with a string type, three level MultiIndex into numeric type objects
38,620,850
<p>I have a pandas dataframe with a three level MultiIndex that looks like this:</p> <pre><code>gene TIMP2 VEGFA VIM 2 TGFb 0.1 0.035655 0.876214 -0.158406 1 0.087623 1.049764 0.039158 10 0.054119 0.887348 -0.052608 24 TGFb 0.1 0.148470 0.565379 0.157153 ...
2
2016-07-27T18:43:04Z
38,621,068
<p>This should do it for you:</p> <pre><code>df.index = df.index.set_levels(idx.levels[0].astype(int), level=0) \ .set_levels(idx.levels[2].astype(float), level=2) </code></pre>
1
2016-07-27T18:55:22Z
[ "python", "pandas", "multi-index" ]
Fix “UnicodeDecodeError: can't decode byte
38,620,892
<p>Well I have written a code in python2. Usually I use python3 and never had the issue but its not working here. Please help, can't post the code, it's the policy. I hope you would understand as a programmer.</p> <p>Hope anyone can help.</p>
-5
2016-07-27T18:46:05Z
38,621,028
<pre><code>import sys reload(sys) sys.setdefaultencoding('utf8') </code></pre> <p>Its just a guess as there is no code but if your code used to work in python3 and not in Python2 then this was the only problem I could think of. Try this if it helps. Otherwise its very difficult to recognize the issue.</p> <p><stro...
-2
2016-07-27T18:53:32Z
[ "python", "python-3.x" ]
Using command line args from different files in python
38,620,899
<p>I recently discovered (Much to my surprised) you can call command line args in files other than the one that is explicitly called when you enter it. </p> <p>So, you can run <code>python file1.py abc</code> in command line, and use sys.argv[1] to get the string 'abc' from within file2.py or file3.py.</p> <p>I still...
0
2016-07-27T18:46:22Z
38,621,007
<p>As for the how/why, <code>sys</code> is only imported once (when python starts up). When <code>sys</code> is imported, it's <code>argv</code> member gets populated with the commandline arguements. Subsequent <code>import</code> statements return the same <code>sys</code> module object so no matter where you <code>...
2
2016-07-27T18:52:29Z
[ "python", "command-line-arguments" ]
Django extract queryset from ManyToMany with through field
38,620,984
<p>Say we have those models:</p> <pre><code>class A(models.Model): field = models.ManyToManyField(B, through="C") class B(models.Model): value = models.CharField() class C(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) order = models.IntegerField() </code></pre> <p>Is there an o...
0
2016-07-27T18:51:20Z
38,621,259
<p>Use the <code>C</code> model reverse relations to do the order, e.g.</p> <pre><code>a.fields.order_by(c__order) </code></pre>
0
2016-07-27T19:07:20Z
[ "python", "django" ]
Django extract queryset from ManyToMany with through field
38,620,984
<p>Say we have those models:</p> <pre><code>class A(models.Model): field = models.ManyToManyField(B, through="C") class B(models.Model): value = models.CharField() class C(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) order = models.IntegerField() </code></pre> <p>Is there an o...
0
2016-07-27T18:51:20Z
38,621,291
<p>If you put a an <code>ordering</code> on model <code>C</code>, all queryset on <code>C</code> would obey that order:</p> <pre><code>class C(models.Model): class Meta: ordering = ('order', ) </code></pre> <p>Now if you want <code>B</code> objects related to <code>A</code>, you could sort the <code>B</c...
1
2016-07-27T19:09:42Z
[ "python", "django" ]
Sphinx fails to document flask project due to import current_app
38,621,256
<p>I have set up Sphinx to document my flask project, however, I encounter this error:</p> <pre><code>[$]&gt;&gt;&gt; make html sphinx-build -b html -d build/doctrees -W -v source build/html Running Sphinx v1.4.5 loading pickled environment... not yet created building [mo]: targets for 0 po files that are out of date...
1
2016-07-27T19:07:11Z
38,669,424
<p>The issue is actually with sphinx. Sphinx 1.4.5 contains a bug that causes this behavior. This can be fixed by installing sphinx from git. Hopefully they will push a new version out to pypi soon.</p> <p>edit: Sphinx 1.4.4 also works fine.</p>
3
2016-07-30T01:08:44Z
[ "python", "flask", "python-sphinx" ]
Dropzone doesn't redirect after upload to Flask app
38,621,273
<p>I'm writing a resource to upload files to a Flask app using Dropzone. After files are uploaded the app should redirect to the hello world page. This is not happening and the app is stuck on the view that uploaded the files. I'm using jQuery 3.1.0 and Dropzone from master.</p> <pre><code>from flask import Flask, r...
0
2016-07-27T19:08:44Z
38,621,506
<p>I'm not too familiar with dropzone, but I will give you an example from one of my flask applications that uses file uploading. I'm just using the standard HTML upload form. Hopefully from here you should be able to get an idea of what's going on.</p> <p>Note, i'm not using a template for my file uploading.</p> <pr...
0
2016-07-27T19:22:24Z
[ "javascript", "python", "flask", "dropzone.js" ]
Dropzone doesn't redirect after upload to Flask app
38,621,273
<p>I'm writing a resource to upload files to a Flask app using Dropzone. After files are uploaded the app should redirect to the hello world page. This is not happening and the app is stuck on the view that uploaded the files. I'm using jQuery 3.1.0 and Dropzone from master.</p> <pre><code>from flask import Flask, r...
0
2016-07-27T19:08:44Z
39,529,288
<p>I had similar problem in my flask application and I solved it with following jQuery function:</p> <pre><code>Dropzone.options.myDropzone = { autoProcessQueue: false, init: function() { var submitButton = document.querySelector("#upload-button"); myDropzone = this; submitButton.addEventListener("click...
0
2016-09-16T10:31:33Z
[ "javascript", "python", "flask", "dropzone.js" ]
How to Stop OneNote API From Returning ID for Deleted Pages
38,621,322
<p>I place a call using the OneNote REST API to return a list of all the pages in a section. This works successfully. However, some of the pages it returns should no longer exist! Yet I can see their information, IDs, etc., even though they have previously been deleted. But if I try to delete them again using REST, I g...
0
2016-07-27T19:11:26Z
38,622,608
<p>I assume these pages do appear as deleted in your notebook if you open OneNote. Can you try adding this header to your GET ~/pages request?</p> <pre><code>FavorDataRecency: true </code></pre> <p>This will bypass our index and go directly to your pages. It will take longer but should be consistent - do you see your...
0
2016-07-27T20:28:10Z
[ "python", "delete-file", "onenote", "http-delete", "onenote-api" ]
Python function design for arithmetic operations
38,621,338
<p>Purpose:<br> <i>"Write a Python function that takes 3 numbers as arguments. Your function should repeatedly subtract the second argument from the first argument until the value is less than zero. Your function should then print out this (negative) value."</i></p> <p>My suggested solution (What I have so far):</p> ...
0
2016-07-27T19:12:49Z
38,621,489
<pre><code>def subtraction(a,b,c): # why does c exist? return a % b - b </code></pre> <p>The smallest positive number achieved by repeated subtraction (repeated subtraction is division) is the modulus of the two numbers. To find the next number, just subtract once more.</p> <p>Unless you <em>have</em> to use...
3
2016-07-27T19:21:38Z
[ "python" ]
Python function design for arithmetic operations
38,621,338
<p>Purpose:<br> <i>"Write a Python function that takes 3 numbers as arguments. Your function should repeatedly subtract the second argument from the first argument until the value is less than zero. Your function should then print out this (negative) value."</i></p> <p>My suggested solution (What I have so far):</p> ...
0
2016-07-27T19:12:49Z
38,621,558
<p>You're forgetting to loop! As a result, you're not subtracting <code>b</code> from <code>a</code> until <code>a</code> is less than zero. I suggest using a while loop like this,</p> <pre><code>def subtraction(a, b, c): firstnum = a while firstnum &gt;= 0: firstnum -= b return firstnum </code></...
2
2016-07-27T19:25:44Z
[ "python" ]