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 |
|---|---|---|---|---|---|---|---|---|---|
Add header #ifndef into C header files in current directory | 38,778,409 | <p>In current directory, All C header files (*.h) don't include the preprocessor macro </p>
<pre><code>#ifndef FILENAME_H
#define FILENAME_H
...
#endif
</code></pre>
<p>, it's too tedious to add them in each header manually. How to do that automatically via python or shell?</p>
| -1 | 2016-08-04T22:30:51Z | 38,778,739 | <p>Assuming you are in a <code>unix</code> shell with <code>find</code>, <code>cut</code>, and <code>sed</code> available. You can get each filename using <code>find</code>, then use <code>sed</code> to change those files.</p>
<p>You can save the below script in a file called <code>addifndef.sh</code>.</p>
<pre><cod... | 1 | 2016-08-04T23:07:29Z | [
"python",
"c",
"shell",
"c-preprocessor"
] |
Add header #ifndef into C header files in current directory | 38,778,409 | <p>In current directory, All C header files (*.h) don't include the preprocessor macro </p>
<pre><code>#ifndef FILENAME_H
#define FILENAME_H
...
#endif
</code></pre>
<p>, it's too tedious to add them in each header manually. How to do that automatically via python or shell?</p>
| -1 | 2016-08-04T22:30:51Z | 38,778,750 | <p>I'm going to second @kaylum's advice and also not give you the whole thing, but here is some pseudocode that might set you on the right path</p>
<pre><code>for each file in the directory
if filename doesn't end with .h
continue
open the file
store its contents in a variable
create the header guard... | 1 | 2016-08-04T23:09:23Z | [
"python",
"c",
"shell",
"c-preprocessor"
] |
Add header #ifndef into C header files in current directory | 38,778,409 | <p>In current directory, All C header files (*.h) don't include the preprocessor macro </p>
<pre><code>#ifndef FILENAME_H
#define FILENAME_H
...
#endif
</code></pre>
<p>, it's too tedious to add them in each header manually. How to do that automatically via python or shell?</p>
| -1 | 2016-08-04T22:30:51Z | 38,789,861 | <p>Based on Cody's answer, I implemented the guardHeader.py:</p>
<pre><code> 1 #!/usr/bin/python3
2
3 import glob,os,sys
4
5 global search_dir
6
7 def clearContent(pfile):
8 pfile.seek(0)
9 pfile.truncate()
10
11 def guard(fileName):
12 file = open(fileName, 'r+')
13 content = file... | 2 | 2016-08-05T12:58:30Z | [
"python",
"c",
"shell",
"c-preprocessor"
] |
Separate data from one column into three columns | 38,778,498 | <p>I have a column in an excel which contains a mix of First Names, Last Names and Job titles. Only pattern that can be observed is - in each set of 3 rows, every 1st row is first name, 2nd row is last name and 3rd row is job title. I want to create 3 different columns and and segregate this data
Sample data:</p>
<pr... | 2 | 2016-08-04T22:41:17Z | 38,778,571 | <p>You can use <a href="https://docs.python.org/2/library/functions.html#range" rel="nofollow">this notation</a> to get every third element with different starting points.</p>
<pre><code>l = ['John', 'Bush', 'Manager', 'Katrina', 'Cohn', 'Secretary']
pd.DataFrame({'First Name': l[::3], 'Last Name': l[1::3], 'Job Titl... | 3 | 2016-08-04T22:48:57Z | [
"python",
"pandas"
] |
Separate data from one column into three columns | 38,778,498 | <p>I have a column in an excel which contains a mix of First Names, Last Names and Job titles. Only pattern that can be observed is - in each set of 3 rows, every 1st row is first name, 2nd row is last name and 3rd row is job title. I want to create 3 different columns and and segregate this data
Sample data:</p>
<pr... | 2 | 2016-08-04T22:41:17Z | 38,778,820 | <pre><code>s = pd.Series([
'John',
'Bush',
'Manager',
'Katrina',
'Cohn',
'Secretary'])
df = pd.DataFrame(s.values.reshape(-1, 3),
columns=['First Name', 'Last Name', 'Job Title'])
df
</code></pre>
<p><a href="http://i.stack.imgur.com/gN5Bu.png" rel="n... | 1 | 2016-08-04T23:18:24Z | [
"python",
"pandas"
] |
Ignore elements of a list up to a certain index | 38,778,546 | <p>I am creating two lists by reading from a text file with two columns, which always has the same layout but the length of the columns differ.</p>
<pre><code>def read_columns(x,y,filename,rw):
print(filename)
if(not os.path.isfile(filename)):
sys.exit(filename + " does not exi... | 0 | 2016-08-04T22:46:10Z | 38,778,733 | <p>You have a couple of problems in your code besides what you're trying to do. I've tried to fix the errors and explain what I was doing.</p>
<pre><code>import logging
from collections import namedtuple
logging.basicConfig(level=logging.DEBUG)
# See https://docs.python.org/3/library/collections.html#collections.name... | 0 | 2016-08-04T23:06:37Z | [
"python",
"list"
] |
Django Rest framework 3.4.0, ViewSet with custom create() and Many-to-many relationship | 38,778,587 | <p>I have the following Django models:</p>
<pre><code>class Task(models.Model):
'''Task needed to complete a goal'''
title = models.CharField(max_length=200)
class Issue(models.Model):
'''Issue from different forges'''
title = models.CharField(max_length=200, blank=True)
tasks = models.ManyToManyF... | 0 | 2016-08-04T22:51:02Z | 38,778,638 | <p>You marked <code>tasks</code> to be <code>read_only</code> in <code>IssueSerializer</code>. That's why you can't find the <code>tasks</code> keys in the <code>validated_data</code>. </p>
| 0 | 2016-08-04T22:56:56Z | [
"python",
"django",
"django-rest-framework"
] |
Python script for web scraping from web pages to find ip address for urls present in it | 38,778,590 | <p>I have started writing script as mentioned below</p>
<pre><code>import urllib2
from bs4 import BeautifulSoup
trg_url='http://timesofindia.indiatimes.com/'
req=urllib2.Request(trg_url)
handle=urllib2.urlopen(req)
page_content=handle.read()
soup=BeautifulSoup(page_content,"html")
new_list=soup.find_all('a')
for li... | -1 | 2016-08-04T22:51:30Z | 38,779,255 | <p>Use the socket module to get the ip address:</p>
<pre><code>import urllib2
from bs4 import BeautifulSoup
import socket
import csv
trg_url='http://timesofindia.indiatimes.com/'
req=urllib2.Request(trg_url)
handle=urllib2.urlopen(req)
page_content=handle.read()
soup=BeautifulSoup(page_content,"lxml")
new_list=soup.f... | -1 | 2016-08-05T00:12:54Z | [
"python",
"scripting",
"web-crawler"
] |
building python-boost hello world on Mac OS X with Homebrew - Makefile vs. Resolution | 38,778,676 | <p>While not directly an explicit question - I am trying to make a post that addresses some of the bizarre issues encountered when trying to install <code>boost-python</code> as a novice</p>
<p>The post is based on <a href="https://feralchicken.wordpress.com/2013/12/07/boost-python-hello-world-example-using-cmake/" re... | 0 | 2016-08-04T23:00:30Z | 38,778,677 | <p>This doesn't directly address the <code>Makefile</code> issues but is rather to make other python users will be aware of my breakthrough that a <code>Makefile</code> was not necessary. </p>
<p>I'll still accept any answers leading to a fix with the <code>Makefile</code> attempt.</p>
<p>Using a different example <c... | 0 | 2016-08-04T23:00:30Z | [
"python",
"c++",
"osx",
"makefile",
"boost-python"
] |
PyQt: QLineEdit input mask for hexadecimal | 38,778,755 | <p>How can I use the input mask for QLineEdit of pyqt to limit 9 digits of hex numbers only. For example,
I want to limit user to enter hex from 0x300000000 to 0x400000000 only</p>
| 0 | 2016-08-04T23:10:14Z | 38,786,754 | <p>For this particular example you can use the <code>QValidator</code> class which provides validation of input text, please see example below:</p>
<pre><code>import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import Qt, QRegExp
from PyQt4.QtGui import QRegExpValidator
def window():
app = QtGui.QApplic... | 0 | 2016-08-05T10:15:27Z | [
"python",
"pyqt",
"pyqt4"
] |
Trying to insert a table into jinja2 template from flask | 38,778,758 | <p>I have been trying to create my first Flask website, using super simple templates in <code>Jinja2</code>. <em>(I started with my regular html and abandoned it quickly because figuring out where to put things was a nightmare. I will go back in after this hard part and tweak the flask code, for now, I have eliminated ... | 1 | 2016-08-04T23:10:24Z | 38,784,353 | <p>You need to convert timestamps to datetime objects</p>
<pre><code>from dateutil.parser import parse # pip install python-dateutil
raw = json.loads(raw)
for item in raw:
item['date_time'] = parse(item['date_time'])
</code></pre>
<p>And pass <code>table</code> to template</p>
<pre><code>return render_template(... | 1 | 2016-08-05T08:12:00Z | [
"python",
"html",
"flask",
"jinja2"
] |
Tensorflow: No gradients provided for any variable | 38,778,760 | <p>I am new to <code>tensorflow</code> and I am building a network but failing to compute/apply the gradients for it. I get the error:</p>
<pre><code>ValueError: No gradients provided for any variable: ((None, tensorflow.python.ops.variables.Variable object at 0x1025436d0), ... (None, tensorflow.python.ops.variables.V... | 1 | 2016-08-04T23:10:58Z | 38,783,256 | <p>I always have the tf.nn.softmax_cross_entropy_with_logits() used so that I have the logits as first argument and the labels as second. Can you try this?</p>
| 1 | 2016-08-05T07:10:15Z | [
"python",
"machine-learning",
"tensorflow"
] |
Bind a Dictionary to a SQLAlchemy Model for Update | 38,778,791 | <p>I have a Dictionary (from a WTForm) that has keys in it that match fields in my SQLAlchemy Model.</p>
<pre><code>class Company(database.Model):
__tablename__ = "company"
id = database.Column(database.Integer, primary_key=True, autoincrement=True)
name = database.Column(database.String(255), nullable=Fal... | 1 | 2016-08-04T23:15:08Z | 38,778,828 | <p>Assuming you actually want to create the record it should be as simple as:</p>
<pre><code>company = Company.create(**company_dict)
</code></pre>
<p>Or for an update:</p>
<pre><code>company.update(**company_dict)
</code></pre>
| 0 | 2016-08-04T23:19:12Z | [
"python",
"sqlalchemy",
"flask-sqlalchemy",
"wtforms"
] |
Python - Fabric maximum 10 parallel SSH connections | 38,778,998 | <p>I am using <code>Fabric</code> with the parallel decorator like so:</p>
<pre><code>parallel(pool_size=100)
def mytask():
# do work
</code></pre>
<p>I was hoping the program to open 100 distinct SSH connections and run the <code>Fabric</code> task on all those servers in parallel.</p>
<p>However, monitoring th... | 0 | 2016-08-04T23:38:14Z | 38,790,988 | <p>The <code>get_pool_size</code> method in the fabric.tasks.Task class is a bit convoluted, trying to guess a not too large pool_size. It returns an integer, after picking values from the global config, task config, default passed, number of hosts.</p>
<p>By my reading of it, it <em>should</em> return the minimum of ... | 0 | 2016-08-05T13:53:08Z | [
"python",
"ssh",
"fabric"
] |
python libusb1: asynchronous TRANSFER_NO_DEVICE status just after successful syncronous transfers | 38,779,019 | <h1>Story</h1>
<p>I'm programming a driver for a scientific camera. It uses the Cypress FX3 usb peripheral controller. In order to communicate with it I'm using libusb1 for python, specifically the module usb1. My OS is Ubuntu 16.04 LTS.</p>
<p>The communication has two steps:</p>
<ul>
<li><p>The camera is configure... | 0 | 2016-08-04T23:41:12Z | 38,796,487 | <p>As <a href="http://stackoverflow.com/users/5546740/dryman">dryman</a> pointed out, I was freeing the context before finishing (because I opened the context twice). If we inline the read_async and write_sync calls in the code extract:</p>
<pre><code>print(" Prepare read")
with port_read.read_async(512) as data_colle... | 0 | 2016-08-05T19:24:45Z | [
"python",
"linux",
"asynchronous",
"libusb-1.0"
] |
Two blank lines after function | 38,779,052 | <p>The PEP 8 style guide says to surround top level functions with <a href="https://www.python.org/dev/peps/pep-0008/#blank-lines" rel="nofollow">two blank lines</a>. I have Sublime Text configured with Anaconda, so it highlights the need to put two blank lines after each function in Flask. But I noticed on GitHub that... | 2 | 2016-08-04T23:44:16Z | 39,435,551 | <p>The PEP 8 style guidance to add two blank lines after classes and functions is followed by major open source projects. I will keep doing it! </p>
| -2 | 2016-09-11T11:21:58Z | [
"python",
"anaconda",
"pep8"
] |
Using Python dict comprehension to index list of words by first letter | 38,779,082 | <p>Conceptually, this is pretty easy, but I can't seem to figure it out. </p>
<p>I want to turn a list of strings into a dict with each key being the first letter of the list of words associated with it.</p>
<pre><code># My list of sounds
sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'br... | 1 | 2016-08-04T23:47:58Z | 38,779,153 | <p>Is this what you are trying to achieve?</p>
<pre><code>firsts = {s[0] for s in sounds}
indexed = {first: [s for s in sounds if s[0]==first] for first in firsts}
</code></pre>
| 0 | 2016-08-04T23:56:07Z | [
"python"
] |
Using Python dict comprehension to index list of words by first letter | 38,779,082 | <p>Conceptually, this is pretty easy, but I can't seem to figure it out. </p>
<p>I want to turn a list of strings into a dict with each key being the first letter of the list of words associated with it.</p>
<pre><code># My list of sounds
sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'br... | 1 | 2016-08-04T23:47:58Z | 38,779,163 | <p>No problem, <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow">itertools to the rescue</a>. You can group the elements by their first letter, then create a dict out of them.</p>
<pre><code>sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'bre', 'bo... | 3 | 2016-08-04T23:57:46Z | [
"python"
] |
Using Python dict comprehension to index list of words by first letter | 38,779,082 | <p>Conceptually, this is pretty easy, but I can't seem to figure it out. </p>
<p>I want to turn a list of strings into a dict with each key being the first letter of the list of words associated with it.</p>
<pre><code># My list of sounds
sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'br... | 1 | 2016-08-04T23:47:58Z | 38,779,249 | <p>this can be done in one go with just the standard library</p>
<pre><code>>>> sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'bre', 'bore']
>>> result=dict()
>>> for s in sounds:
result.setdefault(s[0],[]).append(s)
>>> result
{'b': ['bark', '... | 4 | 2016-08-05T00:12:13Z | [
"python"
] |
Using Python dict comprehension to index list of words by first letter | 38,779,082 | <p>Conceptually, this is pretty easy, but I can't seem to figure it out. </p>
<p>I want to turn a list of strings into a dict with each key being the first letter of the list of words associated with it.</p>
<pre><code># My list of sounds
sounds = ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'br... | 1 | 2016-08-04T23:47:58Z | 38,782,332 | <p>This is not a good use for a dict comprehension - you will end up with more loops than you need. If you write it directly then you only scan the input list once:</p>
<pre><code>dict1 = {}
for s in ['sniff', 'bark', 'bork', 'blork', 'heck', 'borf', 'bjork', 'boo', 'bre', 'bore']:
if not s[0] in dict1.keys():
d... | 0 | 2016-08-05T06:15:02Z | [
"python"
] |
How to connect the QFileSystemModel dataChanged signal in PyQt5? | 38,779,112 | <p>I'm trying to connect the <code>QFileSystemModel.dataChanged</code> signal, but with no luck so far. The code below is spawning this error:</p>
<blockquote>
<p>TypeError: bytes or ASCII string expected not 'list'</p>
</blockquote>
<pre><code>import sys
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtWid... | 1 | 2016-08-04T23:51:35Z | 38,779,472 | <p>You don't need to explicitly select the signal if doesn't have any overloads. So the correct way to connect the signal is like this:</p>
<pre><code> self.model.dataChanged.connect(self.dataChanged)
</code></pre>
<p>But in any case, when you <strong>do</strong> need to select the signature, you must pass in eith... | 1 | 2016-08-05T00:38:56Z | [
"python",
"pyqt",
"signals-slots",
"pyqt5",
"qfilesystemmodel"
] |
Extra fields on CSV | 38,779,138 | <p>I'm trying to write my first Python script which prints what clients are probing for AP and what APs they're doing for. So my problem comes when a client (well, not client yet) probes for more than one AP. </p>
<pre><code>import csv
import sys
if len(sys.argv) != 2:
print("usage: ./scriptpy.py csvfile")
pa... | 0 | 2016-08-04T23:54:40Z | 38,779,180 | <p>One way to deal with key errors is <code>.get('my_key', 'alternate_value')</code>, like this:</p>
<pre><code>row.get('extra', '') # rather than row['extra']
</code></pre>
| 1 | 2016-08-05T00:00:18Z | [
"python",
"csv"
] |
Ansible: validating a variable inside a multi-dimensional array/dict in one statement | 38,779,196 | <p>With the <code>uri</code> module (though this issue isn't limited to that) you can query a web endpoint and get a result back, and I'm trying to validate (with a <code>when</code> conditional) an object in the JSON response. Unfortunately the actual value is (roughly) in:</p>
<pre><code>registered_variable_name.js... | 0 | 2016-08-05T00:02:24Z | 38,780,623 | <p>This seems to work just fine (with ansible 2.1.1.0):</p>
<ul>
<li>debug:
msg: "The key is defined"
when: registered_variable_name.json.result.my_key is defined
and registered_variable_name.json.result.my_key == 'target value'</li>
</ul>
<p>Here's a complete example:</p>
<pre><code>- hosts: localhost
name: K... | 1 | 2016-08-05T03:28:54Z | [
"python",
"dictionary",
"ansible"
] |
For Loop to determine weighted average python | 38,779,242 | <p>I'm new with Python and am having trouble crafting the correct for loop for a situation.</p>
<p>I have a dataframe <code>dfclean</code> that contains two columns: a restaurant star rating <code>"Star_Rating"</code> and total number of reviews <code>"Review_Count"</code>.</p>
<p>I want to find weighted averages for... | 3 | 2016-08-05T00:11:19Z | 38,779,270 | <p>You shouldn't use a for loop. You can take advantage of broadcasting to do something the following:</p>
<pre><code>dfclean['weightedavg'] = dfclean['Star_Rating'] * dfclean['Review_Count'] / dfclean['Review_Count'].sum()
</code></pre>
<p>This is much faster than using a Python loop and is also syntactically cleane... | 5 | 2016-08-05T00:15:17Z | [
"python",
"pandas",
"for-loop",
"dataframe"
] |
Random Forest handle negation | 38,779,262 | <p>I'm using Random Forest to apply a sentiment to a string. So basically after cleaning the reviews, which essentially means that stop words (<code>nltk.corpus -> stopwords</code> from where I remove words as <em>no, not, nor, won, wasn, weren</em>) are removed, as well as non-letter characters, and everything is p... | 2 | 2016-08-05T00:13:41Z | 38,783,100 | <p>I believe this question is better suited for the Cross Validated stack exchange, but anyhow.</p>
<p>There are several things that might improve your results:</p>
<ol>
<li><p>For sentiment analysis it doesn't feel right to remove negation stopwords like 'no', 'not', etc. since they can change totally the positive/n... | 2 | 2016-08-05T07:02:25Z | [
"python",
"scikit-learn",
"random-forest",
"sklearn-pandas"
] |
Python program for rearranging an array swapping 2 at a time doesn't work, could someone help me? | 38,779,326 | <p>This is the code I've written for a Python program (please keep in mind that I learnt Python from the Internet a couple of days ago). It is supposed to rearrange a inputted list (say, [3,2,4,1,5]), into, in the example case, [1,2,3,4,5].
For some reason, it's not working, and I can't figure the reason out. I've trie... | 1 | 2016-08-05T00:21:31Z | 38,779,454 | <p><code>solvepos()</code> operates on the <code>global pos</code>, but that's a string - when you do <code>if pos[z] == q+1:</code>, <code>q+1</code> is an integer (one of the values from the <code>range</code>), but <code>pos[z]</code> is a string (one of the characters of the input). These will never compare equal, ... | 0 | 2016-08-05T00:36:55Z | [
"python"
] |
Reorder pandas groupby dataframe | 38,779,335 | <p>I have the following groupby dataframe in pandas</p>
<pre><code>Crop Region
maize_1 Temperate 30.0
Tropical 46.0
maize_2 Tropical 77.5
Temperate 13.5
soybean_1 Temperate 18.5
Tropical 35.0
</code></pre>
<p>How ... | 2 | 2016-08-05T00:23:13Z | 38,779,365 | <p>Check out <code>sortlevel</code> (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sortlevel.html" rel="nofollow">docs</a>) or <code>sort_index</code> (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow">docs</a>).</p>
<pre><... | 0 | 2016-08-05T00:27:30Z | [
"python",
"pandas"
] |
Reorder pandas groupby dataframe | 38,779,335 | <p>I have the following groupby dataframe in pandas</p>
<pre><code>Crop Region
maize_1 Temperate 30.0
Tropical 46.0
maize_2 Tropical 77.5
Temperate 13.5
soybean_1 Temperate 18.5
Tropical 35.0
</code></pre>
<p>How ... | 2 | 2016-08-05T00:23:13Z | 38,779,379 | <h3>Setup</h3>
<pre><code>idx = pd.MultiIndex.from_tuples([('maize_1', 'Temperate'), ('maize_1', 'Tropical'),
('maize_2', 'Tropical'), ('maize_2', 'Temperate'),
('soybean_1', 'Temperate'), ('soybean_1', 'Tropical')],
names... | 3 | 2016-08-05T00:28:56Z | [
"python",
"pandas"
] |
Slow equality evaluation for identical objects (x == x) | 38,779,421 | <p>Is there any reason <code>x == x</code> is not evaluated quickly? I was hoping <code>__eq__</code> would check if its two arguments are identical, and if so return True instantly. But it doesn't do it:</p>
<pre><code>s = set(range(100000000))
s == s # this doesn't short-circuit, so takes ~1 sec
</code></pre>
<p>Fo... | 15 | 2016-08-05T00:32:55Z | 38,779,482 | <p>As you say, someone could quite easily define an <code>__eq__</code> that you personally don't happen to approve of ... for example, the <a href="https://en.wikipedia.org/wiki/IEEE_floating_point" rel="nofollow">Institute of Electrical and Electronics Engineers</a> might be so foolish as to do that:</p>
<pre><code>... | 5 | 2016-08-05T00:40:32Z | [
"python",
"python-3.x",
"python-internals"
] |
Python CGI downloads the file instead of executing on CentOS | 38,779,463 | <p>I have worked on CGI by python programming on Ubuntu and I got satisfied result. I have a HTML file that has a simple form with a simple input as button, and an action to <code>.py</code> file. the <code>.py</code> file has <code>755</code> permission and is located in <code>/var/www/cgi-bin</code>. and the HTML is ... | 0 | 2016-08-05T00:37:42Z | 38,981,249 | <p>Are you running the html file like <code>hhtp://localhost/display_databse.html</code> ?
Well if its still not working you can try <a href="https://www.apachefriends.org" rel="nofollow">XAMPP</a>.Its hassle free to setup the same apache server with mariadb/php for home/testing usage but needs some tweaking for produc... | 0 | 2016-08-16T17:41:30Z | [
"python",
"centos",
"cgi"
] |
how to dynamically generate methods for proxy class? | 38,779,590 | <p>I have a object like:</p>
<pre><code>class Foo(object):
def __init__(self,instance):
self.instance = instance
</code></pre>
<p>with</p>
<pre><code>>>> instance = SomeOtherObject()
>>> f = Foo(instance)
</code></pre>
<p>I want to be able to do</p>
<pre><code>>>> f.some_meth... | 0 | 2016-08-05T00:58:00Z | 38,779,644 | <p>Write a <code>__getattr__()</code> method for your proxy class. This will be called when an attribute is accessed that doesn't exist on your instance. Return your contained object's attribute of the same name (or a wrapper if you insist, but there's no need if you just want to call the contained object's method and ... | 3 | 2016-08-05T01:06:36Z | [
"python",
"metaprogramming"
] |
how to dynamically generate methods for proxy class? | 38,779,590 | <p>I have a object like:</p>
<pre><code>class Foo(object):
def __init__(self,instance):
self.instance = instance
</code></pre>
<p>with</p>
<pre><code>>>> instance = SomeOtherObject()
>>> f = Foo(instance)
</code></pre>
<p>I want to be able to do</p>
<pre><code>>>> f.some_meth... | 0 | 2016-08-05T00:58:00Z | 38,779,703 | <p>You should look at the <code>wrapt</code> module. It is purpose built for creating transparent object proxy where you can selectively override certain aspects of the wrapped object. For example:</p>
<pre><code>class Test(object):
def some_method(self):
print 'original'
import wrapt
proxy = wrapt.Objec... | 1 | 2016-08-05T01:15:25Z | [
"python",
"metaprogramming"
] |
pandas "stacked" bar plot with values not added to give height | 38,779,638 | <p>I am trying to display a bar plot in <code>pandas 0.18.1</code> where the values for the different columns are displayed on top of each other but not added. So this is I think a stacked bar chart without the <strong>"stacking"</strong> which adds all stack values.</p>
<p>So in the example below</p>
<pre><code>impo... | 2 | 2016-08-05T01:05:53Z | 38,780,304 | <p>Please check out the following code, it is not a comprehensive solution, but basically achieve what you want. </p>
<pre><code>import pandas as pd
import matplotlib.pyplot as plt
so_example = pd.DataFrame( [(15 , 0 , 0 , 4),(16, 0, 1, 4),(17 , 0 , 0 , 6)]).set_index(0)
fig = plt.figure()
ax = fig.add_subplot(111... | 2 | 2016-08-05T02:44:16Z | [
"python",
"pandas",
"matplotlib",
"bar-chart"
] |
setAttr of a list in maya python | 38,779,640 | <p>I'm still figuring out how Python and Maya work together so forgive ignorance on my part. So I'm trying to change the attributes of a list of joints in maya using a loop like so:</p>
<p><code>for p in jointList:
cmd.getAttr(p, 'radius', .5)</code></p>
<p>and I get this error:</p>
<p><code>Invalid argument 1,... | 0 | 2016-08-05T01:05:56Z | 38,791,535 | <p>You need to specify both the node and the channel as your first argument, like 'joint1.radius'.</p>
<p>to set the radius to .5 on all your joints, your code would be:</p>
<pre><code>for p in jointList:
cmd.setAttr(p + '.radius', .5)
</code></pre>
| 0 | 2016-08-05T14:20:25Z | [
"python",
"maya",
"mel"
] |
setAttr of a list in maya python | 38,779,640 | <p>I'm still figuring out how Python and Maya work together so forgive ignorance on my part. So I'm trying to change the attributes of a list of joints in maya using a loop like so:</p>
<p><code>for p in jointList:
cmd.getAttr(p, 'radius', .5)</code></p>
<p>and I get this error:</p>
<p><code>Invalid argument 1,... | 0 | 2016-08-05T01:05:56Z | 38,794,243 | <p>Unless you work with pyMel you need to specify attr name and node to get or set. </p>
<p><strong>for getAttr :</strong></p>
<pre><code>for p in jointList:
val = cmd.getAttr('%s.radius' % (p))
</code></pre>
<p><strong>for setAttr :</strong></p>
<pre><code>for p in jointList:
cmd.setAttr('%s.radius' % (p),... | 2 | 2016-08-05T16:51:42Z | [
"python",
"maya",
"mel"
] |
setAttr of a list in maya python | 38,779,640 | <p>I'm still figuring out how Python and Maya work together so forgive ignorance on my part. So I'm trying to change the attributes of a list of joints in maya using a loop like so:</p>
<p><code>for p in jointList:
cmd.getAttr(p, 'radius', .5)</code></p>
<p>and I get this error:</p>
<p><code>Invalid argument 1,... | 0 | 2016-08-05T01:05:56Z | 39,084,531 | <pre><code># lets have a look on the valid/available attributes
# and change some attributes
# create list based on your selection
item_list = cmds.ls(selection=True)
for item in item_list:
# iterate all keyable and unlocked attributes
for key in cmds.listAttr(item, keyable = True, unlocked=True):
# g... | -1 | 2016-08-22T16:32:11Z | [
"python",
"maya",
"mel"
] |
setAttr of a list in maya python | 38,779,640 | <p>I'm still figuring out how Python and Maya work together so forgive ignorance on my part. So I'm trying to change the attributes of a list of joints in maya using a loop like so:</p>
<p><code>for p in jointList:
cmd.getAttr(p, 'radius', .5)</code></p>
<p>and I get this error:</p>
<p><code>Invalid argument 1,... | 0 | 2016-08-05T01:05:56Z | 40,136,254 | <p>Going from examples in the documentation:</p>
<blockquote>
<p><a href="http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/getAttr.html" rel="nofollow">http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/CommandsPython/getAttr.html</a></p>
<p><a href="http://help.autodesk.com/clo... | 0 | 2016-10-19T15:51:59Z | [
"python",
"maya",
"mel"
] |
Tensorflow doesn't like pandas dataframe? | 38,779,654 | <p>I was trying out tensorflow with the Titanic data from Kaggle:<a href="https://www.kaggle.com/c/titanic" rel="nofollow">https://www.kaggle.com/c/titanic</a></p>
<p>Here's the code I tried to implement from Sendex:<a href="https://www.youtube.com/watch?v=PwAGxqrXSCs&index=46&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P5... | 0 | 2016-08-05T01:08:49Z | 38,779,816 | <p>I think the error is on this line:</p>
<pre><code> hidden_layer_1 = {'weights': tf.Variable(tf.random_normal([8, n_nodes_hl1])),
'biases': tf.Variable(tf.random_normal(n_nodes_hl1))}
</code></pre>
<p>The <code>shape</code> argument to <code>tf.random_normal()</code> must be a 1-D vector (o... | 1 | 2016-08-05T01:36:59Z | [
"python",
"pandas",
"tensorflow"
] |
Comparison of collections containing non-reflexive elements | 38,779,705 | <p>In python, a value <code>x</code> is not always constrained to equal itself. Perhaps the best known example is <code>NaN</code>:</p>
<pre><code>>>> x = float("NaN")
>>> x == x
False
</code></pre>
<p>Now consider a list of exactly one item. We might consider two such lists to be <em>equal</em> i... | 8 | 2016-08-05T01:15:56Z | 38,779,764 | <p>Per <a href="https://docs.python.org/3/reference/expressions.html#value-comparisons" rel="nofollow">the docs</a>,</p>
<blockquote>
<p>In enforcing reflexivity of elements, <strong>the comparison of collections assumes that for a collection element x, x == x is always true</strong>. Based on that assumption, eleme... | 7 | 2016-08-05T01:27:31Z | [
"python"
] |
python list - convert to list of list | 38,779,723 | <p>I am hoping someone can point me in the right direction along with any documentation that can provide even more info than just the answer. Here we go, I have a list of strings:</p>
<pre><code>arr = ["abcd","abcdef","def","abcdef"]
</code></pre>
<p>I want to turn that list into a list of lists so that the new eleme... | 1 | 2016-08-05T01:19:23Z | 38,779,752 | <p><code>sorted(["abcd","abcdef","def","abcdef"], key=len)</code> will do the job.</p>
| 0 | 2016-08-05T01:25:36Z | [
"python",
"list",
"sorting",
"indexing"
] |
python list - convert to list of list | 38,779,723 | <p>I am hoping someone can point me in the right direction along with any documentation that can provide even more info than just the answer. Here we go, I have a list of strings:</p>
<pre><code>arr = ["abcd","abcdef","def","abcdef"]
</code></pre>
<p>I want to turn that list into a list of lists so that the new eleme... | 1 | 2016-08-05T01:19:23Z | 38,779,768 | <p>Simple and pythonic.</p>
<pre><code>[(v, lst[:i].count(v)+1) for i,v in enumerate(lst)]
</code></pre>
<p>where <code>lst</code> is your list.</p>
<pre><code>>>> lst = ["abcd","abcdef","def","abcdef"]
>>> [(v, lst[:i].count(v)+1) for i,v in enumerate(lst)]
[('abcd', 1), ('abcdef', 1), ('def', 1),... | -1 | 2016-08-05T01:29:09Z | [
"python",
"list",
"sorting",
"indexing"
] |
python list - convert to list of list | 38,779,723 | <p>I am hoping someone can point me in the right direction along with any documentation that can provide even more info than just the answer. Here we go, I have a list of strings:</p>
<pre><code>arr = ["abcd","abcdef","def","abcdef"]
</code></pre>
<p>I want to turn that list into a list of lists so that the new eleme... | 1 | 2016-08-05T01:19:23Z | 38,779,779 | <p>Try the following for loop:</p>
<pre><code>>>> arr = ["abcd","abcdef","def","abcdef"]
>>> counts = {}
>>> new = []
>>> for item in arr:
... if item not in counts:
... new.append((item, 1))
... counts[item] = 1
... else:
... counts[item]... | 4 | 2016-08-05T01:30:43Z | [
"python",
"list",
"sorting",
"indexing"
] |
python list - convert to list of list | 38,779,723 | <p>I am hoping someone can point me in the right direction along with any documentation that can provide even more info than just the answer. Here we go, I have a list of strings:</p>
<pre><code>arr = ["abcd","abcdef","def","abcdef"]
</code></pre>
<p>I want to turn that list into a list of lists so that the new eleme... | 1 | 2016-08-05T01:19:23Z | 38,779,841 | <p>this look like a job for <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow">Counter</a></p>
<pre><code>>>> from collections import Counter
>>> arr = ["abcd","abcdef","def","abcdef"]
>>> result = []
>>> current_count = Counter()
>>... | 0 | 2016-08-05T01:39:46Z | [
"python",
"list",
"sorting",
"indexing"
] |
python list - convert to list of list | 38,779,723 | <p>I am hoping someone can point me in the right direction along with any documentation that can provide even more info than just the answer. Here we go, I have a list of strings:</p>
<pre><code>arr = ["abcd","abcdef","def","abcdef"]
</code></pre>
<p>I want to turn that list into a list of lists so that the new eleme... | 1 | 2016-08-05T01:19:23Z | 38,779,875 | <p>Python's sort is stable, per <a href="https://docs.python.org/3.3/library/stdtypes.html?highlight=sort#list.sort" rel="nofollow">docs</a>:</p>
<blockquote>
<p>The sort() method is guaranteed to be stable. A sort is stable if it guarantees not to change the relative order of elements that compare equal</p>
</block... | 3 | 2016-08-05T01:43:47Z | [
"python",
"list",
"sorting",
"indexing"
] |
summation using List Comprehensions | 38,779,770 | <p>I am trying to perform a sum as following:</p>
<pre><code>list=[b_{i}{j}=SUMMATION(|d_{i}{j}| - |g_{j}{k}|)] or simply
list=[SUMMATION(|d_{i}{j}| - |g_{j}{k}|)]
</code></pre>
<p>for this using list comprehension I am trying following:</p>
<pre><code>d=Function ('d', IntSort(), IntSort(),RealSort())
g=Function ('... | 0 | 2016-08-05T01:29:31Z | 38,779,912 | <p>I think what you want is</p>
<pre><code>benefit=[[[(b(i) == b(i) + abs(d[i][j]) - abs(g[j][k])) for k in range(j) ] for j in range(i) ] for i in range(input) ]
</code></pre>
<p>You cannot iterate over an integer variable, i.e. running <code>f(k) for k in j</code> where j is an int is invalid. You must create an it... | 0 | 2016-08-05T01:51:06Z | [
"python",
"python-2.7",
"python-3.x",
"z3py"
] |
summation using List Comprehensions | 38,779,770 | <p>I am trying to perform a sum as following:</p>
<pre><code>list=[b_{i}{j}=SUMMATION(|d_{i}{j}| - |g_{j}{k}|)] or simply
list=[SUMMATION(|d_{i}{j}| - |g_{j}{k}|)]
</code></pre>
<p>for this using list comprehension I am trying following:</p>
<pre><code>d=Function ('d', IntSort(), IntSort(),RealSort())
g=Function ('... | 0 | 2016-08-05T01:29:31Z | 38,780,895 | <p>I'm not currently convinced your code is doing what you think it's doing. However, I'm not familiar with z3py, so I could be mistaken here.</p>
<p>First, take a look at this snippet.</p>
<pre><code>d=Function ('d', IntSort(), IntSort(),RealSort())
</code></pre>
<p>I assume <code>Function</code> is a callable defi... | 1 | 2016-08-05T04:01:16Z | [
"python",
"python-2.7",
"python-3.x",
"z3py"
] |
summation using List Comprehensions | 38,779,770 | <p>I am trying to perform a sum as following:</p>
<pre><code>list=[b_{i}{j}=SUMMATION(|d_{i}{j}| - |g_{j}{k}|)] or simply
list=[SUMMATION(|d_{i}{j}| - |g_{j}{k}|)]
</code></pre>
<p>for this using list comprehension I am trying following:</p>
<pre><code>d=Function ('d', IntSort(), IntSort(),RealSort())
g=Function ('... | 0 | 2016-08-05T01:29:31Z | 38,781,154 | <p>Anything you can do with a comprehension can also be done (using a few more lines) with nested loops. I can't tell quite what you're trying to accomplish, and also have a slight suspicion that what you actually want to do isn't best done with list comprehensions.</p>
<p>Can you re-write your <code>benefit = ...</co... | 0 | 2016-08-05T04:30:47Z | [
"python",
"python-2.7",
"python-3.x",
"z3py"
] |
Python Reportlab VerticalBarChart - add chart title | 38,779,796 | <p>I'm using VerticalBarChart from reportlab.graphics.charts.barcharts, and I can't find a documentation to simply add to a title to the chart's bottom. Please help! </p>
<pre><code>chart = VerticalBarChart()
</code></pre>
| 0 | 2016-08-05T01:33:25Z | 38,785,040 | <p>According to the user guide the axis title attribute is not implemented yet, so no there is no quick solution for this. </p>
<blockquote>
<p><strong>title</strong></p>
<p>Not Implemented Yet. This needs to be like a label, but also
lets you set the text directly. It would have a default
location below th... | 0 | 2016-08-05T08:48:13Z | [
"python",
"reportlab"
] |
Passing a "pointer to a virtual function" as argument in Python | 38,779,876 | <p>Compare the following code in <strong>C++</strong>:</p>
<pre><code>#include <iostream>
#include <vector>
struct A
{
virtual void bar(void) { std::cout << "one" << std::endl; }
};
struct B : public A
{
virtual void bar(void) { std::cout << "two" << std::endl; }
};
void test... | 11 | 2016-08-05T01:43:56Z | 38,780,044 | <p>The following produces the output you want:</p>
<pre><code>class A:
def bar(self):
print("one")
class B(A):
def bar(self):
print("two")
def test(objs, funcname):
noop = lambda: None
for o in objs:
getattr(o, funcname, noop)()
objs = [A(), B()]
test(objs, "bar")
</code></pr... | 4 | 2016-08-05T02:08:02Z | [
"python",
"c++",
"reference",
"virtual-functions",
"dispatch"
] |
Passing a "pointer to a virtual function" as argument in Python | 38,779,876 | <p>Compare the following code in <strong>C++</strong>:</p>
<pre><code>#include <iostream>
#include <vector>
struct A
{
virtual void bar(void) { std::cout << "one" << std::endl; }
};
struct B : public A
{
virtual void bar(void) { std::cout << "two" << std::endl; }
};
void test... | 11 | 2016-08-05T01:43:56Z | 38,780,855 | <p>Regarding your edit, one thing you could do is use a little wrapper lambda that calls the method you want to reference. This way the method call looks like "regular python code" instead of being something complicated based on string-based access.</p>
<p>In your example, the only part that would need to change is th... | 9 | 2016-08-05T03:56:17Z | [
"python",
"c++",
"reference",
"virtual-functions",
"dispatch"
] |
Random order of returned values in python dictionary | 38,779,921 | <p>I don't understand this and it's going to bother me until I do. </p>
<p>This python code counts the number of times each character appears in the 'message' variable: </p>
<pre><code>message = 'Some random string of words'
dictionary= {}
for character in message.upper():
dictionary.setdefault(character,0)
... | 1 | 2016-08-05T01:51:54Z | 38,779,940 | <p><code>dict</code>s are inherently unordered.</p>
<p>From the <a href="https://docs.python.org/2/library/stdtypes.html#dictionary-view-objects" rel="nofollow">Python docs</a>:</p>
<blockquote>
<p>Keys and values are iterated over in an arbitrary order which is non-random, varies across Python implementations, and... | 2 | 2016-08-05T01:54:32Z | [
"python"
] |
Random order of returned values in python dictionary | 38,779,921 | <p>I don't understand this and it's going to bother me until I do. </p>
<p>This python code counts the number of times each character appears in the 'message' variable: </p>
<pre><code>message = 'Some random string of words'
dictionary= {}
for character in message.upper():
dictionary.setdefault(character,0)
... | 1 | 2016-08-05T01:51:54Z | 38,780,037 | <p>The way that <code>dict</code> is implemented is designed for look ups to be quick and efficient. Even as the size of the <code>dict</code> increases. Under the hood this means that the key order may change. </p>
<p>If the order of the keys is important to you, try using an <code>ordereddict</code> from <code>coll... | 1 | 2016-08-05T02:06:49Z | [
"python"
] |
Random order of returned values in python dictionary | 38,779,921 | <p>I don't understand this and it's going to bother me until I do. </p>
<p>This python code counts the number of times each character appears in the 'message' variable: </p>
<pre><code>message = 'Some random string of words'
dictionary= {}
for character in message.upper():
dictionary.setdefault(character,0)
... | 1 | 2016-08-05T01:51:54Z | 38,780,069 | <p>Because of two things:</p>
<ul>
<li>Dictionaries "aren't ordered". You of course get <strong>some</strong> order, but it depends, among other things, on the hash values of the keys.</li>
<li>You use (single-character) strings as keys, and <strong>string hashes are randomized</strong>. If you do <code>print(hash(mes... | 3 | 2016-08-05T02:10:42Z | [
"python"
] |
Random order of returned values in python dictionary | 38,779,921 | <p>I don't understand this and it's going to bother me until I do. </p>
<p>This python code counts the number of times each character appears in the 'message' variable: </p>
<pre><code>message = 'Some random string of words'
dictionary= {}
for character in message.upper():
dictionary.setdefault(character,0)
... | 1 | 2016-08-05T01:51:54Z | 38,780,110 | <p>This happens due to security. When you're writing any application where external user can provide data which ends up in a dictionary, you need to make sure they don't know what the result of hashing will be. If they do, they can make sure that every new entry they provide will hash to the same bin. When they do that... | 2 | 2016-08-05T02:15:59Z | [
"python"
] |
How to make axis tick labels visible on the other side of the plot in gridspec? | 38,779,933 | <p>Plotting my favourite example dataframe,which looks like this:</p>
<pre><code> x val1 val2 val3
0 0.0 10.0 NaN NaN
1 0.5 10.5 NaN NaN
2 1.0 11.0 NaN NaN
3 1.5 11.5 NaN 11.60
4 2.0 12.0 NaN 12.08
5 2.5 12.5 12.2 12.56
6 3.0 13.0 19.8 13.04
7 3.5 13.... | 0 | 2016-08-05T01:53:22Z | 38,780,417 | <p>try something like</p>
<pre><code>axes2.yaxis.tick_right()
</code></pre>
<p>Just look around <a href="http://stackoverflow.com/questions/10354397/python-matplotlib-y-axis-labels-on-right-side-of-plot">Python Matplotlib Y-Axis Labels on Right Side of Plot</a>.</p>
| 2 | 2016-08-05T03:01:37Z | [
"python",
"matplotlib"
] |
How to make axis tick labels visible on the other side of the plot in gridspec? | 38,779,933 | <p>Plotting my favourite example dataframe,which looks like this:</p>
<pre><code> x val1 val2 val3
0 0.0 10.0 NaN NaN
1 0.5 10.5 NaN NaN
2 1.0 11.0 NaN NaN
3 1.5 11.5 NaN 11.60
4 2.0 12.0 NaN 12.08
5 2.5 12.5 12.2 12.56
6 3.0 13.0 19.8 13.04
7 3.5 13.... | 0 | 2016-08-05T01:53:22Z | 38,987,039 | <p>No, ok, found out it is precisely what I wanted.
I want the TICKS to be on BOTH sides, just the LABELS to be on the right. The solution above removes my ticks from the left side of the subplot, which doesn't look good. However, this <a href="http://stackoverflow.com/a/20481365/5553319">answer</a> seems to get the r... | 0 | 2016-08-17T02:04:19Z | [
"python",
"matplotlib"
] |
Collection comparison is reflexive, yet does not short circuit. Why? | 38,779,970 | <p>In python, the built in collections compare elements with the explicit assumption that they are reflexive:</p>
<blockquote>
<p>In enforcing reflexivity of elements, <strong>the comparison of collections assumes that for a collection element x, x == x is always true</strong>. Based on that assumption, element iden... | 6 | 2016-08-05T01:59:20Z | 38,780,091 | <p>While I'm not privy to the developers' thinking, my guess is that they might have felt comparing <code>L == L</code> does not happen often enough to warrant a special check, and moreover, the user can always use <code>(L is L) or (L==L)</code> to build a
short-circuiting check himself if he deems that advantageous.<... | 2 | 2016-08-05T02:13:58Z | [
"python"
] |
XML parsing issue in Python using xml.etree or Dom API | 38,780,126 | <p>I have following simple code that is parsing a XML file.
The issue is if in XML file the name space contains ":" i get an error. Not having it, no issue. It happens when i have ":" between "Junos and Style" when i remove the ":" from XML it works perfectly.
Please advise.</p>
<p><strong>Fail with this:</strong></... | 1 | 2016-08-05T02:19:02Z | 38,781,070 | <p>Just found what the issue is.</p>
<p>I had to define xmlns:junos in XML.</p>
<p></p>
<p>Don't know why but somehow i had omitted this line in my XML. I think it happened while i was copy pasting the XML.</p>
<p>Thanks for reply.</p>
| 1 | 2016-08-05T04:21:54Z | [
"python",
"xml"
] |
XML parsing issue in Python using xml.etree or Dom API | 38,780,126 | <p>I have following simple code that is parsing a XML file.
The issue is if in XML file the name space contains ":" i get an error. Not having it, no issue. It happens when i have ":" between "Junos and Style" when i remove the ":" from XML it works perfectly.
Please advise.</p>
<p><strong>Fail with this:</strong></... | 1 | 2016-08-05T02:19:02Z | 38,783,181 | <p>Adding the definition for <strong><em>junos</em></strong> apparently resolves the parsing issue.</p>
<pre><code><rpc-reply xmlns:junos="http://xml.juniper.net/junos/12.1X47/junos">
</code></pre>
<p>I have used the following working sample for <a href="http://pastebin.com/peJVU6Zj" rel="nofollow">reference</a... | 0 | 2016-08-05T07:06:35Z | [
"python",
"xml"
] |
Not getting video from cv2.VideoCapture from Parrot AR Drone | 38,780,140 | <p>I am not getting video from <code>cv2.VideoCapture</code> from Parrot AR Drone: <code>ret</code> is always <code>False</code></p>
<pre><code>import numpy as np
import cv2
cap = cv2.VideoCapture("tcp://192.168.1.1:5555")
ret, frame = cap.read()
print ret
cap.release()
cv2.destroyAllWindows()
</code></pre>
| 0 | 2016-08-05T02:21:00Z | 38,780,350 | <pre><code>I am not used to Python, but If it was in Windows I will first check whether cap is getting frames from the given IP Address using:
if(!cap.IsOpened())
{
cerr <<"No video Frames were read, please check your IP and Port" <<endl;
return -1;
}
This will easily help me know whether I am fetching fr... | 0 | 2016-08-05T02:51:00Z | [
"python",
"opencv",
"ar.drone"
] |
OpenSSL.crypto.X509.sign() throws " 'bytes' object has no attribute 'encode' " | 38,780,150 | <p>So I'm trying to use the OpenSSL crypto module to generate a new CA certificate with this code:</p>
<pre><code>#warning: this block is background information, probably not
#where my real problem is
#generate the key pair
key=OpenSSL.crypto.PKey()
key.generate_key(OpenSSL.crypto.TYPE_RSA,2048)
#print the private ... | 1 | 2016-08-05T02:22:27Z | 38,885,306 | <p>It turns out that my IDE (PyCharm) was leading me astray. <code>ca.sign(key, 'sha1')</code> is really the correct way to do it. Even though PyCharm gives a type error program execution flows right through the statement and the output is correct.</p>
| 0 | 2016-08-10T23:54:16Z | [
"python",
"python-3.x",
"pyopenssl"
] |
How to use a dict for resampling a multindex pandas data frame? (>0.18.0) | 38,780,181 | <p>Before pandas 0.18.0 I used to be able to do resample my deeply pivoted table like so:</p>
<pre><code>pivot_df = SoilSensorDf.pivot(status_df, ['A', 'B', 'C'])
resample_methods = map({'A': 'sum',
'B': 'mean',
'C': 'min'}.get,
[x[0] for x in pivot_d... | 1 | 2016-08-05T02:27:41Z | 38,794,088 | <p>Looks like this is a bug that will be worked on by the pandas team:
<a href="https://github.com/pydata/pandas/issues/13914" rel="nofollow">https://github.com/pydata/pandas/issues/13914</a></p>
| 0 | 2016-08-05T16:40:46Z | [
"python",
"python-2.7",
"pandas",
"pivot-table"
] |
Vanilla Django Query to show 'flattened' User/Group (ManyToMany) Listing | 38,780,190 | <p>I'm trying to write a simple Django query to show all users in all groups within the vanilla django.contrib.auth models:</p>
<pre><code>User.username | Group.name
------------- | -----------
user1 | groupA
user1 | groupB
user2 | groupA
user2 | groupC
user3 | groupA
</code></p... | 0 | 2016-08-05T02:28:51Z | 38,780,279 | <p>This will get you a list of all users in all groups:</p>
<pre><code>from django.contrib.auth.models import Group
for group in Group.objects.all():
for user in group.user_set.all():
print '%s\t%s' % (user.username, group.name)
</code></pre>
<p>You can also get the same information in one single query w... | 1 | 2016-08-05T02:41:33Z | [
"python",
"django"
] |
Vanilla Django Query to show 'flattened' User/Group (ManyToMany) Listing | 38,780,190 | <p>I'm trying to write a simple Django query to show all users in all groups within the vanilla django.contrib.auth models:</p>
<pre><code>User.username | Group.name
------------- | -----------
user1 | groupA
user1 | groupB
user2 | groupA
user2 | groupC
user3 | groupA
</code></p... | 0 | 2016-08-05T02:28:51Z | 38,780,451 | <p>For what it's worth, I also found that:</p>
<pre><code>from django.contrib.auth.models import User, Group
qs = User.objects.raw("""select *, g.name as groupname
from auth_user_groups ug
inner join auth_user u on ug.user_id = u.id
inner... | 0 | 2016-08-05T03:05:17Z | [
"python",
"django"
] |
Can a LP created on a Windows platform be run on a Linux platform? | 38,780,223 | <p>I have a huge MILP in Matlab, which I want to re-program in Gurobi using python language, on a Windows desktop. But after that I want to run it on a super computer which has a Linux os. I know python is cross-platform. Does this mean anything I create in Gurobi on Windows will run on Linux too? If this question is d... | 1 | 2016-08-05T02:33:54Z | 38,780,526 | <p>Yes, you can write Gurobi Python code on one system, then copy it and run it on another. You can go from Windows to Linux, Mac to Windows, etc. Alternately, if you have Gurobi Compute Server, your Windows computer can be a client of your Linux server.</p>
| 0 | 2016-08-05T03:16:07Z | [
"python",
"linux",
"windows",
"matlab",
"gurobi"
] |
Can a LP created on a Windows platform be run on a Linux platform? | 38,780,223 | <p>I have a huge MILP in Matlab, which I want to re-program in Gurobi using python language, on a Windows desktop. But after that I want to run it on a super computer which has a Linux os. I know python is cross-platform. Does this mean anything I create in Gurobi on Windows will run on Linux too? If this question is d... | 1 | 2016-08-05T02:33:54Z | 38,789,742 | <p>You could also export the MILP from Matlab as a <a href="https://en.wikipedia.org/wiki/MPS_(format)" rel="nofollow">mps</a> file, using e.g. the <a href="https://www.mathworks.com/matlabcentral/fileexchange/19618-mps-format-exporting-tool" rel="nofollow">MPS format exporting tool</a> and then load the file to Gurobi... | 0 | 2016-08-05T12:53:33Z | [
"python",
"linux",
"windows",
"matlab",
"gurobi"
] |
I typed python -v in my terminal and something weird happened | 38,780,240 | <p>Thinking I was about to check the version of Python installed on my computer, I typed </p>
<pre><code>python -v
</code></pre>
<p>in my terminal and I got a first line saying </p>
<blockquote>
<p>"installing zipimport hook", but then also a whole bunch of text (probably 50 or so lines of text), among which "imp... | 0 | 2016-08-05T02:35:44Z | 38,780,265 | <p>You want <code>python -V</code> (uppercase) or <code>python --version</code>. The lowercase <code>-v</code> means âverboseâ and adds a bunch of diagnostic information to the output that you can safely ignore.</p>
| 5 | 2016-08-05T02:39:13Z | [
"python",
"terminal"
] |
Improving Python Threads Performance based on Resource Locking | 38,780,252 | <p>The reason between Java and Python threads is </p>
<ul>
<li>Java is designed to lock on the resources</li>
<li>Python is designed to lock the thread itself(GIL)</li>
</ul>
<p>So Python's implementation performs better on a machine with singe core processor. This is fine 10-20 years before. With the increasing comp... | 0 | 2016-08-05T02:37:26Z | 38,780,573 | <p>I think the most straight way for you, that will give you also a nice performance increase is to use Cython. </p>
<p>Cython is a Python superset that compiles Python-like code to C code (which makes use of the cPython API), and from there to executable. It allows one to optionally type variables, that then can use ... | 1 | 2016-08-05T03:22:45Z | [
"python",
"multithreading"
] |
max of two dates comes in a totally different format | 38,780,269 | <p>I have 2 columns with dates in them, i want to create a 3rd column with the max of these 2 dates:</p>
<pre><code>df['xxx_MaxSettDate'][0]
Out[186]: Timestamp('2017-01-20 00:00:00')
df['yyy_MaxSettDate'][0]
Out[166]: NaT
</code></pre>
<p>here is my max function:</p>
<pre><code> df['MaxSettDate']=df[['xxx_MaxSettDa... | 0 | 2016-08-05T02:39:48Z | 38,780,347 | <p>UPDATE:</p>
<p>you can convert your <code>MaxSettDate</code> column to datetime first:</p>
<pre><code>df['MaxSettDate'] = pd.to_datetime(df['MaxSettDate'])
</code></pre>
<p>Demo:</p>
<pre><code>In [41]: pd.to_datetime(1.4848704e+18)
Out[41]: Timestamp('2017-01-20 00:00:00')
</code></pre>
<p>OLD amswer:</p>
<p>... | 1 | 2016-08-05T02:50:42Z | [
"python",
"datetime",
"pandas"
] |
Predicting new data using sklearn after standardizing the training data | 38,780,302 | <p>I am using Sklearn to build a linear regression model (or any other model) with the following steps:</p>
<p>X_train and Y_train are the training data</p>
<ol>
<li><p>Standardize the training data</p>
<pre><code> X_train = preprocessing.scale(X_train)
</code></pre></li>
<li><p>fit the model</p>
<pre><code> model... | 1 | 2016-08-05T02:43:43Z | 38,782,801 | <p>Take a look at <a href="http://scikit-learn.org/stable/modules/preprocessing.html" rel="nofollow">these docs</a>. </p>
<p>You can use the <code>StandardScaler</code> class of the preprocessing module to remember the scaling of your training data so you can apply it to future values.</p>
<pre><code>from sklearn.pre... | 3 | 2016-08-05T06:44:34Z | [
"python",
"machine-learning",
"scikit-learn"
] |
Python3 src encodings of Emojis | 38,780,324 | <p><strong>I'd like to print emojis from python(3) src</strong></p>
<p>I'm working on a project that analyzes <a href="https://www.facebook.com/help/131112897028467/" rel="nofollow">Facebook Message histories</a> and in the raw htm data file downloaded I find a lot of emojis are displayed as boxes with question marks,... | 4 | 2016-08-05T02:47:44Z | 38,782,246 | <p>This has nothing to do with Python. An escape like <code>\U000fe328</code> just contains the hexadecimal representation of a code point, so this one is <code>U+0FE328</code> (which is a private use character).</p>
<p>These days a lot of emoji are assigned to code points, eg. í ½í¸¤ is <code>U+01F624 â FACE WITH L... | 2 | 2016-08-05T06:08:48Z | [
"python",
"string",
"unicode",
"encoding"
] |
What state_union class is used for | 38,780,440 | <p>Could anyone tell me what is this class' return type and what are its public methods and its general application? Or point me to the place I can read on it? Couldn't find it in <a href="http://www.nltk.org/" rel="nofollow">http://www.nltk.org/</a> docs at all! While other classes, like <code>PunktSentenceTokenizer</... | 0 | 2016-08-05T03:03:49Z | 38,780,495 | <p>In a python console exec: </p>
<pre><code>import nltk
help(nltk)
help(nltk.PunktSentenceTokenizer)
</code></pre>
| 0 | 2016-08-05T03:13:06Z | [
"python",
"nltk"
] |
How to use pandas read_excel() for excel file with multi sheets? | 38,780,485 | <p>I have one excel file with many sheets. There is only one column in every sheet, which is column A. I plan to read the excel file with <code>read_excel()</code> method. Hier is the code:</p>
<pre><code>import pandas as PD
ExcelFile = "C:\\AAA.xlsx"
SheetNames = ['0', '1', 'S', 'B', 'U']
# There are five sheets i... | 0 | 2016-08-05T03:10:38Z | 38,780,512 | <p>Referring to the answer here:
<a href="http://stackoverflow.com/questions/26521266/using-pandas-to-pd-read-excel-for-multiple-worksheets-of-the-same-workbook">Using Pandas to pd.read_excel() for multiple worksheets of the same workbook</a></p>
<p>Perhaps you can try this:</p>
<pre><code>import pandas as pd
xls = p... | 0 | 2016-08-05T03:14:44Z | [
"python",
"pandas"
] |
How to use pandas read_excel() for excel file with multi sheets? | 38,780,485 | <p>I have one excel file with many sheets. There is only one column in every sheet, which is column A. I plan to read the excel file with <code>read_excel()</code> method. Hier is the code:</p>
<pre><code>import pandas as PD
ExcelFile = "C:\\AAA.xlsx"
SheetNames = ['0', '1', 'S', 'B', 'U']
# There are five sheets i... | 0 | 2016-08-05T03:10:38Z | 38,781,007 | <p>Why are you using <code>sheetname=str(SheetNames[Page])</code>?</p>
<p>If I understand your question properly I think what you want is:</p>
<pre><code>import pandas as PD
excel_file = r"C:\\AAA.xlsx"
sheet_names = ['0', '1', 'S', 'B', 'U']
for sheet_name in sheet_names:
df = pd.read_excel(excel_file, heade... | 0 | 2016-08-05T04:14:59Z | [
"python",
"pandas"
] |
Using the python sh module, how can I show the output of a command as it's happening? | 38,780,563 | <p>The python <code>sh</code> module seem to wait until a command or at least a line is finished before it can show any of the output. How can I show the output of a command as it's happening? </p>
<p>Here's what I've tried so far. This is for git cloning something using <code>sh</code>. </p>
<pre><code>for line in s... | 0 | 2016-08-05T03:21:07Z | 38,780,923 | <p>Use the <code>_out_bufsize</code> parameter.
In my case, works OK with 100...</p>
<pre><code>for line in sh.git.clone(url, '--progress', '--recursive', _err_to_out=True, _iter=True, _out_bufsize=100):
print(line)
</code></pre>
<p><strong>Output:</strong></p>
<blockquote>
<p>Cloning into 'some_project'...<br... | 3 | 2016-08-05T04:04:41Z | [
"python"
] |
Matplotlib: how to update the figure title after user has zoomed? | 38,780,641 | <p>Is there any way to <strong>update the title</strong> of a Matplotlib figure after the user has zoomed in? For example, I would like the title to display the exact extends of the x-axis,</p>
<pre><code>import pylab as pl
import numpy as np
x = np.arange(10,step=0.1)
y = np.sin(x)
f = pl.figure()
pl.plot(x,y)
def... | 1 | 2016-08-05T03:30:28Z | 38,780,707 | <p>You can register callback functions on the <code>xlim_changed</code> and <code>ylim_changed</code> events. Try something like this:</p>
<pre><code>def on_xylims_change(axes):
x1,x2 = f.gca().get_xlim() # FIXME value hasn't been updated yet
pl.title("x = [%f, %f]" % (x1,x2))
fig, ax = pl.subplots(1, 1)
ax.callb... | 1 | 2016-08-05T03:39:40Z | [
"python",
"matplotlib"
] |
How can I git clone a repository with python, and get the progress of the clone process? | 38,780,693 | <p>I'd like to be able to git clone a large repository using python, using some library, but importantly I'd like to be able to see the progress of the clone as it's happening. I tried pygit2 and GitPython, but they don't seem to show their progress. Is there another way? </p>
| 0 | 2016-08-05T03:37:54Z | 38,780,917 | <p>You can use <a href="http://gitpython.readthedocs.io/en/stable/reference.html#git.remote.RemoteProgress" rel="nofollow"><code>RemoteProgress</code></a> from <a href="http://gitpython.readthedocs.io/en/stable/" rel="nofollow">GitPython</a>. Here is a crude example:</p>
<pre><code>import git
class Progress(git.remot... | 0 | 2016-08-05T04:03:44Z | [
"python",
"git"
] |
Tkinter Scrollbar not working | 38,780,724 | <p>I have a piece of tkinter code running on python 3.4 that is a large frame placed in a canvas with a vertical scrollbar, however the scrollbar is grayed out and doesn't seem to be linked to the size of the frame. The code I'm using is essentially:</p>
<pre><code>class EntryWindow:
def __init__(self, master):
... | 0 | 2016-08-05T03:41:53Z | 38,788,177 | <p>You must do three things when configuring a scrolling canvas:</p>
<ol>
<li>have the canvas notify the scrollbar when it scrolls, by configuring the <code>yscrollcommand</code> attribute of the canvas to point to the scrollbar</li>
<li>have the scrollbar control the canvas when it is dragged, by configuring the <cod... | 2 | 2016-08-05T11:29:20Z | [
"python",
"python-3.x",
"tkinter",
"tk",
"tkinter-canvas"
] |
How to create a list from a text file in Python | 38,780,764 | <p>I have a text file called "test", and I would like to create a list in Python and print it. I have the following code, but it does not print a list of words; it prints the whole document in one line.</p>
<pre><code>file = open("test", 'r')
lines = file.readlines()
my_list = [line.split(' , ')for line in open ("tes... | 0 | 2016-08-05T03:46:12Z | 38,780,845 | <p>You could do </p>
<pre><code>my_list = open("filename.txt").readlines()
</code></pre>
| 1 | 2016-08-05T03:55:15Z | [
"python",
"python-3.x"
] |
How to create a list from a text file in Python | 38,780,764 | <p>I have a text file called "test", and I would like to create a list in Python and print it. I have the following code, but it does not print a list of words; it prints the whole document in one line.</p>
<pre><code>file = open("test", 'r')
lines = file.readlines()
my_list = [line.split(' , ')for line in open ("tes... | 0 | 2016-08-05T03:46:12Z | 38,780,865 | <p>When you do this:</p>
<pre><code>file = open("test", 'r')
lines = file.readlines()
</code></pre>
<p>Lines is a list of lines. If you want to get a list of words for each line you can do:</p>
<pre><code>list_word = []
for l in lines:
list_word.append(l.split(" "))
</code></pre>
| 1 | 2016-08-05T03:57:36Z | [
"python",
"python-3.x"
] |
How to create a list from a text file in Python | 38,780,764 | <p>I have a text file called "test", and I would like to create a list in Python and print it. I have the following code, but it does not print a list of words; it prints the whole document in one line.</p>
<pre><code>file = open("test", 'r')
lines = file.readlines()
my_list = [line.split(' , ')for line in open ("tes... | 0 | 2016-08-05T03:46:12Z | 38,780,886 | <p>I believe you are trying to achieve something like this:</p>
<pre><code>data = [word.split(',') for word in open("test", 'r').readlines()]
</code></pre>
<p>It would also help if you were to specify what type of text file you are trying to read as there are several modules(i.e. csv) that would produce the result in... | 2 | 2016-08-05T04:00:14Z | [
"python",
"python-3.x"
] |
Iterate a tuple with dict inside | 38,780,801 | <p>Having trouble iterating over tuples such as this:</p>
<pre><code>t = ('a','b',{'c':'d'})
for a,b,c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 3, got 1)
for a,b,*c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 2, got 1)
for a,b,**c in t:
print (a,b... | 0 | 2016-08-05T03:50:24Z | 38,780,824 | <p>You'd need to put <code>t</code> inside some other iterable container:</p>
<pre><code>for a, b, c in [t]:
print(a, b, c)
</code></pre>
<p>The problem with your attempts is that each on is iterating over a single element from <code>t</code> and trying to unpack that. e.g. the first turn of the loop is trying t... | 2 | 2016-08-05T03:53:25Z | [
"python",
"python-3.x",
"python-3.4"
] |
Iterate a tuple with dict inside | 38,780,801 | <p>Having trouble iterating over tuples such as this:</p>
<pre><code>t = ('a','b',{'c':'d'})
for a,b,c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 3, got 1)
for a,b,*c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 2, got 1)
for a,b,**c in t:
print (a,b... | 0 | 2016-08-05T03:50:24Z | 38,780,826 | <p>Try this:</p>
<pre><code>for a,b,c in [t]:
print(a,b,c)
</code></pre>
<p>Putting <code>t</code> inside a list will allow you to unpack it.</p>
| 1 | 2016-08-05T03:53:37Z | [
"python",
"python-3.x",
"python-3.4"
] |
Iterate a tuple with dict inside | 38,780,801 | <p>Having trouble iterating over tuples such as this:</p>
<pre><code>t = ('a','b',{'c':'d'})
for a,b,c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 3, got 1)
for a,b,*c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 2, got 1)
for a,b,**c in t:
print (a,b... | 0 | 2016-08-05T03:50:24Z | 38,780,831 | <p>try this</p>
<pre><code>for x in t:
print(x)
</code></pre>
<p><code>x</code> will take all the values in <code>t</code> iteratively, so <code>'a'</code>, then <code>'b'</code> and finally <code>{'c':'d'}</code>.</p>
<p>And to print exactly <code>a = 'a'</code> etc you can do:</p>
<pre><code>for param, val in... | 0 | 2016-08-05T03:54:07Z | [
"python",
"python-3.x",
"python-3.4"
] |
Iterate a tuple with dict inside | 38,780,801 | <p>Having trouble iterating over tuples such as this:</p>
<pre><code>t = ('a','b',{'c':'d'})
for a,b,c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 3, got 1)
for a,b,*c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 2, got 1)
for a,b,**c in t:
print (a,b... | 0 | 2016-08-05T03:50:24Z | 38,780,862 | <p>Why are you iterating at all when it's a single <code>tuple</code>? Just unpack the single <code>tuple</code>, if that's what you need to do:</p>
<pre><code>a, b, c = t
print(a, b, c)
</code></pre>
<p>Or if it's just printing you want to do unpack in the call itself:</p>
<pre><code>print(*t)
</code></pre>
| 2 | 2016-08-05T03:56:46Z | [
"python",
"python-3.x",
"python-3.4"
] |
Iterate a tuple with dict inside | 38,780,801 | <p>Having trouble iterating over tuples such as this:</p>
<pre><code>t = ('a','b',{'c':'d'})
for a,b,c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 3, got 1)
for a,b,*c in t:
print(a,b,c) # ValueError: not enough values to unpack (expected 2, got 1)
for a,b,**c in t:
print (a,b... | 0 | 2016-08-05T03:50:24Z | 38,780,866 | <p>You can use tuple unpacking with multiple assignment:</p>
<pre><code>a, b, c = t
print(a, b, c)
</code></pre>
| 0 | 2016-08-05T03:57:38Z | [
"python",
"python-3.x",
"python-3.4"
] |
regex to set the group length in python | 38,780,964 | <p>I have a version 'major.minor.patch'<br>
major version range <code>[0-99999]</code><br>
minor version range <code>[0-9999]</code><br>
patch version range <code>[0-999999]</code><br>
but on the whole 'major.minor.path' should not exceed 16 characters including . (dot).
I have tried the following reg expression </p>
... | 2 | 2016-08-05T04:09:25Z | 38,781,230 | <p>Add a lookahead at the beginning that allows a match only if its within 1-16 range by using a <code>$</code> to anchor at the end: <code>(?=^.{1,16}$)</code></p>
| 1 | 2016-08-05T04:38:02Z | [
"python",
"regex"
] |
regex to set the group length in python | 38,780,964 | <p>I have a version 'major.minor.patch'<br>
major version range <code>[0-99999]</code><br>
minor version range <code>[0-9999]</code><br>
patch version range <code>[0-999999]</code><br>
but on the whole 'major.minor.path' should not exceed 16 characters including . (dot).
I have tried the following reg expression </p>
... | 2 | 2016-08-05T04:09:25Z | 38,781,235 | <p>You have two regular expressions here that you want to combine</p>
<ol>
<li><code>^[\d.]{,16}$</code> </li>
<li><code>^\d{1,5}[.]\d{1,4}[.]\d{1,6}$</code></li>
</ol>
<p>Both in itself is invalid as (1) can match more than 2 dots and the individual length limits on each version are not honoured. (2) definitely does... | 1 | 2016-08-05T04:39:06Z | [
"python",
"regex"
] |
Why is my .pythonrc file being run in non-interactive programs? | 38,781,067 | <p>Context: I started using OSX about a year ago, and I had a kind of screwy python installation. That is, I was using system python, and installed packages with sudo when that seemed to make things work. Now, I'm starting from a fresh OSX install, and trying to do it the Right Way. I've installed python and python3 fr... | 0 | 2016-08-05T04:20:54Z | 38,814,182 | <p>You can ask the traceback module:</p>
<pre><code>$ cat .pythonrc
import traceback; traceback.print_stack()
$ cat test.py
import ipdb
</code></pre>
<p>Then by running</p>
<pre><code>$ PYTHONSTARTUP="$HOME/.pythonrc" python test.py
</code></pre>
<p>you should get a traceback that tells you exactly from where the... | 1 | 2016-08-07T12:34:04Z | [
"python",
"osx",
"ipython",
"homebrew"
] |
Tensorflow softmax function returning one-hot encoded array | 38,781,155 | <p>I have this piece of code which computes the softmax function on the output predictions from my convnet. </p>
<pre><code>pred = conv_net(x, weights, biases, keep_prob, batchSize)
softmax = tf.nn.softmax(pred)
</code></pre>
<p>My prediction array is of shape [batch_size, number_of_classes] = [128,6]
An example ro... | 0 | 2016-08-05T04:30:49Z | 38,794,752 | <p>You have a serious need for some regularization. Your outputs are on the order of 10^8. Usually, we deal with much smaller numbers. If you add more regularization your classifier won't be so certain about everything and it won't give outputs that look like one-hot encodings.</p>
| 0 | 2016-08-05T17:22:14Z | [
"python",
"machine-learning",
"tensorflow",
"deep-learning",
"softmax"
] |
fill in missing fields using import csv | 38,781,211 | <p>My data set looks like the below:</p>
<pre><code>W000000457,,
,9/18/2016 11:28,37
,4/21/2016 0:07,54
,11/5/2016 12:05,42
,7/14/2016 15:43,54
W000000457 - Count,,100
2069320,,
,12/10/2016 0:22,12
,9/25/2016 14:07,28
,1/24/2016 6:54,59
2069320 - Count,,100
111,,
,1/16/2016 10:25,58
,6/11/2016 4:17,43
,4/21/2016 7:56,... | 0 | 2016-08-05T04:36:11Z | 38,781,431 | <p>With csv type data, use <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a>.</p>
<p>Reading the data:</p>
<pre><code>import pandas as pd
from io import StringIO
df = pd.read_csv(StringIO('''W000000457,,
,9/18/2016 11:28,37
,4/21/2016 0:07,54
,11/5/2016 12:05,42
,7/14/2016 15:43,54
W000000457 - Count,,10... | 1 | 2016-08-05T04:59:19Z | [
"python"
] |
Is it possible to increase the depth of the sphinx search page? | 38,781,268 | <p><img src="http://i.stack.imgur.com/gntPs.png" alt="Sphinx search page"></p>
<p>The above image is the search feature of the Sphinx documentation generator. </p>
<p>As you can see in the image, the search page doesn't show the 'objects' under <code>Definitions</code> and <code>Orders</code>. Is there a setting whic... | 0 | 2016-08-05T04:43:16Z | 38,819,575 | <p>I assume with <code>objects</code> you refer to a snippet of the article's text that contains the search hit (<a href="http://www.sphinx-doc.org/en/stable/search.html?q=text&check_keywords=yes&area=default" rel="nofollow">example</a>). Let's call it a <em>search summary</em>.</p>
<p>1) The length of the sum... | 1 | 2016-08-07T23:41:26Z | [
"python",
"documentation",
"python-sphinx"
] |
Pro-Football-Reference Team Stats XPath | 38,781,357 | <p>I am using the scrapy shell on this page <a href="http://www.pro-football-reference.com/boxscores/201509100nwe.htm" rel="nofollow">Pittsburgh Steelers at New England Patriots - September 10th, 2015</a> to pull individual team stats. For example, I want to pull total yards for the away team (464) which, when inspect... | 0 | 2016-08-05T04:52:29Z | 38,781,659 | <p>The problem you encounter is (as in most of cases like this) that the website uses JavaScript to render the complete information of the game. This means that Scrapy does not see the website as you see it when you open it in your browser.</p>
<p>Because Scrapy does not run any JavaScript after loading the page it do... | 1 | 2016-08-05T05:24:59Z | [
"python",
"xpath",
"scrapy"
] |
Trouble with Django urls | 38,781,389 | <p>I'm new to Django and using version 1.9.8. I followed the official tutorial, and now I'm trying <a href="https://thinkster.io/django-angularjs-tutorial#registering-new-users" rel="nofollow">this</a> more advanced one. I'm at the end/checkpoint of the "registering users" section. When I visit <code>http://localhost:8... | 0 | 2016-08-05T04:56:10Z | 38,782,639 | <pre><code>url('^.*$', IndexView.as_view(), name='index'),
</code></pre>
<p><code>.*</code> in <code>'^.*$'</code>, tells any url will go to this IndexView</p>
<p>and</p>
<p>you did'nt add url for your register page in url.py</p>
<pre><code>url(r'^register/',views.yourview,name='givenameforthisurl')
</code></pre>
| 1 | 2016-08-05T06:35:19Z | [
"python",
"django",
"django-views",
"django-urls"
] |
How to count the most frequent character from various strings inputted inside a while loop? | 38,781,400 | <p>I have to write a code that finds the most frequent letter/character used (including special characters like . , / ), while allowing the user to keep inputting new inputs until he/she enters a "!". I wrote the following, but it only counts the most frequent letter in the last string inputted. Does anyone know how I ... | 0 | 2016-08-05T04:57:04Z | 38,781,454 | <p>Use the print statement inside the <code>while</code> loop.</p>
<pre><code>while w.count != 2:
w = input("Enter here: ")
w.count("!")
max_letter = w[0]
min_letter = w[0]
max = w.count(w[0])
min = w.count(w[0])
for char in w:
if char is not " ":
if w.count(char... | 1 | 2016-08-05T05:01:39Z | [
"python",
"python-3.x"
] |
global name 'reqparse' is not defined | 38,781,416 | <p>I am trying to develop an API in python to create user. Below is my code.</p>
<pre><code> from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class CreateUser(Resource):
def post(self):
try:
# Parse the arguments
... | 0 | 2016-08-05T04:58:25Z | 38,787,368 | <p>You will want to instantiate your parser and add the arguments before your request handler. I mean move</p>
<pre><code># Parse the arguments
parser = reqparse.RequestParser()
parser.add_argument('email', type=str, help='Email address to create user')
parser.add_argument('password', type=str, help='Password to... | 0 | 2016-08-05T10:47:27Z | [
"python",
"api",
"rest"
] |
global name 'reqparse' is not defined | 38,781,416 | <p>I am trying to develop an API in python to create user. Below is my code.</p>
<pre><code> from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class CreateUser(Resource):
def post(self):
try:
# Parse the arguments
... | 0 | 2016-08-05T04:58:25Z | 38,792,127 | <p>As said in the comments of your post, you need to import reqparse:</p>
<pre><code>from flask_restful import Resource, Api, reqparse
</code></pre>
<p>And for your other problem of null received, you need to be careful to the case.
If you send: <code>{ "Email" : "abc@xyz.com" , "Password" : "abc" }</code>, your pyth... | 0 | 2016-08-05T14:50:04Z | [
"python",
"api",
"rest"
] |
Calculating Fibonacci numbers in Python | 38,781,423 | <p>While doing <a href="http://www.mathblog.dk/project-euler-25-fibonacci-sequence-1000-digits/" rel="nofollow">Project Euler Problem 25</a>, I came across various techniques to compute the nth Fibonacci number. Memoization seemed to be the fastest amongst them all, and intuitively, I expected memoization to be faster ... | 3 | 2016-08-05T04:58:52Z | 38,781,474 | <p>Developing on thesonyman101: <code>my_list[i]</code> gives you immediate access to the element while <code>my_dict[key]</code> requires to compute the hash function and checking for collisions before looking what's in the bucket. Also your memoization sets up some potentially deep recursion stack which has some cost... | 0 | 2016-08-05T05:04:21Z | [
"python",
"python-2.7",
"fibonacci",
"series",
"memoization"
] |
Calculating Fibonacci numbers in Python | 38,781,423 | <p>While doing <a href="http://www.mathblog.dk/project-euler-25-fibonacci-sequence-1000-digits/" rel="nofollow">Project Euler Problem 25</a>, I came across various techniques to compute the nth Fibonacci number. Memoization seemed to be the fastest amongst them all, and intuitively, I expected memoization to be faster ... | 3 | 2016-08-05T04:58:52Z | 38,781,486 | <p>take a look at this <a href="http://stackoverflow.com/questions/360748/computational-complexity-of-fibonacci-sequence">stackoverflow question</a>.</p>
<p>as you can see, the complexity of fibonacci algorithm(with recursion) comes out to be approximately O(2^n).</p>
<p>while for the <code>fib3</code> it'll be O(n).... | -2 | 2016-08-05T05:05:54Z | [
"python",
"python-2.7",
"fibonacci",
"series",
"memoization"
] |
Calculating Fibonacci numbers in Python | 38,781,423 | <p>While doing <a href="http://www.mathblog.dk/project-euler-25-fibonacci-sequence-1000-digits/" rel="nofollow">Project Euler Problem 25</a>, I came across various techniques to compute the nth Fibonacci number. Memoization seemed to be the fastest amongst them all, and intuitively, I expected memoization to be faster ... | 3 | 2016-08-05T04:58:52Z | 38,781,578 | <p>You are using recursion in fib4 function. Which is exponential in terms of time complexity</p>
<p>EDIT after some one said memorize makes fib4 linear:
Except it does not. </p>
<p>The memorize thing works to reduce calculation time for repetitive calls only. For the first time the Fibonacci value of a number n is ... | -1 | 2016-08-05T05:16:50Z | [
"python",
"python-2.7",
"fibonacci",
"series",
"memoization"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.