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
passing parameters through url to view django
39,078,506
<p>I'm having some difficulty passing values to my view through url.</p> <p>So far, I've managed to run my view without any issues. </p> <p>view.py (draws a graph):</p> <pre><code>def draw(request) .... .... return HttpResponse (buffer.getvalue(), content_type="Image/png") </code></pre> <p>but I need my...
1
2016-08-22T11:35:36Z
39,078,852
<p>Fo url like</p> <pre><code>url(r'^graph/(?P&lt;desired_loan&gt;\d+)/$', views.draw, name='draw'), </code></pre> <p>Change your view to: </p> <pre><code>def draw(request, *args, **kwargs): loanAmount = kwargs['desired_loan'] ..... </code></pre> <p>Then change in template:</p> <pre><code>&lt;img src="{% url 'gr...
2
2016-08-22T11:52:34Z
[ "python", "django" ]
Django-superform does not render
39,078,772
<p><strong>My spec:</strong> <br>Django 1.9<br> Python 3.5.1<br> django-superform 0.3.1<br></p> <p><strong>My goal:</strong><br> I want <code>bod_quota</code> form nested with <code>CustomerForm</code></p> <p><strong>My attempt</strong><br></p> <p>I have follow the docs <a href="https://github.com/gregmuellegger/dja...
0
2016-08-22T11:49:10Z
39,084,603
<p>There’s two way to show this in the browser.</p> <pre><code>• views methods: I think it’s well explained here </code></pre> <p><a href="http://tutorial.djangogirls.org/en/django_forms/" rel="nofollow">http://tutorial.djangogirls.org/en/django_forms/</a></p> <pre><code>• django admin interface </code><...
0
2016-08-22T16:37:08Z
[ "python", "django" ]
Traversing level order for the graph in networkx
39,078,805
<p>I am trying to convert a <code>DiGraph</code> into n-ary tree and displaying the nodes in level order or BFS. My tree is similar to this, but much larger, for simplicity using this example: </p> <pre><code>G = networkx.DiGraph() G.add_edges_from([('n', 'n1'), ('n', 'n2'), ('n', 'n3')]) G.add_edges_from([('n4', 'n41...
0
2016-08-22T11:51:02Z
39,080,114
<p>You could use the bfs_edges() function to get a list of nodes in a breadth-first-search order.</p> <pre><code>In [1]: import networkx In [2]: G = networkx.DiGraph() In [3]: G.add_edges_from([('n', 'n1'), ('n', 'n2'), ('n', 'n3')]) In [4]: G.add_edges_from([('n4', 'n41'), ('n1', 'n11'), ('n1', 'n12'), ('n1', 'n13...
1
2016-08-22T12:53:29Z
[ "python", "networkx" ]
Resampling and Normalizing Irregular Time Series Data in Pandas
39,078,835
<p>I have irregularly spaced time-series data. I have total energy usage and the duration over which the energy was used.</p> <pre><code>Start Date Start Time Duration (Hours) Usage(kWh) 1/3/2016 12:28:00 PM 2.233333333 6.23 1/3/2016 4:55:00 PM 1.9 11.45 1/4/2016 6:47...
1
2016-08-22T11:52:13Z
39,085,505
<p>Here is a straight-forward implementation which simply sets up a Series, <code>result</code>, whose index has minute-frequency, and then loops through the rows of <code>df</code> (using <code>df.itertuples</code>) and adds the appropriate amount of power to each row in the associated interval:</p> <pre><code>import...
3
2016-08-22T17:34:42Z
[ "python", "pandas", "time-series", "aggregate" ]
Resampling and Normalizing Irregular Time Series Data in Pandas
39,078,835
<p>I have irregularly spaced time-series data. I have total energy usage and the duration over which the energy was used.</p> <pre><code>Start Date Start Time Duration (Hours) Usage(kWh) 1/3/2016 12:28:00 PM 2.233333333 6.23 1/3/2016 4:55:00 PM 1.9 11.45 1/4/2016 6:47...
1
2016-08-22T11:52:13Z
39,130,274
<p>The solution I used below is the itertuples method. Please note using numpy's .sum function did not work for me. I instead used the pandas resample keyword, "how" and set it equal to sum.</p> <p>I also renamed the columns in my files to make the import easier. </p> <p>I was not time/resource constrained so I went ...
0
2016-08-24T18:10:40Z
[ "python", "pandas", "time-series", "aggregate" ]
Filter safe does not work on the shy tag issue
39,078,914
<p>I have a problem with breaking words in the right place at the Django template. Appears <code>&amp;shy;</code> I'm trying to filter safe, but it does not work.</p> <p>Here is my code:</p> <pre><code> &lt;div class="my_class"&gt; &lt;h3&gt;{{ object.title|safe }}&lt;/h3&gt; &lt;/div&gt; </code></pre>...
0
2016-08-22T11:55:12Z
39,079,946
<p>From the doc here:<a href="https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#safe" rel="nofollow">safe</a></p> <blockquote> <p>safe</p> <p>Marks a string as not requiring further HTML escaping prior to output. When autoescaping is off, this filter has no effect.</p> </blockquote> <p>And Django'...
0
2016-08-22T12:45:27Z
[ "python", "django", "templates", "frontend", "css-hyphens" ]
How to recognize text regions using histogram?
39,078,999
<p>I have a sample image which looks like this:</p> <p><img src="http://i.stack.imgur.com/lIgK4.png" alt=""></p> <p>There could be one or more horizontal lines that separate text sections. I am looking to get 4 chunks of text which looks like:</p> <p><img src="http://i.stack.imgur.com/k3z4P.png" alt=""></p> <p>The ...
1
2016-08-22T11:59:35Z
39,087,523
<p>Detect hougLines -> Black Out the Lines -> Dialate . </p> <h1>Code</h1> <pre><code>import cv2 import numpy as np; im = cv2.imread("im.png") im_gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY) ret,thresh = cv2.threshold(im_gray,127,255,cv2.THRESH_BINARY_INV) edges = cv2.Canny(im_gray,50,150,apertureSize = 3) minLineLeng...
0
2016-08-22T19:44:39Z
[ "python", "opencv", "histogram" ]
Spliting up data to match a certian criteria in my view and template django
39,079,037
<p>I want to be able to split up my reading(reading is Inspeciton_vals object) data into multiple rows based off of a description(description is a object from my dimension model) So far I haven't figured out any way of doing so, any help would be greatly appreciated. </p> <p>To break it down I have a Inspeciton_vals ...
0
2016-08-22T12:01:51Z
39,130,363
<p>Figured it out basically I turned two list into a dictionary and just iterate over them to give me the results I wanted.</p> <pre><code>complete_data = Sheet.objects.raw("""select s.id, d.id d_id, s.work_order, d.target, i.reading, d.description, i.serial_number from app_sheet s left join app_dimension d on s.id = ...
0
2016-08-24T18:14:56Z
[ "python", "django", "python-2.7" ]
Index out of range error in scrapy
39,079,044
<p>I am trying to scrape a website and get details of the products. Some of the products have unit and some have not. The structure is something like this below:</p> <p><strong>For products having a unit:</strong></p> <pre><code>&lt;div class="unit"&gt; &lt;p&gt;200ml&lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>...
-2
2016-08-22T12:02:01Z
39,079,543
<p>There's a slight flaw in your spider's logic. Usually it's possible to get list of products selectors and just iterate through them. Something like this:</p> <pre><code>def product(self, response): products = response.xpath('descendant::*[@class="product_list_ul"]') # [1] "//" is short for "descendant::" so...
0
2016-08-22T12:26:48Z
[ "python", "web-scraping", "scrapy" ]
Index out of range error in scrapy
39,079,044
<p>I am trying to scrape a website and get details of the products. Some of the products have unit and some have not. The structure is something like this below:</p> <p><strong>For products having a unit:</strong></p> <pre><code>&lt;div class="unit"&gt; &lt;p&gt;200ml&lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>...
-2
2016-08-22T12:02:01Z
39,092,768
<p>So I figured out a way to do this.</p> <pre><code>def unit_xpath(self, response): x = [txt for item in response.xpath('descendant::*[@class="unit"]/p') for txt in item.xpath('text()').extract() or [u'N/A']] return x def product(self, response): products = response.xpath('descendant::*[@clas...
0
2016-08-23T05:06:18Z
[ "python", "web-scraping", "scrapy" ]
Python List Comprehension - extracting from nested data
39,079,131
<p>Im new to python and was trying to extract out some nested data</p> <p>Here is the JSON for two products. A product can belong to zero or more categories</p> <pre><code> {  "Item":[  {  "ID":"170", "InventoryID":"170", "Categories":[  {  ...
2
2016-08-22T12:07:01Z
39,079,206
<p>That's a very poor document structure in that case; you shouldn't have to deal with this. If an item can contain multiple values, it should always be a list.</p> <p>Be that as it may, you can still deal with it in your code by checking if it is a list or not.</p> <pre><code>for x in products: productsInCatego...
4
2016-08-22T12:10:58Z
[ "python" ]
Python List Comprehension - extracting from nested data
39,079,131
<p>Im new to python and was trying to extract out some nested data</p> <p>Here is the JSON for two products. A product can belong to zero or more categories</p> <pre><code> {  "Item":[  {  "ID":"170", "InventoryID":"170", "Categories":[  {  ...
2
2016-08-22T12:07:01Z
39,079,456
<p>I've run into this issue frequently before in JSON structures...frequently enough that I wrote a small library for it a few weeks ago...</p> <p><a href="https://github.com/tfulmer1/nkr" rel="nofollow">nested key retriever (nkr)</a></p> <p>Try the generator and see if it solves your problem. You should be able to s...
1
2016-08-22T12:22:32Z
[ "python" ]
Reports With Django
39,079,169
<p>I'm trying to create a pretty advanced query within django and im having problems doing so, i can use the basic:</p> <pre><code>for obj in Invoice.objects.filter(): </code></pre> <p>but if i try and move this into raw PostgreSQL query i get an error telling me that the relation does not exist am i doing something ...
-1
2016-08-22T12:09:27Z
39,079,288
<p>try running your raw sql directly in the database.. my guess is that your table name is not correct, usually they're lowercase</p> <p>BTW.. I hope you have a very good reason for using raw sql queries and not the awesome ORM ;)</p>
1
2016-08-22T12:14:55Z
[ "python", "django", "postgresql" ]
Python Multiprocessing using Pool goes recursively haywire
39,079,183
<p>I'm trying to make an expensive part of my pandas calculations parallel to speed up things.</p> <p>I've already managed to make Multiprocessing.Pool work with a simple example:</p> <pre><code>import multiprocessing as mpr import numpy as np def Test(l): for i in range(len(l)): l[i] = i**2 return l t = li...
1
2016-08-22T12:09:55Z
39,079,709
<p>I managed to make it work by enceasing the entire script into the <code>if __name__ == "__main__":</code>-statement, not just the multiprocessing part.</p>
1
2016-08-22T12:34:36Z
[ "python", "pandas", "python-multiprocessing" ]
Python script makes a file but doesn't write anything
39,079,278
<p>First, code gets a name and makes a file with <code>w</code> permission (also tested <code>r+</code>) and it should write any other input in file, but it doesn't. I get an empty file.</p> <pre><code>user_name_in =input("gets Input") fname = user_name_in f = input() ufile = open(fname,"w") while True: f=input(a...
1
2016-08-22T12:14:24Z
39,079,406
<p>This code works for me:</p> <pre><code>user_name_in =input("gets Input") fname = user_name_in f = input() ufile = open(fname,"w") while True: f=input(answer) ufile.write(f) </code></pre> <p>Some considerations: I don't see where <em>answer</em> is declared, neither python interpreter see :P, maybe you forg...
1
2016-08-22T12:20:17Z
[ "python" ]
Python script makes a file but doesn't write anything
39,079,278
<p>First, code gets a name and makes a file with <code>w</code> permission (also tested <code>r+</code>) and it should write any other input in file, but it doesn't. I get an empty file.</p> <pre><code>user_name_in =input("gets Input") fname = user_name_in f = input() ufile = open(fname,"w") while True: f=input(a...
1
2016-08-22T12:14:24Z
39,079,416
<p>As i wrote in the comments, always use the <code>with</code> block to handle files as it takes care of intricacies you don't have to worry about. Now on the code, you repeat yourself, for example the first two lines are actually one.. This is what it would look when cleaned a bit.</p> <pre><code>fname = input("gets...
5
2016-08-22T12:20:37Z
[ "python" ]
Largest subset in an array such that the smallest and largest elements are less than K apart
39,079,381
<p>Given an array, I want to find the largest subset of elements such that the smallest and largest elements of the subset are less than or equal to K apart. Specifically, I want the elements, not just the size. If there are multiple occurrences, any can be matched.</p> <p>For example, in the array <code>[14,15,17,20,...
3
2016-08-22T12:19:16Z
39,079,856
<p>Brute force approach:</p> <pre><code>arr = [14,14,14,15,16,17,17] max_difference = 3 solution = [] for i, start in enumerate(arr): tmp = [] largest = start smallest = start for j, end in enumerate(arr[i:]): if abs(end - largest) &lt;= max_difference and abs(end - smallest) &lt;= max_differe...
-1
2016-08-22T12:41:56Z
[ "python", "algorithm" ]
Largest subset in an array such that the smallest and largest elements are less than K apart
39,079,381
<p>Given an array, I want to find the largest subset of elements such that the smallest and largest elements of the subset are less than or equal to K apart. Specifically, I want the elements, not just the size. If there are multiple occurrences, any can be matched.</p> <p>For example, in the array <code>[14,15,17,20,...
3
2016-08-22T12:19:16Z
39,079,955
<p>An inefficient algorithm (O(n^2)) for this would be very simple:</p> <pre><code>l = [14,15,17,20,23] s = max((list(filter(lambda x: start&lt;=x&lt;=start+3, l)) for start in l), key=len) print(s) </code></pre>
-1
2016-08-22T12:45:46Z
[ "python", "algorithm" ]
Largest subset in an array such that the smallest and largest elements are less than K apart
39,079,381
<p>Given an array, I want to find the largest subset of elements such that the smallest and largest elements of the subset are less than or equal to K apart. Specifically, I want the elements, not just the size. If there are multiple occurrences, any can be matched.</p> <p>For example, in the array <code>[14,15,17,20,...
3
2016-08-22T12:19:16Z
39,080,422
<p>A speedy approach with complexity O(n*log(n)) for the sort and O(n) to search for the longest chain:</p> <pre><code>list_1 = [14, 15, 17, 20, 23] k = 3 list_1.sort() list_len = len(list_1) min_idx = -1 max_idx = -1 idx1 = 0 idx2 = 0 while idx2 &lt; list_len-1: idx2 += 1 while list_1[idx2] - list_1[idx1]...
-1
2016-08-22T13:07:55Z
[ "python", "algorithm" ]
Largest subset in an array such that the smallest and largest elements are less than K apart
39,079,381
<p>Given an array, I want to find the largest subset of elements such that the smallest and largest elements of the subset are less than or equal to K apart. Specifically, I want the elements, not just the size. If there are multiple occurrences, any can be matched.</p> <p>For example, in the array <code>[14,15,17,20,...
3
2016-08-22T12:19:16Z
39,093,507
<p>I assume that <strong>we can not modify array by sorting it</strong> &amp; we have to find out <strong>largest consecutive Subset</strong>, So my solution (in python 3.2) is :</p> <pre><code>arr = [14, 15, 17, 20, 23] k = 3 f_start_index=0 f_end_index =0 length = len(arr) for i in range(length): min_value = a...
1
2016-08-23T06:06:42Z
[ "python", "algorithm" ]
Largest subset in an array such that the smallest and largest elements are less than K apart
39,079,381
<p>Given an array, I want to find the largest subset of elements such that the smallest and largest elements of the subset are less than or equal to K apart. Specifically, I want the elements, not just the size. If there are multiple occurrences, any can be matched.</p> <p>For example, in the array <code>[14,15,17,20,...
3
2016-08-22T12:19:16Z
39,144,412
<p>This seems very similar to your "naïve" approach, but it's O(n) excluding the sort so I don't think you can improve on your approach much. The optimization is to use indices and only create a second array once the answer is known:</p> <pre><code>def largest_less_than_k_apart(a, k): a.sort() upper_index = l...
1
2016-08-25T11:46:01Z
[ "python", "algorithm" ]
implemention of python builtin function
39,079,400
<p>I'm a freshman in python and I want to study the implemention of python's builtin function like <code>abs()</code>, but in the python file of <code>\__builtin__.py</code> I saw this:</p> <p><img src="http://i.stack.imgur.com/VW1od.png" alt="builtin_abs_function"></p> <p>Does anybody know how it works?</p>
0
2016-08-22T12:20:10Z
39,079,597
<p>The built-in functions are implemented in the same language as the interpreter, so the source code is different depending on the Python implementation you are using (Jython, CPython, PyPy, etc). You are probably using CPython, so the <code>abs()</code> function is implemented in C. You can look at the real source co...
5
2016-08-22T12:29:30Z
[ "python", "builtin" ]
Data frame group ID, create value: count in column
39,079,415
<p>Given the following sample dataset:</p> <pre><code>import numpy as np import pandas as pd df1 = (pd.DataFrame(np.random.randint(3, size=(5, 4)), columns=('ID', 'X1', 'X2', 'X3'))) print(df1) ID X1 X2 X3 0 2 2 0 2 1 1 0 2 1 2 1 2 1 1 3 1 2 0 2 4 2 0 0 0 d = {'ID' : pd....
2
2016-08-22T12:20:35Z
39,208,560
<p><a href="/questions/tagged/user3939059" class="post-tag" title="show questions tagged &#39;user3939059&#39;" rel="tag">user3939059</a></p> <pre><code>1 0 2 1 [One: 3, Two: 3] </code></pre> <p>should be [One: 2, Two:3] instead right? Considering that:</p> <pre><code> 1 : [One,Two] 0 : None 2 : [Two] ...
0
2016-08-29T14:20:47Z
[ "python", "pandas" ]
linear programming with scipy.optimize.linprog - variable coefficients
39,079,458
<p>Trying to optimize using scipy.optimize.linprog a cost function, where the cost coefficients are function of the variables; e.g. </p> <p>Cost = c1 * x1 + c2 * x2 (x1,x2 are the variables)</p> <p>for example</p> <p>if x1 = 1, c1 = 0.5</p> <p>if x1 = 2, c1 = 1.25</p> <p>etc.</p> <p>Thank you for your help</p> <...
-1
2016-08-22T12:22:36Z
39,089,821
<p>Here is some prototype-code to show you how, that your problem is quite hard (regarding formulation and performance; the former is visible in the code).</p> <p>The implementation uses cvxpy for modelling (<strong>convex-programming only</strong>) and is based on the <strong>mixed-integer approach</strong>.</p> <h3...
1
2016-08-22T22:44:12Z
[ "python", "numpy", "simplex" ]
Error in dictionary to list manipulation in python
39,079,477
<p>I got stuck in a code in python. I am new to python.<br> I have tried to add the polynomial in a basic way but I don't know how to get the values as a dictionary and convert it to a list and back.<br> This is the code I have tried:</p> <pre><code>def add(s1,s2): if len(s1) &gt; len(s2): new = [i for i i...
-1
2016-08-22T12:23:15Z
39,080,409
<p>I am running your code in python-3.x and it gives output like <code>[(-4, 3, 4, 3), (2, 1, 3, 0)]</code><br> so it is only a concatenation of the input, because for the input <code>add([(4,3),(3,0)],[(-4,3),(2,1)])</code> there is a list inside another list.</p> <p>For more explanation: if the input is like <code>a...
2
2016-08-22T13:07:30Z
[ "python", "python-3.x" ]
Matplotlib animation: vertical cursor line through subplots
39,079,562
<p><strong>[Solution has been added to the EDIT sections in this post]</strong></p> <p>2 animated subplots are stacked vertically.</p> <p>I would like to show a black vertical line through them according to the mouse position. </p> <p>Up to now I can only completely mess the figure when moving the mouse...</p> <p>H...
0
2016-08-22T12:27:48Z
39,082,657
<p>replace your <code>onMouseMove</code> with the following one:</p> <p>(I used <a href="http://stackoverflow.com/questions/4981815/how-to-remove-lines-in-a-matplotlib-plot">How to remove lines in a Matplotlib plot</a>)</p> <pre><code>def onMouseMove(event): ax1.lines = [ax1.lines[0]] ax2.lines = [ax2.lines[0]] ...
1
2016-08-22T14:51:55Z
[ "python", "animation", "matplotlib", "cursor", "mouse" ]
Pillow: strange behavior using Draw.rectangle
39,080,087
<p>I am drawing rectangles in a for-loop using Pillow. This worked on my desktop computer, but throwing a strange exception on my laptop.</p> <p>This is the code (shortened):</p> <pre><code>from PIL import Image, ImageDraw (...) img = Image.open(sys.argv[1]) rimg = img.copy() rimg_draw = ImageDraw.Draw(rimg) (...) (f...
0
2016-08-22T12:51:54Z
39,081,436
<p>After slight adjustments to your code to make it run, I was not able to reproduce the exception.</p> <pre><code>from PIL import Image, ImageDraw img = Image.open('testfig.png') rimg = img.copy() rimg_draw = ImageDraw.Draw(rimg) rimg_draw.rectangle((10, 10, 30, 30), fill=None, outline=(255, 0, 0)) rimg.show() </cod...
2
2016-08-22T13:55:22Z
[ "python", "python-2.7", "python-imaging-library", "pillow" ]
Find clipped pixels in a RGB image
39,080,153
<p>I have an image image.png and I want to find all clipped pixels. Here is what I have so far:</p> <pre><code>for i in range(1,width): for j in range(1, height): r,g,b = image.getpixel((i,j)) If( ): # I don't know what should be the condition here # do something else </code></pre> <p>I...
1
2016-08-22T12:55:27Z
39,081,018
<p>If by 'clipped' you mean saturated, then you probably want to create a threshold based on the intensity of the pixel. There are a few equations that try to determine this, but I would recommend one of the <a href="https://en.wikipedia.org/wiki/Grayscale" rel="nofollow">Grayscale equations</a>. Looking at the equatio...
0
2016-08-22T13:34:01Z
[ "python", "image", "tkinter", "python-imaging-library", "clipped" ]
Python check if date is within 24 hours
39,080,155
<p>I have been trying some code for this, but I can't seem to completely wrap my head around it.</p> <p>I have a set date, <code>set_date</code> which is just some random date as you'd expect and that one is just data I get. Now I would like some error function that raises an error if <code>datetime.now()</code> is wi...
1
2016-08-22T12:55:37Z
39,080,237
<p>Like that?</p> <pre><code>if now-timedelta(hours=24) &lt;= set_date &lt;= now: ... #date less than 24 hours in the past </code></pre> <p>If you want to check for the date to be within 24 hours on either side:</p> <pre><code>if now-timedelta(hours=24) &lt;= set_date &lt;= now+timedelta(hours=24): ... #date...
4
2016-08-22T12:59:16Z
[ "python" ]
Python check if date is within 24 hours
39,080,155
<p>I have been trying some code for this, but I can't seem to completely wrap my head around it.</p> <p>I have a set date, <code>set_date</code> which is just some random date as you'd expect and that one is just data I get. Now I would like some error function that raises an error if <code>datetime.now()</code> is wi...
1
2016-08-22T12:55:37Z
39,080,745
<p>That will do:</p> <pre><code>if now - timedelta(hours=24) &lt;= set_date &lt;= now + timedelta(hours=24): #Do something </code></pre> <p>Which is equivalent to:</p> <pre><code>if now - timedelta(hours=24) &lt;= set_date &lt;= now or now &lt;= set_date &lt;= now + timedelta(hours=24): # ...
0
2016-08-22T13:22:20Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,284
<p>try the following (list comprehension)</p> <pre><code>['%.5f'% t for t in tup] </code></pre>
0
2016-08-22T13:01:34Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,291
<p>Try this:</p> <pre><code>class showlikethis(float): def __repr__(self): return "%0.5f" % self tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) tup = map(showlikethis, tup) print tup </code></pre> <p>You may like to re-quote your question, tuple dnt have pre...
-1
2016-08-22T13:01:50Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,297
<p>You can print the floats with custom precision "like a tuple":</p> <pre><code>&gt;&gt;&gt; tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) &gt;&gt;&gt; print('(' + ', '.join(('%.5f' % f) for f in tup) + ')') (0.00390, 0.39024, -0.00585, -0.58537) </code></pre>
0
2016-08-22T13:02:02Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,299
<p>you can work on single item. Try this:</p> <pre><code>&gt;&gt;&gt; tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) &gt;&gt;&gt; for t in tup: print ("%.5f" %(t)) 0.00390 0.39024 -0.00585 -0.58537 </code></pre>
0
2016-08-22T13:02:13Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,318
<p>You can iterate over tuple like this, and than you can print result for python > 3</p> <pre><code>["{:.5f}".format(i) for i in tup] </code></pre> <p>And for python 2.7</p> <pre><code>['%.5f'% t for t in tup] </code></pre>
0
2016-08-22T13:03:17Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,333
<p>Possible workaround:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, - 0.005853658536585366, -0.5853658536585366) print [float("{0:.5f}".format(v)) for v in tup] </code></pre>
0
2016-08-22T13:03:42Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,377
<p>Most Pythonic way to achieve this is with <code>map()</code> and <code>lambda()</code> function.</p> <pre><code>&gt;&gt;&gt; map(lambda x: "%.5f" % x, tup) ['0.00390', '0.39024', '-0.00585', '-0.58537'] </code></pre>
0
2016-08-22T13:05:51Z
[ "python" ]
Printing a tuple in Python with user-defined precision
39,080,180
<p>Following <a href="http://stackoverflow.com/questions/1455602/printing-tuple-with-string-formatting-in-python">Printing tuple with string formatting in Python</a>, I'd like to print the following tuple:</p> <pre><code>tup = (0.0039024390243902443, 0.3902439024390244, -0.005853658536585366, -0.5853658536585366) </co...
-1
2016-08-22T12:57:00Z
39,080,415
<p>I figured out another workaround using Numpy:</p> <pre><code>import numpy as np np.set_printoptions(precision=5) print(np.array(tup)) </code></pre> <p>which yields the following output:</p> <pre><code>[ 0.0039 0.39024 -0.00585 -0.58537] </code></pre>
0
2016-08-22T13:07:44Z
[ "python" ]
Google TaskQueue (pull) insert task by API
39,080,283
<p>I'm using the apiclient.discovery.build to lease tasks from a Google Pull Queue.. It's working fine.. But when I try to insert tasks in this Queue, I always get the same error:</p> <pre><code>from apiclient.discovery import build build = build('taskqueue', 'v1beta2', credentials=GoogleCredentials.get_application_de...
1
2016-08-22T13:01:30Z
39,086,041
<p>Well.. I changed the payload with the exactly payload from the leased tasks.. except for some fields (e.g., ID or leasing time) and added the '~s' to the project name in 'queueName'.</p> <pre><code>resp = {u'kind': u'taskqueues#task', u'queueName': u'projects/s~project_name/taskqueues/pullqq', u'payloadBase64': u'c...
1
2016-08-22T18:07:44Z
[ "python", "google-cloud-platform", "task-queue", "pull-queue" ]
How to send a "method" via socket
39,080,288
<p>I'm trying to send packet made with scapy library via sockets in python 3..</p> <p>That's the code:</p> <pre><code>from scapy.all import * import socket, threading def loop(): global threads for x in range(800): sending().start() class sending(threading.Thread): def run(self): self.c...
0
2016-08-22T13:01:47Z
39,080,461
<p>The particular error you are seeing is because you aren't calling the <code>spoofing</code> method. It will go away if you add parentheses, like this:</p> <pre><code>s.send(self.spoofing()) </code></pre> <p>However you have rather more serious issues. <code>socket.socket(socket.AF_INET, socket.SOCK_STREAM)</code> ...
1
2016-08-22T13:09:21Z
[ "python", "sockets", "python-3.x", "methods", "byte" ]
Why and how Mysql float works fine only with Java?
39,080,345
<p>I am trying to execute the below queries with different languages and different DB clients.</p> <pre><code>SELECT MY_FLOAT_COL*1 FROM MY_TABLE; SELECT MY_FLOAT_COL FROM MY_TABLE; </code></pre> <p>As per my observation the first query returns deviated results in Python and DB clients such as Heidi SQL, as reasoned...
1
2016-08-22T13:04:07Z
39,080,441
<p>As you mentioned on the <a href="http://stackoverflow.com/questions/39047486/whats-going-on-with-mysql-float/39048275#39048275">other question</a> multiply the <code>MY_FLOAT_COL*1</code> change the precision level because it is converted to <code>DOUBLE</code>.</p> <p>When you retrieve data from a client, if you t...
1
2016-08-22T13:08:33Z
[ "java", "python", "mysql", "floating-point" ]
X and Y or Z - ternary operator
39,080,416
<p>In Java or C we have <code>&lt;condition&gt; ? X : Y</code>, which translates into Python as <code>X if &lt;condition&gt; else Y</code>.</p> <p>But there's also this little trick: <code>&lt;condition&gt; and X or Y</code>. </p> <p>While I understand that it's equivalent to the aforementioned ternary operators, I f...
6
2016-08-22T13:07:46Z
39,080,631
<blockquote> <p>While I understand that it's equivalent to the aforementioned ternary operators</p> </blockquote> <p>This is incorrect:</p> <pre><code>In [32]: True and 0 or 1 Out[32]: 1 In [33]: True and 2 or 1 Out[33]: 2 </code></pre> <p>Why the first expression returns <code>1</code> (i.e. <code>Y</code>), w...
8
2016-08-22T13:16:40Z
[ "python", "syntax", "ternary-operator" ]
X and Y or Z - ternary operator
39,080,416
<p>In Java or C we have <code>&lt;condition&gt; ? X : Y</code>, which translates into Python as <code>X if &lt;condition&gt; else Y</code>.</p> <p>But there's also this little trick: <code>&lt;condition&gt; and X or Y</code>. </p> <p>While I understand that it's equivalent to the aforementioned ternary operators, I f...
6
2016-08-22T13:07:46Z
39,080,644
<p>I think that first it will check <code>&lt;condition&gt;</code> if it's <code>True</code> then it execute <code>X</code> and skip executing <code>Y</code> if <code>X</code> evaluate to True </p> <p>But if <code>&lt;condition&gt;</code> fails then it skip executing <code>X</code> and execute OR statement and execute...
1
2016-08-22T13:17:00Z
[ "python", "syntax", "ternary-operator" ]
X and Y or Z - ternary operator
39,080,416
<p>In Java or C we have <code>&lt;condition&gt; ? X : Y</code>, which translates into Python as <code>X if &lt;condition&gt; else Y</code>.</p> <p>But there's also this little trick: <code>&lt;condition&gt; and X or Y</code>. </p> <p>While I understand that it's equivalent to the aforementioned ternary operators, I f...
6
2016-08-22T13:07:46Z
39,080,648
<p>If we examine <code>A and B</code>, <code>B</code> will be evaluated only if <code>A</code> is <code>True</code>.</p> <p>Like so, in <code>A or B</code>, <code>B</code> will only be evaluated in case <code>A</code> is <code>False</code>.</p> <p>Therefore, <code>&lt;condition&gt; and X or Y</code> will return <code...
3
2016-08-22T13:17:35Z
[ "python", "syntax", "ternary-operator" ]
X and Y or Z - ternary operator
39,080,416
<p>In Java or C we have <code>&lt;condition&gt; ? X : Y</code>, which translates into Python as <code>X if &lt;condition&gt; else Y</code>.</p> <p>But there's also this little trick: <code>&lt;condition&gt; and X or Y</code>. </p> <p>While I understand that it's equivalent to the aforementioned ternary operators, I f...
6
2016-08-22T13:07:46Z
39,080,650
<p>The trick is how python boolean operators <a href="https://docs.python.org/2/reference/expressions.html#boolean-operations" rel="nofollow">work</a></p> <blockquote> <p>The expression <code>x and y</code> first evaluates <code>x</code>; if <code>x</code> is false, its value is returned; otherwise, <code>y</code> i...
0
2016-08-22T13:17:37Z
[ "python", "syntax", "ternary-operator" ]
X and Y or Z - ternary operator
39,080,416
<p>In Java or C we have <code>&lt;condition&gt; ? X : Y</code>, which translates into Python as <code>X if &lt;condition&gt; else Y</code>.</p> <p>But there's also this little trick: <code>&lt;condition&gt; and X or Y</code>. </p> <p>While I understand that it's equivalent to the aforementioned ternary operators, I f...
6
2016-08-22T13:07:46Z
39,080,730
<p>This makes use of the fact that precedence of <code>and</code> is higher than <code>or</code>.</p> <p>So <code>&lt;condition&gt; and X or Y</code> is basically <code>(&lt;condition&gt; and X) or Y</code>. If <code>&lt;condition&gt; and X</code> evaluates to <code>True</code>, there is no need to evaluate further, a...
0
2016-08-22T13:21:46Z
[ "python", "syntax", "ternary-operator" ]
Beginner to python facing 'builtin_function_or_method' object has no attribute error
39,080,520
<p>I am trying to run a python code and this seems to cause error. Please help me </p> <pre><code>def randomPlace(b,lis): pos = [] for i in lis: if available(b,i): pos.append(i) if len.pos() != 0: return random.choice(pos) else: return None </code></pre> <p><code>b...
1
2016-08-22T13:11:59Z
39,080,669
<p>The expression <code>len.pos()</code> asks the interpreter to locate <code>len</code> (the standard built-in function), look up its <code>pos</code> attribute (clue: it doesn't have one) and that call that looked up result. You actually want to apply the <code>len</code> function to the value of <code>pos</code>, an...
1
2016-08-22T13:18:39Z
[ "python", "artificial-intelligence" ]
Beginner to python facing 'builtin_function_or_method' object has no attribute error
39,080,520
<p>I am trying to run a python code and this seems to cause error. Please help me </p> <pre><code>def randomPlace(b,lis): pos = [] for i in lis: if available(b,i): pos.append(i) if len.pos() != 0: return random.choice(pos) else: return None </code></pre> <p><code>b...
1
2016-08-22T13:11:59Z
39,080,685
<p>Use <code>len(pos)</code>. </p> <p>In order to find the size of list in python, the syntax is <code>len(your_list)</code>.</p> <p>In your case <code>len</code> function is not even required. You may simply do:</p> <pre><code>if pos: return random.choice(pos) else: return None </code></pre> <p>Because if ...
1
2016-08-22T13:19:28Z
[ "python", "artificial-intelligence" ]
pandas get_level_values for multiple columns
39,080,555
<p>Is there a way to get the result of <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.Index.get_level_values.html" rel="nofollow"><code>get_level_values</code></a> for more than one column?</p> <p>Given the following <code>DataFrame</code>:</p> <pre><code> d a b c 1 4 10 1...
1
2016-08-22T13:13:08Z
39,081,256
<p>This is less cumbersome insofar as you can pass the list of index names you want to select:</p> <pre><code>df.reset_index()[['a', 'c']].to_dict(orient='split')['data'] </code></pre> <p>I have not found a way of selecting levels <code>'a'</code> and <code>'b'</code> from the index object directly, hence the use of ...
0
2016-08-22T13:46:07Z
[ "python", "python-3.x", "pandas", "dataframe", "multi-index" ]
pandas get_level_values for multiple columns
39,080,555
<p>Is there a way to get the result of <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.Index.get_level_values.html" rel="nofollow"><code>get_level_values</code></a> for more than one column?</p> <p>Given the following <code>DataFrame</code>:</p> <pre><code> d a b c 1 4 10 1...
1
2016-08-22T13:13:08Z
39,081,316
<p>The <code>.tolist()</code> method of a <code>MultiIndex</code> gives a list of tuples for all the levels in the <code>MultiIndex</code>. For example, with your example <code>DataFrame</code>,</p> <pre><code>df.index.tolist() # =&gt; [(1, 4, 10), (1, 4, 11), (1, 5, 12), (2, 5, 13), (2, 6, 14), (3, 7, 15)] </code></p...
2
2016-08-22T13:49:16Z
[ "python", "python-3.x", "pandas", "dataframe", "multi-index" ]
django rest framework filter on related model
39,080,701
<p>I have a model countries and a model of persons on holiday in a certain year to a country. I want to have an Api of Countries in which I can filter only the countries in which certain persons had a holiday in a certain year.</p> <p>Models.py</p> <pre><code>from django.db import models class Country(models.Model):...
0
2016-08-22T13:20:35Z
39,080,909
<p>Your <code>queryset</code> should be:</p> <pre><code>Country.objects.filter(personyears__year='your_year', person='your_person').values_list('country', flat=True) </code></pre> <p>This will return list of all the countries.</p> <p><strong>Note:</strong> This will filter based on the name of person which may be sa...
1
2016-08-22T13:28:41Z
[ "python", "django", "django-rest-framework" ]
Compiling C extensions for Python3 on CentOS
39,080,726
<p>I need to write python interface wrappers around some C functions, which requires the Python.h header file. I want to make sure I get the correct Python.h.</p> <p>I'm working in CentOS 6.6 and decided to use Python 3.4 so as to avoid using the OS's python distribution. Online sources suggest getting the correct Pyt...
2
2016-08-22T12:38:42Z
39,080,873
<p>If you do things properly and make a complete installable package for your wrapper, with <code>setup.py</code>, then you do not even need to know the location of the includes; as your python3.4 executable would know their location.</p> <p>Minimlly your <code>setup.py</code> could be something like </p> <pre><code>...
1
2016-08-22T13:27:24Z
[ "centos6", "python" ]
How to selecting column arrays from matrix in python
39,080,931
<p>I am studying python on my own and I want to create a matrix; by reading in the internet I found many ways to define a matrix and I decided to select these 2 methodologies:</p> <pre><code>import numpy as np # Method 1 w, h = 5, 5 M = [[0 for x in range(w)] for y in range(h)] M[1][2] = 100 # ok m = M[:,2] # &l...
1
2016-08-22T13:29:53Z
39,081,242
<p><code>A</code> and <code>M</code> are very different objects, as you have also discovered yourself. They might store the same information, but they do it differently and allow you to manipulate it in different ways. They have different interfaces, which means you have to interact with them differently. This affects ...
2
2016-08-22T13:45:24Z
[ "python", "arrays", "numpy", "matrix", "multidimensional-array" ]
Get specific letters from a string
39,080,944
<p>My input is a variable is a string:</p> <pre><code> entity = "SmartSys_1_13_PP" </code></pre> <p>I need to extra the last two letters of the name of the entity. The results would be PP in this case.</p> <p>One possible solution is to delimit the name using the _ and then consider the last field as the answer. Is ...
1
2016-08-22T13:30:36Z
39,081,015
<p>You my use string slicing. For your case, it will be: <code>name[-2:]</code></p> <p>But do not forget to add check, because it will return the string as it is in case length of string is less than 2. Your code should be like:</p> <pre><code>if len(name) &gt; 2: print name[-2:] else: # Whatever you want to ...
3
2016-08-22T13:33:57Z
[ "python", "delimiter" ]
Get specific letters from a string
39,080,944
<p>My input is a variable is a string:</p> <pre><code> entity = "SmartSys_1_13_PP" </code></pre> <p>I need to extra the last two letters of the name of the entity. The results would be PP in this case.</p> <p>One possible solution is to delimit the name using the _ and then consider the last field as the answer. Is ...
1
2016-08-22T13:30:36Z
39,081,033
<p><a href="https://docs.python.org/2/tutorial/introduction.html#strings" rel="nofollow">Python strings</a> are sequences of individual characters. You can slice them the same way you would slice a Python list.</p> <pre><code>entity = 'SmartSys_1_13_PP' print(entity[-2:]) PP </code></pre>
1
2016-08-22T13:34:36Z
[ "python", "delimiter" ]
Get specific letters from a string
39,080,944
<p>My input is a variable is a string:</p> <pre><code> entity = "SmartSys_1_13_PP" </code></pre> <p>I need to extra the last two letters of the name of the entity. The results would be PP in this case.</p> <p>One possible solution is to delimit the name using the _ and then consider the last field as the answer. Is ...
1
2016-08-22T13:30:36Z
39,083,951
<p>As you suggest, you can split the string on '_' then get the last substring:</p> <pre><code>&gt;&gt;&gt; entity = "SmartSys_1_13_PP" &gt;&gt;&gt; entity.split('_')[-1] 'PP' </code></pre>
0
2016-08-22T15:57:53Z
[ "python", "delimiter" ]
Selecting multiindex entry using labels
39,080,995
<p>I do not find any explanation of how to select Pandas multiindex objects by labels. Here is an example from the documentation (<a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/advanced.html</a>)</p> <pre><code>In [1]: arrays = [['bar', 'b...
1
2016-08-22T13:32:54Z
39,083,993
<p>You can use <code>unstack</code> and <code>ix</code> or <code>iloc</code> together to achieve this.</p> <pre><code>s.unstack().ix[0, 0] # or s.unstack().iloc[0, 0] </code></pre> <p>would give <code>0.469112</code></p>
0
2016-08-22T16:00:57Z
[ "python", "pandas" ]
How do we use "left outer join" for large size pandas dataframes (larger than 5~20GB)?
39,081,044
<p>I try to merge two large size dataframes.</p> <p>One dataframe (patent_id) has 5,271,459 of rows and the others have more than 10,000 of columns.</p> <p>To combine these two big dataframes, I use "merge" and separate right dataframe into chunks. (similar with <a href="http://stackoverflow.com/questions/32635169/me...
0
2016-08-22T13:35:08Z
39,081,896
<p>Below approach works for me which is from <a href="http://stackoverflow.com/questions/32635169/memoryerror-with-python-pandas-and-large-left-outer-joins">MemoryError with python/pandas and large left outer joins</a></p> <pre><code>import csv def gen_chunks(reader, chunksize=1000000): chunk = [] for i, line...
0
2016-08-22T14:16:41Z
[ "python", "database", "pandas", "join", "merge" ]
How to increment or decrement a recordset? odoo9
39,081,083
<p>My record set is <code>items = product.pricelist.item(4,3,2)</code></p> <p><code>qty_in_product_uom</code> is passed by the user( <code>4= min_quantity 500, 3= 250, 2= 100</code> )</p> <pre><code>for rule in items: if rule.min_quantity and qty_in_product_uom &lt; rule.min_quantity: print inside rule.i...
0
2016-08-22T13:37:06Z
39,089,475
<p>The recordset(<code>BaseModel</code> class) is an iterable Python object. That means you can use the object in almost the same way you use a list. For example:</p> <p><code>item = product.pricelist.item(4,3,2)[0]</code></p> <p><code>print item # This will print product.pricelist.item(4,)</code></p> <p>If you want...
1
2016-08-22T22:08:33Z
[ "python", "api", "orm", "openerp", "odoo-9" ]
Django: how to switch to another view with the click of a button?
39,081,115
<p>I am building a django app using django 1.9.5 and Python 2.7.11. My project (which I named djan_web) directory looks like the following:</p> <pre><code>djan_web\ manage.py djan_frontend\ views.py templates\ djan_frontend\ upload.html djan_homepag...
0
2016-08-22T13:38:58Z
39,081,413
<p>You need to fix your URLs in <code>urls.py</code>. Try:</p> <pre><code>urlpatterns = [ url(r'^$', views.homepage, name="homepage"), url(r'^admin/', admin.site.urls), url(r'^upload-file/$', views.upload, name='upload') ] </code></pre> <p>Notice The <code>$</code> at the end of the regexs. You need to a...
0
2016-08-22T13:54:12Z
[ "python", "html", "django", "django-templates", "django-views" ]
BFS, wanting to find the longest path between nodes, reducing the findchildren-method
39,081,149
<p>I've opened another thread with exactly this subject, but I think I posted too much code and I didn't really know where my problem was, now I think I have a better idea but still in need of help. What we have is a text-file with 3 letter words, only 3 letter words. I also have a Word (node) and queue-class. My findc...
4
2016-08-22T13:40:54Z
39,082,167
<p>There are more efficient ways to do this (the below is O(n^2) so not great) but here is a simple algorithm to get you started:</p> <pre><code>import itertools from collections import defaultdict words = ['abc', 'def', 'adf', 'adc', 'acf', 'dec'] bigrams = {k: {''.join(x) for x in itertools.permutations(k, 2)} for ...
0
2016-08-22T14:29:41Z
[ "python", "python-3.x", "bfs" ]
BFS, wanting to find the longest path between nodes, reducing the findchildren-method
39,081,149
<p>I've opened another thread with exactly this subject, but I think I posted too much code and I didn't really know where my problem was, now I think I have a better idea but still in need of help. What we have is a text-file with 3 letter words, only 3 letter words. I also have a Word (node) and queue-class. My findc...
4
2016-08-22T13:40:54Z
39,098,520
<p>Solution (which is O(n^2) sadly) for the updated requirement in Python 3 (run it <a href="https://repl.it/Cq11/0" rel="nofollow">here</a>):</p> <p>from collections import defaultdict</p> <pre><code>words = ['fan', 'ban', 'fbn', 'ana', 'and', 'ann'] def isChildOf(a, b): return sum(map(lambda xy: xy[0] == xy[1]...
0
2016-08-23T10:22:19Z
[ "python", "python-3.x", "bfs" ]
Displaying Flask-WTF error shows extra characters
39,081,265
<p>I want to display an error from a field in my Flask-WTF form with JavaScript. Printing out <code>form.errors['password']</code> gives <code>['This field is required']</code>, but I don't want <code>['</code> <code>']</code> in the output. How do I display the error in the right format?</p>
-1
2016-08-22T13:46:17Z
39,082,297
<p>Each field can have multiple errors, so they are always contained in a list, even if there is only one error. There is nothing special about Jinja or Flask-WTF here, you just need to pay attention to the data you're working with.</p> <pre><code>{{ form.password.errors[0] }} {{ form.errors['password'][0] }} </code>...
1
2016-08-22T14:36:13Z
[ "python", "flask", "jinja2", "flask-wtforms" ]
Django apps resolving to the wrong namespace
39,081,321
<p>In my project I have three apps, "abc", "xyz" and "common." Common isn't a real app inasmuch as it just stores templates, models and views that are inherited and extended by both apps.</p> <p>Project-level urls.py looks like so, and properly redirects requests to the respective app:</p> <pre><code>urlpatterns = [ ...
1
2016-08-22T13:49:27Z
39,081,749
<p>Django can't tell the difference between the URLs under <code>abc/</code> and <code>xyz/</code> just by the view name and arguments. Since reversing will go through the patterns in reverse order, the patterns under <code>xyz/</code> will always match first, so all links generated using <code>reverse()</code> or the ...
3
2016-08-22T14:10:14Z
[ "python", "django" ]
Pandas plotting: How to format datetimeindex?
39,081,327
<p>I am doing a barplot out of a dataframe with a 15min datetimeindex over a couple of years. Using this code:</p> <pre><code>df_Vol.resample('A',how='sum').plot.bar(title='Sums per year', style='ggplot', alpha=0.8) </code></pre> <p>Unfortunately the ticks on the X-axis are now shown with the full timestamp like this...
0
2016-08-22T13:49:44Z
39,144,402
<p>As it does not seem to be possible to Format the date within the Pandas df.plot(), I have decided to create a new dataframe and plot from it.</p> <p>The solution below worked for me:</p> <pre><code>df_Vol_new = df_Vol.resample('A',how='sum') df_Vol_new.index = df_Vol_new.index.format(formatter=lambda x: x.strftime...
0
2016-08-25T11:45:15Z
[ "python", "pandas", "matplotlib", "formatting", "datetimeindex" ]
Python finding some, not all custom packages
39,081,371
<p>I have a project with the following file structure:</p> <pre><code>root/ run.py bot/ __init__.py my_discord_bot.py dice/ __init__.py dice.py # dice files help/ __init__.py help.py # help files parser/ __init__.py par...
1
2016-08-22T13:52:22Z
39,083,134
<p>Make sure that your <code>parser</code> is not shadowing a built-in or third-party package/module/library. </p> <p>I am not 100% sure about the specifics of how this name conflict would be resolved, but it seems like you can potentially a). have your module overridden by the existing module (which seems like it mig...
1
2016-08-22T15:13:56Z
[ "python", "windows", "python-3.5" ]
Python finding some, not all custom packages
39,081,371
<p>I have a project with the following file structure:</p> <pre><code>root/ run.py bot/ __init__.py my_discord_bot.py dice/ __init__.py dice.py # dice files help/ __init__.py help.py # help files parser/ __init__.py par...
1
2016-08-22T13:52:22Z
39,083,301
<p>Put run.py outside root folder, so you'll have run.py next to root folder, then create <code>__init__.py</code> inside root folder, and change imports to:</p> <pre><code>import root.parser.parser as p </code></pre> <p>Or just rename your parser module.</p> <p>Anyway you should be careful with naming, because you ...
0
2016-08-22T15:22:20Z
[ "python", "windows", "python-3.5" ]
Ansible: Change value in template based on deployment
39,081,395
<p>Is it possible for change value on a deployment basis with ansible? I'm configuring keepalived on two machines, I'd like to add a loop for the priority. </p> <p>I can't loop or use the range() function as that'd just loop within the same deployment. </p> <p>I'm trying to set priority:</p> <ul> <li>lb1 = 100 </li...
1
2016-08-22T13:53:28Z
39,081,765
<p>You can use host index inside your template like this (if you don't care about who will get higher priority):</p> <pre><code>priority {{ play_hosts.index(inventory_hostname) }} </code></pre> <p>Or you can assign priorities in advance as host variables in your inventory file like this:</p> <pre><code>server1 vrrp_...
2
2016-08-22T14:10:45Z
[ "python", "templates", "ansible", "jinja2" ]
Google Drive API 403 error when updating spreadsheet title
39,081,509
<p>We are using Google Drive API in our Google App Engine application. This weekend we noticed that it has problems with updating spreadsheet title. We are getting the following error:</p> <pre><code>HttpError: &lt;HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1_X51WMK0U12rfPKc2x60E_EuyqtQ8ko...
0
2016-08-22T13:58:31Z
39,096,183
<p>Based from this <a href="https://developers.google.com/drive/v3/web/handle-errors#403_the_user_has_not_granted_the_app_appid_verb_access_to_the_file_fileid" rel="nofollow">documentation</a>, error occurs when the requesting app is not on the ACL for the file and the user never explicitly opened the file with this Dr...
1
2016-08-23T08:34:02Z
[ "python", "google-app-engine", "google-drive-sdk" ]
How to determine what string subprocess is passing to the commandline?
39,081,535
<p>On Windows, you make a subprocess call by passing a list of string arguments that it then reformats as a single string to call the relevant command. It does this by a series of rules as outline in the documentation <a href="https://docs.python.org/2/library/subprocess.html#converting-an-argument-sequence-to-a-string...
1
2016-08-22T13:59:59Z
39,082,547
<p>I dug into the actual subprocess module and found an answer in there in fact. There's a function called <code>list2cmdline</code> that's used to just take a list passed to <code>Popen</code> and turn it into a single string of commandline arguments. It can just be called on with the list to get the result I need:</p...
1
2016-08-22T14:46:59Z
[ "python", "windows", "subprocess" ]
Light persistence in the context of ThreadPoolExecutor in Python
39,081,583
<p>I've got some Python code that farms out expensive jobs using ThreadPoolExecutor, and I'd like to keep track of which of them have completed so that if I have to restart this system, I don't have to redo the stuff that already finished. In a single-threaded context, I could just mark what I've done in a shelf. Here'...
1
2016-08-22T14:02:07Z
39,720,663
<p>While you're still in the outer-most <code>with</code> context manager, the <code>done</code> shelve is just a normal python object- it is only written to disk when the context manager closes and it runs its <code>__exit__</code> method. It is therefore just as thread safe as any other python object, due to the <a h...
1
2016-09-27T09:12:23Z
[ "python", "multithreading", "shelve" ]
Adding a parcel repository using Cloudera Manager Python API
39,081,629
<p>I'm trying to install CDH5 parcels on Hadoop-cluster using <a href="http://cloudera.github.io/cm_api/docs/python-client/" rel="nofollow">Cloudera Manager Python API</a>. I'm doing this using following code:</p> <pre><code>test_cluster = ... # configuring cluster # adding hosts ... for parcel in test_cluster.get_all...
0
2016-08-22T14:04:10Z
39,136,543
<p>You may want to be more specific about the parcel you are acting on. I use something like this for the same purpose, the important part for your question is the combined check on <code>parcel.version</code> and <code>parcel.product</code>. After that (yes I am verbose in my output) I print the list of parcels to ve...
2
2016-08-25T04:05:47Z
[ "python", "cloudera-cdh", "cloudera-manager" ]
What are formatted string literals in Python 3.6?
39,081,766
<p>One of the features of Python 3.6 are formatted strings.</p> <p><a href="http://stackoverflow.com/questions/35745050/string-with-f-prefix-in-python-3-6">This SO question</a>(String with 'f' prefix in python-3.6) is asking about the internals of formatted string literals, but I don't understand the exact use case of...
2
2016-08-22T14:10:50Z
39,082,102
<blockquote> <p>Simple is better than complex.</p> </blockquote> <p>So here we have formatted string. It gives the simplicity to the string formatting, while keeping the code explicit (comprared to other string formatting mechanisms).</p> <pre><code>title = 'Mr.' name = 'Tom' msg_count = 3 # This is explicit but c...
5
2016-08-22T14:26:49Z
[ "python", "python-3.6" ]
Python: Process in one Thread stopping a Process in another Thread from finishing
39,081,791
<p>I'd appreciate some help with threading, which I pretty new to. </p> <p>The example code is not exactly what I’m doing (‘notepad’ and ‘calc’ are just example commands), but a simplified version that shows my problem.</p> <p>I want to run two seperate threads that each run a different command a number of ...
1
2016-08-22T14:11:56Z
39,082,516
<p>So the <code>communicate()</code> method is apparently waiting for all processes created by <code>Popen</code> and executing <code>cmd.exe</code> <strong>and started at nearly the same time</strong> to terminate. Since the <code>cmd.exe</code> that runs <code>calculator</code> starts at nearly the same time as the <...
0
2016-08-22T14:45:32Z
[ "python", "multithreading", "subprocess", "popen", "terminate" ]
PyQT QTableWidget extremely slow
39,081,852
<p>this is the code I use to fill a table drawn in QT Designer. Designed to be universal for any table, it works fine, but... When I try to show a datasat containing 18 columns and ~12000 rows, it just freezes for 30 seconds or more. So, what I am doing wrong and is there way to speed up, keeping the code still suitabl...
0
2016-08-22T14:14:42Z
39,081,908
<p>In GUI applications one comes across a situation where there is a need to display a lot of items in a tabular or list format (for example displaying large number of rows in a table). One way to increase the GUI responsiveness is to load a few items when the screen is displayed and defer loading of rest of the items ...
0
2016-08-22T14:17:10Z
[ "python", "qt", "pyqt", "qtablewidget" ]
PyQT QTableWidget extremely slow
39,081,852
<p>this is the code I use to fill a table drawn in QT Designer. Designed to be universal for any table, it works fine, but... When I try to show a datasat containing 18 columns and ~12000 rows, it just freezes for 30 seconds or more. So, what I am doing wrong and is there way to speed up, keeping the code still suitabl...
0
2016-08-22T14:14:42Z
39,088,300
<p>Here a test script which compares a few ways of populating a table.</p> <p>The custom model is much faster, because it does not have to create all the items up front - but note that it is a very basic implementation, so does not implement sorting, editing, etc. (See <a href="http://doc.qt.io/qt-4.8/model-view-progr...
2
2016-08-22T20:36:14Z
[ "python", "qt", "pyqt", "qtablewidget" ]
UDF (User Defined Function) python gives different answer in pig
39,081,890
<p>I want to write a UDF python for pig, to read lines from the file called like</p> <pre><code>#'prefix.csv' spol. LLC Oy OOD </code></pre> <p>and match the names and if finds any matches, then replaces it with white space. here is my python code </p> <pre><code>def list_files2(name, f): fin = open(f, 'r') ...
0
2016-08-22T14:16:14Z
39,096,001
<p>I don't know <code>pig</code> but the way you are checking for a match is strange and might be the cause of your problem.</p> <p>If you want to check whether a string is a substring of another, <code>python</code> provides the <code>find</code> method on strings:</p> <pre><code>if name.find(line.strip()) != -1: ...
0
2016-08-23T08:24:52Z
[ "python", "apache-pig", "jython", "udf" ]
ImportError: No module named keras.optimizers
39,081,910
<p>I have this import statement in Keras:</p> <pre><code>from keras.optimizers import SGD, RMSprop </code></pre> <p>But getting this error on this error:</p> <pre><code>ImportError: No module named keras.optimizers </code></pre> <p>Why is that? And, how can I solve this issue?</p> <p>Thanks.</p>
-1
2016-08-22T14:17:12Z
39,082,014
<p>Most obvious answer would be: You do not have <code>keras</code> installed. Do you? Maybe try <code>pip install keras</code> or <code>pip freeze</code> to check? Or if you are on Linux, you can also try <code>which keras</code>.</p> <p>Can you provide us with additional information?</p>
2
2016-08-22T14:22:35Z
[ "python", "keras" ]
Passing Bokeh plot objects into and out of functions
39,082,342
<p>I am currently using Bokeh to make multiple plots and generating their components (script/div). I pass in the plot object to a function, add plot lines to the object based on calculations performed in the function, I then pass the object out to main. I do this frequently for different functions. This seems to create...
0
2016-08-22T14:38:11Z
39,083,177
<p>There are unfortunate and unavoidable tensions between interactive, exploratory use-cases and development use-cases. Making Bokeh simple, convenient and unobtrusive to use in Jupyter Notebooks, etc. meant making it do some "automagic" things. In particular there is an implicit "current document", and unless it is ex...
0
2016-08-22T15:15:39Z
[ "python", "function", "plot", "bokeh" ]
Return list built from a loop with lambda
39,082,671
<p>I have a function to return a list of files and folders in a given folder (with recurse and only get files options), or just the file in a list if given path is not a folder:</p> <pre><code>def path_to_list(path, onlyFiles = False, recurse = False): if os.path.isdir(path): if onlyFiles: if r...
0
2016-08-22T14:52:17Z
39,083,766
<p>You can return list of directories by:</p> <pre><code>return [dir for _, _, dir in list(os.walk(path))] </code></pre>
0
2016-08-22T15:47:58Z
[ "python", "python-2.7" ]
How does for in loop work with multiple sequences python
39,082,721
<p>I meet following code of for-loop, and not very sure how it goes:</p> <pre><code>for sentence in snippet, phrase: result = sentence[:] </code></pre> <p>is it iterate through 'snippet' then 'phrase'? </p> <p>EDIT: </p> <pre><code>PHRASES = { "class %%%(%%%):": "Make a class named %%% that is-a %%%.", "class...
-2
2016-08-22T14:54:37Z
39,082,760
<p>No. <code>snippet, phrase</code> defines a tuple of those two elements only. The iteration is over that tuple; ie sentence is first the value of <code>snippet</code> and then the value of <code>phrase</code>. It doesn't iterate through the contents of those values.</p>
1
2016-08-22T14:56:28Z
[ "python", "for-loop" ]
Why is my code only parsing part of the XML file?
39,082,749
<p>Apologies in advance I am a novice in Python. I am trying to sum across all the elements in this XML file but it seems my code is only summing part of the file for some reason. I tried to figure out but failed. May I kindly ask for some advice? Thanks. Sorry for the long file</p> <pre><code>import xml.etree.Elemen...
0
2016-08-22T14:56:00Z
39,083,064
<p>One of your <code>&lt;comment&gt;</code> tags has no <code>&lt;count&gt;</code>:</p> <pre><code>&lt;comment&gt; &lt;name&gt;Uchenna&lt;/name&gt; &lt;/comment&gt; </code></pre> <p>This results in <code>item.find('count')</code> being <code>None</code>. Obviously, <code>None</code> doesn't have a <code>.text</code>...
1
2016-08-22T15:10:04Z
[ "python", "xml" ]
How to access a variable being updated in a while loop
39,082,766
<p>I am trying to access a variable that is being constantly updated in a while loop in a different file. Here is the code I used for testing:</p> <pre><code># file1 import time x = 0 while True: x += 1 time.sleep(2.0) # file2 from file1 import x print x </code></pre> <p>When I run file2, it starts the w...
0
2016-08-22T14:57:04Z
39,082,921
<p>I'm not quite sure what you mean. Are you wanting file1 to run, and be incrementing the value of "x" every 2 seconds, indefinitely and that when you run file2 at any time, it pulls the current value of "x" from the program/python instance running "file1"?</p> <p>If so, this is not how you would approach it. With fi...
2
2016-08-22T15:03:24Z
[ "python", "while-loop" ]
How to access a variable being updated in a while loop
39,082,766
<p>I am trying to access a variable that is being constantly updated in a while loop in a different file. Here is the code I used for testing:</p> <pre><code># file1 import time x = 0 while True: x += 1 time.sleep(2.0) # file2 from file1 import x print x </code></pre> <p>When I run file2, it starts the w...
0
2016-08-22T14:57:04Z
39,083,009
<p>You can try the following. First, as there's and infinite loop, importing file1 will block, so you should run the loop in a thread. And second you can wrap the integer being incremented in a list (or any other kind of objects), so you can use the reference to its current value (otherwise you will be importing a valu...
1
2016-08-22T15:07:50Z
[ "python", "while-loop" ]
Constructing python-click commands
39,082,806
<p>I have a command like :</p> <p><code>$trial login --user</code></p> <p>For this I used <code>python-click</code> to wrap my python functions and is working fine. I am very new to <code>python-click</code> and having having to construct a command in a certain way than what is mentioned above.</p> <p>Below is my pr...
0
2016-08-22T14:58:39Z
39,085,237
<p>You just need to make another <code>group</code> that's a child of <code>cli</code>, so make a <code>k8s</code> function and decorate it with <code>cli.group()</code>, then change <code>login</code> to be a <code>k8s.command()</code></p>
0
2016-08-22T17:17:34Z
[ "python", "python-click" ]
Call function or function (python)
39,083,022
<p>I have 4 functions. I want my code to perform the first one AND the second, third, or fourth. I also want at least one (any of them) no matter what unless they all fail. My initial implementation was:</p> <pre><code>try: function1(var) except: pass try: function2(var) or function3(var) or function4(var...
0
2016-08-22T15:08:13Z
39,083,194
<p>In case the success of failure of a function is determined, whether it raises an exception or not, you could write a helper method, that would try to call a list of functions until a successful one returns.</p> <pre><code>#!/usr/bin/env python # coding: utf-8 import sys def callany(*funs): """ Returns the...
2
2016-08-22T15:16:35Z
[ "python", "function", "try-catch", "boolean-logic" ]
Running python program doesn't work and only gives function address
39,083,030
<p>When I run my python program from terminal with <code>python sumSquares.py</code>, I get the following result: <code>&lt;function diffSum at 0x1006dfe60&gt;</code> My program looks like this:</p> <pre><code>def diffSum(): sumSquares = 0 for i in range(0, 100): sumSquares += i**2 squareSum = 0 ...
-3
2016-08-22T15:08:31Z
39,083,074
<p>You need to call the function by adding parentheses after its name, as in:</p> <pre><code>print(diffsum()) </code></pre>
1
2016-08-22T15:10:29Z
[ "python" ]
Error 'is not in list'
39,083,060
<p>I am trying to get the index values of the values in outputx[vX]</p> <pre><code>&gt;&gt;&gt; outs = np.array(outputx[vX]).tolist() &gt;&gt;&gt; print outs [0.806, 0.760, 0.8] &gt;&gt;&gt; print type(outs) (type 'list') &gt;&gt;&gt; idx = outputX.index(outs) error -&gt; [0.806, 0.760, 0.8] is not in list </code></pr...
0
2016-08-22T15:09:52Z
39,083,262
<p>The <code>index</code> list method expects a single value, and returns that value's position in the list on which the method is called. If the given value isn't in the list the method will raise a <code>ValueError</code> exception. So, for example:</p> <pre><code>&gt;&gt;&gt; [2, 4, 6, 8].index(6) 2 &gt;&gt;&gt; [2...
0
2016-08-22T15:20:32Z
[ "python", "list" ]
Error 'is not in list'
39,083,060
<p>I am trying to get the index values of the values in outputx[vX]</p> <pre><code>&gt;&gt;&gt; outs = np.array(outputx[vX]).tolist() &gt;&gt;&gt; print outs [0.806, 0.760, 0.8] &gt;&gt;&gt; print type(outs) (type 'list') &gt;&gt;&gt; idx = outputX.index(outs) error -&gt; [0.806, 0.760, 0.8] is not in list </code></pr...
0
2016-08-22T15:09:52Z
39,084,200
<p>If you want a list of indices you might use list comprehensions:</p> <pre><code>idx = [outputX.index(i) for i in outs] </code></pre> <p>But you should be dead sure that all values of the <code>outs</code> list are in the <code>outputX</code> list also, otherwise python will throw you a <code>ValueError</code>.</p>...
0
2016-08-22T16:12:02Z
[ "python", "list" ]
How to condense multiple different if statements (Python)
39,083,109
<p>I am making a quiz in the style of 20 Questions. It uses a text file to create a dictionary with codes relating to answers. At the moment it only has 5 questions which is no where near enough to be accurate with 'guesses' but already it is looking messy and hard to understand</p> <p>CODES.txt Example Contents:</p> ...
0
2016-08-22T15:12:21Z
39,083,329
<p>I will try to give you some thoughts but not solve your problem directly:</p> <ul> <li>Think about what you can put into a separate function. This would make sense for statements that are repeated several times.</li> <li>You can very easily return strings from Python functions. Then you can use the returned string...
1
2016-08-22T15:23:56Z
[ "python", "python-3.x", "if-statement", "dictionary" ]
interval comparison in pandas data frame
39,083,157
<p>I am trying to do an interval comparison similar to what is described in <a href="http://stackoverflow.com/questions/13628791/how-do-i-check-whether-an-int-is-between-the-two-numbers">this question</a> as <code>10000 &lt;= number &lt;= 30000</code> but I'm trying to do it in a data frame. For example, below is my sa...
0
2016-08-22T15:14:44Z
39,083,212
<p>Chained comparisons are not supported. You need to do:</p> <pre><code>df[df['lat'].between(coords[0] - 1, coords[0] + 1)] # inclusive=True by default Out: lat long type 0 5 7 wolf 1 5 6 cow 3 5 3 rabbit 4 3 2 cow </code></pre>
1
2016-08-22T15:17:44Z
[ "python", "pandas" ]
Django allauth Redirect to email verification after social signup
39,083,287
<p>I use Twitter for main signup/login and I would like to redirect to 'accounts/email' link after social signup because I want to force new user to provide their emails. I've found same <a href="http://stackoverflow.com/questions/27759407/django-allauth-redirect-after-social-signup">question</a> and answer from <a hre...
1
2016-08-22T15:21:43Z
39,101,570
<p>In setting.py I only add those two lines and forgot about the adapter :</p> <pre><code>SOCIALACCOUNT_AUTO_SIGNUP = True SOCIALACCOUNT_EMAIL_REQUIRED = True </code></pre> <p>and now after signup or login it redircts new users only to /accounts/social/signup/ and this view actually force the user to submit his eami...
1
2016-08-23T12:43:26Z
[ "python", "django", "django-allauth" ]
Special characters get truncated when using bing tts api from python
39,083,305
<p>I have modified the python example found at <a href="https://github.com/Microsoft/Cognitive-Speech-TTS/tree/master/Samples-Http/Python" rel="nofollow">https://github.com/Microsoft/Cognitive-Speech-TTS/tree/master/Samples-Http/Python</a> to synthesize voice in spanish changing</p> <pre><code>"&lt;speak version='1.0'...
0
2016-08-22T15:22:28Z
39,112,184
<p>If you look at the HTTP request, you will see that the http.client library does not encode the string correctly. The easiest workaround is to encode it yourself:</p> <pre><code>ssml = "&lt;speak version='1.0' xml:lang='es-ES'&gt;...&lt;/speak&gt;" body = ssml.encode('utf8') </code></pre>
0
2016-08-23T23:25:23Z
[ "python", "text-to-speech", "bing-api", "microsoft-cognitive" ]
Why cant I do blob detection on this binary image
39,083,360
<p>First, now i am doing the blob detection by Python2.7 with Opencv. What i want to do is to finish the blob detection after the color detection. i want to detect the red circles(marks), and to avoid other blob interference, i want to do color detection first, and then do the blob detection.</p> <p>and the image afte...
2
2016-08-22T15:25:33Z
39,084,845
<p>Its an opencv bug in the filter by color . All you need to do is to invert the color of the image -> Detect Blobs -> Invert again to get back to the original color </p> <h1>Code</h1> <pre><code>import cv2 import numpy as np; # Read image im = cv2.imread("myblob.jpg", cv2.IMREAD_GRAYSCALE) # Set up the detector w...
1
2016-08-22T16:52:13Z
[ "python", "opencv", "image-processing", "binary", "blob" ]
Why cant I do blob detection on this binary image
39,083,360
<p>First, now i am doing the blob detection by Python2.7 with Opencv. What i want to do is to finish the blob detection after the color detection. i want to detect the red circles(marks), and to avoid other blob interference, i want to do color detection first, and then do the blob detection.</p> <p>and the image afte...
2
2016-08-22T15:25:33Z
39,085,129
<p>Easiest way would be what @ArjitMukherjee said.</p> <p>But I also echo what @meetaig commented initially about difference in structure of blobs in both the images</p> <blockquote> <p>A clue for why it might not work could be the structure of the blobs. In the first image the white pixels are not all connected ...
0
2016-08-22T17:10:55Z
[ "python", "opencv", "image-processing", "binary", "blob" ]
Why cant I do blob detection on this binary image
39,083,360
<p>First, now i am doing the blob detection by Python2.7 with Opencv. What i want to do is to finish the blob detection after the color detection. i want to detect the red circles(marks), and to avoid other blob interference, i want to do color detection first, and then do the blob detection.</p> <p>and the image afte...
2
2016-08-22T15:25:33Z
39,085,654
<p>It looks that the blob detector has <code>filterByInertia</code> and <code>filterByConvexity</code> parameters enabled by default. You can check this in your system:</p> <pre><code>import cv2 params = cv2.SimpleBlobDetector_Params() print params.filterByColor print params.filterByArea print params.filterByCirculari...
2
2016-08-22T17:44:14Z
[ "python", "opencv", "image-processing", "binary", "blob" ]
Untar file in Python script with wildcard
39,083,448
<p>I am trying in a Python script to import a tar.gz file from HDFS and then untar it. The file comes as follow <b>20160822073413-EoRcGvXMDIB5SVenEyD4pOEADPVPhPsg.tar.gz</b>, it has always the same structure.</p> <p>In my python script, I would like to copy it locally and the extract the file. I am using the followin...
0
2016-08-22T15:30:27Z
39,083,616
<p>Try with the <code>shell</code> option:</p> <pre><code>p=subprocess.Popen(args, shell=True) </code></pre> <p>From <a href="https://docs.python.org/2/library/subprocess.html#frequently-used-arguments" rel="nofollow">the docs</a>:</p> <blockquote> <p>If shell is True, the specified command will be executed throug...
2
2016-08-22T15:39:36Z
[ "python", "unix", "rar" ]
Untar file in Python script with wildcard
39,083,448
<p>I am trying in a Python script to import a tar.gz file from HDFS and then untar it. The file comes as follow <b>20160822073413-EoRcGvXMDIB5SVenEyD4pOEADPVPhPsg.tar.gz</b>, it has always the same structure.</p> <p>In my python script, I would like to copy it locally and the extract the file. I am using the followin...
0
2016-08-22T15:30:27Z
39,083,762
<p>In addition to @martriay answer, you also got a typo - you wrote "20160822*.tar", while your file's pattern is "20160822*.tar.gz"</p> <p>When applying <code>shell=True</code>, the command should be passed as a whole string (see <a href="https://docs.python.org/3/library/subprocess.html#popen-constructor" rel="nofol...
2
2016-08-22T15:47:35Z
[ "python", "unix", "rar" ]
Untar file in Python script with wildcard
39,083,448
<p>I am trying in a Python script to import a tar.gz file from HDFS and then untar it. The file comes as follow <b>20160822073413-EoRcGvXMDIB5SVenEyD4pOEADPVPhPsg.tar.gz</b>, it has always the same structure.</p> <p>In my python script, I would like to copy it locally and the extract the file. I am using the followin...
0
2016-08-22T15:30:27Z
39,096,316
<p>I found a way to do what I needed, instead of using os command, I used python tar command and it works!</p> <pre><code>import tarfile import glob os.chdir("/folder_to_scan/") for file in glob.glob("*.tar.gz"): print(file) tar = tarfile.open(file) tar.extractall() </code></pre> <p>Hope this help.</p> <p>Rega...
0
2016-08-23T08:40:05Z
[ "python", "unix", "rar" ]
Multiple Regression in Python (with Factor Selection)
39,083,462
<p>All the threads that I've read with respect to Multiple Regression in Python mostly recommend the OLS function within Statsmodels. Here's the problem that I am encountering, I am trying to explain a fund's returns (HYFAX highlighted in green) by regressing its returns against 14 independent variables that could expl...
1
2016-08-22T15:31:10Z
39,135,999
<p>Sounds like you just want to see the results from your model fit. Heres an example with 1 predictor, but easily extendable to 14:</p> <p>Import statsmodels and specify the model you want to build (this is where you'd include your 14 predictors):</p> <pre><code>import statsmodels.api as sm #read in your data howev...
0
2016-08-25T02:57:22Z
[ "python", "numpy", "scikit-learn", "regression" ]