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
Django 1.9 + Photologue: no such column
39,113,057
<p>I am using Django 1.9+ Photologue 3.x to build a photo gallery web app.</p> <p>When I am trying to add photo or gallery, it returns <code>'NO SUCH COLUMN EXCEPTION'</code></p> <pre><code>Request Method: GET Request URL: http://127.0.0.1:8000/admin/photologue/gallery/ Django Version: 1.9.5 Exception Type: Operat...
0
2016-08-24T01:27:26Z
39,113,591
<p>Although <code>syncdb</code> command has removed from Django 1.9</p> <p>There is <code>python manage.py migrate appname --run-syncdb</code> command.</p> <p>Which sync the model with the database.</p>
0
2016-08-24T02:44:34Z
[ "python", "django", "photologue" ]
Django 1.9 + Photologue: no such column
39,113,057
<p>I am using Django 1.9+ Photologue 3.x to build a photo gallery web app.</p> <p>When I am trying to add photo or gallery, it returns <code>'NO SUCH COLUMN EXCEPTION'</code></p> <pre><code>Request Method: GET Request URL: http://127.0.0.1:8000/admin/photologue/gallery/ Django Version: 1.9.5 Exception Type: Operat...
0
2016-08-24T01:27:26Z
39,129,174
<p>You say that the Django migration system - "python manage.py migrate" does not work. What happens? Do you get an error message?</p>
0
2016-08-24T17:02:22Z
[ "python", "django", "photologue" ]
Converting a dictionary into a square matrix
39,113,110
<p>I am wanting to learn how to convert a dictionary into a square matrix. From what I have read, I may need to convert this into a numpy array and then reshape it. I do not want to use reshape as I want to be able to do this based on information a user puts in. In other words, I want a code to give out a square matrix...
0
2016-08-24T01:34:06Z
39,113,347
<p>You may achieve this via generating a nested dictionary like:</p> <pre><code>{'Bob': {'Bob': .., 'Sarah': .., 'Ann': .., 'Jen':..} 'Sarah': {.. .. ..}, 'Ann': {.. .. ..}, 'Jen': {.. .. ..}, } </code></pre> <p>Below is the sample code:</p> <pre><code>&gt;&gt;&gt; my_dict = {'Bob VS Sarah': {'shepherd': 1...
0
2016-08-24T02:07:19Z
[ "python", "numpy", "dictionary", "matrix" ]
Converting a dictionary into a square matrix
39,113,110
<p>I am wanting to learn how to convert a dictionary into a square matrix. From what I have read, I may need to convert this into a numpy array and then reshape it. I do not want to use reshape as I want to be able to do this based on information a user puts in. In other words, I want a code to give out a square matrix...
0
2016-08-24T01:34:06Z
39,113,385
<p>If you can get your data in the format </p> <pre><code>{name1: {name1:data, name2:data, name3:data, ...}, name2: {name1:data, name2:data, name3:data, ...}, ... } </code></pre> <p>then you can just hand it to a pandas DataFrame and it will make it for you. The data at position <code>row = name1 and col = name2</...
2
2016-08-24T02:12:21Z
[ "python", "numpy", "dictionary", "matrix" ]
Concatenating two strings in a list of lists
39,113,122
<p>The title is a bit misleading as I'm not quite clever enough to come up with an appropriate header that describes exactly what I'm trying to accomplish, so I apologize for that. Hopefully I can compensate for this with the description below.</p> <p>I'm working on an exercise from a book that requires a bit of clean...
0
2016-08-24T01:35:30Z
39,113,171
<p>For your specific case, if it's always the platform that is potentially the issue, you could check if the list has too many items, and if so, combine the items on the 2nd and 3rd indices. If you need a broader solution though, please clarify in your problem.</p> <pre><code>NUM_ITEMS_PER_LIST = 5 lists = [ ['e72...
0
2016-08-24T01:45:12Z
[ "python", "python-3.x" ]
Concatenating two strings in a list of lists
39,113,122
<p>The title is a bit misleading as I'm not quite clever enough to come up with an appropriate header that describes exactly what I'm trying to accomplish, so I apologize for that. Hopefully I can compensate for this with the description below.</p> <p>I'm working on an exercise from a book that requires a bit of clean...
0
2016-08-24T01:35:30Z
39,113,190
<p>You could use a simple list comprehension:</p> <pre><code>&gt;&gt;&gt; data = [['e726fb69de83a3ec', 'General_Mobile', 'Android', 'unknown', '0'], ['1b8978f618d59eef', 'General_Mobile', 'iOS', 'unknown', '0'], ['8ee82ed6c2c5af59', 'General_Desktop', 'Windows', 'XP', 'male', '29'], ['d0fff09ca1829e65', 'General_Mobil...
2
2016-08-24T01:46:52Z
[ "python", "python-3.x" ]
Concatenating two strings in a list of lists
39,113,122
<p>The title is a bit misleading as I'm not quite clever enough to come up with an appropriate header that describes exactly what I'm trying to accomplish, so I apologize for that. Hopefully I can compensate for this with the description below.</p> <p>I'm working on an exercise from a book that requires a bit of clean...
0
2016-08-24T01:35:30Z
39,113,220
<p>Use <code>map</code>:</p> <pre><code>mylist = [['e726fb69de83a3ec', 'General_Mobile', 'Android', 'unknown', '0'], ['1b8978f618d59eef', 'General_Mobile', 'iOS', 'unknown', '0'], ['8ee82ed6c2c5af59', 'General_Desktop', 'Windows', 'XP', 'male', '29'], ['d0fff09ca1829e65', 'General_Mobile', 'Android', 'female', '48'], ...
0
2016-08-24T01:50:29Z
[ "python", "python-3.x" ]
How to print pass arguments to code object via exec and print in python?
39,113,137
<p>How to print pass arguments to code object via exec and print in python? Below are just few examples to see how things work in a generic case.</p> <pre><code>def foo(x, y): return x * y exec(foo.func_code {'x': 1, 'y': 5}) # This didn't work def bar(): return 3*5 exec(bar.func_code) # this got executed b...
1
2016-08-24T01:38:47Z
39,113,266
<p>I don't think you'll be able to pass arguments to a code object without using "black magic". Why not use <code>exec("print foo(1, 5)")</code>?</p> <p>In your both examples, nothing is printed because <code>exec</code> simply executes <code>xxx.func_code</code>, but function <code>foo</code> and <code>bar</code> con...
-1
2016-08-24T01:56:47Z
[ "python" ]
Seaborn kdeplot not plotting some data?
39,113,224
<p>I'm trying to get the <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.kdeplot.html" rel="nofollow">Seaborn kdeplot</a> example to work on my dataset. For some reason, one of my datasets isn't plotting at all, but the other seems to be plotting fine. To get a minimal working example, I have ...
0
2016-08-24T01:50:48Z
39,126,085
<p>I don't think gaussian KDE is a good fit for either of your datasets. You have one variable with discrete values and one variable where the large majority of values seem to be a constant. This is not well modeled by a bivariate gaussian distribution.</p> <p>As for what exactly is happening, without the full dataset...
0
2016-08-24T14:27:48Z
[ "python", "pandas", "matplotlib", "seaborn" ]
Infinite loop while adding two integers using bitwise operations in Python 3
39,113,479
<p>I am trying to solve a question which is about writing python code for adding two integers without the use of '+' or '-' operators. I have the following code which works perfectly for two positive numbers:</p> <pre><code>def getSum(self, a, b): while (a &amp; b): x = a &amp; b y = a ^ b ...
3
2016-08-24T02:27:39Z
39,113,614
<p>Python 3 has <a href="https://www.python.org/dev/peps/pep-0237/">arbitrary-precision integers ("bignums")</a>. This means that anytime <code>x</code> is negative, <code>x &lt;&lt; 1</code> will make <code>x</code> a negative number with twice the magnitude. Zeros shifting in from the right will just push the numbe...
5
2016-08-24T02:47:03Z
[ "python", "python-3.x", "bit-manipulation", "bitwise-operators" ]
Infinite loop while adding two integers using bitwise operations in Python 3
39,113,479
<p>I am trying to solve a question which is about writing python code for adding two integers without the use of '+' or '-' operators. I have the following code which works perfectly for two positive numbers:</p> <pre><code>def getSum(self, a, b): while (a &amp; b): x = a &amp; b y = a ^ b ...
3
2016-08-24T02:27:39Z
39,113,669
<p>I'm guessing that this is a homework question, so I don't want to just give you a function that works --- you'll learn more by struggling with it.</p> <p>The issue stems from the way that negative integers are stored. For illustration purposes, let's pretend that you're dealing with 4-bit signed integers (instead o...
1
2016-08-24T02:53:16Z
[ "python", "python-3.x", "bit-manipulation", "bitwise-operators" ]
TypeError: object of type 'bool' has no len() - Odoo v9
39,113,494
<p>I'm trying to connect to a webservice through an Odoov9 module.</p> <p>This is my class:</p> <pre><code>class invoice(models.Model): _inherit = "account.invoice" @api.multi def send_xml_file(self): # haciendolo para efacturadelsur solamente por ahora host = 'https://www.efacturadelsur.cl' post = '/ws/...
0
2016-08-24T02:29:26Z
39,114,224
<p>When you try to access <em>self.sii_xml_request.</em> First check it's value weather its empty or not. </p> <p>In your case, it returns an empty string which is <em>False</em>. To avoid this, try the following code:</p> <pre><code>_logger.info('len (como viene): %s' % (len(self.sii_xml_request) if self.sii_xml_req...
2
2016-08-24T04:02:08Z
[ "python", "openerp", "odoo-9" ]
Python 3.5: Exporting Chinese Characters
39,113,533
<p>I have been trying several times to export Chinese from list variables to csv or txt file and found problems with that. </p> <p>Specifically, I have already set the encoding as utf-8 or utf-16 when reading the data and writing them to the file. However, I noticed that I cannot do that when my Window 7’s base lang...
0
2016-08-24T02:35:46Z
39,114,483
<p>I just found that you need to do 2 things to achieve this:</p> <ol> <li>Change the Window's display language to Chinese.</li> <li>Use encoding UTF-16 in the writing process.</li> </ol>
0
2016-08-24T04:33:06Z
[ "python", "python-3.x", "character-encoding" ]
Python 3.5: Exporting Chinese Characters
39,113,533
<p>I have been trying several times to export Chinese from list variables to csv or txt file and found problems with that. </p> <p>Specifically, I have already set the encoding as utf-8 or utf-16 when reading the data and writing them to the file. However, I noticed that I cannot do that when my Window 7’s base lang...
0
2016-08-24T02:35:46Z
39,115,980
<p>Here's US Windows 10, running a Python IDE called PythonWin. There are no problems with Chinese.</p> <p><a href="http://i.stack.imgur.com/Szezw.png" rel="nofollow"><img src="http://i.stack.imgur.com/Szezw.png" alt="enter image description here"></a></p> <p>Here's the same program running in a Windows console. No...
0
2016-08-24T06:33:18Z
[ "python", "python-3.x", "character-encoding" ]
How to speed up simple loop in python
39,113,552
<p>I want to accelerate the speed of loop in python. There is a code below.</p> <pre><code>for x in dpath.util.search(self.data, "**", yielded=True): self.contentsList.append(x) </code></pre> <p>dpath.util.search is generator. how could I speed up this simple loop??</p>
-2
2016-08-24T02:38:16Z
39,113,572
<p>Well, the loop itself is unnecessary; you could let Python do the looping &amp; append work with a single function call instead of many calls with:</p> <pre><code>self.contentsList.extend(dpath.util.search(self.data, "**", yielded=True)) </code></pre>
2
2016-08-24T02:41:23Z
[ "python", "optimization" ]
Psycopg2 execute tuple index out of range
39,113,555
<p>I am very new to python and this is my first programming language. This is my first shot at using SQL as well as psycopg2. Any "dumb" advice is much appreciated!</p> <p>I am not sure what the problem is. My research tells me im feeding too few or too many arguments to the <code>cursor.execute(INSERT...</code> but i...
0
2016-08-24T02:38:37Z
39,113,804
<p>You have 8 parameters in the query but provided only 6 fields in the tuple. The code should be:</p> <pre><code>#Insert row data into DB table cursor.execute("""INSERT INTO arkonor (typeid, min, max, median, volume, average) VALUES (%s, %s, %s, %s, %s, %s)""", ('itemid', 'buymin', 'buymax', 'buymedian', 'b...
0
2016-08-24T03:11:53Z
[ "python", "postgresql", "psycopg2" ]
My answers are 5, 4, 3, 2,but when I run the code ,the answers are 5, 4.Why?
39,113,605
<pre><code>num = 5 if num &gt; 2: print(num) num -= 1 print(num) </code></pre> <p>Here are my thoughts:5>2,5,4; 4>2,4,3; 3>2,3,2; 2.So my answers are the 5, 4, 3, 2 but when I run the code,the answers are the 5 ,4. I really don't understand it.</p>
-5
2016-08-24T02:46:20Z
39,113,660
<p>use <code>while</code> instead of <code>if</code>.</p> <pre><code>&gt;&gt;&gt; num = 5 &gt;&gt;&gt; while num &gt; 2: ... print(num) ... num -= 1 # 5 # 4 # 3 &gt;&gt;&gt; print(num) # 2 </code></pre>
3
2016-08-24T02:52:02Z
[ "python", "python-3.x" ]
Tensorflow multi-variable logistic regression not working
39,113,871
<p>I am trying to create a program which will classify a point as either <code>1</code> or <code>0</code> using <a href="https://www.tensorflow.org/" rel="nofollow">Tensorflow</a>. I am trying to create an oval shape around the center of this plot, where the blue dots are:</p> <p>Everything in the oval should be class...
2
2016-08-24T03:20:13Z
39,120,655
<p>The problem occurs when you use <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/nn.html#softmax_cross_entropy_with_logits" rel="nofollow">softmax_cross_entropy_with_logits</a>. In your concrete case, both <code>logits</code> and <code>labels</code> should have shape <code>[batch_size, number_of_la...
1
2016-08-24T10:23:37Z
[ "python", "machine-learning", "tensorflow", "logistic-regression" ]
Python url encode/decode - Convert % escaped hexadecimal digits into string
39,113,885
<p>For example, if I have an encoded string as:</p> <pre><code>url='locality=Norwood&amp;address=138+The+Parade&amp;region=SA&amp;country=AU&amp;name=Pav%C3%A9+cafe&amp;postalCode=5067' </code></pre> <p>The name parameter has the characters %C3%A9 which actually implies the character é.</p> <p>Hence, I would like t...
0
2016-08-24T03:23:34Z
39,114,307
<p>This is actually due to the difference between <code>__repr__</code> and <code>__str__</code>. When printing a unicode string, <code>__str__</code> is used and results in the <code>é</code> you see when printing <code>new_url</code>. However, when a list or dict is printed, <code>__repr__</code> is used, which uses...
0
2016-08-24T04:13:18Z
[ "python", "python-2.6", "python-unicode" ]
How python interpreter determine the type of variable at runtime?
39,114,009
<p>I just want to know how python's <strong>(python 2.7)</strong> interpreter is find the type of variable. Like How python Dynamic Type Behaviour internally works. </p> <pre><code>MacBook-Pro:~ neelabhsingh$ python Python 2.7.12 (default, Jun 29 2016, 14:05:02) &gt;&gt;&gt; type(i) &lt;type 'int'&gt; &gt;&gt;&gt; typ...
3
2016-08-24T03:37:17Z
39,114,156
<p>In CPython 2.7 (i.e. the C language implementation of Python), there is a <a href="https://docs.python.org/2/c-api/structures.html#c.PyObject" rel="nofollow"><code>PyObject</code> type</a>. There is also a <a href="https://docs.python.org/2/c-api/object.html#c.PyObject_Type" rel="nofollow"><code>PyObject_Type</code>...
4
2016-08-24T03:55:10Z
[ "python" ]
Type Error Occured in python executed in visual studio
39,114,222
<p>i am running the below code to calculate current age in python using visual studio.</p> <p>but i am getting the below piece of error: Error:</p> <pre><code>Type Error Occured Unsupported operand Type for built_in_function or method </code></pre> <p>code:</p> <pre><code>import datetime def my_current_age(): ...
1
2016-08-24T04:01:49Z
39,114,273
<p>You are assigning a method of <code>datetime</code> to <code>today_date</code> with:</p> <pre><code>today_date=(datetime.date.today) </code></pre> <p>i.e, you are <em>calling</em> the function. Call it, instead:</p> <pre><code>today_date=(datetime.date.today()) </code></pre> <p>in order for it to work.</p> <p>A...
1
2016-08-24T04:09:25Z
[ "python", "python-3.x" ]
How to search phrases in a string in python
39,114,398
<p>I change my text file into a string. The string has been formatted to look like</p> <pre><code>{'AU': 'Smith, S’}, {'AU': 'James, A’}, {'AU': 'Stevens, P’} </code></pre> <p>I then used this code to try and find the number of times a name appears in the data. However, it returned the actual original string. I...
0
2016-08-24T04:23:31Z
39,114,824
<pre><code>searchfile = open('test', 'r') word = "test" lst = [] for line in searchfile: a = line.split() for x in a: if x == word: lst.append(x) print(lst) searchfile.close() </code></pre> <p>This took a little bit of research and testing, but it should do what you wanted :). So the line...
0
2016-08-24T05:07:20Z
[ "python", "file" ]
How to search phrases in a string in python
39,114,398
<p>I change my text file into a string. The string has been formatted to look like</p> <pre><code>{'AU': 'Smith, S’}, {'AU': 'James, A’}, {'AU': 'Stevens, P’} </code></pre> <p>I then used this code to try and find the number of times a name appears in the data. However, it returned the actual original string. I...
0
2016-08-24T04:23:31Z
39,115,009
<p>if you just want to count the number of times a particular name appears in your string, you can maintain a counter map against it. Something like</p> <pre><code>import sys def main(some_name): counter_map = {} for x in input_string.split(','): if some_name in x: count = counter_map.get(...
0
2016-08-24T05:23:06Z
[ "python", "file" ]
How to search phrases in a string in python
39,114,398
<p>I change my text file into a string. The string has been formatted to look like</p> <pre><code>{'AU': 'Smith, S’}, {'AU': 'James, A’}, {'AU': 'Stevens, P’} </code></pre> <p>I then used this code to try and find the number of times a name appears in the data. However, it returned the actual original string. I...
0
2016-08-24T04:23:31Z
39,115,053
<p>This should be what you need, assuming that the whole file is a string as you said. It searches for the <code>name</code> argument given and if found prints that <code>name</code> argument. Otherwise it prints <code>"not found"</code>:</p> <pre><code>file = "{'AU': 'Smith, S'},{'AU': 'James, A'},{'AU': 'Stevens, P'...
0
2016-08-24T05:26:09Z
[ "python", "file" ]
AUC calculation in decision tree in scikit-learn
39,114,463
<p>Using scikit-learn with Python 2.7 on Windows, what is wrong with my code to calculate AUC? Thanks.</p> <pre><code>from sklearn.datasets import load_iris from sklearn.cross_validation import cross_val_score from sklearn.tree import DecisionTreeClassifier clf = DecisionTreeClassifier(random_state=0) iris = load_iris...
0
2016-08-24T04:31:17Z
39,114,583
<p>The <code>roc_auc</code> in <code>sklearn</code> works only with binary class:</p> <p><a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html" rel="nofollow">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html</a></p> <p>One way to move around this issue...
1
2016-08-24T04:43:56Z
[ "python", "python-2.7", "machine-learning", "scikit-learn", "decision-tree" ]
Django Channels using django shell
39,114,502
<p>I'm currently am trying to use Celery to send sockets with django channels. However I found the same issue there as with using Django's shell, and was hoping if someone could enlighten me.</p> <p>I have it set up so that within views.py, when a user sends a POST request it will call </p> <pre><code>Group("chat"...
1
2016-08-24T04:35:16Z
39,311,008
<p>If you are using <code>In-Memory</code> Channel Layer then likely <code>it does not support cross-process communication.</code> So try with other channel layer types and you are good to go.</p>
1
2016-09-03T20:20:34Z
[ "python", "django", "django-celery", "django-channels" ]
For Loop on Plotly Python
39,114,575
<p>I am trying to replace</p> <pre><code>fig.append_trace(trace1, 1, 1) fig.append_trace(trace2, 2, 1) </code></pre> <p>with the for loop code</p> <pre><code>totalPlot = 2 x = ['trace%s'%(item + 1) for item in range(totalPlot)] y = [(item + 1) for item in range(totalPlot)] z = totalPlot * [1] for i, j, k in zip(x, ...
0
2016-08-24T04:43:09Z
39,114,901
<p>In this code it looks like <code>trace1</code> is some kind of array-like data structure:</p> <pre><code>trace1 = go.Scatter( x=[1, 2, 3], y=[4, 5, 6] ) </code></pre> <p>So I imagine that when you call <code>fig.append_trace(trace1, 1, 1)</code> it's adding an element to this array-like structure, the firs...
1
2016-08-24T05:14:19Z
[ "python", "for-loop", "plotly" ]
Python - Applying multiple conditions output in list comprehension
39,114,636
<p>I have been trying code an RGB to Hex function in Python when I faced a problem that I wasn't able to figure out how to do. Here is the function itself: <br></p> <pre><code>def rgb(r, g, b): return ''.join([format("{0:x}".format(x).rjust(2, "0").upper()) if int(x) &gt;= 0 else "00" if int(x) &lt;= 255 else "FF"...
0
2016-08-24T04:50:01Z
39,114,762
<p>You current <code>... if ... else ...</code> clause doesn't make much sense:</p> <pre><code>format("{0:x}".format(x).rjust(2, "0").upper()) if int(x) &gt;= 0 else "00" if int(x) &lt;= 255 else "FF" </code></pre> <p>means:</p> <ul> <li><code>format(...)</code> if <code>int(x) &gt;= 0</code></li> <li><p>else, if <c...
2
2016-08-24T05:01:31Z
[ "python", "if-statement", "list-comprehension", "multiple-conditions" ]
Python - Applying multiple conditions output in list comprehension
39,114,636
<p>I have been trying code an RGB to Hex function in Python when I faced a problem that I wasn't able to figure out how to do. Here is the function itself: <br></p> <pre><code>def rgb(r, g, b): return ''.join([format("{0:x}".format(x).rjust(2, "0").upper()) if int(x) &gt;= 0 else "00" if int(x) &lt;= 255 else "FF"...
0
2016-08-24T04:50:01Z
39,114,976
<p>Here's your current if-else statement, broken down into a function. It should be clear from this where the problem is.</p> <pre><code>def broken_if_statement(x): if int(x) &gt;= 0: # Print value as UPPERCASE hexadecimal. return format("{0:x}".format(x).rjust(2, "0").upper()) else if int(x) &...
-1
2016-08-24T05:20:05Z
[ "python", "if-statement", "list-comprehension", "multiple-conditions" ]
how can I get python's np.savetxt to save each iteration of a loop in a different column?
39,114,780
<p>This is an extremely basic code that does what I want... except with regard to the writing of the text file.</p> <pre><code>import numpy as np f = open("..\myfile.txt", 'w') tst = np.random.random(5) tst2 = tst/3 for i in range(3): for j in range(5): test = np.random.random(5)+j a = np.random.n...
0
2016-08-24T05:02:57Z
39,115,028
<p>So a run produces:</p> <pre><code>2218:~/mypy$ python3 stack39114780.py [ 4.13312217 4.34823388 4.92073836 4.6214074 4.07212495] [ 4.39911371 5.15256451 4.97868452 3.97355995 4.96236119] [ 3.82737975 4.54634489 3.99827574 4.44644041 3.54771411] 2218:~/mypy$ cat myfile.txt 4.13 4.35 4...
1
2016-08-24T05:23:54Z
[ "python", "python-2.7", "numpy", "for-loop" ]
Show user position on 2D maze - Python
39,114,784
<p>I have this task where I must print a maze that also provides the user's position. However this position can be dependent on the generated position from another function. What I mean is that the position can have many different possibilites. </p> <p>I tried to use slicing with a combination of the .replace method t...
0
2016-08-24T05:03:22Z
39,116,860
<p>It seems like you're making it harder than it need be. Rather than load the maze as one string, read it into an array. Do your <code>.strip()</code> one in load_maze rather than every call to <code>print-maze()</code>:</p> <pre><code>def load_maze(filename): """ Returns maze string from text file loa...
0
2016-08-24T07:21:55Z
[ "python", "string", "object-slicing" ]
Tensorflow TypeError: Fetch argument None has invalid type <type 'NoneType'>?
39,114,832
<p>I'm making a RNN loosely based off of tensorflow's <a href="https://www.tensorflow.org/versions/r0.10/tutorials/recurrent/index.html" rel="nofollow" title="tutorial">tutorial</a>. With the relevant parts of my model as follows ("Comment if you need to see more, I don't want to make this post too long xD):</p> <pre>...
0
2016-08-24T05:07:54Z
39,115,010
<p>You are re-assigning the <code>train_step</code> variable to the second element of the result of <code>sess.run()</code> (which happens to be <code>None</code>). Hence, on the second iteration, <code>train_step</code> is <code>None</code>, which leads to the error.</p> <p>The fix is fortunately simple:</p> <pre><c...
1
2016-08-24T05:23:06Z
[ "python", "artificial-intelligence", "tensorflow", "typeerror", "recurrent-neural-network" ]
Dictionary comprehension to calculate statistics across dict of dicts for each key in inner dicts
39,114,871
<p>I have a dictionary like this:</p> <pre><code>property2region2value = { 'countryA':{ 'a': 24, 'b': 56, 'c': 78 }, 'countryB':{ 'a': 3, 'b': 98 }, 'countryC':{ 'a': 121, 'b': 12121, 'c': 12989121, 'd':16171 }, 'countr...
1
2016-08-24T05:11:26Z
39,115,014
<p>You should use <code>pandas</code> for this task:</p> <h2>Edit</h2> <p>Pandas can help you accomplish what you want:</p> <pre><code>In [3]: pd.DataFrame(property2region2value) Out[3]: countryA countryB countryC countryD countryE countryF a 24.0 3.0 121 123.0 1011.0 1433 b ...
2
2016-08-24T05:23:17Z
[ "python", "loops", "numpy", "dictionary", "dictionary-comprehension" ]
Dictionary comprehension to calculate statistics across dict of dicts for each key in inner dicts
39,114,871
<p>I have a dictionary like this:</p> <pre><code>property2region2value = { 'countryA':{ 'a': 24, 'b': 56, 'c': 78 }, 'countryB':{ 'a': 3, 'b': 98 }, 'countryC':{ 'a': 121, 'b': 12121, 'c': 12989121, 'd':16171 }, 'countr...
1
2016-08-24T05:11:26Z
39,115,120
<p>Undoubtedly, <code>pandas</code> is a good choice for this task, while, in a plain python way, you can simply collect all values for each <strong>property</strong> in one loop.</p> <pre><code>from collections import defaultdict xs = defaultdict(list) for _, vs in property2region2value.items(): for k, v in vs....
2
2016-08-24T05:32:38Z
[ "python", "loops", "numpy", "dictionary", "dictionary-comprehension" ]
How to put pickle dict value into an object
39,114,897
<p>I am using pickle to dump a dictionary object into a txt file. I need to grab the dictionary from the file and extract only certain values and put them inside of an object as a string.</p> <p>My dictionary looks something like this:</p> <pre><code>obj_dict = { 'name': 'MYID', 'value': 'usdf23444', '...
0
2016-08-24T05:13:58Z
39,115,121
<p>After the update, it looks like it is a list of dicts. Try:</p> <pre><code>strings = ["VALUE{}={}".format(i, d['value']) for i, d in enumerate(obj_dict)] </code></pre>
1
2016-08-24T05:32:46Z
[ "python", "dictionary", "pickle" ]
train logistic regression model with different feature dimension in scikit learn
39,114,952
<p>Using Python 2.7 on Windows. Want to fit a logistic regression model using feature <code>T1</code> and <code>T2</code> for a classification problem, and target is <code>T3</code>.</p> <p>I show the values of <code>T1</code> and <code>T2</code>, as well as my code. The question is, since <code>T1</code> has dimensio...
0
2016-08-24T05:18:12Z
39,115,738
<p>It needs to concatenate the feature data matrices using numpy.concatenate.</p> <pre><code>import numpy as np from sklearn import linear_model, datasets arc = lambda r,c: r-c T1 = np.array([[arc(r,c) for c in xrange(4)] for r in xrange(5)]) T2 = np.array([[arc(r,c) for c in xrange(1)] for r in xrange(5)]) T3 = np.a...
1
2016-08-24T06:19:19Z
[ "python", "python-2.7", "machine-learning", "scikit-learn", "logistic-regression" ]
Export button is not visible with django-import-export package
39,114,969
<p>I am trying to use django-import-export module in my admin and here are my settings</p> <p><strong>admin.py</strong></p> <pre><code>from import_export.admin import ImportExportMixin, ImportMixin, ExportActionModelAdmin, ImportExportActionModelAdmin class RegistrationAdmin(ImportExportActionModelAdmin): list_d...
0
2016-08-24T05:19:32Z
39,116,457
<p>You need to use <a href="https://django-import-export.readthedocs.io/en/latest/api_admin.html#import_export.admin.ImportExportModelAdmin" rel="nofollow"><code>ImportExportModelAdmin</code></a></p> <p><a href="https://django-import-export.readthedocs.io/en/latest/api_admin.html#import_export.admin.ImportExportAction...
0
2016-08-24T07:00:44Z
[ "python", "django", "django-admin", "django-import-export" ]
Find and Edit Text File
39,114,980
<p>I'm looking to find if there is a way of automating this process. Basically I have 300,000 rows of data needed to download on a daily basis. There are a couple of rows that need to be edited before it can be uploaded to SQL.</p> <pre class="lang-none prettyprint-override"><code>Jordan || Michael | 23 | Bulls | Chic...
2
2016-08-24T05:20:39Z
39,115,224
<p>Python or vbscript could be used but they are overkill for something this simple. Try <code>sed</code>:</p> <pre><code>$ sed -E 's/(Jordan *)\|/\1/g; s/(Kobe *)\| *\|/\1/g' file Jordan | Michael | 23 | Bulls | Chicago Bryant | Kobe | 8 || LA </code></pre> <p>To save to a new file:</p> <pre><code>sed -E 's/(Jord...
2
2016-08-24T05:41:23Z
[ "python", "replace", "vbscript", "automation", "find" ]
Find and Edit Text File
39,114,980
<p>I'm looking to find if there is a way of automating this process. Basically I have 300,000 rows of data needed to download on a daily basis. There are a couple of rows that need to be edited before it can be uploaded to SQL.</p> <pre class="lang-none prettyprint-override"><code>Jordan || Michael | 23 | Bulls | Chic...
2
2016-08-24T05:20:39Z
39,115,460
<p>I wrote a code snippet in Python 3.5 as follows.</p> <pre><code># -*- coding: utf-8 -*- rows = ["Jordan||Michael|23|Bulls|Chicago", "Bryant|Kobe|||8||LA"] keywords = ["Jordan", "Kobe"] def get_keyword(row, keywords): for word in keywords: if word in row: return word el...
1
2016-08-24T06:00:00Z
[ "python", "replace", "vbscript", "automation", "find" ]
How to install module from another python installation
39,115,001
<p>I am using winpython. Now for simple distribution, I want to use winpython zero. Is it possible to install the package from winpython folder to winpython zero folder?</p>
0
2016-08-24T05:22:13Z
39,115,859
<p>One of the simplest ways is just copying the <code>site-package</code> directory in the original winpython to the new one (It is assumed that the versions of two winpythons are the same, saying python 3.5).</p> <p>If you thinks the above way is silly, then you can use <code>pip</code> instead.</p> <ol> <li><p>Extr...
1
2016-08-24T06:25:56Z
[ "python" ]
How to install module from another python installation
39,115,001
<p>I am using winpython. Now for simple distribution, I want to use winpython zero. Is it possible to install the package from winpython folder to winpython zero folder?</p>
0
2016-08-24T05:22:13Z
39,128,838
<p>In theory, a possible way would be to:</p> <ul> <li><p>download packages from <a href="https://sourceforge.net/projects/winpython/files/WinPython_Source/Do_It_Yourself/Winpython_2016-03/" rel="nofollow">https://sourceforge.net/projects/winpython/files/WinPython_Source/Do_It_Yourself/Winpython_2016-03/</a></p></li> ...
1
2016-08-24T16:42:25Z
[ "python" ]
How to resample a Numpy array of arbitrary dimensions?
39,115,166
<p>There is <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imresize.html" rel="nofollow"><code>scipy.misc.imresize</code></a> for resampling the first two dimensions of 3D arrays. It also supports bilinear interpolation. However, there does not seem to be an existing function for resizing all d...
1
2016-08-24T05:36:13Z
39,116,147
<p>You want <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.zoom.html#scipy.ndimage.zoom" rel="nofollow"><code>scipy.ndimage.zoom</code></a>, which can be used as follows:</p> <pre><code>&gt;&gt;&gt; x = np.arange(8, dtype=np.float_).reshape(2, 2, 2) &gt;&gt;&gt; scipy.ndimage.zoom(x, 1.5, ...
2
2016-08-24T06:43:58Z
[ "python", "numpy", "multidimensional-array", "image-resizing", "linear-interpolation" ]
Getting an error as var5 is undefined ? but it runs fine without class
39,115,227
<pre><code>class roger: root1 = Tk() frame1 = Frame(root1, width=100, height=100) frame1.pack(side=TOP) label5 = Label(frame1, text="x1=") label6 = Label(frame1, text="x2=") label7 = Label(frame1, text="x3=") label8 = Label(frame1, text="x4=") label5.grid(row=0) label6.grid(row=1) ...
0
2016-08-24T05:41:32Z
39,115,669
<p>Use <code>roger.var5</code> instead of <code>var5</code>, since you have defined it as class's static property. Similarly do for other variables.</p>
0
2016-08-24T06:14:51Z
[ "python", "tkinter" ]
Event when entry's xview changes
39,115,234
<p>I am creating a simple program using <code>Tkinter</code>. I want a function to be called every time <code>xview</code> property of <code>entry</code> changes. But there doesn't seem to be an event like this, at least not one that I can find.</p> <p>The <code>&lt;Configure&gt;</code> event fires only on resize, whi...
1
2016-08-24T05:42:27Z
39,123,953
<p>There is no mechanism for getting notified when the xview changes. There are ways to do it by modifying the underlying tcl code, but it's much more difficult than it's worth.</p> <p>A simple solution is to write a function that polls the xview every few hundred milliseconds. It can keep track of the most recent xvi...
1
2016-08-24T12:55:50Z
[ "python", "tkinter" ]
Python Code to create Google Project
39,115,311
<p>Is it possible to create a new Google Developer/Cloud project(for an existing Google Account) automatically using a python script ? </p> <p>If its possible, Can someone please redirect me to some helpful links/references ?</p> <p>Thanks,</p>
1
2016-08-24T05:48:24Z
39,128,497
<p>Is it possible?: Yes, using <a href="https://cloud.google.com/appengine/docs/admin-api" rel="nofollow">App Engine's Admin API</a> or the <a href="https://cloud.google.com/resource-manager/docs/apis" rel="nofollow">Cloud Resource Manager APIs</a> with although this functionality is currently in beta as of the time of...
3
2016-08-24T16:23:25Z
[ "python", "python-2.7", "google-app-engine", "google-cloud-platform" ]
Is there a way to access the properties of a class created in one function from another function?
39,115,578
<p>Is there a way to access the properties of a class created in one function from another function ?</p> <pre><code>class Component(object): Name = '' Num = 100 def __setattr__(self, name, value): object.__setattr__(self, name, value) def one(): exec('AAA' + '=Component()') AAA.Name = 'A...
-3
2016-08-24T06:09:13Z
39,115,776
<p>Class level attributes belong to the class and are therefore shared among all instances of that class.</p> <p>If you want different instances of the class to have different <code>name</code> and <code>num</code> attributes (by the way, you should be using lowercased attribute names for instances), you should add th...
0
2016-08-24T06:21:18Z
[ "python", "python-2.7", "function", "global" ]
Is there a way to access the properties of a class created in one function from another function?
39,115,578
<p>Is there a way to access the properties of a class created in one function from another function ?</p> <pre><code>class Component(object): Name = '' Num = 100 def __setattr__(self, name, value): object.__setattr__(self, name, value) def one(): exec('AAA' + '=Component()') AAA.Name = 'A...
-3
2016-08-24T06:09:13Z
39,115,829
<p><strong>One possible solution:</strong></p> <p>Create a global list(tuple, dict or any proper data structure you want) and add the instance to the list in function one, then get the instance from the list in function two. </p> <p>However, global variables are not recommended.</p>
0
2016-08-24T06:24:17Z
[ "python", "python-2.7", "function", "global" ]
Is there a way to access the properties of a class created in one function from another function?
39,115,578
<p>Is there a way to access the properties of a class created in one function from another function ?</p> <pre><code>class Component(object): Name = '' Num = 100 def __setattr__(self, name, value): object.__setattr__(self, name, value) def one(): exec('AAA' + '=Component()') AAA.Name = 'A...
-3
2016-08-24T06:09:13Z
39,116,023
<p>Instantiate <code>class</code> outside the <code>function</code> and use that class instance with in the function. Below is the code:</p> <pre><code>&gt;&gt;&gt; class Component(object): ... Name = '' ... Num = 100 ... def __setattr__(self, name, value): ... object.__setattr__(self, name, value)...
0
2016-08-24T06:36:12Z
[ "python", "python-2.7", "function", "global" ]
pycharm debugger not working properly
39,115,603
<p>I am doing simple python coding in pycharm but the problem is whenever I debug it starts debugging some other file in my project and not the one I am working with.</p> <p>I did go to run-->edit configuration and check if my file was set for debugging and it was but still it debugs another file when I start debuggin...
0
2016-08-24T06:10:42Z
39,115,848
<p>If you debug using pressing <code>SHIFT-F9</code> it debugs the last file you debugged, which might be some file you debugged yesterday...</p> <p>To debug a new file press <code>ALT-SHIF-F9</code>.</p> <p>You can see these two different debugging options from the <code>Run</code> menu. There is <code>Debug &lt;las...
0
2016-08-24T06:25:28Z
[ "python", "debugging", "pycharm" ]
pycharm debugger not working properly
39,115,603
<p>I am doing simple python coding in pycharm but the problem is whenever I debug it starts debugging some other file in my project and not the one I am working with.</p> <p>I did go to run-->edit configuration and check if my file was set for debugging and it was but still it debugs another file when I start debuggin...
0
2016-08-24T06:10:42Z
39,118,300
<p>I think you can do it with Right clicking on body of codes and select your project name form there. Also can select <code>Run</code> > <code>Debug</code> </p> <p>you can debug it line by line from <a href="http://stackoverflow.com/questions/28687771/how-to-debug-in-pycharm">here</a></p>
0
2016-08-24T08:35:09Z
[ "python", "debugging", "pycharm" ]
Django: Search Engine
39,115,743
<p>I am trying to make a search engine of sorts in Django, where the user enters a query via a form and gets an output if the query exists in the database. Here's my code:</p> <p>urls.py:</p> <pre><code>from django.conf.urls import url from django.contrib import admin from Search import views urlpatterns = [ url(r'...
0
2016-08-24T06:19:32Z
39,117,129
<p><code>form.is_valid()</code> must be called before accessing to <code>cleaned_data</code>.</p>
0
2016-08-24T07:36:03Z
[ "python", "django" ]
Call constructor of cls object in Python
39,116,035
<p>I am trying to call the constructor of a <code>class</code> object in python. I managed to get it to work using the following few lines:</p> <pre><code>obj = cls.__new__(cls) n = (List of attribute names) v = (List of attribute values) for s in n: setattr(obj, s, v[s]) </code></pre> <p>I was wondering if ther...
0
2016-08-24T06:36:58Z
39,116,117
<p><code>__init__</code> is the constructor of Python class instead of <code>__new__</code>. Refer <a href="http://stackoverflow.com/questions/674304/pythons-use-of-new-and-init">Pythons use of new and init</a> for more information.</p>
0
2016-08-24T06:41:30Z
[ "python" ]
Call constructor of cls object in Python
39,116,035
<p>I am trying to call the constructor of a <code>class</code> object in python. I managed to get it to work using the following few lines:</p> <pre><code>obj = cls.__new__(cls) n = (List of attribute names) v = (List of attribute values) for s in n: setattr(obj, s, v[s]) </code></pre> <p>I was wondering if ther...
0
2016-08-24T06:36:58Z
39,116,422
<p>To add, if you want to store arbitrary attributes to your class, you can use <code>dict.update</code> like so:</p> <pre><code>class BaseClass: def __init__(self, basic_attribute=1, **kw): self.basic_attribute = basic_attribute self.__dict__.update(**kw) class InheritingClass(BaseClass): de...
0
2016-08-24T06:58:57Z
[ "python" ]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 448: ordinal not in range(128)
39,116,122
<p>I am currently using selenium python to scrape linkedin data. I can parse through various webpages and scrape data but the process is interrupted after the first few pages due to the Unicode error. Here's my code:</p> <pre><code>from selenium import webdriver from time import sleep driver = webdriver.Firefox() dri...
1
2016-08-24T06:42:02Z
39,118,524
<p>You can use UnicodeWriter (from Python docs):</p> <pre><code>import codecs import cStringIO import csv from time import sleep from selenium import webdriver class UnicodeWriter: """ A CSV writer which will write rows to CSV file "f", which is encoded in the given encoding. """ def __init__(s...
0
2016-08-24T08:45:11Z
[ "python", "selenium", "unicode" ]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 448: ordinal not in range(128)
39,116,122
<p>I am currently using selenium python to scrape linkedin data. I can parse through various webpages and scrape data but the process is interrupted after the first few pages due to the Unicode error. Here's my code:</p> <pre><code>from selenium import webdriver from time import sleep driver = webdriver.Firefox() dri...
1
2016-08-24T06:42:02Z
39,119,326
<p>it is an improper encoding... you claim that a bytestream is encoded by UTF-8 and that is not true at the referred position according to the UTF-8 implementation only ascii character(0-127) is allowed, so the UTF-8 decoding fails... I do not see at your code how and when that UTF-8 decoding fails, so you should trac...
0
2016-08-24T09:23:20Z
[ "python", "selenium", "unicode" ]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 448: ordinal not in range(128)
39,116,122
<p>I am currently using selenium python to scrape linkedin data. I can parse through various webpages and scrape data but the process is interrupted after the first few pages due to the Unicode error. Here's my code:</p> <pre><code>from selenium import webdriver from time import sleep driver = webdriver.Firefox() dri...
1
2016-08-24T06:42:02Z
40,101,810
<pre><code>import sys reload(sys) sys.setdefaultencoding("utf-8") print sys.getdefaultencoding() </code></pre> <p>add it on the top of your code.</p> <p>also, u might need to preprocess your code to replace some nonenglish words</p> <pre><code> words=word_tokenize(content) # print words word=...
0
2016-10-18T07:13:03Z
[ "python", "selenium", "unicode" ]
ProtocolError IncompleteRead using requests
39,116,123
<p>I got this wierd error when I tried to download some images using <code>requests</code> with quite a brief code as follows,</p> <pre><code>import requests import StringIO r = requests.get(image_url, stream=True) if r.status_code == 200: r.raw.decode_content = True data = StringIO.StringIO(r.raw.data) #...
0
2016-08-24T06:42:03Z
39,116,450
<p>Since you are using <code>stream=True</code> you should iterate over the response and save the file in chunks:</p> <pre><code>with open('pic1.jpg', 'wb') as handle: response = requests.get(image_url, stream=True) if response.ok: for block in response.iter_content(1024): if not block: ...
1
2016-08-24T07:00:28Z
[ "python", "python-2.7", "http", "python-requests" ]
How to upload a file to Hug REST API
39,116,130
<p>I'm working on a basic Hug API and one of my functions needs a file.</p> <p>Does Hug have a way to upload a file? </p>
-1
2016-08-24T06:42:22Z
39,126,169
<p>I <em>think</em> it can. Looking at the <a href="https://github.com/timothycrosley/hug/blob/develop/hug/input_format.py" rel="nofollow">input_format.py</a> you should be able to extract a file encoded some codex (url, utf-8, etc). Looking at the github readme, there is this example:</p> <pre><code>@hug.default_inpu...
0
2016-08-24T14:31:14Z
[ "python", "python-3.x" ]
How can I apply decorator to a superclass method in a subclass?
39,116,151
<p>Say, we have the following situation,</p> <pre><code>class A(): def something(): ... ... ... class B(A): def use_something(): ... ... # Now, at this point I want something() to be decorated with a # decorator. But, since it is already defined in bas...
-1
2016-08-24T06:44:09Z
39,116,679
<p>Here you go (with params and without):</p> <pre><code>def simple_dec(func): def wrapped(*args, **kwargs): return 'No way' return wrapped def simple_dec_params(first_param, second_param): def dec(func): def wrapped(*args, **kwargs): return '{} {}'.format(first_param, second_...
0
2016-08-24T07:12:56Z
[ "python", "inheritance", "python-decorators" ]
How can I apply decorator to a superclass method in a subclass?
39,116,151
<p>Say, we have the following situation,</p> <pre><code>class A(): def something(): ... ... ... class B(A): def use_something(): ... ... # Now, at this point I want something() to be decorated with a # decorator. But, since it is already defined in bas...
-1
2016-08-24T06:44:09Z
39,116,856
<p>Any particular reason why you can't just override <code>something()</code>?</p> <pre><code>class A(): def something(self): ... class B(A): def use_something(self): ... self.something() ... def something(self): # Do "decorator" stuff super().something() ...
0
2016-08-24T07:21:41Z
[ "python", "inheritance", "python-decorators" ]
Custom printing in jupyter notebook
39,116,201
<p>I'm looking for an alternative to MathCad to make simple calculations but I wanted the expressions to look like if I was using pen and paper and make it easy to read for people who don't know programming. I tried Sweave, Knitr but I was unhappy with it. I recently found Jupyter notebook with SymPy and it's still not...
3
2016-08-24T06:46:46Z
39,117,457
<p>You can use sympy.printing.latex.</p> <p><a href="http://i.stack.imgur.com/4uUqU.png" rel="nofollow"><img src="http://i.stack.imgur.com/4uUqU.png" alt="SymPy using LaTeX printing"></a></p> <p>Refer to the following link for more information.</p> <p><a href="http://docs.sympy.org/dev/modules/printing.html?highligh...
0
2016-08-24T07:52:59Z
[ "python", "ipython", "sympy", "jupyter-notebook" ]
Custom printing in jupyter notebook
39,116,201
<p>I'm looking for an alternative to MathCad to make simple calculations but I wanted the expressions to look like if I was using pen and paper and make it easy to read for people who don't know programming. I tried Sweave, Knitr but I was unhappy with it. I recently found Jupyter notebook with SymPy and it's still not...
3
2016-08-24T06:46:46Z
39,123,380
<p>If you need a more convenient way, you can define a wrapper function as follows.</p> <pre><code>class Equation(object): def __init__(self, left, right, mode='latex'): self.mode = mode self.left = left self.right = right self._eq = sym.Eq(left, right) self._la...
3
2016-08-24T12:30:04Z
[ "python", "ipython", "sympy", "jupyter-notebook" ]
Custom printing in jupyter notebook
39,116,201
<p>I'm looking for an alternative to MathCad to make simple calculations but I wanted the expressions to look like if I was using pen and paper and make it easy to read for people who don't know programming. I tried Sweave, Knitr but I was unhappy with it. I recently found Jupyter notebook with SymPy and it's still not...
3
2016-08-24T06:46:46Z
39,128,587
<p>You need to use <code>sympy.Eq</code> if you want to print an equation. The <code>=</code> operator just assigns variables in Python, meaning in your example, the Python variable <code>R_r</code> is assigned to the SymPy expression <code>(c_1 + (c_2*x/G) + c_3*V)*G</code>. </p> <p>In general in Python, there is no ...
2
2016-08-24T16:28:26Z
[ "python", "ipython", "sympy", "jupyter-notebook" ]
how many loops to execute in nested generators
39,116,276
<p>I readed the famous article <a href="http://www.dabeaz.com/generators/" rel="nofollow">Generator Tricks for Systems Programmers</a> and very confused with nested generators (or you can call it generator pipeline ? ).so I have some questions about following code.</p> <pre><code>def field_map(dictseq, name, func): ...
-3
2016-08-24T06:50:42Z
39,116,337
<p><code>loglines</code> is traversed once. If it were traversed multiple times, it wouldn't work, as generators become exhausted after they are iterated over.</p>
0
2016-08-24T06:54:28Z
[ "python", "generator" ]
Python 3.5: Web-scraping with Stripping html codes
39,116,455
<p>I am scraping the web content but stuck with a problem. After a series of processing to strip the scope that I want, I cannot strip the html code to make it plain text in a list. I have tried using the function of replace, re.compile and join (try to change the list to text for stripping). All doesn't work as they a...
0
2016-08-24T07:00:36Z
39,116,696
<p>use <code>.text</code> to extract text from bs4 element</p> <pre><code>&gt;&gt;&gt; a = soup.find_all('p') &gt;&gt;&gt; data = [ item for item in a if 'Instructor' in item] [&lt;p class="course-d-title"&gt;Instructor&lt;/p&gt;] &gt;&gt;&gt; data[0].text 'Instructor' </code></pre>
1
2016-08-24T07:13:48Z
[ "python", "web-scraping" ]
Python 3.5: Web-scraping with Stripping html codes
39,116,455
<p>I am scraping the web content but stuck with a problem. After a series of processing to strip the scope that I want, I cannot strip the html code to make it plain text in a list. I have tried using the function of replace, re.compile and join (try to change the list to text for stripping). All doesn't work as they a...
0
2016-08-24T07:00:36Z
39,124,909
<p>If you want to take the Name of Instructor and Enquiries phone number also, below code can help you.</p> <pre><code> import requests from bs4 import BeautifulSoup url_text = 'http://www.scs.cuhk.edu.hk/en/part-time/accounting-and-finance/accounting-and-finance/fundamental-accounting/162-610441-01' resp = requests....
0
2016-08-24T13:37:47Z
[ "python", "web-scraping" ]
Python 3.5: Web-scraping with Stripping html codes
39,116,455
<p>I am scraping the web content but stuck with a problem. After a series of processing to strip the scope that I want, I cannot strip the html code to make it plain text in a list. I have tried using the function of replace, re.compile and join (try to change the list to text for stripping). All doesn't work as they a...
0
2016-08-24T07:00:36Z
39,136,160
<p>I found the following code, in a simpler and more flexible way, can achieve the same purposes but allow keyword search:</p> <pre><code>from bs4 import BeautifulSoup import requests url_text = 'http://www.scs.cuhk.edu.hk/en/part-time/accounting-and-finance/accounting-and-finance/fundamental-accounting/162-610441...
0
2016-08-25T03:18:13Z
[ "python", "web-scraping" ]
Group by of a Column and Sum Contents of another column with python
39,116,735
<p>I have a dataframe merged_df_energy:</p> <pre><code>merged_df_energy.head() ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 ACT_TIME_AERATEUR_1_F5 class_energy 63.333333 63.333333 63.333333 low 0 0 0 high 45.67 0 55.94 high 0 0 23.99 low 0 20 23.99 medium </code></pre> <p>I would like to create for each <code>ACT_T...
2
2016-08-24T07:16:01Z
39,116,796
<p>You can add all columns to <code>[]</code> for aggregating:</p> <pre><code>print (df.groupby(by=['class_energy'])['ACT_TIME_AERATEUR_1_F1', 'ACT_TIME_AERATEUR_1_F3','ACT_TIME_AERATEUR_1_F5'].sum()) ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 \ class_energy ...
2
2016-08-24T07:19:03Z
[ "python", "pandas", "dataframe", "group-by", "aggregate" ]
Plot average on subplots (pandas)
39,116,827
<p>I've managed to plot subplots from a groupby. I have two columns 'A', and 'B', which I want to plot on subplot (1 per value in 'B') with their respective averages. I prepare my data by counting, dropping the duplicates, and then summing it up (if there is a more elegant way to do it, please let me know!).</p> <pre>...
0
2016-08-24T07:20:30Z
39,118,463
<p>IIUC, you can use <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#aggregation" rel="nofollow"><code>agg</code></a> on the mean and count to compute averages and counts beforehand.</p> <pre><code>df_1 = df.groupby(['A', 'B'])['A'].agg({'counts': 'count'}).reset_index() df_2 = df.groupby('B')['A'].a...
0
2016-08-24T08:42:30Z
[ "python", "pandas", "matplotlib", "plot" ]
python2.7 histogram comparison - white background anomaly
39,116,877
<p>my program's purpose is to take 2 images and decide how similar they are. im not talking here about identical, but similarity. for example, if i take 2 screenshots of 2 different pages of the same website, their theme colors would probably be very similar and therefor i want the program to declare that they are simi...
0
2016-08-24T07:22:45Z
39,119,151
<p>You can remove the white color, rebin the histogra and then compare:</p> <ul> <li>Compute a histrogram with 256 bins.</li> <li>Remove the white bin (or make it zero).</li> <li>Regroup the bins to have 64 bins by adding the values of 4 consecutive bins. </li> <li>Perform the compareHist().</li> </ul> <p>This would...
0
2016-08-24T09:15:17Z
[ "python", "python-2.7", "opencv", "image-processing", "histogram" ]
Iterate a pymongo cursor from MLab
39,116,919
<p>Why won't the cursor iterate? I feel sure there <em>should</em> be an easy solution.</p> <p>I have tried multiple Stack Overflow answers and the documentation for Mongodb <a href="https://docs.mongodb.com/getting-started/python/query/" rel="nofollow">https://docs.mongodb.com/getting-started/python/query/</a></p> <...
1
2016-08-24T07:25:13Z
39,117,013
<p>This may help you:-</p> <pre><code> # Perform query cursor = db.posts.find().toAray(function(err, result){ #Iterate the cursor and print the documents. for document in result: print(document); }) //Will give you array of objects. </code></pre> <p>Let me know if it works.</p>
0
2016-08-24T07:30:25Z
[ "python", "mongodb", "pymongo" ]
Iterate a pymongo cursor from MLab
39,116,919
<p>Why won't the cursor iterate? I feel sure there <em>should</em> be an easy solution.</p> <p>I have tried multiple Stack Overflow answers and the documentation for Mongodb <a href="https://docs.mongodb.com/getting-started/python/query/" rel="nofollow">https://docs.mongodb.com/getting-started/python/query/</a></p> <...
1
2016-08-24T07:25:13Z
39,121,808
<p>Found the answer, I was focusing on the cursor rather than loading the object from the cursor from JSON to a list of JSON.</p> <p>Final code is below (removing the URI)</p> <pre><code>import json from datetime import date, timedelta from pymongo import MongoClient from bson import json_util #Connect to Mongo Clie...
0
2016-08-24T11:14:53Z
[ "python", "mongodb", "pymongo" ]
Raspberry Pi Photobooth Printing
39,117,196
<p>I've built <a href="http://makezine.com/projects/raspberry-pi-photo-booth/" rel="nofollow">this</a> photobooth, and I am struggling to figure out what code i would need to add to the script in order to get this to print a copy of each photo. I have already mapped my printer to the raspberry pi using cups. </p> <p><...
0
2016-08-24T07:39:32Z
39,118,346
<p>First, you will need <a href="https://pypi.python.org/pypi/pycups" rel="nofollow">pycups</a>. Then this code <em>should</em> work but I cannot test it:</p> <pre><code># Set up CUPS conn = cups.Connection() printers = conn.getPrinters() printer_name = printers.keys()[0] cups.setUser('pi') # Save the picture to a te...
0
2016-08-24T08:37:29Z
[ "python", "printing", "raspberry-pi" ]
Python Websocket - with time and message limit
39,117,226
<p>I am getting the data from websocket (ws://localhost:8080) and doing command line args with that. code mentioned below.. </p> <p>python datapy.py -i 127.0.0.1 -p 8080</p> <pre><code>from websocket import create_connection #import ConfigParser #from test import settings import sys import argparse import socket pa...
1
2016-08-24T07:40:39Z
39,117,633
<p>I couldn't test, but something along these lines should work.</p> <pre><code>from websocket import create_connection #import ConfigParser #from test import settings import sys import argparse import socket import time parser = argparse.ArgumentParser() parser.add_argument('-i', dest='ip' , help='host name / IP') ...
1
2016-08-24T08:01:27Z
[ "python", "websocket", "argparse" ]
nginx flask aws 502 Bad Gateway
39,117,239
<p>My server is running great yesterday but now it returned a 502 error, how could this happen?</p> <p>In my access.log shows:</p> <pre><code>[24/Aug/2016:07:40:29 +0000] "GET /ad/image/414 HTTP/1.1" 502 583 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.1...
-1
2016-08-24T07:41:08Z
39,117,320
<p>The HTTP status code 502 normally means that the application server Nginx is proxying to is not running. As this is a Flask app I presume this is something like Gunicorn or uwsgi. Check to see if that is running.</p> <p>I normally use something like Supervisor to ensure that the application server gets restarted au...
1
2016-08-24T07:45:47Z
[ "python", "amazon-web-services", "nginx", "flask" ]
nginx flask aws 502 Bad Gateway
39,117,239
<p>My server is running great yesterday but now it returned a 502 error, how could this happen?</p> <p>In my access.log shows:</p> <pre><code>[24/Aug/2016:07:40:29 +0000] "GET /ad/image/414 HTTP/1.1" 502 583 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.1...
-1
2016-08-24T07:41:08Z
39,117,324
<p>It usually happens when the service isn't running.</p> <p>So I'd bet your flask application or <code>wsgi</code> isn't running.</p>
1
2016-08-24T07:45:59Z
[ "python", "amazon-web-services", "nginx", "flask" ]
nginx flask aws 502 Bad Gateway
39,117,239
<p>My server is running great yesterday but now it returned a 502 error, how could this happen?</p> <p>In my access.log shows:</p> <pre><code>[24/Aug/2016:07:40:29 +0000] "GET /ad/image/414 HTTP/1.1" 502 583 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.1...
-1
2016-08-24T07:41:08Z
39,117,338
<p>I believe that <code>gunicorn</code> is not running on your system. Check the status of gunicorn process, and if it is not runningm start the process </p>
1
2016-08-24T07:46:51Z
[ "python", "amazon-web-services", "nginx", "flask" ]
nginx flask aws 502 Bad Gateway
39,117,239
<p>My server is running great yesterday but now it returned a 502 error, how could this happen?</p> <p>In my access.log shows:</p> <pre><code>[24/Aug/2016:07:40:29 +0000] "GET /ad/image/414 HTTP/1.1" 502 583 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.1...
-1
2016-08-24T07:41:08Z
39,117,535
<p>Looking at your <code>error</code> it mentions <code>123.49.616.74, server: app.example.com.au</code>, I think within your configuration you have mentioned the IP address of your server. Replace that with your local IP i.e <code>127.0.0.1</code>. </p> <p>Since you are making the request as <code>127.0.0.1</code> in...
1
2016-08-24T07:57:17Z
[ "python", "amazon-web-services", "nginx", "flask" ]
Python xml generation automatically
39,117,292
<p>I have suppose to save my data which derived from my script to xml. I need to automate it. Think if there is a array so i need to add items of this array to xml as its elements one by one automatically. Is there is any way to do this.</p> <p>this is my python script used to pass data to xml</p> <pre><code>if score...
0
2016-08-24T07:44:20Z
39,117,499
<p>Maybe try something like this :</p> <pre><code>ET.SubElement(doc, frameno, name="frame").text = ' - '.join(predicted_list) </code></pre>
0
2016-08-24T07:54:55Z
[ "python", "xml" ]
Fitting and aligning two lists together in python
39,117,304
<p>I'm trying to match up two lists made up of tuples (x,y,z). I need to fit them together based on the z-values, and remove any tuples containing z-values that are not common to both lists. </p> <p>Input: </p> <pre><code>a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b = [(0,1,1),(2,3,2),(3,4,4)] </code></pre> <p>Output:</p...
1
2016-08-24T07:45:00Z
39,117,537
<p>This will partially satisfy your requirement and be a good starting point. From here you can tweak it to return the cases of repetitions and how to order your stuff.</p> <pre><code>a= [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b= [(0,1,1),(2,3,2),(3,4,4)] a1=[] b1=[] for i in a: for j in b: if i[2] == j[2]: ...
0
2016-08-24T07:57:27Z
[ "python", "python-3.x" ]
Fitting and aligning two lists together in python
39,117,304
<p>I'm trying to match up two lists made up of tuples (x,y,z). I need to fit them together based on the z-values, and remove any tuples containing z-values that are not common to both lists. </p> <p>Input: </p> <pre><code>a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b = [(0,1,1),(2,3,2),(3,4,4)] </code></pre> <p>Output:</p...
1
2016-08-24T07:45:00Z
39,117,664
<pre><code>common_z = set([tup[2] for tup in a]).intersection([tup[2] for tup in b]) a_ = [tup for tup in a if tup[2] in common_z] b_ = [tup for tup in b if tup[2] in common_z] &gt;&gt;&gt; a_ [(3, 4, 1), (5, 3, 2)] &gt;&gt;&gt; b_ [(0, 1, 1), (2, 3, 2)] </code></pre>
4
2016-08-24T08:02:44Z
[ "python", "python-3.x" ]
Fitting and aligning two lists together in python
39,117,304
<p>I'm trying to match up two lists made up of tuples (x,y,z). I need to fit them together based on the z-values, and remove any tuples containing z-values that are not common to both lists. </p> <p>Input: </p> <pre><code>a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b = [(0,1,1),(2,3,2),(3,4,4)] </code></pre> <p>Output:</p...
1
2016-08-24T07:45:00Z
39,117,740
<p>You may achieve it by using <code>set</code> as:</p> <pre><code>&gt;&gt;&gt; a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] &gt;&gt;&gt; b = [(0,1,1),(2,3,2),(3,4,4)] # Intersection of z co-ordinates in 'a' and 'b' list &gt;&gt;&gt; z_ab = set(map(lambda x: x[2], a)) &amp; set(map(lambda x: x[2], b)) &gt;&gt;&gt; new_a =...
0
2016-08-24T08:06:27Z
[ "python", "python-3.x" ]
Fitting and aligning two lists together in python
39,117,304
<p>I'm trying to match up two lists made up of tuples (x,y,z). I need to fit them together based on the z-values, and remove any tuples containing z-values that are not common to both lists. </p> <p>Input: </p> <pre><code>a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b = [(0,1,1),(2,3,2),(3,4,4)] </code></pre> <p>Output:</p...
1
2016-08-24T07:45:00Z
39,117,945
<pre><code>a = [(0,0,0),(3,4,1),(5,3,2),(1,2,3)] b = [(0,1,1),(2,3,2),(3,4,4)] a_dict = {z:[x,y] for x,y,z in a} b_dict = {z:[x,y] for x,y,z in b} a1=[] b1=[] for item in a_dict.keys(): if item in b_dict.keys(): a_dict[item].append(item) a1.append(tuple(a_dict[item])) b_dict[item].append(...
0
2016-08-24T08:16:25Z
[ "python", "python-3.x" ]
How to delete records of main model when records of child model (created using inherits main model) deleted in odoo
39,117,421
<p>In my odoo application, i have Two models. One main model and a child model.</p> <p>main model</p> <pre><code>class main_model(models.Model): _name = 'main.model' </code></pre> <p>My child model is</p> <pre><code>class child_model(models.Model): _inherits = { 'main.model: 'main_ref' } _name = ...
0
2016-08-24T07:51:09Z
39,118,249
<p>Use attribute <strong>ondelete='cascade'</strong> in fields definition.</p> <pre><code>main_ref = fields.Many2one('main.model', ondelete='cascade' ) </code></pre> <p>Hope it will solve your problem.</p>
1
2016-08-24T08:32:07Z
[ "python", "odoo-8" ]
How to interpret list as an integer in python
39,117,445
<p>I am fetching data from MySQL database which is then converted to a list in python. Since the data being fetched is of integer type, I am passing it as index to find character within a string. I am getting the following error </p> <pre><code>TypeError: 'list' object cannot be interpreted as an index </code></pre>...
-1
2016-08-24T07:52:14Z
39,117,670
<p>You can´t handle a list like an int.</p> <p>Guessing you can recover one value of the list (and parse it if it is needed) or use a dictionary for assigning int to a list:</p> <pre><code>var dict = {1: your_list} </code></pre> <p>or:</p> <pre><code>int i = (int)your_list[i] </code></pre>
0
2016-08-24T08:03:02Z
[ "python" ]
How to interpret list as an integer in python
39,117,445
<p>I am fetching data from MySQL database which is then converted to a list in python. Since the data being fetched is of integer type, I am passing it as index to find character within a string. I am getting the following error </p> <pre><code>TypeError: 'list' object cannot be interpreted as an index </code></pre>...
-1
2016-08-24T07:52:14Z
39,117,690
<p>So I guess the exception is here</p> <pre><code>row1 = [item[0] for item in cur1.fetchall()] </code></pre> <p>What you want is probably</p> <pre><code>row1 = [(item[0] for item in cur1.fetchall())[0]] </code></pre> <p>Still, it's not very efficient. Use <code>cursor.fetchone()</code> instead</p> <pre><code>ro...
0
2016-08-24T08:03:57Z
[ "python" ]
Printing a corresponding value of a column in Pandas
39,117,547
<p>I have a table with 3 parameters "Date", "Time" and "Value". I want to add a new column to this table which has values corresponding to "Time" after every <strong>10 minutes</strong>.</p> <p><img src="http://i.stack.imgur.com/UYHu5.png" alt="Image"></p> <p>I though of creating a new column with Seconds for ease.<...
1
2016-08-24T07:57:48Z
39,117,985
<p>IIUC you can first remove <code>dates</code> and <code>hours</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.sub.html" rel="nofollow"><code>sub</code></a>, add <code>10 Min</code>, then convert to <code>miliseconds</code> and divide <code>1000</code>:</p> <pre><code>df = pd.Da...
0
2016-08-24T08:18:40Z
[ "python", "datetime", "pandas", "dataframe", "timedelta" ]
The file copied by python can not be access by another process
39,117,734
<p>I use python <strong>shuitl.copy2</strong> method to copy some file from a share folder, after copy success there will start a process which need access these copied file. <strong>The question</strong> is sometimes there have a file can not be access by the new process, <strong>Error 32</strong> is reported. My scri...
0
2016-08-24T08:06:12Z
39,117,794
<p>The file pointer is probably not closed properly.</p> <p>Maybe add a little <code>time.sleep()</code> between the copy and the start of the process.</p>
0
2016-08-24T08:08:45Z
[ "python", "file", "copy", "shutil" ]
The file copied by python can not be access by another process
39,117,734
<p>I use python <strong>shuitl.copy2</strong> method to copy some file from a share folder, after copy success there will start a process which need access these copied file. <strong>The question</strong> is sometimes there have a file can not be access by the new process, <strong>Error 32</strong> is reported. My scri...
0
2016-08-24T08:06:12Z
39,327,474
<p>I got it! The issue happened because another process created by the parent process during the copy thread coping files. so the file handle of one copied file be passed to the new process, and the new process keeps handle the file handle until it end. So during the process running, the file can not be access by other...
0
2016-09-05T09:22:53Z
[ "python", "file", "copy", "shutil" ]
Settings for timedata in seaborn FacetGrid plots
39,117,835
<p>I want to plot data monthly and show year label once per each year. Here is the data:</p> <pre><code>timedates = ['2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01', '2013-07-01', '2013-08-01', '2013-09-01', '2013-10-01', '2013-11-01', '2013-12-01', '2014-01-01', '2014-02-0...
3
2016-08-24T08:10:38Z
39,121,507
<p>By far, I did it manually. Just separated lines by type and plotted them together. </p> <p>Changed this line </p> <pre><code>ax.plot_date(df_x.timedates, df_x.amount, 'v-') </code></pre> <p>Into three plot-lines:</p> <pre><code>types_levels = df_x.types.unique() for i in types_levels: ax.plot_date(df_x[df_x...
0
2016-08-24T11:01:40Z
[ "python", "matplotlib", "plot", "time-series", "seaborn" ]
Settings for timedata in seaborn FacetGrid plots
39,117,835
<p>I want to plot data monthly and show year label once per each year. Here is the data:</p> <pre><code>timedates = ['2013-01-01', '2013-02-01', '2013-03-01', '2013-04-01', '2013-05-01', '2013-06-01', '2013-07-01', '2013-08-01', '2013-09-01', '2013-10-01', '2013-11-01', '2013-12-01', '2014-01-01', '2014-02-0...
3
2016-08-24T08:10:38Z
39,121,567
<p>You could format the <code>xticks</code> to just include the <code>month</code> and <code>year</code> of the <code>datetime</code> object and get a <code>pointplot</code> with <code>xticks</code> corresponding to the position of scatter plot points.</p> <pre><code>df['timedates'] = df['timedates'].map(lambda x: x.s...
2
2016-08-24T11:04:33Z
[ "python", "matplotlib", "plot", "time-series", "seaborn" ]
Assigning strings to a variable in python
39,117,843
<p>Consider the below string which will be given as the input to a function.</p> <blockquote> <p>01 02 01 <strong>0D A1 D6 72 02 00</strong> 01 00 00 00 00 53 73 F2</p> </blockquote> <p>The highlighted part is the address I need. </p> <p>If the preceding byte is 1 then I have to take only 6 octet and assign it to ...
0
2016-08-24T08:11:04Z
39,118,349
<p>Here I think this does it, let me know if there is anything that needs changing: </p> <pre><code>import string def address_extract(line_input): line_input = string.split(line_input, ' ') length = 6 * int(line_input[2]) device_list = [] for x in range(3, 3+length, 6): if x+6 &gt; len(line...
0
2016-08-24T08:37:37Z
[ "python", "python-2.7" ]
Assigning strings to a variable in python
39,117,843
<p>Consider the below string which will be given as the input to a function.</p> <blockquote> <p>01 02 01 <strong>0D A1 D6 72 02 00</strong> 01 00 00 00 00 53 73 F2</p> </blockquote> <p>The highlighted part is the address I need. </p> <p>If the preceding byte is 1 then I have to take only 6 octet and assign it to ...
0
2016-08-24T08:11:04Z
39,118,535
<p>Here is some code that I hope will help you. I tried to add many comments to explain what is happening</p> <pre><code>import binascii import struct #note python 3 behaves differently and won't work with this code (personnaly I find it easyer for strings convertion to bytes) def main(line_input): formated_line ...
0
2016-08-24T08:45:48Z
[ "python", "python-2.7" ]
Download files after opening a webpage using Python
39,117,979
<p>I have opened a webpage('<a href="http://example.com/protected_page.php" rel="nofollow">http://example.com/protected_page.php</a>') using Python's requests Library.</p> <pre><code>from requests import session payload = { 'action': 'login', 'username': USERNAME, 'password': PASSWORD } with session() as...
-1
2016-08-24T08:18:14Z
39,118,343
<p>Can you please give more information about these links ?</p> <p>Are these linkA and linkB always the same links ? If yes then you can use :</p> <pre><code>r = requests.get(linkA, stream=True) </code></pre> <p>If the url links are not the same all the time , then maybe you can find another way, using the order of...
0
2016-08-24T08:37:14Z
[ "python", "web-scraping" ]
Download files after opening a webpage using Python
39,117,979
<p>I have opened a webpage('<a href="http://example.com/protected_page.php" rel="nofollow">http://example.com/protected_page.php</a>') using Python's requests Library.</p> <pre><code>from requests import session payload = { 'action': 'login', 'username': USERNAME, 'password': PASSWORD } with session() as...
-1
2016-08-24T08:18:14Z
39,118,867
<p>In fact what you are referring is more precisely called as web scrapping , in which one can scrape some specific contents from the given web site:</p> <blockquote> <p>Web scraping is a computer software technique of extracting information from websites. This technique mostly focuses on the transformation of u...
0
2016-08-24T09:01:14Z
[ "python", "web-scraping" ]
Python 3, Variables in loops
39,117,991
<p>I'm new to python, and just playing around, getting to learn different features with this code.(Please read note)</p> <pre><code>less = ["science", "maths"] for i in range(0,len(less)): a = ("You have got; " + (less[i])) b = (a) #By putting in print here I figured out that it added science first then m...
1
2016-08-24T08:18:54Z
39,118,047
<p>You can iterate simply over objects in the list and make <code>print</code> statement not terminate the line. </p> <pre><code>less = ["science", "maths"] print ("You have got; ", end="") for i in less: print (i, end=" ") </code></pre>
1
2016-08-24T08:21:25Z
[ "python", "loops", "python-3.x", "variables" ]
Python 3, Variables in loops
39,117,991
<p>I'm new to python, and just playing around, getting to learn different features with this code.(Please read note)</p> <pre><code>less = ["science", "maths"] for i in range(0,len(less)): a = ("You have got; " + (less[i])) b = (a) #By putting in print here I figured out that it added science first then m...
1
2016-08-24T08:18:54Z
39,118,061
<p>To achieve this, use <code>join</code>:</p> <pre><code>&gt;&gt;&gt; less = ["science", "maths"] &gt;&gt;&gt; print("You have got; %s" % ' '.join(less)) You have got; science maths </code></pre> <p>Explanation: <code>join</code> joins the elements in the list as a single <code>string</code> which you may add at the...
0
2016-08-24T08:22:18Z
[ "python", "loops", "python-3.x", "variables" ]
Python 3, Variables in loops
39,117,991
<p>I'm new to python, and just playing around, getting to learn different features with this code.(Please read note)</p> <pre><code>less = ["science", "maths"] for i in range(0,len(less)): a = ("You have got; " + (less[i])) b = (a) #By putting in print here I figured out that it added science first then m...
1
2016-08-24T08:18:54Z
39,118,066
<pre><code>less = ["science", "maths"] print ('You have got; {}'.format(' '.join(less))) </code></pre>
1
2016-08-24T08:22:37Z
[ "python", "loops", "python-3.x", "variables" ]
XLRDError when reading xls files
39,118,056
<p>I tried reading excel files by the following code:</p> <pre><code>import os import xlrd files = os.listdir(".")[1:101] for file in files: workbook = xlrd.open_workbook(file) </code></pre> <p>but I got an error message like this.</p> <blockquote> <p>XLRDError: Unsupported format, or corrupt file: Expected...
0
2016-08-24T08:22:06Z
39,119,373
<p>Try <code>xlrd.open_workbook(file, encoding_override="utf-8")</code></p>
1
2016-08-24T09:25:25Z
[ "python", "encoding", "xlrd" ]
Using javascript to update HTML in python loop
39,118,093
<p>I'm currently trying to integrate a progress bar to my website. I've successfully put it in my web page, and I am trying to animate it now.</p> <p>I have a js script that updates the progress bar every second, which is exactly what I want, but the problem is that if you refresh the page, the progress bar gets back ...
2
2016-08-24T08:24:26Z
39,124,187
<p>You can use Web Sockets and in javascript you can receive the data from server and update the progress bar. Please check the article below:</p> <p><a href="https://www.fullstackpython.com/websockets.html" rel="nofollow">Web Sockets</a></p>
1
2016-08-24T13:06:12Z
[ "javascript", "python", "html", "multithreading", "progress-bar" ]