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
using newaxis in Python
39,157,426
<pre><code>A = np.array([[ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9], [10,11,12]]) B = A[:, np.newaxis] print(B) print(B.shape) </code></pre> <p>the output is</p> <pre><code>[[[ 1 2 3]] [[ 4 5 6]] [[ 7 8 9]] [[10 11 12]]] (4L, 1L, 3L) </code></pre> <p>I have two questions...
0
2016-08-26T02:22:59Z
39,157,603
<p>The "extra" bracket and the 1L are there for the same reason: your use of <code>np.newaxis</code> inserted a new dimension of extent 1 into the array shape—in other words, you transformed a two-dimensional 4x3 array into a three-dimensional 4x1x3 array. </p> <p>Each of the 4 "rows" of <code>B</code>contains a tw...
0
2016-08-26T02:49:24Z
[ "python", "arrays", "numpy", "matrix" ]
How to set empty value to DateField in django model?
39,157,455
<p>What am I doing wrong here? I need to set empty value to doing_field. </p> <pre><code>def delete_todo_today(request): if request.is_ajax() and request.POST and request.user.is_authenticated: thingtodo = ThingToDo.objects.filter(author = request.user, thing = request.POST.get('item')) thingtodo.d...
0
2016-08-26T02:27:36Z
39,157,721
<p>by default <code>models.DateField.empty_strings_allowed</code> is set to <code>False</code>, <a href="https://docs.djangoproject.com/en/1.10/_modules/django/db/models/fields/#DateField" rel="nofollow">https://docs.djangoproject.com/en/1.10/_modules/django/db/models/fields/#DateField</a></p> <p>try defining <code>Th...
0
2016-08-26T03:06:44Z
[ "python", "django" ]
How to set empty value to DateField in django model?
39,157,455
<p>What am I doing wrong here? I need to set empty value to doing_field. </p> <pre><code>def delete_todo_today(request): if request.is_ajax() and request.POST and request.user.is_authenticated: thingtodo = ThingToDo.objects.filter(author = request.user, thing = request.POST.get('item')) thingtodo.d...
0
2016-08-26T02:27:36Z
39,157,795
<p>You are using <code>.filter()</code> to get the objects for <code>thingtodo</code>. This will return a QuerySet or simply said a list of objects. You can not set an attribute on multiple objects directly. </p> <p>If you wat to retrieve one object only, use <code>get()</code> instead of <code>.filter()</code>. This ...
2
2016-08-26T03:17:40Z
[ "python", "django" ]
Simplest example for streaming audio with Alexa
39,157,599
<p>I'm trying to get the new streaming audio API going. Is the following response valid? I'm getting a "there was a problem with the skill" error when I test it on my device. </p> <p>Here is the code for my AWS-lambda function:</p> <pre><code>def lambda_handler(event, context): return { "response": { ...
7
2016-08-26T02:49:19Z
39,283,692
<p>The following code worked for me:</p> <pre><code>def lambda_handler(event, context): return { "response": { "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "REPLACE_ALL", "audioItem": { ...
7
2016-09-02T03:03:11Z
[ "python", "aws-lambda", "alexa-skills-kit" ]
Sorting based on max length and max sum
39,157,890
<p>Can you please help me figure this out</p> <pre><code>q = [[12, 13, 14], [8, 9, 10,11], [2, 3, 4], [5, 6, 7]] </code></pre> <p>suppose I've a list like q, How do I sort the based on </p> <ol> <li>Max length of sublists and </li> <li>Max sum of the sublists</li> </ol> <p>The output should be:</p> <pre><code>q =...
1
2016-08-26T03:31:21Z
39,157,907
<p>Supply your criteria in a lambda function for the <code>key</code>:</p> <pre><code>sorted(q, key=lambda sub: (len(sub), sum(sub)), reverse=True) &gt;&gt;&gt; [[8, 9, 10, 11], [12, 13, 14], [5, 6, 7], [2, 3, 4]] </code></pre> <p>The <code>lambda</code> function will take every sub-list <code>x</code> and sort it ba...
5
2016-08-26T03:34:27Z
[ "python", "list", "sorting" ]
Sorting based on max length and max sum
39,157,890
<p>Can you please help me figure this out</p> <pre><code>q = [[12, 13, 14], [8, 9, 10,11], [2, 3, 4], [5, 6, 7]] </code></pre> <p>suppose I've a list like q, How do I sort the based on </p> <ol> <li>Max length of sublists and </li> <li>Max sum of the sublists</li> </ol> <p>The output should be:</p> <pre><code>q =...
1
2016-08-26T03:31:21Z
39,157,940
<p>Try:</p> <pre><code>sorted(q, lambda a,b: len(b)-len(a) or sum(b)-sum(a)) </code></pre>
3
2016-08-26T03:39:50Z
[ "python", "list", "sorting" ]
Python retrieving value from URL
39,157,895
<p>I'm trying to write a python script that checks money.rediff.com for a particular stock price and prints it. I know that this can be done easily with their API, but I want to learn how urllib2 works, so I'm trying to do this the old fashioned way. But, I'm stuck on how to use the urllib. Many tutorials online asked ...
5
2016-08-26T03:32:27Z
39,157,965
<p>You can certainly do this with just <code>urllib2</code> and perhaps a regular expression, but I'd encourage you to use better tools, namely <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a> and <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow...
2
2016-08-26T03:43:28Z
[ "python", "html", "urllib2" ]
Python retrieving value from URL
39,157,895
<p>I'm trying to write a python script that checks money.rediff.com for a particular stock price and prints it. I know that this can be done easily with their API, but I want to learn how urllib2 works, so I'm trying to do this the old fashioned way. But, I'm stuck on how to use the urllib. Many tutorials online asked ...
5
2016-08-26T03:32:27Z
39,157,966
<p>BeautifulSoup is good for html parsing</p> <pre><code>from bs4 import BeautifulSoup ##Use your urllib code to get the source code of the page source = (Your get code here) soup = BeautifulSoup(source) ##This assumes the id 'ltpid' is the one you are looking for all the time span = soup.find('span', id="ltpid") flo...
1
2016-08-26T03:44:10Z
[ "python", "html", "urllib2" ]
Python retrieving value from URL
39,157,895
<p>I'm trying to write a python script that checks money.rediff.com for a particular stock price and prints it. I know that this can be done easily with their API, but I want to learn how urllib2 works, so I'm trying to do this the old fashioned way. But, I'm stuck on how to use the urllib. Many tutorials online asked ...
5
2016-08-26T03:32:27Z
39,196,267
<p>Use BeautifulSoup instead of regex to parse HTML. </p>
1
2016-08-28T22:11:27Z
[ "python", "html", "urllib2" ]
Install pyhdf error: hdf.h: No such file or directory
39,157,914
<p>I want to install <code>pyhdf</code> to read hdf4 files in python on ubuntu, and I downloaded from <a href="https://sourceforge.net/projects/pysclint/files/pyhdf/" rel="nofollow">https://sourceforge.net/projects/pysclint/files/pyhdf/</a>,<code>pyhdf-0.8.3.tar.gz</code>, but when I run <code>python setup.py install</...
0
2016-08-26T03:35:17Z
39,200,807
<p>Well finally I am answering my own question now...For people who want to install python-hdf4 on ubuntu.</p> <p>Firstly you need to install the hdf4 and then the python-hdf4.</p> <p>Hdf4 could be downloaded from <a href="https://www.hdfgroup.org/products/hdf4/" rel="nofollow">https://www.hdfgroup.org/products/hdf4/...
0
2016-08-29T07:34:38Z
[ "python", "pyhdf" ]
confused about random_state in decision tree of scikit learn
39,158,003
<p>Confused about <code>random_state</code> parameter, not sure why decision tree training needs some randomness. My thoughts, (1) is it related to random forest? (2) is it related to split training testing data set? If so, why not use training testing split method directly (<a href="http://scikit-learn.org/stable/modu...
1
2016-08-26T03:48:43Z
39,158,831
<p>This is explained in <a href="http://scikit-learn.org/stable/modules/tree.html#tree" rel="nofollow">the documentation</a></p> <blockquote> <p>The problem of learning an optimal decision tree is known to be NP-complete under several aspects of optimality and even for simple concepts. Consequently, practical decisi...
1
2016-08-26T05:26:06Z
[ "python", "python-2.7", "machine-learning", "scikit-learn", "decision-tree" ]
How to add corresponding elements of 2 multidimensional matrices in python?
39,158,062
<p>I have 2 multidimensional arrays , both of size 128X640X5. 5 is the number of channels for the matrices. I wish to add the respective channel values of both the matrices for every point in the matrices. For eg if we have A and B as 2 matrices, I wish to do an operation something like this: A(x,y,0)+B(x,y,0) =A(x,y,0...
0
2016-08-26T03:58:26Z
39,158,367
<p>In order to add each corresponding point of a <code>ndarray</code> in numpy you can use numpy's add function (<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.add.html" rel="nofollow">numpy.add</a>).</p> <p>It will add up each corresponding point of two ndarrays which have the <strong>same</strong...
0
2016-08-26T04:35:24Z
[ "python", "numpy", "image-processing" ]
Python eve - POST a list media files with curl command failed with 422 error
39,158,068
<p>I use python-eve to build my RESTful API, I set a endpoint 'risks' in settings.py, like so:</p> <pre><code>risks = { 'schema': { 'description': { 'type': 'string', 'required': True, }, 'pic': { 'type': 'list', 'schema': { 't...
0
2016-08-26T03:58:52Z
39,218,316
<p>When you access the <code>risks</code> endpoint you need to supply the right datatypes in order for the resource endpoint to work. It complains about the pic you send because that is still a string and not a list.</p> <p>You can make your life a bit easier by using <code>requests</code></p> <pre><code>import reque...
0
2016-08-30T03:25:13Z
[ "python", "list", "curl", "media", "eve" ]
Python eve - POST a list media files with curl command failed with 422 error
39,158,068
<p>I use python-eve to build my RESTful API, I set a endpoint 'risks' in settings.py, like so:</p> <pre><code>risks = { 'schema': { 'description': { 'type': 'string', 'required': True, }, 'pic': { 'type': 'list', 'schema': { 't...
0
2016-08-26T03:58:52Z
39,518,331
<blockquote> <p>@Mike Tung</p> <p>...</p> <p>You can make your life a bit easier by using requests</p> <p>...</p> </blockquote> <p><strong>How do you pass files to the requests <code>json</code> kwarg ? As file handles ? Or Strings ?</strong></p> <p>When I try this,</p> <pre><code>import requests ur...
0
2016-09-15T18:48:52Z
[ "python", "list", "curl", "media", "eve" ]
Select dropdown in AngularJS application from Python Selenium
39,158,148
<p>I wanted to test page in <code>Python</code> <code>Selenium</code>, which uses <code>AngularJS</code>. It contains a select option and I have tried a number of options to select it but it fails.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet...
0
2016-08-26T04:09:18Z
39,158,523
<p>Use the Select class from selenium.webdriver.support.ui. Pass the select webelement to the constructor. Use selectByVisibleText. Refer to the answer by @alecxe in the post - <a href="http://stackoverflow.com/questions/7867537/selenium-python-drop-down-menu-option-value">Selenium - Python - drop-down menu option valu...
0
2016-08-26T04:56:47Z
[ "python", "selenium", "protractor" ]
Select dropdown in AngularJS application from Python Selenium
39,158,148
<p>I wanted to test page in <code>Python</code> <code>Selenium</code>, which uses <code>AngularJS</code>. It contains a select option and I have tried a number of options to select it but it fails.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet...
0
2016-08-26T04:09:18Z
39,179,288
<p>If you have tried all the possible attempt but never got success, you should try using <code>execute_script()</code> as below :-</p> <pre><code>element = driver.find_element_by_id("xtzpp001") driver.execute_script("var select = arguments[0]; for(var i = 0; i &lt; select.options.length; i++){ if(select.options[i].t...
0
2016-08-27T08:54:58Z
[ "python", "selenium", "protractor" ]
Select dropdown in AngularJS application from Python Selenium
39,158,148
<p>I wanted to test page in <code>Python</code> <code>Selenium</code>, which uses <code>AngularJS</code>. It contains a select option and I have tried a number of options to select it but it fails.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet...
0
2016-08-26T04:09:18Z
39,193,018
<p>you can also use Actions to click the menu item, here is an example:</p> <pre><code>menu = driver.find_element_by_css_selector(".nav") hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1") ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform() </code></pre>
0
2016-08-28T15:46:49Z
[ "python", "selenium", "protractor" ]
GraphLab Create Launcher installation error
39,158,156
<p>Why problem creating the "gl-env" ? I have tried reinstalling it also... but nothing help me out. </p> <pre><code>CIO_TEST: &lt;not set&gt; CONDA_DEFAULT_ENV: &lt;not set&gt; CONDA_ENVS_PATH: &lt;not set&gt; PATH: C:\Users\Himanshu\Anaconda2\Library\bin;C:\Users\Himanshu\Anaconda2;C:\Users\Himanshu\Anaconda2\Script...
4
2016-08-26T04:10:58Z
39,297,359
<p>Having the same problem. Read elsewhere it is because the PATH variable is too long. I deleted everything possible from the PATH variable and that is not the solution.</p>
0
2016-09-02T16:52:21Z
[ "python", "windows", "git", "anaconda", "graphlab" ]
Exception: Acess Violation in client C#
39,158,157
<p>I am trying to learn C# through trials and errors. I have a server in Python, and the client in C#.</p> <p>The client is supposed to get data from the server, save it to disk ((which it doesn't)), then continue using that data to communicate until the user decides to exit it.</p> <p>Unfortunately, it has been rais...
-1
2016-08-26T04:11:21Z
39,158,696
<p>You might have a stream that remained open, which prevents a new one to be created. If the msgid is "ConOK" you are creating a new instance without closing it after the write operation is done.</p> <pre><code>if (msgid == "ConOK"){ string userid = rd.Substring(0, 16); Game.DisplayHelp(rd.Substring(16, (rd.L...
1
2016-08-26T05:12:12Z
[ "c#", "python", "networking", "visual-studio-2015" ]
Exception: Acess Violation in client C#
39,158,157
<p>I am trying to learn C# through trials and errors. I have a server in Python, and the client in C#.</p> <p>The client is supposed to get data from the server, save it to disk ((which it doesn't)), then continue using that data to communicate until the user decides to exit it.</p> <p>Unfortunately, it has been rais...
-1
2016-08-26T04:11:21Z
39,163,165
<p>At a first glance, you can have different class of bugs. Disregarding the logic flows and intended behaviour of the program, let's start with basic debugging.</p> <ul> <li><p>at this step, don't use threads and fibers, from Main just call Run</p></li> <li><p>there isn't strong input validation</p></li> <li><p>use ...
1
2016-08-26T09:37:52Z
[ "c#", "python", "networking", "visual-studio-2015" ]
Comparing Dates in SQLLite
39,158,180
<p>Hello Im currently doing a small project in python and sqllite and I have a csv that has been imported into a database with values under table name : Members.</p> <p>Each member has a "Date Joined" field in the format m/dd/yy. Some example formats are below:</p> <p><strong>I cant change the values in the csv becau...
2
2016-08-26T04:13:33Z
39,158,610
<p>You can try the following query:</p> <pre><code>SELECT * FROM yourTable WHERE CAST(SUBSTR(SUBSTR(join_date, INSTR(join_date, '/') + 1), INSTR(SUBSTR(join_date, INSTR(join_date, '/') + 1), '/') + 1) AS INTEGER) &lt;= 16 OR ( CAST(SUBSTR(SUBSTR(join_date, INSTR(join_date, '/') + 1), INSTR(SUBSTR(join_...
0
2016-08-26T05:04:56Z
[ "python", "sql", "database", "sqlite" ]
Python Multithreading basics confusion
39,158,275
<p>I have the below code:</p> <pre><code>import time from threading import Thread def fun1(): time.sleep(5) def fun2(): time.sleep(5) def fun3(): time.sleep(5) def fun4(): time.sleep(5) if __name__ == '__main__': t1 = Thread(target=fun1, args=()) t2 = Thread(target=fun2, args=()) t3 = Thread(target=fun3...
1
2016-08-26T04:24:58Z
39,158,320
<p>Blocking calls in Python (<code>sleep</code>, waiting on I/O or locks) release the GIL, allowing other threads to run while they are blocked, so all four threads can <code>sleep</code> in parallel, that's why you're seeing a five second delay. If you want to see the effects of GIL contention, have the thread functio...
3
2016-08-26T04:29:51Z
[ "python", "multithreading", "multiprocessing", "python-2.x", "gil" ]
Python Multithreading basics confusion
39,158,275
<p>I have the below code:</p> <pre><code>import time from threading import Thread def fun1(): time.sleep(5) def fun2(): time.sleep(5) def fun3(): time.sleep(5) def fun4(): time.sleep(5) if __name__ == '__main__': t1 = Thread(target=fun1, args=()) t2 = Thread(target=fun2, args=()) t3 = Thread(target=fun3...
1
2016-08-26T04:24:58Z
39,158,326
<p>Q1: Yes</p> <p>Q2: If the threads each did something that took 5 seconds of processing time, then you would expect the total time to be 20 seconds. But each thread is just sleeping for 5 seconds, so each thread releases the <code>GIL</code>, and thus allows other threads to run "in parallel" (only conceptually), as...
2
2016-08-26T04:31:12Z
[ "python", "multithreading", "multiprocessing", "python-2.x", "gil" ]
Python Multithreading basics confusion
39,158,275
<p>I have the below code:</p> <pre><code>import time from threading import Thread def fun1(): time.sleep(5) def fun2(): time.sleep(5) def fun3(): time.sleep(5) def fun4(): time.sleep(5) if __name__ == '__main__': t1 = Thread(target=fun1, args=()) t2 = Thread(target=fun2, args=()) t3 = Thread(target=fun3...
1
2016-08-26T04:24:58Z
39,158,496
<p>For multithreading environment in python. We have two very different kind of taks:</p> <ul> <li>CPU bound: like adding number, running for loop ... any activities that consume CPU. This kind of task hold GIL so it prevent other thread running.</li> <li>not CPU bound (may be waiting for IO activities from outside re...
1
2016-08-26T04:53:17Z
[ "python", "multithreading", "multiprocessing", "python-2.x", "gil" ]
Reshaping a numpy array (matrix) where elements appear in order
39,158,300
<p>I have a numpy array with the following shape:</p> <pre><code>shape -&gt; data 5x3 -&gt; [[ 12 10 33 9 88 41 13 39 27 1 4 7 65 78 13 ]] </code></pre> <p>I need the numpy array to look like this though:</p> <pre><code>shape -&gt; data 5x3 -&gt;...
0
2016-08-26T04:27:19Z
39,158,373
<p>It's a simple enough procedure. We just need to perform two phases, a reshape and a transpose:</p> <pre><code>Y = X.reshape(X.shape[::-1]).T </code></pre>
1
2016-08-26T04:36:18Z
[ "python", "arrays", "numpy" ]
Why does using .latest() on an empty Django queryset return...nothing?
39,158,325
<p>Here's some code that builds a queryset, and prints the output at each step (for debugging):</p> <pre><code>qs = self.get_queryset(True) print(qs) # [&lt;MyModel: obj_1&gt;, &lt;MyModel: obj_2&gt;, &lt;MyModel: obj_2&gt;, &lt;MyModel: obj_3&gt;] qs = qs.get_user(user) print(qs) # [] qs = qs.completed() print(qs...
0
2016-08-26T04:30:57Z
39,162,440
<p><a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#latest" rel="nofollow">From the documentation</a>:</p> <blockquote> <p>Like get(), earliest() and latest() raise DoesNotExist if there is no object with the given parameters.</p> </blockquote> <p><code>qs.latest('field')</code> should raise <c...
2
2016-08-26T09:03:48Z
[ "python", "django", "django-queryset" ]
How to convert the following Matlab loop into Python?
39,158,384
<p>I have been working on translating Matlab code into Python and came across a loop that I'm having some difficulty converting as I'm fairly new to both the languages.</p> <pre><code>if fdp &gt;=2 degreeTwoVector=[]; counter =1; for i = 1:numVariables for j = 1:numVariables degreeTwoVector(counter,:) = [i...
2
2016-08-26T04:37:43Z
39,158,704
<p>You are not too far off: You do not need a <code>break</code> statement, it is causing a precocious, well, break to the loop (at the first iteration). So here you go: </p> <pre><code>numVariables = np.shape(X)[0] # number of rows in X which is given if fdp &gt;= 2: degreeTwoVector = np.zeros((numVariables, 3))...
3
2016-08-26T05:13:06Z
[ "python", "matlab", "python-2.7" ]
How to create mask for outer pixels when using skimage.transform.rotate
39,158,420
<p>skimage rotate function create "outer" pixels, no matter how this pixels extrapolated (wrap, mirror, constant, etc) - they are fake, and can affect statistical analysis of image. How can I get mask of this pixels to ignore them in analysis? <a href="http://i.stack.imgur.com/xzg5n.png" rel="nofollow"><img src="http:/...
2
2016-08-26T04:43:39Z
39,160,945
<pre><code>mask_val = 2 rotated = skimage.transform.rotate(img, 15, resize=True, cval=mask_val, preserve_range=False) mask = rotated == mask_val </code></pre> <p>Idea: pick a value for the mask which doesn't appear in the image, then obtain mask by checking for equality with this va...
1
2016-08-26T07:41:18Z
[ "python", "skimage" ]
socket progamming : tcp_client "gai" error
39,158,573
<p>I'm setting up a simple client socket (my server socket works well). But I'm stuck by a lil bug. here's my code and here's the error. Cant find this errorr nowhere on the web.</p> <pre><code>from socket import * import sys host=socket.gethostname() #host=127.0.0.1 serverPort= 12345 clientSocket =socket(AF_INET,SOC...
0
2016-08-26T05:01:35Z
39,158,700
<p>Your code is incorrect here (did you post the real code you ran?):</p> <ol> <li>host cannot be empty</li> <li><code>connect</code> takes 1 argument and it's a tuple</li> <li>if you do <code>from socket import *</code>, you cannot do <code>socket.socket</code></li> </ol> <p>fixed:</p> <pre><code>import socket impo...
0
2016-08-26T05:12:51Z
[ "python", "serversocket", "tcpsocket" ]
Can you have multiple read/writes to SQLite database simultaneously?
39,158,621
<p>I am using Python with SQLite currently and wondering if it is safe to have multiple threads reading and writing to the database simultaneously. Does SQLite handle data coming in as a queue or have sort of mechanism that will stop the data from getting corrupt?</p>
1
2016-08-26T05:05:33Z
39,158,655
<p>SQLite has a number of robust locking mechanisms to ensure the data doesn't get corrupted, but the problem with that is if you have a number of threads reading and writing to it simultaneously you'll suffer pretty badly in terms of performance as they all trip over the others. It's not intended to be used this way, ...
1
2016-08-26T05:08:54Z
[ "python", "multithreading", "sqlite" ]
Can you have multiple read/writes to SQLite database simultaneously?
39,158,621
<p>I am using Python with SQLite currently and wondering if it is safe to have multiple threads reading and writing to the database simultaneously. Does SQLite handle data coming in as a queue or have sort of mechanism that will stop the data from getting corrupt?</p>
1
2016-08-26T05:05:33Z
39,163,285
<p>This is my issue too. SQLite using some kind of locking mechanism which prevent you doing concurrency operation on a DB. But here is a trick which i use when my db are small. You can select all your tables data into memory and operate on it and then update the original table.</p> <p>As i said this is just a trick a...
2
2016-08-26T09:43:14Z
[ "python", "multithreading", "sqlite" ]
I am simply trying to write a python script that will change the filename in a directory of files
39,158,636
<p>I am trying to create a script in python 2.7 that will rename all the files in a directory. Below is the code I have so far. The first function removes any numbers in the file name. The second function is supposed to rename the new file name. I get the following error when the second function runs:</p> <blockquote>...
4
2016-08-26T05:07:08Z
39,158,669
<p>instead of doing:</p> <pre><code>if file_name == filename: file_name = file_name + 1 </code></pre> <p>do something like this:</p> <pre><code>counter = 0 for file_name in file_container: if file_name == file_name: # this will always be True - so it's unnecessary file_name = "{0}_{1}".format(file_na...
4
2016-08-26T05:10:10Z
[ "python", "python-2.7", "loops", "increment" ]
Using HTML, CSS, JS with Python to make desktop application?
39,158,663
<p>I recently made a program. It's developed using Node.JS and Electron to make it a desktop application. Unfortunately, Electron is quite big in base file size and I'd like to reduce the file size. I've looked at my app files before adding electron and it's around 38mb. When adding electron it's roughly over 100mb mor...
-1
2016-08-26T05:09:29Z
39,163,137
<p>YES. You can use QT standard library but if you persist on writing UI yourself there is an HTMLpy Library which can find here <a href="http://amol-mandhane.github.io/htmlPy/" rel="nofollow">HTMLPY</a></p> <p>htmlPy is a wrapper around PySide's QtWebKit library. It helps with creating beautiful GUIs using HTML5, CSS...
1
2016-08-26T09:36:21Z
[ "javascript", "python", "html", "css" ]
How to select column and rows in pandas without column or row names?
39,158,699
<p>I have a pandas dataframe(df) like this</p> <pre><code> Close Close Close Close Close Date 2000-01-03 00:00:00 NaN NaN NaN NaN -0.033944 2000-01-04 00:00:00 NaN NaN NaN...
1
2016-08-26T05:12:49Z
39,158,738
<p>If you want the fifth column:</p> <pre><code>df.ix[:,4] </code></pre> <p>Stick the colon in there to take all the rows for that column.</p> <p>To exclude a fifth column you could try:</p> <pre><code>df.ix[:, (x for x in range(0, len(df.columns)) if x != 4)] </code></pre>
1
2016-08-26T05:16:56Z
[ "python", "pandas" ]
How to select column and rows in pandas without column or row names?
39,158,699
<p>I have a pandas dataframe(df) like this</p> <pre><code> Close Close Close Close Close Date 2000-01-03 00:00:00 NaN NaN NaN NaN -0.033944 2000-01-04 00:00:00 NaN NaN NaN...
1
2016-08-26T05:12:49Z
39,158,821
<p>To select filter column by index:</p> <pre><code>In [19]: df Out[19]: Date Close Close.1 Close.2 Close.3 Close.4 0 2000-01-0300:00:00 NaN NaN NaN NaN -0.033944 1 2000-01-0400:00:00 NaN NaN NaN NaN 0.035137 2 2000-01-0500:00:00 -0.033944 ...
1
2016-08-26T05:24:48Z
[ "python", "pandas" ]
How to select column and rows in pandas without column or row names?
39,158,699
<p>I have a pandas dataframe(df) like this</p> <pre><code> Close Close Close Close Close Date 2000-01-03 00:00:00 NaN NaN NaN NaN -0.033944 2000-01-04 00:00:00 NaN NaN NaN...
1
2016-08-26T05:12:49Z
39,160,661
<p>Use <code>iloc</code>. It is explicitly a position based indexer. <code>ix</code> can be both and will get confused if an index is integer based.</p> <pre><code>df.iloc[:, [4]] </code></pre> <p><a href="http://i.stack.imgur.com/dfnha.png" rel="nofollow"><img src="http://i.stack.imgur.com/dfnha.png" alt="enter im...
2
2016-08-26T07:26:05Z
[ "python", "pandas" ]
List conversion - inplace
39,158,754
<p>I am trying to convert ['1','2','3','4'] to [1,2,3,4] I want to make this conversion inplace. Is it possible to do it? If not, what is the optimal solution.</p>
3
2016-08-26T05:18:40Z
39,158,850
<p>This should be pretty much in-place?</p> <pre><code>In [31]: l = ['1','2','3','4'] In [32]: for i in range(len(l)): ....: l[i] = int(l[i]) ....: In [33]: l Out[33]: [1, 2, 3, 4] </code></pre> <p>Or, you could do it by using <code>enumerate</code> which takes an iterable (like a <code>list</code>) ...
0
2016-08-26T05:29:05Z
[ "python", "arrays", "list", "in-place" ]
List conversion - inplace
39,158,754
<p>I am trying to convert ['1','2','3','4'] to [1,2,3,4] I want to make this conversion inplace. Is it possible to do it? If not, what is the optimal solution.</p>
3
2016-08-26T05:18:40Z
39,158,927
<p>As long as the whole array fits in memory, you should just be able to step through it, replacing each item as you go:</p> <pre><code># bigarray is ['1','2','3','4',...]; # loop through bigarray using index i for i in range(len(bigarray)): # coerce bigarray[i] to int in place bigarray[i] = int(bigarray[i]) ...
0
2016-08-26T05:33:46Z
[ "python", "arrays", "list", "in-place" ]
List conversion - inplace
39,158,754
<p>I am trying to convert ['1','2','3','4'] to [1,2,3,4] I want to make this conversion inplace. Is it possible to do it? If not, what is the optimal solution.</p>
3
2016-08-26T05:18:40Z
39,159,317
<p>you can do it with list comprehension like this:</p> <pre><code>l = [int(item) for item in l] </code></pre>
1
2016-08-26T06:04:03Z
[ "python", "arrays", "list", "in-place" ]
List conversion - inplace
39,158,754
<p>I am trying to convert ['1','2','3','4'] to [1,2,3,4] I want to make this conversion inplace. Is it possible to do it? If not, what is the optimal solution.</p>
3
2016-08-26T05:18:40Z
39,161,253
<p>I think it is better to use <a href="https://docs.python.org/3/library/functions.html?highlight=map#map" rel="nofollow"><code>map</code></a> for this kind of tasks. Which creates iterator, what means it is more memory efficient.</p> <pre><code>l = list(map(int, l)) # here I convert it to list, but usually you would...
2
2016-08-26T07:59:19Z
[ "python", "arrays", "list", "in-place" ]
Python adaptfilt-echo canceller example with two .wav files
39,158,762
<p>this code isa modification from the example of adaptfilt2.0 echo canceller</p> <pre><code> u(n) -------&gt;-&gt;------+-----------&gt;-&gt;----------- | | +-----------------+ +------------------+ +-&gt;-| Adaptive filter | | John's ...
0
2016-08-26T05:19:27Z
39,158,878
<p>It looks like you have a "copy and paste" error. After reading <code>audio2.wav</code>, this line</p> <pre><code>v = np.float64(u) </code></pre> <p>should be </p> <pre><code>v = np.float64(v) </code></pre> <p>(Now that you see it is a trivial mistake, feel free to delete your question!)</p> <hr> <p>P.S. Using...
0
2016-08-26T05:30:45Z
[ "python", "numpy", "audio", "wave", "pyaudio" ]
Iterating through a list and using ltems of other lists
39,158,795
<pre><code>l = ['hello','hi'] a=[1,2,3,4] b=[4,5,6,7] for i in l: func(x=a[index],y=b[index]) </code></pre> <p>Now when I'm iterating through l , in the first iteration i want to use first a[0]and b[0] for a function and then use a[1] and b[1] for the same function</p> <p>And in the second iteration of l,i want to u...
1
2016-08-26T05:22:47Z
39,158,858
<pre><code>&gt;&gt;&gt; l = ['hello','hi'] &gt;&gt;&gt; a=[1,2,3,4] &gt;&gt;&gt; b=[4,5,6,7] &gt;&gt;&gt; for i, val in enumerate(l): ... print '---iteration', i ... print 'l:', val ... print 'a:', a[2*i], ', b:', b[2*i] ... print 'a:', a[2*i+1], ' b:', b[2*i+1] ... ---iteration 0 l: hello a: 1 , b: 4 a...
2
2016-08-26T05:29:53Z
[ "python", "python-2.7" ]
Iterating through a list and using ltems of other lists
39,158,795
<pre><code>l = ['hello','hi'] a=[1,2,3,4] b=[4,5,6,7] for i in l: func(x=a[index],y=b[index]) </code></pre> <p>Now when I'm iterating through l , in the first iteration i want to use first a[0]and b[0] for a function and then use a[1] and b[1] for the same function</p> <p>And in the second iteration of l,i want to u...
1
2016-08-26T05:22:47Z
39,177,025
<p>You can use the index method to find the index of the element of the list you are iterating through. Using that index you can find the element from the list you want to pass to the function.</p> <pre><code>l = ['hello','hi'] a=[1,2,3,4] b=[4,5,6,7] def demo(x, y): print x, y for i in l: print i idx = ...
0
2016-08-27T02:57:02Z
[ "python", "python-2.7" ]
Python Regex and group function
39,158,859
<p>Hi trying to separate each of the expressions from the colon. So want to obtain 'ss_vv', 'kk' and 'pp'. But the two print expressions below give me 'v' and 'k', so getting parts only of each string. Can anyone see what wrong here? </p> <pre><code>m0 = re.compile(r'([a-z]|_)+:([a-z]|_)+:([a-z]|_)+') m1 = m0...
0
2016-08-26T05:29:53Z
39,158,945
<pre><code>In [52]: m0 = re.compile(r'([a-z|_]+):([a-z|_]+):([a-z|_]+)') In [53]: m1 = m0.search('ss_vv:kk:pp') In [54]: print m1.group(1) ss_vv In [55]: print m1.group(2) kk In [56]: print m1.group(3) pp </code></pre> <p>What my regex does:</p> <pre><code>([a-z|_]+):([a-z|_]+):([a-z|_]+) </code></pre> <p><img s...
4
2016-08-26T05:35:41Z
[ "python", "regex" ]
Python Regex and group function
39,158,859
<p>Hi trying to separate each of the expressions from the colon. So want to obtain 'ss_vv', 'kk' and 'pp'. But the two print expressions below give me 'v' and 'k', so getting parts only of each string. Can anyone see what wrong here? </p> <pre><code>m0 = re.compile(r'([a-z]|_)+:([a-z]|_)+:([a-z]|_)+') m1 = m0...
0
2016-08-26T05:29:53Z
39,158,948
<p>No need to use regex for your case. You can just split on basis of ':' and get required output..</p> <pre><code>&gt;&gt;&gt; a = 'ss_vv:kk:pp' &gt;&gt;&gt; b_list = a.split(':') &gt;&gt;&gt; b_list ['ss_vv', 'kk', 'pp'] &gt;&gt;&gt; </code></pre>
1
2016-08-26T05:35:55Z
[ "python", "regex" ]
Python Regex and group function
39,158,859
<p>Hi trying to separate each of the expressions from the colon. So want to obtain 'ss_vv', 'kk' and 'pp'. But the two print expressions below give me 'v' and 'k', so getting parts only of each string. Can anyone see what wrong here? </p> <pre><code>m0 = re.compile(r'([a-z]|_)+:([a-z]|_)+:([a-z]|_)+') m1 = m0...
0
2016-08-26T05:29:53Z
39,159,009
<p>What are the other rules for the regular expression? based on your question, this regex would do:</p> <pre><code>m0 = re.compile(r'(.*):(.*):(.*)') m1 = m0.search('ss_vv:kk:pp') print m1.group(1) print m1.group(2) </code></pre> <p><strong>UPDATE:</strong> as mentioned by @Jan in the comments, for efficient and bet...
2
2016-08-26T05:40:57Z
[ "python", "regex" ]
Extract data from an HTML tag which has specific attributes
39,158,931
<pre><code>&lt;tr bgcolor="#FFFFFF"&gt; &lt;td class="tablecontent" scope="row" rowspan="1"&gt; &lt;a href="http://netprofile-us2/netprofile/npIndex.do?cpyKey=80823"&gt;ZURICH AMERICAN INSURANCE COMPANY&lt;/a&gt; &lt;/td&gt; &lt;td class="tablecontent" scope="row" rowspan="1"&gt; FARMERS GRO...
-1
2016-08-26T05:34:08Z
39,164,693
<p>You can use css selector <code>nth-of-type</code> to navigate through the <code>td</code>s</p> <p>Here's a sample"</p> <pre><code>soup = BeautifulSoup(html, 'html.parser') a = soup.select('td:nth-of-type(1) a')[0] href = a['href'] td = soup.select("td:nth-of-type(3)")[0] text = td.get_text(strip=True) </code></pre...
0
2016-08-26T10:58:06Z
[ "python", "python-2.7", "beautifulsoup" ]
Extract data from an HTML tag which has specific attributes
39,158,931
<pre><code>&lt;tr bgcolor="#FFFFFF"&gt; &lt;td class="tablecontent" scope="row" rowspan="1"&gt; &lt;a href="http://netprofile-us2/netprofile/npIndex.do?cpyKey=80823"&gt;ZURICH AMERICAN INSURANCE COMPANY&lt;/a&gt; &lt;/td&gt; &lt;td class="tablecontent" scope="row" rowspan="1"&gt; FARMERS GRO...
-1
2016-08-26T05:34:08Z
39,168,372
<p>You can find all <code>tr</code> elements, iterate over them, then do the context-specific searches for the inner <code>td</code> elements and get the first and the third:</p> <pre><code>for tr in soup.find_all('tr'): cells = tr.find_all('td') if len(cells) &lt; 3: continue # safety pillow lin...
1
2016-08-26T14:13:16Z
[ "python", "python-2.7", "beautifulsoup" ]
How to get a single value from gae ndb query?
39,158,983
<p>I'm using Google App Engine with ndb backend and I want to get a single value ex: <code>int</code> from the ndb entity, after any query I get the whole entity with a projection, in my case I have a Transactions entity and I want to sum the amount properties.</p> <p>What I'm using now is list comprehension on the qu...
0
2016-08-26T05:39:00Z
39,163,351
<p>There is no direct way to get list of values from projection fetch (I suppose you are looking for ndb analog of django orm Transactions.query().all().values()), you may do as follows:</p> <pre><code>result = sum([x.amount for x in Transactions.query().fetch( projection=[Transactions.amount,])]) </code></pre> <...
1
2016-08-26T09:46:43Z
[ "python", "google-app-engine", "app-engine-ndb", "gql", "gqlquery" ]
How to implement SNMP in python?
39,159,059
<p>I am now currently working with SNMP. The package I used is pysnmp but I do not know how to implement snmp in python. The problem is, given an ip address, it should give the details of that device using snmp. Could anyone suggest me how to do it?</p>
-5
2016-08-26T05:44:47Z
39,170,725
<p>If I was in your shoes, I'd read briefly on the <a href="http://pysnmp.sourceforge.net/docs/tutorial.html" rel="nofollow">subject</a> e.g. how SNMP is designed and how it is typically used. Then I'd try to use ready-made <a href="http://pysnmp.sourceforge.net/examples/hlapi/asyncore/sync/manager/cmdgen/walking-opera...
0
2016-08-26T16:22:23Z
[ "python", "ip", "snmp", "pysnmp" ]
Is there a direct way to ignore parts of a python datetime object?
39,159,092
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p> <pre><code>a = datetime.datetime(2015,07,04,01,01,01) b = datetime.datetime(2016,07,04,01,01,01) </code></pre> <p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create ...
3
2016-08-26T05:47:26Z
39,159,198
<pre><code>(a.month, a.day, a.hour, a.minute, a.second == b.month, b.day, b.hour, b.minute, b.second) </code></pre> <p>A less explicit method is to compare the corresponding elements in the time tuples:</p> <pre><code>a.timetuple()[1:6] == b.timetuple()[1:6] </code></pre>
8
2016-08-26T05:56:26Z
[ "python", "datetime" ]
Is there a direct way to ignore parts of a python datetime object?
39,159,092
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p> <pre><code>a = datetime.datetime(2015,07,04,01,01,01) b = datetime.datetime(2016,07,04,01,01,01) </code></pre> <p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create ...
3
2016-08-26T05:47:26Z
39,159,319
<pre><code>def cmp(a,b): return (a &gt; b) - (a &lt; b) d1=(2015,7,4,1,1,1) d2=(2016,7,4,1,1,1) cmp(list(d1)[1:],list(d2)[1:]) </code></pre> <p>Returns 0 - they are the same, i.e. 0 differences</p> <pre><code>d1=(2015,7,4,1,1,1) d2=(2015,2,4,1,1,1) cmp(list(d1)[1:], list(d2)[1:]) </code></pre> <p>returns -1, the...
1
2016-08-26T06:04:13Z
[ "python", "datetime" ]
Is there a direct way to ignore parts of a python datetime object?
39,159,092
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p> <pre><code>a = datetime.datetime(2015,07,04,01,01,01) b = datetime.datetime(2016,07,04,01,01,01) </code></pre> <p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create ...
3
2016-08-26T05:47:26Z
39,159,366
<p>You can also consider comparing formatted date strings consisting of the fields you wish to include in the comparison. This allows you to be somewhat explicit while using shortened versions of the fields (as opposed to accessing <code>a.year</code>, <code>a.month</code>, etc.).</p> <pre><code>from datetime import d...
3
2016-08-26T06:07:10Z
[ "python", "datetime" ]
Is there a direct way to ignore parts of a python datetime object?
39,159,092
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p> <pre><code>a = datetime.datetime(2015,07,04,01,01,01) b = datetime.datetime(2016,07,04,01,01,01) </code></pre> <p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create ...
3
2016-08-26T05:47:26Z
39,159,367
<p>Try:</p> <pre><code>a.replace(year=1,microsecond=0) == b.replace(year=1,microsecond=0) </code></pre>
5
2016-08-26T06:07:14Z
[ "python", "datetime" ]
Is there a direct way to ignore parts of a python datetime object?
39,159,092
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p> <pre><code>a = datetime.datetime(2015,07,04,01,01,01) b = datetime.datetime(2016,07,04,01,01,01) </code></pre> <p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create ...
3
2016-08-26T05:47:26Z
39,159,370
<pre><code>In [70]: a Out[70]: datetime.datetime(2015, 7, 4, 0, 0) In [71]: b Out[71]: datetime.datetime(2016, 7, 4, 0, 0) In [72]: def my_date_cmp(a, b): ....: return a.replace(year = b.year) == b ....: In [73]: my_date_cmp(a, b) Out[73]: True </code></pre>
0
2016-08-26T06:07:22Z
[ "python", "datetime" ]
Looping through (and opening) specific types of files in folder?
39,159,131
<p>I want to loop through files with a certain extension in a folder, in this case .txt, open the file, and print matches for a regex pattern. When I run my program however, it only prints results for one file out of the two in the folder:</p> <blockquote> <p>Anthony is too cool for school. I Reported the criminal. ...
0
2016-08-26T05:50:19Z
39,159,248
<p>U can do as simple as this :(its just a loop through file)</p> <pre><code>import re, os Regex = re.compile(r'[A-Z]') filepath =input('Enter a folder path: ') files = os.listdir(filepath) count = 0 for file in files: if '.txt' in file: fileobj = open(os.path.join(filepath, file), 'r') filetext ...
1
2016-08-26T05:59:25Z
[ "python", "regex", "loops", "operating-system" ]
Looping through (and opening) specific types of files in folder?
39,159,131
<p>I want to loop through files with a certain extension in a folder, in this case .txt, open the file, and print matches for a regex pattern. When I run my program however, it only prints results for one file out of the two in the folder:</p> <blockquote> <p>Anthony is too cool for school. I Reported the criminal. ...
0
2016-08-26T05:50:19Z
39,159,640
<p>The <code>del</code> is causing the problem. The <code>for</code> loop have no idea if you delete an element or not, so it always advances. There might be a hidden file in the directory, and it is the first element in the files. After it got deleted, the for loop skips one of the files and then reads the second one....
0
2016-08-26T06:27:31Z
[ "python", "regex", "loops", "operating-system" ]
Looping through (and opening) specific types of files in folder?
39,159,131
<p>I want to loop through files with a certain extension in a folder, in this case .txt, open the file, and print matches for a regex pattern. When I run my program however, it only prints results for one file out of the two in the folder:</p> <blockquote> <p>Anthony is too cool for school. I Reported the criminal. ...
0
2016-08-26T05:50:19Z
39,159,867
<p><strong>glob module</strong> will help you much more since you want to read files with specific extension.</p> <p>You can directly get list of files with extension "txt" i.e. you saved one <strong>'if'</strong> construct.</p> <p>More info on <a href="https://pymotw.com/2/glob/" rel="nofollow">glob module</a>.</p> ...
0
2016-08-26T06:41:43Z
[ "python", "regex", "loops", "operating-system" ]
Label Not Showing in Odoo-9
39,159,296
<p>I created a boolean field. The boolean is showing but the label isn't.</p> <pre><code>class product_pricelist_inherit(models.Model): _inherit = 'product.pricelist' myfield= fields.Boolean(string="Is this Pricelist Eligible for Me?") </code></pre> <p>XML:</p> <pre><code>&lt;odoo&gt; &lt;record id="produ...
5
2016-08-26T06:02:40Z
39,159,432
<p>It will not show your field label because you have added field in <code>&lt;div&gt;</code></p> <p>Try with following code.</p> <p>Replace </p> <pre><code>&lt;field name="myfield"/&gt; </code></pre> <p>with</p> <pre><code>&lt;label for="myfield"/&gt; &lt;field name="myfield"/&gt; </code></pre>
3
2016-08-26T06:12:03Z
[ "python", "xml", "openerp", "odoo-9" ]
Label Not Showing in Odoo-9
39,159,296
<p>I created a boolean field. The boolean is showing but the label isn't.</p> <pre><code>class product_pricelist_inherit(models.Model): _inherit = 'product.pricelist' myfield= fields.Boolean(string="Is this Pricelist Eligible for Me?") </code></pre> <p>XML:</p> <pre><code>&lt;odoo&gt; &lt;record id="produ...
5
2016-08-26T06:02:40Z
39,167,275
<p>You can use <code>group</code> to show field label: </p> <pre><code>&lt;group&gt; &lt;field name="myfield"/&gt; &lt;/group&gt; </code></pre> <p>There is a <code>group</code> just after <code>name</code> field, It can be done using <code>xpath</code>: </p> <pre><code>&lt;xpath expr="//group" position="inside...
1
2016-08-26T13:16:18Z
[ "python", "xml", "openerp", "odoo-9" ]
Python Multithreading vs Multiprocessing vs Sequential Execution
39,159,438
<p>I have the below code:</p> <pre><code>import time from threading import Thread from multiprocessing import Process def fun1(): for _ in xrange(10000000): print 'in fun1' pass def fun2(): for _ in xrange(10000000): print 'in fun2' pass def fun3(): for _ in xrange(10000000): ...
4
2016-08-26T06:12:36Z
39,159,940
<p>You use <code>time.clock</code>, wich gave you CPU time and not real time : you can't use that in your case, as it gives you the execution time (how long did you use the CPU to run your code, wich will be almost the same time for each of these case)</p> <p>Running your code with <code>time.time()</code> instead of ...
4
2016-08-26T06:46:09Z
[ "python", "multithreading", "python-2.7", "multiprocessing" ]
Python Multithreading vs Multiprocessing vs Sequential Execution
39,159,438
<p>I have the below code:</p> <pre><code>import time from threading import Thread from multiprocessing import Process def fun1(): for _ in xrange(10000000): print 'in fun1' pass def fun2(): for _ in xrange(10000000): print 'in fun2' pass def fun3(): for _ in xrange(10000000): ...
4
2016-08-26T06:12:36Z
39,160,139
<p>Basically you're right. What platform do you use to run the code snippet? I guess Windows. Be noticed that "print" <strong>is not CPU bound</strong> so you should comment out "print" and try to run it on Linux to see the difference (It should be what you expect). Use code like this:</p> <pre><code>def fun1(): fo...
0
2016-08-26T06:57:05Z
[ "python", "multithreading", "python-2.7", "multiprocessing" ]
pandas: how to do multiple groupby-apply operations
39,159,475
<p>I have more experience with R’s <code>data.table</code>, but am trying to learn <code>pandas</code>. In <code>data.table</code>, I can do something like this:</p> <pre><code>&gt; head(dt_m) event_id device_id longitude latitude time_ category 1: 1004583 -100015673884079572 NA ...
6
2016-08-26T06:14:58Z
39,159,561
<p>IIUC, use <code>groupby</code> and <code>agg</code>. See <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#applying-multiple-functions-at-once" rel="nofollow">docs</a> for more information.</p> <pre><code>df = pd.DataFrame(np.random.rand(10, 2), pd.MultiIndex.from_product([list('X...
7
2016-08-26T06:20:40Z
[ "python", "pandas", "dataframe", "group-by" ]
pandas: how to do multiple groupby-apply operations
39,159,475
<p>I have more experience with R’s <code>data.table</code>, but am trying to learn <code>pandas</code>. In <code>data.table</code>, I can do something like this:</p> <pre><code>&gt; head(dt_m) event_id device_id longitude latitude time_ category 1: 1004583 -100015673884079572 NA ...
6
2016-08-26T06:14:58Z
39,177,298
<p>@piRSquared has a great answer but in your particular case I think you might be interested in using pandas very flexible <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.apply.html" rel="nofollow" title="apply function">apply function</a>. Because it can be applied to each ...
0
2016-08-27T03:54:08Z
[ "python", "pandas", "dataframe", "group-by" ]
Trouble with restoring pretrained model in tensorflow
39,159,528
<p>I ran the demo program of word2vec which is included in TensorFlow, and now trying to restore the pretrained model from files, but it doesn't work.</p> <p>I ran this script file: <a href="https://github.com/tensorflow/tensorflow/blob/r0.10/tensorflow/models/embedding/word2vec.py" rel="nofollow">https://github.com/t...
0
2016-08-26T06:18:08Z
39,161,774
<p>Try the following:</p> <pre><code>saver = tf.train.Saver() with tf.Session() as sess: checkpoint = tf.train.get_checkpoint_state(checkpoint_dir) if checkpoint and checkpoint.model_checkpoint_path: saver.restore(sess, checkpoint.model_checkpoint_path) </code></pre> <p>Where <code>checkpoint_dir</cod...
0
2016-08-26T08:28:42Z
[ "python", "tensorflow", "word2vec" ]
Trouble with restoring pretrained model in tensorflow
39,159,528
<p>I ran the demo program of word2vec which is included in TensorFlow, and now trying to restore the pretrained model from files, but it doesn't work.</p> <p>I ran this script file: <a href="https://github.com/tensorflow/tensorflow/blob/r0.10/tensorflow/models/embedding/word2vec.py" rel="nofollow">https://github.com/t...
0
2016-08-26T06:18:08Z
39,162,836
<p>I solved this by myself. I wondered where the key 'Skipgram' comes from, and dug the source code. To solve the problem, just add the following on the top:</p> <pre><code>from tensorflow.models.embedding import gen_word2vec </code></pre> <p>I still don't understand exactly what I am doing, but maybe this is because...
0
2016-08-26T09:22:42Z
[ "python", "tensorflow", "word2vec" ]
Find index of multiple queries in a multidimensional numpy array
39,159,548
<p>I am looking for a way to find indices of an array of queries in a multidimensional array. For example:</p> <pre><code>arr = np.array([[17, 5, 19, 9], [18, 13, 3, 7], [ 8, 1, 4, 2], [ 8, 9, 7, 19], [ 6, 11, 8, 5], [11, 16, 13, 18], [ 0, 1, 2, 9], [ 1, 7, 4, 6]]) </code></pre> ...
1
2016-08-26T06:19:37Z
39,159,618
<p>You can get the indices of each matching value by zipping the results of your <code>where</code> function and then using the <code>*</code> dereferencing operator.</p> <pre><code>arr = np.array([[17, 5, 19, 9], [18, 13, 3, 7], [ 8, 1, 4, 2], # (2, 1) [ 8, 9, ...
0
2016-08-26T06:25:33Z
[ "python", "arrays", "numpy", "multidimensional-array" ]
Find index of multiple queries in a multidimensional numpy array
39,159,548
<p>I am looking for a way to find indices of an array of queries in a multidimensional array. For example:</p> <pre><code>arr = np.array([[17, 5, 19, 9], [18, 13, 3, 7], [ 8, 1, 4, 2], [ 8, 9, 7, 19], [ 6, 11, 8, 5], [11, 16, 13, 18], [ 0, 1, 2, 9], [ 1, 7, 4, 6]]) </code></pre> ...
1
2016-08-26T06:19:37Z
39,161,386
<p>IIUC you may try this:</p> <pre><code>In[19]:np.where((arr==4)|(arr==5)) Out[19]: (array([0, 2, 4, 7], dtype=int64), array([1, 2, 3, 2], dtype=int64)) </code></pre>
1
2016-08-26T08:07:40Z
[ "python", "arrays", "numpy", "multidimensional-array" ]
How to return value from recursive function in python?
39,159,573
<p>I'm working with binary tree in python. I need to create a method which searches the tree and return the best node where a new value can be inserted. But i'm have trouble returning a value from this recursive function. I'm a total newbie in python.</p> <pre><code>def return_key(self, val, node): if(val &lt; nod...
0
2016-08-26T06:21:46Z
39,159,591
<p>You need to return the result of your <em>recursive</em> call. You are ignoring it here:</p> <pre><code>if(node.l != None): self.return_key(val, node.l) </code></pre> <p>and</p> <pre><code>if(node.r != None): self.return_key(val, node.r) </code></pre> <p>Recursive calls are no different from other functi...
4
2016-08-26T06:23:01Z
[ "python", "python-2.7", "python-3.x", "recursion", "binary-search-tree" ]
Odoo Server Error ubuntu
39,159,847
<p>When try install any module get this error.</p> <pre><code>Odoo Server Error Traceback (most recent call last): File "/home/nolimit/git/odoo/openerp/http.py", line 648, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/nolimit/git/odoo/openerp/http.py", line 685,...
0
2016-08-26T06:40:53Z
39,161,213
<p>It seems like you forget to declare <code>name</code> field on your Class.</p> <p>You can resolve it with following two option:</p> <ol> <li>Add <em>name</em> field on your <em>class daily_transaction</em> OR</li> <li><p>You may change field definition like</p> <pre><code>'name': fields.char('Subject', size=128, ...
0
2016-08-26T07:57:15Z
[ "python", "openerp", "odoo-8", "odoo-9" ]
Redis get and set decorator
39,160,075
<p>Currently working on python and redis. I have Flask as my framework and working on Blueprints.</p> <p>Looking into implementing cache with redis for my APIs, I have tried <strong>Flask-Cache</strong> and <strong>redis-simple-cache</strong>. Downside are <a href="http://pythonhosted.org/Flask-Cache/" rel="nofollow">...
2
2016-08-26T06:53:55Z
39,160,863
<p>You can use this <a href="https://github.com/dhruvpathak/python-cache-decorator" rel="nofollow">cache decorator</a>, the cache object you create will have to be a flask cache object instead of django one i.e. should support cache.get and cache.set methods, this is pretty flexible based on how you want to create cach...
0
2016-08-26T07:36:42Z
[ "python", "caching", "redis", "decorator" ]
Redis get and set decorator
39,160,075
<p>Currently working on python and redis. I have Flask as my framework and working on Blueprints.</p> <p>Looking into implementing cache with redis for my APIs, I have tried <strong>Flask-Cache</strong> and <strong>redis-simple-cache</strong>. Downside are <a href="http://pythonhosted.org/Flask-Cache/" rel="nofollow">...
2
2016-08-26T06:53:55Z
39,319,855
<p>You seem to not have read the <a href="http://pythonhosted.org/Flask-Cache/" rel="nofollow">Flask-Cache documentation</a> very closely. Caching does <em>not</em> ignore parameters and the cache key is customisable. The decorators the project supplies already give you the functionality you seek.</p> <p>From the <a h...
0
2016-09-04T17:53:49Z
[ "python", "caching", "redis", "decorator" ]
Add parentheses to list elements - Python
39,160,469
<p>I would like to retrieve a set of data in a file in the form of a list.</p> <p>The following is the data i am reading from the file which I want to add to list:</p> <blockquote> <h1>file input: (3,5),(5,2),(2,1),(4,2),(4,1),(3,1)</h1> </blockquote> <p>The following code shows what I have now:</p> <pre><code>wi...
-3
2016-08-26T07:15:37Z
39,160,498
<pre><code>import ast s = "(3,5),(5,2),(2,1),(4,2),(4,1),(3,1)" &gt;&gt;&gt; list(ast.literal_eval(s)) [(3, 5), (5, 2), (2, 1), (4, 2), (4, 1), (3, 1)] </code></pre> <p>Here is an <a href="http://stackoverflow.com/questions/15197673/using-pythons-eval-vs-ast-literal-eval">SO link</a> to <code>eval</code> vs <code>as...
3
2016-08-26T07:17:16Z
[ "python", "string", "list", "file" ]
Add parentheses to list elements - Python
39,160,469
<p>I would like to retrieve a set of data in a file in the form of a list.</p> <p>The following is the data i am reading from the file which I want to add to list:</p> <blockquote> <h1>file input: (3,5),(5,2),(2,1),(4,2),(4,1),(3,1)</h1> </blockquote> <p>The following code shows what I have now:</p> <pre><code>wi...
-3
2016-08-26T07:15:37Z
39,160,922
<p>Solved it by this code, list of tuples! : </p> <pre><code>with open('partial.txt') as f: graph = [tuple(map(int, i.split(','))) for i in f] print (graph) </code></pre>
0
2016-08-26T07:40:20Z
[ "python", "string", "list", "file" ]
How can python function actually change the parameter rather than the formal parameter?
39,160,682
<p>I am trying to code "1024" using python basic library. In the process I try to make a list [0, 2, 4, 4] become [0, 2, 8, 0]. So here is my test code. It's very easy one.</p> <pre><code> def merger(a, b): if a == b: a += b b = 0 numlist = [0, 2, 4, 4] merger(numlist[0], numlist[1...
1
2016-08-26T07:27:27Z
39,160,857
<p>You can pass the list and indexes to the function:</p> <pre><code>def merger(l, a, b): if l[a] == l[b]: l[a] += l[b] l[b] = 0 numlist = [0, 2, 4, 4] merger(numlist, 0, 1) merger(numlist, 1, 2) merger(numlist, 2, 3) print(numlist) </code></pre> <p>As list object will be passed by reference and ...
2
2016-08-26T07:36:19Z
[ "python", "function", "syntax" ]
How to use multiple 'if' statements nested inside an enumerator?
39,160,750
<p>I have a massive string of letters all jumbled up, 1.2k lines long. I'm trying to find a lowercase letter that has EXACTLY three capital letters on either side of it.</p> <p>This is what I have so far</p> <pre><code>def scramble(sentence): try: for i,v in enumerate(sentence): if v.islower()...
0
2016-08-26T07:31:09Z
39,160,899
<p>Here is a way to do it "Pythonically" without<br> regular expressions:</p> <pre><code>s = 'abcdEFGhIJKlmnop' words = [s[i:i+7] for i in range(len(s) - 7) if s[i:i+3].isupper() and s[i+3].islower() and s[i+4:i+7].isupper()] print(words) </code></pre> <p>And the output is:</p> <pre><code>['EFGhIJK'] </code></pre> ...
1
2016-08-26T07:39:13Z
[ "python" ]
How to use multiple 'if' statements nested inside an enumerator?
39,160,750
<p>I have a massive string of letters all jumbled up, 1.2k lines long. I'm trying to find a lowercase letter that has EXACTLY three capital letters on either side of it.</p> <p>This is what I have so far</p> <pre><code>def scramble(sentence): try: for i,v in enumerate(sentence): if v.islower()...
0
2016-08-26T07:31:09Z
39,161,006
<p>if you can't use regular expression</p> <p>maybe this for loop can do the trick </p> <pre><code>if v.islower(): if sentence[i-4].islower() and sentence[i+4].islower(): for k in range(1,4): if sentence[i-k].islower() or sentence[i+k].islower(): break if k == 3: ...
1
2016-08-26T07:44:39Z
[ "python" ]
How to use multiple 'if' statements nested inside an enumerator?
39,160,750
<p>I have a massive string of letters all jumbled up, 1.2k lines long. I'm trying to find a lowercase letter that has EXACTLY three capital letters on either side of it.</p> <p>This is what I have so far</p> <pre><code>def scramble(sentence): try: for i,v in enumerate(sentence): if v.islower()...
0
2016-08-26T07:31:09Z
39,161,141
<p>regex is probably the easiest, using a modified version of @Israel Unterman's answer to account for the outside edges and non-upper surroundings the full regex might be:</p> <pre><code>s = 'abcdEFGhIJKlmnopABCdEFGGIddFFansTBDgRRQ' import re words = re.findall(r'(?:^|[^A-Z])([A-Z]{3}[a-z][A-Z]{3})(?:[^A-Z]|$)', s) ...
1
2016-08-26T07:52:47Z
[ "python" ]
How to get the flag/state of current operation in Odoo 9?
39,160,816
<p>I am new in odoo, I want to know how we get the current flag/state of every operation.</p> <p>For example: when we create a new record how do we know the current flag/state is "add"? or when we view a record how do we know the current flag/state is "view"? </p> <p>It something like current user id that stored in s...
1
2016-08-26T07:34:22Z
39,180,410
<p>There is no such thing as 'flag/state'. </p> <p>What you are probably trying to say is that you want to know which operations are taking place on a record. The easiest method is to take a look at your log. There will be statements there in the form <code>/web/dataset/call_kw/model/operation</code> where model is yo...
0
2016-08-27T11:05:30Z
[ "python", "web", "openerp" ]
Putting/Updating item in DynamoDB fails for the UpdateExpression syntax
39,161,097
<p>I've created a DynamoDB table, and in my Python code, I have the resource initialised as follows:</p> <pre><code>self.dynamodb = self.session.resource('dynamodb').Table('aws-ci') </code></pre> <p>The table has just one index/key, with the name <code>environment</code>. I am trying to <code>PUT</code> into it, an o...
0
2016-08-26T07:50:14Z
39,161,500
<p>Have you tried this? <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames" rel="nofollow">http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames</a></p> <pre><code>set_query = "SET ...
1
2016-08-26T08:14:11Z
[ "python", "amazon-web-services", "amazon-dynamodb", "boto", "boto3" ]
Querying more properties in Google Search Console via python script
39,161,201
<p>I am using a Python (2.7) script to download via API Google Search Console data. I would like to get rid of the property and dates arguments when launching the script:</p> <pre><code>&gt;python script. py ´http://www.example.com´ ´01-01-2000´ ´01-02-2000´ </code></pre> <p>For the latter I managed to do it im...
0
2016-08-26T07:56:30Z
39,531,090
<p>I think I can help as I had the same problem when working from the sample script given by google as guidance. Which is what I think you gotten your code from?</p> <p>The problem is that the script uses the sample_tools.py script in the googleapiclient library, which is meant to abstract away all the authentication ...
0
2016-09-16T12:06:03Z
[ "python", "python-2.7", "google-api", "google-webmaster-tools", "google-api-python-client" ]
How to work around missing PyModule_Create2 in AMD64 Win Python35_d.lib?
39,161,202
<p>I'm trying to debug an extension module that worked fine in 32 bit Python 2.7, but not so fine in 64 bit Python 3.5.</p> <p>I've used the AMD64 Web installer from Python.org, and yet in the link I get</p> <pre><code>__imp_PyModule_Create2 (referenced in libboost_python-vc120-mt-gd-1_57.lib(module.obj)) </code></pr...
0
2016-08-26T07:56:35Z
39,198,661
<p>I've discovered the issue here; the AMD64 factor is irrelevant.</p> <p>The key is that the Boost Python library expects to link against the Release version of Python, even if it is the debug version of Boost Python. By trying to link an extension module that depends on Boost Python, Boost's</p> <pre><code>config/...
0
2016-08-29T04:50:45Z
[ "python" ]
Paraview picture generation
39,161,205
<p>I am trying to run a python script to generate pictures. But every time i run i get the following error.</p> <pre><code>File "/usr2/tmp/Krishnamoorthi/case0383/New/Pics_0.py", line 16, in &lt;module&gt; case_foam.SurfaceArrays = ['meshPhi', 'phi'] File "/cax/sw-cae1/OPENFOAM/LINUX_x86_64/ParaView/ParaView-4.4.0-Qt...
0
2016-08-26T07:56:46Z
39,817,906
<p>The issue is that <code>SurfaceArrays</code> property does not exist on the <code>case_foam</code> reader instance.</p> <p>Try opening the data data file in ParaView UI and see what properties are shown on the <code>Properties Panel</code>. There'd be some other property that should be used to select the <code>mesh...
0
2016-10-02T14:18:15Z
[ "python", "paraview" ]
File lock (flock) compatibility between C and Python
39,161,412
<p>Does the python implementation of flock work transparently along with standard C libraries? If I have two programs, one in Python and the other in C, trying acquire a lock on a single file will it work?</p> <p><strong>Quick links:</strong></p> <ol> <li>Python flock: <a href="https://docs.python.org/2/library/fcntl...
1
2016-08-26T08:09:11Z
39,161,454
<p>Python's <code>fcntl</code> library is built directly on top of the standard C libraries; so on Linux <code>fcntl.flock()</code> uses the <code>flock</code> C function <em>directly</em>.</p> <p>See the <a href="https://hg.python.org/cpython/file/2.7/Modules/fcntlmodule.c#l250" rel="nofollow">source code for the <co...
2
2016-08-26T08:11:25Z
[ "python", "c", "linux", "locking" ]
How to find the position of an item of a list in python?
39,161,431
<p>I have two lists. The first list has a specific length and the second list has unstable length. I want to assign the items from two lists. I use <code>colour_index = sel_pos%(len(colours))</code>. The sel_pos is the item's position from the unstable list. How to find the position every time?</p>
-2
2016-08-26T08:10:02Z
39,161,551
<p>Use <code>l.index(n)</code> to find index of <code>n</code> in list <code>l</code>.</p> <pre><code>&gt;&gt;&gt; x = [1,3,7] &gt;&gt;&gt; x.index(3) 1 </code></pre>
2
2016-08-26T08:17:03Z
[ "python", "list", "colors", "position", "variable-length-array" ]
How to find the position of an item of a list in python?
39,161,431
<p>I have two lists. The first list has a specific length and the second list has unstable length. I want to assign the items from two lists. I use <code>colour_index = sel_pos%(len(colours))</code>. The sel_pos is the item's position from the unstable list. How to find the position every time?</p>
-2
2016-08-26T08:10:02Z
39,161,650
<pre><code>colour_index = selections.index(txt)%(len(colours)) </code></pre>
0
2016-08-26T08:22:07Z
[ "python", "list", "colors", "position", "variable-length-array" ]
How to find the position of an item of a list in python?
39,161,431
<p>I have two lists. The first list has a specific length and the second list has unstable length. I want to assign the items from two lists. I use <code>colour_index = sel_pos%(len(colours))</code>. The sel_pos is the item's position from the unstable list. How to find the position every time?</p>
-2
2016-08-26T08:10:02Z
39,162,756
<p>You can use Index function which is get the element and return the index of it in the list:</p> <pre><code>indexNumber = MyList.Index(Element) </code></pre>
0
2016-08-26T09:19:22Z
[ "python", "list", "colors", "position", "variable-length-array" ]
Regex on list element in for loop
39,161,495
<p>I have a script that searches through config files and finds all matches of strings from another list as follows:</p> <pre><code>dstn_dir = "C:/xxxxxx/foobar" dst_list =[] files = [fn for fn in os.listdir(dstn_dir)if fn.endswith('txt')] dst_list = [] for file in files: parse = CiscoConfParse(dstn_dir+'/'+file) ...
2
2016-08-26T08:13:31Z
39,161,847
<p>Strings in python are iterable, so <code>sfarm</code> is an iterable, but that has little meaning in this case. From reading what <a href="http://www.pennington.net/py/ciscoconfparse/api_CiscoConfParse.html#ciscoconfparse.CiscoConfParse.find_all_children" rel="nofollow"><code>CiscoConfParse.find_all_children()</code...
2
2016-08-26T08:32:34Z
[ "python" ]
Regex on list element in for loop
39,161,495
<p>I have a script that searches through config files and finds all matches of strings from another list as follows:</p> <pre><code>dstn_dir = "C:/xxxxxx/foobar" dst_list =[] files = [fn for fn in os.listdir(dstn_dir)if fn.endswith('txt')] dst_list = [] for file in files: parse = CiscoConfParse(dstn_dir+'/'+file) ...
2
2016-08-26T08:13:31Z
39,161,912
<p>Please check this code. Used glob module to get all "*.txt" files in folder.</p> <p>Please check here for more info on <a href="https://pymotw.com/2/glob/" rel="nofollow">glob module</a>.</p> <pre><code>import glob import re dst_list = [] search_str = ['xrout:55','old:23'] for file_name in glob.glob(r'C:/Users/din...
1
2016-08-26T08:35:29Z
[ "python" ]
collections counter python can't access the key
39,161,593
<p>I am using the collections counter to count each string (they might not be unique) inside lists. The problem is that now I can't access the dictionary, and I am not sure why.</p> <p>My code is:</p> <pre><code>from collections import Counter result1 = Counter(list_final1) #to count strings inside list </code></pre...
0
2016-08-26T08:18:53Z
39,161,633
<p>Use your <code>key</code> with the variable in which you stored the value of <code>Counter</code>, in your case <code>result1</code>. Sample:</p> <pre><code>&gt;&gt;&gt; from collections import Counter &gt;&gt;&gt; my_dict = {'BAM': 44, 'CCC': 20, 'APG': 14, 'MBI': 11, 'BAV': 10} &gt;&gt;&gt; result = Counter(my_di...
2
2016-08-26T08:21:33Z
[ "python", "python-collections" ]
python 2 stdin can't read individual lines
39,161,608
<p>I have the following very simple-looking code:</p> <pre><code>from __future__ import print_function import sys for line in sys.stdin: print("hello!") sys.stdout.flush() </code></pre> <p>When I run it, I expect to type in a line and then immediately see <code>hello!</code> printed out after it, after which...
0
2016-08-26T08:19:54Z
39,162,912
<p>Answer to your question is here <a href="http://stackoverflow.com/questions/107705/disable-output-buffering">Disable output buffering</a>. (4th comment of accepted answer). Your working code should be like this:</p> <pre><code>from __future__ import print_function import sys while True: line = sys.stdin.readli...
3
2016-08-26T09:26:27Z
[ "python", "io", "buffer", "stdin", "python-2.x" ]
How to keep update the files using PYTHON
39,161,653
<pre><code>import os import glob import CameraID files = glob.glob('/tmp/image/*.png') count = 1 while (count==1): for image in files: if ( not os.path.isfile(image)): print("Error: %s file not found" %image) else: print("Sending file %s ..." % image) print Came...
1
2016-08-26T08:22:12Z
39,161,992
<p>moves the line:</p> <pre><code>files = glob.glob('/tmp/image/*.png') </code></pre> <p>into the <code>while loop</code> to keep that updated</p>
2
2016-08-26T08:39:55Z
[ "python", "python-2.7" ]
TemplateSyntaxError at /cart/, Invalid block tag: '"cart:cart_remove"', expected 'endwith'
39,161,736
<p>I'm doing the webshop following the code in the book "Django by Example". I tried Google and searches in Stackoverflow but I did not find answers to this problem. </p> <p>The product list page and the product detail page work fine but when I try to add items to the cart, the browser says: TemplateSyntaxError at /c...
0
2016-08-26T08:26:59Z
39,161,890
<p>The problem is not with <code>endwith</code>, but with the tag that is highlighted. <code>"cart:cart_remove"</code> is not a tag; I expect you meant to use <code>{% url "cart:cart_remove" ... %}</code> there.</p>
1
2016-08-26T08:34:24Z
[ "python", "django" ]
Shopify app: adding a new shipping address via webhook
39,161,806
<p>I'm planning to create a simple app using Django/Python that shows a nice button when installed by the store owner on user's account.</p> <p>Clicking on that button should trigger a webhook request to our servers that would send back the generated shipping address for the user.</p> <p>My questions:</p> <ol> <li>I...
0
2016-08-26T08:30:33Z
39,170,945
<p>Here is the recipe:</p> <ul> <li>create a Proxy in your App to accept incoming Ajax call from customer</li> <li>create a form and button in customer liquid that submits to your Proxy</li> <li>in the App Proxy, validate the call from Shopify and when valid, look for your form params. </li> <li>open the customer reco...
0
2016-08-26T16:35:56Z
[ "python", "django", "shopify" ]
FileNotFoundError: [Errno 2] No such file or directory in Pycharm
39,161,868
<p>I'm pretty new with Python and finding some issues on a trivial code. I'm using Pycharm together with Anaconda. </p> <p>This is my code: </p> <pre><code>posSentences = open('rt-polarity-pos.txt', 'r') print (posSentences.read()) </code></pre> <p>There is no issue in reading the file and printing it out when runn...
0
2016-08-26T08:33:29Z
39,161,923
<p>Python interpreter is run from <code>Desktop\textan</code> but the file is in <code>Desktop\textan\textan\</code> directory, so the path to the file in python code becomes <code>textan\rt...txt</code></p>
0
2016-08-26T08:36:11Z
[ "python", "pycharm", "anaconda" ]
Writing a line of row per iteration to file without overwriting the file in python
39,161,959
<p>I have searched this on Stackoverflow and all of the "duplicates" for this topic but it seems remained unanswered. I have tried all these:</p> <p><strong>Attempt#1:</strong></p> <pre><code>for word in header: writer.writerow([word] </code></pre> <p><em>Pasted from <a href="http://stackoverflow.com/questions/1...
-1
2016-08-26T08:38:03Z
39,162,141
<pre><code>data = [1,2,3,4,5] with open('asd.txt', 'w') as fn: for i in data: fn.write(str(i) + '\n') # Add a \n (newline) so the next write will occure in the next line </code></pre> <p>Content of <code>asd.txt</code>:</p> <pre><code>1 2 3 4 5 </code></pre> <p>If you want to append to a file use <code>w...
0
2016-08-26T08:47:54Z
[ "python", "python-2.7" ]
Writing a line of row per iteration to file without overwriting the file in python
39,161,959
<p>I have searched this on Stackoverflow and all of the "duplicates" for this topic but it seems remained unanswered. I have tried all these:</p> <p><strong>Attempt#1:</strong></p> <pre><code>for word in header: writer.writerow([word] </code></pre> <p><em>Pasted from <a href="http://stackoverflow.com/questions/1...
-1
2016-08-26T08:38:03Z
39,162,677
<p>There is 2 ways to do that:</p> <p>First by adding '\n' character at the end of your output line :</p> <pre><code>for x in row: writer.write(x + "\n") </code></pre> <p>Second by opening file in Append mode, it is going to add lines existing text file but be careful.it's not overwrite the file :</p> <pre><code...
0
2016-08-26T09:14:53Z
[ "python", "python-2.7" ]
Mysql fails to run after reboot using crontab
39,161,966
<p>I have made a script which saves data to Mysql database using mysqldp and python. When I run script from console (python myscript.py) it works, but when I run it on reboot using Crontab I get an email with following error:</p> <blockquote> <p><strong>_mysql_exceptions.OperationalError: (2002, "Can't connect to lo...
-2
2016-08-26T08:38:24Z
39,165,472
<p>Thanks to Shadow's hint I have solved the problem. I just have started the <strong>Mysql</strong> server manually from the script and now it works.</p> <p>I have used this command to start the server</p> <blockquote> <p><strong>from subprocess import call</strong></p> <p><strong>call(['sudo','service','mysq...
0
2016-08-26T11:42:10Z
[ "python", "mysql", "crontab" ]
MDM server - M2Crypto: undefined symbol: SSLv2_method
39,161,999
<p>I have downloaded a code from <a href="https://github.com/project-imas/mdm-server.git" rel="nofollow">GitHub</a>. I tried to run that code in my linux machine and i have installed all required libraries.But the code is not working and displaying the following error. Please help me to get out of this problem.I will b...
0
2016-08-26T08:40:24Z
39,519,917
<p>Although <a href="http://stackoverflow.com/a/11072709/780190">this</a> answer suggests a patch for <code>M2Crypto-0.21.1</code>, it never worked for me.<br> By default ubuntu has <code>openssl</code> built without <code>SSLv2</code> support as <a href="http://stackoverflow.com/a/8219807/780190">explained here</a>, I...
0
2016-09-15T20:34:22Z
[ "python", "mdm", "m2crypto" ]
Python readinto: How to convert from an array.array to a custom ctype structure
39,162,028
<p>I have created an array of integers and I would like them to be interpreted by the structure definition which I have created</p> <pre><code>from ctypes import * from array import array class MyStruct(Structure): _fields_ = [("init", c_uint), ("state", c_char), ("constant", c_int...
0
2016-08-26T08:41:59Z
39,162,081
<p>Does this have to be an array? could you use a list maybe? you can unpack from a list in to a function you can use the * operator:</p> <p>mystr = MyStruct(*arr)</p> <p>or a dict with:</p> <p>mystr = MyStruct(**arr)</p>
0
2016-08-26T08:45:02Z
[ "python", "arrays", "ctypes", "python-2.x" ]