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
Incorrect Padding error while decoding base64 encoding
38,006,798
<p>I have tried to decode a PDF I stored as BLOB and save it into a file with .pdf extension. results[0][1] has the BLOB data extracted from database query.</p> <pre><code> blob_val=results[0][1] if len(blob_val) % 4 != 0: while len(blob_val) % 4 != 0: blob_val = blob_val + b...
0
2016-06-24T06:21:45Z
38,008,093
<p>Each base64 char is encoding six bits. For this to work, the total number of bytes should be divisible by three, not four.</p> <p>This should work (and be a bit simplified):</p> <pre><code> blob_val = results[0][1] # If the length is divisible by 3, the 'while' will never # be entered, so no point in d...
0
2016-06-24T07:39:59Z
[ "python", "mysql", "python-3.x", "pyqt" ]
type(4) == type(int) is False in Python?
38,006,826
<p>I tried <code>type(4) == type(int)</code>, which returns <code>False</code>, but <code>print type(4)</code> returns <code>&lt;type 'int'&gt;</code>, so 4 is obviously <code>int</code>.</p> <p>Confused why the first statement returns <code>False</code> and not <code>True</code>?</p>
2
2016-06-24T06:23:33Z
38,006,838
<p>Look this:</p> <pre><code>&gt;&gt;&gt; type(int) &lt;type 'type'&gt; &gt;&gt;&gt; type(4) &lt;type 'int'&gt; </code></pre> <p>Yu should use:</p> <pre><code>&gt;&gt;&gt; isinstance(4,int) True </code></pre>
2
2016-06-24T06:24:37Z
[ "python", "python-2.7", "types", "integer" ]
type(4) == type(int) is False in Python?
38,006,826
<p>I tried <code>type(4) == type(int)</code>, which returns <code>False</code>, but <code>print type(4)</code> returns <code>&lt;type 'int'&gt;</code>, so 4 is obviously <code>int</code>.</p> <p>Confused why the first statement returns <code>False</code> and not <code>True</code>?</p>
2
2016-06-24T06:23:33Z
38,006,843
<p>The <code>type</code> of <code>int</code> is <em>type itself</em>:</p> <pre><code>&gt;&gt;&gt; type(int) &lt;type 'type'&gt; </code></pre> <p>You'd compare with <code>int</code> <strong>directly</strong>; <code>int</code> is, after all, a type, as we established above:</p> <pre><code>&gt;&gt;&gt; type(4) == int T...
10
2016-06-24T06:25:00Z
[ "python", "python-2.7", "types", "integer" ]
type(4) == type(int) is False in Python?
38,006,826
<p>I tried <code>type(4) == type(int)</code>, which returns <code>False</code>, but <code>print type(4)</code> returns <code>&lt;type 'int'&gt;</code>, so 4 is obviously <code>int</code>.</p> <p>Confused why the first statement returns <code>False</code> and not <code>True</code>?</p>
2
2016-06-24T06:23:33Z
38,006,864
<p>In Python, type <code>int</code> itself is also a object whose type is <code>type</code>. So <code>type(int)</code> is <code>type</code>. On the other hand, <code>type(4)</code> is <code>int</code></p> <p>So if you want to check if <code>type(4)</code> is type <code>int</code>, you should write as</p> <pre><code>t...
2
2016-06-24T06:26:42Z
[ "python", "python-2.7", "types", "integer" ]
type(4) == type(int) is False in Python?
38,006,826
<p>I tried <code>type(4) == type(int)</code>, which returns <code>False</code>, but <code>print type(4)</code> returns <code>&lt;type 'int'&gt;</code>, so 4 is obviously <code>int</code>.</p> <p>Confused why the first statement returns <code>False</code> and not <code>True</code>?</p>
2
2016-06-24T06:23:33Z
38,006,910
<p>You are comparing <code>int</code> with <code>type(int)</code>, instead you should:</p> <pre><code>type(4) == int </code></pre>
2
2016-06-24T06:29:49Z
[ "python", "python-2.7", "types", "integer" ]
type(4) == type(int) is False in Python?
38,006,826
<p>I tried <code>type(4) == type(int)</code>, which returns <code>False</code>, but <code>print type(4)</code> returns <code>&lt;type 'int'&gt;</code>, so 4 is obviously <code>int</code>.</p> <p>Confused why the first statement returns <code>False</code> and not <code>True</code>?</p>
2
2016-06-24T06:23:33Z
38,007,714
<p>The <code>type of int</code> is <code>type</code> and <code>type of 4</code> is <code>int</code>.</p> <pre><code>&gt;&gt;&gt; type(int) &lt;type 'type'&gt; &gt;&gt;&gt; type(4) &lt;type 'int'&gt; </code></pre> <p>So you doing wrong comparison. What you can do to get the desired output is: Compare the <code>type of...
2
2016-06-24T07:17:16Z
[ "python", "python-2.7", "types", "integer" ]
This code give me a TypeError: unhashable type: 'dict' some please expalain what I may ne doing wrong
38,006,835
<pre><code>theBoard = {} theBoard.setdefault({1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9'}) </code></pre>
-1
2016-06-24T06:24:16Z
38,006,885
<pre><code>theBoard = {} theBoard.update({1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9'}) </code></pre>
1
2016-06-24T06:28:03Z
[ "python", "python-3.x" ]
Haar- Cascade face detection OpenCv
38,006,870
<p>I used the following code to detect a face using Haar cascade classifiers provided by OpenCv Python. But the faces are not detected and the square around the face is not drawn. How to solve this?</p> <pre><code>import cv2 index=raw_input("Enter the index No. : ") cascPath = "haarcascade_frontalface_default.xml" f...
-1
2016-06-24T06:27:00Z
38,041,109
<p>Use the full path for the classifier.</p>
0
2016-06-26T17:16:32Z
[ "python", "opencv" ]
Python loop with enumerate by 2
38,006,929
<p>I'm not 100% sure how to pose the question's title, but what I want to do is simple. I want to loop over a list using the enumerate function in Python, but I want to know if it's possible to do it by 2, something I would do without enumerate, like this:</p> <pre><code>numbers = ['One', 'Two', 'Three', 'Four', 'Five...
0
2016-06-24T06:30:48Z
38,006,988
<p>Just <em>multiply</em> the <code>enumerate()</code> output by two:</p> <pre><code>for i, number in enumerate(numbers): print(i * 2, number) </code></pre> <p>This is essentially what the <code>range()</code> object does in Python 3; calculate the number for any given index. Since your series starts at 0, all yo...
0
2016-06-24T06:34:25Z
[ "python", "list", "for-loop" ]
AttributeError and syntax in Simpy traffic simulation
38,006,945
<p>I am trying to create a discrete event simulation of traffic congestion on a single lane. The lane is divided into 10 segments that are the "width" of each car passing through. These segments all take 1 unit of time to pass. My current set up has cars coming through at the same speed but I will change it to allow fo...
0
2016-06-24T06:31:40Z
38,011,165
<ol> <li><p>Street.seg1 is the function seg1 that you defined within the Strett class, not the resource that you defined above (Why do you even that your resource instances in the simpy-Namespace??).</p></li> <li><p>Yes, there are better ways.</p></li> </ol> <p>I think you should toy around with the examples provided ...
0
2016-06-24T10:26:09Z
[ "python", "simulation", "traffic", "simpy" ]
mocking a variable inside a file
38,006,968
<p>I have a file named</p> <pre><code>a.py file = "/home/test/abc.txt" </code></pre> <p>I am working on creating a unittest for another file which takes value of this file variable from a.py</p> <p>How can I mock this variable name to any dummy file for example?</p> <pre><code>file = "/tmp/a.txt" </code></pre>
0
2016-06-24T06:33:18Z
38,007,939
<p>In your specific case, why not just <code>import a</code> and then <code>a.file = "/tmp/a.txt"</code> ?</p> <p>Which version of Python are you on? Python 3.x has <a href="https://docs.python.org/dev/library/unittest.mock.html" rel="nofollow"><code>unittest.mock</code></a> which is <a href="https://pypi.python.org/p...
0
2016-06-24T07:31:17Z
[ "python", "mocking" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,042
<p>That's because the result of following part is <code>"'ARR'"</code>:</p> <pre><code>&gt;&gt;&gt; ('\'ARR\'' or '\'ABC\'' or '\'SAC\'') "'ARR'" </code></pre> <p>Basically the <code>or</code> operator will return the left operand when both operands are True and here, since all the strings evaluated as True by python...
1
2016-06-24T06:37:54Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,075
<p>You should use <code>in</code> for the search.</p> <pre><code>if MM[0] in {"'ARR'", "'ABC'", "'SAC'"} </code></pre> <p>Then, don't escape everywhere with backslashes, it's ugly. If you know your string has single quotes in it, delimit it with double quotes, it will be much more readable.</p>
0
2016-06-24T06:40:01Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,076
<p>I think this should work </p> <pre><code>MM[0] in ('ARR', 'ABC','SAC') </code></pre> <p>Cheers</p>
0
2016-06-24T06:40:03Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,088
<p>You should put all valid choices in a list, and perform a list membership check like this:</p> <pre><code>wanted = r"'ARR'" if wanted in [r"'ARR'", r"'ABC'", r"'SAC'"]: print("Given value was a member of the list.") </code></pre> <p>The <code>r</code> in front of the strings is to denote them as <code>raw</co...
0
2016-06-24T06:41:16Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,130
<pre><code>MM=['ARR', 'ABC','SAC','WWW','ZZZ'] if MM[0] in ('ARR', 'ABC', 'SAC'): pass else: print('wrong') </code></pre> <p>Works just fine. You're overthinking it. You don't have to specify MM is an array, as python can figure that out. You don't have to escape the single quotes either. You aren't trying t...
0
2016-06-24T06:43:33Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,276
<p><strong>\'</strong> will make <strong>'</strong> to be a part of a string. ex:</p> <pre><code>&gt;&gt;&gt; str1 = '\'demo_string\'' &gt;&gt;&gt; str1 "'demo_string'" </code></pre> <p>The whole <code>str1</code> is <strong><code>'demo_string'</code></strong>.</p> <p>If you want to match <strong><code>ARR</code></s...
0
2016-06-24T06:52:25Z
[ "python", "python-2.7", "python-3.x" ]
String extraction with single quote
38,007,009
<p>I wish to detect a string with the below if statement, but it gives me the wrong output. I could not detect <code>ARR</code>. When I use below if statement, the output will be "wrong". It should go to pass when my input is <code>ARR</code>.</p> <p>My data is in this way, I wish to edit my if-statement instead of ed...
1
2016-06-24T06:35:42Z
38,007,303
<p>I think it not the single quote make the output of your code unexpected, it's because you use a wrong if statement.</p> <p>If you want to check <code>MM[0]</code> is either 'ARR' or 'ABC' or 'SAC', you need to use</p> <pre><code>MM[0] == 'ARR' or MM[0] == 'ABC' or MM[0] == 'SAC' </code></pre> <p>or</p> <pre><cod...
1
2016-06-24T06:53:39Z
[ "python", "python-2.7", "python-3.x" ]
python timer in minutes
38,007,046
<p>I am trying to run the below code. It fails to run for 5 minutes, can you please let me know what the issue is here. I am trying to run this in background by saving as <code>.pyw</code> and alert me after finishing 1 hours, as per what is passed in timer arguments.</p> <pre><code>import time import ctypes def timer...
-1
2016-06-24T06:38:06Z
38,007,148
<p>Your <code>timer()</code> function is infinitely looping.</p> <p>After your <code>while elapsed &lt; seconds:</code> loop, two lines down, you've put <code>timer(5)</code>. So that just calls itself again, and again, again...</p> <p>Once you remove this line, it will work as expected:</p> <pre><code>timer(5) #wou...
0
2016-06-24T06:44:31Z
[ "python", "python-2.7" ]
How do I write sections of a file into separate lists in python 3.0?
38,007,131
<p>I have a text file like this:</p> <pre><code>line 1 line 2 . . END OF SECTION 1, BEGIN SECTION 2 line 100 line 101 . . END OF SECTION 2, BEGIN SECTION 3 line 999 line 1000 . . END OF SECTION 3, BEGIN SECTION 4 END OF SECTION 4, BEGIN SECTION 5 line 5000 line 5001 . . END OF SECTION 5 Q </code></pre> <p>So, this fi...
0
2016-06-24T06:43:44Z
38,008,821
<p>So you have your list right with this command:</p> <pre><code>myList = [] with open("test.txt", 'r') as fileopen: myList = [line.strip() for line in fileopen] print (myList) </code></pre> <p>Output:</p> <pre><code>['line 1', 'line 2', 'END OF SECTION 1, BEGIN SECTION 2', 'line 100', 'line 101', 'END OF SECTIO...
0
2016-06-24T08:25:17Z
[ "python", "excel" ]
How do I write sections of a file into separate lists in python 3.0?
38,007,131
<p>I have a text file like this:</p> <pre><code>line 1 line 2 . . END OF SECTION 1, BEGIN SECTION 2 line 100 line 101 . . END OF SECTION 2, BEGIN SECTION 3 line 999 line 1000 . . END OF SECTION 3, BEGIN SECTION 4 END OF SECTION 4, BEGIN SECTION 5 line 5000 line 5001 . . END OF SECTION 5 Q </code></pre> <p>So, this fi...
0
2016-06-24T06:43:44Z
38,011,098
<p>The reason your code isn't working is because <code>exit</code> doesn't do what you think it does, assuming you want it to break out of the for-loop, in which case you want the <code>break</code> statement. <code>exit</code> is a built-in constant, which when called - like so: <code>exit()</code> - raises <code>Syst...
0
2016-06-24T10:22:07Z
[ "python", "excel" ]
Create user on ejabbred when user sign up in django app
38,007,215
<p>I am using django with jsxc (<a href="https://jsxc.org" rel="nofollow">https://jsxc.org</a>) to make user chat. I want to add user to ejabbed when user sign up on django. Right now in demo i have to manually create user on ejabberd and hard code in jsxc code. I want to make a django site with one to one user chat.</...
0
2016-06-24T06:48:54Z
38,008,141
<p>You can use API to create user in ejabberd. The command name is "register": <a href="https://docs.ejabberd.im/admin/api/#register---register-a-user" rel="nofollow">https://docs.ejabberd.im/admin/api/#register---register-a-user</a></p>
0
2016-06-24T07:43:00Z
[ "python", "django", "xmpp", "ejabberd", "strophe" ]
little XPath for scrapy
38,007,349
<p>By Chrome I got the XPATH like</p> <pre><code>/html/body/div[2]/div[2]/section[2]/div/div[2]/div[2]/div[5]/div </code></pre> <p>Sector</p> <pre><code>body &gt; div.off-canvas-wrap &gt; div.inner-wrap.brand-padding &gt; section:nth-child(2) &gt; div &gt; div.row.article-view &gt; div.columns.small-12.medium-7 &gt;...
-2
2016-06-24T06:56:51Z
38,007,529
<p>Please try:</p> <pre><code>response.xpath('//div[@class="columns small-12"]').extract() </code></pre>
0
2016-06-24T07:07:03Z
[ "python", "scrapy" ]
Remove transparent pixels from an image numpy array
38,007,439
<p>I have an image's numpy array of shape (224,224,4). Each pixel has 4 dimension - r,g,b,alpha. I need to extract the (r,g,b) values for each pixel where it's alpha channel is 255.</p> <p>I thought to first delete all elements in the array where alpha value is &lt;255, and then extract only the first 3 values(r,g,b) ...
1
2016-06-24T07:01:52Z
38,007,546
<p>something like this?</p> <pre><code>import numpy as np x = np.random.random((255,255,4)) y = np.where(x[:,:,3] &gt;0.5) res = x[y][:,0:3] </code></pre> <p>where you have to fit <code>&gt; 0.5</code> to your needs (e.g. <code>==255</code>). The result will be a matrix with all pixels stacked vertically</p>
1
2016-06-24T07:08:21Z
[ "python", "opencv", "numpy" ]
Remove transparent pixels from an image numpy array
38,007,439
<p>I have an image's numpy array of shape (224,224,4). Each pixel has 4 dimension - r,g,b,alpha. I need to extract the (r,g,b) values for each pixel where it's alpha channel is 255.</p> <p>I thought to first delete all elements in the array where alpha value is &lt;255, and then extract only the first 3 values(r,g,b) ...
1
2016-06-24T07:01:52Z
38,007,564
<p>This should work: <code>arr[arr[:,:,3]==255][:,:,:3]</code></p>
2
2016-06-24T07:09:40Z
[ "python", "opencv", "numpy" ]
Django and missing libmemcached.so.10
38,007,505
<p>After a yum update on the server, a django webapp suddenly started to throw 500 internal server errors of each request. This was found in the log file. </p> <pre><code>Traceback (most recent call last): File "/usr/local/virtualenv-django19/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 123,...
1
2016-06-24T07:05:40Z
38,007,506
<p>Replace pylibmc with <a href="https://pypi.python.org/pypi/python-memcached" rel="nofollow">python-memcached</a>.</p> <p>Pylibmc is said to have better performance than python-memcached but the difference is slight. pylibmc 1.5.1 does not seem to be compatible with libmemcached 1.0.16. Making the change is quite ea...
0
2016-06-24T07:05:40Z
[ "python", "django", "memcached", "django-cache", "pylibmc" ]
Removing special characters from JSON
38,007,511
<p>I have a JSON File with 3 objects like this:</p> <p><code>[{"ID": "44585", "TITLE": "A day in *Australia*=/", "MailThread": [{"email": " Its a great day, isn't it."}, {"email": " Yes, indeed."}, {"email": " Great Day!!!"}], "SUMMARY": "", "NAME": "Mike's Journal", "PRIORITY": 3, "FLIGHTTICKETNO": 25565826...
-4
2016-06-24T07:05:52Z
38,007,918
<p>Only handle <strong>TITLE</strong>, if you want something else, please handle it youeself as follow:</p> <pre><code>$ python demo.py {'PRIORITY': 3, 'TITLE': 'A day in Australia', 'FLIGHTTICKETNO': 25565826, 'MailThread': [{'email': " Its a great day, isn't it."}, {'email': ' Yes, indeed.'}, {'email': ' Great Day!!...
0
2016-06-24T07:30:11Z
[ "python", "json", "pandas" ]
How to make a socket server that only accepts one connection?
38,007,785
<p>I write a TCP server using Python. I want the server only accept on client connection.</p> <p>I use the <a href="https://docs.python.org/3/library/socket.html#socket.socket.listen" rel="nofollow"><code>listen</code></a> function</p> <pre><code>listen(1) </code></pre> <p>but the server still can accepts more than...
0
2016-06-24T07:21:07Z
38,007,836
<p>From <a href="https://docs.python.org/3/library/socket.html#socket.socket.listen" rel="nofollow">the documentation</a>:</p> <blockquote> <p>If backlog is specified, it must be at least 0 (if it is lower, it is set to 0); it specifies the number of unaccepted connections that the system will allow before refusing ...
0
2016-06-24T07:24:33Z
[ "python", "sockets", "network-programming" ]
How to make a socket server that only accepts one connection?
38,007,785
<p>I write a TCP server using Python. I want the server only accept on client connection.</p> <p>I use the <a href="https://docs.python.org/3/library/socket.html#socket.socket.listen" rel="nofollow"><code>listen</code></a> function</p> <pre><code>listen(1) </code></pre> <p>but the server still can accepts more than...
0
2016-06-24T07:21:07Z
38,008,196
<p>If you want only one connection, pleae don't use loop for <code>socket.accept()</code> in- connections. </p> <h2>demo code:</h2> <pre><code>#!/usr/bin/python import time import socket server = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) server.setsockopt(socket.SOL_SOCKET, socket.SO_RE...
0
2016-06-24T07:45:44Z
[ "python", "sockets", "network-programming" ]
Adding column names while looping through files
38,007,791
<p>I am very new to Python so bear with me please. I have a folder with csv files where the first row is data I need to work with. So I need to give them column names so I can call them later. Each csv has the same number of columns. For my practice I'm using three columns.</p> <p>I understand how to add file names to...
1
2016-06-24T07:21:33Z
38,008,201
<p>IIUC you need <code>glob</code>:</p> <pre><code>#glob can use path with *.txt - see http://stackoverflow.com/a/3215392/2901002 import glob key_codes = [] for files in glob.glob('files/*.csv'): df = pd.read_csv(files, names = ['first','second','third']) key_codes.append(df.second.map(str) + df.third.map(str)...
0
2016-06-24T07:46:18Z
[ "python", "csv", "for-loop", "pandas" ]
Can compile function output be used to detect changes in the source code
38,007,884
<p>Python's builtin function <a href="https://docs.python.org/2/library/functions.html#compile" rel="nofollow">compile()</a></p> <pre><code>code = """def fact(x): if x &lt;= 1: return 1 print (1) return x*fact(x-1) fact(10)""" c = compile(code, "&lt;string&gt;", "exec") code = """def fact(y): ...
2
2016-06-24T07:27:54Z
38,051,409
<p>There are many ways to do this that are a lot simpler than what you are trying:</p> <ol> <li><p>Use <code>diff</code>, with the <code>-w</code> (ignore whitespace) flag. If there is a resulting difference, you will know it is highly likely that it is a code change.</p></li> <li><p>Use git or other source code repos...
2
2016-06-27T10:18:57Z
[ "python", "python-2.x" ]
Can compile function output be used to detect changes in the source code
38,007,884
<p>Python's builtin function <a href="https://docs.python.org/2/library/functions.html#compile" rel="nofollow">compile()</a></p> <pre><code>code = """def fact(x): if x &lt;= 1: return 1 print (1) return x*fact(x-1) fact(10)""" c = compile(code, "&lt;string&gt;", "exec") code = """def fact(y): ...
2
2016-06-24T07:27:54Z
38,051,970
<p>So many questions...</p> <blockquote> <p>Can compile object be used to detect changes in the Python source code?</p> </blockquote> <p>Yes, sort of. However, since code objects contain the names of their local variables, renaming <code>x</code> to <code>y</code> will make your comparison fail even though there's ...
1
2016-06-27T10:46:15Z
[ "python", "python-2.x" ]
Can compile function output be used to detect changes in the source code
38,007,884
<p>Python's builtin function <a href="https://docs.python.org/2/library/functions.html#compile" rel="nofollow">compile()</a></p> <pre><code>code = """def fact(x): if x &lt;= 1: return 1 print (1) return x*fact(x-1) fact(10)""" c = compile(code, "&lt;string&gt;", "exec") code = """def fact(y): ...
2
2016-06-24T07:27:54Z
38,057,336
<p><strong>Don't do this</strong>, <em>as an optimization it won't result in great speed ups</em>.</p> <p><code>compile</code> <strong>is a <a href="https://github.com/python/cpython/blob/master/Python/bltinmodule.c#L651" rel="nofollow">built-in function</a></strong>, it is implemented in <code>C</code>, it is fast an...
3
2016-06-27T15:03:24Z
[ "python", "python-2.x" ]
Dev and prod values in python
38,008,046
<p>what i need is following in some class , when i am running it on local host vs running it on production</p> <pre><code>if __debug__: return {'dbhost' : "localhost", 'dbuser' : "root", 'dbpass' : "", 'dbname' : "some_DB"} else: return {'dbhost' : "localhost", 'dbuser' : "appwork_ayurveda", 'dbpass' : "some_password"...
1
2016-06-24T07:37:44Z
38,008,173
<p>You should have a separate settings.py file for your development settings.</p> <p>Aside from that, none of your settings files should be storing the password in raw text, the most common approach is to have your settings files reference environment variables that contain the database authentication settings.</p> <...
1
2016-06-24T07:44:15Z
[ "python", "django" ]
django pytest - unable to create testdb
38,008,055
<p>I have trouble creating a test DB and gives error as there is no database found. Im really not sure what is wrong and why database is not creating</p> <p>pytest.ini</p> <pre><code>[pytest] DJANGO_SETTINGS_MODULE=testing.test_settings addopts = --nomigrations --cov=. --cov-report=html </code></pre> <p>test_setting...
0
2016-06-24T07:38:03Z
38,009,878
<p>I'm not sure that pytest.ini will pass environment variable. Try running like this</p> <pre><code>DJANGO_SETTINGS_MODULE=testing.test_settings py.test --reuse-db </code></pre> <p>Also I hope you know that that the name of created db is generated like <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#st...
1
2016-06-24T09:23:00Z
[ "python", "django", "pytest-django" ]
OperationalError: (psycopg2.OperationalError) FATAL: password authentication failed for user
38,008,154
<p>I'm relatively new to python and postgresql. I have inherited some code (python) that built a postgresql database using psycopg2 and sqlalchemy. </p> <p>The database is named <code>'tetradev'</code> with user <code>'tetra'</code></p> <p>On top of this is a browser based application running via flask that queries t...
0
2016-06-24T07:43:31Z
38,086,227
<p>Finally figured this one out. I did end up updating the config file to the proper password but it still did not work. </p> <p>I later learned that environmental variables were set that over-rode the config file (this is all being hosted through a cloud service). I updated the password there and the URL now works. <...
0
2016-06-28T21:02:12Z
[ "python", "postgresql", "flask" ]
how can i turn "11 12 13 14" to "12 13 14 15" by using re.sub in python
38,008,218
<p>It is easy to convert <code>11 12 13 14</code> to <code>11a 12a 13a 14a</code>, using:</p> <pre><code>myStr = "11 12 13 14" myStr = re.sub(r'(\d*)', r'\1a', myStr) print myStr # 11a 12a 13a 14a </code></pre> <p>but how can I turn <code>11 12 13 14</code> to <code>12 13 14 15</code> by using <code>re.sub</code>?</...
1
2016-06-24T07:47:24Z
38,008,381
<p>A regex solution with <code>re.sub()</code>:</p> <pre><code>import re string = "11 12 13 14" def repl(m): number = int(m.group(1)) + 1 return str(number) print re.sub(r'\b(\d+)\b', repl, string) # 12 13 14 15 </code></pre> <p>See <a href="http://ideone.com/U0NPsV" rel="nofollow"><strong>a demo on ideone....
4
2016-06-24T07:55:14Z
[ "python", "regex", "python-2.7" ]
how can i turn "11 12 13 14" to "12 13 14 15" by using re.sub in python
38,008,218
<p>It is easy to convert <code>11 12 13 14</code> to <code>11a 12a 13a 14a</code>, using:</p> <pre><code>myStr = "11 12 13 14" myStr = re.sub(r'(\d*)', r'\1a', myStr) print myStr # 11a 12a 13a 14a </code></pre> <p>but how can I turn <code>11 12 13 14</code> to <code>12 13 14 15</code> by using <code>re.sub</code>?</...
1
2016-06-24T07:47:24Z
38,009,073
<p>The simplest approach for a string that only contains integer numbers separated with space is</p> <pre><code>s = "11 12 13 14" print(" ".join([str(int(x)+1) for x in s.split()])) # =&gt; 12 13 14 15 </code></pre> <p>See the <a href="https://ideone.com/jcFGQx" rel="nofollow">IDEONE demo</a></p> <p>An alternative w...
1
2016-06-24T08:40:50Z
[ "python", "regex", "python-2.7" ]
different type of obj for response_add() and response_delete()
38,008,379
<p>I modified my response_add and response_delete action in my admin app.</p> <p>My codes is in below.</p> <pre><code>def response_add(self, request, obj, post_url_continue=None): print(obj, type(obj)) return super().response_add(request, obj, post_url_continue) def response_delete(self, request, obj): ...
0
2016-06-24T07:55:11Z
38,008,926
<p>The only thing I've found so far that calls <code>response_delete</code> is the <a href="https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1720" rel="nofollow"><code>DeleteView</code></a></p> <p>Which has a comment a few lines above it stating that the object has been deleted.</p> <pre>...
0
2016-06-24T08:31:38Z
[ "python", "django", "django-models", "django-admin" ]
How can I asyncio schedule a filesystem stat operation?
38,008,388
<p>Converting some code to using <a href="https://docs.python.org/3/library/asyncio.html" rel="nofollow">asyncio</a>, I'd like to give back control to the <a href="https://docs.python.org/3/library/asyncio-eventloop.html" rel="nofollow"><code>asyncio.BaseEventLoop</code></a> as quickly as possible. This means to avoid ...
2
2016-06-24T07:55:44Z
38,022,029
<p><code>os.stat()</code> translates to a <code>stat</code> syscall:</p> <pre><code>$ strace python3 -c 'import os; os.stat("/")' [...] stat("/", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 [...] </code></pre> <p>which is blocking, and there's no way to get a non-blocking <code>stat</code> syscall.</p> <p><code>a...
2
2016-06-24T20:58:07Z
[ "python", "python-3.x", "python-asyncio", "stat" ]
Is it possible to have a vertical-oriented button in tkinter?
38,008,389
<p>Is it possible to orient a <code>tk.Button</code> or <code>ttk.Button</code> vertically? Smething like orienting a <code>tk.Scrollbar</code> in a way <code>self.scrlbr = tk.Scrollbar(master, orient = vertical)</code>?</p> <p>Have tried <code>tk.Button(*args).pack(fill = tk.Y)</code>, but it does not provide desired...
4
2016-06-24T07:55:47Z
38,014,382
<p>The button widget does not provide this option but you can emulate the button widget to get the effect if required. One way, as mentioned is to use an image containing the rotated text. Depending on your theme you may also create a button using a <code>canvas</code> which allows you to rotate text drawn on itself us...
3
2016-06-24T13:15:33Z
[ "python", "button", "tkinter" ]
How to constuct a column of data frame recursively with pandas-python?
38,008,390
<p>Give such a data frame <code>df</code>:</p> <pre><code>id_ val 11111 12 12003 22 88763 19 43721 77 ... </code></pre> <p>I wish to add a column <code>diff</code> to <code>df</code>, and each row of it equals to, let's say, the <code>val</code> in that row minus the <code>diff</code> in the pre...
2
2016-06-24T07:55:52Z
38,008,937
<p>You can use:</p> <pre><code>df.ix[0, 'diff'] = df.ix[0, 'val'] * 0.4 for i in range(1, len(df)): df.ix[i, 'diff'] = (df.ix[i, 'val'] - df.ix[i-1, 'diff']) * 0.4 + df.ix[i-1, 'diff'] print (df) id_ val diff 0 11111 12 4.8000 1 12003 22 11.6800 2 88763 19 14.6080 3 43721 77 39.5648 <...
3
2016-06-24T08:32:07Z
[ "python", "pandas", "recursion", "dataframe", "multiple-columns" ]
How to constuct a column of data frame recursively with pandas-python?
38,008,390
<p>Give such a data frame <code>df</code>:</p> <pre><code>id_ val 11111 12 12003 22 88763 19 43721 77 ... </code></pre> <p>I wish to add a column <code>diff</code> to <code>df</code>, and each row of it equals to, let's say, the <code>val</code> in that row minus the <code>diff</code> in the pre...
2
2016-06-24T07:55:52Z
38,546,278
<p>if you are using apply in pandas, you should not be using the dataframe again within the lambda function.</p> <p>your object in all cases within the lambda function should be 'row'.</p>
0
2016-07-23T20:46:39Z
[ "python", "pandas", "recursion", "dataframe", "multiple-columns" ]
Flask not interacting with Ajax
38,008,453
<p>This script </p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { $('.send').live('click', 'button', function() { var user1 = $(this).val(); var user2=$(this).prev().val(); var text=$(this).prev().prev().val(); var my_data = { user1: user1, text:text, user2:user2, }; console.log(my_data) $.ajax({...
1
2016-06-24T07:59:15Z
38,034,078
<p>Solved The proper form was user1 = request.values.get("user1")</p> <p>source: <a href="http://stackoverflow.com/a/20341272">http://stackoverflow.com/a/20341272</a></p>
0
2016-06-26T00:11:10Z
[ "python", "ajax", "flask" ]
Is it possible to GROUP BY an aggregate query with django ORM?
38,008,466
<p>I'm trying to calculate the equivalent of <code>SELECT SUM(...) FROM ... GROUP BY ...</code>. Here's a simplified analogy:</p> <p>Let's say <code>Salesperson</code> objects sell stuff and get a commission on the margin they generate through each <code>Sale</code>:</p> <pre><code>sp = Salesperson.objects.get(pk=1) ...
3
2016-06-24T07:59:55Z
38,009,575
<p>The <code>Sum()</code> aggregate function is available in <code>django.db.models</code> and you can use related fields in an F expression.</p> <pre><code>from django.db.models import F, Sum Sales.objects.values('salesperson__id').annotate(commission=Sum( (F('selling_price') - F('cost_price')) * F('salesperson_...
2
2016-06-24T09:09:05Z
[ "python", "django", "django-orm" ]
Is there any type in python that I can't convert into a string?
38,008,576
<p>Just wondering if I can convert everything into a string in Python 3.5. </p> <p>For instance, will this ever throw an error?</p> <pre><code>def test(arg): try: arg=str(arg) except ValueError: </code></pre>
0
2016-06-24T08:07:45Z
38,008,775
<p>Every type in standard library can be converted to string in Python using str() function, but not every object in Python needs to be in standard library.</p> <p>Theoretically this will throw an error (as we override here default <code>__str__</code> method to something that does not return string):</p> <pre><code>...
3
2016-06-24T08:21:46Z
[ "python", "python-3.x" ]
How to find the spread for all the permutation/combination of the timeseries in a data-frame?
38,008,627
<p>I am new to python . Just created a data-frame of around 10 time series , I want to find the spread of all the permutation/combination of all the time series . For example : </p> <pre><code>Sn.No Series A Series B Series C 1 10 17 12 2 1...
1
2016-06-24T08:11:31Z
38,009,204
<p>is that what you want?</p> <pre><code>In [38]: from itertools import combinations In [40]: df Out[40]: Sn.No Series_A Series_B Series_C 0 1 10 17 12 1 2 11 13 15 2 3 13 15 13 In [41]: cols = df.filter(like='Series_').columns In [...
0
2016-06-24T08:48:42Z
[ "python", "pandas", "dataframe", "combinations", "permutation" ]
Can I bind read() function to type 'instance' in python?
38,008,664
<p>i'm learning BeautifulSoup and i encountered this </p> <pre><code>from bs4 import BeautifulSoup import urllib2 url = "https://en.wikipedia.org/wiki/Katy_Perry" open_url = urllib2.urlopen(url) read = open_url.read() print(read) </code></pre> <p>This prints the html code of the page. But how can we use read() here ...
0
2016-06-24T08:14:43Z
38,011,757
<p>If you print both <code>open_url</code> you will see that <code>fp = socket._fileobject ..</code></p> <pre><code>&lt;addinfourl at 139707791457312 whose fp = &lt;socket._fileobject object at 0x7f104303bd50&gt;&gt; </code></pre> <p>So you see the file object is actually a <code>socket._fileobject</code> which you ...
0
2016-06-24T10:56:48Z
[ "python", "web-scraping", "beautifulsoup", "urllib2" ]
Python: implementing a step-by-step, modified Barabasi-Albert model for scale-free networks
38,008,748
<p>In Python, I need to create an Exponential Network, which is different from an Exponential Random Graph. </p> <p><a href="http://www.cc.ac.cn/05research_report/0508.pdf" rel="nofollow">Exponential Networks were introduced in 2005 by Liu &amp; Tang</a>, and originate from a <em>slight variation</em> of the Barabasi-...
1
2016-06-24T08:20:30Z
38,066,745
<p>I have implemented an <a href="https://github.com/Abdallah-Sobehy/barabasi_albert" rel="nofollow">animation for Barabasi-Albert graph growth</a> and I think the implementation is easily adjustable for the preferential attachment criteria and nodes positions.</p> <p><strong>Nodes Positions</strong></p> <blockquote>...
1
2016-06-28T03:50:13Z
[ "python", "algorithm", "networkx" ]
After conversion to float, matplotlib outputs cannot convert string to float
38,008,774
<p>I have a program that inputs 2 txt files. </p> <p><strong>deaths.txt</strong></p> <pre><code>29.0 122.0 453.0 </code></pre> <p><strong>years.txt</strong></p> <pre><code>1995 1996 1997 </code></pre> <p>I make lists from the data</p> <pre><code>deaths = open("deaths.txt").read().splitlines() years = open("years....
2
2016-06-24T08:21:46Z
38,010,534
<p>The following should get you going. Rather than using <code>readlines()</code> to read the whole file, a better approach would be to convert each row as it is read in.</p> <p>As your two data files have a different number of elements, the code makes use of <a href="https://docs.python.org/3/library/itertools.html?h...
1
2016-06-24T09:53:49Z
[ "python", "python-3.x", "matplotlib" ]
Python Regex match all occurrences of decimal pattern followed by another pattern
38,008,831
<p>I've done lots of searching, including <a href="http://stackoverflow.com/questions/17049622/regexp-last-occurence-of-pattern-that-occurs-before-another-pattern">this SO post</a>, which almost worked for me. </p> <p>I'm working with a <em>huge</em> string, trying to capture the groups of four digits that appear afte...
1
2016-06-24T08:26:13Z
38,009,241
<h1>SINGLE LINE STRING APPROACH:</h1> <p>Just match the float number <em>right before</em> the 4 standalone digits:</p> <pre><code>r'\d+\.\d+\s+(\d{4})\b' </code></pre> <p>See <a href="https://regex101.com/r/jS4bB7/3" rel="nofollow">this regex demo</a></p> <p><a href="https://ideone.com/xIEVYu" rel="nofollow">Pytho...
0
2016-06-24T08:50:49Z
[ "python", "regex" ]
Python Regex match all occurrences of decimal pattern followed by another pattern
38,008,831
<p>I've done lots of searching, including <a href="http://stackoverflow.com/questions/17049622/regexp-last-occurence-of-pattern-that-occurs-before-another-pattern">this SO post</a>, which almost worked for me. </p> <p>I'm working with a <em>huge</em> string, trying to capture the groups of four digits that appear afte...
1
2016-06-24T08:26:13Z
38,009,427
<p>This will help you:</p> <pre><code>"((\d+\.\d+)\s+)+(\d+)\s?(?=\w+)"gm </code></pre> <p>use group three means \3</p> <p><a href="https://regex101.com/r/hU4vO7/1" rel="nofollow">Demo And Explaination</a></p>
0
2016-06-24T09:01:44Z
[ "python", "regex" ]
Python Regex match all occurrences of decimal pattern followed by another pattern
38,008,831
<p>I've done lots of searching, including <a href="http://stackoverflow.com/questions/17049622/regexp-last-occurence-of-pattern-that-occurs-before-another-pattern">this SO post</a>, which almost worked for me. </p> <p>I'm working with a <em>huge</em> string, trying to capture the groups of four digits that appear afte...
1
2016-06-24T08:26:13Z
38,015,921
<p>Try this patter:</p> <pre><code>re.compile(r'(\d+[.]\d+)+\s+(?P&lt;cap&gt;\d{4})\s+\w+') </code></pre> <p>I wrote a little code and checked against it and it works.</p> <pre><code>import re p=re.compile(r'(\d+[.]\d+)+\s+(?P&lt;cap&gt;\d{4})\s+\w+') my_string = """BEAVER COUNTY 001 0000 1010 BEAVER 2010 BEAVER...
0
2016-06-24T14:33:44Z
[ "python", "regex" ]
linux cron job to create file using python
38,008,999
<p>bash script,</p> <pre><code>#! /bin/bash echo 'hi bash' aa python ~/fledgling/cron/test.py echo 'after python script' </code></pre> <p>here <code>aa</code> is alias, which activates virtualenv </p> <pre><code>alias aa='cd /home/fledgling/projects/myblog/base' </code></pre> <p>python script,</p> <pre><code>im...
0
2016-06-24T08:35:45Z
38,009,133
<p>The problem is that you can not use <code>~</code> in python, <a href="https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html" rel="nofollow">which will be expanded</a> in shell not python.</p> <p>Since mentioned by some answers, one thing to declared is</p> <blockquote> <p>A space after #! is o...
1
2016-06-24T08:44:09Z
[ "python", "linux", "bash", "cron", "crontab" ]
linux cron job to create file using python
38,008,999
<p>bash script,</p> <pre><code>#! /bin/bash echo 'hi bash' aa python ~/fledgling/cron/test.py echo 'after python script' </code></pre> <p>here <code>aa</code> is alias, which activates virtualenv </p> <pre><code>alias aa='cd /home/fledgling/projects/myblog/base' </code></pre> <p>python script,</p> <pre><code>im...
0
2016-06-24T08:35:45Z
38,009,208
<ul> <li>No ~ in Python</li> <li>No space after ! in bash header</li> <li>Not sure bash launched by cron will guess your alias</li> <li>Not sure crontab accept ~</li> <li>Look at your log (/var/log/syslog maybe)</li> <li>Try redirect 2>/tmp/debug.log in crontab</li> <li>check if test.sh is executable</li> </ul>
0
2016-06-24T08:48:59Z
[ "python", "linux", "bash", "cron", "crontab" ]
linux cron job to create file using python
38,008,999
<p>bash script,</p> <pre><code>#! /bin/bash echo 'hi bash' aa python ~/fledgling/cron/test.py echo 'after python script' </code></pre> <p>here <code>aa</code> is alias, which activates virtualenv </p> <pre><code>alias aa='cd /home/fledgling/projects/myblog/base' </code></pre> <p>python script,</p> <pre><code>im...
0
2016-06-24T08:35:45Z
38,009,354
<p>If You are running that script on server then You may not be using:</p> <pre><code>os.path.expanduser('~') </code></pre>
0
2016-06-24T08:56:50Z
[ "python", "linux", "bash", "cron", "crontab" ]
linux cron job to create file using python
38,008,999
<p>bash script,</p> <pre><code>#! /bin/bash echo 'hi bash' aa python ~/fledgling/cron/test.py echo 'after python script' </code></pre> <p>here <code>aa</code> is alias, which activates virtualenv </p> <pre><code>alias aa='cd /home/fledgling/projects/myblog/base' </code></pre> <p>python script,</p> <pre><code>im...
0
2016-06-24T08:35:45Z
38,013,437
<p>In your shell script use the full path rather then an alias.</p> <p>aa=/home/fledgling/projects/myblog/base</p> <p>cd $aa </p>
0
2016-06-24T12:26:39Z
[ "python", "linux", "bash", "cron", "crontab" ]
How to dynamically allocate memory in Python
38,009,008
<p>Is there any method in python, that I can use to get a block of memory from the heap ,and use a variable to reference it. Just like the keyword "new" , or the function <code>malloc()</code> in other languages:</p> <pre><code>Object *obj = (Object *) malloc(sizeof(Object)); Object *obj = new Object(); </code></pre>...
0
2016-06-24T08:36:14Z
38,009,068
<p>You should read the <a href="https://docs.python.org/3/tutorial/index.html" rel="nofollow">Python tutorial</a>.</p> <p>You can create lists, dictionaries, objects and closures in Python. All these live in the (Python) <a href="https://en.wikipedia.org/wiki/Memory_management#HEAP" rel="nofollow">heap</a>, and Python...
1
2016-06-24T08:40:39Z
[ "python", "memory", "heap" ]
How to dynamically allocate memory in Python
38,009,008
<p>Is there any method in python, that I can use to get a block of memory from the heap ,and use a variable to reference it. Just like the keyword "new" , or the function <code>malloc()</code> in other languages:</p> <pre><code>Object *obj = (Object *) malloc(sizeof(Object)); Object *obj = new Object(); </code></pre>...
0
2016-06-24T08:36:14Z
38,069,710
<p>The equivalent of "new" in python is to just use a constructor eg:</p> <pre><code>new_list = list() # or [] - expandable heterogeneous list new_dict = dict() # expandable hash table new_obj = CustomObject() # assuming CustomObject has been defined </code></pre> <p>Since you are porting from C, some things to note....
0
2016-06-28T07:27:18Z
[ "python", "memory", "heap" ]
How to dynamically allocate memory in Python
38,009,008
<p>Is there any method in python, that I can use to get a block of memory from the heap ,and use a variable to reference it. Just like the keyword "new" , or the function <code>malloc()</code> in other languages:</p> <pre><code>Object *obj = (Object *) malloc(sizeof(Object)); Object *obj = new Object(); </code></pre>...
0
2016-06-24T08:36:14Z
39,013,696
<p>Keep in mind that interpreted languages usually don't flatten the types as compiled languages do. The memory layout is (probably) completely different than in the raw data. Therefore, you cannot simply cast raw data to a class instance or vice versa. You have to read the raw data, interpret it and fill your objects ...
0
2016-08-18T08:47:25Z
[ "python", "memory", "heap" ]
scrapy random waits per spider
38,009,013
<p>I'd like to have scrapy use random waits between requests, and have that wait be set per scraper. </p> <p>Ideally I'd be able to set an average and stddev, something like injecting:</p> <pre><code>import time import numpy as np avg, stddev = 10, 5 time.sleep(np.random.normal(loc=avg, scale=stddev)) </code></pre>...
0
2016-06-24T08:36:29Z
38,027,149
<p>you should use <a href="http://doc.scrapy.org/en/latest/topics/settings.html?highlight=delay#download-delay" rel="nofollow">DOWNLOAD_DELAY</a> AND <a href="http://doc.scrapy.org/en/latest/topics/settings.html?highlight=delay#randomize-download-delay" rel="nofollow">RANDOMIZE_DOWNLOAD_DELAY</a> </p> <p>You can set ...
2
2016-06-25T09:50:30Z
[ "python", "web-scraping", "scrapy", "scrapy-spider" ]
Tkinter: Merging 2 windows
38,009,037
<p>I've been playing around with my first Python Tkinter GUI. Below you van find te script I've made. Must be honest, I've looked around on the internet to find out how to do it.</p> <p>When I run my script now I get 2 seperate windows. One window, lets call this "window A", with my text and input boxes and one empty ...
0
2016-06-24T08:38:29Z
38,009,255
<p>The answer is easy: In the build_widgets method you are constructing a new Tk frame and tcl interpreter with</p> <pre><code> master = Tk() </code></pre> <p>You should never have two Tk() calls in your application. The solution is to delete this line and change every occurance of master to self. Self represe...
2
2016-06-24T08:51:39Z
[ "python", "tkinter" ]
Tkinter: Merging 2 windows
38,009,037
<p>I've been playing around with my first Python Tkinter GUI. Below you van find te script I've made. Must be honest, I've looked around on the internet to find out how to do it.</p> <p>When I run my script now I get 2 seperate windows. One window, lets call this "window A", with my text and input boxes and one empty ...
0
2016-06-24T08:38:29Z
38,009,774
<p>@Jannick, with your script I don't get the results in the GUI. With your script I get the results in CMD and the "Run" bottun gives an error</p> <p>With my code below I get the results in the GUI.</p> <pre><code>from Tkinter import * import sys sys.path.append("C:\Users\Magali\Desktop\Tennis\tennisMatchProbability...
0
2016-06-24T09:18:08Z
[ "python", "tkinter" ]
SQLAlchemy querying twice with a joined relationship
38,009,190
<p>Basically, I'm running into a problem where SQLAlchemy (version 1.0.13) ends up querying the table that is supposed to be loaded as a join, separately, whenever I try to access any attribute of the other table through the <code>myrelationship</code> relationship.</p> <p>The relationship is defined as follows:</p> ...
0
2016-06-24T08:47:50Z
38,010,753
<p>This was due to a commit in between fetching and reading the data that caused it to expire. Solved by using <code>expire_on_commit = False</code> for that session.</p>
0
2016-06-24T10:03:57Z
[ "python", "sqlalchemy" ]
how to make join after where condition with peewee
38,009,219
<p>Is that possible making join after where condition like that</p> <pre><code>query = (AppCompany .select(AppCompany,User) .join(User) .where(AppCompany.status_id==request.args.status_id) ) if request.args.industry: query = query.switch(AppCompany).join(AppCompanyToInd...
2
2016-06-24T08:49:59Z
38,009,385
<p>Provide a join condition</p> <pre><code>query = query.switch(AppCompany) .join(AppCompanyToIndustry) .where(AppCompanyID == AppCompanyToIndustryID) </code></pre> <p>Here you should replace <code>AppCompanyID</code> and <code>AppCompanyToIndustryID</code> with proper column</p>
2
2016-06-24T08:58:37Z
[ "python", "mysql", "join", "peewee" ]
sknn - input dimension mismatch on second fit
38,009,309
<p>I was attempting to create a neural network that utilizes reinforcement learning. I picked scikit-neuralnetwork as the library (because it's simple). It seems though, that fitting twice crashes Theano.</p> <p>Here's the simplest code that causes the crash (Note, it doesn't matter what layers there are, nor does the...
6
2016-06-24T08:54:39Z
38,621,430
<p>I don't use <code>sknn</code> very often however it's very similar to <code>sklearn</code> so I might be able to help!</p> <p>First of all when using the <code>fit</code> method you will reinitialise the weights, if you want to update the weights based on new data you should use the <code>partial_fit</code> method....
1
2016-07-27T19:17:59Z
[ "python", "scikit-learn", "reinforcement-learning" ]
OpenCV Python: Window Size and Mouse Events Coordinates
38,009,377
<p>I'm trying to use mouse events and store the coordinates over which the cursor browsed. The problem is that my images are very small, 96x96 pixels and OpenCV chooses a window size that has bigger width than my images. So my image only takes the left side of the window. But the coordinates that are recognized by Open...
0
2016-06-24T08:58:06Z
38,010,333
<p>I think it can be done by Scaling up your image size. Here is some python code.</p> <pre><code>scaleFactor = 10 rows, cols = img.shape[:2] img = cv2.resize(img, (scaleFactor*cols, scaleFactor*rows), interpolation=cv2.INTER_LINEAR) </code></pre> <p>Then get mouse position and scale down. ( pseudo code...)</p> <...
1
2016-06-24T09:43:51Z
[ "python", "opencv" ]
What might the variable createtot=None mean in this function?
38,009,388
<p>I am trying to understand the following code, I do understand in general what was done: we define a data frame we want to work with, but can not get what in particular <code>createtot=None</code> here means?</p> <pre><code>def returnmyframe(dataframe_in, filter, grouper_in, columns_in, indexnames, createtot=None, s...
0
2016-06-24T08:58:45Z
38,009,463
<p>I think it's short for 'create total': it's expected to be given as</p> <pre><code>{"totalsum": &lt;input column name&gt;, "name": &lt;result column name&gt;} </code></pre> <p>and will then add up (sum) all values in the input column and put that in a result column.</p>
0
2016-06-24T09:03:05Z
[ "python", "python-3.x" ]
python - does return on a threading.Thread class free all the memory?
38,009,480
<p>I have this class, which at some point will call on_close(), how do I make sure that my thread will be closed and all the memory used freed? Is putting a return in on_close() enough? Also, is it safe to run 500+ threads? Noob questions, I know.. But I'm trying to learn!</p> <pre><code>class MyClass(threading.Thread...
0
2016-06-24T09:04:00Z
38,010,275
<p>Using the <a href="https://docs.python.org/2/library/gc.html#module-gc" rel="nofollow">gc</a> module may help you in forcing the garbage collector to run.</p> <p>Regarding your second question, In modern PC you can run up to around 4000 threads, <strong>BUT</strong> Python's <a href="https://wiki.python.org/moin/Gl...
0
2016-06-24T09:41:18Z
[ "python", "memory-management", "python-multithreading" ]
Pygame loads glitched versions of the original images
38,009,561
<p>Hello Stacked Overflow Community!!</p> <p>I've been a long time browser of this community but a first time poster. I'm only posting because I'm desperate as well. When I import images in pygame, certain images get messed up beyond repair. I import images with the built-in pygame.image.load(filename) and the weird g...
0
2016-06-24T09:08:32Z
38,019,325
<p>I fixed this error by uninstalling python and pygame and reinstalling.</p>
0
2016-06-24T17:47:50Z
[ "python", "pygame" ]
How do I replace all zeroes in a python list with nothing?
38,009,574
<p>I need to replace the zeros in newsplitted with nothing. Basically, I need to remove them. How do I do this WITHOUT imports? Can Anyone help? </p> <pre><code>input_string = "01-result.xls,2-result.xls,03-result.xls,05-result.xls" # Must be turned into ['result1','result2', 'result3', 'result5'] splitted = input_s...
3
2016-06-24T09:09:04Z
38,009,752
<p>A one liner with a list comprehension</p> <pre><code>input_string = "01-result.xls,2-result.xls,03-result.xls,05-result.xls" result = [''.join(i.split('-')[::-1]).replace('.xls', '').replace('0', '') for i in input_string.split(',')] </code></pre> <p>result</p> <pre><code>['result1', 'result2', 'result3', 'resul...
2
2016-06-24T09:17:14Z
[ "python" ]
How do I replace all zeroes in a python list with nothing?
38,009,574
<p>I need to replace the zeros in newsplitted with nothing. Basically, I need to remove them. How do I do this WITHOUT imports? Can Anyone help? </p> <pre><code>input_string = "01-result.xls,2-result.xls,03-result.xls,05-result.xls" # Must be turned into ['result1','result2', 'result3', 'result5'] splitted = input_s...
3
2016-06-24T09:09:04Z
38,009,755
<p>Use the builtin <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow">map</a> method:</p> <pre><code>newsplitted = ['result01', 'result2', 'result03', 'result05'] result = map(lambda x: x.replace('0', ''), newsplitted) </code></pre> <p>Using <strong>map()</strong> is good practice when you...
1
2016-06-24T09:17:20Z
[ "python" ]
How do I replace all zeroes in a python list with nothing?
38,009,574
<p>I need to replace the zeros in newsplitted with nothing. Basically, I need to remove them. How do I do this WITHOUT imports? Can Anyone help? </p> <pre><code>input_string = "01-result.xls,2-result.xls,03-result.xls,05-result.xls" # Must be turned into ['result1','result2', 'result3', 'result5'] splitted = input_s...
3
2016-06-24T09:09:04Z
38,009,918
<pre><code>input_string = "01-result.xls,2-result.xls,03-result.xls,05-result.xls" result = [el[el.index('-')+1:]+el[el.index('-')-1] for el in input_string.replace(".xls","").split(',')] </code></pre> <p>And the result is :</p> <pre><code>['result1', 'result2', 'result3', 'result5'] </code></pre>
1
2016-06-24T09:24:12Z
[ "python" ]
How to sendKeys() using/from a python dictionary
38,009,614
<p>Something like;</p> <p><code>element(by.model('formData.name')).sendKeys('David Cameron');</code></p> <p>I am trying to find a way to test my admin side when a user signs up. Somewhere I'll have to use <code>expect</code> (to check whether entry was submitted to backend) but I want to use a python dictionary of ab...
1
2016-06-24T09:11:17Z
38,014,619
<p>Dump your Python dictionary into a JSON file via, for example, <a href="https://docs.python.org/2/library/json.html#json.dump" rel="nofollow"><code>json.dump()</code></a>, then you can import the JSON file and set the <code>browser.params</code> in <code>onPrepare()</code>:</p> <pre><code>onPrepare: function () { ...
1
2016-06-24T13:28:40Z
[ "javascript", "python", "angularjs", "protractor" ]
How to sendKeys() using/from a python dictionary
38,009,614
<p>Something like;</p> <p><code>element(by.model('formData.name')).sendKeys('David Cameron');</code></p> <p>I am trying to find a way to test my admin side when a user signs up. Somewhere I'll have to use <code>expect</code> (to check whether entry was submitted to backend) but I want to use a python dictionary of ab...
1
2016-06-24T09:11:17Z
38,026,608
<p>I figured it out by creating javaScript objects straight away in my testing *spec.js file e.g for 3 random people (objects);</p> <p>Inside my <strong>sell-spec.js</strong> file;</p> <pre><code>var random = function(){ return Math.floor((Math.random() * 3) + 1); } var users = []; var user1 = { name : "Jaco...
1
2016-06-25T08:38:58Z
[ "javascript", "python", "angularjs", "protractor" ]
How to find two random unconnected nodes in graph using python/igraph?
38,009,618
<p>Following my previous question on finding two unconnected nodes in graph and its accepted response (<a href="http://stackoverflow.com/questions/37183749/how-to-find-two-randoms-nodes-with-no-edges-between-them-in-graph">How to find two randoms nodes with no edges between them in graph?</a>). I want to do the same in...
0
2016-06-24T09:11:30Z
38,296,285
<p>How about this:</p> <pre><code>from random import randint def get_random_unconnected_node_pair(graph): n = graph.vcount() - 1 while True: u = random.randint(0, n) v = random.randint(0, n) if not graph.are_connected(u, v): return u, v </code></pre>
0
2016-07-10T20:41:24Z
[ "python", "igraph" ]
Select pytest tests dynamically at the beginning of test run
38,009,667
<p>I'm writing unit tests for my Python app with pytest. Most of my experience with unit test writing comes from Javacript frameworks such as Jasmine, where you can mark singly mark tests to run in next test round with word 'fit' or mark test to be excluded with word 'xit'. 'fit' is nice during development when I want ...
1
2016-06-24T09:13:41Z
38,020,555
<p>Pytest plugin <code>pytest_collection_modifyitems</code> seems what you need. (put the following code in your <code>conftest.py</code>)</p> <pre><code>def pytest_collection_modifyitems(session, config, items): """ called after collection has been performed, may filter or re-order the items in-place.""" ...
2
2016-06-24T19:12:00Z
[ "python", "unit-testing", "py.test" ]
How to tell if tensorflow is using gpu acceleration from inside python shell?
38,009,682
<p>I have installed tensorflow in my ubuntu 16.04 using the second answer <a href="https://devtalk.nvidia.com/default/topic/936429/-solved-tensorflow-with-gpu-in-anaconda-env-ubuntu-16-04-cuda-7-5-cudnn-/" rel="nofollow">here</a> with ubuntu's builtin apt cuda installation.</p> <p>Now my question is how can I test if ...
4
2016-06-24T09:14:23Z
38,019,608
<p>No, I don't think "open CUDA library" is enough to tell, because different nodes of the graph may be on different devices.</p> <p>To find out which device is used, you can enable log device placement like this:</p> <pre><code>sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) </code></pre>
7
2016-06-24T18:07:13Z
[ "python", "ubuntu", "tensorflow" ]
Alternative to python hash function for arbitrary objects
38,009,699
<p>In python2.7, I'm successfully using <code>hash()</code> to place objects into buckets stored persistently on disk. A mockup code looks like this:</p> <pre><code>class PersistentDict(object): def __setitem__(self, key, value): bucket_index = (hash(key)&amp;0xffffffff) % self.bucket_count self._store_to_bu...
0
2016-06-24T09:15:12Z
38,053,682
<p>I've had success using a combination of <code>hash</code> and <code>zlib.adler32</code>. The most straightforward implementation is this:</p> <pre><code>def hashkey(obj, salt=0): """ Create a key suitable for use in hashmaps :param obj: object for which to create a key :type: str, bytes, :py:class:`datetim...
0
2016-06-27T12:12:33Z
[ "python", "python-3.x", "python-2.x" ]
Python - text mining - TypeError: __hash__ method should return an integer
38,009,703
<p>I am working on a classification problem in python. Fact is, I'm not good yet in python. So I have the same problem since a long time now and I don't know how to fix it. I hope you could help me :)</p> <p>This is my code :</p> <pre><code>tableau = pandas.DataFrame({'Exigence':exigence,'Résumé':resume}) df2,...
1
2016-06-24T09:15:20Z
38,010,029
<p>You are passing an <strong>object</strong> as <code>doc_class</code>, check what <code>df2['Target']</code> returns, probably a pandas Series, convert it to a single string, and pass it then. </p>
0
2016-06-24T09:29:16Z
[ "python", "machine-learning", "text-mining" ]
How to extract meta description from urls using python?
38,009,787
<p>I want to extract the title and description from the following website:</p> <p>view-source:<a href="http://www.virginaustralia.com/au/en/bookings/flights/make-a-booking/" rel="nofollow">http://www.virginaustralia.com/au/en/bookings/flights/make-a-booking/</a></p> <p>with the following snippet of source code:</p> ...
2
2016-06-24T09:18:55Z
38,011,010
<p>Please check <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc" rel="nofollow">BeautifulSoup</a> as solution.</p> <p>For question above, you may use the following code to extract "description" info:</p> <pre><code>import requests from bs4 import BeautifulSoup url = 'http://www.virginaustralia.com/au/...
2
2016-06-24T10:17:36Z
[ "python", "url", "extract", "meta-tags", "goose" ]
How to extract meta description from urls using python?
38,009,787
<p>I want to extract the title and description from the following website:</p> <p>view-source:<a href="http://www.virginaustralia.com/au/en/bookings/flights/make-a-booking/" rel="nofollow">http://www.virginaustralia.com/au/en/bookings/flights/make-a-booking/</a></p> <p>with the following snippet of source code:</p> ...
2
2016-06-24T09:18:55Z
38,011,236
<p>do you know html xpath? use lxml lib with xpath to extract html element is one fast way.</p> <pre><code>import lxml doc = lxml.html.document_fromstring(html_content) title_element = doc.xpath("//title") website_title = title_element[0].text_content().strip() meta_description_element = doc.xpath("//meta[@property='...
0
2016-06-24T10:29:23Z
[ "python", "url", "extract", "meta-tags", "goose" ]
How Flask Sqlalchemy db.query session works?
38,009,939
<p>I use flask-sqlalchemy, define a model:</p> <pre><code>from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) db = SQLAlchemy(app) class User(db.Model): # define user model pass </code></pre> <p>When I use it as :</p> <pre><code>User.query.all() </code></pre> <p>how the s...
-2
2016-06-24T09:25:24Z
38,023,965
<p>When you <strong>query</strong> for object in flask sqlalchemy, you do not need to <strong>commit</strong>. If you are <strong>inserting</strong> or <strong>editing</strong> you do need to yes.</p> <p>Just some query:</p> <pre><code>&gt;&gt;&gt; User.query.limit(1).all() [&lt;User u'admin'&gt;] </code></pre> <p>I...
0
2016-06-25T00:56:16Z
[ "python", "flask", "flask-sqlalchemy" ]
Checking if two rectangles overlap
38,010,021
<p>I have a few tests, and have written the code to check to see if the code works. I have two issues.</p> <ol> <li>I am not sure why 2 of my tests for checking if a Point is "contained" within a rectangle fail?</li> <li>Secondly, I have written a few tests, and code for whether two rectangles touch (or collide). I ha...
1
2016-06-24T09:28:47Z
38,010,845
<h2>Wrong Inequalities</h2> <p>Why does your contain function use strict inequalities only for the outer point ? </p> <pre><code>self.corner.x &lt;= point.x &lt; outer_x </code></pre> <p>You should decide whether the definition of "contain" means strictly inside, or counting anything exactly on the edges as well. Ei...
0
2016-06-24T10:09:13Z
[ "python", "python-3.x" ]
List of Points taken from a moving Object
38,010,161
<p>I am having some trouble accessing a list of stored x,y coordinates from the center of a block that moves across the screen. I have been able to successfully get the x and y coordinate of the block for each frame but am having trouble storing this information and then being able to access the point at certain stages...
3
2016-06-24T09:35:00Z
38,011,071
<p>Post all the code from the updating loop to the printing loop without breaks, "as is", because it is hard to see the problem like this. But from what I see - you possibly have your list created, updated and printed inside the updating loop, like this:</p> <pre><code>while condition: MultPeople=[] Person=Pe...
2
2016-06-24T10:20:47Z
[ "python", "python-2.7", "class", "opencv", "append" ]
Requests POST encoding with python
38,010,226
<p>I'm posting this character "ç" that is usually sent through a form, to a website I don't control. I'm having trouble with the encoding of the data. Trying to send data without encoding it to utf-8 produces this error (correction: this error was for another special character, mistake!):</p> <pre><code>File "D:\Pyth...
1
2016-06-24T09:38:57Z
38,038,955
<p>The simplest answer to this question was that i was opening the datafile without specifying the encoding. Had i added the <code>encoding="utf-8"</code> to the open function, and encoded the request as utf-8 this would have been solved rather quickly.</p>
1
2016-06-26T13:29:31Z
[ "python", "encoding", "utf-8", "python-requests" ]
BeautifulSoup4 showing me error when installing in PyCharm. Any viable alternatives?
38,010,306
<p>I'm trying to create a Spider by watching thenewboston tutorials, but when I try to install BeautifulSoup4 I get the following error:</p> <p><img src="http://i.stack.imgur.com/qsZJw.png" alt="This is the error its showing"></p>
0
2016-06-24T09:42:43Z
38,010,416
<p>You 've installed <code>BeautifulSoup3</code> which is not compatible with Python 3. </p> <p>Use the following command to install <code>BeautifulSoup4</code></p> <pre><code>pip install beautifulsoup4 </code></pre>
0
2016-06-24T09:47:56Z
[ "python", "web-crawler", "pycharm" ]
Share python objects between two (or more) .py files
38,010,391
<p>I'd like to be able to run a python file (<code>file1</code>) that simply loads several large files into memory as python objects, then, with a different python file (<code>file2</code>), access those same objects without having to reload the files into memory a second time. <em>The motivation is that I want to be a...
-2
2016-06-24T09:47:06Z
38,010,456
<p>Objects do not belong to a specific file. The class they belong to or the function that generates them may have been out of a module that "physically" resides in a different file, but this doesn't matter. As long as you are in a single python interpreter session objects will not need to be copied.</p> <p>There is o...
2
2016-06-24T09:50:13Z
[ "python", "memory", "memory-management" ]
django: How DetailView work for two model or how class-based-views work for two model?
38,010,597
<p>I planing to write a blog with Django.In my blog page,I want to show Blog and Comment,I tried to use DetailView</p> <pre><code>class BlogDetailView(DetailView): template_name = 'inventory/item_detail.html' model = Blogitem def get_context_data(self, **kwargs): context = super(BlogDetailView, s...
1
2016-06-24T09:56:36Z
38,012,302
<p>You have to specify your <code>model</code> in Detail View. and add comments_list in <code>get_context_data</code></p> <pre><code>class BlogDetailView(DetailView): model = Blogitem template_name = 'inventory/item_detail.html' slug_field = 'pk' def get_context_data(self, **kwargs): context =...
1
2016-06-24T11:26:28Z
[ "python", "django" ]
Remove/Exclude Non-Breaking Space from Scrapy result
38,010,601
<p>I am currently trying to scrape a website for article prices but I have run into a problem (after having somehow solved the problem that the prices were dynamically generated, which was a huge pain). </p> <p>I am able to receive the prices and the article names without a problem, but every second result for 'price'...
1
2016-06-24T09:56:45Z
38,010,708
<p><code>\xa0</code> is a non-breaking space in Latin1. Replace it like this:</p> <pre><code>string = string.replace(u'\xa0', u' ') </code></pre> <p><em>Update:</em></p> <p>You can apply the code as following:</p> <pre><code>for post in response.xpath('//body'): item = myItem() item['article_name'] = post.x...
2
2016-06-24T10:01:37Z
[ "python", "scrapy" ]
Use date field from MongoDB list as DatetimeIndex in Pandas DataFrame
38,010,778
<p>I am reading in data from a MongoDB collection</p> <pre><code>mongo_url = 'mongodb://localhost:27017/db' client = pymongo.MongoClient(mongo_url) db = client.db collection = db.coll docs = list(collection.find({}, {"Date": 1, "Cost" : 1, "_id" : 0 }).sort("date", pymongo.ASCENDING)) </code></pre> <p>so I end up wit...
2
2016-06-24T10:05:24Z
38,011,023
<p>If need create <code>Datetimindex</code> in <code>DataFrame</code> constructor:</p> <pre><code>docs = [{u'Date': u'2008-01-01', u'Cost': 8557.0},{u'Date': u'2008-01-02', u'Cost': 62307.0}] idx = pd.DatetimeIndex([x['Date'] for x in docs], freq='D') print (idx) DatetimeIndex(['2008-01-01', '2008-01-02'], dtype='da...
2
2016-06-24T10:18:11Z
[ "python", "mongodb", "numpy", "pandas", "dataframe" ]
python tkinter toplevel transparent
38,010,991
<p>i know that there is alot of these questions around, some thats said to work, and some thats said that dont work, however most of them are more than 2 years old, so i thought that something might have change that makes mine not work, what i want to do is simply make a tkinter window transparent, using python 3.4,</p...
0
2016-06-24T10:16:28Z
38,018,946
<p>Oh, lookslike the problem is with Linux, ive copied the propgram to windows 7 and now it works, thanks for the help, so for anyone else who might find this usefull:</p> <p>using:</p> <pre><code>from tkinter import * import time root = Tk() root.geometry('600x300') root.wm_attributes('-alpha',0.3) l = Label(root,bg...
0
2016-06-24T17:21:44Z
[ "python", "tkinter", "python-3.4", "transparent" ]
Use excel row with specific value openpyxl
38,011,107
<p>I'm trying to find a row in an excel sheet that has a certain value and then work with the cells in that row.</p> <p>So for example, I want to find the row that has a value of "Yes" in column A. I've tried to do this with the following code (hoping it would print the number of the row with "Yes" in it), but nothing...
1
2016-06-24T10:22:30Z
38,011,450
<p>The following works on my machine, no matter if "Yes" is after row 5 or not.</p> <pre><code>strValue="Yes" for row in range(ws.max_row): for column in "A": cell_name = "{}{}".format(column, row+1) value= str(ws[cell_name].value) if value==strValue: rownum = row p...
0
2016-06-24T10:40:25Z
[ "python", "openpyxl" ]
Use excel row with specific value openpyxl
38,011,107
<p>I'm trying to find a row in an excel sheet that has a certain value and then work with the cells in that row.</p> <p>So for example, I want to find the row that has a value of "Yes" in column A. I've tried to do this with the following code (hoping it would print the number of the row with "Yes" in it), but nothing...
1
2016-06-24T10:22:30Z
38,012,970
<p>If you are only looking for a single value this is best approach.</p> <pre><code>sentinel = u"Yes" for row in ws: for cell in row: if cell.value == sentinel: print(cell.row) # break </code></pre> <p>If you are likely to be looking for several values then creating a dictionary o...
0
2016-06-24T12:01:08Z
[ "python", "openpyxl" ]
pandas Python 3.5.1: incremental developement using the same dataset, changed a column name but on running script, old name remains in the dataframe
38,011,187
<p>I am parsing a Tsv (Tab separated value) file to create a pandas Dataframe using <code>pandas.read_csv()</code>. I am doing incremental changes to the Python script and executing the script each time to reflect the changes.</p> <p>For example, this is how I am parsing:</p> <pre><code>data_column_names = ['Query','...
0
2016-06-24T10:27:30Z
38,012,404
<p>Well I found the cause in the end. The TSV file, i.e. my data file has Header at row 0 and in the TSV file the Column names are given as 'Query' 'StartOffSet' 'EndOffset', so I have to go with those names only in my code. </p> <p>Changing the column names in the <code>usecols</code> parameter of <code>pandas.read_c...
0
2016-06-24T11:31:15Z
[ "python", "pandas", "dataframe" ]
Python indentation syntax error -- if/else tree
38,011,189
<p>I got an error in the printing program I wrote.</p> <pre><code>from variables import * li = [] for i in range(len(word)): if i in graph: for j in graph[i]: if j in graph[i]: li.append(len(graph[i][j]) else: # line 23 li.append(0) else: ...
-1
2016-06-24T10:27:31Z
38,011,207
<p>You are missing a paranthesis.</p> <pre><code>li.append(len(graph[i][j]) </code></pre> <p>should be</p> <pre><code>li.append(len(graph[i][j])) </code></pre>
2
2016-06-24T10:28:23Z
[ "python", "syntax" ]
Flask Google Maps API autocomplete Jquery not recognized
38,011,204
<p>I want to implement the simple autocomplete function from google, as simple as in their example: <a href="https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform" rel="nofollow">Google Autocomplete Example</a></p> <p>I created a random html page and tested the code with ...
1
2016-06-24T10:28:18Z
38,025,032
<p>You're not calling the <code>geolocate()</code> function in your html. I don't see how it will work on a single html page either.</p> <p>From the googles example, you need to add this:</p> <pre><code>&lt;div id="locationField"&gt; &lt;input id="autocomplete" placeholder="Enter your address" onFo...
0
2016-06-25T04:42:11Z
[ "jquery", "python", "python-2.7", "flask", "autocomplete" ]
merging data frames confusion
38,011,252
<p>I've got a bit confused with merging a couple of dataframes. The following dataframes are called (dayData and data):</p> <p>dayData:</p> <pre><code> id stock_name broad_sector currency 0 BBG.XLON.BTA.S BT GROUP PLC Communications GBp 1 BBG.XLON.VOD.S VODAFONE GROUP PLC C...
0
2016-06-24T10:30:32Z
38,011,536
<p>I think you can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.join.html" rel="nofollow"><code>join</code></a> <code>Serie</code> to <code>DataFrame</code>, but before set <code>Serie name</code> to <code>price</code> by <code>data.name = 'price'</code> :</p> <pre><code>print (dayDa...
0
2016-06-24T10:46:06Z
[ "python", "pandas" ]
Loop through a list for dataframe column plot in matplotlib
38,011,306
<p>I have been trying to loop through this list of 19000 tuple and have matplot lib to plot them according the key value of columns in data frame but I could not plot it out.</p> <pre><code>import os import pandas as pd os.chdir('/home/xyzcsv') %matplotlib inline from pylab import * with open('list_tuple.txt','rb') ...
0
2016-06-24T10:33:42Z
38,011,351
<p>Use subscripting to return the column by string name:</p> <pre><code>names = df[cola] names1 = df[colb] </code></pre> <p>by trying to access the cols as an attribute it fails as <code>cola</code> is not an attribute but if you pass the column names to subscript then it will return that column</p> <p>Also I strong...
0
2016-06-24T10:35:49Z
[ "python", "pandas", "matplotlib" ]
Radix sorting, "Queue" object not iterable
38,011,331
<p>I've come to an end with my assignment, I don't know where I go from where I am right now, the code is currently looking like this:</p> <pre><code>def radixsorting1(n,m): div=1 mod=10 bin_list=[] alist=[] r=[] s=[] for bins in range(0,10): bin_list.append(Queue()) for k in ra...
1
2016-06-24T10:34:51Z
38,011,779
<p>You need to add a bit more code to make it an iterable. <code>__iter__</code> should return an iterator. The iterator should have a <code>next</code> method.</p> <p>Take a look at this:</p> <p><a href="http://stackoverflow.com/questions/19151/how-to-make-class-iterable">How to make class iterable?</a></p> <p>So i...
1
2016-06-24T10:57:48Z
[ "python", "list", "python-3.x", "queue", "radix" ]