title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How can I find out what Python distribution I am using from within Python? | 39,295,364 | <p>I'm using an application (QGIS) that can execute Python and can be extended with plugins written in Python. Depending on the platform, the installer of this application brings along its own Python distribution which it installs alongside the application to be used by the application. On other platforms, the installa... | 2 | 2016-09-02T14:54:15Z | 39,295,386 | <p><code>version_info</code> from <code>sys</code> module gives you that answer:</p>
<pre><code>import sys
print sys.version_info
sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)
</code></pre>
<p>You can get every value of it by using ie.: </p>
<pre><code>print sys.version_info.major
</c... | 2 | 2016-09-02T14:55:49Z | [
"python"
] |
How can I find out what Python distribution I am using from within Python? | 39,295,364 | <p>I'm using an application (QGIS) that can execute Python and can be extended with plugins written in Python. Depending on the platform, the installer of this application brings along its own Python distribution which it installs alongside the application to be used by the application. On other platforms, the installa... | 2 | 2016-09-02T14:54:15Z | 39,295,406 | <pre><code>>>> import sys
>>> sys.version
'2.7.12 (default, Jun 29 2016, 14:05:02) \n[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]'
</code></pre>
| 0 | 2016-09-02T14:56:38Z | [
"python"
] |
How can I find out what Python distribution I am using from within Python? | 39,295,364 | <p>I'm using an application (QGIS) that can execute Python and can be extended with plugins written in Python. Depending on the platform, the installer of this application brings along its own Python distribution which it installs alongside the application to be used by the application. On other platforms, the installa... | 2 | 2016-09-02T14:54:15Z | 39,295,476 | <pre><code>>>> import platform
>>> print(platform.python_version())
</code></pre>
| 0 | 2016-09-02T15:00:41Z | [
"python"
] |
Something like ast.literal_eval to execute variable assignments | 39,295,414 | <p>I want to do something like:</p>
<pre><code>import ast
def foo(common_stuff, assignment_str):
common_stuff()
ast.literal_eval(assignment_str) # assignment to unknown or passed variable
foo('a=1;b=2')
</code></pre>
<p>is this possible in Python?</p>
<p>I am trying to write a general function to (enforce ... | 0 | 2016-09-02T14:57:04Z | 39,296,116 | <p>Yes you can</p>
<pre><code>exec('a=1;b=2')
</code></pre>
<p>but you shouldn't.
<a href="http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided">Why should exec() and eval() be avoided?</a></p>
| 0 | 2016-09-02T15:36:59Z | [
"python",
"eval",
"variable-assignment",
"literals"
] |
Something like ast.literal_eval to execute variable assignments | 39,295,414 | <p>I want to do something like:</p>
<pre><code>import ast
def foo(common_stuff, assignment_str):
common_stuff()
ast.literal_eval(assignment_str) # assignment to unknown or passed variable
foo('a=1;b=2')
</code></pre>
<p>is this possible in Python?</p>
<p>I am trying to write a general function to (enforce ... | 0 | 2016-09-02T14:57:04Z | 39,296,162 | <p><code>ast.literal_eval()</code> 'executes' the AST parse tree of an evaluation, and limits this to a strict subset that only allows for standard Python literals. You could take the <a href="https://hg.python.org/cpython/file/v3.5.1/Lib/ast.py#l38" rel="nofollow">source code</a> and add assignment support (where I'd ... | 1 | 2016-09-02T15:39:08Z | [
"python",
"eval",
"variable-assignment",
"literals"
] |
The MSS-maximum likelihood method for Fluctuation Test | 39,295,443 | <p>I am trying to implement an algorithm in the following paper (method 5) <a href="http://dx.doi.org/10.1016%2FS0076-6879(05)09012-9" rel="nofollow">http://dx.doi.org/10.1016%2FS0076-6879(05)09012-9</a> in python2.7 to improve my programming skill. Implementations can be found at these locations: Apparently I cannot p... | 1 | 2016-09-02T14:58:41Z | 39,298,785 | <p>Thanks for looking, there were a couple stupid mistakes in my code. Here is the working code (as far as I can tell):</p>
<pre><code> import numpy as np
import sympy as sp
from scipy.optimize import minimize
def leeCoulson(nparray):
median=np.median(nparray)
x=sp.Symbol('x')
... | 0 | 2016-09-02T18:34:23Z | [
"python",
"algorithm"
] |
Why does struct.pack return these values? | 39,295,552 | <p>I have an array of signed 16bit integers that I want to convert to a little endian byte string using struct.pack in python. But I don't understand, what values struct.pack returns. Here's an example:</p>
<pre><code>>>> bytestr = struct.pack('<9h',*[45, 70, 33, 38, -6, 26, 34, 46, 57])
>>> bytes... | 0 | 2016-09-02T15:05:29Z | 39,295,591 | <p>When Python shows you a representation of a string, it'll always try to show you printable text where possible. <code>-</code>, <code>F</code>, <code>!</code>, <code>&</code>, etc. are printable ASCII characters for the given bytes.</p>
<p>The output is otherwise entirely correct.</p>
<ul>
<li><p><code>45</cod... | 1 | 2016-09-02T15:07:46Z | [
"python",
"struct",
"pack"
] |
Python Web Scraper print issue | 39,295,642 | <p>I have created a web scraper in python but when printing at the end I want to print ("Bakerloo: " + info_from_website) that I have downloaded as you can see in the code, but it always comes out just as info_from_website and ignores the "Bakerloo: " string. Can't find anyway of solving it.</p>
<pre><code>import urll... | 1 | 2016-09-02T15:10:25Z | 39,295,883 | <p>I would use a <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors" rel="nofollow">CSS selector</a> instead, getting the element with <code>disruption-summary</code> class:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = 'https://tfl.gov.uk/tube-dlr-overground/status/'
p... | 2 | 2016-09-02T15:23:09Z | [
"python",
"python-3.x",
"web-scraping"
] |
How to real-time check the django view operating process | 39,295,659 | <p>Here is the thing, When I submit a form from template to view ,since the process of this view will cost a lot time. I don's think our user enjoy to wait.
So, I want to this: when user click the submit button,the browser will redirect to a new page or just show a sub-page in the same window that can print the real-ti... | 0 | 2016-09-02T15:11:09Z | 39,295,894 | <p><a href="https://channels.readthedocs.io/en/latest/" rel="nofollow">django-channels</a> could be a good solution to send information as they execute on the server side in this way you can send information on the client side by opening a websocket. </p>
<p>Channel can be used to post data to the client side without... | 0 | 2016-09-02T15:23:27Z | [
"python",
"django",
"celery"
] |
How does "\x"+* work? | 39,295,728 | <p>I'm trying to make a filesharing program, so I open the files in readbinary, and read it, establish a connection, and I try to send byte for byte.</p>
<p>How can I send <code>b"\x" + (encoded bytes of the int from dataread[i])</code>?</p>
<p>I always gives me an error, also, if it won't work, how can I read exactl... | -3 | 2016-09-02T15:15:05Z | 39,295,757 | <p>The <code>'\xhh'</code> notation only works in <em>string or byte literals</em>. If you have an integer, just pass this to a <code>bytes()</code> object in a list:</p>
<pre><code>bytes(dataread) # if dataread is a list of integers
</code></pre>
<p>or</p>
<pre><code>bytes([dataread]) # if dataread is a single in... | 2 | 2016-09-02T15:16:29Z | [
"python",
"sockets",
"python-3.x",
"byte"
] |
groupby, sum and count to one table | 39,295,910 | <p>I have a dataframe below</p>
<pre><code>df=pd.DataFrame({"A":np.random.randint(1,10,9),"B":np.random.randint(1,10,9),"C":list('abbcacded')})
A B C
0 9 6 a
1 2 2 b
2 1 9 b
3 8 2 c
4 7 6 a
5 3 5 c
6 1 3 d
7 9 9 e
8 3 4 d
</code></pre>
<p>I would like to get grouping result (with key... | 1 | 2016-09-02T15:24:42Z | 39,296,273 | <p>One option is to count the size and sum the columns for each group separately and then join them by index:</p>
<pre><code>df.groupby("C")['A'].agg({"number": 'size'}).join(df.groupby('C').sum())
number A B
# C
# a 2 11 8
# b 2 14 12
# c 2 8 5
# d 2 11 12
# e 1 7 ... | 1 | 2016-09-02T15:44:59Z | [
"python",
"pandas",
"numpy"
] |
groupby, sum and count to one table | 39,295,910 | <p>I have a dataframe below</p>
<pre><code>df=pd.DataFrame({"A":np.random.randint(1,10,9),"B":np.random.randint(1,10,9),"C":list('abbcacded')})
A B C
0 9 6 a
1 2 2 b
2 1 9 b
3 8 2 c
4 7 6 a
5 3 5 c
6 1 3 d
7 9 9 e
8 3 4 d
</code></pre>
<p>I would like to get grouping result (with key... | 1 | 2016-09-02T15:24:42Z | 39,296,352 | <p>You can do this using a single <code>groupby</code> with</p>
<pre><code>res = df.groupby(df.C).agg({'A': 'sum', 'B': {'sum': 'sum', 'count': 'count'}})
res.columns = ['A_sum', 'B_sum', 'count']
</code></pre>
| 1 | 2016-09-02T15:49:03Z | [
"python",
"pandas",
"numpy"
] |
Send already filled form with Python Requests | 39,295,920 | <p>just a quick question.</p>
<p>Is there a way to submit a pre-filled form with the Python Requests library?</p>
<p>For example, I'm on a page with a pre-filled form, there is a 'Submit' button that's gonna submit a post request with data which is already in form. Is there a way to 'simulate' clicking the 'Submit' b... | -1 | 2016-09-02T15:25:13Z | 39,296,026 | <p>Things like these can easily and transparently be solved with packages like <a href="https://github.com/hickford/MechanicalSoup" rel="nofollow"><code>MechanicalSoup</code></a> or <a href="https://github.com/jmcarp/robobrowser" rel="nofollow"><code>RoboBrowser</code></a>. Both are based on <code>requests</code> and <... | 0 | 2016-09-02T15:31:44Z | [
"python",
"forms",
"submit",
"python-requests"
] |
Python: Append tuple to a set with tuples | 39,295,942 | <p>Following is my code which is a set of tuples: </p>
<pre><code>data = {('A',20160129,36.44),('A',20160201,37.37),('A',20160104,41.06)};
print(data);
</code></pre>
<p>Output: <code>set([('A', 20160129, 36.44), ('A', 20160104, 41.06), ('A', 20160201, 37.37)])</code></p>
<p>How do I append another tuple <code>('A', ... | -1 | 2016-09-02T15:26:53Z | 39,296,040 | <p>the trick is to send it inside brackets so it doesn't get exploded</p>
<pre><code>data.update([('A', 20160000, 22)])
</code></pre>
| 2 | 2016-09-02T15:32:22Z | [
"python",
"set"
] |
Concatenation of Strings and lists | 39,295,972 | <p>In the following python script, it converts the Celsius degree to Fahrenheit but I need to join two list with strings between and after them</p>
<pre><code>Celsius = [39.2, 36.5, 37.3, 37.8]
fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print '\n'.join(str(i) for i in Celsius)+" in Celsius is "+''.join(s... | 2 | 2016-09-02T15:28:26Z | 39,296,030 | <p>It's probably easiest to do the formatting as you go:</p>
<pre><code>Celsius = [39.2, 36.5, 37.3, 37.8]
def fahrenheit(c):
return (float(9)/5)*c + 32
template = '{} in Celsius is equivalent to {} in fahrenheit'
print '\n'.join(template.format(c, fahrenheit(c)) for c in Celsius)
</code></pre>
<p><strong>EDIT</... | 8 | 2016-09-02T15:31:50Z | [
"python",
"python-2.7"
] |
Concatenation of Strings and lists | 39,295,972 | <p>In the following python script, it converts the Celsius degree to Fahrenheit but I need to join two list with strings between and after them</p>
<pre><code>Celsius = [39.2, 36.5, 37.3, 37.8]
fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print '\n'.join(str(i) for i in Celsius)+" in Celsius is "+''.join(s... | 2 | 2016-09-02T15:28:26Z | 39,296,134 | <p>You could always try formatting using %f for float numbers and placing the output in a loop:</p>
<pre><code>for i in range(len(Celsius)):
print '%f in Celsius is equivalent to %f in fahrenheit' % (Celsius[i], fahrenheit[i])
</code></pre>
<p>EDIT: As per the suggestion of @mgilson, using <code>zip</code> would ... | 0 | 2016-09-02T15:37:48Z | [
"python",
"python-2.7"
] |
Concatenation of Strings and lists | 39,295,972 | <p>In the following python script, it converts the Celsius degree to Fahrenheit but I need to join two list with strings between and after them</p>
<pre><code>Celsius = [39.2, 36.5, 37.3, 37.8]
fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print '\n'.join(str(i) for i in Celsius)+" in Celsius is "+''.join(s... | 2 | 2016-09-02T15:28:26Z | 39,296,366 | <p>In order to do it with <code>join</code>, you can include the extra parts of the string inside of the <code>join</code> statement.</p>
<pre><code>celsius = [39.2, 36.5, 37.3, 37.8]
fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print '\n'.join(str(i) + " in celsius is " + str(j) + "in farenheit" for i, j ... | 2 | 2016-09-02T15:49:27Z | [
"python",
"python-2.7"
] |
Concatenation of Strings and lists | 39,295,972 | <p>In the following python script, it converts the Celsius degree to Fahrenheit but I need to join two list with strings between and after them</p>
<pre><code>Celsius = [39.2, 36.5, 37.3, 37.8]
fahrenheit = map(lambda x: (float(9)/5)*x + 32, Celsius)
print '\n'.join(str(i) for i in Celsius)+" in Celsius is "+''.join(s... | 2 | 2016-09-02T15:28:26Z | 39,296,523 | <p>3 lines:</p>
<pre><code>>>> Celsius = [39.2, 36.5, 37.3, 37.8]
>>> msg = '%g in Celsius is equivalent to %g in Fahrenheit'
>>> print '\n'.join(msg % (c, (9. * c)/5. + 32.) for c in Celsius)
</code></pre>
<p>yields:</p>
<blockquote>
<p>39.2 in Celsius is equivalent to 102.56 in Fahrenh... | 2 | 2016-09-02T15:58:25Z | [
"python",
"python-2.7"
] |
"rect" class can't be the parameterof the method "screen.blit()" | 39,295,996 | <p>I want to draw a rectangle to be a simplified rocket, but my <code>pycharm</code> shows <code>argument 1 must be pygame.Surface, not pygame.Rect</code> just like in the picture.<a href="http://i.stack.imgur.com/gk1MH.png" rel="nofollow"><img src="http://i.stack.imgur.com/gk1MH.png" alt="enter image description here"... | 0 | 2016-09-02T15:29:45Z | 39,296,121 | <p>The function <code>pygame.draw.rect</code> draws directly on the Surface (the one you've given as argument) and returns a Rect object representing the area drawn. It doesn't return a Surface. </p>
<p>You can remove the line <code>screen.blit(moon, [0, 500, 400, 100])</code> since the rectangle is already drawn to t... | 1 | 2016-09-02T15:37:10Z | [
"python",
"python-2.7",
"pygame"
] |
No Results from Multi-property Projection Query in Google Cloud Datastore | 39,296,051 | <p>I'm trying to query the database with: </p>
<pre><code>fields = "property_1, property_2, ... property_n"
query = "SELECT {0} FROM Table WHERE property_{n+1} = '{1}'".format(fields, property_{n+1})
all_objs = CacheDatastore.fetch(query, refresh=True)
</code></pre>
<p>The problem is that the returned list is ... | 0 | 2016-09-02T15:32:57Z | 39,797,780 | <p>It turned to be a bug in the db library which is no longer in development, so I'm leaving here the link to the ticket and the comments on it.<br>
GAE allows indexing of static members of the db.Model class hierarchy, but returns 0 results for projection queries where the static member is included
among the project... | 0 | 2016-09-30T18:23:37Z | [
"python",
"google-app-engine",
"cloud",
"google-cloud-datastore",
"projection"
] |
Python zipfile removes execute permissions from binaries | 39,296,101 | <p>Not sure why this is happening, but when I run unzip a file (e.g. apache-groovy-binary-2.4.7.zip) at the command line... </p>
<ul>
<li>directories are rwx-r-xr-x </li>
<li>files are rwxr-xr-x or rw-r--r--</li>
</ul>
<p>But when I run zipfile.extractall from a Python 2.7 script on the same file... </p>
<ul>
<li>d... | 0 | 2016-09-02T15:36:24Z | 39,296,577 | <p>The reason for this can be found in the <code>_extract_member()</code> method in <code>zipfile.py</code>, it only calls <code>shutil.copyfileobj()</code> which will write the output file without any execute bits.</p>
<p>The easiest way to solve this is by subclassing <code>ZipFile</code> and changing <code>extract(... | 0 | 2016-09-02T16:01:51Z | [
"python",
"python-2.7"
] |
Cross-referencing in lists with slightly different coordinates | 39,296,124 | <p>I want to do something very similar to the question asked here:</p>
<p><a href="http://stackoverflow.com/questions/28393071/comparing-two-lists-of-coordinates-in-python-and-using-coordinate-values-to-assi">Comparing two lists of coordinates in python and using coordinate values to assign values</a></p>
<p>That is,... | 1 | 2016-09-02T15:37:21Z | 39,301,684 | <p>This is definitely a computational geometry algorithm. You can reformulate it as follows: given a set of points in a plane, find for all points <code>P</code> the set of all points at a distance <code><= R</code> (with respect to the <a href="https://en.wikipedia.org/wiki/Chebyshev_distance" rel="nofollow">Chebys... | 0 | 2016-09-02T23:02:31Z | [
"python",
"algorithm",
"list"
] |
Pyyhon regular expression works on OSx but not on Windows | 39,296,214 | <pre><code>expression = re.compile(ur'\?(.*)')
</code></pre>
<p>The expression is simple and this project was originally built on a mac. It runs fine on the mac, however it doesn't run on windows failing with </p>
<pre><code>File "path/to/scrapy/spiders/spider.py", line 42
expression = re.compile(ur'\?(.*)')
... | 1 | 2016-09-02T15:41:40Z | 39,296,380 | <p>It is not about Mac vs Windows, I suspect, <em>it is about the Python version you are using to run this code on</em>.</p>
<p>When I run this code on Python 2.7 - it runs fine, no problems. On Python 3.5 I get a <code>SyntaxError</code> (cause of the <code>u</code> prefix, of course):</p>
<pre><code> File "/Users/... | 0 | 2016-09-02T15:50:08Z | [
"python",
"windows",
"osx"
] |
plotting vertical bars instead of points, plot_date | 39,296,229 | <p>I want to plot vertical bars instead of points. The actual data I have are irregularly spaced, so this will help visualize gaps more easily.
When I try to plot it, the best I can do are points, which don't increase in size as you zoom in!</p>
<pre><code>import matplotlib
from matplotlib import pyplot as plt
import... | 1 | 2016-09-02T15:42:32Z | 39,296,554 | <p>You can use <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.vlines" rel="nofollow"><code>ax.vlines</code></a> to plot a collection of vertical lines. </p>
<p>You can adjust <code>ymin</code> and <code>ymax</code> to suit your data.</p>
<pre><code>import matplotlib
from matplotlib import pyplot... | 1 | 2016-09-02T16:00:28Z | [
"python",
"date",
"matplotlib"
] |
plotting vertical bars instead of points, plot_date | 39,296,229 | <p>I want to plot vertical bars instead of points. The actual data I have are irregularly spaced, so this will help visualize gaps more easily.
When I try to plot it, the best I can do are points, which don't increase in size as you zoom in!</p>
<pre><code>import matplotlib
from matplotlib import pyplot as plt
import... | 1 | 2016-09-02T15:42:32Z | 39,296,638 | <p>Did you mean bars like this? </p>
<p><a href="http://i.stack.imgur.com/Cb83O.png" rel="nofollow"><img src="http://i.stack.imgur.com/Cb83O.png" alt="enter image description here"></a></p>
<p>And here is the code:</p>
<pre><code>import matplotlib
from matplotlib import pyplot as plt
import datetime
XX = [datetime.... | 0 | 2016-09-02T16:05:14Z | [
"python",
"date",
"matplotlib"
] |
alternative to strptime for comparing dates? | 39,296,230 | <p>Is there any way to compare two dates without calling strptime each time in python? I'm sure given my problem there's no other way, but want to make sure I've checked all options. </p>
<p>I'm going through a very large log file, each line has a date which I need to compare to see if that date is within the range of... | 5 | 2016-09-02T15:42:37Z | 39,296,349 | <p>I'm assuming current_date is a string</p>
<p>First, make a dictionary</p>
<pre><code>moDict = {"Aug":8, "Jan":1} #etc
</code></pre>
<p>Then, find year/month/day etc</p>
<pre><code>current_date = "01/Aug/1995:23:59:53"
Yr = int(current_date[7:11])
Mo = moDict[(current_date[3:6])]
Day = int(current_date[0:2])
m_... | 1 | 2016-09-02T15:48:50Z | [
"python",
"regex",
"loops",
"strptime"
] |
alternative to strptime for comparing dates? | 39,296,230 | <p>Is there any way to compare two dates without calling strptime each time in python? I'm sure given my problem there's no other way, but want to make sure I've checked all options. </p>
<p>I'm going through a very large log file, each line has a date which I need to compare to see if that date is within the range of... | 5 | 2016-09-02T15:42:37Z | 39,297,009 | <p>Since your dates appear to be in a fixed length format, it's trivially easy to parse and you don't need <code>strptime</code> to do it. You can rearrange them into the <a href="https://en.wikipedia.org/wiki/ISO_8601" rel="nofollow">ISO 8601 date/time format</a> and compare them directly as strings!</p>
<pre><code>m... | 1 | 2016-09-02T16:28:08Z | [
"python",
"regex",
"loops",
"strptime"
] |
FirefoxDriver - Connection is not secure | 39,296,285 | <p>When I attempt to run my automation tests against Firefox 47.0.1 I get a warning mentioning that the connection is insecure. I have written the below code to resolve the issue, which unfortunately it's not working. If anyone has a solution that would be great. </p>
<pre><code>if browser == 'firefox':
profi... | 0 | 2016-09-02T15:45:20Z | 39,296,424 | <p>This occures because of
<code>profile.set_preference("webdriver_accept_untrusted_certs", True)</code></p>
<p>Remove this and try instead:
<code>profile.set_preference("webdriver_assume_untrusted_issuer", False)</code>
<code>profile.update_preferences()</code></p>
| 0 | 2016-09-02T15:52:50Z | [
"python",
"selenium-webdriver",
"selenium-firefoxdriver"
] |
Microbit python variables issue | 39,296,356 | <p>I'm trying to make a higher or lower game for my sisters microbit and am having problems with my variables
<code>random_int</code> & <code>r_number</code>:</p>
<pre><code>from microbit import *
import random
random_int = random.randint(0, 9)
r_number = 7
while True:
display.scroll(r_number)
if button_... | 0 | 2016-09-02T15:49:07Z | 39,499,339 | <p>Not sure what this is supposed to do. Not withstanding you only initialise your main variables once, and that outside of your main loop, I see syntax errors like that in #12 i.e. "if r_number =< random_int):" That widowed closing bracket looks a mite strange to me. The micro:bit's is not very forgiving, and it's ... | 0 | 2016-09-14T20:42:07Z | [
"python",
"bbc-microbit"
] |
Weird dictionary construct - duplicate keys | 39,296,387 | <p>I needed to write a function that 'maps' -1 to just '-', 1 to '' (yes, nothing) and every other value to a string representation of itself. Instead of using <code>if</code> statements i though i would do it with a dictionary like so:</p>
<pre><code>def adj(my_value):
return {-1: '-', 1: '', my_value: str(my_val... | 1 | 2016-09-02T15:50:21Z | 39,296,438 | <p>The dictionary you made doesn't have duplicate keys. The "duplicates" overwrote each other. It's just as if you had done this:</p>
<pre><code>d = {}
d[1] = ''
d[1] = 1
print(d[1])
</code></pre>
<p>To demonstrate:</p>
<pre><code>>>> def adj(my_value):
... d = {-1: '-', 1: '', my_value: str(my_value)}... | 6 | 2016-09-02T15:53:43Z | [
"python",
"python-3.x",
"dictionary"
] |
Weird dictionary construct - duplicate keys | 39,296,387 | <p>I needed to write a function that 'maps' -1 to just '-', 1 to '' (yes, nothing) and every other value to a string representation of itself. Instead of using <code>if</code> statements i though i would do it with a dictionary like so:</p>
<pre><code>def adj(my_value):
return {-1: '-', 1: '', my_value: str(my_val... | 1 | 2016-09-02T15:50:21Z | 39,296,491 | <p>Quoting the <a href="https://docs.python.org/3/reference/expressions.html#dictionary-displays" rel="nofollow">Python docs</a>:</p>
<blockquote>
<p>If a comma-separated sequence of key/datum pairs is given, they are evaluated from left to right to define the entries of the dictionary: each key object is used as a ... | 4 | 2016-09-02T15:56:31Z | [
"python",
"python-3.x",
"dictionary"
] |
Weird dictionary construct - duplicate keys | 39,296,387 | <p>I needed to write a function that 'maps' -1 to just '-', 1 to '' (yes, nothing) and every other value to a string representation of itself. Instead of using <code>if</code> statements i though i would do it with a dictionary like so:</p>
<pre><code>def adj(my_value):
return {-1: '-', 1: '', my_value: str(my_val... | 1 | 2016-09-02T15:50:21Z | 39,296,499 | <p>By doing <code>{-1: '-', 1: '', my_value: str(my_value)}</code>, you overwrite the <code>-1</code> or <code>1</code> entries if <code>my_value</code> is <code>-1</code> or <code>1</code> respectively. Instead, you can use <a href="https://docs.python.org/3/library/stdtypes.html#dict.get" rel="nofollow"><code>dict.ge... | 1 | 2016-09-02T15:57:03Z | [
"python",
"python-3.x",
"dictionary"
] |
tastypie overid create_response() method | 39,296,421 | <p>I tring to override tastypie <code>create_response</code> because I have some verification to do before sending response to user. this is my code:</p>
<pre><code>class MyNamespacedModelResource(NamespacedModelResource):
def create_response(self , request , data):
r = super(MyNamespacedModelResource , se... | 0 | 2016-09-02T15:52:34Z | 39,299,666 | <p>You have defined the method <code>create response()</code> with two positional arguments. However, the super class definition looks like this: </p>
<pre><code>def create_response(self, request, data, response_class=HttpResponse, **response_kwargs)
</code></pre>
<p>Why this is a problem is that your overridden met... | 0 | 2016-09-02T19:41:26Z | [
"python",
"django",
"tastypie"
] |
extract number from a text file into variable using list | 39,296,518 | <p>I've a .text file with text</p>
<blockquote>
<p>.numvar 5</p>
</blockquote>
<p>I want to extract this 5 into a separate variable and use.
I've used list to extract value but, I cannot manipulate the variable.</p>
<pre><code> if ".numvars" in line:
splitter=re.compile(r'\d+')
numvars=splitter.findall(... | 0 | 2016-09-02T15:57:59Z | 39,296,652 | <p>How about:</p>
<pre><code>import re
with open("test.txt") as f:
for line in f:
if ".numvar" in line:
splitter = re.compile(r'\d+')
numvars = splitter.findall(line)
my_numbers = [int(n) for n in numvars]
my_number = my_numbers[0]
print(my_numbe... | 0 | 2016-09-02T16:05:42Z | [
"python",
"list"
] |
How do I just display the numbers from the list without the comma and brackets on Python? | 39,296,539 | <pre><code>#This will ask the user to enter a 7 digit number
#then it would calculate the modulus 11 check digit
#then would show the user the complete 8 digit number
weight=[8,7,6,5,4,3,2]
number= input("Please enter your 7 digit number: ")
#If the user enters more than 7 characters it will prompt the user to try ag... | -2 | 2016-09-02T15:59:32Z | 39,296,603 | <pre><code>>>> "".join(map(str,account_number))
</code></pre>
<p>This first converts ints to str, then joins them together with no spaces</p>
<p>example:</p>
<pre><code>>>> a = [1,2,3]
>>> map(str,a)
['1', '2', '3']
>>> "".join(map(str,a))
'123'
>>>
</code></pre>
<p>In ... | 5 | 2016-09-02T16:03:10Z | [
"python",
"algorithm"
] |
selecting random json element | 39,296,542 | <p><strong>python 3.5</strong></p>
<p>hi i have following json file and i want to select json data random...</p>
<p><strong>json</strong></p>
<pre><code>{"x":[
{"A":"B"},
{"A":"C"},
{"F":"H"}
]}
</code></pre>
<p>select data where item in data['x'] is A </p>
<p>(result would be C or B)</p>
<p><strong>c... | 0 | 2016-09-02T15:59:39Z | 39,298,227 | <p>Perhaps this program will answer your (not-yet-asked) question:</p>
<pre><code>import json
import random
data = json.load(open('j.json'))
values = [v for d in data['x'] for k,v in d.items() if k == 'A']
try:
x = random.choice(values)
print(x)
except IndexError:
print("nothing found")
</code></pre>
| 0 | 2016-09-02T17:53:19Z | [
"python",
"json"
] |
How do I set initial form values of CreateView view using POST only (and not GET)? | 39,296,546 | <p>Users click a button that takes them to a new form via a POST request, which contains a pk. This is used to pre-populate the new form with some extra data. No data has been saved to database at this point. I don't want to pass this pk along the URL so can't call view using GET.</p>
<p>I've tried overriding the <cod... | 0 | 2016-09-02T15:59:56Z | 39,299,515 | <p>What I'd do:</p>
<pre><code>def post(self, request, **kwargs):
# Replace 'list_of_pets' with stuff that you'll definitely have in the first request
if 'list_of_pets' in request.POST:
# Provide initial data for form in get()
return self.get(request, **kwargs)
else:
# Provides auto... | 0 | 2016-09-02T19:28:49Z | [
"python",
"django",
"django-views"
] |
Python it is possible to spawn background process which runs even if main process exits? | 39,296,559 | <p>What I'm trying to achieve:
I want that my main process spawn another independent python process.
Like:</p>
<pre><code>for i in range(2):
p = proces()
p.start()
sys.exit(0)
</code></pre>
<p>And my spawned processes should run in the background doing some task :)
Because at the moment, if I spawn a proces... | 0 | 2016-09-02T16:00:40Z | 39,296,658 | <pre><code>import time
import multiprocessing
import sys
def run_forever():
print "ENTERED SUBPROCESS"
while True:
print "HELLO from subprocess"
time.sleep(2)
print "GOODBYE SUBPROCESS"
if __name__ == "__main__":
print "STARTING IN MAIN"
multiprocessing.Process(target=run_forev... | 0 | 2016-09-02T16:05:59Z | [
"python",
"multithreading",
"multiprocessing"
] |
Receiving a ValueError: Unknown level when running GoogleScraper | 39,296,645 | <p>I recently decided to get to grips with some python and try to learn my way around the language but i've inevitably ran into a couple of problems that I was hoping someone could help me with.</p>
<p>Basically, I'm running on an OSx machine, I uninstalled the python that came with the operating system and used HomeB... | 2 | 2016-09-02T16:05:33Z | 39,297,246 | <p>As per <a href="https://github.com/NikolaiT/GoogleScraper/blob/master/GoogleScraper/log.py" rel="nofollow">the source</a>, the logging level is a string that corresponds to a <a href="https://en.wikipedia.org/wiki/Syslog#Severity_level" rel="nofollow">syslog severity level</a>, not a number indicating level of verbo... | 1 | 2016-09-02T16:44:36Z | [
"python",
"osx",
"python-3.x"
] |
if statement seemingly being ignored in for loop | 39,296,720 | <p>noobie having trouble with if statements within a for loop </p>
<p>def abilityBuy():</p>
<pre><code>totalPoints = 28
abilities = {
"Str":0,
"Con":0,
"Dex":0,
"Int":0,
"Wis":0,
"Cha":0
}
for i,v in abilities.items():
print "You have %s points." % totalPoints
text = "Enter sta... | 0 | 2016-09-02T16:09:49Z | 39,296,824 | <p>First thing that comes to mind: <code>raw_input()</code> returns a string, but your if statements compare stat to integers so none of them will evaluate to true.
A simple solution is to convert it: <code>int(stat)</code>, but you will want to add a check for when users input non-numbers or values beyond what you tes... | 0 | 2016-09-02T16:16:35Z | [
"python"
] |
if statement seemingly being ignored in for loop | 39,296,720 | <p>noobie having trouble with if statements within a for loop </p>
<p>def abilityBuy():</p>
<pre><code>totalPoints = 28
abilities = {
"Str":0,
"Con":0,
"Dex":0,
"Int":0,
"Wis":0,
"Cha":0
}
for i,v in abilities.items():
print "You have %s points." % totalPoints
text = "Enter sta... | 0 | 2016-09-02T16:09:49Z | 39,296,828 | <p>It's because your <code>stat = raw_input</code> is returning a str value. stat is a str, and in your if statements your trying to compare it to an integer. <code>str == int</code> never works out. Either cast stat to an int, or compare it to str like...</p>
<pre><code>stat = int(stat)
</code></pre>
<p>or </p>
<pr... | 1 | 2016-09-02T16:16:42Z | [
"python"
] |
if statement seemingly being ignored in for loop | 39,296,720 | <p>noobie having trouble with if statements within a for loop </p>
<p>def abilityBuy():</p>
<pre><code>totalPoints = 28
abilities = {
"Str":0,
"Con":0,
"Dex":0,
"Int":0,
"Wis":0,
"Cha":0
}
for i,v in abilities.items():
print "You have %s points." % totalPoints
text = "Enter sta... | 0 | 2016-09-02T16:09:49Z | 39,296,832 | <p>The problem is with <a href="https://docs.python.org/2/library/functions.html#raw_input" rel="nofollow"><code>raw_input</code></a>. It returns a string, and you're just comparing it to ints.</p>
<pre><code>stat = int(raw_input(text))
</code></pre>
<p>would solve that part.</p>
| 1 | 2016-09-02T16:16:56Z | [
"python"
] |
if statement seemingly being ignored in for loop | 39,296,720 | <p>noobie having trouble with if statements within a for loop </p>
<p>def abilityBuy():</p>
<pre><code>totalPoints = 28
abilities = {
"Str":0,
"Con":0,
"Dex":0,
"Int":0,
"Wis":0,
"Cha":0
}
for i,v in abilities.items():
print "You have %s points." % totalPoints
text = "Enter sta... | 0 | 2016-09-02T16:09:49Z | 39,296,852 | <p>changed:</p>
<p>from
stat = raw_input(text)</p>
<p>to
stat = int(raw_inpur(text))</p>
<p>problem solved</p>
| 0 | 2016-09-02T16:18:09Z | [
"python"
] |
Replace in string with alternation | 39,296,886 | <p>I want to replace <code>##</code> with <code><<</code> and <code>>></code> with alternation. For example <code>abc##123##qwe##asd##</code> to <code>abc<<123>>qwe<<asd>></code>. Of course I can read symbols one by one, check them, do the replace to <code><<</code> if it's eve... | 0 | 2016-09-02T16:20:18Z | 39,297,787 | <p>you can use following statement to change only pair of <code>##</code> and leave non-matching <code>##</code> as it is</p>
<pre><code>d = "abc##123##qwe##asd"
re.sub(r'(##)(.*?)(?(1)##)', r'<<\2>>', d)
# 'abc<<123>>qwe##asd'
</code></pre>
<p>or you can do this</p>
<pre><code>re.sub(r'(##)... | 0 | 2016-09-02T17:22:57Z | [
"python",
"string",
"replace"
] |
How to fight with "maximum recursion depth exceeded" using matplotlib.pyplot | 39,296,892 | <p>The following code adds point on canvas by left click, draws a polyline with the drawn points by right click and also draws a sliding point on the lines while a cursor is moving. The only problem is that the execution stops pretty soon after "sliding" because of the title reason. How can I overcome this problem and ... | 0 | 2016-09-02T16:20:54Z | 39,299,342 | <p>Okey, fellas, I got it. The problem was due to intensive use of <strong>plt.show()</strong> in the event handler. Replacing it with <strong>event.canvas.draw()</strong> does the job.</p>
| 0 | 2016-09-02T19:15:16Z | [
"python",
"matplotlib"
] |
Change the facecolor of boxplot in pandas | 39,297,093 | <p>I need to change the colors of the boxplot drawn using <code>pandas</code> utility function. I can change most properties using the <code>color</code> argument but can't figure out how to change the <code>facecolor</code> of the box. Someone knows how to do it?</p>
<pre><code>import pandas as pd
import numpy as np
... | 1 | 2016-09-02T16:32:52Z | 39,297,393 | <p>While I still recommend seaborn and raw matplotlib over the plotting interface in pandas, it turns out that you can pass <code>patch_artist=True</code> as a kwarg to <code>df.plot.box</code>, which will pass it as a kwarg to <code>df.plot</code>, which will pass is as a kwarg to <code>matplotlib.Axes.boxplot</code>.... | 1 | 2016-09-02T16:54:49Z | [
"python",
"pandas",
"matplotlib",
"boxplot"
] |
Change the facecolor of boxplot in pandas | 39,297,093 | <p>I need to change the colors of the boxplot drawn using <code>pandas</code> utility function. I can change most properties using the <code>color</code> argument but can't figure out how to change the <code>facecolor</code> of the box. Someone knows how to do it?</p>
<pre><code>import pandas as pd
import numpy as np
... | 1 | 2016-09-02T16:32:52Z | 39,352,762 | <p>As suggested, I ended up creating a function to plot this, using raw <code>matplotlib</code>. </p>
<pre><code>def plot_boxplot(data, ax):
bp = ax.boxplot(data.values, patch_artist=True)
for box in bp['boxes']:
box.set(color='DarkGreen')
box.set(facecolor='DarkGreen')
for whisker in bp[... | 0 | 2016-09-06T15:29:29Z | [
"python",
"pandas",
"matplotlib",
"boxplot"
] |
Is it possible to kill the parent thread from within a child thread in python? | 39,297,166 | <p>I am using Python 3.5.2 on windows. </p>
<p>I would like to run a python script but guarantee that it will not take more than <strong>N</strong> seconds. If it <em>does</em> take more than <strong>N</strong> seconds, an exception should be raised, and the program should exit. Initially I had thought I could just la... | 1 | 2016-09-02T16:38:45Z | 39,297,260 | <p>If the parent thread is the root thread, you may want to try <code>os._exit(0)</code>.</p>
<pre><code>import os
import threading
import time
def may_take_a_long_time(name, wait_time):
print("{} started...".format(name))
time.sleep(wait_time)
print("{} finished!.".format(name))
def kill():
time.sle... | 1 | 2016-09-02T16:45:59Z | [
"python",
"multithreading",
"time"
] |
Is it possible to kill the parent thread from within a child thread in python? | 39,297,166 | <p>I am using Python 3.5.2 on windows. </p>
<p>I would like to run a python script but guarantee that it will not take more than <strong>N</strong> seconds. If it <em>does</em> take more than <strong>N</strong> seconds, an exception should be raised, and the program should exit. Initially I had thought I could just la... | 1 | 2016-09-02T16:38:45Z | 39,297,315 | <p>You can use <a href="https://docs.python.org/2/library/thread.html" rel="nofollow"><code>_thread.interrupt_main</code></a> (this module is called <code>thread</code> in Python 2.7):</p>
<pre><code>import time, threading, _thread
def long_running():
while True:
print('Hello')
def stopper(sec):
time... | 2 | 2016-09-02T16:49:20Z | [
"python",
"multithreading",
"time"
] |
Python Failed to Verify any CRLs for SSL/TLS connections | 39,297,240 | <p>In Python 3.4, a <code>verify_flags</code> that can be used to check if a certificate was revoked against CRL, by set it to <code>VERIFY_CRL_CHECK_LEAF</code> or <code>VERIFY_CRL_CHECK_CHAIN</code>.</p>
<p>I wrote a simple program for testing. But on my systems, this script failed to verify ANY connections even if ... | 0 | 2016-09-02T16:44:23Z | 39,297,998 | <p>To check against CRL you have to manually download the CRL and put them in the right place so that the underlying OpenSSL library will find it. There is no automatic downloading of CRL and specifying the place where to look for the CRL is not intuitive either. What you can do:</p>
<ul>
<li>get the CRL distribution ... | 1 | 2016-09-02T17:36:49Z | [
"python",
"ssl"
] |
For Loop Not Respecting Continue Command | 39,297,255 | <p>The problem I'm having is that the <code>continue</code> command is skipping inconsistently. It skips the numerical output <code>ebitda</code> but puts the incorrect <code>ticker</code> next to it. Why is this? If I make the ticker just <code>phm</code> an input it should skip, it correctly prints an empty list <cod... | -2 | 2016-09-02T16:45:11Z | 39,297,366 | <p>The <code>continue</code> works just fine. You produce this list:</p>
<pre><code>[73961996288, 8618000384]
</code></pre>
<p>However, you then zip that list with <code>ticker</code>, which still has 3 elements in it, including <code>'phm'</code>. <code>zip()</code> stops when one of the iterables is empty, so you p... | 2 | 2016-09-02T16:53:02Z | [
"python",
"for-loop",
"continue"
] |
Is there a faster way to change the 0s in a linespace? | 39,297,284 | <p>I'm working with Jupyter Notebooks and I need to do some calculations using a <code>linspace</code> which go to <code>b</code> from <code>a</code>, the problem is that I get the Zero Division Error, so I was wondering if there was a faster way to change the 0s in a linespace, instead of going trough each element, ch... | 0 | 2016-09-02T16:47:26Z | 39,297,412 | <pre><code>a= numpy.linspace(...)
zero_mask = a==0
</code></pre>
<p>is that what you mean?</p>
| 2 | 2016-09-02T16:55:44Z | [
"python",
"numpy"
] |
Store Scraped WebPage with Python SqlAlchemy | 39,297,328 | <p>I do many look ups and scrapes of webpages and I would like to store the response to those lookups in a database to avoid having to request them again (to improve speed but also to not be a nuisance). I am using sqlalchemy and python, and I've created an ORM class like below:</p>
<pre><code>class MyClass(Base):
... | 0 | 2016-09-02T16:50:14Z | 39,297,653 | <p>I think, escape the url before store it will resolve the problem.</p>
<p>eg:</p>
<pre><code>article = requests.get(url).text
url = url.replace(":", "COLON")
session.add(MyClass(url=url,article=article)
</code></pre>
<p>In a similar way, you can restore it when you take data out</p>
| -1 | 2016-09-02T17:12:12Z | [
"python",
"web-scraping",
"sqlalchemy"
] |
Detecting merged cells in a word document table | 39,297,368 | <p><strong>A little background</strong></p>
<p>I have a software specification which I need to parse requirements from in the form of tables. They are not always in the same format either. I inherited a python script that uses win32com to parse the word document, and then openpyxl to export the requirements to an exce... | 0 | 2016-09-02T16:53:05Z | 39,297,551 | <p>According to <a href="https://msdn.microsoft.com/en-us/library/office/ff821310.aspx" rel="nofollow">the doc</a> merged cells in Word become one cell after being merged (<a href="https://msdn.microsoft.com/en-us/library/office/ff840729.aspx" rel="nofollow">unlike excel</a>). So the concept of merged cells do not real... | 0 | 2016-09-02T17:05:56Z | [
"python",
"vba",
"ms-word",
"win32com"
] |
Finding square root without using math.sqrt()? | 39,297,441 | <p>I recently was working on finding the square root of a number in <code>python</code> without using <code>sqrt()</code>. I came across this code and am having difficulty in understanding the logic in this code:</p>
<pre><code>def sqrt(x):
last_guess= x/2.0
while True:
guess= (last_guess + x/last_gues... | 0 | 2016-09-02T16:57:45Z | 39,297,698 | <p>You can always use the power (<code>**</code>) operator with an inverse exponent:</p>
<pre><code>a = 2 ** (1.0 / 2)
a
> 1.41421...
</code></pre>
| 1 | 2016-09-02T17:16:07Z | [
"python",
"square-root"
] |
How to properly run a Python script from PHP | 39,297,480 | <p>I have a PHP script that unzips an archive containing Python scripts into a directory, str_replaces some things inside the script, shell_exec's the script, and then unlinks the script.</p>
<p>I have no problems unzipping the archive or chmodding the contents to 0755. I can execute the generated scripts through term... | 0 | 2016-09-02T17:00:42Z | 39,307,722 | <p>I'll focus on this line:</p>
<pre><code>shell_exec('python '.$TempScript.' -i '.$CTD);
</code></pre>
<ol>
<li>Seems like <code>$CTD</code> is not defined.</li>
<li>Don't use <code>-i</code> flag because it enforces python prompt.</li>
<li>Try to use <code>exec()</code> instead for better debugging.</li>
</ol>
<p>... | 0 | 2016-09-03T13:58:00Z | [
"php",
"python",
"permissions",
"shell-exec"
] |
Plot CDF + cumulative histogram using Seaborn Python | 39,297,523 | <p>Is there a way to plot the CDF + cumulative histogram of a Pandas Series in Python using Seaborn only? I have the following:</p>
<pre><code>import numpy as np
import pandas as pd
import seaborn as sns
s = pd.Series(np.random.normal(size=1000))
</code></pre>
<p>I know I can plot the cumulative histogram with <code>... | 0 | 2016-09-02T17:03:50Z | 39,306,779 | <pre><code>import numpy as np
import seaborn as sns
x = np.random.randn(200)
sns.distplot(x,
hist_kws=dict(cumulative=True),
kde_kws=dict(cumulative=True))
</code></pre>
<p><a href="http://i.stack.imgur.com/eBDry.png" rel="nofollow"><img src="http://i.stack.imgur.com/eBDry.png" alt="enter im... | 2 | 2016-09-03T12:17:17Z | [
"python",
"pandas",
"seaborn"
] |
missing last bin in histogram plot from matplot python | 39,297,630 | <p>I'm trying to draw histrogram based of my value </p>
<pre><code>x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
'2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8',
'8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
'5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x... | 0 | 2016-09-02T17:10:34Z | 39,297,910 | <pre><code>import matplotlib.pyplot as plt
x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
'2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8',
'8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
'5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x]
key = '0123456789'
fo... | 1 | 2016-09-02T17:30:30Z | [
"python",
"matplotlib"
] |
Python module runs but shows "Syntax error while detecting tuple" in aptana | 39,297,634 | <p>I am learning python and when I was running the below code</p>
<pre><code>print("X",end='awesome')
</code></pre>
<p>The code runs but shows the following syntax error</p>
<pre><code>"Syntax error while detecting tuple"
</code></pre>
<p>How I can resolve it?</p>
| 0 | 2016-09-02T17:11:11Z | 39,297,887 | <p>Aptana is set to use syntax checking for Python 2.x, where <code>print</code> is a statement. It is recognizing this statement as if you were trying to print a tuple, which is what that would be in Python 2.x, and correctly pointing out that you can't have an <code>=</code> sign inside the tuple. But the code is wri... | 1 | 2016-09-02T17:29:00Z | [
"python",
"aptana"
] |
Kivy Screen class bug | 39,297,676 | <p>For some reason in kivy when you create a screen class and add a widget to it, specifically an image you get an image 10x bigger than the original for some reason compared to when you make a widget class and add that widget class as a child to the screen class. Here is my code for the kv file: </p>
<pre><code><S... | 0 | 2016-09-02T17:13:53Z | 39,307,415 | <pre><code><MainScreen>
name: 'Main'
orientation: 'vertical'
FloatLayout:
Image:
source: r'Images\Button.png'
allow_stretch: True
keep_ratio: False
size: 100, 100
</code></pre>
<p>I didn't check if it's causing your particular issue, but the Ima... | 1 | 2016-09-03T13:25:25Z | [
"python",
"kivy",
"kivy-language"
] |
if two requirements in a multiple if statement are meet than the next time they are meet I want to check something else | 39,297,689 | <p>So this is the code I have right now.</p>
<pre><code>count1_1 = 0
previous_1 = False
for i in B:
if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
if A[i] * A[i + 2] == 1:
current_1 = i % 10 == 1
if current_1 and previous_1:
count1_1 += 1
previous_1 = current_... | -2 | 2016-09-02T17:15:22Z | 39,298,135 | <p>I think that I get it</p>
<pre><code>def my_count(A):
count = 0
previous=False
for i in range(1, len(A)-2, 10):
current = A[i] * A[i + 2] == 1
if previous and current:
count += 1
previous = current
return count
data=[ 0, 1, 1, 1, 4, 1, 6, 1, 8... | 0 | 2016-09-02T17:46:41Z | [
"python"
] |
Why does this very basic query on this Django model fail? | 39,297,718 | <p>I have the following Django class:</p>
<pre><code>from caching.base import CachingManager, CachingMixin
from mptt.models import MPTTModel
def make_id():
'''
inspired by http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram
'''
START_TIME = 1876545318034
return (int(... | 0 | 2016-09-02T17:18:03Z | 39,297,795 | <p>It could be you have no My_Class with id = 5000</p>
<pre><code>try:
mc = My_Class.objects.get(pk=id)
except My_Class.DoesNotExist:
mc = None
</code></pre>
| 2 | 2016-09-02T17:23:21Z | [
"python",
"django",
"django-queryset"
] |
Python List assignment and memory allocation | 39,297,776 | <p>Why does index assignment of another list form a linked list and list slice(one element slice) assignment of another list makes the list part of the original list when both the slice and element with the index points the same element? What changes happen in the memory allocation?</p>
<pre><code>l = [1,2,3,4,5,6]
l[... | 0 | 2016-09-02T17:22:03Z | 39,312,203 | <p>Your assumption is incorrect, when you say <em>"initialy l[2]=3 and l[2:3]=3"</em>.</p>
<p>This is how it is, in fact:</p>
<pre><code>l = [1, 2, 3, 4, 5, 6]
l[2] # 3
l[2:3] # [3]
</code></pre>
<p><code>l[2]</code> is the element at index 2.
<code>l[2:3]</code> is the slice (a sublist) of length one starting a... | 1 | 2016-09-03T23:27:31Z | [
"python",
"list"
] |
How to store Dict type result in database? | 39,297,785 | <p>I am using using <strong>facebook.graphAPI</strong> in python for searching restaurants in some specific city. The result it gives back is in <strong>DICT</strong> type.<br>
My Code:</p>
<pre><code>import facebook
import json
# get access_token from https://developers.facebook.com/tools/access_token/
graph = face... | 0 | 2016-09-02T17:22:48Z | 39,297,920 | <p>Start by having an accessible Database server. Either set one up locally or if you have the means, set one up remotely.
The image you attached to the question looks like a windows terminal, so download the MySQL Community Server for windows <a href="http://dev.mysql.com/downloads/mysql/" rel="nofollow">here</a>. </... | 0 | 2016-09-02T17:31:09Z | [
"python",
"json",
"facebook-graph-api"
] |
Shell.BrowseForFolder in Python, how to retrieve folder path | 39,297,801 | <p>I have the following code which displays the Windows folder selection window:</p>
<pre><code>from comtypes.client import CreateObject
shell = CreateObject("Shell.Application")
folder = shell.BrowseForFolder(0, "Select a folder", 1)
</code></pre>
<p>The Microsoft doc doesn't say anything about how to retrieve (the ... | 0 | 2016-09-02T17:23:48Z | 39,298,285 | <p>As said TessellatingHeckler above, it works with win32com:</p>
<pre><code>import win32com.client
shell = win32com.client.Dispatch("Shell.Application")
folder = shell.BrowseForFolder(0, "Now browse...", 1)
print(folder.Self.Path)
</code></pre>
<p>But if you really want to use comtypes, here is a workaround:</p>
<... | 0 | 2016-09-02T17:57:50Z | [
"python",
"activex",
"comtypes"
] |
How to skip an unknown number of empty lines before header on pandas.read_csv? | 39,297,878 | <p>I want to read a dataframe from a csv file where the header is not in the first line. For example:</p>
<pre><code>In [1]: import pandas as pd
In [2]: import io
In [3]: temp=u"""#Comment 1
...: #Comment 2
...:
...: #The previous line is empty
...: Header1|Header2|Header3
...: 1|2|3
...: 4|5|6
... | 1 | 2016-09-02T17:28:39Z | 39,298,213 | <p>You need to set <code>skip_blank_lines=True</code></p>
<pre><code>df = pd.read_csv(io.StringIO(temp), sep="|", comment="#", skip_blank_lines=True).dropna()
</code></pre>
| 3 | 2016-09-02T17:52:17Z | [
"python",
"csv",
"pandas",
"file-io",
"data-import"
] |
confused by tornado.concurrent.Future exception | 39,297,897 | <p>I'm trying to implement a variant of <a href="http://stackoverflow.com/questions/37849128/tornado-one-handler-blocks-for-another">this question</a> using tornado Futures. The queues a problem, because I don't want to past data being accumulated. IOW, I want the one http request handler to block waiting for result of... | 1 | 2016-09-02T17:29:31Z | 39,298,214 | <p>You need to use</p>
<pre><code>result = yield future
</code></pre>
<p>Not</p>
<pre><code>result = yield future.result()
</code></pre>
<p><code>yield future.result()</code> is actually equivalent to <code>yield <whatever is returned by future.result()></code>. If the result isn't ready yet, that means that ... | 2 | 2016-09-02T17:52:26Z | [
"python",
"python-3.x",
"promise",
"tornado",
"future"
] |
CSV file unread columns | 39,297,959 | <p>l m trying to get data from CSV file and there are three column ("date",stations","pcp" ) including 41 years data set. l would like to get these data separately.</p>
<p>example dataset:</p>
<pre><code> date stations pcp
1.01.1979 6 1.071
2.01.1979 6 5.909
3.01.1979 6 9.134
1.01.1979 5 1.2... | 1 | 2016-09-02T17:33:53Z | 39,298,206 | <p>Your input file (<code>p2.csv</code>):</p>
<pre><code>date stations pcp
1.01.1979 6 1.071
2.01.1979 6 5.909
3.01.1979 6 9.134
1.01.1979 5 1.229
2.01.1979 5 0.014
3.01.1979 5 3.241
</code></pre>
<p>Your code:</p>
<pre><code>import csv
import numpy as np
with open('p2.csv') as csvfile:
reader = csv.DictReader(... | 1 | 2016-09-02T17:51:38Z | [
"python",
"csv"
] |
Generating 15 minute time interval array in python | 39,298,054 | <p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array =
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm... | 2 | 2016-09-02T17:40:53Z | 39,298,331 | <p>Looking at the data file, you should use the built in python date-time objects. followed by <code>strftime</code> to format your dates. </p>
<p>Broadly you can modify the code below to however many date-times you would like
First create a starting date. </p>
<pre><code>Today= datetime.datetime.today()
</code></pre... | 3 | 2016-09-02T18:00:25Z | [
"python",
"arrays",
"python-2.7"
] |
Generating 15 minute time interval array in python | 39,298,054 | <p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array =
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm... | 2 | 2016-09-02T17:40:53Z | 39,298,362 | <p>Here's a generic <code>datetime_range</code> for you to use.</p>
<h3>Code</h3>
<pre><code>from datetime import datetime, timedelta
def datetime_range(start, end, delta):
current = start
while current < end:
yield current
current += delta
dts = [dt.strftime('%Y-%m-%d T%H:%M Z') for dt i... | 1 | 2016-09-02T18:02:54Z | [
"python",
"arrays",
"python-2.7"
] |
Generating 15 minute time interval array in python | 39,298,054 | <p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array =
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm... | 2 | 2016-09-02T17:40:53Z | 39,298,434 | <p>I'll provide a solution that does <em>not</em> handle timezones, since the problem is generating dates and times and you can set the timezone afterwards however you want.</p>
<p>You have a starting date and starting and ending time (for each day), plus an interval (in minutes) for these datetimes. The idea is to c... | 2 | 2016-09-02T18:07:11Z | [
"python",
"arrays",
"python-2.7"
] |
Generating 15 minute time interval array in python | 39,298,054 | <p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array =
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm... | 2 | 2016-09-02T17:40:53Z | 39,298,697 | <p>Here is an example using an arbitrary date time</p>
<pre><code>from datetime import datetime
start = datetime(1900,1,1,0,0,0)
end = datetime(1900,1,2,0,0,0)
</code></pre>
<p>Now you need to get the timedelta (the difference between two dates or times.) between the <code>start</code> and <code>end</code></p>
<pre... | 1 | 2016-09-02T18:26:39Z | [
"python",
"arrays",
"python-2.7"
] |
Generating 15 minute time interval array in python | 39,298,054 | <p>I am new to python. I am trying to generate time interval array. for example:
<code>
time_array =
["2016-09-02T17:30:00Z", "2016-09-02T17:45:00Z", "2016-09-02T18:00:00Z", "2016-09-02T18:15:00Z", "2016-09-02T18:30:00Z", "2016-09-02T18:45:00Z"]
</code>
1. It should create the element like above in zulu time till 9 pm... | 2 | 2016-09-02T17:40:53Z | 39,303,050 | <p>This is the final script I have written based on the answers posted on my question:</p>
<pre><code>from datetime import datetime
from datetime import timedelta
import calendar
current_utc = datetime.utcnow().strftime("%Y-%m-%d-%H-%M-%S")
current_year = int(current_utc.split("-")[0])
current_month = int(current_ut... | 0 | 2016-09-03T03:47:12Z | [
"python",
"arrays",
"python-2.7"
] |
I'm trying to enhance the contrast of image using following code | 39,298,057 | <p>Here i'm trying to:
- Apply Adaptive filtering to image .
- Enhance the contrast of image .
my code is as follow : </p>
<pre><code>#!/usr/bin/python
import cv2
import numpy as np
import PIL
from PIL import ImageFilter
from matplotlib import pyplot as plt
img = cv2.imread('Crop.jpg',0)
cv2.imshow('origin... | 0 | 2016-09-02T17:41:08Z | 39,299,335 | <p>You may confuse with <a href="http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html?highlight=.smooth#cv.Smooth" rel="nofollow">cv.Smooth</a></p>
| 0 | 2016-09-02T19:14:53Z | [
"python",
"image",
"numpy"
] |
Linking a Kivy Button to Function | 39,298,059 | <p>There is something in kivy I do not understand, and am hoping that someone could shed light. I have done a lot of reading in this topic but it just doesn't seem to be connecting in my head.</p>
<p>My issue comes from linking a function to a kivy button.
Right now I am trying to learn how to do a simple function:</p... | 2 | 2016-09-02T17:41:14Z | 39,299,585 | <pre><code><AnotherScreen>:
name: "other"
FloatLayout:
Button:
...
on_release: root.add <-- here *root* evaluates to the top widget in the rule.
</code></pre>
<p>Which is an AnotherScreen instance, but it doesn't have an <code>add</code> method.</p>
<pre><code>class M... | 0 | 2016-09-02T19:34:37Z | [
"python",
"kivy",
"kivy-language"
] |
Formatting json strings in Python | 39,298,089 | <p>I have a query that runs and creates a dataframe like below:</p>
<pre><code>Group Hour
G1 0
G1 4
G2 1
G3 5
</code></pre>
<p>I then write the dataframe to a json file using</p>
<pre><code>out = df1.to_json(orient='records')[1:-1].replace('},{', '} {')
</code></pre>
<p>Currently my ou... | -1 | 2016-09-02T17:43:37Z | 39,298,130 | <p>Just change the <code>.replace('},{', '} {')</code> part to <code>.replace('},{', '}\n{')</code>?</p>
| 0 | 2016-09-02T17:46:21Z | [
"python",
"json",
"pandas"
] |
Django: Create new data sets automatically | 39,298,091 | <p>I have three models. <code>Question</code>, <code>Person</code> and <code>Response</code>. Every person can only have one answer or response to a question. Because of that, I use <code>unique_together</code>:</p>
<pre><code>class Meta:
unique_together = (("question", "person"),)
</code></pre>
<p>So, my... | 0 | 2016-09-02T17:43:50Z | 39,299,112 | <p>Use a post save signal. Documentation here: <a href="https://docs.djangoproject.com/en/1.10/ref/signals/" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/signals/</a></p>
| 0 | 2016-09-02T18:59:00Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Pandas dataframe - data type issue | 39,298,108 | <p>I am trying to create a <code>pd.DataFrame</code>, but I am having trouble getting the data type correct. I have two <code>numpy</code> arrays that are type <code>float</code>.</p>
<p>They were created from a list of coordinates (x & y) as seen here:</p>
<pre><code># Take coordinates from list and convert to a... | -1 | 2016-09-02T17:45:05Z | 39,298,302 | <p>This is the scientific notation of the same number. 1.895464e+06 means 1.895464*10^6 = 1895465. So the decimal place did not shift, just the representation. If you want to change the looks of the numbers, look at <a href="http://pandas.pydata.org/pandas-docs/stable/options.html" rel="nofollow">http://pandas.pydata.o... | 3 | 2016-09-02T17:58:49Z | [
"python",
"pandas",
"numpy"
] |
Boofuzz Doesn't Restart Process After Crash | 39,298,133 | <p>I'm learning how to fuzz using boofuzz. I have everything setup on a Windows 7 VM. The target is the Vulnserver application. Since I know the <code>TRUN</code>, <code>GMON</code>, and <code>KSTET</code> commands are vulnerable, I put these commands in a <code>s_group</code> list. I expect the <code>vulnserver.exe</c... | 3 | 2016-09-02T17:46:33Z | 39,311,029 | <h2>TL;DR</h2>
<p>The failure to restart is a result of a series of bugs. Run <code>pip install --upgrade boofuzz</code> to get <a href="https://pypi.python.org/pypi/boofuzz/0.0.5" rel="nofollow">v0.0.5</a> or later, or pull down the latest code from <a href="https://github.com/jtpereyda/boofuzz/" rel="nofollow">Githu... | 0 | 2016-09-03T20:24:03Z | [
"python",
"fuzzing"
] |
Stop the thread from inside the target function? | 39,298,143 | <p>Is there a way that I can stop the thread after few seconds (INTERNALLY)</p>
<pre><code>t1 = Thread(target=call_script1, args=())
t2 = Thread(target=call_script2, args=())
t3 = Thread(target=call_script3, args=())
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
</code></pre>
<p>The Main program wa... | 0 | 2016-09-02T17:47:18Z | 39,298,705 | <p>The <a href="https://docs.python.org/3/library/threading.html#threading.Thread" rel="nofollow"><code>Thread.join</code></a> method has an optional <code>timeout</code> parameter.</p>
<pre><code># block until thread ``t`` completes, or just wait 3 seconds
t.join(3)
</code></pre>
<p>If you want the target function t... | 0 | 2016-09-02T18:27:23Z | [
"python",
"multithreading"
] |
Stop the thread from inside the target function? | 39,298,143 | <p>Is there a way that I can stop the thread after few seconds (INTERNALLY)</p>
<pre><code>t1 = Thread(target=call_script1, args=())
t2 = Thread(target=call_script2, args=())
t3 = Thread(target=call_script3, args=())
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
</code></pre>
<p>The Main program wa... | 0 | 2016-09-02T17:47:18Z | 39,298,758 | <p>I think you can get the behavior you want by using the <code>timeout</code> parameter available on the <code>serial.Serial()</code> constructor. Additionally, you'll need to protect your interactions with the <code>Serial</code> instance with a <code>threading.Lock()</code>, so that your threads don't step on each o... | 1 | 2016-09-02T18:32:04Z | [
"python",
"multithreading"
] |
Hello! I am trying to set a line of a text file to a variable | 39,298,160 | <p>I used an if statement to see if the variable assignment worked but I think I am formatting something wrong. I tried this with and without the \n. Any help would be greatly appreciated.</p>
<pre><code>lines=[] #creates a list
file = open("gmail.txt", "r") #opens the text file
for line in file:
lines.append(lin... | -1 | 2016-09-02T17:48:41Z | 39,298,634 | <p>I think you're asking about how to read from a file. Here's the Pythonic way:</p>
<pre><code>with open('gmail.txt') as f:
for line in f:
print(line)
</code></pre>
<p>If you want to save all the lines of the file into a list of lines:</p>
<pre><code>with open('gmail.txt') as f:
lines = f.readlines(... | 0 | 2016-09-02T18:22:11Z | [
"python",
"text-files"
] |
Selecting highest rows on matrix pandas python. | 39,298,235 | <p>I have the following data:</p>
<p><a href="https://github.com/antonio1695/Python/blob/master/nearBPO/facturasb.csv" rel="nofollow">https://github.com/antonio1695/Python/blob/master/nearBPO/facturasb.csv</a></p>
<p>It is a matrix like the following example:</p>
<pre><code>UUID A B C D E F G H I
... | 1 | 2016-09-02T17:53:39Z | 39,298,355 | <p>IIUC</p>
<pre><code>df[df.sum().nlargest(3).index]
</code></pre>
<p><a href="http://i.stack.imgur.com/V6YQi.png" rel="nofollow"><img src="http://i.stack.imgur.com/V6YQi.png" alt="enter image description here"></a></p>
<hr>
<p>To exclude rows with all zeros among the n largest</p>
<pre><code>n = df.sum().nlarges... | 3 | 2016-09-02T18:02:08Z | [
"python",
"pandas",
"matrix"
] |
Selecting highest rows on matrix pandas python. | 39,298,235 | <p>I have the following data:</p>
<p><a href="https://github.com/antonio1695/Python/blob/master/nearBPO/facturasb.csv" rel="nofollow">https://github.com/antonio1695/Python/blob/master/nearBPO/facturasb.csv</a></p>
<p>It is a matrix like the following example:</p>
<pre><code>UUID A B C D E F G H I
... | 1 | 2016-09-02T17:53:39Z | 39,298,562 | <p>Let's break this task into two parts. First, find which columns have the most <code>1</code>'s. Second, select only those columns.</p>
<p>Here's some data:</p>
<pre><code>In [1]: import numpy as np
In [2]: import pandas as pd
In [3]: import string
In [4]: data = np.random.randint(2, size=(10, 10))
In [5]: data... | 0 | 2016-09-02T18:16:03Z | [
"python",
"pandas",
"matrix"
] |
running a python script within Flask | 39,298,249 | <p>So I have this simple python script running on Flask that I'd like to pass variables to with an ajax jQuery request. I might be missing something obvious but I can't get it to work properly. </p>
<pre><code>@app.route('/test', methods=['GET', 'POST'])
def test():
my_int1 = request.args.get('a')
my_int2 = re... | 0 | 2016-09-02T17:54:44Z | 39,298,381 | <p>Please refer to <a href="http://flask.pocoo.org/docs/0.11/api/#flask.Request" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/#flask.Request</a></p>
<pre><code>request.args : If you want the parameters in the URL
request.form : If you want the information in the body (as sent by a html POST form)
request.values... | 1 | 2016-09-02T18:04:12Z | [
"jquery",
"python",
"ajax",
"flask"
] |
running a python script within Flask | 39,298,249 | <p>So I have this simple python script running on Flask that I'd like to pass variables to with an ajax jQuery request. I might be missing something obvious but I can't get it to work properly. </p>
<pre><code>@app.route('/test', methods=['GET', 'POST'])
def test():
my_int1 = request.args.get('a')
my_int2 = re... | 0 | 2016-09-02T17:54:44Z | 39,298,852 | <p>It appears your jQuery reference on that HTML page is not being loaded or not correct, please add this in the <code><head> here </head></code> section of your HTML page.</p>
<pre><code><script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</code></pre>
| 0 | 2016-09-02T18:40:04Z | [
"jquery",
"python",
"ajax",
"flask"
] |
running a python script within Flask | 39,298,249 | <p>So I have this simple python script running on Flask that I'd like to pass variables to with an ajax jQuery request. I might be missing something obvious but I can't get it to work properly. </p>
<pre><code>@app.route('/test', methods=['GET', 'POST'])
def test():
my_int1 = request.args.get('a')
my_int2 = re... | 0 | 2016-09-02T17:54:44Z | 39,300,543 | <p>Please, try with the following code and let me know if that's what you are looking for:</p>
<pre><code>from flask import Flask, request
import csv
app = Flask(__name__)
@app.route('/test', methods=['GET', 'POST'])
def test():
if request.is_xhr:
a = request.json['a']
b = request.json['b']
... | 1 | 2016-09-02T20:51:16Z | [
"jquery",
"python",
"ajax",
"flask"
] |
Python Pandas: Check if all columns in rows value is NaN | 39,298,372 | <p>Kindly accept my apologies if my question has already been answered. I tried to find a solution but all I can find is to dropna solution for all NaN's in a dataframe.
My question is that I have a dataframe with 6 columns and 500 rows. I need to check if in any particular row all the values are NaN so that I can dro... | 0 | 2016-09-02T18:03:31Z | 39,298,489 | <blockquote>
<p>I need to check if in any particular row all the values are NaN so that I can drop them from my dataset. </p>
</blockquote>
<p>That's exactly what <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html" rel="nofollow"><code>pd.DataFrame.dropna(how='all')</code></a... | 1 | 2016-09-02T18:11:22Z | [
"python",
"pandas",
null
] |
something better than time.time()? | 39,298,445 | <p>My team and I are designing a project which requires the detection of rising edge of a square wave and then storing the time using time.time() in a variable.If a same square wave is given to 3 different pins of RPi,and event detection is applied on each pin,theoretically,they should occur at the same time,but they h... | 1 | 2016-09-02T18:08:00Z | 39,298,941 | <p><code>time.time</code> uses <code>gettimeofday</code> on platforms that support it. That means its resolution is in microseconds.</p>
<p>You might try using <code>time.clock_gettime(time.CLOCK_REALTIME)</code> which provides nanosecond resolution (assuming the underlying hardware/OS provides that). The result still... | 0 | 2016-09-02T18:46:51Z | [
"python",
"time",
"soc"
] |
Whitenoise, Mezzanine, Django -ImportError: cannot import name ManifestStaticFilesStorage | 39,298,540 | <p>I am trying to deploy my mezzanine project on heroku. The last error gives me an ultimate stack- ImportError: cannot import name ManifestStaticFilesStorage. Here is my core project structure:</p>
<pre><code>âââ deploy
â  âââ crontab
â  âââ gunicorn.conf.py.template
â  âââ loca... | 0 | 2016-09-02T18:14:37Z | 39,307,701 | <p>ManifestStaticFilesStorage was introduced in Django 1.7. Are you using an older version of Django? If so, you should upgrade to a <a href="https://www.djangoproject.com/download/#supported-versions" rel="nofollow">supported version</a>.</p>
<p>It's still possible to use <a href="http://whitenoise.evans.io/en/legacy... | 1 | 2016-09-03T13:55:08Z | [
"python",
"django",
"heroku",
"gunicorn",
"mezzanine"
] |
Protecting a view without requiring login in Django? | 39,298,659 | <p>I'm trying to password protect my registration page in Django without requiring the user to login, but I can't seem to figure it out. My flow should be:</p>
<ol>
<li>User accesses mydomain.com/register/</li>
<li>User enters password into <code>registration_access</code> form</li>
<li>If unsuccessful, user re-enters... | 0 | 2016-09-02T18:23:48Z | 39,298,924 | <p>"Redirect" means, by definition, to redirect back to the server. Thus you need to redirect to a URL. You can redirect to the same URL, but then you'd need to write your view to be able to handle the different things you want to do.</p>
<p>To me, it sounds like you'd be better served using Javascript and handle thin... | 0 | 2016-09-02T18:45:38Z | [
"python",
"django"
] |
Anaconda Python virtualdev can't find libpython3.5m.so.1.0 on Windows Subsystem for Linux (Ubuntu 14.04) | 39,298,681 | <p>I installed Python 3.5.2 using Anaconda 4.1.1 on the Windows Anniversary Edition Linux Subsystem (WSL), which is more or less embedded Ubuntu 14.04.5 LTS.</p>
<p>I installed virtualenv using:</p>
<pre><code>pip install virtualenv
</code></pre>
<p>Then I tried to create a virtual environment inside <code>~/temp</c... | 1 | 2016-09-02T18:25:31Z | 39,370,303 | <p>I have not experienced the same issue or tried to replicate the WSL environment. But usually when something similar happens with other libraries it is just likely to be a poorly configured environment. You have to checkout your library path:</p>
<pre><code>echo $LD_LIBRARY_PATH
</code></pre>
<p>And make sure the d... | 1 | 2016-09-07T12:44:17Z | [
"python",
"linux",
"ubuntu",
"virtualenv",
"wsl"
] |
Selenium Python: What are the errors in my code? | 39,298,794 | <p>i would like to know why this code opens mozilla twice, and why it doesn´t close it when finishes. Furthermore, i don´t understand 100% why login is a class with a function, and not a function directly.</p>
<pre><code>> import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import We... | 0 | 2016-09-02T18:35:27Z | 39,298,899 | <p>This is because you <em>instantiate webdriver twice</em> - once inside the <code>TestCase</code> and once inside the <code>LoginDetails</code> class.</p>
<h1>Why the other answer is not entirely correct</h1>
<p>The WebDriver should not be controlled by the <code>LoginDetails</code> class in this case. <code>LoginD... | 2 | 2016-09-02T18:44:12Z | [
"python",
"selenium",
"selenium-webdriver",
"webdriver"
] |
Selenium Python: What are the errors in my code? | 39,298,794 | <p>i would like to know why this code opens mozilla twice, and why it doesn´t close it when finishes. Furthermore, i don´t understand 100% why login is a class with a function, and not a function directly.</p>
<pre><code>> import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import We... | 0 | 2016-09-02T18:35:27Z | 39,298,908 | <h1>Firefox opens twice</h1>
<p>In your test <code>self.ld = LoginDetails()</code> runs the <code>__init__</code> function of <code>LoginDetails()</code> which in turn runs <code>webdriver.Firefox()</code> then you issue the same in the next line in the test case. That is why Firefox opens twice. </p>
<h1>Firefox doe... | 2 | 2016-09-02T18:44:42Z | [
"python",
"selenium",
"selenium-webdriver",
"webdriver"
] |
Improving LBP/HAAR detection XML cascades | 39,298,867 | <p>I am trying to do a car detector from UAV images with Python 2.7 and OpenCV 2.4.13. The goal is to detect cars from an upper view in any direction, in urban environments. I am facing time execution and accuracy problems.</p>
<p>Detector works fine when I use it with some cascades that I obtained from internet:</p>
... | 3 | 2016-09-02T18:41:31Z | 39,385,938 | <p>I can't say exactly, but I have an idea why you can't train HAAR (LBP) cascades to detect arbitrary oriented cars. </p>
<p>These cascades work fine when detected objects with approximately the same shape and color (lightness). A frontal oriented face is a good example of these objects. But it works much worse when ... | 0 | 2016-09-08T08:20:16Z | [
"python",
"image",
"opencv",
"object-detection",
"cascade-classifier"
] |
Play multiple sounds at the same time in python | 39,298,928 | <p>I have been looking into a way to play sounds from a list of samples, and I found some modules that can do this.</p>
<p>I am using <strong>AudioLazy</strong> module to play the sound using the following script:</p>
<pre><code>from audiolazy import AudioIO
sound = Somelist
with AudioIO(True) as player:
player.pl... | 2 | 2016-09-02T18:45:53Z | 39,298,977 | <p>I suggest using <a href="https://people.csail.mit.edu/hubert/pyaudio/docs/" rel="nofollow">Pyaudio</a> to do this.</p>
<pre><code>sound1 = wave.open("/path/to/sound1", 'rb')
sound2 = wave.open("/path/to/sound2", 'rb')
def callback(in_data, frame_count, time_info, status):
data1 = sound1.readframes(frame_count)... | 1 | 2016-09-02T18:49:25Z | [
"python",
"audio",
"interactive"
] |
Play multiple sounds at the same time in python | 39,298,928 | <p>I have been looking into a way to play sounds from a list of samples, and I found some modules that can do this.</p>
<p>I am using <strong>AudioLazy</strong> module to play the sound using the following script:</p>
<pre><code>from audiolazy import AudioIO
sound = Somelist
with AudioIO(True) as player:
player.pl... | 2 | 2016-09-02T18:45:53Z | 39,298,998 | <p>Using multiple threads will solve your problem :</p>
<pre><code>import threading
from audiolazy import AudioIO
sound = Somelist
with AudioIO(True) as player:
t = threading.Thread(target=player.play, args=(sound,), kwargs={'rate':44100})
t.start()
</code></pre>
| 1 | 2016-09-02T18:50:26Z | [
"python",
"audio",
"interactive"
] |
Play multiple sounds at the same time in python | 39,298,928 | <p>I have been looking into a way to play sounds from a list of samples, and I found some modules that can do this.</p>
<p>I am using <strong>AudioLazy</strong> module to play the sound using the following script:</p>
<pre><code>from audiolazy import AudioIO
sound = Somelist
with AudioIO(True) as player:
player.pl... | 2 | 2016-09-02T18:45:53Z | 39,644,525 | <p>Here is a simpler solution using <a href="https://github.com/jiaaro/pydub/" rel="nofollow">pydub</a>. </p>
<p>Using <code>overlay</code> function of <code>AudioSegment</code> module, you can very easily <code>superimpose</code> multiple audio on to each other. </p>
<p>Here is a working code to combine three aud... | 1 | 2016-09-22T16:40:25Z | [
"python",
"audio",
"interactive"
] |
python pandas dtypes detection from sql | 39,298,989 | <p>I am quite troubled by the behaviour of Pandas DataFrame about Dtype detection.</p>
<p>I use 'read_sql_query' to retrieve data from a database to build a DataFrame, and then dump it into a csv file.</p>
<p>I don't need any transformation. Just dump it into a csv file and change date fields in the form : <strong>'%... | 0 | 2016-09-02T18:50:06Z | 39,301,020 | <p>It is difficult to dig into your issue without some data samples. However, you probably face either of the two cases:</p>
<ul>
<li>Some of the rows you select in your second case contain <code>NULL</code> values, which stops pandas interpret automatically your column as a datetime</li>
<li>You have a different MDY ... | 1 | 2016-09-02T21:36:48Z | [
"python",
"sql",
"csv",
"pandas",
"dataframe"
] |
python pandas dtypes detection from sql | 39,298,989 | <p>I am quite troubled by the behaviour of Pandas DataFrame about Dtype detection.</p>
<p>I use 'read_sql_query' to retrieve data from a database to build a DataFrame, and then dump it into a csv file.</p>
<p>I don't need any transformation. Just dump it into a csv file and change date fields in the form : <strong>'%... | 0 | 2016-09-02T18:50:06Z | 39,313,375 | <p>Your <code>to-csv</code> operation does not convert all specified date fields because as you mention, not all datetime columns are read in as datetime format but show as string (<em>object</em> dtype) in current dataframe. This is the unfortunate side effect of reading from external sources as the imported system --... | 2 | 2016-09-04T03:49:37Z | [
"python",
"sql",
"csv",
"pandas",
"dataframe"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.