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 |
|---|---|---|---|---|---|---|---|---|---|
Is it possible to access a local variable in another function? | 39,682,842 | <p>Goal: Need to use local variable in another function. Is that possible in Python?</p>
<p>I would like to use the local variable in some other function. Because in my case I need to use a counter to see the number of connections happening and number of connections releasing/ For that I am maintaining a counter. To i... | 0 | 2016-09-25T02:32:22Z | 39,683,886 | <p>Except <code>closure</code> you wont have access to local vars outside the scope of your functions.
If variables have to be shared across different methods better make them as global as @pavnik has mentioned.</p>
| 0 | 2016-09-25T05:57:07Z | [
"python",
"python-2.7",
"python-3.x"
] |
'int' object is not callable error in class | 39,682,852 | <p>In python 2.7, I am writing a class called <code>Zillion</code>, which is to act as a counter for very large integers. I believe I have it riddled out, but I keep running into <code>TypeError: 'int' object is not callable</code> , which seems to mean that at some point in my code I tried to call an <code>int</code> ... | -1 | 2016-09-25T02:34:19Z | 39,682,886 | <p>You have both an instance variable and a method named <code>increment</code> that seems to be your problem with that traceback at least.</p>
<p>in <code>__init__</code> you define <code>self.increment = 1</code> and that masks the method with the same name</p>
<p>To fix, just rename one of them (and if it's the va... | 1 | 2016-09-25T02:43:09Z | [
"python"
] |
'int' object is not callable error in class | 39,682,852 | <p>In python 2.7, I am writing a class called <code>Zillion</code>, which is to act as a counter for very large integers. I believe I have it riddled out, but I keep running into <code>TypeError: 'int' object is not callable</code> , which seems to mean that at some point in my code I tried to call an <code>int</code> ... | -1 | 2016-09-25T02:34:19Z | 39,682,897 | <p>You have defined an instance variable in <code>Zillion.__init__()</code></p>
<pre><code>def __init__(self, digits):
self.new = []
self.count = 0
self.increment = 1 # Here!
</code></pre>
<p>Then you defined a method with the same name 'Zillion.increment()`:</p>
<pre><code>def increment(sel... | 0 | 2016-09-25T02:45:51Z | [
"python"
] |
'int' object is not callable error in class | 39,682,852 | <p>In python 2.7, I am writing a class called <code>Zillion</code>, which is to act as a counter for very large integers. I believe I have it riddled out, but I keep running into <code>TypeError: 'int' object is not callable</code> , which seems to mean that at some point in my code I tried to call an <code>int</code> ... | -1 | 2016-09-25T02:34:19Z | 39,682,934 | <p>Because you have a variable member <code>self.increment</code>ï¼and it has been set to the 1 in your <code>__init__</code> function.</p>
<p><code>z.increment</code> represents the variable member which set to 1.</p>
<p>You can rename your function from <code>increment</code> to the <code>_increment</code>(or any ... | 0 | 2016-09-25T02:54:19Z | [
"python"
] |
Spurious ValueError using learning_curve on sklearn.svm.SVC(kernel='rbf') classifier | 39,682,885 | <p>I am getting weird ValueError when using learning_curve on svm.SVC(kernel='rbf') classifier.</p>
<p>I am using:</p>
<pre><code>from sklearn import svm
from sklearn import cross_validation, datasets, preprocessing
clf=svm.SVC(kernel='rbf')
cv=cross_validation.StratifiedKFold(y, n_folds=10)
for enum, (train, test) i... | 0 | 2016-09-25T02:43:03Z | 39,693,288 | <p>This looks likely to be caused by the <code>learning_curve</code> which retrains the model on different sized subsamples of your data; by default the sample sizes are <code>train_sizes=array([ 0.1, 0.33, 0.55, 0.78, 1. ])</code>, depending on your data you may be able address the issue by leaving out the smaller fra... | 1 | 2016-09-26T00:48:56Z | [
"python",
"machine-learning",
"scikit-learn"
] |
Comparing element in list and string | 39,682,927 | <p>I am just learning python, and I come across the question where i have to read a file and see search for a word</p>
<p>my code is</p>
<pre><code>Search_Word = input("Type your search word : ")
file = open(input("Your file name"), 'r')
read_line = file.readlines()
file.close()
def isPartOf(read_line, Search_Word):... | 1 | 2016-09-25T02:52:18Z | 39,683,284 | <p>Just replace</p>
<pre><code>for i in range (0, len(read_line)):
if(str(read_line[i) == Search_Word):
</code></pre>
<p>by</p>
<pre><code>for i in read_line:
if i.strip('\n') == Search_Word:
</code></pre>
| 0 | 2016-09-25T04:10:03Z | [
"python",
"string-comparison",
"helpers"
] |
Why use itertools.groupby instead of doing it yourself? | 39,683,041 | <pre><code>from collections import defaultdict
import itertools
items = [(0, 0), (0, 1), (1, 0), (1, 1)]
keyfunc = lambda x: x[0]
# Grouping yourself
item_map = defaultdict(list)
for item in items:
item_map[keyfunc(item)].append(item)
# Using itertools.groupby
item_map = {}
for key, group in itertools.groupby(i... | 1 | 2016-09-25T03:18:34Z | 39,683,156 | <p>Generally the point of using iterators is to avoid keeping an entire data set in memory. In your example, it doesn't matter because:</p>
<ul>
<li>The input is already all in memory.</li>
<li>You're just dumping everything into a <code>dict</code>, so the output is also all in memory.</li>
</ul>
<blockquote>
<p>O... | 1 | 2016-09-25T03:40:40Z | [
"python"
] |
Cannot find python 3.5.x interpreter using .msi extension | 39,683,090 | <p>I'm new to stack overflow. I was wondering if anybody knew if there was a .msi package for a python interpreter for python 3.5, I'm teaching a basic python class and wanted to be prepared for when it starts in a few weeks. There is a .msi packaged interpreter for 2.7 python on the official python.org downloads page ... | -1 | 2016-09-25T03:28:56Z | 39,683,413 | <p>After <a href="https://www.python.org/downloads/release/python-344/" rel="nofollow">Python 3.4.4</a> was released python.org stopped providing MSI installers for their Windows releases. Web-based, exectuable, and zipped installers are now provided for both 32-bit and 64-bit Windows releases. I'm not sure what the re... | 0 | 2016-09-25T04:35:06Z | [
"python",
"python-2.7",
"ide",
"pycharm",
"python-3.5"
] |
Find documents which contain a particular value - Mongo, Python | 39,683,102 | <p>I'm trying to add a search option to my website but it doesn't work. I looked up solutions but they all refer to using an actual string, whereas in my case I'm using a variable, and I can't make those solutions work. Here is my code:</p>
<pre><code>cursor = source.find({'title': search_term}).limit(25)
for document... | 1 | 2016-09-25T03:31:28Z | 39,683,190 | <p>You can use <code>$regex</code> to do contains searches.</p>
<pre><code>cursor = collection.find({'field': {'$regex':'regular expression'}})
</code></pre>
<p>And to make it case insensitive:</p>
<pre><code>cursor = collection.find({'field': {'$regex':'regular expression', '$options'ââ:'i'}})
</code></pre>
<p... | 1 | 2016-09-25T03:48:17Z | [
"python",
"mongodb"
] |
Find documents which contain a particular value - Mongo, Python | 39,683,102 | <p>I'm trying to add a search option to my website but it doesn't work. I looked up solutions but they all refer to using an actual string, whereas in my case I'm using a variable, and I can't make those solutions work. Here is my code:</p>
<pre><code>cursor = source.find({'title': search_term}).limit(25)
for document... | 1 | 2016-09-25T03:31:28Z | 39,683,196 | <h3>$text</h3>
<p>You can perform a text search using <code>$text</code> & <code>$search</code>. You first need to set a text index, then use it:</p>
<pre><code>$ db.docs.createIndex( { title: "text" } )
$ db.docs.find( { $text: { $search: "search_term" } } )
</code></pre>
<h3>$regex</h3>
<p>You may also use <c... | 0 | 2016-09-25T03:49:23Z | [
"python",
"mongodb"
] |
Is there a good way to find the rank of a matrix in a field of characteristic p>0? | 39,683,153 | <p>I need an efficient algorithm or a known way to determine <a href="https://en.wikipedia.org/wiki/Rank_(linear_algebra)" rel="nofollow">the mathematical rank</a> of a matrix A with coefficients in a field of positive characteristic. </p>
<p>For example, in the finite field of 5 elements I have the following matrix:<... | 3 | 2016-09-25T03:39:58Z | 39,725,042 | <p>Numpy doesn't have built-in support for finite fields. The matrix <code>A</code> in your code is treated as a matrix of real numbers, and hence has rank 2. </p>
<p>If you really need to support finite fields with Numpy, you'll have to define your own data type along with the arithmetic operations yourself, as shown... | 1 | 2016-09-27T12:44:01Z | [
"python",
"numpy",
"matrix"
] |
How would I use the M.E.A.N. Stack with a Python script backend where the python script is in a container? | 39,683,166 | <p>So I am in the process of writing a web app with the full M.E.A.N. stack and know how to work with both the front end and the back end. My only problem is incorporating things outside of M.E.A.N. As an example, I am going to be running a Python script as the algorithmic back end for the web app (mainly due to nece... | -1 | 2016-09-25T03:41:57Z | 39,845,346 | <p>Getting started with the MEAN stack might seem very daunting at first. You might think that there is too much new technology to learn. The truth is that you really only need to know âJavascript.â Thatâs right, MEAN is simply a javascript web development stack.</p>
<p>So, how do you actually get started devel... | 0 | 2016-10-04T06:17:35Z | [
"python",
"docker",
"containers",
"mean-stack",
"microservices"
] |
I am trying to use PTVS in visual studio, but cannot set python interpreter | 39,683,194 | <p>I am trying to use <code>PTVS in visual studio</code>, but cannot set <code>python interpreter</code>. I installed visual studio enterprise 2015 and installed python 3.5.2. </p>
<p>I opened python environment in visual studio, but I cannot find installed interpreter, even cannot click the '<code>+custom</code>' but... | 0 | 2016-09-25T03:49:02Z | 39,732,669 | <p>I have just reinstalled windows 10, python, and visual studio again. It works now. I have no clue why it did not work before.</p>
| 0 | 2016-09-27T19:19:24Z | [
"python",
"visual-studio",
"ptvs"
] |
How to set sender email Id while using Flask Mail | 39,683,211 | <p>I am using Flak Mail to send email from a website's contact form. Contact form has a <code>sender</code> email id field as well. So when I receive the email at "recipient" email id I want <code>from</code> to be set as <code>sender</code> email Id to have the value entered on the form. Following is the class that ha... | -1 | 2016-09-25T03:52:28Z | 39,686,127 | <p>Have you checked that the <code>email_id</code> you are passing in is what you think it is?</p>
<p><a href="https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L275" rel="nofollow">The Flask Mail source code</a> suggests that it will only use the default if the <code>sender</code> you pass in is fal... | 0 | 2016-09-25T11:04:14Z | [
"python",
"flask",
"smtp",
"flask-mail"
] |
Read all columns from CSV file? | 39,683,221 | <p>I am trying to read in a CSV file and then take all values from each column and put into a separate list. I do not want the values by row. Since the CSV reader only allows to loop through the file once, I am using the seek() method to go back to the beginning and read the next column. Besides using a Dict mapping, i... | 0 | 2016-09-25T03:54:15Z | 39,683,290 | <p>You could feed the <code>reader</code> to <a href="https://docs.python.org/3.5/library/functions.html#zip" rel="nofollow"><code>zip</code></a> and unpack it to variables as you wish.</p>
<pre><code>import csv
with open('input.csv') as f:
first, second, third, fourth = zip(*csv.reader(f))
print('first: {}, ... | 1 | 2016-09-25T04:11:45Z | [
"python",
"python-3.x",
"csv",
"list-comprehension"
] |
Read all columns from CSV file? | 39,683,221 | <p>I am trying to read in a CSV file and then take all values from each column and put into a separate list. I do not want the values by row. Since the CSV reader only allows to loop through the file once, I am using the seek() method to go back to the beginning and read the next column. Besides using a Dict mapping, i... | 0 | 2016-09-25T03:54:15Z | 39,683,297 | <p>I am not sure why you dont want to use dict mapping. This is what I end up doing</p>
<p><strong>Data</strong></p>
<pre><code>col1,col2,col3
val1,val2,val3
val4,val5,val6
</code></pre>
<p><strong>Code</strong></p>
<pre><code>import csv
d = dict()
with open("abc.text") as csv_file:
reader = csv.DictReader(csv... | 0 | 2016-09-25T04:14:10Z | [
"python",
"python-3.x",
"csv",
"list-comprehension"
] |
Read all columns from CSV file? | 39,683,221 | <p>I am trying to read in a CSV file and then take all values from each column and put into a separate list. I do not want the values by row. Since the CSV reader only allows to loop through the file once, I am using the seek() method to go back to the beginning and read the next column. Besides using a Dict mapping, i... | 0 | 2016-09-25T03:54:15Z | 39,683,298 | <p>Something like this would do it in one pass:</p>
<pre><code>kinds = NOUNS, VERBS, ADJECTIVES, SENTENCES = [], [], [], []
with open(fpath, "r") as infile:
for cols in csv.reader(infile):
for i, kind in enumerate(kinds):
kind.append(cols[i])
</code></pre>
| 1 | 2016-09-25T04:14:14Z | [
"python",
"python-3.x",
"csv",
"list-comprehension"
] |
Read all columns from CSV file? | 39,683,221 | <p>I am trying to read in a CSV file and then take all values from each column and put into a separate list. I do not want the values by row. Since the CSV reader only allows to loop through the file once, I am using the seek() method to go back to the beginning and read the next column. Besides using a Dict mapping, i... | 0 | 2016-09-25T03:54:15Z | 39,683,370 | <p>This works assuming you know exactly how many columns are in the csv (and there isn't a header row).</p>
<pre><code>NOUNS = []
VERBS = []
ADJECTIVES = []
SENTENCES = []
with open(fpath, "r") as infile:
reader = csv.reader(infile)
for row in reader:
NOUNS.append(row[0])
VERBS.append(row[... | 1 | 2016-09-25T04:27:34Z | [
"python",
"python-3.x",
"csv",
"list-comprehension"
] |
Google api client for python log level and debuglevel not working | 39,683,228 | <p>While building a basic python app on AppEngine I found this page:
<a href="https://developers.google.com/api-client-library/python/guide/logging" rel="nofollow">https://developers.google.com/api-client-library/python/guide/logging</a></p>
<p>Which states you can do the following to set the log level:</p>
<pre><cod... | 2 | 2016-09-25T03:56:33Z | 39,683,997 | <p>In PyCharm edit your project's Run configuration (<code>Run</code> -> <code>Edit Configurations</code> then select your project) and in the <code>Additional options</code> field add <code>--log_level=debug</code>.</p>
<p>BTW - you don't need to set the <code>logger</code> options, the above should suffice.</p>
| 0 | 2016-09-25T06:14:19Z | [
"python",
"google-app-engine",
"debugging",
"google-api",
"pycharm"
] |
How to close a current window and open a new window at the same time? | 39,683,274 | <p>This code opens a button, which links to another button. The other button can close its self, but the first button can't close itself and open a new one at the same time, How do I fix this?</p>
<pre><code>import tkinter as tk
class Demo1:
def __init__(self, master):
self.master = master
self.fr... | 2 | 2016-09-25T04:07:06Z | 39,683,581 | <p>Try this:</p>
<pre><code>import tkinter as tk
class windowclass():
def __init__(self, master):
self.master = master
self.btn = tk.Button(master, text="Button", command=self.command)
self.btn.pack()
def command(self):
self.master.withdraw()
toplevel = tk.Toplevel(sel... | -1 | 2016-09-25T05:04:40Z | [
"python",
"tkinter"
] |
How to close a current window and open a new window at the same time? | 39,683,274 | <p>This code opens a button, which links to another button. The other button can close its self, but the first button can't close itself and open a new one at the same time, How do I fix this?</p>
<pre><code>import tkinter as tk
class Demo1:
def __init__(self, master):
self.master = master
self.fr... | 2 | 2016-09-25T04:07:06Z | 39,718,403 | <p>Try redefine your <code>Demo1.new_window()</code> as below:</p>
<pre><code>def new_window(self):
self.master.destroy() # close the current window
self.master = tk.Tk() # create another Tk instance
self.app = Demo2(self.master) # create Demo2 window
self.master.mainloop()
</code></pre>
| 0 | 2016-09-27T07:17:07Z | [
"python",
"tkinter"
] |
How can I improve formatting of floats output from my tax calculator? | 39,683,352 | <p>I didn't have any problems writing this much, but the output numbers are a little wonky. Sometimes I'll get something like 83.78812, for example, and I'd rather round it up to 83.79.</p>
<p>Here's the code itself:</p>
<pre><code>#This is a simple tax calculator based on Missouri's tax rate.
while True:
tax = 0.07... | -2 | 2016-09-25T04:24:19Z | 39,683,475 | <p>You should use <strong>round</strong>:</p>
<pre><code>round(final,2)
</code></pre>
| 0 | 2016-09-25T04:43:47Z | [
"python",
"python-2.7",
"calculator",
"number-formatting"
] |
How can I improve formatting of floats output from my tax calculator? | 39,683,352 | <p>I didn't have any problems writing this much, but the output numbers are a little wonky. Sometimes I'll get something like 83.78812, for example, and I'd rather round it up to 83.79.</p>
<p>Here's the code itself:</p>
<pre><code>#This is a simple tax calculator based on Missouri's tax rate.
while True:
tax = 0.07... | -2 | 2016-09-25T04:24:19Z | 39,683,903 | <blockquote>
<p>"typing in a string results in an error that crashes the program, but I'd rather it simply give an error message and loop back to the beginning." </p>
</blockquote>
<p>To do this, you can use a while loop with <code>try & catch</code> That will keep on prompting for the item cost until it gets a... | 2 | 2016-09-25T06:00:27Z | [
"python",
"python-2.7",
"calculator",
"number-formatting"
] |
List in Function in Python Read as Multiple Objects | 39,683,536 | <p>I have a function that looks like this:</p>
<pre><code>class Question:
Ans = "";
checkAns = 0;
isPos=False;
def Ask(Q, PosAns):
checkAns=0;
Ans = raw_input("{} ({})".format(Q,PosAns));
while(checkAns<len(PosAns) and isPos!=True):
if(Ans==PosAns[x]):
... | 0 | 2016-09-25T04:55:24Z | 39,683,667 | <p>You missed the 'self' in method declaration. Every class method (except static methods) require first argument to be <code>self</code>. self is implicily passed so doesnt show up in our method calls.
self can be used to refer the the other attributes of call like <code>isPos</code>, <code>checkAns</code> and <code>a... | 0 | 2016-09-25T05:22:15Z | [
"python"
] |
Why can't I import a module from within the same directory? | 39,683,616 | <p>If I have two python modules in a directory <code>main.py</code> and <code>somemodule.py</code>, I can import <code>somemodule</code> by using <code>import somemodule</code>.</p>
<p><code>./
main.py
somemodule.py
__init__.py</code></p>
<p>In django application where we have <code>urls.py</code> and <code>vie... | 0 | 2016-09-25T05:12:39Z | 39,683,817 | <p>That's because of python 3 import style and is irrelevant to Django.</p>
<p>Read this for more details:
<a href="http://stackoverflow.com/questions/12172791/changes-in-import-statement-python3">Changes in import statement python3</a></p>
| 0 | 2016-09-25T05:47:31Z | [
"python",
"python-3.x",
"python-import"
] |
Viewing h264 stream over TCP | 39,683,734 | <p>I have a small wifi based FPV camera for a drone. I've managed to get it to the point where I can download and save an h264 file using python.</p>
<pre><code>TCP_IP = '193.168.0.1'
TCP_PORT = 6200
BUFFER_SIZE = 2056
f = open('stream.h264', 'wb')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect... | 0 | 2016-09-25T05:33:02Z | 39,691,426 | <p>I successfully output to mplayer using </p>
<p><code>data = sock.recv(BUFFER_SIZE)
sys.stdout.buffer.write(data)</code></p>
<p>and then having mplayer pipe the input</p>
<p><code>python cam.py - | mplayer -fps 20 -nosound -vc ffh264 -noidx -mc 0 -</code></p>
| 0 | 2016-09-25T20:18:20Z | [
"python",
"stream",
"video-streaming",
"h.264"
] |
Viewing h264 stream over TCP | 39,683,734 | <p>I have a small wifi based FPV camera for a drone. I've managed to get it to the point where I can download and save an h264 file using python.</p>
<pre><code>TCP_IP = '193.168.0.1'
TCP_PORT = 6200
BUFFER_SIZE = 2056
f = open('stream.h264', 'wb')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect... | 0 | 2016-09-25T05:33:02Z | 39,696,111 | <p>It is a simple way, yes: send H.264 NALU stream (you put 0,0,0,1 prefix before each nal unit and it is ok).</p>
<p>If you want something more cool, then you can add packing to RTP and send it via multicast. It will be rather simple to code and easy to read.</p>
| 0 | 2016-09-26T06:35:42Z | [
"python",
"stream",
"video-streaming",
"h.264"
] |
This is a dfs search implemented using python which i have taken from internet | 39,683,744 | <pre><code>graph={
'A':set(['B','C']),
'B':set(['A','D','E']),
'C':set(['A','F']),
'D':set(['B']),
'E':set(['B','F']),
'F':set(['C','E'])}
def dfs(graph, start):
visited, stack = set(), [start]
while stack:
vertex = stack.pop()
if vertex ... | 0 | 2016-09-25T05:35:30Z | 39,684,497 | <p>The first line you're asking about is initializing the <code>visited</code> and <code>stack</code> variables. You could write it on two lines if you wanted to:</p>
<pre><code>visited = set()
stack = []
</code></pre>
<p>I like initializing things on separate lines a bit better, but it's mostly a matter of style. I ... | 0 | 2016-09-25T07:38:54Z | [
"python"
] |
How to store multiple users in a MySQL table row | 39,683,748 | <p>What I have is a program that allows users to monitor posts by specifying what they are looking for. I'm predicting that many users will monitor the same posts, and would like to instead of having them all listed as separate posts, have all of the users grouped into the same row.</p>
<p>I'm unsure of wether MySQL h... | 0 | 2016-09-25T05:36:11Z | 39,683,827 | <p>Putting user names in a comma-separated list is a <em>terrible</em> solution. Please don't do that. It leads to all sorts of problems.</p>
<p>The best way to do this is to create a new table with two columns: <code>USER_ID</code> and <code>POST_ID</code>. Whenever a user wants to monitor a post, add a row with t... | 3 | 2016-09-25T05:49:38Z | [
"python",
"mysql"
] |
Nested Loops calculation output is incorrect, but program runs | 39,683,920 | <p>How am I able to get my program to display year 1 for the first 12 months and then year 2 for the next 12 months if the input value for years = 2?</p>
<p>Also I don't know where my calculation is going wrong. According to my desired output, the total rainfall output should be 37, but I am getting 39.</p>
<p><a hre... | 0 | 2016-09-25T06:02:40Z | 39,683,980 | <p>Before the print statement, you don't need to add rain value again for rainTotal. This is because grandTotal accounts for the rain per year. And it is being added twice for two years already. So what you're doing is essentially adding the last value of rain twice (2 in this case)
Make your print statement this and r... | 3 | 2016-09-25T06:11:41Z | [
"python",
"nested-loops"
] |
Nested Loops calculation output is incorrect, but program runs | 39,683,920 | <p>How am I able to get my program to display year 1 for the first 12 months and then year 2 for the next 12 months if the input value for years = 2?</p>
<p>Also I don't know where my calculation is going wrong. According to my desired output, the total rainfall output should be 37, but I am getting 39.</p>
<p><a hre... | 0 | 2016-09-25T06:02:40Z | 39,684,030 | <pre><code>rainTotal = rain + grandTotal
</code></pre>
<blockquote>
<p>is performing following: 2 + 37 because you have last rain input = 2 and already total or grandTotal is = 37 (total input for each year) so <em>rainTotal = rain + grandTotal</em> is <strong>not needed</strong></p>
</blockquote>
| 0 | 2016-09-25T06:18:58Z | [
"python",
"nested-loops"
] |
Nested Loops calculation output is incorrect, but program runs | 39,683,920 | <p>How am I able to get my program to display year 1 for the first 12 months and then year 2 for the next 12 months if the input value for years = 2?</p>
<p>Also I don't know where my calculation is going wrong. According to my desired output, the total rainfall output should be 37, but I am getting 39.</p>
<p><a hre... | 0 | 2016-09-25T06:02:40Z | 39,684,058 | <p>I've shortened your code a little bit. Hopefully this is a complete and correct program:</p>
<pre><code>def main():
years = int(input("Enter the number of years you want the rainfall calculator to determine: "))
calcRainFall(years)
def calcRainFall(yearsF):
months = 12 * yearsF # total number of months... | 2 | 2016-09-25T06:23:26Z | [
"python",
"nested-loops"
] |
Nested Loops calculation output is incorrect, but program runs | 39,683,920 | <p>How am I able to get my program to display year 1 for the first 12 months and then year 2 for the next 12 months if the input value for years = 2?</p>
<p>Also I don't know where my calculation is going wrong. According to my desired output, the total rainfall output should be 37, but I am getting 39.</p>
<p><a hre... | 0 | 2016-09-25T06:02:40Z | 39,684,102 | <p>Notes for your code:</p>
<p>As stated earlier, rainTotal is unneeded.</p>
<p>You can try: </p>
<pre><code>print 'Enter the number of inches of rainfall for year %d month %d' % (years_rain, month), end='')
</code></pre>
<p>This will fill the first %d for the value for years_rain and the second %d with the va... | 0 | 2016-09-25T06:32:38Z | [
"python",
"nested-loops"
] |
scipy.sparse.coo_matrix how to fast find all zeros column, fill with 1 and normalize | 39,683,931 | <p>For a matrix, i want to find columns with all zeros and fill with 1s, and then normalize the matrix by column. I know how to do that with np.arrays</p>
<pre><code>[[0 0 0 0 0]
[0 0 1 0 0]
[1 0 0 1 0]
[0 0 0 0 1]
[1 0 0 0 0]]
|
V
[[0 1 0 0 0]
[0 1 1 0 0]
[1 1 0 1 0]
[0 1 0 0 1]
[1 1 0 0 0... | 0 | 2016-09-25T06:04:12Z | 39,684,081 | <p>This will be a lot easier with the <code>lil</code> format, and working with rows rather than columns:</p>
<pre><code>In [1]: from scipy import sparse
In [2]: A=np.array([[0,0,0,0,0],[0,0,1,0,0],[1,0,0,1,0],[0,0,0,0,1],[1,0,0,0,0]])
In [3]: A
Out[3]:
array([[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[1, 0, 0,... | 1 | 2016-09-25T06:28:02Z | [
"python",
"numpy",
"scipy",
"linear-algebra",
"sparse-matrix"
] |
What is wrong with the following code for computing distance between all pairs of vectors? | 39,684,114 | <p>I'm trying to find manhattan distance between all pairs of vectors.</p>
<pre><code>import numpy as np
import itertools
class vector:
def __init__(self):
self.a = 0
self.b = 0
c = vector()
d = vector()
l = vector()
m = vector()
e = [c,d]
n = [l,m]
o = np.array(n)
f = np.array(e)
p = itertools.... | 1 | 2016-09-25T06:34:21Z | 39,684,213 | <p>I have to say I'd approach this differently. Numerical Python doesn't deal well with Python classes and such.</p>
<p>Your class</p>
<pre><code>class vector:
def __init__(self):
self.a = 0
self.b = 0
</code></pre>
<p>Is basically a length-2 vector. So, if you're going to operate on many length-... | 2 | 2016-09-25T06:50:27Z | [
"python",
"vectorization",
"itertools"
] |
What is wrong with the following code for computing distance between all pairs of vectors? | 39,684,114 | <p>I'm trying to find manhattan distance between all pairs of vectors.</p>
<pre><code>import numpy as np
import itertools
class vector:
def __init__(self):
self.a = 0
self.b = 0
c = vector()
d = vector()
l = vector()
m = vector()
e = [c,d]
n = [l,m]
o = np.array(n)
f = np.array(e)
p = itertools.... | 1 | 2016-09-25T06:34:21Z | 39,684,233 | <p>The way you've written <code>comp</code>, it expects to be called with a two-tuple as an argument, but that's not what happens. <code>p</code> is a list of tuples. When you call a vectorized function on it, it is converted to a numpy array. The tuples are split into separate columns so you get a 4x2 array. Your ... | 0 | 2016-09-25T06:53:19Z | [
"python",
"vectorization",
"itertools"
] |
Writing a mandelbrot set to an image in python | 39,684,141 | <p>I am trying to write a mandelbrot set to an image in python, and am having a problem with one of my functions. </p>
<p>The issue is: While I expect something like <a href="http://i.stack.imgur.com/mOwfm.jpg" rel="nofollow">this</a>. I am getting a plain white image. Here is my code:</p>
<p>Quick Summary of code:
C... | -1 | 2016-09-25T06:37:45Z | 39,689,842 | <p>Your handling of the <code>y</code> coordinate is faulty. You begin the outer loop with </p>
<pre><code>y = 2
</code></pre>
<p>and have the loop condition as </p>
<pre><code>while TopLeftY <= y <= BottomRightY:
</code></pre>
<p>After substituting their values, this is</p>
<pre><code>while 2 <= y <=... | 0 | 2016-09-25T17:39:16Z | [
"python",
"mandelbrot"
] |
How can I make use of intel-mkl with tensorflow | 39,684,300 | <p>I've seen a lot of documentation about making using of a CPU with tensorflow, however, I don't have a GPU. What I do have is a fairly capable CPU and a holing 5GB of intel math kernel, which, I hope, might help me speed up tensorflow a fair bit.</p>
<p>Does anyone know how I can "make" tensorflow use the intel-mlk ... | 3 | 2016-09-25T07:04:11Z | 39,686,012 | <p>You can install <a href="https://software.intel.com/en-us/intel-distribution-for-python" rel="nofollow">Intel Python Distribution</a>, this comes packaged with optimized NumPy, SciPy etc. You can install Tensorflow post this installation, Tensorflow uses Eigen, which is optimized to use SIMD vector lanes on CPU well... | 0 | 2016-09-25T10:49:40Z | [
"python",
"c++",
"numpy",
"tensorflow",
"blas"
] |
How can I make use of intel-mkl with tensorflow | 39,684,300 | <p>I've seen a lot of documentation about making using of a CPU with tensorflow, however, I don't have a GPU. What I do have is a fairly capable CPU and a holing 5GB of intel math kernel, which, I hope, might help me speed up tensorflow a fair bit.</p>
<p>Does anyone know how I can "make" tensorflow use the intel-mlk ... | 3 | 2016-09-25T07:04:11Z | 39,771,199 | <p>Since tensorflow uses Eigen, try to use an MKL enabled version of Eigen as described <a href="https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html" rel="nofollow">here</a>:</p>
<blockquote>
<ol>
<li>define the EIGEN_USE_MKL_ALL macro before including any Eigen's header</li>
<li>link your program to MKL lib... | 0 | 2016-09-29T13:07:32Z | [
"python",
"c++",
"numpy",
"tensorflow",
"blas"
] |
Heroku gunicorn flask login is not working properly | 39,684,364 | <p>I have a flask app that uses Flask-Login for authentication. Everything works fine locally both using flask's built in web server and gunicorn run locally. But when it's on heroku it's faulty, sometimes it logs me in and sometimes it does not. When I successfully logged in within a few seconds of navigating my sessi... | 0 | 2016-09-25T07:15:29Z | 39,768,181 | <p>The problem was solved by adding the <code>--preload</code> option to gunicorn. I'm not entirely sure how that solved the problem and would appreciate if someone can explain.</p>
<p>Updated Procfile:</p>
<p><code>web: gunicorn app:app --preload</code></p>
| 0 | 2016-09-29T10:46:00Z | [
"python",
"heroku",
"flask",
"gunicorn",
"flask-login"
] |
How to end a while loop properly? | 39,684,365 | <p>I want to create a program that asks a user for sentences that then combine to create a story that is displayed to the user. The user decides how many sentences he or she wishes to write. </p>
<p>This is probably a dumb question with a simple answer, but with the code below a <code>q</code> or <code>Q</code> is alw... | -1 | 2016-09-25T07:15:44Z | 39,684,389 | <p>You should check after input, if the look should end or not. If so you can exit using <code>break</code></p>
<pre><code>story = ""
while True
sentence = input("Enter the sentence(Enter 'q' to quit): ")
if sentence.lower() != 'q':
story += sent
else:
break
print(story)
</code></pre>
| 2 | 2016-09-25T07:19:18Z | [
"python"
] |
How to end a while loop properly? | 39,684,365 | <p>I want to create a program that asks a user for sentences that then combine to create a story that is displayed to the user. The user decides how many sentences he or she wishes to write. </p>
<p>This is probably a dumb question with a simple answer, but with the code below a <code>q</code> or <code>Q</code> is alw... | -1 | 2016-09-25T07:15:44Z | 39,684,407 | <p>The extra 'q' gets inserted because you are storing the character 'q' in variable sent. Perform story+=sent before the input statement instead.</p>
<pre><code>sent = ""
story = ""
while sent.lower() != 'q':
story += sent
sent = input("Enter the sentence(Enter 'q' to quit): ")
print(story)
</code></pre>
| 1 | 2016-09-25T07:22:48Z | [
"python"
] |
TensorFlow getting elements of every row for specific columns | 39,684,415 | <p>If <code>A</code> is a TensorFlow variable like so </p>
<pre><code>A = tf.Variable([[1, 2], [3, 4]])
</code></pre>
<p>and <code>index</code> is another variable </p>
<pre><code>index = tf.Variable([0, 1])
</code></pre>
<p>I want to use this index to select columns in each row. In this case, item 0 from first row... | 2 | 2016-09-25T07:23:46Z | 39,686,130 | <p>After dabbling around for quite a while. I found two functions that could be useful.</p>
<p>One is <code>tf.gather_nd()</code> which might be useful if you can produce a tensor
of the form <code>[[0, 0], [1, 1]]</code> and thereby you could do </p>
<p><code>index = tf.constant([[0, 0], [1, 1]])</code></p>
<p><co... | 2 | 2016-09-25T11:05:06Z | [
"python",
"numpy",
"tensorflow"
] |
sqlite - return all columns for max of one column without repeats | 39,684,477 | <p>Im using Python to query a SQL database. I'm fairly new with databases. I've tried looking up this question, but I can't find a similar enough question to get the right answer.</p>
<p>I have a table with multiple columns/rows. I want to find the MAX of a single column, I want ALL columns returned (the entire ROW), ... | 0 | 2016-09-25T07:35:19Z | 39,688,400 | <p>In SQLite 3.7.11 or later, you can just retrieve all columns together with the maximum value:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT *, max(f) FROM cbar;
</code></pre>
<p>But your Python might be too old. In the general case, you can sort the table by that column, and then just read the firs... | 1 | 2016-09-25T15:08:50Z | [
"python",
"sqlite",
"max"
] |
Searching a file for words from a list | 39,684,483 | <p>I am trying to search for words in a file. Those words are stored in a separate list.
The words that are found are stored in another list and that list is returned in the end.</p>
<p>The code looks like:</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "... | 1 | 2016-09-25T07:36:16Z | 39,684,613 | <p>You get empty lists because <code>None</code> is not equal to an empty list. What you might want is to change the condition to the following:</p>
<pre><code>if matching:
# do your stuff
</code></pre>
<p>It seems that you're checking if a substring is present in the strings in the qualities list. Which might no... | 1 | 2016-09-25T07:56:22Z | [
"python",
"python-2.7"
] |
Searching a file for words from a list | 39,684,483 | <p>I am trying to search for words in a file. Those words are stored in a separate list.
The words that are found are stored in another list and that list is returned in the end.</p>
<p>The code looks like:</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "... | 1 | 2016-09-25T07:36:16Z | 39,684,616 | <p>The code should be written as follows (if I understand the desired output format correctly):</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "sqlite", "c#", "c++", "c", "javascript", "pascal",
"html", "css", "jquery", "linux", "windows"]
... | 1 | 2016-09-25T07:56:43Z | [
"python",
"python-2.7"
] |
Searching a file for words from a list | 39,684,483 | <p>I am trying to search for words in a file. Those words are stored in a separate list.
The words that are found are stored in another list and that list is returned in the end.</p>
<p>The code looks like:</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "... | 1 | 2016-09-25T07:36:16Z | 39,684,635 | <p>First of all, you are getting a bunch of "empty seats" because your condition is not defined correctly. If matching is an empty list, it is not None. That is: <code>[] is not None</code> evaluates to <code>True</code>. This is why you are getting all these "empty seats".</p>
<p>Seconds of all, the condition in your... | 1 | 2016-09-25T07:59:43Z | [
"python",
"python-2.7"
] |
Searching a file for words from a list | 39,684,483 | <p>I am trying to search for words in a file. Those words are stored in a separate list.
The words that are found are stored in another list and that list is returned in the end.</p>
<p>The code looks like:</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "... | 1 | 2016-09-25T07:36:16Z | 39,684,857 | <p>You can also use regular expression like this:</p>
<pre><code>def scan_education(file_name):
education = []
qualities_list = ["python", "java", "sql", "mysql", "sqlite", "c\#", "c\+\+", "c", "javascript", "pascal",
"html", "css", "jquery", "linux", "windows"]
qualities = re.compile... | 1 | 2016-09-25T08:29:39Z | [
"python",
"python-2.7"
] |
Searching a file for words from a list | 39,684,483 | <p>I am trying to search for words in a file. Those words are stored in a separate list.
The words that are found are stored in another list and that list is returned in the end.</p>
<p>The code looks like:</p>
<pre><code>def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "... | 1 | 2016-09-25T07:36:16Z | 39,684,873 | <p>Here's a short example of using sets and a little bit of list comprehension filtering to find the common words between a text file (or as I used just a text string) and a list that you provide. This is faster and imho clearer than trying to use a loop.</p>
<pre><code>import string
try:
with open('myfile.txt')... | 1 | 2016-09-25T08:32:27Z | [
"python",
"python-2.7"
] |
Convert the string 2.90K to 2900 or 5.2M to 5200000 in pandas dataframe | 39,684,548 | <p>Need some help on processing data inside a pandas dataframe.
Any help is most welcome.</p>
<p>I have OHCLV data in CSV format. I have loaded the file in to pandas dataframe.</p>
<p>How do I convert the volume column from 2.90K to 2900 or 5.2M to 5200000.
The column can contain both K in form of thousands and M in... | 2 | 2016-09-25T07:47:20Z | 39,684,629 | <p>assuming you have the following DF:</p>
<pre><code>In [30]: df
Out[30]:
Date Val
0 2016-09-23 100
1 2016-09-22 9.60M
2 2016-09-21 54.20K
3 2016-09-20 115.30K
4 2016-09-19 18.90K
5 2016-09-16 176.10K
6 2016-09-15 31.60K
7 2016-09-14 10.00K
8 2016-09-13 3.20M
</code></pre>
... | 0 | 2016-09-25T07:59:01Z | [
"python",
"pandas",
"dataframe"
] |
Regex, filter url ending with and without digit | 39,684,549 | <p>I have below four url out of which I want to filter only two using regex expression. </p>
<p>/chassis/motherboard/cpu <---- this</p>
<p>/chassis/motherboard/cpu/core0</p>
<p>/chassis/motherboard/cpu0 <---- this</p>
<p>/chassis/motherboard/cpu1/core0</p>
<p>I have tried to play around with ^.*[0-9... | 1 | 2016-09-25T07:47:31Z | 39,684,592 | <p>You can use this regex:</p>
<pre><code>^.*/cpu[0-9]*$
</code></pre>
<p>This will match any text that ends with <code>/cpu</code> or <code>/cpy<number></code></p>
| 1 | 2016-09-25T07:52:52Z | [
"python",
"regex",
"url",
"filter",
"uri"
] |
run celery tasks in random times | 39,684,554 | <p>i need to run few celery tasks in random times - every run should be at a new random time - the random number should generated every run. <br>
what I did in the past is:<br></p>
<pre><code> "my_task": {
"task": "path.to.my_task",
"schedule": crontab(minute='*/%s' % rand),
},
rand = random(1,12)
</code></... | 0 | 2016-09-25T07:47:48Z | 39,685,496 | <p>I faced a similar problem in which i had to generate <strong>facebook</strong> like notifications between <strong>random users</strong> at <strong>random interval of time</strong></p>
<p>Initially i was also doing the same as you, using the <code>random</code> function to give the <code>minute</code> value to <code... | 1 | 2016-09-25T09:49:10Z | [
"python",
"django",
"celery",
"celerybeat"
] |
Retrieve the last migration for a custom migration, to load initial data | 39,684,568 | <p>I created a custom migration "0000_initial_data.py" and I want that to get applied after all the other migrations are done. Though when I try to use ____latest____ in the dependencies I get "dependencies reference nonexistent parent node" error I feel it is trying to find ____latest____ named migration in the folder... | 0 | 2016-09-25T07:50:06Z | 39,684,884 | <p>Generally custom migrations are used for changing existing data. If you wanna create new data, I recommend you to put your code inside a management command and run that after all migrations.</p>
| 1 | 2016-09-25T08:33:56Z | [
"python",
"django",
"django-migrations"
] |
Selenium TypeError: __init__() takes 2 positional arguments but 3 were given | 39,684,653 | <pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Firefox()
driver.get("http://somelink.com/")
WebDriverWait(driver, 10).until(expected_conditions.i... | 0 | 2016-09-25T08:01:45Z | 39,685,597 | <p>Change this</p>
<pre><code>WebDriverWait(driver, 10).until(expected_conditions.invisibility_of_element_locateââd((By.XPATH, "//input[@id='message']")))
</code></pre>
<p>I have added extra () , hope this should work.</p>
| 0 | 2016-09-25T10:01:30Z | [
"python",
"selenium",
"webdriver"
] |
Create Python dictionary from MS-Access table | 39,684,757 | <p>I have an MS-Access table that has 6 columns. I want to extract the first column and use it as the key and then extract the 2nd and 3rd columns and use them as values in a Python dictionary. There are multiple values for one key.</p>
<p>This is what I have so far but I can't figure out what to do next:</p>
<pre><c... | 0 | 2016-09-25T08:15:00Z | 39,684,800 | <p>You can use <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" rel="nofollow"><code>defaultdict</code></a> to do that</p>
<pre><code>>>> from collections import defaultdict
>>> data = [{u'MAIN_VW': {u'PRESSURE_ZONE_NUM': u'LU_PRESSURE_ZONE_VW'}},
{u'MAIN_VW': {u'D... | 1 | 2016-09-25T08:20:50Z | [
"python",
"dictionary"
] |
App Engine frontend waiting for backend to finish and return data - what's the right way to do it? | 39,684,847 | <p>I'm using a frontend built in angularjs and a backend built in python and webapp2 in app engine.</p>
<p>The backend makes calls to a third party API, fetches data and returns to the frontend.</p>
<p>The API request from the backend may take upto 30s or more. The problem is the frontend can't really progress any fu... | 0 | 2016-09-25T08:28:18Z | 39,687,501 | <p>Requests from the frontend are capped at 30 seconds; after that they time out in the server side. That is part of GAE's design. Requests originating from the task queue get 10 minutes, so your idea is viable. However, you'll want some identifier to use for polling, rather than just using "the last sent," to distingu... | 1 | 2016-09-25T13:45:27Z | [
"python",
"angularjs",
"google-app-engine"
] |
How to make word boundary \b not match on dashes | 39,684,942 | <p>I simplified my code to the specific problem I am having.</p>
<pre><code>import re
pattern = re.compile(r'\bword\b')
result = pattern.sub(lambda x: "match", "-word- word")
</code></pre>
<p>I am getting</p>
<pre><code>'-match- match'
</code></pre>
<p>but I want </p>
<pre><code>'-word- match'
</code></pre>
<p>ed... | 6 | 2016-09-25T08:42:29Z | 39,685,053 | <p>What you need is a negative lookbehind.</p>
<pre><code>pattern = re.compile(r'(?<!-)\bword\b')
result = pattern.sub(lambda x: "match", "-word- word")
</code></pre>
<p>To cite the <a href="https://docs.python.org/3/library/re.html#regular-expression-syntax" rel="nofollow">documentation</a>:</p>
<blockquote>
<... | 5 | 2016-09-25T08:54:28Z | [
"python",
"regex"
] |
How to make word boundary \b not match on dashes | 39,684,942 | <p>I simplified my code to the specific problem I am having.</p>
<pre><code>import re
pattern = re.compile(r'\bword\b')
result = pattern.sub(lambda x: "match", "-word- word")
</code></pre>
<p>I am getting</p>
<pre><code>'-match- match'
</code></pre>
<p>but I want </p>
<pre><code>'-word- match'
</code></pre>
<p>ed... | 6 | 2016-09-25T08:42:29Z | 39,685,126 | <p><code>\b</code> basically denotes a word boundary on characters other than <code>[a-zA-Z0-9_]</code> which includes spaces as well. Surround <code>word</code> with negative lookarounds to ensure there is no non-space character after and before it:</p>
<pre><code>re.compile(r'(?<!\S)word(?!\S)')
</code></pre>
| 1 | 2016-09-25T09:02:50Z | [
"python",
"regex"
] |
How to make word boundary \b not match on dashes | 39,684,942 | <p>I simplified my code to the specific problem I am having.</p>
<pre><code>import re
pattern = re.compile(r'\bword\b')
result = pattern.sub(lambda x: "match", "-word- word")
</code></pre>
<p>I am getting</p>
<pre><code>'-match- match'
</code></pre>
<p>but I want </p>
<pre><code>'-word- match'
</code></pre>
<p>ed... | 6 | 2016-09-25T08:42:29Z | 39,685,218 | <p>Instead of word boundaries, you could also match the character before and after the word with a <code>(\s|^)</code> and <code>(\s|$)</code> pattern. </p>
<p><strong>Breakdown</strong>: <code>\s</code> matches every whitespace character, which seems to be what you are trying to achieve, as you are excluding the dash... | 0 | 2016-09-25T09:13:32Z | [
"python",
"regex"
] |
scipy.sparse matrix: subtract row mean to nonzero elements | 39,685,168 | <p>I have a sparse matrix in <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.html" rel="nofollow">csr_matrix</a> format. For each row i need to subtract row mean from the nonzero elements. The means must be computed on the number of the nonzero elements of the row (instead of... | 2 | 2016-09-25T09:07:35Z | 39,685,793 | <p>This one is tricky. I think I have it. The basic idea is that we try to get a diagonal matrix with the means on the diagonal, and a matrix that is like M, but has ones at the nonzero data locations in M. Then we multiply those and subtract the product from M. Here goes... </p>
<pre><code>>>> import numpy... | 2 | 2016-09-25T10:23:54Z | [
"python",
"scipy",
"updates",
"sparse-matrix",
"mean"
] |
scipy.sparse matrix: subtract row mean to nonzero elements | 39,685,168 | <p>I have a sparse matrix in <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.html" rel="nofollow">csr_matrix</a> format. For each row i need to subtract row mean from the nonzero elements. The means must be computed on the number of the nonzero elements of the row (instead of... | 2 | 2016-09-25T09:07:35Z | 39,688,751 | <p>Starting with <code>@Dthal's</code> sample:</p>
<pre><code>In [92]: a = sparse.csr_matrix([[1.,0,2],[1,2,3]])
In [93]: a.A
Out[93]:
array([[ 1., 0., 2.],
[ 1., 2., 3.]])
In [94]: sums=np.squeeze(a.sum(1).A)
# sums=a.sum(1).A1 # shortcut
In [95]: counts=np.diff(a.tocsr().indptr)
In [96]: means=sums/co... | 2 | 2016-09-25T15:44:57Z | [
"python",
"scipy",
"updates",
"sparse-matrix",
"mean"
] |
Scapy send probe request and receive probe response | 39,685,316 | <p>I am trying to do a job that send <strong>802.11</strong> probe request and receive probe response from. But the result is not good.</p>
<p>Here is my sending frame part, I use <code>Scapy</code> in python:</p>
<pre><code> class Scapy80211():
def __init__(self,intf='wlan0',ssid='test',\
source='00... | 1 | 2016-09-25T09:27:19Z | 39,696,177 | <p>Unless I'm wrong, you are sending your probes, then sniffing the responses. If an answer arrives, it is likely that it arrives meanwhile.</p>
<p>You should probably use <code>srp()</code> function that does the job of sending frames and matching the answers.</p>
| 0 | 2016-09-26T06:39:55Z | [
"python",
"wireless",
"scapy",
"802.11"
] |
Using Sphinx to document multiple Python pojects | 39,685,369 | <p>I'm getting started using Sphinx. I've read a few tutorials but I'm still a bit hung up on how I set up multiple projects.</p>
<p>What I mean is, after installing sphinx, <a href="https://pythonhosted.org/an_example_pypi_project/sphinx.html" rel="nofollow">this guide</a> says</p>
<blockquote>
<p>To get started, ... | 0 | 2016-09-25T09:32:40Z | 39,685,586 | <p>The <code>sphinx-quickstart</code> command generates a documentation skeleton for <em>a single project</em>, so if you have multiple separate projects you will have to run it in each one of them. The link you posted uses the phrase <em>"documentation directory"</em> because the directory name and relative position i... | 2 | 2016-09-25T10:00:01Z | [
"python",
"documentation",
"python-sphinx",
"autodoc"
] |
Django 1.10 - how to load initial users | 39,685,512 | <p>What is the right way to load initial users in Django 1.10?</p>
<p>When we talk about our own django app then it is recommended to have a /fixtures/initial_data.json (as mentioned <a href="http://stackoverflow.com/questions/25960850/loading-initial-data-with-django-1-7-and-data-migrations">here</a>).</p>
<p>But in... | 0 | 2016-09-25T09:50:31Z | 39,685,751 | <p>You can create fixture from default user model by below command:</p>
<pre><code>python manage.py dumpdata auth.user -o FIXTURE_ADDRESS
</code></pre>
<p>and load initial data by below command:</p>
<pre><code>python manage.py loaddata FIXTURENAME
</code></pre>
<p>that <code>FIXTURENAME</code> is name of your fixtu... | 1 | 2016-09-25T10:19:08Z | [
"python",
"django",
"django-models",
"django-migrations"
] |
Trying to use pandas pivot like excel pivot | 39,685,518 | <p>I have a pandas data frame like this that I want to pivot using pd.pivot_table</p>
<pre><code>import pandas
df = pd.DataFrame({"Id":[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10],
"Error":[0, 99, 0, 0, 0, 98, 0, 0, 0, 0, 33, 0, 23, 0, 0, 0, 83, 0]})
</code></pre>
<p>Im trying to pivot i... | 0 | 2016-09-25T09:50:58Z | 39,685,532 | <p>IIUC you can do it this way:</p>
<pre><code>In [7]: df.pivot_table(index='Id', columns='Error', aggfunc='size', fill_value=0)
Out[7]:
Error 0 23 33 83 98 99
Id
1 1 0 0 0 0 1
2 2 0 0 0 0 0
3 1 0 0 0 1 0
4 2 0 0 0 0 0
5 2 0 0 0 0 0... | 2 | 2016-09-25T09:52:59Z | [
"python",
"excel",
"pandas",
"dataframe",
"pivot"
] |
GraphAPIError: An active access token must be used to query information about the current user | 39,685,650 | <p>On Facebook GraphAPI, with the Python SDK, I am trying to send a notification to a user. I receive the error:</p>
<pre><code>GraphAPIError: An active access token must be used to query information about the current user
</code></pre>
<p>My Python code is:</p>
<pre><code>graph = facebook.GraphAPI(access_token=TO... | 0 | 2016-09-25T10:07:10Z | 39,688,017 | <p>Solution:</p>
<pre><code>graph = facebook.GraphAPI(access_token=TOKENS["user_token"])
user_info= graph.get_object(id='me', fields='id')
graph = facebook.GraphAPI(access_token=TOKENS["app_token"])
graph.put_object(parent_object= user_info['id'], connection_name='notifications', template='Tell us how you like the ... | 0 | 2016-09-25T14:33:45Z | [
"python",
"facebook",
"facebook-graph-api"
] |
Do something to every row on a pandas dataframe | 39,685,737 | <p>Im trying to do something to a pandas dataframe as follows:</p>
<p>If say row 2 has a 'nan' value in the 'start' column, then I can replace all row entries with '999999'</p>
<pre><code>if pd.isnull(dfSleep.ix[2,'start']):
dfSleep.ix[2,:] = 999999
</code></pre>
<p>The above code works but I want to do it for e... | 0 | 2016-09-25T10:17:22Z | 39,685,789 | <p>UPDATE:</p>
<pre><code>In [63]: df
Out[63]:
a b c
0 0 3 NaN
1 3 7 5.0
2 0 5 NaN
3 4 1 6.0
4 7 9 NaN
In [64]: df.ix[df.c.isnull()] = [999999] * len(df.columns)
In [65]: df
Out[65]:
a b c
0 999999 999999 999999.0
1 3 7 5.0
2 999999 999999 999999.0
... | 1 | 2016-09-25T10:23:39Z | [
"python",
"pandas",
"dataframe"
] |
Do something to every row on a pandas dataframe | 39,685,737 | <p>Im trying to do something to a pandas dataframe as follows:</p>
<p>If say row 2 has a 'nan' value in the 'start' column, then I can replace all row entries with '999999'</p>
<pre><code>if pd.isnull(dfSleep.ix[2,'start']):
dfSleep.ix[2,:] = 999999
</code></pre>
<p>The above code works but I want to do it for e... | 0 | 2016-09-25T10:17:22Z | 39,685,898 | <p>I think <code>row</code> in your approach is not an row index. It's a row of the DataFrame</p>
<p>You can use this instead:</p>
<pre><code>for row in df.iterrows():
if pd.isnull(dfSleep.ix[row[0],'start']):
dfSleep.ix[row[0],:] = 999999
</code></pre>
| 1 | 2016-09-25T10:36:55Z | [
"python",
"pandas",
"dataframe"
] |
Calculate sklearn.roc_auc_score for multi-class | 39,685,740 | <p>I would like to calculate AUC, precision, accuracy for my classifier.
I am doing supervised learning:</p>
<p>Here is my working code.
This code is working fine for binary class, but not for multi class.
Please assume that you have a dataframe with binary classes:</p>
<pre><code>sample_features_dataframe = self._g... | 0 | 2016-09-25T10:17:43Z | 39,693,007 | <p>You can't use <code>roc_auc</code> as a single summary metric for multiclass models. If you want, you could calculate per-class <code>roc_auc</code>, as </p>
<pre><code>roc = {label: [] for label in multi_class_series.unique()}
for label in multi_class_series.unique():
selected_classifier.fit(train_set_datafram... | 3 | 2016-09-26T00:00:46Z | [
"python",
"scikit-learn",
"supervised-learning"
] |
Calculate sklearn.roc_auc_score for multi-class | 39,685,740 | <p>I would like to calculate AUC, precision, accuracy for my classifier.
I am doing supervised learning:</p>
<p>Here is my working code.
This code is working fine for binary class, but not for multi class.
Please assume that you have a dataframe with binary classes:</p>
<pre><code>sample_features_dataframe = self._g... | 0 | 2016-09-25T10:17:43Z | 39,703,870 | <p>The <code>average</code> option of <code>roc_auc_score</code> is only defined for multilabel problems.</p>
<p>You can take a look at the following example from the scikit-learn documentation to define you own micro- or macro-averaged scores for multiclass problems:</p>
<p><a href="http://scikit-learn.org/stable/au... | 2 | 2016-09-26T13:13:06Z | [
"python",
"scikit-learn",
"supervised-learning"
] |
How to make a new filter and apply it on an image using cv2 in python2.7? | 39,685,757 | <p>How to make a new filter and apply it on an image using cv2 in python2.7?</p>
<p>For example:</p>
<pre><code>kernel = np.array([[-1, -1, -1],
[-1, 4, -1],
[-1, -1, -1]])
</code></pre>
<p>i'm new to opencv so if you can explain that'd be great. thanks!</p>
| 2 | 2016-09-25T10:19:22Z | 39,687,055 | <p>As far as applying a custom kernel to a given image you may simply use <a href="http://docs.opencv.org/3.1.0/d4/d13/tutorial_py_filtering.html" rel="nofollow">filter2D</a> method to feed in a custom filter. You may also copy the following code to get you going. But The results with current filter seem a bit weird:</... | 3 | 2016-09-25T12:52:57Z | [
"python",
"python-2.7",
"opencv"
] |
How to make a new filter and apply it on an image using cv2 in python2.7? | 39,685,757 | <p>How to make a new filter and apply it on an image using cv2 in python2.7?</p>
<p>For example:</p>
<pre><code>kernel = np.array([[-1, -1, -1],
[-1, 4, -1],
[-1, -1, -1]])
</code></pre>
<p>i'm new to opencv so if you can explain that'd be great. thanks!</p>
| 2 | 2016-09-25T10:19:22Z | 39,687,099 | <p>You can just adapt the code at <a href="http://docs.opencv.org/3.1.0/d4/d13/tutorial_py_filtering.html" rel="nofollow">http://docs.opencv.org/3.1.0/d4/d13/tutorial_py_filtering.html</a>.
That is an OpenCV 3 page but it will work for OpenCV 2.</p>
<p>The only difference in the code below is how the kernel is set.</p... | 2 | 2016-09-25T12:57:33Z | [
"python",
"python-2.7",
"opencv"
] |
error using where with pandas and categorical columns | 39,685,764 | <p>Problem: using the where clause with a dataframe with categorical columns produces <strong>ValueError: Wrong number of dimensions</strong></p>
<p>I Just can't figure out what am I doing wrong.</p>
<pre><code>df=pd.read_csv("F:/python/projects/mail/Inbox_20160911-1646/rows.csv",header=0,sep=",",quotechar="'",quotin... | 1 | 2016-09-25T10:19:54Z | 39,685,946 | <p>Here is a small demo, that reproduces your error:</p>
<pre><code>In [11]: df = pd.DataFrame(np.random.randint(0, 10, (5,3)), columns=list('abc'))
In [12]: df
Out[12]:
a b c
0 9 9 8
1 5 6 1
2 2 9 8
3 8 1 3
4 1 5 1
</code></pre>
<p>this works:</p>
<pre><code>In [13]: df > 1
Out[13]:
a... | 0 | 2016-09-25T10:43:10Z | [
"python",
"pandas",
"categorical-data"
] |
Conversion of integers to Roman numerals (python) | 39,685,765 | <p>I understand there were many similar questions being asked on this topic. But I still have some doubts need to be clear.</p>
<pre><code>def int_to_roman(input):
if type(input) != type(1):
raise TypeError, "expected integer, got %s" % type(input)
if not 0 < input < 4000:
raise ValueErr... | -2 | 2016-09-25T10:19:56Z | 39,685,825 | <p>The names of the two lists are awful (<code>ints</code> and <code>nums</code>). </p>
<p>However, starting with the highest roman numeral (<code>nums[0]</code> = 'M'), the loop finds out how many times the value of that numeral (<code>ints[0]</code> = 1000) divides into the input value, and appends the numeral that... | 1 | 2016-09-25T10:27:12Z | [
"python",
"python-2.7",
"function",
"roman-numerals"
] |
Conversion of integers to Roman numerals (python) | 39,685,765 | <p>I understand there were many similar questions being asked on this topic. But I still have some doubts need to be clear.</p>
<pre><code>def int_to_roman(input):
if type(input) != type(1):
raise TypeError, "expected integer, got %s" % type(input)
if not 0 < input < 4000:
raise ValueErr... | -2 | 2016-09-25T10:19:56Z | 39,685,870 | <p>The two lists, <code>ints</code> and <code>nums</code> are the same length. The loop iterates over the length of <code>ints</code>, which means that the variable <code>i</code> can access the same position of either list, matching one to the other.</p>
<p>If we step through the loop, <code>count</code> is assigned... | 1 | 2016-09-25T10:32:54Z | [
"python",
"python-2.7",
"function",
"roman-numerals"
] |
how to change file name and extension in pyhon? | 39,685,775 | <p>I want to move and rename file called <code>malicious.txt</code> located at path <code>/home/dina/A</code> to a new location <code>/home/dina/b</code> with a new name based on <code>apkName</code> (e.g. <code>a.apk</code> or <code>b.apk</code>, etc) I want the final name to have <code>.json</code> extension instead ... | -1 | 2016-09-25T10:21:33Z | 39,686,594 | <p>The following should rename "malicious.txt" to be name of apkfile with extension of ".json"</p>
<pre><code>import os
apkName = "a.apk"
apkFullpath = os.path.join(os.path.sep,"home","dina","a",apkName)
jsonName = os.path.splitext(apkName)[0]+".json"
jsonFullpath = os.path.join(os.path.sep,"home","dina","b",jsonName)... | 0 | 2016-09-25T12:05:13Z | [
"python"
] |
Assertion error, eventhough my return value is the same | 39,685,804 | <pre><code>def interleave(s1,s2): #This function interleaves s1,s2 together
guess = 0
total = 0
while (guess < len(s1)) and (guess < len(s2)):
x = s1[guess]
y = s2[guess]
m = x + y
print ((m),end ="")
guess += 1
if (len(s1) == len(s2)):
return ("")
... | -1 | 2016-09-25T10:25:04Z | 39,686,026 | <p>You are confusing what is printed by interleave() from what is returned by it. The assert is testing the returned value. For example, when s1 and s2 are the same length, your code prints the interleave (on the <code>print((m),end="")</code> line) but returns an empty string (in the line <code>return ("")</code></p>
... | 1 | 2016-09-25T10:51:14Z | [
"python"
] |
Assertion error, eventhough my return value is the same | 39,685,804 | <pre><code>def interleave(s1,s2): #This function interleaves s1,s2 together
guess = 0
total = 0
while (guess < len(s1)) and (guess < len(s2)):
x = s1[guess]
y = s2[guess]
m = x + y
print ((m),end ="")
guess += 1
if (len(s1) == len(s2)):
return ("")
... | -1 | 2016-09-25T10:25:04Z | 39,686,082 | <p>The problem is that your function just prints the interleaved portion of the resulting string, it doesn't return it, it only returns the tail of the longer string.</p>
<p>Here's a repaired and simplified version of your code. You don't need to do those <code>if... elif</code> tests. Also, your code has a lot of sup... | 0 | 2016-09-25T10:58:15Z | [
"python"
] |
Complex search in xml using lxml | 39,685,806 | <p><strong>Background</strong> I am trying to read a password from a keepass2 file using <a href="https://github.com/phpwutz/libkeepass" rel="nofollow">libkeepass</a> python library.</p>
<p>Using <a href="http://lxml.de/" rel="nofollow">lxml</a> (beause that is what libkeepass gives me) I have to search for an entry l... | 1 | 2016-09-25T10:25:08Z | 39,685,834 | <p>I just realized, I can navigate up using "..". So the solution is:</p>
<pre><code>kdb.obj_root.findall(".//Entry/String[Key='Title'][Value='MyPassword']/../String[Key='Password']/Value")
</code></pre>
| 1 | 2016-09-25T10:27:57Z | [
"python",
"lxml"
] |
Complex search in xml using lxml | 39,685,806 | <p><strong>Background</strong> I am trying to read a password from a keepass2 file using <a href="https://github.com/phpwutz/libkeepass" rel="nofollow">libkeepass</a> python library.</p>
<p>Using <a href="http://lxml.de/" rel="nofollow">lxml</a> (beause that is what libkeepass gives me) I have to search for an entry l... | 1 | 2016-09-25T10:25:08Z | 39,686,298 | <p>Alternatively, instead of going down to <code>String</code>, back up to <code>Entry</code> and then down again to another <code>String</code>, you can just use predicate on <code>Entry</code> element and then return the target <code>String</code> element from there. </p>
<p>Since you're using <code>lxml</code>, I'd... | 1 | 2016-09-25T11:27:56Z | [
"python",
"lxml"
] |
Python 3 defining a variable within a function | 39,685,969 | <p>I am working on my own code to encrypt/decrypt messages and all is working fine. Now I am just trying to tidy up the code a bit and I'm also trying to add error catching. I want to make this error catching within a function so I don't have to type out the error catching like 6 times within one block of code.</p>
<p... | -1 | 2016-09-25T10:45:27Z | 39,689,152 | <p>You are getting an error when you remove line 3 of your example as you are removing the definition of test1.</p>
<p>It isn't neccessary to pass values to a function in order to return them, a more general application of the same code is as follows:</p>
<pre><code>def wait_and_validate (validation_list):
while ... | 0 | 2016-09-25T16:26:26Z | [
"python",
"function"
] |
Is it possible to test a REST API against documentation in Django? | 39,685,973 | <p>I develop a RESTful API server using Django REST Framework, and while the app matures, entity signatures sometimes change.</p>
<p>While writing tests for this app, I began to wonder if there are tools to check that API returns data as stated in documentation, i.e. User entity contains all the required fields etc.</... | 0 | 2016-09-25T10:45:43Z | 39,691,509 | <p>Why won't you test it with simple unit tests?
I assume that you have your API urls mapped properly to Django'u url_patterns.</p>
<p>Then you can simply unit test them with Django REST Framework <a href="http://www.django-rest-framework.org/api-guide/testing/#test-cases" rel="nofollow">Test Cases</a></p>
<p>Here is... | 0 | 2016-09-25T20:27:15Z | [
"python",
"django",
"rest",
"testing"
] |
Is it possible to test a REST API against documentation in Django? | 39,685,973 | <p>I develop a RESTful API server using Django REST Framework, and while the app matures, entity signatures sometimes change.</p>
<p>While writing tests for this app, I began to wonder if there are tools to check that API returns data as stated in documentation, i.e. User entity contains all the required fields etc.</... | 0 | 2016-09-25T10:45:43Z | 39,691,858 | <p>There are dedicated tools for API documentation (i.e. Swagger: <a href="http://swagger.io/" rel="nofollow">http://swagger.io/</a>). You can also google for "API contracting".</p>
<p>You can validate your server against API spec using DREDD (<a href="http://dredd.readthedocs.io/en/latest/" rel="nofollow">http://dred... | 0 | 2016-09-25T21:07:54Z | [
"python",
"django",
"rest",
"testing"
] |
Addition of every two columns | 39,686,055 | <p>I would like calculate the sum of two in two column in a matrix(the sum between the columns 0 and 1, between 2 and 3...).</p>
<p>So I tried to do nested "for" loops but at every time I haven't the good results.</p>
<p>For example:</p>
<pre><code>c = np.array([[0,0,0.25,0.5],[0,0.5,0.25,0],[0.5,0,0,0]],float)
freq... | 1 | 2016-09-25T10:54:12Z | 39,686,134 | <p>Here is one way using <code>np.split()</code>:</p>
<pre><code>In [36]: np.array(np.split(c, np.arange(2, c.shape[1], 2), axis=1)).sum(axis=-1)
Out[36]:
array([[ 0. , 0.5 , 0.5 ],
[ 0.75, 0.25, 0. ]])
</code></pre>
<p>Or as a more general way even for odd length arrays:</p>
<pre><code>In [87]: def ve... | 2 | 2016-09-25T11:05:38Z | [
"python",
"numpy"
] |
Addition of every two columns | 39,686,055 | <p>I would like calculate the sum of two in two column in a matrix(the sum between the columns 0 and 1, between 2 and 3...).</p>
<p>So I tried to do nested "for" loops but at every time I haven't the good results.</p>
<p>For example:</p>
<pre><code>c = np.array([[0,0,0.25,0.5],[0,0.5,0.25,0],[0.5,0,0,0]],float)
freq... | 1 | 2016-09-25T10:54:12Z | 39,686,188 | <p>You can simply reshape to split the last dimension into two dimensions, with the last dimension of length <code>2</code> and then sum along it, like so -</p>
<pre><code>freq = c.reshape(c.shape[0],-1,2).sum(2).T
</code></pre>
<p>Reshaping only creates a view into the array, so effectively, we are just using the su... | 3 | 2016-09-25T11:13:53Z | [
"python",
"numpy"
] |
Addition of every two columns | 39,686,055 | <p>I would like calculate the sum of two in two column in a matrix(the sum between the columns 0 and 1, between 2 and 3...).</p>
<p>So I tried to do nested "for" loops but at every time I haven't the good results.</p>
<p>For example:</p>
<pre><code>c = np.array([[0,0,0.25,0.5],[0,0.5,0.25,0],[0.5,0,0,0]],float)
freq... | 1 | 2016-09-25T10:54:12Z | 39,686,325 | <p>Add the slices <code>c[:, ::2]</code> and <code>c[:, 1::2]</code>:</p>
<pre><code>In [62]: c
Out[62]:
array([[ 0. , 0. , 0.25, 0.5 ],
[ 0. , 0.5 , 0.25, 0. ],
[ 0.5 , 0. , 0. , 0. ]])
In [63]: c[:, ::2] + c[:, 1::2]
Out[63]:
array([[ 0. , 0.75],
[ 0.5 , 0.25],
[ 0.5... | 3 | 2016-09-25T11:31:53Z | [
"python",
"numpy"
] |
Find edges of images | 39,686,084 | <p>I have software that generates several images like the following four images:</p>
<p><a href="http://i.stack.imgur.com/XwbtA.png" rel="nofollow"><img src="http://i.stack.imgur.com/XwbtA.png" alt="image 01"></a></p>
<p><a href="http://i.stack.imgur.com/OiezM.png" rel="nofollow"><img src="http://i.stack.imgur.com/Oi... | 0 | 2016-09-25T10:58:47Z | 39,780,360 | <p>The simplest thing to try is to:</p>
<ul>
<li>Convert your images to binary images (by a simple threshold)</li>
<li>Apply the Hough transform (OpenCV, Matlab have it already implemented)</li>
<li>In the Hough transform results, detect the peaks for angles 0 degree, + and - 90 degrees. (Vertical and horizontal lines... | 1 | 2016-09-29T21:31:55Z | [
"python",
"algorithm",
"python-2.7",
"numpy",
"image-processing"
] |
How to ignore or override calls to all methods of a class for testing | 39,686,119 | <p>I have set up a unit test that looks around like that:</p>
<pre><code>from unittest import TestCase
from . import main
from PIL import Image
class TestTableScreenBased(TestCase):
def test_get_game_number_on_screen2(self):
t = main.TableScreenBased()
t.entireScreenPIL = Image.open('tests/1773793_Pre... | 0 | 2016-09-25T11:02:58Z | 39,686,492 | <p>If you are using Python >= 3.3 you can use the built in <a href="https://docs.python.org/3/library/unittest.mock.html" rel="nofollow">unittest.mock</a> module. If you are using an earlier version of Python you can use the same tools by installing <a href="https://pypi.python.org/pypi/mock" rel="nofollow">the backpo... | 1 | 2016-09-25T11:52:45Z | [
"python",
"unit-testing"
] |
Pandas: How to open certain files | 39,686,132 | <p>I am currently working on the data set from this <a href="https://github.com/smarthi/UnivOfWashington-Machine-Learning/tree/master/MLFoundations/week4/people_wiki.gl" rel="nofollow">link</a>. But I am unable to read these files from Pandas? Has anyone tried to play with such files?</p>
<p>I am trying the following:... | 2 | 2016-09-25T11:05:21Z | 39,686,244 | <p>Those files are parts of a saved <a href="https://turi.com/products/create/docs/generated/graphlab.SFrame.html" rel="nofollow">SFrame</a>.</p>
<p>So you can load them this way:</p>
<pre><code>import sframe
sf = sframe.SFrame('/path/to/dir/')
</code></pre>
<p>Demo: I've downloaded all files from <a href="https://... | 3 | 2016-09-25T11:21:35Z | [
"python",
"python-2.7",
"pandas",
"dataframe"
] |
Pandas: How to open certain files | 39,686,132 | <p>I am currently working on the data set from this <a href="https://github.com/smarthi/UnivOfWashington-Machine-Learning/tree/master/MLFoundations/week4/people_wiki.gl" rel="nofollow">link</a>. But I am unable to read these files from Pandas? Has anyone tried to play with such files?</p>
<p>I am trying the following:... | 2 | 2016-09-25T11:05:21Z | 39,686,415 | <p>Just clarifying on the answer by <a href="http://stackoverflow.com/a/39686244/6842947">MaxU</a>, you are trying to read it the wrong way. It is a raw file and its formatting is contained in the other files which are there in the same folder in that <a href="https://github.com/smarthi/UnivOfWashington-Machine-Learnin... | 2 | 2016-09-25T11:42:53Z | [
"python",
"python-2.7",
"pandas",
"dataframe"
] |
Python text game - Cant exit a while loop | 39,686,135 | <p>this is the main code:</p>
<pre><code>import MainMod
print("Welcome!")
print("Note: In this games you use wasd+enter to move!\nYou press 1 key and then enter,if you press multiple kets it wont work.\nYou will always move by 5 meters.")
CurrentRoom = 1
#Limits work this way!1st and 2nd number are X values(1st is &l... | 0 | 2016-09-25T11:05:48Z | 39,686,850 | <p>Since I could not imagine it didn't work, I added two markers (print commands), to room 1 and 2:</p>
<pre><code>while CurrentRoom == 1:
print("one")
mod.MainLel()
</code></pre>
<p>and</p>
<pre><code>while CurrentRoom == 2:
print("two")
mod.MainLel()
</code></pre>
<p>This is what happened:</p>
<p... | 1 | 2016-09-25T12:32:38Z | [
"python"
] |
SMTP AUTH extension not supported by server in python | 39,686,141 | <p>I'm using the following def to send email based on status , </p>
<pre><code>def sendMail(fbase, status):
server = smtplib.SMTP(config["global"]["smtp_server"], config["global"]["smtp_port"])
server.login(config["global"]["smtp_user"],config["global"]["smtp_pass"])
server.ehlo()
server.starttls()
... | 0 | 2016-09-25T11:07:24Z | 39,686,285 | <p>Perform the login step <em>after</em> you've started TLS.</p>
<pre><code>def sendMail(fbase, status):
server = smtplib.SMTP(config["global"]["smtp_server"], config["global"]["smtp_port"])
server.ehlo()
server.starttls()
server.login(config["global"]["smtp_user"],config["global"]["smtp_pass"])
... | 0 | 2016-09-25T11:26:29Z | [
"python",
"python-2.7"
] |
NetworkX most efficient way to find the longest path in a DAG at start vertex with no errors | 39,686,213 | <p>Starting from a certain vertex, how would one find the longest path relative to that vertex? I've been browsing all over and can't find a solution to this problem which actually works for all possible cases of DAGs. Source code in NetworkX would be preferred but regular python is fine too. Im genuinely curious as to... | -1 | 2016-09-25T11:16:46Z | 39,687,051 | <p>First, I would check if this graph is connected. If so, then the longest path is the path across all nodes. If not, it means this vertex is contained in a connected component. Then I would use <a href="https://networkx.github.io/documentation/networkx-1.9.1/reference/generated/networkx.algorithms.components.connecte... | 0 | 2016-09-25T12:52:32Z | [
"python",
"python-3.x",
"networkx",
"directed-acyclic-graphs",
"longest-path"
] |
Python program that sends txt file to email | 39,686,410 | <p>I've recently created a python keylogger. The code is :</p>
<pre><code>import win32api
import win32console
import win32gui
import pythoncom,pyHook
win=win32console.GetConsoleWindow()
win32gui.ShowWindow(win,0)
def OnKeyboardEvent(event):
if event.Ascii==5:
_exit(1)
if event.Ascii !=0 or 8:
#open output.txt to... | -3 | 2016-09-25T11:42:27Z | 39,686,489 | <p><a href="https://docs.python.org/3/library/email-examples.html" rel="nofollow">The python docs has good documentation of emails in python.</a></p>
<pre><code># Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain te... | 0 | 2016-09-25T11:52:27Z | [
"python",
"keylogger"
] |
What does python return on the leap second | 39,686,553 | <p>What does python <code>time</code> and <code>datetime</code> module return on the leap second?</p>
<p>What will I get when we are at <em>23:59:60.5</em> if I call:</p>
<ul>
<li><code>time.time()</code></li>
<li><code>datetime.datetime.utcnow()</code></li>
<li><code>datetime.datetime.now(pytz.utc)</code></li>
</ul>... | 4 | 2016-09-25T11:59:26Z | 39,686,629 | <p>Leap seconds are occasionally <em>manually</em> scheduled. Currently, computer clocks have no facility to honour leap seconds; there is no standard to tell them up-front to insert one. Instead, computer clocks periodically re-synch their time keeping via the NTP protocol and adjust automatically after the leap secon... | 2 | 2016-09-25T12:08:58Z | [
"python",
"datetime",
"time",
"leap-second"
] |
Add elements properly to a ListStore in python | 39,686,558 | <p>I have a textfile with the current data:</p>
<pre><code>Firefox 2002 C++
Eclipse 2004 Java
Pitivi 2004 Python
Netbeans 1996 Java
Chrome 2008 C++
Filezilla 2001 C++
Bazaar 2005 Python
Git 2005 C
Linux Kernel 1991 C
GCC 1987 C
Frostwire 2004 Java
</code></pre>
<p>I want to read it from my python program and add it ... | 0 | 2016-09-25T12:01:06Z | 39,813,485 | <p>Ok, line 9 in data.txt is:</p>
<pre><code>Linux Kernel 1991 C
</code></pre>
<p>which contains 4 elements. Try:</p>
<pre><code>Linux_Kernel 1991 C
</code></pre>
<p>or simply:</p>
<pre><code>Linux 1991 C
</code></pre>
| 0 | 2016-10-02T03:08:32Z | [
"python",
"gtk",
"pygobject"
] |
Python: Converting multiple files from xls to csv | 39,686,591 | <p>I'm trying to write a script in Python 2.7 that would convert all .xls and .xlsx files in the current directory into .csv with preserving their original file names.</p>
<p>With help from other similar questions here (sadly, not sure who to credit for the pieces of code I borrowed), here's what I've got so far:</p>
... | 0 | 2016-09-25T12:04:39Z | 39,686,752 | <p>One possible solution would be using <code>glob</code> and <a href="http://pandas.pydata.org/pandas-docs/stable/io.html" rel="nofollow"><code>pandas</code></a>.</p>
<pre><code>excel_files = glob('*xls*')
for excel in excel_files:
out = excel.split('.')[0]+'.csv'
df = pd.read_excel(excel, 'Sheet1')
df.... | 1 | 2016-09-25T12:22:19Z | [
"python",
"excel",
"csv"
] |
Merging the 2 lists into 1 which are values in a Dictionary | 39,686,642 | <p>Hello all I am very new to the programming.</p>
<p>I have a dictC</p>
<p>dictC = {'a':[1,2,3,4,5],'b':[5,6,7,8,9,10]}</p>
<p>I want my output like </p>
<p>mergedlist = [1,2,3,4,5,6,7,8,9,10]</p>
<p>Could any one help me with the logic to define a function?</p>
<p>I have tried some thing like this </p>
<p>ente... | 0 | 2016-09-25T12:10:22Z | 39,686,689 | <pre><code>mergedlist = dictC['a']+ dictC['b']
</code></pre>
<p>edit - wait - do you know there are repeated elements in the list( last element of list 1 is 5, but so is the first element of list 2) - is this an invariant feature of the data. More info required I think..</p>
| 0 | 2016-09-25T12:15:29Z | [
"python",
"python-2.7",
"python-3.x"
] |
Merging the 2 lists into 1 which are values in a Dictionary | 39,686,642 | <p>Hello all I am very new to the programming.</p>
<p>I have a dictC</p>
<p>dictC = {'a':[1,2,3,4,5],'b':[5,6,7,8,9,10]}</p>
<p>I want my output like </p>
<p>mergedlist = [1,2,3,4,5,6,7,8,9,10]</p>
<p>Could any one help me with the logic to define a function?</p>
<p>I have tried some thing like this </p>
<p>ente... | 0 | 2016-09-25T12:10:22Z | 39,686,855 | <pre><code>def MergeDictValues(dictC):
return [x for y in dictC.values() for x in y]
</code></pre>
<p>Input :</p>
<pre><code>dictC = {'a':[1,2,3,4,5],'b':[5,6,7,8,9,10]}
MergeDictValues(dictC)
</code></pre>
<p>Out put :</p>
<pre><code>[1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10]
</code></pre>
| 0 | 2016-09-25T12:33:06Z | [
"python",
"python-2.7",
"python-3.x"
] |
How can I have a spinner while waiting for socket.accept? | 39,686,644 | <p>I have a spinner right here:</p>
<pre><code>spinner = itertools.cycle(['-', '/', '|', '\\'])
while True:
sys.stdout.write(spinner.next())
sys.stdout.flush()
sys.stdout.write('\b')
time.sleep(0.1)
</code></pre>
<p>I'm stuck at my code</p>
<pre><code>server = socket.socket(socket.AF_INET, socket.SOC... | 0 | 2016-09-25T12:10:36Z | 39,688,037 | <p>You should set a timeout before calling <code>accept()</code> in a loop. See here: <a href="http://stackoverflow.com/questions/7354476/python-socket-object-accept-time-out">python socket object accept time out</a> for details on how, but the idea is to try to accept a new connection for say 0.1 seconds, then bump t... | 0 | 2016-09-25T14:35:58Z | [
"python",
"python-2.7"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.