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 |
|---|---|---|---|---|---|---|---|---|---|
what is the order of the dictionary in python | 38,514,915 | <p>I have a question about the order of the dictionary in python. I am in python 2.7</p>
<pre><code>array ={"dad":"nse","cat":"error","bob":"das","nurse":"hello"}
for key in array:
print key
</code></pre>
<p>why result shows </p>
<pre><code>dad
bob
nurse
cat
</code></pre>
<p>NOT</p>
<pre><code>dad
cat
bob
nu... | -4 | 2016-07-21T21:47:58Z | 38,514,945 | <p>According to the <a href="https://docs.python.org/2/library/collections.html" rel="nofollow">Python documentation</a>, there is no ordering to the elements in a dictionary. Python can return the entries to you in whatever order it chooses. If you want a dictionary with order, you can use an <a href="https://docs.pyt... | 0 | 2016-07-21T21:50:03Z | [
"python",
"python-2.7",
"dictionary"
] |
what is the order of the dictionary in python | 38,514,915 | <p>I have a question about the order of the dictionary in python. I am in python 2.7</p>
<pre><code>array ={"dad":"nse","cat":"error","bob":"das","nurse":"hello"}
for key in array:
print key
</code></pre>
<p>why result shows </p>
<pre><code>dad
bob
nurse
cat
</code></pre>
<p>NOT</p>
<pre><code>dad
cat
bob
nu... | -4 | 2016-07-21T21:47:58Z | 39,764,611 | <p>Yes, I agree, dictionary is an independent data structure, which means it always live its life :) , but check out this example:</p>
<pre><code>from collections import OrderedDict
days = {"Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5}
print days
sorted_days = OrderedDict(sorted(days.items(), ... | 0 | 2016-09-29T08:00:27Z | [
"python",
"python-2.7",
"dictionary"
] |
Django - Stream request from external site as received | 38,514,919 | <p>How can Django be used to fetch data from an external API, triggered by a user request, and stream it directly back in the request cycle without (or with progressive/minimal) memory usage?</p>
<p><strong>Background</strong></p>
<p>As a short-term solution to connect with externally hosted micro-services, there is ... | 1 | 2016-07-21T21:48:35Z | 38,515,948 | <pre><code>import requests
from django.http import StreamingHttpResponse
def api_gateway_portal(request, path=''):
url = 'http://some.ip.address/%s?api_key=12345678901234567890' % (path,)
r = requests.get(url, stream=True)
response = StreamingHttpResponse(
(chunk for chunk in r.iter_content(512 *... | 1 | 2016-07-21T23:28:08Z | [
"python",
"django",
"python-requests"
] |
JSON formatted string to pandas dataframe | 38,514,984 | <p>OK, I have been beating my head against the wall with this one all afternoon. I know that there are many similar posts, but I keep getting errors and am probably making a stupid mistake. </p>
<p>I am using the <code>apyori</code> package found here to do some transaction basket analysis: <a href="https://pypi.pytho... | 0 | 2016-07-21T21:54:02Z | 38,515,465 | <p>I would suggest reading up on StackOverflow's guidelines on producing a <a href="http://stackoverflow.com/help/mcve">Minimal, Complete, and Verifiable example</a>. Also, statements like "I keep getting errors" are not very helpful. That said, I took a look at your code and the source code for this <code>apyori</cod... | 1 | 2016-07-21T22:36:52Z | [
"python",
"json",
"apriori"
] |
Binning Pandas column values by standard deviation centered on average? | 38,515,023 | <p>I have a Pandas data frame with a bunch of values in sorted order:</p>
<pre><code>df = pd.DataFrame(np.arange(1,21))
</code></pre>
<p>I want to end up with a list/array like this:</p>
<pre><code>[0,1.62,4.58,7.54,10.5,13.45,16.4,19.37,20]
</code></pre>
<p>The first and last element are <code>df.min()</code> and ... | 3 | 2016-07-21T21:57:16Z | 38,515,202 | <p><code>mu_sig</code> calculates various multiples of standard deviations by multiplying <code>[-2, -1, 0, 1, 2]</code> by sigma. </p>
<p><code>edges</code> takes a series and gets <code>mu_sig</code> results. Then checks to see that the series minimum is less then minimum multiple of standard deviation less the mea... | 2 | 2016-07-21T22:12:45Z | [
"python",
"numpy",
"pandas",
"dataframe",
"vectorization"
] |
Pyspark: Create histogram for each key in Pair RDD | 38,515,025 | <p>I'm new to pyspark. I have a Pair RDD (key, value). I would like to create a histogram of n buckets for each key. The output would be something like this:</p>
<pre><code>[(key1, [...buckets...], [...counts...]),
(key2, [...buckets...], [...counts...])]
</code></pre>
<p>I have seen examples for retrieving the max ... | 0 | 2016-07-21T21:57:21Z | 38,516,154 | <p>Try:</p>
<pre><code>>>> import numpy as np
>>>
>>> rdd.groupByKey().map(lambda (x, y): np.histogram(list(y)))
</code></pre>
| 0 | 2016-07-21T23:58:01Z | [
"python",
"apache-spark",
"histogram",
"pyspark",
"rdd"
] |
Python: Reading input when finished typing | 38,515,138 | <p>I am writing a python script which is going to take use of input from a barcode scanner. As it stands, the barcode scanner acts as a keyboard, writing the scanned code into the console (such a code may for ex. be: 123456789). Is there a way to automatically read the inputted code when the scanner is finished writing... | 0 | 2016-07-21T22:07:24Z | 38,515,272 | <p>Reading the input with <code>raw_input</code> will not work because it waits for the user hitting the return button. However, <code>sys.stdin.read()</code> reads single characters from the standard input. Use this function and check if the characters that were already entered are as many as you expect.</p>
<p>Infor... | 0 | 2016-07-21T22:18:52Z | [
"python"
] |
communication of a value in streaming between python and c++ | 38,515,166 | <p>I have a script in C++ done by someone else which is doing online (realtime) analysis from video. In the running code there is a switch case. Each case depend of what is detect in the online video analysis, the frequency of event should be close to 20Hz.</p>
<p>Inside each "case" I would like to send "something" to... | 0 | 2016-07-21T22:09:18Z | 39,276,210 | <p>I found a way using "pipe" in a shell script :</p>
<pre><code>./scriptc++ | ./script2.py
</code></pre>
<p>the standard output of my C++ a redirected to the standard input of my puthon script
It work !</p>
| 0 | 2016-09-01T16:03:38Z | [
"python",
"c++",
"real-time",
"communication"
] |
How to make a staggered nested loop using list comprehensions in Python | 38,515,426 | <p>I have an array.</p>
<p>I want to output an array of arrays, where each inner array contains values that represent the numerical distance of each element to the elements after it.</p>
<p>So in better terms, I want to turn [1, 2, 3] into <code>[[1, 2], [1], []]</code>. If I was doing this in Javascript, it would be... | 0 | 2016-07-21T22:32:45Z | 38,515,479 | <p>How about</p>
<pre><code>[[abs(y-x) for y in thearray[idx+1:]] for idx, x in enumerate(thearray)]
</code></pre>
| 1 | 2016-07-21T22:38:31Z | [
"python",
"arrays",
"list-comprehension",
"nested-loops"
] |
Pickle dump Pandas DataFrame | 38,515,433 | <p>This is a question from a lazy man.</p>
<p>I have 4 million rows of pandas DataFrame and would like to save them into smaller chunks of pickle files. </p>
<p>Why smaller chunks?
To save/load them quicker.</p>
<p>My question is:
1) Is there a better way (in-built function) to save them in smaller pieces than manu... | 2 | 2016-07-21T22:33:30Z | 38,515,510 | <p>If the goal is to save and load quickly you should look into <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html" rel="nofollow">using sql</a> rather than raw text pickling. If your computer chokes when you ask it to write 4 million rows you can specify a chunk size.</p>
<p>F... | 2 | 2016-07-21T22:41:14Z | [
"python",
"pandas",
"dataframe",
"pickle"
] |
Pickle dump Pandas DataFrame | 38,515,433 | <p>This is a question from a lazy man.</p>
<p>I have 4 million rows of pandas DataFrame and would like to save them into smaller chunks of pickle files. </p>
<p>Why smaller chunks?
To save/load them quicker.</p>
<p>My question is:
1) Is there a better way (in-built function) to save them in smaller pieces than manu... | 2 | 2016-07-21T22:33:30Z | 38,515,583 | <p>I've been using this for a dataframe of size 7,000,000 x 250</p>
<p>Use hdfs <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_hdf.html" rel="nofollow">DOCUMENTATION</a></p>
<pre><code>df = pd.DataFrame(np.random.rand(5, 5))
df
</code></pre>
<p><a href="http://i.stack.imgur.com/7x... | 2 | 2016-07-21T22:48:42Z | [
"python",
"pandas",
"dataframe",
"pickle"
] |
Python Encoding Issue with JSON and CSV | 38,515,447 | <p>I am having an encoding issue when I run my script below:
Here is the error code:
-UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 9: ordinal not in range(128)</p>
<p>Here is my script:</p>
<pre><code>import logging
import urllib
import csv
import json
import io
import codecs
with ope... | 1 | 2016-07-21T22:34:53Z | 38,515,617 | <p>Looks like you are using Python 2.x, instead of python's standard open, use codecs.open where you can optionally pass an encoding to use and what to do when there are errors. Gets a little less confusing in Python 3 where the standard Python open can do this.</p>
<p>So in your two lines where you are opening, do:<... | 1 | 2016-07-21T22:52:50Z | [
"python",
"json",
"csv",
"utf-8"
] |
How Do I Authenticate OneNote Without Opening Browser? | 38,515,700 | <p>I want to create a python script that will allow me to upload files to OneNote via command line. I have it working perfectly and it authenticates fine. However, everytime it goes to authenticate, it has to open a browser window. (This is because authentication tokens only last an hour with OneNote, and it has to use... | 2 | 2016-07-21T23:01:10Z | 38,515,902 | <p>If this is always with the same account - you can make the "browser opening and password typing" a one time setup process. Once you've authenticated, you have the "access token" and the "refresh token". You can keep using the access token for ~1hr. Once it expires, you can use the "refresh token" to exchange it for ... | 0 | 2016-07-21T23:22:56Z | [
"python",
"authentication",
"terminal",
"onenote",
"onenote-api"
] |
How Do I Authenticate OneNote Without Opening Browser? | 38,515,700 | <p>I want to create a python script that will allow me to upload files to OneNote via command line. I have it working perfectly and it authenticates fine. However, everytime it goes to authenticate, it has to open a browser window. (This is because authentication tokens only last an hour with OneNote, and it has to use... | 2 | 2016-07-21T23:01:10Z | 38,516,911 | <p>You don't need a browser to refresh the token, that can be done by just a simple http request: <a href="https://msdn.microsoft.com/en-us/office/office365/howto/onenote-auth#get-new-access-token-msa" rel="nofollow">https://msdn.microsoft.com/en-us/office/office365/howto/onenote-auth#get-new-access-token-msa</a></p>
| 0 | 2016-07-22T01:40:18Z | [
"python",
"authentication",
"terminal",
"onenote",
"onenote-api"
] |
Can't run matplotlib with cmd | 38,515,781 | <p>I wanted to make some graphs with <code>matplot</code>, I installed it with <code>pip install matlotlib</code>, I ran a few commands in <code>python.exe</code>, everything was working fine, I got the graph but then I made a script file <code>hello_matplot.py</code> I launched it through the <code>cmd</code> and I go... | 0 | 2016-07-21T23:09:02Z | 38,515,814 | <p>U need to make sure you are using the full file path in cmd... C:/file.py <em>EXAMPLE</em></p>
<p>When trying to find matplotlib, you can always go to your environment variables in system control panel to find the library...</p>
| 1 | 2016-07-21T23:12:38Z | [
"python",
"matplotlib"
] |
scipy.signal's convolve isn't convolving the way it should | 38,515,782 | <p>I'd like to discuss a little bit on convolution as applied to CNNs and image filtering... If you have an RGB image (dimensions of say <code>3xIxI</code>) and <code>K</code> filters, each of size <code>3xFxF</code>, then you would end up with a <code>Kx(I - F + 1)x(I - F + 1)</code> output, assuming your stride is <c... | 0 | 2016-07-21T23:09:09Z | 38,516,537 | <p>You wrote:</p>
<blockquote>
<p>... the same as this:</p>
</blockquote>
<pre><code>I -> 3x5x5 matrix
F -> 3x2x2 matrix
(I[0] * F[0]) + (I[1] * F[1]) + (I[2] * F[2]) -> 1x4x4 matrix
</code></pre>
<p>You have forgotten that convolution <em>reverses</em> one of the arguments. So the above is not true. In... | 3 | 2016-07-22T00:49:14Z | [
"python",
"numpy",
"scipy",
"convolution"
] |
Can anyone explain this error [AttributeError: 'DataFrame' object has no attribute 'to_numeric'] | 38,515,783 | <p>I'm tryting to change the salaries to the intergers so I can then do some analysis and make a chart of their price per pitch. When I try to do this it says that the dataframe doesnt have the attribute to_numeric. I got the code of the API DOCs so I was wondering what is happening. Is it a list of DataFrames or somet... | 1 | 2016-07-21T23:09:20Z | 38,515,823 | <p>The manner of calling the function involves using the module and then passing in the column of the <code>DataFrame</code> you want to modify, like so:</p>
<pre><code>pd.to_numeric(df3.Avg_Annual)
</code></pre>
<p>You'll get another error because the module can't convert dollar signs and commas to numeric. Try this... | 2 | 2016-07-21T23:12:55Z | [
"python",
"pandas"
] |
Input problems in cmd | 38,515,870 | <p>I'm having a problem where if I run my python program in the windows terminal, text with inserted variables (<code>%s</code>) have wacky results, where as in the python shell it works fine.</p>
<p>Code:</p>
<pre><code>print("Hi! What's your name?")
name = input("name: ")
print("Nice to meet you %s" % name)
print("... | 0 | 2016-07-21T23:18:37Z | 38,519,790 | <p>This is a bug in the original 3.2.0 on Windows. The <code>input()</code> statement stripped off the "\n" but not the '\r', so the string input is hidden. </p>
<p>See <a href="https://bugs.python.org/issue11272" rel="nofollow">https://bugs.python.org/issue11272</a> </p>
<p>Quick fix:</p>
<pre><code>name = input("... | 0 | 2016-07-22T06:40:49Z | [
"python",
"shell",
"python-3.x",
"input",
"cmd"
] |
Django Multiple select field validation | 38,515,921 | <p>The problem is that I have a couple of Multiple select fields in my form class and they cannot pass <em>is_valid</em> method in a view.py.</p>
<p><strong>Forms.py</strong></p>
<pre><code>class SearchForm(forms.Form) :
LIMIT_OPTIONS = (('5', '5'),
('10', '10'),
('15', '15'),
... | 1 | 2016-07-21T23:24:50Z | 38,516,023 | <p>The default widget for MultipleChoiceField is <a href="https://docs.djangoproject.com/en/1.9/ref/forms/widgets/#selectmultiple" rel="nofollow">SelectMultiple</a>.</p>
<blockquote>
<p>Similar to Select, but allows multiple selection: ...</p>
</blockquote>
<p>You have changed that in your form to <code>forms.Selec... | 1 | 2016-07-21T23:39:37Z | [
"python",
"django",
"select",
"view"
] |
Django Multiple select field validation | 38,515,921 | <p>The problem is that I have a couple of Multiple select fields in my form class and they cannot pass <em>is_valid</em> method in a view.py.</p>
<p><strong>Forms.py</strong></p>
<pre><code>class SearchForm(forms.Form) :
LIMIT_OPTIONS = (('5', '5'),
('10', '10'),
('15', '15'),
... | 1 | 2016-07-21T23:24:50Z | 38,516,340 | <p>So, if you want to have Drop Down Select Field in you forms.py and <a href="https://docs.djangoproject.com/en/1.9/ref/forms/widgets/#select" rel="nofollow">Widget - Select</a> does not pass validation (<code>is_valid</code> method)</p>
<pre><code>class SearchForm(forms.Form) :
LIMIT_OPTIONS = (('5', '5'),
... | 0 | 2016-07-22T00:22:23Z | [
"python",
"django",
"select",
"view"
] |
django how to download a file from the internet | 38,515,929 | <p>I want to have a user input a file URL and then have my django app download the file from the internet. </p>
<p>My first instinct was to call wget inside my django app, but then I thought there may be another way to get this done. I couldn't find anything when I searched. Is there a more django way to do this?</p>
| 0 | 2016-07-21T23:26:05Z | 38,516,104 | <p>You are not really dependent on Django for this.
I happen to like using <code>requests</code> library.
<br>
Here is an example:</p>
<pre><code> import requests
def download(url, path, chunk=2048):
req = requests.get(url, stream=True)
if req.status_code == 200:
with open(path, 'wb... | 2 | 2016-07-21T23:50:57Z | [
"python",
"django"
] |
django how to download a file from the internet | 38,515,929 | <p>I want to have a user input a file URL and then have my django app download the file from the internet. </p>
<p>My first instinct was to call wget inside my django app, but then I thought there may be another way to get this done. I couldn't find anything when I searched. Is there a more django way to do this?</p>
| 0 | 2016-07-21T23:26:05Z | 38,516,563 | <p>You can use urlopen from urllib2 like in this example:</p>
<pre><code>import urllib2
pdf_file = urllib2.urlopen("http://www.example.com/files/some_file.pdf")
with open('test.pdf','wb') as output:
output.write(pdf_file.read())
</code></pre>
<p>For more information, read the <a href="https://docs.python.org/2/li... | 1 | 2016-07-22T00:52:31Z | [
"python",
"django"
] |
Flask Sijax handling callbacks in @app.before_request | 38,515,970 | <p>I have callbacks in @app.before_request in my Flask application.</p>
<pre><code>@app.before_request
def before_request():
def alert(response):
response.alert('Message')
if g.sijax.is_sijax_request:
g.sijax.register_callback('alert', alert)
return g.sijax.process_request()
</code></pre>
<p>The rea... | 0 | 2016-07-21T23:32:12Z | 38,571,016 | <p>Register your default callback in the after_request event and check if the <code>_callback</code> dictionary is empty, if so, register the default callback else pass on the existing response.</p>
<pre><code>import os
from flask import Flask, g, render_template_string
import flask_sijax
path = os.path.join('.', os.... | 1 | 2016-07-25T14:52:37Z | [
"python",
"ajax",
"flask",
"sijax"
] |
Ignoring a key when looping through a sorted dictionary in Python | 38,515,977 | <p>I have a dictionary in python and I'm assigning elements to an array utilizing a key with four elements. I want to plot my arrays by looping through my sorted dictionary but I'd like to ignore one of the keys in the loop. My code looks like this:</p>
<pre><code>key = (process, temp, board, chip)
#Do some stu... | -3 | 2016-07-21T23:33:09Z | 38,516,006 | <p>If you're not worried about speed I would just check whether or not you are at an acceptable key in the loop. You can directly check against one value you want to skip or make a list of values you want to skip</p>
<pre><code>ignore_list = [chip]
for key in sorted(svmDict):
if key not in ignore_list:
#do... | 0 | 2016-07-21T23:36:45Z | [
"python",
"sorting",
"dictionary"
] |
Setting windows system PATH in Registry via Python winreg | 38,516,044 | <p>I've written a program to add directories to the PATH variable via the registry, either the HKCU(user) or HKLM(system) path, depending on an input option.</p>
<p><strong>It works fine when using the User path.</strong>
However, when setting the path for the System, Windows acts as if the path variable is empty, e.g... | 0 | 2016-07-21T23:42:22Z | 38,516,492 | <p>As in the comments, changing <code>REG_SZ</code> to <code>REG_EXPAND_SZ</code> did the trick, as variables using "%" weren't being recognized. This also works when no "%"s exist, so I use it for the user path as well rather than needing to switch between the two.</p>
<p><code>registry.SetValueEx(env_key,"Path",0,re... | 1 | 2016-07-22T00:43:27Z | [
"python",
"windows",
"registry"
] |
Having user sort list smallest to biggest | 38,516,138 | <p>So I'm making a code where it asks the user to to swap two places on the list until the list is from smallest to biggest. So it should look like this:</p>
<pre class="lang-none prettyprint-override"><code>Hello: Your current list is [6, 7, 8, 2 , 9, 10, 12, 15, 16, 17]
Please pick your first location -> 4
Ple... | -3 | 2016-07-21T23:54:38Z | 38,516,503 | <p>From what I could understand from your somewhat confusing explanation, I made this working script with some good coding conducts every beginner should learn when starting python and programming overall. The two first small functions are used to avoid code repetition, this way I can avoid aswell a too long main funct... | 1 | 2016-07-22T00:44:36Z | [
"python",
"python-3.x"
] |
ValueError: Cannot cast DatetimeIndex to dtype datetime64[us] | 38,516,251 | <p>I'm trying to create a PostgreSQL table of 30-minute data for the S&P 500 ETF
(spy30new, for testing freshly inserted data) from a table of several stocks with 15-minute data (all15). all15 has an index on 'dt' (timestamp) and 'instr' (stock symbol). I would like spy30new to have an index on 'dt'.</p>
<pre><cod... | 1 | 2016-07-22T00:08:30Z | 38,530,416 | <p>Using pd.to_datetime() on each element worked. Option 4, which doesn't work, applies pd.to_datetime() to the entire series. Perhaps the Postgres driver understands python datetime, but not datetime64. Option 4 produced the correct output, but I got ValueError (see title) when sending the DF to Postgres</p>
<pre><co... | 0 | 2016-07-22T15:36:27Z | [
"python",
"postgresql",
"pandas"
] |
pandas converting floats to strings without decimals | 38,516,316 | <p>I have a dataframe</p>
<pre><code>df = pd.DataFrame([
['2', '3', 'nan'],
['0', '1', '4'],
['5', 'nan', '7']
])
print df
0 1 2
0 2 3 nan
1 0 1 4
2 5 nan 7
</code></pre>
<p>I want to convert these strings to numbers and sum the columns and convert back to strin... | 4 | 2016-07-22T00:18:14Z | 38,516,323 | <p>Add a <code>astype(int)</code> in the mix:</p>
<pre><code>df.astype(float).sum().astype(int).astype(str)
0 7
1 4
2 11
dtype: object
</code></pre>
| 5 | 2016-07-22T00:19:22Z | [
"python",
"pandas"
] |
pandas converting floats to strings without decimals | 38,516,316 | <p>I have a dataframe</p>
<pre><code>df = pd.DataFrame([
['2', '3', 'nan'],
['0', '1', '4'],
['5', 'nan', '7']
])
print df
0 1 2
0 2 3 nan
1 0 1 4
2 5 nan 7
</code></pre>
<p>I want to convert these strings to numbers and sum the columns and convert back to strin... | 4 | 2016-07-22T00:18:14Z | 38,516,334 | <p>Add <code>astype(int)</code> right before conversion to a string:</p>
<pre><code>print (df.astype(float).sum().astype(int).astype(str))
</code></pre>
<p>Generates the desired result.</p>
| 1 | 2016-07-22T00:21:08Z | [
"python",
"pandas"
] |
pandas converting floats to strings without decimals | 38,516,316 | <p>I have a dataframe</p>
<pre><code>df = pd.DataFrame([
['2', '3', 'nan'],
['0', '1', '4'],
['5', 'nan', '7']
])
print df
0 1 2
0 2 3 nan
1 0 1 4
2 5 nan 7
</code></pre>
<p>I want to convert these strings to numbers and sum the columns and convert back to strin... | 4 | 2016-07-22T00:18:14Z | 39,482,489 | <p>Converting to <code>int</code> (i.e. with <code>.astype(int).astype(str)</code>) won't work if your column contains nulls; it's often a better idea to use string formatting to explicitly specify the format of your string column:</p>
<pre><code>In [52]: df.astype(float).sum().map(lambda x: "{:.0f}".format(x))
Out[52... | 1 | 2016-09-14T04:28:47Z | [
"python",
"pandas"
] |
Apply different decorators based on a condition | 38,516,426 | <p>I'm using unittest and nose-parametarized, and want to apply different decorators to a test based on a condition.</p>
<p>I have a test and I want to skip <code>unittest.skip</code> the test or execute it <code>@parameterized.expand(args)</code>based on the arguments passed to args.</p>
<p>I think I need to have an... | 0 | 2016-07-22T00:34:52Z | 38,516,676 | <p>A decorator can also be called as a function. <code>@decorator</code> is equivalent to <code>decorator(func)</code> and <code>@decorator(args)</code> to <code>decorator(args)(func)</code>. So you could return the value of those function returns conditionally in your decorator. Here is an example below:</p>
<pre><co... | 2 | 2016-07-22T01:06:22Z | [
"python",
"python-unittest",
"python-decorators",
"parameterized-unit-test",
"nose-parameterized"
] |
Trying to remove commas and dollars signs with Pandas in Python | 38,516,481 | <p>Tring to remove the commas and dollars signs from the columns. But when I do, the table prints them out and still has them in there. Is there a different way to remove the commans and dollars signs using a pandas function. I was unuable to find anything in the API Docs or maybe i was looking in the wrong place</p>
... | 4 | 2016-07-22T00:42:15Z | 38,516,583 | <p>You have to access the <code>str</code> attribute per <a href="http://pandas.pydata.org/pandas-docs/stable/text.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/text.html</a></p>
<pre><code>df1['Avg_Annual'] = df1['Avg_Annual'].str.replace(',', '')
df1['Avg_Annual'] = df1['Avg_Annual'].str.replace('... | 4 | 2016-07-22T00:56:01Z | [
"python",
"pandas"
] |
Variable not updating after sending data to cloud servers | 38,516,506 | <p>I have been having trouble with updating this global variable that is an array of strings. This <code>rfDataArray</code> is supposed to be updated as the rf data is coming in from another device. Now, when I have tested this <strong>without</strong> sending anything over to the cloud servers, it works (the <code>rfD... | 0 | 2016-07-22T00:44:59Z | 38,516,766 | <p>You are running into a race condition. The array is trying to store values before the cloud can send it back. You need to do the operations asynchronously. One solution is to use the callback methods from Python multithreading. Alternatively, you could use some 'locking' mechanism and not execute the rest of the pro... | 0 | 2016-07-22T01:17:51Z | [
"python",
"python-2.7",
"http",
"global-variables",
"cloud"
] |
Epoch Time and Time Zones | 38,516,524 | <p>Here's my problem, I have 2 times I'm feeding into Python, one in EST and other in GMT. I need to convert both to epoch and compare them. From what it's looking like when I convert the EST to epoch, it's should convert to the exact equivalent of GMT I thought. It doesn't look like it is:</p>
<pre><code>from datetim... | 0 | 2016-07-22T00:47:17Z | 38,516,735 | <p>So, I think you're confusing what epoch means here.
Epoch is a representation of time which counts the numbers of seconds from 1970/01/01 00:00:00 to a given a date.</p>
<p>Epoch conversion doesn't care about timezones and you can actually have negative epoch times with timezone conversion (play around at <a href="... | 0 | 2016-07-22T01:14:13Z | [
"python",
"date",
"time",
"epoch"
] |
Iterable error with int when using for / argument ()error while using map. Where am i going worng | 38,516,581 | <p>I tried bith ways using map nad using for loop but its not working i know for for loop it has to list,tuples or string. So how do i make this work</p>
<h1>1</h1>
<pre><code>def narcissistic(value):
x = ((value)== sum((c)**len(value) for c in list(value)))
return x
</code></pre>
<h1>2</h1>
<pre><code>def ... | -1 | 2016-07-22T00:55:44Z | 38,516,936 | <p>Your issue comes down to confusion about the type of your different objects. Python is a strongly typed language, so each object has a clear type at any given moment and the language generally won't convert anything to another type automatically for you.</p>
<p>Based on the error you're getting, you're calling your... | 0 | 2016-07-22T01:44:50Z | [
"python",
"python-2.7"
] |
Anti-Join Pandas | 38,516,664 | <p>I have two tables and I would like to append them so that only all the data in table A is retained and data from table B is only added if its key is unique (Key values are unique in table A and B however in some cases a Key will occur in both table A and B). </p>
<p>I think the way to do this will involve some sort... | 4 | 2016-07-22T01:05:11Z | 38,516,887 | <p>Consider the following dataframes</p>
<pre><code>TableA = pd.DataFrame(np.random.rand(4, 3),
pd.Index(list('abcd'), name='Key'),
['A', 'B', 'C']).reset_index()
TableB = pd.DataFrame(np.random.rand(4, 3),
pd.Index(list('aecf'), name='Key'),
... | 3 | 2016-07-22T01:38:11Z | [
"python",
"pandas",
"merge",
"anti-join"
] |
Anti-Join Pandas | 38,516,664 | <p>I have two tables and I would like to append them so that only all the data in table A is retained and data from table B is only added if its key is unique (Key values are unique in table A and B however in some cases a Key will occur in both table A and B). </p>
<p>I think the way to do this will involve some sort... | 4 | 2016-07-22T01:05:11Z | 38,520,623 | <p>You'll have both tables <code>TableA</code> and <code>TableB</code> such that both <code>DataFrame</code> objects have columns with unique values in their respective tables, but some columns may have values that occur simultaneously (have the same values for a row) in both tables. </p>
<p>Then, we want to merge the... | 1 | 2016-07-22T07:29:20Z | [
"python",
"pandas",
"merge",
"anti-join"
] |
Unable to get min value of DataFrame column with Pandas | 38,516,668 | <p>I'm trying to get the min value of values in a column of times. If I take a subset of the data I'm able to do it:</p>
<pre><code>print(df7.ix[3,'START_TIME'].min())
type(df7.ix[3,'START_TIME'].min())
</code></pre>
<p>output is returned correctly:</p>
<pre><code>09:17:09
str
</code></pre>
<p>But if I try on the e... | 2 | 2016-07-22T01:05:30Z | 38,516,864 | <p>It seems to me that you have both floats and strings in that one column.</p>
<p>See if this works:</p>
<pre><code>print(df7['START_TIME'].astype(str).min())
</code></pre>
<p>If it does, then you also have floats in that column. You want to find them and deal with them.</p>
<pre><code>my_floats_indices = [i for ... | 2 | 2016-07-22T01:35:10Z | [
"python",
"pandas",
"dataframe"
] |
Scipy sparse csr matrix returns nan on 0.0/1.0 | 38,516,694 | <p>I spotted an unexpected behavior in scipy.sparse.csr_matrix, which seems a bug to me. Can anyone confirm that this is not normal? I am not an expert in sparse structures so I may be misunderstanding proper usage.</p>
<pre><code>>>> import scipy.sparse
>>> a=scipy.sparse.csr_matrix((1,1))
>>&... | 3 | 2016-07-22T01:08:38Z | 38,518,128 | <p>For sparse matrix/sparse matrix, the </p>
<p>scipy/sparse/compressed.py</p>
<pre><code> if np.issubdtype(r.dtype, np.inexact):
# Eldiv leaves entries outside the combined sparsity
# pattern empty, so they must be filled manually. They are
# always nan, so that the matrix is completely fu... | 1 | 2016-07-22T04:24:30Z | [
"python",
"numpy",
"scipy",
"sparse-matrix"
] |
Filtering out abnormal shapes from a binary image in python opencv | 38,516,817 | <p>Any ideas for filters I could use to clean the following image up?
<a href="http://i.stack.imgur.com/giKri.png" rel="nofollow"><img src="http://i.stack.imgur.com/giKri.png" alt="enter image description here"></a></p>
<p>Perhaps something with a polygonal approximation?</p>
| 1 | 2016-07-22T01:26:33Z | 38,520,344 | <p>I've had a similar problem. Here is what I did:</p>
<ol>
<li>Small opening to clean the image from all the small useless patterns (not mandatory in your case)</li>
<li>Connected component labeling.</li>
<li>Separate each component</li>
<li>For each component, compute the geodesic diameter (<a href="http://imagej.ne... | 1 | 2016-07-22T07:13:23Z | [
"python",
"opencv",
"computer-vision",
"shape"
] |
Filtering out abnormal shapes from a binary image in python opencv | 38,516,817 | <p>Any ideas for filters I could use to clean the following image up?
<a href="http://i.stack.imgur.com/giKri.png" rel="nofollow"><img src="http://i.stack.imgur.com/giKri.png" alt="enter image description here"></a></p>
<p>Perhaps something with a polygonal approximation?</p>
| 1 | 2016-07-22T01:26:33Z | 38,554,220 | <p>You can use a shape descriptor that is rotation,scale and translation invariant like Hu moments.</p>
<p>Calculate the shape descriptor of the wanted shape from one image that you filtered manually (Form the image above just take the biggest connected component) </p>
<p>For each new image calculate the matchShapes ... | 0 | 2016-07-24T16:27:49Z | [
"python",
"opencv",
"computer-vision",
"shape"
] |
Regression Method Used in statsmodels adfuller()? | 38,516,846 | <p>What is the method of regression used in <code>adfuller()</code>? I'm performing an augmented dickey fuller test on a time series, and I'm trying two different ways of doing it.</p>
<p>First, I use <code>pandas.diff()</code> to get the change in price <code>dy</code>. Then I'm passing the original time series as an... | 0 | 2016-07-22T01:31:36Z | 38,517,928 | <p>This can be solved by setting the maxlag=1 in the input for adfuller()</p>
| 0 | 2016-07-22T03:59:36Z | [
"python",
"linear-regression",
"statsmodels",
"reversion"
] |
Oracle Python Use Select Result as Column Name in other select | 38,516,866 | <p>I am using cx oracle module in python. I have two tables that looks like this:</p>
<p>1st table:</p>
<pre><code>| parameter | context |
+--------------+------------+
| a | column_1 |
| b | column_2 |
</code></pre>
<p>2nd:</p>
<pre><code>|id| column_1 | column_2 |
+--+---... | 0 | 2016-07-22T01:35:32Z | 38,519,352 | <p>Use dynamic SQL to design a query in runtime and then EXECUTE IMMEDIATE clause.</p>
| 0 | 2016-07-22T06:12:55Z | [
"python",
"sql",
"oracle"
] |
Oracle Python Use Select Result as Column Name in other select | 38,516,866 | <p>I am using cx oracle module in python. I have two tables that looks like this:</p>
<p>1st table:</p>
<pre><code>| parameter | context |
+--------------+------------+
| a | column_1 |
| b | column_2 |
</code></pre>
<p>2nd:</p>
<pre><code>|id| column_1 | column_2 |
+--+---... | 0 | 2016-07-22T01:35:32Z | 38,519,388 | <blockquote>
<p>"the column_name is variable it can be column1 if parameter a but can be column2 if parameter b"</p>
</blockquote>
<p>Writing such a statement is not possible with regular SQL: you'll need to go dynamic and that means PL/SQL. <a href="https://docs.oracle.com/cloud/latest/db112/LNPLS/executeimmediate_... | 2 | 2016-07-22T06:14:46Z | [
"python",
"sql",
"oracle"
] |
With tkinter, how to add or remove Entries or Labels via optionmenu selection? | 38,516,921 | <p>I'm using tkinter. When a person using my program selects from a dropdown menu (created with <code>OptionMenu</code>), depending on what the selection is, I want <code>Entry</code> fields to appear. So if they select <code>a</code> from the menu, an <code>Entry</code> field should appear so they can enter a number l... | -1 | 2016-07-22T01:41:21Z | 38,530,687 | <blockquote>
<p>I think its not working because I am trying to create and edit Entries
within the function that is launched.</p>
</blockquote>
<p>What makes you think the function is launched? Your code gives a</p>
<pre><code>NameError: name 'optc' is not defined
</code></pre>
<p>when you try to create the firs... | -1 | 2016-07-22T15:51:56Z | [
"python",
"tkinter"
] |
Verify if an element of a list is in a string | 38,516,973 | <p>Verify if an element of a list is a a string</p>
<p>I have a list of key words:</p>
<pre><code>check_list = ['aaa','bbb','ccc']
</code></pre>
<p>And a group of strings:</p>
<pre><code>test_string_1 = 'hellor world ccc'
test_string_2 = 'hellor world 2'
</code></pre>
<p>And I want to verify if any of the element... | 2 | 2016-07-22T01:50:35Z | 38,517,006 | <p>If I understand right what you want, you can do:</p>
<pre><code>def test(check_list, test_string)
for key in check_list:
if key in test_string:
return True
return False
</code></pre>
<p>or in a single line you could do:</p>
<pre><code>any([key in test_string for key in check_list])
</c... | 3 | 2016-07-22T01:55:29Z | [
"python",
"string",
"list"
] |
Verify if an element of a list is in a string | 38,516,973 | <p>Verify if an element of a list is a a string</p>
<p>I have a list of key words:</p>
<pre><code>check_list = ['aaa','bbb','ccc']
</code></pre>
<p>And a group of strings:</p>
<pre><code>test_string_1 = 'hellor world ccc'
test_string_2 = 'hellor world 2'
</code></pre>
<p>And I want to verify if any of the element... | 2 | 2016-07-22T01:50:35Z | 38,517,105 | <p>use built-in functions</p>
<pre><code>>>> check_list = ['aaa','bbb','ccc']
>>> test_string_1 = 'hellor world ccc'
>>> test_string_2 = 'hellor world 2'
>>> any([(element in test_string_1) for element in check_list])
True
>>> any([(element in test_string_2) for element in... | 2 | 2016-07-22T02:10:03Z | [
"python",
"string",
"list"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,517,025 | <pre><code>import collections as co
l = [["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
dd = co.defaultdict(int)
for i in l:
dd[i[0]] += i[1]
newlist = [list((k,v)) for k,v in dd.iteritems()]
</code></pre>
<p>Result:</p>
<pre><code>>>> newlist
[['FR', 4], ['UK', 5], ['US', 6]]
</code></p... | 0 | 2016-07-22T01:58:18Z | [
"python"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,517,029 | <p>Do a list comprehension:</p>
<pre><code>myNewList = [i for i in listOne if i in listTwo]
</code></pre>
<p>Here's an example:</p>
<pre><code>listOne = [2, 4, 5, 7]
listTwo = [2, 3, 5, 6]
print ([i for i in listOne if i in listTwo])
# prints [2, 5]
</code></pre>
<p>Here's what I got when I ran it with both of you... | 0 | 2016-07-22T01:58:41Z | [
"python"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,517,050 | <p>First if you don't know how to do it you don't need optimization but I'll give myself a challenge of 5 seconds to answer your question :) </p>
<pre><code>from collections import defaultdict
b=defaultdict(int)
a=[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
for i in a: b[i[0]]+=i[1]
#now the w... | 0 | 2016-07-22T02:01:15Z | [
"python"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,517,055 | <p>You could use a combination of <code>itertools.groupby</code>, <code>reduce</code> and list comprehensions, like so:</p>
<pre><code>a = [["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
a.sort()
b = []
for k, g in groupby(a, lambda x: x[0]):
b.append([k, reduce(lambda p, c: p + c, [y[1] for y i... | 0 | 2016-07-22T02:01:50Z | [
"python"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,517,070 | <p>Group them by name, sum the numbers for each group:</p>
<pre><code>from itertools import groupby
from operator import itemgetter
my_list = [["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
summary_list = []
for name, group in groupby(sorted(my_list), key=itemgetter(0)):
summary_list.append([... | 0 | 2016-07-22T02:04:21Z | [
"python"
] |
How to sum the second elements of the list if the first elements in the list are matching | 38,516,977 | <p>Input: </p>
<pre><code>[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Output: </p>
<pre><code>[["US", 6], ["UK", 5], ["FR", 4]]
</code></pre>
<p>I want to sum the second elements of the list if the first elements in the list are matching. I have tried using the dictionaries a... | -1 | 2016-07-22T01:51:08Z | 38,806,714 | <p>Starting with this:</p>
<pre><code> ll =[["US", 2], ["UK", 3], ["FR", 4], ["US", 2], ["US", 2], ["UK", 2]]
</code></pre>
<p>Try this:</p>
<pre><code> dd = {k:0 for k in dict(ll).keys()}
for x in ll: dd[x[0]] += x[1]
dd
{'FR': 4, 'UK': 5, 'US': 6}
[[k,v] for k,v in dd.iteritems()]
[['FR', 4], ['US', 6], [... | 0 | 2016-08-06T17:01:09Z | [
"python"
] |
How to handle IncompleteRead: in biopython | 38,516,984 | <p>I am trying to fetch fasta sequence for accession numbers from NCBI using Biopython module. Usually the sequences were successfully downloaded. But once in a while i get the below error</p>
<blockquote>
<p>http.client.IncompleteRead: IncompleteRead(61808640 bytes read)</p>
</blockquote>
<p>I have searched the an... | 0 | 2016-07-22T01:52:18Z | 38,524,722 | <p>You will need to add a try/except to catch common network errors like this. Note that exception httplib.IncompleteRead is a subclass of the more general HTTPException, see: <a href="https://docs.python.org/3/library/http.client.html#http.client.IncompleteRead" rel="nofollow">https://docs.python.org/3/library/http.cl... | 0 | 2016-07-22T10:56:47Z | [
"python",
"biopython",
"http.client"
] |
How to set the signature of a function? | 38,517,016 | <p>I tried changing the signature of a function using the <code>inspect</code> module:</p>
<pre><code>import inspect
def some_func(a, b):
return
sig = inspect.signature(some_func)
new_params = list(sig.parameters.values()) + [inspect.Parameter('c', inspect._ParameterKind.POSITIONAL_OR_KEYWORD)]
new_sig = sig.rep... | 2 | 2016-07-22T01:56:54Z | 38,517,108 | <p>Reassigning function signatures is not something Python supports.</p>
<p>Most functions <em>do</em> something with their arguments. If you somehow managed to change a function's signature, the function body wouldn't have the right arguments to work with. It's not a thing that makes sense to do.</p>
<p>If you're ab... | 0 | 2016-07-22T02:10:44Z | [
"python"
] |
How to set the signature of a function? | 38,517,016 | <p>I tried changing the signature of a function using the <code>inspect</code> module:</p>
<pre><code>import inspect
def some_func(a, b):
return
sig = inspect.signature(some_func)
new_params = list(sig.parameters.values()) + [inspect.Parameter('c', inspect._ParameterKind.POSITIONAL_OR_KEYWORD)]
new_sig = sig.rep... | 2 | 2016-07-22T01:56:54Z | 38,517,110 | <p>I think this is a category error. You can create a <code>Signature</code> object by inspecting an existing function, but you can't assign an existing function a new signature the way you're trying to do.</p>
<p>That is, <code>hasattr(some_func, '__signature__')</code> returns <code>False</code>. You assigned it in ... | 0 | 2016-07-22T02:10:54Z | [
"python"
] |
Class Based View to get user authentication in Django | 38,517,032 | <p>Ok, have a class based view that passes a <code>query_set</code> into my <code>AssignedToMe</code> class. The point of this class based view is to see if a user is logged in and if they are, they can go to a page and it will display all of records that are assigned to their ID. Currently, it is working how I want it... | 0 | 2016-07-22T01:59:01Z | 38,517,140 | <p>I dont know whats the context of your ClassBasedView ... but you can use the LoginRequiredMixin to require the login before calling your class :</p>
<p><code>class ServerDeleteView(LoginRequiredMixin, DeleteView):
model = Server
success_url = reverse_lazy('ui:dashboard')</code></p>
| 0 | 2016-07-22T02:14:50Z | [
"python",
"django",
"class",
"authentication",
"request"
] |
Class Based View to get user authentication in Django | 38,517,032 | <p>Ok, have a class based view that passes a <code>query_set</code> into my <code>AssignedToMe</code> class. The point of this class based view is to see if a user is logged in and if they are, they can go to a page and it will display all of records that are assigned to their ID. Currently, it is working how I want it... | 0 | 2016-07-22T01:59:01Z | 38,517,264 | <p>You can create a login required mixin to use in your ClassBasedViews like this:</p>
<pre><code>from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
class LoginRequiredMixin(object):
@method_decorator(login_required)
def dispatch(self, request, *args, ... | 1 | 2016-07-22T02:34:42Z | [
"python",
"django",
"class",
"authentication",
"request"
] |
Beautiful Soup Cleaning and Errors | 38,517,083 | <p>I have this code:</p>
<pre><code>from bs4 import BeautifulSoup
import urllib2
from lxml import html
from lxml.etree import tostring
trees = urllib2.urlopen('http://aviationweather.gov/adds/metars/index? station_ids=KJFK&std_trans=translated&chk_metars=on&hoursStr=most+recent... | 0 | 2016-07-22T02:06:27Z | 38,517,120 | <p>The first problem is in this part:</p>
<pre><code>trees = urllib2.urlopen('http://aviationweather.gov/adds/metars/index?station_ids=KJFK&std_trans=translated&chk_metars=on&hoursStr=most+recent+only&chk_tafs=on&submit=Submit').read()
soup = BeautifulSoup(open(trees))
</code></pre>
<p><code>trees... | 0 | 2016-07-22T02:11:55Z | [
"python",
"beautifulsoup"
] |
Why is browsermobproxy not working for my internal ip? | 38,517,096 | <p>While I am used to python, I am not very familiar with all the protocols used by browser. I am not trying to setup a proxy for my selenium webdriver and this is the code that I use.</p>
<pre><code>from browsermobproxy import Server, Client
server = Server('/Users/***/Downloads/browsermob-proxy-2.1.1/bin/browsermob-... | 0 | 2016-07-22T02:08:04Z | 38,545,988 | <p>Most likely BMP is rejecting connections to the host because the certificate presented by <a href="https://10.203.9.156/login.html" rel="nofollow">https://10.203.9.156/login.html</a> is not valid for that IP address. In both Embedded Mode and command-line/standalone/REST API mode, there is a <code>trustAllServers</c... | 0 | 2016-07-23T20:07:33Z | [
"python",
"selenium",
"proxy",
"browsermob",
"browsermob-proxy"
] |
Doing Groupby in Django ORMs | 38,517,142 | <p>I have a simple table with the following values </p>
<pre><code> "uid": "some_uid",
"name": "test1",
"trig_time": 1234, #unix timestamp
"notify_time": 1235 #unix timestamp
</code></pre>
<p>I have lot of tuples which may or may not have the same name. I intend to groupby results based on name and have the no of... | 1 | 2016-07-22T02:15:03Z | 38,517,434 | <p>You can use <a href="https://docs.djangoproject.com/en/1.9/topics/db/aggregation/#values" rel="nofollow">aggregation with <code>values()</code></a> to get there:</p>
<pre><code>from django.db.models import Count, Max
Trig.objects.filter(uid=uid).values('name')\
.annotate(count=Count('id'), late... | 1 | 2016-07-22T02:56:24Z | [
"python",
"django"
] |
Python Regex Parser | 38,517,224 | <p>I need to fine tune the following regex. Right now it gives me srcip, dstip, srcport, dstport and date. I need it to also give me the protocol (UDP, TCP). Here is the line it needs to parse:</p>
<pre><code>03/09-13:00:59.136048 [**] [1:2003410:9] ET POLICY FTP Login Successful [**] [Classification: Misc activity] ... | 1 | 2016-07-22T02:28:19Z | 38,517,316 | <p>This regex should work with what you want:</p>
<pre><code>([0-9\/]+)-([0-9:.]+)\s+.*?\s\{(\w+)\}\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):?(\d{1,5})?\s+->\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):?(\d{1,5})?
</code></pre>
<p>I have added <code>\s\{(\w+)\}\s</code> to match the protocol. I also made the protocol and ... | 1 | 2016-07-22T02:41:43Z | [
"python",
"regex",
"parsing",
"alert",
"snort"
] |
How to get last update Twitter API | 38,517,301 | <p>How to get time last status update on Twitter ? use python and tweepy</p>
<p>help please</p>
| 0 | 2016-07-22T02:39:58Z | 39,055,182 | <p>These are the commands that I used to read tweets from my personal Twitter account using Python. I hope you can use the same to read the last status update from Twitter.</p>
<pre><code>#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from ... | 0 | 2016-08-20T14:25:09Z | [
"python",
"twitter",
"tweepy"
] |
Global dataframes - good or bad | 38,517,334 | <p>I have a program that i load millions of rows into dataframes, and i declare them as global so my functions (>50) can all use them like i use a database in the past. I read that using globals are a bad, and due to the memory mapping for it, it is slower to use globals. </p>
<p>I like to ask if globals are bad, how... | 1 | 2016-07-22T02:43:35Z | 38,517,371 | <p>Yes. Instead of using globals, you should wrap your data into an object and pass that object around to your functions instead (see dependency injection).</p>
<p>Wrapping it in an object instead of using a global will :</p>
<ol>
<li>Allow you to unit test your code. This is absolutely the most important reason. Usi... | 2 | 2016-07-22T02:50:05Z | [
"python",
"pandas",
"global"
] |
How to early return from within a helper function? | 38,517,374 | <p>So I thought I was being smart and <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY</a> by removing a bunch of common code from a bunch of similar functions and turning them into helper functions all defined in a single place. (see <a href="https://github.com/scipy/scipy/commit/61b... | 1 | 2016-07-22T02:50:50Z | 38,517,441 | <p>You can extract <code>a-specific stuff</code> and <code>b-specific stuff</code> to core functions, that are passed to your helper function. Then the helper will decide whether to call the core functions:</p>
<pre><code>_helper(stuff, _core_func):
if stuff == guard_condition:
return early
things = bo... | 2 | 2016-07-22T02:57:42Z | [
"python",
"return",
"helpers"
] |
How to early return from within a helper function? | 38,517,374 | <p>So I thought I was being smart and <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY</a> by removing a bunch of common code from a bunch of similar functions and turning them into helper functions all defined in a single place. (see <a href="https://github.com/scipy/scipy/commit/61b... | 1 | 2016-07-22T02:50:50Z | 38,517,793 | <p>Does this help?</p>
<pre><code> def common_stuff(f):
def checked_for_guards(*args, **kwargs):
if stuff == guard_condition:
return early
things = boilerplate
else:
return f(*args, **kwargs)
return checked_for_guards
@common_stuff
def func_A(stuff):
do A-sp... | 2 | 2016-07-22T03:40:24Z | [
"python",
"return",
"helpers"
] |
OpenCV: L1 normalization of descriptor matrix | 38,517,401 | <p>I'm trying to implement SIFTRoot in C++ following <a href="http://www.pyimagesearch.com/2015/04/13/implementing-rootsift-in-python-and-opencv/" rel="nofollow">this</a> article.</p>
<p>In particular:</p>
<pre><code> # apply the Hellinger kernel by first L1-normalizing and taking the
# square-root
descs /... | 0 | 2016-07-22T02:52:46Z | 38,517,889 | <p>The SIFT descriptor is basically a histogram, so it shouldn't have negative values. I don't think there exists a single function in OpenCV that does what you want to achieve. But it's not too hard to come up with a few lines that does the job</p>
<pre><code>// For each row
for (int i = 0; i < descs.rows; ++i) {
... | 1 | 2016-07-22T03:53:42Z | [
"python",
"c++",
"opencv",
"normalization",
"norm"
] |
Importing a Python script that requires system arguments into unit test | 38,517,471 | <p>I have a Python file, let's call it script1.py. I am trying to write a unit test (using unittest) called script1_test.py. script1 is meant to be called from command line and take in a number of arguments. When script 1 is run, it starts off with:</p>
<pre><code>if __name__ == "__main__" and len(sys.argv) == 6:
... | 0 | 2016-07-22T03:01:54Z | 38,518,025 | <p>When you do the import of your script, <code>__name__</code> is not equal to main so you're calling the <code>else</code> block. Instead you should nest your <code>if</code> blocks:</p>
<pre><code>if __name__ == "__main__":
if len(sys.argv) == 6:
func1()
else:
print "Wrong number of arguments"... | 1 | 2016-07-22T04:11:47Z | [
"python",
"python-2.7",
"unit-testing",
"python-unittest"
] |
How to permutate tranposition in tensorflow? | 38,517,533 | <p>From the <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/array_ops.html#transpose" rel="nofollow">docs</a>:</p>
<blockquote>
<p>Transposes a. Permutes the dimensions according to perm.</p>
<p>The returned tensor's dimension i will correspond to the input
dimension perm[i]. If perm is not ... | 1 | 2016-07-22T03:09:50Z | 38,518,079 | <p>I think <code>perm</code> is permuting the dimensions. For example <code>perm=[0,2,1]</code> is short for <code>dim_0 -> dim_0, dim_1 -> dim_2, dim_2 -> dim_1</code>. So for a 2D tensor, <code>perm=[1,0]</code> is just matrix transpose. Does this answer your question?</p>
| 2 | 2016-07-22T04:18:30Z | [
"python",
"numpy",
"tensorflow",
"permutation",
"transpose"
] |
Modify a linux file, and save in Python | 38,517,652 | <p>My goal is to modify a linux config file and update one of the settings from : </p>
<p>PasswordAuthentication <code>no</code> --> PasswordAuthentication <code>yes</code></p>
<hr>
<p>I have </p>
<pre><code>import os
import fileinput
username = raw_input("Enter username : ")
os.system("adduser -m "+username )... | 1 | 2016-07-22T03:23:42Z | 38,517,741 | <p>str.replace will take first argument as "old string" and second one as "New string"</p>
<pre><code>str.replace(old, new[, max])
</code></pre>
<p>you have given it in reverse.</p>
| 0 | 2016-07-22T03:34:38Z | [
"python",
"linux"
] |
how does dask distribute data to workers from the scheduler? | 38,517,736 | <p>Is there any documentation about how dask splits and sends data to workers? I wasn't able to find it on the official website.</p>
| 2 | 2016-07-22T03:34:12Z | 38,524,905 | <p>If you are interested in data movement policies then this document on data locality may be of interest to you: <a href="http://distributed.readthedocs.io/en/latest/locality.html" rel="nofollow">http://distributed.readthedocs.io/en/latest/locality.html</a></p>
<p>If you are interested in the message protocol then th... | 0 | 2016-07-22T11:06:45Z | [
"python",
"dask"
] |
Python - managing asynchronous methods via threading | 38,517,745 | <p>Within my Python Script I am receiving a constant flow of data but want to push the data asynchronously via calling a asynchronous method. The data which exists in a buffer is always pushed when the method is available. </p>
<p>Inorder to achieve this I have a try/catch that is constantly being called that creates ... | 0 | 2016-07-22T03:34:47Z | 38,530,471 | <p>You should use a Queue. One thread just has the job of monitoring the queue and pushing out any new data. The main thread just adds to the queue when new data is available.</p>
<p>Example:</p>
<pre><code>import threading
import queue
def pusher(q):
while True:
item = q.get()
if item is None:
retur... | 0 | 2016-07-22T15:39:03Z | [
"python",
"multithreading",
"python-multithreading"
] |
Strip operation is removing a character from a url when it shouldnt be | 38,517,765 | <p>I have a strange problem here. I have a list of Youtube urls in a txt file, these aren't normal YT urls though as I believe they were saved from a mobile device and thus they are all like this</p>
<p><a href="https://youtu.be/A6RXqx_QtKQ" rel="nofollow">https://youtu.be/A6RXqx_QtKQ</a></p>
<p>I want to download th... | 0 | 2016-07-22T03:37:30Z | 38,517,816 | <p>According to the <a href="https://docs.python.org/3/library/stdtypes.html#str.strip" rel="nofollow">documentation</a>, <code>strip()</code> removes the <em>combination</em> of all the characters specified as parameter. Because there's an <code>o</code> in <code>youtu.be</code> that also gets removed.</p>
<p>Hence <... | 2 | 2016-07-22T03:43:53Z | [
"python",
"strip",
"youtube-dl"
] |
Strip operation is removing a character from a url when it shouldnt be | 38,517,765 | <p>I have a strange problem here. I have a list of Youtube urls in a txt file, these aren't normal YT urls though as I believe they were saved from a mobile device and thus they are all like this</p>
<p><a href="https://youtu.be/A6RXqx_QtKQ" rel="nofollow">https://youtu.be/A6RXqx_QtKQ</a></p>
<p>I want to download th... | 0 | 2016-07-22T03:37:30Z | 38,517,821 | <p><code>strip</code> is working correctly. It removes any of the characters in the argument from the beginning or end of the string. There is an "o" in the argument so if there is an "o" at the beginning of the code, of course it's going to be removed.</p>
<p>Try this instead:</p>
<pre><code>if line.startswih("https... | 2 | 2016-07-22T03:44:23Z | [
"python",
"strip",
"youtube-dl"
] |
Strip operation is removing a character from a url when it shouldnt be | 38,517,765 | <p>I have a strange problem here. I have a list of Youtube urls in a txt file, these aren't normal YT urls though as I believe they were saved from a mobile device and thus they are all like this</p>
<p><a href="https://youtu.be/A6RXqx_QtKQ" rel="nofollow">https://youtu.be/A6RXqx_QtKQ</a></p>
<p>I want to download th... | 0 | 2016-07-22T03:37:30Z | 38,517,996 | <p>Gonna throw out another solution, this is a good place for <code>str.rpartition</code>.</p>
<pre><code>'https://youtu.be/o5kO4y87Gew'.rpartition('/')
# ('https://youtu.be', '/', 'o5kO4y87Gew')
'https://youtu.be/o5kO4y87Gew'.rpartition('/')[-1]
# 'o5kO4y87Gew'
</code></pre>
| 2 | 2016-07-22T04:08:31Z | [
"python",
"strip",
"youtube-dl"
] |
Strip operation is removing a character from a url when it shouldnt be | 38,517,765 | <p>I have a strange problem here. I have a list of Youtube urls in a txt file, these aren't normal YT urls though as I believe they were saved from a mobile device and thus they are all like this</p>
<p><a href="https://youtu.be/A6RXqx_QtKQ" rel="nofollow">https://youtu.be/A6RXqx_QtKQ</a></p>
<p>I want to download th... | 0 | 2016-07-22T03:37:30Z | 38,520,204 | <p>youtube-dl deals with whole URLs just fine. You can check that on the command line with <code>youtube-dl https://youtu.be/A6RXqx_QtKQ --list-extractor</code>, which shows that the correct extractor <code>youtube</code> will be used. There is no need for any stripping of URLs that are already present.</p>
| 3 | 2016-07-22T07:04:48Z | [
"python",
"strip",
"youtube-dl"
] |
Efficient data structure for storing data with relative ordering | 38,517,778 | <p>I have to store a sentence along with the possible semgments of the sentence into an efficient data structure. Currently I use a dictionary followed by a list for each key of the dictionary to store the segments. Can I use a better data structure to store the same efficiently. I have detailed the whole requirements ... | 2 | 2016-07-22T03:38:41Z | 38,518,224 | <p>It seems like you could get away with a backtracking depth-first-search on a properly constructed tree:</p>
<pre><code>sentence = "pravaramuku.........yugalah"
words = sentenceToWords(sentence) # it seems like you already have this
tree = collections.defauldict(list)
for word in words:
for i in (i for i in ra... | 1 | 2016-07-22T04:33:16Z | [
"python",
"performance",
"data-structures",
"collections"
] |
Create a dataframe from a list in pyspark.sql | 38,517,808 | <p>I am totally lost in a wired situation. Now I have a list <code>li</code></p>
<pre><code>li = example_data.map(lambda x: get_labeled_prediction(w,x)).collect()
print li, type(li)
</code></pre>
<p>the output is like,</p>
<pre><code>[(0.0, 59.0), (0.0, 51.0), (0.0, 81.0), (0.0, 8.0), (0.0, 86.0), (0.0, 86.0), (0.0,... | 0 | 2016-07-22T03:42:53Z | 38,517,873 | <p>You have a <code>list of float64</code> and I think it doesn't like that type. On the other hand, when you hard code it it's just a <code>list of float</code>.<br>
Here is a <a href="http://stackoverflow.com/questions/9452775/converting-numpy-dtypes-to-native-python-types">question</a> with an answer that goes over ... | 0 | 2016-07-22T03:52:02Z | [
"python",
"spark-dataframe",
"pyspark-sql"
] |
Why does jupyter display "None not found"? | 38,517,887 | <p>I am trying to use jupyter to write and edit python code. I have a .ipynb file open, but I see "None not found" in the upper right hand corner and I can't execute any of the code that I write. What's so bizarre is that I'll open other .ipynb files and have no problem. Additionally, when I click on the red "None not ... | 10 | 2016-07-22T03:53:26Z | 38,519,191 | <p>I suspect that that specific <code>.ipynb</code> file contains some metadata specifying a kernel that you do not have installed - see <a href="https://ipython.org/ipython-doc/3/notebook/nbformat.html" rel="nofollow">the file format specification</a>.</p>
<p>If you open that file with a text editor and search for <c... | 3 | 2016-07-22T05:58:20Z | [
"python",
"kernel",
"anaconda",
"jupyter",
"jupyter-notebook"
] |
Why does jupyter display "None not found"? | 38,517,887 | <p>I am trying to use jupyter to write and edit python code. I have a .ipynb file open, but I see "None not found" in the upper right hand corner and I can't execute any of the code that I write. What's so bizarre is that I'll open other .ipynb files and have no problem. Additionally, when I click on the red "None not ... | 10 | 2016-07-22T03:53:26Z | 38,930,008 | <p>Same problem after a new installation of Anaconda on notebooks that worked before the new installation. I installed an older version (3 4.0.0) and the problem was fixed.</p>
| 0 | 2016-08-13T06:43:44Z | [
"python",
"kernel",
"anaconda",
"jupyter",
"jupyter-notebook"
] |
Why does jupyter display "None not found"? | 38,517,887 | <p>I am trying to use jupyter to write and edit python code. I have a .ipynb file open, but I see "None not found" in the upper right hand corner and I can't execute any of the code that I write. What's so bizarre is that I'll open other .ipynb files and have no problem. Additionally, when I click on the red "None not ... | 10 | 2016-07-22T03:53:26Z | 39,225,574 | <p>I had the same problem here. The solution for me was:</p>
<ol>
<li>in the menu in Kernel -> Change kernel -> choose Python [Root] (or
the kernel you want),</li>
<li>save the file,</li>
<li>close it,</li>
<li>reopen it.</li>
</ol>
| 12 | 2016-08-30T10:53:59Z | [
"python",
"kernel",
"anaconda",
"jupyter",
"jupyter-notebook"
] |
trouble with resampling objects | 38,517,897 | <p>I've got a class that has two attributes: a value <code>val</code> and a weight <code>weight</code>. Then I have a list of these. </p>
<p>As step 1 of 2, I want to sample with replacement from this list of objects. Since it's sampling with replacement, the result list will usually have duplicate objects (objects wi... | 0 | 2016-07-22T03:54:56Z | 38,519,081 | <p>Do you really need that <code>class MyClass</code>? I think object oriented code should be used where you have a collection of heterogeneous data and accompanying methods, and/or use inheritance. Since you're just working with NxM floats, simply using <code>numpy.array</code>s here is far easier to understand, maint... | 1 | 2016-07-22T05:50:33Z | [
"python",
"python-3.x",
"numpy"
] |
trouble with resampling objects | 38,517,897 | <p>I've got a class that has two attributes: a value <code>val</code> and a weight <code>weight</code>. Then I have a list of these. </p>
<p>As step 1 of 2, I want to sample with replacement from this list of objects. Since it's sampling with replacement, the result list will usually have duplicate objects (objects wi... | 0 | 2016-07-22T03:54:56Z | 38,519,534 | <p>This works. Resample the indices, then deepcopy everything. Still waiting for suggestions on faster stuff. Thanks to @BrenBarn for suggestions.</p>
<pre><code>import numpy as np
import copy
class MyClass:
def __init__(self, val, weight):
self.val = val
self.weight = weight
def update(self)... | 0 | 2016-07-22T06:23:38Z | [
"python",
"python-3.x",
"numpy"
] |
Why is a single process pool faster than serialized implementation in this python code? | 38,517,936 | <p>I'm experiencing with multiprocessing in python. I know that it can be slower than serialized computation, this is not the point of my post.</p>
<p>I'm just wandering why a single process pool is faster than the serialized computation of my basic problem. Shouldn't these times be the same?</p>
<p>Here is the code:... | 1 | 2016-07-22T04:00:16Z | 38,518,294 | <p>Your current code to calculate the time taken by multiprocessing is actually telling the time taken by the process to submit the task to the pool. The processing is actually happening in asynchronous mode without blocking the thread. </p>
<p>I tried your program with following changes:</p>
<pre><code>def multi_pro... | 2 | 2016-07-22T04:42:13Z | [
"python",
"multiprocessing"
] |
Outer addition and subtraction in tensorflow | 38,517,940 | <p>Is the an equivalent operation (or series of operations) that acts like the numpy outer functions? </p>
<pre><code>import numpy as np
a = np.arange(3)
b = np.arange(5)
print np.subtract.outer(a,b)
[[ 0 -1 -2 -3 -4]
[ 1 0 -1 -2 -3]
[ 2 1 0 -1 -2]]
</code></pre>
<p>The obvious candidate <a href="https://www.... | 1 | 2016-07-22T04:00:34Z | 38,532,520 | <p>Use broadcasting:</p>
<pre><code>sess.run(tf.transpose([tf.range(3)]) - tf.range(5))
</code></pre>
<p>Output</p>
<pre><code>array([[ 0, -1, -2, -3, -4],
[ 1, 0, -1, -2, -3],
[ 2, 1, 0, -1, -2]], dtype=int32)
</code></pre>
<p>To be more specific, given <code>(3, 1)</code> and <code>(1, 5)</code> ... | 2 | 2016-07-22T17:46:54Z | [
"python",
"tensorflow"
] |
How to create pandas dataframe from python dictionary? | 38,517,960 | <p>I have a python dictionary below:</p>
<pre><code>dict = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)};
</code></pre>
<p>I want to change dictionary to dataframe like:</p>
<p><a href="http://i.stack.imgur.com/puqs2.png" rel="nofollow"><img src="http://i.stack.imgur.com/puqs2.png" alt="enter image descri... | 1 | 2016-07-22T04:03:17Z | 38,517,970 | <p>You are overcomplicating the problem, just pass your dictionary into the <code>DataFrame</code> constructor:</p>
<pre><code>import pandas as pd
d = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)}
print(pd.DataFrame(d))
</code></pre>
<p>Prints:</p>
<pre><code> stock1 stock2 stock3
0 5 1 ... | 4 | 2016-07-22T04:04:50Z | [
"python",
"pandas",
"dictionary"
] |
How to create pandas dataframe from python dictionary? | 38,517,960 | <p>I have a python dictionary below:</p>
<pre><code>dict = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)};
</code></pre>
<p>I want to change dictionary to dataframe like:</p>
<p><a href="http://i.stack.imgur.com/puqs2.png" rel="nofollow"><img src="http://i.stack.imgur.com/puqs2.png" alt="enter image descri... | 1 | 2016-07-22T04:03:17Z | 38,518,890 | <p>Try this: <strong>Do not name your variables python key words!</strong> </p>
<pre><code>dd = {'stock1': (5,6,7), 'stock2': (1,2,3),'stock3': (7,8,9)};
#pd.DataFrame(dd) Should work!
pd.DataFrame.from_dict(dd, orient='columns')
stock1 stock2 stock3
0 5 1 7
1 6 2 8
2 7... | 2 | 2016-07-22T05:34:26Z | [
"python",
"pandas",
"dictionary"
] |
Can Excel Dashboards update automatically? | 38,518,227 | <p>I need to create a dashboard based upon an excel table and I know excel has a feature for creating dashboards. I have seen tutorials on how to do it and have done my research, but in my case, the excel table on which the dashboard would be based is updated every 2 minutes by a python script. My question is, does the... | 0 | 2016-07-22T04:33:22Z | 38,520,493 | <p>If the "dashboard" is in Excel and if it contains charts that refer to data in the current workbook's worksheets, then the charts will update automatically when the data is refreshed, unless the workbook calculation mode is set to "manual". By default calculation mode is set to "automatic", so changes in data will i... | 1 | 2016-07-22T07:22:18Z | [
"python",
"excel",
"dashboard"
] |
python filter doesn't work | 38,518,240 | <p>I have an algorithm that can generate a prime list as a generator:</p>
<pre><code>def _odd_iter():
n=3
while True:
yield n
n=n+2
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yield 2
L=_odd_iter()
while True:
n=next(L)
yield n
L=... | 7 | 2016-07-22T04:35:13Z | 38,518,855 | <p>Here's a simpler program which illustrates the same problem.</p>
<pre><code>adders = []
for i in range(4):
adders.append(lambda a: i + a)
print(adders[0](3))
</code></pre>
<p>While one would expect the output to be <code>3</code>, the actual output is <code>6</code>.
This is because a closure in python remembe... | 6 | 2016-07-22T05:31:06Z | [
"python",
"lambda",
"filter"
] |
python filter doesn't work | 38,518,240 | <p>I have an algorithm that can generate a prime list as a generator:</p>
<pre><code>def _odd_iter():
n=3
while True:
yield n
n=n+2
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yield 2
L=_odd_iter()
while True:
n=next(L)
yield n
L=... | 7 | 2016-07-22T04:35:13Z | 38,518,859 | <p>The lambda that works is <code>lambda x, n=n: x%n != 0</code>. You apparently need to do this if you want <code>n</code> to be captured at the time the lambda is defined. Otherwise a lambda only looks up the variable name when it gets around to evaluating the lambda. In your case I think that meant locking onto an <... | 4 | 2016-07-22T05:31:33Z | [
"python",
"lambda",
"filter"
] |
Backport CSRF_TRUSTED_ORIGINS to Django 1.6 | 38,518,389 | <p><strong>The Problem:</strong></p>
<p>In Django 1.9, <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#csrf-trusted-origins" rel="nofollow"><code>CSRF_TRUSTED_ORIGINS</code></a> was added to the available settings which allows to, for example, access the application from all the subdomains:</p>
<pre><cod... | 1 | 2016-07-22T04:50:46Z | 38,620,854 | <p>Fixed, basically, by <em>backporting</em> the <a href="https://github.com/django/django/blob/master/django/middleware/csrf.py" rel="nofollow"><code>csrf</code> middleware from Django 1.9</a> manually to be compatible with Django 1.6. Not pretty, but works at the moment.</p>
| 0 | 2016-07-27T18:43:17Z | [
"python",
"django",
"csrf",
"csrf-protection",
"django-middleware"
] |
wxPython produces no GUI output | 38,518,600 | <p>Am new to GUI with wxPython.Was trying out this block of code from a book and it produces the following output but no GUI with the message string.Here's the code..</p>
<p><a href="http://i.stack.imgur.com/RP2Ox.png" rel="nofollow">Here's the code </a></p>
<p><a href="http://i.stack.imgur.com/vJSIE.png" rel="nofoll... | 0 | 2016-07-22T05:08:40Z | 38,519,150 | <p>Python is case-sensitive and you need to use an uppercase 'O' in <code>OnInit</code>.</p>
<pre><code>import wx
class MyApp(wx.App):
def OnInit(self):
wx.MessageBox('Hello Brian', 'wxApp')
return True
app = MyApp()
app.MainLoop()
</code></pre>
| 1 | 2016-07-22T05:55:12Z | [
"python",
"wxpython"
] |
getting unhashable type: 'list' while using .split() | 38,518,639 | <p>I am using python 3 to begin with. I am trying to split the input from the console to match a key in my dictionary and the display the value of said key on the console. I've been trying things for hours and have decided to break down and ask for help. Here's some of the code. </p>
<pre><code>enter = input("test ")... | 0 | 2016-07-22T05:12:54Z | 38,518,696 | <p>If you know your URLs are going to be like that use <code>rsplit('/')</code> like so:</p>
<pre><code>>>> enter = int(input('test: ').rsplit('/')[-1])
test: www.domain.com/8450
>>> enter
8450
>>> names1[enter]
'C'
</code></pre>
<p>Also your keys are stored as ints so convert the input to ... | 1 | 2016-07-22T05:16:42Z | [
"python",
"python-3.x"
] |
getting unhashable type: 'list' while using .split() | 38,518,639 | <p>I am using python 3 to begin with. I am trying to split the input from the console to match a key in my dictionary and the display the value of said key on the console. I've been trying things for hours and have decided to break down and ask for help. Here's some of the code. </p>
<pre><code>enter = input("test ")... | 0 | 2016-07-22T05:12:54Z | 38,518,726 | <p><code>split()</code> returns a list</p>
<p>Eg:</p>
<pre><code>>>> input('test:').split()
test:hello
>>> ['hello']
</code></pre>
<p>You are checking if any of the keys in the dict are a list, like this:</p>
<pre><code>>>> if ['input'] in {'input': 'sample data'}
</code></pre>
<p>Which... | 0 | 2016-07-22T05:19:40Z | [
"python",
"python-3.x"
] |
Python TypeError: function takes 1 positional arguments but 2 were given | 38,518,644 | <p>I have a function that is design to operate like <code>root.title(winTitle)</code>. Here's my code:</p>
<pre><code>from tkinter import *
class UIWindow():
def __init__(self):
Tk()
def setWindowTitle(winTitle):
self.title(winTitle)
</code></pre>
<p>But when I run it, it gives the error:</p>
... | -1 | 2016-07-22T05:13:00Z | 38,518,806 | <pre><code>from Tkinter import *
class UIWindow():
def __init__(self, *arg, **kwarg):
self.root=Tk(*arg, **kwarg)
def setWindowTitle(self, winTitle):
self.root.title(winTitle)
x = UIWindow()
x.setWindowTitle("This is the Test Title.")
x.root.mainloop()
</code></pre>
<p>You are missing <strong>... | 1 | 2016-07-22T05:26:57Z | [
"python",
"tkinter",
"arguments",
"typeerror"
] |
Unable to get repr for <class 'django.db.models.QuerySet'> while aggregating data | 38,518,800 | <pre><code>@user_passes_test(lambda u: u.is_staff, login_url='/pyramid/login/')
def defaulters_report(request):
template = 'private/admin/report_defaulters.html'
queryset = list(TreeNode.objects.all())
for x in queryset:
x.d = x.debt
defaulters = TreeNode.objects.filter(id__in=([x.id for x in qu... | 1 | 2016-07-22T05:26:29Z | 38,520,374 | <p>You get this error, because some of generated SQL queries are too large for SQLite. If you need sum of <code>annuities</code> with past <code>expected_date</code> of <code>treenodes</code> with positive <code>debt</code>, you can try this:</p>
<pre><code>@user_passes_test(lambda u: u.is_staff, login_url='/pyramid/l... | 1 | 2016-07-22T07:15:27Z | [
"python",
"django"
] |
Why and how are Python functions hashable? | 38,518,849 | <p>I recently tried the following commands in Python:</p>
<pre><code>>>> {lambda x: 1: 'a'}
{<function __main__.<lambda>>: 'a'}
>>> def p(x): return 1
>>> {p: 'a'}
{<function __main__.p>: 'a'}
</code></pre>
<p>The success of both <code>dict</code> creations indicates that... | 38 | 2016-07-22T05:30:35Z | 38,518,893 | <p>It's nothing special. As you can see if you examine the unbound <code>__hash__</code> method of the function type:</p>
<pre><code>>>> def f(): pass
...
>>> type(f).__hash__
<slot wrapper '__hash__' of 'object' objects>
</code></pre>
<p>it just inherits <code>__hash__</code> from <code>objec... | 37 | 2016-07-22T05:34:56Z | [
"python",
"hash"
] |
Why and how are Python functions hashable? | 38,518,849 | <p>I recently tried the following commands in Python:</p>
<pre><code>>>> {lambda x: 1: 'a'}
{<function __main__.<lambda>>: 'a'}
>>> def p(x): return 1
>>> {p: 'a'}
{<function __main__.p>: 'a'}
</code></pre>
<p>The success of both <code>dict</code> creations indicates that... | 38 | 2016-07-22T05:30:35Z | 38,518,991 | <p>A function is hashable because it is a normal, builtin, non mutable object.</p>
<p>From the <a href="https://docs.python.org/2/glossary.html" rel="nofollow">Python Manual</a>:</p>
<blockquote>
<p>An object is hashable if it has a hash value which never changes during its lifetime (it needs a <code>__hash__()</co... | 3 | 2016-07-22T05:42:32Z | [
"python",
"hash"
] |
Why and how are Python functions hashable? | 38,518,849 | <p>I recently tried the following commands in Python:</p>
<pre><code>>>> {lambda x: 1: 'a'}
{<function __main__.<lambda>>: 'a'}
>>> def p(x): return 1
>>> {p: 'a'}
{<function __main__.p>: 'a'}
</code></pre>
<p>The success of both <code>dict</code> creations indicates that... | 38 | 2016-07-22T05:30:35Z | 38,519,187 | <p>It can be useful, e.g., to create sets of function objects, or to index a dict by functions. Immutable objects <em>normally</em> support <code>__hash__</code>. In any case, there's no internal difference between a function defined by a <code>def</code> or by a <code>lambda</code> - that's purely syntactic.</p>
<p... | 20 | 2016-07-22T05:58:09Z | [
"python",
"hash"
] |
Selenium leaves behind running processes? | 38,518,998 | <p>When my selenium program crashes due to some error, it seems to leave behind running processes. </p>
<p>For example, here is my process list:</p>
<pre><code>carol 30186 0.0 0.0 103576 7196 pts/11 Sl 00:45 0:00 /home/carol/test/chromedriver --port=51789
carol 30322 0.0 0.0 102552 7160 pts/11 Sl ... | 2 | 2016-07-22T05:43:15Z | 38,519,089 | <p>Chromedriver.exe crowds the TaskManager ( in case of Windows) everytime Selenium runs on Chrome.Sometimes, it doesn't clear even if the browser didn't crash. <br><br>I usually run a bat file or a cmd to kill all the existing chromedriver.exe processes before launching another one.</p>
<p>Take a look at this : <a hr... | 0 | 2016-07-22T05:50:59Z | [
"python",
"python-2.7",
"selenium",
"selenium-webdriver",
"selenium-chromedriver"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.