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 |
|---|---|---|---|---|---|---|---|---|---|
Sklearn kNN usage with a user defined metric (again) | 37,626,043 | <p>Someone posted a similar question here but i couldn't get my job done</p>
<p>see</p>
<p><a href="http://stackoverflow.com/questions/21052509/sklearn-knn-usage-with-a-user-defined-metrgammaic">Sklearn kNN usage with a user defined metric</a></p>
<p>i want to define my user_metric and use it in KNN
I have a signatu... | 0 | 2016-06-04T03:29:02Z | 37,634,618 | <p>From <a href="http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html" rel="nofollow">KNeighborsClassifier documentation</a> : the <code>metric</code> argument must be a string or <a href="http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html" rel... | 0 | 2016-06-04T20:16:50Z | [
"python",
"scikit-learn",
"knn"
] |
Sklearn kNN usage with a user defined metric (again) | 37,626,043 | <p>Someone posted a similar question here but i couldn't get my job done</p>
<p>see</p>
<p><a href="http://stackoverflow.com/questions/21052509/sklearn-knn-usage-with-a-user-defined-metrgammaic">Sklearn kNN usage with a user defined metric</a></p>
<p>i want to define my user_metric and use it in KNN
I have a signatu... | 0 | 2016-06-04T03:29:02Z | 37,741,405 | <p>my question was very stupid</p>
<p>the syntax was correct</p>
<p>the problem is that exponentiation in python is not with ^ but with **</p>
<p>hence 16=2**4 instead of 2^4</p>
| 0 | 2016-06-10T06:34:42Z | [
"python",
"scikit-learn",
"knn"
] |
Permission denied when saving to file as text, a | 37,626,050 | <p>When I am trying to save to a file, it denies me permission. It raises an error:</p>
<pre><code>PermissionError: [Errno 13] Permission denied: 'BLAH.txt'
</code></pre>
<p>However, when I do it in pycharm the data is saved without an error. Here is my code: </p>
<pre><code>save = name + ": " + "RoundNo: " + str(ro... | -1 | 2016-06-04T03:29:38Z | 37,626,206 | <p>The problem can be following: </p>
<p>(I am assuming that you are using windows here based on your screenshot).</p>
<p>You are trying to save the file at a place where windows doesn't allow to save without admin privileges. A python script won't with admin privileges unless invoked from admin command line. The rea... | 0 | 2016-06-04T04:00:07Z | [
"python"
] |
Permission denied when saving to file as text, a | 37,626,050 | <p>When I am trying to save to a file, it denies me permission. It raises an error:</p>
<pre><code>PermissionError: [Errno 13] Permission denied: 'BLAH.txt'
</code></pre>
<p>However, when I do it in pycharm the data is saved without an error. Here is my code: </p>
<pre><code>save = name + ": " + "RoundNo: " + str(ro... | -1 | 2016-06-04T03:29:38Z | 37,626,289 | <p>I copied the code into another file and it worked</p>
| 0 | 2016-06-04T04:15:37Z | [
"python"
] |
Scrapy with proxies using downloader middleware | 37,626,063 | <p>I'm new to Scrapy and I am trying to build my own Downloader Middleware in order to go through a proxy to scrape the web. I am getting this error:</p>
<pre><code>Traceback (most recent call last):
File "/Users/bli1/Development/projects/hinwin/chisel/lib/python2.7/site-packages/twisted/internet/defer.py", line 112... | 0 | 2016-06-04T03:32:53Z | 37,626,453 | <p>According to the <a href="http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#activating-a-downloader-middleware" rel="nofollow">docs</a> the path should include the project (<code>'myproject.middlewares.CustomDownloaderMiddleware'</code>) in your case I think it should be:</p>
<pre><code>'chisel.down... | 1 | 2016-06-04T04:43:50Z | [
"python",
"proxy",
"scrapy"
] |
Python function to populate multiple tables in PyQt | 37,626,112 | <p>I have a class with multiple functions and in, almost, everyone of them I have to populate different QTableWidgets. <strong>I would like to make a function that given a tables name, headers and data populates the said table.</strong></p>
<p>This is working (but static and works just for one table "tableParada"):</p... | 0 | 2016-06-04T03:42:05Z | 37,633,569 | <p>Try passing <code>self.ui.tableParada</code> instead of the string <code>'tableParada'</code>. You need to pass the actual widget object.</p>
| 0 | 2016-06-04T18:18:04Z | [
"python",
"python-3.x",
"object",
"pyqt",
"qtablewidget"
] |
How to add a placeholder attribute in Django Form | 37,626,119 | <p>I am having trouble in adding a placeholder attribute in my forms. I want to add a placeholder that will make my HTML look like:</p>
<pre><code><input type="text" name="sample" placeholder="sample">
</code></pre>
<p>Right now this is my codes look like.</p>
<p>This is my Models:</p>
<pre><code>from django.... | 0 | 2016-06-04T03:42:59Z | 37,626,188 | <p>in form itself, this works for me always </p>
<pre><code>class SampleForm(ModelForm):
class Meta:
model = Sample
name = forms.CharField(
label='Name',
widget=forms.TextInput(
attrs={'class': 'form-control', 'placeholder': 'Enter title here'}
)
)
</code></pre... | 0 | 2016-06-04T03:56:54Z | [
"python",
"django",
"forms",
"placeholder"
] |
How to write a binary search that looks for words in a list | 37,626,130 | <p>I was wondering how to write a binary search that looks for the most popular baby names from 2009 - 2014, the names are stored in a list and then I when I receive a prompt asking for what i would like to search for then i would type in the name and it would give how many times it iterated over to find the certain na... | -1 | 2016-06-04T03:45:02Z | 37,626,226 | <p>Why do you need to use a binary search? What if you used <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow"><code>collections.Counter</code></a>?</p>
<p>Just pass your list (doesn't matter if it's sorted or not) of baby names to <code>Counter</code> and then lookup whate... | 1 | 2016-06-04T04:03:23Z | [
"python",
"binary",
"dataset",
"binary-search"
] |
write a program that determines if user input is even or odd and loops | 37,626,194 | <p>I am trying to make a program that will continuously take a user input and determine if the user input is even or odd. The program will only stop when zero is entered.</p>
<p>However, when I enter zero, it <code>print</code>s <code>0 is an even number</code> followed by <code>All done!</code>. The expected output i... | -3 | 2016-06-04T03:57:46Z | 37,626,221 | <p>The problem here is that when Python reads your code, it reads it top down. When it reaches <code>if entry % 2 == 0:</code> first and will output whatever that is there. Then it continues to <code>if entry == 0</code> and outputs whatever that's there again.</p>
<p>What you want is that it should go to one code blo... | 0 | 2016-06-04T04:03:04Z | [
"python",
"loops",
"break"
] |
write a program that determines if user input is even or odd and loops | 37,626,194 | <p>I am trying to make a program that will continuously take a user input and determine if the user input is even or odd. The program will only stop when zero is entered.</p>
<p>However, when I enter zero, it <code>print</code>s <code>0 is an even number</code> followed by <code>All done!</code>. The expected output i... | -3 | 2016-06-04T03:57:46Z | 37,626,232 | <p>If you want to check whether the input is zero before doing anything else, do so. If you want to stop the loop in certain conditions, put the <code>break</code> inside a conditional. Note that <code>count</code> and <code>total</code> were unused. Also, <code>format()</code> with no formatting is redundant.</p>
<pr... | 0 | 2016-06-04T04:04:12Z | [
"python",
"loops",
"break"
] |
write a program that determines if user input is even or odd and loops | 37,626,194 | <p>I am trying to make a program that will continuously take a user input and determine if the user input is even or odd. The program will only stop when zero is entered.</p>
<p>However, when I enter zero, it <code>print</code>s <code>0 is an even number</code> followed by <code>All done!</code>. The expected output i... | -3 | 2016-06-04T03:57:46Z | 37,626,235 | <p>You should check for 0 before the <code>entry%2==0</code> condition, ince 0%2==0 it is not breaking the loop.</p>
<p>Secondly use <code>raw_input</code> instead of input.</p>
<pre><code>def main():
total = 0
count = 0
while True:
entry=int(raw_input('Enter a number or 0 to quit:'))
if... | 0 | 2016-06-04T04:04:39Z | [
"python",
"loops",
"break"
] |
write a program that determines if user input is even or odd and loops | 37,626,194 | <p>I am trying to make a program that will continuously take a user input and determine if the user input is even or odd. The program will only stop when zero is entered.</p>
<p>However, when I enter zero, it <code>print</code>s <code>0 is an even number</code> followed by <code>All done!</code>. The expected output i... | -3 | 2016-06-04T03:57:46Z | 37,626,264 | <p>Why not try something like this</p>
<pre><code>if entry == 0:
print ('All done!')
break
else if entry % 2 == 0:
print (format (entry), 'is an even number.')
else:
print (format (entry),'is an odd number.')
</code></pre>
<p>Sorry about the wrong indentation. I'm not really familiar with pyt... | 0 | 2016-06-04T04:10:38Z | [
"python",
"loops",
"break"
] |
Getting the correct colours for pcolormesh | 37,626,225 | <p>I am using pcolormesh to show the results from some algorithm I am running.
I create the usual mesh for some <code>x_min, x_max</code>, etc., and define my color map</p>
<pre><code>h = (x_max - x_min) / 1000.
xx, yy = numpy.meshgrid(numpy.arange(x_min, x_max, h), numpy.arange(y_min, y_max, h))
colours = ("blue", "g... | 2 | 2016-06-04T04:03:20Z | 37,626,452 | <p>You can use <code>clim</code> to fix your colorbar. </p>
<pre><code>plt.clim(0, 3)
</code></pre>
<p>That will force 0 to be blue, 1 to be green, 2 to be red.</p>
| 2 | 2016-06-04T04:43:49Z | [
"python",
"matplotlib"
] |
Getting the correct colours for pcolormesh | 37,626,225 | <p>I am using pcolormesh to show the results from some algorithm I am running.
I create the usual mesh for some <code>x_min, x_max</code>, etc., and define my color map</p>
<pre><code>h = (x_max - x_min) / 1000.
xx, yy = numpy.meshgrid(numpy.arange(x_min, x_max, h), numpy.arange(y_min, y_max, h))
colours = ("blue", "g... | 2 | 2016-06-04T04:03:20Z | 37,626,576 | <p>You have to normalize ColorMap:</p>
<pre><code>import matplotlib.pylab as plt
import numpy as np
from matplotlib.colors import ListedColormap, BoundaryNorm
x_max = 100.
x_min = 0.
y_max = 100.
y_min = 0.
h = (x_max - x_min) / 5.
xx, yy = np.meshgrid(np.arange(x_min, x_max+h, h), np.arange(y_min, y_max+h, h))
Z = n... | 1 | 2016-06-04T05:03:05Z | [
"python",
"matplotlib"
] |
[{'code': 32, 'message': 'Could not authenticate you.'} python 3.x | 37,626,253 | <p>Hi could someone help me with this?</p>
<pre><code>import tweepy
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = '-'
ACCESS_TOKEN_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
status = "Testing!"
api.upd... | -1 | 2016-06-04T04:08:45Z | 37,626,302 | <p>There is nothing wrong with your code, this is an authentication issue. Please refer to <a href="https://dev.twitter.com/overview/api/response-codes" rel="nofollow">https://dev.twitter.com/overview/api/response-codes</a></p>
<blockquote>
<p>Code: 32 </p>
<p>Text: Could not authenticate you</p>
<p>Desc... | 2 | 2016-06-04T04:18:23Z | [
"python",
"python-3.x"
] |
Python Class Calling Issue | 37,626,366 | <p>I am having trouble with calling a def statement from another class. What I am trying to do is get the variable from one class then send it to the other class then send it back down again but I am having trouble doing it.</p>
<p>Here is my attempt at it:</p>
<pre><code>from tkinter import *
from tkinter import ttk... | 0 | 2016-06-04T04:29:25Z | 37,626,454 | <p>The problem is easy: just remove <code>self</code></p>
<p><code>self.measurements.trace('w', Logic.update_length())</code></p>
<p>When you calling a static function is <code>Class.Function()</code>. The <code>self</code> is not put. Reviewing your code, you must create the class <code>Logic</code> because <code>up... | 0 | 2016-06-04T04:43:57Z | [
"python",
"python-3.x"
] |
Python Class Calling Issue | 37,626,366 | <p>I am having trouble with calling a def statement from another class. What I am trying to do is get the variable from one class then send it to the other class then send it back down again but I am having trouble doing it.</p>
<p>Here is my attempt at it:</p>
<pre><code>from tkinter import *
from tkinter import ttk... | 0 | 2016-06-04T04:29:25Z | 37,627,223 | <p>You appear to have a more basic misunderstanding of how class methods work. Without understanding more what the code is supposed to do, I think I can only give some basic advice (as there is a lot that is wrong with your code).</p>
<p><strong>Instance methods --</strong> There are three types of methods you can use... | 1 | 2016-06-04T06:40:15Z | [
"python",
"python-3.x"
] |
i am trying to read a txt based website and it is only reading odd lines | 37,626,369 | <pre><code>import urllib.request
mypage=urllib.request.urlopen("http://cryptocode.net/cs8/cities.txt")
def makelist(URL):
list1=[]
for line in mypage:
s=mypage.readline()
</code></pre>
<p>I want to turn the data on the site into a list. When I type <code>for line in mypage:
print(line)</code> it prints... | -1 | 2016-06-04T04:29:46Z | 37,626,492 | <p>The problem here is that when you are iterating through <code>mypage</code> with your for loop, you are actually reading it twice. Lets say you have a webpage with this text:</p>
<pre><code>Hello
you
Hello
will
Hello
only
Hello
read
Hello
this
</code></pre>
<p>When you read it with:</p>
<pre><code>for line in myp... | 4 | 2016-06-04T04:49:40Z | [
"python",
"list",
"readline"
] |
print function does not show output on sublime text 3 console | 37,626,397 | <p>I have started off with Python today and stuck with a weird problem. I am using Python 3.5.1 and Sublime text 3 and have written a basic hello world program.</p>
<p><code>print('Hello World')</code></p>
<p>Saved this file with the name python1.py and pressed Ctrl+B to execute it but the only thing that shows up on... | 0 | 2016-06-04T04:34:26Z | 37,626,560 | <p>Solved it,</p>
<p>Press <code>Ctrl+Shift+B</code> after which a list pops up, select python from that list and its done. From next time just pressing <code>Ctrl+B</code> will work.</p>
| 1 | 2016-06-04T04:59:51Z | [
"python",
"python-3.x",
"sublimetext3"
] |
print function does not show output on sublime text 3 console | 37,626,397 | <p>I have started off with Python today and stuck with a weird problem. I am using Python 3.5.1 and Sublime text 3 and have written a basic hello world program.</p>
<p><code>print('Hello World')</code></p>
<p>Saved this file with the name python1.py and pressed Ctrl+B to execute it but the only thing that shows up on... | 0 | 2016-06-04T04:34:26Z | 37,626,584 | <p>press <code>Shift-Ctrl-B</code> and select python. That happens because the program only checks if your python program is correctly. The next time just pressing <code>Ctrl+B</code>, will work</p>
| 0 | 2016-06-04T05:04:39Z | [
"python",
"python-3.x",
"sublimetext3"
] |
tensorboard shows no contents | 37,626,407 | <p>I'm having problem with tensorboard. My codes runs fine and when I tried to visualize the graph with tensorboard --logdir = logs/log1 and then open the browser typing in localhost:6006 I saw the page with no content (only tensorboard sign and tabs like event, graph ...)
Help very much appreciated. No idea how t... | 0 | 2016-06-04T04:36:29Z | 37,630,177 | <p>Looks like the problem is related to <a href="https://github.com/tensorflow/tensorflow/issues/1421" rel="nofollow">this issue</a>. Make sure you start tensorboard after running your program. And also see what other people did to solve it. It might be a bug in tensorboard. Do you want to build tensorflow from source?... | 0 | 2016-06-04T12:22:07Z | [
"python",
"tensorflow",
"tensorboard"
] |
tensorboard shows no contents | 37,626,407 | <p>I'm having problem with tensorboard. My codes runs fine and when I tried to visualize the graph with tensorboard --logdir = logs/log1 and then open the browser typing in localhost:6006 I saw the page with no content (only tensorboard sign and tabs like event, graph ...)
Help very much appreciated. No idea how t... | 0 | 2016-06-04T04:36:29Z | 37,632,077 | <p>The errors you get don't bother me. I guess the problem is that you wrote nothing. You can try adding this line <code>writer.flush()</code> after the line of <code>add_summary()</code>.</p>
| 0 | 2016-06-04T15:41:33Z | [
"python",
"tensorflow",
"tensorboard"
] |
Changing many values in dictionary without using name of the keys | 37,626,614 | <p>I want to change all values in dictionary to different ones.
For example, in a dictionary</p>
<pre><code>dic = {'a': 1, 'b':2, 'c':3, 'd':4, 'e': 5, 'f':6}
lst = [100, 200, 300, 400, 500, 600]
</code></pre>
<p>I want to change <code>dic</code>'s values to numbers in <code>lst</code> like
<code>dic = {'a': 100 ,'b'... | 0 | 2016-06-04T05:08:58Z | 37,626,646 | <p>If you need to multiply each number in the <code>dict</code> by 100, you could iterate through all the values at once by using a <a href="https://www.python.org/dev/peps/pep-0274/" rel="nofollow">dict comprehension</a>.</p>
<pre><code>dic = {'a': 1, 'b':2, 'c':3, 'd':4, 'e': 5, 'f':6}
dic = {k: v*100 for k, v in di... | 4 | 2016-06-04T05:15:14Z | [
"python",
"list",
"dictionary"
] |
Changing many values in dictionary without using name of the keys | 37,626,614 | <p>I want to change all values in dictionary to different ones.
For example, in a dictionary</p>
<pre><code>dic = {'a': 1, 'b':2, 'c':3, 'd':4, 'e': 5, 'f':6}
lst = [100, 200, 300, 400, 500, 600]
</code></pre>
<p>I want to change <code>dic</code>'s values to numbers in <code>lst</code> like
<code>dic = {'a': 100 ,'b'... | 0 | 2016-06-04T05:08:58Z | 37,626,699 | <p>Short answer: No, dictionaries are not ordered in python, so there's no easy way to match up values. </p>
<p>Longer answer: Sort of, you can used Ordered Dictionaries. </p>
<pre><code>dic={'a': 1, 'b':2, 'c':3, 'd':4, 'e': 5, 'f':6}
o_dic = OrderedDict(sorted(dic.items(), key=lambda t: t[0]))
lst=[100,200,300,400,... | 0 | 2016-06-04T05:25:56Z | [
"python",
"list",
"dictionary"
] |
Get yaml key value in python | 37,626,662 | <p>My yaml file is:</p>
<pre><code>clusters:
test:
tag_cl: tag0
mtest:
tag_cl: tag1, tag12
ctest3:
tag_cl: tag2, tag22
</code></pre>
<p>I want to get value of each <code>tag_cl</code>. I am expecting a below... | 0 | 2016-06-04T05:20:51Z | 37,626,761 | <p>Here is what I found out:</p>
<pre><code>In[17]: d
Out[17]:
{'clusters': {'ctest3': {'tag_cl': 'tag2, tag22'},
'mtest': {'tag_cl': 'tag1, tag12'},
'test': {'tag_cl': 'tag0'}}}
In[18]: d['clusters']
Out[18]:
{'ctest3': {'tag_cl': 'tag2, tag22'},
'mtest': {'tag_cl': 'tag1, tag12'},
'test': {'tag_cl': 'tag0'}... | 0 | 2016-06-04T05:35:30Z | [
"python",
"python-2.7"
] |
Get yaml key value in python | 37,626,662 | <p>My yaml file is:</p>
<pre><code>clusters:
test:
tag_cl: tag0
mtest:
tag_cl: tag1, tag12
ctest3:
tag_cl: tag2, tag22
</code></pre>
<p>I want to get value of each <code>tag_cl</code>. I am expecting a below... | 0 | 2016-06-04T05:20:51Z | 37,626,774 | <p><code>data</code> is a python dictionary. You can retrieve all the data by iterating through <code>data</code> as a dictionary. Note that you can also access python dictionaries by using <code>["clusters"]</code> instead of <code>.get("clusters")</code>.</p>
<p>You would do something like:</p>
<pre><code>for k, v ... | 0 | 2016-06-04T05:37:24Z | [
"python",
"python-2.7"
] |
Get yaml key value in python | 37,626,662 | <p>My yaml file is:</p>
<pre><code>clusters:
test:
tag_cl: tag0
mtest:
tag_cl: tag1, tag12
ctest3:
tag_cl: tag2, tag22
</code></pre>
<p>I want to get value of each <code>tag_cl</code>. I am expecting a below... | 0 | 2016-06-04T05:20:51Z | 37,626,981 | <p>You can use a recursive generator like so:</p>
<pre><code>import yaml
def find(d, tag):
if tag in d:
yield d[tag]
for k, v in d.items():
if isinstance(v, dict):
for i in find(v, tag):
yield i
stream = open('clusters.yml', 'r')
data = yaml.load(stream)
for val i... | 0 | 2016-06-04T06:09:14Z | [
"python",
"python-2.7"
] |
How to calculate the average from a list of records | 37,626,831 | <p>So i am working on an Assignment and seem to be having trouble when it comes to calculating an average from a list of data (the data is read from an external .txt file). Specifically what i am trying to do is to read data records from the list of data below.</p>
<pre><code>1-2-2014,Frankton,42305.67,23
12-4-2014,Gl... | 1 | 2016-06-04T05:48:30Z | 37,626,908 | <p>You shouldn't divide by <code>len(records)</code> when calculating the averages, because <code>records</code> includes the transactions from other branches. You need to add a counter variable that counts the number of transactions from the selected branch, and divide by that.</p>
<pre><code>total = 0
total_transact... | 0 | 2016-06-04T05:58:45Z | [
"python",
"function",
"python-3.x",
"datetime"
] |
How to calculate the average from a list of records | 37,626,831 | <p>So i am working on an Assignment and seem to be having trouble when it comes to calculating an average from a list of data (the data is read from an external .txt file). Specifically what i am trying to do is to read data records from the list of data below.</p>
<pre><code>1-2-2014,Frankton,42305.67,23
12-4-2014,Gl... | 1 | 2016-06-04T05:48:30Z | 37,626,955 | <p>Use <code>pandas</code>!</p>
<pre><code>from pandas import read_csv
def get_sum_and_mean(city):
with open('records.csv', 'r') as open_file:
records = read_csv(open_file, header=None)
records = records.groupby(1)
return records[2].sum()[city], records[3].mean()[city]
</code></pre>
<p>Basically... | 0 | 2016-06-04T06:05:31Z | [
"python",
"function",
"python-3.x",
"datetime"
] |
How to calculate the average from a list of records | 37,626,831 | <p>So i am working on an Assignment and seem to be having trouble when it comes to calculating an average from a list of data (the data is read from an external .txt file). Specifically what i am trying to do is to read data records from the list of data below.</p>
<pre><code>1-2-2014,Frankton,42305.67,23
12-4-2014,Gl... | 1 | 2016-06-04T05:48:30Z | 37,628,675 | <p>Using pandas is much easier for playing around with tables, but if you're not familiar with pandas, spliting columns and lines apart with <code>line.split(',')</code> is helpful, then using it with <code>line[column_number]</code> to get total or average results. besides I prefer seperating two branches at first and... | 0 | 2016-06-04T09:35:16Z | [
"python",
"function",
"python-3.x",
"datetime"
] |
Why does the scope work like this? | 37,626,866 | <p>This question is a result of a student of mine asking a question about the following code, and I'm honestly completely stumped. Any help would be appreciated.</p>
<p>When I run this code:</p>
<pre><code>#test 2
a = 1
def func2(x):
x = x + a
return(x)
print(func2(3))
</code></pre>
<p>it works perfectly ... | 0 | 2016-06-04T05:52:56Z | 37,626,886 | <pre><code>a = 1
def func3(x):
global a
a = x + a
return(x)
print(func3(3))
</code></pre>
<p>Now it should work.</p>
<p>When you put the statement <code>a=x+a</code> inside the function, it creates a new local variable <code>a</code> and tries to reference its value(which clearly hasnt been defined befo... | 2 | 2016-06-04T05:55:37Z | [
"python",
"python-3.x",
"variables",
"scope",
"global-variables"
] |
Why does the scope work like this? | 37,626,866 | <p>This question is a result of a student of mine asking a question about the following code, and I'm honestly completely stumped. Any help would be appreciated.</p>
<p>When I run this code:</p>
<pre><code>#test 2
a = 1
def func2(x):
x = x + a
return(x)
print(func2(3))
</code></pre>
<p>it works perfectly ... | 0 | 2016-06-04T05:52:56Z | 37,627,182 | <pre><code>def func3(x):
a = x + a
return(x)
</code></pre>
<p>On the right hand right side of a = x + a (So, x + a), 'x' is passed as variable, where 'a' is not passed as a variable thus an error.
Without using globals: </p>
<pre><code> a = 1
def func3(x, a=2):
a = x + a
return(x)
... | 0 | 2016-06-04T06:35:39Z | [
"python",
"python-3.x",
"variables",
"scope",
"global-variables"
] |
Why is this regex not matched in python | 37,626,870 | <p>I need to find "<code>7.1/10</code>" in "<code>7.1/10&nb</code>" with the following regex:</p>
<pre><code>\d{1}\.?\d{0,2}\/10
</code></pre>
<p>But the following code does not match anything:</p>
<pre><code>rating= "7.1/10&nb"
p = re.compile(re.escape("\d{1}\.?\d{0,2}\/10"))
m = p.match(rating)
if m:
p... | 0 | 2016-06-04T05:53:46Z | 37,626,917 | <p>Change only one line in your code.</p>
<p><code>p = re.compile(re.escape("\d{1}\.?\d{0,2}\/10"))</code> <strong>to</strong> <code>re.compile(r"\d{1}\.?\d{0,2}\/10")</code></p>
<p>It will work smoothly. </p>
| 1 | 2016-06-04T05:59:34Z | [
"python",
"regex",
"python-2.7"
] |
Why is this regex not matched in python | 37,626,870 | <p>I need to find "<code>7.1/10</code>" in "<code>7.1/10&nb</code>" with the following regex:</p>
<pre><code>\d{1}\.?\d{0,2}\/10
</code></pre>
<p>But the following code does not match anything:</p>
<pre><code>rating= "7.1/10&nb"
p = re.compile(re.escape("\d{1}\.?\d{0,2}\/10"))
m = p.match(rating)
if m:
p... | 0 | 2016-06-04T05:53:46Z | 37,626,927 | <p><code>p = re.compile(r"\d\.?\d{0,2}/10")</code></p>
<p>There are several problems in you re:</p>
<ul>
<li>add 'r' for raw string or you will have to escape all '\':
<code>re.compile("\\d\\.?\\d{0,2}/10")</code></li>
<li>\d{1} can be \d </li>
<li><code>\/</code> can be /, no need to escape</li>
</ul>
| 2 | 2016-06-04T06:02:32Z | [
"python",
"regex",
"python-2.7"
] |
'__proxy__' object has no attribute 'get' in CreateView | 37,626,931 | <p>So I'm thinking that this is not the right way to do things, but I am trying to learn django and I am trying some things out. I am trying to set a foreign key for my <code>Formula</code> model, by hardcoding in an instance of <code>maker</code>. </p>
<p>Models: </p>
<pre><code>class Cooker(models.Model):
name ... | 0 | 2016-06-04T06:02:41Z | 37,627,016 | <p>The reason for your error is that <code>form_valid</code> should return a <code>Response</code> object, and you are returning a URL. </p>
<p>Rather than do this manually you should just call the parent method which will redirect to the <code>success_url</code> that you have already defined:</p>
<pre><code>def form... | 0 | 2016-06-04T06:13:35Z | [
"python",
"django",
"django-views"
] |
Regex to capture url until a certain character | 37,627,222 | <p>With a url such as </p>
<blockquote>
<p><code>https://search.yahoo.com/search?p=Fetty+Wap&amp;fr=fp-tts&</code></p>
</blockquote>
<p>I am using </p>
<pre><code>pat = re.compile('<a href="(https?://.*?)".*',re.DOTALL)
</code></pre>
<p>as a search pattern.</p>
<p>I want to pick any url like the yahoo... | 0 | 2016-06-04T06:40:09Z | 37,627,324 | <p>Regex is really the wrong tool for the job. Doing a basic string split will get you exactly what you want.</p>
<pre><code>def beforeQuestionMrk(inputStr):
return inputStr.split("?")[0]
url = "https://search.yahoo.com/sometext"
url2 = "https://search.yahoo.com/search?p=Fetty+Wap&fr=fp-tts&"
print(befor... | 1 | 2016-06-04T06:52:40Z | [
"python",
"regex",
"group",
"capture"
] |
Regex to capture url until a certain character | 37,627,222 | <p>With a url such as </p>
<blockquote>
<p><code>https://search.yahoo.com/search?p=Fetty+Wap&amp;fr=fp-tts&</code></p>
</blockquote>
<p>I am using </p>
<pre><code>pat = re.compile('<a href="(https?://.*?)".*',re.DOTALL)
</code></pre>
<p>as a search pattern.</p>
<p>I want to pick any url like the yahoo... | 0 | 2016-06-04T06:40:09Z | 37,627,902 | <p>I agree with other answer, that using regexp here is not a solution, especially because there my be any number of parameters before opening of the <code><a></code> tag and href parameter, there can be a new line in between too.</p>
<p>but, answering to the initial question:</p>
<p>'*', '+', and '?' qualifier... | 0 | 2016-06-04T08:02:55Z | [
"python",
"regex",
"group",
"capture"
] |
Regex to capture url until a certain character | 37,627,222 | <p>With a url such as </p>
<blockquote>
<p><code>https://search.yahoo.com/search?p=Fetty+Wap&amp;fr=fp-tts&</code></p>
</blockquote>
<p>I am using </p>
<pre><code>pat = re.compile('<a href="(https?://.*?)".*',re.DOTALL)
</code></pre>
<p>as a search pattern.</p>
<p>I want to pick any url like the yahoo... | 0 | 2016-06-04T06:40:09Z | 37,639,106 | <p>Bobble bubbles solution above worked very well for me; </p>
<p>"You can try like this by use of negated class: ]*?href="(http[^"?]+)"<- bobbles answer. </p>
<p>url looks like this </p>
<p><a href="https://search.yahoo.com/search?p=Justin+Bieber&fr=fp-tts&fr2=p:fp,m:tn,ct:all" rel="nofollow">https://sea... | 0 | 2016-06-05T06:24:48Z | [
"python",
"regex",
"group",
"capture"
] |
How to find area under exponential curve (and the curve) from random distribution in python? | 37,627,331 | <p>Given the following algorithm:</p>
<pre><code>import numpy as np
from matplotlib import pyplot as plt
exponent = 2
sample = np.random.random_sample(1000000)
distribution = sample ** exponent
plt.hist(distribution)
plt.show()
</code></pre>
<p><a href="http://i.stack.imgur.com/pEjRx.png" rel="nofollow"><img src="h... | 1 | 2016-06-04T06:53:15Z | 37,627,516 | <p>Define type of distribution for samples of a random distribution is not easy task. You have to check some validation tests to define distribution with desirable statistical confidence.</p>
<p>Scipy has test for normal distribution: <a href="http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.msta... | 2 | 2016-06-04T07:15:43Z | [
"python",
"numpy",
"math",
"matplotlib",
"scipy"
] |
Naive Bayes text classification incorrect results | 37,627,356 | <p>I've coded up a Naive Bayes Classifier, but it doesn't seem to be working particularly well. Counting the words etc. is not a problem but the probabilities have been.</p>
<p>The method I've been using starts at page 180 in <a href="https://docs.google.com/file/d/0ByVUs_BZLlUyRi1zT1VjZEJGcTA/edit" rel="nofollow">thi... | 0 | 2016-06-04T06:55:54Z | 37,631,035 | <blockquote>
<p>This score seems to be completely wrong and I'm not sure what to do. </p>
</blockquote>
<p>First of all, category probability is not estimated by the fraction of words in a category vs. total number of words</p>
<pre><code>for category in categories:
category_probability[category] = total_words_... | 1 | 2016-06-04T13:53:22Z | [
"python",
"machine-learning",
"naivebayes"
] |
inconsistent migration history when changing a django app's name | 37,627,464 | <p>I'm trying to rename one of the apps in my django website. There is another app which depends on it and its mysql tables. I went over all the files in both apps and changed the instances of the old name to the new one.</p>
<p>However, now I encounter this error message when trying to perform a migration:</p>
<pre>... | 1 | 2016-06-04T07:10:51Z | 39,704,461 | <p>This is issue due to parent models migrations already in database table. SO you have to Delete your database and re-create it.</p>
| 1 | 2016-09-26T13:39:15Z | [
"python",
"mysql",
"django",
"rename"
] |
Insert pandas dataframe to mysql using sqlalchemy | 37,627,520 | <p>I simply try to write a pandas dataframe to local mysql database on ubuntu.</p>
<pre><code>from sqlalchemy import create_engine
import tushare as ts
df = ts.get_tick_data('600848', date='2014-12-22')
engine = create_engine('mysql://user:passwd@127.0.0.1/db_name?charset=utf8')
df.to_sql('tick_data',engine, flavor =... | 0 | 2016-06-04T07:15:51Z | 37,633,634 | <p>You appear to be using an older version of pandas. I did a quick git bisect to find the version of pandas where line 53 contains <code>con.rollback()</code>, and found pandas at v0.12, which is before SQLAlchemy support was added to the <code>execute</code> function.</p>
<p>If you're stuck on this version of pandas... | 3 | 2016-06-04T18:26:25Z | [
"python",
"mysql",
"pandas",
"sqlalchemy"
] |
clang error when installing pygresql under Mac OS | 37,627,609 | <p>I was trying to install PyGreSQL under Mac OS X(10.11.3), but the same clang error occurs when installing from pip and source.</p>
<pre><code>$ python3 setup.py install
running install
running bdist_egg
running egg_info
writing PyGreSQL.egg-info/PKG-INFO
writing top-level names to PyGreSQL.egg-info/top_level.txt
wr... | 0 | 2016-06-04T07:27:20Z | 39,131,236 | <p>I was able to compile the module by editing the modules's <strong>setup.py</strong></p>
<p>Find the line</p>
<pre><code>extra_compile_args = ....
</code></pre>
<p>It's a list of extra compile arguments to pass to clang. One of the extra arguments will be <strong><code>-Werror</code></strong>, which means "treat a... | 0 | 2016-08-24T19:06:28Z | [
"python",
"postgresql",
"clang",
"pygresql"
] |
Django list_editable() can not display primary key value | 37,627,655 | <p>I am new to Django. I try to display different fields in Django admin page and find to options to display details in the page. I am sure that <code>list_display_links</code> works,but I get error when I try <code>list_editable</code>. Can someone points out the reason of error?</p>
<pre><code>class SaleAdmin(admin.... | 0 | 2016-06-04T07:32:11Z | 37,627,729 | <p>The error message complains about this part</p>
<pre><code>list_editable = ["pk", "product_id","old_price", ...
</code></pre>
<p>Change it to "id".</p>
<pre><code>list_editable = ["id", "product_id","old_price", ...
</code></pre>
<p>Better yet, remove <code>pk</code>/<code>id</code> from that list, because you m... | 0 | 2016-06-04T07:41:34Z | [
"python",
"django"
] |
Pygame not displaying text | 37,627,858 | <p>I have this bit of code in my main() function that is meant to show a countdown timer for my game but it is not displaying the time left text. I've run the game and the countdown timer code works fine but there is no text for it. Please help.</p>
<pre><code> def main():
rand = random.randint(1, 4)
... | 0 | 2016-06-04T07:57:20Z | 37,628,099 | <p>you will need to colour the screen before drawing the text. like this:</p>
<pre><code>screen.fill(BLACK)
</code></pre>
<p>then you draw the text:</p>
<pre><code>screen.blit(font.render(output_string, True, WHITE), (150, 110))
</code></pre>
<p>then to display everything you must write:</p>
<pre><code>pygame.disp... | 2 | 2016-06-04T08:27:12Z | [
"python",
"pygame"
] |
Create a hashvalue using a custom key and the algorithm ripemd160 | 37,627,879 | <p>Here's the code I tried in Python but I get <code>AttributeError</code>:</p>
<pre><code>>>> import hmac
>>> import hashlib
>>> h=hashlib.new('ripemd160')
>>> hmac.new("bedford","Hello",hashlib.ripemd160)
Traceback (most recent call last):
File "<stdin>", line 1, in ... | 1 | 2016-06-04T07:59:40Z | 37,627,967 | <p><code>ripemd160</code> is not supported directly by the <code>hashlib</code> module:</p>
<blockquote>
<pre><code>>>> hashlib.algorithms
</code></pre>
<p>A tuple providing the names of the hash algorithms
guaranteed to be supported by this module.</p>
</blockquote>
<p>The following are supported by... | 1 | 2016-06-04T08:11:53Z | [
"python",
"ripemd"
] |
Create a hashvalue using a custom key and the algorithm ripemd160 | 37,627,879 | <p>Here's the code I tried in Python but I get <code>AttributeError</code>:</p>
<pre><code>>>> import hmac
>>> import hashlib
>>> h=hashlib.new('ripemd160')
>>> hmac.new("bedford","Hello",hashlib.ripemd160)
Traceback (most recent call last):
File "<stdin>", line 1, in ... | 1 | 2016-06-04T07:59:40Z | 37,628,012 | <p>This would work:</p>
<pre><code>hmac.new("bedford", "Hello", lambda: hashlib.new('ripemd160'))
</code></pre>
<p>or </p>
<pre><code>h=hashlib.new('ripemd160')
hmac.new("bedford", "Hello", lambda: h)
</code></pre>
| 1 | 2016-06-04T08:16:14Z | [
"python",
"ripemd"
] |
Create a hashvalue using a custom key and the algorithm ripemd160 | 37,627,879 | <p>Here's the code I tried in Python but I get <code>AttributeError</code>:</p>
<pre><code>>>> import hmac
>>> import hashlib
>>> h=hashlib.new('ripemd160')
>>> hmac.new("bedford","Hello",hashlib.ripemd160)
Traceback (most recent call last):
File "<stdin>", line 1, in ... | 1 | 2016-06-04T07:59:40Z | 37,628,030 | <p>Firstly, the key needs to be binary (Python3) -> <code>b"bedford"</code>. </p>
<p>Then, the message needs to be encoded if it's unicode etc (Python3) -> <code>codecs.encode("Hello")</code></p>
<p>Finally, use <a href="https://docs.python.org/3.5/reference/expressions.html#lambda" rel="nofollow"><code>lambda</code>... | 1 | 2016-06-04T08:18:41Z | [
"python",
"ripemd"
] |
Pyglet Syntax Error ("invalid syntax") | 37,627,886 | <p>So, I'm trying to create a program with the Pyglet API, and, upon running what I have written so far, I keep receiving the following error message, which is related to one of Pyglet's modules:</p>
<pre><code> File "/usr/lib/python3.4/site-packages/pyglet/window/__init__.py", line 267
class BaseWindow(EventDisp... | 0 | 2016-06-04T08:01:11Z | 37,627,955 | <p>Your try to run a python3 script with python 2. Use <code>python3</code>.</p>
| 1 | 2016-06-04T08:10:13Z | [
"python",
"syntax",
"window",
"init",
"pyglet"
] |
How to get feature importance in xgboost? | 37,627,923 | <p>I'm using xgboost to build a model, and try to find the importance of each feature using <code>get_fscore()</code>, but it returns <code>{}</code></p>
<p>and my train code is:</p>
<pre><code>dtrain = xgb.DMatrix(X, label=Y)
watchlist = [(dtrain, 'train')]
param = {'max_depth': 6, 'learning_rate': 0.03}
num_round =... | 0 | 2016-06-04T08:05:45Z | 39,107,870 | <p>Try this:</p>
<pre><code>pd.DataFrame(bst.get_fscore().items(), columns=['feature','importance']).sort_values('importance', ascending=False)
</code></pre>
| 0 | 2016-08-23T17:58:44Z | [
"python",
"xgboost"
] |
import error when using python dlib | 37,628,084 | <p>I'm following the instructions on this page: <a href="http://www.learnopencv.com/facial-landmark-detection/" rel="nofollow">http://www.learnopencv.com/facial-landmark-detection/</a></p>
<blockquote>
<p>1.Download a copy from github</p>
<p>git clone <a href="https://github.com/davisking/dlib.git" rel="nofollo... | 0 | 2016-06-04T08:25:29Z | 37,631,392 | <p>For using dlib with python, follow instructions in readme.txt:</p>
<blockquote>
<p>COMPILING DLIB Python API<br>
Before you can run the Python example programs you must compile dlib. <br>
Type:<br>
python setup.py install or type<br>
python setup.py install --yes USE_AVX_INSTRUCTIONS <br>
if you h... | 1 | 2016-06-04T14:31:29Z | [
"python",
"git",
"import",
"face-recognition",
"dlib"
] |
Serve repository using git daemon with GitPython | 37,628,145 | <p>I'm trying to initialize a git repo and then serve it using the git daemon. Everything with GitPython. </p>
<p>Initializing the repo works:</p>
<pre><code>temp_dir = '/tmp/something'
repo = git.Repo.init(temp_dir)
</code></pre>
<p>Starting the daemon as well:</p>
<pre><code>gd = Git().daemon(temp_dir, enable='re... | 0 | 2016-06-04T08:32:55Z | 37,640,395 | <p>Figured it out, Thanks to user3159253.</p>
<pre><code>import git
import tempfile
tmpdir = tempfile.TemporaryDirectory(suffix='.git')
repo = git.Repo.init(tmpdir.name, shared=True, bare=True)
repo.daemon_export = True
gd = git.Git().daemon(tmpdir.name,
enable='receive-pack',
... | 0 | 2016-06-05T09:31:03Z | [
"python",
"gitpython"
] |
Passing a numpy array to C++ | 37,628,180 | <p>I have some code writen in Python for which the output is a numpy array, and now I want to send that output to <code>C++</code> code, where the heavy part of the calculations will be performed.</p>
<p>I have tried using cython's <code>public cdef</code>, but I am running on some issues. I would appreciate your help... | 7 | 2016-06-04T08:36:30Z | 37,633,946 | <h3>Short Answer</h3>
<p>The NameError was cause by the fact that Python couldn't find the module, the working directory isn't automatically added to your <a href="https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH" rel="nofollow"><strong><code>PYTHONPATH</code></strong></a>. Using <a href="http://man7.org... | 2 | 2016-06-04T19:02:27Z | [
"python",
"c++",
"arrays",
"numpy",
"cython"
] |
Subtracting 12 when the sum of two variables is greater or equal to 12 | 37,628,300 | <p>I come from a musical background, so I was interested in implementing music set theory into a Python script.</p>
<p>Basically the variables of musical notes are assigned to numbers (C = 0, C sharp = 1 etc.). However music set theory only works up to the number 11, since B = 11 and the next C would be = 0 again. </p... | 4 | 2016-06-04T08:50:28Z | 37,628,312 | <p>There's a <a href="https://en.wikipedia.org/wiki/Modulo_operation" rel="nofollow">modulo operator</a>, <code>%</code> which does exactly this (see also <a href="https://docs.python.org/2/reference/expressions.html#binary-arithmetic-operations" rel="nofollow">here</a>):</p>
<pre><code>print((11 + 7) % 12)
</code></p... | 4 | 2016-06-04T08:52:10Z | [
"python",
"set",
"music",
"theory"
] |
Subtracting 12 when the sum of two variables is greater or equal to 12 | 37,628,300 | <p>I come from a musical background, so I was interested in implementing music set theory into a Python script.</p>
<p>Basically the variables of musical notes are assigned to numbers (C = 0, C sharp = 1 etc.). However music set theory only works up to the number 11, since B = 11 and the next C would be = 0 again. </p... | 4 | 2016-06-04T08:50:28Z | 37,628,384 | <p>Your solution is almost correct; however, <code>answer - 12</code> is just an expression, i.e. it evaluates to the value <code>answer - 12</code> without having any additional effect.</p>
<p>You need to make a statement that assigns that value to some variable (in this case, the same one):</p>
<p><code>answer = an... | 0 | 2016-06-04T09:01:17Z | [
"python",
"set",
"music",
"theory"
] |
Subtracting 12 when the sum of two variables is greater or equal to 12 | 37,628,300 | <p>I come from a musical background, so I was interested in implementing music set theory into a Python script.</p>
<p>Basically the variables of musical notes are assigned to numbers (C = 0, C sharp = 1 etc.). However music set theory only works up to the number 11, since B = 11 and the next C would be = 0 again. </p... | 4 | 2016-06-04T08:50:28Z | 37,628,441 | <p>I would correct your code as</p>
<pre><code>if (answer >= 12):
answer = answer - 12
</code></pre>
| 0 | 2016-06-04T09:06:22Z | [
"python",
"set",
"music",
"theory"
] |
AIML - Parsing user inputs as variable to Python | 37,628,307 | <p>I am working on an AIML project for leisure and came across pandorabots. I was wondering if there is a way to parse a variable from the user inputs into other languages (in this case python) or framework so that we can do further manipulation through other third party API by means of any templating? </p>
<p>For ins... | 0 | 2016-06-04T08:51:30Z | 38,203,155 | <p>In the pyAIML API, look for the keyword "predicates":</p>
<ul>
<li>kernel.getPredicate('date')</li>
<li>kernel.getBotPredicate('dat')</li>
</ul>
<p>it returns the predicate that was set using </p>
<pre><code><set name="date"><star/></set>
</code></pre>
<p>Then you can easily parse it with pytho... | 0 | 2016-07-05T12:13:09Z | [
"python",
"aiml",
"pandorabots"
] |
Scrapy getting errors with Proxies -- twisted.python.failure.Failure OpenSSL.SSL.Error | 37,628,372 | <p>I'm pretty new to <code>scrapy</code> and I am trying to scrape some craigslist pages using some proxies but I am getting some errors as shown below. I tried the command <code>scrapy shell "https://craigslist.org"</code> and it seemed to work fine. </p>
<p>From my understanding, if I want to use proxies, I have to ... | 1 | 2016-06-04T08:59:35Z | 39,481,226 | <p>I got this because of using <code>base64.encodestring</code> instead of <code>base64.b64encode</code>. This error seems to usually happen when using proxy from proxymesh.com
Reference: <a href="https://github.com/scrapy/scrapy/issues/1855" rel="nofollow">https://github.com/scrapy/scrapy/issues/1855</a></p>
<p>This ... | 0 | 2016-09-14T01:30:59Z | [
"python",
"proxy",
"web-scraping",
"scrapy"
] |
Issues with exe compiled Kivy programs accessing images | 37,628,399 | <p>So I've created a simple program that replaces the slider cursor background with a custom image and tried to compile it using <code>PyInstaller</code> using the <code>-F</code> argument (to compile it into a single exe). Compilation was successful, but when I tried to execute it, it failed to load the image with the... | 4 | 2016-06-04T09:02:24Z | 37,628,434 | <p>You are missing one "sp" in your image source code whatever that is :-)</p>
<p>Instead of:</p>
<pre><code>pos: (self.value_pos[0] - sp(16), self.center_y - sp(17)) if self.orientation == 'horizontal' else (self.center_x - (16), self.value_pos[1] - sp(16))
</code></pre>
<p>Try this:</p>
<pre><code>pos: (self.valu... | 0 | 2016-06-04T09:05:51Z | [
"python",
"python-3.x",
"kivy",
"pyinstaller"
] |
Redis - Get values inside a dict HMGET | 37,628,455 | <p>I've created a key in the redis as following:-</p>
<pre><code>In [1]: import redis
In [2]: conn = redis.Redis('localhost')
In [3]: user = {
...: 'name': 'username',
...: 'age': 25,
...: 'likes': ['football', 'swimming'],
...: 'response': {
...: 'a': 1... | 1 | 2016-06-04T09:08:17Z | 37,632,305 | <p>Redis does not support nested data structures in hashes. Your client has encoded them (<code>likes</code> and <code>response</code>) as strings (probably using <code>repr()</code>, but perhaps JSON), and <code>hgetall()</code> returns them as strings.</p>
<p>So there is no Redis command that is going to get you the... | 0 | 2016-06-04T16:02:08Z | [
"python",
"redis"
] |
Select destination variable for click parser | 37,628,508 | <p>I'm wondering how to override destination variable for the <code>click.option</code> (<a href="http://click.pocoo.org/6/" rel="nofollow">Click lib</a>). For example in such piece of code</p>
<pre><code>import click
@click.command()
@click.option('--output', default='data')
def generate_data(output_folder):
pri... | 1 | 2016-06-04T09:15:16Z | 37,736,928 | <p>Yes, see the section in the click documentation on <a href="http://click.pocoo.org/5/parameters/#parameter-names" rel="nofollow">parameter names</a>, which covers both options and arguments. </p>
<blockquote>
<p>If a parameter is not given a name without dashes, a name is generated automatically by taking the lon... | 1 | 2016-06-09T22:03:00Z | [
"python",
"command-line",
"command-line-interface",
"command-line-arguments",
"python-click"
] |
Python: nested lists, extend & delete elements | 37,628,529 | <p>I have the following list of lists:</p>
<pre><code>list=[
['a', 1, 5],
['b', 10, 25],
['c', 2, 7],
['d', 3, 4],
['e', 0, 0]
]
</code></pre>
<p>which I want to process in order to end up like this:</p>
<pre><code>list=[
['a', 1, 5],
[['b', 10, 25],['c', 2, 7]],
[['d', 3, 4], ['e', 0, 0]]
... | 0 | 2016-06-04T09:17:25Z | 37,628,680 | <p>I don't know about the pandas part, but for converting your first nested Python list into the second nested Python list, just do:</p>
<pre><code>list = [list[0], [list[1], list[2]], [list[3], list[4]]]
</code></pre>
<p>This assigns a newly created nested list to <code>list</code> instead of manipulating the origin... | 2 | 2016-06-04T09:35:39Z | [
"python",
"arrays",
"python-2.7",
"numpy",
"pandas"
] |
Python - ValueError: too many values to unpack - why? | 37,628,588 | <p>I'm very new to Python. I need to compare two lists of words and detect those words in one list which are not in the other.
Here are two test files</p>
<p>big_list.txt</p>
<pre><code>[coin, co-operate, accurate, achieve, adapt, adjust, admire, admission, enter, advance, adventure, aeroplane, plane, affair, aim, ob... | 1 | 2016-06-04T09:25:02Z | 37,628,610 | <p>Try:</p>
<pre><code>big_list, small_list = argv[1:]
</code></pre>
<p>Why? Because <strong>three</strong> parameters will be passed to your script by default, with <code>argv[0]</code> being the script name</p>
<p>P.S. In your last two lines, there is a bug waiting to go off. You <em>can't</em> pass a list as a re... | 4 | 2016-06-04T09:28:10Z | [
"python",
"argv"
] |
Python - ValueError: too many values to unpack - why? | 37,628,588 | <p>I'm very new to Python. I need to compare two lists of words and detect those words in one list which are not in the other.
Here are two test files</p>
<p>big_list.txt</p>
<pre><code>[coin, co-operate, accurate, achieve, adapt, adjust, admire, admission, enter, advance, adventure, aeroplane, plane, affair, aim, ob... | 1 | 2016-06-04T09:25:02Z | 37,628,628 | <p>Try at least(<strong>Please look at the second code snippet for a real fully working answer</strong>):</p>
<pre><code>from sys import argv
big_list, small_list = argv[-2:]
blist = open(big_list).read()
slist = open(small_list).read()
dlist = [item for item in slist if item not in blist]
diff_list = open(dlist, 'w')... | 0 | 2016-06-04T09:30:52Z | [
"python",
"argv"
] |
Python - ValueError: too many values to unpack - why? | 37,628,588 | <p>I'm very new to Python. I need to compare two lists of words and detect those words in one list which are not in the other.
Here are two test files</p>
<p>big_list.txt</p>
<pre><code>[coin, co-operate, accurate, achieve, adapt, adjust, admire, admission, enter, advance, adventure, aeroplane, plane, affair, aim, ob... | 1 | 2016-06-04T09:25:02Z | 37,628,631 | <p><code>argv[0]</code> contains the name of the python script being run (analogous to the way C's <code>argv[0]</code> has the executable name). You obviously cannot assgin three values (<code>['file_comp1.py', 'big_list.txt', 'small_list.txt']</code>) into two variables. You could, e.g., slice <code>argv</code> to ge... | 1 | 2016-06-04T09:31:03Z | [
"python",
"argv"
] |
Python - ValueError: too many values to unpack - why? | 37,628,588 | <p>I'm very new to Python. I need to compare two lists of words and detect those words in one list which are not in the other.
Here are two test files</p>
<p>big_list.txt</p>
<pre><code>[coin, co-operate, accurate, achieve, adapt, adjust, admire, admission, enter, advance, adventure, aeroplane, plane, affair, aim, ob... | 1 | 2016-06-04T09:25:02Z | 37,628,647 | <pre><code>from sys import argv
big_list = argv[1]
small_list = argv[2]
blist = open(big_list).read()
slist = open(small_list).read()
dlist = [item for item in slist if item not in blist]
diff_list = open(dlist, 'w').write()
diff_list.close()
</code></pre>
<p>Check out this answer on how to use argv.<a href="http://st... | 0 | 2016-06-04T09:32:15Z | [
"python",
"argv"
] |
Matrix direct product retaining indices in python | 37,628,593 | <p>I am a novice programmer starting to code in python. I have two 2D numpy arrays which I want to combine to form a 4D numpy array in the following manner,<br>
<code>array_4d[i, j, k, l] = array_1[i, j] * array_2[k, l]</code><br>
I can of course brute force this by writing nested for loops, but I want to know is t... | 2 | 2016-06-04T09:26:14Z | 37,628,797 | <p>Have you had a look at <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html" rel="nofollow"><code>np.einsum</code></a>? It allows you to write this down quite elegantly:</p>
<pre><code>>>> import numpy as np
>>> a = np.random.random_integers(0,9, (2,2))
>>> b = ... | 3 | 2016-06-04T09:51:18Z | [
"python",
"numpy",
"multidimensional-array",
"matrix-multiplication"
] |
How to determine the eigenvalues of sympy.matrices.dense.MutableDenseMatrix? | 37,628,844 | <p>The Python SymPy Matrix API has a <a href="http://docs.sympy.org/dev/tutorial/matrices.html" rel="nofollow">method</a> to determine the eigenvalue. I would like to do similar thing with SymPy MutableDenseMatrix. Unfortunately, the <a href="http://docs.sympy.org/dev/modules/matrices/dense.html" rel="nofollow">API</a>... | 2 | 2016-06-04T09:57:03Z | 37,629,151 | <p>As suggested in my comment, it must of course be a square matrix, but then simply construct a Matrix out of your MutableDenseMatrix:</p>
<pre><code>>>> from sympy.matrices.dense import MutableDenseMatrix
>>> from sympy.matrices import Matrix
>>> a = MutableDenseMatrix([[1,0,0], [0,0,0], [... | 2 | 2016-06-04T10:34:56Z | [
"python",
"python-2.7",
"linear-algebra",
"sympy",
"eigenvalue"
] |
Python implementation of the Kernel Based object tracking algorithm? | 37,628,895 | <p>I want to do some experiments for comparing my algorithm and Kernel-Based method. Does anyone know of a complete Python implementation of the Kernel-based?
Here is the <a href="http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1195991" rel="nofollow">document</a></p>
| -2 | 2016-06-04T10:04:03Z | 37,629,005 | <p>If you mean a pure python implementation then it seems difficult to find such code. </p>
<p>However, there is a <a href="https://github.com/gpsinghsandhu/Kernel-Based-Object-Tracking" rel="nofollow"><code>C++</code> implementation of the algorithm</a> and C/C++ library functions <a href="https://docs.python.org/3.5... | 0 | 2016-06-04T10:16:06Z | [
"python",
"computer-vision"
] |
Python - My frequency function is inefficient | 37,629,142 | <p>I'm writing a function that returns the number of times appeared of a word that appeared the most in the list of words.</p>
<pre><code>def max_frequency(words):
"""Returns the number of times appeared of the word that
appeared the most in a list of words."""
words_set = set(words)
words_list = word... | 1 | 2016-06-04T10:33:35Z | 37,629,265 | <p>While I fully agree with the comments related to your <em>I don't want to import anything</em> statement, I found your question amusing, so let's try it.</p>
<p>You don't need to build a <code>set</code>. Just go directly with <code>words</code>.</p>
<pre><code>words = words = ["Happy", "Happy", "Happy", "Duck", "... | 0 | 2016-06-04T10:47:11Z | [
"python",
"performance",
"python-3.x",
"frequency",
"coding-efficiency"
] |
Python - My frequency function is inefficient | 37,629,142 | <p>I'm writing a function that returns the number of times appeared of a word that appeared the most in the list of words.</p>
<pre><code>def max_frequency(words):
"""Returns the number of times appeared of the word that
appeared the most in a list of words."""
words_set = set(words)
words_list = word... | 1 | 2016-06-04T10:33:35Z | 37,629,288 | <p>To prevent multiple passes of your list for each unique word, you can simply iterate over it once and update dictionary values for each count. </p>
<pre><code>counts = {}
for word in words:
counts[word] = counts.get(word, 0) + 1
</code></pre>
<p><strong>Outputs</strong>:</p>
<pre><code>>>> print(max(... | 3 | 2016-06-04T10:49:13Z | [
"python",
"performance",
"python-3.x",
"frequency",
"coding-efficiency"
] |
Python - My frequency function is inefficient | 37,629,142 | <p>I'm writing a function that returns the number of times appeared of a word that appeared the most in the list of words.</p>
<pre><code>def max_frequency(words):
"""Returns the number of times appeared of the word that
appeared the most in a list of words."""
words_set = set(words)
words_list = word... | 1 | 2016-06-04T10:33:35Z | 37,629,306 | <p>You can try this code which is about 760% faster.</p>
<pre><code>def max_frequency(words):
"""Returns the number of times appeared of the word that
appeared the most in a list of words."""
count_dict = {}
max = 0
for word in words:
current_count = 0
if word in count_dict:
... | 0 | 2016-06-04T10:51:43Z | [
"python",
"performance",
"python-3.x",
"frequency",
"coding-efficiency"
] |
Python - My frequency function is inefficient | 37,629,142 | <p>I'm writing a function that returns the number of times appeared of a word that appeared the most in the list of words.</p>
<pre><code>def max_frequency(words):
"""Returns the number of times appeared of the word that
appeared the most in a list of words."""
words_set = set(words)
words_list = word... | 1 | 2016-06-04T10:33:35Z | 37,629,881 | <h3>Data size similar to OP's</h3>
<p>Let's start with a list of words</p>
<pre><code>In [55]: print(words)
['oihwf', 'rpowthj', 'trhok', 'rtpokh', 'tqhpork', 'reaokp', 'eahopk', 'qeaopker', 'okp[qrg', 'okehtq', 'pinjjn', 'rq38na', 'aogopire', "apoe'ak", 'apfobo;444', 'jiaegro', '908qymar', 'pe9irmp4', 'p9itoijar', '... | 0 | 2016-06-04T11:49:31Z | [
"python",
"performance",
"python-3.x",
"frequency",
"coding-efficiency"
] |
Creating new fields in serializer that access another model's attributes | 37,629,225 | <p>My API call to <code>api/business-review/3abe3a1e-199c-4a4b-9d3b-e7cb522d6bed/</code> currently returns the following:</p>
<pre><code>[
{
"id": "3abe3a1e-199c-4a4b-9d3b-e7cb522d6bed",
"date_time": "2016-05-31T19:18:24Z",
"review": "Another quality job, Anna has a no fuss approach to his ... | 1 | 2016-06-04T10:42:26Z | 37,629,363 | <p>Please try adding the field name explicitly instead of using <code>__all__</code> which only picks up fields which are present in model and not those defined in serializer like this</p>
<p><code>fields = ['person', 'service', 'review', 'employee', 'person_name', 'service_name', 'employee_name', 'date_time']</code... | 2 | 2016-06-04T10:58:19Z | [
"python",
"django",
"django-rest-framework"
] |
Creating new fields in serializer that access another model's attributes | 37,629,225 | <p>My API call to <code>api/business-review/3abe3a1e-199c-4a4b-9d3b-e7cb522d6bed/</code> currently returns the following:</p>
<pre><code>[
{
"id": "3abe3a1e-199c-4a4b-9d3b-e7cb522d6bed",
"date_time": "2016-05-31T19:18:24Z",
"review": "Another quality job, Anna has a no fuss approach to his ... | 1 | 2016-06-04T10:42:26Z | 37,630,107 | <p>Since you want add data to the serialized representation of your object, its better to use <a href="http://www.django-rest-framework.org/api-guide/fields/#serializermethodfield" rel="nofollow"><code>SerializerMethodField()</code></a> for <code>person_name</code>, <code>service_name</code> and <code>employee_name</co... | 1 | 2016-06-04T12:14:34Z | [
"python",
"django",
"django-rest-framework"
] |
List comprehension with condition on the new element | 37,629,382 | <p>I will be stealing the form of the question there: <a href="http://stackoverflow.com/questions/24442091/list-comprehension-with-condition">List comprehension with condition</a></p>
<p>I have a simple list.</p>
<pre><code>>>> a = [0, 1, 2]
</code></pre>
<p>I want to make a new list from it using a list co... | 1 | 2016-06-04T11:00:16Z | 37,629,488 | <p>You don't need to build the list then iterate over it again, you can consume an iterator of the application of <code>afunction</code> to the elements in <code>a</code>, either using <code>map</code>:</p>
<pre><code>[y for y in map(afunction, a) if y is not None]
</code></pre>
<p>or a generator expression (note cha... | 3 | 2016-06-04T11:12:19Z | [
"python",
"list",
"list-comprehension"
] |
Can I loop through a text file when values are strings? | 37,629,454 | <p>I have a problem I'd be very grateful for help with.</p>
<p>Specifically, I have a gigantic text file; I need to replace specific strings in it with entries from a dictionary. Usefully, the words I need to replace are named in sequential fashion: 'Word1', 'Word2', ... , 'Wordn'.</p>
<p>Now, I'd like to write a 'fo... | 0 | 2016-06-04T11:08:28Z | 37,629,632 | <pre><code>n = 1
while not done:
replace_str = 'Word' + str(n)
# find and replace all instances of replace_str in the file text
# set variable done if finished
n += 1
</code></pre>
<p>Does that framework solve your needs? A string is not a variable: a string is a value which can be calculated, while a ... | 2 | 2016-06-04T11:25:04Z | [
"python",
"string",
"loops",
"text",
"replace"
] |
Can I loop through a text file when values are strings? | 37,629,454 | <p>I have a problem I'd be very grateful for help with.</p>
<p>Specifically, I have a gigantic text file; I need to replace specific strings in it with entries from a dictionary. Usefully, the words I need to replace are named in sequential fashion: 'Word1', 'Word2', ... , 'Wordn'.</p>
<p>Now, I'd like to write a 'fo... | 0 | 2016-06-04T11:08:28Z | 37,629,696 | <p>With <a href="https://docs.python.org/3/library/re.html#re.sub" rel="nofollow"><code>re.sub()</code></a>, you can pass it a function instead of a replacement string. This function can look up the replacement from a dictionary. For example:</p>
<pre><code>d = {'0': 'foo', '1': 'bar', '2': 'baz'}
re.sub(r'word(\d+)',... | 4 | 2016-06-04T11:31:14Z | [
"python",
"string",
"loops",
"text",
"replace"
] |
Can I loop through a text file when values are strings? | 37,629,454 | <p>I have a problem I'd be very grateful for help with.</p>
<p>Specifically, I have a gigantic text file; I need to replace specific strings in it with entries from a dictionary. Usefully, the words I need to replace are named in sequential fashion: 'Word1', 'Word2', ... , 'Wordn'.</p>
<p>Now, I'd like to write a 'fo... | 0 | 2016-06-04T11:08:28Z | 37,630,822 | <p>I suppose the text file you were talking was like this:</p>
<blockquote>
<p>Hi! This is word1</p>
<p>I like to swim, word2 and word3 ....</p>
</blockquote>
<p>if so, then you can read line by line, split lines and replace words with values from dictionary, whose keys would be int(word[-1])</p>
<p>Here is t... | 1 | 2016-06-04T13:31:44Z | [
"python",
"string",
"loops",
"text",
"replace"
] |
Same bind for two commands in tkinter | 37,629,477 | <p>So I'm trying to display two numbers using the same .bind ("):</p>
<pre><code>def distance(event):
dchain.configure(text = "distance = " + str(sqrt((x1-z1)**2 + (y1-v1)**2) - 30))
def gravitationalForce(event):
fchain.configure(text = "force = " + str(pow(6.6710, -11.0)*(m1*m2/pow((sqrt((x1-z1)**2 + (y1-v... | 0 | 2016-06-04T11:11:12Z | 37,629,521 | <p>Just wrap the functions into one. You can even do it inline with a <code>lambda</code> expression:</p>
<pre><code>...
win1=Tk()
win1.bind("<ButtonPress>", lambda event: distance(event), gravitationalForce(event))
dchain = Label( win1)
...
</code></pre>
| 3 | 2016-06-04T11:15:51Z | [
"python",
"tkinter",
"bind"
] |
Django Rest Framework ListField and DictField | 37,629,501 | <p>I am having struggle with understanding <code>ListField</code> and <code>DictField</code>. I want to use it as a field on a serializer. I have a <code>ListField</code> which probably will contain many <code>DictField</code>. I tried to write a serializer as below:</p>
<pre><code>class StopOncomingSerialier(serializ... | 1 | 2016-06-04T11:13:28Z | 37,629,684 | <p>I think instead of doing that, you should <strong>use nested serializers</strong>.</p>
<p>Create a <code>BusSerializer</code> having fields <code>idn</code> and <code>stops_left</code>. Then include this serializer in your <code>StopOncomingSerializer</code> as <code>buses</code> field with <code>many=True</code> a... | 1 | 2016-06-04T11:30:27Z | [
"python",
"django",
"python-3.x",
"django-rest-framework"
] |
Write each element of a list on a newline on a text file in Python | 37,629,509 | <p>Having read <a href="https://stackoverflow.com/questions/899103/writing-a-list-to-a-file-with-python">this question</a> and <a href="http://stackoverflow.com/questions/30371987/python-how-to-write-a-list-of-strings-on-separate-lines-but-withot-a-blank-line">this question</a>, I am trying to <strong>write each elemen... | 1 | 2016-06-04T11:14:18Z | 37,629,534 | <p>If you're writing text, you shouldn't use the "b" mode:</p>
<pre><code>with open(filename, mode="w") as outfile:
# Here ---------------^
</code></pre>
| 1 | 2016-06-04T11:17:04Z | [
"python",
"list",
"python-3.x",
"writefile"
] |
Making a contingency table with continous variable | 37,629,778 | <p>i'm stuck on a problem in python. i want to create a contingency table but i have variable which is continous.
suppose:</p>
<pre><code>a=[1,2,5,9,10,11.3,11.9,12.5,18.8]
b=["yes","no","yes","no","yes","no","no","no","yes"]
</code></pre>
<p>and i want to create a contingency table that looks like</p>
<pre><code> ... | 2 | 2016-06-04T11:40:45Z | 37,629,858 | <p>A <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a> solution would be like this:</p>
<p>Construct the dataframe:</p>
<pre><code>df = pd.DataFrame({"a": a, "b": b})
</code></pre>
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow">pd.cut</a> to find the... | 2 | 2016-06-04T11:47:13Z | [
"python"
] |
TypeError: float() argument must be a string or a number, not 'list' python | 37,629,828 | <p>I've a problem with Python.
This is my code:</p>
<pre><code>def calcola():
a = input()
b = float(a[0].split("*"))
c = float(a[0].split("/"))
d = float(a[0].split("-"))
e = float(a[0].split("+"))
j = float(a[1].split("*"))
k = float... | -5 | 2016-06-04T11:45:16Z | 37,629,921 | <p>You can't call <code>float</code> on a list directly. You can use <code>map</code> to call <code>float</code> on each item in the list. Like so:</p>
<pre><code>b = map(float, a[0].split("*"))
</code></pre>
<p>In python 3.x</p>
<pre><code>b = list(map(float, a[0].split("*")))
</code></pre>
<p>Or for more readabil... | 2 | 2016-06-04T11:52:45Z | [
"python"
] |
block read of instance variable when trying to set it | 37,629,938 | <pre><code>Class A(object):
def __init__(self, cookie):
self.__cookie = cookie
def refresh_cookie():
```This method refresh the cookie after every 10 min```
self.__cookie = <newcookie>
@property
def cookie(self):
return self.__cookie
</code></pre>
<p>Problem is cookie value gets changed... | 0 | 2016-06-04T11:54:51Z | 37,630,559 | <p>This is a job for a condition variable.</p>
<pre><code>from threading import Lock, Condition
class A(object):
def __init__(self, cookie):
self.__cookie = cookie
self.refreshing = Condition()
def refresh_cookie():
```This method refresh the cookie after every 10 min```
with self.refreshing:
... | 0 | 2016-06-04T13:02:34Z | [
"python",
"thread-safety"
] |
Pandas read_fwf ignores columns | 37,629,976 | <p>I have a .asc file where each line has 655 entries and looks somewhat like the following (note the leading whitespace)</p>
<pre><code> -999 -999 -999 -999 -999 -999 -999 -999 -999 ... -999 -999
</code></pre>
<p>When I read the file using pandas read_fwf </p>
<pre><code>data = pd.read_fwf('Users/.../file.asc', ind... | 1 | 2016-06-04T11:59:17Z | 37,630,004 | <p><strong>UPDATE2:</strong> using <code>colspecs</code> parameter when calling <code>read_fwf()</code></p>
<pre><code>In [83]: df = pd.read_fwf(fn, skiprows=6, header=None, na_values=[-999],
....: colspecs=[(5,6)] * 654)
In [84]: df.head()
Out[84]:
0 1 2 3 4 5 6 7 8 ... | 3 | 2016-06-04T12:01:48Z | [
"python",
"pandas"
] |
Pandas read_fwf ignores columns | 37,629,976 | <p>I have a .asc file where each line has 655 entries and looks somewhat like the following (note the leading whitespace)</p>
<pre><code> -999 -999 -999 -999 -999 -999 -999 -999 -999 ... -999 -999
</code></pre>
<p>When I read the file using pandas read_fwf </p>
<pre><code>data = pd.read_fwf('Users/.../file.asc', ind... | 1 | 2016-06-04T11:59:17Z | 37,630,049 | <p>Use <code>sep='\s+'</code>as keyword argument as stated in the current documentation for <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_fwf.html" rel="nofollow">pandas - read_fwf</a> to accept 1 or more white space characters as spearators for fields. I would be reluctant in supplying <co... | 0 | 2016-06-04T12:07:09Z | [
"python",
"pandas"
] |
Adding Many Serializer to A Nested Serializer Field | 37,630,032 | <h3>serializers.py</h3>
<pre><code>class BusOncomingSerializer(serializers.Serializer):
idn = serializers.IntegerField(read_only=True)
stops_left = serializers.IntegerField(read_only=True)
class StopOncomingSerialier(serializers.Serializer):
idn = serializers.IntegerField(read_only=True)
buses = BusO... | 2 | 2016-06-04T12:05:32Z | 37,630,264 | <p>You are passing the data incorrectly to <code>StopOncomingSerializer</code>. Instead of passing <code>bus</code> instances, you should pass the values as list of dictionaries.</p>
<p><strong>Sample Data format:</strong></p>
<pre><code>{
'idn': 7,
'buses': [
{'idn':3, 'stops_left': 3},
{'i... | 3 | 2016-06-04T12:31:53Z | [
"python",
"django",
"python-3.x",
"django-rest-framework"
] |
changing inp by deleting element | 37,630,059 | <p>I am looking for a way to delete elements from abaqus inp. The analysis type is dynamic explicit and elements are S4R.
I should notice that elements which should be deleted are updated in a matlab optimization cycle.
Is there any way except using subroutine VUMAT?(even python scripting is preferred)
any idea will a... | 0 | 2016-06-04T12:08:28Z | 37,686,072 | <p>Thank you for reply. I tried your advice, I deleted the elements that I wanted to be removed from *.inp file. But when I imported the the *.inp, ABAQUS did not accept the file and gave error.
What I understood from your answer is that If I could not change *.inp file manually, It would not be possible to make change... | 0 | 2016-06-07T17:51:01Z | [
"python",
"abaqus"
] |
Get All Functions, Classes, datatypes from Python | 37,630,071 | <p>I am developing a small python learning app. where student simply searches for keywords like, <code>list</code>, <code>date</code> my app gives output as help text for keyword.</p>
<p>first i want to extract all python builtins, classes help text using help() into json file.
I tried:</p>
<pre><code>>>> im... | 3 | 2016-06-04T12:10:00Z | 37,630,380 | <p><code>datetime</code> is part of the standard library; its <code>datetime.datetime</code> type is not as built-in as list, which is a <a href="https://docs.python.org/2/library/stdtypes.html" rel="nofollow">built-in type</a>.</p>
<p>If you still insist on iterating through <code>sys.modules</code> rather than <a hr... | 3 | 2016-06-04T12:43:15Z | [
"python"
] |
Get All Functions, Classes, datatypes from Python | 37,630,071 | <p>I am developing a small python learning app. where student simply searches for keywords like, <code>list</code>, <code>date</code> my app gives output as help text for keyword.</p>
<p>first i want to extract all python builtins, classes help text using help() into json file.
I tried:</p>
<pre><code>>>> im... | 3 | 2016-06-04T12:10:00Z | 37,630,556 | <p>You seem to be wanting to create your own version of <code>help()</code>, one that you deem to be in some sense more student-friendly. If so, perhaps you can begin by going to the original. You could look at the source of <code>pydoc.py</code> (found somewhere like <code>C:/Python34/lib/pydoc.py</code>), where <cod... | 0 | 2016-06-04T13:02:13Z | [
"python"
] |
Pygame Menu won't change to level | 37,630,126 | <p>My game opens up to a menu and whenever I select any of the options (Easy, Medium, Hard) it always opens the Easy level no matter what option I click. If someone could have a look over my code (mostly the option, menu, and main functions) and show me where I went wrong and how to fix it that would be greatly appreci... | 0 | 2016-06-04T12:16:06Z | 37,630,777 | <p>Your new edited example isn't working because <code>menu_font</code> is no longer defined. Nevertheless your problem is caused by this line</p>
<pre><code>walls, players, finishes = load_level(currentLevel)
</code></pre>
<p>It is always executed, <code>currentLevel</code> is set to <code>0</code> at the beginning,... | 2 | 2016-06-04T13:27:16Z | [
"python",
"python-3.x",
"pygame"
] |
python pandas: passing in dataframe to df.apply | 37,630,202 | <p>Long time user of this site but first time asking a question! Thanks to all of the benevolent users who have been answering questions for ages :)</p>
<p>I have been using <code>df.apply</code> lately and ideally want to pass a dataframe into the <code>args</code> parameter to look something like so: <code> df.appl... | 3 | 2016-06-04T12:25:36Z | 37,630,775 | <p>The error is in this line:</p>
<pre><code> File "C:\Anaconda3\envs\p2\lib\site-packages\pandas\core\frame.py", line 4017, in apply
if kwds or args and not isinstance(func, np.ufunc):
</code></pre>
<p>Here, <code>if kwds or args</code> is checking whether the length of <code>args</code> passed to <code>apply</... | 2 | 2016-06-04T13:26:47Z | [
"python",
"pandas",
"dataframe"
] |
Taking two and more data frames and extracting data on unique keys in python | 37,630,289 | <p>Firstly I have 2 data frames one in which I have name of a guy and pages liked by him in columns. So no. of columns will be different for different person here is the example. 1st column is the name of user.Then pages liked by him is stored across the row.So no. of columns for 'random guy' will be different from 'ma... | 3 | 2016-06-04T12:33:57Z | 37,695,502 | <p>Thank you for your code. Now it is more clear.</p>
<p>I try optimalize your loops and I think you can rather use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.isin.html" rel="nofollow"><code>isin</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.... | 0 | 2016-06-08T07:08:04Z | [
"python",
"python-2.7",
"pandas"
] |
3 different applications and docker containers | 37,630,394 | <p>I want to setup Kabana and Elastic Search <strong>in Docker</strong> locally first to display logs from a Python web app which isn't in a docker container locally. Although, on a server the Python app is in a docker container.</p>
<p>Kabana and Elastic Search aren't setup on a server and locally yet at all. </p>
<... | 3 | 2016-06-04T12:45:40Z | 37,630,641 | <p>The short answer: Yes, you're own Dockfile, and Yes.</p>
<p>Docker containers can communicate over shared volumes and network bridges.
<a href="https://docs.docker.com/engine/userguide/containers/dockervolumes/" rel="nofollow">https://docs.docker.com/engine/userguide/containers/dockervolumes/</a>
<a href="https://d... | 2 | 2016-06-04T13:12:47Z | [
"python",
"docker",
"containers"
] |
3 different applications and docker containers | 37,630,394 | <p>I want to setup Kabana and Elastic Search <strong>in Docker</strong> locally first to display logs from a Python web app which isn't in a docker container locally. Although, on a server the Python app is in a docker container.</p>
<p>Kabana and Elastic Search aren't setup on a server and locally yet at all. </p>
<... | 3 | 2016-06-04T12:45:40Z | 37,630,642 | <p>I will try to answer your questions:</p>
<ol>
<li>Yes, It's possible, because the container can comunnicate with another container.</li>
</ol>
<blockquote>
<p>Links allow containers to discover each other and securely transfer information about one container to another container. When you set up a link, you crea... | 3 | 2016-06-04T13:12:49Z | [
"python",
"docker",
"containers"
] |
Python: Count of occurrences in dict from another list | 37,630,502 | <p>I am trying to count the number of times a word exists in a dict column based on a subset of interested words.</p>
<p>First I import my data</p>
<pre><code>products = graphlab.SFrame('amazon_baby.gl/')
products['word_count'] = graphlab.text_analytics.count_words(products['review'])
products.head(5)
</code></pre>
... | -1 | 2016-06-04T12:57:30Z | 37,630,780 | <p>Well, I am not pretty sure about what you mean by 'in a dict column'.
If it is a list:</p>
<pre><code>import operator
dictionary={'texts':['red blue blue','red black','blue white white','red','white','black','blue red']}
words=['red','white','blue']
freqs=dict()
for t in dictionary['texts']:
for w in words:
... | 0 | 2016-06-04T13:27:30Z | [
"python",
"word-count",
"graphlab",
"sframe"
] |
Python: Count of occurrences in dict from another list | 37,630,502 | <p>I am trying to count the number of times a word exists in a dict column based on a subset of interested words.</p>
<p>First I import my data</p>
<pre><code>products = graphlab.SFrame('amazon_baby.gl/')
products['word_count'] = graphlab.text_analytics.count_words(products['review'])
products.head(5)
</code></pre>
... | -1 | 2016-06-04T12:57:30Z | 37,631,255 | <p>If you want to count occurrences of words, a fast way to do it is to use <code>Counter</code>object from <code>collections</code></p>
<p>For example : </p>
<pre><code>In [3]: from collections import Counter
In [4]: c = Counter(['hello', 'world'])
In [5]: c
Out[5]: Counter({'hello': 1, 'world': 1})
</code></pre>
... | 1 | 2016-06-04T14:14:56Z | [
"python",
"word-count",
"graphlab",
"sframe"
] |
Python: Count of occurrences in dict from another list | 37,630,502 | <p>I am trying to count the number of times a word exists in a dict column based on a subset of interested words.</p>
<p>First I import my data</p>
<pre><code>products = graphlab.SFrame('amazon_baby.gl/')
products['word_count'] = graphlab.text_analytics.count_words(products['review'])
products.head(5)
</code></pre>
... | -1 | 2016-06-04T12:57:30Z | 37,631,859 | <p>Try this:</p>
<pre><code> wc = {}
for word in products['word_count'].values:
if word in words:
if word not in wc: wc[word] = 1
else: wc[word] += 1
print wc
</code></pre>
| 0 | 2016-06-04T15:21:22Z | [
"python",
"word-count",
"graphlab",
"sframe"
] |
Python: Count of occurrences in dict from another list | 37,630,502 | <p>I am trying to count the number of times a word exists in a dict column based on a subset of interested words.</p>
<p>First I import my data</p>
<pre><code>products = graphlab.SFrame('amazon_baby.gl/')
products['word_count'] = graphlab.text_analytics.count_words(products['review'])
products.head(5)
</code></pre>
... | -1 | 2016-06-04T12:57:30Z | 37,664,005 | <p>If you stick with graphlab (or SFrame), use the <code>SArray.dict_trim_by_keys</code> method. The documentation is here: <a href="https://dato.com/products/create/docs/generated/graphlab.SArray.dict_trim_by_keys.html" rel="nofollow">https://dato.com/products/create/docs/generated/graphlab.SArray.dict_trim_by_keys.h... | 0 | 2016-06-06T18:01:54Z | [
"python",
"word-count",
"graphlab",
"sframe"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.