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 |
|---|---|---|---|---|---|---|---|---|---|
How would I click something in urllib2 | 37,805,359 | <p>This is a text box and I am wondering if it is possible to click it</p>
<pre><code><input type="text" id="FirstName" class="form-control" name="FirstName" data-bind="inputWithPlaceholder: firstName, value: firstName, css: { 'has-error': showError(firstName) }, hasFocus: firstName.focused, tooltip: { target: '#La... | -1 | 2016-06-14T07:16:16Z | 37,806,311 | <p>I would recommend <a href="http://stackoverflow.com/questions/5852968/where-is-webdrivers-python-api-documentation">selenium</a> it is a little bit tricky in the start but since it opens a webb browser it is really easy to follow what is happening.</p>
<p>(When u have located your element by name, id, class etc. yo... | 0 | 2016-06-14T08:04:12Z | [
"python",
"python-2.7",
"python-3.x",
"urllib2",
"urllib"
] |
Multicore python as an alternative to spark | 37,805,437 | <p>I have a python program which uses a lot of <code>pandas</code> and <code>sklearn</code> computing. It basically iterates over a dataframe and makes calculus.
The code uses the <code>map</code> function of the <code>multiprocessing</code> module. It also uses some <code>sklearn</code> models with <code>n_jobs = -1</... | 0 | 2016-06-14T07:19:53Z | 37,806,429 | <p>You can take a look at <a href="http://www.celeryproject.org/" rel="nofollow">Celery</a>.</p>
<p>The project focuses into solving your problem.</p>
<blockquote>
<p>The execution units, called tasks, are executed concurrently on a
single or more worker servers...</p>
</blockquote>
| 1 | 2016-06-14T08:10:35Z | [
"python",
"pandas",
"apache-spark",
"multiprocessing",
"multicore"
] |
simplejson.scanner.JSONDecodeError: Invalid \X escape sequence u's': line 1 column 468 (char 467) | 37,805,751 | <p>I am having a problem while making an HTTP request to a REST api where my JSON formatted response isn't properly formed. There are escape sequences in the JSON which are interpreted correctly, but then there is a specific sentence which has the words "inner\spiritual", making the JSON decoder believe the "\s" is an ... | 0 | 2016-06-14T07:35:01Z | 37,805,777 | <p><strong>My Fix:</strong></p>
<pre><code>def fix_JSON(json_message=None):
result = None
try:
result = json.loads(json_message)
except Exception as e:
# Find the offending character index:
idx_to_replace = int(e.message.split(' ')[-1].replace(')',''))
# ... | 0 | 2016-06-14T07:36:37Z | [
"python",
"json",
"rest",
"python-requests",
"imdb"
] |
How to retain checkbox state after submit in django? | 37,806,114 | <p>Checkbox has two states(checked and unchecked).In my view I have several products and I am trying to filter it based on its category.When I click on any checkbox, checkbox state is changing(getting unchecked).Also I am unable to select multiple checkboxes.</p>
<p>Models.py,</p>
<pre><code>class Add_cat(models.Mode... | 0 | 2016-06-14T07:53:37Z | 37,806,206 | <p>Your for loop is iterating with <code>i</code>, but your if uses an <code>add_cat</code>, change one of them to be the same as the other.</p>
<pre><code>{% for i in My_Cat %} --> {% for add_cat in My_Cat %}
{% if add_cat.cat_name %} --> {% if i.cat_name %}
</code></pre>
| 0 | 2016-06-14T07:58:54Z | [
"python",
"django",
"django-templates"
] |
How to retain checkbox state after submit in django? | 37,806,114 | <p>Checkbox has two states(checked and unchecked).In my view I have several products and I am trying to filter it based on its category.When I click on any checkbox, checkbox state is changing(getting unchecked).Also I am unable to select multiple checkboxes.</p>
<p>Models.py,</p>
<pre><code>class Add_cat(models.Mode... | 0 | 2016-06-14T07:53:37Z | 37,807,207 | <pre><code>{% for i in My_Cat %}
<input type="checkbox" name="{{i.category}}" value="{{i.category}}"
onclick="return myfunction()"
{% if add_cat.cat_name %}checked="checked"{% endif %}>{{i.category}}
{% endfor %}
</code></pre>
<p>You are using the same name for all the checkbox, so when y... | 0 | 2016-06-14T08:50:26Z | [
"python",
"django",
"django-templates"
] |
PyEZ: jnpr.junos.exception.ConnectRefusedError: ConnectRefusedError(xx.xxx.xxx.xxx) | 37,806,657 | <p>PyEZ Device connection returns ConnectRefusedError.</p>
<pre><code>>>> dev = Device(host='xx.xxx.xx.xx', user='xxxx',password='xxxx')
>>> dev.open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\jnpr\junos\device.py", lin... | 0 | 2016-06-14T08:21:58Z | 37,806,658 | <p>It looks like netconf is not enabled on the given device. (hence PyEZ is not able to connect to netconf default 830 port).</p>
<p>We have 2 option</p>
<p>Enable netconf on device using below config command</p>
<pre><code>"set system services netconf ssh"
</code></pre>
<p>Or pass port=22 in device class, so that ... | 1 | 2016-06-14T08:21:58Z | [
"python",
"pyez"
] |
Thread safe client lib on app engine (python) | 37,806,753 | <p>I found a little sample code about bigquery insert in one of Google's git repositories.</p>
<p><a href="https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/bigquery/main.py" rel="nofollow">https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard... | 0 | 2016-06-14T08:27:19Z | 37,809,988 | <p>If you read the docs you reference it says</p>
<blockquote>
<p>The google-api-python-client library is built on top of the httplib2
library, which is not thread-safe. Therefore, if you are running as a
multi-threaded application, each thread that you are making requests
from must have its own instance of ht... | 1 | 2016-06-14T10:54:26Z | [
"python",
"multithreading",
"google-app-engine",
"google-bigquery",
"google-app-engine-python"
] |
Can not post data via ajax to web2py rest api - possible CORS issue | 37,806,801 | <p>I've searched for answers to this issue for nearly two weeks. I have a simple system built in web2py. Note: I'm not exactly a python veteran. I am attempting to use the web2py rest api to post data to the database. If I run the curl command, the database table is updated and the rest returns the id of the newly add... | 1 | 2016-06-14T08:30:08Z | 37,810,840 | <p>Your <code>wrapper</code> function calls <code>return dict()</code>, which executes before the call to <code>f()</code>, so the decorated <code>api</code> function never gets called. Just remove that line.</p>
<p>Also, note that depending on the nature of the Ajax request, the browser might first make a <a href="ht... | 0 | 2016-06-14T11:33:38Z | [
"javascript",
"python",
"ajax",
"cors",
"web2py"
] |
Can not post data via ajax to web2py rest api - possible CORS issue | 37,806,801 | <p>I've searched for answers to this issue for nearly two weeks. I have a simple system built in web2py. Note: I'm not exactly a python veteran. I am attempting to use the web2py rest api to post data to the database. If I run the curl command, the database table is updated and the rest returns the id of the newly add... | 1 | 2016-06-14T08:30:08Z | 37,859,336 | <p>Ok I solved this issue by doing three things.
1. I removed the CORS decorator code from the controller file - default.py
2. I inserted the below code at the top of the default.py controller file</p>
<pre><code>if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin... | 0 | 2016-06-16T12:31:43Z | [
"javascript",
"python",
"ajax",
"cors",
"web2py"
] |
Python: sharing classs variables across threads | 37,806,858 | <p>I have a counter (training_queue) shared among many instances of a class. The class inherits threading.Thread, so it implements a run() method. When I call start(), I expect each thread to increment this counter, so when it reaches a limit no more threads are started. However, none of the threads modifies the varia... | 0 | 2016-06-14T08:33:11Z | 37,808,201 | <p>Your understanding of how state is shared between threads is correct. However, you are using instance attribute "training_queue" instead of class attribute "training_queue".</p>
<p>That is, you always set training_queue to 1 for each new object. </p>
<p>For example:</p>
<pre><code>import threading
class Engine(t... | 0 | 2016-06-14T09:33:44Z | [
"python",
"python-multithreading"
] |
python search for string in file return entire line + next line into new text file | 37,806,925 | <p>I have a very large text file (50,000+ lines) that should always be in the same sequence. In python I want to search the text file for each of the $INGGA lines and join this line with the subsequent $INHDT to create a new text file. I need to do this without reading into memory as this causes it to crash every time.... | 0 | 2016-06-14T08:36:54Z | 37,807,105 | <p>You can just read a line of file and write to another new file.
Like this:</p>
<pre><code>import re
#open new file with append
nf = open('newfile', 'at')
#open file with read
with open('file', 'rt') as f:
for line in f:
r = re.match(r'\$INGGA', line)
if r is not None:
nf.write(lin... | 1 | 2016-06-14T08:45:55Z | [
"python",
"string",
"file",
"search",
"memory"
] |
python search for string in file return entire line + next line into new text file | 37,806,925 | <p>I have a very large text file (50,000+ lines) that should always be in the same sequence. In python I want to search the text file for each of the $INGGA lines and join this line with the subsequent $INHDT to create a new text file. I need to do this without reading into memory as this causes it to crash every time.... | 0 | 2016-06-14T08:36:54Z | 37,807,120 | <p>I suggest using a simple regex that will parse and capture the parts you care about. Here is an example that will capture the piece you care about:</p>
<p><code>(\$INGGA.*\n\$INHDT.*\n)</code></p>
<p><a href="https://regex101.com/r/tK1hF0/3" rel="nofollow">https://regex101.com/r/tK1hF0/3</a></p>
<p>As in my above... | 0 | 2016-06-14T08:46:35Z | [
"python",
"string",
"file",
"search",
"memory"
] |
python search for string in file return entire line + next line into new text file | 37,806,925 | <p>I have a very large text file (50,000+ lines) that should always be in the same sequence. In python I want to search the text file for each of the $INGGA lines and join this line with the subsequent $INHDT to create a new text file. I need to do this without reading into memory as this causes it to crash every time.... | 0 | 2016-06-14T08:36:54Z | 37,807,177 | <p>In the example PuTTY log you give, its all one line separated with space.
So in this case you can use this to replace the space with new line and gets new file - </p>
<pre><code>cat large_file | sed 's/ /\n/g' > new_large_file
</code></pre>
<p>To iterate over the file separated with new line, run this - </p>
<... | 0 | 2016-06-14T08:48:42Z | [
"python",
"string",
"file",
"search",
"memory"
] |
python search for string in file return entire line + next line into new text file | 37,806,925 | <p>I have a very large text file (50,000+ lines) that should always be in the same sequence. In python I want to search the text file for each of the $INGGA lines and join this line with the subsequent $INHDT to create a new text file. I need to do this without reading into memory as this causes it to crash every time.... | 0 | 2016-06-14T08:36:54Z | 37,807,834 | <p>This answer is aimed at python 3.</p>
<p>According to <a href="http://stackoverflow.com/a/8010133/3275967">this other answer</a> (and <a href="https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow">the docs</a>), you can iterate your file line-by-line memory-efficiently:</p>
... | 0 | 2016-06-14T09:19:19Z | [
"python",
"string",
"file",
"search",
"memory"
] |
rpy2: No output when importing R libraries that are not standard R libraries | 37,806,979 | <p>I want to use the rpy2 package. When I import R's PortfolioAnalytics library which does not belong to the standard library, I do not get any output anymore. (I run my python code directly from Idle on Windows and not via the Windows console (because of the problem I outlined below).)</p>
<p>Examples:</p>
<p><stron... | 1 | 2016-06-14T08:39:51Z | 37,821,816 | <p>This should be a comment, but I can't write comments yet.</p>
<p>I tried to reproduce your error, which I couldn't. Here are my thoughts:</p>
<ol>
<li><p>During installation of R on Windows I was forced to set R_USER. I don't know how you got around that, but I think it is a good idea to do so. <br>
There are dif... | 1 | 2016-06-14T20:49:00Z | [
"python",
"rpy2"
] |
Setting render layers with shading masks with Maya Python | 37,806,981 | <p>So I'm trying to write a script that takes the name of materials from a list, creates a render layer named after each material, then applies a white surface shader to materials that share the render layer's name and a black surface shader to objects that don't. </p>
<pre><code>import maya.cmds as cmds
matName = [... | 0 | 2016-06-14T08:39:54Z | 37,824,496 | <p>alright, got it figured out. Just had to change a few things, and include an <code>if else</code> inside a <code>range</code> to apply the shaders in the right order.</p>
<pre><code>import maya.cmds as cmds
#Put in your material names here. Make sure they have the EXACT SAME spelling, caps,
#and name convention... | 0 | 2016-06-15T01:00:40Z | [
"python",
"maya"
] |
Django - Use forloop.counter0 | 37,807,094 | <p>I would like show element in my list on template html like that :</p>
<pre><code><table class="table table-striped col-md-12">
<tbody>
{% for row in list %}
<tr>
<td>{{ row.0 }}</td>
<td>{{ row.1 }}</td>
<td>{{ .... | 0 | 2016-06-14T08:45:34Z | 37,807,258 | <p>You shouldn't need to look up the index at all, just have another forloop inside that loops over the row</p>
<pre><code>{% for i in row %}
<td>{{ i }}</td>
{% endfor %}
</code></pre>
<p>If you need anything more granular, you might want to look into making an actual model to represent the data, and ... | 1 | 2016-06-14T08:52:40Z | [
"python",
"django",
"python-3.x",
"django-1.9"
] |
Select area in figure using Tkinter | 37,807,214 | <p>I have a script which opens a file and plots it via a matplotlib figure embedded in Tkinter.
I would like to be able to select an area in this figure and retrieve the corner values.
I have my script which is working to open the file and plot the data, and a working example <a href="http://stackoverflow.com/questio... | 0 | 2016-06-14T08:50:46Z | 37,811,075 | <p>To combine the scripts I added the event managers (i.e. <code>aid = self.fig.canvas.mpl_connect('button_press_event', self.on_press)</code>) to my <code>plot</code> function and then just defined the functions connected to these event managers (i.e. <code>on_press</code>) within the main class, like the other normal... | -1 | 2016-06-14T11:44:33Z | [
"python",
"matplotlib",
"tkinter",
"tkinter-canvas"
] |
Python to extract the @user and url link in twitter text data with regex | 37,807,244 | <p>There is a list string twitter text data, for example, the following data (actually, there is a large number of text,not just these data), I want to extract the all the user name after @ and url link in the twitter text, for example: galaxy5univ and url link.</p>
<pre><code> tweet_text = ['@galaxy5univ I like you... | 2 | 2016-06-14T08:52:11Z | 37,807,988 | <p>If the usernames doesn't contain special chars, you can use:</p>
<pre><code>@([\w]+)
</code></pre>
<p>See <a href="https://regex101.com/r/lH9pH9/1" rel="nofollow">Live demo</a></p>
| 1 | 2016-06-14T09:25:32Z | [
"python",
"regex",
"twitter",
"text"
] |
Python to extract the @user and url link in twitter text data with regex | 37,807,244 | <p>There is a list string twitter text data, for example, the following data (actually, there is a large number of text,not just these data), I want to extract the all the user name after @ and url link in the twitter text, for example: galaxy5univ and url link.</p>
<pre><code> tweet_text = ['@galaxy5univ I like you... | 2 | 2016-06-14T08:52:11Z | 37,807,990 | <p>Note that your <code>pn = re.compile(r'@(\S+)')</code> regex will capture any 1+ non-whitespace characters after <code>@</code>.</p>
<p>To exclude matching <code>:</code>, you need to convert the shorthand <code>\S</code> class to <code>[^\s]</code> negated character class equivalent, and add <code>:</code> to it:<... | 3 | 2016-06-14T09:25:37Z | [
"python",
"regex",
"twitter",
"text"
] |
Python to extract the @user and url link in twitter text data with regex | 37,807,244 | <p>There is a list string twitter text data, for example, the following data (actually, there is a large number of text,not just these data), I want to extract the all the user name after @ and url link in the twitter text, for example: galaxy5univ and url link.</p>
<pre><code> tweet_text = ['@galaxy5univ I like you... | 2 | 2016-06-14T08:52:11Z | 37,808,247 | <p>I've written an article amout parsing tweets years ago. I think it's still relevant : <a href="https://fromzerotocodehero.blogspot.com/2010/12/parsing-tweets-links-users-and-hash.html" rel="nofollow">https://fromzerotocodehero.blogspot.com/2010/12/parsing-tweets-links-users-and-hash.html</a></p>
| 1 | 2016-06-14T09:35:36Z | [
"python",
"regex",
"twitter",
"text"
] |
cv2 equivalent attributes to cv | 37,807,268 | <p>I have come across this <a href="https://gist.github.com/philipcristiano/5805662" rel="nofollow">link</a> for face detection and image cropping. I would like to use this script but I have cv2 install and only import cv2 works but not import cv. </p>
<p>How can I convert the cv functions in the following function to... | 0 | 2016-06-14T08:53:04Z | 37,807,442 | <p>Either use</p>
<pre><code>import cv2
storage = cv2.cv.CreateMemStorage(0)
</code></pre>
<p>or</p>
<pre><code>from cv2 import *
storage = cv.CreateMemStorage(0)
</code></pre>
| 0 | 2016-06-14T09:01:17Z | [
"python",
"opencv",
"computer-vision"
] |
Import custom module from other directory | 37,807,498 | <p>Let's say I have a custom module in:</p>
<pre><code>/basexx_yy/subdir1/subdir2/subdir3/subdir4/custom_module.py
</code></pre>
<p>And the script which needs to import <code>custom_module.py</code>is located at:</p>
<pre><code>/basexx_yy/subdir1/otherdir/script.py
</code></pre>
<p>The <code>basexx_yy</code> is a d... | 0 | 2016-06-14T09:03:30Z | 37,807,890 | <p>I agree with Nils Werner, that you most probably want to restructure your package(s).</p>
<p>Anyway, your code should work! Only problem is that you use</p>
<pre><code>split = cwd.split('\\')
</code></pre>
<p>instead of</p>
<pre><code>split = cwd.split(os.path.sep)
</code></pre>
| 0 | 2016-06-14T09:21:22Z | [
"python",
"python-import",
"importerror"
] |
Import custom module from other directory | 37,807,498 | <p>Let's say I have a custom module in:</p>
<pre><code>/basexx_yy/subdir1/subdir2/subdir3/subdir4/custom_module.py
</code></pre>
<p>And the script which needs to import <code>custom_module.py</code>is located at:</p>
<pre><code>/basexx_yy/subdir1/otherdir/script.py
</code></pre>
<p>The <code>basexx_yy</code> is a d... | 0 | 2016-06-14T09:03:30Z | 37,809,056 | <p>It is not exactly clear from your question what your situation is, but here goes as it was <em>designed to be used</em>:</p>
<ul>
<li>A <em>package</em> contains a <code>setup.py</code> and can be installed using <code>pip</code>.</li>
<li>A <em>module</em> lives inside a package or a module and contains an <code>_... | 2 | 2016-06-14T10:10:04Z | [
"python",
"python-import",
"importerror"
] |
How to print a variable and a string in Python without a space between | 37,807,685 | <p>My code is the following:</p>
<pre><code>a = 60
print(a, ": string of text")
</code></pre>
<p>this prints <code>"60 : string of text"</code></p>
<p>I would like it to print <code>"60: String of text"</code> without the space after the <code>60</code> if that makes sense</p>
<p>any ideas?</p>
| 1 | 2016-06-14T09:12:51Z | 37,807,780 | <p><code>print("{}: string of text".format(a))</code></p>
| 0 | 2016-06-14T09:17:12Z | [
"python",
"printing"
] |
How to print a variable and a string in Python without a space between | 37,807,685 | <p>My code is the following:</p>
<pre><code>a = 60
print(a, ": string of text")
</code></pre>
<p>this prints <code>"60 : string of text"</code></p>
<p>I would like it to print <code>"60: String of text"</code> without the space after the <code>60</code> if that makes sense</p>
<p>any ideas?</p>
| 1 | 2016-06-14T09:12:51Z | 37,807,805 | <p>if you use <code>print(... , ... , ...)</code> the <code>,</code> will always insert a space.</p>
<p>you can bypass that if you just concatenate them with </p>
<pre><code>print(str(a) + ": string of text")
</code></pre>
<p>(the <code>str(..)</code> is needed because <code>a</code> is a number)
or you can use pla... | 0 | 2016-06-14T09:18:03Z | [
"python",
"printing"
] |
How to print a variable and a string in Python without a space between | 37,807,685 | <p>My code is the following:</p>
<pre><code>a = 60
print(a, ": string of text")
</code></pre>
<p>this prints <code>"60 : string of text"</code></p>
<p>I would like it to print <code>"60: String of text"</code> without the space after the <code>60</code> if that makes sense</p>
<p>any ideas?</p>
| 1 | 2016-06-14T09:12:51Z | 37,808,135 | <p>There are several ways to remove the space delimiter. Fortunately <code>print()</code> only inserts a space between fields by default. From the <code>print()</code> doc:</p>
<p>"<em>sep: string inserted between values, default a space.</em>"</p>
<p>So my preferred way would be to use an empty string:</p>
<pre... | 1 | 2016-06-14T09:31:02Z | [
"python",
"printing"
] |
How to create subplots with different wspace between them in matplotlib? | 37,807,841 | <p>How can we create subplots with varying wspace between them. For example I am plotting 5 graphs, 2 in first row and 3 in second. I want that first row has different wspace and the last 3 have wspace = 0. I know it is possible with gridspec but I was unable to understand it, so is there any other way in subplot to do... | 2 | 2016-06-14T09:19:33Z | 37,809,822 | <p>You have <code>gridspec.GridSpec(3, 3)</code> this means 3 rows and 3 columns, total 9 subplots with indexes <code>gs1[i,j], i - a row, j - a col</code>. </p>
<p>Look at the example:</p>
<pre><code>import numpy as np
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print A[:-1, :] # get first and second rows (that... | 0 | 2016-06-14T10:46:52Z | [
"python",
"matplotlib"
] |
ValueError Django model.Manager.get function | 37,807,858 | <p>I'm trying to overload the get function in the below code...</p>
<pre><code>class QuizzerBotManager(models.Manager):
def create_quizzer_bot(self):
quizzer_bot = self.create(
client_data=None,
should_set_name = False,
should_set_age = False,
should_set_gen... | 0 | 2016-06-14T09:20:07Z | 37,807,925 | <p>You're not passing your <code>args</code> and <code>kwargs</code> correctly. Try this instead:</p>
<pre><code>quizzer_bot = self.get(*args, **kwargs)
</code></pre>
| 2 | 2016-06-14T09:23:01Z | [
"python",
"django",
"django-models"
] |
ValueError Django model.Manager.get function | 37,807,858 | <p>I'm trying to overload the get function in the below code...</p>
<pre><code>class QuizzerBotManager(models.Manager):
def create_quizzer_bot(self):
quizzer_bot = self.create(
client_data=None,
should_set_name = False,
should_set_age = False,
should_set_gen... | 0 | 2016-06-14T09:20:07Z | 37,807,926 | <p>You should pass those parameters on with the relevant unpacking operators:</p>
<pre><code>quizzer_bot = self.get(*args, **kwargs)
</code></pre>
| 0 | 2016-06-14T09:23:01Z | [
"python",
"django",
"django-models"
] |
Parameter pass in PGSQL query | 37,807,911 | <p>I am trying to call an create function in my class which needs to carry a sql statement. I need to pass some parameters in that query and I don't know how to do it.</p>
<p><strong>The create function in roster_substitute class</strong></p>
<pre><code>def create(self, cr, uid, values, context=None):
rec_id=... | 0 | 2016-06-14T09:22:35Z | 37,808,566 | <p>If you're using standard psycopg2 library then</p>
<pre><code>cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
WHERE allocation_start_day = %... | 1 | 2016-06-14T09:48:15Z | [
"python",
"postgresql",
"openerp",
"openerp-7"
] |
running python file with a bash script | 37,807,935 | <p>I want to run a python file with bash script for a certain time of the day. I script.sh like this (ofcourse execute it with chmod +x before) </p>
<pre><code> #!/bin/bash
python /home/user/file.py
</code></pre>
<p>and with crontab -e
I wrote </p>
<pre><code> * 01 * * * /home/user/script.sh
</code></pre... | -1 | 2016-06-14T09:23:16Z | 37,819,266 | <p>Put a shebang/directive in the python script you're trying to run.</p>
<p>Similar to the shell script you gave, this should be the first line in your python script:</p>
<pre><code>#!/usr/bin/python
</code></pre>
<p>...or for python version 3:</p>
<pre><code>#!/usr/bin/python3
</code></pre>
| 0 | 2016-06-14T18:11:30Z | [
"python",
"bash",
"shell"
] |
Recognition faces on a video using python | 37,808,130 | <p>i have this code </p>
<pre><code>import cv2
import sys
# Get user supplied values
imagePath = sys.argv[1]
cascPath = sys.argv[2]
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in... | 0 | 2016-06-14T09:30:42Z | 37,855,057 | <p>Here is the way to save the image</p>
<pre><code>for (x, y, w, h) in faces:
if(x<0 and y<0):
face= frame[ 0:h, 0:h,:]
elif(y<0):
face= frame[ 0:0+h, x:w,:]
elif(x<0):
face= frame[ y:h, 0:0+w,:]
else:
face= frame[ y:h, x:w,:]
cv2.imwrite("folder /test/1.jp... | 0 | 2016-06-16T09:24:52Z | [
"python",
"opencv",
"image-processing",
"face-recognition"
] |
how to get all string lines using regular expression in python | 37,808,166 | <p>I need to take all string line between <code>EndOfSource.</code> and <code>EndOfMessage.</code>.</p>
<p>For example if output is:</p>
<pre><code>8019 Warning Microsoft-Windows-DNS-Client **EndOfSource.** The system failed to register host (A or AAAA) resource records (RRs) for network adapter
with settings:
Ada... | -3 | 2016-06-14T09:32:15Z | 37,809,002 | <p>There are several issues here:</p>
<ul>
<li>The <code>.*</code> is a greedy subpattern, while you need the lazy one, use <code>.*?</code></li>
<li>The <code>.</code> does not match a newline by default, you need to enable a DOTALL mode with <code>re.S</code> or <code>re.DOTALL</code></li>
<li>Dots must be escaped t... | 1 | 2016-06-14T10:07:58Z | [
"python",
"regex"
] |
The loop prints the smallest number as the largest | 37,808,206 | <p>I'm trying to find the smallest and largest numbers, but the output of the program is incorrect. The smallest is the largest in the output and the largest is always 1 smaller than the largest. I entered 2, 4, 6, 8, heres the output:</p>
<pre><code>Enter a number: 2
Enter a number: 4
Enter a number: 6
Enter a number... | 0 | 2016-06-14T09:34:01Z | 37,808,403 | <p>You are always assigning a value to <code>largest</code> and <code>smallest</code> because you use them as targets in a <code>for</code> loop:</p>
<pre><code>for largest in range(halo):
</code></pre>
<p>In the above, <code>largest</code> will be assigned <code>0</code>, then <code>1</code>, then <code>2</code> all... | 4 | 2016-06-14T09:41:30Z | [
"python"
] |
Execute subprocess python script with arguments | 37,808,360 | <p>I have a python3 script that calls other python3 scripts using <code>subprocess.Popen</code>. <br>The first script creates a python object needed by the second script who will run a few times using the same object.</p>
<p>Right now it looks like this:</p>
<pre><code>for x in range(0,10):
pid2 = subprocess.Pope... | 0 | 2016-06-14T09:40:15Z | 37,808,577 | <p>Args is supposed to be either a string or a sequence of strings as per the <a href="https://docs.python.org/3/library/subprocess.html#popen-constructor" rel="nofollow">documentation</a>. But if you do want to pass an object, you could perhaps serialize the object into JSON, then deserialize it back in your second sc... | 1 | 2016-06-14T09:48:51Z | [
"python",
"subprocess",
"popen"
] |
Execute subprocess python script with arguments | 37,808,360 | <p>I have a python3 script that calls other python3 scripts using <code>subprocess.Popen</code>. <br>The first script creates a python object needed by the second script who will run a few times using the same object.</p>
<p>Right now it looks like this:</p>
<pre><code>for x in range(0,10):
pid2 = subprocess.Pope... | 0 | 2016-06-14T09:40:15Z | 37,808,701 | <blockquote>
<p>I have a python3 script that calls other python3 scripts using subprocess.Popen</p>
</blockquote>
<p>ouch</p>
<blockquote>
<p>The first script creates a python object needed by the second script who will run a few times using the same object.</p>
</blockquote>
<p>ouch^2</p>
<blockquote>
<p>How... | 0 | 2016-06-14T09:54:42Z | [
"python",
"subprocess",
"popen"
] |
Exiting a Thread in Python | 37,808,369 | <p>I'm trying to write a program that crawls through a website and download all the videos it has. I'm facing a problem that the number of threads continuously increases even after the downloading of individual videos are done.</p>
<p>Here is the code for the individual Worker object, which is queued and then joined l... | 2 | 2016-06-14T09:40:34Z | 37,811,512 | <p>By looking at your it looks like you have initialized the thread.which calls the run() method for processing.after that your even using the start method which is not a proper way.
Please use the below mentioned code.</p>
<pre>
<code>
from threading import Event
class Worker(Thread):
def __init__(self, thread_... | 0 | 2016-06-14T12:04:55Z | [
"python",
"multithreading"
] |
compare two files line by line in python | 37,808,427 | <p>I want to compare two different files in python. They contain lines with probabilities, and each line has an in id in the end of the file. I need to calculate ratio of each id. The problem is that each line might contain different number of probabilities and eventually, each text a different number of lines. I suc... | 0 | 2016-06-14T09:42:25Z | 37,809,044 | <p>You might want to zip the read contents of both files and iterate over them. Note that when you use zip, for file of varying line lengths, all files get to have the length of the shortest smallest file length. See <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow">Documentation of zip buil... | 1 | 2016-06-14T10:09:49Z | [
"python"
] |
python3: How to convert a string with Unicode encoding to a string of letters | 37,808,448 | <p>In Python3, how do I convert <code>'\\u00A9 PNG'</code> to <code>'\u00A9 PNG'</code> (or <code>'© PNG'</code>)?</p>
<p>For Java, there is <a href="http://stackoverflow.com/questions/11145681/how-to-convert-a-string-with-unicode-encoding-to-a-string-of-letters">Apache Commons Lang</a> to decode it. </p>
<p>I don't... | 0 | 2016-06-14T09:43:08Z | 37,809,008 | <p>This should work for you.</p>
<pre><code>string = '\\u00A9 PNG'
print (string.encode('utf8').decode('unicode-escape'))
</code></pre>
<p>output:</p>
<blockquote>
<p>© PNG</p>
</blockquote>
| 1 | 2016-06-14T10:08:17Z | [
"python",
"python-3.x",
"encoding"
] |
How to get text from url | 37,808,496 | <p>I have some urls</p>
<pre><code>http://go.mail.ru/search?fr=vbm9&fr2=query&q=%D0%BF%D1%80%D0%BE%D0%B3%D1%83%D0%BB%D0%BA%D0%B0+%D0%B0%D0%BA%D1%82%D0%B5%D1%80%D1%8B&us=10&usln=1
https://www.google.ru/search?q=NaoOmiKi&oq=NaoOmiKi&aqs=chrome..69i57j69i61&sourceid=chrome&es_sm=0&ie=U... | 0 | 2016-06-14T09:45:03Z | 37,808,841 | <p><a href="https://docs.python.org/2/library/urlparse.html#urlparse.urlparse" rel="nofollow">urlparse</a> parses a URL into 6 components: scheme, netloc, path, params, query, fragment. You correctly use index 4 to get the path.</p>
<p>The path however, is a <code>&</code>-separated string of key=value pairs with ... | 2 | 2016-06-14T09:59:30Z | [
"python",
"url",
"urllib2",
"urlparse"
] |
Pandas - why is read_csv with chunking 'on' faster than without for small files? | 37,808,550 | <p>I am reading a somewhat large table (90*85000) of strings, integers and missing values into pandas. The file fits easily into my memory. I also ran the script on a server with plenty of memory, observing the same behavior. </p>
<p>I would assume that reading the file in bulk would be faster or as fast as with chunk... | 1 | 2016-06-14T09:47:45Z | 37,808,663 | <p>because in the second part you've created a <code>pandas.io.parsers.TextFileReader object</code> (iterator)... </p>
<p>Demo:</p>
<pre><code>In [17]: df = pd.DataFrame(np.random.randint(0, 10, size=(20, 3)), columns=list('abc'))
In [18]: df.to_csv('d:/temp/test.csv')
In [19]: reader = pd.read_csv('d:/temp/test.cs... | 4 | 2016-06-14T09:52:55Z | [
"python",
"csv",
"pandas",
"dataframe"
] |
How to check if 2 strings contain same letters and numbers in python? | 37,808,567 | <p>I would like to check if two strings contain the same letters and numbers </p>
<p><strong>BUT</strong> Ignore special characters, such as <code>_</code></p>
<p>Example:</p>
<pre><code>word1 = "ABCD" , word2 = "ACDB" => return True
word1 = "ABC1E_" , word2 = "AE1CB" => return True
word1 = "AB12" , word2 = "... | 1 | 2016-06-14T09:48:16Z | 37,808,670 | <p>Edit: And edit in the question was made where only the contents are important, not the count of the numbers. So in order to get the correct result you should switch to a set. And simply make a list of the ignored characters</p>
<pre><code>ignored_chars = ['_']
s = set()
for letter in word:
if letter in ignored_... | -1 | 2016-06-14T09:53:21Z | [
"python",
"string",
"string-comparison"
] |
How to check if 2 strings contain same letters and numbers in python? | 37,808,567 | <p>I would like to check if two strings contain the same letters and numbers </p>
<p><strong>BUT</strong> Ignore special characters, such as <code>_</code></p>
<p>Example:</p>
<pre><code>word1 = "ABCD" , word2 = "ACDB" => return True
word1 = "ABC1E_" , word2 = "AE1CB" => return True
word1 = "AB12" , word2 = "... | 1 | 2016-06-14T09:48:16Z | 37,808,837 | <pre><code>from string import ascii_letters, digits
def compare_alphanumeric_membership(first, second):
for character in first:
if character in ascii_letters + digits and character not in second:
return False
return True
word1 = 'ABCD'
word2 = 'ACDB'
assert compare_alphanumeric_membershi... | 0 | 2016-06-14T09:59:17Z | [
"python",
"string",
"string-comparison"
] |
How to check if 2 strings contain same letters and numbers in python? | 37,808,567 | <p>I would like to check if two strings contain the same letters and numbers </p>
<p><strong>BUT</strong> Ignore special characters, such as <code>_</code></p>
<p>Example:</p>
<pre><code>word1 = "ABCD" , word2 = "ACDB" => return True
word1 = "ABC1E_" , word2 = "AE1CB" => return True
word1 = "AB12" , word2 = "... | 1 | 2016-06-14T09:48:16Z | 37,808,843 | <p>Assuming you want to account for every alphanumeric character in each string being the same (not just the sets of characters), you could compare the <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow"><code>Counter</code></a>s after filtering characters. </p>
<pre><code>f... | 3 | 2016-06-14T09:59:41Z | [
"python",
"string",
"string-comparison"
] |
How to check if 2 strings contain same letters and numbers in python? | 37,808,567 | <p>I would like to check if two strings contain the same letters and numbers </p>
<p><strong>BUT</strong> Ignore special characters, such as <code>_</code></p>
<p>Example:</p>
<pre><code>word1 = "ABCD" , word2 = "ACDB" => return True
word1 = "ABC1E_" , word2 = "AE1CB" => return True
word1 = "AB12" , word2 = "... | 1 | 2016-06-14T09:48:16Z | 37,808,868 | <p>The following function will compare two strings.</p>
<pre><code>from string import ascii_letters, digits
def cmp_strings(str1, str2):
return all([i in str2 for i in str1 if i in ascii_letters + digits])
print cmp_strings('ABCD', 'ACDB_')
print cmp_strings('ABCD_', 'ACDB')
print cmp_strings('AB12', 'ABE2')
pri... | 0 | 2016-06-14T10:00:43Z | [
"python",
"string",
"string-comparison"
] |
How to check if 2 strings contain same letters and numbers in python? | 37,808,567 | <p>I would like to check if two strings contain the same letters and numbers </p>
<p><strong>BUT</strong> Ignore special characters, such as <code>_</code></p>
<p>Example:</p>
<pre><code>word1 = "ABCD" , word2 = "ACDB" => return True
word1 = "ABC1E_" , word2 = "AE1CB" => return True
word1 = "AB12" , word2 = "... | 1 | 2016-06-14T09:48:16Z | 37,808,992 | <p>what about this?</p>
<pre><code>set(word2).issubet(set(word1))
</code></pre>
| 0 | 2016-06-14T10:07:16Z | [
"python",
"string",
"string-comparison"
] |
matplotlib: Handling speech marks/quotation marks within ax.set_xlabel/ax.set_ylabel | 37,808,587 | <p>I have a niche question here, I'm unable to find any guidelines specific to this. I was wondering if anyone knew how to correctly handle the following text for an axis label within the matplotlib package:</p>
<pre><code>ax.set_xlabel(r'$1.005116" per pixel$')
</code></pre>
<p>The quotation marks are telling the cl... | 1 | 2016-06-14T09:49:24Z | 37,808,685 | <p>Like this:</p>
<pre><code>ax.set_xlabel(r'''$1.005116''\ per\ pixel$''')
</code></pre>
| 3 | 2016-06-14T09:53:50Z | [
"python",
"matplotlib"
] |
matplotlib: Handling speech marks/quotation marks within ax.set_xlabel/ax.set_ylabel | 37,808,587 | <p>I have a niche question here, I'm unable to find any guidelines specific to this. I was wondering if anyone knew how to correctly handle the following text for an axis label within the matplotlib package:</p>
<pre><code>ax.set_xlabel(r'$1.005116" per pixel$')
</code></pre>
<p>The quotation marks are telling the cl... | 1 | 2016-06-14T09:49:24Z | 37,808,999 | <p>Taking advantage of the fact that you're using LaTeX:</p>
<pre><code>ax.set_xlabel(r"$1.005116^{\prime\prime}$ per pixel")
</code></pre>
<p>(I think it looks better if the "per pixel" part is <i>not</i> in LaTeX math mode, but that's a stylistic issue.)</p>
| 3 | 2016-06-14T10:07:42Z | [
"python",
"matplotlib"
] |
Python: How to start a Selenium Firefox web browser minimized? | 37,808,593 | <p>My python script is in a loop and runs every half an hour, when ever the code runs it opens Firefox browser. So if I am working/ looking at any other screen all of a sudden the browser window pops up. I want my browser to either start minimized or disappear but my code should execute </p>
<pre><code>while(True):
... | 0 | 2016-06-14T09:49:31Z | 37,808,729 | <p>While Selenium does provide an inbuilt function to maximize the window, unfortunately it doesn't provide the same functionality to minimize the window.</p>
<p>The below code will move the browser window out of sight, but I don't know if this will fulfil your requirements.</p>
<p><code>driver.set_window_position(0,... | 0 | 2016-06-14T09:55:57Z | [
"python",
"selenium",
"firefox",
"web-scraping"
] |
Python: How to start a Selenium Firefox web browser minimized? | 37,808,593 | <p>My python script is in a loop and runs every half an hour, when ever the code runs it opens Firefox browser. So if I am working/ looking at any other screen all of a sudden the browser window pops up. I want my browser to either start minimized or disappear but my code should execute </p>
<pre><code>while(True):
... | 0 | 2016-06-14T09:49:31Z | 37,809,147 | <p>Unfortunately selenium webdriver does not provide any built in function to minimize the window .
However you can position your window out of sight by using below code.
driver.manage().window().setPosition(new Point(-2000, 0));</p>
| 0 | 2016-06-14T10:14:31Z | [
"python",
"selenium",
"firefox",
"web-scraping"
] |
Selenium install Marionette webdriver | 37,808,643 | <p>I have this issue with firefox version 47 <a href="https://github.com/seleniumhq/selenium/issues/2110">https://github.com/seleniumhq/selenium/issues/2110</a></p>
<p>So, i have tried to add Marionette web driver to fix it: <a href="https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver">https://dev... | 8 | 2016-06-14T09:51:45Z | 37,810,397 | <p>the firefox binary capability you're setting points to the <em>firefox</em> binary, not the marionette driver binary. You need to add <code>/Users/myproject/geckodriver-0.8.0-OSX</code> to your path as follows:</p>
<p>Open a terminal and run this command</p>
<pre><code>export PATH=$PATH:/Users/myproject/geckodrive... | 6 | 2016-06-14T11:13:56Z | [
"python",
"selenium",
"firefox",
"firefox-marionette"
] |
Selenium install Marionette webdriver | 37,808,643 | <p>I have this issue with firefox version 47 <a href="https://github.com/seleniumhq/selenium/issues/2110">https://github.com/seleniumhq/selenium/issues/2110</a></p>
<p>So, i have tried to add Marionette web driver to fix it: <a href="https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver">https://dev... | 8 | 2016-06-14T09:51:45Z | 37,842,979 | <p>I <a href="https://github.com/mozilla/geckodriver/issues/90" rel="nofollow">ran into this issue</a> and can confirm that <code>firefox_capabilities['binary']</code> should point to the Firefox binary, not to GeckoDriver. The Python example in the <a href="https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionet... | 4 | 2016-06-15T18:20:40Z | [
"python",
"selenium",
"firefox",
"firefox-marionette"
] |
Error-weighted fit using uncertainties in LMFIT | 37,808,773 | <p>I am trying to fit a model using LMFIT, I can easily do the following:</p>
<pre><code>def loss_function(params):
residuals = []
for x, measured in ...:
y = predict(x, params)
residuals.append(y - measured)
return residuals
params = Parameters()
params.add(...)
model = Minimizer(loss_function, para... | 0 | 2016-06-14T09:57:10Z | 37,825,081 | <p>What is the nature of "totally unreliable"? You would probably want the uncertainties in the data to be strictly positive -- using <code>measured* 0.2</code> could allow negative values or zeros. Note that if there are NaNs or Infs in the residual, the fit will not work well, and almost certainly leave the parame... | 0 | 2016-06-15T02:24:15Z | [
"python",
"curve-fitting",
"model-fitting",
"lmfit",
"function-fitting"
] |
MQTT pub/sub communication format | 37,808,789 | <p>I want to use MQTT protocol for communication using gsm module and raspberry-pi/beaglebone . As gsm provide tcp connection via AT commands. Can someone tell me what is the format for publishing to a mqtt broker?</p>
<p>I am using a beaglebone with a gsm module for tcp connection. I have connected different sensors ... | 0 | 2016-06-14T09:57:42Z | 38,011,070 | <p>If you have Beaglebone why to worry about MQTT implementation. Connect you BB to internet using PPP Dialer/Wvdial. Use <a href="https://eclipse.org/paho/clients/python/" rel="nofollow">Paho Python Client</a> and develop an application to publish your sensor data to cloud.</p>
| 0 | 2016-06-24T10:20:45Z | [
"python",
"raspberry-pi",
"mqtt",
"beagleboneblack"
] |
Constrained MLE with Python | 37,808,793 | <p>I'm doing a MLE implementation with Python. My log-likelihood function has 5 parameters to be estimated and two of them has the constraint that they must be between 0 and 1. I'm able to implement a MLE using GenericLikelihoodModel module from the statsmodels package but I don't know how to do this with the constrain... | 1 | 2016-06-14T09:57:51Z | 37,809,483 | <p>IMHO this is a math question and the simple answer is that you should remodel your question.</p>
<p>To address the problem specifically - you should create a special case model derived from your original model with the constraints inherently defined in it. Then the calculated MLE for the special case model would gi... | 0 | 2016-06-14T10:31:01Z | [
"python",
"statsmodels",
"mle"
] |
Constrained MLE with Python | 37,808,793 | <p>I'm doing a MLE implementation with Python. My log-likelihood function has 5 parameters to be estimated and two of them has the constraint that they must be between 0 and 1. I'm able to implement a MLE using GenericLikelihoodModel module from the statsmodels package but I don't know how to do this with the constrain... | 1 | 2016-06-14T09:57:51Z | 37,812,829 | <p>One common approach to get an interior solution that satisfies the constraints is to transform the parameters so the optimization is unconstrained.</p>
<p>For example: A constraint to be in the open interval (0, 1) can be transformed using the Logit function, used for example here:</p>
<p><a href="https://github.c... | 1 | 2016-06-14T13:01:18Z | [
"python",
"statsmodels",
"mle"
] |
Constrained MLE with Python | 37,808,793 | <p>I'm doing a MLE implementation with Python. My log-likelihood function has 5 parameters to be estimated and two of them has the constraint that they must be between 0 and 1. I'm able to implement a MLE using GenericLikelihoodModel module from the statsmodels package but I don't know how to do this with the constrain... | 1 | 2016-06-14T09:57:51Z | 37,848,826 | <p>Indeed this is a math question rather than programming question. I managed to solve this question by transforming the parameters with constraints,i.e. alpha and sigma into alpha_hat and sigma_hat,</p>
<pre><code> alpha = 1/(1+np.exp(-alpha_hat))
sigma = 1/(1+np.exp(-sigma_hat))
</code></pre>
<p>so that we c... | 0 | 2016-06-16T02:18:47Z | [
"python",
"statsmodels",
"mle"
] |
Selecting a Face and Extruding a Cube in Blender Via Python API | 37,808,840 | <p>I am working on a project in which I will need to be able to extrude the faces of a cube via the python API.</p>
<p>I have managed to extrude a plane via the API:</p>
<pre><code>import bpy
bpy.data.objects['Cube'].select = True # Select the default Blender Cube
bpy.ops.object.delete() # Delete the selected object... | 1 | 2016-06-14T09:59:29Z | 38,815,068 | <p>I'm not too sure what you need here, but if you need this:</p>
<p><a href="http://i.stack.imgur.com/8jJVM.png" rel="nofollow"><img src="http://i.stack.imgur.com/8jJVM.png" alt=""></a></p>
<p>Then this is the code you need:</p>
<pre><code>import bpy
import bmesh
bpy.data.objects['Cube'].select = True # Select the... | 0 | 2016-08-07T14:22:08Z | [
"python",
"blender"
] |
Python 3.5 Youtube API search by keyword: SyntaxError in except block | 37,808,864 | <p>I'm trying to get data with YouTube API with the following code that Youtube releases. I also added my personal API key and the parentheses at <code>print</code>, but the code doesn't work. When I try to run it in PyCharm, I get:</p>
<pre><code>except HttpError, e:
^
SyntaxError: invalid syntax
... | 0 | 2016-06-14T10:00:39Z | 37,809,040 | <p>The original code was written for python 2 and while you converted <code>print</code> to a function (which is necessary for python 3) you forgot to convert the <code>except</code> block:</p>
<p><code>except HttpError as e:</code> is the python 3 way of doing exceptions but you could also use <code>except e:</code> ... | 0 | 2016-06-14T10:09:41Z | [
"python",
"python-3.x",
"youtube-api"
] |
Proper way to dynamically import a module with relative imports? | 37,808,866 | <p>I need to dynamically import modules into my project from another package.</p>
<p>The structure is like:</p>
<pre><code>project_folder/
project/
__init__.py
__main__.py
plugins/
__init__.py
plugin1/
__init__.py
...
plugin2/
__init_... | 0 | 2016-06-14T10:00:39Z | 37,809,762 | <p>I had a similar problem not long ago. I added the path of the project folder to the sys.path using the module's absolute path like this:</p>
<pre><code>import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__))+'/..')
</code></pre>
<p>This adds the project_folder to the sys.path thus allowing... | 0 | 2016-06-14T10:44:15Z | [
"python",
"dynamic",
"import"
] |
Proper way to dynamically import a module with relative imports? | 37,808,866 | <p>I need to dynamically import modules into my project from another package.</p>
<p>The structure is like:</p>
<pre><code>project_folder/
project/
__init__.py
__main__.py
plugins/
__init__.py
plugin1/
__init__.py
...
plugin2/
__init_... | 0 | 2016-06-14T10:00:39Z | 37,925,775 | <p>I managed to solve my own issue after a LOT of googling. Turns out I needed to import using relative paths:</p>
<pre><code>>>> from importlib import import_module
>>> config = import_module("plugins.config")
>>> config
<module 'plugins.config' from '/path/to/plugins/config/__init__.py'... | 0 | 2016-06-20T15:01:57Z | [
"python",
"dynamic",
"import"
] |
Prevent ipython from storing outputs in Out variable | 37,808,904 | <p>I'm currently working with pandas and ipython. Since pandas dataframes are copied when you perform operations with it, my memory usage increases by 500 mb with every cell. I believe it's because the data gets stored in the <code>Out</code> variable, since this doesn't happen with the default python interpreter.</p>
... | 1 | 2016-06-14T10:02:28Z | 37,810,971 | <p>The first option you have is to avoid producing output. If you don't really need to <em>see</em> the intermediate results just avoid them and put all the computations in a single cell.</p>
<p>If you need to actually display that data you can use <code>InteractiveShell.cache_size</code> option to set a maximum size ... | 3 | 2016-06-14T11:40:11Z | [
"python",
"pandas",
"ipython"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,050 | <pre><code>mylist = ['foo','foo','foo','bar','bar','hello']
last = None
for item in mylist:
if item is last:
continue
last = item
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>This assumes that the list is ordered so that identical objects ... | 1 | 2016-06-14T10:09:58Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,089 | <p>You can use collections.Counter for your job:</p>
<pre><code>>>> from collections import Counter
>>> Counter(['foo', 'foo', 'bar'])
Counter({'foo': 2, 'bar': 1})
</code></pre>
<p>Thus,</p>
<pre><code>count_dict = Counter(mylist)
for item in count_dict:
print("You "+item+" are present in "+st... | 3 | 2016-06-14T10:11:49Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,097 | <p>You could use a <code>Counter</code>:</p>
<pre><code>from collections import Counter
mylist = ['foo','foo','foo','bar','bar','hello']
c = Counter(mylist)
for item, cp in c.items():
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
| 5 | 2016-06-14T10:12:10Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,107 | <p>You can get the unique elements of a list using <a href="https://docs.python.org/3/tutorial/datastructures.html" rel="nofollow"><code>set</code></a></p>
<pre><code>mylist = ['foo','foo','foo','bar','bar','hello']
uniq_list = set(my_list)
for item in uniq_list:
cp = mylist.count(item)
print("You "+item+" are... | 2 | 2016-06-14T10:12:43Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,112 | <p>You can also do it this way</p>
<pre><code>mylist = ['foo','foo','foo','bar','bar','hello']
prev = None
for item in mylist:
if item != prev:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
prev = item
</code></pre>
<p>hope it may help !</p>
| 2 | 2016-06-14T10:13:06Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,210 | <p><a href="https://docs.python.org/2/library/sets.html" rel="nofollow">set</a> and <a href="http://www.tutorialspoint.com/python/list_count.htm" rel="nofollow">list counts</a> would do the trick:</p>
<pre><code>mylist = ['foo','foo','foo','bar','bar','hello']
for item in set(mylist):
print("You "+item+" are prese... | 1 | 2016-06-14T10:17:09Z | [
"python",
"for-loop",
"continue"
] |
Skip variable number of iterations in Python for loop | 37,808,990 | <p>I have a list and a for loop such as these: </p>
<pre><code>mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
cp = mylist.count(item)
print("You "+item+" are present in "+str(cp)+" copy(ies)")
</code></pre>
<p>Output:</p>
<pre><code>You foo are present in 3 copy(ies)
You foo are present ... | 2 | 2016-06-14T10:07:13Z | 37,809,462 | <p>Since the elements are consecutive, you could use a <code>groupby</code> which would group the consecutive strings, it is just a matter of summing the length of each group to get the count:</p>
<pre><code>from itertools import groupby
mylist = ['foo','foo','foo','bar','bar','hello']
for k,v in groupby(mylist):
... | 2 | 2016-06-14T10:30:04Z | [
"python",
"for-loop",
"continue"
] |
Converting embedded JSON into flat table - increasing efficiency | 37,809,006 | <p>I am new Python user, who decided to use Python to create simple application that allows for converting json files into flat table and saving the output in cvs format. I was wondering if you could give me some advice how I could improve my code to make it work in more efficient way. I am asking since if I convert re... | 0 | 2016-06-14T10:08:07Z | 37,815,368 | <p>@machine-yearning is right. Try to avoid the nesting--that gets ugly quickly.</p>
<p>Here is my stab at trying to help you along:</p>
<pre><code>import json
import csv
def get_ids(data):
ids = []
for datum in data:
id = datum["_id"]["id"]
ids.append(id)
return ids
def get_devices(dat... | 0 | 2016-06-14T14:49:46Z | [
"python",
"json",
"csv"
] |
how to remove specific character in numpy? | 37,809,049 | <p>I have the variable that get data from numpy for example</p>
<pre><code>dataInput = pd.io.parsers.read_csv(url, sep=',')
dataList['date'] = np.array(dataInput['Date'])
</code></pre>
<p>and my dataList['date'] format is '06/14/2016'
but i have some function that will use the format 06142016 </p>
<p>I try to use s... | 0 | 2016-06-14T10:09:58Z | 37,809,230 | <p>You could try to convert it to a string first and then call replace</p>
<pre><code>my_string_date = str(date).replace('/', '')
</code></pre>
| 1 | 2016-06-14T10:18:06Z | [
"python",
"numpy"
] |
Call to MySQL cursor.execute() (Python driver) hangs | 37,809,163 | <p>I'm using a python driver (mysql.connector) and do the following:</p>
<p><code>_db_config = {
'user': 'root',
'password': '1111111',
'host': '10.20.30.40',
'database': 'ddb'
}</code></p>
<ul>
<li><code>_connection = mysql.connector.connect(**_db_config) # connect to a remote server</code></li>
<li><code>_c... | 1 | 2016-06-14T10:15:07Z | 37,809,458 | <p>The result might hang due to large databases or not optimized queries.
you can try following things</p>
<ul>
<li>optimize your query</li>
<li>use a better connector driver
I generally use python3.x and for this I either use "pymysql" or "pypyodbc"
which are new and optimized drivers</li>
</ul>
<p>here is a post to... | 0 | 2016-06-14T10:29:57Z | [
"python",
"mysql"
] |
Call to MySQL cursor.execute() (Python driver) hangs | 37,809,163 | <p>I'm using a python driver (mysql.connector) and do the following:</p>
<p><code>_db_config = {
'user': 'root',
'password': '1111111',
'host': '10.20.30.40',
'database': 'ddb'
}</code></p>
<ul>
<li><code>_connection = mysql.connector.connect(**_db_config) # connect to a remote server</code></li>
<li><code>_c... | 1 | 2016-06-14T10:15:07Z | 37,839,311 | <p>Moving to MySQLdb (instead of mysql.connector) solved all the issues :-)</p>
| -1 | 2016-06-15T15:10:34Z | [
"python",
"mysql"
] |
How to make curl post request from python | 37,809,233 | <p>I am trying to make a post request using curl in python but the below script throws error</p>
<pre><code>import os
first_name1 = "raj"
last_name1 = "kiran"
full_name = "raj kiran"
headline = "astd"
location1 = "USA"
current_company1 = "ss"
curl_req = 'curl -X POST -H "Content-Type: application/json" -d '{"first_n... | 0 | 2016-06-14T10:18:12Z | 37,809,284 | <p>The problem in your code is the quotes. Change it to:</p>
<pre><code>curl_req = '''curl -X POST -H "Content-Type: application/json" -d '{"first_name":"{0}","last_name":"{1}","current_company":"{2}","title":"{3}","campus":"","location":"{4}","display_name":"{5}","find_personal_email":"true"}' http://localhost:8090''... | 0 | 2016-06-14T10:21:32Z | [
"python",
"rest",
"post",
"curl"
] |
Accept optional input at runtime | 37,809,348 | <p>currently I am writing a robot operating system (ros) node in python. I want to create a while loop which accepts user input on the one hand but is able to continue if no user input is available. </p>
<p>The idea of the following snippet is, that this python-script offers always 'start' or 'stop'. Another node is l... | 0 | 2016-06-14T10:24:22Z | 37,812,585 | <p>In case you don't find a way to do this directly in Python, an easy solution would be to move the user input to another node:</p>
<ul>
<li>The first node (let's call it "user input node") looks basically like the code you posted, but publishes directly the value of <code>input</code> to a topic <code>/user_input</c... | 1 | 2016-06-14T12:52:02Z | [
"python",
"ros"
] |
Importing Selenium2Library | 37,809,377 | <p>Have got stuck importing Selenium2Library for Robotframework. </p>
<p>When trying to validate my installation of Selenium2Library I get the following error in the Python shell</p>
<pre><code>>>> import Selenium2Library
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>... | 0 | 2016-06-14T10:25:40Z | 37,817,837 | <p>As of now, Selenium2Library is not compatible with Python 3.5. Please use Python 2.7 instead.</p>
<p><a href="https://github.com/robotframework/Selenium2Library/issues/479" rel="nofollow">Issue for adding Python 3 support</a></p>
| 0 | 2016-06-14T16:47:35Z | [
"python",
"django",
"robotframework",
"selenium2library"
] |
Importing Selenium2Library | 37,809,377 | <p>Have got stuck importing Selenium2Library for Robotframework. </p>
<p>When trying to validate my installation of Selenium2Library I get the following error in the Python shell</p>
<pre><code>>>> import Selenium2Library
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>... | 0 | 2016-06-14T10:25:40Z | 37,820,305 | <p>There is a pre-release package, which works fine with Python 3.4, <a href="https://github.com/HelioGuilherme66/robotframework-selenium2library/releases/" rel="nofollow">here</a> that you may install with:</p>
<pre><code>pip install --pre -U https://github.com/HelioGuilherme66/robotframework-selenium2library/archive... | 1 | 2016-06-14T19:12:11Z | [
"python",
"django",
"robotframework",
"selenium2library"
] |
Django 1 wrong migration messing up data model | 37,809,400 | <p>strange problem here that I replicated twice on my system this morning. Working with django 1.9.2. </p>
<p>Very simply, I made changes to a model, I changed this:</p>
<pre><code>class Sighting(models.Model):
caption = models.CharField(max_length=100,default=None)
subspecies = models.ForeignKey(Su... | 0 | 2016-06-14T10:26:33Z | 37,809,572 | <p>In django, migrations that have not run previously, run in the order of the migration number, as displayed in the migration file name. When you try adding a new field without a <code>null=True</code>, the database throws an error as it expects some value for that column, for the existing rows. </p>
<p>Now since you... | 1 | 2016-06-14T10:35:44Z | [
"python",
"django",
"database",
"datamodel"
] |
Django 1 wrong migration messing up data model | 37,809,400 | <p>strange problem here that I replicated twice on my system this morning. Working with django 1.9.2. </p>
<p>Very simply, I made changes to a model, I changed this:</p>
<pre><code>class Sighting(models.Model):
caption = models.CharField(max_length=100,default=None)
subspecies = models.ForeignKey(Su... | 0 | 2016-06-14T10:26:33Z | 37,809,639 | <p>It seems like you had previously created a model something like </p>
<pre><code>subspecies = models.ForeignKey(Subspecies, blank=False)
</code></pre>
<p>or</p>
<pre><code>subspecies = models.ForeignKey(Subspecies, unique = True)
</code></pre>
<p>and then removed it, which caused conflicts in your database schema... | 0 | 2016-06-14T10:38:34Z | [
"python",
"django",
"database",
"datamodel"
] |
extract strings between two strings in python using regular expression | 37,809,448 | <blockquote>
<p>"<>THIS is the place to stay at when visiting the historical area of
Seattle.</p>
<p>Your right on the water front near the ferry's and great sea food
hotel.</p>
<p>The breakfast was great. <>"</p>
</blockquote>
<p>Above is my sample text. I want to print the strings fall in betw... | 1 | 2016-06-14T10:29:20Z | 37,809,545 | <p>Use <code>.replace("\n", "")</code> on each found match (use comprehension) to replace any newline with an empty string.</p>
<p>See the <a href="https://ideone.com/2i5Rl8" rel="nofollow">demo</a>:</p>
<pre><code>results = [x.replace("\n", "") for x in pattern.findall(text)]
# => ["THIS is the place to stay at w... | 4 | 2016-06-14T10:34:13Z | [
"python",
"regex",
"string"
] |
extract strings between two strings in python using regular expression | 37,809,448 | <blockquote>
<p>"<>THIS is the place to stay at when visiting the historical area of
Seattle.</p>
<p>Your right on the water front near the ferry's and great sea food
hotel.</p>
<p>The breakfast was great. <>"</p>
</blockquote>
<p>Above is my sample text. I want to print the strings fall in betw... | 1 | 2016-06-14T10:29:20Z | 37,809,561 | <p>just replace those characters you don't want</p>
<p>e.g.</p>
<pre><code>result_without_newline = str(result).replace('\n', '')
</code></pre>
<p>hope this helps :)</p>
| 2 | 2016-06-14T10:35:03Z | [
"python",
"regex",
"string"
] |
How can I pass a variable of type datetime from Pig to python UDF | 37,809,696 | <p>My python UDF code, born is a datetime variable from Pig ,
I tried it as string object but it also gave an error,
and treating it as a datetime object also gave an error</p>
<pre><code>from datetime import date
@outputSchema("age_key:chararray")
def agekeyed(born):
today = date.today()
return born[:4]
</co... | 0 | 2016-06-14T10:40:55Z | 37,813,226 | <p><code>born</code> is a <code>org.joda.time.DateTime</code> object, and substring cannot be applied here.
You need to pass a <code>chararray</code> from pig to the udf, or deal with the object with it's methods</p>
<pre><code>rightnow.monthOfYear().getAsText()
</code></pre>
| 0 | 2016-06-14T13:17:47Z | [
"python",
"datetime",
"apache-pig",
"udf"
] |
Remove white border when using subplot and imshow in python (Matplotlib) | 37,809,697 | <pre><code>import numpy as np
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
</code></pre>
<p>i use the following code to save an image</p>
<pre><code>fig, ax = plt.subplots(frameon=False)
ax.axis ('off')
ax.imshow (array[:,:,0,0,0])
fig.savefig ("file.pn... | 2 | 2016-06-14T10:41:03Z | 37,810,568 | <p>Look at my example it may help you:</p>
<pre><code>import numpy as np
import matplotlib.pylab as plt
def save_image(data, filename):
sizes = np.shape(data)
fig = plt.figure()
fig.set_size_inches(1. * sizes[0] / sizes[1], 1, forward = False)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_... | 2 | 2016-06-14T11:21:12Z | [
"python",
"matplotlib",
"figure",
"imshow"
] |
Remove white border when using subplot and imshow in python (Matplotlib) | 37,809,697 | <pre><code>import numpy as np
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
</code></pre>
<p>i use the following code to save an image</p>
<pre><code>fig, ax = plt.subplots(frameon=False)
ax.axis ('off')
ax.imshow (array[:,:,0,0,0])
fig.savefig ("file.pn... | 2 | 2016-06-14T10:41:03Z | 37,812,313 | <p>Little modification to above answer:</p>
<pre><code>def save_image(data, filename):
sizes = np.shape(data)
fig = plt.figure(figsize=(1,1))
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(data, cmap = plt.get_cmap("bone"))
plt.savefig(filename, dpi = sizes[0])
... | 1 | 2016-06-14T12:40:00Z | [
"python",
"matplotlib",
"figure",
"imshow"
] |
Django inheritance: I'm trying to add a new child but instead modifies the existing one | 37,809,764 | <p>I have 3 models that inherit from an abstract model:</p>
<pre><code>class ParentModel(models.Model):
field_pk = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID', default=0)
fieldone = CharField()
fieldtwo = CharField()
class Meta:
abstract = True
...... | 0 | 2016-06-14T10:44:20Z | 37,810,784 | <p>I guess that: as you defined a primary key with default '0', this value is picked when you edit your models in the admin page. The same primary key will save to the same entry. You should probably leave the <code>default</code> option out, and leave django/ your database to generate an id</p>
| 0 | 2016-06-14T11:31:38Z | [
"python",
"django",
"django-admin"
] |
matplotlib (python) - create single custom legend for multiple plots WITHOUT pyplot | 37,809,836 | <p>I would like to create a custom legend for multiple plots in matplotlib (python) in a pyqt GUI. (pyqt advises against using pyplot so the object-oriented method has to be used).</p>
<p>Multiple plots will be appear in a grid but the user can define how many plots to appear. I would like the legend to appear on the ... | 0 | 2016-06-14T10:47:24Z | 37,810,229 | <p>the error you are getting is because <a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.legend" rel="nofollow"><code>Figure.legend</code></a> requires you to pass it both the <code>handles</code> and the <code>labels</code>. </p>
<p>From the docs:</p>
<blockquote>
<p>legend(handles, labe... | 0 | 2016-06-14T11:05:21Z | [
"python",
"matplotlib",
"pyqt",
"legend"
] |
regex: consecutive match failure | 37,809,858 | <p>Using the regular expression</p>
<pre><code>[^a-zA-Z]([A-Z][&+-\/\\][A-Z](([&+-\/\\][A-Z])+[^a-zA-Z\d:]))
</code></pre>
<p>and wanting to match letters delineated by symbols, the expression achieves successful matches, but fails to properly match patterns that immediately follow correct matches. Note that ... | 1 | 2016-06-14T10:48:40Z | 37,810,595 | <p>You can use</p>
<pre><code>\b[a-zA-Z](?:[./][A-Za-z])*\b
</code></pre>
<p>See the <a href="https://www.regex101.com/r/aQ0sU0/1" rel="nofollow">regex demo</a></p>
<p>If you do not need to match whole words, remove <code>\b</code> (word boundary).</p>
<p><strong>Explanation</strong>:</p>
<ul>
<li><code>\b</code> ... | 1 | 2016-06-14T11:22:27Z | [
"python",
"regex"
] |
stdout pymssql to variable | 37,809,872 | <p>Im trying to retrieve the result form running</p>
<pre><code>import pymssql
conn = pymssql.connect(server='IP', user='domain\user', password='PSWD', tds_version='8.0')
cursor = conn.cursor()
cursor.execute("EXEC msdb.dbo.sp_start_job @job_name = 'jobname'")
</code></pre>
<p>when it add the job to the cue to proces... | 0 | 2016-06-14T10:49:34Z | 37,841,558 | <p>You are seeing the traceback because you are not handling the exception that occurs when the job name does not exist. If you want to capture the error message you can simply catch the exception. As a general-purpose example, instead of just doing</p>
<pre class="lang-python prettyprint-override"><code>crsr.execut... | 2 | 2016-06-15T17:02:51Z | [
"python",
"linux",
"execute",
"pymssql"
] |
How to pip install tensorflow on El Capitan? | 37,810,228 | <p>It appears that El Capitan's system integrity protection is preventing me from following the instructions for getting Tensorflow running on OSX.</p>
<p>I've followed <a href="https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#pip-installation" rel="nofollow">the installation guide</a> but the final ... | 4 | 2016-06-14T11:05:21Z | 37,810,321 | <p>I managed to get it working by using easy_install to upgrade numpy. This seems like a nasty mess so I'd love to either hear a better solution, or have someone explain to me why this is fine.</p>
<p>The command, for those playing along:</p>
<pre><code>sudo easy_install numpy
</code></pre>
| 2 | 2016-06-14T11:10:41Z | [
"python",
"tensorflow",
"osx-elcapitan"
] |
How to scrape geographic coordinates from dynamic map? | 37,810,242 | <p>A dynamic Google map is embedded on a web page, with a drag-gable marker. This gives the location when the marker is dropped. I am trying to scrape the latitude and longitude using python. I have tried the following code:</p>
<pre><code>import urllib
import re
url = urllib.urlopen("file:///C:/Users/Test.html").read... | 0 | 2016-06-14T11:06:02Z | 37,811,989 | <p>you need to get the groups (captured with '(..)' in your regex) from your result:</p>
<pre><code>lat = results.groups(1)
long = results.groups(2)
</code></pre>
| 1 | 2016-06-14T12:26:22Z | [
"python",
"html",
"google-maps",
"web-scraping"
] |
Make a dot-plot in python | 37,810,252 | <p>I'm trying to make a dot plot of two datasets. To simplify those two datasets, I'll put some letters</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
x = np.array([['a',1],['b',3],['c',4],['d',5],['e',6],['f',3]])
y = np.array([['c',3],['e',2],['b',6],['a',5],['h',5],['f',2]])
#in reality, those ... | 0 | 2016-06-14T11:06:31Z | 37,814,994 | <p>I would use a nested for loop here, to iterate over the two datasets, and calculate the '(b1+b2)/abs(b1-b2)' parameter if the condition (b in first dataset and b in second dataset) holds. You can then fill a 2d list with the respective values and use matplotlib.pyplot.imshow() to generate a heatmap.</p>
<p>Some pse... | -1 | 2016-06-14T14:33:28Z | [
"python",
"arrays",
"matplotlib",
"plot"
] |
Component wise comparision of float values in Numpy is returning wrong result | 37,810,294 | <p>I am getting wrong results when I do an element wise comparison on a numpy array of floats.</p>
<p>For eg:</p>
<pre><code>import numpy as np
a = np.arange(4, 5 + 0.025, 0.025)
print a
mask = a==5.0
print mask
na = a[mask]
print na
</code></pre>
<p>When I run the above code, a == 5.0 doesn't give me a True value... | 2 | 2016-06-14T11:08:51Z | 37,810,396 | <p>There is an imprecision here when using float types, use <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.isclose.html" rel="nofollow"><code>np.isclose</code></a> to compare an array against a scalar float value:</p>
<pre><code>In [50]:
mask = np.isclose(a,5.0)
print(mask)
na = a[mask]
na
... | 1 | 2016-06-14T11:13:55Z | [
"python",
"arrays",
"numpy"
] |
Python character encoding returns incorrect value | 37,810,368 | <p>I'm using Python 2.7.11 , I get a wrong value when getting decimal value of a character from extended ascii table</p>
<pre><code># -*- coding: utf-8 -*-
str="è"
print(ord(str[0])) #prints 232 decimal
</code></pre>
<p>but the value of this char is 138 decimal
(<a href="http://www.asciitable.com/" rel="nofollow">ht... | 1 | 2016-06-14T11:12:36Z | 37,810,476 | <p>UTF-8 is not extended asci. If you check the UTF-8 table <a href="http://www.utf8-chartable.de/" rel="nofollow">here</a>, you will see that 232 is indeed the correct ordinal.</p>
<p>Also, I recommend Joel on software's <a href="http://www.joelonsoftware.com/articles/Unicode.html" rel="nofollow">UTF-8 article</a></p... | 3 | 2016-06-14T11:17:35Z | [
"python",
"encoding"
] |
Python character encoding returns incorrect value | 37,810,368 | <p>I'm using Python 2.7.11 , I get a wrong value when getting decimal value of a character from extended ascii table</p>
<pre><code># -*- coding: utf-8 -*-
str="è"
print(ord(str[0])) #prints 232 decimal
</code></pre>
<p>but the value of this char is 138 decimal
(<a href="http://www.asciitable.com/" rel="nofollow">ht... | 1 | 2016-06-14T11:12:36Z | 37,810,529 | <p>The character <code>è</code> referes in the unicode/utf-8 encoding to <code>0x00E8</code> which means <code>232</code>.</p>
<p><a href="http://unicode-table.com/de/#00E8" rel="nofollow">See this reference</a></p>
<p>The character is contained in the extended ASCII see <a href="http://stackoverflow.com/questions/2... | 0 | 2016-06-14T11:19:39Z | [
"python",
"encoding"
] |
Python socket.recv evaluation | 37,810,374 | <p>I am writing a small python script in order to use it for checking haproxy. What the script does is to connect on haproxy socket and "poll" for stats.</p>
<pre><code>#!/usr/bin/env python
import socket
import sys
my_socket = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM )
try:
my_socket.connect( "/var/run/... | 0 | 2016-06-14T11:13:02Z | 37,811,490 | <p>By default the socket will be in blocking mode and <code>recv()</code> will block until data is received or the connection is closed.</p>
<p>If you can assume that the proxy will respond within a certain amount of time you can set a timeout on the client socket. The timeout is the number of seconds to wait for a so... | 0 | 2016-06-14T12:03:53Z | [
"python",
"sockets"
] |
Can't create azure storage container with python | 37,810,438 | <p>I followed the azure tutorial in order to upload photos in an azure account storage : <a href="https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/" rel="nofollow">https://azure.microsoft.com/en-us/documentation/articles/storage-python-how-to-use-blob-storage/</a></p>
<p>... | 0 | 2016-06-14T11:15:33Z | 37,813,265 | <p>The error is related to your account key being incorrect. The Azure storage key is base64-encoded. The string you provided (<code>"account_key"</code>) is not properly base64-encoded, hence the <code>Incorrect padding</code> error. Try running this again with the full account key (either primary or secondary) provid... | 1 | 2016-06-14T13:19:08Z | [
"python",
"azure",
"windows-azure-storage",
"azure-storage-blobs"
] |
Why doesn't NLTK wn.all_synsets() function in wordnet return a list of synsets? | 37,810,469 | <p>I code for the question:</p>
<blockquote>
<p>What percentage of noun synsets have no hyponyms? You can get all noun synsets using wn.all_synsets('n').</p>
</blockquote>
<p>Here is my code:</p>
<pre><code>import nltk
from nltk.corpus import wordnet as wn
all_noun = wn.all_synsets('n')
print(all_noun)
print(wn.a... | 2 | 2016-06-14T11:17:23Z | 37,811,574 | <p>It has little to do with NLTK but more of the difference between <a href="http://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehension">Generator Expressions vs. List Comprehension</a>. </p>
<p>Let's go through a small example:</p>
<p>First, let's create a function that returns a simple lis... | 2 | 2016-06-14T12:07:22Z | [
"python",
"nlp",
"generator",
"nltk",
"wordnet"
] |
Install numpy for python 2.7 and not 3.4 | 37,810,671 | <p>I have been literally struggling to install numpy for python 2.7 and not 3.4 both of which are on my ubuntu. I have tried:</p>
<p>sudo pip2 install numpy</p>
<p>but it says </p>
<pre><code>Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
</code></pre>
<p>but whe... | 0 | 2016-06-14T11:26:07Z | 37,811,974 | <p>First, do <code>pip uninstall numpy</code> and <code>pip2 uninstall numpy</code> just to clean up any old files.</p>
<p>Then, since you are on Ubuntu, you should just run</p>
<pre><code>sudo apt-get install python-numpy
</code></pre>
<p>This will install numpy for python2. If you later choose you want it for pyth... | 0 | 2016-06-14T12:25:29Z | [
"python",
"python-2.7",
"numpy"
] |
ComputeBandStats extremely slow | 37,810,687 | <p>When I try to use ComputeBandStats it takes extremely long time to finish. Is there any way to speed up the process?</p>
<p>Here is my code:</p>
<pre><code>inIMG = gdal.Open(infile)
bandas = [inIMG.GetRasterBand(b+1) for b in range(3)]
print('hej1')
meanSD = [b.ComputeBandStats(1) for b in bandas]
print('hej2')
</... | 1 | 2016-06-14T11:26:41Z | 37,917,191 | <p>I found out that ComputeStatistics is much faster than ComputeBandStats, so I'm using it instead. I don't know exactly what the difference is, but aside from the speed advantage, ComputeStatistics also ignores no-data values, which turned out to be a problem for ComputeBandStats. It also calculates min, max, mean an... | 0 | 2016-06-20T07:53:50Z | [
"python",
"python-2.7",
"python-3.x",
"gdal"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.