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 |
|---|---|---|---|---|---|---|---|---|---|
Salt times out when using external authentication (PAM) | 37,667,046 | <p>I'm trying to use <strong>Salt (2015.8.10 Beryllium)</strong> with "external_auth" via PAM. My ultimate goal is to use salt-api to authenticate a request from a salt-minion which will allow that minion to call for it's own key to be accepted. As a first step, it's suggested that you first get authentication workin... | 0 | 2016-06-06T21:18:51Z | 37,690,126 | <p>At this time Salt's "external_auth" pam implementation is tied directly to the Linux pam binaries and will only work on Linux. So that means no Solaris, unfortunately.</p>
| 1 | 2016-06-07T21:59:09Z | [
"python",
"authentication",
"salt-stack",
"pam"
] |
Performing regex extraction with apply() on pandas dataframe column uses result of first row for all rows | 37,667,135 | <p>I have a column of time zone strings in a <code>Pandas DateFrame</code> where each string entry is a variation on the following:</p>
<pre><code>'Local Time Zone (America/Chicago (CST) offset -21600)'
</code></pre>
<p>I am trying to extract the numeric offset (listed in seconds) at the end of the string with an <co... | -1 | 2016-06-06T21:26:40Z | 37,667,732 | <p>I would do it this way:</p>
<pre><code>In [85]: In [82]: df
Out[85]:
id timezone
0 1 Local Time Zone (America/Chicago (CST) offset -21600)
1 2 Local Time Zone (Kiev/Ukraine (EEST) offset +10800)
In [86]: df['minuteOffset'] = df.timezone.str.replace(r'.*offse... | 0 | 2016-06-06T22:21:45Z | [
"python",
"regex",
"dataframe"
] |
Twilio django send SMS and get answer using SMS as parameter | 37,667,238 | <p>In the twilio <a href="https://www.twilio.com/docs/tutorials/walkthrough/employee-directory/python/flask#1" rel="nofollow">example made in flask</a>, I can send an SMS and receive an answer using text and the SMS as the search parameter in the database. I need make this but in a django project, my first option that... | 0 | 2016-06-06T21:34:31Z | 37,668,495 | <p>Use <code>request.POST</code> to access the <code>form data</code>:</p>
<pre><code>from django.shortcuts import render
def my_view(request):
if request.method == "POST":
data = request.POST
# all posted data
data['body']
# the rest of your view logic
return render(request, 'te... | 1 | 2016-06-06T23:50:44Z | [
"python",
"django",
"django-rest-framework",
"twilio"
] |
running median excluding zeros | 37,667,250 | <p>I borrowed some code to calculate the running median of an array. But for each running array, I want to exclude the zero values. Below is the code:</p>
<pre><code>def RunningMedian(seq, M):
seq = iter(seq)
s = []
m = M // 2
# Set up list s (to be sorted) and load deque with first window of seq
... | 0 | 2016-06-06T21:35:30Z | 37,667,880 | <p>try:</p>
<pre><code>[s[s!=0] for s in np.dstack((a[:-2], a[1:-1], a[2:]))[0]]
</code></pre>
| 0 | 2016-06-06T22:36:15Z | [
"python",
"numpy",
"median"
] |
running median excluding zeros | 37,667,250 | <p>I borrowed some code to calculate the running median of an array. But for each running array, I want to exclude the zero values. Below is the code:</p>
<pre><code>def RunningMedian(seq, M):
seq = iter(seq)
s = []
m = M // 2
# Set up list s (to be sorted) and load deque with first window of seq
... | 0 | 2016-06-06T21:35:30Z | 37,667,894 | <p>The main issue with your code is that throwing away zeros in <code>s</code> messes with the length of the objects used, which explains why you didn't get 3-length windows at the end.</p>
<p>I suggest another approach: using a proper function for <code>median</code> and ignoring those zero values locally. This way i... | 2 | 2016-06-06T22:37:01Z | [
"python",
"numpy",
"median"
] |
Writing tuple output to a text file | 37,667,267 | <p>Is it possible to write my output tuple to a text file? I am using following code to get text between two strings as write them to a text file:</p>
<pre><code>def format_file(file, start, end):
f = open('C:\TEMP\Test.txt', 'r').read()
return tuple(x for x in ''.join(f.split(start)).replace('\n', '').split(e... | 0 | 2016-06-06T21:36:30Z | 37,667,321 | <p>Did your try converting your tuple into a string and writing to the file?</p>
<pre><code> s = str('XYZ', 'Q2 2016 Apple Inc Earnings Call - Final', 'Event Brief of Q1 2016 Apple Inc Earnings Call - Final')
file.write(s)
</code></pre>
| 0 | 2016-06-06T21:41:44Z | [
"python",
"text"
] |
Modifying a dict during iteration | 37,667,277 | <p>What's going on below</p>
<pre><code>>>> d = {0:0}
>>> for i in d:
... del d[i]
... d[i+1] = 0
... print(i)
...
0
1
2
3
4
5
6
7
>>>
</code></pre>
<p>Why does the iteration stop at 8 without any error? </p>
<p>Reproducible on both python2.7 and python 3.5. </p>
| 8 | 2016-06-06T21:38:10Z | 37,667,331 | <p>The initial size of the key table in a dict is 8 elements. So <code>0</code>...<code>7</code> sets the 1st to 8th element and 8 sets the 1st element again, ending the loop.</p>
<h3><a href="https://github.com/python/cpython/blob/master/Objects/dictobject.c#L60" rel="nofollow">Source: Objects/dictobject.c</a></h3>
... | 7 | 2016-06-06T21:43:01Z | [
"python",
"dictionary"
] |
Modifying a dict during iteration | 37,667,277 | <p>What's going on below</p>
<pre><code>>>> d = {0:0}
>>> for i in d:
... del d[i]
... d[i+1] = 0
... print(i)
...
0
1
2
3
4
5
6
7
>>>
</code></pre>
<p>Why does the iteration stop at 8 without any error? </p>
<p>Reproducible on both python2.7 and python 3.5. </p>
| 8 | 2016-06-06T21:38:10Z | 37,668,817 | <p>This behavior originates from the key look up algorithm in cpython <code>static PyDictKeyEntry * lookdict(...)</code> as written in the <a href="https://github.com/python/cpython/blob/master/Objects/dictobject.c#L418" rel="nofollow">document</a>:</p>
<blockquote>
<p>The basic lookup function used by all operation... | 5 | 2016-06-07T00:37:11Z | [
"python",
"dictionary"
] |
Why is my if true/elif/else-code not working? | 37,667,305 | <p>In python, I am trying to make this code accept the user to move forward if he writes "True", and not if he writes "False" for the statement in User_Answer. When I run the code however, I get the "the answer is correct!"-part no matter what I write. The part I am having trouble with starts with "Test_Answer".</p>
<... | -1 | 2016-06-06T21:40:18Z | 37,667,330 | <p>True is a boolean constant. What the user enters will be either "True" or "False", both character strings. Also, your <strong>elif</strong> condition cannot be true. What are you trying to do with three decision branches?</p>
<p>Without changing your code too much ... try this?</p>
<pre><code>Test_Answer = "Tru... | 0 | 2016-06-06T21:42:55Z | [
"python",
"python-3.x",
"if-statement"
] |
HTML Extraction with Python | 37,667,318 | <p>The issue being tackled is being unable to click and go to the next page on an HTML page. An HTML page is being accessed which displays results after your search query. At the bottom of the page, there is a line of numbers to select from the page of your query i.e. "1 2 3 4 next" - clicking "2" shows you the results... | 0 | 2016-06-06T21:41:05Z | 37,667,424 | <p>You can use the method driver.<strong>find_element_by_link_text</strong>('next') to find the element and, then, call .click()</p>
| 0 | 2016-06-06T21:51:36Z | [
"python",
"html",
"python-2.7",
"selenium-webdriver",
"html-content-extraction"
] |
HTML Extraction with Python | 37,667,318 | <p>The issue being tackled is being unable to click and go to the next page on an HTML page. An HTML page is being accessed which displays results after your search query. At the bottom of the page, there is a line of numbers to select from the page of your query i.e. "1 2 3 4 next" - clicking "2" shows you the results... | 0 | 2016-06-06T21:41:05Z | 37,667,547 | <p>Alternatively you could add an ID to the next button and call:</p>
<p><code>driver.find_element_by_id('whatever_id_you_use').click()</code></p>
<p>or categorize the next arrow and the previous arrow by adding a class to differentiate the two and call:</p>
<p><code>driver.find_element_by_class_name('next_arrow').c... | 0 | 2016-06-06T22:02:31Z | [
"python",
"html",
"python-2.7",
"selenium-webdriver",
"html-content-extraction"
] |
Displaying Temperature from DHT11 in GUI - Automatic Refresh? | 37,667,389 | <p>Newbie to Python, started off messing with a DHT11 Temp/Humidity Sensor, a Raspberry Pi 3, and Python 3.</p>
<p>I am using the standard <a href="https://github.com/adafruit/Adafruit_Python_DHT" rel="nofollow">Adafruit DHT11 Library</a> for Python. </p>
<p>Reading from GPIO 27</p>
<p>I am able to display the tempe... | 1 | 2016-06-06T21:48:05Z | 37,681,471 | <p>Create the <code>Label</code> once at the start of the program, and save a reference:</p>
<pre><code>the_label = Label (win, text="", fg="black", bg="white", font="36")
the_label.grid(row=0, column=0)
</code></pre>
<p>Next, create a function that gets the value and updates the label:</p>
<pre><code>def READ():
... | 1 | 2016-06-07T13:57:23Z | [
"python",
"tkinter"
] |
Selenium Find Sub-Child href Element | 37,667,537 | <p>I'm trying to click the following link using selenium. </p>
<pre><code><div id="RECORD_2" class="search-results-item">
<a hasautosubmit="true" oncontextmenu="javascript:return IsAllowedRightClick(this);" class="smallV110" href="#;cacheurlFromRightClick=no"></a>
</div>
</code></pre>
<p... | -1 | 2016-06-06T22:01:42Z | 37,667,621 | <p>Note that this is not Selenium IDE and you don't need the <code>css=</code> at the beginning of a selector.</p>
<p>There are multiple ways to locate the link element, e.g.:</p>
<pre><code>driver.find_element_by_css_selector(".search-results-item a.smallV110")
driver.find_element_by_css_selector("[id^=RECORD] a.sma... | 1 | 2016-06-06T22:09:19Z | [
"python",
"html",
"selenium",
"web-scraping"
] |
wxpython 3.0 & multiprocessing - update GUI from background process | 37,667,606 | <p>From my wxpython GUI app I have an rsync task that I kick off as a multiprocessing.Process.</p>
<p>The idea is to update a wx.textCtrl with the constant output from this background process.</p>
<p>I am using a pubsub subscribe method. </p>
<p>The functions work fine but I can't get the textCtrl to update.</p>
<p... | 0 | 2016-06-06T22:08:16Z | 37,734,616 | <p>The problem is that the child process can't write back to the main process. Use a <a href="https://docs.python.org/2/library/multiprocessing.html#exchanging-objects-between-processes" rel="nofollow">queue</a> to pass messages back to the main process, and update the control from within a timer or a background thread... | 1 | 2016-06-09T19:27:27Z | [
"python",
"wxpython",
"multiprocessing",
"publish-subscribe"
] |
How can I make the background of an image appear transparent without PIL? | 37,667,631 | <p>I'm trying to make a GUI in tkinter that uses one image as an overlay on top of another, but when I place the image over the lower one, the transparent area of the image appears as grey.</p>
<p>I've searched for solutions to this, but all the results that I've found have pointed towards using PIL.</p>
<p>Is it pos... | 0 | 2016-06-06T22:10:21Z | 37,801,513 | <p>You could use some basic photoshop tools like the magic wand tool to remove the background, but keep in mind, some PNG format images have a faint background. This is either in the from of a watermark, or the image background was rendered with a lower opacity than the rest of the image. Your GUI may also have a layer... | 0 | 2016-06-14T01:18:06Z | [
"python",
"user-interface",
"tkinter",
"transparent"
] |
Group a List of Python Dictionaries | 37,667,632 | <p>I have some JSON data coming from the API as a list of dictionaries, such as:</p>
<pre><code>entities = [
{'name': 'McDonalds', 'city': 'New York', 'gross': 250000000, 'id': '000001'},
{'name': 'McDonalds', 'city': 'Philadelphia', 'gross': 190000000, 'id': '000002'},
{'name': 'Shake Shack', 'city': 'Los... | 3 | 2016-06-06T22:10:23Z | 37,667,708 | <p>This should work:</p>
<pre><code>def group_entities(entities):
entity_groups = {}
# Within each business's list, add separate dictionaries with details
for entity in entities:
name = entity['name'] # name is the key for entity_groups
del entity['name'] # remove it from each enti... | 1 | 2016-06-06T22:18:32Z | [
"python",
"list",
"dictionary"
] |
Group a List of Python Dictionaries | 37,667,632 | <p>I have some JSON data coming from the API as a list of dictionaries, such as:</p>
<pre><code>entities = [
{'name': 'McDonalds', 'city': 'New York', 'gross': 250000000, 'id': '000001'},
{'name': 'McDonalds', 'city': 'Philadelphia', 'gross': 190000000, 'id': '000002'},
{'name': 'Shake Shack', 'city': 'Los... | 3 | 2016-06-06T22:10:23Z | 37,667,731 | <pre><code>bycompany = {}
for ent in entities:
if not ent['name'] in bycompany:
# if there is no location list for this company name,
# then start a new list for this company.
bycompany[ent['name']] = []
# Add the dict to the list of locations for this company.
bycompany[ent['name']... | 1 | 2016-06-06T22:21:42Z | [
"python",
"list",
"dictionary"
] |
Group a List of Python Dictionaries | 37,667,632 | <p>I have some JSON data coming from the API as a list of dictionaries, such as:</p>
<pre><code>entities = [
{'name': 'McDonalds', 'city': 'New York', 'gross': 250000000, 'id': '000001'},
{'name': 'McDonalds', 'city': 'Philadelphia', 'gross': 190000000, 'id': '000002'},
{'name': 'Shake Shack', 'city': 'Los... | 3 | 2016-06-06T22:10:23Z | 37,667,937 | <p>If your data is ordered by name:</p>
<pre><code>from itertools import groupby
from operator import itemgetter
entities = [
{'name': 'McDonalds', 'city': 'New York', 'gross': 250000000, 'id': '000001'},
{'name': 'McDonalds', 'city': 'Philadelphia', 'gross': 190000000, 'id': '000002'},
{'name': 'Shake Sh... | 3 | 2016-06-06T22:43:15Z | [
"python",
"list",
"dictionary"
] |
Compare csv files rank order | 37,667,696 | <p>I am trying to compare the first 300 lines of one csv file to another. I am iterating through each line of the first file. Within that iteration I am iterating through the second file, counting each iteration, until I find a match. Then I am outputing the counting value (row of the matched line in the second file) i... | 0 | 2016-06-06T22:15:45Z | 37,668,524 | <p>Your primary problem is trying to iterate over the second file multiple times. In order to iterate over its entire contents more than once, you need to close and reopen it. You can also let Python count the line numbers automatically by using <code>enumerate()</code> and count the number of matches by storing them i... | 1 | 2016-06-06T23:54:50Z | [
"python",
"csv",
"order",
"rank"
] |
opencv cannot read MP4 file from sony camcorder | 37,667,745 | <p>The sony camcorder recorded video in MP4 format. I am reading the file by</p>
<pre><code>import cv2
vid = cv2.VideoCapture('sample.MP4')
</code></pre>
<p>my OpenCV version is 2.4.8, as a Python module.</p>
<p><strong>The codec of the 'sample.MP4' is H.264, Linear PCM.</strong></p>
<pre><code>ffprobe sample.MP4
<... | 1 | 2016-06-06T22:22:57Z | 37,688,280 | <p>The commands:</p>
<pre><code>avconv -i sample.MP4 -c:v copy sample_converted.mp4
</code></pre>
<p>and</p>
<pre><code>ffmpeg -i sample.MP4 -c:v copy sample_converted.mp4
</code></pre>
<p>both work, by converting the MP4 video file from Sony camcorder, to a MP4 file readable for OpenCV for further analysis. The vi... | 1 | 2016-06-07T20:01:27Z | [
"python",
"opencv",
"video",
"ffmpeg",
"mp4"
] |
Key mapping problems for 2 player game | 37,667,886 | <p>I'm making a 2-player maze runner game, and I have come to some trouble with keyboard events. If both players hit a key at the same time, only player 1 moves, because my code tests for player1's events first. Is there a way in python and pygame to check for both events simultaneously? Here's a part of my player1 cla... | 0 | 2016-06-06T22:36:39Z | 37,668,119 | <p>Keeping my comments above in mind, let's take a shot at a solution. First of all, I want to make your code a little more general, and perhaps easier on the eyes: use a look-up table for the move translation.</p>
<pre><code>move_translate = {
pygame.K_LEFT: (-1, 0),
pygame.K_RIGHT: (1, 0),
pygame.K_UP: ... | 0 | 2016-06-06T23:04:44Z | [
"python",
"events",
"keyboard",
"pygame"
] |
PyCharm "Frames are not Available"... How to add frames so I can view Variables in Debug? | 37,667,924 | <p>Sorry if this is pretty basic, but I can't seem to figure out how to enable/add Frames under the PyCharm Debugger so I can view Variable information, even after selecting a checkpoint. When I'm under the Debugger all I see is "Frame is not available"... I have searched for hours and tried enabling the "Python Except... | 0 | 2016-06-06T22:41:20Z | 37,684,800 | <p>Just run the code :)</p>
<p>If you'd like to debug a program, there are some ways to do it:</p>
<ol>
<li><code>Right-Click</code> on the tab with file name (<code>LASClipCPU_test.py</code> in your case) and select <code>Debug 'LASClipCPU_test'</code></li>
</ol>
<p>or</p>
<ol start="2">
<li>Go to <code>Run</code>... | 0 | 2016-06-07T16:39:04Z | [
"python",
"debugging",
"pycharm",
"jetbrains"
] |
Adding an element from a tuple within a list to another list | 37,667,986 | <p>I have a list of tuples and I am trying to take a specific element from one of the tuples inside the list and adding it to another, separate list.</p>
<p>So, I have:</p>
<pre><code>List=[("a", "\\"), ("o", "-"), ("e", "s")]
</code></pre>
<p>and I want to add the 'o' from the second tuple to another list.
I know y... | 0 | 2016-06-06T22:48:47Z | 37,668,004 | <p><code>List[1]</code> gives you the second element of the list <code>List</code> which is the tuple <code>("o", "-")</code>.</p>
<p>You want the first element of that tuple which you can access with <code>List[1][0]</code>.</p>
<pre><code>>>> List=[("a", "\\"), ("o", "-"), ("e", "s")]
>>> newList ... | 2 | 2016-06-06T22:51:13Z | [
"python",
"list",
"tuples"
] |
Adding an element from a tuple within a list to another list | 37,667,986 | <p>I have a list of tuples and I am trying to take a specific element from one of the tuples inside the list and adding it to another, separate list.</p>
<p>So, I have:</p>
<pre><code>List=[("a", "\\"), ("o", "-"), ("e", "s")]
</code></pre>
<p>and I want to add the 'o' from the second tuple to another list.
I know y... | 0 | 2016-06-06T22:48:47Z | 37,668,016 | <p>You can index tuples just like lists with brackets.</p>
<p>Generally best not to name variables like types, so let's do this instead:</p>
<pre><code>new_list = []
li=[("a", "\\"), ("o", "-"), ("e", "s")]
new_list.append(li[1][0])
print new_list
>> ["o"]
</code></pre>
| 1 | 2016-06-06T22:52:33Z | [
"python",
"list",
"tuples"
] |
Adding an element from a tuple within a list to another list | 37,667,986 | <p>I have a list of tuples and I am trying to take a specific element from one of the tuples inside the list and adding it to another, separate list.</p>
<p>So, I have:</p>
<pre><code>List=[("a", "\\"), ("o", "-"), ("e", "s")]
</code></pre>
<p>and I want to add the 'o' from the second tuple to another list.
I know y... | 0 | 2016-06-06T22:48:47Z | 37,668,140 | <p>Tuples can be accessed in much the same way as lists. In your case you have a list of 3 tuples. Their indexes are:</p>
<pre><code> 0 -> ("a", "\\")
1 -> ("o", "-")
2 -> ("e", "s")
</code></pre>
<p>The elements inside each of these tuples are also indexed:</p>
<p>i.e.
In the tuple ("o", "-") the inde... | 1 | 2016-06-06T23:07:05Z | [
"python",
"list",
"tuples"
] |
Ever-growing Bokeh's embed source files | 37,668,057 | <p>Bokeh's embed source file keeps getting larger every time I make one (from Jupyter Notebook). How can I stop this?</p>
<p>Code:</p>
<pre><code>from bokeh.plotting import figure, show
from bokeh.embed import components
from bokeh.io import output_notebook
output_notebook()
def my_plot(color):
p = figure(plot_w... | 0 | 2016-06-06T22:57:15Z | 37,687,981 | <p>As of version <code>0.11.1</code> you need to explicitly call <code>reset_output</code> in some instances:</p>
<pre><code>from bokeh.io import reset_output
reset_output()
</code></pre>
<p>I would suggest calling this at the top of your <code>my_plot</code> function. </p>
| 1 | 2016-06-07T19:42:29Z | [
"python",
"bokeh"
] |
Is there a faster way of inserting N^2 items than using an N^2 Loop? | 37,668,067 | <p>You have a database where Many <code>Foos</code> have Many <code>Bars</code>, so:</p>
<pre><code>Foo --< FooBar >-- Bar
</code></pre>
<p>You have 10 Foos and 10 Bars and need to associate every <code>Foo</code> with every <code>Bar</code> by inserting 100 records into FooBar</p>
<p>Is there a more efficient... | 1 | 2016-06-06T22:58:16Z | 37,668,093 | <p>You need to insert <code>n^2</code> elements. There is no way to do this faster than in <code>n^2</code>. The only thing I can suggest is to use <a href="http://stackoverflow.com/q/1609637/1090562">batch insert</a> instead of individual inserts.</p>
| 2 | 2016-06-06T23:01:48Z | [
"python",
"database",
"algorithm"
] |
Is there a faster way of inserting N^2 items than using an N^2 Loop? | 37,668,067 | <p>You have a database where Many <code>Foos</code> have Many <code>Bars</code>, so:</p>
<pre><code>Foo --< FooBar >-- Bar
</code></pre>
<p>You have 10 Foos and 10 Bars and need to associate every <code>Foo</code> with every <code>Bar</code> by inserting 100 records into FooBar</p>
<p>Is there a more efficient... | 1 | 2016-06-06T22:58:16Z | 37,668,338 | <p>The only way you can get faster than <code>O(n^2)</code> is by not inserting <code>n^2</code> elements. In your case, you could perhaps only store records where the two items are <em>not</em> related, if you expect to only have a few of these. In SQL, you could then form your queries to account for this, or in case ... | 2 | 2016-06-06T23:30:13Z | [
"python",
"database",
"algorithm"
] |
How to add visual annotations to an image using python in a jupyter notebook? | 37,668,094 | <p>The overall objective is to view medical images from some server, add visual annotations to the image (i.e., highlighting/circling a tumor in red), then upload those images back to the server with the annotation as some sort of metadata.</p>
<p>The viewing/uploading/storing metadata is essentially complete, but I h... | 1 | 2016-06-06T23:01:58Z | 37,668,231 | <p>Inside Jupyter notebook you can use:</p>
<pre><code>%matplotlib inline
</code></pre>
| -1 | 2016-06-06T23:16:45Z | [
"python",
"matplotlib",
"jupyter"
] |
How to add visual annotations to an image using python in a jupyter notebook? | 37,668,094 | <p>The overall objective is to view medical images from some server, add visual annotations to the image (i.e., highlighting/circling a tumor in red), then upload those images back to the server with the annotation as some sort of metadata.</p>
<p>The viewing/uploading/storing metadata is essentially complete, but I h... | 1 | 2016-06-06T23:01:58Z | 37,686,528 | <p>Thanks to the suggestions from @michael_j_ward, I found a solution. I looked through those discussions and tutorials as well as read the documentation for the matplotlib axes. This is what I came up with/altered</p>
<pre><code>import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import numpy as np
im... | 2 | 2016-06-07T18:17:48Z | [
"python",
"matplotlib",
"jupyter"
] |
How can I make none of radiobuttons checked when the program starts while the variable is StringVar? | 37,668,128 | <h1>Here I get all of the radiobuttons checked when the program starts. However, I want none of them to be checked at first, only a user can then choose one of them:</h1>
<pre><code>from tkinter import *
root = Tk()
var = StringVar()
l = Label(root)
l.pack()
def f():
l.config(text=var.get())
rb1 = Radiobutton(... | 1 | 2016-06-06T23:05:45Z | 37,668,299 | <p>You should be able to set your radiobutton to ' ' == "empty var" so none are selected, but this makes no sense as mentioned by @bryan Oakley.</p>
<p>Im not usre i'm within best practices by adding values to a list for creating radiobuttons, but this should allow you to have unselected radiobuttons</p>
<pre><code>f... | 0 | 2016-06-06T23:25:38Z | [
"python",
"python-3.x",
"tkinter",
"radio-button",
"tk"
] |
Does colliderect work with classes, if so then how do I use it? | 37,668,155 | <p>I am having an issue adding "colliderect" to my game. I have this class for setting values to the objects, and then one for drawing the items to the screen. </p>
<p>**Edited **
Throughout edits I have updated what my code is having issues with. I have yet to make any of the bel
ow solutions work with my class. All... | 2 | 2016-06-06T23:08:41Z | 37,668,384 | <p>Your method <code>render()</code> that your wrote does not return any value (Ok, it returns <code>None</code>.)</p>
<p>Were you intending to return the rect at the end of that method?</p>
<pre><code>def render(self):
self.rect = pygame.draw.rect(screen,self.color,(self.x,self.y,self.width,self.height))
r... | 0 | 2016-06-06T23:34:48Z | [
"python",
"pygame"
] |
Does colliderect work with classes, if so then how do I use it? | 37,668,155 | <p>I am having an issue adding "colliderect" to my game. I have this class for setting values to the objects, and then one for drawing the items to the screen. </p>
<p>**Edited **
Throughout edits I have updated what my code is having issues with. I have yet to make any of the bel
ow solutions work with my class. All... | 2 | 2016-06-06T23:08:41Z | 37,680,271 | <p>Something like that might work. To use colliderect Pygame expects a <code>Rect(x,y,width,height)</code> or <code>Rect((x,y),(width,height))</code>.</p>
<p>So basically you want: <code>myrectangle1.colliderect(myrectangle2)</code>
Similarly to use collidepoint you need: <code>myrectangle1.collidepoint(mypoint1)</cod... | 0 | 2016-06-07T13:05:20Z | [
"python",
"pygame"
] |
How to make deep copy of Python class? | 37,668,233 | <p>I'd like to make a copy of class, while updating all of its methods to refer a new set of <code>__globals__</code></p>
<p>I was thinking something like below, however unlike <code>types.FunctionType</code>, the constructor for <code>types.UnboundMethodType</code> does not accept <code>__globals__</code>, any sugges... | 1 | 2016-06-06T23:16:53Z | 37,668,269 | <p>The <code>__dict__</code> values are functions, not unbound methods. The unbound method objects only get created on attribute access. If you <em>are</em> seeing unbound method objects in the <code>__dict__</code>, something weird happened with your class object before this function got to it.</p>
| 1 | 2016-06-06T23:21:16Z | [
"python",
"python-2.7",
"monkeypatching"
] |
How to make deep copy of Python class? | 37,668,233 | <p>I'd like to make a copy of class, while updating all of its methods to refer a new set of <code>__globals__</code></p>
<p>I was thinking something like below, however unlike <code>types.FunctionType</code>, the constructor for <code>types.UnboundMethodType</code> does not accept <code>__globals__</code>, any sugges... | 1 | 2016-06-06T23:16:53Z | 37,668,516 | <p>I don't know about you, but I generally don't like to use <code>types</code> for anything other than type checking (which I don't do very often ;-). I'd much rather <code>inspect</code>...</p>
<p>I have to preface this code by saying that I hope you have a really good reason for wanting to do this ;-) -- to me, it... | 1 | 2016-06-06T23:53:19Z | [
"python",
"python-2.7",
"monkeypatching"
] |
How to make a Trello session persist using Python as the client? | 37,668,234 | <p>I'm trying to write a Python script that, from my command line, will allow me to:</p>
<ol>
<li><p>Log in to Trello</p></li>
<li><p>Use the <a href="https://pythonhosted.org/trello/" rel="nofollow">Trello Python API</a> to retrieve data from Trello boards, etc.</p></li>
</ol>
<p>I'm restricted to using Python 2.7.6... | 0 | 2016-06-06T23:16:57Z | 37,669,274 | <p>Apparently there are 2 calls to make to get the token:</p>
<ol>
<li><a href="https://trello.com/1/authentication" rel="nofollow">https://trello.com/1/authentication</a>
which contains the <code>code</code> string in the response</li>
<li><a href="https://trello.com/1/authorization/session" rel="nofollow">https://tr... | 0 | 2016-06-07T01:45:22Z | [
"python",
"python-requests",
"trello"
] |
Trying to load a .dat file into python and reading the file | 37,668,252 | <pre><code>data=[]
time=[]
with open('fismflux20010415.dat','r') as info:
for i in info:
data.append(i)
time.append(data[1:5])
if __name__=="__main__":
print(time)
</code></pre>
<p>I need help trying to load a .dat file into python and put the data into 2 different lists. The way that the file is set up is the... | 0 | 2016-06-06T23:18:46Z | 37,668,467 | <pre><code>for line in info:
parts = line.split()
data.append(parts[6:])
time.append(data[:6])
</code></pre>
| 0 | 2016-06-06T23:46:26Z | [
"python"
] |
Trying to load a .dat file into python and reading the file | 37,668,252 | <pre><code>data=[]
time=[]
with open('fismflux20010415.dat','r') as info:
for i in info:
data.append(i)
time.append(data[1:5])
if __name__=="__main__":
print(time)
</code></pre>
<p>I need help trying to load a .dat file into python and put the data into 2 different lists. The way that the file is set up is the... | 0 | 2016-06-06T23:18:46Z | 37,668,488 | <p>This should do the stuff:</p>
<pre><code>data=[]
time=[]
f = open( 'fismflux20010415.dat' )
f_lines = f.readlines()
for l in f_lines:
tmp_l = l.split()
time.append( [ int( i ) for i in tmp_l[ : 6 ] ] )
data.append( [ float( i ) for i in tmp_l[ 6 : ] ] )
if __name__=="__main__":
print(time)
prin... | 0 | 2016-06-06T23:49:14Z | [
"python"
] |
Convert coordinates for San Francisco using pyproj | 37,668,267 | <p>I have a shapefile of San Francisco that I successfully loaded but I need to convert the coordinates to longitude/latitude form. The variables I have are as follows:</p>
<p>w1 = x coordinates
w2 = y coordinates</p>
<p>Currently the coordinates look like this:</p>
<pre><code>print(w1[0], w2[0])
6017864.66784 21047... | 2 | 2016-06-06T23:21:00Z | 37,668,855 | <p>I just learned more about pyproj than I had originally intended:</p>
<p>All you need to do is add <code>preserve_units = True</code> to your Projection aliases:</p>
<pre><code>w1=[1]
w2=[1]
w1[0]=6010936.158609
w2[0]=2090667.302531
from pyproj import Proj, transform
inProj = Proj(init='epsg:2227', preserve_units=T... | 0 | 2016-06-07T00:43:02Z | [
"python",
"coordinates",
"gis",
"proj"
] |
Flatten double nested JSON | 37,668,291 | <p>I am trying to flatten a JSON file that looks like this:</p>
<pre><code>{
"teams": [
{
"teamname": "1",
"members": [
{
"firstname": "John",
"lastname": "Doe",
"orgname": "Anon",
"phone": "916-555-1234",
"mobile": "",
"email": "john.doe@wildlife.net"
... | 3 | 2016-06-06T23:24:19Z | 37,668,569 | <p>This is one way to do it. Should give you some ideas.</p>
<pre><code>df = pd.concat(
[
pd.concat([pd.Series(m) for m in t['members']], axis=1) for t in data['teams']
], keys=[t['teamname'] for t in data['teams']]
)
0 1
1 email j... | 3 | 2016-06-07T00:00:53Z | [
"python",
"json",
"excel",
"pandas",
"dictionary"
] |
Move Rows Up By One Of Specified Column In Pandas | 37,668,301 | <p>I have a file like this:</p>
<pre><code>value1, value2, value3, value4, value5
NAN NAN value8, value9, value0
value6, value7, NAN NAN NAN
</code></pre>
<p>And I would like to push row 3 up to do the following:</p>
<pre><code>value1, value2, value3, value4, value5
value6, value7, value8, value9, ... | 0 | 2016-06-06T23:25:55Z | 37,668,423 | <p>This should work:</p>
<pre><code>df = pd.DataFrame(
{'value1': {0: np.nan, 1: 'value6'},
'value2': {0: np.nan, 1: 'value7'},
'value3': {0: 'value8', 1: np.nan},
'value4': {0: 'value9', 1: np.nan},
'value5': {0: 'value0', 1: np.nan}}
)
print df
print
print df.iloc[0, :].combine_first(df.iloc... | 0 | 2016-06-06T23:39:53Z | [
"python",
"pandas"
] |
Move Rows Up By One Of Specified Column In Pandas | 37,668,301 | <p>I have a file like this:</p>
<pre><code>value1, value2, value3, value4, value5
NAN NAN value8, value9, value0
value6, value7, NAN NAN NAN
</code></pre>
<p>And I would like to push row 3 up to do the following:</p>
<pre><code>value1, value2, value3, value4, value5
value6, value7, value8, value9, ... | 0 | 2016-06-06T23:25:55Z | 37,668,547 | <p>Try <strong><em>df.fillna()</em></strong> method. Also it helps if dataframe definition and code are provided.</p>
<pre><code>>>> import pandas as pd;
>>> import numpy as np;
>>> df = pd.DataFrame({'r1':['v1','v2','v3','v4','v5'],'r2':[np.NaN,np.NaN,'v8','v9','v0'],'r3':['v6','v7',np.NaN,... | 0 | 2016-06-06T23:58:05Z | [
"python",
"pandas"
] |
Create an int list feature to save as tfrecord in tensorflow? | 37,668,485 | <p>How can I create a tensorflow record from a list?</p>
<p>From the documentation here it seems possible:
<a href="https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/core/example/feature.proto#L9-10" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/core/example/feature.proto#L9-... | 1 | 2016-06-06T23:48:40Z | 37,676,073 | <p>As per my understanding you want to store a list of integers in the tfrecord.
It is possible to store oneof packed BytesList,FloatList, or Int64List as per the documentation
<a href="https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/core/example/example.proto" rel="nofollow">https://github.com/tensorflow... | 0 | 2016-06-07T09:54:52Z | [
"python",
"tensorflow"
] |
Create an int list feature to save as tfrecord in tensorflow? | 37,668,485 | <p>How can I create a tensorflow record from a list?</p>
<p>From the documentation here it seems possible:
<a href="https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/core/example/feature.proto#L9-10" rel="nofollow">https://github.com/tensorflow/tensorflow/blob/r0.9/tensorflow/core/example/feature.proto#L9-... | 1 | 2016-06-06T23:48:40Z | 37,709,422 | <p>After a while of messing around with it and looking further in the documentation I found my own answer.
In the above function using the example code as a base:</p>
<pre><code>def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
...
'label': _int64_feature(labels[index])... | 1 | 2016-06-08T17:45:43Z | [
"python",
"tensorflow"
] |
Run a file before py.test session starts, without __init__ | 37,668,554 | <p><strong>Is there a way to run a .py at the very beginning besides <code>__init__.py</code>?</strong> </p>
<p>My problem is I need to save the current database state before the parsing of the files changes things. Because I have temporary tests variables that change, but if I can store the state before parsing this... | 0 | 2016-06-06T23:59:20Z | 37,695,610 | <p>You could use pytest's <a href="http://pytest.org/latest/writing_plugins.html" rel="nofollow">plugin hooks</a> with a <code>conftest.py</code> to do so.</p>
<p>I'm not sure which hook would be best for your case. Probably <code>pytest_configure</code>.</p>
<p>For example, with this in a <code>conftest.py</code>:</... | 1 | 2016-06-08T07:13:46Z | [
"python",
"python-3.x",
"py.test"
] |
Writing a dictionary to replace switch statements in functions | 37,668,587 | <p>I've written a menu in Python 3 that takes user input, however to convert the string properly I've had to manually write out an if statement.</p>
<p>I need to change this all to a dictionary to use across several different functions, storing variables in some and lists in another. So far the if statement looks like... | 0 | 2016-06-07T00:03:14Z | 37,668,633 | <p>This <em>is</em> a normal dictionary. The difference is that your "switch" dictionary is an in-line constant with an index. Let's expand this just a little:</p>
<pre><code>def f(x):
ref_dict = {
'a': 1,
'b': 2,
}
return_tone = ref_dict[x]
return return_tone
</code></pre>
<p>Do yo... | 1 | 2016-06-07T00:08:13Z | [
"python",
"dictionary",
"switch-statement"
] |
Create new column for data after each iteration of a for loop in python | 37,668,636 | <p>Using the next code I want to put the results in columns for differents values of m</p>
<pre><code>import numpy as np
for m in np.arange(0, 4, 1):
for n in np.arange(1, 4, 1):
coef = 2*m/n
print coef
</code></pre>
<p>The results of this is:</p>
<pre><code>0
0
0
2
1
0
4
2
1
6
3
2
</code></pre>
<... | 1 | 2016-06-07T00:09:08Z | 37,668,648 | <p>Add a comma after the print so we don't add a newline and another print outside the inner loop to separate each line:</p>
<pre><code>import numpy as np
for m in np.arange(0, 4, 1):
for n in np.arange(1, 4, 1):
coef = 2*m/n
print coef,
print
</code></pre>
<p>Which will give you:</p>
<pre><cod... | 2 | 2016-06-07T00:11:01Z | [
"python",
"numpy"
] |
Create new column for data after each iteration of a for loop in python | 37,668,636 | <p>Using the next code I want to put the results in columns for differents values of m</p>
<pre><code>import numpy as np
for m in np.arange(0, 4, 1):
for n in np.arange(1, 4, 1):
coef = 2*m/n
print coef
</code></pre>
<p>The results of this is:</p>
<pre><code>0
0
0
2
1
0
4
2
1
6
3
2
</code></pre>
<... | 1 | 2016-06-07T00:09:08Z | 37,668,750 | <p>As I understood correctly, you want to create new array where its columns are like you've specified. </p>
<pre><code>import numpy as np
a = np.zeros([3,4])
for m in np.arange(0, 4, 1):
col = []
for n in np.arange(1, 4, 1):
coef = int(2*m/n)
col.append(coef)
a[:, int(m)] = col
print(a.T... | 1 | 2016-06-07T00:26:59Z | [
"python",
"numpy"
] |
Create new column for data after each iteration of a for loop in python | 37,668,636 | <p>Using the next code I want to put the results in columns for differents values of m</p>
<pre><code>import numpy as np
for m in np.arange(0, 4, 1):
for n in np.arange(1, 4, 1):
coef = 2*m/n
print coef
</code></pre>
<p>The results of this is:</p>
<pre><code>0
0
0
2
1
0
4
2
1
6
3
2
</code></pre>
<... | 1 | 2016-06-07T00:09:08Z | 37,669,126 | <p>What you are doing with a loop would work just as well with <code>range</code>. No need to use <code>numpy</code>.</p>
<p>But if this is an exercise in learning <code>numpy</code>, I'd suggest a different approach.</p>
<p>Make an array directly from the ranges. <code>//</code> is integer division.</p>
<pre><cod... | 1 | 2016-06-07T01:25:46Z | [
"python",
"numpy"
] |
Python, Remove characters, such as emoji, that cannot be handled by UTF8 MySQL DB | 37,668,642 | <p>How can I replace characters, such as emojis í ½í¸, that cannot be handled by a UTF8 MySQL DB?</p>
<p>The key is to ONLY remove those characters that cannot be handled. I got this code from this answer <a href="http://stackoverflow.com/questions/33404752/removing-emojis-from-a-string-in-python">removing emojis fro... | 1 | 2016-06-07T00:09:48Z | 37,668,788 | <pre><code>>>> u"abcd ⥠\ud83c".encode("utf-8", errors="replace").decode("utf-8")
'abcd ⥠?'
</code></pre>
| 0 | 2016-06-07T00:32:16Z | [
"python",
"mysql",
"regex",
"utf-8",
"emoji"
] |
Python, Remove characters, such as emoji, that cannot be handled by UTF8 MySQL DB | 37,668,642 | <p>How can I replace characters, such as emojis í ½í¸, that cannot be handled by a UTF8 MySQL DB?</p>
<p>The key is to ONLY remove those characters that cannot be handled. I got this code from this answer <a href="http://stackoverflow.com/questions/33404752/removing-emojis-from-a-string-in-python">removing emojis fro... | 1 | 2016-06-07T00:09:48Z | 37,668,867 | <p>MySQL's <code>utf8</code> encodes precisely the basic multilingual plane (BMP). Rather than specifically emoji, you need to exclude all code points from supplementary planes, since in MySQL these require <code>utf8mb4</code>.</p>
<p>Since you appear to be matching against 16 bit rather than 32 bit wide strings, a c... | 3 | 2016-06-07T00:45:07Z | [
"python",
"mysql",
"regex",
"utf-8",
"emoji"
] |
How to make python exception handing for my app? | 37,668,701 | <p>I have finished a simple application to calculate the BMI, however, I need to create a couple of exception handlings in an another file, such like exceptions.py </p>
<p>These exceptions are: empty value exception, integer value exception, and email format exception. </p>
<p>Can anyone show me how to make these exc... | 0 | 2016-06-07T00:20:00Z | 37,668,884 | <p>The point Pythonista made is that you don't need to create new exceptions because they'll be created for you in most cases.</p>
<p>For example if you try creating an int from an empty entry, <code>int('')</code> will raise a <code>ValueError</code> by itself. The question is where you should handle the exception.
T... | 0 | 2016-06-07T00:47:38Z | [
"python",
"exception-handling"
] |
How to REALLY disable re-indent on paste | 37,668,706 | <p>I'm using Atom at work for editing Python code, and I'm running against a painful interaction between muscle memory and a labor-saving feature.</p>
<p>Near as I can tell, Atom will, when you paste a snippet of code, redo the indentation so that it's consistent with the indentation of the line it was pasted into, pr... | 0 | 2016-06-07T00:21:01Z | 37,685,872 | <p>You have to set the config options <code>autoIndentOnPaste</code> and <code>normalizeIndentOnPaste</code> both to <code>false</code>, and then reload the configuration.</p>
| 0 | 2016-06-07T17:40:00Z | [
"python",
"atom-editor"
] |
How to print original string from Unicode string(such as \uD14C\uC2A4\uD2B8) in python | 37,668,737 | <p>I searched a bit about this. But most of people want to convert original string(í
ì¤í¸) to unicode(\uD14C\uC2A4\uD2B8). </p>
<p>But <strong>what I want is converting unicode string(such as \uD14C\uC2A4\uD2B8) to real string(í
ì¤í¸)</strong>. I have JSON file in which all the Korean strings are in form of unic... | 0 | 2016-06-07T00:24:47Z | 37,669,468 | <pre><code>import codecs
file_variable = 'path/to/file.json'
with codecs.open(file_variable, encoding='utf-8') as file:
json_object = json.load(file)
</code></pre>
<p>See if that allows you to handle your json in unicode. The import codecs also allows you to use the .encode() and .decode() functions to go back and... | 0 | 2016-06-07T02:13:33Z | [
"python",
"string",
"unicode"
] |
How to print original string from Unicode string(such as \uD14C\uC2A4\uD2B8) in python | 37,668,737 | <p>I searched a bit about this. But most of people want to convert original string(í
ì¤í¸) to unicode(\uD14C\uC2A4\uD2B8). </p>
<p>But <strong>what I want is converting unicode string(such as \uD14C\uC2A4\uD2B8) to real string(í
ì¤í¸)</strong>. I have JSON file in which all the Korean strings are in form of unic... | 0 | 2016-06-07T00:24:47Z | 37,718,811 | <p>I solved by this way</p>
<ol>
<li>read byte by byte and add byte(variable c) into variable
aJSON+=encode(c)</li>
<li>aJSON.decode('unicode-escape') gives expected result.</li>
</ol>
<p>Thanks for interest anyway..</p>
| -1 | 2016-06-09T06:55:27Z | [
"python",
"string",
"unicode"
] |
Edit package installed by pip | 37,668,773 | <p>I'm trying to edit a package that I installed via pip, called py_mysql2pgsql (I had an error when converting my db from mysql to postgre, just like <a href="http://stackoverflow.com/questions/26008398/error-transferring-database-from-mysql-to-postgres-using-mysql2pgsql">this</a>. </p>
<p>However, when I got to the ... | -1 | 2016-06-07T00:29:43Z | 37,668,909 | <p><code>py_mysql2pgsql</code> package is hosted on PyPI: <a href="https://pypi.python.org/pypi/py-mysql2pgsql" rel="nofollow">https://pypi.python.org/pypi/py-mysql2pgsql</a></p>
<p>If you want the code for that specific version, just download the source tarball from PyPI (py-mysql2pgsql-0.1.5.tar.gz)</p>
<p>Developm... | 0 | 2016-06-07T00:52:26Z | [
"python",
"pip"
] |
Edit package installed by pip | 37,668,773 | <p>I'm trying to edit a package that I installed via pip, called py_mysql2pgsql (I had an error when converting my db from mysql to postgre, just like <a href="http://stackoverflow.com/questions/26008398/error-transferring-database-from-mysql-to-postgres-using-mysql2pgsql">this</a>. </p>
<p>However, when I got to the ... | -1 | 2016-06-07T00:29:43Z | 37,669,205 | <h1>TL;DR:</h1>
<p>Modifying in place is dangerous. Modify the source and <em>then</em> install it from your modified version.</p>
<h1>Details</h1>
<p>pip is a tool for managing the installation of packages. You should not modify files creating during package installation. At best, doing so would mean pip will belie... | 1 | 2016-06-07T01:35:30Z | [
"python",
"pip"
] |
Edit package installed by pip | 37,668,773 | <p>I'm trying to edit a package that I installed via pip, called py_mysql2pgsql (I had an error when converting my db from mysql to postgre, just like <a href="http://stackoverflow.com/questions/26008398/error-transferring-database-from-mysql-to-postgres-using-mysql2pgsql">this</a>. </p>
<p>However, when I got to the ... | -1 | 2016-06-07T00:29:43Z | 37,669,217 | <p>just print out the <code>.__file__</code> attribute of the module:</p>
<pre><code>>>> import numpy
>>> numpy.__file__
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/numpy/__init__.py'
</code></pre>
<p>Obviously the path and specific package would be different for y... | 0 | 2016-06-07T01:37:07Z | [
"python",
"pip"
] |
How to display a loaded image on a pygame.Overlay() | 37,668,794 | <p>I am trying to use overlays in pygame to display video. The trouble is that my frames are loaded as RGB Surface()s while Overlay().display() requires YUV format.</p>
<p>I saw that pygame.camera module contains a colorspace() function that should be able to convert RGB Surface() to YUV one. Does anyone know how to d... | 1 | 2016-06-07T00:32:51Z | 37,676,698 | <p>I haven't had much time to play with .Overlay()</p>
<p>but the colorspace function seems to go as follows:</p>
<pre><code>yuv_surface = pygame.camera.colorspace(rgb_surface,"YUV")
</code></pre>
<p>This example runs without error:</p>
<pre><code>import pygame
import pygame.camera
pygame.init()
pygame.camera.init... | 0 | 2016-06-07T10:22:11Z | [
"python",
"image",
"pygame"
] |
Matplotlib separate 2D contour projection plots of 3D data | 37,668,874 | <p>I am trying to create 2D plots of the projection of 3D data. Very simply, based on <a href="http://matplotlib.org/examples/mplot3d/contourf3d_demo2.html" rel="nofollow">this example</a> is there a way to produce the three contour projections shown (in the X, Y, and Z directions) as separate 2D plots? I can easily cr... | 2 | 2016-06-07T00:45:52Z | 37,679,087 | <p>The <code>zdir</code> parameter in a 3D contour basically says which axis will be used to determine the contour levels in a 3D plot. In a 2D plot this is usually specified by the order of the arguments, so what we normally think of as "Z", that is, the values that determine the contour level, is put in as the third... | 1 | 2016-06-07T12:14:10Z | [
"python",
"matplotlib",
"contour"
] |
How can I use a decorator to modify the type of *args? | 37,668,895 | <p>I would like to use a <code>@decorator</code> to allow me to be able to access <code>' - '.join(args)</code> as <code>args</code>, as depicted below. Is this possible, using a metaclass perhaps?</p>
<pre><code>def a(*args):
print(args)
a(1, 2, 3)
# (1, 2, 3)
@magic
def b(*args):
print(args)
b(1, 2, 3)
# 1 ... | 3 | 2016-06-07T00:49:12Z | 37,669,074 | <p>You can get close:</p>
<pre><code>def magic(func):
def wrapper(*args):
return func(' - '.join(map(str, args)))
return wrapper
</code></pre>
<p>but this prints out <code>('1 - 2 - 3',)</code> because the body of <code>b</code> sees <code>args</code> as a tuple due to the <code>*args</code>, and I do... | 2 | 2016-06-07T01:16:57Z | [
"python",
"python-3.x",
"arguments",
"decorator",
"metaclass"
] |
How can I use a decorator to modify the type of *args? | 37,668,895 | <p>I would like to use a <code>@decorator</code> to allow me to be able to access <code>' - '.join(args)</code> as <code>args</code>, as depicted below. Is this possible, using a metaclass perhaps?</p>
<pre><code>def a(*args):
print(args)
a(1, 2, 3)
# (1, 2, 3)
@magic
def b(*args):
print(args)
b(1, 2, 3)
# 1 ... | 3 | 2016-06-07T00:49:12Z | 37,669,094 | <p>So part of the problem is that you're using integers where you need strings, so convert them into strings and then use the join function. </p>
<pre><code>def magic(func):
def wrapper(*args):
return ' - '.join(map(str, args))
return wrapper
@magic
def a(*args):
return 'Arguments were {}.'.format... | 0 | 2016-06-07T01:20:15Z | [
"python",
"python-3.x",
"arguments",
"decorator",
"metaclass"
] |
Matplotlib Animated 3D Bar Chart with fixed Z-limits | 37,668,967 | <p>The following code works, except for one line; if I include <code>ax.set_zlim3d(minz, maxz)</code> (line 29) then the bars all become offset in the x-y plane. How can I alter this code to fix the limits of the z-axis without this happening?</p>
<pre><code>%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
i... | 1 | 2016-06-07T01:01:32Z | 37,669,313 | <p>When you change the limits on the z axis, you are shifting the plot and essentially zooming in on the bars, moving the center to (3.25,3.25) on the x-y plane. You can change the limits of the x-y plane manually by inserting the following lines in the <code>setup_plot</code> function:</p>
<pre><code>ax.set_ylim3d(2,... | 1 | 2016-06-07T01:51:51Z | [
"python",
"animation",
"matplotlib"
] |
Flask: App structure to avoid circular imports | 37,668,983 | <p>I am following the book <em>Mastering flask</em>'s recommended file structure. </p>
<p>(The name of my project is Paw)</p>
<p>In <code>Paw/paw/__init__.py</code>: </p>
<pre><code>def create_app(object_name):
app = Flask(__name__)
app.config.from_object(object_name)
db.init_app(app)
robot = LoggingWeRobot... | 0 | 2016-06-07T01:02:55Z | 37,670,392 | <p>Simply use the same pattern you are using for <code>db</code> - create <code>robot</code> elsewhere and import it into your <code>Paw/paw/__init__.py</code> file, just as you do with <code>db</code>:</p>
<pre><code>import db from models
import robot from wechat_setup
# wechat_setup is where you would invoke
# robot... | 1 | 2016-06-07T04:16:36Z | [
"python",
"flask"
] |
Flask: App structure to avoid circular imports | 37,668,983 | <p>I am following the book <em>Mastering flask</em>'s recommended file structure. </p>
<p>(The name of my project is Paw)</p>
<p>In <code>Paw/paw/__init__.py</code>: </p>
<pre><code>def create_app(object_name):
app = Flask(__name__)
app.config.from_object(object_name)
db.init_app(app)
robot = LoggingWeRobot... | 0 | 2016-06-07T01:02:55Z | 37,699,979 | <p>I usually put project global variables in one file (say <code>gvars.py</code>).</p>
<p>Then the project structure will be some sort like this:</p>
<pre><code>.
âââ etc
â  âââ webapp.py
âââ models
â  âââ common.py
âââ views
â  âââ common.py
âââ gvars.py
ââ... | 0 | 2016-06-08T10:30:55Z | [
"python",
"flask"
] |
False positive in python for loop | 37,668,992 | <p>I've been writing a simple method to check if a web address has subdirectories and, if it does, separate them for me into a list. The code I wrote should ignore the last subdirectory the URL has (this was a mistake I realized after I noticed the loop was iterating about 4 times while checking a URL with a single sub... | -2 | 2016-06-07T01:04:46Z | 37,669,315 | <p>As @TadhgMcDonald-Jensen explained, what is happening is that Python is iterating over each one of the characters, @Evert's suggested using a 'while' loop, which gives the result I was originally looking for.</p>
<p>I'll probably end up using <a href="https://docs.python.org/3/library/urllib.parse.html" rel="nofoll... | 1 | 2016-06-07T01:52:14Z | [
"python",
"python-3.x"
] |
Django 'if not' statement is not working properly | 37,669,072 | <p>I'm trying to make it so that when I am signed in all my drafts show the word DRAFT in red letters so I tried the following </p>
<pre><code><h6 id="date">{% if post.draft %}<div id="draft">DRAFT</div>{% endif %} </h6>
</code></pre>
<p>but it's not working but if I do </p>
<pre><code><h6... | 0 | 2016-06-07T01:16:44Z | 37,669,159 | <p>In your template you should use:</p>
<pre><code>{% if post.status == 'draft' %}
</code></pre>
<p>You have the following field on your model:</p>
<pre><code>status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')
</code></pre>
<p>You need only check if the post status' field value is dra... | 3 | 2016-06-07T01:30:07Z | [
"python",
"django",
"conditional"
] |
Split file name on python | 37,669,129 | <p>I'm trying to split a filename use it by parts. <br/>
The file is always an apache binary (for example, httpd-2.2.31.tar.gz) and I only need the version (in this case 22) in that specific format.<br/>
I have done it and it works, but I believe there should be a better way</p>
<pre><code>binary_name = "httpd-2.2.31.... | 0 | 2016-06-07T01:26:06Z | 37,669,176 | <p>if you want to do it in one line,may be it will help :</p>
<pre><code>binary_name = "httpd-2.2.31.tar.gz"
print binary_name.split("-")[1][:3].replace('.','')
</code></pre>
<p>will return 22</p>
| 1 | 2016-06-07T01:32:25Z | [
"python",
"split"
] |
Split file name on python | 37,669,129 | <p>I'm trying to split a filename use it by parts. <br/>
The file is always an apache binary (for example, httpd-2.2.31.tar.gz) and I only need the version (in this case 22) in that specific format.<br/>
I have done it and it works, but I believe there should be a better way</p>
<pre><code>binary_name = "httpd-2.2.31.... | 0 | 2016-06-07T01:26:06Z | 37,669,188 | <p>You could make it a little easier by using <a href="https://docs.python.org/3/library/re.html" rel="nofollow">regular expressions</a>. There's a nifty site called <a href="http://pythex.org/" rel="nofollow">Pythex</a> where you can experiment with these yourself. To fix your example:</p>
<pre><code>import re
r = re... | 0 | 2016-06-07T01:33:25Z | [
"python",
"split"
] |
Split file name on python | 37,669,129 | <p>I'm trying to split a filename use it by parts. <br/>
The file is always an apache binary (for example, httpd-2.2.31.tar.gz) and I only need the version (in this case 22) in that specific format.<br/>
I have done it and it works, but I believe there should be a better way</p>
<pre><code>binary_name = "httpd-2.2.31.... | 0 | 2016-06-07T01:26:06Z | 37,669,201 | <p>use <code>re</code></p>
<pre><code>(?<=-)(\d+)\.(\d+)
</code></pre>
<p>See demo.</p>
<p><a href="https://regex101.com/r/oS7mT8/1" rel="nofollow">Regex101 demo</a></p>
<p>or</p>
<p><a href="http://pythex.org/?regex=%28%3F%3C%3D-%29%28%5Cd%2B%29%5C.%28%5Cd%2B%29&test_string=httpd-2.2.31.tar.gz&ignoreca... | 2 | 2016-06-07T01:35:11Z | [
"python",
"split"
] |
Split file name on python | 37,669,129 | <p>I'm trying to split a filename use it by parts. <br/>
The file is always an apache binary (for example, httpd-2.2.31.tar.gz) and I only need the version (in this case 22) in that specific format.<br/>
I have done it and it works, but I believe there should be a better way</p>
<pre><code>binary_name = "httpd-2.2.31.... | 0 | 2016-06-07T01:26:06Z | 37,669,422 | <p>As far as a better way there is no such thing as long as your code solves the problem you set out to solve, and in this case it does. As far as performance goes there are probably faster ways to achieve the same thing but even with a list of thousands of string to parse the difference in speed would be minimal or in... | 0 | 2016-06-07T02:07:16Z | [
"python",
"split"
] |
Using groupy and subplots with pandas dataframe | 37,669,152 | <p>I have a dataframe object with time series data in multiple columns (see below). I am trying to make a graphic with subplots for each of the columns in the dataframe where each subplot has 12 boxplots, one for each month. </p>
<p>I have used the following code to <em>just</em> make subplots from a dataframe before ... | 0 | 2016-06-07T01:28:47Z | 37,687,133 | <p>AFAIK, if you group your DF you have either apply some aggregate (reducing) function or call <code>.groups</code> which would return you a dict with group keys and corresponding indexes for each key. So if you just want to plot 12 subplots </p>
<p>IIUC you may try to do it this way (using seaborn module):</p>
<pre... | 1 | 2016-06-07T18:51:40Z | [
"python",
"pandas",
"group-by",
"boxplot",
"subplot"
] |
Using groupy and subplots with pandas dataframe | 37,669,152 | <p>I have a dataframe object with time series data in multiple columns (see below). I am trying to make a graphic with subplots for each of the columns in the dataframe where each subplot has 12 boxplots, one for each month. </p>
<p>I have used the following code to <em>just</em> make subplots from a dataframe before ... | 0 | 2016-06-07T01:28:47Z | 37,687,386 | <p>If seaborn is not an option, creating an additional "month" column and grouping by that will work:</p>
<pre><code>df['month'] = df.index.month
df.boxplot(by='month', figsize=(12,8));
</code></pre>
<p><img src="http://i.stack.imgur.com/oS4tO.png" alt="boxplotbymonth"></p>
| 1 | 2016-06-07T19:06:03Z | [
"python",
"pandas",
"group-by",
"boxplot",
"subplot"
] |
Read Bunch() from string | 37,669,160 | <p>I have the following string in a report file:</p>
<pre><code>"Bunch(conditions=['s1', 's2', 's3', 's4', 's5', 's6'], durations=[[30.0], [30.0], [30.0], [30.0], [30.0], [30.0]], onsets=[[172.77], [322.77], [472.77], [622.77], [772.77], [922.77]])"
</code></pre>
<p>I would like to turn it into a <code>Bunch()</code>... | 3 | 2016-06-07T01:30:11Z | 37,683,851 | <p>Here is my ugly piece of code, please check:</p>
<pre><code>import re
import json
l = "Bunch(conditions=['s1', 's2', 's3', 's4', 's5', 's6'], durations=[[30.0], [30.0], [30.0], [30.0], [30.0], [30.0]], onsets=[[172.77], [322.77], [472.77], [622.77], [772.77], [922.77]])"
exec('{}="{}"'.format(l[:5],l[6:-1]))
sb = ... | 2 | 2016-06-07T15:45:56Z | [
"python",
"json",
"parsing",
"dictionary",
"bunch"
] |
Read Bunch() from string | 37,669,160 | <p>I have the following string in a report file:</p>
<pre><code>"Bunch(conditions=['s1', 's2', 's3', 's4', 's5', 's6'], durations=[[30.0], [30.0], [30.0], [30.0], [30.0], [30.0]], onsets=[[172.77], [322.77], [472.77], [622.77], [772.77], [922.77]])"
</code></pre>
<p>I would like to turn it into a <code>Bunch()</code>... | 3 | 2016-06-07T01:30:11Z | 37,684,691 | <p>This pyparsing code will define a parsing expression for your Bunch declaration.</p>
<pre><code>from pyparsing import (pyparsing_common, Suppress, Keyword, Forward, quotedString,
Group, delimitedList, Dict, removeQuotes, ParseResults)
# define pyparsing parser for the Bunch declaration
LBRACK,RBRACK,LPAR,RPAR... | 2 | 2016-06-07T16:32:08Z | [
"python",
"json",
"parsing",
"dictionary",
"bunch"
] |
SikulixIDE How do I change to utf-8 | 37,669,177 | <p>I am using SikulixIDE in python, but a can't change the encoding to utf-8. Someone help-me?</p>
<pre><code>Settings.MoveMouseDelay=0.0
click("1465260706046.png")
sleep(2)
type("ação")
</code></pre>
| 0 | 2016-06-07T01:32:26Z | 37,669,755 | <p>It is a known issue. The bug is documented <a href="https://bugs.launchpad.net/sikuli/+bug/1299462" rel="nofollow">here</a>. </p>
<p>The source of this issue is the Java AWT Robot that is used for Sikuli's <code>type()</code>. The usage of the <code>type()</code> is generally restricted to whatever you can produce ... | 0 | 2016-06-07T02:52:56Z | [
"python",
"automation",
"sikuli",
"sikuli-script",
"sikuli-ide"
] |
Connecting to a MongoDB replica set - pymongo | 37,669,209 | <p>So I have a cluster of 3 mongo replica sets. The primary (master) is at rs1, while rs2 and rs3 are secondaries.
However, the primary may change, for example, rs2 may be the primary at any given time due to some configuration issue. Therefore, I need to be able to connect to the appropriate replica set.
Let's say the... | 1 | 2016-06-07T01:36:06Z | 37,670,034 | <p>In your MongoClient you need to tell pymongo that you are connecting to a replica set so it can discover all the members in the set <a href="https://api.mongodb.com/python/current/examples/high_availability.html#id1" rel="nofollow">https://api.mongodb.com/python/current/examples/high_availability.html#id1</a></p>
| 1 | 2016-06-07T03:33:03Z | [
"python",
"django",
"mongodb"
] |
Connecting to a MongoDB replica set - pymongo | 37,669,209 | <p>So I have a cluster of 3 mongo replica sets. The primary (master) is at rs1, while rs2 and rs3 are secondaries.
However, the primary may change, for example, rs2 may be the primary at any given time due to some configuration issue. Therefore, I need to be able to connect to the appropriate replica set.
Let's say the... | 1 | 2016-06-07T01:36:06Z | 37,670,084 | <p><a href="https://api.mongodb.com/python/current/examples/high_availability.html#id1" rel="nofollow">From the docs</a></p>
<blockquote>
<p>A connection to a replica set can be made using the MongoClient()
constructor, specifying one or more members of the set, along with the
replica set name.</p>
</blockquote>... | 1 | 2016-06-07T03:41:01Z | [
"python",
"django",
"mongodb"
] |
Switch dictionary in Python not converting int and str correctly | 37,669,214 | <p>Followed on from a previous question, I've written a switch dictionary to replace switch statements in functions. I've placed this dictionary under def f(x) after receiving user input, like so. Then the function should write whatever was matched in the dictionary to 'a' and 'b', so it can be used in the add() functi... | 1 | 2016-06-07T01:36:42Z | 37,669,293 | <p>Try printing a and b before calling the add function to see what their values are.</p>
<p>My guess is, the variables inside the switch functions are inside the scope of the function and are not changing the variables outside the function.</p>
<p>Why don't you receive the returned values in a variable?</p>
<blockq... | 1 | 2016-06-07T01:48:01Z | [
"python",
"dictionary",
"switch-statement"
] |
Switch dictionary in Python not converting int and str correctly | 37,669,214 | <p>Followed on from a previous question, I've written a switch dictionary to replace switch statements in functions. I've placed this dictionary under def f(x) after receiving user input, like so. Then the function should write whatever was matched in the dictionary to 'a' and 'b', so it can be used in the add() functi... | 1 | 2016-06-07T01:36:42Z | 37,669,294 | <p>Try This:</p>
<pre><code>def add(va,vb):
print ((va), "+", (vb), "=", (va + vb) %12)
aa = f(a)
bb = g(b)
add(aa, bb)
</code></pre>
| 1 | 2016-06-07T01:48:19Z | [
"python",
"dictionary",
"switch-statement"
] |
How can I hint that a type is comparable with typing | 37,669,222 | <p>Say I want to write a comparison sorting function, I can hint that the input must be a sequence with <code>Sequence[T]</code> (or <code>MutableSequence[T]</code> in this case).</p>
<pre><code>from typing import MutableSequence, T
def comparison_sort(s: MutableSequence[T]) -> None:
pass
</code></pre>
<p>How... | 0 | 2016-06-07T01:38:19Z | 37,669,538 | <p>As noted in the comments, <code>Comparable</code> isn't a state of being, it's only meaningful as a descriptor for a pair of types. Usually, a sorting function is working with homogeneous types though, so as long as you don't mind the type checker only handling the concept of "supports <code><</code> with some ty... | 2 | 2016-06-07T02:22:32Z | [
"python",
"python-3.x"
] |
Export to CSV separating all chars into fields | 37,669,256 | <p>I'm having a little trouble with a python script that I'm writing to audit all the CSV files from my firm's many disparate applications, and I have it nearly done with a proof of concept to bring to the boss, AND show off what I can do with python, but the issue is that I don't understand the CSV class in python all... | 0 | 2016-06-07T01:43:51Z | 37,669,344 | <p>as is, your write rows method is generated comma separated values (.csv)</p>
<blockquote>
<p>The csv module doesnât directly support reading and writing Unicode,
but it is 8-bit-clean save for some problems with ASCII NUL
characters. So you can write functions or classes that handle the
encoding and decod... | 0 | 2016-06-07T01:54:41Z | [
"python",
"python-3.x",
"csv",
"export-to-csv"
] |
Export to CSV separating all chars into fields | 37,669,256 | <p>I'm having a little trouble with a python script that I'm writing to audit all the CSV files from my firm's many disparate applications, and I have it nearly done with a proof of concept to bring to the boss, AND show off what I can do with python, but the issue is that I don't understand the CSV class in python all... | 0 | 2016-06-07T01:43:51Z | 37,669,447 | <p>The problem is each item in <code>computers</code> is a string, and strings in Python are sequences of characters, so <code>writer.writerow()</code> thinks each character is a separate field. To fix that you need to first <code>split</code> each string into fields based on where the commas are in it:</p>
<pre><code... | 0 | 2016-06-07T02:11:05Z | [
"python",
"python-3.x",
"csv",
"export-to-csv"
] |
Export to CSV separating all chars into fields | 37,669,256 | <p>I'm having a little trouble with a python script that I'm writing to audit all the CSV files from my firm's many disparate applications, and I have it nearly done with a proof of concept to bring to the boss, AND show off what I can do with python, but the issue is that I don't understand the CSV class in python all... | 0 | 2016-06-07T01:43:51Z | 37,669,460 | <p>The CSV writer function, <code>writerow</code>, takes a list as the input and writes each element to the row. When you pass a single string into the function, the writer interprets the string as a list of characters. </p>
<p>I am assuming that you want to write each row as is appears in the string. So instead of us... | 0 | 2016-06-07T02:12:52Z | [
"python",
"python-3.x",
"csv",
"export-to-csv"
] |
Querying on optional parameters | 37,669,263 | <p>Suppose I have a user table with age and name columns. I would like to write a function to query this table, either selecting everything, or selecting based on age. Naively I might do</p>
<pre><code>def query(age=''):
query_args = ' WHERE {}'.format(age) if age else ''
db.execute('SELECT * FROM users' + que... | 1 | 2016-06-07T01:44:38Z | 37,680,721 | <p>You are right in that building a query string is a terrible idea. This problem is not a driver one. It is just SQL:</p>
<pre><code>query = """
select *
from users
where
(%(age)s is null or %(age)s = age)
and
(%(name)s is null or %(name)s = name)
"""
parameters = dict(name = None,... | 1 | 2016-06-07T13:25:30Z | [
"python",
"postgresql",
"psycopg2"
] |
How to install Scrapy on Unbuntu 16.04? | 37,669,290 | <p>I followed <a href="http://doc.scrapy.org/en/master/topics/ubuntu.html#topics-ubuntu" rel="nofollow">the official guide</a>, but got this error message:</p>
<pre><code>The following packages have unmet dependencies:
scrapy : Depends: python-support (>= 0.90.0) but it is not installable
Recommends: python-s... | 0 | 2016-06-07T01:47:33Z | 37,677,910 | <p>You should be good with:</p>
<pre><code>apt-get install -y \
python3 \
python-dev \
python3-dev
# for cryptography
apt-get install -y \
build-essential \
libssl-dev \
libffi-dev
# for lxml
apt-get install -y \
libxml2-dev \
libxslt-dev
# install pip
apt-get install -y python-pip
<... | 1 | 2016-06-07T11:17:32Z | [
"python",
"ubuntu",
"scrapy",
"python-3.5",
"ubuntu-16.04"
] |
Python TCP Server Stops Responding After A While | 37,669,323 | <p>So I wrote this python code on my RPI to create a digital poster that talks with my crestron control processor. For some reason my code stops responding after a while. I dont know why. <strike>I dont know if my Pi is going to sleep but if anyone could point out anything in my code that could cause this please let me... | -1 | 2016-06-07T01:52:55Z | 38,414,013 | <p>I was creating a new FBI process every time i went through the loop, and i ended up using up all of the Pi's RAM until it came to a halt because it didnt have any left. I now kill the FBI process after loading the image which fixed that. Thanks for everyones help.</p>
<p>I also figured out some other things that ma... | 0 | 2016-07-16T17:57:26Z | [
"python",
"raspberry-pi",
"tcpsocket"
] |
Count the frequency of occurrence of a certain row | 37,669,335 | <p>Suppose I have a data frame with 3 columns as</p>
<pre><code> date amount type
0 20160101 50 apple
1 20160101 50 apple
2 20160101 50 banana
3 20160102 30 apple
4 20160102 50 apple
5 20160102 40 banana
6 201601... | 0 | 2016-06-07T01:53:52Z | 37,669,571 | <p>Here's a hack that will get you your answer. I feel like there needs to be a more direct way though</p>
<pre><code>df['times'] = 1
df.groupby(['Date', 'Amount', 'Type'], as_index=False).sum()
</code></pre>
<p>EDIT:</p>
<p>found a second solution (you need to rename the column</p>
<pre><code>df.groupby(['date','t... | 1 | 2016-06-07T02:26:33Z | [
"python",
"pandas"
] |
Count the frequency of occurrence of a certain row | 37,669,335 | <p>Suppose I have a data frame with 3 columns as</p>
<pre><code> date amount type
0 20160101 50 apple
1 20160101 50 apple
2 20160101 50 banana
3 20160102 30 apple
4 20160102 50 apple
5 20160102 40 banana
6 201601... | 0 | 2016-06-07T01:53:52Z | 37,670,459 | <pre><code>>>> df.groupby(['date', 'amount', 'type']).size().reset_index()
date amount type 0
0 20160101 50 apple 2
1 20160101 50 banana 1
2 20160102 30 apple 1
3 20160102 40 banana 2
4 20160102 50 apple 1
</code></pre>
<p>or you can use <a href="http://p... | 1 | 2016-06-07T04:24:43Z | [
"python",
"pandas"
] |
Unable to find vcvarsall.bat(while installing scikit-image: pip) | 37,669,376 | <p>I am trying to install pylab in windows python
But half-way down while installing scikit-image I got the error-message: </p>
<blockquote>
<p>Setup script exited with error: Unable to find vcvarsall.bat</p>
</blockquote>
<p>I tried to fix it by installing Visual C++ compiler package but it did not fix it
Please s... | 1 | 2016-06-07T01:59:20Z | 37,671,901 | <p>You can download a wheel of <code>scikit-image</code> from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-image" rel="nofollow">here</a> which allows you bypass installation with <code>vcvarsall.bat</code>. Install by doing:</p>
<pre><code> pip install scikit_image-*.whl
</code></pre>
<p>Be sure to sel... | 0 | 2016-06-07T06:22:42Z | [
"python",
"pip"
] |
Error in installation pycurl 7.19.0 | 37,669,428 | <p>I need install this specific version (7.19.0) pycurl.</p>
<p>When I try to install with this command:</p>
<blockquote>
<p>pip install pycurl==7.19.0</p>
</blockquote>
<p>I'm receiving this error.</p>
<blockquote>
<p>Failed building wheel for pycurl Running setup.py clean for pycurl
Failed to build pycurl... | 4 | 2016-06-07T02:08:16Z | 38,080,358 | <p>I had the same error and was unable to find a way to install <code>pycurl==7.19.0</code> on Ubuntu 16.04. I instead switched to <code>pycurl==7.43.0</code> and pip installed it just fine.</p>
| 0 | 2016-06-28T15:27:07Z | [
"python",
"ubuntu",
"installation",
"pip",
"pycurl"
] |
Python 3.5 : TypeError: __init__() got an unexpected keyword argument 'nosigint' | 37,669,435 | <p>I am using Python 3.5 to do doctest. There is always an error:</p>
<pre><code> File "D:\Program Files\Anaconda\lib\doctest.py", line 357, in __init__
pdb.Pdb.__init__(self, stdout=out, nosigint=True)
TypeError: __init__() got an unexpected keyword argument 'nosigint'
</code></pre>
<p>It seems that the error ... | 3 | 2016-06-07T02:09:20Z | 37,746,859 | <p>It looks like you are using the Anaconda Python distribution.</p>
<p>Are you running using the Spyder IDE?</p>
<p>There is an <a href="https://github.com/spyder-ide/spyder/issues/1855" rel="nofollow">open bug</a> in Spyder's issue tracker.</p>
<p>The suggested work-around involves modifying the source of <code>pd... | 1 | 2016-06-10T11:16:09Z | [
"python"
] |
How do I sort a list by specific characters within each element? | 37,669,474 | <p>I have been asked to define a function that sorts a list based on file extension..</p>
<p>I understand sorting, but I don't understand how to start the sort from the "." character.</p>
<p>I want the following result:</p>
<pre><code>>>> extsort(['a.c', 'a.py', 'b.py', 'bar.txt', 'foo.txt', 'x.c'])
['a.c',... | 0 | 2016-06-07T02:14:17Z | 37,669,510 | <p>You can pass key function as a parameter for <a href="https://docs.python.org/2/library/functions.html#sorted" rel="nofollow"><code>sorted</code></a>:</p>
<pre><code>>>> l = ['a.c', 'a.py', 'b.py', 'bar.txt', 'foo.txt', 'x.c']
>>> sorted(l, key=lambda x: splitext('.')[1])
['a.c', 'a.py', 'b.py', '... | 4 | 2016-06-07T02:19:00Z | [
"python",
"list",
"function",
"sorting",
"sorted"
] |
How do I sort a list by specific characters within each element? | 37,669,474 | <p>I have been asked to define a function that sorts a list based on file extension..</p>
<p>I understand sorting, but I don't understand how to start the sort from the "." character.</p>
<p>I want the following result:</p>
<pre><code>>>> extsort(['a.c', 'a.py', 'b.py', 'bar.txt', 'foo.txt', 'x.c'])
['a.c',... | 0 | 2016-06-07T02:14:17Z | 37,669,640 | <p>For a solution that works even if some of the files don't have extensions (and is somewhat more self-documenting), use <a href="https://docs.python.org/3/library/os.path.html#os.path.splitext" rel="nofollow"><code>os.path.splitext</code></a> as part of <a href="https://docs.python.org/3/library/functions.html#sorted... | 3 | 2016-06-07T02:37:21Z | [
"python",
"list",
"function",
"sorting",
"sorted"
] |
Python real-time updating plot with multiple (configurable) figures and multiple (configurable) subplots | 37,669,484 | <p>I'm basically trying to create a configurable number of figures and a configurable number of subplots on each figure. And then go retrieve data once a minute or so and update those plots.</p>
<p>If I do plot.show() the plot comes up and seems to wait for the figures to be close before executing any other lines of c... | 1 | 2016-06-07T02:15:21Z | 37,669,780 | <p>Your design is getting stuck because you are trying to do 2 tasks in 1 thread: showing a GUI, and updating the background data for it. A GUI in python takes an entire thread to run itself, which is why your program stops, or "<strong>blocks</strong>" continuing on when you call this function. What you need to do is... | 2 | 2016-06-07T02:55:17Z | [
"python",
"matplotlib",
"jquery-animate"
] |
How to run a cancellable function when a new Tkinter window opens | 37,669,517 | <p>In tkinter, I would like to create the following:</p>
<p>When the button foo is pressed, the function foo begins running immediately. A new window will pop up with a a "cancel" button that lets the user terminate the process midway through (as my actual process can take up to 30 minutes). If foo runs to completion,... | 3 | 2016-06-07T02:19:35Z | 37,688,044 | <p>Perhaps you are looking for something like this:</p>
<pre><code>from tkinter import ttk, messagebox, Toplevel, Tk
import time
import multiprocessing
def foo():
for i in range(100):
print(i)
time.sleep(0.1)
class ProcessWindow(Toplevel):
def __init__(self, parent, process):
Toplevel... | 1 | 2016-06-07T19:46:19Z | [
"python",
"python-3.x",
"tkinter",
"python-multiprocessing"
] |
python logger, disable log for some modules | 37,669,602 | <p>Is it possible to disable logs for some modules in my project? I have this log_config.ini:</p>
<pre><code>[loggers]
keys=root
[handlers]
keys=stream_handler
[formatters]
keys=formatter
[logger_root]
level=DEBUG
handlers=stream_handler
[handler_stream_handler]
class=StreamHandler
level=INFO
formatter=formatter
a... | -1 | 2016-06-07T02:31:36Z | 37,669,765 | <pre><code>[logger_modulename]
handlers=null_handler
propagate=0
qualname=modulename
level=NOTSET
[handler_null_handler]
class=NullHandler
level=NOTSET
</code></pre>
<p>Do not forget to add <code>null_handler</code> and <code>modulename</code> under <code>handler</code> and <code>loggers</code> sections.</p>
| 0 | 2016-06-07T02:53:51Z | [
"python",
"logging"
] |
Display table when ng-click based on the id | 37,669,620 | <p>I have the following angular script, its does nothing but create a list of objects:</p>
<pre><code>//To get the existing records
$scope.get_records = function(){
filter_data = {set__iexact: $scope.final_data.set};
bin.get(filter_data,
function(data){
$scope.main_list = data['objects'];
c... | 1 | 2016-06-07T02:34:49Z | 37,670,694 | <p>You must add: </p>
<p>0 - The Filter: A second row will have the ID of other elements to filter, in my case will be father row.</p>
<pre><code><tr align="center" ng-repeat="f in main_list" ng-cloak>
</code></pre>
<p>Will change to </p>
<pre><code><tr align="center" ng-repeat="f in main_list | filter:{f... | 0 | 2016-06-07T04:47:14Z | [
"javascript",
"python",
"html",
"angularjs",
"django"
] |
OpenCV (Python) video subplots | 37,669,622 | <p>I am trying to show two OpenCV video feeds in the same figure as subplots, but couldn't find how to do it. When I try using <code>plt.imshow(...), plt.show()</code>, the window won't even appear. When I try using <code>cv2.imshow(...)</code>, it shows two independent figures. What I actually want are subplots :(. An... | 2 | 2016-06-07T02:35:17Z | 37,670,023 | <p>You may simply use the <code>cv2.hconcat()</code> method to horizontally join 2 images and then display using imshow, But keep in mind that the images must be of same <strong>size</strong> and <strong>type</strong> for applying <code>hconcat</code> on them.</p>
<p>You may also use <code>vconcat</code> to join the i... | 2 | 2016-06-07T03:31:03Z | [
"python",
"opencv",
"matplotlib",
"subplot"
] |
Python matrix represented as (40000,) | 37,669,714 | <p>I have seen and executed a python program where a matrix has been sliced into a column vector using <code>a[:,j]</code> and passed into a function. The column vector has dimensions <code>40000x1</code>. While tracing the output, I printed the dimensions of <code>a</code> in the function and it printed <code>(40000,)... | 3 | 2016-06-07T02:48:44Z | 37,669,840 | <p>I am assuming that you are referring to the <a href="https://docs.scipy.org/doc/numpy-dev/user/quickstart.html" rel="nofollow"><code>numpy</code></a> package. There are other array packages available for Python, but that seems to be the most popular one.</p>
<p><code>numpy</code> deals with multidimensional arrays,... | 1 | 2016-06-07T03:02:22Z | [
"python",
"numpy",
"matrix"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.