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
Numeric output and dont echo repeating numbers for ex 1010101; 2020202, 1212121
39,433,142
<p>Looking for a script that can pipe or print to file and generate a random, non repeating output wordlist/numberlist [crunch for example can do that with the -d option but 10101 etc dont get sorted out]. </p> <p>Example: a numeric list <code>000000-999999</code> and written to a file / pipe to program all numbers b...
0
2016-09-11T05:22:58Z
39,433,384
<p>You are looking for a (pseudo-) random number generator, and there are many to choose from. Scale what your chosen one gives you (usually between 0 and 1) and fill your sequences by calling it repeatedly. Or use the scaled sequence to pull from ASCII tables if you want characters.</p> <p>Perl comes with a builtin <...
2
2016-09-11T06:14:36Z
[ "python", "bash", "perl", "random", "sequence" ]
Numeric output and dont echo repeating numbers for ex 1010101; 2020202, 1212121
39,433,142
<p>Looking for a script that can pipe or print to file and generate a random, non repeating output wordlist/numberlist [crunch for example can do that with the -d option but 10101 etc dont get sorted out]. </p> <p>Example: a numeric list <code>000000-999999</code> and written to a file / pipe to program all numbers b...
0
2016-09-11T05:22:58Z
39,433,487
<p>Here's a potential, simple solution for the specific six digit range, 000000-999999, you requested:</p> <pre><code>from regex import match from random import sample DIGITS = 6 assert (DIGITS % 2 == 0), "Only works for even digit string lengths" number_format = "{:0" + str(DIGITS) + "d}" for number in sample(ran...
1
2016-09-11T06:36:35Z
[ "python", "bash", "perl", "random", "sequence" ]
Numeric output and dont echo repeating numbers for ex 1010101; 2020202, 1212121
39,433,142
<p>Looking for a script that can pipe or print to file and generate a random, non repeating output wordlist/numberlist [crunch for example can do that with the -d option but 10101 etc dont get sorted out]. </p> <p>Example: a numeric list <code>000000-999999</code> and written to a file / pipe to program all numbers b...
0
2016-09-11T05:22:58Z
39,435,515
<p>Your question is not completely clear. Is 123435 allowed, since the 3 is repeated?</p> <p>Assuming absolutely no repetition is required, then put the ten digits [0..9] in an array, shuffle the array and pick off the first six digits. If you don't want a leading zero, then if necessary drop the leading zero and ad...
0
2016-09-11T11:17:35Z
[ "python", "bash", "perl", "random", "sequence" ]
Numeric output and dont echo repeating numbers for ex 1010101; 2020202, 1212121
39,433,142
<p>Looking for a script that can pipe or print to file and generate a random, non repeating output wordlist/numberlist [crunch for example can do that with the -d option but 10101 etc dont get sorted out]. </p> <p>Example: a numeric list <code>000000-999999</code> and written to a file / pipe to program all numbers b...
0
2016-09-11T05:22:58Z
39,490,035
<p>OK, this is my definition of finding and eliminating repetitive strings. The idea is to:</p> <ul> <li>draw a random string of numbers and zeropad it (<code>str</code>)</li> <li>store the first two characters (<code>replen</code> actually) of every substring to an array (<code>prefix</code>) and if there is a collis...
0
2016-09-14T12:06:47Z
[ "python", "bash", "perl", "random", "sequence" ]
Python metaclass for randomized quiz questions
39,433,159
<p>For teaching a large math class, it's helpful to write questions with some randomization built in, so that not all students get the exact same questions. My solution is to write a short Python script to generate a few questions -- identical except slight variations in the numbers. The result might be to give the c...
0
2016-09-11T05:26:29Z
39,435,420
<p>There will be many questions and there will be randomization of some of the parameters within each question. I assume there is no randomization of the choice of questions, only their parameters (although that would be solved the same way).</p> <p>So, you could have a class for each question:</p> <pre><code>class Q...
0
2016-09-11T11:06:28Z
[ "python", "metaclass" ]
Convert int into str while in __getitem__ Python 2.7
39,433,191
<p>Okay, i have this string:</p> <p><code>string = "HelloWorld"</code> </p> <p>And for this example, I am using a dictionary similar to this:</p> <p><code>dic = [{'a':'k','b':'i'},{'a':'i','b':'l'},{'a':'x','b':'n'},{'a':'q','b':'o'}]</code></p> <p>Now.. I need to reference a dictionary from the list, so that I can...
-5
2016-09-11T05:34:44Z
39,433,308
<p>Here's my best crystal ball guess at what you want. The keys of your dictionary are only <code>a</code> and <code>b</code>, which aren't any characters in <code>HelloWorld</code>, but if you actually had characters from your string as keys like the following, this is how I'd do the replacement, assuming you want to...
0
2016-09-11T06:01:21Z
[ "python", "python-2.7" ]
Adding one or more attractors to a set of random 2D points
39,433,259
<p>Given a set of pseudorandom 2D points generated like so:</p> <pre><code>points = random.sample([[x, y] for x in xrange(width) for y in yrange(height)], 100) </code></pre> <p>I would like to be able to add one or more non random attractor points around which the other points will be drawn. I don't plan to animate t...
3
2016-09-11T05:50:14Z
39,433,706
<p>You said you want to be able to change the function, so we need to add a function <code>f</code> to the arguments of <code>attract</code>. This function should need one arguments, the distance of the point, and it should return a number.</p> <pre><code>import math def attract(random_point_list, attractor_point_li...
0
2016-09-11T07:10:45Z
[ "python", "game-physics", "voronoi" ]
Adding one or more attractors to a set of random 2D points
39,433,259
<p>Given a set of pseudorandom 2D points generated like so:</p> <pre><code>points = random.sample([[x, y] for x in xrange(width) for y in yrange(height)], 100) </code></pre> <p>I would like to be able to add one or more non random attractor points around which the other points will be drawn. I don't plan to animate t...
3
2016-09-11T05:50:14Z
39,435,357
<p>This turned out to be a more challenging problem than my initial estimate of it as a pure implementation-effort task. The difficulty is in defining a good attraction model.</p> <ol> <li><p>Simulating plain free-fall on attractors (as if in a real gravity field created by multiple point masses) is problematic since ...
1
2016-09-11T10:58:36Z
[ "python", "game-physics", "voronoi" ]
How does this reduce + lambda list filter function work?
39,433,301
<p>I saw the following code to filter a list into two classes:</p> <pre><code>reduce(lambda(a,b),c: (a+[c],b) if c &gt; 60 else (a,b + [c]), [49, 58, 76, 82, 88, 90],([],[])) </code></pre> <p>How does it work? the <code>([], [])</code> looks initializing the <code>(a, b)</code> in lambda, but how does it work step by...
0
2016-09-11T05:59:58Z
39,433,394
<p>To answer your first query, the equivalent using for loop:</p> <pre><code>&gt;&gt;&gt; c = [49, 58, 76, 82, 88, 90] &gt;&gt;&gt; final = ([], []) &gt;&gt;&gt; for val in c: ... if val &gt; 60: ... final[0].append(val) ... else: ... final[1].append(val) ... &gt;&gt;&gt; final ([76, 8...
0
2016-09-11T06:16:31Z
[ "python", "lambda", "reduce" ]
How does this reduce + lambda list filter function work?
39,433,301
<p>I saw the following code to filter a list into two classes:</p> <pre><code>reduce(lambda(a,b),c: (a+[c],b) if c &gt; 60 else (a,b + [c]), [49, 58, 76, 82, 88, 90],([],[])) </code></pre> <p>How does it work? the <code>([], [])</code> looks initializing the <code>(a, b)</code> in lambda, but how does it work step by...
0
2016-09-11T05:59:58Z
39,433,411
<blockquote> <p>How does it work? the <code>([], [])</code> looks initializing the <code>(a, b)</code> in lambda, but how does it work step by step?</p> </blockquote> <p>At each point, the reduce sees a left hand operand, <code>(a, b)</code>, which is a pair of lists (initially two empty lists), and an element <code...
1
2016-09-11T06:19:54Z
[ "python", "lambda", "reduce" ]
How does this reduce + lambda list filter function work?
39,433,301
<p>I saw the following code to filter a list into two classes:</p> <pre><code>reduce(lambda(a,b),c: (a+[c],b) if c &gt; 60 else (a,b + [c]), [49, 58, 76, 82, 88, 90],([],[])) </code></pre> <p>How does it work? the <code>([], [])</code> looks initializing the <code>(a, b)</code> in lambda, but how does it work step by...
0
2016-09-11T05:59:58Z
39,467,535
<p>Take a look at the following experiment:</p> <pre><code>&gt;&gt;&gt; reduce(lambda(a,b),c: (a+[c],b) if c &gt; 60 else (a,b + [c]), [49],([],[])) ([], [49]) &gt;&gt;&gt; reduce(lambda(a,b),c: (a+[c],b) if c &gt; 60 else (a,b + [c]), [49,58],([],[])) ([], [49, 58]) &gt;&gt;&gt; reduce(lambda(a,b),c: (a+[c],b) if c &...
0
2016-09-13T10:16:03Z
[ "python", "lambda", "reduce" ]
Numpy collapse columns according to list
39,433,389
<p>In numpy, I have a d x n array A and a list L of length n describing where I want each column of A to end up in matrix B. The idea is that column i of matrix B is the sum of all columns of A for which the corresponding value in L is i. I can do this with a loop:</p> <pre><code>A = np.arange(15).reshape(3,5) L = [0,...
3
2016-09-11T06:15:28Z
39,434,463
<p>Is this iteration on ``B` the same (not tested)?</p> <pre><code> for I in range(B.shape[1]): B[:, I] = A[:, L==I].sum(axis=1) </code></pre> <p>The number loops will be fewer. But more importantly it may give other vectorization insights.</p> <p>(edit) on testing, this works, but is much slower.</p> <p>+=...
1
2016-09-11T08:59:19Z
[ "python", "numpy", "vectorization", "numpy-broadcasting" ]
Numpy collapse columns according to list
39,433,389
<p>In numpy, I have a d x n array A and a list L of length n describing where I want each column of A to end up in matrix B. The idea is that column i of matrix B is the sum of all columns of A for which the corresponding value in L is i. I can do this with a loop:</p> <pre><code>A = np.arange(15).reshape(3,5) L = [0,...
3
2016-09-11T06:15:28Z
39,434,530
<p>You are sum-reducing/collapsing the columns off <code>A</code> using <code>L</code> for selecting those columns. Also, you are updating the columns of output array based on the uniqueness of <code>L</code> elems. </p> <p>Thus, you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.redu...
3
2016-09-11T09:08:47Z
[ "python", "numpy", "vectorization", "numpy-broadcasting" ]
How do I configure Visual Studio Code with Python extension to not complain about inability to import modules?
39,433,401
<p>I am new to VS Code and I installed e.g. PySide for my tutorial project written in Python. I try to:</p> <pre><code>from PySide.QtGui import QDialog, QApplication, QVBoxLayout, QLineEdit, QTextBrowser from PySide.QtCore import * </code></pre> <p>Although the code runs perfectly well using the imported modules, VS ...
0
2016-09-11T06:18:28Z
39,461,767
<p>@Andreas Schwab, You need to ensure pylint is installed in the python environment in which you have installed the PySide package. You will also need to ensure this same environment (python interpreter) is referenced in settings.json in the python.pythonPath setting.</p> <p>You can find more details on these two her...
0
2016-09-13T03:25:53Z
[ "python", "qt", "pyside", "vscode" ]
Smartsheet SDK exception handling
39,433,457
<p>I am trying to write try except block for smartsheet aPI using python sdk, specially in cases where the API response to call returns error object rather than a usual index result object. Could someone explain what kind of exception would I be catching. I am not sure if I would have to create custom exceptions of my ...
0
2016-09-11T06:29:44Z
39,480,478
<p>Knowing what a successful response will look like you could try checking for the error response. For example, running a get_row with an invalid rowId will result in this error:</p> <p><code> {"requestResponse": null, "result": {"code": 1006, "name": "NotFoundError", "recommendation": "Do not retry without fixing th...
0
2016-09-13T23:37:33Z
[ "python", "python-2.7", "exception-handling", "smartsheet-api", "smartsheet-api-1.1" ]
Python return False if list is empty
39,433,505
<p>In one coding example i saw the following code snippet that returns <strong>True</strong> if the list is empty and <strong>False</strong> if not</p> <pre><code>return a == [] </code></pre> <p>the reason for that is to avoid writing</p> <pre><code>if a: return False else: return True </code></pre> <p>In a...
3
2016-09-11T06:39:03Z
39,433,777
<p>No. There is no speed difference in either case. Since in both cases the <code>length</code> of the list is checked first. In the first case, the <code>len</code> of <code>a</code> is compared with the <code>len</code> of <code>[]</code> before any further comparison. Most times the <code>len</code> should differ, s...
2
2016-09-11T07:20:31Z
[ "python" ]
Python return False if list is empty
39,433,505
<p>In one coding example i saw the following code snippet that returns <strong>True</strong> if the list is empty and <strong>False</strong> if not</p> <pre><code>return a == [] </code></pre> <p>the reason for that is to avoid writing</p> <pre><code>if a: return False else: return True </code></pre> <p>In a...
3
2016-09-11T06:39:03Z
39,433,990
<p>If you're asking which method would faster if put in a function(hence the <code>return</code>'s), then I used the <code>timeit</code> module to do a little testing. I put each method in a function, and then ran the program to see which function ran faster. Here is the program:</p> <pre><code>import timeit def is_e...
2
2016-09-11T07:54:51Z
[ "python" ]
i want to write a function in python named cont() which sends a message "continue" and which should take no argument
39,433,532
<p>i want to write a function in python named cont() which sends a message "continue" and which should take no argument.the function should print the message yes,y or Y.then return true otherwise false. i have done it but there is an error.</p> <pre><code>def cont(): x = input("enter any word of your choice") ...
-5
2016-09-11T06:42:12Z
39,433,744
<p>Sadly the code that you supplied and the description that you wrote, do not agree with each other. There is no attempt to <code>return</code> any value, indeed, there is nothing to suggest what the decision of <code>True</code> or <code>False</code> would be based upon.<br> Assuming that you are using python 2.7, th...
0
2016-09-11T07:15:42Z
[ "python", "python-2.7", "python-3.x" ]
How do you restrict the scaling of the sine wave upto certain value
39,433,557
<p>I am using the below codes so as to scale up the amplitude of the sine wave after the limit value 20.Here I am not able to restrict the amplitude of the sine wave.Please refer the figure below.I need the output as mentioned in figure in single plot window[not via subplot]. I need only amplitude scaling not the frequ...
-1
2016-09-11T06:46:07Z
39,436,918
<p>It can be done relatively straightforward as follows:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np Limit=20 x=np.linspace(-20,20,4000) y=np.sin(x) plt.plot(x[x&lt;0],y[x&lt;0], lw=2, color='k') y[(y&lt;=Limit)] = y*0.5 plt.plot(x[x&gt;0],y[x&gt;0], lw=2, color='k') plt.grid() plt.show() </c...
0
2016-09-11T14:07:10Z
[ "python", "numpy", "matplotlib" ]
How do you restrict the scaling of the sine wave upto certain value
39,433,557
<p>I am using the below codes so as to scale up the amplitude of the sine wave after the limit value 20.Here I am not able to restrict the amplitude of the sine wave.Please refer the figure below.I need the output as mentioned in figure in single plot window[not via subplot]. I need only amplitude scaling not the frequ...
-1
2016-09-11T06:46:07Z
39,438,845
<p>Are you looking for this:</p> <pre><code>import matplotlib.pyplot as plt import numpy as np x_limit = 20 x = np.linspace(0,40,400) y = np.sin(x) y[x &lt;= x_limit] *= 0.5 plt.plot(x,y) plt.grid() plt.show() </code></pre> <p>I think you wanted to apply the limit to the x, not the y.</p> <p><a href="http://i.sta...
1
2016-09-11T17:36:29Z
[ "python", "numpy", "matplotlib" ]
How to switch to frame source in selenium
39,433,681
<p>I want to click an frame source's radio button, but it doesn't work. I think, frame source doesn't have iframe id or name. my code is this.</p> <pre><code>import time from selenium import webdriver Url='https://www.youtube.com/watch?v=eIStvhR347g' driver = webdriver.Firefox() driver.get('https://video-download.onli...
1
2016-09-11T07:05:58Z
39,433,839
<p>The <code>iframe</code> is inside <code>&lt;noscript&gt;</code> tag, witch means the <code>driver</code> will see it only when <code>javascript</code> is disabled, as human user would. You can try to disable <code>javascript</code> when creating the driver</p> <pre><code>fp = webdriver.FirefoxProfile() fp.set_prefe...
0
2016-09-11T07:30:02Z
[ "python", "html", "forms", "selenium", "iframe" ]
How to switch to frame source in selenium
39,433,681
<p>I want to click an frame source's radio button, but it doesn't work. I think, frame source doesn't have iframe id or name. my code is this.</p> <pre><code>import time from selenium import webdriver Url='https://www.youtube.com/watch?v=eIStvhR347g' driver = webdriver.Firefox() driver.get('https://video-download.onli...
1
2016-09-11T07:05:58Z
39,437,692
<p>As I'm seeing <a href="https://video-download.online" rel="nofollow">on this url</a>, there are multiple <code>iframe</code> present while, you are trying to switch to <code>iframe</code> with it's <code>tagName</code> only which will switch to first find <code>iframe</code> in order while your desired <code>iframe<...
0
2016-09-11T15:28:49Z
[ "python", "html", "forms", "selenium", "iframe" ]
How to switch to frame source in selenium
39,433,681
<p>I want to click an frame source's radio button, but it doesn't work. I think, frame source doesn't have iframe id or name. my code is this.</p> <pre><code>import time from selenium import webdriver Url='https://www.youtube.com/watch?v=eIStvhR347g' driver = webdriver.Firefox() driver.get('https://video-download.onli...
1
2016-09-11T07:05:58Z
39,629,725
<p>I have created a simple method for switching the frames :</p> <pre><code>**public static void fn_SwitchToFrame(WebDriver driver, String frame){ if(frame.contains("&gt;")){ String[] List = frame.split("&gt;"); int ListSize = List.length; for (int i=0; i&lt;=(ListSize-1);...
0
2016-09-22T03:22:52Z
[ "python", "html", "forms", "selenium", "iframe" ]
Python dedicated class for file names
39,433,691
<p>I am writing a program that utilises a large number of files. Does Python feature an inbuilt class for file paths, or does one have to be implemented by the user (like below):</p> <pre><code>class FilePath: def __init__(path): shazam(path) def shazam(self, path): """ something happens, path...
2
2016-09-11T07:07:43Z
39,433,748
<p>Python has several cross platform modules for dealing with the file system, <a href="https://docs.python.org/2/library/os.path.html" rel="nofollow">paths</a> and <a href="https://docs.python.org/2/library/os.html" rel="nofollow">operating system</a>.</p> <p>The <a href="https://docs.python.org/2/library/os.html" re...
2
2016-09-11T07:15:58Z
[ "python", "file", "class", "variables" ]
Python dedicated class for file names
39,433,691
<p>I am writing a program that utilises a large number of files. Does Python feature an inbuilt class for file paths, or does one have to be implemented by the user (like below):</p> <pre><code>class FilePath: def __init__(path): shazam(path) def shazam(self, path): """ something happens, path...
2
2016-09-11T07:07:43Z
39,435,016
<p>Since Python 3.4 there is <a href="https://docs.python.org/3/library/pathlib.html" rel="nofollow">pathlib</a> which seems to be what you are looking for. Of course there are the functions from <a href="https://docs.python.org/3/library/os.path.html" rel="nofollow">os.path</a>, too - but for an object-oriented approa...
1
2016-09-11T10:14:22Z
[ "python", "file", "class", "variables" ]
Django: How to implement user profiles?
39,433,707
<p>I'm making a Twitter clone and trying to load profile pages. My logic was to start simple and find all tweets that match a certain author and load those tweets on a page as the user's profile. I really don't know where to start.</p> <p>urls.py</p> <pre><code>url(r'^users/(?P&lt;username&gt;\w+)/$', views.UserProfi...
0
2016-09-11T07:11:02Z
39,434,004
<p>Foreign key require model object or primary key of object.</p> <p>pass the id of object whose username is "admin". use</p> <pre><code>Howl.objects.filter(author=1) </code></pre> <p>instead of</p> <pre><code>Howl.objects.filter(author="admin") </code></pre> <p>or you can use this one also</p> <pre><code>user ...
0
2016-09-11T07:57:14Z
[ "python", "django" ]
Changing strings into integers
39,433,738
<p>I'm going crazy and I can not figure the right solution :(</p> <p>How can I solve that problems. I have a loop and I can get diffrent types like:</p> <pre><code>empty string 10 10K 2.3K 2.34K 2M 2.2M 2.23M </code></pre> <p>I need to change them into numbers:</p> <pre><code>0 10 10000 2300 2340 2000000 2200000 22...
1
2016-09-11T07:15:22Z
39,433,807
<p>Your steps should be:</p> <ul> <li>check if string is empty <ul> <li>return 0</li> </ul></li> <li>check if string ends in K or M <ul> <li>if it does, strip that character off the end, store it for later</li> <li>multiply by appropriate factor (K = 1000 or M = 1000000)</li> </ul></li> </ul> <p>This can be achieve...
2
2016-09-11T07:24:36Z
[ "python", "regex", "python-2.7" ]
Changing strings into integers
39,433,738
<p>I'm going crazy and I can not figure the right solution :(</p> <p>How can I solve that problems. I have a loop and I can get diffrent types like:</p> <pre><code>empty string 10 10K 2.3K 2.34K 2M 2.2M 2.23M </code></pre> <p>I need to change them into numbers:</p> <pre><code>0 10 10000 2300 2340 2000000 2200000 22...
1
2016-09-11T07:15:22Z
39,433,816
<p>A quick hack to get the floats:</p> <pre><code>In [15]: powers = {'K': 10 ** 3, 'M': 10 ** 6} In [16]: def f(s): ...: try: ...: if s[-1] in powers.keys(): ...: return float(s[:-1]) * powers[s[-1]] ...: else: ...: return float(s) ...: except: ...
2
2016-09-11T07:26:01Z
[ "python", "regex", "python-2.7" ]
Changing strings into integers
39,433,738
<p>I'm going crazy and I can not figure the right solution :(</p> <p>How can I solve that problems. I have a loop and I can get diffrent types like:</p> <pre><code>empty string 10 10K 2.3K 2.34K 2M 2.2M 2.23M </code></pre> <p>I need to change them into numbers:</p> <pre><code>0 10 10000 2300 2340 2000000 2200000 22...
1
2016-09-11T07:15:22Z
39,437,859
<p>I agree with other answers, this solution will be best to solve it without Regular Expression.</p> <p>But, if you still want to use regex, here is a nice way to do this using JavaScript (sorry, not familiar with Python):</p> <pre><code>var new_arr = ['','10','10K','2.3K','2.34K','2M','2.2M','2.23M'].map(function(v...
0
2016-09-11T15:46:35Z
[ "python", "regex", "python-2.7" ]
How can I make a while loop only run a limited number of times?
39,433,761
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p> <p>How can I achieve that?</p> <pre><code>import random ydeal = random.randint(1,15) adeal = random.randint(1,15) yscore = 0 ascore = 0 def rol...
-2
2016-09-11T07:18:25Z
39,433,892
<p>Not sure about your code, but you can limit the number of loops by adding one to <code>n</code> on each loop, and use <code>while n &lt;= 52</code> (or any other value):</p> <pre><code>n = 1 while n &lt;= 3: word = "monkey" if n == 1 else "monkeys" print(n, word) if input("press Return to increase the n...
0
2016-09-11T07:38:39Z
[ "python" ]
How can I make a while loop only run a limited number of times?
39,433,761
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p> <p>How can I achieve that?</p> <pre><code>import random ydeal = random.randint(1,15) adeal = random.randint(1,15) yscore = 0 ascore = 0 def rol...
-2
2016-09-11T07:18:25Z
39,433,958
<p>I noticed a couple of problems in your code:</p> <ol> <li>Inside the <code>roll()</code> function you have to declare that you want to use the global variables and not two new variables that are local to the function,</li> <li>You are not assigning the increment to the value. A correct way to do it is: <code>yscore...
0
2016-09-11T07:49:41Z
[ "python" ]
How can I make a while loop only run a limited number of times?
39,433,761
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p> <p>How can I achieve that?</p> <pre><code>import random ydeal = random.randint(1,15) adeal = random.randint(1,15) yscore = 0 ascore = 0 def rol...
-2
2016-09-11T07:18:25Z
39,434,044
<p>I support Jacob's answer that you can limit the number of loops by adding one to n on each loop, and use while n &lt;= 52 (or any other value). I also read many programming tips at <a href="http://ubuhanga.com" rel="nofollow">http://ubuhanga.com</a> and I think they can also help you</p>
0
2016-09-11T08:02:27Z
[ "python" ]
How can I make a while loop only run a limited number of times?
39,433,761
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p> <p>How can I achieve that?</p> <pre><code>import random ydeal = random.randint(1,15) adeal = random.randint(1,15) yscore = 0 ascore = 0 def rol...
-2
2016-09-11T07:18:25Z
39,434,124
<p>How about this using <code>range</code> as per my comment</p> <pre><code>import random def ydeal(): return random.randint(1,15) def adeal(): return random.randint(1,15) yscore = ascore = draw = 0 def roll(): global yscore, ascore, draw if deal == "Deal": for x in range(52): yy...
0
2016-09-11T08:14:22Z
[ "python" ]
How can I make a while loop only run a limited number of times?
39,433,761
<p>In the code below, I'd like to run the function <code>roll()</code>, after: <code>deal = input("Your Turn: ")</code>, but only up to a limited number of cycles (52)</p> <p>How can I achieve that?</p> <pre><code>import random ydeal = random.randint(1,15) adeal = random.randint(1,15) yscore = 0 ascore = 0 def rol...
-2
2016-09-11T07:18:25Z
39,434,202
<p>Here my previous suggestion with the while loop in the correct place:</p> <pre><code>import random yscore = 0 ascore = 0 max_score = 52; def roll(): #Notify that the variables you want to use are not defined inside the function global yscore global ascore if deal == "!": while (yscore &lt;...
0
2016-09-11T08:23:31Z
[ "python" ]
Missing .dll when running pyinstaller .exe file on another computer
39,433,821
<p>I have been busy making a short script in python to get users HWID. Because computers without python installed can't run the script, I have converted it to an .exe file using pyinstaller.</p> <p>However, when I tried running the .exe file on my laptop (running windows 7 ultimate and does not have python installed) ...
1
2016-09-11T07:26:28Z
40,029,542
<p>The issue is a missing <a href="https://www.microsoft.com/en-us/download/details.aspx?id=48145" rel="nofollow">Visual C++ 2015 Redistributable</a> as @eryksun alluded to. However it was published July 10, 2015 so I don't know that it's necessarily an update issue as well.</p> <p>I had the same problem on a recentl...
0
2016-10-13T19:38:57Z
[ "python", "windows", "python-3.x", "compilation", "pyinstaller" ]
Insert HTML tag in all HTML files in a folder in Python
39,433,888
<p>I'm new to python and trying a program to do the following:</p> <ol> <li><p>Open all folder and subfolders in a directory path</p></li> <li><p>Identify the HTML files</p></li> <li><p>Load the HTML in BeautifulSoup</p></li> <li><p>Find the first body tag</p></li> <li><p>If the body tag is immediately followed by &lt...
0
2016-09-11T07:37:59Z
39,434,670
<p>So you can install the <a href="https://docs.python.org/3/library/glob.html" rel="nofollow">iglob</a> library for python. With iglob you can recursively traverse the main directory you specify and the sub-directories and list all the files with a given extension. Then open up the HTML file, read all the lines, trave...
2
2016-09-11T09:26:15Z
[ "python", "html", "beautifulsoup" ]
Insert HTML tag in all HTML files in a folder in Python
39,433,888
<p>I'm new to python and trying a program to do the following:</p> <ol> <li><p>Open all folder and subfolders in a directory path</p></li> <li><p>Identify the HTML files</p></li> <li><p>Load the HTML in BeautifulSoup</p></li> <li><p>Find the first body tag</p></li> <li><p>If the body tag is immediately followed by &lt...
0
2016-09-11T07:37:59Z
39,434,723
<p>My take on it, might have some bugs:</p> <p>edited to add: I have since realized that this code does not ensure <code>&lt;!-- Google Tag Manager --&gt;</code> is the first tag after <code>&lt;body&gt;</code>, instead it ensures it is the first comment after <code>&lt;body&gt;</code>. Which is not what the question ...
0
2016-09-11T09:33:53Z
[ "python", "html", "beautifulsoup" ]
Python Import Error: No module named Flask.myMethod
39,434,016
<p>I've read documentation, but I still can't quite wrap my head around how Python handles imports. I get the following error:</p> <p>I've checked for circular imports (serv imports class_definitions: <code>from class_definitions import *</code> as well as a few other typical python modules) <code>class_definitions.py...
-2
2016-09-11T07:59:12Z
39,435,047
<p>It seems that you have a py file at this path:</p> <pre><code>"/home/pi/Desktop/barbot/flask-files/class_definitions.py" </code></pre> <p>And you are trying to import something named <code>Flask.class_definitions</code> when you <code>pickle.load</code>.</p> <p>This fails because <code>class_definitions</code> is...
0
2016-09-11T10:18:24Z
[ "python", "flask" ]
Regular expression for separating strings
39,434,084
<p>I have the following string</p> <blockquote> <p>Long string 1 [sucess 50] long string 2 [apple 5 banana 20 orange 75] long string 3 [failure: 100]</p> </blockquote> <p>Now I want to split it into three strings:</p> <ol> <li>Long string 1 [sucess 50]<br/></li> <li>long string 2 [apple 5 banana 20 orange 75]<br...
-7
2016-09-11T08:07:30Z
39,434,165
<p>No need for regular expressions in such a simple task. Just use Python's built-in <code>str.replace()</code> method like so:</p> <pre><code>your_str = your_str.replace(']', ']\n') </code></pre> <p>To split it and get a list, use <code>your_str.split(']')</code></p> <p>But if you really want regex or the string in...
3
2016-09-11T08:19:43Z
[ "python", "regex" ]
Regular expression for separating strings
39,434,084
<p>I have the following string</p> <blockquote> <p>Long string 1 [sucess 50] long string 2 [apple 5 banana 20 orange 75] long string 3 [failure: 100]</p> </blockquote> <p>Now I want to split it into three strings:</p> <ol> <li>Long string 1 [sucess 50]<br/></li> <li>long string 2 [apple 5 banana 20 orange 75]<br...
-7
2016-09-11T08:07:30Z
39,434,201
<pre><code>In [79]: import re In [80]: my_string = "Long string 1 [sucess 50] long string 2 [apple 5 banana 20 orange 75] long string 3 [failure: 100]" In [81]: re.findall(r'([^\[]*\[[^\]]*\])(?: ?)', my_string) Out[81]: ['Long string 1 [sucess 50]', 'long string 2 [apple 5 banana 20 orange 75]', 'long string 3 [f...
0
2016-09-11T08:23:30Z
[ "python", "regex" ]
Refreshing a specific div every few seconds in django using javascript
39,434,086
<p>I am trying to refresh the content of a table every few seconds in my html page using javascript. I keep getting 500 error when it tries to refresh the div, internal server error. Could someone enlighten the reason this is not working? I have used this: <a href="http://stackoverflow.com/questions/3776571/refresh-div...
-4
2016-09-11T08:07:44Z
39,434,842
<p>Your django view takes no arguments, but usually django tries to pass request param into it. From the error in the screenshot you provided in comments, looks likе this is your problem. </p> <p>I think you error will be fixed by making your view function take this argument:</p> <pre><code>def specialScoreboardDiv(...
0
2016-09-11T09:47:54Z
[ "javascript", "jquery", "python", "html", "django" ]
Python; How to replace escaped non-unicode characters with their respective 'real' utf-8
39,434,177
<p>I am relatively new to programming, and I have a small problem writing a python equivalent of Snip for spotify for ubuntu(linux) Somehow i can encode the title correctly, but am unable to encode the artist the same way</p> <p>when i try to encode the artist in the same fashion i get this:</p> <pre><code>File "./so...
3
2016-09-11T08:20:40Z
39,434,245
<p>The error you getting is not about unicode, it is about wrong type. Python complains that you trying to call string method <code>encode</code> from the array object. Which does not have this method. </p> <p>The first this I would try is to remove redundant brackets here it getting artiststr like this: <code>artists...
0
2016-09-11T08:30:40Z
[ "python", "unicode", "encoding", "utf-8", "dbus" ]
Python; How to replace escaped non-unicode characters with their respective 'real' utf-8
39,434,177
<p>I am relatively new to programming, and I have a small problem writing a python equivalent of Snip for spotify for ubuntu(linux) Somehow i can encode the title correctly, but am unable to encode the artist the same way</p> <p>when i try to encode the artist in the same fashion i get this:</p> <pre><code>File "./so...
3
2016-09-11T08:20:40Z
39,434,496
<p>Final program, feel free to use if you like:</p> <pre><code>import time import dbus session_bus = dbus.SessionBus() spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2") spotify_properties = dbus.Interface(spotify_bus, "org.freedesktop.DBus.Properties") def currentplayi...
0
2016-09-11T09:03:27Z
[ "python", "unicode", "encoding", "utf-8", "dbus" ]
Python; How to replace escaped non-unicode characters with their respective 'real' utf-8
39,434,177
<p>I am relatively new to programming, and I have a small problem writing a python equivalent of Snip for spotify for ubuntu(linux) Somehow i can encode the title correctly, but am unable to encode the artist the same way</p> <p>when i try to encode the artist in the same fashion i get this:</p> <pre><code>File "./so...
3
2016-09-11T08:20:40Z
39,439,062
<p>Looking at your question <code>metadata</code> contains at least something like this with Unicode strings. The artist field seems to be some sort of iterable the begins with the artist. Something like this (feel free to post actual metadata content):</p> <pre><code>metadata = {'xesam:title':u'title','xesam:artist...
0
2016-09-11T18:00:49Z
[ "python", "unicode", "encoding", "utf-8", "dbus" ]
I can't understand why "ax=ax" meaning in matplotlib
39,434,190
<pre><code>from datetime import datetime fig=plt.figure() ax=fig.add_subplot(1,1,1) data=pd.read_csv(r"C:\Users\champion\Desktop\ch02\spx.csv") spx=data["SPX"] spx.plot(**ax=ax**,style="k-") </code></pre> <p>I can't understand why "ax=ax" meaning in matplotlib.</p>
0
2016-09-11T08:21:47Z
39,434,237
<p>From the documentation of <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html" rel="nofollow">plot()</a>:</p> <blockquote> <p>DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, sharex=None, sharey=False, layout=None, figsize=None, use_index=True, title=N...
0
2016-09-11T08:28:29Z
[ "python", "matplotlib" ]
Using Oauth library in python
39,434,207
<p>I am running a twitter api in python using oauth library. I have included the code below. When I run the code "twtest.py", I get the error `'module' object has no attribute 'OAuthConsumer'.</p> <p>1.twtest.py</p> <pre><code> import urllib from twurl import augment print '* Calling Twitter...' url = a...
0
2016-09-11T08:24:17Z
39,434,272
<p>You need to import <code>oauth</code> from <code>oauth</code> instead of <code>import oauth</code></p> <pre><code>&gt;&gt;&gt; from oauth import oauth &gt;&gt;&gt; oauth.OAuthConsumer &lt;class 'oauth.oauth.OAuthConsumer'&gt; </code></pre>
0
2016-09-11T08:35:03Z
[ "python", "python-2.7", "oauth", "web-scraping", "twitter-oauth" ]
Removing noise from image Python PIL
39,434,216
<p>Newbie here. Have an image I added noise on image, and them i need to clear image with noise(or something like that). The unnoising algorythm is next:</p> <blockquote> <p>If the brightness of the pixel is greater than the average brightness of the local neighborhood, then the brightness of the pixel is replac...
2
2016-09-11T08:25:31Z
39,437,920
<p>First of all, you need to create a copy of your image to write your data to: <code>imgCopy = img.copy()</code>. Else, your noise corrected pixels will influence the correction of pixels not yet touched. In your else statement you simply have to normalize your middle pixel, then multiply it with the average brightnes...
1
2016-09-11T15:52:41Z
[ "python", "python-imaging-library" ]
is this a series or dataframe?
39,434,323
<p>I am quite new to Python, and have some basic questions which I could not find answer till now.</p> <p>suppose I have the following dataframe named phone.</p> <pre><code> current_cellphone | months of usage | previous_cellphone 0 | Motorola | 11 | Motorola 1 | Huawei ...
3
2016-09-11T08:42:40Z
39,434,395
<p>It's <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html" rel="nofollow">pandas.Series</a> object. You can find that out using <a href="https://docs.python.org/2/library/functions.html#type" rel="nofollow">type()</a>.</p> <pre><code>In [157]: phone Out[157]: current_cellphone | mo...
4
2016-09-11T08:51:26Z
[ "python", "pandas", "numpy" ]
is this a series or dataframe?
39,434,323
<p>I am quite new to Python, and have some basic questions which I could not find answer till now.</p> <p>suppose I have the following dataframe named phone.</p> <pre><code> current_cellphone | months of usage | previous_cellphone 0 | Motorola | 11 | Motorola 1 | Huawei ...
3
2016-09-11T08:42:40Z
39,434,479
<pre><code>type(phone['current_cellphone'].value_counts()) pandas.core.series.Series </code></pre> <hr> <pre><code>phone['current_cellphone'].value_counts().to_frame() </code></pre> <p><a href="http://i.stack.imgur.com/a2mWg.png" rel="nofollow"><img src="http://i.stack.imgur.com/a2mWg.png" alt="enter image descript...
3
2016-09-11T09:01:35Z
[ "python", "pandas", "numpy" ]
Post/Redirect/Get pattern in flask
39,434,377
<p>The view function of my toy app was:</p> <pre><code>@app.route('/', methods=['GET', 'POST']) def index(): name = None form = NameForm() if form.validate_on_submit(): name = form.name.data form.name.data = '' return render_template('index.html', form=form, name=name) </code></pre> <p...
0
2016-09-11T08:48:45Z
39,434,390
<p>It can't pass anything on a redirect, as it is a completely new request.</p>
1
2016-09-11T08:51:12Z
[ "python", "redirect", "flask", "flask-wtforms", "post-redirect-get" ]
Python scrapy ReactorNotRestartable substitute
39,434,406
<p>I have been trying to make an app in Python using <code>Scrapy</code> that has the following functionality:</p> <ul> <li>A <strong><em>rest api</em></strong> (I had made that using flask) listens to all requests to crawl/scrap and return the response after crawling.(the crawling part is short enough, so the connect...
7
2016-09-11T08:52:33Z
39,516,357
<p>I recommend you using a queue system like <a href="http://python-rq.org/" rel="nofollow">Rq</a> (for simplicity, but there are few others).<br> You could have a craw function:</p> <pre><code>from twisted.internet import reactor import scrapy from scrapy.crawler import CrawlerRunner from scrapy.utils.log import conf...
1
2016-09-15T16:46:08Z
[ "python", "flask", "scrapy", "reactor", "twisted.internet" ]
Python scrapy ReactorNotRestartable substitute
39,434,406
<p>I have been trying to make an app in Python using <code>Scrapy</code> that has the following functionality:</p> <ul> <li>A <strong><em>rest api</em></strong> (I had made that using flask) listens to all requests to crawl/scrap and return the response after crawling.(the crawling part is short enough, so the connect...
7
2016-09-11T08:52:33Z
39,535,459
<p>Here is a simple solution to your problem</p> <pre><code>from flask import Flask import threading import subprocess import sys app = Flask(__name__) class myThread (threading.Thread): def __init__(self,target): threading.Thread.__init__(self) self.target = target def run(self): sta...
1
2016-09-16T15:45:16Z
[ "python", "flask", "scrapy", "reactor", "twisted.internet" ]
Extending functionality of Element and ElementTree
39,434,449
<p>I would like to extend the functionality of <code>Element</code> and <code>ElementTree</code> classes from <code>xml.etree</code> and use them with <code>xml.etree.ElementTree.parse()</code>.</p> <p>After a few tries, I've managed to create a solution for that problem, but I would like to know if there is a better ...
1
2016-09-11T08:57:27Z
39,434,539
<p>This is the way, hot patching works. But be aware, that the patch has to be applied before any other Module (or Submodule) is imported, that uses ElementTree, too.</p>
0
2016-09-11T09:10:01Z
[ "python", "xml.etree" ]
500 Internal Server Error (trying to upload file)
39,434,467
<p>I have small app in flask was is hosted on pythonanywhere. When I try uploading a file I get 500 error. I copied the code exactly except for changing the UPLOAD_FOLDER path and ALLOWED_EXTENSIONS. Local(on my computer) all working good but on server not.</p> <p><a href="http://pastebin.com/hWdh4VvB" rel="nofollow">...
-1
2016-09-11T08:59:42Z
39,434,930
<p>Looks like the problem is in <code>UPLOAD_FOLDER</code> path value.</p> <p>Your python script complains it can't find the directory you set up for uploads. And since you set up it as:</p> <pre><code>UPLOAD_FOLDER = 'upload/' </code></pre> <p>And in docs this variable has absolute path to the directory, I think, i...
2
2016-09-11T10:01:58Z
[ "python", "flask", "pythonanywhere" ]
Does Python VM cache the integer objects which cannot be released automatically?
39,434,547
<p>I have a single script as below:</p> <pre><code>a = 999999999999999999999999999999 b = 999999999999999999999999999999 print(a is b) </code></pre> <p>Output is:</p> <pre><code>[root@centos7-sim04 python]# python test2.py True </code></pre> <p>On the other hand, the same code with command line:</p> <pre><code>&gt...
2
2016-09-11T09:10:50Z
39,434,850
<p>Regarding your first question actually that because of peephole optimizer which simplifies the expressions. Which in this case it means using one integer for all equal ones. It also use this approach for interning the strings.</p> <p>The reason that you don't see such behavior within the interactive shell is that e...
0
2016-09-11T09:49:07Z
[ "python", "integer" ]
Extract data from JSON in python
39,434,587
<p>Can I access link inside <code>next</code> from the below <code>Json</code> data? I am doing in this way </p> <pre><code>data = json.loads(html.decode('utf-8')) for i in data['comments']: for h in i['paging']: print(h) { </code></pre> <p>Because <code>comments</code> is a main object. Inside th...
0
2016-09-11T09:16:26Z
39,434,634
<p>You're iterating through "comments" which results in three objects: <code>data</code>, <code>paging</code>, and <code>summary</code>. All you want is <code>paging</code>, but your first for-loop wants you to go through all the others.</p> <p>Thus, when it starts with <code>data</code>, you're trying to call <code>d...
1
2016-09-11T09:21:54Z
[ "python", "json" ]
Why do I get this TypeError?
39,434,606
<p>I believe this error means I can't include a variable in a loop however I am struggling to see a way around....</p> <p>the error is </p> <pre><code>TypeError: range() integer end argument expected, got unicode. </code></pre> <p>The problem the book tried to ask me is: </p> <blockquote> <p>Try wring a program t...
1
2016-09-11T09:19:02Z
39,434,667
<p>The <code>raw_input</code> function gives you a <em>string,</em> not an integer. If you want it as an integer (such as if you want to multiply it by twelve or use it in that <code>range</code> call), you need something such as:</p> <pre><code>choice = int(raw_input("Which times table would you like")) </code></pre>...
1
2016-09-11T09:25:50Z
[ "python", "python-2.7" ]
Why do I get this TypeError?
39,434,606
<p>I believe this error means I can't include a variable in a loop however I am struggling to see a way around....</p> <p>the error is </p> <pre><code>TypeError: range() integer end argument expected, got unicode. </code></pre> <p>The problem the book tried to ask me is: </p> <blockquote> <p>Try wring a program t...
1
2016-09-11T09:19:02Z
39,434,673
<p>Your program will run with a few changes.</p> <pre><code>def main(): pass choice = input("Which times table would you like") print ("This is the " + choice + "'s times table to 12") var1 = int(choice)*12 + 1 for loopCounter in range (0,var1,int(choice)): print(loopCounter) if __name__ == ...
-1
2016-09-11T09:26:53Z
[ "python", "python-2.7" ]
Why do I get this TypeError?
39,434,606
<p>I believe this error means I can't include a variable in a loop however I am struggling to see a way around....</p> <p>the error is </p> <pre><code>TypeError: range() integer end argument expected, got unicode. </code></pre> <p>The problem the book tried to ask me is: </p> <blockquote> <p>Try wring a program t...
1
2016-09-11T09:19:02Z
39,434,678
<p>This error just means that it got a unicode value when an integer was assumed. That happens because you use <code>raw_input</code> for <code>choice</code>.</p> <p>Edit: <code>raw_input</code> does not interpret your input. <code>input</code> does. </p>
0
2016-09-11T09:27:23Z
[ "python", "python-2.7" ]
Setting elements to None in pandas dataframe
39,434,733
<p>I'm not sure why this happens</p> <pre><code>&gt;&gt;&gt; df = pd.DataFrame(np.arange(15).reshape(5,3),columns=list('ABC')) &gt;&gt;&gt; df A B C 0 0 1 2 1 3 4 5 2 6 7 8 3 9 10 11 4 12 13 14 </code></pre> <p>Assign <code>None</code> to elements in last row turns it into <code>NaN N...
1
2016-09-11T09:34:54Z
39,434,877
<p>It's because your dtypes are being changed after each assignment:</p> <pre><code>In [7]: df = pd.DataFrame(np.arange(15).reshape(5,3),columns=list('ABC')) In [8]: df.dtypes Out[8]: A int32 B int32 C int32 dtype: object In [9]: df.ix[5,:] = None In [10]: df.dtypes Out[10]: A float64 B float64 C ...
2
2016-09-11T09:53:10Z
[ "python", "pandas", "dataframe" ]
How to change element class attribute value using selenium
39,434,821
<p>I lost my credentials.. so I'm creating this new thread. The old question it here if it helps: <a href="http://stackoverflow.com/questions/39424703/how-to-click-a-button-to-vote-with-python">How to click a button to vote with python</a></p> <p>I'd like to change this line:</p> <pre><code>&lt;a data-original-title=...
1
2016-09-11T09:44:39Z
39,439,119
<p>From comments:-</p> <blockquote> <p>Do you want to interact with element which has <code>data-faucet</code> attribute value <code>39274</code>??</p> <p>exatly! just what I want to do!</p> </blockquote> <p>You should try using <code>css_selector</code> as below :-</p> <pre><code>element = driver.find_elemen...
0
2016-09-11T18:05:50Z
[ "python", "python-3.x", "selenium", "selenium-webdriver", "css-selectors" ]
Why is sklearn's Perceptron predicting with accuracy, precision etc. of 1?
39,434,858
<p>I am using sklearn.linear_model.Perceptron on a synthetic dataset I created. The data consists of 2 classes each of which is a multivariate Gaussian with a common non-diagonal covariance matrix. The centroids of the classes are close enough that there is significant overlap. </p> <pre><code>mean1 = np.ones((20,)) m...
1
2016-09-11T09:50:40Z
39,436,473
<p>The correct way of using <code>cross_validation.train_test_split</code> is to give it the complete dataset, and letting it partition the data to <code>x_train, x_test, y_train, y_test</code>.</p> <p>The following code works better:</p> <pre><code>class1 = np.random.multivariate_normal(mean1, cov, 2000) class2 = np...
-1
2016-09-11T13:12:23Z
[ "python", "scikit-learn" ]
Youtube-dl python module missing ffprobe or avprobe
39,434,894
<p>I am just trying to run the example of converting youtube videos to mp3. Here is the code: </p> <pre><code>from __future__ import unicode_literals import youtube_dl def my_hook(d): if d['status'] == 'finished': print('Done downloading, now converting ...') ydl_opts = { 'format': 'bestaudio/bes...
0
2016-09-11T09:56:05Z
39,589,158
<p>You must placed ffmpeg.exe and ffprobe.exe into your youtube-dl project directory root. This works fine.</p>
0
2016-09-20T08:28:14Z
[ "python", "youtube", "youtube-dl", "ffprobe", "avprobe" ]
Sort certain rows in Data Frames by columns
39,434,933
<p>I have a dataframe that is unsorted. I want to sort columns <code>A</code>,<code>B</code>,<code>C</code> and <code>D</code> in descending order (largest to smallest) however they must remain in the denomination group. For example, it should sort denomination 100 by columns <code>A</code>,<code>B</code>,<code>C</code...
1
2016-09-11T10:02:50Z
39,434,976
<p>This should do it:</p> <pre><code>df.sort_values(by=['Denomination', 'A', 'B', 'C', 'D'], ascending=[True, False, False, False, False]) Out: Denomination A B C D 0 100 5 0 0 0 2 100 0 2 0 0 1 100 0 0 1 0 6 200 10 0 0 0 3 2...
3
2016-09-11T10:07:58Z
[ "python", "sorting", "pandas", "dataframe" ]
Django rest_framework IsAdminUser not behaving
39,434,937
<p>I have a <code>viewset</code> in rest framework that is not behaving like I would expect. If I login with a non-staff user and navigate to the api-url/users I can see all the users listed there. </p> <p>The <code>IsAuthenticated</code> permission is working, because if I logout I get an error saying that I am not a...
0
2016-09-11T10:03:15Z
39,434,975
<p>Typo!</p> <p>It's <a href="http://www.django-rest-framework.org/api-guide/permissions/" rel="nofollow"><code>permission_classes</code></a>, not <code>permissions_classes</code>.</p> <hr> <p>About this part:</p> <blockquote> <p>The IsAuthenticated permission is working, because if I logout I cget an error saysi...
1
2016-09-11T10:07:56Z
[ "python", "django", "django-rest-framework" ]
AttributeError: 'Timestamp' object has no attribute 'timestamp
39,434,979
<p>While converting a <code>panda</code> object to a timestamp, I am facing this strange issue.</p> <p>Train['date'] value is like <code>01/05/2014</code> which I am trying to convert into linuxtimestamp.</p> <p>My code:</p> <pre><code>Train = pd.read_csv("data.tsv", sep='\t') # use TAB as column separator Train['ti...
0
2016-09-11T10:08:36Z
39,435,091
<p>The method to_datetime will return a <code>TimeStamp</code> instance. I'm not sure what you are hoping to accomplish by the lambda function, but it appears you are trying to convert some object to a <code>TimeStamp</code>. </p> <p>Try removing the apply section so it looks like this:</p> <p><code>Train['timestamp...
0
2016-09-11T10:25:13Z
[ "python", "time", "timestamp" ]
AttributeError: 'Timestamp' object has no attribute 'timestamp
39,434,979
<p>While converting a <code>panda</code> object to a timestamp, I am facing this strange issue.</p> <p>Train['date'] value is like <code>01/05/2014</code> which I am trying to convert into linuxtimestamp.</p> <p>My code:</p> <pre><code>Train = pd.read_csv("data.tsv", sep='\t') # use TAB as column separator Train['ti...
0
2016-09-11T10:08:36Z
39,679,056
<p>You're looking for <a href="https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp" rel="nofollow"><code>datetime.timestamp()</code></a>, which was added in Python 3.3. Pandas itself isn't involved.</p> <blockquote> <p><em>N.B.</em> <code>.timestamp()</code> will localize naive timestamps to ...
0
2016-09-24T17:26:54Z
[ "python", "time", "timestamp" ]
Comparing by section two numpy arrays in python and displays the index column which is not the same
39,434,996
<p>I want to show you where the index column of the array is not the same.</p> <pre><code>import numpy as np array1 = np.array(list(np.zeros(10))+list(np.ones(10))) array2 = np.array(list(np.random.randint(2, size=10))+list(np.random.randint(2, size=10))) matches = array1 == array2 section_sums = np.bincount(np.arange...
0
2016-09-11T10:11:38Z
39,435,090
<p>Here's an approach -</p> <pre><code>idx = np.flatnonzero(~matches) cut_idx = np.unique(idx//10,return_index=True)[1] out = np.split(np.mod(idx,10)+1,cut_idx)[1:] </code></pre> <p>Sample run for the given input arrays -</p> <pre><code>In [182]: matches = array1 == array2 ...: idx = np.flatnonzero(~matches) ...
0
2016-09-11T10:24:51Z
[ "python", "arrays", "python-2.7", "numpy" ]
Comparing by section two numpy arrays in python and displays the index column which is not the same
39,434,996
<p>I want to show you where the index column of the array is not the same.</p> <pre><code>import numpy as np array1 = np.array(list(np.zeros(10))+list(np.ones(10))) array2 = np.array(list(np.random.randint(2, size=10))+list(np.random.randint(2, size=10))) matches = array1 == array2 section_sums = np.bincount(np.arange...
0
2016-09-11T10:11:38Z
39,435,098
<p>If you split your arrays into the two section then you can compare them.</p> <pre><code>In [18]: a = np.array(np.split(a, [10])) In [19]: b = np.array(np.split(b, [10])) In [23]: ind, items = np.where(a != b) In [25]: items[ind==0] + 1 Out[25]: array([ 2, 4, 5, 6, 8, 10]) In [26]: items[ind==1] + 1 Out[26]:...
1
2016-09-11T10:25:48Z
[ "python", "arrays", "python-2.7", "numpy" ]
python list comprehension to create repeated value from the list
39,435,027
<p>I am trying to create </p> <pre><code>[ x for x in [1,2,3] for y in [3,1,4] ] </code></pre> <p>Output:</p> <pre><code>[1, 1, 1, 2, 2, 2, 3, 3, 3] </code></pre> <p>but what I want is to create </p> <ul> <li>1 3 times </li> <li>2 1 times </li> <li>3 4 times</li> </ul> <p><strong>Expected Output:</strong>...
0
2016-09-11T10:16:11Z
39,435,040
<p>Use the <a href="https://docs.python.org/3/library/functions.html#zip"><code>zip()</code> function</a> to pair up your numbers with their counts:</p> <pre><code>numbers = [1, 2, 3] counts = [3, 1, 4] output = [n for n, c in zip(numbers, counts) for _ in range(c)] </code></pre>
5
2016-09-11T10:17:44Z
[ "python", "list" ]
python list comprehension to create repeated value from the list
39,435,027
<p>I am trying to create </p> <pre><code>[ x for x in [1,2,3] for y in [3,1,4] ] </code></pre> <p>Output:</p> <pre><code>[1, 1, 1, 2, 2, 2, 3, 3, 3] </code></pre> <p>but what I want is to create </p> <ul> <li>1 3 times </li> <li>2 1 times </li> <li>3 4 times</li> </ul> <p><strong>Expected Output:</strong>...
0
2016-09-11T10:16:11Z
39,435,045
<p>Sure, with <code>zip</code>:</p> <pre><code>&gt;&gt;&gt; [item for x,y in zip([1,2,3], [3,1,4]) for item in [x]*y] [1, 1, 1, 2, 3, 3, 3, 3] </code></pre>
2
2016-09-11T10:18:12Z
[ "python", "list" ]
python list comprehension to create repeated value from the list
39,435,027
<p>I am trying to create </p> <pre><code>[ x for x in [1,2,3] for y in [3,1,4] ] </code></pre> <p>Output:</p> <pre><code>[1, 1, 1, 2, 2, 2, 3, 3, 3] </code></pre> <p>but what I want is to create </p> <ul> <li>1 3 times </li> <li>2 1 times </li> <li>3 4 times</li> </ul> <p><strong>Expected Output:</strong>...
0
2016-09-11T10:16:11Z
39,435,064
<p>I'm you could also use <code>np.repeat</code> if you fine with an array as a results</p> <pre><code>import numpy as np np.repeat([1, 2, 3] ,[3, 1, 4]) </code></pre>
1
2016-09-11T10:21:35Z
[ "python", "list" ]
Ranking tweets from most relevant to least relevant in a document using Python
39,435,110
<p>I have a document with, say, 15 tweets. Given a query, how can we rank the tweets from most relevant to the query to least relevant?</p> <p>That is, let D be the document containing 15 tweets:</p> <pre><code>D = ['Tweet 1', 'Tweet 2' ..... 'Tweet 15'] Q = "some noun phrase" </code></pre> <p>Given Q, what method w...
-3
2016-09-11T10:27:04Z
39,435,161
<p>It can be on the basis of how many words contained in the tweet are contained on the tweet topic. If they are on the same topic or the top topic, ranking should be a good idea.</p>
0
2016-09-11T10:34:46Z
[ "python", "python-2.7", "tf-idf", "topic-modeling" ]
Ranking tweets from most relevant to least relevant in a document using Python
39,435,110
<p>I have a document with, say, 15 tweets. Given a query, how can we rank the tweets from most relevant to the query to least relevant?</p> <p>That is, let D be the document containing 15 tweets:</p> <pre><code>D = ['Tweet 1', 'Tweet 2' ..... 'Tweet 15'] Q = "some noun phrase" </code></pre> <p>Given Q, what method w...
-3
2016-09-11T10:27:04Z
39,435,469
<p>Yoe need <a href="http://www.nltk.org&quot;" rel="nofollow">nltk</a> (Natural Language Toolkit) libery. There is built-in function which count tf-idf</p>
0
2016-09-11T11:13:20Z
[ "python", "python-2.7", "tf-idf", "topic-modeling" ]
Python version conflicts and pip3
39,435,176
<p>It is a tough situation I am dealing with. Here is short version of my problem:</p> <ul> <li>I am working on Ubuntu 12.04</li> <li>I would like to install <code>Python 3.5.x</code> with <code>openCV</code> library. I would also like to use <code>pip3</code> for managing package installation of python. </li> </ul> ...
0
2016-09-11T10:36:18Z
39,474,390
<blockquote> <p>This solved my first problem. Now the second problem aslo remains, how can I install pip3 under python 3.5.2 (preferably using viretualenv) ?</p> </blockquote> <p>Here is answer:</p> <pre><code>python3 -m virtualenv py3env source py3env/bin/activate </code></pre> <p>Python 3.5 should have pip by...
1
2016-09-13T15:59:49Z
[ "python", "python-3.x", "pip" ]
Plotting 2 data sets in 1 graph + linear regression in MATPLOTLIB
39,435,177
<p>I'm new to Python and have any programming background.. I'm trying to plot 2 data sets of y for the same x data set, linear regress it using scipy and get the R^2 value. This is how i've gotten so far:</p> <pre><code>import matplotlib import matplotlib.pyplot as pl from scipy import stats #first order '''sin(Δθ...
0
2016-09-11T10:36:23Z
39,435,241
<p>There are multiple errors in this code.</p> <ol> <li><p>You cannot simply type greek letters in plot labels and titles, here is how you can do it:</p> <pre><code>pl.xlabel(r'theoretical $\lambda$ (in nm)') </code></pre></li> <li><p><code>y1label</code> and <code>y2label</code> are not objects of the <code>pl</code...
0
2016-09-11T10:47:03Z
[ "python", "matplotlib", "linear-regression" ]
python pandas elegant dataframe access rows 2:end
39,435,218
<p>I have a dataframe, <code>dF = pd.DataFrame(X)</code> where X is a numpy array of doubles. I want to remove the last row from the dataframe. I know for the first row I can do something like this <code>dF.ix[1:]</code>. I want to do something similar for the last row. I know in matlab you could do something like this...
1
2016-09-11T10:42:34Z
39,435,700
<p>you can do it this way:</p> <pre><code>In [129]: df1 Out[129]: c1 c2 c3 0 1 2 3 1 4 5 6 2 7 8 9 In [130]: df2 Out[130]: c1 c2 c3 0 a b c 1 d e f 2 g h i In [131]: df1.iloc[1:].reset_index(drop=1).join(df2.iloc[:-1].reset_index(drop=1), rsuffix='_2') Out[131]: c1 c2 c3 c1_2 c...
0
2016-09-11T11:42:07Z
[ "python", "matlab", "pandas", "numpy" ]
Appending data to Dataframe
39,435,236
<p>I have a directory which contains some csv files called :</p> <pre><code>results_roll_3_oe_2016-02-04 results_roll_2_oe_2016-01-28 </code></pre> <p>results_roll_3_oe_2016-02-04 looks like:</p> <pre><code>date day_performance 2016-01-26 3.714011839374111 2016-01-27 -8.402334555591418 2016-01-28 -41.0...
2
2016-09-11T10:46:18Z
39,435,264
<p><strong>UPDATE:</strong> your CSV files are either space-delimited or TAB-delimited, so you have to specify it. Beside that all your CSV files have a header line and have only two columns, so you don't need to use <code>usecols</code>, <code>header</code>, <code>names</code> parameters:</p> <pre><code>In [100]: fma...
0
2016-09-11T10:49:15Z
[ "python", "pandas" ]
Insert statment created by django ORM at bulk_create
39,435,322
<p>I am kind of new to python and django.</p> <p>I am using <code>bulk_create</code> to insert a lot of rows and as a former DBA I would very much like to see what insert statments are being executed. I know that for querys you can use <code>.query</code> but for insert statments I can't find a command.</p> <p>Is the...
0
2016-09-11T10:55:08Z
39,437,816
<p>The easiest way is to set <code>DEBUG = True</code> and check <code>connection.queries</code> after executing the query. This stores the raw queries and the time each query takes. </p> <pre><code>from django.db import connection MyModel.objects.bulk_create(...) print(connection.queries[-1]['sql']) </code></pre> ...
0
2016-09-11T15:41:52Z
[ "python", "django", "orm" ]
How do I make strings and variables editable and printing them? (Python)
39,435,339
<p>Yes I know that this is very much to ask, and I'm sorry, but I usually learn the best by doing stuff instead of reading stuff.</p> <p>So I would like to for example set a variable to 1995 and a string to John and then when I open the python file, I would be able to see the name of the string and variable and change...
-2
2016-09-11T10:56:50Z
39,435,496
<p>for learn you should read python reference:</p> <p><a href="https://www.python.org/" rel="nofollow">https://www.python.org/</a></p> <p>but :</p> <p>in python create variable is very easy </p> <pre><code>year = 1995 </code></pre> <p>and then :</p> <pre><code>year = input("Enter Year:") print(year) </code></pre>...
1
2016-09-11T11:16:14Z
[ "python" ]
Python trainticket machine
39,435,359
<p>I am stuck at an excercise, I need to make a train ticket machine but I am just 1 week practicing in Python and I don't know how to start.</p> <p>First I've got this:</p> <pre><code>stations = ['Schagen', 'Heerhugowaard', 'Alkmaar', 'Castricum', 'Zaandam', 'Amsterdam Sloterdijk','Amsterdam Centraal', 'Amsterdam Am...
0
2016-09-11T10:58:44Z
39,436,860
<p>In languages like C++ and Java, you use curly braces for different constructs. However, in Python, you use spaces or tabs for indentation instead of curly braces.</p> <p>Here's a code that will get you started:</p> <pre><code>src = input('Source station:') dest = input('Destination: ') if src in stations and dest...
0
2016-09-11T14:01:18Z
[ "python", "python-3.x" ]
Can I join lists with sum()?
39,435,401
<p>Is it pythonic to use <code>sum()</code> for list concatenation?</p> <pre><code>&gt;&gt;&gt; sum(([n]*n for n in range(1,5)),[]) [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] </code></pre>
3
2016-09-11T11:03:17Z
39,435,470
<p>No it's not, Actually it's <a href="http://en.wikichip.org/wiki/schlemiel_the_painter%27s_algorithm" rel="nofollow">shlemiel the painter algorithm</a>. Because each time it wants to concatenate a new list it has to traverse the whole list from beginning. (For more info read this article by Joel: <a href="http://www...
8
2016-09-11T11:13:24Z
[ "python" ]
Can I join lists with sum()?
39,435,401
<p>Is it pythonic to use <code>sum()</code> for list concatenation?</p> <pre><code>&gt;&gt;&gt; sum(([n]*n for n in range(1,5)),[]) [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] </code></pre>
3
2016-09-11T11:03:17Z
39,435,707
<p>No, this will get very slow for large lists. List comprehensions are a far better option.</p> <p>Code for timing list flattening via list comprehensions, summation and itertools.chain.from_iterable:</p> <pre><code>import time from itertools import chain def increasing_count_lists(upper): yield from ([n]*n for...
3
2016-09-11T11:43:14Z
[ "python" ]
Django datatable and enum
39,435,418
<p>I have a campaign model as follows:</p> <pre><code>id campaign objective platform 1 Hello Word MOBILE_APP_ENGAGEMENT Facebook 2 Hi There VIDEO_VIEWS_PREROLL Twitter </code></pre> <p>Model:</p> <pre><code>class Campaign(Model): id = models.TextField(primary_key=True) name = models.Te...
2
2016-09-11T11:06:06Z
39,437,249
<p>As far as I know (which isn't much where Django is concerned), to make this work you'll need to use a single <code>Enum</code> per field. So in your case I would put the Twitter or FB designation in the name of the members:</p> <pre><code>Class Objective(Enum): FB_MOBILE_APP_ENGAGEMENT FB_MOBILE_APP_DOWNLO...
1
2016-09-11T14:45:07Z
[ "python", "django", "enums" ]
Creating a Calc Function that performs arithmetic in Python
39,435,436
<p>Ok, so I'm trying to create a function in Python named calc that can perform the 4 basic arithmetic operations.</p> <pre><code>def calc(n, num1, num2): if n == '+': return num1 + num2 elif n == '-': return num1 - num2 elif n == 'x': return num1 * num2 elif n == '/': ...
0
2016-09-11T11:08:49Z
39,435,468
<p>You can't make a function which would handle this:</p> <pre><code>calc(+ 4 6) </code></pre> <p>That is invalid syntax.</p> <p>But you could do this:</p> <pre><code>calc('+', 4, 6) </code></pre> <p>You function would already work with it.</p> <p>Or you could have this:</p> <pre><code>calc('+ 4 6') </code></pre...
0
2016-09-11T11:13:15Z
[ "python", "function" ]
Why is Python 3 http.client so much faster than python-requests?
39,435,443
<p>I was testing different Python HTTP libraries today and I realized that <a href="https://docs.python.org/3/library/http.client.html" rel="nofollow"><code>http.client</code></a> library seems to perform much much faster than <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a>...
1
2016-09-11T11:09:45Z
39,438,703
<p>Based on profiling both, the main difference appears to be that the <code>requests</code> version is doing a DNS lookup for every request, while the <code>http.client</code> version is doing so once.</p> <pre><code># http.client ncalls tottime percall cumtime percall filename:lineno(function) 1974 0.541...
4
2016-09-11T17:20:22Z
[ "python", "http", "python-requests" ]
Why is Python 3 http.client so much faster than python-requests?
39,435,443
<p>I was testing different Python HTTP libraries today and I realized that <a href="https://docs.python.org/3/library/http.client.html" rel="nofollow"><code>http.client</code></a> library seems to perform much much faster than <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a>...
1
2016-09-11T11:09:45Z
39,446,009
<p>copy-pasting response from @Lukasa posted <a href="https://github.com/kennethreitz/requests/issues/3568#issuecomment-246271506" rel="nofollow">here</a>:</p> <blockquote> <p>The reason Requests is slower is because it does substantially more than httplib. httplib can be thought of as the bottom layer of the stack:...
0
2016-09-12T08:19:20Z
[ "python", "http", "python-requests" ]
How to generate numbers in range with specific average with Python?
39,435,481
<p>For example I would like to generate 22 numbers between 20 and 46 with an average value of 27. And I would like the numbers to cover the range as well as possible.</p> <p>EDIT: These numbers don't need to be random.</p>
1
2016-09-11T11:14:23Z
39,435,600
<p>Warning: this is not the optimal solution but it works quite fast with your input parameters:</p> <pre><code>import random def gen_avg(expected_avg=27, n=22, a=20, b=46): while True: l = [random.randint(a, b) for i in range(n)] avg = reduce(lambda x, y: x + y, l) / len(l) if avg == ex...
3
2016-09-11T11:29:12Z
[ "python", "math" ]
How to generate numbers in range with specific average with Python?
39,435,481
<p>For example I would like to generate 22 numbers between 20 and 46 with an average value of 27. And I would like the numbers to cover the range as well as possible.</p> <p>EDIT: These numbers don't need to be random.</p>
1
2016-09-11T11:14:23Z
39,435,610
<p>You could sove this in a pure mathematical way. <br/></p> <ol> <li>Randomly pick a number (call it n) within the wanted range</li> <li>The next number will be avg + abs(n-avg)</li> <li>repeat this until you fill the amount of numbers you want</li> </ol> <p>if the amount of needed numbers is no even - just select o...
1
2016-09-11T11:30:34Z
[ "python", "math" ]
How to generate numbers in range with specific average with Python?
39,435,481
<p>For example I would like to generate 22 numbers between 20 and 46 with an average value of 27. And I would like the numbers to cover the range as well as possible.</p> <p>EDIT: These numbers don't need to be random.</p>
1
2016-09-11T11:14:23Z
39,436,460
<p>So I also used the random number generator. In addition, in order to meet the specification to cover the range as well as possible, I also calculated the standard deviation, which is a good measure of spread. So whenever a sample set meets the criteria of mean of 27, I compared it to previous matches and constantly ...
1
2016-09-11T13:10:53Z
[ "python", "math" ]
How to generate numbers in range with specific average with Python?
39,435,481
<p>For example I would like to generate 22 numbers between 20 and 46 with an average value of 27. And I would like the numbers to cover the range as well as possible.</p> <p>EDIT: These numbers don't need to be random.</p>
1
2016-09-11T11:14:23Z
39,445,629
<p>Not optimal in terms of covering the range as much as possible, but you can try this:</p> <pre><code>def GenerateArr(count,minimum,maximum,average): arr = [] diff = 1 while len(arr) &lt; count-1: if minimum &lt;= average-diff and average+diff &lt;= maximum: arr.append(average-diff) ...
1
2016-09-12T07:50:44Z
[ "python", "math" ]
How to run Scrapy unit tests in Pycharm
39,435,518
<p>I am working with Pycharm, trying to run scrapy unit tests - and it fails to run. The errors are for missing imports, seems like all imports are failing. e.g.</p> <pre><code> Import error... "no module named mock" </code></pre> <p>what I did:</p> <ol> <li><p>Get scrapy from github</p></li> <li><p>Run pip to insta...
4
2016-09-11T11:18:02Z
39,435,565
<p>You need to additionally pip install the <a href="https://github.com/scrapy/scrapy/blob/master/tests/requirements.txt" rel="nofollow">tests requirements</a>:</p> <pre><code>pip install -r tests/requirements.txt # Python 2 pip install -r tests/requirements-py3.txt # Python 3 </code></pre> <p>That would install th...
4
2016-09-11T11:24:31Z
[ "python", "python-2.7", "scrapy", "pycharm" ]
"Can't load the profile" error occured with Selenium WebDriver by Python3.5 and FF48
39,435,532
<p>&nbsp;I'm trying to use Selenium with Python.<br /> &nbsp;So, I wrote the following codes and save as the file named <strong>test.py</strong> in working directory <strong>/Users/ykt68/seleniumwork</strong> .</p> <pre class="lang-none prettyprint-override"><code>[ykt68@macbp15 seleniumwork]$ pwd /Users/ykt68/seleniu...
4
2016-09-11T11:19:46Z
39,435,615
<p>From what I understand and concluded, you can keep the latest <code>selenium</code> package version, but you have to <em>downgrade Firefox to 47</em> (<a href="https://ftp.mozilla.org/pub/firefox/releases/47.0.1/" rel="nofollow">47.0.1</a> is the latest stable from the 47 branch).</p>
2
2016-09-11T11:31:21Z
[ "python", "selenium", "selenium-webdriver" ]
Transforming string output to JSON
39,435,620
<p>I'm getting some data from an external system (Salesforce Marketing Cloud) over API and I'm getting the data back in the format below:</p> <pre><code>Results: [(List){ Client = (ClientID){ ID = 113903 } PartnerKey = None CreatedDate = 2013-07-29 04:43:32.000073 ModifiedDate = 2013-0...
5
2016-09-11T11:31:52Z
39,440,076
<p>It looks like an object called suds which is already in Python. The Fuel-SDK uses it.</p> <p>The suds object already did that for you. Just call the attribute you are looking for.</p> <p><BR> However, if you want it as a dict, attached is the common function for that:</p> <pre><code>from suds.sudsobject import as...
1
2016-09-11T19:56:04Z
[ "python", "json" ]
Transforming string output to JSON
39,435,620
<p>I'm getting some data from an external system (Salesforce Marketing Cloud) over API and I'm getting the data back in the format below:</p> <pre><code>Results: [(List){ Client = (ClientID){ ID = 113903 } PartnerKey = None CreatedDate = 2013-07-29 04:43:32.000073 ModifiedDate = 2013-0...
5
2016-09-11T11:31:52Z
39,440,332
<p>To convert your array, you could use var jsonString = JSON.stringify(yourArray);</p>
2
2016-09-11T20:28:19Z
[ "python", "json" ]
ERR IOError: [Errno 21] Is a directory: '/app/.heroku/python/lib/python2.7/site-packages/setuptools-20.3-py2.7.egg'
39,435,645
<p>I try to deploy a Flask app in python (python 2.7.10). It is a very easy app with requirements.txt </p> <ul> <li>Flask==0.10.1</li> <li>distribute==0.6.27</li> <li>setuptools==20.3</li> <li>scipy==0.17</li> <li>matplotlib==1.5.1</li> <li>pickleshare==0.7.2</li> <li>scikit-learn==0.17.1</li> <li>numpy==1.11.1</li> ...
0
2016-09-11T11:35:46Z
39,449,227
<p>Solved ! Instead of writing if name == "main": app.run() Just do port = os.getenv('PORT', PORT_NUMBER) if name == "main": app.run(host='0.0.0.0', port=int(port)) and it works !</p>
0
2016-09-12T11:23:59Z
[ "python", "heroku", "flask", "ibm-bluemix" ]
Wagtail: How can I copy a page instance in wagtail with all its property and method
39,435,711
<p>I have a CoursePage model in Wagtail site.</p> <pre><code>class CoursePage(Page): ..... institute = models.ForeignKey(Institute) ..... </code></pre> <p>I have a django models ForeignKey field in it named <em>institute</em></p> <p>I want to make a copy of its instance programmatically so that the newly...
0
2016-09-11T11:43:42Z
39,437,618
<p>The <code>Page</code> model implements a <code>copy</code> method to do this:</p> <pre><code>def copy(self, recursive=False, to=None, update_attrs=None, copy_revisions=True, keep_live=True, user=None): </code></pre> <p>The parameters it accepts are:</p> <ul> <li><code>recursive</code> - if true, copies c...
1
2016-09-11T15:21:16Z
[ "python", "django-models", "wagtail" ]
Setting scan coordinates in device options on pyinsane
39,435,820
<p>I use Sane's command line utility (<code>scanimage</code>) in order to scan films from the transparency unit of my scanner. Here is the command that I have been using with success:</p> <pre><code>scanimage --device-name pixma:04A9190D \ --source 'Transparency Unit' \ --resolution "4800" \ --format "tiff" \ --mode "...
0
2016-09-11T11:58:12Z
39,449,601
<p>pyinsane's option descriptions actually say the values are in milimeters: </p> <pre><code>Option: br-x Title: Bottom-right x Desc: Bottom-right x position of scan area. Type: &lt;class 'pyinsane.rawapi.SaneValueType'&gt; : Fixed (2) Unit: &lt;class 'pyinsane.rawapi.SaneUnit'&gt; : Mm (3) Size: 4 Capabi...
0
2016-09-12T11:47:26Z
[ "python", "scanning", "sane", "pyinsane" ]
Setting scan coordinates in device options on pyinsane
39,435,820
<p>I use Sane's command line utility (<code>scanimage</code>) in order to scan films from the transparency unit of my scanner. Here is the command that I have been using with success:</p> <pre><code>scanimage --device-name pixma:04A9190D \ --source 'Transparency Unit' \ --resolution "4800" \ --format "tiff" \ --mode "...
0
2016-09-11T11:58:12Z
39,919,746
<p>Pyinsane reports what Sane reports, as is. And Sane reports what the drivers report. In my experience, all the drivers don't behave exactly the same way, which may explain this weird unit (in other words, it could be a driver's bug). I never really worried about the unit before. I will check on my scanner what it sa...
0
2016-10-07T14:31:06Z
[ "python", "scanning", "sane", "pyinsane" ]
Django rest framework, should be able to override get_queryset and not define queryset attribute?
39,435,836
<p>I am confused. Looking through the ViewSet source code it looks like I should be able to not define a queryset in a viewset and then just override the get queryset function to get whatever queryset I want. But my code fails with this error:</p> <pre><code>AssertionError: `base_name` argument not specified, and coul...
1
2016-09-11T12:01:09Z
39,436,581
<p>DRF Router is complaining, because it can't <a href="http://www.django-rest-framework.org/api-guide/routers/" rel="nofollow">automatically generate a basename for the viewset</a>:</p> <blockquote> <p><strong>base_name</strong> - The base to use for the URL names that are created. If unset the basename will be aut...
1
2016-09-11T13:25:39Z
[ "python", "django", "django-rest-framework" ]