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
Why can't Python request lib replicate this Ajax call?
38,986,403
<p><strong>Short version:</strong> This Python request doesn't work. The Javascript version does. Why? </p> <pre><code>import json import requests url = 'https://inputtools.google.com/request?itc=ja-t-i0-handwrit&amp;app=demopage' data = '{"app_version":0.4,"api_level":"537.36","device":"Mozilla/5.0 (Windows NT 6.1; ...
0
2016-08-17T00:28:00Z
39,010,456
<p>The line <code>json=data</code> should have been <code>data=data</code>. The json attribute accepts a dictionary, which that <code>data</code> string is not. Here is what working code looks like:</p> <pre><code>import json import requests url = 'https://inputtools.google.com/request?itc=ja-t-i0-handwrit&amp;app=dem...
0
2016-08-18T05:18:21Z
[ "python", "ajax", "request" ]
Pandas: resample time group names after a dataframe groupby
38,986,427
<p>My dataframe looks like</p> <pre><code>Time, Id A B C 2016-06-15 08:09:26.212962 115516 3 3.238 7.790000 2016-06-15 08:10:13.863304 115517 ...
1
2016-08-17T00:31:13Z
38,986,732
<p>Simplest way is to form them into another DataFrame. Use <code>pd.concat</code></p> <pre><code>frames, names = [], [] grouped = df.groupby(pd.TimeGrouper("5Min"), as_index=False) for name, group in grouped: names.extend([name]) frames.extend([group]) pd.concat(frames, keys=names) </code></pre>
0
2016-08-17T01:16:02Z
[ "python", "pandas", "dataframe", "time-series" ]
Pandas: resample time group names after a dataframe groupby
38,986,427
<p>My dataframe looks like</p> <pre><code>Time, Id A B C 2016-06-15 08:09:26.212962 115516 3 3.238 7.790000 2016-06-15 08:10:13.863304 115517 ...
1
2016-08-17T00:31:13Z
38,989,448
<p>This is the best I could come up with for now.</p> <pre><code>df.set_index('Time').groupby(pd.TimeGrouper('5T')) \ .apply(lambda df: df.reset_index()).unstack() \ .resample('5T').last().stack(dropna=False) </code></pre>
0
2016-08-17T06:25:13Z
[ "python", "pandas", "dataframe", "time-series" ]
Django logout function is not working
38,986,470
<p>I'm using the Django login and logout functions, the login function works, but the logout is not working.</p> <p>In my HTML file, I have:</p> <pre><code>&lt;a href="{% url 'django.contrib.auth.views.logout' %}"&gt;logout&lt;/a&gt; &lt;a href="{% url 'django.contrib.auth.views.login' %}"&gt;login&lt;/a&gt; </code><...
0
2016-08-17T00:37:17Z
38,987,984
<p>Try this:</p> <pre><code>{% if request.user.is_authenticated %} Hello {{ request.user.username }}. {% else %} Hello Guest {% endif %} </code></pre>
1
2016-08-17T04:10:01Z
[ "python", "django" ]
Django logout function is not working
38,986,470
<p>I'm using the Django login and logout functions, the login function works, but the logout is not working.</p> <p>In my HTML file, I have:</p> <pre><code>&lt;a href="{% url 'django.contrib.auth.views.logout' %}"&gt;logout&lt;/a&gt; &lt;a href="{% url 'django.contrib.auth.views.login' %}"&gt;login&lt;/a&gt; </code><...
0
2016-08-17T00:37:17Z
38,988,037
<p>There are a couple of issues here. </p> <p>Firstly, you have exactly the same URL pattern (<code>'^$'</code>) for both login and logout views. This means that the second (logout) pattern will never actually be used because the first one always matches. When you try to log out, the first view that matches is the log...
2
2016-08-17T04:16:29Z
[ "python", "django" ]
Program not terminating when score limit is reached?
38,986,525
<p>I'm working on a simple text-based trivia game as my first python project, and my program won't terminate once the score limit is reached.</p> <pre><code>def game(quest_list): points = 0 score_limit = 20 x, y = info() time.sleep(2) if y &gt;= 18 and y &lt; 100: time.sleep(1) wh...
1
2016-08-17T00:45:21Z
38,986,607
<p>It looks like the <code>points</code> variable is not increased. Something like this might work in your inner loop:</p> <pre><code> while points &lt; score_limit: points = random.choice(quest_list)(points) time.sleep(2) print("Current score:", points, "points") </code></pre> <p>I'm assum...
2
2016-08-17T00:58:13Z
[ "python" ]
Sunrise and Sunset time in Python
38,986,527
<p>I'm currently working on a IoT project using NanoPi M1 and it's expected to notify the users when the amount of light received is not adequate during the day time. I've done the part related to light. Hence, I need to find an effective way to retrieve sunrise and sunset time in python, since the whole script is writ...
2
2016-08-17T00:45:38Z
38,986,561
<p>Check out <a href="https://pypi.python.org/pypi/astral/1.2" rel="nofollow">astral</a>. Here's a slightly modified <a href="http://pythonhosted.org/astral/#example" rel="nofollow">example from their docs</a>:</p> <pre><code>&gt;&gt;&gt; from astral import Astral &gt;&gt;&gt; city_name = 'London' &gt;&gt;&gt; a = Ast...
3
2016-08-17T00:50:39Z
[ "python", "datetime", "time", "raspberry-pi" ]
Making python code more efficient
38,986,567
<p>I have the code</p> <pre><code>num = 1 num2 = 1 num3 = 1 list = [] list2 = [] list3 = [] def numCheck1 (num): while num&lt;1001: if (num%3==0): if (num%5==0): print num list.append(num) num+=1 numCheck1(num) bre...
0
2016-08-17T00:51:21Z
38,986,596
<p><code>numCheck1</code>: Since <em>all</em> multiples of 3 and 5 are <em>also</em> multiples of 15, you can simply print out each item in <code>range(0, 1001, 15)</code> (counts by 15)</p> <p><code>numCheck2</code>: <code>range(0, 1001, 5)</code> (counts by 5) should already be all multiples of 5 less than or equal ...
1
2016-08-17T00:57:07Z
[ "python", "performance" ]
Making python code more efficient
38,986,567
<p>I have the code</p> <pre><code>num = 1 num2 = 1 num3 = 1 list = [] list2 = [] list3 = [] def numCheck1 (num): while num&lt;1001: if (num%3==0): if (num%5==0): print num list.append(num) num+=1 numCheck1(num) bre...
0
2016-08-17T00:51:21Z
38,986,717
<p>I've re-written your code, with comments in-line. You could improve things even more over this, but I think seeing where you could improve this code will be helpful for you.</p> <pre><code># If you use this, it should be the first line # in your code. If you're using Python2, you *should* # use this, because it wil...
2
2016-08-17T01:13:36Z
[ "python", "performance" ]
How to transform user input string into correct object type
38,986,720
<p>I am using Python (2.7) along with Natural Language Toolkit (3.2.1) and WordNet. I am <em>very</em> new to programming.</p> <p>I am trying to write a program which asks the user for a word, then prints synonym sets for that word, then asks the user which synonym set it wants to see the lemmas for.</p> <p>The probl...
3
2016-08-17T01:14:09Z
38,988,026
<p>Try this:</p> <pre><code>from nltk.corpus import wordnet as wn w1 = raw_input ("What is the word? ") synset_dict = dict() for synset in wn.synsets(w1): name = synset.name() synset_dict[name] = synset print name synset1 = raw_input ("Which sense are you looking for? [Use same format as above] ") if s...
0
2016-08-17T04:15:20Z
[ "python", "nltk", "wordnet" ]
"Counting digits" on numbers input by user (Python 2.x)
38,986,721
<p>Please bear with my novice question as I just started learning Python (2.x). I'm trying to run a script where user could enter any number (e.g. ints or float) and the expected output would be the total digit numbers of that input number.</p> <p>However, I've encountered the following problems and wondered if you co...
2
2016-08-17T01:14:42Z
38,986,804
<p><code>n</code> is always going to be zero because you have this line:</p> <pre><code>while n: </code></pre> <p>It can never exit that loop without becoming a False-y value. If you want to keep the original value, either operate on a copy, or store the original value:</p> <pre><code>def num_digits(n): original...
0
2016-08-17T01:27:36Z
[ "python", "python-2.7" ]
"Counting digits" on numbers input by user (Python 2.x)
38,986,721
<p>Please bear with my novice question as I just started learning Python (2.x). I'm trying to run a script where user could enter any number (e.g. ints or float) and the expected output would be the total digit numbers of that input number.</p> <p>However, I've encountered the following problems and wondered if you co...
2
2016-08-17T01:14:42Z
38,986,830
<p>Since you also want to be able to count the digits of floats, simply doing <code>n/10</code> isn't enough. With float values, your loop will end up being infinite, since it will be doing float division instead of int division. (Ex. <code>16.3 / 10 = 1.63</code> --> <code>1.63 / 10 = .163</code> etc -- it will never ...
0
2016-08-17T01:32:24Z
[ "python", "python-2.7" ]
"Counting digits" on numbers input by user (Python 2.x)
38,986,721
<p>Please bear with my novice question as I just started learning Python (2.x). I'm trying to run a script where user could enter any number (e.g. ints or float) and the expected output would be the total digit numbers of that input number.</p> <p>However, I've encountered the following problems and wondered if you co...
2
2016-08-17T01:14:42Z
38,986,970
<p>Another answers have already explaine your bug. Anyway, here's a couple of other options for you to take a look &amp; understand:</p> <pre><code>def num_digits1(n): return len(str(n).replace(".", "").replace("-", "")) def num_digits2(n): return sum(c.isdigit() for c in str(n)) for v in [-1.0, 0, 00, 000,...
1
2016-08-17T01:53:12Z
[ "python", "python-2.7" ]
"Counting digits" on numbers input by user (Python 2.x)
38,986,721
<p>Please bear with my novice question as I just started learning Python (2.x). I'm trying to run a script where user could enter any number (e.g. ints or float) and the expected output would be the total digit numbers of that input number.</p> <p>However, I've encountered the following problems and wondered if you co...
2
2016-08-17T01:14:42Z
38,987,002
<p>This should do everything you asked. Feel free to comment any questions</p> <pre><code>def num_digits(): while True: n = raw_input('Enter a number:\n') try: float(n) if '.' and '-' in n: print len(n) - 2 elif '.' in n or '-' in n: ...
0
2016-08-17T01:58:57Z
[ "python", "python-2.7" ]
Understanding inheritance with python classes
38,986,722
<p>so I am trying to understand how to build child classes in python.</p> <p>So ive created a perent and a child class but I just cant understand how to get them to work</p> <p>so this is my current code</p> <pre><code>from abc import ABCMeta, abstractmethod class Persion(object): __metaclass__ = ABCMeta # sets...
1
2016-08-17T01:14:43Z
38,986,788
<p>There are <strong>three main problems</strong> with your code:</p> <ol> <li><p>Change <code>__int__</code> to <code>__init__</code>. Your instance isn't getting initialized, which is why you get the <code>no attribute 'speed'</code> error.</p></li> <li><p>Your subclass (the class that's inheriting, which in this ca...
2
2016-08-17T01:24:33Z
[ "python", "class" ]
Why won't my kv BoxLayout centre horizontally?
38,986,793
<p>This is my test.kv file:</p> <pre><code>BoxLayout: BoxLayout: orientation: 'vertical' size_hint: None, None height: '160sp' width: '380sp' pos_hint: {'center_x': .5, 'center_y': .5} BoxLayout: Label: text: 'UserName' TextInp...
0
2016-08-17T01:25:42Z
38,986,842
<p>Ahh, silly Mike. I just re-read the docs for the 100th time and it was staring me right in the face.</p> <p>pos_hint is not used by all layouts!</p> <p>From FloatLayout docs: FloatLayout honors the pos_hint and the size_hint properties of its children.</p> <p>Changed my test.kv file so outer BoxLayout is now a Fl...
1
2016-08-17T01:33:31Z
[ "python", "kivy" ]
When import Theano, I got exception: "dot.exe" not found in path
38,986,821
<p>I am running python on Anaconda. I downloaded the Theano from "<a href="https://github.com/Theano/Theano.git" rel="nofollow">https://github.com/Theano/Theano.git</a>" and installed it by running </p> <pre><code>cd Theano python setup.py develop </code></pre> <p>However, when I tried to import the theano on Ipython...
0
2016-08-17T01:30:51Z
38,987,596
<p>Seems like you are running anaconda in windows. When installing <code>Theano</code> in a windows machines sometimes there are some issues.</p> <p><a href="http://rosinality.ncity.net/doku.php?id=python:installing_theano" rel="nofollow">Here</a> you can see a good way to install theano in windows machines. If you ha...
0
2016-08-17T03:21:52Z
[ "python", "theano" ]
Convert js function to python functions does't work
38,986,824
<p>I have found an algorithm written in js (That I don't know how to code with) then I tried to convert it to python after a conversation with some friends who know js<br /> <strong>Javascript</strong></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="sni...
0
2016-08-17T01:31:28Z
38,986,857
<p>No. It's not the same code.</p> <pre><code>for(var i = 0; i &lt; code.length; i++) { if(i%2 == 0) { </code></pre> <p>is NOT the same as</p> <pre><code>for letter in code: i =code.find(letter) if i%2 == 0: </code></pre> <p>What happens if all letters in the code is the same?</p> <p>I didn't look furt...
2
2016-08-17T01:36:01Z
[ "javascript", "python", "algorithm", "base64", "swap" ]
Convert js function to python functions does't work
38,986,824
<p>I have found an algorithm written in js (That I don't know how to code with) then I tried to convert it to python after a conversation with some friends who know js<br /> <strong>Javascript</strong></p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="sni...
0
2016-08-17T01:31:28Z
38,986,944
<p>You are searching for the first occurrence of letter in the code, in the line <code>i =code.find(letter)</code>. As you want the index, I recommend using <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow">enumerate</a></p> <p>Result:</p> <pre class="lang-py prettyprint-override"><c...
0
2016-08-17T01:49:02Z
[ "javascript", "python", "algorithm", "base64", "swap" ]
__init__ : Inheriting __init__ parameter (dict) to another class's __init__ method?
38,986,838
<p>I am confused even after checking many questions asked in SO. I have 2 different class (2 different script) &amp; I want to inherit super class's <code>__init__</code> method's parameters.</p> <p>script1.py</p> <pre><code>class MainClass(): def __init__(self,params): self.one=params['ONE'] self...
0
2016-08-17T01:33:17Z
38,987,560
<p>Is this what you need?</p> <p><strong>script1.py</strong></p> <pre><code>class MainClass(): def __init__(self,params): # Save params for use by a self.params = params self.one=params['ONE'] self.two=params['TWO'] ... self.five=params['FIVE'] def a(): ...
0
2016-08-17T03:18:43Z
[ "python", "python-2.7", "class", "oop", "inheritance" ]
__init__ : Inheriting __init__ parameter (dict) to another class's __init__ method?
38,986,838
<p>I am confused even after checking many questions asked in SO. I have 2 different class (2 different script) &amp; I want to inherit super class's <code>__init__</code> method's parameters.</p> <p>script1.py</p> <pre><code>class MainClass(): def __init__(self,params): self.one=params['ONE'] self...
0
2016-08-17T01:33:17Z
38,987,585
<p>You can pass any and all the non-keyword arguments from the subclass's <code>__init__()</code>to the superclass's like this:</p> <pre><code>class SubClass(SuperClass): def __init__(self, *params): MainClass.__init__(self, *params) ... </code></pre> <p>This same idea will work for other methods,...
0
2016-08-17T03:20:43Z
[ "python", "python-2.7", "class", "oop", "inheritance" ]
string substitution using regex
38,986,841
<p>I have this string in python </p> <pre><code>a = "haha" result = "hh" </code></pre> <p>What i would like to achieve is using regex to replace all occurrences of "aha" to "h" and all "oho" to "h" and all "ehe" to "h"</p> <p>"h" is just an example. Basically, i would like to retain the centre character. In other ...
0
2016-08-17T01:33:30Z
38,986,903
<p>What about <code>re.sub(r'[aeo]h[aeo]','h',a)</code> ?</p>
1
2016-08-17T01:42:53Z
[ "python", "regex" ]
string substitution using regex
38,986,841
<p>I have this string in python </p> <pre><code>a = "haha" result = "hh" </code></pre> <p>What i would like to achieve is using regex to replace all occurrences of "aha" to "h" and all "oho" to "h" and all "ehe" to "h"</p> <p>"h" is just an example. Basically, i would like to retain the centre character. In other ...
0
2016-08-17T01:33:30Z
38,986,904
<p>You can use <a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow"><code>re.sub</code></a>:</p> <pre><code>import re print re.sub('aha|oho|ehe', 'h', 'haha') # hh print re.sub('aha|oho|ehe', 'h', 'hoho') # hh print re.sub('aha|oho|ehe', 'h', 'hehe') # hh print re.sub('aha|oho|ehe', 'h', 'hehe...
2
2016-08-17T01:43:00Z
[ "python", "regex" ]
Doing a "qrsh" inside python script
38,987,091
<p>I want to do a "qrsh" which is a grid command which returns a terminal from pool of machines, its behavior is very similar to "rsh", I am trying to run it from inside a python script and came up with following :</p> <pre><code>os.execl("/remote/sge1/default/bin/lx-amd64/qrsh", "-P test") </code></pre> <p>Is it pos...
0
2016-08-17T02:12:31Z
38,988,822
<p>The syntax of <code>os.execl</code> is slightly tricky. You are apparently looking for</p> <pre><code> os.execl("/remote/sge1/default/bin/lx-amd64/qrsh", "qrsh", "-P", "test") </code></pre> <p>However, if you want to actually retain control of the subprocess, the <code>execl</code> is wrong - it will <em>replace<...
1
2016-08-17T05:38:36Z
[ "python", "subprocess" ]
Better Database Design for a Hierarchical Structure?
38,987,124
<p>I've created a bilingual dictionary app<sup>1</sup>, and it's currently very simple, but we're going to be starting to develop the entries more fully and I'm trying to figure out the best database structure for it. Previous dictionary projects I've worked on have used xml (since dictionary entries are largely hierar...
2
2016-08-17T02:18:09Z
39,005,920
<p>Why not use the python <a href="https://docs.python.org/2/library/stdtypes.html#dictionary-view-objects" rel="nofollow">dictionary</a> data structure (or json/bson) along with <a href="https://www.mongodb.com" rel="nofollow">mongodb</a>? </p> <p>In python, it is much more convenient than <code>xml</code>.</p> <p>...
-1
2016-08-17T20:41:20Z
[ "python", "django", "data-structures", "nlp" ]
Better Database Design for a Hierarchical Structure?
38,987,124
<p>I've created a bilingual dictionary app<sup>1</sup>, and it's currently very simple, but we're going to be starting to develop the entries more fully and I'm trying to figure out the best database structure for it. Previous dictionary projects I've worked on have used xml (since dictionary entries are largely hierar...
2
2016-08-17T02:18:09Z
39,821,465
<p>You can emulate saving dictionaries in sql databases as well. Someone wrote this awesome helper already:</p> <p><a href="https://djangosnippets.org/snippets/2451/" rel="nofollow">Django Dictionary Model</a></p> <p>I use it in my project as well.</p>
0
2016-10-02T20:37:46Z
[ "python", "django", "data-structures", "nlp" ]
How to extract the grammar productions rules given bracketed parses?
38,987,138
<p>I have a sample sentence. "Open the door." that I parsed a sentence to get the bracketed parse output as below.</p> <blockquote> <p>(S (VP (VB open) (NP (DT the) (NN door))) (. .))</p> </blockquote> <p>I need to extract the CFG grammar rules that produce the parsed output. I can manually write them out as such:<...
2
2016-08-17T02:20:09Z
39,049,856
<p>You can use <strong>Tree.productions()</strong> method to get CFG rules from Tree.</p> <p><strong>Example:</strong></p> <pre><code>from nltk import Tree t = Tree.fromstring("(S (VP (VB open) (NP (DT the) (NN door))) (. .))") print t.productions() </code></pre> <p><strong>Output:</strong></p> <pre><code>[S -&gt;...
2
2016-08-20T02:20:01Z
[ "python", "parsing", "nlp", "nltk", "context-free-grammar" ]
How to extract the grammar productions rules given bracketed parses?
38,987,138
<p>I have a sample sentence. "Open the door." that I parsed a sentence to get the bracketed parse output as below.</p> <blockquote> <p>(S (VP (VB open) (NP (DT the) (NN door))) (. .))</p> </blockquote> <p>I need to extract the CFG grammar rules that produce the parsed output. I can manually write them out as such:<...
2
2016-08-17T02:20:09Z
39,051,849
<p>If you're looking to create the rules from a bracketed parsed, you can use <a href="http://www.nltk.org/api/nltk.html#nltk.tree.Tree.productions" rel="nofollow"><code>Tree.productions()</code></a></p> <pre><code>&gt;&gt;&gt; from nltk import Tree &gt;&gt;&gt; t = Tree.fromstring("(S (NP (D the) (N dog)) (VP (V chas...
2
2016-08-20T07:55:31Z
[ "python", "parsing", "nlp", "nltk", "context-free-grammar" ]
This works BUT WHY?
38,987,146
<p>I'm learing Python on codecademy and came across this solution for a function that's meant to remove duplicates from a list of numbers:</p> <pre><code>x = [1, 1, 2, 2] def remove_duplicates(x): p = [] for i in x: if i != i: p.append(i) return i </code></pre> <p>I ran this in pycharm ...
4
2016-08-17T02:21:32Z
38,987,201
<p>You are correct: it doesn't make any sense. First, it creates a list called <code>p</code> that gets each item that is not equal to itself. The only object that I know of that is not equal to itself is NaN, but you don't have any of those, so <code>p</code> is just an empty list. Defining <code>p</code> is useles...
4
2016-08-17T02:29:01Z
[ "python" ]
This works BUT WHY?
38,987,146
<p>I'm learing Python on codecademy and came across this solution for a function that's meant to remove duplicates from a list of numbers:</p> <pre><code>x = [1, 1, 2, 2] def remove_duplicates(x): p = [] for i in x: if i != i: p.append(i) return i </code></pre> <p>I ran this in pycharm ...
4
2016-08-17T02:21:32Z
38,987,221
<p>Take a look to this snippet to see the pythonic way to remove duplicated (good_result) and also to understand why your code doesn't make any sense:</p> <pre><code>x = [1, 1, 2, 2] def remove_duplicates(x): p = [] for i in x: if i != i: p.append(i) return i good_result = list(set(x...
2
2016-08-17T02:31:49Z
[ "python" ]
This works BUT WHY?
38,987,146
<p>I'm learing Python on codecademy and came across this solution for a function that's meant to remove duplicates from a list of numbers:</p> <pre><code>x = [1, 1, 2, 2] def remove_duplicates(x): p = [] for i in x: if i != i: p.append(i) return i </code></pre> <p>I ran this in pycharm ...
4
2016-08-17T02:21:32Z
38,987,448
<p>your code just returns the last element of the number, that is same as </p> <pre><code>return x[-1] </code></pre> <p>It doesn't return a list. I think you need to check the question that they may be asking like, </p> <p>a)function to return one of the duplicating element in a list. </p> <p>b)function to ret...
0
2016-08-17T03:03:34Z
[ "python" ]
How to get the number of columns in a postgresql table and store it to variable in python?
38,987,151
<p>What command would I use to get the number of columns in a postgresql table in python and store it to a variable called rowCount?</p>
-1
2016-08-17T02:22:01Z
38,987,541
<p>I don't know about Python, but you can get the number of columns in a table with the following:</p> <pre><code>select count (*) as column_count from information_schema.columns where table_schema = :YOUR_SCHEMA and table_name = :YOUR_TABLE </code></pre> <p>Insert whatever wrapper code you normally use for Pytho...
0
2016-08-17T03:16:00Z
[ "python", "postgresql" ]
"Element is not clickable at point (x,y)". Invisible element covers the button
38,987,154
<p>I’m stuck trying to get Selenium with Chrome Webdriver to click a buttom, but there is an element <code>&lt;div class="modal-overlay" style="display: block;"&gt;&lt;/div&gt;</code> that covers the entire page and is invisble, that is blocking my clicks. How can I work around this?</p> <p>I tried using this:</p> ...
1
2016-08-17T02:22:41Z
38,987,275
<p>Just use <code>execute_script</code> to submit the form</p> <pre><code>driver.execute_script("document.getElementById('myForm').submit()"); </code></pre>
1
2016-08-17T02:39:54Z
[ "javascript", "python", "selenium" ]
"Element is not clickable at point (x,y)". Invisible element covers the button
38,987,154
<p>I’m stuck trying to get Selenium with Chrome Webdriver to click a buttom, but there is an element <code>&lt;div class="modal-overlay" style="display: block;"&gt;&lt;/div&gt;</code> that covers the entire page and is invisble, that is blocking my clicks. How can I work around this?</p> <p>I tried using this:</p> ...
1
2016-08-17T02:22:41Z
38,987,927
<p>In your case you need to make overlay element invisible forcefully before going to click on submit button as below :-</p> <pre><code>#first make overlay element invisible overlay = driver.find_element_by_css_selector("div.modal-overlay") driver.execute_script("arguments[0].style.display = 'none'", overlay) #now f...
1
2016-08-17T04:03:06Z
[ "javascript", "python", "selenium" ]
AWS lambda function ConnectionError when configured with VPC
38,987,195
<p><em>I have an AWS lambda function to trigger daily importer jobs</em></p> <p>I am using a "A starter AWS Lambda function." for this and the lambda_handler is quite simple. This is a pseudo code of what I am doing:</p> <pre><code>try: cron_job = CloudCron() status = redis_get_importer_status(db_key, key) ...
0
2016-08-17T02:27:55Z
38,997,446
<p>Once you place the Lambda function inside your VPC it can only access resources inside the VPC. It can't connect to <code>test.site.com.au</code> because that resolves to a public IP address outside your VPC. You have a few options to get around this issue:</p> <ul> <li>Add a NAT Gateway to your VPC. This will prov...
0
2016-08-17T13:02:51Z
[ "python", "aws-lambda", "amazon-vpc" ]
Alternative to using deepcopy for nested dictionaries?
38,987,212
<p>I have a nested dict like this, but much larger:</p> <pre><code>d = {'a': {'b': 'c'}, 'd': {'e': {'f':2}}} </code></pre> <p>I've written a function which takes a dictionary and a path of keys as input and returns the value associated with that path.</p> <pre><code>&gt;&gt;&gt; p = 'd/e' &gt;&gt;&gt; get_from_path...
1
2016-08-17T02:30:28Z
38,987,280
<p>Depending on your use case, one approach to avoid making changes to an existing dictionary is to wrap it in a <a href="https://docs.python.org/3/library/collections.html#chainmap-objects" rel="nofollow"><code>collections.ChainMap</code></a>:</p> <pre><code>&gt;&gt;&gt; import collections &gt;&gt;&gt; # here's a di...
1
2016-08-17T02:40:50Z
[ "python", "dictionary" ]
how to scrape facebook event and render them in web site
38,987,260
<p>I would like to list the facebook events in a particular region on a web site. What's your advice on how to make it with python or other language.</p>
-3
2016-08-17T02:37:29Z
38,987,625
<p><a href="https://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> is the standard screen scraping utility for Python. You could also look into using the Python <code>requests</code> library together with the <a href="https://developers.facebook.com/docs/graph-api" rel="nofollow">Facebook API...
0
2016-08-17T03:26:42Z
[ "python", "facebook", "events", "screen-scraping" ]
Python requests - how to set default retries object for created sessions?
38,987,263
<p>I'd like to force all requests to retry on some 5xx HTTP status codes. What I would do is:</p> <pre><code>retry = requests.packages.urllib3.util.retry.Retry( total=20, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504], method_whitelist=frozenset(['GET', 'POST'])) for adapter ...
1
2016-08-17T02:38:15Z
39,050,757
<pre><code>import requests import logging logging.basicConfig(level='DEBUG') def forceretry(max_retries): """ Decorator for `requests.adapters.HTTPAdapter.__init__`. """ def decorate(func): def wrapper(self, *args, **kwargs): func(self, *args, **kwargs) self.max_retries = max...
0
2016-08-20T05:24:44Z
[ "python", "python-requests" ]
Python requests - how to set default retries object for created sessions?
38,987,263
<p>I'd like to force all requests to retry on some 5xx HTTP status codes. What I would do is:</p> <pre><code>retry = requests.packages.urllib3.util.retry.Retry( total=20, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504], method_whitelist=frozenset(['GET', 'POST'])) for adapter ...
1
2016-08-17T02:38:15Z
39,052,802
<p>I would use <a href="https://en.wikipedia.org/wiki/Exponential_backoff" rel="nofollow">exponential backoff</a> algorithm.</p> <p>Here is a nice package that provides a decorator for you: <a href="https://pypi.python.org/pypi/backoff/1.3.1" rel="nofollow">backoff</a>. Can be used with <code>requests</code>.</p> <p>...
0
2016-08-20T09:59:12Z
[ "python", "python-requests" ]
IDLE's subprocess didn't make connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection
38,987,289
<p>I started programing a game on a Mac. Then, I brought the same EXACT code to another Mac. </p> <p>I got many, many different errors with Pygame saying it wasn't installed, EVEN THOUGH IT WAS! </p> <p>Anyway, I fixed those errors, then I went to go run the module and the window appeared then it crashed and gave me ...
0
2016-08-17T02:41:31Z
39,058,369
<p>The most likely reason that your getting this error, is because you're not the administrator of the computer and you're trying to run a script from your local disk. There are a few things that you could do to solve this.</p> <h2>1. Move the .py file:</h2> <p>Before jumping to the method below, simply try moving yo...
0
2016-08-20T20:17:58Z
[ "python", "osx", "pygame", "osx-elcapitan" ]
PIP install for scipy fails spectacularly on Ubuntu 14.04
38,987,322
<p>I'm trying to install the scipy package on Ubuntu 14.04.4 LTS, only because gensim needs it, using pip (before anyone chimes in on switching to any of the twelve other python package managers: No). I have installed all the prereq packages:</p> <ul> <li>python 2.7</li> <li>libblas3</li> <li>liblapack3</li> <li>gcc</...
1
2016-08-17T02:46:11Z
39,024,932
<p>It turns out that what was needed was for pip itself to be upgraded to the latest version: <code>pip install --upgrade pip</code>. After that was done, scipy installed without a problem.</p>
0
2016-08-18T18:15:39Z
[ "python", "python-2.7", "ubuntu", "numpy", "scipy" ]
Format attribute of Java and Python in C
38,987,327
<p>In Python, we could use the format attribute this way: </p> <pre><code>"Today is {}/{}/{}".format(self.day, self.month, self.year) </code></pre> <p>In Java, we could do the same: </p> <pre><code>MessageFormat.format("Today is {0}/{1}/{2}", this.day, this.month, this.year); </code></pre> <p>Is there an equivale...
1
2016-08-17T02:46:52Z
38,987,383
<p>It can't be done in C. Not cleanly, at least.</p> <p>Both Java and Python have <em>strong typing</em>. This means that objects have an intrinsic type that cannot change, and this type is known during the execution of the program. You can transform any object to a string appropriately, because their types are known ...
2
2016-08-17T02:56:19Z
[ "java", "python", "c" ]
Is it possible to make a list comprehension from the following function?
38,987,378
<p>There is a function that returns a sum of integers from list x that are greater than integer y. If there is none of the numbers greater than y the function returns 0.</p> <pre><code>def sum_greater(x, y): result = 0 for i in range(len(x)): if x[i] &gt; y: result = result + x[i] retur...
0
2016-08-17T02:56:08Z
38,987,398
<p>You can use the <code>sum()</code> function with a generator expression:</p> <pre><code>sum(i for i in x if i &gt; y) </code></pre>
3
2016-08-17T02:58:09Z
[ "python", "list-comprehension" ]
Is it possible to make a list comprehension from the following function?
38,987,378
<p>There is a function that returns a sum of integers from list x that are greater than integer y. If there is none of the numbers greater than y the function returns 0.</p> <pre><code>def sum_greater(x, y): result = 0 for i in range(len(x)): if x[i] &gt; y: result = result + x[i] retur...
0
2016-08-17T02:56:08Z
38,987,405
<p>Since 0 is the natural result of the sum of nothing, that doesn't need any special handling. You can send a <a href="https://www.python.org/dev/peps/pep-0289/" rel="nofollow">generator expression</a> to the built-in <code>sum</code>:</p> <pre><code>def sum_greater(x, y): return sum(i for i in x if i&gt;y) </cod...
3
2016-08-17T02:59:16Z
[ "python", "list-comprehension" ]
if statement inside an if statement
38,987,390
<p>this is kinda my homework and I'm stuck on making the code becoming a follow up question, like this code here, I've tried inserting an if statement after that but it gave me an unexpected incent error.</p> <p>Here are my codes so far:</p> <pre><code>Choice = input("Hello! Do you want to buy or sell snakes? Please ...
1
2016-08-17T02:57:02Z
38,987,403
<p>You have an extra indent. Just remove the extra level of indentation:</p> <pre><code>Choice = input("Hello! Do you want to buy or sell snakes? Please enter (b) or (s) :") if Choice == "b": buySnake = input ("What snake do you want to buy? We are selling python, kingsnake, rattlesnake, deathadder, cobra, mamba, ...
4
2016-08-17T02:58:57Z
[ "python" ]
if statement inside an if statement
38,987,390
<p>this is kinda my homework and I'm stuck on making the code becoming a follow up question, like this code here, I've tried inserting an if statement after that but it gave me an unexpected incent error.</p> <p>Here are my codes so far:</p> <pre><code>Choice = input("Hello! Do you want to buy or sell snakes? Please ...
1
2016-08-17T02:57:02Z
38,987,429
<p>Indentation is the way to create code blocks in Python. Your error says exactly what you did wrong.</p> <pre><code>if condition: # executes if condition is met if internalCondition: # executes if both condition and internalCondition is met elif otherCondition: # executes if first statement didn'...
0
2016-08-17T03:01:15Z
[ "python" ]
Kmeans is not producing an elbow
38,987,400
<p>I have a data frame of about 300,000 unique product names and I am trying to use k means to cluster similar names together. I used sklearn's tfidfvectorizer to vectorize the names and convert to a tf-idf matrix.</p> <p>Next I ran k means on the tf-idf matrix with number of clusters ranging from 5 to 25. Then I plot...
0
2016-08-17T02:58:17Z
39,806,928
<p>Most likely because k-means w=th TF-IDF doesn't work well on such short text such as product names.</p> <p>Not seeing an elbow is an indication that the results aren't good.</p>
0
2016-10-01T13:02:14Z
[ "python", "scikit-learn", "cluster-computing", "k-means" ]
Why can't use "r+" mode to create a new file in Python with open()
38,987,408
<p>In the docs of open() build in function of python,the meaning of "+" is as follows:</p> <blockquote> <p>open a disk file for updating(reading and writing)</p> </blockquote> <p>but when i use the open() build-in to create a new file with python 3.5 in win7,i got the "FileNotFoundError".</p> <pre><code>tmp_fileï...
0
2016-08-17T02:59:23Z
38,987,518
<p><code>r+</code> mode will open an <strong>existing</strong> file for write, but will not create the file if it doesn't exists.</p> <p>You should open the file with <code>w</code> if you want to create a new file.</p>
0
2016-08-17T03:12:35Z
[ "python", "python-3.x" ]
Why can't use "r+" mode to create a new file in Python with open()
38,987,408
<p>In the docs of open() build in function of python,the meaning of "+" is as follows:</p> <blockquote> <p>open a disk file for updating(reading and writing)</p> </blockquote> <p>but when i use the open() build-in to create a new file with python 3.5 in win7,i got the "FileNotFoundError".</p> <pre><code>tmp_fileï...
0
2016-08-17T02:59:23Z
38,987,526
<p>You should use :<br /> file = open(str(temp_path), 'w+')</p>
0
2016-08-17T03:13:35Z
[ "python", "python-3.x" ]
urlopen for loop with beautifulsoup
38,987,427
<p>New user here. I'm <em>starting</em> to get the hang of Python syntax but keep getting thrown off by for loops. I understand each scenario I've reach on SO thus far (and my previous examples), but can't seem to come up with one for my current scenario.</p> <p>I am playing around with BeautifulSoup to extract featur...
-1
2016-08-17T03:00:56Z
38,988,164
<pre><code>from __future__ import print_function # try: # from urllib import urlopen # Support Python 2 and 3 except ImportError: # from urllib.request import urlopen # from bs4 import BeautifulSoup as bs for line in open('urls.dat'): # Read u...
1
2016-08-17T04:33:04Z
[ "python", "for-loop", "beautifulsoup", "urlopen" ]
urlopen for loop with beautifulsoup
38,987,427
<p>New user here. I'm <em>starting</em> to get the hang of Python syntax but keep getting thrown off by for loops. I understand each scenario I've reach on SO thus far (and my previous examples), but can't seem to come up with one for my current scenario.</p> <p>I am playing around with BeautifulSoup to extract featur...
-1
2016-08-17T03:00:56Z
38,988,694
<p>Try this for reading urls from list:</p> <pre><code>from bs4 import BeautifulSoup as bs import urllib2 import requests list = {"https://play.google.com/store/apps/details?id=com.tov.google.ben10Xenodromeplus&amp;hl=en", "https://play.google.com/store/apps/details?id=com.doraemon.doraemonRepairShopSeasons&amp;hl=en...
1
2016-08-17T05:26:16Z
[ "python", "for-loop", "beautifulsoup", "urlopen" ]
Django: Change status and color in a bootstrap button
38,987,443
<p>I am trying to change the status (from Authenticate to Authenticated) and color (from default to success) on a bootstrap button whenever my Soundcloud API has authenticated its user and is redirected back to my website.</p> <p>Here is my Soundcloud class in <code>views.py</code>:</p> <pre><code>class SoundcloudAcc...
0
2016-08-17T03:02:29Z
38,987,769
<p>You can render bootstrap status to your template, like</p> <pre><code>return render(request, self.template_name, {'status': 'btn btn-success'}) return render(request, self.template_name, {'status': 'btn btn-danger'}) </code></pre> <p>then use it in the template, like</p> <pre><code>&lt;input type="button" class={...
0
2016-08-17T03:42:47Z
[ "python", "django", "twitter-bootstrap" ]
How to detect ending location (x,y,z) of certain sequence in 3D domain
38,987,464
<p>I have protein 3D creo-EM scan, such that it contains a chain which bends and twists around itself - and has in 3-dimension space 2 chain endings (like continuous rope). I need to detect (x,y,z) location within given cube space of two or possibly multiplier of 2 endings. Cube space of scan is presented by densities ...
2
2016-08-17T03:05:29Z
38,987,964
<p>One approach would be to choose a threshold density, convert all voxels below this threshold to 0 and all above it to 1, and then look for <strong>the pair of 1-voxels whose shortest path is longest</strong> among all pairs of 1-voxels. These two voxels should be near the ends of the longest "rope", regardless of t...
1
2016-08-17T04:07:38Z
[ "python", "algorithm", "graph", "analytics", "d3dimage" ]
How to detect ending location (x,y,z) of certain sequence in 3D domain
38,987,464
<p>I have protein 3D creo-EM scan, such that it contains a chain which bends and twists around itself - and has in 3-dimension space 2 chain endings (like continuous rope). I need to detect (x,y,z) location within given cube space of two or possibly multiplier of 2 endings. Cube space of scan is presented by densities ...
2
2016-08-17T03:05:29Z
38,993,951
<p>If you want to enumerate each continuous path (thereby obtaining the ends of each path) in your 3D scan you could, for each position, apply a basic depth-first-search, for example:</p> <pre><code>//applied at some voxel dfs(...) for each surrounding voxel dfs(...) </code></pre> <p>Or in detail:</p> <...
0
2016-08-17T10:22:03Z
[ "python", "algorithm", "graph", "analytics", "d3dimage" ]
eval() and run() in tensorflow
38,987,466
<p>I'm referring to <strong>Deep MNIST for Experts tutorial</strong> given by the tensorflow. I have a problem in <a href="https://www.tensorflow.org/versions/r0.10/tutorials/mnist/pros/index.html#train-and-evaluate-the-model" rel="nofollow">Train and Evaluate</a> part of that tutorial. There they have given a sample c...
1
2016-08-17T03:05:52Z
38,990,824
<p>If you have only one default session, they are basically the same.</p> <p>From <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/framework.html#Operation" rel="nofollow">https://www.tensorflow.org/versions/r0.10/api_docs/python/framework.html#Operation</a>:</p> <blockquote> <p>op.run() is a shor...
2
2016-08-17T07:43:16Z
[ "python", "python-2.7", "tensorflow" ]
using ansible pam_limits module to change max user processes, but failed
38,987,582
<p>I deployed ansible 2.1.1.0 with python 2.7.12 on Redhat 6.5. And I tried below script to modify max user processes, it runs with no failed msg but did not have effects on max user processes.</p> <p>I know I can try other ways by editing /etc/security/limit.d/90-nproc.conf using either copy module or shell module, b...
0
2016-08-17T03:20:34Z
38,989,254
<p>Ansible <a href="http://docs.ansible.com/ansible/pam_limits_module.html#synopsis" rel="nofollow"><code>pam_limits</code></a> module uses <code>/etc/security/limits.conf</code> by default.</p> <p>You need to add a <code>dest</code> parameter to specify path to a different file.</p>
1
2016-08-17T06:12:10Z
[ "python", "ansible", "ansible-playbook", "ansible-2.x" ]
How to return 1 out of 2 values depending on input values from a function
38,987,628
<p>Hi basically I would like to return 1 value if input is negative and another if input is positive. But not return both at the same time. The values returned would be used for the curve_fit function from scipy to determine my unknow parameters (a &amp; b). </p> <p>I tried using a if loop inside the function but it g...
1
2016-08-17T03:26:59Z
38,988,706
<p>How about: </p> <p>def f(x, a, b): return a * (1 - 2*abs(x)/b + (x/b)**2) </p> <p>I know, it's a workaround and doesn't solve the general cae.</p>
0
2016-08-17T05:28:10Z
[ "python", "function", "python-3.x", "jupyter-notebook" ]
How to return 1 out of 2 values depending on input values from a function
38,987,628
<p>Hi basically I would like to return 1 value if input is negative and another if input is positive. But not return both at the same time. The values returned would be used for the curve_fit function from scipy to determine my unknow parameters (a &amp; b). </p> <p>I tried using a if loop inside the function but it g...
1
2016-08-17T03:26:59Z
38,989,033
<p>Your input <code>x</code> is a list. You cannot check for positive or negative value for whole list. You have to check each element one by one. Try this:</p> <pre><code>def f2(x,a,b): y=[] for i in range(len(x)): if x[i]&lt;0: y.append(a*((1+(x[i]/b))**2)) else: y.app...
0
2016-08-17T05:56:24Z
[ "python", "function", "python-3.x", "jupyter-notebook" ]
python:I want to read the csv file which contains chinese,I used the 'reload(sys)' but it can't work
38,987,658
<p>I use Python 3.5 and PyCharm.</p> <p>My code:</p> <pre><code>import importlib,sys importlib.reload (sys) sys.setdefaultencoding("utf-8") </code></pre> <p>The error:</p> <pre class="lang-none prettyprint-override"><code> sys.setdefaultencoding("utf-8") AttributeError: module 'sys' has no attribute 'setdefaultenc...
0
2016-08-17T03:29:56Z
38,987,874
<p>Use of sys.setdefaultencoding("utf-8") is strictly discouraged.</p> <p>In Python 3, the default encoding has been switched from ascii to utf-8. First check what encoding is set from python prompt using the following commands.</p> <pre><code>$ python &gt;&gt;&gt; import sys &gt;&gt;&gt; sys.stdout.encoding 'UTF-8' ...
1
2016-08-17T03:57:31Z
[ "python" ]
How to import the module which using argparse
38,987,831
<p>I got the module call foo.py, use argparse to handle variables, requires some variables, -a and a element</p> <pre><code>python foo.py -a element </code></pre> <p>This works well, now I get a list of elements, I try to use foo.py to run all of them.So I create a script like this:</p> <pre><code>import foo for i i...
0
2016-08-17T03:51:06Z
38,989,617
<p>Thanks to @Karin,This works great.</p> <pre><code>import sys sys.argv += ['-a','-H MYHOSTNAME' .... other options] from pyrseas import dbtoyaml dbtoyaml.main() </code></pre> <p>And this also work.</p> <pre><code>proc = subprocess.Popen(['python', 'foo.py', '-a', 'bala'], stdout=subprocess.PIPE, stderr=subprocess...
0
2016-08-17T06:35:12Z
[ "python" ]
Attempting to plot images with annotations in matplotlib, but the overlap makes them unreadable
38,987,840
<p>I'm writing a script to classify images based on their features: Histogram, color balance, keypoint count, etc. And although the function that I wrote to display the charts works fine:</p> <pre><code>fig,axes = plt.subplots(2,3,figsize=(15,7)) axes[0, 0].scatter((zip(*xy_a))[0], (zip(*xy_a))[1]) for i, txt in enum...
0
2016-08-17T03:52:53Z
38,994,535
<p>I would suggest that, instead of showing all annotations at all time, just show the annotation when you click on a data point. The same data point could also be highlighted in the other subplots.</p> <p>See <a href="http://scipy-cookbook.readthedocs.io/items/Matplotlib_Interactive_Plotting.html" rel="nofollow">this...
1
2016-08-17T10:48:47Z
[ "python", "matplotlib", "graph", "charts", "annotations" ]
Django and weasyprint, merge pdf
38,987,854
<p>It's possible to merge multiple pdf in django with weasyprint?</p> <p>I have something like this:</p> <pre><code>def verpdf(request, pk): odet = get_object_or_404(Note, pk = pk) template = get_template('pdfnot.html') template1 = get_template('pdfnot2.html') p1 = template.render({'odet': odet}).enco...
0
2016-08-17T03:54:17Z
38,988,594
<p>Took me a while, but i solved it, was my fault for not understand the documentation lol, here is the code if anyone have the same problem:</p> <pre><code>def verpdf(request, pk): odet = get_object_or_404(Note, pk = pk) template = get_template('pdfnot.html') template1 = get_template('pdfnot2.html') p...
0
2016-08-17T05:17:54Z
[ "python", "django", "pdf", "weasyprint" ]
Django add GenericForeignKey search fields
38,987,895
<p>Django 1.8.4 add GenericForeignKey search fields does not work.</p> <p>I've created several Product models like:</p> <pre><code>class Product1(models.Model): ... orders = GenericRelation(Order) class Product2(models.Model): ... orders = GenericRelation(Order) </code></pre> <p>And in Order model:<...
1
2016-08-17T03:59:58Z
39,016,729
<p>By override the default <code>get_search_results</code> method, the following code Generally works, but still got a little problem. </p> <pre><code>def get_search_results(self, request, queryset, search_term): """Override to Include searching `product__name` which is a GenericForeignKey Field of all produc...
0
2016-08-18T11:13:05Z
[ "python", "django" ]
Python Non-recursive Permutation
38,987,928
<p>Does anyone understand the following iterative algorithm for producing all permutations of a list of numbers?</p> <p>I do not understand the logic within the <code>while len(stack)</code> loop. Can someone please explain how it works?</p> <pre><code># Non-Recursion @param nums: A list of Integers. @return: A list ...
0
2016-08-17T04:03:08Z
38,988,162
<p>As mentioned in the comments section to your question, debugging may provide a helpful way to understand what the code does. However, let me provide a high-level perspective of what your code does.</p> <p>First of all, although there are no recursive calls to the function permute, the code your provided is effectiv...
2
2016-08-17T04:32:46Z
[ "python", "algorithm", "permutation" ]
Python Non-recursive Permutation
38,987,928
<p>Does anyone understand the following iterative algorithm for producing all permutations of a list of numbers?</p> <p>I do not understand the logic within the <code>while len(stack)</code> loop. Can someone please explain how it works?</p> <pre><code># Non-Recursion @param nums: A list of Integers. @return: A list ...
0
2016-08-17T04:03:08Z
38,990,643
<p>The answer from @ilim is correct and should be the accepted answer but I just wanted to add another point that wouldn't fit as a comment. Whilst I imagine you are studying this algorithm as an exercise it should be pointed out that a better way to proceed, depending on the size of the list, may be to user <code>ite...
0
2016-08-17T07:32:45Z
[ "python", "algorithm", "permutation" ]
Deployed django app to heroku missing CSS / static files
38,987,993
<p>Preface this by saying I have now read multiple posts on this question (including <a href="http://stackoverflow.com/questions/28961177/heroku-static-files-not-loading-django?rq=1">here</a>, <a href="http://stackoverflow.com/questions/34121663/static-files-not-found-deploying-django-on-heroku?rq=1">here</a>, and <a h...
0
2016-08-17T04:10:53Z
38,993,312
<ol> <li><p>The main problem with your configuration is the <code>STATIC_ROOT</code> setting. You should change this to something like <code>os.path.join(BASE_DIR, 'static_root')</code>.</p> <p><code>STATIC_ROOT</code> should point to an empty directory (it doesn't need to exist, Django will create it if necessary) wh...
1
2016-08-17T09:52:30Z
[ "python", "django", "heroku" ]
Access Host redis database from docker conatiner
38,987,997
<p>I am trying to connect to host redis database through my docker conatiner.</p> <p>In my dockerfile , I have redis as a requirement, which gets installed [pip install redis] and image is build using that docker file. After than I instantiate the conatiner using following command</p> <pre><code>sudo docker run -p 6...
0
2016-08-17T04:11:45Z
38,988,477
<ol> <li><p>If you have a redis instance running on the host machine and just want the container to connect to that redis instance, then you just need to mount the socket file inside the container. For example, if the location of the socket file on the host machine is <code>/var/run/redis/redis.sock</code> and you want...
0
2016-08-17T05:05:57Z
[ "python", "database", "docker", "redis" ]
Access Host redis database from docker conatiner
38,987,997
<p>I am trying to connect to host redis database through my docker conatiner.</p> <p>In my dockerfile , I have redis as a requirement, which gets installed [pip install redis] and image is build using that docker file. After than I instantiate the conatiner using following command</p> <pre><code>sudo docker run -p 6...
0
2016-08-17T04:11:45Z
38,989,493
<p>You need to access the hosts localhost loopback device, so what you do is <a href="https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c#file-gistfile1-txt" rel="nofollow">https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c#file-gistfile1-txt</a></p> <p>You create this file at</p> <ul...
0
2016-08-17T06:27:41Z
[ "python", "database", "docker", "redis" ]
Odoo payslip with leave in salary rule python code
38,988,205
<p>I have to calculate the basic pay with if condition.if the employee does not have unpaid leave means Unpaid is not there under Worked days and input under payslip then unpaid leave should be o(Zero). I have tried the below code but its given error.</p> <pre><code>day=contract.wage/30 if not worked_days.Unpaid.n...
0
2016-08-17T04:38:18Z
38,988,407
<p>The in command in python is used to check for membership. E.g. : <code>3 in [1, 2, 3]</code> results in True. I am not exactly sure what is the purpose of payslip in your code but from what I understand you may try this:</p> <pre><code>day=contract.wage/30 if Not(worked_days.Unpaid.number_of_days): result=day*(...
1
2016-08-17T04:59:04Z
[ "python", "openerp", "odoo-8" ]
Urllib HTTP Error 403
38,988,249
<p>I've searched through the forums to try and figure out why the following code was not working:</p> <pre><code>import nltk, re, pprint from urllib import request url = "http://www.gutenberg.org/files/2554/2554.txt" response = request.urlopen(url) raw = response.read().decode('utf8') print(raw[:75]) </code></pre> <p...
0
2016-08-17T04:43:20Z
38,988,344
<p>This code works:</p> <p><em>Python 2</em></p> <pre><code>from urllib import urlopen url = "http://www.gutenberg.org/files/2554/2554.txt" response = urlopen(url) if response.code == 200: raw = response.read().decode('utf-8') print raw[:75] else: print 'Error', response.code response.close() </code><...
3
2016-08-17T04:54:19Z
[ "python", "urllib", "http-error", "urlopen" ]
Django Rest Framework (DRF) How to set pagination class depending on query_params?
38,988,272
<p>I'm trying to use different sets of pagination classes on a viewset depending on query_params.</p> <pre><code>class BlockViewSet(viewsets.ModelViewSet): pagination_class = defaultPaginationClass def get_queryset(self): queryset = Block.objects.all() user = self.request.query_params.get('use...
0
2016-08-17T04:45:39Z
38,989,390
<p>Try to redefine <code>paginator</code> property and if there is user query param, assign your custom pagination class to <code>self._paginator</code></p> <pre><code>@property def paginator(self): """ The paginator instance associated with the view, or `None`. """ if not hasattr(self, '_paginator'): ...
0
2016-08-17T06:21:12Z
[ "python", "django", "pagination", "django-rest-framework" ]
Still getting 404 page not found on Django using correct route files and settings
38,988,331
<p>I'm going through the polls Django tutorial and have searched for answers to this. So far:</p> <ol> <li><p>I made sure I'm using the right directories. The main urls.py is in mysite/mysite/, the polls urls.py is in mysite/polls/urls.py.</p></li> <li><p>Tried adding 'polls' to INSTALLED_APPS in the settings.py of my...
0
2016-08-17T04:52:24Z
38,988,444
<p>In your <code>polls/urls.py</code> change <code>url(r'^%', views.index, name='index')</code> to <code>url(r'^$', views.index, name='index')</code>. </p> <p>Also in your urls.py, you have route for <code>127.0.0.1:8000/polls/</code> and you request for <code>127.0.0.1:8000/polls</code> . Notice the trailing slash.</...
0
2016-08-17T05:01:59Z
[ "python", "django" ]
Still getting 404 page not found on Django using correct route files and settings
38,988,331
<p>I'm going through the polls Django tutorial and have searched for answers to this. So far:</p> <ol> <li><p>I made sure I'm using the right directories. The main urls.py is in mysite/mysite/, the polls urls.py is in mysite/polls/urls.py.</p></li> <li><p>Tried adding 'polls' to INSTALLED_APPS in the settings.py of my...
0
2016-08-17T04:52:24Z
38,988,448
<p>So i tried your Index view with your urls.py. It works, the only thing different is in your "Request URL, you must request for - 127.0.0.1:8000/polls/%</p> <p>changing your urls to </p> <p>url('^/%', index) - polls URLs.py url('^polls', include('polls.urls')) - project URLs</p> <p>This will work.</p>
0
2016-08-17T05:02:41Z
[ "python", "django" ]
Python advanced slicing
38,988,560
<p>I am a little confused with Python's advanced slicing. I basically had a dictionary and with help from SO, I made it into an array. </p> <pre><code> array1 = ([[[36, 16], [48, 24], [12, 4], [12, 4]], [[48, 24], [64, 36], [16, 6], [16, 6]], [[12, 4], [16, 6], [ 4...
0
2016-08-17T05:13:50Z
38,988,696
<blockquote> <p>I read that this means [number of indices, rows, columns]. [...] What throws me off is the number of rows is ":" and the number of columns is "0", if I read this concept correctly.</p> </blockquote> <p>No. It means [which parts I want on dimension 1, which parts I want on dimension 2, which parts I...
4
2016-08-17T05:26:27Z
[ "python", "arrays", "numpy", "matrix" ]
Python advanced slicing
38,988,560
<p>I am a little confused with Python's advanced slicing. I basically had a dictionary and with help from SO, I made it into an array. </p> <pre><code> array1 = ([[[36, 16], [48, 24], [12, 4], [12, 4]], [[48, 24], [64, 36], [16, 6], [16, 6]], [[12, 4], [16, 6], [ 4...
0
2016-08-17T05:13:50Z
38,988,981
<p>I just wanted to add a clarifying example:</p> <pre><code>&gt;&gt;&gt; np.arange(4*4*2).reshape(4,4,2) array([[[ 0, 1], [ 2, 3], [ 4, 5], [ 6, 7]], [[ 8, 9], [10, 11], [12, 13], [14, 15]], [[16, 17], [18, 19], [20, 21], [22...
2
2016-08-17T05:52:04Z
[ "python", "arrays", "numpy", "matrix" ]
how to read the nested list in csv file using pandas like a list
38,988,909
<p>I have scraped the data from a site "itjuzi.com",and store nested list in csv file, and read it with pandas .But now the how to read the unicode string or nested list like a list ? and encoding ?</p> <p><a href="http://i.stack.imgur.com/gTx44.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/gTx44.jpg" alt="en...
-3
2016-08-17T05:45:47Z
39,016,774
<p>The unicode data is there, it's just not rendered:</p> <pre><code>$ print(u'[\u9e64\u5e74\u5802\u4e2d\u533b\u9662]') [鹤年堂中医院] </code></pre> <p>Regarding your list of lists you need to adjust your spider code. By default scrapy ItemLoaders and even Selector's <code>eextract()</code> method returns a lis...
-1
2016-08-18T11:14:45Z
[ "python", "csv", "pandas", "scrapy", "nested-lists" ]
django unit test for exceptions
38,988,968
<p>i am working in a django project and writing services to facilitate apis.in the services , i have class and class methods like this,</p> <pre><code>class ProductService(object): def delete_product(self, product_id, deleting_user): try: product = Product.objects.get(pk=product_id) exc...
0
2016-08-17T05:50:35Z
38,989,108
<p>We are using Enum for this case:</p> <pre><code>class ProductErrors(Enum): not_found = "Product {} not found" doesnt_exist = "Product {} doesn't exist" </code></pre> <p>This will allow you to use this enum in your tests and check it like that:</p> <pre><code>def test_raise_does_not_exist_error_for_wrong_p...
0
2016-08-17T06:02:06Z
[ "python", "django", "unit-testing" ]
django unit test for exceptions
38,988,968
<p>i am working in a django project and writing services to facilitate apis.in the services , i have class and class methods like this,</p> <pre><code>class ProductService(object): def delete_product(self, product_id, deleting_user): try: product = Product.objects.get(pk=product_id) exc...
0
2016-08-17T05:50:35Z
38,989,257
<p>If I understand correctly, you are worried about the lot of repetitive code, which would make it hard to maintain the tests should anything change (e.g.: the method's signature accepting a new parameter, etc.).</p> <p>Introducing a helper method might help (be careful not to create too many helper methods that use ...
0
2016-08-17T06:12:24Z
[ "python", "django", "unit-testing" ]
django unit test for exceptions
38,988,968
<p>i am working in a django project and writing services to facilitate apis.in the services , i have class and class methods like this,</p> <pre><code>class ProductService(object): def delete_product(self, product_id, deleting_user): try: product = Product.objects.get(pk=product_id) exc...
0
2016-08-17T05:50:35Z
38,989,718
<p>Now that I understand the original question that the goal is to allow changing the error text without having the tests break, I suggest to use <a href="https://docs.djangoproject.com/en/1.10/topics/i18n/translation/" rel="nofollow">translations</a>. Instead of the full English text of the error, just use keys/codena...
0
2016-08-17T06:40:25Z
[ "python", "django", "unit-testing" ]
Get array row and column number according to values in python
38,988,974
<p>For example I have a <code>5*5 np.array</code> like this:</p> <pre><code>a=[[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16,17,18,19,20], [21,22,23,24,25]] </code></pre> <p>if I want to get the range of row and column where <code>number&lt;=15</code>, how can I do this?</p> <p>On the contrary, if I k...
1
2016-08-17T05:51:10Z
38,989,212
<p>To get the range based on a condition, you can either apply the condition directly, or use <a href="https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>np.where</code></a> :</p> <pre><code>&gt;&gt;&gt; a array([[ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10], ...
0
2016-08-17T06:09:19Z
[ "python", "arrays", "numpy" ]
Copy / paste JetBrains PyCharm behavior
38,988,979
<p>I'm new to PyCharm and cannot understand it's <strong>copy/paste</strong> behavior - If i copy <code>code('foobar')</code> and insert it <strong>inside</strong> code i've got</p> <pre><code>code-code-codefoobarcode-code </code></pre> <p>and it's right as for me, but if i paste <strong>'foobar'</strong> at the end...
-1
2016-08-17T05:51:45Z
38,992,262
<p>The behavior I was confused of difference between "paste simple" and "paste". I've found keymap editor and edited shortcuts. Thanks.</p>
1
2016-08-17T09:02:04Z
[ "python", "pycharm", "jetbrains" ]
Index error: String out of range, but it shouldn't be going out of range?
38,989,032
<p>Alright so I am making an encoder/decoder and currently I'm testing to see if my idea will work, but I keep getting the error telling me my string index is out of range when it shouldn't be going out of range in the first place.</p> <pre><code>message = "abc" #Should come out as 212223 translated = ' ' n = 1 whil...
0
2016-08-17T05:56:04Z
38,989,115
<pre><code>n = 0 while n &gt;= 0: </code></pre> <p>You have an infinite loop as you keep on incrementing <code>n</code>. At some point <code>message[n]</code> will get out of range.</p> <p>You should move the <code>while n &lt;= len(message):</code> to be your main loop instead of your current one.</p> <p>A better ...
3
2016-08-17T06:02:30Z
[ "python", "python-3.x", "encryption" ]
Index error: String out of range, but it shouldn't be going out of range?
38,989,032
<p>Alright so I am making an encoder/decoder and currently I'm testing to see if my idea will work, but I keep getting the error telling me my string index is out of range when it shouldn't be going out of range in the first place.</p> <pre><code>message = "abc" #Should come out as 212223 translated = ' ' n = 1 whil...
0
2016-08-17T05:56:04Z
38,989,129
<p>Here:</p> <pre><code>while n &lt;= len(message): n = n + 1 </code></pre> <p>Should need changing to:</p> <pre><code>while n &lt; len(message): n = n + 1 </code></pre> <p>The last index of a string will be <code>len(message) - 1</code>, as indexing starts at 0. I would just set n to len(message) - 1 insta...
0
2016-08-17T06:03:23Z
[ "python", "python-3.x", "encryption" ]
Index error: String out of range, but it shouldn't be going out of range?
38,989,032
<p>Alright so I am making an encoder/decoder and currently I'm testing to see if my idea will work, but I keep getting the error telling me my string index is out of range when it shouldn't be going out of range in the first place.</p> <pre><code>message = "abc" #Should come out as 212223 translated = ' ' n = 1 whil...
0
2016-08-17T05:56:04Z
38,989,154
<p>Because at last loop you are using t = message[3]..It is the cause of your error. If you message variable contain "abc" then you can access only t = message[0], t = message[1], t = message[2]. So try this</p> <pre><code>message = "abc" #Should come out as 212223 translated = ' ' n = 1 while n &gt;= 0: t = m...
0
2016-08-17T06:04:28Z
[ "python", "python-3.x", "encryption" ]
Python Avro writer.append doesn't work when a json string is passed as a variable.
38,989,070
<p>Avro Schema file: user.avsc</p> <pre><code>{"namespace": "example.avro", "type": "record", "name": "User", "fields": [ {"name": "TransportProtocol", "type": "string"} ] } </code></pre> <p>Pasting my code snippet that works:-</p> <pre><code>import json from avro import schema, datafile, io import avro.sch...
0
2016-08-17T05:59:29Z
38,995,511
<p>I think that might be due to the fact that in your first example you actually pass a dictionary <code>{"TransportProtocol": "udp"}</code>, not a string. But in the second one, you pass a string <code>'{"TransportProtocol": "udp"}'</code>. </p> <p>Check this out (<a href="http://avro.apache.org/docs/1.7.6/gettingsta...
1
2016-08-17T11:34:56Z
[ "python", "avro", "writer" ]
How to Replace' \ ' with' / '
38,989,121
<pre><code>a="D:/R_SVN/hostworkspace/middleware/projects/module/com.ofss.fc.module.ac/src/com/ofss/fc/app\ac\service\writeoffrecovery\ext\WriteoffRecoveryApplicationServiceExtExecutor.java" b=a.replace('\','/') print b </code></pre> <p>Error: </p> <pre><code> b=a.replace('\','/') </code></pre> <p>SyntaxError: <c...
2
2016-08-17T06:02:43Z
38,989,149
<p>You have to escape the backslash, because it is a special character:</p> <pre><code> b=a.replace('\\','/') </code></pre>
2
2016-08-17T06:04:17Z
[ "python" ]
How to Replace' \ ' with' / '
38,989,121
<pre><code>a="D:/R_SVN/hostworkspace/middleware/projects/module/com.ofss.fc.module.ac/src/com/ofss/fc/app\ac\service\writeoffrecovery\ext\WriteoffRecoveryApplicationServiceExtExecutor.java" b=a.replace('\','/') print b </code></pre> <p>Error: </p> <pre><code> b=a.replace('\','/') </code></pre> <p>SyntaxError: <c...
2
2016-08-17T06:02:43Z
38,989,328
<p>As "Backslash notation" is used for "<strong>Escape character</strong>", you have to add <code>\\</code> instead of <code>\</code></p> <pre><code>a.replace('\\','/') </code></pre>
2
2016-08-17T06:16:57Z
[ "python" ]
How to Replace' \ ' with' / '
38,989,121
<pre><code>a="D:/R_SVN/hostworkspace/middleware/projects/module/com.ofss.fc.module.ac/src/com/ofss/fc/app\ac\service\writeoffrecovery\ext\WriteoffRecoveryApplicationServiceExtExecutor.java" b=a.replace('\','/') print b </code></pre> <p>Error: </p> <pre><code> b=a.replace('\','/') </code></pre> <p>SyntaxError: <c...
2
2016-08-17T06:02:43Z
38,990,087
<p>In strings <code>\</code> is escape character e.g if there are two \ like <code>\\</code> then first one is escape character.</p> <p>in <code>b=a.replace('\','/')</code> '\' is read as escape character. so you can replace it with <code>\\</code>. In this case first \ will be escaped and second one will perform oper...
1
2016-08-17T07:01:43Z
[ "python" ]
How to use a python function from another module
38,989,150
<p>I trying to import a module and use a function from that module in my current python file.</p> <p>I run the nosetests on the parser_tests.py file but it fails with "name 'parse_subject' not defined"</p> <p>e.g its not finding the parse_subject function which is clearly defined in the parsrer.py file</p> <p>This i...
1
2016-08-17T06:04:23Z
38,989,228
<h1>Import Module</h1> <p>You can either import the whole module or you can specifically import that specific function using <strong>from an example keyword</strong>.</p> <p>For example:</p> <pre><code>from parser_tests import parse_subject # and then you can invoke the function. parse_subject() </code></pre>
0
2016-08-17T06:10:40Z
[ "python", "import", "module" ]
How to use a python function from another module
38,989,150
<p>I trying to import a module and use a function from that module in my current python file.</p> <p>I run the nosetests on the parser_tests.py file but it fails with "name 'parse_subject' not defined"</p> <p>e.g its not finding the parse_subject function which is clearly defined in the parsrer.py file</p> <p>This i...
1
2016-08-17T06:04:23Z
38,989,452
<p>It is difficult to know exactly how to diagnose your issue without seeing your code, but here's my best guess as to what might help.</p> <p>First, <a href="https://docs.python.org/2/library/parser.html" rel="nofollow"><code>parser</code></a> is already a builtin module in Python, so you should consider a different ...
0
2016-08-17T06:25:29Z
[ "python", "import", "module" ]
How to use a python function from another module
38,989,150
<p>I trying to import a module and use a function from that module in my current python file.</p> <p>I run the nosetests on the parser_tests.py file but it fails with "name 'parse_subject' not defined"</p> <p>e.g its not finding the parse_subject function which is clearly defined in the parsrer.py file</p> <p>This i...
1
2016-08-17T06:04:23Z
38,989,510
<p>Could it be that there is already a built in function called parser. I am calling one of my locally created parser.py file that I put together instead. </p>
0
2016-08-17T06:28:45Z
[ "python", "import", "module" ]
Can XSLT be improved further?
38,989,162
<p>I have 2 XSLs:</p> <p><strong>GET ID</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:oval-res="http...
0
2016-08-17T06:05:05Z
38,990,027
<p>Would something like this work for you?</p> <p><strong>XSLT 1.0</strong></p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:oval-res="http://oval.mitre.org/XMLSchema/oval-results-5" xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" exclude-resu...
1
2016-08-17T06:58:07Z
[ "python", "xml", "xslt" ]
Pandas plot, combine two plots
38,989,178
<p>Currently I have 3 plots that I am plotting in the 2x2 subplots. It looks like this:</p> <pre><code>fig, axes = plt.subplots(nrows=2, ncols=2) df1.plot('type_of_plot', ax=axes[0, 0]); df2.plot('type_of_plot', ax=axes[0, 1]); df3.plot('type_of_plot', ax=axes[1, 0]); </code></pre> <p>The 4-th subplot is empty, and I...
4
2016-08-17T06:06:16Z
38,989,558
<p>You can do this : </p> <pre><code>import matplotlib.pyplot as plt fig=plt.figure() a=fig.add_axes((0.05,0.05,0.4,0.4)) # number here are coordinate (left,bottom,width,height) b=fig.add_axes((0.05,0.5,0.4,0.4)) c=fig.add_axes((0.5,0.05,0.4,0.85)) df1.plot('type_of_plot', ax=a); df2.plot('type_of_plot', ax=b); df3....
2
2016-08-17T06:31:45Z
[ "python", "pandas", "matplotlib" ]
Export SVM model to PMML using Python
38,989,272
<p>I am applying SVM algorithm using Scikit-Learn to predict whether a Customer will opt for a Home Loan or not. I want the model to be exported into PMML format. The features and labels in the dataset are shown below:<br><br> <strong>Features</strong> <br>1. Frequency of visits <br>2. Response to offers<br>3. Usage o...
0
2016-08-17T06:13:43Z
38,989,758
<p>Obviously, one of your data columns does not meet the expectations of the <code>sklearn2pmml.decoration.ContinuousDomain</code> transformation. It's impossible to say which column, and what is the exact nature of the problem (eg. categorical operational type instead of continuous, wrong numeric data type, <strong>co...
1
2016-08-17T06:42:18Z
[ "python", "scikit-learn", "svm", "pmml" ]
Padding in Panel and static text wrap in wxpython
38,989,282
<p>I would like to have a layout something like this</p> <p><a href="http://i.stack.imgur.com/NLjCQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/NLjCQ.png" alt="enter image description here"></a></p> <p>There is a Main Panel just inside the frame with blank padding in the left and right which another Sub Pa...
0
2016-08-17T06:14:04Z
39,005,419
<p>It is often helpful to set some background colours while trying to implement a layout with sizers, that way it's easy to visualize where the boundaries are, and how they behave while resizing things. Another helpful tool is the <a href="https://wiki.wxpython.org/Widget%20Inspection%20Tool" rel="nofollow">Widget Ins...
2
2016-08-17T20:09:34Z
[ "python", "user-interface", "layout", "wxpython", "wx" ]
How many times a number appears in succession without a break or change in number python/numpy
38,989,309
<p>I need to find the max consecutive number of times a number has appeared. Specifically 1 or 0 . To clarify. </p> <pre><code>a = [1,0,0,0,1,1,1,1,0,1] </code></pre> <p>What I want python to do is count how many times 1 and 0 appeared in succession. </p> <p>So for 1 the max it appeared in succession is 4 and for 0...
1
2016-08-17T06:15:59Z
38,989,521
<p>You can use <code>groupby</code></p> <pre><code>from itertools import groupby max_of_1 = max([i for i in [[key,len(list(group))] for key, group in groupby(a)] if i[0]])[1] max_of_0 = max([i for i in [[key,len(list(group))] for key, group in groupby(a)] if not i[0]])[1] </code></pre> <p><strong>Result</strong></p> ...
1
2016-08-17T06:30:09Z
[ "python", "numpy" ]
I want my board to be printed as a rhombus. So every previous line should have a smaller indentation than the next. How can I do that?
38,989,403
<pre><code>global counter global winner def initBoard(): global x global y x = int(input("Give x size for the board ")) while x &lt; 1 or x &gt; 20: x = int(input("Please give a valid input (between 1 and 20) ")) y = int(input("Give y size for the board ")) while y &lt; 1 or y &gt; 20: ...
-1
2016-08-17T06:22:10Z
38,990,768
<p>I believe this is what you are looking for:</p> <pre><code>global counter global winner def initBoard(): global x global y x = int(input("Give x size for the board ")) while x &lt; 1 or x &gt; 20: x = int(input("Please give a valid input (between 1 and 20) ")) y = int(input("Give y siz...
0
2016-08-17T07:40:27Z
[ "python" ]
Import error flask application
38,989,454
<p>I got this error running the application with this command 'python manage.py runserver'</p> <p>the error</p> <pre><code>C:\Users\Kamran\Envs\thermos\lib\site-packages\flask_sqlalchemy\__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the futu...
-2
2016-08-17T06:25:33Z
38,993,541
<p>It is not the Cirular Import problem, Its bad addressing the modules</p> <p>In the views.py</p> <pre><code>from flask import render_template, redirect, url_for, flash from thermos import models, app, db from forms import BookmarkForm from models import User, Bookmark </code></pre>
0
2016-08-17T10:02:54Z
[ "python", "flask", "import" ]
Why I can't instantiate a instance in the same module?
38,989,481
<p>Suppose my module is <code>myclass.py</code>, and here is the code:</p> <pre><code>#!/usr/bin/env python # coding=utf-8 class A(object): b = B() def __init__(self): pass class B(object): pass </code></pre> <p>and import it</p> <pre><code>In [1]: import myclass -------------------------------...
2
2016-08-17T06:27:00Z
38,989,614
<p>The class definition is a statement. When statement <code>AA</code> is executed, The statement of <code>BB</code> is not executed yet. Therefore, There is no class <code>B</code> yet and you get <code>NameError: name 'B' is not defined</code></p> <pre><code>class A(object): b = B() # &lt;== AA ...
8
2016-08-17T06:34:52Z
[ "python" ]
Why I can't instantiate a instance in the same module?
38,989,481
<p>Suppose my module is <code>myclass.py</code>, and here is the code:</p> <pre><code>#!/usr/bin/env python # coding=utf-8 class A(object): b = B() def __init__(self): pass class B(object): pass </code></pre> <p>and import it</p> <pre><code>In [1]: import myclass -------------------------------...
2
2016-08-17T06:27:00Z
38,989,669
<p>It should work if you do it like so:</p> <pre><code>class A(object): def __init__(self): self.b = B() class B(object): pass </code></pre> <p><strong>EDIT:</strong> You can do it like this if you want to write all the definitions of the class after you have written class A.</p> <pre><code>clas...
0
2016-08-17T06:38:10Z
[ "python" ]