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 |
|---|---|---|---|---|---|---|---|---|---|
Return True if item is empty string | 39,194,596 | <p>Please consider this snippet:</p>
<pre><code>>>> i = ["", 1, 2]
>>> all([x for x in i])
False
</code></pre>
<p>What would be Pythonic way to make this snippet return <code>True</code> even if item in iterable is empty string?</p>
<p>Standard restrictions should apply - if item is <code>None</cod... | 0 | 2016-08-28T18:40:59Z | 39,194,613 | <pre><code>>>> lst = ["", 1, 2]
>>>
>>> all(True if i=='' else i for i in lst)
True
</code></pre>
<p>If you want True if there is at least one item that evaluates to True use <code>any()</code>.</p>
<pre><code>>>> any(lst)
True
</code></pre>
<p>Note that in general <code>any()</c... | 2 | 2016-08-28T18:42:42Z | [
"python"
] |
Return True if item is empty string | 39,194,596 | <p>Please consider this snippet:</p>
<pre><code>>>> i = ["", 1, 2]
>>> all([x for x in i])
False
</code></pre>
<p>What would be Pythonic way to make this snippet return <code>True</code> even if item in iterable is empty string?</p>
<p>Standard restrictions should apply - if item is <code>None</cod... | 0 | 2016-08-28T18:40:59Z | 39,194,624 | <pre><code>all([x for x in i if not isinstance(x, str)])
</code></pre>
<p>The only falsy string is the empty string, so if you don't want to test for it, then filter out the strings.</p>
| 1 | 2016-08-28T18:43:56Z | [
"python"
] |
Return True if item is empty string | 39,194,596 | <p>Please consider this snippet:</p>
<pre><code>>>> i = ["", 1, 2]
>>> all([x for x in i])
False
</code></pre>
<p>What would be Pythonic way to make this snippet return <code>True</code> even if item in iterable is empty string?</p>
<p>Standard restrictions should apply - if item is <code>None</cod... | 0 | 2016-08-28T18:40:59Z | 39,194,641 | <p>You can use <a href="https://docs.python.org/2/library/functions.html#all" rel="nofollow">all</a>, for instance:</p>
<pre><code>tests = [
[None, False, "", 1, 2],
["", 1, 2],
[1, 2],
[]
]
for i in tests:
print i
print all(filter(lambda x: x != '', i))
print all(True if x == '' else x fo... | -1 | 2016-08-28T18:45:12Z | [
"python"
] |
Return True if item is empty string | 39,194,596 | <p>Please consider this snippet:</p>
<pre><code>>>> i = ["", 1, 2]
>>> all([x for x in i])
False
</code></pre>
<p>What would be Pythonic way to make this snippet return <code>True</code> even if item in iterable is empty string?</p>
<p>Standard restrictions should apply - if item is <code>None</cod... | 0 | 2016-08-28T18:40:59Z | 39,194,726 | <p>This option looks nice to me.</p>
<pre><code>all(x or x=="" for x in i)
</code></pre>
| 2 | 2016-08-28T18:55:30Z | [
"python"
] |
'ImportError: No module named pillow' in PyCharm | 39,194,601 | <p>I'm getting an error while using PyCharm which doesn't allow me to import the pillow module even though I have it installed as a package in the project interpreter. Any help is greatly appreciated!</p>
<p><a href="http://imgur.com/a/DfjC3" rel="nofollow">http://imgur.com/a/DfjC3</a></p>
| 0 | 2016-08-28T18:41:19Z | 39,194,684 | <p>You try to run code with default Python interpreter (<code>/Library/Frameworks/Python.framework/Versions/3.2/bin/python3</code>). You need to configure PyCharm to run Your code with anaconda (<code>~/anaconda/bin/python</code>)</p>
<p>And now (Like @JamesK say) read Pillow tutorial and documentation:</p>
<p><code>... | 0 | 2016-08-28T18:49:19Z | [
"python",
"python-3.x",
"import",
"pycharm"
] |
'ImportError: No module named pillow' in PyCharm | 39,194,601 | <p>I'm getting an error while using PyCharm which doesn't allow me to import the pillow module even though I have it installed as a package in the project interpreter. Any help is greatly appreciated!</p>
<p><a href="http://imgur.com/a/DfjC3" rel="nofollow">http://imgur.com/a/DfjC3</a></p>
| 0 | 2016-08-28T18:41:19Z | 39,194,779 | <p>While the name of the package is pillow, it is a replacement for PIL and uses the PIL for the name of the base module</p>
<p>the usual way to use pillow is</p>
<pre><code>from PIL import Image
im = Image.open("filename")
</code></pre>
<p>See the <a href="http://pillow.readthedocs.io/en/3.1.x/handbook/tutorial.htm... | 0 | 2016-08-28T19:01:17Z | [
"python",
"python-3.x",
"import",
"pycharm"
] |
How to import the most recent version of the print function in Python 2.7.x? | 39,194,615 | <p>I have discovered that I can't use the <code>flush</code> argument in the new print function if I use Python 2.7.11. I have used:</p>
<pre><code>from __future__ import print_function
print('Hello', flush=True)
</code></pre>
<p>but it complains with the error:</p>
<pre><code>Traceback (most recent call last):
F... | 0 | 2016-08-28T18:42:43Z | 39,213,378 | <ol>
<li><blockquote>
<p>its importing the python function that I am not expecting</p>
</blockquote>
<p>I don't see why, this is the version of <code>print</code> <a href="https://docs.python.org/2/library/functions.html#print" rel="nofollow">that's documented in 2.7.x</a>.</p>
<blockquote>
<p>which print functio... | 1 | 2016-08-29T19:03:53Z | [
"python",
"python-2.7",
"python-3.x",
"printing",
"flush"
] |
Python for loop doesn't work as expected | 39,194,734 | <p>I don't get any error messages, but the for loop doesn't produce the same result as the explicit statements. kp is an instance of a class and key0-9 are child elements of that class. Should what I'm trying to do actually work? If yes then maybe its something about how PyQt4 classes are constructed that is the pro... | 2 | 2016-08-28T18:56:18Z | 39,194,919 | <p>What seems to be the problem is while you are invoking the disconnect() function in for loop, there could be some error with the list depending on the scope you are using it in or some constraint against running the function in a loop.</p>
<p>A good way to debug this will be to run this code to see where the code i... | -1 | 2016-08-28T19:18:15Z | [
"python",
"pyqt4"
] |
How to add a character at the begining of multiples selected lines | 39,194,747 | <p>I'm coding some python files with sublime and I'd like to comment multiple selected lines which means putting the character '#' at the beginning of each selected line. Is it possible to create a such shortcut-key Binding on sublime to do that ?</p>
<p>Thanks
Vincent</p>
| -1 | 2016-08-28T18:57:48Z | 39,194,781 | <p>To comment code with sublime text3 you can use the existing shortcut, which is bound to <code>Ctrl-/</code></p>
<p>If you want to change that shortcut, you can edit your keyboard user settings and add this line:</p>
<p><code>{ "keys": ["ctrl+7"], "command": "toggle_comment", "args": { "block": false } }</code></p>... | 0 | 2016-08-28T19:01:21Z | [
"python",
"sublimetext"
] |
How to add a character at the begining of multiples selected lines | 39,194,747 | <p>I'm coding some python files with sublime and I'd like to comment multiple selected lines which means putting the character '#' at the beginning of each selected line. Is it possible to create a such shortcut-key Binding on sublime to do that ?</p>
<p>Thanks
Vincent</p>
| -1 | 2016-08-28T18:57:48Z | 39,194,790 | <p>You can put three times ' in the front of your commented block and three times at the end.</p>
<pre><code>''' This is
a multi-line
comment '''
</code></pre>
| 0 | 2016-08-28T19:01:54Z | [
"python",
"sublimetext"
] |
Slicing is adding a 3rd Dimension to my Array - Not sure why | 39,194,834 | <p>I am trying to index the testdata with just the labels that equal 2 and 3. However, when I run this code, it turns my array from 2D (100 x 100) into 3D (100 x 1 x 100).</p>
<p>Can anyone explain why it is doing this? The last line in the code is the culprit, but I am not sure why it is happening.</p>
<pre><code>... | 2 | 2016-08-28T19:07:26Z | 39,196,101 | <p>When there are puzzles, print intermediate values. Better yet, run a test case in a interactive shell so you can check each value, and understand what is going on. Keep track of the shapes.</p>
<p>Looks like <code>labels</code> is a 1d array of numbers like:</p>
<pre><code>In [212]: labels=np.array([0,1,2,2,3,2,... | 1 | 2016-08-28T21:48:57Z | [
"python",
"numpy"
] |
OpenGL: How do I apply a texture to this cube? | 39,194,862 | <p>I'm trying to learn OpenGL, and I've been going through a lot of tutorials on loading a texture, but every single one seems to miss the most important step: how do I actually put a texture on something?</p>
<p>I'm using Python for this, and here is my function that loads the texture:</p>
<pre><code>def loadTexture... | 0 | 2016-08-28T19:11:35Z | 39,195,353 | <p>There are few issues with your actual code:</p>
<ul>
<li>You're not calling the method to load your textures. </li>
<li>You're drawing only lines of the cube, you need polygons to be filled up with the actual textures, which means using either triangles or quads with texture coordinates.</li>
<li>You're not process... | 4 | 2016-08-28T20:11:37Z | [
"python",
"opengl",
"pygame",
"pyopengl"
] |
Pandas groupby to get two aggregated functions then convert to list of list | 39,194,893 | <p>I'm looking for a better way to write this. This works fine for my sample data set, but is pretty slow on a larger data set. Starting with a <code>dataframe</code> of customer purchases numbers. I'd like to get a list of lists in the format: ``[Customer, Mean of Orders, Count of Orders]`</p>
<pre><code>import panda... | 2 | 2016-08-28T19:15:30Z | 39,194,923 | <p>Can you try this one? </p>
<pre><code>df.groupby('Customer').agg(['mean', 'count']).reset_index().values.tolist()
Out: [['Customer0', 11, 2], ['Customer1', 23, 1]]
</code></pre>
<p>A small note: This can only improve your code significantly if the number of groups (<code>len(values)</code>) is quite large because ... | 2 | 2016-08-28T19:18:40Z | [
"python",
"python-2.7",
"pandas"
] |
Queue size appears to be the ENV size in SimPy | 39,194,898 | <p>I am just starting to work on an event simulation, and I am having some issues with monitoring the queue.</p>
<p>It appears that everytime I check the queue, it is actually showing the Env.now. Any advice?</p>
<pre><code>import simpy
num_of_machines = 2
env = simpy.Environment()
bcs = simpy.Resource(env, capaci... | 0 | 2016-08-28T19:15:48Z | 39,215,796 | <p>You spawn a <code>process_client()</code> every timestep, so when the first of these processes is done after 90 time steps, you already have created 90 new processes that are queueing up. So your numbers are looking quite right.</p>
| 0 | 2016-08-29T21:55:55Z | [
"python",
"simpy"
] |
Python Stored procedure not running, No errors | 39,194,924 | <p>The following procedure works fine from mysql client but not running from Python.</p>
<p><strong>Stored Procedure</strong></p>
<pre><code>CREATE DEFINER=`music-cnv`@`%` PROCEDURE `StoreFileStats`(FNAME VARCHAR(200), FEXT varchar(4), FBDIR VARCHAR(100), FRDIR VARCHAR(250), FSIZE bigint(8), FMDATE bigint(8), FCDATE ... | 0 | 2016-08-28T19:19:06Z | 39,196,993 | <p>Just needed to commit. When running procedure from shell auto commit is enabled. But when run from Python must manually run commit.</p>
| 0 | 2016-08-29T00:18:45Z | [
"python",
"mysql",
"stored-procedures"
] |
Python global array with multiprocessing | 39,194,994 | <p>Please consider the following code:</p>
<pre><code>from multiprocessing import Process
import time
myArray = []
def myThread():
counter = 0
global myArray
while True:
myArray.append(counter)
time.sleep(1)
counterThread = Process(target=myThread,)
counterThread.start()
while True:
... | 1 | 2016-08-28T19:28:38Z | 39,195,075 | <p>You are creating an second process, which has no access to data of the main process. You can use threading.Thread(target=myThread,), but you has to synchronize the access threading.Lock(), if you are using more than one thread. </p>
<p>You should terminate your thread, when you are finished and wait for the thread ... | 2 | 2016-08-28T19:38:06Z | [
"python",
"arrays",
"multithreading",
"global",
"multiprocess"
] |
Create a new variable to represent the last result in a time series with pandas | 39,195,043 | <p>I have a df that looks something like this:</p>
<pre><code>A B C outcome time people_id
. . . 0 34 'ID_4'
. . . 1 23 'ID_2'
. . . 0 2 'ID_1'
. . . 1 85 'ID_4'
</code></pre>
<p>I am trying to create a new variable that represents the most recent result of a per each ID bu... | 0 | 2016-08-28T19:34:14Z | 39,229,090 | <p>This should do it if I'm understanding what you want correctly:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'a': ['A', 'B', 'C', 'D', 'E'],
'outcome': [0, 1, 0, 1, 1],
'time': [34, 34, 2, 85, 34],
'people_id': ['ID_4', 'ID_2', 'ID_1', 'ID_4', 'ID_4... | 1 | 2016-08-30T13:37:56Z | [
"python",
"pandas"
] |
Use Jinja Variable to generate n elements | 39,195,065 | <p>I want to use Jinja variables to generate n options in a drop down. Here is an example:</p>
<pre><code> Session Select: <br>
{{ sessions }}
<select style="color:black">
{% for session in sessions %}
<li>{{ session }}</li>
{% endfor %}
</select&g... | -1 | 2016-08-28T19:36:48Z | 39,195,168 | <p>To generate items within a select box you use the <code><option></code> tag, not <code><li></code>.</p>
| 0 | 2016-08-28T19:49:36Z | [
"python",
"flask",
"jinja2"
] |
Use Jinja Variable to generate n elements | 39,195,065 | <p>I want to use Jinja variables to generate n options in a drop down. Here is an example:</p>
<pre><code> Session Select: <br>
{{ sessions }}
<select style="color:black">
{% for session in sessions %}
<li>{{ session }}</li>
{% endfor %}
</select&g... | -1 | 2016-08-28T19:36:48Z | 39,199,413 | <pre><code>Session Select: <br>
<select style="color:black">
{% for session in sessions %}
<option value="{{ session }}">{{ session }}</option>
{% endfor %}
</select> <br><br>
</code></pre>
| 0 | 2016-08-29T06:00:30Z | [
"python",
"flask",
"jinja2"
] |
Use Jinja Variable to generate n elements | 39,195,065 | <p>I want to use Jinja variables to generate n options in a drop down. Here is an example:</p>
<pre><code> Session Select: <br>
{{ sessions }}
<select style="color:black">
{% for session in sessions %}
<li>{{ session }}</li>
{% endfor %}
</select&g... | -1 | 2016-08-28T19:36:48Z | 39,279,509 | <p>Assuming <code>no_sessions</code> is your <code>n</code> value... I would try something like this:</p>
<pre><code>Session Select: <br>
<select style="color:black">
{% range number from 1 to no_sessions %}
<option>Session {{ number }}</option>
{% endrange %}
</select> &l... | 0 | 2016-09-01T19:30:51Z | [
"python",
"flask",
"jinja2"
] |
How can I store raw input into a variable and then pass that variable into another script without requesting input again? | 39,195,077 | <p>Basically what I am trying to do is store raw input into a variable and then call that variable in another script. However, when I do this the second script asks for the input again. Is there a way to save the input in the variable without requesting the input in the second script?</p>
<pre><code>#!/usr/bin/env pyt... | 0 | 2016-08-28T19:38:26Z | 39,195,159 | <p>Not sure whether I've understood correctly your question but you could try this:</p>
<blockquote>
<p>main.py</p>
</blockquote>
<pre><code>from bar import user_input
def foo():
token, member = user_input()
print "Login user {0} with token {1}".format(member, token)
if __name__ == "__main__":
foo()
<... | 0 | 2016-08-28T19:47:43Z | [
"python"
] |
How to load multiple images in a numpy array ? | 39,195,113 | <p>How to load pixels of multiple images in a directory in a numpy array . I have loaded a single image in a numpy array . But can not figure out how to load multiple images from a directory . Here what i have done so far </p>
<pre><code>image = Image.open('bn4.bmp')
nparray=np.array(image)
</code></pre>
<p>This load... | 1 | 2016-08-28T19:43:06Z | 39,195,332 | <p>To get a list of BMP files from the directory <code>BengaliBMPConvert</code>, use:</p>
<pre><code>import glob
filelist = glob.glob('BengaliBMPConvert/*.bmp')
</code></pre>
<p>On the other hand, if you know the file names already, just put them in a sequence:</p>
<pre><code>filelist = 'file1.bmp', 'file2.bmp', 'fi... | 0 | 2016-08-28T20:09:08Z | [
"python",
"image",
"numpy",
"image-processing"
] |
Python/Requests: Correct login returns 401 unauthorized | 39,195,170 | <p>I have a python application logs in to a remote host via basic HTTP authentication.
Authentication is as follows: </p>
<pre><code>def make_authenticated_request(host, username, password):
url = host
r = requests.get(url, auth=(username, password))
r.raise_for_status()
return r
test = Looter.make_a... | 0 | 2016-08-28T19:49:39Z | 39,195,305 | <p>I might rewrite it to look something like this.. change it around however you need or like. The point here is that i'm using a session and passing it around to make another requests. You can reuse that session object to make other requests. Now if you making lots of requests an authing in each time like your code... | 1 | 2016-08-28T20:05:37Z | [
"python",
"python-requests"
] |
How can I extract data using the 'groupby' | 39,195,179 | <pre><code>import pandas as pd
df= pd.DataFrame({'date':[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5],
'name':list('aaaaabbbbbccccc'),
'v1':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50],
'v2':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50],
'v3':[10,20,30,40,50,10,20,30,40,50,10,20,30,40,50]})
a= list(set(list(... | 1 | 2016-08-28T19:50:26Z | 39,195,661 | <p>looking at your desired data set i don't think you need to <code>groupby</code> your <code>df</code>, you can simply filter it:</p>
<pre><code>In [112]: df.query('v1 >= 10 and v2 >= 20 and v3 <= 40')
Out[112]:
date name v1 v2 v3
1 2 a 20 20 20
2 3 a 30 30 30
3 4 a 40 ... | 0 | 2016-08-28T20:50:53Z | [
"python",
"python-3.x",
"pandas",
"dataframe"
] |
peewee custom field - define allowed values | 39,195,189 | <p>Two cases:</p>
<p>1.) I'd like to define an attribute (val) that can take the integers 0, 1, or 2 only.</p>
<pre><code>class Trinary(Model):
"""val should accept the values 0, 1 or 2 only"""
val = IntegerField()
</code></pre>
<p>2.) I'd like to define an attribute (val) that can take specific strings only... | 1 | 2016-08-28T19:51:22Z | 39,195,355 | <p>The objects <code>IntegerField</code> etc. are classes, and can be subclassed (<a href="http://docs.peewee-orm.com/en/latest/peewee/models.html#custom-fields" rel="nofollow">documentation</a>):</p>
<p>The classes should define <code>db_value</code> to convert from python to database,
and <code>python_value</code> f... | 1 | 2016-08-28T20:11:53Z | [
"python",
"python-3.x",
"peewee"
] |
Translating a Linear Regression from Matlab to Python | 39,195,204 | <p>I tried to translate a piece of code from Matlab to Python and I'm running into some errors:</p>
<p>Matlab:</p>
<pre><code>function [beta] = linear_regression_train(traindata)
y = traindata(:,1); %output
ind2 = find(y == 2);
ind3 = find(y == 3);
y(ind2) = -1;
y(ind3) = 1;
X = traindata(:,2:257); %X matrix,with siz... | 1 | 2016-08-28T19:53:15Z | 39,197,068 | <p>The problem is that you are working with numpy arrays, not matrices as in MATLAB. Matrices, by default, do matrix mathematical operations. So <code>X*Y</code> does a matrix multiplication of <code>X</code> and <code>Y</code>. With arrays, however, the default is to use element-by-element operations. So <code>X*Y... | 2 | 2016-08-29T00:33:33Z | [
"python",
"matlab"
] |
How to get Model Choice Field name instead of id in template using django rest framework | 39,195,262 | <p>I am getting id of choice field in the template.But I want name of the choice field to display. Please review the below files and let me know how to get the name.</p>
<p>here is my models.py</p>
<p>===============================================================</p>
<pre><code>class Posted(models.Model):
name ... | 0 | 2016-08-28T20:00:18Z | 39,195,806 | <p>What do you mean by choices ? I see no <code>choices</code> in Field kwargs. You can set Choice field by for example:
<code>chairs = models.IntegerField(max_length=255, choices=CHOICES)</code> and where exactly you get id's instead of name ?</p>
| 0 | 2016-08-28T21:09:38Z | [
"python",
"django",
"django-rest-framework"
] |
How to get Model Choice Field name instead of id in template using django rest framework | 39,195,262 | <p>I am getting id of choice field in the template.But I want name of the choice field to display. Please review the below files and let me know how to get the name.</p>
<p>here is my models.py</p>
<p>===============================================================</p>
<pre><code>class Posted(models.Model):
name ... | 0 | 2016-08-28T20:00:18Z | 39,208,554 | <p>You can use <a href="http://www.django-rest-framework.org/api-guide/relations/#slugrelatedfield" rel="nofollow">SlugRelatedField</a> option to return a specific field as a relation object. For example,</p>
<pre><code>class BlogsSerializer(serializers.ModelSerializer):
author = AccountSerializer(read_only=True,requi... | 0 | 2016-08-29T14:20:18Z | [
"python",
"django",
"django-rest-framework"
] |
How to get Model Choice Field name instead of id in template using django rest framework | 39,195,262 | <p>I am getting id of choice field in the template.But I want name of the choice field to display. Please review the below files and let me know how to get the name.</p>
<p>here is my models.py</p>
<p>===============================================================</p>
<pre><code>class Posted(models.Model):
name ... | 0 | 2016-08-28T20:00:18Z | 39,210,089 | <p>thanks @ Karol Sztajerwald.
Yes BlogsSerializer has to be made like that.</p>
<p>Finally Blogs Serializer.py is </p>
<pre><code>class TagsSerializer(serializers.ModelSerializer):
class Meta:
model = Tags
fields = ('id','name')
read_only_fields=('id','name')
class PostedSerializer(seri... | 0 | 2016-08-29T15:37:56Z | [
"python",
"django",
"django-rest-framework"
] |
django rest framework: change in ListAPIView return format? | 39,195,268 | <p>Just in the process of upgrading django rest framework from 3.2.3 to 3.4.6.<br>
I also upgraded django from 1.8.6 to 1.10</p>
<p>It looks like return values from ListAPIView have changed format? i.e. they used to be objects like</p>
<pre><code>{
"count": 0,
"next": null,
"previous": null,
"results": []
}
<... | 0 | 2016-08-28T20:00:52Z | 39,195,876 | <p>Apparently now in django rest framework you must explictly set the pagination class or at least a global default.</p>
<p><a href="http://www.django-rest-framework.org/api-guide/pagination/#setting-the-pagination-style" rel="nofollow">http://www.django-rest-framework.org/api-guide/pagination/#setting-the-pagination-... | 0 | 2016-08-28T21:20:06Z | [
"python",
"django",
"django-rest-framework"
] |
Find the largest subset of a set of numbers such that the sum of any 2 numbers is not divisible by a given number | 39,195,291 | <p>I'm trying to solve the Hackerrank problem <a href="https://www.hackerrank.com/challenges/non-divisible-subset?h_r=next-challenge&h_v=zen" rel="nofollow">Non-Divisible Subset</a> stated below:</p>
<p><a href="http://i.stack.imgur.com/LYyCy.png" rel="nofollow"><img src="http://i.stack.imgur.com/LYyCy.png" alt="e... | 4 | 2016-08-28T20:03:40Z | 39,218,562 | <p><strong>Instead of generating all pairs, this could be done by counting modulus.</strong></p>
<p>Time Complexity: O(n + k)</p>
<p>Space Complexity: O(k) or O(1), because k is 100 at max, O(k) => O(1)</p>
<hr>
<p><strong>Basic idea</strong></p>
<blockquote>
<p>(a + b) % k = ((a % k) + (b % k)) % k</p>
</blockq... | 2 | 2016-08-30T04:00:54Z | [
"python",
"algorithm"
] |
Find the largest subset of a set of numbers such that the sum of any 2 numbers is not divisible by a given number | 39,195,291 | <p>I'm trying to solve the Hackerrank problem <a href="https://www.hackerrank.com/challenges/non-divisible-subset?h_r=next-challenge&h_v=zen" rel="nofollow">Non-Divisible Subset</a> stated below:</p>
<p><a href="http://i.stack.imgur.com/LYyCy.png" rel="nofollow"><img src="http://i.stack.imgur.com/LYyCy.png" alt="e... | 4 | 2016-08-28T20:03:40Z | 39,218,953 | <p>The method I used was:</p>
<pre><code>1. find power set of given list of integers.
2. sort power set by subset size.
3. iterate down the sorted power set and print if subset meets problem's conditions.
</code></pre>
<p>In java:</p>
<pre class="lang-java prettyprint-override"><code>import java.util.*;
public class... | 1 | 2016-08-30T04:50:12Z | [
"python",
"algorithm"
] |
TypeError: cannot determine truth value of Relational when using sympy.solver | 39,195,378 | <p>I want to numerically solve the equation </p>
<blockquote>
<p>beta.ppf(x,a,b)-c=0</p>
</blockquote>
<p>where a,b,c are known constants. When I tried</p>
<pre><code>from sympy.solvers import solve
from sympy import Symbol
from scipy.stats import beta
x=Symbol('x')
solve(beta.ppf(x,a,b)-c,x)
</code></pre>
<p>It... | 0 | 2016-08-28T20:14:16Z | 39,195,756 | <p><a href="http://docs.scipy.org/doc/scipy/reference/optimize.html#root-finding" rel="nofollow">Scipy.optimize</a> (check section: "Root finding") provides numerous functions for numerically solving equations. </p>
<p>For the following example, I will use the <code>newton</code> function (the other available solvers ... | 1 | 2016-08-28T21:03:20Z | [
"python",
"scipy"
] |
Importing Cookies with Mechanize | 39,195,395 | <p>(Using Python 2.7, with Mechanize)</p>
<p>Let's say I have a cookie on Twitter, named <code>auth_token</code> and it's Value is: <code>ABC123</code>.</p>
<p><a href="http://i.stack.imgur.com/1GGXW.png" rel="nofollow"><img src="http://i.stack.imgur.com/1GGXW.png" alt="https://i.gyazo.com/de568907c939617c14a87469666... | 0 | 2016-08-28T20:16:04Z | 39,358,045 | <pre><code>import Cookie
import cookielib
cookiejar =cookielib.LWPCookieJar()
br = mechanize.Browser()
br.set_cookiejar(cookiejar)
cookie = cookielib.Cookie(auth_token='ABC123')
cookiejar.set_cookie(cookie)
</code></pre>
| 0 | 2016-09-06T21:22:06Z | [
"python",
"cookies",
"mechanize",
"cookielib"
] |
NameError: name 'articles' is not defined | 39,195,396 | <p>I'm beginner in Django and I am having errors on my very first day.
Can anyone help me?</p>
<p>Here is error I'm getting </p>
<blockquote>
<p>File "/home/akshay/Desktop/cdsmalpha/cdsmalpha/urls.py", line 23, in module><br>
url(r'^hello/', articles.views.hello, name = 'hello'),<br>
NameError: name 'art... | 0 | 2016-08-28T20:16:06Z | 39,195,476 | <p>You are importing the <code>views</code> class from the module <code>articles</code>. You never imported the articles module its self. there is no need to say <code>articles.views</code>. You only use the syntax <code>module.class</code> or <code>module.function</code> when just importing the module. But if import... | 1 | 2016-08-28T20:25:07Z | [
"python",
"django",
"django-views"
] |
NameError: name 'articles' is not defined | 39,195,396 | <p>I'm beginner in Django and I am having errors on my very first day.
Can anyone help me?</p>
<p>Here is error I'm getting </p>
<blockquote>
<p>File "/home/akshay/Desktop/cdsmalpha/cdsmalpha/urls.py", line 23, in module><br>
url(r'^hello/', articles.views.hello, name = 'hello'),<br>
NameError: name 'art... | 0 | 2016-08-28T20:16:06Z | 39,195,535 | <p>You have already imported articles app, so now you can just point it from there:
<code>views.hello</code></p>
| 1 | 2016-08-28T20:33:23Z | [
"python",
"django",
"django-views"
] |
Travelling salesman with a directional constraint | 39,195,429 | <p>I am trying to order an array of 3D coordinates by their order along a path. A sample:</p>
<pre><code>points = np.array([[ 0.81127451, 0.22794118, 0.52009804],
[ 0.62986425, 0.4546003 , 0.12971342],
[ 0.50666667, 0.41137255, 0.65215686],
[ 0.79526144, ... | 24 | 2016-08-28T20:19:30Z | 39,252,240 | <p>Judging by the documentation on pytsp, the distance matrix doesn't have to be symmetric. This means that you could modify the L2 norm to incorporate information on a preferred direction into that matrix. Say you have a preferred direction for some pairs of points (i,j), then for each of these point you could divide ... | 1 | 2016-08-31T14:22:51Z | [
"python",
"numpy",
"linear-algebra",
"graph-algorithm",
"traveling-salesman"
] |
Plotting PatchCollection according to a function | 39,195,553 | <p>Completely new to the site and to rather new to Python as well, so help and hints appreciated.</p>
<p>I've got some data of (x,y) forming several nearly circle-shaped curves around a center. But for the sake of the example, I just created some (x,y) forming circles.</p>
<p>Now, I want to plot those and fill the sp... | 3 | 2016-08-28T20:36:06Z | 39,201,159 | <p>You need to add the circles from the biggest to the smallest, so they won't run over each other.</p>
<p>I used <a href="http://stackoverflow.com/questions/9215658/plot-a-circle-with-pyplot">plot a circle with pyplot</a>
and <a href="http://matplotlib.org/users/colormaps.html" rel="nofollow">http://matplotlib.org/us... | 1 | 2016-08-29T07:54:44Z | [
"python",
"matplotlib",
"plot"
] |
django admin not recognized after enabling django-social-auth backends | 39,195,559 | <p>I have used django-social-auth in my project to sign in using facebook but then I couldn't login to django admin page even after logout from facebook.</p>
<p>I thought I forgot my password and tried to change it from shell got: </p>
<pre><code>>>> from django.contrib.auth.models import User
>>> U... | 0 | 2016-08-28T20:36:56Z | 39,195,758 | <p>Did you run <code>python manage.py createsuperuser</code> ? It looks like you have no super user at all. How did you login into <code>admin</code> ?</p>
| 0 | 2016-08-28T21:03:26Z | [
"python",
"django",
"django-admin"
] |
Looping constans in python with MMA8451 Accelerometer on RPi | 39,195,567 | <p>I would like to continuously retrieve data from device MMA8451 accelerometer. Unfortunately there is no proper workaround available.</p>
<p>The problem is that the code get me the first values of axis, but even though i put the request into a loop it just keep on giving me back the same measurements.</p>
<p>My cod... | 1 | 2016-08-28T20:38:07Z | 39,202,762 | <p>The way it is currently coded, you read the device once then loop getting the X/Y/Z values from that single reading.</p>
<p>You need to move the call to block_read() INSIDE the loop, i.e. Below the <code>For a in range(10000):</code> statement.</p>
| 0 | 2016-08-29T09:27:02Z | [
"python",
"raspberry-pi",
"adafruit"
] |
Difficulty replacing values in Pandas column | 39,195,624 | <p>First time posting here, pretty new to Python and having some difficulty rewriting a value in a pandas column. I have a data frame with some columns (among them 'Ba Avg', 'Study', 'Latitude', 'Upper Depth', etc). I'm trying to average some of the values and write them to a new column called 'Upper Avg'.</p>
<p>At t... | 3 | 2016-08-28T20:46:50Z | 39,196,068 | <p>Start with this. Here is <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow">np.where</a> <code>outcome = np.where(condition,true,false)</code></p>
<pre><code>#df['Upper Avg'] = ""
#index = df.index.tolist()
# for i in index:
# if df['Study'][i] == 1020:
# ... | 1 | 2016-08-28T21:44:51Z | [
"python",
"pandas"
] |
Difficulty replacing values in Pandas column | 39,195,624 | <p>First time posting here, pretty new to Python and having some difficulty rewriting a value in a pandas column. I have a data frame with some columns (among them 'Ba Avg', 'Study', 'Latitude', 'Upper Depth', etc). I'm trying to average some of the values and write them to a new column called 'Upper Avg'.</p>
<p>At t... | 3 | 2016-08-28T20:46:50Z | 39,196,596 | <p>When you use .loc, .ix, and .iloc, you will probably (correctly) get a warning about setting a value on a copy if you use the syntax:</p>
<pre><code>df.loc[index]["column"]
</code></pre>
<p>The way to correctly do this is like this:</p>
<pre><code>df.loc[index, "column"]
</code></pre>
<p>Note the difference. If ... | 0 | 2016-08-28T23:08:59Z | [
"python",
"pandas"
] |
Plot multiple ROC from multiple column values | 39,195,628 | <p>Assuming I have retrieved 3 arrays from 3 columns in a <code>csv</code> file which are:</p>
<pre><code>y1=['1', '0', '0', '0', '1'];
y2=['1', '1', '1', '0', '0'];
y3=['0', '1', '1', '0', '1'];
</code></pre>
<p>How can I plot 2 ROCs such that <code>y1</code> vs <code>y2</code> and <code>y1</code> vs <code>y3</code>... | 0 | 2016-08-28T20:47:24Z | 39,198,364 | <p>Assuming y1 is your label and y2 and y3 are your scores below code should do it:</p>
<pre><code>y1=[1, 0, 0, 0, 1];
y2=[1, 1, 0, 0, 1];
y3=[0, 0, 1, 0, 1];
from sklearn.metrics import *
import pandas as pd
import matplotlib.pyplot as plt
plt.figure(figsize=(14,10),dpi=640)
fpr, tpr, thresholds = roc_curve(y1, y2)
... | 0 | 2016-08-29T04:10:07Z | [
"python",
"scikit-learn",
"multiple-columns",
"roc"
] |
Tkinter import with PyCharm | 39,195,711 | <p>I want to create a tkinter window using pycharm:</p>
<pre><code>from tkinter import *
root = Tk()
root.mainloop()
</code></pre>
<p>Apparently PyCharm tells me that <code>from tkinter import *</code> is an unused import statement, and <code>root = Tk()</code> is an unresolved reference. What's confusing me is tha... | 1 | 2016-08-28T20:57:13Z | 39,195,760 | <p>Try this </p>
<pre><code>from Tkinter import *
</code></pre>
| -3 | 2016-08-28T21:03:54Z | [
"python",
"tkinter",
"pycharm"
] |
Tkinter import with PyCharm | 39,195,711 | <p>I want to create a tkinter window using pycharm:</p>
<pre><code>from tkinter import *
root = Tk()
root.mainloop()
</code></pre>
<p>Apparently PyCharm tells me that <code>from tkinter import *</code> is an unused import statement, and <code>root = Tk()</code> is an unresolved reference. What's confusing me is tha... | 1 | 2016-08-28T20:57:13Z | 39,205,052 | <p>In the end I managed to fix this problem myself, here's what I did:</p>
<ul>
<li>Deleted the ".idea" file associated with the project.</li>
<li>In PyCharm: <strong>File >> Open >> "path to project" >> Ok</strong> (reopen project)</li>
</ul>
<p>Now it it looks as normal as it was before.</p>
| 0 | 2016-08-29T11:21:40Z | [
"python",
"tkinter",
"pycharm"
] |
Numpy indexing: Set values of an array given by conditions in different array | 39,195,729 | <p>I want to set all values of an array to 0 that have values that are not in a different array.</p>
<p>Easy if it's only one condition:</p>
<pre><code>a = np.array([[1,2],[2,4],[5,6]])
cond = 1
a[a!=cond] = 0
</code></pre>
<p>What about if I have a list of conditions, e.g. </p>
<pre><code>cond = np.array([1,2,6])
... | 3 | 2016-08-28T20:59:01Z | 39,195,786 | <p>Crux of the solution is : </p>
<p><code>NOT( option1) & NOT(option2) & NOT(option3)</code> would be an equivalent of</p>
<p><code>NOT (option1 | option2 | option3 )</code>. </p>
<p>Now, to get the mask for <code>option1 | option2 | option3</code>, we have a built-in <a href="http://docs.scipy.org/doc/nump... | 5 | 2016-08-28T21:08:05Z | [
"python",
"numpy",
"indexing"
] |
Numpy indexing: Set values of an array given by conditions in different array | 39,195,729 | <p>I want to set all values of an array to 0 that have values that are not in a different array.</p>
<p>Easy if it's only one condition:</p>
<pre><code>a = np.array([[1,2],[2,4],[5,6]])
cond = 1
a[a!=cond] = 0
</code></pre>
<p>What about if I have a list of conditions, e.g. </p>
<pre><code>cond = np.array([1,2,6])
... | 3 | 2016-08-28T20:59:01Z | 39,195,835 | <p>Well, there's the function <code>np.in1d</code> which tests if the first array<br>
contains any of the items from the second array. <br>
But since this works on 1d arrays, and you need to test on a 2d array<br>
the solution is a bit tricky, using the fact that <code>ravel()</code> returns a view:</p>
<pre><code>a =... | 3 | 2016-08-28T21:12:53Z | [
"python",
"numpy",
"indexing"
] |
Run independent file from main | 39,195,913 | <p>I have a <code>run.py</code> that looks something like this:</p>
<pre><code>def main():
# Tested and working code here
if __name__ == '__main__':
main()
</code></pre>
<p>Then I have another file that runs a TCP Socket Server, <code>bup.py</code>:</p>
<pre><code>import socket
import os
from threading imp... | 0 | 2016-08-28T21:24:35Z | 39,196,010 | <p>If you just want to run bup.py as a separate file, maybe you can define that <strong>main</strong> in your bup.py and run that file using python bup.py. I am not exactly sure what bup.py need to be bound to a run.py, did I miss anything?</p>
| 0 | 2016-08-28T21:37:31Z | [
"python",
"python-3.x",
"subprocess",
"os.system"
] |
Run independent file from main | 39,195,913 | <p>I have a <code>run.py</code> that looks something like this:</p>
<pre><code>def main():
# Tested and working code here
if __name__ == '__main__':
main()
</code></pre>
<p>Then I have another file that runs a TCP Socket Server, <code>bup.py</code>:</p>
<pre><code>import socket
import os
from threading imp... | 0 | 2016-08-28T21:24:35Z | 39,196,026 | <p>You can use <a href="https://docs.python.org/2/library/subprocess.html" rel="nofollow"><code>subprocess</code></a>.</p>
<pre><code>import subprocess
def main()
# do your work
subprocess.Popen(["python","bup.py"])
</code></pre>
<p>This should run in the background if your current process doesn't depend on th... | 1 | 2016-08-28T21:39:09Z | [
"python",
"python-3.x",
"subprocess",
"os.system"
] |
Error with Python after I Uninstalled Anaconda | 39,195,925 | <p>I'm running Mac OS X 10.11.6 and just uninstalled Anaconda following <a href="http://stackoverflow.com/questions/22585235/python-anaconda-how-to-safely-uninstall">this thread</a>. I downloaded Python 3.5.2 from python.org and installed that version but in the terminal when I type in python it responds with the foll... | 0 | 2016-08-28T21:26:43Z | 39,204,382 | <p>IDLE should already be bundled with the standard Python installation on OS X, so just type <code>idle</code> in a Terminal window and it should start up. This should work even when you have Anaconda (or Miniconda) installed.</p>
<p>Personally, I have Miniconda installed and I can still run <code>idle</code>.</p>
... | 0 | 2016-08-29T10:47:29Z | [
"python",
"python-3.x",
"anaconda"
] |
Write formula to Excel with Python | 39,195,957 | <p>I am in the process of brain storming how to best tackle the below problem. Any input is greatly appreciated.</p>
<p>Sample Excel sheet columns:</p>
<pre><code>Column A | Column B | Column C
Apple | Apple |
Orange | Orange |
Pear | Banana |
</code></pre>
<p>I want Excel to tell me whet... | 1 | 2016-08-28T21:31:53Z | 39,196,008 | <p>You probably want to make the creation of the formula dynamic so each row of <code>C</code> takes from the corresponding rows of <code>A</code> and <code>B</code>:</p>
<pre><code>for i, cellObj in enumerate(Sheet.columns[2], 1):
cellObj.value = '=IF($A${0}=$B${0}, "Match", "Mismatch")'.format(i)
</code></pre>
| 2 | 2016-08-28T21:37:20Z | [
"python",
"excel",
"openpyxl"
] |
Prioritize OR Pipe in Regex based on first match in the regex not in the source? | 39,195,968 | <p>If I do a regex with an <code>OR</code> pipe like <code>(A|B|C)</code></p>
<p><a href="https://regex101.com/r/gB1eP0/4" rel="nofollow">https://regex101.com/r/gB1eP0/4</a></p>
<p>It always finds the first match in order in my source e.g.</p>
<ul>
<li>ABC=A</li>
<li>BCA=B</li>
<li>CBA=C</li>
</ul>
<p>I am trying i... | 1 | 2016-08-28T21:33:06Z | 39,196,460 | <p>Building on @WiktorStribiżew's example:</p>
<p><code>(A|(B|C(?!.*B))(?!.*A))</code></p>
<p>basically, the negative lookahead is used, and then cascaded for all the Or pipes (using the parentheses).</p>
<ol>
<li><p>Match A (A)</p></li>
<li><p>Match B if not followed by A (B)(?!.*A)</p></li>
<li><p>Match C if not ... | 2 | 2016-08-28T22:43:40Z | [
"python",
"regex"
] |
Selecting values from pandas data frame using multiple conditions | 39,196,053 | <p>I have the following dataframe in Pandas. Score and Date_of_interest columns are to be calculated. Below it is already filled out to make the explanation of the problem easy.</p>
<p>First let's assume that Score and Date_of_interest columns are filled with NaN's only. Below are the steps to fill the values in them... | 1 | 2016-08-28T21:43:13Z | 39,196,698 | <p>Usually having to resort to iterative/imperative methods is a sign of trouble when working with <code>pandas</code>. Given the dataframe</p>
<pre><code>In [111]: df2
Out[111]:
Datetime Item_id PC_id Value
0 1998-04-08 01:00:00 1 200 35
1 1998-04-08 02:00:00 1 200 92
2... | 1 | 2016-08-28T23:25:37Z | [
"python",
"pandas"
] |
Libraries in "virtualenv" much bigger than system libraries | 39,196,057 | <p>I use virtualenv through pew (which I think is a fantastic tool), but I noticed something strange.</p>
<p>I have scipy system-side installed:</p>
<pre><code> 7,7 MiB [##########] /sparse
5,1 MiB [###### ] /special
5,1 MiB [###### ] /stats
5,0 MiB [###### ] /linalg
3,5 MiB [#### ] /... | 4 | 2016-08-28T21:43:26Z | 39,196,353 | <p>The shared library files in the Python wheels distributed for Scipy aren't stripped, so they are bigger than what your package manager installs:</p>
<pre><code>$ file _sparsetools.cpython-35m-x86_64-linux-gnu.so
_sparsetools.cpython-35m-x86_64-linux-gnu.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), d... | 5 | 2016-08-28T22:25:43Z | [
"python",
"numpy",
"scipy",
"virtualenv"
] |
Plot or reshape 2D array matplotlib | 39,196,147 | <p>i have no idea how can i plot scatter with a 2D array of this type:</p>
<pre><code>a=[[x0,t0],[x1,t1],...,[xn,tn]]
</code></pre>
<p>the plot should be x vs t, maybe instead of doing this with a maplotlib routine be able to reshape a to obtain:</p>
<pre><code>a=[[x0,x1,...,xn],[t0,t1,...,tn]]
</code></pre>
<p>tha... | 0 | 2016-08-28T21:54:32Z | 39,196,181 | <p>Assuming your data starts in the format a = [[x0, t0]]: </p>
<p>Split x & t into separate lists, then you can pass them into matplotlib.</p>
<pre><code>import matplotlib.pyplot as plt
x = [i[0] for i in a]
t = [i[1] for i in a]
plt.plot(x, t)
</code></pre>
| 3 | 2016-08-28T21:59:10Z | [
"python",
"numpy",
"matplotlib"
] |
Plot or reshape 2D array matplotlib | 39,196,147 | <p>i have no idea how can i plot scatter with a 2D array of this type:</p>
<pre><code>a=[[x0,t0],[x1,t1],...,[xn,tn]]
</code></pre>
<p>the plot should be x vs t, maybe instead of doing this with a maplotlib routine be able to reshape a to obtain:</p>
<pre><code>a=[[x0,x1,...,xn],[t0,t1,...,tn]]
</code></pre>
<p>tha... | 0 | 2016-08-28T21:54:32Z | 39,196,311 | <p>You can use <code>numpy.transpose</code>:</p>
<pre><code>import numpy as np
a=[["x0","t0"],["x1","t1"],["xn","tn"]]
np.transpose(a)
# array([['x0', 'x1', 'xn'],
# ['t0', 't1', 'tn']],
# dtype='<U2')
</code></pre>
| 3 | 2016-08-28T22:18:25Z | [
"python",
"numpy",
"matplotlib"
] |
Unreasonable output from codecs.decode() | 39,196,210 | <p>I have been playing around with the <code>codecs</code> module lately and I stumbled upon this behavior that I find rather weird:<br>
<code>codecs.encode(b'a', 'hex')</code> returns <code>b'61'</code>.</p>
<p>My question is, why? I really didn't expect it to return <code>b'61'</code>. I was expecting <code>b'\x61'<... | -2 | 2016-08-28T22:03:18Z | 39,196,544 | <p>The behaviour of codec is documented, the purpose is to make a text representation of (possibly) binary data. </p>
<p>If you want to convert a character 'a' to a bytes representation of that character using ascii, you don't need the codec module; just use the <code>bytes</code> builtin.</p>
<pre><code>>>>... | 0 | 2016-08-28T23:00:10Z | [
"python",
"python-3.x",
"encoding"
] |
Python read from a file, and only do work if a string isn't found | 39,196,216 | <p>So I'm trying to make a reddit bot that will exec code from a submission. I have my own sub for controlling these clients. </p>
<pre><code>while __name__ == '__main__':
string = open('config.txt').read()
for submission in subreddit.get_new(limit = 1):
if submission.url not in string:
f.w... | -1 | 2016-08-28T22:04:03Z | 39,197,715 | <p>First a critique of your existing code (in comments):</p>
<pre><code># the next two lines are not needed; open('config.txt', "a")
# will create the file if it doesn't exist.
if not os.path.exists('file'):
open('config.txt', 'w').close()
f = open('config.txt', "a")
# this is an unusual condition which will con... | 0 | 2016-08-29T02:22:21Z | [
"python",
"praw"
] |
Issue with the global command within a function | 39,196,556 | <p>I am having an issue with getting this code to run properly:</p>
<pre><code>def ip_is_valid():
check = False
#Global exposes outside the local function
global ip_list
while True:
#Prompting user for input
print "\n" + "# " * 20 + "\n"
ip_file = raw_input("# Enter IP file nam... | 0 | 2016-08-28T23:02:03Z | 39,196,567 | <p>Before using variable <code>ip_list</code> as <code>global</code> variable, you must have to define it at the outer scope. For example in your case, you may make it run like: </p>
<pre><code>ip_list = []
def ip_is_valid():
# Some logic
global ip_list
# Some more logic
</code></pre>
<p>OR define it base... | 2 | 2016-08-28T23:04:11Z | [
"python",
"networking"
] |
MySql is unable to find file in same directory? | 39,196,571 | <p>I'm trying to load a picture into a mysql database with the following code:</p>
<pre><code>cursor, db = get_db()
cursor.execute("UPDATE People SET photo = LOAD_FILE(\'myphoto.jpg\')")
cursor.close()
db.commit()
db.close()
</code></pre>
<p>I've been able to set photo to other values by replacing the <code>LOAD_FILE... | 1 | 2016-08-28T23:04:40Z | 39,196,734 | <p>Check whether the file is loaded into the mysql or not.</p>
<pre><code>select load_file('/currentdir/file.blob')
+-----------------------------+
| load_file('currentdir/file.blob') |
+-----------------------------+
| NULL |
+-----------------------------+
</code></pre>
<p>This could be becca... | 0 | 2016-08-28T23:31:08Z | [
"python",
"mysql",
"file"
] |
Django ValueError: ModelForm has no model class specified | 39,196,601 | <p>I have the following code which complains about the following error:</p>
<p>ValueError: ModelForm has no model class specified.</p>
<pre><code>from django import forms
from straightred.models import StraightredTeam
from straightred.models import UserSelection
class SelectTwoTeams1(forms.Form):
campaignnoqu... | 0 | 2016-08-28T23:09:58Z | 39,196,637 | <p>The error message is clearly telling you that you have not specified a model class.</p>
<p>For a ModelForm, you have to use Model class:</p>
<pre><code>class ProductForm(forms.ModelForm):
class Meta:
model = Product
</code></pre>
<p>If this isn't a form based on a model, don't inherit from forms.Model... | 1 | 2016-08-28T23:16:14Z | [
"python",
"django"
] |
Python - Efficiently working with large permutated lists | 39,196,603 | <p>I've written a short <strong>Anagram Solver</strong> script in <strong>Python 2.7</strong>. </p>
<pre><code>#Import Permutations Module
from itertools import permutations as perm
#Defined Functions
def check(x,y):
#Opens Dictionary File
with open('wordsEn.txt') as dictionary:
'''Checks the permut... | 0 | 2016-08-28T23:10:12Z | 39,196,700 | <p>This should help. The <code>itertools.permutations</code> function returns an iterator. This means that the entire list is not stored in memory; rather you can call for the next value and it will compute what is needed on the fly.</p>
<pre><code>from itertools import permutations
with open('./wordlist.txt', 'r')... | 0 | 2016-08-28T23:25:47Z | [
"python",
"python-2.7",
"permutation",
"itertools",
"anagram"
] |
Python - Efficiently working with large permutated lists | 39,196,603 | <p>I've written a short <strong>Anagram Solver</strong> script in <strong>Python 2.7</strong>. </p>
<pre><code>#Import Permutations Module
from itertools import permutations as perm
#Defined Functions
def check(x,y):
#Opens Dictionary File
with open('wordsEn.txt') as dictionary:
'''Checks the permut... | 0 | 2016-08-28T23:10:12Z | 39,196,754 | <p>It think the best solution may be to not use permutations. It's much more likely than not that most generated permutations are not a word - so it's a waste to generate them all.</p>
<p>You can consider pre-processing this dictionary to a dictionary of sorted letters to list of words that those letters consist of. T... | 1 | 2016-08-28T23:34:39Z | [
"python",
"python-2.7",
"permutation",
"itertools",
"anagram"
] |
Python get property value in dict for large dict | 39,196,632 | <p>I have a very large dictionary, like this:</p>
<pre><code>d['property1']['property2'][0]['property3']['property4']['property5']['property6']
</code></pre>
<p>I need to get <code>property6</code>. What's the simplest way for me to get this value?</p>
<p>I was thinking something like this would work:</p>
<pre><cod... | -2 | 2016-08-28T23:15:36Z | 39,196,664 | <p>Unfortunately, there is no generic way to get value of key from nested dict based on levels (due to obvious reasons). But, you may write a function for your specific scenario in order to simplify it. For example:</p>
<pre><code>def get_value_from_dict(my_dict, level, key):
return my_dict['property1']['property2... | 1 | 2016-08-28T23:20:12Z | [
"python"
] |
Issues with Python pandas: read_html and python3-lxml installation | 39,196,648 | <p>I'm trying to run the following code, to no avail. To my knowledge, there aren't any syntax errors.</p>
<pre><code>import quandl
import pandas as pd
fifty_states =pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
print(fifty_states)
</code></pre>
<p>I'm getting the following error when I run t... | 2 | 2016-08-28T23:18:03Z | 39,197,125 | <p>From what I understand and according to the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_html.html" rel="nofollow">docs</a>, if <code>read_html()</code> fails to use <code>lxml</code>, it should fall back to <code>html5lib</code>, but it looks ike it does not happen in your case and an ... | 1 | 2016-08-29T00:43:50Z | [
"python",
"pandas",
"lxml"
] |
Python imaplib deleting multiple emails gmail | 39,196,695 | <p>my code look like this...</p>
<pre><code>import imaplib
import email
obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login('user','pass')
obj.select('inbox')
delete = []
for i in range(1, 10):
typ, msg_data = obj.fetch(str(i), '(RFC822)')
print i
x = i
for response_part in msg_data:
if isinstance(r... | 0 | 2016-08-28T23:24:59Z | 39,217,226 | <p>You might find this a bit easier using <a href="https://pypi.python.org/pypi/IMAPClient/1.0.2" rel="nofollow">IMAPClient</a> as it takes care of a lot more of low level protocol aspects for you.</p>
<p>Using IMAPClient your code would look something like:</p>
<pre><code>from imapclient import IMAPClient
import ema... | 0 | 2016-08-30T00:41:46Z | [
"python",
"email",
"imaplib",
"uid"
] |
Optimizing dictionaries in Python | 39,196,788 | <p>My question is different from the one asked <a href="http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended">here</a>. Primarily I am asking what improvements could be made to code containing dictionaries. However, the link explains about memory profilers, which will be my next step.</... | 0 | 2016-08-28T23:41:07Z | 39,196,838 | <p>If you want to ask among these two, second is better. But overall, both methods have something or other which could be improved. If I had to do something similar, I would have done:</p>
<pre><code>>>> a = {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
>>> [a[i] for i in (1,2,3) if i in a]
['a', 'b', 'c']
</code... | 0 | 2016-08-28T23:49:09Z | [
"python",
"python-2.7"
] |
Optimizing dictionaries in Python | 39,196,788 | <p>My question is different from the one asked <a href="http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended">here</a>. Primarily I am asking what improvements could be made to code containing dictionaries. However, the link explains about memory profilers, which will be my next step.</... | 0 | 2016-08-28T23:41:07Z | 39,196,854 | <p>If you're optimizing for memory use generators are often a good tool. For example:</p>
<pre><code>def get_keys(mapping, keys):
for key in keys:
try:
yield mapping[key]
except KeyError:
continue
</code></pre>
<p>On your example:</p>
<pre><code>list(get_keys(a, (1, 2, 3))... | 1 | 2016-08-28T23:52:38Z | [
"python",
"python-2.7"
] |
IndexError : index out of bounds | 39,196,798 | <p>I have implemented MultinomialNB but I get this message. Please help me to solve it. Here my code : </p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>kf = KFold(len(X)... | 0 | 2016-08-28T23:43:33Z | 39,196,879 | <p>Python uses zero based indexing so if the zeroth dimension of <code>X.ix[index_train,:]</code> or <code>y[index_train]</code> is 100, the maximum value of <code>index_train</code> that would be valid is 99. Likewise for <code>index_test</code>.</p>
<p>Something in</p>
<pre><code>kf = KFold(len(X), n_folds=2, shuff... | 0 | 2016-08-28T23:56:25Z | [
"python",
"function"
] |
Django return objects to HTML from view with queryset? | 39,196,832 | <p>I trying to show some info in HTML from query set in Django. But I don't know the best way to do it.</p>
<p>The idea is when I open the page this show me the name of user and the competitions related with it. The user can create competition in admin of Django.</p>
<p>My url is that.</p>
<pre><code>url(r'^home/(?P... | 0 | 2016-08-28T23:48:08Z | 39,198,627 | <p>you dont have to return the different querysets from get_queryset, Its complicated. List view has one method called get_context_data"
you can override it to fill the extra objects or data you want.</p>
<p>for example just write</p>
<pre><code>class HomeView(ListView):
model = User, Competition
template_nam... | 0 | 2016-08-29T04:46:02Z | [
"python",
"html",
"django",
"django-queryset"
] |
Why can't use the newly installed TensorFlow library using python 3? | 39,196,882 | <p>I recently upgraded to python 3.5 and was trying to use TensorFlow. I followed the instructions <a href="https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html" rel="nofollow">https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html</a> and installed tensorflow with GPU enabled:</p>
<pre><co... | 0 | 2016-08-28T23:57:25Z | 39,212,005 | <p>you need to export the path to the folder of the cuda dylibs (like libcudart) with <code>export DYLD_LIBRARY_PATH</code> in your <code>~/.bash_profile</code></p>
| 0 | 2016-08-29T17:36:03Z | [
"python",
"tensorflow"
] |
How to get the total number of entries contained in a TFRecord file? | 39,196,955 | <p>I am able to write and read TFrecord files with tensorflow. How can I quickly get the total number of entries contained in a TFRecord file? Is there any API to get the count?</p>
| 1 | 2016-08-29T00:12:16Z | 39,197,123 | <p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/python_io.html#tfrecords-format-details" rel="nofollow">TFRecords file format</a> is basically a sequence of structures in the form:</p>
<pre><code>struct TFRecords {
uint64_t length;
uint32_t length_checksum;
uint8_t data[length];
... | 0 | 2016-08-29T00:43:38Z | [
"python",
"tensorflow"
] |
Error when updating function-based views to class-based views in Django Rest Framework | 39,197,011 | <p>I've been in the process of running through the tutorials on Django Rest Framework to build a simple todo list app. </p>
<p>When I transitioned from a function-based view to a class-based view, I started getting a stack trace to Django and all http calls started failing.</p>
<p>I'm using <code>virtualenv</code> to... | 0 | 2016-08-29T00:22:09Z | 39,207,440 | <p>@SergeyGornostaev had the right intuition to look at and post <code>urls.py</code>.</p>
<p>In the refactor from function-based views to class-based views, I neglected to call <code>as_view()</code> on the views when I updated the routing.</p>
<p>Before: <code>url(<pattern>, views.ListsView)</code></p>
<p>Af... | 0 | 2016-08-29T13:24:18Z | [
"python",
"django",
"django-rest-framework",
"python-3.5"
] |
Python - list index out of range - genetic algorithm | 39,197,023 | <p>I'm having problems with my code and I know this problem is simple but I just can't figure it out how to solve it, I'll really appreciate if someone could tell me what I'm doing wrong:</p>
<pre><code> import random
from math import *
def create_population(dim,pn):
... | -4 | 2016-08-29T00:24:08Z | 39,197,078 | <p>You don't need "score[z]" when you do "for z in score", z is not an index, is a value of the score list.</p>
<p>You can just do</p>
<pre><code>if z == maxx
</code></pre>
| 1 | 2016-08-29T00:36:28Z | [
"python",
"list",
"genetic-algorithm",
"indexoutofrangeexception"
] |
Python - list index out of range - genetic algorithm | 39,197,023 | <p>I'm having problems with my code and I know this problem is simple but I just can't figure it out how to solve it, I'll really appreciate if someone could tell me what I'm doing wrong:</p>
<pre><code> import random
from math import *
def create_population(dim,pn):
... | -4 | 2016-08-29T00:24:08Z | 39,197,120 | <p>As you delete things in a list, you end up with index problems using <code>range(len)</code>. If you have a list and then delete an item in it, you end up with a list whose length is now one less. This leads to <code>IndexErrors</code> as you try to access up to the original <code>len(list)</code>.</p>
<p>Perhaps t... | 0 | 2016-08-29T00:43:20Z | [
"python",
"list",
"genetic-algorithm",
"indexoutofrangeexception"
] |
Calling MKL from Python : DSTEVR | 39,197,132 | <p><strong>dstevr</strong> computes eigensolutions of triangular symmetric matrix. Cool. Except it was not one of the routines ported with a wrapper to SCIPY. So I've followed the instructions on how to call MKL directly from Python and the attached seems to give the correct answer. But gosh.... Is there someway to cle... | 0 | 2016-08-29T00:45:16Z | 39,203,022 | <p>You can use instead a cython wrapper in cython_lapack, <a href="http://docs.scipy.org/doc/scipy/reference/linalg.cython_lapack.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/linalg.cython_lapack.html</a></p>
<p>You'll need cython though.</p>
| 0 | 2016-08-29T09:38:25Z | [
"python",
"scipy",
"eigenvalue",
"intel-mkl"
] |
Django-tastypie: utf8 is incorrect | 39,197,148 | <pre><code>class ActionResource(ModelResource):
class Meta:
queryset = ActionInfo.objects.all()
resource_name = 'action'
def dehydrate(self, bundle):
bundle.data['name'] = bundle.obj.name
bundle.data['expect_time'] = bundle.obj.expect_time
bundle.data['type'] = bundle.o... | 0 | 2016-08-29T00:48:27Z | 39,201,416 | <p>Instead of <code>__str__()</code> use <code>__unicode__()</code>. And use <a href="https://docs.djangoproject.com/es/1.10/ref/utils/#django.utils.encoding.smart_text" rel="nofollow">smart_text</a>:</p>
<pre><code>from django.utils.encoding import smart_text
class ActionName(models.Model):
name = models.CharFie... | 1 | 2016-08-29T08:09:49Z | [
"python",
"django",
"unicode",
"utf-8",
"tastypie"
] |
Throw ValueError for two digit year dates with dateutil.parser.parse | 39,197,156 | <p>While doing some data cleaning, I noticed that <code>dateutil.parser.parse</code> failed to reject a certain malformed date, thinking that the first number in it is a two digit year. Can this library be forced to treat two digit years as invalid?</p>
<p>Example:</p>
<pre><code>from dateutil.parser import parse
par... | 1 | 2016-08-29T00:49:16Z | 39,197,157 | <p>I managed to work around this by passing a custom <code>dateutil.parser.parserinfo</code> object via the <code>parserinfo</code> parameter to <code>dateutil.parser.parse</code>. Luckily, <code>dateutil.parser.parserinfo</code> has a <code>convertyear</code> method that can be overloaded in a derived class in order t... | 2 | 2016-08-29T00:49:16Z | [
"python",
"date",
"parsing",
"python-dateutil",
"2-digit-year"
] |
How to re-generate tables in Django | 39,197,204 | <p>I'm new in Django. Here is how I do:
Create app by : python manager.py startap test
and I add serveral model, then execute:
python manager.py maiemigrations
python manager migrate</p>
<p>It will generate tables automatically. Then I dropped the table in database by:
drop table table_name</p>
<p>execute again:
pyth... | 0 | 2016-08-29T00:59:46Z | 39,200,171 | <p>Delete all the migration file in your app's migrations directory. Then run </p>
<pre><code>python makemigrations your_app
python miagrate
</code></pre>
| 0 | 2016-08-29T06:53:58Z | [
"python",
"django"
] |
Global variable not defined after seperating functions to seperate Python file | 39,197,255 | <p>Continuing to write my dictionary attack script for project. </p>
<p>My script calls upon two functions that perform an actual dictionary attack on SSH. First I declared my global variable in my get_args() function in <code>main.py</code>, following with the main() function</p>
<pre><code>def get_args():
# stu... | 1 | 2016-08-29T01:07:10Z | 39,213,506 | <p>The concept of global defining means that you should define it outside of the function, try to init all globals outside fuction with None or something and see if the problem is resolved</p>
| -1 | 2016-08-29T19:12:16Z | [
"python",
"module",
"global-variables"
] |
How to add multiple values to a key in a Python dictionary | 39,197,261 | <p>I am trying to create a dictionary from the values in the <code>name_num</code> dictionary where the length of the list is the new key and the <code>name_num</code> dictionary key and value are the value. So:</p>
<pre><code>name_num = {"Bill": [1,2,3,4], "Bob":[3,4,2], "Mary": [5, 1], "Jim":[6,17,4], "Kim": [21,54,... | 7 | 2016-08-29T01:07:33Z | 39,197,284 | <p>This is a good use case for <a href="https://docs.python.org/3/library/collections.html"><code>defaultdict</code></a>:</p>
<pre><code>from collections import defaultdict
name_num = {
'Bill': [1, 2, 3, 4],
'Bob': [3, 4, 2],
'Mary': [5, 1],
'Jim': [6, 17, 4],
'Kim': [21, 54, 35],
}
new_dict = def... | 22 | 2016-08-29T01:13:43Z | [
"python",
"dictionary"
] |
How to add multiple values to a key in a Python dictionary | 39,197,261 | <p>I am trying to create a dictionary from the values in the <code>name_num</code> dictionary where the length of the list is the new key and the <code>name_num</code> dictionary key and value are the value. So:</p>
<pre><code>name_num = {"Bill": [1,2,3,4], "Bob":[3,4,2], "Mary": [5, 1], "Jim":[6,17,4], "Kim": [21,54,... | 7 | 2016-08-29T01:07:33Z | 39,197,299 | <p><a href="https://en.wikipedia.org/wiki/Associative_array">Dictionary</a>, associative array or map (many names, basically the same functionality) property is that keys are unique.</p>
<p>The keys you wish to have, which are integers, are not unique if lengths are the same, that's why your code doesn't work. Putting... | 5 | 2016-08-29T01:15:57Z | [
"python",
"dictionary"
] |
How to add multiple values to a key in a Python dictionary | 39,197,261 | <p>I am trying to create a dictionary from the values in the <code>name_num</code> dictionary where the length of the list is the new key and the <code>name_num</code> dictionary key and value are the value. So:</p>
<pre><code>name_num = {"Bill": [1,2,3,4], "Bob":[3,4,2], "Mary": [5, 1], "Jim":[6,17,4], "Kim": [21,54,... | 7 | 2016-08-29T01:07:33Z | 39,197,390 | <p>Just an alternative to others; you can sort by length and use <a href="https://docs.python.org/2/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a>:</p>
<pre><code>>>> result = {}
>>> f = lambda t: len(t[1])
>>> for length, groups in itertools.grou... | 4 | 2016-08-29T01:34:14Z | [
"python",
"dictionary"
] |
Django - LOCALHOST missing despite other views working | 39,197,311 | <p><strong>BACKGROUND</strong>:</p>
<p>Worked through Django's tutorial and created multiple views:</p>
<ul>
<li>/admin</li>
<li>/app</li>
</ul>
<p>Currently having issues with "localhost:8000" despite localhost/app and localhost/admin views working (see below):</p>
<p><strong>CODE</strong></p>
<p><strong>Folder S... | 0 | 2016-08-29T01:17:33Z | 39,197,697 | <blockquote>
<p>localhost/app or localhost/admin shows a rendered page. However, "localhost:8000" does not show the original, django landing page (despite it working before). What am I missing?</p>
</blockquote>
<p>It looks like <code>main/main/urls.py</code> is your global urls config, which would mean that <code>l... | 0 | 2016-08-29T02:20:02Z | [
"python",
"django"
] |
Django - LOCALHOST missing despite other views working | 39,197,311 | <p><strong>BACKGROUND</strong>:</p>
<p>Worked through Django's tutorial and created multiple views:</p>
<ul>
<li>/admin</li>
<li>/app</li>
</ul>
<p>Currently having issues with "localhost:8000" despite localhost/app and localhost/admin views working (see below):</p>
<p><strong>CODE</strong></p>
<p><strong>Folder S... | 0 | 2016-08-29T01:17:33Z | 39,197,864 | <p><code>../main/main/urls.py</code> is your entry point for defining your URL patterns and you have no pattern defined to handle <code>/</code> which is what <code>localhost:8000</code> would be in this case. You have two basic options.</p>
<p>First, if you want the stuff in <code>../main/app</code> to have a URL th... | 0 | 2016-08-29T02:50:32Z | [
"python",
"django"
] |
How do I run a python script between two times? | 39,197,323 | <p>I have a python script that I would like to run between 9 am and 4 pm everyday, but there's also a part of the same script that I'd like to run every 10 seconds during this time. How would I go about in doing this? I have looked at datetime modules, but I did not come across examples where they compare times and sch... | 1 | 2016-08-29T01:19:20Z | 39,198,096 | <p>If you are using Linux,you should read <a href="http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/" rel="nofollow">crontab</a>,it is a powerful tool to help you with schedule.<br>
On the other hand,in Python2.7 ,try <a href="https://docs.python.org/2/library/sched.html" rel="nofollow">sched</a> to ... | 0 | 2016-08-29T03:26:48Z | [
"python",
"python-2.7",
"datetime"
] |
What are the requirements to install TensorFlow with python 3? | 39,197,333 | <p>I was trying to install TensorFlow with enabled GPU. For this I was using the instructions form <a href="https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#anaconda-installation" rel="nofollow">the official site</a>. First, I created my environment:</p>
<pre><code>conda create --name tf_py3_tf_gpu ... | 1 | 2016-08-29T01:21:34Z | 39,198,066 | <p>Verify if <code>pip</code> is not in the <code>bin</code> folder of your virtualenv.</p>
<p>Try using <code>/path/to/python -m pip [...]</code> to make sure you are using the right <code>pip</code></p>
<p>Rename your <code>~/.local</code> folder because conda venv try to use them even if they are unrelated to thei... | 0 | 2016-08-29T03:21:59Z | [
"python",
"tensorflow"
] |
Iterating over a Pandas grouped dataframe | 39,197,379 | <p>I am using <code>groupby</code> in <code>pandas</code> to create some <code>json</code> style data. I am having trouble iterating over the grouped <code>dataframe</code> as it doesn't recognize my keys</p>
<pre><code>import pandas as pd
df = pd.DataFrame(data=[['Group A', 10],
['Group A', 1... | 1 | 2016-08-29T01:30:57Z | 39,197,424 | <p>As <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.iteritems.html" rel="nofollow">documented</a>, <code>iteritems</code> iterates over the columns (specifically, name/column pairs). It looks like you want <code>iterrows</code>. (You will still need to change it to access <co... | 1 | 2016-08-29T01:39:02Z | [
"python",
"json",
"python-2.7",
"pandas"
] |
Iterating over a Pandas grouped dataframe | 39,197,379 | <p>I am using <code>groupby</code> in <code>pandas</code> to create some <code>json</code> style data. I am having trouble iterating over the grouped <code>dataframe</code> as it doesn't recognize my keys</p>
<pre><code>import pandas as pd
df = pd.DataFrame(data=[['Group A', 10],
['Group A', 1... | 1 | 2016-08-29T01:30:57Z | 39,197,600 | <p>Try this: Here's a link to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_json.html" rel="nofollow">DataFrame.to_json()</a></p>
<pre><code>df = df.groupby('Group').mean().reset_index().rename(columns = {'Group':"id" })
df['name'] = df['id']
df.to_json(orient="records")
'[{"id":"... | 1 | 2016-08-29T02:06:55Z | [
"python",
"json",
"python-2.7",
"pandas"
] |
Django drf-nested-routers - model object has no attributed related field | 39,197,418 | <p>I am creating an API using the <a href="https://github.com/alanjds/drf-nested-routers" rel="nofollow">drf-nested-routers</a> application for <a href="http://www.django-rest-framework.org/" rel="nofollow">Django Rest Framework</a>. This application is a tracker where users have sessions and tasks. Each user can have ... | 0 | 2016-08-29T01:38:19Z | 39,197,509 | <p>I rubber-ducked it with my wife and figured out my problem.</p>
<p>I had 'related_name="sessions"' in my ForeignKey field for user in models.py.</p>
<p>I was missing that information in the ForeignKey field in the task model.</p>
<p>Hopefully someone else stumbles on this and can learn from my mistake.</p>
| 0 | 2016-08-29T01:51:44Z | [
"python",
"django",
"django-rest-framework",
"drf-nested-routers"
] |
Multiply array with diagonal matrix stored as vector | 39,197,421 | <p>I have a 1D array A = [a, b, c...] (length N_A) and a 3D array T of shape (N_A, N_B, N_A). A is meant to represent a diagonal N_A by N_A matrix.</p>
<p>I'd like to perform contractions of A with T without having to promote A to dense storage. In particular, I'd like to do </p>
<pre><code>np.einsum('ij, ikl', A, T)... | 0 | 2016-08-29T01:38:56Z | 39,197,507 | <p><code>np.einsum('ij, ikl', np.diag(a), t)</code> is equivalent to <code>(a * t.T).T</code>.</p>
<p><code>np.einsum('ikl, lm', t, np.diag(a))</code> is equivalent to <code>a * t</code>.</p>
<p>(found by trial-and-error)</p>
| 1 | 2016-08-29T01:51:29Z | [
"python",
"numpy"
] |
Python custom 404 response error | 39,197,452 | <p>I wrote a hiscore checker for a game that I play, basically you enter a list of usernames into the .txt file & it outputs the results in found.txt.</p>
<p>However if the page responds a 404 it throws an error instead of returning output as " 0 " & continuing with the list.</p>
<p>Example of script, </p>
<... | 0 | 2016-08-29T01:43:18Z | 39,197,540 | <p>It seems that <code>total</code> can end up being <code>None</code>. In that case you can't check that it has <code>'err'</code> in it. To fix the crash, try changing that line to:</p>
<pre><code>if total is not None and "err" not in total:
</code></pre>
<p>To be more specific, <code>get_total</code> is returning ... | 0 | 2016-08-29T01:57:17Z | [
"python"
] |
Make the background of 'Text' widget in tkinter transparent | 39,197,579 | <p>I'm looking to add an image in the background of a Text widget in tkinter, but as far as I'm concerned, that is not possible. So, to work around this, I'm wondering if it is possible to make the background of a Text widget transparent.</p>
<p>Thanks in advance.</p>
| 0 | 2016-08-29T02:03:17Z | 39,197,855 | <p>No, it is not possible to make the background of the text widget transparent. </p>
| 0 | 2016-08-29T02:48:40Z | [
"python",
"tkinter",
"widget",
"transparent",
"python-3.5"
] |
Threads not exiting and program won't exit | 39,197,587 | <p>Using the script below, I cannot seem to exit the threads. The script runs smoothly without issues but never exits when done. I can still see the thread alive, I have to use <code>htop</code> to kill them or completely exit the command line.</p>
<p>How can I get this script to exit and the threads to die?</p>
<pre... | 0 | 2016-08-29T02:04:26Z | 39,198,312 | <blockquote>
<p>Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. Otherw... | 0 | 2016-08-29T04:01:53Z | [
"python",
"multithreading"
] |
Threads not exiting and program won't exit | 39,197,587 | <p>Using the script below, I cannot seem to exit the threads. The script runs smoothly without issues but never exits when done. I can still see the thread alive, I have to use <code>htop</code> to kill them or completely exit the command line.</p>
<p>How can I get this script to exit and the threads to die?</p>
<pre... | 0 | 2016-08-29T02:04:26Z | 39,198,706 | <p>Your threads are stuck in <code>dname = q.get()</code></p>
<p>If you reaching empty queue, <code>q.get()</code> will wait forever for value to arrive.</p>
<p>You can replace <code>get</code> with <code>get_nowait()</code> but get ready to catch <code>Queue.Empty</code> execption</p>
| 0 | 2016-08-29T04:55:55Z | [
"python",
"multithreading"
] |
'module' object is not subscriptable | 39,197,634 | <p>here is very simplified version of my code , so pleas ignore syntax errors </p>
<p>i have a helper function basically reading a row from database using django orm and doing some validation finally return it using a dictionary </p>
<p>modVerify.py</p>
<pre><code>def verify(request):
try :
req = Request... | 0 | 2016-08-29T02:11:52Z | 39,197,931 | <p>It seems like you should be doing </p>
<pre><code>req = result['req']
</code></pre>
<p>instead of </p>
<pre><code>req = modeVerify['req']
</code></pre>
| 1 | 2016-08-29T03:00:08Z | [
"python",
"django"
] |
Install Paramiko Errors | 39,197,688 | <p>I am trying to install Paramiko. I get the following errors. </p>
<pre><code>Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, in load_entry... | 0 | 2016-08-29T02:18:27Z | 39,200,689 | <p>i was installed without error:)
upgrade your pip :</p>
<pre><code>pip install --upgrade pip
</code></pre>
<p>and install requirements:</p>
<pre><code>pyasn1>=0.1.7
cryptography>=1.1
idna>=2.0
six>=1.4.1
setuptools>=11.3
enum34
ipaddress
cffi>=1.4.1
pycparser
</code></pre>
| 0 | 2016-08-29T07:28:03Z | [
"python",
"python-2.7",
"paramiko"
] |
Failed to append an element to a numpy array | 39,197,733 | <p>I'm trying to add the values generated by the function <code>calc_class</code>, but it is not working and I don't know the reason. I've tried to use the <code>numpy.append</code>, <code>numpy.insert</code> and the built-in Python function <code>append</code> unsuccessfully.</p>
<p>This is my piece of code:</p>
<pr... | -1 | 2016-08-29T02:24:00Z | 39,197,821 | <p>You can use pdb do debug (or ipdb for ipython).</p>
<pre><code>from pdb import set_trace
</code></pre>
<p>use "set_trace()" instead of "print('p(spam|new_email)=', p_spam_given_new[0])"(third line counted from end-line), than run your code. It will pause at this line, and you can run any python code there, such a... | 0 | 2016-08-29T02:41:01Z | [
"python",
"arrays",
"numpy"
] |
theano CPU running out of memory: what is wrong? | 39,197,775 | <p>I run a simple network with theano on the server and got out-of-memory error, but I am not sure what is the reason. I am asking because it is unlikely to be just because I am using too much memory. </p>
<p>Here are the reasons:</p>
<p>First, according to this <a href="http://deeplearning.net/software/theano/faq.ht... | 0 | 2016-08-29T02:32:18Z | 39,198,082 | <p>What size are your minibatches? You need to remember that the activations take space in memory too.</p>
| 1 | 2016-08-29T03:24:21Z | [
"python",
"memory",
"theano"
] |
Can I use something like scipy.stats, in Python, to create a fitness function responds like a distribution | 39,197,789 | <p>I need to create a normalised fitness function for positive values 0ââ. I want to experiment, starting with (inputâoutput) something like 0â0, 1â1, ââ0. My maths is a bit weak and expect this is really not hard, if you no how.</p>
<p>So the output of the function should be heavily skewed towards 0 and... | 0 | 2016-08-29T02:35:12Z | 39,202,944 | <p>So you want a probability dustribution with a pdf of this form? Then you need to:</p>
<ul>
<li>normalize it (the integral of pdf over the domain is unity)</li>
<li>subclass the rv_continuous class like shown in the docs, <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html" re... | 0 | 2016-08-29T09:34:53Z | [
"python",
"scipy",
"fitness"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.