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
Unable to loop thru JSON array inside an object
39,886,460
<p>This is how my JSON return object looks like:</p> <pre><code>{ u'Policy': u'{ "Version": "2012-10-17", "Statement": [{ "Sid": "xxxxx", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": ...
0
2016-10-06T02:13:49Z
39,886,498
<p>You should convert the JSON into a dictionary with</p> <pre><code>import json mydict = json.load(bucket_policy) </code></pre> <p>Then loop:</p> <pre><code>for stmt in mydict['Policy']['Statement']: print stmt </code></pre>
0
2016-10-06T02:20:38Z
[ "python", "json" ]
Unable to loop thru JSON array inside an object
39,886,460
<p>This is how my JSON return object looks like:</p> <pre><code>{ u'Policy': u'{ "Version": "2012-10-17", "Statement": [{ "Sid": "xxxxx", "Effect": "Allow", "Principal": { "Service": "cloudtrail.amazonaws.com" }, "Action": ...
0
2016-10-06T02:13:49Z
39,886,506
<p>The way it's shown in your question, <code>bucket_policy['Policy']</code> contains a string, not a dictionary.</p> <p>Either define it as a dictionary (i.e. get rid of <code>u'</code> at the beginning and <code>'</code> at the end) or parse the JSON with <a href="https://docs.python.org/3/library/json.html#json.loa...
0
2016-10-06T02:21:35Z
[ "python", "json" ]
can't get multi-select field name when post (no choice)
39,886,466
<p>html:</p> <pre><code>&lt;form method="post"&gt;{% module xsrf_form_html() %} &lt;input name="username" type="text"&gt; &lt;select name="ss" multiple&gt; &lt;option value="1"&gt;hello&lt;/option&gt; &lt;option value="2"&gt;word&lt;/option&gt; &lt;/select&gt; &lt;button type="submit"&g...
0
2016-10-06T02:14:54Z
39,886,874
<p>To determine whether the user selected <strong>none</strong> of the options, do:</p> <pre><code>ss = self.request.arguments.get("ss") </code></pre> <p>The <code>get</code> method returns <code>None</code> if there is no value. So,</p> <pre><code>if ss is None: print("User selected nothing") else: print("s...
0
2016-10-06T03:04:46Z
[ "python", "html", "tornado", "multi-select" ]
can't get multi-select field name when post (no choice)
39,886,466
<p>html:</p> <pre><code>&lt;form method="post"&gt;{% module xsrf_form_html() %} &lt;input name="username" type="text"&gt; &lt;select name="ss" multiple&gt; &lt;option value="1"&gt;hello&lt;/option&gt; &lt;option value="2"&gt;word&lt;/option&gt; &lt;/select&gt; &lt;button type="submit"&g...
0
2016-10-06T02:14:54Z
39,915,109
<p>Instead of parsing <code>request.arguments</code>, I recommend using the <a href="http://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.get_argument" rel="nofollow"><code>get_argument</code></a> method.</p>
0
2016-10-07T10:28:05Z
[ "python", "html", "tornado", "multi-select" ]
Using PyCharm, Can't Seem to Import Pyperclip module
39,886,467
<p>When I type <code>pip install pyperclip</code>, I get:</p> <pre><code>Collecting pyperclip Using cached pyperclip-1.5.27.zip Installing collected packages: pyperclip Running setup.py install for pyperclip ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/pr...
0
2016-10-06T02:14:56Z
39,886,534
<p>You are not able to make the necessary directories. Either do this:</p> <pre><code>sudo pip install paperclip </code></pre> <p>or the better and preferred solution, install <code>virtualenv</code>. Plenty of SO examples, here's link:</p> <p><a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/" rel="no...
1
2016-10-06T02:24:47Z
[ "python", "pyperclip" ]
Coordinate transformations from a randomly generated normal vector
39,886,503
<p>I'm trying to randomly generate coordinate transformations for a fitting routine I'm writing in python. I want to rotate my data (a bunch of [x,y,z] coordinates) about the origin, ideally using a bunch of randomly generated normal vectors I've already created to define planes -- I just want to shift each plane I've ...
0
2016-10-06T02:20:56Z
39,920,799
<p>I think you have a wrong concept of rotation matrices. Rotation matrices define rotation of a certain angle and can not have diagonal structure. </p> <p>If you imagine every rotation as a composition of a rotation around the X axis, then around the Y axis, then around the Z axis, you can build each matrix and compo...
1
2016-10-07T15:24:22Z
[ "python", "3d", "coordinate-transformation", "rotational-matrices" ]
Coordinate transformations from a randomly generated normal vector
39,886,503
<p>I'm trying to randomly generate coordinate transformations for a fitting routine I'm writing in python. I want to rotate my data (a bunch of [x,y,z] coordinates) about the origin, ideally using a bunch of randomly generated normal vectors I've already created to define planes -- I just want to shift each plane I've ...
0
2016-10-06T02:20:56Z
39,924,357
<p>Thanks to the people over in the math stack exchange, I have an answer that works. But note that it would not work if you also needed to perform a translation, which I didn't because I'm defining my planes by a normal vector and a point, and the normal vector changes but the point does not. Here's what worked for me...
0
2016-10-07T19:14:32Z
[ "python", "3d", "coordinate-transformation", "rotational-matrices" ]
Python 3.x - Cannot fix error: "slice indices must be integers or None or have an __index__ method" + more
39,886,505
<p>I'm working on a class that replicates the Sieve of Eratosthenes and have been getting the error message given in the title. Below is my code, more questions follow.</p> <pre><code> class Sieve: def __init__(self, max): if max &lt; 0: raise RuntimeError else: self.numbers = [([False] * 2...
0
2016-10-06T02:21:22Z
39,886,752
<p>In python, <code>for i in self.numbers</code> works like Java enhanced For loop, where the For loop will iterate over the list, <code>i</code> will be the list entry (In your case, <code>True / False</code>) instead of the index.</p> <p>If you want to access the list index, please utilize <code>for i in range(len(s...
1
2016-10-06T02:50:44Z
[ "python", "list", "class", "syntax" ]
Variables in jinja2 template imported by flask duplicated
39,886,535
<p>I try to use Flask to scan all the file in a specific folder and build the url links to those files automatically, so first I defined a app route in Flask:</p> <pre><code>homepath = os.getcwd() # the root path of the app @app.route('/&lt;folder&gt;/') def showList(folder): folder_abs_path = homepat...
0
2016-10-06T02:24:57Z
39,906,538
<p>As @Klaus said in the comment, you are generating relative paths for the static files. To avoid that, just use the <a href="http://flask.pocoo.org/docs/0.11/api/#flask.url_for" rel="nofollow">url_for()</a> function in the template for path generating:</p> <pre><code>{% extends "layouts/main.html" %} {% block conten...
0
2016-10-06T22:24:03Z
[ "python", "templates", "flask", "jinja2" ]
Converting python lists to pd.DataFrame
39,886,556
<p>If I have 3 python lists items:</p> <pre><code>list1 = [1,2,3] list2 = ['a','b','c'] list3 = ['I',"II","III"] </code></pre> <p>And my goal is to build a pd.DataFrame using list1 as index and the rest as columns:</p> <pre><code> list2 list3 1 "a" "I" 2 "b" "II" 3 "c" "III" </code></p...
1
2016-10-06T02:28:21Z
39,886,612
<p>Use the DataFrame constructor:</p> <pre><code>In [1]: import pandas as pd, numpy as np In [2]: list1 = [1,2,3] In [3]: list2 = ['a','b','c'] In [4]: list3 = ['I',"II","III"] In [5]: pd.DataFrame({'list2':list2,'list3':list3}, index=list1) Out[5]: list2 list3 1 a I 2 b II 3 c III In [6]:...
0
2016-10-06T02:34:36Z
[ "python", "pandas" ]
Why are the conditions in if block not working correctly?
39,886,604
<p>Yakshemash ! I am a Java programmer learning python to make throwaway scripts. I want to make a parser which is shown in the code below.</p> <pre><code>class Parser(object): def parse_message(self, message): size= len(message) if size != 3 or size != 5: raise ValueError("Message leng...
0
2016-10-06T02:33:59Z
39,886,656
<p>Your problem is with your conditional statement using <code>or</code>: </p> <pre><code>if size != 3 or size != 5: </code></pre> <p>If the size is not equal to 3 "OR" it is not equal to 5, then raise. </p> <p>So, with your input being passed: <code>12345</code></p> <pre><code>Is it not equal to 3? True Is it not ...
3
2016-10-06T02:40:35Z
[ "python" ]
Why are the conditions in if block not working correctly?
39,886,604
<p>Yakshemash ! I am a Java programmer learning python to make throwaway scripts. I want to make a parser which is shown in the code below.</p> <pre><code>class Parser(object): def parse_message(self, message): size= len(message) if size != 3 or size != 5: raise ValueError("Message leng...
0
2016-10-06T02:33:59Z
39,886,887
<p>Syntactically, there is nothing wrong in your code. The output is correct according to your code.</p> <pre><code>size != 3 or size != 5: # This will be always *true* because it is impossible for **message** to be of two different lengths at the same time to make the condition false. </code></pre> <p>Since the...
1
2016-10-06T03:06:40Z
[ "python" ]
Checking a variable against a list and seeing if a word in that list starts with the variable
39,886,605
<p>I'm trying to write a function that uses a checker that could be any length and checks it against the list. It should be case insensitive when checking and print the word. Example below</p> <p><code>Input= startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot'])</code></p> <p><strong>Output:</strong></p...
-1
2016-10-06T02:34:04Z
39,886,701
<pre><code>def startsWith(checker,lister): for i in range(len(lister)): words = lister[i].lower() if(words.startswith(checker)): print(lister[i]) def main(): startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot']) main() </code></pre> <p>OUTPUT</p> <pre><code>apple Ap...
1
2016-10-06T02:45:17Z
[ "python" ]
Checking a variable against a list and seeing if a word in that list starts with the variable
39,886,605
<p>I'm trying to write a function that uses a checker that could be any length and checks it against the list. It should be case insensitive when checking and print the word. Example below</p> <p><code>Input= startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot'])</code></p> <p><strong>Output:</strong></p...
-1
2016-10-06T02:34:04Z
39,886,845
<p>Here's the root of the problem</p> <pre><code>lister = [element.lower() for element in lister] </code></pre> <p><code>lister</code> now only contains lowercase strings, which you then print. You need to delay the <code>lower()</code> until you check for <code>checker</code>. </p> <hr> <p>No need to check the len...
1
2016-10-06T03:01:41Z
[ "python" ]
Checking a variable against a list and seeing if a word in that list starts with the variable
39,886,605
<p>I'm trying to write a function that uses a checker that could be any length and checks it against the list. It should be case insensitive when checking and print the word. Example below</p> <p><code>Input= startsWith('a',['apple','ApPle','orange','Apple','kiwi','apricot'])</code></p> <p><strong>Output:</strong></p...
-1
2016-10-06T02:34:04Z
39,886,854
<p>You should not mutate the original elements of <code>lister</code>, rather do the comparison on a new copy of those elements that has been converted to lower case.</p> <p>It can be done in a single list comprehension.</p> <pre><code>def startsWith(checker, lister): cl = checker.lower() return [s for s in l...
0
2016-10-06T03:02:17Z
[ "python" ]
"SyntaxError: Invalid Syntax" but it worked before! (Python 3.5.2 doing a tutorial for beginners)
39,886,673
<p>Soo I swear this code worked before! </p> <h1>Is there a setting on IDLE that I might have accidently turned on?</h1> <p>I'm trying to do something very simple..set variables.</p> <p>As you can see these work:</p> <pre><code>&gt;&gt;&gt; print("hello") hello &gt;&gt;&gt; def main(): print("hey") &gt...
0
2016-10-06T02:41:51Z
39,887,299
<p>As pointed out in the comments several times, You are simply missing a closing <code>)</code> on line 4 of your program. line 4 should look like</p> <p><code>n = eval(input("Enter amount of coffee in pounds: "))# &lt;--extra parenthesis</code></p> <hr> <p>Some unrelated points in your code:</p> <ul> <li>Why are ...
0
2016-10-06T04:00:52Z
[ "python" ]
Delete the first elements of each row in list in python2.7
39,886,674
<p>My list looks like: ['0 0.690001', '1 0.970671', '2 1.520989', '3 1.946516', '4 2.229378']</p> <p>how can I get [ 0.69000,0.970671,1.520989,1.946516,2.229378]</p>
-3
2016-10-06T02:41:52Z
39,886,850
<p>Use list comprehension as:</p> <pre><code>my_list = ['0 0.690001', '1 0.970671', '2 1.520989', '3 1.946516', '4 2.229378'] [float(item.split()[1]) for item in my_list] </code></pre> <p>OR, you may also use <code>map()</code>:</p> <pre><code>map(lambda x: float(x.split()[1]), my_list) </code></pre>
0
2016-10-06T03:02:17Z
[ "python", "python-2.7" ]
Delete the first elements of each row in list in python2.7
39,886,674
<p>My list looks like: ['0 0.690001', '1 0.970671', '2 1.520989', '3 1.946516', '4 2.229378']</p> <p>how can I get [ 0.69000,0.970671,1.520989,1.946516,2.229378]</p>
-3
2016-10-06T02:41:52Z
39,888,827
<pre><code>import re map(lambda x:float(re.sub(r'[^ ]+ ','',x)),l) </code></pre>
0
2016-10-06T06:18:36Z
[ "python", "python-2.7" ]
Django: Organize objects in a dictionary by foreign key
39,886,744
<p>I have this problem: I've got two models, products and categories, the categories are defined in a fixture (they won't change), and I need to display all categories in a single template, as a grid. The models are rather simple, the important thing is that Products have a foreign key pointing to Category model, and a...
0
2016-10-06T02:50:06Z
39,887,619
<p>There is better way to do this. Use <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#prefetch-objects" rel="nofollow"><code>Prefetch</code></a> object. Prefetch will have only filtered data for each category.</p> <pre><code>from django.db.models.query import Prefetch def index(request): us...
2
2016-10-06T04:38:03Z
[ "python", "django", "django-templates" ]
How to customize the list_display option in django using queryset?
39,886,747
<p>I want to make a course guidance app for my college. Here is my model.py</p> <pre><code>from django.db import models from django.contrib.auth.models import User # Create your models here. class Instructor(models.Model): name = models.CharField(max_length=200) owner = models.ForeignKey(User) # other st...
1
2016-10-06T02:50:16Z
39,887,393
<p>Your code is mostly right but the method is actually <code>get_queryset</code> rather than <code>queryset</code> you've probably mixed it up with the queryset property</p> <pre><code>def get_queryset(self, request): qs = super(CourseAdmin, self).get_queryset(request) if request.user.is_superuser: re...
0
2016-10-06T04:13:53Z
[ "python", "django", "django-admin", "django-authentication" ]
How to add Pandas dataframe column from a element of a list in another column without lambda?
39,886,810
<p>Suppose I have this dataframe</p> <pre><code>A B [ 'a' , 'b' , 'c' ] 3 [ 'e' , 'f' , 'g' , 'h'] 5 </code></pre> <p>How can I create a new column such as below without lambda?</p> <pre><code>A B C [ 'a' , 'b' , 'c' ] 3 'b' [ 'e'...
0
2016-10-06T02:59:10Z
39,887,010
<p>You can define your lambda as a regular function and call it using apply like so:</p> <pre><code>def my_function(x): return x[-2] df['C'] = df['A'].apply(my_function) </code></pre>
0
2016-10-06T03:24:28Z
[ "python", "pandas" ]
How to add Pandas dataframe column from a element of a list in another column without lambda?
39,886,810
<p>Suppose I have this dataframe</p> <pre><code>A B [ 'a' , 'b' , 'c' ] 3 [ 'e' , 'f' , 'g' , 'h'] 5 </code></pre> <p>How can I create a new column such as below without lambda?</p> <pre><code>A B C [ 'a' , 'b' , 'c' ] 3 'b' [ 'e'...
0
2016-10-06T02:59:10Z
39,887,192
<p>A solution is to use <code>str</code> to index from the list but it requires the string lengths to be uniform. You could also use the list comprehension proposed by Bob which is the most robust solution.</p> <pre><code>In [110]: df.A.str.join(',').str[-3] Out[110]: 0 b 1 g Name: A, dtype: object </code></pre>...
0
2016-10-06T03:45:49Z
[ "python", "pandas" ]
Reading data in python pandas by defining width of each column as number of characters
39,886,884
<p>I'm trying to read a file in which columns are separated by variable spaces. I was wondering if there is a way to read the file by defining the width of each column in terms of number of characters reserved for that column.</p> <p>For example:</p> <pre><code>A B C D - ---------- -- --- 1 foo 32 9....
0
2016-10-06T03:06:20Z
39,886,927
<p>You should use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_fwf.html" rel="nofollow"><code>pandas.read_fwf()</code></a>. It stands for Read Fixed Width File.</p>
3
2016-10-06T03:12:18Z
[ "python", "csv", "pandas", "numpy", "data-analysis" ]
Reading data in python pandas by defining width of each column as number of characters
39,886,884
<p>I'm trying to read a file in which columns are separated by variable spaces. I was wondering if there is a way to read the file by defining the width of each column in terms of number of characters reserved for that column.</p> <p>For example:</p> <pre><code>A B C D - ---------- -- --- 1 foo 32 9....
0
2016-10-06T03:06:20Z
39,887,092
<p>The <code>delimiter</code> for <code>np.genfromtxt</code> can be a list of column widths instead of a delimiter character.</p>
1
2016-10-06T03:34:48Z
[ "python", "csv", "pandas", "numpy", "data-analysis" ]
Shuffling specific values in a dictionary (Python 3.5)
39,886,922
<p>I am writing a murder mystery--a lot like Clue. I am using dictionaries to store all my info. My question: is there a way to shuffle dictionary values which pull from a set range of integers? I want every game to shuffle certain values within the dictionaries when starting a new game. Right now I'm focused on charac...
0
2016-10-06T03:10:46Z
39,886,963
<p>Python dictionaries are unordered, so I dont see why you woulf want to "shuffle" them. If you want to pick random strings inside the dict, maybe you could use a list to wrap this dictionary for simplicity sake.</p> <p>Like so:</p> <p><code>Locations = [ {"name": "bedroom...}, {"name": "livingroom"...},...]</code><...
0
2016-10-06T03:18:23Z
[ "python", "dictionary", "text", "adventure" ]
Shuffling specific values in a dictionary (Python 3.5)
39,886,922
<p>I am writing a murder mystery--a lot like Clue. I am using dictionaries to store all my info. My question: is there a way to shuffle dictionary values which pull from a set range of integers? I want every game to shuffle certain values within the dictionaries when starting a new game. Right now I'm focused on charac...
0
2016-10-06T03:10:46Z
39,887,050
<p>If Python3.x then do:</p> <pre><code>import random random.choice(list(someDictionary.keys())) </code></pre> <p>If Python2.x then do:</p> <pre><code>import random random.choice(someDictionary.keys()) </code></pre>
0
2016-10-06T03:29:10Z
[ "python", "dictionary", "text", "adventure" ]
python - How to deploy Flask+Gunicorn+Nginx+supervisor on a cloud server?
39,886,992
<p>I've read a lot of instructions since yesterday about this issue but all of them have similar steps. However I followed step by step but still can't get everything Ok.</p> <p>Actually I can make Flask+Gunicorn+supervisor working but Nginx is not working well.</p> <p>I connect my remote cloud server with SSH and I'...
-1
2016-10-06T03:21:51Z
39,887,658
<p><code>0.0.0.0</code> means the server will accept connections from all IP address. See <a href="https://en.wikipedia.org/wiki/0.0.0.0" rel="nofollow">https://en.wikipedia.org/wiki/0.0.0.0</a> for more detail.</p> <p>If the gunicorn server listens on <code>127.0.0.1</code>, only you (or someone else on the same mach...
0
2016-10-06T04:41:22Z
[ "python", "nginx", "web", "flask", "server" ]
How to search CSV line for string in certain column, print entire line to file if found
39,887,098
<p>Sorry, very much a beginner with Python and could really use some help.</p> <p>I have a large CSV file, items separated by commas, that I'm trying to go through with Python. Here is an example of a line in the CSV.</p> <p>123123,JOHN SMITH,SMITH FARMS,A,N,N,12345 123 AVE,CITY,NE,68355,US,12345 123 AVE,CITY,NE,6835...
0
2016-10-06T03:35:11Z
39,887,170
<p>You're not actually using your <code>reader</code> to read the input CSV, you're just reading the raw lines from the file itself.</p> <p>A fixed version looks like the following (untested):</p> <pre><code>import csv with open('Sample.csv', 'rb') as f, open('NE_Sample.csv', 'wb') as outf: reader = csv.reader(f...
2
2016-10-06T03:43:20Z
[ "python", "string", "csv", "search" ]
How to search CSV line for string in certain column, print entire line to file if found
39,887,098
<p>Sorry, very much a beginner with Python and could really use some help.</p> <p>I have a large CSV file, items separated by commas, that I'm trying to go through with Python. Here is an example of a line in the CSV.</p> <p>123123,JOHN SMITH,SMITH FARMS,A,N,N,12345 123 AVE,CITY,NE,68355,US,12345 123 AVE,CITY,NE,6835...
0
2016-10-06T03:35:11Z
39,887,350
<p>This snippet should solves your problem</p> <pre><code>import csv with open('Sample.csv', 'rb') as f, open('NE_Sample.csv', 'wb') as outf: reader = csv.reader(f, delimiter=',') writer = csv.writer(outf) for row in reader: if "NE" in row: print ('Found: {}'.format(row)) w...
0
2016-10-06T04:08:21Z
[ "python", "string", "csv", "search" ]
How to extract a string from a list
39,887,149
<p>I'm new to Python without any programming background except for some shell scripting.</p> <p>I want to extract 2 fields from the below list: Here I want 'title' and 'plays' and assign it to a another list eg) new_list=[title,plays]</p> <pre><code>alist=[(0, 'title', 'TEXT', 0, None, 0), (1, 'plays', 'integer', 0, ...
0
2016-10-06T03:41:39Z
39,887,252
<p>The simplest way, of course, it is just write the assignment statement:</p> <pre><code>new_list=['title','plays'] </code></pre> <p>But you probably intended to ask a more general question, like "How can I extract the 2nd item from the first two tuples in a list?" Like so:</p> <pre><code>new_list = [alist[0][1], a...
3
2016-10-06T03:54:55Z
[ "python", "python-2.7", "python-3.x" ]
How to extract a string from a list
39,887,149
<p>I'm new to Python without any programming background except for some shell scripting.</p> <p>I want to extract 2 fields from the below list: Here I want 'title' and 'plays' and assign it to a another list eg) new_list=[title,plays]</p> <pre><code>alist=[(0, 'title', 'TEXT', 0, None, 0), (1, 'plays', 'integer', 0, ...
0
2016-10-06T03:41:39Z
39,887,269
<pre><code>alist = [(0, 'title', 'TEXT', 0, None, 0),(0, 'plays', 'integer', 0, None, 0)] new_list = [alist[0][1], alist[1][1]] </code></pre> <p>to check,</p> <pre><code>print(new_list) </code></pre> <p><strong>Explain</strong></p> <p>This line: </p> <pre><code>alist = [(0, 'title', 'TEXT', 0, None, 0), (0, 'plays...
2
2016-10-06T03:58:00Z
[ "python", "python-2.7", "python-3.x" ]
Round Robin Scheduling for a pandas dataframe
39,887,219
<p>I have been working on a bit of code that reads in a tab-delimited CSV file, which represents a series of processes and their start times and durations, and creates a dataframe for it using pandas. I then need to apply the simplified round-robin form of scheduling to find the turnaround time for the process, with th...
0
2016-10-06T03:50:05Z
39,887,746
<p>I revised your code a little bit and it works.You can't actually cover the original value with a revised value in your way, so the loop will not end.</p> <pre><code>while (d1['Duration']).any() &gt; 0: for index, row in d1.iterrows(): # if value in column 'Duration' &gt; the timeslice, add the value of ...
0
2016-10-06T04:50:42Z
[ "python", "python-3.x", "csv", "pandas" ]
Plotting unique values in pandas
39,887,382
<p>I have a data frame where the first column is time and the second is a letter:</p> <pre><code>Time Letter 2016-10-05 20:46:12 'A' 2016-10-05 20:47:12 'A' 2016-10-05 20:50:12 'B' 2016-10-06 00:46:12 'A' 2016-10-06 01:46:12 'B' 2016-10-06 01:47:12 'C' 2016-10-06 02:46:12 'D' </code></pre> <p>I need t...
0
2016-10-06T04:12:27Z
39,887,966
<p>You can either use pd.Grouper:</p> <pre><code>df.groupby(pd.Grouper(key='Time', freq='H'))['Letter'].nunique() </code></pre> <p>Or set the time column as index and resample:</p> <pre><code>df.set_index('Time').resample('H')['Letter'].nunique() </code></pre> <p>Both will fill the missing interval with zeros. Sinc...
0
2016-10-06T05:11:43Z
[ "python", "pandas" ]
Plotting unique values in pandas
39,887,382
<p>I have a data frame where the first column is time and the second is a letter:</p> <pre><code>Time Letter 2016-10-05 20:46:12 'A' 2016-10-05 20:47:12 'A' 2016-10-05 20:50:12 'B' 2016-10-06 00:46:12 'A' 2016-10-06 01:46:12 'B' 2016-10-06 01:47:12 'C' 2016-10-06 02:46:12 'D' </code></pre> <p>I need t...
0
2016-10-06T04:12:27Z
39,888,004
<p>You can remove minutes and seconds by converting column <code>Time</code> to <code>numpy array</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.values.html" rel="nofollow"><code>values</code></a> and then <code>groupby</code>:</p> <pre><code>print (df.Time.values.astype('&lt;M8...
0
2016-10-06T05:15:37Z
[ "python", "pandas" ]
How to use two nets in TFlearn?
39,887,397
<p>I am trying to train DQN to play Tic-Tac-Toe. I trained it to play X (while O moves are random). After 12h of training it plays ok, but not flawless. Now I want to train two nets simultaneously - one for X moves and one for O moves. But when I try to do model.predict(state) on second network, I get errors like:</p> ...
0
2016-10-06T04:14:20Z
39,891,385
<p>Looks like I should add</p> <pre><code>with tf.Graph().as_default(): #define model here </code></pre> <p>to prevent TFLearn to append both models to default graph. With this addition everything works.</p>
0
2016-10-06T08:39:38Z
[ "python", "machine-learning", "tensorflow" ]
More arguments in derived class __init__ than base class __init__
39,887,422
<p>How can I extend the <code>__init__</code> of a base class, <strong>add more arguments to be parsed</strong>, without requiring <code>super().__init__(foo, bar)</code> in every derived class?</p> <pre class="lang-python prettyprint-override"><code>class Ipsum: """ A base ipsum instance. """ def __init__(se...
2
2016-10-06T04:16:21Z
39,887,755
<p>The usual way to write these is roughly as follows:</p> <pre><code>class Ipsum: # 3.x-ism; in 2.x always inherit from object. def __init__(self, arg1, arg2, arg3): # etc... class LoremIpsum(Ipsum): def __init__(self, arg4, arg5, *args, **kwargs): super().__init__(*args, **kwargs) # 3.x-is...
1
2016-10-06T04:51:42Z
[ "python", "inheritance" ]
More arguments in derived class __init__ than base class __init__
39,887,422
<p>How can I extend the <code>__init__</code> of a base class, <strong>add more arguments to be parsed</strong>, without requiring <code>super().__init__(foo, bar)</code> in every derived class?</p> <pre class="lang-python prettyprint-override"><code>class Ipsum: """ A base ipsum instance. """ def __init__(se...
2
2016-10-06T04:16:21Z
39,887,759
<p>A flexible approach is to have every method in the ancestor tree cooperatively designed to accept keyword arguments and a keyword-arguments dictionary, to remove any arguments that it needs, and to forward the remaining arguments using <code>**kwds</code>, eventually leaving the dictionary empty for the final call i...
2
2016-10-06T04:52:11Z
[ "python", "inheritance" ]
More arguments in derived class __init__ than base class __init__
39,887,422
<p>How can I extend the <code>__init__</code> of a base class, <strong>add more arguments to be parsed</strong>, without requiring <code>super().__init__(foo, bar)</code> in every derived class?</p> <pre class="lang-python prettyprint-override"><code>class Ipsum: """ A base ipsum instance. """ def __init__(se...
2
2016-10-06T04:16:21Z
39,887,762
<p>Derived classes need to call the superclass <code>__init__</code>. That's how object-oriented programming works. Is it brittle? Yes, it can be; that's why deep or broad class hierarchies aren't usually a good idea. If the operations on <code>foo</code> and <code>bar</code> in <code>Lorem</code> are significant (...
0
2016-10-06T04:52:25Z
[ "python", "inheritance" ]
Unable to use jinja2 template in pip package created from python module
39,887,573
<p>I have a python project with the following directory structure</p> <pre><code>foo |--MANIFEST.in |--requirements.txt |--setup.py |--foo.py |--templates/ |--bar.tmpl </code></pre> <p>where <code>setup.py</code> is a python script. Previously, I was using an install script to symlink the script to my ...
0
2016-10-06T04:32:02Z
39,887,784
<p><code>MANIFEST.in</code> tell what files to include in the source distribution, i.e. <code>python setup.py sdist</code>, but it does not directly affect what files are installed because <code>pip install .</code> just calls into setuptools and doesn't do anything special with package_data.</p> <p>You need to includ...
1
2016-10-06T04:55:14Z
[ "python", "python-2.7", "pip", "jinja2", "setuptools" ]
How do I apply a smoothing filter with dask
39,887,682
<p>I have a 2 dimensional array, I would like to do a 2 dimensional convolution with a kernel, for example a simple flat square matrix.</p> <p>See for example: <a href="http://nbviewer.jupyter.org/gist/zonca/f0d819048ef7318eff944396b71af1c4" rel="nofollow">http://nbviewer.jupyter.org/gist/zonca/f0d819048ef7318eff94439...
2
2016-10-06T04:44:08Z
39,895,157
<p>The <a href="http://dask.pydata.org/en/latest/array-api.html#dask.array.Array.map_overlap" rel="nofollow">map_overlap</a> method may do what you want. It allows you to map a function over chunks of your array where those chunks have been pre-buffered with an overlapping region from nearby chunks. </p> <p>Somethin...
0
2016-10-06T11:46:24Z
[ "python", "dask" ]
Separating HTML file with keyword for scraping
39,887,834
<p>I am programming in Python with Scrapy and have a huge <code>html</code> file with a structure similar to the one demonstrated below:</p> <pre><code>&lt;span&gt;keyword&lt;/span&gt; &lt;title&gt;Title 1&lt;/title&gt; &lt;span&gt;Date 1&lt;/span&gt; &lt;div&gt;Content 1&lt;/div&gt; &lt;span&gt;keyword&lt;/span&gt; ...
-1
2016-10-06T05:00:16Z
39,888,963
<h2>Update</h2> <p>Carl, the thing is that regex and even mere text processing (split, etc.) are not effective to work with big text samples. </p> <p><strong>xPath</strong> is the technique that fits best in your case. </p> <p>Though a target html might be malformed, still the modern DOM libraries are good to turn h...
0
2016-10-06T06:27:36Z
[ "python", "web-scraping", "scrapy" ]
Can a python function know when it's being called by a list comprehension?
39,887,880
<p>I want to make a python function that behaves differently when it's being called from a list comprehension:</p> <pre><code>def f(): # this function returns False when called normally, # and True when called from a list comprehension pass &gt;&gt;&gt; f() False &gt;&gt;&gt; [f() for _ in range(3)] [True...
3
2016-10-06T05:04:10Z
39,888,055
<p>Addon to my comment:</p> <pre><code>def f(lst=False): return True if lst else False f() #False [f(True) for _ in range(3)] # [True True True] </code></pre> <p>This would work, but is this the real problem that you're trying to solve? It seems a really unintuitive use-case which can be solved better by other m...
0
2016-10-06T05:19:17Z
[ "python" ]
Can a python function know when it's being called by a list comprehension?
39,887,880
<p>I want to make a python function that behaves differently when it's being called from a list comprehension:</p> <pre><code>def f(): # this function returns False when called normally, # and True when called from a list comprehension pass &gt;&gt;&gt; f() False &gt;&gt;&gt; [f() for _ in range(3)] [True...
3
2016-10-06T05:04:10Z
39,888,195
<p>You can determine this by inspecting the stack frame in the following sort of way:</p> <pre><code>def f(): try: raise ValueError except Exception as e: if e.__traceback__.tb_frame.f_back.f_code.co_name == '&lt;listcomp&gt;': return True </code></pre> <p>Then: </p> <pre><code>&g...
8
2016-10-06T05:30:50Z
[ "python" ]
Cannot import python naoqi library after upgrading Ubuntu 14.04 to 16.04
39,887,889
<p>I have recently upgraded the system to 16.04 Gnome. The most troubling thing that I am facing is that I cannot import a NAOqi library for my work. The python version of this library was pretty simple to set-up. One just has to untar the file and then enter a path variable called PYTHONPATH pointing to this library a...
0
2016-10-06T05:04:39Z
39,899,013
<p>Installing libboost1.55 did the trick. 16.04 comes with libboost1.58 but naoqi is not yet compatible with it. Manual installation of libboost1.55 solved the import error.</p>
0
2016-10-06T14:43:12Z
[ "python", "python-2.7", "gnome", "ubuntu-16.04", "nao-robot" ]
Django REST FileUpload serializer returns {'file': None}
39,887,923
<p>I’ve been working on a Django project that requires a file upload. I use API approach in my app designs using django-rest-framework. I created my model, APIView, and serializer but unfortunately every time the request goes through the serializer the upload.data returns {'file': None}. If I just use request.FILES['...
0
2016-10-06T05:07:33Z
39,892,375
<p>It would be helpful to see how you are uploading the file. If you are using a multipart/form-data request and providing the json for "file" properly, the most likely thing is that the file is failing validation for some reason.</p> <p>If you can, it might also be helpful to test from the browsable api (as that guar...
1
2016-10-06T09:29:01Z
[ "python", "django", "django-rest-framework", "django-serializer" ]
Split a string in parts and convert this in a datetime
39,887,944
<p>I scrapped a html string with the following content.</p> <blockquote> <p>[u'Mitglied seit M\xe4rz 2016']</p> </blockquote> <p>M\xe4rz should be März (German word for March).</p> <p>I want to convert this scrapped output in a datetime. My first try was to convert the output in a string and split this with the f...
0
2016-10-06T05:09:47Z
39,888,002
<p>There is a way to encode the \xe4 character.</p> <pre><code>str = 'Mitglied seit M\xe4rz 2016' str = str.decode('unicode-escape').encode('utf-8') str = '1. ' + str.split(' ')[2] + ' ' + str.split(' ')[3] </code></pre>
0
2016-10-06T05:15:32Z
[ "python", "datetime", "scrapy", "type-conversion" ]
Split a string in parts and convert this in a datetime
39,887,944
<p>I scrapped a html string with the following content.</p> <blockquote> <p>[u'Mitglied seit M\xe4rz 2016']</p> </blockquote> <p>M\xe4rz should be März (German word for March).</p> <p>I want to convert this scrapped output in a datetime. My first try was to convert the output in a string and split this with the f...
0
2016-10-06T05:09:47Z
39,903,281
<p>There is a lot of code. You can simplify or adopt it, but I think it should help:</p> <pre><code># encoding: utf-8 import datetime months = { u'Januar': '1', u'Februar': '2', u'März': '3', u'April': '4', u'Mai': '5', u'Juni': '6', u'Juli': '7', u'August': '8', u'September': '9...
0
2016-10-06T18:31:59Z
[ "python", "datetime", "scrapy", "type-conversion" ]
How to unit test program interacting with block devices
39,888,013
<p>I have a program that interacts with and changes block devices (/dev/sda and such) on linux. I'm using various external commands (mostly commands from the fdisk and GNU fdisk packages) to control the devices. I have made a class that serves as the interface for most of the basic actions with block devices (for infor...
3
2016-10-06T05:15:54Z
39,888,724
<p>You should look into the mock module (I think it's part of the unittest module now in Python 3).</p> <p>It enables you to run tests without the need to depened in any external resources while giving you control over how the mocks interact with your code.</p> <p>I would start from the docs in <a href="http://www.vo...
2
2016-10-06T06:12:07Z
[ "python", "unit-testing" ]
pyspark type error on reading a pandas dataframe
39,888,188
<p>I read some CSV file into pandas, nicely preprocessed it and set dtypes to desired values of float, int, category. However, when trying to import it into spark I get the following error:</p> <pre><code>Can not merge type &lt;class 'pyspark.sql.types.DoubleType'&gt; and &lt;class 'pyspark.sql.types.StringType'&gt; <...
1
2016-10-06T05:30:27Z
39,889,639
<p>You'll need to define the spark <code>DataFrame</code> schema explicitly and pass it to the <code>createDataFrame</code> function :</p> <pre><code>from pyspark.sql.types import * import pandas as pd small = pdf.read_csv("data.csv") small.head() # myColumns # 0 NaN # 1 A sch = StructType([StructFi...
2
2016-10-06T07:07:56Z
[ "python", "csv", "pandas", "apache-spark", "pyspark" ]
Python 3.5 running in IDLE shell, but not macOS Terminal
39,888,268
<p>I'm trying to get Python 3.5 to run in my terminal. I made a script using idle that printed out the version of python in use to try to solve my problem. The script looked like this:</p> <pre><code>import sys print(sys.version_info) </code></pre> <p>When I ran it in IDLE, I got the following output:</p> <pre><cod...
0
2016-10-06T05:37:02Z
39,888,289
<h1>Running Python from the terminal</h1> <p>If you have Python installed, then:</p> <ul> <li><code>python</code> or <code>python2</code> opens the interactive prompt or runs a script if a file is supplied as an argument</li> <li><code>python3</code> does the same as above, but for Python 3</li> </ul> <p>Note that i...
0
2016-10-06T05:38:47Z
[ "python", "osx", "shell", "pip", "python-idle" ]
Python 3.5 running in IDLE shell, but not macOS Terminal
39,888,268
<p>I'm trying to get Python 3.5 to run in my terminal. I made a script using idle that printed out the version of python in use to try to solve my problem. The script looked like this:</p> <pre><code>import sys print(sys.version_info) </code></pre> <p>When I ran it in IDLE, I got the following output:</p> <pre><cod...
0
2016-10-06T05:37:02Z
39,888,348
<p>To run idle from command line Type <code>idle3</code> in the terminal for <code>Python 3</code> idle and if you want to run <code>Python 2</code> idle, type <code>idle</code> in the terminal .</p> <p>Similarly, if you need to run a script or python prompt from terminal you should type <code>python3</code> when you ...
0
2016-10-06T05:44:15Z
[ "python", "osx", "shell", "pip", "python-idle" ]
How do I iterate through a dictionary's sets of values and return the key of the sets of values that matches a given set?
39,888,354
<p>I have a function guess which is supposed to return the key of the set of animal values (arg2) that matches the set of observations (arg1). For instance, if the set of observations = {'pet,' 'fluffy'} and the dictionary of animals = {'cat': {'pet,' 'fluffy', 'cute'}, 'dog': {'pet'}} then the function should return t...
0
2016-10-06T05:44:39Z
39,888,524
<p>Idea is to iterate over all potential animals and see if the observed values are a subset of their respective attributes). I'm assuming there could be multiple animals satisfying the observations.</p> <pre><code>observations = {'pet,' 'fluffy'} animals = {'cat': {'pet,' 'fluffy', 'cute'}, 'dog': {'pet'}} def guess...
3
2016-10-06T05:56:27Z
[ "python", "python-3.x" ]
How do I iterate through a dictionary's sets of values and return the key of the sets of values that matches a given set?
39,888,354
<p>I have a function guess which is supposed to return the key of the set of animal values (arg2) that matches the set of observations (arg1). For instance, if the set of observations = {'pet,' 'fluffy'} and the dictionary of animals = {'cat': {'pet,' 'fluffy', 'cute'}, 'dog': {'pet'}} then the function should return t...
0
2016-10-06T05:44:39Z
39,888,637
<p>What you want to know is whether the value of each item in <code>animals</code> is a superset of <code>observations</code>. Thankfully, <code>set</code> has a <a href="https://docs.python.org/3/library/stdtypes.html#set.issuperset" rel="nofollow">method</a> to test exactly that, so your function is straightforward:<...
1
2016-10-06T06:04:32Z
[ "python", "python-3.x" ]
How do I iterate through a dictionary's sets of values and return the key of the sets of values that matches a given set?
39,888,354
<p>I have a function guess which is supposed to return the key of the set of animal values (arg2) that matches the set of observations (arg1). For instance, if the set of observations = {'pet,' 'fluffy'} and the dictionary of animals = {'cat': {'pet,' 'fluffy', 'cute'}, 'dog': {'pet'}} then the function should return t...
0
2016-10-06T05:44:39Z
39,888,853
<p>It appears to me that you're looking for the <em>best</em> match (most matched attributes), so I'd propose this:</p> <pre><code>def guess(observations, animals): return max(list((len(observations &amp; value), key) # most matches for key, value in animals.items() if obs...
0
2016-10-06T06:20:09Z
[ "python", "python-3.x" ]
How do constants work in an if block?
39,888,396
<p>I am new to python. I want to learn how to make and use "constants". Here is my code:</p> <pre><code>class Constantine(object): ONE = 1 TWO = 2 def test(self, code): if code not in(self.ONE, self.TWO): print("safe") else: print("not safe") keeanu = Constantine()...
-2
2016-10-06T05:48:42Z
39,888,493
<p>You are testing whether <code>code</code> is <strong><em>not</em></strong> in <code>(self.ONE, self.TWO)</code>. If it <strong><em>is</em></strong> found, it will print <code>not safe</code>, which it does.</p> <p>The reason it is found is because the interpreter first looks up <code>self.ONE</code> and <code>self....
3
2016-10-06T05:54:19Z
[ "python" ]
Defining the Linear Programming Model for Traveling Salesman in Python
39,888,448
<p>Using Python and <code>PuLP</code> library, how can we create the linear programming model to solve the Traveling Salesman Problem (TSP)?</p> <p>From Wikipedia, the objective function and constraints are </p> <p><a href="http://i.stack.imgur.com/Z9wuZ.png" rel="nofollow"><img src="http://i.stack.imgur.com/Z9wuZ.pn...
1
2016-10-06T05:52:00Z
39,888,814
<p>The last constraint is <strong>not</strong> a single constraint. You should add one constraint for each pair of indices <code>i, j</code> that satisfy that condition:</p> <pre><code>for i in range(n-1): for j in range(i+1, n): m += pulp.lpSum([ u[i] - u[j] + n*x[i,j]]) &lt;= n-1 </code></pre> <p>Howeve...
0
2016-10-06T06:17:42Z
[ "python", "algorithm", "python-2.7", "linear-programming", "pulp" ]
Searching files based on extension using os.path
39,888,494
<p>I was wondering how to search for files based on their extension. If you were to search for py or txt or some other extension, the user would input it and then it would search for it. I'm not allowed to use glob nor os.walk</p> <p>This is the method I have. If necessary, I'll post the whole code.</p> <p>The user f...
0
2016-10-06T05:54:20Z
39,888,621
<p>In your code,</p> <pre><code> for file in directory </code></pre> <p>is definitely wrong, as directory is a string with the path in it. it should be something like </p> <pre><code>for file in os.listdir(directory): </code></pre> <p>to get a list of files in the directory </p>
1
2016-10-06T06:03:15Z
[ "python", "os.path" ]
How can I draw a point with Canvas in Tkinter?
39,888,580
<p>I want to draw a point in Tkinter,Now I'm using <code>Canvas</code> to make it,but I didn't find such method to draw a point in <code>Canvas</code> class.<code>Canvas</code> provides a method called <code>crete_line(x1,y1,x2,y2)</code>,so i tried to set <code>x1=x2,y1=y2</code> to draw a point, but it doesn't work.<...
0
2016-10-06T06:00:44Z
39,890,145
<p>There is no method to directly put a point on <code>Canvas</code>. The method below shows points using <code>create_oval</code> method.</p> <p>Try this:</p> <pre><code>from Tkinter import * canvas_width = 500 canvas_height = 150 def paint(event): python_green = "#476042" x1, y1 = (event.x - 1), (event.y...
0
2016-10-06T07:34:13Z
[ "python", "canvas", "tkinter" ]
Print predicted column content for Naive Bayes
39,888,607
<pre><code>import warnings from sklearn.naive_bayes import GaussianNB import numpy as np import csv with open('/home/kk/Neha/demo1.csv', 'rb') as csvfile: lines = csv.reader(csvfile) for row in lines: print ', '.join(row) x = dataset[:,0:1] y = dataset[:,1] model = GaussianN...
-2
2016-10-06T06:02:29Z
39,888,717
<p>you need a map//list of the index to the associated values, and then </p> <pre><code>print "\n".join([index_to_value for marg_pred to predictions]) </code></pre>
0
2016-10-06T06:11:31Z
[ "python", "algorithm", "classification" ]
Not sure why my python output is looping
39,888,626
<p>I wrote a little bit of code to read a number in a file. Append it to a variable, then increment the number so the next time it runs the number in the file will be number +1. It looks like its working except it seems to increment twice.. For example here is my code :</p> <pre><code> 11 def mcIPNumber(): 12 ...
0
2016-10-06T06:03:39Z
39,888,649
<p>Because of this:</p> <pre><code> def makeNameMCTag(): NameNumber = mcIPNumber() </code></pre> <p>You are calling mcIPNumber from inside makeNameMCTag, so you don't excplicitly need to call that method in line 32.</p> <p>Alternatively</p> <pre><code>def make_name_mc_tag(name_number): NameTag = "varName" ...
5
2016-10-06T06:05:10Z
[ "python", "loops" ]
Quick way to find the duplicate cell in a certain column of data frame in python-pandas?
39,888,653
<p>Given a data frame <code>df</code> in the following form:</p> <pre><code>item attr 1 {1, 2, 3, 4} 2 {2, 4, 3, 2, 10} 3 {4, 37} 4 {1, 2, 3, 4} </code></pre> <p>I want to find the item-pair with same <code>attr</code>, like, <code>item 1</code> and <code>item 2</code>. ...
1
2016-10-06T06:05:18Z
39,888,926
<p>You can first convert <code>set</code> to <code>tuple</code> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.aggregate.html" rel="nofollow"><code>aggregate</code></a> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.n...
1
2016-10-06T06:25:05Z
[ "python", "pandas", "python-3.5" ]
Extract specific string part from HTML content with Regex
39,888,770
<p>I'm trying to extract with REGEX from the following string:</p> <p><code>&lt;tr class="data"&gt;&lt;td class="first"&gt;&lt;a href="en/clinics/al-khayal-medical-centre-6d15db1f.aspx"&gt;AL KHAYAL MEDICAL CENTRE&lt;/a&gt;&lt;/td&gt;&lt;td class="second not-responsive"&gt;&lt;a href="/portal/en/healthcare/clinics.asp...
-2
2016-10-06T06:15:29Z
39,888,858
<p>The modern way of doing this is to use something like BeautifulSoup. One does not try to process mark up using regular expressions anymore because the resulting code is unreadble and even the slightest change to the markup can break your beautifully crafted regular expression.</p> <pre><code>from bs4 import Beautif...
2
2016-10-06T06:20:21Z
[ "python", "regex", "python-2.7", "html-parsing" ]
Extract specific string part from HTML content with Regex
39,888,770
<p>I'm trying to extract with REGEX from the following string:</p> <p><code>&lt;tr class="data"&gt;&lt;td class="first"&gt;&lt;a href="en/clinics/al-khayal-medical-centre-6d15db1f.aspx"&gt;AL KHAYAL MEDICAL CENTRE&lt;/a&gt;&lt;/td&gt;&lt;td class="second not-responsive"&gt;&lt;a href="/portal/en/healthcare/clinics.asp...
-2
2016-10-06T06:15:29Z
39,888,890
<pre><code>import re html = ''' &lt;tr class="data"&gt;&lt;td class="first"&gt;&lt;a href="en/clinics/al-khayal- medical-centre-6d15db1f.aspx"&gt;AL KHAYAL MEDICAL CENTRE&lt;/a&gt;&lt;/td&gt; &lt;td class="second not-responsive"&gt;&lt;a href="/portal/en/healthcare/clinics.aspx?speciality=Urology"&gt;Urology&lt;...
0
2016-10-06T06:22:19Z
[ "python", "regex", "python-2.7", "html-parsing" ]
Python loop ask
39,888,809
<p>Can someone help me how do i display both food and drink if i answered yes?</p> <p>example:</p> <p>choose:1</p> <p>you have entered food</p> <p>Do you want to select another?(Y/N):y</p> <p>choose:2</p> <p>Do you want to select another?(Y/N):n</p> <p>selected:</p> <p>food</p> <p>drink</p> <p>thanks in advan...
0
2016-10-06T06:17:22Z
39,889,151
<pre><code>food = False drink = False answer="Y" while(answer=="Y"): print("1-food") print("2-drink") opt=int(input("Choose:")) if(opt==1): print("You have selected food") food = True if(op==2): print("You have selected drink"): drink...
0
2016-10-06T06:39:11Z
[ "python", "loops", "while-loop" ]
python writing list to text file result in different lengths
39,888,880
<p>i have 2 lists of strings with the same length but when i write them to a file where each item appear on separate lines in the file, they length of the list and file do not match:</p> <pre><code>print len(x) print len(y) 317858 317858 </code></pre> <p>However when i write each item in the list to a text file: the...
0
2016-10-06T06:21:39Z
39,889,049
<p>The only possible way for finding more lines in b.txt than the number of string written is that some of the strings in <code>y</code> actually contain new lines.</p> <p>Here is a small example</p> <pre><code>l = [ 'a', 'b\nc'] print len(l) with open('tst.txt', 'wb') as fd: for i in l: print &gt;&gt; fd...
0
2016-10-06T06:34:06Z
[ "python", "linux" ]
python writing list to text file result in different lengths
39,888,880
<p>i have 2 lists of strings with the same length but when i write them to a file where each item appear on separate lines in the file, they length of the list and file do not match:</p> <pre><code>print len(x) print len(y) 317858 317858 </code></pre> <p>However when i write each item in the list to a text file: the...
0
2016-10-06T06:21:39Z
39,889,136
<p>I'm sure others will quickly point out the cause of this difference (it's related to newline characters), but since you asked 'How can I debug this?' I'd like to address that question:</p> <p>Since the only difference between the passing and the failing run are the lists themselves, I'd concentrate on those. There ...
0
2016-10-06T06:38:24Z
[ "python", "linux" ]
ImportError: cannot import name _unquotepath
39,888,903
<p>I am trying to use scrapy for my project &amp; after some initial struggle i started with <a href="https://doc.scrapy.org/en/latest/intro/tutorial.html" rel="nofollow">https://doc.scrapy.org/en/latest/intro/tutorial.html</a> </p> <p>When i use :</p> <p><code>scrapy startproject tutorial</code></p> <p>It throws me...
0
2016-10-06T06:23:19Z
40,026,134
<p>Upgrading w3lib (to 1.15.0) solved the problem for me.</p>
0
2016-10-13T16:16:32Z
[ "python", "ubuntu", "scrapy" ]
Fastest way to concatenate multiple files column wise - Python
39,888,949
<p><strong>What is the fastest method to concatenate multiple files column wise (within Python)?</strong></p> <p>Assume that I have two files with 1,000,000,000 lines and ~200 UTF8 characters per line.</p> <p><strong>Method 1:</strong> Cheating with <code>paste</code></p> <p>I could concatenate the two files under a...
3
2016-10-06T06:26:08Z
39,892,264
<p>You can try to test your function with <code>timeit</code>. This <a href="https://docs.python.org/2/library/timeit.html" rel="nofollow">doc</a> could be helpful.</p> <p>Or the same magic function <code>%%timeit</code> in Jupyter notebook. You just need to write <code>%%timeit func(data)</code> and you will get a r...
-1
2016-10-06T09:24:27Z
[ "python", "shell", "text-files", "delimiter", "paste" ]
Fastest way to concatenate multiple files column wise - Python
39,888,949
<p><strong>What is the fastest method to concatenate multiple files column wise (within Python)?</strong></p> <p>Assume that I have two files with 1,000,000,000 lines and ~200 UTF8 characters per line.</p> <p><strong>Method 1:</strong> Cheating with <code>paste</code></p> <p>I could concatenate the two files under a...
3
2016-10-06T06:26:08Z
39,962,542
<p>You can replace the <code>for</code> loop with <code>writelines</code> by passing a genexp to it and replace <code>zip</code> with <code>izip</code> from <code>itertools</code> in method 2. This may come close to <code>paste</code> or surpass it.</p> <pre><code>with open(file1, 'rb') as fin1, open(file2, 'rb') as f...
1
2016-10-10T16:17:55Z
[ "python", "shell", "text-files", "delimiter", "paste" ]
Fastest way to concatenate multiple files column wise - Python
39,888,949
<p><strong>What is the fastest method to concatenate multiple files column wise (within Python)?</strong></p> <p>Assume that I have two files with 1,000,000,000 lines and ~200 UTF8 characters per line.</p> <p><strong>Method 1:</strong> Cheating with <code>paste</code></p> <p>I could concatenate the two files under a...
3
2016-10-06T06:26:08Z
40,003,693
<p>Method #1 is the fastest because it uses native (instead of Python) code to concatenate the files. However it is definitively cheating.</p> <p>If you want to cheat, you may also consider also writing your own C extension for Python - it may be even faster, depending on your coding skills.</p> <p>I am afraid Method...
-1
2016-10-12T16:26:55Z
[ "python", "shell", "text-files", "delimiter", "paste" ]
Fastest way to concatenate multiple files column wise - Python
39,888,949
<p><strong>What is the fastest method to concatenate multiple files column wise (within Python)?</strong></p> <p>Assume that I have two files with 1,000,000,000 lines and ~200 UTF8 characters per line.</p> <p><strong>Method 1:</strong> Cheating with <code>paste</code></p> <p>I could concatenate the two files under a...
3
2016-10-06T06:26:08Z
40,053,439
<p>From all four methods I'd take the second. But you have to take care of small details in the implementation. (with a few improvements it takes <em>0.002 seconds</em> meanwhile the original implementation takes about <em>6 seconds</em>; the file I was working was 1M rows; but there should not be too much difference...
1
2016-10-14T23:36:50Z
[ "python", "shell", "text-files", "delimiter", "paste" ]
Tkinter .withdraw() strange behaviour
39,889,105
<p>Using the following code, the Tkinter root window will be hidden: </p> <pre><code>def main(): root = Tkinter.Tk() root.iconify() a = open(tkFileDialog.askopenfilename(), 'r') main() </code></pre> <p>However, using this variation, the root window will not be hidden: </p> <pre><code>class Comparison: ...
0
2016-10-06T06:37:01Z
39,889,411
<p>When you do this:</p> <pre><code>def __init__(self, file=open(tkFileDialog.askopenfilename(),'r')): </code></pre> <p>That <em>immediately</em> runs <code>open(tkFileDialog.askopenfilename(),'r')</code>, because default arguments are evaluated when the function is defined. Therefore, when you run the second code bl...
2
2016-10-06T06:53:20Z
[ "python", "python-2.7", "tkinter" ]
How to pass the java parameter to python , Call Python code from Java
39,889,146
<p>I create simple python statement my_utils.py</p> <pre><code>def adder(a, b): c=a+b return c </code></pre> <p>I would like to assign value to python in Java.</p> <pre><code>public class ParameterPy { public static void main(String a[]){ try{ int number1 = 100; int number2 = 200; ProcessBuilder pb = new P...
0
2016-10-06T06:38:52Z
39,889,900
<p>The Python <code>sys</code> module provides access to any command-line arguments via the <code>sys.argv</code>. But the type of arguments is string always. Here is the example how I would like to check numeric values:</p> <pre><code>import sys print 'Number of arguments:', len(sys.argv), 'arguments.' print 'Argume...
1
2016-10-06T07:21:50Z
[ "java", "python", "parameter-passing", "processbuilder" ]
How to pass the java parameter to python , Call Python code from Java
39,889,146
<p>I create simple python statement my_utils.py</p> <pre><code>def adder(a, b): c=a+b return c </code></pre> <p>I would like to assign value to python in Java.</p> <pre><code>public class ParameterPy { public static void main(String a[]){ try{ int number1 = 100; int number2 = 200; ProcessBuilder pb = new P...
0
2016-10-06T06:38:52Z
39,892,057
<pre><code>import sys # print sys.argv print "sys.argv is:",sys.argv # ['D://my_utils.py', '100', '200', 'google'] a= sys.argv[1] b= sys.argv[2] print "a is:", a print "b is:", b a= int (a) b= int(b) def adder(a, b): c=a+b return c print adder(a,b) searchTerm=sys.argv[3] print searchTerm ##google def wor...
1
2016-10-06T09:13:25Z
[ "java", "python", "parameter-passing", "processbuilder" ]
Can tensorflow's mod operator match python's modulo implementation?
39,889,349
<p>Python's <code>%</code> operator always returns a number with the same sign as the divisor (second argument), for example:</p> <pre><code>-7.0 % 3.0 -&gt; 2.0 </code></pre> <p>However, Tensorflow's mod operator seems to be implemented slightly differently:</p> <pre><code>tf.mod(-7.0, 3.0).eval() -&gt; -1.0 </code...
0
2016-10-06T06:50:24Z
39,907,847
<p>Interesting finding. Maybe worth filing a github issue here: <a href="https://github.com/tensorflow/tensorflow/issues" rel="nofollow">https://github.com/tensorflow/tensorflow/issues</a></p> <p>For a workaround, I think you can use this line:</p> <pre><code>mod_tf = tf.cond(mod_tf &lt; 0, lambda: mod_tf+v_div, lamb...
0
2016-10-07T01:02:57Z
[ "python", "tensorflow" ]
Can tensorflow's mod operator match python's modulo implementation?
39,889,349
<p>Python's <code>%</code> operator always returns a number with the same sign as the divisor (second argument), for example:</p> <pre><code>-7.0 % 3.0 -&gt; 2.0 </code></pre> <p>However, Tensorflow's mod operator seems to be implemented slightly differently:</p> <pre><code>tf.mod(-7.0, 3.0).eval() -&gt; -1.0 </code...
0
2016-10-06T06:50:24Z
39,914,691
<p>Here's another solution. It adds the divisor to the result of the first modulo, then does modulo again.</p> <pre><code>def positive_mod(val, div): # Return the positive result of the modulo operator. # Does x = ((v % div) + div) % div return tf.mod(tf.add(tf.mod(val, div), div), div) </code></pre>
0
2016-10-07T10:07:19Z
[ "python", "tensorflow" ]
How to download the same file twice? (urlretrieve issue)
39,889,389
<p>Python 2.7.</p> <pre><code>from urllib import urlretrieve urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file1") urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file2") </code></pre> <p>The first download goes correctly but the seco...
0
2016-10-06T06:52:12Z
39,889,508
<p>From the documentation for <a href="https://docs.python.org/2/library/urllib.html#urllib.urlretrieve" rel="nofollow">urlretrieve for Python2</a>:</p> <p><code>If the URL points to a local file, or a valid cached copy of the object exists, the object is not copied</code></p> <p>so the first impression is that the l...
0
2016-10-06T07:00:04Z
[ "python", "python-2.7" ]
How to download the same file twice? (urlretrieve issue)
39,889,389
<p>Python 2.7.</p> <pre><code>from urllib import urlretrieve urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file1") urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file2") </code></pre> <p>The first download goes correctly but the seco...
0
2016-10-06T06:52:12Z
39,900,735
<p>Unfortunately,urlretrieve has something wrong in Python2.7. Called urlretrieve repeatedly works by HTTP, not by FTP in Python2.7. The reason is ftplib sends PASV by ftplib again and again. Fortunately,we can call urlcleanup before urlretrieve when download file by ftp. And the documentation is <a href="https://docs....
0
2016-10-06T16:02:40Z
[ "python", "python-2.7" ]
how to make connection from node js to python?
39,889,395
<p>I am new to node js and python just i want to communicate node js to python and vice versa. I need simple script that runs and host on web browser to get executed python script in node js. Just wan to transfer one message from node js to python using after running node js script with hosted envirnoment.</p>
0
2016-10-06T06:52:46Z
39,889,710
<p>You need to execute python code from nodejs using system call.</p> <pre><code>var exec = require('child_process').exec; var cmd = 'python myscript.py'; exec(cmd, function(error, stdout, stderr) { // command output is in stdout (This the output from the python script that you might use }); </code></pre>
1
2016-10-06T07:11:31Z
[ "python", "node.js" ]
Ways to filter files in directory and join directory path - Python
39,889,516
<p>Given a suffix and a directory path, I need to extract the full path of the files in the directory that ends with a given suffix.</p> <p>Currently, I'm doing it as such:</p> <pre><code>import os dir_path = '/path/to/dir' suffix = '.xyz' filenames = filter(lambda x: x.endswith(suffix), os.listdir(dir_path)) filenam...
0
2016-10-06T07:00:42Z
39,889,726
<p>You can use a <a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow"><code>list comprehension</code></a> to build the result in one go:</p> <pre><code>&gt;&gt;&gt; [os.path.join(os.sep, x, dir_path) for x in os.listdir(dir_path) if x.endswith(suffix)] ['/home/msvalkon/f...
1
2016-10-06T07:12:35Z
[ "python", "operating-system", "filepath", "glob", "listdir" ]
Django app defaults?
39,889,529
<p>I'm looking for a way to have application defaults and settings that are easy to use, difficult to get wrong, and have little overhead..</p> <p>Currently I have it organized as follows:</p> <pre><code>myapp/defaults.py # application defaults import sys if sys.platform == 'win32': MYAPP_HOME_RO...
1
2016-10-06T07:01:16Z
39,889,790
<blockquote> <p>Problem #1: When running unit tests for the app there is no site however, so settings wouldn't have any of the myapp.defaults.</p> </blockquote> <p>This problem is solved by using the testing framework that comes with django (see <a href="https://docs.djangoproject.com/en/1.10/topics/testing/overvi...
2
2016-10-06T07:15:53Z
[ "python", "django" ]
Slicing or aggregating data frame based on certain conditions
39,889,635
<p>I have a dataset which contains latitude and longitudes. I want to take those rows in data set where distance is less than 1 km. For entire distance calculation part I have written a function which will return true or false. So I want to consider those rows on which this condition is applied.</p> <p>It may be throu...
0
2016-10-06T07:07:45Z
39,890,896
<p>Can you give more information about your dataset? Does he contain two columns, one for lat and one for long?</p> <p>If you want to apply your func to the dataset you can use <code>map</code> Somth like this:</p> <pre><code>func = lambda x: x &gt; 0 data = [1, -1, 3, -2] result = list(map(func, dataset)) </code></p...
0
2016-10-06T08:15:19Z
[ "python", "python-3.x", "lambda", "aggregate" ]
Loop of function for taking multiple audio files from a directory
39,889,680
<p>I am currently taking input from a directory, for a single audio file and I am saving my output in CSV file, with the file name and converted speech to text output but I have 100 files in that directory (i.e 001.wav,002.wav,003.wav..........100.wav)</p> <p>I want to write a loop or function which saves the speech t...
0
2016-10-06T07:09:46Z
39,891,310
<p>You can get all files of a directory and subdirectory with <code>os.walk</code>, which I have included in the <code>get_file_paths()</code> in the code below, here is an example:</p> <pre><code>import speech_recognition as sr import csv import os DIRNAME = r'c:\path\to\directory' OUTPUTFILE = r'c:\path\to\outputf...
1
2016-10-06T08:35:25Z
[ "python", "python-2.7", "python-3.x" ]
Looking for a way to adjust the values of one array based on another array?
39,889,689
<p>I started with a set of bivariate data. My goal is to first find points in that data set for which the y-values are outliers. Then, I wanted to create a new data set that included not only the outlier points, but also any points with an x-value of within 0.01 of any given outlier point.</p> <p>Then (if possible) I ...
1
2016-10-06T07:10:03Z
39,892,419
<p>Once you have the set with y-outliers values and the set with the expanded values, you can go over the whole second set with a for loop and subtract the corresponding 1st set value using 2 <code>For()</code> loops:</p> <pre><code>import numpy as np x =np.array([0,0.994,0.995,0.996,0.997,0.998,1.134,1.245,1.459,1.4...
0
2016-10-06T09:31:29Z
[ "python", "arrays", "numpy", "indexing" ]
Looking for a way to adjust the values of one array based on another array?
39,889,689
<p>I started with a set of bivariate data. My goal is to first find points in that data set for which the y-values are outliers. Then, I wanted to create a new data set that included not only the outlier points, but also any points with an x-value of within 0.01 of any given outlier point.</p> <p>Then (if possible) I ...
1
2016-10-06T07:10:03Z
39,892,452
<p>Let's see if I understood you correctly. This code should find the outliers, and put an array into res for each outlier.</p> <pre><code>import numpy as np mean = np.mean(y) SD = np.std(y) x = np.array([0,0.994,0.995,0.996,0.997,0.998,1.134,1.245,1.459,1.499,1.500,1.501,2.103,2.104,2.105,2.106]) y = np.array([1.5,...
0
2016-10-06T09:32:59Z
[ "python", "arrays", "numpy", "indexing" ]
Kivy - Is there any way to bind Python functions to Widgets created in the kv language?
39,889,786
<p>I am trying to create a simple Pokemon battle simulator. A trainer has 6 Pokémon, stored in a list. I have labels in the .kv file displaying the desired information.<br> My problem is that if I have the text property of the labels set to a Python variable:</p> <pre><code>text: '{}/{}'.format(root.pokemon.stats['cH...
2
2016-10-06T07:15:37Z
39,890,598
<p>the <em>kv lang</em> will auto-bind properties that are declared in it, so can you send the stats to your function and the binding will occur :)</p> <pre><code>text: root.pokemon.getHP(root.pokemon.stats) </code></pre> <p>Each time that <strong>stats</strong> is changed, the function will be called.</p>
0
2016-10-06T07:58:02Z
[ "python", "kivy", "kivy-language" ]
Extract data from login authentication website using scrapy
39,889,986
<p>I am trying to login first and then extract data from pages which are visible after login. my spider is- </p> <pre><code>import scrapy from scrapy.selector import HtmlXPathSelector from scrapy.http.request import Request from scrapy.spiders import BaseSpider from scrapy.http import FormRequest from loginform import...
0
2016-10-06T07:26:43Z
39,890,275
<p>You haven't created an instance of your class <code>ElementSpider</code>.<br> You first need to create an instance of the class.<br><br> <strong>NOTICE</strong><br> Every class should have a constructor, Therefor it is recommended you should implement the <code>__init__</code> method in your class.<br></p> <p>This ...
0
2016-10-06T07:40:50Z
[ "python", "scrapy", "web-crawler" ]
Python: ImportError: No module named 'tutorial.quickstart'
39,890,020
<p>I am getting import error even when I am following the tutorial <a href="http://www.django-rest-framework.org/tutorial/quickstart/" rel="nofollow">http://www.django-rest-framework.org/tutorial/quickstart/</a> line by line.</p> <pre><code>from tutorial.quickstart import views </code></pre> <blockquote> <p>Import...
0
2016-10-06T07:28:13Z
39,891,590
<p>Make sure your tutorial.quickstart is in the same folder as your project. Also make sure it is unzipped ! Otherwise use a absolute path.</p> <p>Hope it helps !</p>
0
2016-10-06T08:49:51Z
[ "python", "django", "python-3.x" ]
Keras uses way too much GPU memory when calling train_on_batch, fit, etc
39,890,147
<p>I've been messing with Keras, and like it so far. There's one big issue I have been having, when working with fairly deep networks: When calling model.train_on_batch, or model.fit etc., Keras allocates significantly more GPU memory than what the model itself should need. This is not caused by trying to train on some...
4
2016-10-06T07:34:16Z
39,890,190
<p>It is a very common mistake to forget that the activations also take vram, not just the parameters. This takes the required vram multiple times higher than your calculation (at the very least by a <code>minibatch_size</code> factor.</p> <p>So, in the beginning when the network is created, only the parameters are al...
1
2016-10-06T07:36:41Z
[ "python", "memory", "tensorflow", "theano", "keras" ]
UnboundLocalError: local variable 'restaurantToDelete' referenced before assignment Flask app
39,890,182
<p>When I try to delete an item from the database in a Flask view, the following error is shown</p> <pre><code>UnboundLocalError: local variable 'restaurantToDelete' referenced before assignment </code></pre> <pre><code>@app.route('/restaurant/&lt;int:restaurant_id&gt;/delete',methods=['GET','POST']) def deleteRest...
0
2016-10-06T07:36:28Z
39,890,245
<p>Look at the else, at that point restaurantToDelete isn't defined, your code should be something like</p> <pre><code>@app.route('/restaurant/&lt;int:restaurant_id&gt;/delete',methods=['GET','POST']) def deleteRestaurant(restaurant_id): restaurantToDelete=session.query(Restaurant).filter_by(id=restaurant_id).one(...
1
2016-10-06T07:39:20Z
[ "python", "flask", "sqlalchemy" ]
UnboundLocalError: local variable 'restaurantToDelete' referenced before assignment Flask app
39,890,182
<p>When I try to delete an item from the database in a Flask view, the following error is shown</p> <pre><code>UnboundLocalError: local variable 'restaurantToDelete' referenced before assignment </code></pre> <pre><code>@app.route('/restaurant/&lt;int:restaurant_id&gt;/delete',methods=['GET','POST']) def deleteRest...
0
2016-10-06T07:36:28Z
39,890,253
<p>You're defining the variable <code>restaurantToDelete</code> inside an <code>if</code>-block, and then you try to use it inside the <code>else</code>-block. If the <code>request.method</code> is not <code>POST</code>, the variable does not exist, because your code does not enter the <code>if</code>-block. You can fi...
1
2016-10-06T07:39:32Z
[ "python", "flask", "sqlalchemy" ]
Python XML modifying by ElementTree destroys the XML structure
39,890,217
<p>I am using Python V 3.5.1 on windows framework in order to modify a text inside , the modification works great but after saving the tree all the empty tags get destroyed as the following example:</p> <pre><code>&lt;HOSTNAME&gt;&lt;/HOSTNAME&gt; Is being changed to &lt;HOSTNAME /&gt; </code></pre> <p>child with a t...
-1
2016-10-06T07:37:54Z
39,891,805
<p>OK, i found the solution - just adding method = "html" to the tree.write line it keeps it as needed.</p> <pre><code>tree.write(AccountsFile,method = 'html') </code></pre> <p>Thanks.</p>
0
2016-10-06T09:00:06Z
[ "python", "xml", "elementtree" ]
python Get HTML from JS using selenium
39,890,353
<p>I'm trying to get the div HTML from <a href="https://www.workday.com/en-us/company/careers/open-positions.html#?q=" rel="nofollow">https://www.workday.com/en-us/company/careers/open-positions.html#?q=</a>.</p> <p>But the div listing job posts is loaded from <code>granite.min.js</code> based on network XHR.</p> <pr...
-2
2016-10-06T07:44:55Z
39,902,136
<p>Ok, so your code has a couple of problems.</p> <p>a) you need to wait for the <code>template-content</code> div to load its content. In the code bellow I use <a href="http://selenium-python.readthedocs.io/waits.html" rel="nofollow"><code>implicitly_wait</code></a> to wait 30 seconds. <br> b) <code>find_element_by_i...
1
2016-10-06T17:21:51Z
[ "javascript", "python", "selenium" ]
Pandas fuzzy group summary statistics
39,890,417
<p>I have a data frame defined from a CSV and would like to calculate basic summary statistics e.g. mean, variance, ... for the train part of all the models.</p> <p>Inserting a model number and grouping by that would work fine - but does not seem to be a good solution. <strong>How can I get the summary statistics per ...
1
2016-10-06T07:48:25Z
39,890,470
<p>IIUC you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.describe.html" rel="nofollow"><code>DataFrameGroupBy.describe</code></a>:</p> <pre><code>print (df.groupby(['modelName', 'typeOfRun']).describe()) f1_R ...
1
2016-10-06T07:50:54Z
[ "python", "pandas", "group-by", "summary" ]
numba argument argtypes deprecated keyword
39,890,420
<p>When i type following code :</p> <pre><code>mandel_numba = numba.jit(restype=uint32, argtypes=[float32, float32, uint32])(mandel) </code></pre> <p>and get error message </p> <pre><code> raise DeprecationError(_msg_deprecated_signature_arg.format('argtypes')) numba.errors.DeprecationError: Deprecated keyword argum...
1
2016-10-06T07:48:40Z
39,890,760
<p>The error message is telling you what it expects</p> <pre><code>Signatures should be passed as the first positional argument. </code></pre> <p>So instead of</p> <pre><code>numba.jit(restype=uint32, argtypes=[float32, float32, uint32]) </code></pre> <p>They should be positional</p> <pre><code>numba.jit(uint32(fl...
2
2016-10-06T08:06:31Z
[ "python", "numba" ]
range filter not working in django
39,890,447
<p>I want to filter my queryset on the basis of two values.</p> <p>I want result between two numbers.I am trying some code but it is not working .It did not return me proper result. my code</p> <pre><code>def project(request): try: proTitle = request.GET.get('title') ProDescription = request.GET....
1
2016-10-06T07:49:52Z
39,893,326
<p>In python when you use <code>range</code> it means <code>range1 &lt;= i &lt; range2</code>, but the filter you are looking for your query is <code>range1 &lt;= i &lt;= range2</code>, so you should not look forward <code>range</code> instead go </p> <pre><code> result = Project.objects.filter(budgeted_cost__gte=cos...
0
2016-10-06T10:14:57Z
[ "python", "django" ]
AppEngine docs recommend command-line flags instead of app.yaml file elements
39,890,593
<p>In the <a href="https://cloud.google.com/appengine/docs/python/config/appref" rel="nofollow">app.yaml</a> documentation, Google makes the following recommendation of number of times:</p> <blockquote> <p>"The recommended approach is to remove the <strong>ELEMENT NAME</strong> [e.g. <code>application</code>] from y...
4
2016-10-06T07:57:20Z
39,949,231
<p>I think mainly because they are slowly moving away from the <code>appcfg.py</code>, to start using the <a href="https://cloud.google.com/sdk/" rel="nofollow">Cloud SDK</a> instead, where <code>application</code> is not supported. You can set your default application so you won't need to use command line all the time...
1
2016-10-09T22:36:51Z
[ "python", "google-app-engine", "documentation", "app.yaml" ]
Django export filtered query to csv
39,890,594
<p>So the scenario is this: I have a search form where the user types or selects the criteria. These criteria are being posted and I get a query in returned, filtered with these criteria. The code for the search form is similar to the code shown below. </p> <p>What I want to do now is take these results and export th...
1
2016-10-06T07:57:26Z
39,890,967
<p>Youre seeing only one row because youre passing only one row:</p> <pre><code>for field in results: field_list = [ field.filed_1, field.field_2, field.field_3, field.field_4, ] </code></pre> <p>The above puts only the item from the last iteration in <code>field_list</code> and the prev...
0
2016-10-06T08:18:34Z
[ "python", "django", "csv" ]
Accessing a path which case sensitive without writing so
39,890,750
<p>I would like to know whether it possible to access linux path like: <code>/home/dan/CaseSensitivE/test.txt</code></p> <p>In a way we write it as <code>/home/dan/casesensitive/test.txt</code> and it goes to the right place, means python consider paths as not case sensitive and allow entering them that way, although ...
0
2016-10-06T08:06:11Z
39,891,399
<p>As Klaus said, the simple answer is no. You could, however, take a more laborious route, and enumerate all folders/files in your top directory (<code>os.path, glob</code>), convert to lower case (<code>string.lower</code>), test equality, step one level down, etc.</p> <p>This works for me:</p> <pre><code>import os...
1
2016-10-06T08:40:05Z
[ "python", "python-2.7" ]
google cloud machine learning hyperparameter tuning avoid Nans
39,890,785
<p>I am running google cloud machine learning beta - and use the hypertune setup with tensorflow.</p> <p>In some of the sub runs of hyperparameter tuning I have losses becoming NaNs - and that crashes the computations - which in turns stop the hyperparameter tuning job. </p> <pre><code>Error reported to Coordinator: ...
2
2016-10-06T08:08:00Z
39,901,926
<p>You should protect the loss function by checking for NaNs. Any crash or exception thrown by the program is treated by Cloud ML as a failure of the trial, and if enough trials fail the entire job will be failed.</p> <p>If the trial exits cleanly without setting any hyperparameter summaries, the trial will be consid...
1
2016-10-06T17:09:06Z
[ "python", "machine-learning", "tensorflow", "google-cloud-ml" ]