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 to get matplotlib to place lines accurately? | 39,183,658 | <p>By default, matplotlib plot can place lines very inaccurately.</p>
<p>For example, see the placement of the left endpoint in the attached plot. There's at least a whole pixel of air that shouldn't be there. In fact I think the line center is 2 pixels off.</p>
<p>How to get matplotlib to draw <strong>accurately</st... | 2 | 2016-08-27T17:04:28Z | 39,186,474 | <p>Consider the following to see what is going on</p>
<pre><code>import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 4], clip_on=False, lw=5, alpha=.5)
ax.set_xlim([1, 3])
fig.savefig('so.png', dpi=400)
</code></pre>
<p><a href="http://i.stack.imgur.com/1s56E.png" rel="nofollow"><img ... | 2 | 2016-08-27T22:46:43Z | [
"python",
"matplotlib"
] |
strip() works selectively on the input function but properly on a string literal | 39,183,662 | <p>I am trying to understand the <code>strip()</code> function. And I'm seeing a confusing behavior.</p>
<pre><code>import sys
test = input().strip('e')
print(test)
N = input().strip('cmowz.')
print(N)
print('www.example.com'.strip('cmowz.'))
</code></pre>
<p>This gives the following output:</p>
<pre><code>test ... | 0 | 2016-08-27T17:05:00Z | 39,183,691 | <p>According to the <a href="https://docs.python.org/2/library/string.html#string.strip" rel="nofollow">docs</a>:</p>
<blockquote>
<p>string.strip(s[, chars]) Return a copy of the string with leading and
trailing characters removed. If chars is omitted or None, whitespace
characters are removed. If given and not... | 1 | 2016-08-27T17:08:17Z | [
"python",
"python-3.x",
"strip"
] |
strip() works selectively on the input function but properly on a string literal | 39,183,662 | <p>I am trying to understand the <code>strip()</code> function. And I'm seeing a confusing behavior.</p>
<pre><code>import sys
test = input().strip('e')
print(test)
N = input().strip('cmowz.')
print(N)
print('www.example.com'.strip('cmowz.'))
</code></pre>
<p>This gives the following output:</p>
<pre><code>test ... | 0 | 2016-08-27T17:05:00Z | 39,183,694 | <p>From the <a href="https://docs.python.org/2/library/string.html#string.strip" rel="nofollow">documentation</a>:</p>
<blockquote>
<p>Return a copy of the string with <code>leading</code> and <code>trailing</code> characters removed. If chars is omitted or None, whitespace characters are removed. If given and not N... | 2 | 2016-08-27T17:08:44Z | [
"python",
"python-3.x",
"strip"
] |
How to mock components within unit tests for Click-based CLI applications? | 39,183,741 | <p>I'm not sure if this is the best fit for here or the Programmers Stack Exchange, but I'll try here first and cross-post this over there if it's not appropriate.</p>
<p>I've recently developed a web service and I'm trying to create a Python-based command-line interface to make it easier to interact with. I've been u... | 1 | 2016-08-27T17:14:33Z | 39,191,622 | <p>I think I've found one way of doing it. I stumbled across Python's <a href="https://docs.python.org/3/library/unittest.mock.html" rel="nofollow">unittest.mock</a> module, and after a bit of playing around with it I ended up with the following.</p>
<p>In my 'comms' module, I define <code>CommunicationService</code>:... | 0 | 2016-08-28T13:11:33Z | [
"python",
"testing",
"mocking",
"command-line-interface",
"python-click"
] |
Topological Sort not behaving as expected | 39,183,880 | <p>Here's my graph implementation in Python. This is a directed graph.</p>
<pre><code>class DiGraph:
def __init__(self):
self.all_vertices = []
self.vertex_map = {}
self.size = 0
def add(self, a, b):
if a in self.vertex_map:
av = self.vertex_map[a]
if b... | 0 | 2016-08-27T17:28:43Z | 39,183,906 | <p>If <code>v.neighbors</code> is empty, <code>n</code> is never set, so the <code>stack.append(n)</code> <em>outside</em> the <code>for n in v.neighbors:</code> fails.</p>
<p>If all <code>n</code> must be added to the stack (and not just the last), indent <code>stack.append()</code> properly to be inside the loop:</p... | 1 | 2016-08-27T17:32:20Z | [
"python",
"graph",
"topological-sort"
] |
How to view output from print statements with Django on Elastic Beanstalk | 39,183,886 | <p>I am running a Django app on Elastic Beanstalk. If I put a print statement in e.g. <code>admin.py</code>, how can I see the result?</p>
| 0 | 2016-08-27T17:29:52Z | 39,189,921 | <p>You should use logging instead of print, you can look back your log anytime and filter the result depend on different level. Check this out <a href="https://docs.python.org/2/howto/logging-cookbook.html" rel="nofollow">logging cookbook</a></p>
| 0 | 2016-08-28T09:40:43Z | [
"python",
"django",
"amazon-web-services",
"elastic-beanstalk"
] |
regex - swap two phrases around | 39,183,970 | <p>Python 3. Each line is constructed of a piece of text, then a pipe symbol, then a second piece of text.
I want to swap the two pieces of text around and remove the pipe.
This is the code so far:</p>
<pre><code>p = re.compile('^(.*) \| (.*)$', re.IGNORECASE)
mytext = p.sub(r'\2\1', mytext)
</code></pre>
<p>Yet for ... | 1 | 2016-08-27T17:38:15Z | 39,184,013 | <p>sorry if I'm missing something here, but why not just use <code>re.match</code> with groups instead of <code>re.sub</code>?:</p>
<pre><code>import re
p = re.compile('^(.*) \| (.*)$', re.IGNORECASE)
sample = "(https://www.youtube.com/watch?v=NIKdKCQnbNo) | [Regular Expressions 101 - YouTube]"
matches = p.search(sa... | 0 | 2016-08-27T17:42:44Z | [
"python",
"regex",
"python-3.x"
] |
regex - swap two phrases around | 39,183,970 | <p>Python 3. Each line is constructed of a piece of text, then a pipe symbol, then a second piece of text.
I want to swap the two pieces of text around and remove the pipe.
This is the code so far:</p>
<pre><code>p = re.compile('^(.*) \| (.*)$', re.IGNORECASE)
mytext = p.sub(r'\2\1', mytext)
</code></pre>
<p>Yet for ... | 1 | 2016-08-27T17:38:15Z | 39,184,041 | <p>This should help you. (View demo on <a href="https://regex101.com/r/hW2kR9/2" rel="nofollow">regex101</a>)</p>
<pre><code>(\S+)\s*\|\s*(.+)
</code></pre>
<p>Sub with:</p>
<pre><code> \2\1
</code></pre>
| 1 | 2016-08-27T17:45:27Z | [
"python",
"regex",
"python-3.x"
] |
Graphical map objects representation website | 39,183,987 | <p>Sorry this question is too broad, but I need any advice, because I'm facing a task bit above my experience level.</p>
<p>The map should be displayed with database objects like restaurants/events/etc. The suggested platform is Python/Django (which is fine both for me and customer) for both frontend and backend. As a... | 0 | 2016-08-27T17:39:58Z | 39,184,353 | <p>Your plan seems solid.</p>
<blockquote>
<p>Maybe its definetly better to switch to JS frontend for this type of application (as future planning)?</p>
</blockquote>
<p>You're already using JS with leaflet, so I assume you're asking about building your own or using a maps service API directly. That approach will t... | 1 | 2016-08-27T18:21:35Z | [
"javascript",
"python",
"django",
"leaflet"
] |
Google App Engine Error: __init__() got an unexpected keyword argument 'require' | 39,184,071 | <p>I'm doing a tutorial on Google App Engine and I"m getting this error:</p>
<pre><code>ERROR 2016-08-27 17:41:18,545 webapp2.py:1552] __init__() got an unexpected keyword argument 'require'
</code></pre>
<p>And I don't know what it's asking for or what it means. Please advise. Thanks. </p>
<p>This happens when I... | 0 | 2016-08-27T17:49:08Z | 39,184,184 | <p>You have a typo: <code>require</code> instead of <code>required</code> here:</p>
<pre><code> password = db.StringProperty(require = True)
</code></pre>
| 1 | 2016-08-27T18:02:19Z | [
"python",
"python-2.7",
"google-app-engine"
] |
Flask receiving Post Json | 39,184,083 | <p>I'm working on a flask web application in which the client posts data to the server in the form of:</p>
<p>{
"sess_id" : 1 ,
"annotations" :
[ {"tag_start" : "TIME","tag_end" : "TIME","tag" : "YOUR_TAG"}, {"tag_start" : "TIME","tag_end" : "TIME","tag" : "YOUR_TAG"}, {"tag_start" : "TIME","tag_end" : "TIME","tag" : ... | 0 | 2016-08-27T17:50:44Z | 39,184,251 | <p>Just passing a content-type header of JSON doesn't actually make the data itself into JSON. You either need to do that yourself, or tell jQuery to do so.</p>
<pre><code>$.ajax({
url: 'http://127.0.0.1:5000/api/saveannotation',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({'ses... | 2 | 2016-08-27T18:08:56Z | [
"python",
"json",
"flask"
] |
What does cur.fetchone()[0] do? | 39,184,133 | <p>I am using the following code for an educational purpose:</p>
<pre><code>import json
import sqlite3
conn = sqlite3.connect('rosterdb.sqlite')
cur = conn.cursor()
# Do some setup
cur.executescript('''
DROP TABLE IF EXISTS User;
DROP TABLE IF EXISTS Member;
DROP TABLE IF EXISTS Course;
CREATE TABLE User (
id ... | 0 | 2016-08-27T17:55:56Z | 39,184,169 | <p><code>cur.fetchone()</code> retrieves one result row for the query that was executed on that cursor. A row is always a sequence of 1 or more columns, and <code>[0]</code> indexes that row to get the first element.</p>
<p>It only makes sense to retrieve results from a <code>SELECT</code> query; in <code>INSERT</code... | 1 | 2016-08-27T17:59:52Z | [
"python",
"sql",
"python-2.7",
"sqlite",
"mooc"
] |
Deserialisation "pickle" file | 39,184,135 | <p>My code is:</p>
<pre><code>import _pickle
with open('items_10000_matrix.pickle', 'rb') as f:
data_new = _pickle.load(f)
</code></pre>
<p>But an error occurs: </p>
<pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 212: ordinal not in range(128)
</code></pre>
<p>I am using windows... | 2 | 2016-08-27T17:56:00Z | 39,215,566 | <p>Try using <code>_pickle.load(f, encoding='bytes')</code>.</p>
<p>By the way, in Python 3, there's no reason to explicitly import <code>_pickle</code> rather than <code>pickle</code> because it will automatically switch to the C version if it's available. See the accepted answer to the question <a href="http://stack... | 1 | 2016-08-29T21:33:24Z | [
"python",
"python-3.x",
"pickle",
"python-unicode"
] |
Deserialisation "pickle" file | 39,184,135 | <p>My code is:</p>
<pre><code>import _pickle
with open('items_10000_matrix.pickle', 'rb') as f:
data_new = _pickle.load(f)
</code></pre>
<p>But an error occurs: </p>
<pre><code>UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 212: ordinal not in range(128)
</code></pre>
<p>I am using windows... | 2 | 2016-08-27T17:56:00Z | 39,215,717 | <p>I was told to use python 2 instead of python 3, and it worked. Still dont know the solution for python3</p>
| 0 | 2016-08-29T21:48:55Z | [
"python",
"python-3.x",
"pickle",
"python-unicode"
] |
Converting time from AM/PM format to military time in Python | 39,184,198 | <p>Without using any libraries, I'm trying to solve the Hackerrank problem "<a href="https://www.hackerrank.com/challenges/time-conversion?h_r=next-challenge&h_v=zen" rel="nofollow">Time Conversion</a>", the problem statement of which is copied below.</p>
<p><a href="http://i.stack.imgur.com/YRr6p.png" rel="nofoll... | 1 | 2016-08-27T18:03:25Z | 39,184,237 | <p>I figured it out: it was converting "12:00:00PM" to "24:00:00" and not "12:00:00". I modified the code as follows:</p>
<pre><code>time = raw_input().strip()
meridian = time[-2:] # "AM" or "PM"
time_without_meridian = time[:-2]
hour = int(time[:2])
if meridian == "AM":
hour = (hour+1) % 12 - 1
print... | 0 | 2016-08-27T18:07:30Z | [
"python"
] |
Converting time from AM/PM format to military time in Python | 39,184,198 | <p>Without using any libraries, I'm trying to solve the Hackerrank problem "<a href="https://www.hackerrank.com/challenges/time-conversion?h_r=next-challenge&h_v=zen" rel="nofollow">Time Conversion</a>", the problem statement of which is copied below.</p>
<p><a href="http://i.stack.imgur.com/YRr6p.png" rel="nofoll... | 1 | 2016-08-27T18:03:25Z | 39,184,280 | <p>You've already solved the problem but here's another possible answer:</p>
<pre><code>from datetime import datetime
def solution(time):
return datetime.strptime(time, '%I:%M:%S%p').strftime('%H:%M:%S')
if __name__ == '__main__':
tests = [
"12:00:00PM",
"12:00:00AM",
"07:05:45PM"
... | 1 | 2016-08-27T18:12:30Z | [
"python"
] |
Converting time from AM/PM format to military time in Python | 39,184,198 | <p>Without using any libraries, I'm trying to solve the Hackerrank problem "<a href="https://www.hackerrank.com/challenges/time-conversion?h_r=next-challenge&h_v=zen" rel="nofollow">Time Conversion</a>", the problem statement of which is copied below.</p>
<p><a href="http://i.stack.imgur.com/YRr6p.png" rel="nofoll... | 1 | 2016-08-27T18:03:25Z | 39,184,444 | <p>It's even simpler than how you have it.</p>
<pre><code>hour = int(time[:2])
meridian = time[8:]
if (hour == 12):
hour = 0
if (meridian == 'PM'):
hour += 12
print("%02d" % hour + time[2:8])
</code></pre>
| 2 | 2016-08-27T18:31:21Z | [
"python"
] |
sha256 result dosen't change | 39,184,256 | <p>First time using sha256.</p>
<p>With this code, the result always equals to <code>4aa6892909e369933b9f1babc10519121e2dfd1042551f6b9bdd4eae51f1f0c2</code></p>
<p>what is wrong?</p>
<pre><code>def signning(self,D_path):
BUF_SIZE = 65536
hashed = hashlib.sha256()
with open(D_path, 'rb') as f:
w... | -1 | 2016-08-27T18:09:29Z | 39,184,317 | <p>Yeah, there is nothing wrong with your code, here's a little example showing that hashlib.sha256 is deterministic:</p>
<pre><code>import random
import string
import hashlib
random.seed(1)
for i in range(5):
data = ''.join(random.choice(string.ascii_uppercase + string.digits)
for _ in range(... | 0 | 2016-08-27T18:17:57Z | [
"python",
"python-2.7",
"sha256",
"sha"
] |
How can I decorate all functions imported from a file? | 39,184,338 | <p>I have created many functions that are divided into different files, now I would like to apply the same decorator for all of them without modifying the files and without applying the decorators one by one.</p>
<p>I have tried to use <a href="http://stackoverflow.com/questions/6307761/how-can-i-decorate-all-function... | 1 | 2016-08-27T18:19:56Z | 39,184,411 | <p>A little bit of introspection (<a href="https://docs.python.org/3/library/functions.html#dir" rel="nofollow"><code>dir()</code></a>) and dynamic look-up with <a href="https://docs.python.org/3/library/functions.html#getattr" rel="nofollow"><code>getattr()</code></a> and <a href="https://docs.python.org/3/library/fun... | 3 | 2016-08-27T18:28:08Z | [
"python",
"wrapper",
"python-decorators"
] |
Is there any expression in Swift that similar Python for else syntax | 39,184,398 | <p>I am solving a algorithm problem, and I use both Python and Swift to solve it. In python, I can use a for else syntax solve it easily. But in Swift, I am struggling to find a way that similar to python's for else syntax. </p>
<p>Here is the algorithm problem, it may help you understand what I am doing.</p>
<blockq... | 1 | 2016-08-27T18:26:27Z | 39,184,537 | <p>You could just introduce a flag to record if <code>break</code> is called or not. The statement</p>
<pre><code>for a in b:
if c(a):
break
else:
d()
</code></pre>
<p>is the same as</p>
<pre><code>found = False
for a in b:
if c(a):
found = True
break
if not found:
d()
</code>... | 0 | 2016-08-27T18:41:03Z | [
"python",
"swift2",
"for-else"
] |
Is there any expression in Swift that similar Python for else syntax | 39,184,398 | <p>I am solving a algorithm problem, and I use both Python and Swift to solve it. In python, I can use a for else syntax solve it easily. But in Swift, I am struggling to find a way that similar to python's for else syntax. </p>
<p>Here is the algorithm problem, it may help you understand what I am doing.</p>
<blockq... | 1 | 2016-08-27T18:26:27Z | 39,186,853 | <p>I would like to share my answer. Appreciate Kennytm's help. </p>
<pre><code>class Solution
{
func maxProduct(words: [String]) -> Int
{
var input = words
var length = input.count
var maximum = 0
while input.count != 0
{
let cur_word = Set(input[0].charac... | 0 | 2016-08-28T00:03:04Z | [
"python",
"swift2",
"for-else"
] |
Celery connect to remote server broker_url | 39,184,400 | <p>I'm daemonizing celery following the <a href="http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html" rel="nofollow">docs</a>. </p>
<p>My BROKER_URL has been set in the following format:- <code>'amqp://<user>:<password>@<ip>/<vhost>'</code>.</p>
<p>So, when I start celery manua... | 0 | 2016-08-27T18:26:36Z | 39,185,568 | <p>Well, I found the answer to the question:-</p>
<p>Pass broker url is <code>CELERY_OPTS</code> as <code>CELERYD_OPTS="-n worker2.%h --broker=amqp://<user>:<password>@<ip>/<vhost>"</code> in celeryd file.</p>
| 0 | 2016-08-27T20:42:35Z | [
"python",
"django",
"celery",
"django-celery",
"djcelery"
] |
Atom package linter-flake8 not showing output | 39,184,428 | <p>I have installed linter-flake8 with Atom on MacOSX. Atom automatically installed linter. My problem is that the package doesn't detect any errors with python scripts. The strange thing is that if I run flake8 from the command line, it does detect multiple errors and specifies in which file the errors occured.</p>
<... | 0 | 2016-08-27T18:29:19Z | 39,184,531 | <p>I've notices several Flake8 plugins don't support reading from stdin priperly since <code>flake8 >= 3</code>. The flake8 Atom package basically runs <code>cat $FILENAME | flake8 -</code>. Try running that command from the terminal and report differences in output to the relevant plugin.</p>
| 0 | 2016-08-27T18:40:20Z | [
"python",
"atom-editor",
"flake8"
] |
pandas.DataFrame set all string values to nan | 39,184,442 | <p>I have a <code>pandas.DataFrame</code> that contain string, float and int types.</p>
<p>Is there a way to set all strings that cannot be converted to float to <code>NaN</code> ?</p>
<p>For example:</p>
<pre class="lang-py prettyprint-override"><code> A B C D
0 1 2 5 7
1 0 4 NaN 15
2 ... | 1 | 2016-08-27T18:30:49Z | 39,184,505 | <p>Try </p>
<pre><code>df.convert_objects(convert_numeric=True)
</code></pre>
<p>To be fair to the other answers using to_numeric, this method is deprecated as Merlin pointed out. So make sure to take that into account when using this, especially if you plan to roll it into a long term solution. Although, you shoul... | 3 | 2016-08-27T18:37:21Z | [
"python",
"string",
"pandas",
"dataframe"
] |
pandas.DataFrame set all string values to nan | 39,184,442 | <p>I have a <code>pandas.DataFrame</code> that contain string, float and int types.</p>
<p>Is there a way to set all strings that cannot be converted to float to <code>NaN</code> ?</p>
<p>For example:</p>
<pre class="lang-py prettyprint-override"><code> A B C D
0 1 2 5 7
1 0 4 NaN 15
2 ... | 1 | 2016-08-27T18:30:49Z | 39,184,512 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.to_numeric.html" rel="nofollow"><code>pd.to_numeric</code></a> with <code>errors='coerce'</code>. </p>
<pre><code>In [30]: df = pd.DataFrame({'a': [1, 2, 'NaN', 'bob', 3.2]})
In [31]: pd.to_numeric(df.a, errors='coerce')
Out[... | 1 | 2016-08-27T18:37:59Z | [
"python",
"string",
"pandas",
"dataframe"
] |
pandas.DataFrame set all string values to nan | 39,184,442 | <p>I have a <code>pandas.DataFrame</code> that contain string, float and int types.</p>
<p>Is there a way to set all strings that cannot be converted to float to <code>NaN</code> ?</p>
<p>For example:</p>
<pre class="lang-py prettyprint-override"><code> A B C D
0 1 2 5 7
1 0 4 NaN 15
2 ... | 1 | 2016-08-27T18:30:49Z | 39,184,562 | <p>Here is a way:</p>
<pre><code>df['E'] = pd.to_numeric(df.D, errors='coerce')
</code></pre>
<p>And then you have:</p>
<pre><code>
A B C D E
0 1 2 5.0 7 7.0
1 0 4 NaN 15 15.0
2 4 8 9.0 10 10.0
3 11 5 8.0 0 0.0
4 11 5 8.0 wajdi NaN
</code></pre>
| 3 | 2016-08-27T18:43:47Z | [
"python",
"string",
"pandas",
"dataframe"
] |
Connect JS client with Python server | 39,184,455 | <p>I'm relatively new to JS and Python, so this is probably a beginners question. I'm trying to send a string from a JS client to Python Server (and then send the string to another Python client).</p>
<p>This is my code:</p>
<p>JS client:</p>
<pre><code> var socket = io.connect('http://127.0.0.1:8484');
socke... | 0 | 2016-08-27T18:32:03Z | 39,184,584 | <p><code>socket.socket()</code> doesn't create a websocket server.</p>
<p>You should use a websocket server, check this : <a href="https://websockets.readthedocs.io/en/stable/" rel="nofollow">https://websockets.readthedocs.io/en/stable/</a></p>
<p>Also your python client should use <code>websockets</code> too, even t... | 0 | 2016-08-27T18:46:11Z | [
"javascript",
"python",
"node.js",
"sockets",
"socket.io"
] |
Connect JS client with Python server | 39,184,455 | <p>I'm relatively new to JS and Python, so this is probably a beginners question. I'm trying to send a string from a JS client to Python Server (and then send the string to another Python client).</p>
<p>This is my code:</p>
<p>JS client:</p>
<pre><code> var socket = io.connect('http://127.0.0.1:8484');
socke... | 0 | 2016-08-27T18:32:03Z | 39,184,665 | <p>If you want to connect to the python TCP server, then you can use a code similar to the following in node:</p>
<pre><code>var net = require('net');
var client = new net.Socket();
client.connect(8484, '127.0.0.1', function() {
console.log('Connected');
client.write('Hello, server! Love, Client.');
});
clie... | 0 | 2016-08-27T18:55:46Z | [
"javascript",
"python",
"node.js",
"sockets",
"socket.io"
] |
using sdl2 in Kivy instead of pygame | 39,184,571 | <p>I couldn't resize my windows on the applications i made with Kivy, so I found out using sdl2, instead of Pygame, with Kivy can fix this. I uninstalled Kivy and Pygame, then installed sdl2, then reinstalled Kivy. Kivy still is trying to use pygame though. Please Help.</p>
<pre><code>File "/Library/Frameworks/Python.... | 1 | 2016-08-27T18:44:41Z | 39,186,099 | <p>The easiest way to fix this is to purge your current kivy install and re-install it fresh using the following links as a reference point (these are the official installation instructions)</p>
<p><a href="https://kivy.org/docs/installation/installation-windows.html" rel="nofollow">https://kivy.org/docs/installation/... | 1 | 2016-08-27T21:55:45Z | [
"python",
"python-3.x",
"pygame",
"kivy",
"sdl-2"
] |
QWebEngineView fails loading SVG using setHtml(...) | 39,184,615 | <p>I tried two different ways to load and show an SVG file in PyQt:</p>
<pre><code>import sys
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
app = QApplication(sys.argv)
webView = QWebEngineView()
# Variant 1: Reasonably fast
webView.load(QU... | 1 | 2016-08-27T18:50:02Z | 39,186,648 | <p>The <code>setHtml</code> function cannot load any content (not just svg) that is greater than 2MB in size. This is because Chromium uses a <code>data:</code> scheme url to load the content (which obvioulsy limits the size to the maximum length for a url). So it would seem that the only option is to load the svg from... | 1 | 2016-08-27T23:18:12Z | [
"python",
"qt",
"svg",
"pyqt5",
"qtwebengine"
] |
Create a list from a list of dictionaries subject to a condition (counter and accumulator) in python | 39,184,654 | <p>I have a list dictionary of items: </p>
<pre><code>ListDictItem = [ {'Item No': 1,'Weight':610,'Quantity':2},{'Item No': 2,'Weight':610,'Quantity':2},{'Item No': 3,'Weight':500,'Quantity':2},{'Item No': 4,'Weight':484,'Quantity':2},{'Item No': 5,'Weight':470,'Quantity':2},{'Item No': 6,'Weight':440,'Quantity':2},{'... | 0 | 2016-08-27T18:54:49Z | 39,185,046 | <p>I took a simpler approach:</p>
<pre><code>ListDictItem = [{'Item No': 1,'Weight':610,'Quantity':2},
{'Item No': 2,'Weight':610,'Quantity':2},
{'Item No': 3,'Weight':500,'Quantity':2},
{'Item No': 4,'Weight':484,'Quantity':2},
{'Item No': 5,'Weight':470... | 4 | 2016-08-27T19:39:29Z | [
"python",
"list",
"python-3.x",
"dictionary"
] |
Create a list from a list of dictionaries subject to a condition (counter and accumulator) in python | 39,184,654 | <p>I have a list dictionary of items: </p>
<pre><code>ListDictItem = [ {'Item No': 1,'Weight':610,'Quantity':2},{'Item No': 2,'Weight':610,'Quantity':2},{'Item No': 3,'Weight':500,'Quantity':2},{'Item No': 4,'Weight':484,'Quantity':2},{'Item No': 5,'Weight':470,'Quantity':2},{'Item No': 6,'Weight':440,'Quantity':2},{'... | 0 | 2016-08-27T18:54:49Z | 39,185,394 | <pre><code>ListDictItem = [ {'Item No': 1,'Weight':610,'Quantity':2},{'Item No': 2,'Weight':610,'Quantity':2},{'Item No': 3,'Weight':500,'Quantity':2},{'Item No': 4,'Weight':484,'Quantity':2},{'Item No': 5,'Weight':470,'Quantity':2},{'Item No': 6,'Weight':440,'Quantity':2},{'Item No': 7,'Weight':440,'Quantity':2},{'Ite... | 0 | 2016-08-27T20:19:33Z | [
"python",
"list",
"python-3.x",
"dictionary"
] |
Classifier.fit(X,y) error | 39,184,664 | <p>I'm trying some machine learning algorithms.</p>
<p>I'm using sklearn tool for logistic regression script.</p>
<p>this is my script:</p>
<pre><code>import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LogisticRegression
#from sklearn.neighbors import KNeighborsClassifier
X = np... | -1 | 2016-08-27T18:55:29Z | 39,184,785 | <p>The <code>LogisticRegression.fit()</code> method expects a one-dimensional array for the target vector <code>y</code>. The error you mentioned should be gone if you remove the <code>.reshape((1, -1))</code> that converts it into a 1x4 matrix (row vector).</p>
<p>Furthermore, the last line of your code</p>
<pre><co... | 0 | 2016-08-27T19:11:08Z | [
"python",
"scikit-learn"
] |
SciKit Learn - Mathematical model behind linear regression? | 39,184,669 | <p>What mathematical model does the <a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html#sklearn.linear_model.LinearRegression" rel="nofollow">Linear Regression</a> function use in scikit learn? The Ordinary Least Squares model has more than one way to minimize the cost f... | 2 | 2016-08-27T18:56:39Z | 39,184,847 | <p>You can basically hunt around the source code enough, and you'll find it.</p>
<ul>
<li><p>In <a href="https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/linear_model/base.py#L349" rel="nofollow"><code>base.py</code></a>, you can find it uses <code>linal.lstsq</code>.</p></li>
<li><p>In <a href="https... | 0 | 2016-08-27T19:19:41Z | [
"python",
"math",
"scikit-learn",
"linear-regression"
] |
Process a dictionary based on types of it's value and generate another dictionary by using dictionary comprehension | 39,184,703 | <p>Input dictionary </p>
<pre><code>{11: [1, 2], 23: 'ewewe', 3: [4], 41: 5, 55: 6}
</code></pre>
<p>I need to form another dictionary based on types of items in input dictionary,
it would be like :- </p>
<pre><code>{type: list of keys which has this type}
</code></pre>
<p>Expected output would be</p>
<pre><code>... | 3 | 2016-08-27T19:01:13Z | 39,184,722 | <p>You can't do this with dictionary comprehension (only with one), instead as a more pythonic way you can use <code>collections.defaultdict()</code>:</p>
<pre><code>>>> from collections import defaultdict
>>> d = defaultdict(list)
>>>
>>> test = {11: [1, 2], 23: 'ewewe', 3: [4], 4... | 1 | 2016-08-27T19:04:10Z | [
"python",
"dictionary",
"dictionary-comprehension"
] |
Process a dictionary based on types of it's value and generate another dictionary by using dictionary comprehension | 39,184,703 | <p>Input dictionary </p>
<pre><code>{11: [1, 2], 23: 'ewewe', 3: [4], 41: 5, 55: 6}
</code></pre>
<p>I need to form another dictionary based on types of items in input dictionary,
it would be like :- </p>
<pre><code>{type: list of keys which has this type}
</code></pre>
<p>Expected output would be</p>
<pre><code>... | 3 | 2016-08-27T19:01:13Z | 39,184,772 | <p>Using <code>defaultdict</code> and dictionary comprehension (kind of):</p>
<pre><code>from collections import defaultdict
input_dict = {1: [1, 2], 2: 'ewewe', 3: [4], 4: 5, 5: 6}
d = defaultdict(list)
{d[type(value)].append(key) for key, value in input_dict.items()}
d = dict(d)
print(d)
</code></pre>
<p><strong... | 1 | 2016-08-27T19:09:46Z | [
"python",
"dictionary",
"dictionary-comprehension"
] |
Update program: overwrite files? | 39,184,705 | <p>I'm developing a software and I want, for several reasons, to develop my own auto-update feature. The program is a full GUI, written with PyQt, and uses icons, data files, etc. It will be frozen with cx_freeze or pyinstaller.</p>
<p>The auto-update part will download the new version (a zip) on a remote server. Then... | 0 | 2016-08-27T19:01:36Z | 39,190,539 | <p>This is a similar <a href="http://stackoverflow.com/questions/16549331/pyqt-application-performing-updates">question</a> to yours and the accepted answer says:</p>
<blockquote>
<p>After downloading the installer for the newer version, you can use
<a href="http://docs.python.org/2/library/atexit.html#atexit.regi... | 0 | 2016-08-28T10:56:45Z | [
"python",
"pyqt",
"auto-update"
] |
exponent digits in scientific notation in Python | 39,184,719 | <p>In Python, scientific notation always gives me 2 digits in exponent:</p>
<pre><code>print('%17.8E\n' % 0.0665745511651039)
6.65745512E-02
</code></pre>
<p>However, I badly want to have 3 digits like:</p>
<pre><code>6.65745512E-002
</code></pre>
<p>Can we do this with a built-in configuration/function in Python?<... | 1 | 2016-08-27T19:03:44Z | 39,186,094 | <p>Unfortunately, you can not change this default behavior since you can not override the <code>str</code> methods. </p>
<p>However, you can wrap the float, and use the <code>__format__</code> method:</p>
<pre><code>class MyNumber:
def __init__(self, val):
self.val = val
def __format__(self,format_sp... | 1 | 2016-08-27T21:55:25Z | [
"python",
"scientific-notation",
"exponent"
] |
exponent digits in scientific notation in Python | 39,184,719 | <p>In Python, scientific notation always gives me 2 digits in exponent:</p>
<pre><code>print('%17.8E\n' % 0.0665745511651039)
6.65745512E-02
</code></pre>
<p>However, I badly want to have 3 digits like:</p>
<pre><code>6.65745512E-002
</code></pre>
<p>Can we do this with a built-in configuration/function in Python?<... | 1 | 2016-08-27T19:03:44Z | 39,188,256 | <p>You can use your own formatter and override <code>format_field</code>:</p>
<pre><code>import string
class MyFormatter(string.Formatter):
def format_field(self, value, format_spec):
ss = string.Formatter.format_field(self,value,format_spec)
if format_spec.endswith('E'):
if ( 'E' in s... | 0 | 2016-08-28T05:19:08Z | [
"python",
"scientific-notation",
"exponent"
] |
ComboBox with two columns | 39,184,776 | <p>I'm trying to create a <code>GtkComboBox</code> with two columns. I picked up some examples and I'm trying to adapt but without success. Only the items that would be the second column are shown.</p>
<pre><code>#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Co... | 1 | 2016-08-27T19:10:21Z | 39,184,892 | <p>There must be a CellRendererText for each column to be displayed.</p>
<pre><code>cell1 = Gtk.CellRendererText()
cell2 = Gtk.CellRendererText()
combobox.pack_start(cell1, True)
combobox.pack_start(cell2, True)
combobox.add_attribute(cell1, "text", 0)
combobox.add_attribute(cell2, "text", 1)
</code></pre>
| 1 | 2016-08-27T19:23:23Z | [
"python",
"python-3.x",
"gtk",
"gtk3"
] |
How to efficiently find all paths formed by k number of nodes in a directed acyclic graph? | 39,184,881 | <p>I have a DAG that looks like this:
<a href="http://i.stack.imgur.com/d4MN0.png" rel="nofollow">Example DAG</a></p>
<p>I want to extract all the paths constituted by 4 nodes in this graph.</p>
<p>My expected result should look like this:</p>
<p>N1 -> N2 -> N3 -> N4</p>
<p>N1 -> N2 -> N3 -> N5</p>
<p>N1 -> N3 -> ... | 2 | 2016-08-27T19:22:31Z | 39,185,156 | <p>Part of your problem could be that if you come across a node <code>u</code> as the second node in a path then you do all of the calculations to find all the paths of length 3. But then if you come across <code>u</code> again as the second node, you repeat all of these calculations.</p>
<p>So try to avoid this. We... | 0 | 2016-08-27T19:52:20Z | [
"python",
"algorithm",
"graph",
"networkx",
"graph-traversal"
] |
How to efficiently find all paths formed by k number of nodes in a directed acyclic graph? | 39,184,881 | <p>I have a DAG that looks like this:
<a href="http://i.stack.imgur.com/d4MN0.png" rel="nofollow">Example DAG</a></p>
<p>I want to extract all the paths constituted by 4 nodes in this graph.</p>
<p>My expected result should look like this:</p>
<p>N1 -> N2 -> N3 -> N4</p>
<p>N1 -> N2 -> N3 -> N5</p>
<p>N1 -> N3 -> ... | 2 | 2016-08-27T19:22:31Z | 39,185,177 | <p>Here is a function that returns the paths of a given length between all nodes in the graph. It iterates between all sets of nodes and uses the <code>networkx.all_simple_paths</code> to get the paths.</p>
<pre><code>import networkx as nx
g = nx.DiGraph()
g.add_nodes_from(['A','B','C','D','E'])
g.add_path(['A','B... | 0 | 2016-08-27T19:54:03Z | [
"python",
"algorithm",
"graph",
"networkx",
"graph-traversal"
] |
How to efficiently find all paths formed by k number of nodes in a directed acyclic graph? | 39,184,881 | <p>I have a DAG that looks like this:
<a href="http://i.stack.imgur.com/d4MN0.png" rel="nofollow">Example DAG</a></p>
<p>I want to extract all the paths constituted by 4 nodes in this graph.</p>
<p>My expected result should look like this:</p>
<p>N1 -> N2 -> N3 -> N4</p>
<p>N1 -> N2 -> N3 -> N5</p>
<p>N1 -> N3 -> ... | 2 | 2016-08-27T19:22:31Z | 39,344,130 | <p>Number of sequences is of order |V|*d^3, where d is average node output degree. From how graph is created, d is bounded. I suppose that d is not very small (like < 5). That means, for 5M nodes graph there are > 1G paths.</p>
<p>Since finding one path is fast (they are short) it is not sure that DP like algorithm... | 0 | 2016-09-06T08:27:33Z | [
"python",
"algorithm",
"graph",
"networkx",
"graph-traversal"
] |
ValueError: math domain error, keeps popping up | 39,185,025 | <p>I keep getting this message from time to time.
i tried all variations, changing the way i use the sqrt, doing it step by step..etc
But still this error keeps popping up.
It might be a rookie mistake which i am not noticing since i am new to python and ubuntu.
This is my source code:-(a very simple program)</p>
<pr... | 0 | 2016-08-27T19:37:05Z | 39,185,060 | <p>If a,b,c doesn't form a triangle, sq will come out to be -ve.
Check if <code>s*(s-a)*(s-b)*(s-c)</code> is positive because sqrt(-ve number) is a complex number. </p>
<p>To resolve this issue, you can use exception handling. </p>
<pre><code>try:
a=input("Input the side 'a' of a triangle ")
b=input("Input the ... | 2 | 2016-08-27T19:41:24Z | [
"python",
"math"
] |
ValueError: math domain error, keeps popping up | 39,185,025 | <p>I keep getting this message from time to time.
i tried all variations, changing the way i use the sqrt, doing it step by step..etc
But still this error keeps popping up.
It might be a rookie mistake which i am not noticing since i am new to python and ubuntu.
This is my source code:-(a very simple program)</p>
<pr... | 0 | 2016-08-27T19:37:05Z | 39,190,634 | <p>As others have pointed out, your calculation for area using Heron's formula will involve the square root of a negative number if the three "sides" do not actually form a triangle. One answer showed how to handle that with exception handling. However, that does not catch the case where the three "sides" form a degene... | 1 | 2016-08-28T11:08:29Z | [
"python",
"math"
] |
additional column when saving pandas data frame to csv file | 39,185,028 | <p>Here the the code to process and save csv file, and raw input csv file and output csv file, using pandas on Python 2.7 and wondering why there is an additional column at the beginning when saving the file? Thanks.</p>
<pre><code>c_a,c_b,c_c,c_d
hello,python,pandas,0.0
hi,java,pandas,1.0
ho,c++,numpy,0.0
sample = p... | 1 | 2016-08-27T19:37:46Z | 39,185,114 | <p>The additional column corresponds to the index of the dataframe and is aggregated once you read the CSV file. You can use this index to slice, select or sort your DF in an effective manner.</p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.html" rel="nofollow">http://pandas.pydata.o... | 1 | 2016-08-27T19:47:16Z | [
"python",
"python-2.7",
"csv",
"pandas",
"dataframe"
] |
Django Project Setup on Google VM | 39,185,034 | <p>I am trying to setup a django project on a VM by Google Compute Engine. I have done all the installations & have copied the project on my VM. But I am not able to do the Apache/mod_wsgi Or Gunicorn/Nginx linking to make the project run end to end on the final IP address of VM. </p>
<p>I have two queries:</p>
<... | 0 | 2016-08-27T19:38:28Z | 39,185,566 | <p>Add the Following Code in /etc/apache2/sites-available/000-default.conf File.
Do make corresponding changes acc. to your project path.</p>
<p>1) sudo vim /etc/apache2/sites-available/000-default.conf</p>
<p>2) Add below code between & </p>
<pre><code><VirtualHost *:80>
. . .
Alias /static /hom... | 0 | 2016-08-27T20:41:49Z | [
"python",
"django",
"nginx",
"virtual-machine",
"google-compute-engine"
] |
calculations for different columns in a numpy array | 39,185,056 | <p>I have a 2D array with filled with some values (column 0) and zeros (rest of the columns). I would like to do pretty much the same as I do with MS excel but using numpy, meaning to put into the rest of the columns values from calculations based on the first column. Here it is a MWE:</p>
<pre><code>import numpy as n... | 2 | 2016-08-27T19:40:35Z | 39,185,102 | <p>Your usage of <code>column</code> is a little ambiguous: in <code>for column in a[:, 1:]</code>, it is treated as a column and in the body, however, it is treated as index to the column. You can try this instead:</p>
<pre><code>for column in range(1, a.shape[1]):
a[:, column] = a[:, column-1]+1
a
#array([[1, 2... | 1 | 2016-08-27T19:45:51Z | [
"python",
"numpy"
] |
calculations for different columns in a numpy array | 39,185,056 | <p>I have a 2D array with filled with some values (column 0) and zeros (rest of the columns). I would like to do pretty much the same as I do with MS excel but using numpy, meaning to put into the rest of the columns values from calculations based on the first column. Here it is a MWE:</p>
<pre><code>import numpy as n... | 2 | 2016-08-27T19:40:35Z | 39,185,121 | <p>Looping is slow and there is no need to loop to produce the array that you want:</p>
<pre><code>>>> a = np.ones(20, dtype=np.int8).reshape(4,5)
>>> a[:, 0] = b
>>> a
array([[1, 1, 1, 1, 1],
[2, 1, 1, 1, 1],
[3, 1, 1, 1, 1],
[4, 1, 1, 1, 1]], dtype=int8)
>>> n... | 2 | 2016-08-27T19:48:05Z | [
"python",
"numpy"
] |
Multiple unexpected errors | 39,185,086 | <p>I'm not entirely sure what is wrong with these line, I don't understand why they are problematic. In the order of the problems (failing line will be highlighted with ***)</p>
<p>File "C:\Users\Harry\Desktop\CS Project\game test", line 32, in drawArena
pygame.draw.line(DISPLAYSURF, WHITE, ((WINDOWWIDTH/2),0),((W... | -1 | 2016-08-27T19:44:43Z | 39,185,155 | <p>It's telling you the error. When using the method <code>pygame.draw.line()</code>, you must provide integer arguments for the dimensions of the line. If you look at your problematic line:</p>
<p><code>pygame.draw.line(DISPLAYSURF, WHITE, ((WINDOWWIDTH/2),0),((WINDOWWIDTH/2),WINDOWHEIGHT), (LINETHICKNESS/4))</code><... | 1 | 2016-08-27T19:52:09Z | [
"python",
"python-3.x"
] |
How to call a dictionary from my first function in my second function in Python | 39,185,157 | <p>I am pretty new to Python and to help new learn, I am building a program, which I want broken down into 2 steps:</p>
<p>Step 1) Count the number of a particular words in a text file, store that in a dictionary where the key, value pairs are {word, count}</p>
<p>Step 2) Order the dictionary from (1) in descending o... | 0 | 2016-08-27T19:52:20Z | 39,185,186 | <p>These tasks are exactly what <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow"><code>collections.Counter()</code></a> is for. You can use this function in order to create a counter-dictionary object contains words and their frequency, you can call it on splited text. The... | 0 | 2016-08-27T19:55:15Z | [
"python",
"dictionary"
] |
How to call a dictionary from my first function in my second function in Python | 39,185,157 | <p>I am pretty new to Python and to help new learn, I am building a program, which I want broken down into 2 steps:</p>
<p>Step 1) Count the number of a particular words in a text file, store that in a dictionary where the key, value pairs are {word, count}</p>
<p>Step 2) Order the dictionary from (1) in descending o... | 0 | 2016-08-27T19:52:20Z | 39,185,218 | <p>your tally function is returning the first item it sees; <code>return</code> can only return once, but you're calling it in a loop. try returning the whole wordcount dict:</p>
<pre><code>filename = 'nameoffile.txt'
def tally():
file = open(filename,'r')
wordcount={}
for word in file.read().split():
if w... | 1 | 2016-08-27T19:58:59Z | [
"python",
"dictionary"
] |
How to call a dictionary from my first function in my second function in Python | 39,185,157 | <p>I am pretty new to Python and to help new learn, I am building a program, which I want broken down into 2 steps:</p>
<p>Step 1) Count the number of a particular words in a text file, store that in a dictionary where the key, value pairs are {word, count}</p>
<p>Step 2) Order the dictionary from (1) in descending o... | 0 | 2016-08-27T19:52:20Z | 39,185,320 | <p>Your issue is that you returned <code>k,v</code> after the first iteration meaning you only ever grabbed the first item. The following code fixes this. I also added the reversal function.</p>
<pre><code>def tally():
file = open(filename,'r')
wordcount={}
for word in file.read().split():
if word ... | 0 | 2016-08-27T20:10:55Z | [
"python",
"dictionary"
] |
Python 3.5 Tkinter How to separate 2 sets of radio buttons | 39,185,158 | <p>My first question here.</p>
<p>I'm currently writing a GUI with Tkinter in Python 3.5.</p>
<p>I have a settings frame in my application and I have radio buttons to let the user change them. There is no problem when I have only one set of radio buttons but when I add a second set of radio buttons, Python thinks tha... | 0 | 2016-08-27T19:52:22Z | 39,185,249 | <p>You didn't bind two different variables to your button groups. Each <code>Radiobutton</code> group has to be associated with a single <code>StringVar()</code> or <code>IntVar()</code>.</p>
<pre><code>v1 = tk.StringVar()
v2 = tk.StringVar()
# Group 1
s1r1=tk.Radiobutton(root,text="Red", variable=v1)
s1r2=tk.Radiobut... | 2 | 2016-08-27T20:02:36Z | [
"python",
"tkinter",
"radio-button"
] |
Pass variable into AppleScript from python | 39,185,160 | <p>Can someone show me how to pass a variable into an Applescript using osascript in python? I've seen some documentation/samples on doing this but I'm not understanding it at all. </p>
<p>Here is my python code:</p>
<pre><code># I want to pass this value into my apple script below
myPythonVariable = 10
cmd = """
... | 0 | 2016-08-27T19:52:33Z | 39,192,929 | <p>String concatenation with the <strong>+</strong> operator</p>
<pre><code>myPythonVariable = 10
cmd = """
osascript -e '
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "MyApp" is in activeApp then
set stepCount to """... | 1 | 2016-08-28T15:36:51Z | [
"python",
"applescript",
"osascript"
] |
Flask admin overrides password when user model is changed | 39,185,230 | <p>I am currently diving into a flask project and try to use flask-admin for the first time. Everything is working fine so far, but one thing really bothers me:
Whenever I edit my User model the users password gets overwritten. I am following the advice given in the second answer of <a href="http://stackoverflow.com/qu... | 0 | 2016-08-27T20:00:10Z | 39,190,347 | <p>Might be easier to override the <code>get_edit_form</code> method and delete the password field entirely from the edit form. </p>
<pre><code>class UserView(MyModelView):
def get_edit_form(self):
form_class = super(UserView, self).get_edit_form()
del form_class.password
return form_class
... | 0 | 2016-08-28T10:29:41Z | [
"python",
"flask",
"flask-admin"
] |
Use pip to Install to a different interpreter | 39,185,255 | <p>I downloaded Python2.7 a while ago to my C:\ directory. After that I downloaded pip to install packages. After that I installed the Anaconda interpreter to a different directory within my user. I prefer to use the Anaconda interpreter but every time I install a package with pip it is put in C:\Python27\Lib\site-pack... | 1 | 2016-08-27T20:03:35Z | 39,185,406 | <p>What you could do is create a symbolic link.</p>
<p>Or in your case, on windows, a shortcut.</p>
<p>So in your case : <code>C:\path_to_anaconda_interpreter_in_user\Lib\site-packages</code> would be a shortcut leading to <code>C:\Python27\Lib\site-packages</code></p>
<p>(right click python27/lib/site-packages, cli... | 0 | 2016-08-27T20:20:41Z | [
"python",
"windows",
"pip"
] |
bypass validation for form field django | 39,185,272 | <pre><code> class PostForm(forms.ModelForm):
description = forms.CharField(widget=PagedownWidget(show_preview=False))
class Meta:
model = Post
fields = [
'title',
'image',
... | -1 | 2016-08-27T20:05:39Z | 39,185,391 | <p>from <a href="https://pypi.python.org/pypi/django-embed-video" rel="nofollow">the docs</a> it looks like it should support empty now since version 0.3, i would suggest trying</p>
<pre><code>video = EmbedVideoField(null=True,blank=True)
</code></pre>
<p>the docs say it should function like a URL field, so just the ... | 0 | 2016-08-27T20:19:17Z | [
"python",
"django"
] |
Are HSV values stored as VSH in numpy array? | 39,185,277 | <p>since RGB is stored as BGR ,does the same happens in the case of HSV ?</p>
<p>I am making a project where i take input from webcam and convert it to HSV colour, to track object of a specific colour.</p>
| 0 | 2016-08-27T20:06:19Z | 39,216,745 | <p>No. It's HSV mode.</p>
<p>Read the below code and its run on a sample image.</p>
<pre><code>int main()
{
// Load your Red colored image
cv::Mat frame = imread("test.png");
// Split each channel
cv::Mat rgbChannels[3];
cv::split(frame, rgbChannels);
cv::imshow("RGB", frame);
// Check v... | 1 | 2016-08-29T23:37:15Z | [
"python",
"opencv",
"numpy",
"colors"
] |
Python3 always shows ImportError message | 39,185,360 | <p>Whenever I try to run a script the python interpreter always shows an <code>ImportError</code> message such as (e.g.) <code>No module named 'setuptools'</code>. So, I tried install (or to satisfy this requirement) with <code>apt-get</code>... I do this for both Python 2.7 and Python 3.5 until <code>Requirement alrea... | 0 | 2016-08-27T20:15:55Z | 39,185,377 | <p>try :</p>
<pre><code>python3.5 -m pip install setuptools
</code></pre>
| 2 | 2016-08-27T20:17:35Z | [
"python",
"python-2.7",
"python-3.x",
"pip",
"importerror"
] |
Python3 always shows ImportError message | 39,185,360 | <p>Whenever I try to run a script the python interpreter always shows an <code>ImportError</code> message such as (e.g.) <code>No module named 'setuptools'</code>. So, I tried install (or to satisfy this requirement) with <code>apt-get</code>... I do this for both Python 2.7 and Python 3.5 until <code>Requirement alrea... | 0 | 2016-08-27T20:15:55Z | 39,186,569 | <p>From your description of the problem, you have likely been installing the Python 2 versions of the packages you want with <code>apt</code> and/or <code>pip</code>. <code>sudo apt-get install python-django</code>, for example, will install the Python 2 version of Django, while <code>sudo apt-get install python3-djang... | 2 | 2016-08-27T23:02:21Z | [
"python",
"python-2.7",
"python-3.x",
"pip",
"importerror"
] |
Should PYTHONPATH include ./build/*? | 39,185,417 | <p>Running</p>
<pre><code>$ python setup.py build_ext
</code></pre>
<p>with the usual Cython extension configuration creates a <code>build</code> directory and places the compiled modules deep within it.</p>
<p>How is the Python interpreter supposed to find them now? Should <code>PYTHONPATH</code> include those sub-... | 1 | 2016-08-27T20:21:44Z | 39,185,484 | <p>Presumably, when you write a package containing Cython code, <a href="http://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html" rel="nofollow">your <code>setup.py</code> will contain something similar to this</a>:</p>
<pre><code>setup(
ext_modules = cythonize("example.pyx")
)
</cod... | 1 | 2016-08-27T20:30:23Z | [
"python",
"python-2.7",
"cython",
"distutils",
"pythonpath"
] |
Should PYTHONPATH include ./build/*? | 39,185,417 | <p>Running</p>
<pre><code>$ python setup.py build_ext
</code></pre>
<p>with the usual Cython extension configuration creates a <code>build</code> directory and places the compiled modules deep within it.</p>
<p>How is the Python interpreter supposed to find them now? Should <code>PYTHONPATH</code> include those sub-... | 1 | 2016-08-27T20:21:44Z | 39,185,529 | <p>You will find the information here <a href="https://docs.python.org/3.5/install/" rel="nofollow">https://docs.python.org/3.5/install/</a></p>
<p>Build is an intermediary result before python actually install the module. Put in pythonpath the paths to the library that is, for instance:</p>
<pre><code><dir>/lo... | 1 | 2016-08-27T20:35:55Z | [
"python",
"python-2.7",
"cython",
"distutils",
"pythonpath"
] |
Is it possible to use jQuery and Django on the same page? | 39,185,436 | <p>I'm trying to just a jQuery function to show a table on a Django page. When I test the script on jsfiddle, it works great but it's not working on my Django site. Do I need to import something into Django to make it work?</p>
<p>This is what I have thus far:</p>
<p>html file:</p>
<pre><code><table class="panel"... | -1 | 2016-08-27T20:23:46Z | 39,185,494 | <p>You should add reference to jquery script from your Django html template, for example </p>
<pre><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</code></pre>
<p>More information on <a href="http://jquery.com/download/" rel="nofollow">jquery site</a> </p>
| -1 | 2016-08-27T20:31:58Z | [
"javascript",
"jquery",
"python",
"django"
] |
ImportError: No module named stdio, any way to start fresh with python? | 39,185,453 | <p>I'm getting the error </p>
<pre><code>Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
</code></pre>
<p>When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tri... | 0 | 2016-08-27T20:26:23Z | 39,185,593 | <p>When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.</p>
<p>I couldn't find a module ... | -3 | 2016-08-27T20:44:59Z | [
"python"
] |
comparison of negative numbers turn out wrong | 39,185,489 | <p>I am doing a test of position bounding boxes, but when comparing negative (south or west) positions with other negative positions it turns the result upside down.</p>
<pre><code>if minlat > maxlat:
minlat, maxlat = swap(minlat, maxlat)
if minlon > maxlon:
minlon, maxlon = swap(minlon, maxlon)
</code><... | -1 | 2016-08-27T20:31:10Z | 39,185,522 | <p>generally you'll want to compare the absolute values rather than the actual values in this scenario, try</p>
<pre><code>if abs(minlat) > abs(maxlat):
</code></pre>
<p>good luck!</p>
| 0 | 2016-08-27T20:35:22Z | [
"python",
"python-2.7"
] |
comparison of negative numbers turn out wrong | 39,185,489 | <p>I am doing a test of position bounding boxes, but when comparing negative (south or west) positions with other negative positions it turns the result upside down.</p>
<pre><code>if minlat > maxlat:
minlat, maxlat = swap(minlat, maxlat)
if minlon > maxlon:
minlon, maxlon = swap(minlon, maxlon)
</code><... | -1 | 2016-08-27T20:31:10Z | 39,186,376 | <p><code>if float(minlat) > float(maxlat):</code></p>
<p>Making sure the compared numbers are actually numbers and not string objects. Comparing string objects using less than or greater than can have strange results.</p>
| 0 | 2016-08-27T22:29:54Z | [
"python",
"python-2.7"
] |
Convert import string to float with numpy's loadtext | 39,185,612 | <p>I'm attempting to import text from a flat file and to convert it to float values within a single line. I've seen <a href="http://stackoverflow.com/questions/8420143/valueerror-could-not-convert-string-to-float-id">this post</a> which has the same error, but I haven't found which characters are invalid in my input fi... | 0 | 2016-08-27T20:47:22Z | 39,185,675 | <p>Could you try:</p>
<pre><code>data = np.loadtxt(file, delimiter="\tb'", dtype=str)
</code></pre>
<p>To signify that the actual delimiter seems to include the characters "b'"?</p>
| 1 | 2016-08-27T20:56:16Z | [
"python",
"python-3.x",
"ipython"
] |
Convert import string to float with numpy's loadtext | 39,185,612 | <p>I'm attempting to import text from a flat file and to convert it to float values within a single line. I've seen <a href="http://stackoverflow.com/questions/8420143/valueerror-could-not-convert-string-to-float-id">this post</a> which has the same error, but I haven't found which characters are invalid in my input fi... | 0 | 2016-08-27T20:47:22Z | 39,185,776 | <p>Thanks to everyone who took a look at my question. I restarted IPython and was now able to execute the same code without any problems. Here's the code that worked which is identical to above. </p>
<pre><code>data_float = np.loadtxt(file, delimiter='\t', dtype=float, skiprows=1)
</code></pre>
<p>Result:</p>
<p... | 1 | 2016-08-27T21:10:03Z | [
"python",
"python-3.x",
"ipython"
] |
Convert import string to float with numpy's loadtext | 39,185,612 | <p>I'm attempting to import text from a flat file and to convert it to float values within a single line. I've seen <a href="http://stackoverflow.com/questions/8420143/valueerror-could-not-convert-string-to-float-id">this post</a> which has the same error, but I haven't found which characters are invalid in my input fi... | 0 | 2016-08-27T20:47:22Z | 39,185,908 | <p>The problem is that your numbers are quoted. That is, the field is <code>'99'</code>, rather than <code>99</code>. There are two ways you can do this. You can provide converter functions that strip the quotes and return a float. Or you can use the <code>csv</code> module to load your data in and then pass that data ... | 1 | 2016-08-27T21:28:51Z | [
"python",
"python-3.x",
"ipython"
] |
Python if and elif not working, giving error | 39,185,705 | <p>I'm new in Python and doing an online tutorial. I have an assignment that I can not accomplish. My problem is that when I run this code, the <code>minimum</code> variable stays the same to <code>None</code> and does not record the new value input.</p>
<pre><code>maximum = None
minimum = None
while True:
try:
... | 0 | 2016-08-27T21:00:22Z | 39,185,762 | <p>Your problem is that your are checking if <code>(some number) <= None</code> You cannot compare numbers with <code>None</code>. Instead, <code>minimum=float("inf")</code> and <code>maximum=float("-inf")</code> would set minimum to infinity, and maximum to negative infinity. That way, the first number entered woul... | 0 | 2016-08-27T21:07:15Z | [
"python",
"python-2.7",
"if-statement"
] |
Python if and elif not working, giving error | 39,185,705 | <p>I'm new in Python and doing an online tutorial. I have an assignment that I can not accomplish. My problem is that when I run this code, the <code>minimum</code> variable stays the same to <code>None</code> and does not record the new value input.</p>
<pre><code>maximum = None
minimum = None
while True:
try:
... | 0 | 2016-08-27T21:00:22Z | 39,185,803 | <pre><code>import sys
maximum = None
minimum = sys.maxsize
while True:
try:
num2 = raw_input('Type here ')
if num2 == 'done':break
else:
num = int(num2)
minimum = min(minimum, num)
maximum = max(maximum, num)
except:
print 'Invalid Entry'
if ... | 0 | 2016-08-27T21:13:57Z | [
"python",
"python-2.7",
"if-statement"
] |
Python if and elif not working, giving error | 39,185,705 | <p>I'm new in Python and doing an online tutorial. I have an assignment that I can not accomplish. My problem is that when I run this code, the <code>minimum</code> variable stays the same to <code>None</code> and does not record the new value input.</p>
<pre><code>maximum = None
minimum = None
while True:
try:
... | 0 | 2016-08-27T21:00:22Z | 39,185,804 | <p>You are comparing <code>None</code> and <code>int</code>, Python does not know how to do that.
Instead, you should do:</p>
<pre><code>maximum = float('-inf')
minimum = float('inf')
</code></pre>
<p>Any <code>int</code> would be greater than <code>-infinity</code> and lower than <code>infinity</code>, so things wil... | 0 | 2016-08-27T21:14:04Z | [
"python",
"python-2.7",
"if-statement"
] |
What the numpy array stores when i convert a grayscale image into a numpy array? | 39,185,781 | <p>I converted a 32 x 32 grayscale image into a numpy array using this procedure </p>
<pre><code>image = Image.open('bn2.bmp')
nparray=np.array(image)
</code></pre>
<p>when I print the numpy array, it prints 6 different matrix. When I printed the size of the numpy array, it showed me 3072. I suppose that the calculat... | 1 | 2016-08-27T21:10:49Z | 39,185,964 | <p>Looking at the documentation on the page <a href="http://scikit-image.org/docs/dev/user_guide/numpy_images.html" rel="nofollow">A crash course on NumPy for images</a></p>
<p>If you use <code>shape</code>, </p>
<pre><code>nparray.shape
</code></pre>
<p>this will give the dimensions of the image as something like</... | 0 | 2016-08-27T21:37:12Z | [
"python",
"numpy",
"image-processing"
] |
sl4a startActivity find out packagename and classname | 39,185,785 | <p>So I'm trying to start WhatsApp with a predefined message in sl4a using Python. This is my code:</p>
<pre><code>import android
droid = android.Android()
droid.startActivity("android.intent.action.SEND",
None, "text/plain",
{'com.whatsapp.locale.extras.TEXT':"sl4a test"},
... | 0 | 2016-08-27T21:11:36Z | 39,186,187 | <p>Nevermind I just figured out that I could set WhatsApp as the standard app in the dialog so I don't have to specify the packagename anyway.</p>
| 0 | 2016-08-27T22:06:11Z | [
"android",
"python",
"whatsapp",
"sl4a"
] |
How do most people do console.log debugging in Python? | 39,185,797 | <p>In Node.js when I want to quickly check the value of something rather than busting out the debugger and stepping through, I quickly add a console.log(foo) and get a beautiful:</p>
<pre><code>{
lemmons: "pie",
number: 9,
fetch: function(){..}
elements: {
fire: 99.9
}
}
</code></pre>
<p>Very cle... | 1 | 2016-08-27T21:13:05Z | 39,185,974 | <p>You can print your objects & Python classes in a lot of different ways, here's a simple one:</p>
<pre><code>class LinkedList:
head = None
tail = None
lemmons = 99
def __str__(self):
return str(vars(LinkedList))
print LinkedList()
</code></pre>
<p>I'd recommend you start for getting fa... | 0 | 2016-08-27T21:38:54Z | [
"python",
"class",
"debugging",
"object",
"tostring"
] |
How do most people do console.log debugging in Python? | 39,185,797 | <p>In Node.js when I want to quickly check the value of something rather than busting out the debugger and stepping through, I quickly add a console.log(foo) and get a beautiful:</p>
<pre><code>{
lemmons: "pie",
number: 9,
fetch: function(){..}
elements: {
fire: 99.9
}
}
</code></pre>
<p>Very cle... | 1 | 2016-08-27T21:13:05Z | 39,186,873 | <p>The expectation is that you <a href="https://docs.python.org/2/howto/logging.html#using-arbitrary-objects-as-messages" rel="nofollow">implement your own <code>__str__</code> method</a> so that you can pick what is important to log in your diags.</p>
<p>However, there is the option to log the whole object dictionary... | 0 | 2016-08-28T00:08:18Z | [
"python",
"class",
"debugging",
"object",
"tostring"
] |
Nervana Neon AttributeError: 'NoneType' object has no attribute 'sizeI' | 39,185,835 | <p>I'm a trying to do fprop with Nervana Neon, however, when I go to run model fprop I get the following error:</p>
<blockquote>
<p>AttributeError: 'NoneType' object has no attribute 'sizeI'</p>
</blockquote>
<p>I am following their example for fprop very close. I've trained the model using their <code>ImageLoader<... | 0 | 2016-08-27T21:17:41Z | 39,186,472 | <p>Working backwards on your stacktrace...</p>
<p>The problem comes from an attempt to dereference the <code>sizeI</code> attribute of a <code>layer</code> object when <code>layer</code> is <code>None</code>:</p>
<p><code>-> 1938 assert layer.sizeI == I.size</code></p>
<p>I'd call that a bug in the neon l... | 0 | 2016-08-27T22:46:26Z | [
"python",
"deep-learning"
] |
Intersection of 2 lists which contain non-hashables | 39,185,978 | <p>What is the most efficient way to find the intersection of 2 lists when both lists contain non-hashables?</p>
<p>Basically, let's say I have the following lists (which I completely made up):</p>
<pre><code>A = [<foo.bar object at 0x7f267c664080>, <foo.bar object at 0x7f267c664099>]
B = [<foo.bar obj... | 0 | 2016-08-27T21:39:28Z | 39,185,991 | <p>Hashing is what makes the <code>set</code> efficient. If you can't hash, then you can't take advantage of that efficiency - you have to compare every object with every other object and you get an O(n²) algorithm instead of an amortized O(n) one.</p>
<p>However, if you care only about object <em>identity</em> and n... | 1 | 2016-08-27T21:41:30Z | [
"python"
] |
Intersection of 2 lists which contain non-hashables | 39,185,978 | <p>What is the most efficient way to find the intersection of 2 lists when both lists contain non-hashables?</p>
<p>Basically, let's say I have the following lists (which I completely made up):</p>
<pre><code>A = [<foo.bar object at 0x7f267c664080>, <foo.bar object at 0x7f267c664099>]
B = [<foo.bar obj... | 0 | 2016-08-27T21:39:28Z | 39,186,008 | <p>A simple solution using list comprehension: <code>intersection = [element for element in A if element in B</code> checks if two elements of the same <em>value</em> are there. For example, for <code>[1, 2, 3]</code> and <code>[0, 1, 5]</code>, it will return <code>[1]</code>.</p>
| 0 | 2016-08-27T21:43:36Z | [
"python"
] |
Converting 2D Numpy array to a list of 1D columns | 39,185,985 | <p>What would be the best way of converting a 2D numpy array into a list of 1D columns?</p>
<p>For instance, for an array:</p>
<pre><code>array([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]])
</code></pre>
<p>I would like to get:</p>
<pre><code>[array([0, 1, 2, 3,... | 0 | 2016-08-27T21:40:23Z | 39,186,077 | <p>Well, here's <em>another</em> way. (I assume x is your original 2d array.)</p>
<pre><code>[row for row in x.T]
</code></pre>
<p>Still uses a Python list generator expression, however.</p>
| 0 | 2016-08-27T21:53:15Z | [
"python",
"numpy"
] |
Converting 2D Numpy array to a list of 1D columns | 39,185,985 | <p>What would be the best way of converting a 2D numpy array into a list of 1D columns?</p>
<p>For instance, for an array:</p>
<pre><code>array([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]])
</code></pre>
<p>I would like to get:</p>
<pre><code>[array([0, 1, 2, 3,... | 0 | 2016-08-27T21:40:23Z | 39,186,088 | <p>I can't think of any reason you would need </p>
<pre><code>[array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13, 14])]
</code></pre>
<p>Instead of</p>
<pre><code>array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14]])
</code></pre>
<p>Which you can get simply with <code>a.T</code></p>
... | 3 | 2016-08-27T21:54:39Z | [
"python",
"numpy"
] |
Converting 2D Numpy array to a list of 1D columns | 39,185,985 | <p>What would be the best way of converting a 2D numpy array into a list of 1D columns?</p>
<p>For instance, for an array:</p>
<pre><code>array([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]])
</code></pre>
<p>I would like to get:</p>
<pre><code>[array([0, 1, 2, 3,... | 0 | 2016-08-27T21:40:23Z | 39,186,135 | <p>Here is one way:</p>
<pre><code>In [20]: list(a.T)
Out[20]: [array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13, 14])]
</code></pre>
<p>Here is another one:</p>
<pre><code>In [40]: [*map(np.ravel, np.hsplit(a, 3))]
Out[40]: [array([0, 1, 2, 3, 4]), array([5, 6, 7, 8, 9]), array([10, 11, 12, 13,... | 1 | 2016-08-27T22:00:39Z | [
"python",
"numpy"
] |
CodingBat has22 why is this solution wrong? | 39,185,999 | <pre><code>def has22(nums):
if nums[len(nums) - 1] == 2:
if nums[len(nums) - 2] == 2:
return True
else:
for n in range(len(nums) - 3):
if nums[n] == 2 :
if nums[n + 1] == 2:
return True
else:
return False
</code></pre>
<p>I need to return True if the array contai... | -1 | 2016-08-27T21:42:34Z | 39,186,589 | <p>I think the error you report can only happen if <code>nums</code> is an empty list. In that situation, <code>nums[len(nums) - 1]</code> is not a valid index (as there are no valid indexes into an empty list).</p>
<p>For this problem, there's really not much point to special casing the last two items in the list. Yo... | 1 | 2016-08-27T23:05:55Z | [
"python"
] |
Why is my code not working? (Beginner programmer, python 1st language) | 39,186,000 | <p>I need some major improvements in my programming/coding and it's already been a month of this computer language field.</p>
<p>Right now I'm trying to create a class with 3 functions (lunch, breakfast, and dinner) and let's say I want to call the function lunch and add 'Strawberry' to the lunch list; it's supposed t... | 1 | 2016-08-27T21:42:54Z | 39,186,215 | <p>It doesn't seem like your 'Strawberry' parameter matches the lunch_count parameter in your lunch function. In the lunch method, you then can increment it by one every time you call lunch, rather than adding it as a parameter.</p>
<p>If you are new to Python, I would recommend <a href="https://learnpythonthehardway.... | 0 | 2016-08-27T22:09:20Z | [
"python"
] |
Why is my code not working? (Beginner programmer, python 1st language) | 39,186,000 | <p>I need some major improvements in my programming/coding and it's already been a month of this computer language field.</p>
<p>Right now I'm trying to create a class with 3 functions (lunch, breakfast, and dinner) and let's say I want to call the function lunch and add 'Strawberry' to the lunch list; it's supposed t... | 1 | 2016-08-27T21:42:54Z | 39,186,237 | <pre><code>class Food():
lunch_count = 0
lunch_list = {}
def __init__(self, food_name):
self.lc = None
self.food_name = food_name
def lunch(self):
Food.lunch_count += 1
self.lc = Food.lunch_count
Food.lunch_list[Food.lunch_count] = self.food_name
retur... | 0 | 2016-08-27T22:12:15Z | [
"python"
] |
Why is my code not working? (Beginner programmer, python 1st language) | 39,186,000 | <p>I need some major improvements in my programming/coding and it's already been a month of this computer language field.</p>
<p>Right now I'm trying to create a class with 3 functions (lunch, breakfast, and dinner) and let's say I want to call the function lunch and add 'Strawberry' to the lunch list; it's supposed t... | 1 | 2016-08-27T21:42:54Z | 39,186,640 | <p>Easier to read and understand.</p>
<pre><code>lunch_count=0
lunch_item=""
lunch_menu={}
while lunch_item != "quit":
lunch_item=input("Enter Item: ")
menu_item=str(lunch_item)
lunch_count+=1
lunch_menu.update({lunch_count:menu_item})
print(lunch_menu)
else:
print("exiting")
</code></pre>
<p>... | 0 | 2016-08-27T23:17:08Z | [
"python"
] |
Python urllib2 proxy setting issue | 39,186,031 | <p>I've looked through some of the other posts on this and I hope I'm not duplicating, but I'm stuck on a real headscratcher with setting a proxy server for urllib2. I'm running the below: </p>
<pre><code> file, site = argv
uri = 'https://'+site
http_proxy_server = "http://newyork.wonderproxy.com"
http_... | 0 | 2016-08-27T21:46:04Z | 39,186,645 | <p>Well this is a bit silly, but I tried a different example and my connection is working fine now.</p>
<pre><code> import urllib2
proxlist= ['minneapolis.wonderproxy.com', 'newyork.wonderproxy.com']
ports = [0,1,2,3]
for prox in proxlist:
for port in ports:
proxy = urllib2.ProxyHan... | 0 | 2016-08-27T23:17:38Z | [
"python",
"proxy",
"urllib2"
] |
Python urllib2 proxy setting issue | 39,186,031 | <p>I've looked through some of the other posts on this and I hope I'm not duplicating, but I'm stuck on a real headscratcher with setting a proxy server for urllib2. I'm running the below: </p>
<pre><code> file, site = argv
uri = 'https://'+site
http_proxy_server = "http://newyork.wonderproxy.com"
http_... | 0 | 2016-08-27T21:46:04Z | 39,441,442 | <p>Your question sets the proxy URL to</p>
<p><code>http://user:password@http://newyork.wonderproxy.com:11001</code></p>
<p>which isn't valid. If you changed <code>http_proxy_server</code> to <code>newyork.wonderproxy.com</code> then your first solution might work better.</p>
| 0 | 2016-09-11T22:56:41Z | [
"python",
"proxy",
"urllib2"
] |
Styling ModelMultipleChoiceField Django | 39,186,043 | <p>I'm having trouble styling my django form with a ModelMultipleChoiceField.</p>
<p>Heres my form:</p>
<pre><code>class SkriptenSelect(forms.Form):
skripten = StyledModelMultipleChoiceField(
queryset=None,
widget=forms.CheckboxSelectMultiple,
)
def __init__(self, *args, **kwargs):
choices = kwargs.pop('... | 0 | 2016-08-27T21:48:40Z | 39,186,752 | <p>You can use <code>render_to_string</code>. It loads a template and renders it with a context. Returns a string.</p>
<pre><code>from django.template.loader import render_to_string
rendered = render_to_string('my_template.html', {'foo': 'bar'})
</code></pre>
<p>For various variants you can make various StyledModelMu... | 0 | 2016-08-27T23:39:03Z | [
"python",
"html",
"django"
] |
pandas group by confusion -- unhashable type | 39,186,067 | <p>Using Pandas data frame group by feature and I want to group by column <code>c_b</code> and calculate unique count for column <code>c_a</code> and column <code>c_c</code>. My expected results are,</p>
<p><strong>Expected results</strong>,</p>
<pre><code>c_b,c_a_unique_count,c_c_unique_count
python,2,2
c++,2,2
</co... | -1 | 2016-08-27T21:52:26Z | 39,186,332 | <p>For the number of unique elements in each group, you can use:</p>
<pre><code>df.groupby('c_b')['c_a', 'c_d'].agg(pd.Series.nunique)
</code></pre>
<hr>
<pre><code>df.groupby('c_b')['c_a', 'c_d'].agg(pd.Series.nunique)
Out:
c_a c_d
c_b
c++ 2 2
python 2 2
df.groupby('c_b', as_i... | 1 | 2016-08-27T22:24:50Z | [
"python",
"python-2.7",
"pandas",
"dataframe",
"group-by"
] |
Positive Negative - Simple Python exercise | 39,186,071 | <p>Given 2 int values, return True if one is negative and one is positive. Except if the parameter "negative" is True, then return True only if both are negative.</p>
<p>I finally figured it out.</p>
<pre><code>def pos_neg(a, b, negative):
if negative:
return (a < 0 and b < 0)
else:
return (a > 0... | -4 | 2016-08-27T21:52:50Z | 39,186,097 | <p>You are not returning those two lines. You are returning the values that those two lines <em>evaluate to</em>. In your cases, those are boolean expressions that will evaluate to either true or false. That final boolean value is what your function returns.</p>
| 1 | 2016-08-27T21:55:42Z | [
"python"
] |
Positive Negative - Simple Python exercise | 39,186,071 | <p>Given 2 int values, return True if one is negative and one is positive. Except if the parameter "negative" is True, then return True only if both are negative.</p>
<p>I finally figured it out.</p>
<pre><code>def pos_neg(a, b, negative):
if negative:
return (a < 0 and b < 0)
else:
return (a > 0... | -4 | 2016-08-27T21:52:50Z | 39,186,360 | <p>Python evaluates whatever expression follows the <code>return</code> statement, and the result of the evaluation is what is returned. You have used two boolean expressions:</p>
<pre><code>(a < 0 and b < 0)
</code></pre>
<p>This evaluates to True if both a < 0 and b < 0; otherwise it evaluates to False... | 1 | 2016-08-27T22:28:10Z | [
"python"
] |
Django form - using variable from database | 39,186,161 | <p>I have the following form which is working perfectly:</p>
<pre><code># coding=utf-8
from django import forms
from straightred.models import StraightredTeam
from straightred.models import UserSelection
class SelectTwoTeams(forms.Form):
cantSelectTeams = UserSelection.objects.filter(campaig... | 0 | 2016-08-27T22:02:37Z | 39,191,129 | <p>Got there in the end :)</p>
<p>I used the following: </p>
<pre><code>campaignnoquery = UserSelection.objects.filter(user=349).order_by('-campaignno')[:1]
for x in campaignnoquery:
test2 = x.campaignno
</code></pre>
<p>I can then use test2 as the variable.</p>
| 0 | 2016-08-28T12:11:28Z | [
"python",
"mysql",
"django"
] |
Model comparison in PyMC3 | 39,186,183 | <p>I am new to PyMC3 and am trying to implement the hierarchical model from Kruschke (2015) section 12.2.2 (model comparison). </p>
<p>I succeeded in defining the full model and then looking at the differences of posterior parameter values (determine whether difference can credibly be said to be zero).</p>
<p>I also ... | 1 | 2016-08-27T22:05:56Z | 39,199,113 | <p>The error you are getting is because you are trying to index a list using a tensor. One way to solve this will be to turn the list into a tensor. </p>
<pre><code>import theano.tensor as tt
a0 = tt.as_tensor([.48*500, aP])
</code></pre>
<p>Alternatively you can use <code>pmc.switch()</code> to choose between priors... | 1 | 2016-08-29T05:36:27Z | [
"python",
"bayesian",
"pymc3"
] |
What is web.session.Session in the python web.py module | 39,186,201 | <p>I'm currently learning Python and can't work out what the <code>web.session.Session</code> is in the follow game program:</p>
<pre><code>app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'room': None})
</code></pre>
<p>What are <code>app</code... | 1 | 2016-08-27T22:07:53Z | 39,234,533 | <p>This <code>web.session</code> module gives you the session support, </p>
<ul>
<li><p><code>initializer</code> - You can set the initial session which is not mandatory.</p>
<p>eg: <code>initializer={'room': None}</code> sets the initial session of room to None.</p></li>
<li><p><code>DiskStore</code> makes the sessi... | 0 | 2016-08-30T18:20:36Z | [
"python",
"web.py"
] |
How to add instance variable to Scrapy CrawlSpider? | 39,186,207 | <p>I am running a CrawlSpider and I want to implement some logic to stop following some of the links in mid-run, by passing a function to <code>process_request</code>.</p>
<p>This function uses the spider's <strong>class</strong> variables in order to keep track of the current state, and depending on it (and on the re... | 0 | 2016-08-27T22:08:25Z | 39,188,109 | <p>I think <a href="http://doc.scrapy.org/en/latest/topics/spiders.html#spider-arguments" rel="nofollow">spider arguments</a> would be the solution in your case.</p>
<p>When invoking scrapy like <code>scrapy crawl some_spider</code>, you could add arguments like <code>scrapy crawl some_spider -a foo=bar</code>, and th... | 1 | 2016-08-28T04:47:44Z | [
"python",
"scrapy",
"scrapy-spider"
] |
More elegant conversion of Postgres data within pandas Dataframe | 39,186,262 | <p>I have some data in a PostgreSQL table.</p>
<p>I am pulling the data back to a notebook via code like the following:</p>
<pre><code>import numpy as np
import pandas as pd
%load_ext sql
%sql postgresql://foo:foo@localhost:5432/barbar
result_from_sql = %%sql SELECT Date, Year,Score, Cost FROM MyData;
result_df = r... | 0 | 2016-08-27T22:16:13Z | 39,187,676 | <p>you can use the following solution to parse to numeric:</p>
<hr>
<pre><code>s = ['score', 'cost']
result_df[s] = result_df[s].astype(float) # incase you wanted to parse them to floats
</code></pre>
<p>let me know if this works </p>
| 1 | 2016-08-28T03:08:27Z | [
"python",
"postgresql",
"pandas"
] |
Tkinter - Make status bar longer than window | 39,186,503 | <p>I was working on a Tkinter GUI with a status bar at the bottom to display instructions or the file paths on hover over a specific widget, especially if the file path was too long to write in the given section. Is there any way that the status bar could extends past the window in the case of a long name? (Like maybe ... | 1 | 2016-08-27T22:51:48Z | 39,189,008 | <p>Yes, it's possible:</p>
<pre><code>from tkinter import *
root = Tk()
root.geometry("800x500-500+50")
root.config(bg="lightblue")
stslabel = Label(root, anchor=W,
text="Process another input file to get citations. blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah bl... | 0 | 2016-08-28T07:36:37Z | [
"python",
"tkinter"
] |
Flask, MySQL and SQLAlchemy quering ID error | 39,186,521 | <p>I get a weird error when I try to query an item by id. I have tried all suggestion I have found and only when doing raw query I get a proper result.</p>
<p>Part of the Traceback:</p>
<pre><code> File "C:\Users\pgsid\Envs\xo\lib\site-packages\flask\app.py", line 1988, in wsgi_app
response = self.full_dispatch_... | 0 | 2016-08-27T22:55:47Z | 39,187,997 | <p>Turns out it was the fact that in the MySQL schema for some reason deleted was defined as a <code>BIT</code> type. </p>
<p>All type combinations in SQLAlchemy failed. I had to change the schema to make it into a <code>TINYINT(1)</code></p>
| 0 | 2016-08-28T04:24:47Z | [
"python",
"mysql",
"flask",
"sqlalchemy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.