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
Parse arithmetic string with regular expression
39,820,551
<p>I need to parse an arithmetic string with only <em>times</em> (<code>*</code>) and <em>add</em> (<code>+</code>), e.g., <code>300+10*51+20+2*21</code>, use regular expressions. </p> <p>I have the working code below: </p> <pre><code>import re input_str = '300+10*51+20+2*21' #input_str = '1*2+3*4' prod_re = re....
0
2016-10-02T19:02:17Z
39,821,045
<p>The algorithm seems not correct. An input of <code>1*2+3*4</code> does not yield a correct result. It seems wrong that after resolving one multiplication you continue to resolve an addition, while in some cases you would have to first resolve more multiplications before doing any additions.</p> <p>With some change ...
1
2016-10-02T19:52:17Z
[ "python", "regex", "math" ]
Parse arithmetic string with regular expression
39,820,551
<p>I need to parse an arithmetic string with only <em>times</em> (<code>*</code>) and <em>add</em> (<code>+</code>), e.g., <code>300+10*51+20+2*21</code>, use regular expressions. </p> <p>I have the working code below: </p> <pre><code>import re input_str = '300+10*51+20+2*21' #input_str = '1*2+3*4' prod_re = re....
0
2016-10-02T19:02:17Z
39,830,803
<p>The solution to your problem should be a possible sign preceded <code>term</code> followed by a list of terms, separated by an adding operator like in</p> <pre><code>[+-]?({term}([+-]{term})*) </code></pre> <p>in which each term is one factor, followed by a possible empty list of a multiplicative operator and anot...
0
2016-10-03T11:43:46Z
[ "python", "regex", "math" ]
Using pathlib/os.path etc correctly
39,820,595
<p>I was wondering how to use the os.path and pathlib correctly. I'm supposed to search for a directory(which I already did) and then after that enter a letter and space and it will decide what it will do.</p> <p>import os import os.path import shutil from pathlib import Path</p> <pre><code>def search_files(): di...
0
2016-10-02T19:06:04Z
39,822,114
<p>This script will do what you want. Along with using the result of your directory search function for the next call, I also changed the compare to use <code>.startswith</code> so that a emtpy string response doesn't crash the program.</p> <pre><code>import os from pathlib import * def search_files(): directory ...
0
2016-10-02T21:55:58Z
[ "python" ]
Cannot find the json via ajax
39,820,695
<p>I am trying to implement a simple web using flask. When I tried to read a local json data from python and pass it to the front end. It failed.</p> <p>My file hierarchy:</p> <pre><code>-app -static -data predict.json scripts.js -templates index.html models.py ...
0
2016-10-02T19:18:08Z
39,858,185
<p>The problem here is that the browser cache the javascript file, so that no matter what modification I made, it just failed to detect it.</p> <p>To avoid it, a smart way is to add change the js statement in html to href="xxx.js?ver=1.0"</p>
0
2016-10-04T17:17:01Z
[ "jquery", "python", "json", "ajax", "flask" ]
SyntaxError at Cloud9 IDE? Is this a bug or did I do something wrong?
39,820,713
<p>I believe I have found a bug with the Cloud9 IDE, as I get a syntax error in the following code: </p> <pre><code> for x in optionMenu: print x[0], x[1] action = raw_input ("Please select an action: ") if action == "1": direction = directionMenu() if direction =...
0
2016-10-02T19:19:38Z
39,820,907
<p>As I examine your code as posted here, the line <code>elif action == 4:</code> is preceded by 4 spaces then 2 tabs. Mixing spaces and tabs in Python is <em>a very bad idea</em>. I also see that some lines, such as the preceding one, use only spaces for indentation.</p> <p>Replace those two tabs, as well as any othe...
1
2016-10-02T19:38:54Z
[ "python", "syntax" ]
Using Selenium for Python Scripting
39,820,726
<p>I have written a <code>Python</code> code to open my gmail account. Here is the code that I am using:</p> <pre><code>from selenium import webdriver browser = webdriver.Firefox() browser.get('https://www.gmail.com') emailElem = browser.find_element_by_id('email') emailElem.send_keys(myemail) emailElem = browser.find...
-1
2016-10-02T19:20:41Z
39,820,787
<p>Experimentation. If the site is not showing a captcha to normal users you'll have to mimic being a human with your code. So that could mean that you use <code>time.sleep(x)</code> to make it seem like it takes a while before certain actions happen. </p> <p>Otherwise there are services out there that solve captchas ...
0
2016-10-02T19:26:41Z
[ "python", "selenium", "browser", "scripting" ]
Using Selenium for Python Scripting
39,820,726
<p>I have written a <code>Python</code> code to open my gmail account. Here is the code that I am using:</p> <pre><code>from selenium import webdriver browser = webdriver.Firefox() browser.get('https://www.gmail.com') emailElem = browser.find_element_by_id('email') emailElem.send_keys(myemail) emailElem = browser.find...
-1
2016-10-02T19:20:41Z
39,824,386
<p>If you perform the same actions repetitively, gmail(or any other site which tries to block automation) will identify your actions as automated ones. To get around this you need to pass random sleep time in your script. Also, switching between multiple credential helps.</p>
0
2016-10-03T03:54:45Z
[ "python", "selenium", "browser", "scripting" ]
Using Selenium for Python Scripting
39,820,726
<p>I have written a <code>Python</code> code to open my gmail account. Here is the code that I am using:</p> <pre><code>from selenium import webdriver browser = webdriver.Firefox() browser.get('https://www.gmail.com') emailElem = browser.find_element_by_id('email') emailElem.send_keys(myemail) emailElem = browser.find...
-1
2016-10-02T19:20:41Z
39,825,967
<p>For that you must used some Captcha resolver API. Here I will provide you website which provide text code of captcha <a href="https://2captcha.com/" rel="nofollow">https://2captcha.com/</a></p>
0
2016-10-03T06:53:59Z
[ "python", "selenium", "browser", "scripting" ]
Print the string, if string in the line ends with specific characters
39,820,840
<p>How do I print every string that ends on 'je' in a line</p> <p>For example : </p> <pre><code>for line in sys.stdin: for string in line: if string ends with 'je': print string </code></pre> <p>And only if the string ends with '....je' , so no 'je' included. And if the string ends with '.......
-3
2016-10-02T19:32:22Z
39,820,903
<p>Assuming that your string name dosent allow '?,.' at all, it should work.</p> <pre><code>for line in sys.stdin: for string in line: string = string.strip('.,?') if string.endswith('je'): print(string) </code></pre>
1
2016-10-02T19:38:39Z
[ "python", "string", "file", "character", "line" ]
Print the string, if string in the line ends with specific characters
39,820,840
<p>How do I print every string that ends on 'je' in a line</p> <p>For example : </p> <pre><code>for line in sys.stdin: for string in line: if string ends with 'je': print string </code></pre> <p>And only if the string ends with '....je' , so no 'je' included. And if the string ends with '.......
-3
2016-10-02T19:32:22Z
39,820,971
<p>There are two problems in your code. <code>for string in line:</code> will go through every single character, not through every word. By the way, you should not name your variable <code>string</code>. <code>for word in line.split():</code> will do what you expect.</p> <p>Also, <code>if string ends with 'je':</code>...
1
2016-10-02T19:44:05Z
[ "python", "string", "file", "character", "line" ]
iPython (python 2) - ImportError: No module named model_selection
39,820,893
<p>iPython Notebook Python 2</p> <p>Complaining about this line:</p> <pre><code>from sklearn.model_selection import train_test_split </code></pre> <p>Why isn't model selection working?</p>
0
2016-10-02T19:37:35Z
39,830,815
<p>In order to remedy this issue, you need to first find out if you are importing the actual <code>sklearn</code> package, and not just some script with the name <code>sklearn.py</code> saved somewhere in your working directory. The way Python imports modules is somewhat similar to the way it finds variables in its nam...
0
2016-10-03T11:44:23Z
[ "python", "scikit-learn", "ipython", "sklearn-pandas" ]
do action while raw_input is empty
39,820,909
<p>I'd like to do some actions while waiting for a user input: I was thinking of:</p> <pre><code>var = raw_input("what are you thinking about") while var == None: dosomethingwhilewaiting() print "input is:", var </code></pre> <p>but raw_input is blocking until a user input come in. Any ideas?</p>
0
2016-10-02T19:39:03Z
39,821,033
<p>you can use threads. </p> <pre><code>import thread import time var = None def get_input(): global var var = raw_input("what are you thinking about") thread.start_new_thread(get_input, ()) i = 0 while var == None: i += 0.1 time.sleep(0.1) print "input is:", var print "it took you %d seconds to ans...
1
2016-10-02T19:50:37Z
[ "python", "input" ]
Fastest way to select rows where value of column of strings is in a set
39,820,963
<p>I have a <code>set</code> of email addresses that I've selected from one set of values. I'd like to subset a <code>pandas DataFrame</code> to include only rows where the <code>unique_id</code> column value is not contained in the set. Here's what I've done that is running very slow:</p> <pre><code>signup_emails = s...
-2
2016-10-02T19:43:21Z
39,821,075
<p>Use the <code>isin</code> method.</p> <pre><code>event_attendees[event_attendees.isin(signup_emails)] </code></pre> <p>For not in the signup_emails, you can do</p> <pre><code>event_attendees[event_attendees.isin(signup_emails) == False] </code></pre>
1
2016-10-02T19:56:08Z
[ "python", "pandas" ]
Merge lists in specific order
39,821,023
<p>I have a list of lists and i want to merge the lists with an specific order. See example:</p> <pre><code>id list 0 1 2 [[0], [2, 6, 1, 4], [3, 7, 5]] Order Resulting List [1, 0, 2] = [2, 6, 1, 4, 0, 3, 7, 5] [0, 2, 1] = [0, 3, 7, 5, 2, 6, 1, 4] [2, 1, 0] = [3, 7, 5, 2, 6, 1, 4,...
0
2016-10-02T19:49:49Z
39,821,052
<p>This solution is basically identical to the one you proposed, but more Python-esque, using a list comprehension.</p> <pre><code>&gt;&gt;&gt; def merge_lists(desired_order): ... merged_list = [element for i in desired_order for element in parts[i]] ... return merged_list ... &gt;&gt;&gt; desired_order = ord...
1
2016-10-02T19:53:32Z
[ "python", "list", "merge" ]
Merge lists in specific order
39,821,023
<p>I have a list of lists and i want to merge the lists with an specific order. See example:</p> <pre><code>id list 0 1 2 [[0], [2, 6, 1, 4], [3, 7, 5]] Order Resulting List [1, 0, 2] = [2, 6, 1, 4, 0, 3, 7, 5] [0, 2, 1] = [0, 3, 7, 5, 2, 6, 1, 4] [2, 1, 0] = [3, 7, 5, 2, 6, 1, 4,...
0
2016-10-02T19:49:49Z
39,821,066
<p>You could use some other technique like a comprehension. The following will return a flat list:</p> <pre><code>return [part for order in orders for i in order for part in parts[i]] </code></pre> <p>And the following will return a 2D list:</p> <pre><code>return [[part for i in order for part in parts[i]] for order...
2
2016-10-02T19:55:24Z
[ "python", "list", "merge" ]
Merge lists in specific order
39,821,023
<p>I have a list of lists and i want to merge the lists with an specific order. See example:</p> <pre><code>id list 0 1 2 [[0], [2, 6, 1, 4], [3, 7, 5]] Order Resulting List [1, 0, 2] = [2, 6, 1, 4, 0, 3, 7, 5] [0, 2, 1] = [0, 3, 7, 5, 2, 6, 1, 4] [2, 1, 0] = [3, 7, 5, 2, 6, 1, 4,...
0
2016-10-02T19:49:49Z
39,821,172
<p>Just call itertools.chain on the indexes and combine with with <em>operator.itemgetter</em>:</p> <pre><code> frIn [9]: groups = [[0], [2, 6, 1, 4], [3, 7, 5]] In [10]: orders = [[0, 2, 1], [1, 0, 2], [2, 1, 0]] # Ord In [11]: from itertools import chain In [12]: from operator import itemgetter In [13]: [list(...
1
2016-10-02T20:07:22Z
[ "python", "list", "merge" ]
Merge lists in specific order
39,821,023
<p>I have a list of lists and i want to merge the lists with an specific order. See example:</p> <pre><code>id list 0 1 2 [[0], [2, 6, 1, 4], [3, 7, 5]] Order Resulting List [1, 0, 2] = [2, 6, 1, 4, 0, 3, 7, 5] [0, 2, 1] = [0, 3, 7, 5, 2, 6, 1, 4] [2, 1, 0] = [3, 7, 5, 2, 6, 1, 4,...
0
2016-10-02T19:49:49Z
39,821,173
<pre><code>inputs = [[1,2,3], [4,5,6], [7]] orders = [[0,1,2], [2,1,0]] result = [input_element for order in orders for order_element in order for input_element in inputs[order_element]] print(result) </code></pre>
0
2016-10-02T20:07:27Z
[ "python", "list", "merge" ]
Limits of hashes comparisons
39,821,040
<p>I'm storing hash codes in a file, one hash per line.</p> <p>When I have a new hash code, I open the file and check if the hash code already exists and if it doesn't exist, I save it to that file.</p> <pre><code>f = open("hashes.txt", "w") hashes = f.readlines() hash_code = "ff071fdf1e060400" if not hash_code in ha...
-1
2016-10-02T19:51:27Z
39,821,152
<p>I would agree with Bert on this. If you expect that there will be a lot of hashes it would be better to use a database. If this only happens locally a sqlite database is fine. There is an excellent orm library that works for sqlite; <a href="http://docs.peewee-orm.com/en/latest/" rel="nofollow">Peewee</a>. It got so...
1
2016-10-02T20:05:19Z
[ "python", "hash" ]
Limits of hashes comparisons
39,821,040
<p>I'm storing hash codes in a file, one hash per line.</p> <p>When I have a new hash code, I open the file and check if the hash code already exists and if it doesn't exist, I save it to that file.</p> <pre><code>f = open("hashes.txt", "w") hashes = f.readlines() hash_code = "ff071fdf1e060400" if not hash_code in ha...
-1
2016-10-02T19:51:27Z
39,821,156
<p>A <a href="https://docs.python.org/3.6/library/stdtypes.html#set" rel="nofollow">set</a> can be used for fast membership lookups. Since files can be used as an iterator, passing an open file handle to the set constructor will read entries into the set by line without first filling an intermediate in-memory array.</p...
1
2016-10-02T20:05:43Z
[ "python", "hash" ]
Limits of hashes comparisons
39,821,040
<p>I'm storing hash codes in a file, one hash per line.</p> <p>When I have a new hash code, I open the file and check if the hash code already exists and if it doesn't exist, I save it to that file.</p> <pre><code>f = open("hashes.txt", "w") hashes = f.readlines() hash_code = "ff071fdf1e060400" if not hash_code in ha...
-1
2016-10-02T19:51:27Z
39,821,643
<p>I would do this:</p> <pre><code>class Hashes(object): def __init__(self, filename): self.filename = filename with open(filename, 'rt') as f: # read the file only once self.hashes = set(line.strip() for line in f) def add_hash(self, hash): if hash not in self....
2
2016-10-02T20:57:37Z
[ "python", "hash" ]
What's the difference between Celery task and subtask?
39,821,099
<p>If I understood the tutorial correctly, Celery <em>subtask</em> supports almost the same API as <em>task</em>, but has the additional advantage that it can be passed around to other functions or processes.</p> <p>Clearly, if that was the case, Celery would have simply replaced <em>tasks</em> with <em>subtasks</em> ...
1
2016-10-02T19:59:50Z
39,832,523
<p>You will take the difference into account when you start using <a href="http://docs.celeryproject.org/en/latest/userguide/canvas.html" rel="nofollow">complex workflows</a> with celery.</p> <blockquote> <p>A signature() wraps the arguments, keyword arguments, and execution options of a single task invocation in ...
1
2016-10-03T13:11:56Z
[ "python", "celery" ]
reading *.lz4 file in python
39,821,116
<p>I have a huge number of tweet data that are compressed in lz4 formats. I'd like to open each file and decompress it, and extract some information from python. </p> <p>When I decompress the file using <code>lz4c -d</code> command in Ubuntu, the file decompresses just fine. But when I use <code>lz4.loads('path_to_fil...
0
2016-10-02T20:00:57Z
39,821,165
<p><code>lz4.loads()</code> decompresses the string you pass to it and not the file path in that string. It doesn't seem like this library supports opening files, so you have to read the data yourself.</p> <pre><code>lz4.loads(open('path_to_file', 'rb').read()) </code></pre>
0
2016-10-02T20:06:49Z
[ "python", "lz4" ]
reading *.lz4 file in python
39,821,116
<p>I have a huge number of tweet data that are compressed in lz4 formats. I'd like to open each file and decompress it, and extract some information from python. </p> <p>When I decompress the file using <code>lz4c -d</code> command in Ubuntu, the file decompresses just fine. But when I use <code>lz4.loads('path_to_fil...
0
2016-10-02T20:00:57Z
39,821,362
<p>Try with the lz4tools package instead: <a href="https://pypi.python.org/pypi/lz4tools" rel="nofollow">https://pypi.python.org/pypi/lz4tools</a></p> <p>My test fails with <code>lz4</code></p> <pre><code>&gt;&gt;&gt; lz4.loads(open("test.js.lz4","rb").read()) Traceback (most recent call last): File "&lt;stdin&gt;"...
0
2016-10-02T20:26:32Z
[ "python", "lz4" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,179
<pre><code>[sublist[::-1] for sublist in to_reverse[::-1]] </code></pre> <p>List comprehension works here. <code>[::-1]</code> is basically the same as <code>reversed</code>, but does not modify the list.</p> <p>EDIT:</p> <p>As pointed out below, <code>reversed</code> doesn't modify the list. It returns a <code>li...
4
2016-10-02T20:08:48Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,238
<p>This looks very familiar :). I'm not going to give the whole working solution but here are some tips:</p> <p>As you know, there are two steps, reverse each sub-list and then reverse the outer list (in place, without making a new list, so it will mutate the global <code>L</code>).</p> <p>So you can loop through th...
0
2016-10-02T20:14:27Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,239
<p>You could make this recursive, so it will work for arbitrarily deep nests.</p> <p>something like (UNTESTED):</p> <pre><code>def deep_reverse(L) """ assumes L is a list of lists whose elements are ints Mutates L such that it reverses its elements and also reverses the order of the int elements in ...
-1
2016-10-02T20:14:31Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,379
<p>This should do the trick.</p> <pre><code>L = [[1, 2], [3, 4], [5, 6, 7]] def deep_reverse(L): for i in range(len(L)): L[i]=L[i][::-1] L=L[::-1] return L </code></pre>
1
2016-10-02T20:28:50Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,514
<p>Alternatively you use <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow"><code>map()</code></a> to achieve this as:</p> <pre><code>&gt;&gt;&gt; map(lambda x: x[::-1], L[::-1]) # In Python 2.x [[7, 6, 5], [4, 3], [2, 1]] &gt;&gt;&gt; list(map(lambda x: x[::-1], L[::-1])) # In Python...
0
2016-10-02T20:42:43Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
How to reverse the elements in a sublist?
39,821,166
<p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist. for example:</p> <p>For example, if L = [[1, 2], [3, 4], [5, 6, 7]] then deep_reverse(L) mutates L to be [[7, 6, 5], [4, 3], [2, 1]]</p> <p>I figured out how to reverse the order of one l...
4
2016-10-02T20:06:54Z
39,821,639
<blockquote> <p>I'm trying to create a function that reverses the order of the elements in a list, and also reverses the elements in a sublist.</p> </blockquote> <p>Then do exactly those two things:</p> <pre><code>L.reverse() for sublist in L: sublist.reverse() </code></pre> <hr> <p>Full demo because you seem...
2
2016-10-02T20:57:03Z
[ "python", "list", "python-3.x", "reverse", "sublist" ]
Python PyQt on mac OSX Sierra
39,821,177
<p>Does anyone know if I can get to work PyQt 4 or 5 on a mac with the new OSX Sierra? It seems that I have to wait for a new version of PyQt but I am not sure if that is actually true. Thanks</p>
0
2016-10-02T20:08:22Z
39,974,832
<p>The easiest way to install PyQt (4 or 5) on OSX is probably using <a href="http://homebrew.sh" rel="nofollow">Homebrew</a>. This will also install a separate standalone Python from the system Python, meaning it will continue to work without problems following any future system updates. </p> <p>According to this <a ...
0
2016-10-11T10:02:47Z
[ "python", "osx", "pyqt" ]
How to parse Omnifocus XML data for details about a particular task?
39,821,208
<p>Considering that Omnifocus does not have an API, I've created a script that pulls Omnifocus Data which is in XML format on a recurring basis</p> <p><a href="https://gist.githubusercontent.com/ChrismCruz/3612fdbe9f7baeef0c668113ca15fd17/raw/e6c8ca70bedc23456f499bca8dcc499a787f4018/gistfile1.txt" rel="nofollow">See l...
0
2016-10-02T20:10:31Z
39,831,552
<p>You just need to use the <em>name</em> text to find the node then just call <em>.parent</em> to get the <em>task</em> node.</p> <pre><code>In [55]: task Out[55]: &lt;task id="lyZY7EINc02" op="update"&gt;&lt;added&gt;2016-10-02T19:53:09.672Z&lt;/added&gt;&lt;modified&gt;2016-10-02T19:53:13.912Z&lt;/modified&gt;&lt;n...
0
2016-10-03T12:22:39Z
[ "python", "xml", "parsing", "beautifulsoup", "omnifocus" ]
Convert number values into ascii characters?
39,821,249
<p>The part where I need to go from the number values I obtained to characters to spell out a word it not working, it says I need to use an integer for the last part?</p> <p>accept string</p> <pre><code>print "This program reduces and decodes a coded message and determines if it is a palindrome" string=(str(raw_input...
0
2016-10-02T20:16:02Z
39,821,326
<p>It looks like you have a list of lists instead of a list of ints when you call <code>result.append([code-offset])</code>. This means later when you call <code>chr(i) for i in result</code>, you are passing a list instead of an int to <code>chr()</code>.</p> <p>Try changing this to <code>result.append(code-offset)</...
0
2016-10-02T20:23:08Z
[ "python", "ascii", "chr" ]
Convert number values into ascii characters?
39,821,249
<p>The part where I need to go from the number values I obtained to characters to spell out a word it not working, it says I need to use an integer for the last part?</p> <p>accept string</p> <pre><code>print "This program reduces and decodes a coded message and determines if it is a palindrome" string=(str(raw_input...
0
2016-10-02T20:16:02Z
39,821,356
<p>You are passing a list to <code>chr</code> when it only accepts integers. Try <code>result.append(code-offset)</code>. <code>[code-offset]</code> is a one-item list.</p> <p>Specifically, instead of:</p> <pre><code>result=[] for i in string_lowercase: code=ord(i) result.append([code-offset]) </code></pre> ...
0
2016-10-02T20:25:48Z
[ "python", "ascii", "chr" ]
Convert number values into ascii characters?
39,821,249
<p>The part where I need to go from the number values I obtained to characters to spell out a word it not working, it says I need to use an integer for the last part?</p> <p>accept string</p> <pre><code>print "This program reduces and decodes a coded message and determines if it is a palindrome" string=(str(raw_input...
0
2016-10-02T20:16:02Z
39,821,406
<p>While doing <code>.append()</code> to list, use <code>code-offset</code> instead of <code>[code-offset]</code>. As in later you are storing the value as a list (of one ASCII) instead of storing the ASCII value directly.</p> <p>Hence your code should be:</p> <pre><code>result = [] for i in string_lowercase: cod...
0
2016-10-02T20:31:32Z
[ "python", "ascii", "chr" ]
Why numpy performs worst on a more powerful computer?
39,821,339
<p>I have 2 computers:</p> <ol> <li>A 2012 Dell Latitude, with a Intel i5 processor, 4 gb of Ram.</li> <li>A 2016 MacBook Pro, with a (last generation) Intel i5 processor 8 gb of ram.</li> </ol> <p>Then, I also have Python program that does extensive use of numpy's libraries, that is able to run on both the computers...
-4
2016-10-02T20:24:29Z
39,828,735
<p>Valid question imo. If I had to guess, from most likely to less likely:</p> <ol> <li><p>The numpy on the 2012 system uses faster BLAS/LAPACK libraries. You can check which are used by running <code>numpy.show_config()</code> on both systems.</p></li> <li><p>The processor in the 2012 system may actually be faster th...
3
2016-10-03T09:45:33Z
[ "python", "numpy" ]
python passlib verify doesn't match
39,821,369
<p>I am working with Flask and MongoDB, trying to implement username / password verification with passlib.</p> <p>The class from models.py : </p> <pre><code>from passlib.hash import sha256_crypt class Users(object): def __init__(self, username='', password='', collection=db.users, articles=''): self.collecti...
0
2016-10-02T20:27:26Z
39,821,478
<p>That is happening because you're encrypting not <code>self.password</code> but <code>'self.password'</code></p> <p>So you need to change your <code>addUser</code> method to the following:</p> <pre><code>def addUser(self): self.collection.insert({'username': self.username, 'password': sha256_crypt.encrypt(self....
0
2016-10-02T20:38:56Z
[ "python", "mongodb", "passlib" ]
Numpy not found in Python3
39,821,470
<p>I am trying to run numpy in Python 3, using the WinPy distribution. I put #!python3 at the top of the script, because I was told that is something that Winpy has that allows you to make it run in a certain version. If I run the script in the shell(Eclipse) it works fine, but when I try to run it from the console, I ...
0
2016-10-02T20:38:10Z
39,821,932
<p>The "#!python3" is to help the console determine the right version of python. However you need to make sure the path is correct. Instead of putting "#!python3", put "#!/usr/bin/" and then your python version, so "python" or "python3". </p> <p>Check this article for more information on this. <a href="http://stackove...
0
2016-10-02T21:35:38Z
[ "python", "numpy" ]
Many Selenium browsers doing the same task (python)
39,821,619
<p>I have a list of ids that identify websites. I need to do this:</p> <pre><code>Open a browser open a main website that allows a query for id in ids: -search in the main website the id, so that I get the website corresponding to the id with the browser -load the website corresponding to id with the brows...
0
2016-10-02T20:54:45Z
39,822,195
<p>If you think that splitting it in two parts will help speed up things then you can do this (furthering the split technique).</p> <p>1) Write a function that takes as argument the id of a website.</p> <p>2) Write a for loop which calls the def again and again sending the nenxt id.</p> <p>Something like this:</p> ...
0
2016-10-02T22:05:12Z
[ "python", "selenium", "parallel-processing" ]
List index out of range though appearing not to be
39,821,646
<p>I wrote a simple program to check if strings are substrings of eachother. The issue is I keep getting a list index out of bounds error.</p> <p>I tried printing i and j with each iteration and they never go out of the bounds of the list. I even tried to insert elements at s[5] and s[6] to check the index but still g...
0
2016-10-02T20:59:01Z
39,821,680
<p>You seem to increase j only when i is already 5 (notice the <code>and</code> in the if-clause). Thus, when i=5 you are still in the while loop (which only depends on j) and you try to access s[i] = s[5] which is undefined.</p>
0
2016-10-02T21:03:26Z
[ "python", "python-3.x", "indexing" ]
List index out of range though appearing not to be
39,821,646
<p>I wrote a simple program to check if strings are substrings of eachother. The issue is I keep getting a list index out of bounds error.</p> <p>I tried printing i and j with each iteration and they never go out of the bounds of the list. I even tried to insert elements at s[5] and s[6] to check the index but still g...
0
2016-10-02T20:59:01Z
39,821,700
<p>At the point when your code is raising the exception, the value of <code>i</code> is <code>5</code> and the value of <code>j</code> is 4. In your <code>print</code> statement you try to do <code>s[i]</code> i.e. <code>s[5]</code>and since max index of s is <code>4</code>, your code is raising <code>IndexError</code>...
0
2016-10-02T21:05:33Z
[ "python", "python-3.x", "indexing" ]
List index out of range though appearing not to be
39,821,646
<p>I wrote a simple program to check if strings are substrings of eachother. The issue is I keep getting a list index out of bounds error.</p> <p>I tried printing i and j with each iteration and they never go out of the bounds of the list. I even tried to insert elements at s[5] and s[6] to check the index but still g...
0
2016-10-02T20:59:01Z
39,821,712
<p>The problem is in the line 18</p> <pre><code>s = [] s.insert(0,str("a b c")) s.insert(1,str("a b c d")) s.insert(2,str("a b")) s.insert(3,str("b c")) s.insert(4,str("d")) print(s) j = 0 i = 0 while j &lt; 5: if s[j] in s[i]: print("\"" + s[j] + "\" is in the str...
1
2016-10-02T21:07:20Z
[ "python", "python-3.x", "indexing" ]
List index out of range though appearing not to be
39,821,646
<p>I wrote a simple program to check if strings are substrings of eachother. The issue is I keep getting a list index out of bounds error.</p> <p>I tried printing i and j with each iteration and they never go out of the bounds of the list. I even tried to insert elements at s[5] and s[6] to check the index but still g...
0
2016-10-02T20:59:01Z
39,821,791
<p>Your i and j variables in while loop are incorrect. After changing values following code is working. </p> <pre><code>s = [] s.insert(0,str("a b c")) s.insert(1,str("a b c d")) s.insert(2,str("a b")) s.insert(3,str("b c")) s.insert(4,str("d")) print s j = 0 i = 0 while j &l...
0
2016-10-02T21:16:42Z
[ "python", "python-3.x", "indexing" ]
List index out of range though appearing not to be
39,821,646
<p>I wrote a simple program to check if strings are substrings of eachother. The issue is I keep getting a list index out of bounds error.</p> <p>I tried printing i and j with each iteration and they never go out of the bounds of the list. I even tried to insert elements at s[5] and s[6] to check the index but still g...
0
2016-10-02T20:59:01Z
39,821,826
<p>Keeping your form it would be:</p> <pre><code>s = [] s.insert(0,str("a b c")) s.insert(1,str("a b c d")) s.insert(2,str("a b")) s.insert(3,str("b c")) s.insert(4,str("d")) j = 0 i = 0 while j &lt; 5: if s[j] in s[i]: print("\"" + s[j] + "\" is in the string \"" ...
0
2016-10-02T21:21:01Z
[ "python", "python-3.x", "indexing" ]
GnuPlot auto set xlabel (or ylabel), reading from column head of CSV file
39,821,685
<p>In GnuPlot, I can auto set a plot legend with <code>title columnhead</code> option in a plot command like:</p> <pre><code>plot 'test.txt' using 0:1 w linespoints title columnhead </code></pre> <p>So it reads the column name from the CSV file and use it in the legend.</p> <p><a href="http://i.stack.imgur.com/1YO6S...
0
2016-10-02T21:03:49Z
39,838,857
<p>as pointed out by @Christoph, the <code>system</code> command is probably the only viable solution - in your particular case, you could do:</p> <pre><code>fname="test.txt" getTitle(colNum)=system(sprintf("head -n1 '%s' | cut -f%d -d';'", fname, colNum+1)) set xlabel getTitle(0) set ylabel getTitle(1) </code></pre...
0
2016-10-03T19:16:23Z
[ "python", "gnuplot" ]
Testing a time-dependent method
39,821,687
<p>I have a method that takes a datetime and returns what period of time this datetime belongs to, for example "yesterday" or "a month ago".</p> <pre><code>from datetime import datetime def tell_time_ago(basetime): difference = datetime.now() - basetime days = difference.days seconds = difference.second...
2
2016-10-02T21:04:11Z
39,822,174
<p>In general, I think it's a good idea to make your nontrivial functions and classes as close to mathematical functions (e.g., <code>sin(x)</code>), as possible. Given the same input, a mathematical function gives the same output each time, irrespective of the current date, random choices, and so forth. </p> <ul> <li...
1
2016-10-02T22:03:22Z
[ "python", "unit-testing" ]
Scrapy - print pipeline data in a script's context
39,821,693
<p>After using <code>scrapy</code> <code>framework</code>, I would like to process my <code>pipeline.py</code> output within my <code>python</code> script context.</p> <p>The pipeline output is <code>tracks.jl</code>, as follows:</p> <p><strong>pipeline.py</strong></p> <pre><code>class PitchforkTracks(object): ...
0
2016-10-02T21:04:39Z
39,834,084
<p>I think it's because your pipeline never closes the file object. You should open a file in your pipeline's <code>open_spider()</code> method and close it in <code>close_spider()</code> method.</p> <pre><code>class PitchforkTracks(object): def open_spider(self, spider): self.file = open('tracks.jl', 'wb...
0
2016-10-03T14:31:04Z
[ "python", "scrapy" ]
Save a matrix as an image without changes after recovery
39,821,756
<p>I need to save matrix as an image, so, that after back reading, initial and recovered matrices be the same. I have the code:</p> <pre><code>import scipy.misc def get_matrix(N, M): import random matrix = [[ random.randint(1, 100) for j in range(M) ] for i in range(N)] return matrix def equal(matA, m...
0
2016-10-02T21:12:52Z
39,822,184
<p>If you're willing to use matplotlib or scikit-image, these libraries have built-in functionality for what you want. Otherwise take a look at the imageio package.</p>
1
2016-10-02T22:04:08Z
[ "python", "matrix", "scikit-image" ]
Optional return type annotations?
39,821,758
<p>I have a function that will either return a generator (<code>types.GeneratorType</code>) or <code>list</code>, depending upon the value of an argument. For example:</p> <pre><code>def foo(switch: bool) -&gt; list: # return type of list || types.GeneratorType ... # create some generator object named f1 if sw...
0
2016-10-02T21:13:23Z
39,821,835
<p>The two solutions that immediately spring to mind are: </p> <ol> <li><p>Make a <a href="https://docs.python.org/3/library/typing.html#typing.Union" rel="nofollow"><code>Union</code></a> type</p> <pre><code>def foo(switch: bool) -&gt; Union[list, GeneratorType]: </code></pre> <p>which means <em>"returns either lis...
3
2016-10-02T21:21:53Z
[ "python", "python-3.x", "annotations", "type-hinting" ]
Optional return type annotations?
39,821,758
<p>I have a function that will either return a generator (<code>types.GeneratorType</code>) or <code>list</code>, depending upon the value of an argument. For example:</p> <pre><code>def foo(switch: bool) -&gt; list: # return type of list || types.GeneratorType ... # create some generator object named f1 if sw...
0
2016-10-02T21:13:23Z
39,821,846
<p>Wouldn't it be better to pass "type" as an argument? </p> <pre><code>def foo(switch: type) -&gt; list | tuple | gen_func ... # create some generator object named f1 return switch(f1) foo(list) &gt; list type foo(tuple) &gt; tuple # And if you would want to get generator you would only need to provide g...
0
2016-10-02T21:23:04Z
[ "python", "python-3.x", "annotations", "type-hinting" ]
recurDescents(p) and recurAncestors(p)
39,821,762
<p>I need to write a Python script with two functions. One function is to return the descendants children of (p) and Take (p) and return ancestors of (p). </p> <p>I made a script that returns the children of (p). </p> <pre><code>parent = [("Homer","Bart"),("Homer","Lisa"),("Abe","Homer"),("Bart","Jim"),("Jim","Kim"),...
0
2016-10-02T21:13:49Z
39,821,844
<p>Your return statements are in the wrong places. They should be outside the loops:</p> <pre><code>def f(): for loop stuff return ... </code></pre> <p>If you want a slightly more concise version:</p> <pre><code>#find children of parent p [child for parent, child in list_of_parents if parent == p] #...
0
2016-10-02T21:22:43Z
[ "python", "python-3.x" ]
try / except loop with bash terminal command as interrupt
39,821,895
<p>I'm using a simple python.py script in Linux. I need to run a while/counter loop and would like to stop the loop immediately by using a/any terminal command. I need to run the script using Screen. Simply stopping the Screen session doesn't work - it only stops the current process in the loop and then continues with ...
0
2016-10-02T21:30:26Z
39,919,330
<p>If this is linux then you can use Operating System Signals. Just create a signal handler that throws an exception and catch that exception. Register the signal handler with</p> <pre><code>signal.signal(signal.SIGINT, handler) </code></pre> <p>This will register the handler function to be called when ever the SIGIN...
0
2016-10-07T14:11:12Z
[ "python", "gnu-screen" ]
How to correctly overload a variable in class inheritance with the same variables
39,821,911
<p>I need to override or overload a variable in a class inheritance. Here is what I am trying to achieve:</p> <pre><code>class MainClass: def __init__(self, a, b, c, d): type(a) = str class MyClass(MainClass): def __init__(self, a, b, c, d): type(a) = object of one of my classes. </code></pre> ...
-2
2016-10-02T21:32:25Z
39,822,319
<p>What it seems like you're trying to do is make each class able to access the other. However this is not how class inheritance works. Try using this for the classes to access each other. </p> <pre><code>class MainClass: def __init__(self, a, b, c): # main class with variables, a, b and c. self.a = a ...
0
2016-10-02T22:21:21Z
[ "python", "python-3.x", "inheritance" ]
How to correctly overload a variable in class inheritance with the same variables
39,821,911
<p>I need to override or overload a variable in a class inheritance. Here is what I am trying to achieve:</p> <pre><code>class MainClass: def __init__(self, a, b, c, d): type(a) = str class MyClass(MainClass): def __init__(self, a, b, c, d): type(a) = object of one of my classes. </code></pre> ...
-2
2016-10-02T21:32:25Z
39,822,614
<p> So you are trying to <em>reset</em> the variable.<br> Really, it's the same as creating the variable for the first time.</p> <pre class="lang-py prettyprint-override"><code>class Base: var = 12 class Cls(Base): var = 'abc' </code></pre> <p>The class's variables are copied when you create a new class, so t...
0
2016-10-02T23:03:57Z
[ "python", "python-3.x", "inheritance" ]
Error when trying to get the union, intersection and difference in a set
39,821,918
<p>As the title says, I am getting an error in my code here:</p> <pre><code>#!/usr/bin/python3 import random A = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5) B = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5) print(A | B) print(A &amp; B) print(A - B) </code></pre> <p>The error I'm getting is...
0
2016-10-02T21:33:37Z
39,822,013
<p>So, as error says, function: </p> <pre><code>random.sample </code></pre> <p>returns <strong>list</strong> object not <strong>set</strong> , try convert them like this :</p> <pre><code>A = set(random.sample(range(1,10), 5)) </code></pre>
0
2016-10-02T21:44:28Z
[ "python", "python-3.x" ]
Error when trying to get the union, intersection and difference in a set
39,821,918
<p>As the title says, I am getting an error in my code here:</p> <pre><code>#!/usr/bin/python3 import random A = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5) B = random.sample(set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), 5) print(A | B) print(A &amp; B) print(A - B) </code></pre> <p>The error I'm getting is...
0
2016-10-02T21:33:37Z
39,822,337
<p>Try this:</p> <pre><code>import random A = set(random.sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)) B = set(random.sample([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)) print(A | B) print(A &amp; B) print(A - B) </code></pre> <p>It should produce the following output:</p> <pre><code>{2, 3, 4, 5, 6, 7, 10} {2, 4, 6} {10...
0
2016-10-02T22:23:12Z
[ "python", "python-3.x" ]
TensorFlow feed an integer
39,821,942
<p>I am trying to do a convolution over variable input sizes. To achieve that, I am using a batch size of 1. However, one of the nodes is a max pooling node which needs the shape of the input as a list <code>ksize</code>:</p> <pre><code> pooled = tf.nn.max_pool( h, ksize=[1, self.input_...
0
2016-10-02T21:36:57Z
39,834,890
<p>I'm not sure that it's the best way, but you can get dynamically the shape of <code>self.input_x</code> in a list with :</p> <pre><code>input_shape = tf.unpack(tf.shape(self.input_x)) </code></pre> <p><code>tf.shape(self.input_x)</code> give you a Tensor representing the shape of self.input_x and <code>f.unpack</c...
0
2016-10-03T15:14:09Z
[ "python", "neural-network", "tensorflow", "convolution", "conv-neural-network" ]
Turtle and drawing tree with RapydScript
39,822,008
<p>today I want draw a tree in browser with RapydScript. I have code in Python:</p> <pre><code>import random import turtle def tree(size, myTurtle): myTurtle.pensize(size / 20) if size &lt; random.randint(1,2) * 20: myTurtle.color("green") else: myTurtle.color("brown") if size &gt; 5...
1
2016-10-02T21:43:48Z
39,825,291
<p>See <code>src/lib</code> in <a href="https://github.com/atsepkov/RapydScript" rel="nofollow">RapydScript repo</a> - there is no <code>turtle</code> module. And it can't import turtle module from Python because it doesn't draw on canvas in browser. So you can't draw tree if you doesn't create turtle module.</p>
2
2016-10-03T05:53:21Z
[ "python", "browser", "turtle-graphics", "rapydscript" ]
Turtle and drawing tree with RapydScript
39,822,008
<p>today I want draw a tree in browser with RapydScript. I have code in Python:</p> <pre><code>import random import turtle def tree(size, myTurtle): myTurtle.pensize(size / 20) if size &lt; random.randint(1,2) * 20: myTurtle.color("green") else: myTurtle.color("brown") if size &gt; 5...
1
2016-10-02T21:43:48Z
39,831,709
<p>As @furas mentioned, there is no <code>turtle</code> module in the base repo. First of all, I think you're misunderstanding what the <code>turtle</code> module is, it's nothing more than an abstraction around another graphics library. Even in Python, it's not the preferred way of handling graphics, it's just a subse...
2
2016-10-03T12:30:23Z
[ "python", "browser", "turtle-graphics", "rapydscript" ]
getting transaction result from transaction module
39,822,021
<p>I am using Sqlalchemy and PostgreSQL. In my models I have a <code>Product</code> and an <code>Image</code>. I want each product to have multiple images. This is the product submission method:</p> <pre><code>def submit_product(self, **kwargs): product = Product( title=kwargs['title'], sub_catego...
0
2016-10-02T21:45:56Z
39,822,439
<p>After using:</p> <pre><code>transaction.commit() </code></pre> <p>you can use <code>product.id</code>, because changes have been commited. So product has now its id:</p> <pre><code>for image in kwargs['images']: image = Image( product_id=product.id, # what should I put here?, image=image.file....
1
2016-10-02T22:35:50Z
[ "python", "sqlalchemy" ]
getting transaction result from transaction module
39,822,021
<p>I am using Sqlalchemy and PostgreSQL. In my models I have a <code>Product</code> and an <code>Image</code>. I want each product to have multiple images. This is the product submission method:</p> <pre><code>def submit_product(self, **kwargs): product = Product( title=kwargs['title'], sub_catego...
0
2016-10-02T21:45:56Z
39,860,183
<p>the trick is to <code>DBSession.flush()</code> after adding the image so the adding will be done and <code>product.id</code> will be accessible .</p>
1
2016-10-04T19:22:43Z
[ "python", "sqlalchemy" ]
flask Sqlalchemy One to Many getting parent attributes
39,822,087
<p>Im trying to get the Pet owner or persons name</p> <pre><code>class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20)) pets = db.relationship('Pet', backref='owner', lazy='dynamic') class Pet(db.Model): id = db.Column(db.Integer, primary_key=...
2
2016-10-02T21:53:06Z
39,822,369
<pre><code>pets = db.session.query(Pet, Person.name).join(Person) for pet, person_name in pets: print pet.name, person_name </code></pre> <p>Using that type of querying we force SQLAlchemy to use Mapping of <code>pet</code> table to <code>Pet</code> object and get <code>Person</code>'s name as second item in sele...
1
2016-10-02T22:27:11Z
[ "python", "flask", "sqlalchemy", "flask-sqlalchemy" ]
Index out of range using Flask/Python
39,822,159
<p>I am working on a web app and running into some issues with the following code. I have a database where I need to update a value. When I try to update the value I am getting an index out of range error, however when I run the code with just python not using the web part it runs and performs as expected.. I cannot fi...
2
2016-10-02T22:01:51Z
39,822,258
<p>I could think of two possible reasons:</p> <ol> <li>Database configuration you are using with/without Flask are different</li> <li>Check the <code>type</code> and value of your <code>user_id</code> in both the code. It might be different.</li> </ol>
0
2016-10-02T22:12:50Z
[ "python", "flask", "sqlite3", "jinja2" ]
Flask URL variable type None?
39,822,188
<p>I'm trying to pass a number through URL and retrieve it on another page. If I try to specify the variable type, i get a malformed URL error and it won't compile. If I don't specify the var type, it will run, but the variable becomes Type None. I can't cast it to an int either. How can I pass it as an Integer...? Tha...
2
2016-10-02T22:04:34Z
39,822,237
<p>In your second example, instead of <code>num = request.args.get('num')</code> try to simply use <code>num</code>. Since you specified it as an input to your route/function, you should be able to access it directly. </p>
1
2016-10-02T22:10:02Z
[ "python", "flask" ]
Flask URL variable type None?
39,822,188
<p>I'm trying to pass a number through URL and retrieve it on another page. If I try to specify the variable type, i get a malformed URL error and it won't compile. If I don't specify the var type, it will run, but the variable becomes Type None. I can't cast it to an int either. How can I pass it as an Integer...? Tha...
2
2016-10-02T22:04:34Z
39,822,292
<p>Try this:</p> <pre><code>@app.route('/iLike/&lt;int:num&gt;', methods=['GET','POST']) def single2(num): print(num) </code></pre>
1
2016-10-02T22:16:45Z
[ "python", "flask" ]
Flask URL variable type None?
39,822,188
<p>I'm trying to pass a number through URL and retrieve it on another page. If I try to specify the variable type, i get a malformed URL error and it won't compile. If I don't specify the var type, it will run, but the variable becomes Type None. I can't cast it to an int either. How can I pass it as an Integer...? Tha...
2
2016-10-02T22:04:34Z
39,822,302
<p>You are mixing route parameters and request arguments here.</p> <p>Parameters you specify in the route are route parameters and are a way to declare <a href="http://flask.pocoo.org/docs/0.11/quickstart/#variable-rules" rel="nofollow">variable routes</a>. The values for these parameters are passed as function argume...
3
2016-10-02T22:17:42Z
[ "python", "flask" ]
Flask URL variable type None?
39,822,188
<p>I'm trying to pass a number through URL and retrieve it on another page. If I try to specify the variable type, i get a malformed URL error and it won't compile. If I don't specify the var type, it will run, but the variable becomes Type None. I can't cast it to an int either. How can I pass it as an Integer...? Tha...
2
2016-10-02T22:04:34Z
39,822,311
<p>You recieve <code>None</code> here:</p> <pre><code>num = request.args.get('num') </code></pre> <p>because you're not passing <code>num</code> as element of querystring.</p> <p>When use <code>request.args.get('num')</code>?</p> <p>If we would have URL like this one:</p> <pre><code>localhost:8080/iLike?num=2 </co...
1
2016-10-02T22:19:42Z
[ "python", "flask" ]
What effect did DataFrame.loc() cause on the data frame?
39,822,219
<p>I used numpy.random.permutation() to generate random order to an original data frame X and want to assign whole X to X_perm by the random order. </p> <pre><code>X_perm=X y_perm=y perm = np.random.permutation(X.shape[0]) for i in range(len(perm)): X_perm.loc[i]=(X.loc[perm[i]]) y_perm.loc[i]=(y.loc[perm[i]]) </...
0
2016-10-02T22:07:57Z
39,822,317
<p>The reason for this unexpected behavior is that X_perm is not an array that is independent of X. X_perm is a reference to X. So modifications to X_perm are also modifications made to X.</p> <p>To demonstrate this:</p> <pre><code>import numpy as np a = np.arange(16) print a b = a # as your X_perm = X print b # sa...
0
2016-10-02T22:20:58Z
[ "python", "numpy" ]
Flask Testing - How to retrieve variables that were passed to Jinja?
39,822,265
<p>In Flask, how can I test what variables were returned to a Jinja template with <code>render_template</code>?</p> <pre><code>@app.route('/foo/'): def foo(): return render_template('foo.html', foo='bar') </code></pre> <p>In this example, I want to test that <code>foo</code> is equal to <code>"bar"</code>. </p> ...
2
2016-10-02T22:13:37Z
39,822,401
<p>The best way will be to use something like that:</p> <pre><code>self.assertTrue('Hello bar!' in r.body) </code></pre> <p>And in <code>foo.html</code>:</p> <pre><code>&lt;div&gt;Hello {{ foo }}!&lt;/div&gt; </code></pre> <p>Of course I don't know structure of your html, so this example above is just a prototype.<...
0
2016-10-02T22:30:59Z
[ "python", "flask" ]
Flask Testing - How to retrieve variables that were passed to Jinja?
39,822,265
<p>In Flask, how can I test what variables were returned to a Jinja template with <code>render_template</code>?</p> <pre><code>@app.route('/foo/'): def foo(): return render_template('foo.html', foo='bar') </code></pre> <p>In this example, I want to test that <code>foo</code> is equal to <code>"bar"</code>. </p> ...
2
2016-10-02T22:13:37Z
39,822,423
<p>This can be done using <a href="http://flask.pocoo.org/docs/0.11/signals/" rel="nofollow">signals</a>. I will reproduce the code snippit here:</p> <pre> import unittest from app import app from flask import template_rendered from contextlib import contextmanager @contextmanager def captured_templates(app): rec...
2
2016-10-02T22:33:47Z
[ "python", "flask" ]
Tweepy - How to "tag" tweets with their respective tracking filter
39,822,272
<p>I'm having a hard time formulating my question, but basically, imagine you're streaming Twitter with Tweepy and filtering the tweets on 2 keywords like that:</p> <pre><code>twitterStream = Stream(auth, listener()) twitterStream.filter(track=["keyword1", "keyword2"]) </code></pre> <p>Basically, I would like to appe...
0
2016-10-02T22:14:26Z
39,822,636
<p>Tweepy use twitter streaming API, from docs of <a href="https://dev.twitter.com/streaming/overview/request-parameters" rel="nofollow">streaming API</a>, I believe its impossible to get result as you expected. Possible solutions are: </p> <ol> <li>If you have very limited keywords to track, then for each of these ke...
0
2016-10-02T23:05:52Z
[ "python", "twitter", "tweepy" ]
numpy multidimensional (3d) matrix multiplication
39,822,276
<p>I get two 3d matrix A (32x3x3) and B(32x3x3), and I want to get matrix C with dimension 32x3x3. The calculation can be done using loop like:</p> <pre><code>a = numpy.random.rand(32, 3, 3) b = numpy.random.rand(32, 3, 3) c = numpy.random.rand(32, 3, 3) for i in range(32): c[i] = numpy.dot(a[i], b[i]) </code></p...
3
2016-10-02T22:14:53Z
39,822,646
<p>You could do this using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html" rel="nofollow"><code>np.einsum</code></a>:</p> <pre><code>In [142]: old = orig(a,b) In [143]: new = np.einsum('ijk,ikl-&gt;ijl', a, b) In [144]: np.allclose(old, new) Out[144]: True </code></pre> <p>One advant...
1
2016-10-02T23:06:35Z
[ "python", "matrix", "multidimensional-array", "matrix-multiplication" ]
add extra value to kwarg list
39,822,419
<p>Suppose there is the following external module and its spelled out like this:</p> <p><strong>module1.py</strong></p> <pre><code>X = [1,2,3] def test_func(keyword_list=X): return keyword_list test_func() </code></pre> <p>In another file I am trying to add another item to the kwarg <code>X</code> where ill be...
0
2016-10-02T22:33:19Z
39,822,474
<p>It seems one way to enable the scenario would be to have your test_func api take two lists...</p> <pre><code>def test_func(user_keywords=None, default_keywords=X): # merge them # more stuff... </code></pre> <p>I am sure there are ways to reflect over the method and get the default args using the <code>insp...
0
2016-10-02T22:41:13Z
[ "python" ]
add extra value to kwarg list
39,822,419
<p>Suppose there is the following external module and its spelled out like this:</p> <p><strong>module1.py</strong></p> <pre><code>X = [1,2,3] def test_func(keyword_list=X): return keyword_list test_func() </code></pre> <p>In another file I am trying to add another item to the kwarg <code>X</code> where ill be...
0
2016-10-02T22:33:19Z
39,822,478
<p>Use another keyword arg:</p> <pre><code>def test_func(keyword_list=[1,2,3,4], additional_list=[]): return keyword_list + additional_list print(test_func()) print(test_func(additional_list=[5])) </code></pre> <p>Should produce</p> <pre><code>[1, 2, 3, 4] [1, 2, 3, 4, 5] </code></pre> <p>Or use a wrapper func...
1
2016-10-02T22:41:27Z
[ "python" ]
Plotting a solid cylinder centered on a plane in Matplotlib
39,822,480
<p>I fit a plane to a bunch of points in 3d and initially gave it an arbitrary size using np.meshgrid, but now I'm trying to plot a cylinder centered on that plane and oriented the same way (such that the plane fit would cut the height of the cylinder in half), but with a specified radius and height. The only examples ...
0
2016-10-02T22:41:32Z
39,823,124
<p>I have modified a solution to a question <a href="http://stackoverflow.com/questions/38076682/how-to-add-colors-to-each-individual-face-of-a-cylinder-using-matplotlib">How to add colors to each individual face of a cylinder using matplotlib</a>, removing the fancy shading and adding end caps. If you want to show the...
1
2016-10-03T00:31:03Z
[ "python", "matplotlib", "plot", "3d", "plane" ]
Using textwrap.dedent() with bytes in Python 3
39,822,598
<p>When I use a triple-quoted multiline string in Python, I tend to use textwrap.dedent to keep the code readable, with good indentation:</p> <pre><code>some_string = textwrap.dedent(""" First line Second line ... """).strip() </code></pre> <p>However, in Python 3.x, textwrap.dedent doesn't seem to wo...
1
2016-10-02T22:59:05Z
39,824,050
<p>Answer 1: Triple-quoted multiline strings (and dedent) are a convenience (sometimes), not a necessity. You can instead write a separate bytes literal ending with b'\n' for each line and let the parser join them. Example:</p> <pre><code>&gt;&gt;&gt; b = ( b'Lorem ipsum dolor sit amet\n' # first line b'cons...
0
2016-10-03T03:03:23Z
[ "python", "python-3.x", "indentation", "literals", "python-unicode" ]
Using textwrap.dedent() with bytes in Python 3
39,822,598
<p>When I use a triple-quoted multiline string in Python, I tend to use textwrap.dedent to keep the code readable, with good indentation:</p> <pre><code>some_string = textwrap.dedent(""" First line Second line ... """).strip() </code></pre> <p>However, in Python 3.x, textwrap.dedent doesn't seem to wo...
1
2016-10-02T22:59:05Z
39,841,195
<p>Answer 2: <code>textwrap</code> is primarily about the <code>Textwrap</code> class and functions. <code>dedent</code> is listed under </p> <pre><code># -- Loosely related functionality -------------------- </code></pre> <p>As near as I can tell, the <em>only</em> things that makes it text (unicode <code>str</code...
1
2016-10-03T22:09:46Z
[ "python", "python-3.x", "indentation", "literals", "python-unicode" ]
Using textwrap.dedent() with bytes in Python 3
39,822,598
<p>When I use a triple-quoted multiline string in Python, I tend to use textwrap.dedent to keep the code readable, with good indentation:</p> <pre><code>some_string = textwrap.dedent(""" First line Second line ... """).strip() </code></pre> <p>However, in Python 3.x, textwrap.dedent doesn't seem to wo...
1
2016-10-02T22:59:05Z
39,841,424
<p>It seems like <code>dedent</code> does not support bytestrings, sadly. However, if you want cross-compatible code, I recommend you take advantage of the <a href="http://pythonhosted.org/six/" rel="nofollow"><code>six</code></a> library:</p> <pre><code>import sys, unittest from textwrap import dedent import six ...
1
2016-10-03T22:30:47Z
[ "python", "python-3.x", "indentation", "literals", "python-unicode" ]
Import error: No module named Include in Python Django
39,822,605
<p>I am a beginner in Python. The Python version is 2.7. When I run the below command </p> <pre><code>(test) C:\virtualenvs\test&gt; python manage.py runserver </code></pre> <p>under a virtual environment I get an error saying </p> <pre><code>File "C:\virtualenvs\test\lib\site-packages\django\apps\config.py", line 9...
0
2016-10-02T23:01:42Z
39,823,908
<p>You have not provided any code, if I was to assume, then I would say you haven't imported <code>include</code> in your urls.py:</p> <pre><code>from django.conf.urls import include </code></pre> <p>Add the above in your urls.py and see what happens.</p>
0
2016-10-03T02:41:33Z
[ "python", "django" ]
Python: how to create a positive test for procedures?
39,822,639
<p>I have a class with some <code>@staticmethod</code>'s that are procedures, thus they do not return anything / their return type is <code>None</code>.</p> <p>If they fail during their execution, they throw an <code>Exception</code>.</p> <p>I want to <code>unittest</code> this class, but I am struggling with designi...
2
2016-10-02T23:05:59Z
39,822,709
<p>If your methods do something, then I'm sure there should be a logic there. Let's consider this dummy example:</p> <pre><code>cool = None def my_static_method(something): try: cool = int(something) except ValueError: # logs here </code></pre> <p>for negative test we have:</p> <pre><code>asse...
1
2016-10-02T23:17:11Z
[ "python", "unit-testing", "static-methods", "assert", "procedure" ]
Python: how to create a positive test for procedures?
39,822,639
<p>I have a class with some <code>@staticmethod</code>'s that are procedures, thus they do not return anything / their return type is <code>None</code>.</p> <p>If they fail during their execution, they throw an <code>Exception</code>.</p> <p>I want to <code>unittest</code> this class, but I am struggling with designi...
2
2016-10-02T23:05:59Z
39,827,425
<p>Without seeing the actual code it is hard to guess, however I will make some assumptions:</p> <ol> <li>The logic in the static methods is deterministic. </li> <li>After doing some calculation on the input value there is a result and some operation is done with this result. </li> <li>python3.4 (mock has evolved and ...
1
2016-10-03T08:33:17Z
[ "python", "unit-testing", "static-methods", "assert", "procedure" ]
Turtle and draw a tree with Transcrypt
39,822,733
<p>today I want draw a tree in browser with Transcrypt. I have code in Python which is work in Skulpt:</p> <pre><code>import random import turtle def tree(size, myTurtle): myTurtle.pensize(size / 20) if size &lt; random.randint(1,2) * 20: myTurtle.color("green") else: myTurtle.color("brow...
2
2016-10-02T23:20:54Z
39,823,845
<p>First: you need some modification in code because some functions in <code>Transcrypt</code> have different names or don't exist. You have to add <code>turtle.done()</code> to dislay result.</p> <p><strong>turtle_tree.py</strong></p> <pre><code>import random import turtle def tree(size, myTurtle): myTurtle.pen...
2
2016-10-03T02:30:11Z
[ "python", "transcrypt" ]
Remove last digit from a numeric value in a column if only the value has 4 digits
39,822,752
<p>I would like to remove the last digit from a numeric field/value from an entire column only if the value has 4 digits either using SQL or Python. Example: Column name is Credit Score Table name is T1 Example values are 888 and 8880, I would like to remove any values with 0 at the end but only if has 4 digits, as som...
0
2016-10-02T23:25:14Z
39,822,765
<p>I think you can just <code>update</code> the column dividing the existing value by 10 if it is >= 1000 and ends in a 0.</p> <pre><code>update tablename set credit_score = credit_score/10 where credit_score &gt;= 1000 and credit_score%10 = 0 </code></pre>
1
2016-10-02T23:27:38Z
[ "python", "sql", "sql-server", "azure" ]
Remove last digit from a numeric value in a column if only the value has 4 digits
39,822,752
<p>I would like to remove the last digit from a numeric field/value from an entire column only if the value has 4 digits either using SQL or Python. Example: Column name is Credit Score Table name is T1 Example values are 888 and 8880, I would like to remove any values with 0 at the end but only if has 4 digits, as som...
0
2016-10-02T23:25:14Z
39,890,739
<p>I tried to implement your needs on SQL Azure, please try to use the sql below.</p> <pre><code>update tablename set credit_score = cast(replace(rtrim(replace(cast(credit_score as varchar), '0', ' ')), ' ', '0') as int) where credit_score &gt;= 1000 </code></pre> <p>For example: 7400 => 74, 70400 => 704</p>
0
2016-10-06T08:05:47Z
[ "python", "sql", "sql-server", "azure" ]
Python Nested Loops To Print Rectangle With Asterisks
39,822,774
<p>Write nested loops to print a rectangle. Sample output for given program:</p> <p>3 stars : ***</p> <p>3 stars : ***</p> <p>I tried it and ended up with this:</p> <pre><code>num_rows = 2 num_cols = 3 '''IDK WHAT TO PUT HERE''' print('*', end=' ') print('') </code></pre> <p>Any help would be appreci...
-3
2016-10-02T23:29:57Z
39,822,887
<p>You're trying to learn, I think, so a here is a hint to push you in the right direction.</p> <p>You need to use a nested <code>for</code> loop. Use the <a href="https://docs.python.org/3/library/functions.html#func-range" rel="nofollow"><code>range()</code></a> builtin to produce an iterable sequence.</p> <p>The o...
0
2016-10-02T23:48:45Z
[ "python", "nested-loops" ]
ipithon notebook doesn't work
39,822,793
<p>I follow instruction and run ipython.exe notebook:</p> <pre><code>&gt; [TerminalIPythonApp] WARNING | Subcommand `ipython notebook` is &gt; deprecated and will be removed in future versions. &gt; [TerminalIPythonApp] WARNING | You likely want to use `jupyter &gt; notebook` in the future Traceback (most recent call ...
0
2016-10-02T23:33:07Z
39,823,664
<p>Like <code>zwol</code> said, your installation might have gotten screwed up. There are two things you can do.</p> <ol> <li>Completely remove your miniconda installation and try again.</li> <li><p>Create a new environment and install ipython/jupyter there. I would try this first. </p> <p><code>conda create -n my...
1
2016-10-03T02:03:43Z
[ "python", "windows", "jupyter-notebook", "miniconda" ]
How to get a masked rgba array from a ScalarMappable object
39,822,915
<p>The docs for <code>to_rgba</code> state:</p> <blockquote> <p>Note: this method assumes the input is well-behaved; it does not check for anomalies such as x being a masked rgba array, or being an integer type other than uint8, or being a floating point rgba array with values outside the 0-1 range.</p> </bloc...
0
2016-10-02T23:52:59Z
39,829,476
<p>Black typically corresponds to [0, 0, 0, 1] in an RGBA array. So just set all masked positions to these values ex post.</p> <pre><code># get mask of masked array mask = spc_map.mask # RGBA array should have one more dimension than spc_map with length 4 spc_map_color[mask] = np.array([0, 0, 0, 1]) </code></pre>
0
2016-10-03T10:28:29Z
[ "python", "matplotlib" ]
Adding horizontal space between data on a Read only script
39,822,944
<p>I need my output to look nice, and it looks very sloppy. </p> <p>--------Current output---------</p> <pre><code>Below are the players and their scores John Doe 120 Sally Smooth 115 </code></pre> <p>----------End current output----------</p> <p>My desired output follows</p> <p>-------Desired output-------------...
3
2016-10-02T23:56:15Z
39,822,961
<p>Try using the tab character to format your spaces better.</p> <pre><code>print(name + "\t" + score) </code></pre> <p>This should give you something closer to your desired output. But you may need to use two if some names are long.</p>
1
2016-10-03T00:00:37Z
[ "python", "readfile" ]
Adding horizontal space between data on a Read only script
39,822,944
<p>I need my output to look nice, and it looks very sloppy. </p> <p>--------Current output---------</p> <pre><code>Below are the players and their scores John Doe 120 Sally Smooth 115 </code></pre> <p>----------End current output----------</p> <p>My desired output follows</p> <p>-------Desired output-------------...
3
2016-10-02T23:56:15Z
39,823,003
<p>You can add the names and the scores to a list and then print it as a table as </p> <pre><code>import numpy as np name_list = ['jane doe' ,'sally smooth'] score = np.array([[102,],[106,]]) #make a numpy array row_format ="{:&gt;15}" * (len(name_list)) for name, row in zip(name_list, score): print(row_format.fo...
1
2016-10-03T00:05:51Z
[ "python", "readfile" ]
List without negative indexing
39,822,973
<p>I am coding a simply discrete system in python which is presented bellow:</p> <pre><code>class System: def __init__(self, a, b): self.a = a self.b = b self.y = [] def dynamics(self, signal): for i in range(len(signal)): try: self.y.append(signal[i] - self.a*self.y[i-1] - self.b*...
0
2016-10-03T00:02:49Z
39,823,085
<p>Although I pointed out my reluctance in the comments, I'll play your game.</p> <pre><code>class PositiveList(list): def __getitem__(self, ind): if ind &lt; 0: raise IndexError("Expected a positive index, instead got {}.".format(ind)) return super(PositiveList, self).__getitem__(ind)...
1
2016-10-03T00:22:26Z
[ "python", "list", "wrap" ]
List without negative indexing
39,822,973
<p>I am coding a simply discrete system in python which is presented bellow:</p> <pre><code>class System: def __init__(self, a, b): self.a = a self.b = b self.y = [] def dynamics(self, signal): for i in range(len(signal)): try: self.y.append(signal[i] - self.a*self.y[i-1] - self.b*...
0
2016-10-03T00:02:49Z
39,823,116
<p>This does what you actually want and is much cleaner. Just keep the latest two y-values in extra variables.</p> <pre><code>def dynamics(self, signal): y1 = y2 = 0 for sig in signal: y1, y2 = sig - self.a * y1 - self.b * y2, y1 self.y.append(y1) </code></pre>
1
2016-10-03T00:29:08Z
[ "python", "list", "wrap" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,134
<p>Make vowels an array with each element it's own letter.</p> <p>Then do</p> <pre><code>for letter in word: if letter in vowels: letter = "_" </code></pre>
1
2016-10-03T00:32:32Z
[ "python" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,140
<p>Lists can be used to easily build words, and with <code>.join()</code> you can combine the list items into a single string.</p> <pre><code>word = 'pizza' vowels = "aeiouy" new_word = [] for letter in word: if letter in vowels: new_word.append('_') else: new_word.append(letter) print(''.join(...
1
2016-10-03T00:33:33Z
[ "python" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,148
<p>You can use <code>string.translate</code> and <code>maketrans</code>.</p> <pre><code>from string import maketrans vowels = "aeiouy" t = "______" st = "trying this string" tran = maketrans(vowels, t) print st.translate(tran) # Gives tr__ng th_s str_ng </code></pre> <p>You may also want to check uppercases.</p>
3
2016-10-03T00:34:51Z
[ "python" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,163
<p>you can use regex </p> <pre><code>import re print(re.sub("[aeiouAEIOU]", "_", "abc")) # prints _bc </code></pre>
1
2016-10-03T00:38:33Z
[ "python" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,167
<p>Using a list comprehension and setting <code>vowels</code> as a <code>set</code> object (this is really only valuable for speeding up performance if you have a large list of words over which you're iterating):</p> <pre><code>&gt;&gt;&gt; vowels = set("aeiouy") &gt;&gt;&gt; word = 'ampersand' &gt;&gt;&gt; new_word =...
0
2016-10-03T00:39:30Z
[ "python" ]
How can I replace the vowels of a word with underscores in python?
39,823,110
<p>I'm a beginner learning the python language and I'm stumped on how take the vowels of a word and replacing them with an underscore. </p> <p>So far this is what I have come up with and it just doesn't work</p> <pre><code>word = input("Enter a word: ") new_word = "" vowels = "aeiouy" for letter in word: if let...
0
2016-10-03T00:28:34Z
39,823,210
<p>To answer why your approach didn't work.</p> <pre><code>if letter != vowels: </code></pre> <p>Does not do what you are thinking. It actually compares the letter against a full string <code>"aeiouy"</code>. It will always be unequal (e.g. <code>"a" != "aeiouy"</code> is True and so is any other letter).</p> <p>Mor...
0
2016-10-03T00:49:52Z
[ "python" ]
Python code for all combinations of part of a list?
39,823,161
<p>I have some code set up to where 2 consonants are randomly generated and 2 vowels are randomly generated, and each are assigned to their own individual variable. I used print (itertools.permutations(list)) to show all possible combinations of the 4 letters, with list being the variables of each vowel or consonant, b...
-1
2016-10-03T00:38:20Z
39,823,175
<pre><code>In [34]: L = ['a', 'e', 'b', 'c'] In [35]: for p in itertools.permutations(L): print(''.join(p)) aebc aecb abec abce aceb acbe eabc eacb ebac ebca ecab ecba baec bace beac beca bcae bcea caeb cabe ceab ceba cbae cbea </code></pre>
2
2016-10-03T00:40:44Z
[ "python", "random", "permutation", "itertools" ]
Tweepy api binder and python properties
39,823,262
<p>I've been digging around the tweepy source code trying to get a feel for how everything is designed. I'm a little confused with the <code>API</code> class and <code>bind_api</code> function. The tweepy source can be found here: <a href="https://github.com/tweepy/tweepy" rel="nofollow">https://github.com/tweepy/tweep...
0
2016-10-03T00:58:55Z
39,864,421
<p>I was not thinking when I asked this the other day.</p> <p><code>bind_api</code> is returning a function. This function is then called when that property is called. That is why each api call is a <code>@property</code> which also answers my second question.</p>
0
2016-10-05T02:13:13Z
[ "python", "tweepy" ]
Python 'if' statement - if in [string] == 'string' -- Not working?
39,823,275
<p>I'm trying to find a letter in a giving string. Here's what I got:</p> <pre><code> if i in steps == 'u': y -= pixels_per_move elif i in [steps] == 'r': x -= pixels_per_move </code></pre> <p>steps is a randomly generated string consisting of u, d, r, l. So it's something like 'uuurlluddd'</p> <p>So i'm ju...
0
2016-10-03T01:02:07Z
39,823,287
<p>What it is saying is that <code>i</code> is an int. You are testing whether <code>i</code> is in <code>steps</code> which is a string. The mostly likely thing I think you are trying to do is get the <code>ith</code> character of the <code>steps</code> in which case you should use <code>if steps[i] == 'u':</code></p>...
1
2016-10-03T01:04:39Z
[ "python", "if-statement" ]
Python 'if' statement - if in [string] == 'string' -- Not working?
39,823,275
<p>I'm trying to find a letter in a giving string. Here's what I got:</p> <pre><code> if i in steps == 'u': y -= pixels_per_move elif i in [steps] == 'r': x -= pixels_per_move </code></pre> <p>steps is a randomly generated string consisting of u, d, r, l. So it's something like 'uuurlluddd'</p> <p>So i'm ju...
0
2016-10-03T01:02:07Z
39,823,376
<p>You confuse the <code>for i in steps</code> with the <code>if</code> statement. Anyway, it should look something like this:</p> <pre><code>for i in steps: if i == "u": #here i isn't a int but a string! y -= pixels_per_move elif i == "r": x -= pixels_per_move </code></pre> <p>You could add a...
1
2016-10-03T01:21:15Z
[ "python", "if-statement" ]