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 |
|---|---|---|---|---|---|---|---|---|---|
Tensorflow sequence-to-sequence LSTM within LSTM (nested) | 37,900,366 | <p>I would like to build an LSTM with a special word embedding, but I have some questions about how this would work. </p>
<p>As you might know, some LSTMs operate on characters, so it is characters in, characters out. I would like to do the same, with an abstraction on words to learn a robust embedding on them with a ... | 0 | 2016-06-18T18:34:22Z | 37,934,231 | <p>I don't know the paper you are referring to.</p>
<p>But here is an idea on how I would implement something like this in TensorFlow:</p>
<p>You can create 2 <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py#L243" rel="nofollow">LSTMCells</a>.</p>
<p>If you want to supp... | 3 | 2016-06-21T01:30:01Z | [
"python",
"tensorflow",
"deep-learning",
"lstm",
"word-embedding"
] |
Infinite loop in own sorting function in python | 37,900,380 | <p>I am very new to python, and as excersize I want to write sorting function just with my little knowledge of python. But my code ends in infinite loop, but I cant figure out why. Can anybody help?</p>
<p>here is my code</p>
<pre><code>#create list
sezn = []
while True:
try :
a = int(input("Number: "))
... | 0 | 2016-06-18T18:36:19Z | 37,900,475 | <p>You are forgetting to set <code>sez</code> to an empty list during the while loop:</p>
<pre><code>while index < length:
sez = [] # <-- need to add this line, and you can also get rid of this from before the while loop
for i in sezn:
if i == min(sezn):
sort.append(i)
else:
... | 0 | 2016-06-18T18:47:04Z | [
"python",
"loops"
] |
Infinite loop in own sorting function in python | 37,900,380 | <p>I am very new to python, and as excersize I want to write sorting function just with my little knowledge of python. But my code ends in infinite loop, but I cant figure out why. Can anybody help?</p>
<p>here is my code</p>
<pre><code>#create list
sezn = []
while True:
try :
a = int(input("Number: "))
... | 0 | 2016-06-18T18:36:19Z | 37,901,475 | <p>The loop is infinite cause you dont get out of it.</p>
<p>if you just want the to get out of the loop. Then:</p>
<pre><code>sezn = []
while True:
try :
a = int(input("Number: "))
sezn.append(a)
break
except :
break
</code></pre>
| 0 | 2016-06-18T20:45:47Z | [
"python",
"loops"
] |
How to get complete link of an image with python? | 37,900,397 | <p>I am trying to make a crawler which goes to the web page and downloads all the images available on that page. My code looks like this</p>
<pre><code>import random
import urllib.request
import requests
from bs4 import BeautifulSoup
def get_images(url):
code = requests.get(url)
text = code.text
soup = Be... | 1 | 2016-06-18T18:37:15Z | 37,900,454 | <p>Full url of your image is <strong>hostname of your webpage</strong> + <strong>relative path in src tag</strong>.</p>
<p>e.g </p>
<p>Url of your webpage is <code>http://example.com/foo/bar.html</code></p>
<p>and image src tag is : <code><img src="/image/smiley.png"></code>,</p>
<p>then absolute url of your ... | 0 | 2016-06-18T18:44:14Z | [
"python",
"beautifulsoup",
"web-crawler"
] |
Persisting filter output inside loop | 37,900,416 | <p>I am trying the following to generate the prime numbers till a given limit. I thought of using sieve of eratosthenes. When I use a list I get the correct output but when I don't make it as a list the output is false and gives back all numbers. Is there a way to do this with recursion and since there is a recursion l... | 1 | 2016-06-18T18:39:39Z | 37,900,745 | <p>I'm not a python expert, but I've done some debugging on your code. It seems, that the lambda expression is evaluated at the time the sequence is read. That is, in the actual expression <code>x % first</code> the <code>first</code> is substituted every time with the <strong>current</strong> value of <code>first</cod... | 1 | 2016-06-18T19:15:57Z | [
"python",
"algorithm",
"generator"
] |
Attaching multiple plots to a seaborn plot | 37,900,452 | <p>The following bit of code:</p>
<pre><code>import seaborn as sns
sns.lmplot(x='EstCurentMarketValueSqFt',
y='MarketValueSqFt',
data=sales,
scatter_kws={'edgecolor': "black",
'linewidth': 1})
</code></pre>
<p>Generates the following picture:</p>
<p><a href="h... | 0 | 2016-06-18T18:44:11Z | 37,900,900 | <p><code>sns.lmplot</code> does not immediately interface with <code>matplotlib</code> methods (at least, not in the way that I'm used to) because it's attached to a <code>sns.FacetGrid</code>.</p>
<p>After reading the API a bit more, <code>regplot</code> is recommended for this purpose. And that works:</p>
<pre><cod... | 0 | 2016-06-18T19:33:36Z | [
"python",
"matplotlib",
"data-visualization",
"seaborn"
] |
Read all XML files under multiple directories using python | 37,900,456 | <p>I am using Pandas through Jupyter Notebooks. I have 10 XML files which are stored in multiple locations.
For example: </p>
<pre><code>./A/1.xml
./A/2.xml
./A/3.xml
./B/4.xml
./B/5.xml
./B/6.xml
</code></pre>
<p>How can I load all of these files so that I can extract three particular elements in each file such as ... | -2 | 2016-06-18T18:44:27Z | 37,904,851 | <p>Use <code>glob</code> to get a list of all the files that match your pattern:</p>
<pre><code>import glob
import os
from lxml import etree
dir = '/path/to/the/parent/directory/'
for file in glob.iglob(os.path.join(dir, '*/*.xml')):
with open(file) as f:
data = etree.parse(f)
</code></pre>
| 1 | 2016-06-19T07:17:23Z | [
"python",
"xml",
"beautifulsoup",
"lxml",
"elementtree"
] |
Subclassing logging.Formatter Changes Default Behavior of logging.Formatter | 37,900,521 | <p>I added two handlers with different formatters to my logger. The first one requires subclassing logging.Formatter to do custom formatting. The default formatter will suffice for the second handler.</p>
<p>Let's say the first formatter simply removes newline characters from the message. The following script illustra... | 4 | 2016-06-18T18:51:53Z | 37,901,298 | <p>This line was your down fall:</p>
<pre><code>record.msg = record.msg.strip().replace('\n', ' ')
</code></pre>
<p>You reassigned the scrubbed string to the record which is used by all remaining handlers/formatters attached to the logger. Copy the record and it works:</p>
<pre><code>import logging
from copy import ... | 1 | 2016-06-18T20:21:43Z | [
"python",
"class",
"python-3.x",
"logging",
"subclass"
] |
Extract strings after a specific offset to x00 inside a binary file on linux | 37,900,616 | <p>i seeking for the simplest way of extracting a string inside a binary file on linux (command line). As example in my case the string begins with offset 138 and ends with the first hex 00.</p>
<p>The last days i tried arround with hexdump and also read the documentation about several times. Sadly in all what i tried... | 1 | 2016-06-18T19:02:08Z | 37,900,787 | <p>You can do this simply by reading from the file at offset 138 into buffer until you reach <code>0x00</code> like so...</p>
<pre><code>// Open the file for read
$fp = fopen($fileName, "rb");
// Set the file pointer to a byte offset of 138 to begin reading
fseek($fp, 138);
$reached = false;
$buffer = "";
// Read into... | 1 | 2016-06-18T19:20:09Z | [
"php",
"python",
"binary",
"offset"
] |
HTTP Error 400: Bad Request (urllib) | 37,900,758 | <p>I'm writing a script to get information regarding buildings in NYC. I know that my code works and returns what i'd like it to. I was previously doing manual entry and it worked. Now i'm trying to have it read addresses from a text file and access the website with that information and i'm getting this error:</p>
<p>... | 1 | 2016-06-18T19:17:14Z | 37,901,334 | <p>A 400 error means that the server cannot understand your request (e.g., malformed syntax). That said, its up to the developers on what status code they want to return and, unfortunately, not everyone strictly follows their intended meaning.</p>
<p>Check out this <a href="https://www.w3.org/Protocols/rfc2616/rfc261... | 1 | 2016-06-18T20:25:44Z | [
"python",
"beautifulsoup",
"urllib"
] |
Printing dataframe to .csv in python. TypeError:must be convertible to a buffer | 37,900,781 | <p>I'm going through a dataframe and appending specific rows into a list. I'm then taking that list and trying to save it as a .csv file. However, I'm getting the following error: TypeError: must be convertible to a buffer, not DataFrame.</p>
<p>Any suggestions on what this is and how to fix this is greatly appreciate... | 0 | 2016-06-18T19:19:43Z | 37,901,810 | <p>You're looking for <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html" rel="nofollow"><code>DataFrame.to_csv</code></a>:</p>
<pre><code>for item in my_list:
item.to_csv(new_file)
</code></pre>
| 1 | 2016-06-18T21:29:49Z | [
"python",
"csv",
"pandas",
"dataframe",
"error-handling"
] |
Meaning of '>>' in Python byte code | 37,900,782 | <p>I have disassembled the following python code </p>
<pre><code>def factorial(n):
if n <= 1:
return 1
elif n == 2:
return 2
elif n ==4:
print('hi')
return n * 2
</code></pre>
<p>and the resulting bytecode </p>
<pre><code> 2 0 LOAD_FAST 0 (n)
... | 11 | 2016-06-18T19:19:45Z | 37,900,805 | <p>They are jump targets; positions earlier <code>*JUMP*</code> bytecode jumps to when the condition is met.</p>
<p>The first jump:</p>
<pre><code> 9 POP_JUMP_IF_FALSE 16
</code></pre>
<p>jumps to offset 16, so at offset 16 the output has a target <code>>></code>:</p>
<pre><code>4 >> 1... | 12 | 2016-06-18T19:21:46Z | [
"python",
"virtual-machine",
"bytecode"
] |
Django Rest Framework - How to restructure json response? | 37,900,873 | <p>I am using Django Rest Framework (along with <a href="https://github.com/umutbozkurt/django-rest-framework-mongoengine" rel="nofollow">rest_framework_mongoengine</a>) and overriding <strong>to_representation()</strong> of my serializer to send back my own custom JSON object. Everything is working fine but the order ... | 3 | 2016-06-18T19:30:25Z | 37,900,962 | <p>Try to return a <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow">OrderedDict</a> in the <code>to_representation</code>:</p>
<pre><code>def to_representation(self, pharmacy):
return OrderedDict([('id', str(pharmacy.id),), ...])
</code></pre>
<p>The dict object in... | 3 | 2016-06-18T19:40:57Z | [
"python",
"django",
"django-rest-framework"
] |
Django Rest Framework - How to restructure json response? | 37,900,873 | <p>I am using Django Rest Framework (along with <a href="https://github.com/umutbozkurt/django-rest-framework-mongoengine" rel="nofollow">rest_framework_mongoengine</a>) and overriding <strong>to_representation()</strong> of my serializer to send back my own custom JSON object. Everything is working fine but the order ... | 3 | 2016-06-18T19:30:25Z | 37,901,321 | <p>If you want to maintain order of response keys, you can use an <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow"><code>OrderedDict</code>.</a> But there is one thing you should remember about <code>OrderedDicts</code>:</p>
<p><strong>OrderedDict maintains order only... | 3 | 2016-06-18T20:24:51Z | [
"python",
"django",
"django-rest-framework"
] |
How can I add items in listWidget? | 37,900,976 | <p>I have trouble adding item in listWidget</p>
<p>I made UI with QT creator and want to import it in python.</p>
<p>When I run this code the items doesn't shows in listWidget, only white blanks.</p>
<p>what is the problem??</p>
<p>please help me</p>
<p>my code is </p>
<pre><code>import sys
from PyQt4 import QtCo... | 0 | 2016-06-18T19:42:01Z | 37,916,510 | <p>You create an instance of <code>Ui_SecDialog</code> in <code>ex</code> but you want to create a <code>SecDialog</code> instance:</p>
<p><code>ex = SecDialog()</code></p>
| 0 | 2016-06-20T07:11:51Z | [
"python",
"python-2.7",
"python-3.x",
"qt-creator"
] |
Pandas: read_table remove comment lines with '##' but not '#<string>'? | 37,900,988 | <p>I have some large tab separated data sets that have long commented sections, followed by the table header, formatted like this:</p>
<pre><code>##FORMAT=<ID=AMQ,Number=.,Type=Integer,Description="Average mapping quality for each allele present in the genotype">
##FORMAT=<ID=SS,Number=1,Type=Integer,Descript... | 1 | 2016-06-18T19:43:17Z | 37,901,359 | <p>use <code>skiprows</code> as a workaround:</p>
<pre><code>SS_txt_df = pd.read_table(SS_txt_file,sep='\t',skiprows=3)
df
Out[13]:
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NORMAL TUMOR
0 chr1 2985885 . c G . . . GT:IGT...
1 chr1 3312963 . C T . . . ... | 1 | 2016-06-18T20:28:29Z | [
"python",
"pandas"
] |
Pandas: read_table remove comment lines with '##' but not '#<string>'? | 37,900,988 | <p>I have some large tab separated data sets that have long commented sections, followed by the table header, formatted like this:</p>
<pre><code>##FORMAT=<ID=AMQ,Number=.,Type=Integer,Description="Average mapping quality for each allele present in the genotype">
##FORMAT=<ID=SS,Number=1,Type=Integer,Descript... | 1 | 2016-06-18T19:43:17Z | 37,905,834 | <p>you can easily calculate the number of header lines, that must be skipped when reading your CSV file:</p>
<pre><code>fn = '/path/to/file.csv'
skip_rows = 0
with open(fn, 'r') as f:
for line in f:
if line.startswith('##'):
skip_rows += 1
else:
break
df = pd.read_table(f... | 1 | 2016-06-19T09:38:00Z | [
"python",
"pandas"
] |
How can I iterate over nested json dicts? | 37,901,044 | <p>I've been trying to figure out how I can iterate over a json like object, so I could get a user id by its name.</p>
<p><strong>json</strong></p>
<pre><code>{
"ApiSearchResult": [
{
"totalNumberResults": 55,
"type": "User",
"searchResults": [
{
... | 1 | 2016-06-18T19:50:23Z | 37,901,122 | <p>This might work if your response is already a python dictionary:</p>
<pre><code>def getidbyname(name):
for event in data["ApiSearchResult"][0]["searchResults"]:
if event["name"] == name:
return event["uid"]
</code></pre>
<p>If your input is a text value, you need to use <code>json.loads(res... | 2 | 2016-06-18T20:00:14Z | [
"python",
"json"
] |
How can I iterate over nested json dicts? | 37,901,044 | <p>I've been trying to figure out how I can iterate over a json like object, so I could get a user id by its name.</p>
<p><strong>json</strong></p>
<pre><code>{
"ApiSearchResult": [
{
"totalNumberResults": 55,
"type": "User",
"searchResults": [
{
... | 1 | 2016-06-18T19:50:23Z | 37,901,157 | <pre><code>def getidbyname(name):
for i in data['ApiSearchResult'][0]['searchResults']:
if i['name'] == name:
return i['uid']
</code></pre>
| 2 | 2016-06-18T20:04:26Z | [
"python",
"json"
] |
I want something to be executed through django | 37,901,077 | <p>I know this question was asked before, but none worked for me. I have this code that I want it to be executed when a button is clicked and a message is passed</p>
<pre><code>import time
from sinchsms import SinchSMS
number = '+yourmobilenumber'
message = 'I love SMS!'
client = SinchSMS(your_app_key, your_app_secr... | 0 | 2016-06-18T19:54:25Z | 37,902,413 | <p>All you need is a form with a message field. In a view, you want to show that form and when the user press submit, you want to execute your script.</p>
<p>Here is some <strong>pseudo</strong>-code:</p>
<pre><code>urls.py
url('^my-page/' my_views.my_view, name='my-page'),
forms.py
SmsForm(forms.Form):
message ... | 0 | 2016-06-18T23:03:11Z | [
"python",
"django"
] |
I want something to be executed through django | 37,901,077 | <p>I know this question was asked before, but none worked for me. I have this code that I want it to be executed when a button is clicked and a message is passed</p>
<pre><code>import time
from sinchsms import SinchSMS
number = '+yourmobilenumber'
message = 'I love SMS!'
client = SinchSMS(your_app_key, your_app_secr... | 0 | 2016-06-18T19:54:25Z | 37,907,861 | <p>Lets start from the dust cloud.</p>
<p>What you are asking is mostly about how the web pages work. You need to know how to pass parameters using HTML. There are lots of ways to do it. But with django there is a pattern.</p>
<p>You need a url, and a view to catch any requests. Then you need to create a template and... | 0 | 2016-06-19T13:42:31Z | [
"python",
"django"
] |
I want something to be executed through django | 37,901,077 | <p>I know this question was asked before, but none worked for me. I have this code that I want it to be executed when a button is clicked and a message is passed</p>
<pre><code>import time
from sinchsms import SinchSMS
number = '+yourmobilenumber'
message = 'I love SMS!'
client = SinchSMS(your_app_key, your_app_secr... | 0 | 2016-06-18T19:54:25Z | 37,947,517 | <p>You can create a view that takes up query parameters from the url and use it for further implementation. Then you can create a link/button in the html template which can redirect you to that url. For example:</p>
<p>in urls.py:</p>
<pre><code>url(r'^run_a/(?P<msg>\w{0,25})/(?P<num>\w{0,25})/$', yourcod... | 0 | 2016-06-21T14:41:10Z | [
"python",
"django"
] |
Faster way to extract patches from images? | 37,901,186 | <p>I am trying to extract patches of fixed size centered at some given position (x,y). The code is given below-</p>
<pre><code>for i,j in zip(indices[0],indices[1]):
patches.append(
x[None,
i-int(np.floor(patch_size/2.0)):i+int(np.floor(patch_size/2.0))+1,
j-int(np.floor(patch_size/2.0)... | 3 | 2016-06-18T20:08:10Z | 37,901,746 | <p>Assuming you are dealing with near-boundary indices separately, as otherwise you would have different shaped patches, let us suggest ourselves a vectorized approach making use <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>broadcasting</code></a> together with some knowl... | 2 | 2016-06-18T21:21:34Z | [
"python",
"performance",
"numpy",
"image-processing"
] |
Faster way to extract patches from images? | 37,901,186 | <p>I am trying to extract patches of fixed size centered at some given position (x,y). The code is given below-</p>
<pre><code>for i,j in zip(indices[0],indices[1]):
patches.append(
x[None,
i-int(np.floor(patch_size/2.0)):i+int(np.floor(patch_size/2.0))+1,
j-int(np.floor(patch_size/2.0)... | 3 | 2016-06-18T20:08:10Z | 37,906,650 | <p>Using scikit-learn:</p>
<pre><code>from sklearn.feature_extraction.image import extract_patches
all_patches = extract_patches(x, patch_size)
upper_left = indices - patch_size // 2
patches = all_patches[upper_left[0], upper_left[1]]
</code></pre>
<p>A similar function can be found in scikit-image: <a href="http:/... | 0 | 2016-06-19T11:19:27Z | [
"python",
"performance",
"numpy",
"image-processing"
] |
How do I generate a list of people I follow using Twython? | 37,901,269 | <p>To get a list of who follows me, I know that I can use:</p>
<pre><code>twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
followers = twitter.get_followers_ids(screen_name = "my_username")
</code></pre>
<p>but how do I get a list of who I follow?</p>
| 0 | 2016-06-18T20:18:45Z | 37,901,270 | <p>While writing this question I was flicking between bits of code trying to work out how to do this, and the answer was painfully simple.</p>
<p>I thought I'd still post this question and answer it myself to perhaps save people some time if they happened to have the same question.</p>
<p>In the line:</p>
<pre><code... | 0 | 2016-06-18T20:18:45Z | [
"python",
"twitter",
"twython"
] |
How to make dynamic stub functions on the fly? | 37,901,273 | <p>I have a class with about 200 stub functions, they look something like this:</p>
<pre><code>def name1(self, **kwargs):
return self.run('name-1', kwargs)
def name2(self, ** kwargs):
return self.run('name-2', kwargs)
</code></pre>
<p>So on and so forth.</p>
<p>There is a run function that takes care of the... | 4 | 2016-06-18T20:19:24Z | 37,901,367 | <p>You can use a <code>__getattr__</code> method in your class that returns a wrapper function around <code>run</code>. You just need a way to translate between the method name (e.g. <code>name1</code>) and the string that should get passed to the <code>run</code> method (e.g. <code>"name-1"</code>). It would of course... | 4 | 2016-06-18T20:29:44Z | [
"python"
] |
How to make dynamic stub functions on the fly? | 37,901,273 | <p>I have a class with about 200 stub functions, they look something like this:</p>
<pre><code>def name1(self, **kwargs):
return self.run('name-1', kwargs)
def name2(self, ** kwargs):
return self.run('name-2', kwargs)
</code></pre>
<p>So on and so forth.</p>
<p>There is a run function that takes care of the... | 4 | 2016-06-18T20:19:24Z | 37,902,070 | <p>Here's a slightly more general and potentially more efficient version of @Blckknight's excellent and relatively concise <a href="http://stackoverflow.com/a/37901367/355230">answer</a>. </p>
<p>It's longer because it's more general in the sense that it uses a regular expression to translate the name the stub functio... | 1 | 2016-06-18T22:07:41Z | [
"python"
] |
Generate a random number from a list, not including one of the numbers | 37,901,341 | <p>I am trying to create a list of sequential integers from 0 to n, then after picking a randon integer from that list, generate another random integer from the same list that doesn't include the integer previously generated.</p>
<pre><code>n = 10
a = np.arange(1,n) #Creating my initial list
for b=np.random.choice(a... | 0 | 2016-06-18T20:26:30Z | 37,901,398 | <p>I think the procedure you are trying to perform is random sampling without replacement. </p>
<p>Let's say you want to pick <code>k</code> numbers:</p>
<pre><code>import numpy as np
n = 10
k = 3
a = np.arange(1,n) #Creating my initial list
numbers = np.random.choice(a, k, replace=False)
</code></pre>
| 3 | 2016-06-18T20:33:25Z | [
"python",
"list",
"random"
] |
Generate a random number from a list, not including one of the numbers | 37,901,341 | <p>I am trying to create a list of sequential integers from 0 to n, then after picking a randon integer from that list, generate another random integer from the same list that doesn't include the integer previously generated.</p>
<pre><code>n = 10
a = np.arange(1,n) #Creating my initial list
for b=np.random.choice(a... | 0 | 2016-06-18T20:26:30Z | 37,902,207 | <blockquote>
<p>Help on method sample in module random:</p>
<p>sample(self, population, k) method of random.Random instance </p>
<p>Chooses k unique random elements from a population sequence.</p>
<p>Returns a new list containing elements from the population while<br>
leaving the original population... | 0 | 2016-06-18T22:27:51Z | [
"python",
"list",
"random"
] |
Generate a random number from a list, not including one of the numbers | 37,901,341 | <p>I am trying to create a list of sequential integers from 0 to n, then after picking a randon integer from that list, generate another random integer from the same list that doesn't include the integer previously generated.</p>
<pre><code>n = 10
a = np.arange(1,n) #Creating my initial list
for b=np.random.choice(a... | 0 | 2016-06-18T20:26:30Z | 37,902,349 | <p>Another answer:</p>
<p>1) Generate your initial list.</p>
<p>2) Shuffle the list. If there is no library function to do it, then use the Fisher-Yates shuffle. Hint: there is a big time saver here.</p>
<p>3) Pick the first number from the shuffled list. This is your initial number.</p>
<p>4) Pick the second nu... | 1 | 2016-06-18T22:52:21Z | [
"python",
"list",
"random"
] |
How to fit various length cuts of lumber into standard length lumber piece | 37,901,378 | <p>I'm trying to write a program that calculates the most efficient way to cut some small pieces of lumber from a standard 2" by 4" by 8' piece. I'm having trouble searching up the algorithm used for this. Please help! I use Python but just want to get the general idea of how an algorithm would work.</p>
<p>The situat... | 0 | 2016-06-18T20:31:32Z | 37,903,473 | <p>This program solves the problem using the crudest of brute force. It enumerates all possible subsets of pieces for the first stick, and then recurses, keeping a cache of previous computations. With 9 target pieces, there's only 512 subsets, so this is entirely fast enough (as it completes instantaneously).</p>
<pre... | 0 | 2016-06-19T02:39:03Z | [
"python",
"algorithm"
] |
How to fit various length cuts of lumber into standard length lumber piece | 37,901,378 | <p>I'm trying to write a program that calculates the most efficient way to cut some small pieces of lumber from a standard 2" by 4" by 8' piece. I'm having trouble searching up the algorithm used for this. Please help! I use Python but just want to get the general idea of how an algorithm would work.</p>
<p>The situat... | 0 | 2016-06-18T20:31:32Z | 37,912,833 | <p>I solved this brutally, using the excellent parallel array processing language <strong><a href="http://www.dyalog.com" rel="nofollow">Dyalog APL</a></strong>. The solution turned out to be rather surprising.</p>
<p>The task is 2-fold; on the other hand you want to minimise the spill amount but on the other hand you... | 0 | 2016-06-19T23:21:37Z | [
"python",
"algorithm"
] |
Nested For Loop Issue in Python | 37,901,504 | <p>I am a newbie in python area ; i was trying to write a simple program to run multiple commands on multiple devices , Input from 2 different text files but the output is a bit wierd and i am not sure what is the issue
sample code as below:</p>
<pre><code>commandsfile = input ("Please Enter CommandsFile path as c:/ex... | 0 | 2016-06-18T20:51:05Z | 37,901,557 | <p>I think the problem is that when you iterate the actual file it moves the cursor or something, so when you iterate it again you're at the end of file.<br>
However, using <code>.readlines()</code> after every <code>open()</code> solves it (maybe because you don't iterate over the file itself but over a list created f... | 1 | 2016-06-18T20:58:02Z | [
"python",
"loops",
"for-loop",
"nested"
] |
Nested For Loop Issue in Python | 37,901,504 | <p>I am a newbie in python area ; i was trying to write a simple program to run multiple commands on multiple devices , Input from 2 different text files but the output is a bit wierd and i am not sure what is the issue
sample code as below:</p>
<pre><code>commandsfile = input ("Please Enter CommandsFile path as c:/ex... | 0 | 2016-06-18T20:51:05Z | 37,901,567 | <p>An easy and quick fix would be to move the <code>commands</code> line into the first loop:</p>
<pre><code>hosts = open((hostsfile) , "r")
for host in hosts:
print("1")
commands1 = open((commandsfile), "r")
for cmd in commands1:
print("2")
</code></pre>
| 0 | 2016-06-18T20:59:53Z | [
"python",
"loops",
"for-loop",
"nested"
] |
Nested For Loop Issue in Python | 37,901,504 | <p>I am a newbie in python area ; i was trying to write a simple program to run multiple commands on multiple devices , Input from 2 different text files but the output is a bit wierd and i am not sure what is the issue
sample code as below:</p>
<pre><code>commandsfile = input ("Please Enter CommandsFile path as c:/ex... | 0 | 2016-06-18T20:51:05Z | 37,901,609 | <p>Your commands1 is exhausted in the first iteration of the for loop.
When you do <code>commands1 = open( (commandsfile), "r")</code> you get an iterator in commands1 and will be exhausted in the for loop. You can convert the commamds1 iterator to a list by doing <code>commamds1 = list(commamds1)</code></p>
<pre><c... | 0 | 2016-06-18T21:04:41Z | [
"python",
"loops",
"for-loop",
"nested"
] |
if isinstance statement in Python is True but it does not pass | 37,901,574 | <p>I'm struggling with the extra credit of excercise 35 from the book "Learn Python the hard way". Based on the advise provided in previous comments (<a href="http://stackoverflow.com/questions/5300506/learn-python-the-hard-way-exercise-35-help">learn python the hard way exercise 35 help</a>) I tried two options:</p>
... | 0 | 2016-06-18T21:00:24Z | 37,901,763 | <p>Raw input is going to be a string, so it's normal for your test to fail. A more pythonic approach is:</p>
<pre><code>next_move = raw_input("> ")
try:
how_much = int(next_move)
except ValueError:
dead("Man, learn to type a number.")
</code></pre>
| 0 | 2016-06-18T21:23:13Z | [
"python",
"python-2.7",
"input"
] |
Python timed list creation | 37,901,665 | <p>I am receiving data from a streaming API that I insert into a list (this list receives data for about 8 hours a day) then after a given period of time perform some calculations on then insert the results of those calculations into another list then wait for another period of time and perform calculations on that lis... | -1 | 2016-06-18T21:10:01Z | 37,903,421 | <p>You can use the <code>Timer</code> class from Python's <code>Threading</code> module.</p>
<p>Your program would look something like this:</p>
<pre><code>from threading import Timer
def buildLists():
global list1, list2, list3
list1 = FirstList()
# Calculate other two lists
list2 = SecondList()
... | 0 | 2016-06-19T02:29:07Z | [
"python",
"python-2.7"
] |
cx_Freeze not including specified files | 37,901,679 | <p>I have built a simple soundboard in Python with tkinter and winsound. The soundboard uses some .gif and .wav data files, which I included in the same directory as the python script itself. I wrote the following setup.py file using cx_Freeze:</p>
<pre><code>import sys
from cx_Freeze import Executable, setup
build_e... | 0 | 2016-06-18T21:12:10Z | 37,901,729 | <p>You need to move your images to the build directory so the executable can find them. I doubt cx_Freeze will package the images into the executable.</p>
| 0 | 2016-06-18T21:19:15Z | [
"python",
"cx-freeze"
] |
Error: Error when checking model input: expected dense_input_6 to have shape (None, 784) but got array with shape (784L, 1L) | 37,901,698 | <p>I get an error when trying to apply the below code onto the MNIST sample dataset for both training and testing. Please helpe </p>
<p>The following is my code: </p>
<pre><code>import pandas
import numpy
import numpy
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense
... | 1 | 2016-06-18T21:15:11Z | 37,902,193 | <p>I assume you are working with <a href="http://makeyourownneuralnetwork.blogspot.fr/2015/03/the-mnist-dataset-of-handwitten-digits.html" rel="nofollow">this tutorial</a>.</p>
<p>I would recommend using pandas to read your format:</p>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
import numpy a... | 0 | 2016-06-18T22:26:08Z | [
"python",
"tensorflow",
"keras"
] |
Flask-Uploads IOError: [Errno 2] No such file or directory | 37,901,716 | <p>So, I've been trying to add an image uploader to my code, but I've been running into issues. Even though I thought I had my <code>upload_folder</code> configured properly, I keep getting errors like: <code>IOError: [Errno 2] No such file or directory: '/static/uploads/compressor.jpg'</code> even though the file/di... | 0 | 2016-06-18T21:17:47Z | 37,901,802 | <p>Both <code>/tmp</code> and <code>/static/uploads/..</code>, are absolute paths. And your code is looking in the <code>/</code> folder instead of looking in your project's folder. You should use the absolute path to point at your folder <code>/path/to/your/project/static/uploads/..</code> or use a path relative to th... | 1 | 2016-06-18T21:28:29Z | [
"python",
"file-upload",
"flask",
"flask-uploads"
] |
Flask-Uploads IOError: [Errno 2] No such file or directory | 37,901,716 | <p>So, I've been trying to add an image uploader to my code, but I've been running into issues. Even though I thought I had my <code>upload_folder</code> configured properly, I keep getting errors like: <code>IOError: [Errno 2] No such file or directory: '/static/uploads/compressor.jpg'</code> even though the file/di... | 0 | 2016-06-18T21:17:47Z | 39,797,491 | <p>This worked for me:</p>
<pre><code>basedir = os.path.abspath(os.path.dirname(__file__))
file.save(os.path.join(basedir, app.config['UPLOAD_FOLDER'], filename))
</code></pre>
| 0 | 2016-09-30T18:03:59Z | [
"python",
"file-upload",
"flask",
"flask-uploads"
] |
How to back reference an object within a mocked method | 37,901,750 | <p><strong>Method:</strong></p>
<pre><code>def analyse_sentence(self, sentence, channel):
found_top_news = 'top news' in sentence or 'trending news' in sentence
if found_top_news:
categories = []
found_categories = SharedNewsUtils.extract_categories(sentence, categories)
... | 0 | 2016-06-18T21:21:49Z | 37,908,770 | <p>If <code>extract_categories</code> is mutating <code>categories</code> then you should be able to use <code>side_effect</code> in your test to mutate <code>categories</code>:</p>
<pre><code>def mutate_categories(sentence, categories):
categories.append('some_item')
mck.side_effect = mutate_categories
</code></p... | 0 | 2016-06-19T15:19:05Z | [
"python",
"unit-testing",
"mocking"
] |
How does one store descriptive dates like the "The last day in Feb", "Fourth Saturday in April"? | 37,901,786 | <p>I have some data that has descriptive dates (e.g., Monday before Thanksgiving, Last day in February, 4th Saturday in April) as part of describing start and end times. Some of the dates are explicit (e.g., October 31st). I want to store the descriptive and the explicit values so for any year I can then calculate when... | 1 | 2016-06-18T21:26:38Z | 38,021,560 | <p>If you have only a handful of reoccurring descriptive dates, the easiest thing to do would be to create a dictionary that can translate them to the explicit dates you want whenever they pop up in your data.</p>
<p>If you have arbitrary descriptive dates or a large number of them, however, it seems that, as was disc... | 1 | 2016-06-24T20:25:19Z | [
"python",
"django",
"date",
"datetime"
] |
Kivy Buildozer Zipfile Error: 98 extra bytes at beginning or within zipfile | 37,901,808 | <p>Upgraded to new buildozer version (Running Kivy,Python and Buildozer on OS X).</p>
<p>Please assist if anyone has picked up similar errors with the android_new branch.</p>
<p>When trying to package a new distribution I'm getting the following zip file errors when running the buildozer command:</p>
<pre><code>buil... | 0 | 2016-06-18T21:29:30Z | 37,902,587 | <p>I don't know why this has started happening, but it apparently can affect all the github .zip files. I pushed a workaround to the p4a master branch earlier today though (it just ignores the error as the extraction still works), so it should hopefully work if you upgrade to master. You can make buildozer re-download ... | 0 | 2016-06-18T23:38:34Z | [
"android",
"python",
"osx",
"kivy",
"buildozer"
] |
updating prior rows of dataframe conditionally upon current | 37,901,827 | <p>I have a dataframe (<code>ev</code>), and I would like to read it and whenever the value of the 'trig' column is 64, I need to update the value of the <code>critical</code> column that is 4 rows above, and change it to 999. I tried the code below but it does not change anything, though seems it should work.</p>
<pr... | 2 | 2016-06-18T21:32:13Z | 37,902,533 | <p>I think you can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a> by <code>mask</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.fillna.html" rel="nofollow"><code>fillna</code></a> <code>False</code>, b... | 0 | 2016-06-18T23:27:35Z | [
"python",
"pandas",
"dataframe"
] |
updating prior rows of dataframe conditionally upon current | 37,901,827 | <p>I have a dataframe (<code>ev</code>), and I would like to read it and whenever the value of the 'trig' column is 64, I need to update the value of the <code>critical</code> column that is 4 rows above, and change it to 999. I tried the code below but it does not change anything, though seems it should work.</p>
<pr... | 2 | 2016-06-18T21:32:13Z | 37,902,881 | <p>Try this, you were close: Learn about single <code>"="</code> vs double <code>"=="</code> </p>
<pre><code> for i in range(0,len(ev)):
if ev['trig'][i] == 64:
ev['critical'][i-4] = 999
</code></pre>
| 0 | 2016-06-19T00:34:41Z | [
"python",
"pandas",
"dataframe"
] |
leave program running in the background and continuously check on the value of the clock | 37,901,832 | <p>My goal is to create a program which continuously checks on the value of time,compares it to variable values (static for now: one or two or three), it will open a specific page, if it matches the value one, I still want the program to stay running till it matches two, perform the same action, same for the value of t... | 1 | 2016-06-18T21:32:42Z | 37,901,871 | <p>Perhaps a pub-sub implementation?</p>
<p>When your time matches, emit a signal. Have other processes subscribe, and listen for that signal. Pseudocoded:</p>
<pre><code>if (time == 1) {
emit "ONE"
} else if (time == 2)
emit "TWO"
} else {
emit "THREE"
}
</code></pre>
<p>Subscriber(s):</p>
<pre><code>... | -1 | 2016-06-18T21:37:39Z | [
"python",
"loops"
] |
leave program running in the background and continuously check on the value of the clock | 37,901,832 | <p>My goal is to create a program which continuously checks on the value of time,compares it to variable values (static for now: one or two or three), it will open a specific page, if it matches the value one, I still want the program to stay running till it matches two, perform the same action, same for the value of t... | 1 | 2016-06-18T21:32:42Z | 37,901,872 | <p>You have to remove the <strong>break</strong> statement and the <strong>else</strong> block, then it won't break the <strong>while</strong> block.</p>
| 0 | 2016-06-18T21:37:45Z | [
"python",
"loops"
] |
leave program running in the background and continuously check on the value of the clock | 37,901,832 | <p>My goal is to create a program which continuously checks on the value of time,compares it to variable values (static for now: one or two or three), it will open a specific page, if it matches the value one, I still want the program to stay running till it matches two, perform the same action, same for the value of t... | 1 | 2016-06-18T21:32:42Z | 37,901,907 | <p>1- How do I let my program run continuously while checking the clock value ?</p>
<p>-- Reassign the clock variables value within the while loop, this will keep checking against the updated timestamp</p>
<p>2- How do I let the program alive to run for the second and third value ?</p>
<p>-- Don't break out of your ... | 1 | 2016-06-18T21:42:56Z | [
"python",
"loops"
] |
Spark k-means OutOfMemoryError | 37,901,846 | <p>I am using spark's k-means clustering under Ml module and I am programming in PySpark. The module works well until 200 clusters but it gives <code>OutOfMemoryError</code> once I go past 300 clusters and more. My
data contains 200k objects and 25k features for each object. I am following the guidelines mentioned unde... | 1 | 2016-06-18T21:34:33Z | 37,903,153 | <pre><code>org.apache.spark.mllib.clustering.VectorWithNorm.toDense(KMeans.scala:612)
</code></pre>
<p>That's the problem. The cluster centres are converted to a dense representation, and then broadcasted to all the executors. This will not scale with thousands of features, which is your case. Checkout <a href="https:... | 1 | 2016-06-19T01:30:28Z | [
"python",
"scala",
"apache-spark",
"out-of-memory",
"cluster-analysis"
] |
Why is sort() not working properly? | 37,901,862 | <p>I am supposed to write a code that initializes an empty list, then read commands and apply them to this list. Everything I have written so far is working great except for sort(), the list was ['5', '10', '9', '1'] and it became ['1', '10', '5', '9'] after sorting which obviously isn't right.
That's my code:</p>
<pr... | 1 | 2016-06-18T21:36:10Z | 37,901,873 | <p>In this case, you're applying <code>sort</code> to a list of strings, which means the comparison is based on characters instead of numeric values.</p>
<p>You need to start by mapping your inputs into integers:</p>
<pre><code>args = map(int, args)
</code></pre>
| 0 | 2016-06-18T21:37:50Z | [
"python",
"python-3.x"
] |
Why is sort() not working properly? | 37,901,862 | <p>I am supposed to write a code that initializes an empty list, then read commands and apply them to this list. Everything I have written so far is working great except for sort(), the list was ['5', '10', '9', '1'] and it became ['1', '10', '5', '9'] after sorting which obviously isn't right.
That's my code:</p>
<pr... | 1 | 2016-06-18T21:36:10Z | 37,901,884 | <p>Your list is made up of strings and not integers (or numerals to be precise). </p>
<p>The <code>sort()</code> method is doing a <em>lexicographical</em> sort (as expected on strings). Try casting your input to <code>int</code>.</p>
<p>You could modify the line:</p>
<pre><code>args = userInput[1:]
</code></pre>
<... | 0 | 2016-06-18T21:39:59Z | [
"python",
"python-3.x"
] |
Why is sort() not working properly? | 37,901,862 | <p>I am supposed to write a code that initializes an empty list, then read commands and apply them to this list. Everything I have written so far is working great except for sort(), the list was ['5', '10', '9', '1'] and it became ['1', '10', '5', '9'] after sorting which obviously isn't right.
That's my code:</p>
<pr... | 1 | 2016-06-18T21:36:10Z | 37,901,887 | <p>You're doing a <em>string</em> sort on the input list (which is made up of strings representing numbers). Hence a lexicographic sort is performed, and that means that <code>10</code> comes after <code>1</code> but before <code>5</code> (it's the same order words would appear in a dictionary). To get the desired orde... | 2 | 2016-06-18T21:40:28Z | [
"python",
"python-3.x"
] |
Why is sort() not working properly? | 37,901,862 | <p>I am supposed to write a code that initializes an empty list, then read commands and apply them to this list. Everything I have written so far is working great except for sort(), the list was ['5', '10', '9', '1'] and it became ['1', '10', '5', '9'] after sorting which obviously isn't right.
That's my code:</p>
<pr... | 1 | 2016-06-18T21:36:10Z | 37,902,132 | <p>You already know why your sort didn't work as expected.</p>
<p>I just wish to give you better solution than converting everything to integers, then sorting, then back to strings. It is very unefficient.</p>
<p>To do it right, you convert both comparison operands to int and compare them in this form. You do it in t... | 0 | 2016-06-18T22:17:01Z | [
"python",
"python-3.x"
] |
Why is sort() not working properly? | 37,901,862 | <p>I am supposed to write a code that initializes an empty list, then read commands and apply them to this list. Everything I have written so far is working great except for sort(), the list was ['5', '10', '9', '1'] and it became ['1', '10', '5', '9'] after sorting which obviously isn't right.
That's my code:</p>
<pr... | 1 | 2016-06-18T21:36:10Z | 37,902,300 | <p>If you want the list items to remain strings, the best solution is probably:</p>
<pre><code>L.sort(key=int)
</code></pre>
<p>This converts all the strings in the list to integers for comparison purposes, but you don't have to convert them back afterward.</p>
| 0 | 2016-06-18T22:44:20Z | [
"python",
"python-3.x"
] |
Handling Accented Characters Python/MySQL | 37,901,865 | <p>I have a system I'm building that inserts rows into a MySQL database through POST requests (API built in Flask/Python). Some of the rows have accents in them. Particularly I have a row that has the name <code>Péter</code> in it. The output in the code when I do the SELECT for the DB in my code is <code>P\xc3\xa9ter... | 0 | 2016-06-18T21:36:37Z | 37,902,049 | <p>For anyone else having this issue, I just had to set <code>charset = 'utf8'</code> in my connection string (explicitly set the charset). I tried encoding strings in the code etc but this did the trick immediately.</p>
| 1 | 2016-06-18T22:04:00Z | [
"python",
"mysql",
"database",
"encoding",
"amazon-rds"
] |
Not sure what is causing the index error in my if statement | 37,901,868 | <p>I am writing code for a black box test for an assignment. In my function the inputs are a 2d array, and int for x, and int for y, and an int for zombie strength. From my start position if the value of the element is less than the zombie strength, I change the value of the element to -1. Than I got to that element... | 0 | 2016-06-18T21:37:04Z | 37,902,923 | <p>Your <code>try</code> clauses aren't necessary as the <code>if</code> test you do before covers the situation. Let's try simplifying and clarifying the code to see if that fixes your problem since we're unable to reproduce it directly.</p>
<p>First, you continue to use <code>front_of_list</code> when <code>x</code... | 0 | 2016-06-19T00:42:10Z | [
"python",
"arrays",
"runtime-error"
] |
Tensorflow reshaping a tensor | 37,901,882 | <p>I'm trying to use <code>tf.nn.sparse_softmax_cross_entropy_with_logits</code> and I have followed the answer by user Olivier Moindrot [here][1] but I'm getting a dimension error</p>
<p>I'm building a segmentation network, so the input image is 200x200 and the output image is 200x200. The classification is binary, s... | 0 | 2016-06-18T21:39:45Z | 37,902,059 | <p>Let's forget about softmax and use a simpler <code>tf.nn.sigmoid_cross_entropy_with_logits</code> here:</p>
<ul>
<li>with sigmoid, you only need one prediction per pixel
<ul>
<li>if pred[pixel] > 0.5, you predict 1</li>
<li>if pred[pixel] < 0.5, you predict 0</li>
</ul></li>
<li>the shape of prediction and targ... | 1 | 2016-06-18T22:06:20Z | [
"python",
"machine-learning",
"neural-network",
"artificial-intelligence",
"tensorflow"
] |
Tensorflow reshaping a tensor | 37,901,882 | <p>I'm trying to use <code>tf.nn.sparse_softmax_cross_entropy_with_logits</code> and I have followed the answer by user Olivier Moindrot [here][1] but I'm getting a dimension error</p>
<p>I'm building a segmentation network, so the input image is 200x200 and the output image is 200x200. The classification is binary, s... | 0 | 2016-06-18T21:39:45Z | 39,017,979 | <p>Using sparse softmax is going to be of help only after the last layer you want to resize the image to the original size (200*200).In this case using reshape as you have would ensure that the the code would be error free.
But in your case you don't have to use sparse softmax. To see why check the dimensions of "pred"... | 0 | 2016-08-18T12:15:05Z | [
"python",
"machine-learning",
"neural-network",
"artificial-intelligence",
"tensorflow"
] |
pdf StringIO embeded rendered html flask template | 37,901,929 | <p>In my flask-app, i'm want to see a preview of pdf that will be generated, before definitely printing and saving it in my application_base_folder.
I could save previews on a tmp dir, but that's not what I really looking for.</p>
<p>I'm creating a pdf with report lab : </p>
<pre><code>def gen_pdf(text):
output =... | 0 | 2016-06-18T21:45:35Z | 38,053,084 | <p>This is a bit late but you could use base64 encoding for this problem:</p>
<pre><code>from base64 import b64encode
# in your view:
return render_template(..., pdf_output=b64encode(pdf_output))
</code></pre>
<p>And your template:</p>
<pre><code><embed src="data:application/pdf;base64,{{ pdf_output }}" type="ap... | 0 | 2016-06-27T11:43:19Z | [
"python",
"html",
"pdf",
"flask",
"reportlab"
] |
Python BeautifulSoup html5lib mix seems to be deleting every other item in for loop | 37,902,071 | <p>I'm new to python but am really enjoying the language so far.</p>
<p>I've been creating a bunch of complicated html5 elements and using the html5lib module.</p>
<p>When I go through elements in paragraph I can print them out fine but when I try and use bs4's insert method I get only get every other element output ... | 0 | 2016-06-18T22:08:12Z | 37,902,681 | <p>So after some experimenting I found that if I stored the elements I needed in a List and then retrieved them from the List instead of trying to edit the soup live it solved my problems.</p>
<p>Once I had the objects created and stored I could add them back into the parent element I'd previously created and inserted... | 0 | 2016-06-18T23:57:55Z | [
"python",
"beautifulsoup",
"html5lib"
] |
'ManyToManyDescriptor' object has no attribute 'add', why? | 37,902,128 | <p>So I refer to another model :</p>
<pre><code> subscriptions = models.ManyToManyField(Season)
</code></pre>
<p>So I use : </p>
<pre><code>@api_view(['POST'])
def buy_season(request):
_id = 1
season = Season.objects.get(id = _id)
a = ExtUser.subscriptions.add(season)
a.save()
return Response(... | 1 | 2016-06-18T22:16:29Z | 37,902,253 | <p>You should use an instance of the <code>ExtUser</code> model as you cannot add a model object directly to a class object.</p>
| 2 | 2016-06-18T22:35:21Z | [
"python",
"django"
] |
Python - applying concat function for two rows in pandas data frame | 37,902,189 | <p>I have a large data frame which is basically an image id and a set of biological features. I have to combine all the IDs(the GIDs) and the resulting features should be concatenation of all the rows with the same ID.</p>
<p>I do understand the solution will require use of <code>group_by</code> function with an apply... | 2 | 2016-06-18T22:24:56Z | 37,902,242 | <p>You can first cast to <code>string</code> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> by column <code>GID</code> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.aggregate.... | 2 | 2016-06-18T22:32:28Z | [
"python",
"pandas",
"dataframe"
] |
Amazon MWS Boto parsed XML missing values | 37,902,230 | <p>Boto 2.40, Python 3.5</p>
<p>When querying Amazon MWS <code>get_competitive_pricing_for_asin</code> some values that are present in the raw XML are missing once parsed by Boto.</p>
<p>The raw XML contains the number of offers for each condition in <code>NumberOfOfferListings</code></p>
<pre><code><CompetitiveP... | 0 | 2016-06-18T22:31:48Z | 38,023,211 | <p>This is the monkey patch I finally came up with:</p>
<pre><code>from boto.mws.response import CompetitivePricing, ElementList, ResponseElement, Element
class OfferListingCount(ResponseElement):
OfferCount = 0
def endElement(self, name, value, connection):
self.OfferCount = value
super(Offe... | 0 | 2016-06-24T22:57:53Z | [
"python",
"boto",
"amazon-mws",
"mws"
] |
Extracting keys and values from a dictionary in Python (in a thread-safe manner) | 37,902,325 | <p>I have a simple function for extracting keys and values from a dictionary. </p>
<pre><code>def separate_kv_fast(adict):
'''Separates keys/values from a dictionary to corresponding arrays'''
return adict.keys(), adict.values()
</code></pre>
<p>I know the order is guaranteed if the dictionary "adict" is not... | 1 | 2016-06-18T22:49:23Z | 37,903,638 | <p>I've been working on learning python disassembly, and I believe this shows the two calls are not atomic:</p>
<pre><code>>>> dis.dis(separate_kv_fast)
2 0 LOAD_FAST 0 (adict)
3 LOAD_ATTR ... | 1 | 2016-06-19T03:19:17Z | [
"python",
"dictionary",
"thread-safety"
] |
Requests: Module works locally but failed on pythonanywhere | 37,902,363 | <p>I am trying to make a twitter bot that uses requests library to get data from nytimes api.<br>
There is a line in the code</p>
<pre><code>resp = requests.get(API_ENDPOINT, my_params)
</code></pre>
<p>Now this works very well when I run it locally. So I uploaded it to pythonanywhere. The moment I tried to run it I ... | 2 | 2016-06-18T22:53:56Z | 37,902,409 | <p>You have <em>different <code>requests</code> versions installed on PythonAnywhere and locally.</em></p>
<hr>
<p>From what I see <code>requests</code> version installed on PythonAnywhere is <code>2.4.0</code>. At that point, you had to <a href="http://docs.python-requests.org/en/v2.4.3/api/?#requests.get" rel="nofo... | 2 | 2016-06-18T23:02:24Z | [
"python",
"python-requests",
"pythonanywhere"
] |
Requests: Module works locally but failed on pythonanywhere | 37,902,363 | <p>I am trying to make a twitter bot that uses requests library to get data from nytimes api.<br>
There is a line in the code</p>
<pre><code>resp = requests.get(API_ENDPOINT, my_params)
</code></pre>
<p>Now this works very well when I run it locally. So I uploaded it to pythonanywhere. The moment I tried to run it I ... | 2 | 2016-06-18T22:53:56Z | 37,902,421 | <p>You can do it like this:</p>
<pre><code>API_ENDPOINT = 'http://your_endpoint_url.com"
my_params = {'key1': 'value1', 'key2': 'value2'}
r = requests.get(API_ENDPOINT, params=my_params) # notice params is named named
</code></pre>
| 0 | 2016-06-18T23:04:44Z | [
"python",
"python-requests",
"pythonanywhere"
] |
Socket receiving in while 1 | 37,902,450 | <p>I'm trying to create socket connections in python. I need to listen to server until it sends a message, thus I need to use <code>while True</code>.
Client:</p>
<pre><code>import RPi.GPIO as GPIO
import time
import socket
GPIO.setmode(GPIO.BOARD)
pinLDR = 7
pinLED = 11
touch = False
sock = socket.socket()
sock.co... | 0 | 2016-06-18T23:08:48Z | 37,902,490 | <p><strong>UPDATE</strong>: The issue with the code in the question is that it has an infinite loop at the top. None of the code below this will ever execute:</p>
<pre><code>while True:
print sock.recv(256)
</code></pre>
<p>(And apparently this particular server doesn't send a message until it's received one firs... | 1 | 2016-06-18T23:17:31Z | [
"python",
"sockets",
"raspberry-pi"
] |
How do I use seaborns color_palette as a colormap in matplotlib? | 37,902,459 | <p>Seaborn offers a function called color_palette, which allows you to easily create new color_palettes for plots.</p>
<pre><code>colors = ["#67E568","#257F27","#08420D","#FFF000","#FFB62B","#E56124","#E53E30","#7F2353","#F911FF","#9F8CA6"]
color_palette = sns.color_palette(colors)
</code></pre>
<p>I want to transfo... | 7 | 2016-06-18T23:11:48Z | 37,902,765 | <p>You have to convert a list of colors from seaborn palette to color map of matplolib:</p>
<pre><code>import seaborn as sns
import matplotlib.pylab as plt
import numpy as np
from matplotlib.colors import ListedColormap
flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]
sns.set_palette(flatui... | 5 | 2016-06-19T00:15:54Z | [
"python",
"design",
"matplotlib",
"plot",
"seaborn"
] |
Unable to unbind a function using tkinter | 37,902,503 | <p>I am working with Tkinter in Python 3.5 and I encounter a weird problem.</p>
<p>I used the <a href="http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm" rel="nofollow">tkinterbook about events and bindings</a> to write this simple example:</p>
<pre><code>from tkinter import *
root = Tk()
frame = Frame(... | 1 | 2016-06-18T23:20:08Z | 37,902,699 | <p>The second argument to <code>unbind</code> is a 'funcid', not a function. <code>help(root.unbind)</code> returns</p>
<blockquote>
<p><code>unbind(sequence, funcid=None)</code> method of tkinter.Tk instance.
Unbind for this widget for event SEQUENCE the function identified with FUNCID.</p>
</blockquote>
<p>M... | 2 | 2016-06-19T00:01:08Z | [
"python",
"binding",
"tkinter",
"python-3.5"
] |
How to remove noise from a white region, without losing the shape of the white region | 37,902,509 | <p>Here's the image:</p>
<p><a href="http://i.stack.imgur.com/MRfMK.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/MRfMK.jpg" alt="enter image description here"></a></p>
<p>I want to remove the noise within the white region without losing the shape of the white region. I've tried dilation, but that effects th... | 1 | 2016-06-18T23:21:54Z | 37,904,237 | <p>If the black region is really as clean as this appears, you might want to try selecting the large black region, e.g. with flood-fill, and just setting the inverse to white.</p>
| -1 | 2016-06-19T05:31:32Z | [
"python",
"opencv",
"numpy",
"image-processing"
] |
How to remove noise from a white region, without losing the shape of the white region | 37,902,509 | <p>Here's the image:</p>
<p><a href="http://i.stack.imgur.com/MRfMK.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/MRfMK.jpg" alt="enter image description here"></a></p>
<p>I want to remove the noise within the white region without losing the shape of the white region. I've tried dilation, but that effects th... | 1 | 2016-06-18T23:21:54Z | 37,910,300 | <p>Your question is unclear about what counts as "noise". The dark stuff inside the oval doesn't look like pure noise to me.</p>
<p>Anyway:</p>
<p>You mentioned preserving the border edges. The go-to filter for removing impulsive noise from an image while preserving edges is the median filter.
Here's some python that... | 0 | 2016-06-19T18:10:47Z | [
"python",
"opencv",
"numpy",
"image-processing"
] |
Search Multiple Strings (from File) in a file and print the line | 37,902,523 | <p>Again apologies for been noob here: Trying below code for searching multiple strings read from keywords and search in <code>f</code> and printing the line.
It works if I have only one keyword but not if I have more then one.</p>
<pre><code>keywords = input("Please Enter keywords path as c:/example/ \n :")
keys = op... | 0 | 2016-06-18T23:24:54Z | 37,902,669 | <p>One of the challenges of looking for keywords is defining what you mean by keyword and how a file's contents should be parsed to find the full set of keywords. If "aa" is a keyword, should it match "aaa" or maybe ""aa()"? Can a keyword have numbers in it?</p>
<p>A simple solution is to say that keywords are alphabe... | 1 | 2016-06-18T23:55:11Z | [
"python",
"file",
"search",
"keyword"
] |
Search Multiple Strings (from File) in a file and print the line | 37,902,523 | <p>Again apologies for been noob here: Trying below code for searching multiple strings read from keywords and search in <code>f</code> and printing the line.
It works if I have only one keyword but not if I have more then one.</p>
<pre><code>keywords = input("Please Enter keywords path as c:/example/ \n :")
keys = op... | 0 | 2016-06-18T23:24:54Z | 37,908,279 | <pre><code>keywords = input("Please Enter keywords path as c:/example/ \n :")
keys = open((keywords), "r").readline()
keys = keys.split(',') # separates key strings
with open("c:/saad/saad.txt") as f:
for line in f:
for key in keys:
if key.strip() in line:
print(line)
</code></p... | 0 | 2016-06-19T14:27:24Z | [
"python",
"file",
"search",
"keyword"
] |
Python Code to get data at set time intervals | 37,902,595 | <p>I am curious if anyone knows how to get from <a href="http://www.fly.faa.gov/flyfaa/flyfaaindex.jsp?ARPT=SFO&p=0" rel="nofollow">http://www.fly.faa.gov/flyfaa/flyfaaindex.jsp?ARPT=SFO&p=0</a>
to get a result like this:
<a href="http://cdn.abclocal.go.com/three/kgo/weather/links/SFO_DELAYS.txt" rel="nofollo... | 0 | 2016-06-18T23:40:12Z | 37,912,633 | <p>If you mean to want to download the stuff from faa.gov as html, you might want to do this:</p>
<pre><code>wget -O x.html http://www.fly.faa.gov/flyfaa/flyfaaindex.jsp?ARPT=SFO&p=0
</code></pre>
<p>in order to process the x.html file with your python script to get some SFO_DELAYS.txt output file.</p>
<p>With y... | 0 | 2016-06-19T22:52:18Z | [
"python"
] |
Exclude certain indices from a KFold split in Python SKlearn | 37,902,713 | <p>I am using SKlearn KFold as follows: </p>
<pre><code> kf = KFold(10000, n_folds=5, shuffle=True, random_state=88)
</code></pre>
<p>However, I want to exclude certain indices from the training folds (only). How can this be achieved? Thanks. </p>
<p>I wonder if this can be achieved by using sklearn.cross_val... | 0 | 2016-06-19T00:05:04Z | 37,903,078 | <p>If you want to remove indices from the training set, but it is ok if they are in the testing set, then this approach will work:</p>
<pre><code>kf_list = list(kf)
</code></pre>
<p>This will return a list of tuples that can be iterated over in the same way as the KFold instance. You can then simply modify the indice... | 0 | 2016-06-19T01:12:05Z | [
"python",
"scikit-learn",
"cross-validation"
] |
python-writing q as a function of i in a for loop | 37,902,897 | <p>I'm completely new to python so forgive me if this question is stupid.I am try to code for a Fibonacci sequence and wanted to know if there is a way for me to write q as a function of i in a for loop.
like: </p>
<pre><code> for i in range (1,x):
q(i)=q(i-1)+q(i-2)
</code></pre>
| 1 | 2016-06-19T00:36:34Z | 37,902,918 | <h3>With lists</h3>
<p>Yes, you can do that:</p>
<pre><code>>>> x = 10
>>> q = 10*[1]
>>> for i in range(2,x):
... q[i] = q[i-1] + q[i-2]
...
>>> q
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
</code></pre>
<p>Notes:</p>
<ol>
<li><p>Subscripts in python are denoted with square bracket... | 1 | 2016-06-19T00:41:21Z | [
"python",
"for-loop"
] |
Pycharm out of memory error | 37,903,004 | <p>I have recently started to use pycharm but when I am running my code, it gives me out of memory error. I searched for increasing heap size in pycharm so i get recommendations to install Ant Window Tool from which I can increase the heap size. But when I searched in plugins there was no ant window available and i als... | -3 | 2016-06-19T00:54:43Z | 37,903,064 | <p>Tip of the Day: NEVER mess around with the computer's heap. That will cause loads of other problems. </p>
<p>The out of memory error you are receiving could be one of two things:</p>
<p><strong>Option 1</strong> - If you are getting a message from your operating system, your computer is actually out of memory (RAM... | 0 | 2016-06-19T01:08:35Z | [
"python",
"heap",
"pycharm"
] |
sprite goes thourgh my platform and gets stuck (pygame) | 37,903,104 | <p>When I try and jump on a platform, I clip through it. I have tried everything and my project is due on monday. Also this is my first stackoverflow question and I just recently started learning pygame and python. Thanks in advance </p>
<pre><code>import pygame
import sys
import time
pygame.init()
screenSize = (800,... | 1 | 2016-06-19T01:18:11Z | 37,903,326 | <p>Your collision resolution code doesn't work the way you intend because it modifies <code>PlayerRect</code> rather than <code>x</code> and <code>y</code>. <code>PlayerRect</code> gets recreated at the start of each pass through the main loop, so the changes from the collision don't persist. You need to modify <code>x... | 0 | 2016-06-19T02:08:09Z | [
"python",
"pygame"
] |
print statement in python, a space is written before the object is writen unless | 37,903,181 | <p><a href="https://docs.python.org/2/reference/simple_stmts.html#the-print-statement" rel="nofollow">From the docs</a>:</p>
<blockquote>
<p>A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no ch... | 0 | 2016-06-19T01:37:43Z | 37,903,252 | <p>They mean any <a href="https://en.wikipedia.org/wiki/Whitespace_character" rel="nofollow">whitespace character</a> other than the ASCII space character U+0020 SPACE (i.e. the character created when you press the space bar on a typical American keyboard). In particular, this includes the carriage return, line feed (... | 1 | 2016-06-19T01:52:08Z | [
"python"
] |
Proper install dependency by requirements.txt or how to properly install dependency which was edited | 37,903,223 | <p>I am using this dependency on my django site.</p>
<pre><code>https://bitbucket.org/tim_heap/django-bleach
</code></pre>
<p>Problem is on django 1.9 there is a fix, and the repository was forked to someone else.</p>
<p>This is the repository</p>
<pre><code>https://bitbucket.org/C14L/django-bleach.git
</code></pre... | 1 | 2016-06-19T01:45:43Z | 37,903,583 | <p>You can put repository urls in <code>requirements.txt</code> like so:</p>
<pre><code>git+https://bitbucket.org/C14L/django-bleach.git
</code></pre>
<p>or be more specific and specify the branch:</p>
<pre><code>git+https://bitbucket.org/C14L/django-bleach.git@django_1_9_fix
</code></pre>
<p><a href="https://pip.p... | 2 | 2016-06-19T03:07:47Z | [
"python",
"git",
"heroku",
"dependencies",
"pip"
] |
Python: Two functions, multiple arguments, cannot get the csv to print | 37,903,313 | <pre><code>def clean_age_data(age):
def make_csv_line(first,last,age):
return'%s, %s, %s' % first,last,age
##print (clean_age_data('9years'))##this works
print (make_csv_line('Jason','Young','20yearsold'))
</code></pre>
<p>So above are two functions that are supposed to print csv string that will have the age entr... | 0 | 2016-06-19T02:04:45Z | 37,903,368 | <p>It would be more helpful if you showed us precisely what troubles you are heaving, like error messages.</p>
<p>A quick scan of your source reveals at least one problem. I'm guessing you are getting <code>TypeError: not enough arguments for format string</code>:</p>
<pre><code>return'%s, %s, %s' % first,last,age
<... | 0 | 2016-06-19T02:16:17Z | [
"python",
"function"
] |
Is there a Python constant for Unicode whitespace? | 37,903,317 | <p>The <code>string</code> module contains a <code>whitespace</code> attribute, which is a string consisting of all the ASCII characters that are considered whitespace. Is there a corresponding constant that includes Unicode spaces too, such as the <a href="http://www.fileformat.info/info/unicode/char/00a0/index.htm">n... | 15 | 2016-06-19T02:05:25Z | 37,903,645 | <blockquote>
<h1>Is there a Python constant for Unicode whitespace?</h1>
</blockquote>
<p>Short answer: <strong>No.</strong> I have personally grepped for these characters (specifically, the numeric code points) in the Python code base, and such a constant is not there.</p>
<p>The sections below explains why it is ... | 9 | 2016-06-19T03:20:37Z | [
"python",
"c",
"string",
"unicode",
"whitespace"
] |
Is it possible for pandas use read_csv for several files | 37,903,327 | <p>Is it possible to use pandas read_csv function to read simultaneously several files each one into separate dataframe?</p>
| -1 | 2016-06-19T02:08:12Z | 37,903,352 | <p>Yes, use the <code>os</code> module to iterate over the file strings in the directory you are interested in (Assuming there are only csv files there) then add them to a list.</p>
<pre><code>import os
import pandas as pd
df_list = []
for i in os.listdir(os.getcwd() + "\\tempdata"):
df_list.append(pd.read_csv(i)... | 0 | 2016-06-19T02:13:32Z | [
"python",
"csv",
"pandas"
] |
How to drag objects around in a Gtk.Fixed widget using mouse events? | 37,903,355 | <p>I have a custom object(a small circle) placed at some point inside a Gtk.Fixed() widget .Is there a way to drag this object around using the mouse. I am not able to map the Mouse Press/Release/Motion events to make this work.</p>
<p>I would prefer solution in Python using PyGobject but any other language will do al... | 1 | 2016-06-19T02:13:57Z | 38,020,439 | <p>GtkFixed is not designed to do drawing work. It's made to locate widgets (such as buttons and such) on a fixed grid (á la Windows).</p>
<p>If you would like to move elements of a drawing, have a look at eg. GooCanvas. Each element on a goocanvas can have events connected, which can then be used to move it around. ... | 1 | 2016-06-24T19:04:45Z | [
"python",
"gtk3",
"pygobject"
] |
Python: Custom Exceptions with a embedded error handling routine? | 37,903,362 | <p>Is it a bad idea to implement my own exceptions with special error handling/logging system embedded? I wish to concentrate some of my error handling stuff in just one place. </p>
<p>For example:</p>
<p><b>errors.py</b></p>
<pre><code>class ReallyBadException(Exception):
def __init__(self, msg, error_handling)... | 0 | 2016-06-19T02:14:53Z | 37,903,503 | <p>Simply put, no this is not a bad idea at all. </p>
<p>In fact, the way I see it, what you're trying to do is ultimately reason why programming languages have exception handling in the first place.</p>
| 0 | 2016-06-19T02:45:53Z | [
"python"
] |
Can't figure out how to scrape data in body tag using beautiful soup (Python) | 37,903,378 | <pre><code>from bs4 import BeautifulSoup
import urllib
from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter
r = urllib.urlopen('https://www.vrbo.com/576329').read()
soup = BeautifulSoup(r)
rate = soup.find_all('body')
print rate
print type(soup)
</code></pre>
<p... | -1 | 2016-06-19T02:18:02Z | 37,903,467 | <p>You need to pick apart your result. It might be helpful to know that those things you seek are called <em>attributes</em> of a <em>tag</em> in HTML:</p>
<pre><code>body_tag = rate[0]
data_bedrooms = body_tag.attrs['data-bedrooms']
</code></pre>
<p>The code above assumes you only have one <code><body></code>... | 0 | 2016-06-19T02:36:50Z | [
"python",
"beautifulsoup"
] |
Can't figure out how to scrape data in body tag using beautiful soup (Python) | 37,903,378 | <pre><code>from bs4 import BeautifulSoup
import urllib
from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter
r = urllib.urlopen('https://www.vrbo.com/576329').read()
soup = BeautifulSoup(r)
rate = soup.find_all('body')
print rate
print type(soup)
</code></pre>
<p... | -1 | 2016-06-19T02:18:02Z | 37,903,628 | <p>To obtain the value of an attribute used rate [ 'attr'], example:
<code></p>
<pre><code>from bs4 import BeautifulSoup
import urllib
from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter
r = urllib.urlopen('https://www.vrbo.com/576329').read()
soup = BeautifulSo... | 1 | 2016-06-19T03:16:49Z | [
"python",
"beautifulsoup"
] |
Can't figure out how to scrape data in body tag using beautiful soup (Python) | 37,903,378 | <pre><code>from bs4 import BeautifulSoup
import urllib
from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter
r = urllib.urlopen('https://www.vrbo.com/576329').read()
soup = BeautifulSoup(r)
rate = soup.find_all('body')
print rate
print type(soup)
</code></pre>
<p... | -1 | 2016-06-19T02:18:02Z | 37,903,674 | <p>Not sure if you wanted <em>only</em> <code>data-bedrooms</code> from the <code>soup</code> object or not. I did some cursory checking of the output produce and was able to reason that the <code>data-*</code> items you mentioned were attributes, rather than tags. If doc structure is consistent, you could probably loc... | -1 | 2016-06-19T03:26:22Z | [
"python",
"beautifulsoup"
] |
How to change input | 37,903,437 | <p>How can I change my input or make my input ignore some characters like "-" or "|"?
I want to do this because I have a lot of inputs in my projects in different modules and classes.</p>
| 0 | 2016-06-19T02:32:22Z | 37,903,737 | <p>You can replace the character:
<code>
<code>cadena = cadena.replace("|", "")</code>
</code></p>
| 0 | 2016-06-19T03:43:40Z | [
"python",
"python-2.7",
"python-3.x"
] |
What is the most suitable way to recreate/reassign a class from within a method? | 37,903,446 | <p>Let's say that I have a class called School, which has a method called createSchool which will create a new instance of School and replace the existing instance (from which createSchool was called)...</p>
<p>The pseudo-code is below:</p>
<pre><code>class School(object):
def __init__(self,a=None,b=None):
... | 0 | 2016-06-19T02:33:16Z | 37,903,489 | <p>I think you can use @classmethod decorator</p>
<pre><code>class School(object):
def __init__(self,a=None,b=None):
self.a = a
self.b = b
@classmethod
def createSchool(cls,schoolFile):
schoolDict = parse(schoolFile)
newClass = School(**schoolDict)
return newClass
<... | 1 | 2016-06-19T02:43:03Z | [
"python",
"class"
] |
What is the most suitable way to recreate/reassign a class from within a method? | 37,903,446 | <p>Let's say that I have a class called School, which has a method called createSchool which will create a new instance of School and replace the existing instance (from which createSchool was called)...</p>
<p>The pseudo-code is below:</p>
<pre><code>class School(object):
def __init__(self,a=None,b=None):
... | 0 | 2016-06-19T02:33:16Z | 37,903,491 | <p>A far better approach is to <strong>not</strong> obliterate the calling instance. Instead, this should expressed as a classmethod</p>
<pre><code>class School(object):
def __init__(self,a=None,b=None):
self.a = a
self.b = b
@classmethod
def createSchool(cls, schoolFile):
# code ... | 1 | 2016-06-19T02:43:27Z | [
"python",
"class"
] |
Python Lambda Function Parsing DynamoDB's JSON Format | 37,903,479 | <p>Python Lambda function that gets invoked for a dynamodb stream has JSON that has DynamoDB format (contains the data types in JSON). I would like to covert DynamoDB JSON to standard JSON. PHP and nodejs have Marshaler that can do this. Please let me know if there are similar or other options for Python.</p>
<p>Dy... | 0 | 2016-06-19T02:40:32Z | 37,958,864 | <p>I couldn't find anything out in the wild. So, I decided to port the PHP implementation of dynamodb json to standard json that was published <a href="https://github.com/aws/aws-sdk-php/blob/master/src/DynamoDb/Marshaler.php" rel="nofollow">here</a>. I tested this in a python lambda function processing DynamoDB strea... | 0 | 2016-06-22T04:57:37Z | [
"python",
"json",
"amazon-web-services",
"lambda",
"amazon-dynamodb"
] |
PhantomJS with Selenium error: Message: 'phantomjs' executable needs to be in PATH | 37,903,536 | <p>I am attempting to run this script:</p>
<p><a href="https://github.com/Chillee/coursera-dl-all" rel="nofollow">https://github.com/Chillee/coursera-dl-all</a></p>
<p>However, the script fails at the line <code>session = webdriver.PhantomJS()</code> with the following error</p>
<pre><code>Traceback (most recent cal... | 2 | 2016-06-19T02:53:04Z | 37,904,430 | <p>you need to download the <a href="http://phantomjs.org/" rel="nofollow">DRIVER</a></p>
<p>after that <code>session = webdriver.PhantomJS("c:\driverPath")</code></p>
| 0 | 2016-06-19T06:03:57Z | [
"python",
"selenium",
"selenium-webdriver",
"phantomjs"
] |
IndexError: list index out of range I don't understand | 37,903,541 | <p>This program is supposed to take all numbers that are divisible by 3 and 5 and add them all together, but I dont understand, I try to run this script and it just keeps giving me the error:</p>
<pre><code>Traceback (most recent call last):
File "first.py", line 23, in <module>
main()
File "first.py", line 19, ... | 2 | 2016-06-19T02:53:47Z | 37,903,564 | <p>This entire block is assuming some length of <code>good</code> that isn't accurate.</p>
<pre><code>while count <= 1000:
merica = merica + good[count-1]
count = count+1
</code></pre>
<p>If you're only putting a <em>subset</em> of your numbers in there, the length can't be 1000.</p>
<p>Regardless... | 0 | 2016-06-19T03:02:48Z | [
"python",
"list",
"indexing"
] |
IndexError: list index out of range I don't understand | 37,903,541 | <p>This program is supposed to take all numbers that are divisible by 3 and 5 and add them all together, but I dont understand, I try to run this script and it just keeps giving me the error:</p>
<pre><code>Traceback (most recent call last):
File "first.py", line 23, in <module>
main()
File "first.py", line 19, ... | 2 | 2016-06-19T02:53:47Z | 37,903,576 | <p>you only append number to good when the count is multiple of 3 or 5 (not both).</p>
<p>So, the size of good won't be 1000.</p>
<p>That's why you are getting error.</p>
<p>your below loop will run only upto count <=466.</p>
<pre><code>def main():
merica = 0
commonfactors = []
good = []
count = ... | 0 | 2016-06-19T03:06:04Z | [
"python",
"list",
"indexing"
] |
IndexError: list index out of range I don't understand | 37,903,541 | <p>This program is supposed to take all numbers that are divisible by 3 and 5 and add them all together, but I dont understand, I try to run this script and it just keeps giving me the error:</p>
<pre><code>Traceback (most recent call last):
File "first.py", line 23, in <module>
main()
File "first.py", line 19, ... | 2 | 2016-06-19T02:53:47Z | 37,903,579 | <p>Since the error says the list index is out of range, let's consider how long the list is and what index we try to use. In here, theres the assumption that the list <code>good</code> has 1000 items in it because the while loop goes up to 1000.</p>
<pre><code>while count <= 1000:
merica = merica + good[cou... | 0 | 2016-06-19T03:06:41Z | [
"python",
"list",
"indexing"
] |
Accessing method variables of one class in another python class | 37,903,557 | <p>I have started learning Object Oriented concepts in python. I have got this sample code below:</p>
<pre><code> class Student(object):
def __init__(self, name, age):
self.name = name
self.age = age
class School(object):
students = []
def __init__(self, name):
self.name = name
def add_student(... | 0 | 2016-06-19T02:59:57Z | 37,903,595 | <p>in the method show_students there's a for loop :</p>
<pre><code>for s in self.students:
print("{0}: {1}".format(s.name, s.age))
</code></pre>
<p>it loops over the list of students added by method add so inside the loop the variable "s" represent an instance of student class so s.name is a legit way of accessin... | 0 | 2016-06-19T03:09:27Z | [
"python",
"python-2.7",
"python-3.x"
] |
Accessing method variables of one class in another python class | 37,903,557 | <p>I have started learning Object Oriented concepts in python. I have got this sample code below:</p>
<pre><code> class Student(object):
def __init__(self, name, age):
self.name = name
self.age = age
class School(object):
students = []
def __init__(self, name):
self.name = name
def add_student(... | 0 | 2016-06-19T02:59:57Z | 37,903,610 | <p>The students are added to <code>School.students</code> list via the <code>add_student</code> method. </p>
<pre><code>my_school.add_student(first_student)
my_school.add_student(second_student)
</code></pre>
<p>These two lines add two references to the <code>School.students</code> list in <code>my_school</code>. So ... | 0 | 2016-06-19T03:13:55Z | [
"python",
"python-2.7",
"python-3.x"
] |
Accessing method variables of one class in another python class | 37,903,557 | <p>I have started learning Object Oriented concepts in python. I have got this sample code below:</p>
<pre><code> class Student(object):
def __init__(self, name, age):
self.name = name
self.age = age
class School(object):
students = []
def __init__(self, name):
self.name = name
def add_student(... | 0 | 2016-06-19T02:59:57Z | 37,903,657 | <pre><code>first_student = Student("Rongan Li", 20)
second_student = Student("Jason Kane", 20)
</code></pre>
<p>These lines create object of student class ,first_student which has name 'Rongan Li' and age '20'. </p>
<p>second_student which has name 'Jason Kane' and age '20'</p>
<p>Now, you add these 2 objects to the... | 0 | 2016-06-19T03:22:28Z | [
"python",
"python-2.7",
"python-3.x"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.