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
listlengths
1
5
The def function I called doesn't implement
38,422,286
<p>So, I'm basically trying to make a program to calculate the mean of five numbers. I called a def function but it doesn't do anything. I run the project on cmd and just it sits there and makes another input line. Bam, no calculation, no anything. There doesn't seem to be a problem with the code because the compiler d...
-6
2016-07-17T14:27:28Z
38,422,471
<p>There are several errors here is a fix.</p> <pre><code>numberNumber1 = float(input("Please enter 1st number: ")) numberNumber2 = float(input("Please enter the 2nd number: ")) numberNumber3 = float(input("3rd please: ")) numberNumber4 = float(input("4th now: ")) numberNumber5 = float(input("5th finally: ")) def mea...
0
2016-07-17T14:46:01Z
[ "python", "function" ]
How to get nth permutation and vice versa given a charset
38,422,347
<p>If you have this character set:</p> <pre><code>abc </code></pre> <p>The permutations would be</p> <pre><code>0 = a 1 = b 2 = c 3 = aa 4 = ab 5 = ac 6 = ba 7 = bb 8 = bc 9 = ca 10 = cb 11 = cc </code></pre> <p>And so on and so forth. Is there a way in python to take n, a number representing which permutation it i...
-1
2016-07-17T14:33:27Z
38,423,153
<p>There may be more efficient ways to do this, but these functions do what you want. Doing the conversions with fixed length strings is easy enough; to handle these variable-length strings we just need to incorporate an offset that accounts for all the strings shorter than the current length. We can easily do that for...
3
2016-07-17T15:58:07Z
[ "python", "algorithm", "permutation", "itertools" ]
ImportError: cannot import name 'prefetch_relations'
38,422,368
<p>It seems I have an error while trying to run my local django server. Whenever I type "python manage.py runserver" this error pops up:</p> <pre><code>Unhandled exception in thread started by &lt;function check_errors.&lt;locals&gt;.wrapper at 0x042E7C48&gt; Traceback (most recent call last): File "C:\Pytho...
0
2016-07-17T14:35:13Z
38,423,625
<p>Solved it. </p> <p>For some reason I had to reinstall the django-notify-x package. </p> <p>Afterwards all worked just fine!</p>
0
2016-07-17T16:50:41Z
[ "python", "django" ]
Repetition in Python for each element of list
38,422,481
<p>I have a list <code>a = [3,7,4]</code></p> <p>I want to generate a list repetition of a sequence generated from each element of list like that:</p> <p><code>b = [1,1,1,2,2,2,2,2,2,2,3,3,3,3]</code></p>
-3
2016-07-17T14:46:47Z
38,422,544
<p>Try like this.</p> <pre><code>result = [] for i,j in enumerate(a): result += [i+1 for n in range(j)] </code></pre> <p><strong>Result</strong></p> <pre><code>[1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3] </code></pre>
-1
2016-07-17T14:52:51Z
[ "python", "list", "for-loop" ]
Repetition in Python for each element of list
38,422,481
<p>I have a list <code>a = [3,7,4]</code></p> <p>I want to generate a list repetition of a sequence generated from each element of list like that:</p> <p><code>b = [1,1,1,2,2,2,2,2,2,2,3,3,3,3]</code></p>
-3
2016-07-17T14:46:47Z
38,422,751
<p>input:</p> <pre><code>a = [3,7,4] b = [x for x in range(len(a)+1)[1::] for j in range(a[x-1])] </code></pre> <p>result:</p> <pre><code>[1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3] </code></pre>
-1
2016-07-17T15:17:26Z
[ "python", "list", "for-loop" ]
How can I set the sizes of nodes when using graphviz on python?
38,422,498
<p>I'm now using python 2.7 and graphviz to draw a cluster-like plot from my data set. Each cluster is represented in this type-->[avg, num] in which "avg" stands for the average value of points in this cluster and "num" stands for the number of points in this cluster</p> <p>I want to create a plot with each node has ...
0
2016-07-17T14:48:14Z
38,422,702
<p>You can set the sizes of the nodes as followed:</p> <pre><code>import graphviz as gv g = gv.Graph(format='png') for i in range(5): g.node(str(i), **{'width':str(i), 'height':str(i)}) g.render('example') </code></pre> <p>Which produce:</p> <p><a href="http://i.stack.imgur.com/nKyvA.png" rel="nofollow"><img src...
1
2016-07-17T15:12:09Z
[ "python", "plot", "graphviz" ]
Can't print a self-made matrix outside of its module
38,422,506
<p>I have 2 modules in my project:</p> <p>1- Ant.py</p> <pre><code>from threading import Thread from Ant_farm import Ant_farm ant_farm = Ant_farm(20, 20) class Ant(Thread): def __init__(self, x, y): global ant_farm Thread.__init__(self) self.x = x self.y = y ant_farm.mat...
0
2016-07-17T14:48:46Z
38,422,591
<p>As the error message says, you did not define what <code>ant_farm[i]</code> is (the function <code>__getitem__</code>). You probably want something like this in your <code>Ant_farm</code> class:</p> <pre><code>def __getitem__(i): return self.matrix[i] </code></pre>
0
2016-07-17T14:58:53Z
[ "python", "python-3.x" ]
In scrapy, 'start_urls' not defined when passed as an input argument
38,422,546
<p>The following spider with fixed <code>start_urls</code> works:</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor class NumberOfPagesSpider(CrawlSpider): name = "number_of_pages" allowed_domains = ["funda.nl"] # def __init__(self, ...
0
2016-07-17T14:53:08Z
38,422,576
<p>Your <code>le_maxpage</code> is a class level variable. When you pass the argument to <code>__init__</code>, you're creating an instance level variable <code>start_urls</code>. </p> <p>You used <code>start_urls</code> in <code>le_maxpage</code>, so for the <code>le_maxpage</code> variable to work, there needs to be...
2
2016-07-17T14:57:06Z
[ "python", "scrapy" ]
In scrapy, 'start_urls' not defined when passed as an input argument
38,422,546
<p>The following spider with fixed <code>start_urls</code> works:</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor class NumberOfPagesSpider(CrawlSpider): name = "number_of_pages" allowed_domains = ["funda.nl"] # def __init__(self, ...
0
2016-07-17T14:53:08Z
38,422,860
<p>Following masnun's answer, I managed to fix this. I list the updated code below for the sake of completeness.</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor class NumberOfPagesSpider(CrawlSpider): name = "number_of_pages" allowed_do...
1
2016-07-17T15:28:42Z
[ "python", "scrapy" ]
Entry in DATABASE using python
38,422,571
<p>I have a database named user and a table named Employee. Now I want a python program that can append the details of a user in the table(employee).</p> <p>for linux the code is:</p> <pre><code> mysql -u root -proot |&gt;use user; |&gt;show tables; |&gt;insert into Employee(name,age,salary) -&gt;values("jac...
0
2016-07-17T14:56:22Z
38,422,590
<p>You need to put placeholders into the query and then <em>parameterize</em> it properly:</p> <pre><code>sql = """ INSERT INTO employee (name, age, salary) VALUES (%s, %s, %s) """ y.execute(sql, (n, a, sal)) x.commit() </code></pre> <p>Also note how we take the advantage of a multi-l...
1
2016-07-17T14:58:51Z
[ "python", "mysql" ]
How can I feed .csv training data to a convolutional neural network in mxnet?
38,422,636
<p>I recently installed mxnet (python package) with GPU support on Windows 10 and Python 3.5. I run through a couple of examples and they seem to work fine.</p> <p>I am used to scikit-learn style machine learning packages and very new to Python deep learning packages such as Mxnet although I have already used Mxnet in...
0
2016-07-17T15:04:23Z
38,450,547
<p>The problems is in this line:</p> <pre><code>X_train = X_train.reshape((1200,28,28,1)) </code></pre> <p>In mxnet the second dimension is feature maps, while the third and fourth dimensions are width and height, so it should be:</p> <pre><code>X_train = X_train.reshape((1200,1,28,28)) </code></pre>
2
2016-07-19T05:55:11Z
[ "python", "csv", "deep-learning", "mxnet" ]
Web scraping data from an interactive chart that changes with cursor position on the screen
38,422,671
<p>I am trying to web scrape data from this url, <a href="http://poker.srv.ualberta.ca/preflop" rel="nofollow">http://poker.srv.ualberta.ca/preflop</a>. On the page you see an interactive table who only shows the preflop actions if you move your cursor over the different squares. I checked the source code and all the i...
1
2016-07-17T15:08:23Z
38,423,013
<p>I dont think you can do this using just lxml and requests. It is a d3 chart that you can probably scrape using a headless browser like phantomjs (to emulate the mouse mouvements). The data you are trying to get, though is available as javascript objects if you check the page source ( before the end ob body tag ). h...
1
2016-07-17T15:45:04Z
[ "python", "web-scraping", "lxml", "lxml.html" ]
Web scraping data from an interactive chart that changes with cursor position on the screen
38,422,671
<p>I am trying to web scrape data from this url, <a href="http://poker.srv.ualberta.ca/preflop" rel="nofollow">http://poker.srv.ualberta.ca/preflop</a>. On the page you see an interactive table who only shows the preflop actions if you move your cursor over the different squares. I checked the source code and all the i...
1
2016-07-17T15:08:23Z
38,423,211
<p>I have seen that there is no AJAX call to load that data behind graphs.</p> <p>Only way they can load that graph's data is from those JS files on their site.</p> <p>I suggest your to look over all the JS files and see how they are computing that values.</p> <p>Here are some of the JS files on their servers.</p> ...
0
2016-07-17T16:04:36Z
[ "python", "web-scraping", "lxml", "lxml.html" ]
Interrupt while loop with user input (controlling neopixels via arduino and python 2.7)
38,422,701
<p>I'm trying to control some neopixels connected to an arduino via python and am running into a problem. For the purposes of this demo, they light up when the arduino receives the "H" or "L" character via serial.</p> <p>My original script was:</p> <pre><code>import serial import time ser = serial.Serial('/dev/ttyA...
2
2016-07-17T15:12:07Z
39,259,562
<p>This is the solution I found myself. </p> <pre><code>import serial import time ser = serial.Serial('/dev/ttyACM0', 9600) #this is necessary because once it opens up the serial port arduino needs a second time.sleep(2) #ask for the initial choice choice= raw_input("1 or 2?") #keeps the loop running forever whil...
2
2016-08-31T21:51:39Z
[ "python", "python-2.7", "arduino", "pyserial" ]
Tensorflow error: "Tensor must be from the same graph as Tensor..."
38,422,764
<p>I am trying to train a simple binary logistic regression classifier using Tensorflow (version 0.9.0) in a very similar way to the <a href="https://www.tensorflow.org/versions/master/tutorials/wide/index.html" rel="nofollow">beginner's tutorial</a> and am encountering the following error when fitting the model:</p> ...
2
2016-07-17T15:18:29Z
39,400,592
<p>When you execute <code>model.fit</code>, the <code>LinearClassifier</code> is <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/estimators/estimator.py#L642" rel="nofollow">creating a separate <code>tf.Graph</code></a> based on the Ops contained in your <code>eval_in...
0
2016-09-08T21:36:47Z
[ "python", "python-2.7", "tensorflow" ]
AttributeError: 'QuerySet' object has no attribute 'related_stocks'
38,422,790
<p>Django newbie here. I'm trying to create a simple app to discuss stocks, where users can create topics and establish many-to-many relationship to specific stocks. In the topic-detail page, I would like to show all the stocks related to that topic. I'm running into a roadblock: AttributeError 'QuerySet' object has no...
0
2016-07-17T15:21:51Z
38,422,810
<p>You should user get instead of filter:</p> <pre><code>topic = Topic.objects.get(id=id, slug=slug) </code></pre> <p>filter returns array. get returns only one object and you need to handle object does not exist scenario.</p>
3
2016-07-17T15:23:49Z
[ "python", "django" ]
AttributeError: 'QuerySet' object has no attribute 'related_stocks'
38,422,790
<p>Django newbie here. I'm trying to create a simple app to discuss stocks, where users can create topics and establish many-to-many relationship to specific stocks. In the topic-detail page, I would like to show all the stocks related to that topic. I'm running into a roadblock: AttributeError 'QuerySet' object has no...
0
2016-07-17T15:21:51Z
38,422,818
<pre><code>topic = Topic.objects.all().filter(id=id, slug=slug) related_stocks = topic.related_stocks </code></pre> <p><code>filter</code> essentially returns a list of <code>Topic</code> models, so <code>topic</code> has no <code>related_stocks</code> attributes.</p> <p>Either:</p> <ol> <li><p>If you are sure <code...
0
2016-07-17T15:24:38Z
[ "python", "django" ]
correlation matrix of one dataframe with another
38,422,893
<p>I was reading through the answers to <a href="http://stackoverflow.com/questions/38422001/pandas-dataframe-corrwith-method">this question</a>. Then question came up on how to calculate the correlations of all columns from one dataframe with all columns from the other dataframe. Since it seemed this question wasn't...
1
2016-07-17T15:32:21Z
38,422,929
<p>One way to do it would be:</p> <pre><code>pd.concat([A, B], axis=1).corr().filter(B.columns).filter(A.columns, axis=0) </code></pre> <p><a href="http://i.stack.imgur.com/fq0DH.png" rel="nofollow"><img src="http://i.stack.imgur.com/fq0DH.png" alt="enter image description here"></a></p> <p>A more efficient way woul...
4
2016-07-17T15:35:16Z
[ "python", "numpy", "pandas" ]
Indexerror in Python for unknown reason
38,422,904
<p>I made connect 4, and Im trying to work out an algorithm to determine the winner. The one below determines the horizontal winner although for some reason an error occurs when the counters are positioned vertically like this. What causes this error and how do I fix it?</p> <p>board[5][5] == 1 (red chip)</p> <p>boar...
0
2016-07-17T15:33:13Z
38,423,068
<p>It seems like the dimensions of your board is mixed. The picture you posted gives the inserted chips inserted in a vertical order with changing y.</p> <pre><code>board[5][5] == 1 (red chip) board[4][5] == 1 (red chip) board[3][5] == 1 (red chip) # Like so </code></pre> <p>So your board layout should actually be ...
1
2016-07-17T15:49:34Z
[ "python", "python-3.x", "pygame" ]
scikits.talkbox: ImportError: No module named cffilter
38,422,945
<p>I'm trying to use the scikits.talkbox in python and I get the following error: </p> <pre><code>ImportError: No module named cffilter </code></pre> <p>I was looking for this file in the scikits.talkbox library and could only find 'cffilter.c' and 'cffilter.pyx' but not 'cffilter.py', it that the problem?</p>
0
2016-07-17T15:36:56Z
39,194,451
<p>I faced the same issue and resolved by installing <code>scikits.statsmodel</code></p> <pre><code>pip install scikits.statsmodels </code></pre> <p>Indeed <code>cffilter</code> is mentioned in <a href="https://scikits.appspot.com/statsmodels" rel="nofollow">https://scikits.appspot.com/statsmodels</a>.</p>
0
2016-08-28T18:25:10Z
[ "python", "scikit-learn", "scikits" ]
Why can't I change a set I'm iterating over?
38,422,997
<p>I've seen solutions and workaround suggested, but couldn't find an explanation of the choice not to allow changing sets while iterating over them. Can you please help me understand why this is OK</p> <pre><code>In [1]: l = [1] In [2]: for i in l: l.append(2*i) if len(l)&gt;10: ...
1
2016-07-17T15:43:04Z
38,423,040
<p>Forcing the implementation of a collection to allow changing while iterating will restrict it to have very bad performance. Think about linked list and the simple iterator that points to a node. Think about dynamic array that expands and needs to reallocate memory, (hash tables, that is the implementation of <code>d...
0
2016-07-17T15:47:26Z
[ "python" ]
Why can't I change a set I'm iterating over?
38,422,997
<p>I've seen solutions and workaround suggested, but couldn't find an explanation of the choice not to allow changing sets while iterating over them. Can you please help me understand why this is OK</p> <pre><code>In [1]: l = [1] In [2]: for i in l: l.append(2*i) if len(l)&gt;10: ...
1
2016-07-17T15:43:04Z
38,423,075
<p>A set is backed by a <em>hash table</em> (see <a href="https://stackoverflow.com/questions/15479928/why-is-the-order-in-python-dictionaries-and-sets-arbitrary">Why is the order in Python dictionaries and sets arbitrary?</a>). Entries in the set are slotted in to that table based on their hash, which in turn determin...
3
2016-07-17T15:50:23Z
[ "python" ]
Why can't I change a set I'm iterating over?
38,422,997
<p>I've seen solutions and workaround suggested, but couldn't find an explanation of the choice not to allow changing sets while iterating over them. Can you please help me understand why this is OK</p> <pre><code>In [1]: l = [1] In [2]: for i in l: l.append(2*i) if len(l)&gt;10: ...
1
2016-07-17T15:43:04Z
38,423,170
<p>First you need to understand a bit about <a href="http://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented">how <code>dicts</code> work</a>. <code>Sets</code> work the same way (in terms of storing keys) under the covers. I don't think I could ever explain this better than <a href=...
0
2016-07-17T15:59:47Z
[ "python" ]
"SyntaxError: EOL while scanning string literal " when i run python code to save data in sqlite
38,423,019
<p>I want to save data in sqlite database , the data is @function and size , block size and dump ( extracting and read @size bytes from @f &amp; return data ) this data are obtained by analysis of binary file. <a href="http://i.stack.imgur.com/DbuzP.png" rel="nofollow">Screenshot shwing the data </a></p> <pre><code> t...
0
2016-07-17T15:45:56Z
38,423,175
<p>You're missing a closing <code>"</code> also a closing <code>)</code> inside the string.</p> <p>Should be something like:</p> <pre><code>c.execute("INSERT INTO disas VALUES ('" + f.name + "', " + str(f.addr) + ", " + str(b.size) + ",'" + dump + "')") </code></pre> <p>It would be a lot easier to read your string i...
1
2016-07-17T16:00:18Z
[ "python", "sqlite" ]
Installing MySql for python 3.5.2
38,423,125
<p>I was trying to installed Mysql as i started off with Django, the methods I have followed:</p> <p>1)pip install MySQL-python</p> <p>error: Unable to find vcvarsall.bat( Does MSvisual studio needed?,I am not sure whether I have it or not maybe I got MSVS 2005)</p> <p>2)<a href="https://sourceforge.net/projects/mys...
0
2016-07-17T15:55:28Z
38,424,546
<p>MySQL-python package is for 2.* version </p> <p>it's been while but i think still there is no mysql connector for 3.5 </p> <p>your best option is to downgrade to python 3.4 and use mysql cli3ent </p> <pre><code>pip install mysqlclient </code></pre> <p>i havn't tested but <a href="http://stackoverflow.com/questio...
1
2016-07-17T18:25:45Z
[ "python", "mysql", "django", "pip" ]
Parallel fill of numpy 3d array with multiple image files
38,423,128
<p>I'd like to concurrently load multiple grayscale images from files on disk and put them inside a large numpy array in order to speed up loading time. Basic code looks like this:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt # prepare filenames image_files = ... mask_files = ... n_samples = len(...
1
2016-07-17T15:55:39Z
38,423,385
<p>You can try doing one for the images and one for the masks</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from threading import Thread # threading functions def readImg(image_files, mask_files): for sample, (img_path, mask_path) in enumerate(zip(image_files, mask_files)): all_images[...
1
2016-07-17T16:25:05Z
[ "python", "multithreading", "image", "numpy" ]
pandas Panel 'iterrows' (iterate through major axis)
38,423,240
<p>I have a <code>pandas</code> Panel that looks like this:</p> <pre><code>import pandas as pd import numpy as np P = pd.Panel(np.arange(90).reshape(5,6,3)) </code></pre> <p>I want to create an generator along the major axis, similar to <code>pd.DataFrame.iterrows</code>, so that at each call, <code>next</code> retur...
3
2016-07-17T16:08:23Z
38,423,281
<p>is that what you want?</p> <pre><code>In [176]: [i for i in P.iteritems()] Out[176]: [(0, 0 1 2 0 0 1 2 1 3 4 5 2 6 7 8 3 9 10 11 4 12 13 14 5 15 16 17), (1, 0 1 2 0 18 19 20 1 21 22 23 2 24 25 26 3 27 28 29 4 30 31 32 5 33 34 35)...
2
2016-07-17T16:14:09Z
[ "python", "pandas", "iterator" ]
pandas Panel 'iterrows' (iterate through major axis)
38,423,240
<p>I have a <code>pandas</code> Panel that looks like this:</p> <pre><code>import pandas as pd import numpy as np P = pd.Panel(np.arange(90).reshape(5,6,3)) </code></pre> <p>I want to create an generator along the major axis, similar to <code>pd.DataFrame.iterrows</code>, so that at each call, <code>next</code> retur...
3
2016-07-17T16:08:23Z
38,423,293
<p>I'd do this:</p> <pre><code>for m, df in P.to_frame().unstack().iterrows(): print m print df.unstack() </code></pre> <p>Better still:</p> <pre><code>for i, item in P.swapaxes(0, 1).iteritems(): print i print item </code></pre> <h3>Solution</h3> <pre><code>P.swapaxes(0, 1).iteritems() </code></pr...
3
2016-07-17T16:15:12Z
[ "python", "pandas", "iterator" ]
Syntax for an If statement using a boolean
38,423,360
<p>Hey guys i just recently joined the python3 HypeTrain! However i just wondered how you can use an if statement onto a boolean: Example: </p> <pre><code>RandomBool = True #and now how can i check this in an if statement? Like the following: if RandomBool == True: #DoYourThing </code></pre> <p>And also, can I j...
-3
2016-07-17T16:22:14Z
38,423,419
<p>You can change the value of a bool all you want. As for an if:</p> <pre><code>if randombool == True: </code></pre> <p>works, but you can also use:</p> <pre><code>if randombool: </code></pre> <p>If you want to test whether something is false you can use:</p> <pre><code>if randombool == False </code></pre> <p>bu...
3
2016-07-17T16:28:59Z
[ "python", "python-3.x", "if-statement", "boolean" ]
BoxLayout design
38,423,435
<p>This is my code:</p> <pre><code>layout = BoxLayout(orientation='horizontal') layout2 = BoxLayout(orientation='vertical') button1 = Button() button2 = Button() button3 = Button() button4 = Button() button5 = Button() button6 = Button() layout.add_widget(button1) layout.add_widg...
0
2016-07-17T16:30:46Z
38,423,537
<p>Its about the order you add the widgets.</p> <p>Change it to</p> <pre><code>layout = BoxLayout(orientation='horizontal') layout2 = BoxLayout(orientation='vertical') button1 = Button() button2 = Button() button3 = Button() button4 = Button() button5 = Button() button6 = Button() layout2.add_widget(button4) layout...
0
2016-07-17T16:41:52Z
[ "python", "kivy" ]
python3 - Create folder structure based on tree output
38,423,498
<p>Using Python I'm extracting the folder tree of Google Drive account, but I'm stuck on how I can create the folder structure locally using <code>os.makedirs</code></p> <p>The below function currently outputs the tree correctly (I use indent to inspect this). This is how the Google Drive account has its folder struct...
1
2016-07-17T16:37:20Z
38,428,326
<p>I've added a new parameter <code>folder_path</code> and I'm creating the folders using the <code>dest_path = folder_path + item['name']</code> line.</p> <p>This is the full code:</p> <pre><code>def tree_folder_contents(items_array, folder_id, folder_path, indent): for item in items_array: if item['pare...
0
2016-07-18T03:50:56Z
[ "python", "python-3.x", "google-drive-sdk" ]
Use BeautifulSoup to get texts without a tag
38,423,542
<p>I'm trying to get some text without tags using BeautifulSoup. I tried using <em>.string</em>, <em>.contents</em>, <em>.text</em>, <em>.find(text=True)</em>, and <em>.next_sibling</em>, and they are listed below.</p> <p><strong>Edit</strong> Nvmd I just noticed that <em>.next_sibling</em> works for me. Anyways this ...
1
2016-07-17T16:42:51Z
38,425,350
<p>Try this. It is still rough but at least it doesn't require you to manually parse the strings. </p> <pre><code>#get all non-empty strings from the backend. texts = [str.strip(x) for x in p.strings if str.strip(x) != ''] #get strings only with tags unwanted_text = [str.strip(x.text) for x in p.find_all()] #take th...
1
2016-07-17T19:52:36Z
[ "python", "beautifulsoup" ]
AttributeError: can't set attribute error in geometry_msgs/Pose in ROS
38,423,657
<p>I am trying to use <a href="http://docs.ros.org/jade/api/geometry_msgs/html/msg/Pose.html" rel="nofollow">geometry_msgs/Pose</a> in a ROS python package. But it is showing following error-</p> <pre><code>AttributeError: can't set attribute error </code></pre> <p>Below is the snippet from the code-</p> <pre><code>...
0
2016-07-17T16:54:03Z
38,523,976
<p>The <code>Position</code> and <code>Quaternion</code> of <code>geometry_msgs/Pose</code> in <em>ROS</em> use <a href="https://docs.python.org/2/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields" rel="nofollow"><code>collections.namedtuple</code></a> to store their values, so once an i...
1
2016-07-22T10:20:33Z
[ "python" ]
Select by index in pandas
38,423,665
<p>Have a dataframe in Pandas like this (id-index): </p> <pre><code> pa wat id 1000 12 1 1001 301 1 1002 0 0 </code></pre> <p>How can I get the values from 1001 index id. I've tried .loc-but doesnt work.</p>
-1
2016-07-17T16:55:01Z
38,423,693
<p>You can use <code>ix</code> or <code>loc</code> if need output as <code>Series</code>:</p> <pre><code>print (df.ix[1001]) pa 301 wat 1 Name: 1001, dtype: int64 print (df.loc[1001]) pa 301 wat 1 Name: 1001, dtype: int64 </code></pre> <p>And if need output <code>Dataframe</code> use double <code>[...
1
2016-07-17T16:56:52Z
[ "python", "pandas" ]
How to select a column location from each row if a condition match
38,423,676
<pre><code>import pandas as pd df = pd.DataFrame({Company : ['abc','def','ghi']} {"2010" : [0,100,230]} {"2011" : [120,0,300]} {"2012" : [130,240,0]}) </code></pre> <h1>Select the first cell from the columns where year bookings is greater than 0</h1> <pre><code>for column_name, column in df.transpose().iterrows(): ...
-1
2016-07-17T16:55:43Z
38,424,570
<p>I fixed your code under some assumption about the data provided as a dict and the company as a list. Feel free to swap years and company names. If doing so, you do not need to use the transpose of the DataFrame.</p> <p>See comments in code for further explanations:</p> <pre><code>import pandas as pd # sample data...
0
2016-07-17T18:28:44Z
[ "python", "pandas" ]
How to print more than one items in QListWidget if more than one items selected
38,423,791
<p>I have QListWidget and there are strings there, when I select a string, I wanted to display the index number and text of that. But the problem is, if I select more than 1 items, it doesn't display all of the indexes. It displays only one.</p> <pre><code>from PyQt5.QtWidgets import * import sys class Pencere(QWidge...
0
2016-07-17T17:08:47Z
38,423,858
<p>You need to use QListWidget's <code>selectedItems()</code> function, which returns a list. <code>currentRow()</code> only returns a single integer, and is intended to be used only in single-selection instances.</p> <p>Once you've got the list of QListWidgetItems, you can use the <code>text()</code> function on each...
0
2016-07-17T17:14:34Z
[ "python", "pyqt", "python-3.4", "pyqt5", "qlistwidget" ]
How to print more than one items in QListWidget if more than one items selected
38,423,791
<p>I have QListWidget and there are strings there, when I select a string, I wanted to display the index number and text of that. But the problem is, if I select more than 1 items, it doesn't display all of the indexes. It displays only one.</p> <pre><code>from PyQt5.QtWidgets import * import sys class Pencere(QWidge...
0
2016-07-17T17:08:47Z
38,424,033
<p>I solved it with this</p> <pre><code>def but(self): x = self.listwidget.selectedItems() for y in x: print (y.text()) </code></pre>
0
2016-07-17T17:31:03Z
[ "python", "pyqt", "python-3.4", "pyqt5", "qlistwidget" ]
CSV Writer Issue in Python
38,423,824
<p>My code is clearly messed up but several tries have led me nowhere. I created a custom dialect as such...</p> <pre><code>def wereofftoseesv(start_id, end_id): with open('nba_2015_16_pbp.csv', "w") as f: csv.register_dialect('scraper', delimiter="[", lineterminator = '', escapechar='', quoting=csv.QUOTE_...
0
2016-07-17T17:11:34Z
38,424,154
<p>So, per <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">pythons documentation on csv here</a>, the delimiter is a single character that separates data fields. First thing you want to do is to change <code>delimiter="[",</code> to <code>delimiter=",",</code>. Then change <code>writer.writerows</c...
1
2016-07-17T17:43:45Z
[ "python", "csv", "export-to-csv" ]
Not able to scrape data from using scrapy
38,423,841
<p>I had used various methods to scrape data from <a href="https://angel.co/companies?locations[]=India" rel="nofollow">angel.co</a></p> <p>but still unable to scrape data using every time getting an empty list </p> <p><code>results = self.driver.find_elements_by_css_selector(".results &gt; div") for result in result...
-1
2016-07-17T17:12:53Z
38,424,471
<p>You need to <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">wait</a> for search results to be loaded and only then extract them:</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait ...
0
2016-07-17T18:19:20Z
[ "python", "selenium", "xpath", "web-scraping", "scrapy" ]
Scrapy spider does not yield feed output after making 'start_urls' variable
38,423,844
<p>The following spider with fixed <code>start_urls</code> works:</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor from funda.items import FundaItem class PropertyLinksSimpleSpider(CrawlSpider): name = "property_links_simple" allowed_do...
1
2016-07-17T17:13:11Z
38,423,899
<p>This turned out to be a simple human error: in the second example, <code>start_urls[0]</code> was no longer the same. I added a <code>self.base_url</code> to make it the same again:</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor from funda.i...
1
2016-07-17T17:17:40Z
[ "python", "scrapy" ]
Django handling tag "multiple" from HTML5
38,423,878
<p>HTML5 allows uploading multiple files:</p> <pre><code>&lt;input type="file" class="form-control" name="images" multiple&gt; </code></pre> <p>I created an appropriate view in views.py, lets say:</p> <pre><code>def sending_email(request): ... email.send() </code></pre> <p>There is a function <em>attach</em...
0
2016-07-17T17:15:52Z
38,459,249
<p>@Svekar thank you! I just wanted to know, if I can treat variable as a list and then attach each element of it.</p>
0
2016-07-19T12:55:48Z
[ "python", "django", "html5" ]
How to share a dict among separate python processes?
38,423,926
<p>I have two separate python processes running on a linux server, p1 and p2, how to read a dict of p1 from p2 ? </p> <p>Two processes are independent, so I can't use multiprocessing based approach, and because of slow performance, I don't want to use socket communication or file based approach. my python version is ...
1
2016-07-17T17:19:56Z
38,423,989
<p>I think that the only way of doing that is using IPC. You can do that using sockets, PIPES. And for all these methods you have to serialise them with pickle or json. If the dictionary is big it can take several seconds.</p> <p>If you don't want to do that you should have some kind of shared memory. <code>Multiproc...
0
2016-07-17T17:27:21Z
[ "python", "python-3.x", "dictionary", "memory" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,484,222
<p>If you make your transform functions unified then you could do something like this:</p> <pre><code>import random slist = [] for i in range(0,100): slist.append(random.randint(0,1000)) # Unified functions which have the same function description # x is the value # i is the counter from enumerate def add(x, i): ...
3
2016-07-20T14:35:10Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,486,549
<p>First of all is the overall process that you make on your strings. You are taking some strings and to each of them you apply certain functions. Then you cleanup the list. Let's say for a while that all the functions you apply to strings works at a constant time (it's no true, but for now it won't matter). In your so...
6
2016-07-20T16:59:41Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,494,899
<p>You have a bunch of checks with which you can make an iterable:</p> <pre><code>def check1(s): if s.islower(): return s def check2(s): if len(s) &lt; 5: return s checks = [check1, check2] </code></pre> <p>And an iterable of strings:</p> <pre><code>l = ['dog', 'Cat', 'house', 'foo'] </code...
3
2016-07-21T04:30:47Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,501,576
<p>First off: I think your example code is not doing what you think. The result is <code>['the0', 'dog1', None, None, 'the4', 'fly5']</code>, but I believe you don't want the <code>None</code> values.</p> <p>The only reasonable answer to this is to measure your performance and identify the bottlenecks, which will prob...
2
2016-07-21T10:21:22Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,579,742
<p>I can see three optimizations you could possibly make. The first is that if all the words in "vocab" are less than or equal to five, you don't need to check if the words in "slist" are less than or equal to five, which means that you can remove that entire for loop. The second optimization is that if all the words i...
2
2016-07-26T01:23:59Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Simplifying / optimizing a chain of for-loops
38,424,004
<p>I have a chain of for-loops that works on an original list of strings and then gradually filtering the list as it goes down the chain, e.g.:</p> <pre><code>import re # Regex to check that a cap exist in string. pattern1 = re.compile(r'\d.*?[A-Z].*?[a-z]') vocab = ['dog', 'lazy', 'the', 'fly'] # Imagine it's a long...
16
2016-07-17T17:28:29Z
38,613,523
<p>Optimizations are much dependent on the specific code. Without knowing the what real manipulations run on strings and the nature of data, there is low chance for effective result. Moreover, OP specifically describe the string manipulations as "more complicated". This reduce the part of the outside loops in general p...
1
2016-07-27T12:51:22Z
[ "python", "dictionary", "filter", "nested-loops", "reduce" ]
Substitute regex match groups where match groups may overlap
38,424,029
<p>I am working in Python. I have a String that matches my regex and would like to substitute all the match groups (The end goal is to wrap each group in an HTML span).</p> <p>I know there are good ways to do this with the re module however I don't know if my case can be handled with that since I know some of my matc...
0
2016-07-17T17:30:49Z
38,424,612
<ol> <li>Create a list of indices where groups begin and end. You can use the <a href="https://docs.python.org/2/library/re.html#re.MatchObject.start" rel="nofollow"><code>.start([group])</code> and <code>.end([group])</code></a> functions for this. (Make sure you have some way of distinguishes group starts from group ...
1
2016-07-17T18:32:45Z
[ "python", "regex", "string" ]
Can someone convert this code
38,424,031
<p>Hey I have some code in C but at the same time I need that bit of code in python, is there a way i can convert <code>for(i = 0; i &lt; MAXFDS; i++)</code> to python i'v tried <code>for i in range(i = 0, MAXFDS = i++)</code> but that will not work please help.</p>
-7
2016-07-17T17:30:59Z
38,424,066
<p>Have you tried this? <code>for i in range(0, MAXDFS)</code></p>
1
2016-07-17T17:34:08Z
[ "python" ]
Can someone convert this code
38,424,031
<p>Hey I have some code in C but at the same time I need that bit of code in python, is there a way i can convert <code>for(i = 0; i &lt; MAXFDS; i++)</code> to python i'v tried <code>for i in range(i = 0, MAXFDS = i++)</code> but that will not work please help.</p>
-7
2016-07-17T17:30:59Z
38,424,069
<p>I would do :</p> <pre><code>for i in xrange(MAXFDS): pass </code></pre> <p>Edit:</p> <p>for python 3</p> <pre><code>for i in range(MAXFDS): pass </code></pre>
-1
2016-07-17T17:34:29Z
[ "python" ]
While loop when keyboard key is held
38,424,032
<p>My issue is rather simple. I want to run a loop while the user holds down a key, in my case <code>R</code>.</p> <p>The catch is: I don't <em>want</em> to use PyGame, and the console window will not be focused. (Selected)</p> <p><strong>Edit:</strong> I saw that this question was labeled a duplicate. I have checked...
1
2016-07-17T17:31:03Z
38,424,440
<p>In case you are using windows:</p> <p>msvcrt is probably the library you are looking for (<a href="https://docs.python.org/2/library/msvcrt.html" rel="nofollow">https://docs.python.org/2/library/msvcrt.html</a>). This lib contains the kbhit function, which 'Return true if a keypress is waiting to be read':</p> <pr...
0
2016-07-17T18:16:18Z
[ "python", "while-loop", "keyboard-events" ]
AttributeError: 'module' object has no attribute 'add_arg_scope'
38,424,041
<p>I am trying to use bleeding edge version of TFLearn (<a href="https://github.com/tflearn/tflearn" rel="nofollow">https://github.com/tflearn/tflearn</a>), a deep learning library. However on importing tflearn into python file, I encounter an attribute error, the stack trace of which is given. In case, anyone has succ...
1
2016-07-17T17:31:40Z
38,427,443
<p>Which version of TensorFlow are you using? It might be too old. Try update your TensorFlow version to 0.8 or 0.9, that should fix that issue.</p>
2
2016-07-18T01:23:14Z
[ "python", "python-2.7", "tensorflow", "deep-learning" ]
Turn function into a generator
38,424,046
<p>With the following method I'm able to list all files from my Google Drive Account:</p> <pre><code>def listAllFiles(self): result = []; page_token = None; while True: try: param = {"q" : "trashed=false", "orderBy": "createdTime"}; if page_token: param['pageToken'] = page_...
1
2016-07-17T17:32:13Z
38,424,113
<p>You're going to have to change the flow of your script. Instead of returning all the files at once, you're going to need to <code>yield</code> individual files. <strike>This will allow you to handle the fetching of results in the background as well.</strike> </p> <p>Edit: The fetching of subsequent results would be...
0
2016-07-17T17:39:54Z
[ "python", "generator" ]
Turn function into a generator
38,424,046
<p>With the following method I'm able to list all files from my Google Drive Account:</p> <pre><code>def listAllFiles(self): result = []; page_token = None; while True: try: param = {"q" : "trashed=false", "orderBy": "createdTime"}; if page_token: param['pageToken'] = page_...
1
2016-07-17T17:32:13Z
38,424,183
<p>You can rewrite your function to act as a generator by simply yielding single file paths.</p> <p>Untested:</p> <pre><code>def listAllFiles(self): result = [] page_token = None while True: try: param = {"q" : "trashed=false", "orderBy": "createdTime"} if page_token: ...
2
2016-07-17T17:47:56Z
[ "python", "generator" ]
Turn function into a generator
38,424,046
<p>With the following method I'm able to list all files from my Google Drive Account:</p> <pre><code>def listAllFiles(self): result = []; page_token = None; while True: try: param = {"q" : "trashed=false", "orderBy": "createdTime"}; if page_token: param['pageToken'] = page_...
1
2016-07-17T17:32:13Z
38,424,394
<p>If you yield each file at a time, you are blocking the generator. But if you yield the whole list that the generator has prepared, while you process the list of files, the generator will have another list ready for you:</p> <p>Instead of Michael's suggestion</p> <pre><code>for f in files["files"]: yield f </co...
1
2016-07-17T18:11:47Z
[ "python", "generator" ]
Unable to login to Github or Facebook or any such site using Python requests?
38,424,130
<p>I am using the following code:</p> <pre><code>import requests s = requests.session() login_data = dict(login='username', password='my_password') s.post('https://github.com/login/', data=login_data) r = s.get('https://github.com/') print(r.text) </code></pre> <p>The content printed is from the login page and not ...
0
2016-07-17T17:41:43Z
38,427,821
<p>The <code>requests</code> module isn't a web browser. Although you <em>can</em> do some pretty cool stuff with it there are situations where it isn't an appropriate tool.</p> <p>Many websites use security on their forms to reduce abuse. A popular strategy is to use a <a href="https://en.wikipedia.org/wiki/Cross-sit...
0
2016-07-18T02:30:11Z
[ "python", "facebook", "python-3.x", "github", "python-requests" ]
manage.py collectstatic: error: unrecognized arguments: --noinput in shell script launched by Docker
38,424,135
<p>I'm working to launch a django-tornado hybrid app in a Docker container from a shell script and and getting <code>--noinput</code> as an unrecognized argument for django commands:</p> <pre><code>usage: manage.py collectstatic [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--py...
5
2016-07-17T17:42:07Z
38,425,862
<p>Looks like my issue was line endings in the shell script. I think sh was feeding in <code>--noinput\R</code> into python, so it was presenting itself in the terminal as looking like <code>--noinput</code>, but really it was getting a <code>CR</code> character as well that it was matching against.</p> <p>When I was ...
5
2016-07-17T20:57:06Z
[ "python", "django", "docker" ]
scrapy Request not yielding any output
38,424,141
<p>I'm trying to adapt the "Following links" example in <a href="http://doc.scrapy.org/en/latest/intro/tutorial.html" rel="nofollow">http://doc.scrapy.org/en/latest/intro/tutorial.html</a> to my own spider:</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import Link...
1
2016-07-17T17:42:47Z
38,424,378
<p>You were not parsing the items to second function this code works fine for me.</p> <pre><code>import scrapy from scrapy.spiders import CrawlSpider, Rule from scrapy.linkextractors import LinkExtractor class FundaItem(scrapy.Item): url = scrapy.Field() title = scrapy.Field() class PropertyLinksSpider(Crawl...
1
2016-07-17T18:10:34Z
[ "python", "scrapy" ]
How to scrap the number of followers from a URL
38,424,151
<p>I have a list of artists in an excel file with the urls of all their social medias accounts (Facebook, Instagram, Soundcloud, Twitter and Youtube).Is there any fast way to scrap the number of followers for each account and report it in the excel file? I have more than 2000 artists so it will be very helpful if I cou...
-3
2016-07-17T17:43:28Z
38,424,266
<p>If </p> <ol> <li>You don't have previous expriences in making a spider.</li> <li>Some of these sites required login for viewing those number.</li> <li>You only have to do this for one-time.</li> </ol> <p>You may checkout <a href="http://selenium-python.readthedocs.io/getting-started.html#simple-usage" rel="nofollo...
0
2016-07-17T17:56:10Z
[ "python", "database", "excel", "web-scraping", "social-media" ]
Finding variables passed to jinja2 from sphinx
38,424,195
<p>I am trying to create a template in sphinx. My intention is not to use the basic template, but to build a new one from scratch. However there is very little (/no) documentation about what variables are passed from sphinx into the templates. </p> <p>I would like to dump all of the variables that are being passed to ...
0
2016-07-17T17:49:19Z
38,557,520
<p>The Sphinx documentation provides a <a href="http://www.sphinx-doc.org/en/stable/templating.html#global-variables" rel="nofollow">list of most variables</a> that are available in templates. You find additional variables - of which most are passed on by docutils - in <a href="https://github.com/sphinx-doc/sphinx/blob...
1
2016-07-24T22:36:41Z
[ "python", "jinja2", "python-sphinx" ]
Adding while loop to script causes errors on input
38,424,345
<p>I'm writing some code to play Hangman (Python 3.5.2). I wan't my code to run forever, e.g with <code>while 1 &lt; 2:</code>, but I start getting syntax errors on statements that work fine without the <code>while</code>. Here is my code:</p> <pre><code>with open('dictionary.txt') as f: words = f.read().splitlines(...
1
2016-07-17T18:05:45Z
38,424,379
<p>The problem occurs because you mask the built-in function <strong><a href="https://docs.python.org/3/library/functions.html#input" rel="nofollow"><code>input()</code></a></strong> with the assignment:</p> <pre><code>input = input('Input: ') </code></pre> <p>For one iteration, this will work just fine because you'r...
1
2016-07-17T18:10:35Z
[ "python", "python-3.x" ]
\B+ vs [\B]+ vs [^\b]+ in Python regex
38,424,355
<p>I ran across an issue I don't understand while answering an SO question. I've created a simplified example to illustrate the problem:</p> <p><strong>THE SCENARIO:</strong></p> <p>I'm testing that two tokens (not random English words!) are at least some distance apart in a string. In this example we have a list o...
2
2016-07-17T18:07:33Z
38,424,418
<ul> <li><code>\B+</code> causes an error because there's no point in repeating a boundary - one boundary is the same as two boundaries. It's more likely that you've done this by mistake, so the error makes sense.</li> <li><code>[\B]+</code> is something completely different. (Most) Escape sequences do not work inside ...
3
2016-07-17T18:13:57Z
[ "python", "regex" ]
\B+ vs [\B]+ vs [^\b]+ in Python regex
38,424,355
<p>I ran across an issue I don't understand while answering an SO question. I've created a simplified example to illustrate the problem:</p> <p><strong>THE SCENARIO:</strong></p> <p>I'm testing that two tokens (not random English words!) are at least some distance apart in a string. In this example we have a list o...
2
2016-07-17T18:07:33Z
38,424,693
<p>The <code>\B+</code> pattern causes nothing to repeat error that is a usual error when you try to <em>quantify a special regex operator that is a zero-width assertion</em>. Any of these - <code>(*</code>, <code>|*</code>, <code>\b+</code>, <code>\B+</code> - will cause this error. Repeating a zero-width assertion ma...
3
2016-07-17T18:41:25Z
[ "python", "regex" ]
Can someone explain this bitwise array-wrap-around expression?
38,424,400
<p>I've been researching on the Diamond-square algorithm and I came across <a href="http://www.bluh.org/code-the-diamond-square-algorithm/" rel="nofollow">this website</a> which pointed me to the source code of Notch's Minicraft, and does a conversion of the algorithm as was implemented by Notch.</p> <p>For the most p...
0
2016-07-17T18:12:13Z
38,424,674
<p><code>w</code> and <code>h</code> must be powers of 2 (and represent the local bounds for <code>x</code> and <code>y</code>, respectively). Then, <code>w-1</code> and <code>h-1</code> are sequences of ones. One for each bit of information which could possibly contribute to a value lower than <code>w</code> and <code...
1
2016-07-17T18:39:54Z
[ "python", "algorithm", "wrapping" ]
How is the for-loop able to use a variable that isn't defined yet
38,424,442
<p>I'm new to coding and I'm a little confused. How/why can a <code>for</code> loop use a variable that isn't defined yet?</p> <p>For example:</p> <pre><code>demond = {'green':'grass', 'red':'fire', 'yellow':'sun'} for i in demond: print(i) </code></pre> <p>Output:</p> <pre> green yellow red </pre>
-1
2016-07-17T18:16:33Z
38,424,455
<p>In python, you don't need to declare variables. In C/C++/JAVA etc. you will have to declare them first and then use them.</p> <p>Variables are nothing but reserved memory locations to store values.Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved m...
0
2016-07-17T18:17:49Z
[ "python", "python-2.7", "for-loop" ]
How is the for-loop able to use a variable that isn't defined yet
38,424,442
<p>I'm new to coding and I'm a little confused. How/why can a <code>for</code> loop use a variable that isn't defined yet?</p> <p>For example:</p> <pre><code>demond = {'green':'grass', 'red':'fire', 'yellow':'sun'} for i in demond: print(i) </code></pre> <p>Output:</p> <pre> green yellow red </pre>
-1
2016-07-17T18:16:33Z
38,483,873
<p>There are two things that you need to keep in mind:</p> <ol> <li><p>because Python is a weakly-typed language, you do not need to explicitly declare any variable to a certain object type. This is something you already know, and why you can assign things without having to state what type they will be.</p></li> <li><...
0
2016-07-20T14:20:50Z
[ "python", "python-2.7", "for-loop" ]
Django creating a user with wrong data freezes shell
38,424,454
<p>I have a user model,</p> <pre><code>class User(AbstractBaseUser, PermissionsMixin): name = models.CharField(max_length=30) email = models.EmailField(max_length=254, unique=True) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=False) date_joined = models.Da...
0
2016-07-17T18:17:44Z
38,429,207
<p>I could replicate the error with PyCharm's Django shell but not with Django shell on terminal. If you are using PyCharm, I guess the issue is with PyCharm's shell.</p>
0
2016-07-18T05:33:31Z
[ "python", "django", "django-models" ]
If Statement Syntax Error on Passed Parameter
38,424,549
<p>I am getting a Syntax Error on the <code>If</code> statement in the following code:</p> <pre><code>def ABC(faze): If faze == "d": print("Got a 'd'") Else: print("Didn't get a 'd'") def XYZ(): ABC("d") XYZ() </code></pre> <p>The <code>faze</code> parameter in the <code>If</code> statem...
-1
2016-07-17T18:26:00Z
38,424,718
<p>That's because Python has no <code>If</code> statements, only <code>if</code> statements. Capitalization matters. (Similarly, <code>Else</code> should be <code>else</code>.)</p> <p>The error occurs because it's reading <code>If</code> as the name of a variable, immediately followed by another variable (<code>faze</...
1
2016-07-17T18:44:42Z
[ "python" ]
If Statement Syntax Error on Passed Parameter
38,424,549
<p>I am getting a Syntax Error on the <code>If</code> statement in the following code:</p> <pre><code>def ABC(faze): If faze == "d": print("Got a 'd'") Else: print("Didn't get a 'd'") def XYZ(): ABC("d") XYZ() </code></pre> <p>The <code>faze</code> parameter in the <code>If</code> statem...
-1
2016-07-17T18:26:00Z
38,424,834
<p>The if-else keywords should be of small case.</p>
0
2016-07-17T18:55:54Z
[ "python" ]
Python unittesting and mock: mock function from the testcase?
38,424,633
<p>I'm attempting to test that a callback is called from a function in one of my packaged objects. However, mock.patch.object isn't allowing me to mock a function from the current testcase. Assuming I have the following (simplified) code and test:</p> <pre><code>import unittest from six.moves import cStringIO from moc...
0
2016-07-17T18:35:32Z
38,425,055
<p>I found my answer: Use patch.object as a context manager within the test call.</p>
0
2016-07-17T19:19:49Z
[ "python", "unit-testing", "mocking" ]
Python - import a module directory given full path
38,424,673
<p>I have a python module here <code>/root/python/foo.py</code>. I have a bunch of other modules here in the folder <code>/root/lib/</code> which looks like this</p> <pre><code> lib/ | ├─ module1/ | ├─ __init__.py    | └─ bar.py | └─ module2/ ├─ __init__.py ...
1
2016-07-17T18:39:27Z
38,424,806
<p><strong>try:</strong></p> <pre><code>from importlib.machinery import SourceFileLoader problem_module = SourceFileLoader('test_mod', '/root/lib/module1/__init__.py').load_module() </code></pre> <p>the <code>__init__.py</code> should take care about the modules in the same package:</p> <p>add <code>from . import ba...
0
2016-07-17T18:52:51Z
[ "python" ]
Python - import a module directory given full path
38,424,673
<p>I have a python module here <code>/root/python/foo.py</code>. I have a bunch of other modules here in the folder <code>/root/lib/</code> which looks like this</p> <pre><code> lib/ | ├─ module1/ | ├─ __init__.py    | └─ bar.py | └─ module2/ ├─ __init__.py ...
1
2016-07-17T18:39:27Z
38,425,083
<p>Python does not give us an easy way to load files that cannot be referenced by <code>sys.path</code>, most usual solution will do one of the following things:</p> <ol> <li>Add desired paths to <code>sys.path</code> or </li> <li>Restructure your modules so that the correct path is already on <code>sys.path</code></l...
1
2016-07-17T19:22:08Z
[ "python" ]
How to get pip3 to work on Linux
38,424,695
<p>I successfully installed Python 3.5.2 on my CentOS 6.5 system. I'm trying to get pip to work with this version of Python to be able to install some modules.</p> <p>When I run <code>$ pip3 install ...</code> it says command not found.</p> <p>I also tried to run:</p> <pre><code>$ sudo yum install python3-pip </code...
1
2016-07-17T18:41:29Z
38,424,809
<blockquote> <p>zipimport.ZipImportError: can't decompress data; zlib not available</p> </blockquote> <p>Then get ZLIB </p> <pre><code>yum install zlib-devel </code></pre> <blockquote> <p>pip 8.1.1 requires SSL/TLS</p> </blockquote> <p>Then get SSL... </p> <pre><code>yum install openssl-devel python3 -m ensur...
2
2016-07-17T18:53:11Z
[ "python", "linux", "python-3.x", "pip" ]
Types complex vs int
38,424,743
<pre><code>a = int(input("Please enter the value of a: ")) b = int(input("Please enter the value of b: ")) c = int(input("Please enter the value of c: ")) root_1 = (-b + ((b**2) - 4*a*c)**0.5) / 2*a root_2 = (-b - ((b**2) - 4*a*c)**0.5) / 2*a if root_1 &lt; 0 or root_2 &lt; 0: root = "No real roots" elif root_1 &...
-2
2016-07-17T18:46:41Z
38,424,762
<p>The hole problem is in the logic you are implementing to decide what is the result of the equation....</p> <p>You are assuming this is the term discriminating the roots in the <a href="https://en.wikipedia.org/wiki/Quadratic_equation" rel="nofollow">quadratic equation</a>: <strong>root_1</strong> and <strong>root...
0
2016-07-17T18:48:55Z
[ "python", "types", "int" ]
Loging and saving to csv
38,424,773
<p>I'm making login/signing section for my code. I have 2 issues with it. I need help:</p> <ol> <li><p>First question Yes or No functions well until other character entered. While loop is not accepted for some reason. How to get back to beginning until Y or N entered?</p></li> <li><p>I would like to store dict with us...
0
2016-07-17T18:49:42Z
38,425,790
<p>1) In your y/n while loop you are missing a tab to indent the print statement.</p> <p>2) <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a></p>
0
2016-07-17T20:46:01Z
[ "python", "login" ]
Loging and saving to csv
38,424,773
<p>I'm making login/signing section for my code. I have 2 issues with it. I need help:</p> <ol> <li><p>First question Yes or No functions well until other character entered. While loop is not accepted for some reason. How to get back to beginning until Y or N entered?</p></li> <li><p>I would like to store dict with us...
0
2016-07-17T18:49:42Z
38,425,800
<p>Some issues I see so far:</p> <ol> <li><p>Indentation. <code>print ("Please enter Y or N")</code> should be indented relative to the <code>while</code> statement on the previous line.</p> <p>Also, the statement <code>if createLogin in users</code> and the following <code>else</code> statement should probably be in...
0
2016-07-17T20:47:35Z
[ "python", "login" ]
How do you add : to a time formatted like this 203045 in python?
38,424,793
<p>I've been trying to get this time formatted value from 203045 to 20:40:45 in python. I clearly have no clue where to start. Any help will be appreciated! Thanks!</p>
1
2016-07-17T18:51:29Z
38,424,916
<p>Use <code>strptime</code> and <code>strftime</code> functions from <code>datetime</code>, the former constructs a datetime object from string and the latter format datetime object to string with specific format: </p> <pre><code>from datetime import datetime datetime.strptime("203045", "%H%M%S").strftime("%H:%M:%S")...
1
2016-07-17T19:04:10Z
[ "python", "formatting", "timestamp" ]
How do you add : to a time formatted like this 203045 in python?
38,424,793
<p>I've been trying to get this time formatted value from 203045 to 20:40:45 in python. I clearly have no clue where to start. Any help will be appreciated! Thanks!</p>
1
2016-07-17T18:51:29Z
38,425,235
<p>you can also play with the regular expression to get the same result :)</p> <pre><code>import re ch = "203045" print ":".join(re.findall('\d{2}',ch)) # '20:30:45' </code></pre>
1
2016-07-17T19:40:39Z
[ "python", "formatting", "timestamp" ]
How do you add : to a time formatted like this 203045 in python?
38,424,793
<p>I've been trying to get this time formatted value from 203045 to 20:40:45 in python. I clearly have no clue where to start. Any help will be appreciated! Thanks!</p>
1
2016-07-17T18:51:29Z
38,437,353
<p>try this to remove the two last digits if they are equal to zero :</p> <pre><code>import re ch = "20304500" print ":".join([e for e in re.findall('\d{2}',ch) if e!="00"]) # '20:30:45' </code></pre> <p>or whatever (the two last digits) :</p> <pre><code>import re ch = "20304500" print ":".join(re.findall('\d{2}',ch...
0
2016-07-18T12:59:05Z
[ "python", "formatting", "timestamp" ]
Handling input with back slashes in python 3
38,424,795
<p>I'm working with a file that contains some lines with backslash characters, such as "moz\\123\\". I have each line then stored in a dictionary and later compared to the original line in the file. The problem is that Python inputs into the dictionary a key with double the number of backslashes (instead of "moz\\123\\...
0
2016-07-17T18:51:48Z
38,425,949
<p>Or simply try to change "\\" to "//", where filepath contains :</p> <pre><code>the here moz//12//14 the/ </code></pre> <p>the code : </p> <pre><code>my_dict={} def reader(): inputfile= open('&lt;filepath&gt;', 'r') for line in inputfile: my_dict[line.strip()]=0 return my_dict print(reader()) </c...
0
2016-07-17T21:10:08Z
[ "python", "input", "io" ]
Access to imports made from separate files in python?
38,424,826
<p>So I'm making a modular program for a security system in python, but I can't access modules I've imported in main.py from other scripts.</p> <p>That is, say I have main.py that imports the random module. I use import camClass to import a script containing an object class from camClass.py in the same directory. When...
0
2016-07-17T18:55:20Z
38,424,845
<blockquote> <p>How do I overcome this error?</p> </blockquote> <p>Every file that wants to use a certain module has to import that module.</p> <blockquote> <p>If I have to reimport the module from within camClass.py,</p> </blockquote> <p>Yes, you do.</p> <blockquote> <p>where do I do it? In the init function...
0
2016-07-17T18:57:01Z
[ "python", "module", "modular" ]
Suds AttributeError: 'NoneType' object has no attribute 'param_defs'
38,424,878
<p>I need to use a SOAP service in python and I read about <b>suds</b> so I am using it but I can't move further.<br/></p> <p>I'm getting an error as soon as I'm creating a Client object. <br/> below is the code<br/></p> <pre><code>from suds.client import Client url = 'http://ebay.davismicro.com.cn:9888/api/wishery.p...
0
2016-07-17T19:00:41Z
38,429,525
<p>Seems like a bug in suds, give <a href="http://docs.python-zeep.org/" rel="nofollow">http://docs.python-zeep.org/</a> a try. It should work, for example:</p> <pre><code>&gt;&gt;&gt; from zeep import Client &gt;&gt;&gt; client = Client('http://ebay.davismicro.com.cn:9888/api/wishery.php?wsdl') &gt;&gt;&gt; client.se...
0
2016-07-18T06:03:02Z
[ "python", "soap", "suds" ]
PyQt: "AttributeError: 'PlayerWindow' object has no attribute 'exec_'" when opening second window
38,424,924
<p>I am coding a GUI using <code>PyQt5</code>. At some point I am trying to open secondary windows from the main window. My second windows are a class <code>PlayerWindow.PlayerWindow</code> inheriting from <code>QWidget</code>. The lines of code opening the windows are:</p> <pre><code>newWindow = PlayerWindow.PlayerWi...
0
2016-07-17T19:05:26Z
38,425,429
<p>Okay, I found my error. the window gets garbage collected if not stored as an attribute of the main window instance. So changing to:</p> <pre><code>self.newWindow = PlayerWindow.PlayerWindow( self.playerUrl) self.newWindow.show() </code></pre> <p>The <code>exec</code> line caused an exception forbidding the garbag...
0
2016-07-17T20:01:30Z
[ "python", "pyqt", "pyqt5" ]
sorting tuples in python
38,424,977
<p>I am trying to get the sorted output from following program.</p> <pre><code>"""Count words.""" # TODO: Count the number of occurences of each word in s # TODO: Sort the occurences in descending order (alphabetically in case of ties) # TODO: Return the top n words as a list of tuples from operator i...
2
2016-07-17T19:11:35Z
38,425,148
<p>You can change:</p> <pre><code>top_n=sorted(temp.items(), key=itemgetter(1,0),reverse=True) </code></pre> <p>To:</p> <pre><code>temp2=sorted(temp.items(), key=itemgetter(0),reverse=False) top_n=sorted(temp2.items(), key=itemgetter(1),reverse=True) </code></pre> <p>and thanks to the <a href="https://docs.python.o...
0
2016-07-17T19:30:30Z
[ "python", "sorting", "tuples" ]
sorting tuples in python
38,424,977
<p>I am trying to get the sorted output from following program.</p> <pre><code>"""Count words.""" # TODO: Count the number of occurences of each word in s # TODO: Sort the occurences in descending order (alphabetically in case of ties) # TODO: Return the top n words as a list of tuples from operator i...
2
2016-07-17T19:11:35Z
38,425,149
<p>You need to change the <code>key</code> function you're giving to <code>sorted</code>, since the items in your desired output need to be sorted in descending order by count but ascending order alphabetically. I'd use a <code>lambda</code> function:</p> <pre><code>top_n = sorted(temp.items(), key=lambda item: (-item...
3
2016-07-17T19:30:38Z
[ "python", "sorting", "tuples" ]
sorting tuples in python
38,424,977
<p>I am trying to get the sorted output from following program.</p> <pre><code>"""Count words.""" # TODO: Count the number of occurences of each word in s # TODO: Sort the occurences in descending order (alphabetically in case of ties) # TODO: Return the top n words as a list of tuples from operator i...
2
2016-07-17T19:11:35Z
38,425,151
<p>Instead of <code>itemgetter</code>, use <code>lambda t:(-t[1],t[0])</code> and drop the <code>reverse=True</code>:</p> <pre><code>top_n=sorted(temp.items(), key=lambda t:(-t[1],t[0])) </code></pre> <p>This returns the same thing as <code>itemgetter(1,0)</code> only with the first value inverted so that higher numb...
0
2016-07-17T19:31:02Z
[ "python", "sorting", "tuples" ]
sorting tuples in python
38,424,977
<p>I am trying to get the sorted output from following program.</p> <pre><code>"""Count words.""" # TODO: Count the number of occurences of each word in s # TODO: Sort the occurences in descending order (alphabetically in case of ties) # TODO: Return the top n words as a list of tuples from operator i...
2
2016-07-17T19:11:35Z
38,425,187
<pre><code>def count_words(s, n): """Return the n most frequently occuring words in s.""" t1=[] t2=[] temp={} top_n={} words=s.split() for word in words: if word not in temp: t1.append(word) temp[word]=1 else: temp[word]+=1 top_n=sorted(t...
0
2016-07-17T19:34:23Z
[ "python", "sorting", "tuples" ]
Python: saving in file big entries
38,425,309
<p>I want to save in a file (don't mind the type) some string informations about entries and objects. I can generate the string from my data and I know how to save a string in a .txt file. However, when I'm reading from the file, I'm reading "lines", so I'm assuming it reads a line till the first new line symbol. Howev...
0
2016-07-17T19:47:57Z
38,438,936
<p>You have a few options:</p> <h1>dump/load as JSON</h1> <pre><code>import tempfile import json text = 'this is my string with a \nnewline in it' with tempfile.TemporaryFile(mode='w+') as f: f.write(json.dumps([text])) f.flush() f.seek(0) lines = json.load(f) print(lines) </code></pre> <p>Down...
1
2016-07-18T14:11:37Z
[ "python", "python-2.7" ]
Splitting a data file in python or pandas
38,425,316
<p>Have a data file consisting of a string (no tabs and no spaces and no column names). First two columns are equivalent to one piece of data, third column is another and 4 thru 7 are something else, etc.</p> <p>How can I get these strings into a dataframe with named columns? All the answers I've seen assume that I ...
-2
2016-07-17T19:48:46Z
38,425,416
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_fwf.html" rel="nofollow">pd.read_fwf</a> with widths parameter. A file with these contents:</p> <pre><code>ieafxfrjzyxfxkymiwuy lqqmceegjnbjpxnidygr zssawojanxbrfwkgbvnl ahcwwhtayjwozzrgfftt </code></pre> <p>Becomes this:</p> <...
2
2016-07-17T19:59:28Z
[ "python", "pandas", "fixed-width" ]
How to generate dict in Python?
38,425,360
<p>I am a beginner in Python and i would like help: My little script:</p> <pre><code>def get_link(): #My datas dict = {} dict['Label1'] = 'URL1' dict['Label2'] = 'URL2' return [{'label': l, 'url': u} for l, u in dict.iteritems()] get_link() </code></pre> <p>So, the problem is at the end. How t...
-2
2016-07-17T19:54:03Z
38,425,397
<p><code>return</code> statement is valid only inside a function. Move your code into a function. Besides your code is broken anyway and is not very clear what yo intend to do.</p>
0
2016-07-17T19:57:27Z
[ "python" ]
How to generate dict in Python?
38,425,360
<p>I am a beginner in Python and i would like help: My little script:</p> <pre><code>def get_link(): #My datas dict = {} dict['Label1'] = 'URL1' dict['Label2'] = 'URL2' return [{'label': l, 'url': u} for l, u in dict.iteritems()] get_link() </code></pre> <p>So, the problem is at the end. How t...
-2
2016-07-17T19:54:03Z
38,425,435
<p>Delete the return statement unless you actually have a function </p> <p>Otherwise you can use dict-comprehension </p> <pre><code>a = {'label': label[i], 'uri': uri[i] for i in range(len(label)) } </code></pre> <p>Though, realistically, you should store the labels and urls together in a list from the start... </p>...
0
2016-07-17T20:01:59Z
[ "python" ]
How to generate dict in Python?
38,425,360
<p>I am a beginner in Python and i would like help: My little script:</p> <pre><code>def get_link(): #My datas dict = {} dict['Label1'] = 'URL1' dict['Label2'] = 'URL2' return [{'label': l, 'url': u} for l, u in dict.iteritems()] get_link() </code></pre> <p>So, the problem is at the end. How t...
-2
2016-07-17T19:54:03Z
38,425,496
<p>As far as I can see from your question, there is always an association between a label and a value. So I suggest to store both in a single dictionary and not spread the information in two independent structures:</p> <pre><code>dict = {} dict['Label1'] = 'URL1' dict['Label2'] = 'URL2' </code></pre> <p>And to output...
0
2016-07-17T20:09:22Z
[ "python" ]
How to generate dict in Python?
38,425,360
<p>I am a beginner in Python and i would like help: My little script:</p> <pre><code>def get_link(): #My datas dict = {} dict['Label1'] = 'URL1' dict['Label2'] = 'URL2' return [{'label': l, 'url': u} for l, u in dict.iteritems()] get_link() </code></pre> <p>So, the problem is at the end. How t...
-2
2016-07-17T19:54:03Z
38,425,567
<h1>hope this helps</h1> <pre><code>def urlAndLables(): label = {} uri = {} #My datas label[0] = 'Label1' uri[0] = 'URL1' label[1] = 'Label2' uri[1] = 'URL2' #Check if list is valid if(len(label) != len(uri)): print("Error label or uri missing") a=[] for i in range(...
1
2016-07-17T20:17:14Z
[ "python" ]
GDAL ReadAsArray() keeps returning None
38,425,399
<p>I can't stop the ReadAsArray() method from returning None. I don't understand why because I have written it in exactly the same was another script that works just fine.</p> <p>I want to point out early that I do have gdal.UseExceptions() enabled.</p> <p>This seems to be a someone common problem from searching but...
0
2016-07-17T19:57:32Z
38,425,856
<p>Well don't I feel stupid...</p> <p>The function is defined as:</p> <pre><code>def qa_mask(in_qa_band, in_cols, in_rows, in_geotransform, mask_tiff): </code></pre> <p>Whereas I called it as:</p> <pre><code>qa_mask(band, rows, cols, geotransform, 'D:\landsat_data\20160710_landsat8qa_test\cloudmask.TIF') </code></p...
1
2016-07-17T20:56:25Z
[ "python", "numpy", "gdal" ]
Automated filling of web form from a list in Python using Selenium
38,425,450
<p>This is the Selenium code in Python "sel.py" :-</p> <pre><code>from selenium import webdriver driver = webdriver.Chrome() driver.get('http://127.0.0.1:8000/employee/register/') employes = ['1', '2016-1-1', 'Tarun', 'Gupta', 'Male', '1995-12-7', 'Indian', 'Hinduism', 'General', 'O+', 'Single', '1122334455', 'dipl...
0
2016-07-17T20:04:01Z
38,434,935
<pre><code>from selenium import webdriver from selenium.webdriver.support.select import Select driver = webdriver.Chrome() driver.get('http://127.0.0.1:8000/employee/register/') employees = { 'id_ApplicationNo':'1', 'id_ApplyOn':'2016-1-1', 'id_FirstName':'Tarun', 'id_LastName':'Gupta', 'id_Gender':'M...
1
2016-07-18T10:56:41Z
[ "python", "django", "selenium", "selenium-webdriver", "selenium-chromedriver" ]
Automated filling of web form from a list in Python using Selenium
38,425,450
<p>This is the Selenium code in Python "sel.py" :-</p> <pre><code>from selenium import webdriver driver = webdriver.Chrome() driver.get('http://127.0.0.1:8000/employee/register/') employes = ['1', '2016-1-1', 'Tarun', 'Gupta', 'Male', '1995-12-7', 'Indian', 'Hinduism', 'General', 'O+', 'Single', '1122334455', 'dipl...
0
2016-07-17T20:04:01Z
38,437,374
<p>Here is the answer !</p> <p>The code opens the chrome then hit the url, fills the form ,submits the form, sleep for 3 secs and refresh the page .This continues till the database is populated with 10 employee data from list in the code.</p> <pre><code>from selenium import webdriver from selenium.webdriver.support.s...
1
2016-07-18T13:00:02Z
[ "python", "django", "selenium", "selenium-webdriver", "selenium-chromedriver" ]
Monitor a cluster of nodes
38,425,519
<p>I have > 10 nodes in a cluster. I have installed an Hadoop stack on the cluster using Cloudera (YARN, HBase, Hue, Hadoop FS, Spark, Flink). Is there an easy way to gather global statistics of all of the nodes (in terms of CPU usage, memory usage and network usage) and read it out with Python? The purpose of using Py...
5
2016-07-17T20:11:56Z
38,437,057
<p>I made a package myself: <a href="http://github.com/kevin91nl/isa" rel="nofollow">http://github.com/kevin91nl/isa</a></p> <p>A tutorial can be found on <a href="https://www.data-blogger.com/2016/07/18/monitoring-your-cluster-in-just-a-few-minutes/" rel="nofollow">https://www.data-blogger.com/2016/07/18/monitoring-y...
4
2016-07-18T12:43:29Z
[ "python", "hadoop", "statistics", "cluster-computing", "monitor" ]
Monitor a cluster of nodes
38,425,519
<p>I have > 10 nodes in a cluster. I have installed an Hadoop stack on the cluster using Cloudera (YARN, HBase, Hue, Hadoop FS, Spark, Flink). Is there an easy way to gather global statistics of all of the nodes (in terms of CPU usage, memory usage and network usage) and read it out with Python? The purpose of using Py...
5
2016-07-17T20:11:56Z
38,599,156
<p>I would suggest to consider using <strong>ansible</strong> for this purpose. Here's a simple <a href="http://docs.ansible.com/ansible/playbooks.html" rel="nofollow">playbook</a> that collects some data on hosts specified in <a href="http://docs.ansible.com/ansible/intro_inventory.html" rel="nofollow">inventory file...
1
2016-07-26T20:18:42Z
[ "python", "hadoop", "statistics", "cluster-computing", "monitor" ]
How to use class that is returned through a function?
38,425,634
<p>If I have a class that generates items for a text-based RPG like so -- keep in mind this is a simplified version of the code I use:</p> <pre><code>from random import choice, randint class Weapon(object): def __init__(self, name, value, damage): self.name = name self.value = value self.d...
0
2016-07-17T20:26:47Z
38,425,651
<p><code>generate()</code> returns a Weapon instance, which you can simply append to your inventory.</p> <pre><code>weapon = createweapon.generate() self.inventory['weapons'].append(weapon) </code></pre> <p>I must say though, I don't think CreateWeapon should be a class. Classes are for things - ie Weapons themselves...
3
2016-07-17T20:29:58Z
[ "python", "python-2.7" ]