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
simple matrix type rotation (without numpy or pandas)
39,004,701
<p>This must be something that is really simple, but I could not fix it.</p> <p>I want to do a matrix type transpose with native python list of list (i.e., without using <code>numpy</code> or <code>pandas</code>). Code is show following. I am having a hard time trying to figure out where it is wrong.</p> <pre><code>r...
0
2016-08-17T19:23:24Z
39,004,924
<p>Using a nested list comprehension:</p> <pre><code>rows, cols = len(raw_matrix_list), len(raw_matrix_list[0]) &gt;&gt;&gt; [[raw_matrix_list[i][j] for i in range(rows)] for j in range(cols)] [[1, 1, 0, 1], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [1, 1, 0, 1], [0, 0, 1, 1]] </code></pre>
0
2016-08-17T19:36:46Z
[ "python" ]
simple matrix type rotation (without numpy or pandas)
39,004,701
<p>This must be something that is really simple, but I could not fix it.</p> <p>I want to do a matrix type transpose with native python list of list (i.e., without using <code>numpy</code> or <code>pandas</code>). Code is show following. I am having a hard time trying to figure out where it is wrong.</p> <pre><code>r...
0
2016-08-17T19:23:24Z
39,005,228
<p>There are already answers that help solve your problem. As to why your code doesn't work, shouldn't it be this (by definition of matrix transpose):</p> <p><code>new_matrix_list[ii][jj] = raw_matrix_list[jj][ii]</code></p>
0
2016-08-17T19:57:00Z
[ "python" ]
Ascending/Resetting Integer Values from MultiIndex Pandas
39,004,736
<p>I have a dataframe:</p> <pre><code>import pandas as pd tuples = [('a', 1990),('a', 1994),('a',1996),('b',1992),('b',1997),('c',2001)] index = pd.MultiIndex.from_tuples(tuples, names = ['Type', 'Year']) vals = ['This','That','SomeName','This','SomeOtherName','SomeThirdName'] df = pd.DataFrame(vals, index=index, col...
1
2016-08-17T19:25:32Z
39,004,767
<p>you can use <code>groupby(level=0)</code> + <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow">cumcount()</a>:</p> <pre><code>In [7]: df['IndexInt'] = df.groupby(level=0).cumcount()+1 In [8]: df Out[8]: Whatev IndexInt Type Ye...
2
2016-08-17T19:27:23Z
[ "python", "pandas" ]
Can't use .update() function on Django context in views?
39,004,754
<p>I have a function that gets some base information in my <code>views.py</code> file, and I'm trying to update the context of each page using it by having it return a dictionary. However, using <code>.update()</code> on the context dictionary in the <code>render()</code> function doesn't seem to work.</p> <p>Here's w...
-2
2016-08-17T19:26:23Z
39,005,157
<p>You should do something like this: </p> <pre><code>def index(request): allPages = list(Page.objects.all()) primaryPages = allPages[:5] secondaryPages = allPages[5:] return render(request, 'pages/index.html', {'p':primaryPages, 'p2':secondaryPages}) </code></pre> <p>Other option should be to make <c...
1
2016-08-17T19:52:03Z
[ "python", "django" ]
Can't use .update() function on Django context in views?
39,004,754
<p>I have a function that gets some base information in my <code>views.py</code> file, and I'm trying to update the context of each page using it by having it return a dictionary. However, using <code>.update()</code> on the context dictionary in the <code>render()</code> function doesn't seem to work.</p> <p>Here's w...
-2
2016-08-17T19:26:23Z
39,005,278
<p>Firstly, if you wanted to use a base dictionary and add objects to that you should do so explicitly:</p> <pre><code>def index(request): context = getBaseInfo() context.update({'otherkey': 'othervalue'}) # or context['otherkey'] = 'othervalue' return(...) </code></pre> <p>However, there is no ne...
2
2016-08-17T19:59:58Z
[ "python", "django" ]
Comparing list with dictionary to make new list in python
39,004,820
<p>I have one list and one dictionary. I want to compare the list values with the keys of the dictionary. If I have:</p> <pre><code>mydict = {'Hello':1,'Hi':2,'Hey':3} </code></pre> <p>and:</p> <pre><code>mylist = ['Hey','What\'s up','Hello'] </code></pre> <p>I want the output to be:</p> <pre><code>output = [3, No...
-1
2016-08-17T19:29:53Z
39,004,905
<p>Use a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>: </p> <pre><code>output = [ mydict.get(key) for key in mylist ] </code></pre> <p>Note that <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries" rel="nofollow">di...
3
2016-08-17T19:35:45Z
[ "python", "python-3.x", "python-3.5" ]
Comparing list with dictionary to make new list in python
39,004,820
<p>I have one list and one dictionary. I want to compare the list values with the keys of the dictionary. If I have:</p> <pre><code>mydict = {'Hello':1,'Hi':2,'Hey':3} </code></pre> <p>and:</p> <pre><code>mylist = ['Hey','What\'s up','Hello'] </code></pre> <p>I want the output to be:</p> <pre><code>output = [3, No...
-1
2016-08-17T19:29:53Z
39,004,914
<p>Use <code>dict.get()</code>, which defaults to <code>None</code> if key does not exist:</p> <pre><code>[mydict.get(k) for k in mylist] </code></pre> <hr> <pre><code>&gt;&gt;&gt; mydict = {'Hello':1,'Hi':2,'Hey':3} &gt;&gt;&gt; mylist = ['Hey','What\'s up','Hello'] &gt;&gt;&gt; out = [mydict.get(k) for k in mylist...
2
2016-08-17T19:36:18Z
[ "python", "python-3.x", "python-3.5" ]
Passing Javascript variable to Django views.py with getJSON
39,004,837
<p>I currently have a javascript variable called myVariableToSend that contains a single string and I need to send to my views where I can make raw SQL queries to gather corresponding data from the database and bring it back to my javascript. Here is what I have:</p> <p><strong>Javascript:</strong></p> <pre><code>fun...
0
2016-08-17T19:31:04Z
39,006,031
<p>If u want to send ur variables to function in view, u can capture it with url, like this: </p> <pre><code>$.getJSON('http://127.0.0.1:8000/getData/' + myVariableToSend +'/', function (serverdata) { //do ur work} </code></pre> <p>Then in urls.py you have: </p> <pre><code>url(r'getData/(?P&lt;my_var&gt;\w+)/$', vie...
0
2016-08-17T20:49:26Z
[ "javascript", "jquery", "python", "django" ]
Passing Javascript variable to Django views.py with getJSON
39,004,837
<p>I currently have a javascript variable called myVariableToSend that contains a single string and I need to send to my views where I can make raw SQL queries to gather corresponding data from the database and bring it back to my javascript. Here is what I have:</p> <p><strong>Javascript:</strong></p> <pre><code>fun...
0
2016-08-17T19:31:04Z
39,006,737
<p><strong>Answering the original question:</strong></p> <p>Your server is failing probably because bad syntax in views.py</p> <pre><code>some_data = request.GET(myVariableToSend) </code></pre> <p><code>myVariableToSend</code> is undefined here. So you should get it like this:</p> <pre><code>some_data = request.GET...
0
2016-08-17T21:43:20Z
[ "javascript", "jquery", "python", "django" ]
How open python2.7 in spyder, jupyter, qtconsole. from Anaconda Navigator installed with python3? (OS X)
39,004,849
<p>Under OS X (10.11.6) I installed the current Python 3.5 version of Anaconda. Anaconda Navigator then works just fine to launch sypder, jupyter,or qtconsole with python 3.5.2 running.</p> <p>At the command line I also created a python 2.7 environment (conda create --name python2 python=2.7 anaconda). But now when I...
0
2016-08-17T19:31:26Z
39,654,422
<p>Type the following commands in the terminal:</p> <ol> <li><p>source activate python2</p></li> <li><p>spyder</p></li> </ol> <p>Spyder will be launched with the python2 environment. With this method you do not use the anaconda navigator, but at least you can use spyder with your python2 environment.</p>
1
2016-09-23T06:53:51Z
[ "python", "anaconda" ]
AWS IoT device is not getting message published by iOS app
39,004,902
<p>So I am building an iOS app that can communicate with a device via AWS IoT. both the device and the app are subscribed to the update/accepted, get/accepted and update/delta. I can publish updates from either side, and the update is reflected on AWS IoT thing shadow, but somehow the update was never relayed from one ...
0
2016-08-17T19:35:33Z
39,085,092
<p>This is intended behavior. The explanation can be found <a href="http://%20http://docs.aws.amazon.com/iot/latest/developerguide/using-thing-shadows.html#delta-state" rel="nofollow">here</a></p> <blockquote> <p>Delta state is a virtual type of state that contains the difference between the desired and reported sta...
1
2016-08-22T17:08:16Z
[ "python", "ios", "swift", "amazon-web-services", "aws-iot" ]
Does timeit clear the local memory after each iteration
39,004,937
<p>I have a moderately sized sorted ascii text file that I am attempting to work with in Python. I am trying to decide at what number of searches it becomes faster to read the entire file into memory and use numpy logical indexing to do searches instead of using a simple binary search function that I wrote using the t...
0
2016-08-17T19:37:23Z
39,005,118
<p>Since timeit is implemented in regular Python it's quite easy to see what it does: <a href="https://hg.python.org/cpython/file/2.7/Lib/timeit.py" rel="nofollow">https://hg.python.org/cpython/file/2.7/Lib/timeit.py</a></p> <p>To answer the question though, no, it will not execute a <code>del data</code> since that's...
0
2016-08-17T19:49:17Z
[ "python", "numpy", "timeit" ]
making an animation from a data file with matplotlib
39,004,963
<p>I have some c++ code which generates trajectories of particles. i. e. x and y coordinates of particles in different steps of simulations, in which the output file looks like this (for 4 particles):</p> <pre><code>#step0 1 2 3 4 5 6 7 8 #step1 1.2 2.2 3.2 4.3 5.2 6.4 7.2 8.5 ... </code></pre> <p>I want to make an a...
0
2016-08-17T19:39:08Z
39,108,146
<p>you are using the default bounds of the box, that's why (assuming your data is similar to the first two data points you posted) nothing shows in the box.</p> <p>to fix this, change line 62 to something like this:</p> <p><code>box = ParticleBox(init_state,bounds = [-1, 10, -1, 10], size=0.04)</code></p>
0
2016-08-23T18:17:51Z
[ "python", "matplotlib", "visualization" ]
Flask server with MongoDB (flask-pymongo)
39,004,969
<p>I'm trying to set up a flask server which adds data/users to a mongoDB database. I set up the DB (using mongo shell) like so:</p> <pre><code>&gt;use dbname switched to dbname &gt;db.users.save( {username:"user", password:"pass"} ) WriteResult({ "nInserted" : 1 }) </code></pre> <p>And confirm the data is writt...
0
2016-08-17T19:39:52Z
39,005,160
<p>You have a typo in</p> <pre><code>@app.route('/login', methods=['GET', 'POST']) </code></pre> <p>PyMongo uses current_app variable from flask which refers to the application instance handling the request. In this case <strong>app</strong> handles the request but <strong>appp</strong> has the configuration. So this...
0
2016-08-17T19:52:28Z
[ "python", "mongodb" ]
Flask server with MongoDB (flask-pymongo)
39,004,969
<p>I'm trying to set up a flask server which adds data/users to a mongoDB database. I set up the DB (using mongo shell) like so:</p> <pre><code>&gt;use dbname switched to dbname &gt;db.users.save( {username:"user", password:"pass"} ) WriteResult({ "nInserted" : 1 }) </code></pre> <p>And confirm the data is writt...
0
2016-08-17T19:39:52Z
39,005,488
<p>Kostas was correct. </p> <p>I changed:</p> <pre><code>appp = Flask(__name__) mongo = PyMongo(appp) </code></pre> <p>to simply</p> <pre><code>mongo = PyMongo(app) </code></pre>
1
2016-08-17T20:13:47Z
[ "python", "mongodb" ]
Inverting tridiagonal matrix
39,005,026
<p>I am having an equation</p> <p>Ax=By</p> <p>Where A and B are tridiagonal matrices. I want to calculate a matrix </p> <p>C=inv (A).B</p> <p>there are different x,s which will give different y,s hence calculation of C is handy. </p> <p>Can someone please tell me a faster method to compute the inverse. I am usin...
-1
2016-08-17T19:43:29Z
39,015,683
<p>There are many method to do it, anyway one of the simplest is the Tridiagonal matrix algorithm see the <a href="https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm" rel="nofollow">Wiki page</a>. This algorithm work in O(n) time, there is a simple implementation in Numpy at the following <a href="https://gist....
1
2016-08-18T10:21:04Z
[ "python", "performance", "sparse-matrix", "matrix-inverse" ]
What unit does scipy's kdtree function return distance in?
39,005,104
<p>I'm new to KD trees and I'm using them to find the nearest neighbour for each point in one array (search_array), compared with all the points in a second array (vec_array).</p> <p>Both arrays are formatted like so:</p> <pre><code>array([[ 51.54094696, 0.09767043], [ 51.53620148, 0.0798 ], [ 51.5362014...
0
2016-08-17T19:48:12Z
39,012,091
<p>As kindly indicated by Warren in the comment above, the units are the same as in the input array.</p>
0
2016-08-18T07:17:37Z
[ "python", "scipy", "spatial", "kdtree" ]
How to install packages with pip to python 2 when python 3 is the "defult"
39,005,114
<p>So I am using python 3 but, for a course I am taking I need to use python 2. So I installed it. Now I need to install a package called zmq. Before I just installed it by doing <code>pip install zmq</code> but how do I install this package to python 2? </p>
0
2016-08-17T19:49:05Z
39,005,313
<p>Generally pip installs not only the <code>pip</code> command but also the <code>pip2</code> and <code>pip2.7</code> command in your Path.</p> <p>So, to install within the Python 2 context use:</p> <pre><code>pip2 install &lt;package&gt; </code></pre> <p>And to install within the Python 3 context use:</p> <pre><c...
1
2016-08-17T20:02:19Z
[ "python", "python-2.7", "pip" ]
When should I store the result of a function as a variable in python?
39,005,133
<p>Suppose a function <code>my_list(obj)</code> returns a list. I want to write a function that returns the single element of <code>my_list(obj)</code> if this list has length one and <code>False</code> otherwise. My code is</p> <pre><code>def my_test(obj): if len(my_list(obj)) == 1: return my_list(obj)[0]...
1
2016-08-17T19:50:00Z
39,005,356
<p>To answer your question on whether it is generally better to store the result of a function as a variable if it is going to be called more than once: it depends. In terms of readability, it's really up to you as a programmer. In terms of speed, storing the result in a variable is generally faster than running the f...
2
2016-08-17T20:05:10Z
[ "python" ]
When should I store the result of a function as a variable in python?
39,005,133
<p>Suppose a function <code>my_list(obj)</code> returns a list. I want to write a function that returns the single element of <code>my_list(obj)</code> if this list has length one and <code>False</code> otherwise. My code is</p> <pre><code>def my_test(obj): if len(my_list(obj)) == 1: return my_list(obj)[0]...
1
2016-08-17T19:50:00Z
39,005,402
<p>You are correct. The second block would be more efficient since it only calls <code>my_list()</code> once. If <code>my_list()</code> isn't particularly computationally expensive, it's unlikely you will notice a difference at all. If you know it will be expensive, on the other hand, it is a good idea to save the resu...
3
2016-08-17T20:08:13Z
[ "python" ]
Inline User Data Input Manipulation for Query Selection | Python
39,005,165
<p>I am in the process of developing a troubleshooting application in Python that will allow a user to input a query. This query would contain the brand of the device and the issue or symptom of their problem. I am in the process of writing a script which essentially dissects the query to find an appropriate solution f...
1
2016-08-17T19:52:49Z
39,048,423
<p><strong>Run this</strong> I hope this gives you some ideas. You need to fix your indentation for the <code>main():</code> function.</p> <pre><code>#Define Globals brands = ["apple", "android", "windows"] brand = '' import random def Main(): init() print("--Welcome to Troubleshooting Applet--") ...
0
2016-08-19T22:19:55Z
[ "python", "user-interface", "user-input", "conditional-operator" ]
Set value for particular cell in pandas DataFrame
39,005,183
<p>This question is similar to <a href="http://stackoverflow.com/questions/13842088/set-value-for-particular-cell-in-pandas-dataframe">this question</a> posted earlier. The difference is that I want to change value in a cell that index column is not unique. For example:</p> <pre><code> x y A 1 5 B 4 6 C 0 3 C...
0
2016-08-17T19:53:35Z
39,005,334
<p>You could go for the ordinal indexes (they are always unique) like so:</p> <pre><code>In [13]: df.iloc[3, 1] = 100 In [14]: df Out[14]: x y A 1 5 B 4 6 C 0 3 C 5 100 </code></pre>
1
2016-08-17T20:03:45Z
[ "python", "pandas" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,337
<p>There may be a better way, but you can do a nested dict comprehension:</p> <pre><code>[{k:d[k] for k in d if k!="a"} for d in l if d.get("a") == 10] </code></pre>
6
2016-08-17T20:04:02Z
[ "python", "list", "dictionary", "slice" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,366
<p>Maybe you can use the functions filter and map for readability and immutability.</p> <p>Example (I didn't test it):</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] l_filtered = filter(lam...
1
2016-08-17T20:05:39Z
[ "python", "list", "dictionary", "slice" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,376
<p>Similar to <a href="http://stackoverflow.com/questions/5844672/delete-an-element-from-a-dictionary">This question</a> on SO for element removal from dictionary. The rest is straightforward.</p> <pre><code>[ {i:elem[i] for i in elem if i!="a"} for elem in l if elem["a"] == 10] </code></pre> <p>Returns</p> <blockqu...
1
2016-08-17T20:06:09Z
[ "python", "list", "dictionary", "slice" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,382
<p>Seems to me that you're working too hard to make this a one-liner. Create two empty lists and append each dict to one or the other depending on the value of the <code>a</code> key.</p> <pre><code>&gt;&gt;&gt; l = [ { "a": 10, "b": 4, "c": 6 }, ... { "a": 10, "b": 6, "c": 8 }, ... { "a": 13, "b": 3, "c":...
0
2016-08-17T20:06:37Z
[ "python", "list", "dictionary", "slice" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,489
<p>I think I've got a pretty cool one-liner that should be very fast and works whether or not <code>a</code> is in the dictionary. It relies on the fact that popping from a dictionary returns the value of the key (or none if key is not present) as well as removes the entry. Note that it does mutate <code>l</code> thoug...
2
2016-08-17T20:13:51Z
[ "python", "list", "dictionary", "slice" ]
Slicing a list of dictionaries and removing one key
39,005,241
<p>I have a list of dictionaries, like the one below:</p> <pre><code>l = [ { "a": 10, "b": 4, "c": 6 }, { "a": 10, "b": 6, "c": 8 }, { "a": 13, "b": 3, "c": 9 }, { "a": 12, "b": 5, "c": 3 }, { "a": 11, "b": 7, "c": 1 } ] </code></pre> <p>Now, I want to slice it and have a list only with dictio...
0
2016-08-17T19:57:53Z
39,005,606
<p>It can be done in a one-liner with map/filter</p> <pre><code>res = [elem for elem in map(lambda x:{k:v for k,v in x.items() if k != 'a'}, [e for e in filter(lambda y:y.get('a') != 10,a)])] </code></pre>
0
2016-08-17T20:21:14Z
[ "python", "list", "dictionary", "slice" ]
Install rpy2 inside virtualenv (can't find library)
39,005,256
<p>I have a Python virtualenv set up with <a href="https://github.com/yyuu/pyenv-virtualenv" rel="nofollow">pyenv-virtualenv</a>. I installed the <a href="https://www.r-project.org/" rel="nofollow">R statistical software</a>, and now I need to install the <a href="https://rpy2.readthedocs.io" rel="nofollow">rpy2</a> pa...
0
2016-08-17T19:58:50Z
39,229,335
<p>I finally could install the package successfully.</p> <p>The issue was that I had installed the <code>python-dev</code> library <em>after</em> the <code>virtualenv</code> was created. This caused the installation of the <code>rpy2</code> package to fail.</p> <p>The solution was to uninstall the <code>virtualenv</c...
0
2016-08-30T13:49:06Z
[ "python", "rpy2" ]
Are all functionalities of ggplot2 available in Python?
39,005,267
<p>the title is actually my question. I googled quite a bit, checked Quora and searched through Stackoverflow. Since I couldn't find an answer to my question I think the question is warranted.</p> <p>So basically my question is twofold:</p> <p>1) are all the ggplot2 functionalities available in python (especially jup...
-1
2016-08-17T19:59:28Z
39,005,568
<p>According to my knowledge, the answer is no. In Jupyter Notebook, however, you can interface with R. In brief, do your calculations in Python and then plot using R in the same notebook. For details, check out this <a href="https://github.com/cliburn/sta-663-2016/blob/master/lectures/18B_Foreing_Language_Interface.ip...
1
2016-08-17T20:19:08Z
[ "python", "ggplot2", "jupyter-notebook" ]
Subset rows by partially matching two columns for words greater than n characters
39,005,274
<p>I would be open to doing this in python pandas, but in R I have the following df:</p> <pre><code> result&lt;-structure(list(traffic_Count_Street = c("San Angelo", "W Commerce St", "W Commerce St", "S Gevers St", "Austin Hwy", "W Evergreen St" ), unit_Street = c("San Pedro Ave", "W Commerce", "W Commerce", "S N...
2
2016-08-17T19:59:47Z
39,005,538
<p>Create a distance filter that has a threshold adjustment. Then you can adjust until you are getting the results you want. A Levenshtein distance of 5 worked well in this case:</p> <pre><code>distanceFilter &lt;- function(df, thresh=5) { ind &lt;- apply(df, 1, function(x) adist(x[1], x[2]) &lt; thresh ) df[ind,]...
1
2016-08-17T20:17:03Z
[ "python", "regex", "pandas", "stringr" ]
Longest Common Subsequence Python 2 function
39,005,328
<p>When I run LCS( 'human', 'chimp' ), I'm getting "h" instead of "hm". When I run LCS( 'gattaca', 'tacgaacta' ), I'm getting "g" instead of "gaaca". When I run LCS( 'wow', 'whew' ), I'm getting "ww" which is correct. When I run LCS( '', 'whew' ), I'm getting "" which is correct. When I run LCS( 'abcdefgh', 'efghabcd' ...
0
2016-08-17T20:03:15Z
39,005,562
<p>That is not how you write LCS. This is how you write very weird function that calculates the number of letters in the second string that are equal to the first letter of the first string.</p> <p>I believe what you meant to write is wrong, so that does not matter, but if I correctly guessed what you meant to write, ...
0
2016-08-17T20:18:57Z
[ "python", "python-2.7", "lcs" ]
Longest Common Subsequence Python 2 function
39,005,328
<p>When I run LCS( 'human', 'chimp' ), I'm getting "h" instead of "hm". When I run LCS( 'gattaca', 'tacgaacta' ), I'm getting "g" instead of "gaaca". When I run LCS( 'wow', 'whew' ), I'm getting "ww" which is correct. When I run LCS( '', 'whew' ), I'm getting "" which is correct. When I run LCS( 'abcdefgh', 'efghabcd' ...
0
2016-08-17T20:03:15Z
39,054,886
<p>Figured it out thanks to the people next to me in the lab! It would also be nice to not run into snooty people on Stack Overflow every now and then.</p> <pre><code>def LCS(S, T): # If either string is empty, stop if len(S) == 0 or len(T) == 0: return "" # First property if S[-1] == T[-1]: return LC...
0
2016-08-20T13:53:15Z
[ "python", "python-2.7", "lcs" ]
What is the best user-friendly way to package up a python script into an executable?
39,005,363
<p>I'm new to python and am writing a web scraping script for some coworkers that will scrape data off of a given webpage and package up into a .csv for them. What is the best way to package up this script so that they can just click on it and maybe enter some search terms then let it run and produce a .csv?</p> <p>Th...
2
2016-08-17T20:05:36Z
39,005,527
<p>For Windows: </p> <p>If your coworkers have Python itself installed, you could simply write a simple batch script which executes</p> <pre><code>python myscript.py </code></pre> <p>You can then provide them the *.py and *.bat file.</p> <p>If you want to build an *.exe from your Python script, take a look at <a hr...
0
2016-08-17T20:16:21Z
[ "python", "user-interface", "scripting" ]
What is the best user-friendly way to package up a python script into an executable?
39,005,363
<p>I'm new to python and am writing a web scraping script for some coworkers that will scrape data off of a given webpage and package up into a .csv for them. What is the best way to package up this script so that they can just click on it and maybe enter some search terms then let it run and produce a .csv?</p> <p>Th...
2
2016-08-17T20:05:36Z
39,012,774
<p>A better solution would be taking arguments while running your python script. The only parameter would be the url of the target webpage. Check this SO <a href="http://stackoverflow.com/questions/4033723/how-do-i-access-command-line-arguments-in-python">answer</a> for getting parameters.</p> <p>My approach would be ...
1
2016-08-18T07:59:19Z
[ "python", "user-interface", "scripting" ]
When using Docker Containers, where are shared Python libraries stored?
39,005,380
<p>In an environment where Docker Containers are used for each application, where are Python's shared libraries stored? Are they stored separately within each Docker Container, or shared by the host O/S?</p> <p>Additionally I'm wondering if it would be best practice to use a virtual environment regardless?</p>
2
2016-08-17T20:06:30Z
39,005,477
<p>Just like everything else in a Docker Container, your libraries are inside the container. Unless you mount a host volume, or a volume from another container of course. On the plus side, though, they're copy-on-write, so if you're not making changes to the libraries in your container (why would you do that anyway?) t...
3
2016-08-17T20:13:15Z
[ "python", "docker", "virtualenv" ]
FMU Variable Values Do Not Match Input
39,005,445
<p>I'm getting some strange behavior in a simple co-simulation that I'm trying to configure. I setup a building energy model in EnergyPlus to test out an FMU generated from JModelica. However, the building energy model would get hung up at the co-simulation step. I then ran the FMU in JModelica and got some very strang...
1
2016-08-17T20:11:27Z
39,134,843
<p>Following @ChristianAndersson's suggestion to update my JModelica installation the problem described in my question above was solved. </p> <p>JModelica 1.17.0 was release in December, 2015. </p> <p>JModelica-SDK-1.12.0 was released in February, 2016 and is built from the source code, which fixed the problem and pr...
0
2016-08-25T00:15:08Z
[ "python", "c", "modelica", "fmi", "jmodelica" ]
can't call an existing function from python shell
39,005,456
<p>I have a python/django project, with a django app called <code>"testApp"</code>. under <code>"testApp"</code> I have a python file: <code>"hello.py"</code>. The file reads:</p> <pre><code>class Hello(): def sayHello(): print ("hello") </code></pre> <p>How can I activate the <code>sayHello</code> function fr...
0
2016-08-17T20:12:06Z
39,005,733
<p>You need to import the actual name you want to use. Just importing testApp won't do anything; you would need to do <code>from testApp.hello import Hello</code>.</p> <p>Note also that since for some reason you have a class, <code>sayHello</code> is an instance method and therefore needs to accept the <code>self</cod...
1
2016-08-17T20:29:36Z
[ "python", "django" ]
render two seaborn figure objects in same ipython cell
39,005,461
<p>I have two matplotlib (seaborn) figure objects both made in different ipython cells.</p> <pre><code>#One Cell fig_1_object = sns.factorplot(y='freq',x='d_fam',col='easy_donor',kind="bar",data=collection_d_fam) fig_1 = fig_1_object.fig #Two Cell fig_2_object = sns.factorplot(y='freq',x='d_fam',col='easy_donor',kin...
0
2016-08-17T20:12:24Z
39,027,892
<p>You just need to import the <code>display</code> function from the <code>IPython.display</code> module:</p> <pre><code>from IPython.display import display import seaborn %matplotlib inline g1 = seaborn.factorplot(**options1) g2 = seaborn.factorplot(**options2) display(g1) display(g2) </code></pre>
2
2016-08-18T21:36:27Z
[ "python", "matplotlib", "ipython", "jupyter-notebook", "seaborn" ]
Python: How to modify values in nested dictionary and have the whole dict returned
39,005,474
<p>Imagine that I have got a file named 'test_dict.txt' containing the following dictionary-like text:</p> <pre><code>{ "subdic1" : { "a_string" : "something1", "a_integer" : 16, "a_list" : [ "str_1", "str_2" ] }, "subdic2" : { "a_string" : "s...
0
2016-08-17T20:13:01Z
39,006,115
<p>As @jonrsharpe mentioned you just need to assign things back to the master or original copy. Here's some spaghetti that iterates on the code you've provided : </p> <pre><code>def to_unicode(d, target_dict={}): for k,v in d.iteritems(): if isinstance(v, dict): target_dict = to_unicode(v, t...
0
2016-08-17T20:55:08Z
[ "python", "dictionary", "unicode" ]
Sending HTTP requests concurrently
39,005,564
<p>I'm looking to send 100K-300K POST requests to an API Endpoint - these requests are originating from a list of JSON objects that I'm iterating over. Unfortunately, the maximum chunk size I'm able to use is 10 events at a time which is greatly decreasing the speed of sending off all the events I want. After I have my...
1
2016-08-17T20:18:59Z
39,007,115
<p>You could use scrapy, which uses twisted (as suggested in the comments). Scrapy is a framework intended for scraping web pages, but you can use it to send <code>post</code> requests too. A spider that achieves the same as your code would look more or less like this:</p> <pre><code>class EventUploader(scrapy.Spider)...
-1
2016-08-17T22:17:06Z
[ "python", "python-requests", "python-multithreading" ]
Python Flask Server Not Working With Twilio
39,005,768
<p>I have been trying to create a personnel log using Raspberry Pi to record who is in the house and to respond to a Twilio text message and reply who is home. I'm using flask to form the server to Twilio however I am getting no response at all when I text the 'whoshome' query. It should reply who is home, although on...
-1
2016-08-17T20:31:58Z
39,006,500
<p>Twilio evangelist here.</p> <p>It looks like you are returning an empty trying from your route:</p> <pre><code>return ' ' </code></pre> <p>Since you've marked the route as accepting GET requests you can check this is what's happening by opening the public URL for this route in a browser and seeing what's returned...
2
2016-08-17T21:22:33Z
[ "python", "flask", "twilio" ]
Menu floats above menu button
39,005,823
<p>So to begin with here is my code:</p> <pre><code>from Tkinter import * def hello(): print "Hello" root = Tk() root.attributes('-fullscreen', 1) icons = [] icons.append(PhotoImage(file="Icons\start.gif")) icons.append(PhotoImage(file="Icons\quit.gif")) icons.append(PhotoImage(file="Icons\save.gif")) icons.appe...
0
2016-08-17T20:35:14Z
39,008,266
<p>The problem seems to be with putting the menu button on the absolute bottom. Here is near minimal code, with menu button one 'line' up from bottom, that works with 3.6 (tk 8.6) on Win10</p> <pre><code>import tkinter as tk root = tk.Tk() root.attributes('-fullscreen', 1) tk.Button(root, text='Close', command=root.d...
0
2016-08-18T00:39:44Z
[ "python", "tkinter" ]
sorting list of decimals in python
39,005,831
<p>I have the following list that I'd like to sort:</p> <p><code>['104.900209904', '238.501860857', '9.59893298149', '362.470027924', '419.737339973']</code></p> <p>I used the "sorted" function to do it:</p> <pre><code>Block1_Video1 = sorted(Block1_Video1) </code></pre> <p>However, this is what I get:</p> <pre><co...
0
2016-08-17T20:35:31Z
39,005,864
<p>The sorting needs to be based on the float values of the corresponding strings in the list.</p> <pre><code>Block1_Video1 = ['104.900209904', '238.501860857', '9.59893298149', '362.470027924', '419.737339973'] sorted(Block1_Video1,key=lambda x:float(x)) </code></pre> <p>Or simply use </p> <pre><code>sorted(Block1_...
7
2016-08-17T20:37:24Z
[ "python", "list", "sorting", "floating-point" ]
sorting list of decimals in python
39,005,831
<p>I have the following list that I'd like to sort:</p> <p><code>['104.900209904', '238.501860857', '9.59893298149', '362.470027924', '419.737339973']</code></p> <p>I used the "sorted" function to do it:</p> <pre><code>Block1_Video1 = sorted(Block1_Video1) </code></pre> <p>However, this is what I get:</p> <pre><co...
0
2016-08-17T20:35:31Z
39,005,888
<p>You have to convert your strings in numbers first, this is possible with the key-Argument of the <code>sorted</code> function:</p> <pre><code>Block1_Video1 = sorted(Block1_Video1, key=float) </code></pre> <p>or as you assign the new list to the same variable, you can also sort in-place:</p> <pre><code>Block1_Vide...
1
2016-08-17T20:38:47Z
[ "python", "list", "sorting", "floating-point" ]
How "generate " multiple TCP clients using Threads instead of opening multiple instances of the terminal and run the script several times?
39,005,901
<p>I wrote the code for a simple TCP client:</p> <pre><code>from socket import * # Configurações de conexão do servidor # O nome do servidor pode ser o endereço de # IP ou o domínio (ola.python.net) serverHost = 'localhost'#ip do servidor serverPort = 50008 # Mensagem a ser mandada codificada em bytes menssagem...
10
2016-08-17T20:39:55Z
39,207,374
<p>Try this: The worker method will be set as target for the thread. So every thread will use the code of the method. After starting all thread, the for loop at the bottom will wait for all threads to finish. </p> <p>In the worker method you can use arrays or lists of data from outside the method. So you can iterate...
2
2016-08-29T13:21:17Z
[ "python", "multithreading", "python-3.x" ]
How "generate " multiple TCP clients using Threads instead of opening multiple instances of the terminal and run the script several times?
39,005,901
<p>I wrote the code for a simple TCP client:</p> <pre><code>from socket import * # Configurações de conexão do servidor # O nome do servidor pode ser o endereço de # IP ou o domínio (ola.python.net) serverHost = 'localhost'#ip do servidor serverPort = 50008 # Mensagem a ser mandada codificada em bytes menssagem...
10
2016-08-17T20:39:55Z
39,224,893
<p>I have just wrapped your code/what you want to do, into a function i.e. <code>worker()</code>. Next, I have added extra code for <code>thread</code> spawning and set the <code>worker()</code> function as the <code>target</code> (the function/work/code each spawned thread will execute - this is why it's a convention ...
0
2016-08-30T10:23:32Z
[ "python", "multithreading", "python-3.x" ]
How "generate " multiple TCP clients using Threads instead of opening multiple instances of the terminal and run the script several times?
39,005,901
<p>I wrote the code for a simple TCP client:</p> <pre><code>from socket import * # Configurações de conexão do servidor # O nome do servidor pode ser o endereço de # IP ou o domínio (ola.python.net) serverHost = 'localhost'#ip do servidor serverPort = 50008 # Mensagem a ser mandada codificada em bytes menssagem...
10
2016-08-17T20:39:55Z
39,322,922
<p>Here is one solution with queues to send distinct messages.</p> <pre><code>#!/usr/bin/python import Queue import threading import time from socket import * DEF_HOST = 'localhost' DEF_PORT = 50008 queueLock = threading.Lock() class myThreadTCP (threading.Thread): def __init__(self, host=DEF_HOST, port=DE...
0
2016-09-05T01:34:45Z
[ "python", "multithreading", "python-3.x" ]
How "generate " multiple TCP clients using Threads instead of opening multiple instances of the terminal and run the script several times?
39,005,901
<p>I wrote the code for a simple TCP client:</p> <pre><code>from socket import * # Configurações de conexão do servidor # O nome do servidor pode ser o endereço de # IP ou o domínio (ola.python.net) serverHost = 'localhost'#ip do servidor serverPort = 50008 # Mensagem a ser mandada codificada em bytes menssagem...
10
2016-08-17T20:39:55Z
39,330,655
<p>The simplest and most pythonic way is to use <a href="https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.dummy" rel="nofollow">multiprocessing thread pool implementation</a>, and then call <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.map" rel="n...
0
2016-09-05T12:29:52Z
[ "python", "multithreading", "python-3.x" ]
Losе links at multiprocessing parsing on Python (selenium/phantomJS/ProcessPoolExecutor)
39,005,906
<p>(Sorry for my English) I want to make parser for some website with include a lot of JS scripts, for this I use selenium+phantomjs+lxml. Needs that this parser works fast, at least 1000 links per 1 hour. For this purpose I use multiprocessing (not Threading!! because GIL) and module Future, and ProcessExecutorPool. <...
0
2016-08-17T20:40:14Z
39,103,553
<p>I try, instead ProcessPoolExecutor - ThreadPoolExecutor, losing links stop. In Thread... case, speed approximately equal to Process. </p> <p>The question is actual, if you have some information about this, please write. Thanks.</p>
0
2016-08-23T14:08:58Z
[ "python", "parsing", "selenium-webdriver", "phantomjs", "multiprocessing" ]
How to get items in a list before and after a specified index
39,005,928
<p>Suppose I have the list <code>f=[1,2,3]</code> and index <code>i</code> -- I want to iterate over <code>f</code>, excluding <code>i</code>. Is there a way I can use <code>i</code> to split the list, something like <code>f[:i:]</code>, where I would be given a new list of <code>[1,3]</code> when ran with <code>i=1</c...
0
2016-08-17T20:42:04Z
39,006,006
<p>iterate y over the index:</p> <pre><code>f = [10,20,30,40,50,60] r = [x + f[y] for x in f for y in range(len(f)) if f[y] != x] </code></pre>
0
2016-08-17T20:47:53Z
[ "python", "python-2.7", "list-comprehension" ]
How to get items in a list before and after a specified index
39,005,928
<p>Suppose I have the list <code>f=[1,2,3]</code> and index <code>i</code> -- I want to iterate over <code>f</code>, excluding <code>i</code>. Is there a way I can use <code>i</code> to split the list, something like <code>f[:i:]</code>, where I would be given a new list of <code>[1,3]</code> when ran with <code>i=1</c...
0
2016-08-17T20:42:04Z
39,006,016
<p>Use <a href="https://docs.python.org/3/library/functions.html#enumerate" rel="nofollow"><code>enumerate()</code></a> in order to have access to index at iteration time.</p> <pre><code>[item for i, item in enumerate(f) if i != 3] </code></pre> <p>In this case you can escape the intended index or if you have a set o...
3
2016-08-17T20:48:39Z
[ "python", "python-2.7", "list-comprehension" ]
How to get items in a list before and after a specified index
39,005,928
<p>Suppose I have the list <code>f=[1,2,3]</code> and index <code>i</code> -- I want to iterate over <code>f</code>, excluding <code>i</code>. Is there a way I can use <code>i</code> to split the list, something like <code>f[:i:]</code>, where I would be given a new list of <code>[1,3]</code> when ran with <code>i=1</c...
0
2016-08-17T20:42:04Z
39,006,424
<p>Probably not the most elegant solution, but this might work:</p> <pre><code>f = [1,2,3,4,5] for i, x in enumerate(f): if i == 0: new_list = f[1:] elif i == len(f) -1: new_list = f[:-1] else: new_list = f[:i]+f[i+1:] print i, new_list </code></pre> <p>prints:</p> <pre><code...
0
2016-08-17T21:17:26Z
[ "python", "python-2.7", "list-comprehension" ]
How to get items in a list before and after a specified index
39,005,928
<p>Suppose I have the list <code>f=[1,2,3]</code> and index <code>i</code> -- I want to iterate over <code>f</code>, excluding <code>i</code>. Is there a way I can use <code>i</code> to split the list, something like <code>f[:i:]</code>, where I would be given a new list of <code>[1,3]</code> when ran with <code>i=1</c...
0
2016-08-17T20:42:04Z
39,006,848
<p>Well, it may seem scary but that's a one-liner that does the work:</p> <pre><code>&gt;&gt;&gt; from numpy import array &gt;&gt;&gt; import itertools &gt;&gt;&gt; list(itertools.chain(*(i+array(l) for i,l in zip(reversed(f), itertools.combinations(f, len(f)-1))))) [3, 4, 3, 5, 4, 5] </code></pre> <p>If you look at ...
0
2016-08-17T21:54:23Z
[ "python", "python-2.7", "list-comprehension" ]
WSGI flask problems 500 error
39,006,019
<p>I am trying to launch a flask program to an apache server and it works... kinda. I can access a test route that yields just a "hello" so I know that everything is configured correctly. However when I try to access any other part I get a 500 error. my first instinct was that there was a flaw in the program and it was...
-2
2016-08-17T20:48:43Z
39,006,179
<p>My guess is Apache is blocking the requests or doesn't forward them to your application. Since I am an Nginx user I don't know much about Apache configuration but here's what I found on the internet.</p> <pre><code>NameVirtualHost * &lt;VirtualHost *&gt; ServerName yourdomain.com ProxyRequests Off &lt;...
-1
2016-08-17T20:58:53Z
[ "python", "apache", "flask", "wsgi" ]
WSGI flask problems 500 error
39,006,019
<p>I am trying to launch a flask program to an apache server and it works... kinda. I can access a test route that yields just a "hello" so I know that everything is configured correctly. However when I try to access any other part I get a 500 error. my first instinct was that there was a flaw in the program and it was...
-2
2016-08-17T20:48:43Z
39,009,338
<p>The problem was that wgsi was eating my authentication. Not sure how I missed it but it happens I guess. Thanks for the help everyone. I had to include a tag to allow authentication to pass through.</p>
0
2016-08-18T03:03:12Z
[ "python", "apache", "flask", "wsgi" ]
How do I take 31 columns for days in pandas and group them into a single column?
39,006,055
<p>I have a very large file that I'm trying to reformat to run QC checks. The format is very strange how do I make it into a single column with a record for each date?</p> <p>current code is:</p> <pre><code>group = df.groupby(['ID','MONTH'], as_index = True).sum() </code></pre> <p>The dataframe looks like this befo...
1
2016-08-17T20:50:56Z
39,006,376
<p>You can <code>melt</code> the days.</p> <pre><code>df2 = pd.melt(df, id_vars=df.columns[:3].tolist(), var_name='day', value_vars=df.columns[3:].tolist()) df2['timestamp'] = pd.to_datetime(df2.MONTH.astype(str) + df2.day.astype(str), format='%Y%m%d') &gt;&gt;&gt; df2....
0
2016-08-17T21:13:38Z
[ "python", "python-2.7", "pandas" ]
Store compiled model in Keras?
39,006,100
<p>I'd like to use a Keras model in production but don't want to have to re-compile the model everytime I need to run it. Should I just pickle it, etc.?</p>
1
2016-08-17T20:54:14Z
39,260,993
<p>If all you want to do is predict (and not train in production) it is not necessary to compile the model.</p> <p>Source: <a href="https://github.com/fchollet/keras/issues/2621" rel="nofollow">https://github.com/fchollet/keras/issues/2621</a></p>
2
2016-09-01T00:28:12Z
[ "python", "neural-network", "keras" ]
Python: Pandas: Groupby & Pivot Tables are missing rows
39,006,133
<p>I have a dataframe composed of individuals (their ID's in), activities, and corresponding scores. I'm trying to get the sum of the scores when grouping by the student and an activity type. I can do this with the following:</p> <pre><code>data_detail.pivot_table(["total_scored","total_scored_omitted"], index = ["id"...
0
2016-08-17T20:56:36Z
39,006,134
<p>The problem is that the <strong><em>data type</em> for the scores wasn't consistent (and a float at that!).</strong> </p> <p>Some of them were strings. After I converted all of the scores into floats, the missing activities showed up.</p> <p>As an added benefit, having the datatypes be uniform, made the calculatio...
1
2016-08-17T20:56:36Z
[ "python", "debugging", "pandas", "dataframe", "pivot-table" ]
Converting a string of length 20 into a float of length 20
39,006,155
<p>I have some strings with numbers inside like '0.9999965341102361' and '3.465889763814134E-6'. I know how to convert them to a float value; however, when I do, they become 9.99996534e-01 and 3.46588976e-06. How can I preserve the full length of the number while still converting to a float? In other words, I don't wan...
0
2016-08-17T20:57:41Z
39,006,268
<p>You can't get better than your machine float, which is 64 bit or 32 bit. My linux laptop has 64 bit words, and the number is preserved:</p> <pre><code> In [6]: f = float('0.9999965341102361') In [7]: f Out[7]: 0.9999965341102361 In [8]: f2 = float('3.465889763814134E-6') In [9]: f2 Out[9]: 3.465889763814134e-06 ...
1
2016-08-17T21:05:17Z
[ "python", "python-3.x" ]
Converting a string of length 20 into a float of length 20
39,006,155
<p>I have some strings with numbers inside like '0.9999965341102361' and '3.465889763814134E-6'. I know how to convert them to a float value; however, when I do, they become 9.99996534e-01 and 3.46588976e-06. How can I preserve the full length of the number while still converting to a float? In other words, I don't wan...
0
2016-08-17T20:57:41Z
39,006,542
<p>Use the decimal module:</p> <pre><code>&gt;&gt;&gt; import decimal &gt;&gt;&gt; &gt;&gt;&gt; a = decimal.Decimal('0.9999965341102361') &gt;&gt;&gt; b = decimal.Decimal('3.465889763814134E-6') &gt;&gt;&gt; a Decimal('0.9999965341102361') &gt;&gt;&gt; b Decimal('0.000003465889763814134') &gt;&gt;&gt; a*10 Decimal('9...
2
2016-08-17T21:26:09Z
[ "python", "python-3.x" ]
Matplotlib - imshow subsplots overlapping
39,006,248
<p>So I'm trying to display a collection of imshow (heatmap) subplots on a single figure, side by side and row by row. As a prelim I am testing just displaying 2 fine, and experiencing issues. </p> <p>See code below:</p> <pre><code>axes = [] fig = plt.figure()#figsize=(10,5)) idx = 0 for symbol in ['EURUSD','GBPUSD...
1
2016-08-17T21:03:43Z
39,006,389
<p>I believe it should be <code>add_subplot(1, 2, idx+1)</code>. That is the subplot is defined by number of rows, then number of cols, and then the region ordinal.</p> <p>Aside from this problem, you might want to "pythonize" your code a bit by auto indexing like this:</p> <pre><code>for idx, symbol in enumerate(['E...
1
2016-08-17T21:14:01Z
[ "python", "matplotlib" ]
How to convert a set of features to a count matrix in pandas
39,006,270
<p>Given a matrix </p> <p>----<code>d1 d2 d3 a: v1 0 v2 b: v1 v3 0</code></p> <p>I want </p> <p>----<code>v1 v2 v3 a: 1 1 0 b: 1 0 1</code></p> <p>I remember vaguely that this can be done with <code>Gensim</code>...but there must also be some module in pandas? I have tried to do <code>for v in v: for ...
1
2016-08-17T21:05:21Z
39,006,865
<p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.get_dummies.html" rel="nofollow"><code>pandas.get_dummies</code></a>, e.g.</p> <pre><code>import pandas as pd # create your dataframe df = pd.DataFrame(index=['a', 'b'], data={'d1': ['v1', 'v1'], ...
3
2016-08-17T21:56:07Z
[ "python", "pandas", "gensim" ]
How to convert a set of features to a count matrix in pandas
39,006,270
<p>Given a matrix </p> <p>----<code>d1 d2 d3 a: v1 0 v2 b: v1 v3 0</code></p> <p>I want </p> <p>----<code>v1 v2 v3 a: 1 1 0 b: 1 0 1</code></p> <p>I remember vaguely that this can be done with <code>Gensim</code>...but there must also be some module in pandas? I have tried to do <code>for v in v: for ...
1
2016-08-17T21:05:21Z
39,007,052
<p>Start with your DataFrame <code>DF</code>, with <code>0</code> replaced with <code>NaN</code></p> <pre><code>DF=ps.DataFrame({'d1':['v1','v1'],'d2':[NaN,'v3'],'d3':['v2',NaN]},index=['a','b']) </code></pre> <p>Get the unique values you want to count:</p> <pre><code>Vals=DF.stack().unique() </code></pre> <p>use s...
1
2016-08-17T22:12:33Z
[ "python", "pandas", "gensim" ]
Infinite loop in python - why?
39,006,344
<p>I'm using the code</p> <pre><code>fibList=[1] def fib(n1, n2): n3 = n1+n2 n1=n2 n2=n3 num1=1 num2=2 while(num2&lt;4000000): fib(num1,num2) if (num2%2==0): fibList.append(num2) total = sum(fibList) print total </code></pre> <p>in an online compiler, repl.it. It was going and ...
0
2016-08-17T21:10:57Z
39,006,390
<p><code>n1</code>, <code>n2</code> and <code>n3</code> are local variables and have nothing in common with <code>num1</code> and <code>num2</code> in the outer scope, despite their initial value. You have to <code>return</code> the value and assign these results to <code>num1</code> and <code>num2</code> again.</p> <...
6
2016-08-17T21:14:02Z
[ "python" ]
How I can make my db add codes for users to register with one of the codes ? (Python-Django)
39,006,439
<p>I want to put a number of codes in my database so that when a user wants to register my application need to enter a code of those who are in the database, so that the system registry access.</p> <p>All this in django, but honestly I have no idea how to do it, if you can help me, I would appreciate it very much.</p>...
0
2016-08-17T21:18:30Z
39,006,758
<p>There are a couple of steps that you will need to do, but essentially you are just seeding the DB with valid registration codes. To generate a number of registration codes you can use the following, I limit the number to 1000 but this can be changed</p> <pre><code>import uuid codes = set() num_codes = 1000 while...
0
2016-08-17T21:44:47Z
[ "python", "django" ]
Saving averages in text file
39,006,474
<p>I am making an average calculator in python, i have to save the averages in a text file and have done it like this:</p> <pre><code>Mean = statistics.mean(aver) Mode = statistics.mode(aver) Medi = statistics.median(aver) file = open("Averages.txt", "a") file.write("\n\nYour numbers are" + aver + "\nMean ...
1
2016-08-17T21:21:18Z
39,006,548
<pre><code>file.write("\n\nYour numbers are" + **aver** + </code></pre> <p>this would be better as something like this:</p> <pre><code>aver = " " + ", ".join(aver) + " " </code></pre> <p>which converts your list to a comma separated string.</p>
1
2016-08-17T21:26:48Z
[ "python", "list", "average" ]
How to use localtime (HH:MM) in if statement - python
39,006,475
<p>I made some code to turn on a light depending on movement and the time of the day in an if statement. If the (local)time is between sunrise and a preset time or sunset and a preset time the if statement is true and the motion detection statements will follow. </p> <p>At the moment the time is only presented in hour...
0
2016-08-17T21:21:19Z
39,006,851
<p>Do all calculations with <code>datetime</code>-objects:</p> <pre><code>import RPi.GPIO as GPIO import time import urllib2 import json from datetime import datetime from business_calendar import Calendar, MO, TU, WE, TH, FR from pytz import timezone, utc local_timezone = timezone('Europe/Amsterdam') print "Here we...
1
2016-08-17T21:54:33Z
[ "python", "python-2.7", "if-statement", "localtime" ]
How to use localtime (HH:MM) in if statement - python
39,006,475
<p>I made some code to turn on a light depending on movement and the time of the day in an if statement. If the (local)time is between sunrise and a preset time or sunset and a preset time the if statement is true and the motion detection statements will follow. </p> <p>At the moment the time is only presented in hour...
0
2016-08-17T21:21:19Z
39,006,860
<p>I no longer use the builtin <code>datetime</code> lib it sucks. Look into <code>arrow</code> <a href="http://crsmithdev.com/arrow/" rel="nofollow">http://crsmithdev.com/arrow/</a></p> <p>just one tip.</p> <p>Also look into using <code>requests</code> its the defacto way of doing http stuff in python.</p> <p>I hav...
0
2016-08-17T21:55:27Z
[ "python", "python-2.7", "if-statement", "localtime" ]
Unicode error in `str.format()`
39,006,484
<p>I am trying to run the following script, which scans for <code>*.csproj</code> files and checks for project dependencies in Visual Studio solutions, but I am getting the following error. I have already tried all sorts of <code>codec</code> and <code>encode/decode</code> and <code>u''</code> combination, to no avail....
0
2016-08-17T21:21:45Z
39,006,764
<p>When Python 2.x tries to use a byte string in a Unicode context, it automatically tries to <code>decode</code> the byte string to a Unicode string using the <code>ascii</code> codec. While the <code>ascii</code> codec is a safe choice, it often doesn't work.</p> <p>For Windows environments the <code>mbcs</code> cod...
1
2016-08-17T21:45:25Z
[ "python", "unicode", "encoding", "python-unicode" ]
Remove documents from a collection based on value located in another collection
39,006,486
<p>I started working with mongodb yesterday. I have two collections in the same database with 100 million and 300 million documents. I want to remove documents in one collection if a value in the document is not found in any document of the second collection. To maybe make this more clear I have provided python/mongodb...
0
2016-08-17T21:21:53Z
39,006,667
<p>If <code>document["arbitrary"]</code> is a immuable value, you can store all the values (without duplicates) in a <code>set</code>:</p> <p>values = {document["arbitrary"] for document in db.collection_TWO}</p> <p>The process like you suggest:</p> <pre><code>for doc_one in db.collection_ONE: if doc_one["arbitr...
0
2016-08-17T21:36:21Z
[ "python", "mongodb" ]
On linux, how can I allow any user to write to a file, but only by running my (python) script?
39,006,562
<p>I'm working on a GUI for managing the contents of a specific network folder. The files are created/deleted and moved by a script.</p> <p>I have a json index file that has information about the files in this folder.</p> <p>Is there a way to give all users write permission to these files, but only if they use my scr...
1
2016-08-17T21:28:04Z
39,007,077
<p>You can specify this type of thing using visudo.</p> <p>From: <a href="http://www.atrixnet.com/allow-an-unprivileged-user-to-run-a-certain-command-with-sudo/" rel="nofollow">http://www.atrixnet.com/allow-an-unprivileged-user-to-run-a-certain-command-with-sudo/</a></p> <p>First, you’ll need to use the visudo util...
1
2016-08-17T22:13:55Z
[ "python", "linux" ]
On linux, how can I allow any user to write to a file, but only by running my (python) script?
39,006,562
<p>I'm working on a GUI for managing the contents of a specific network folder. The files are created/deleted and moved by a script.</p> <p>I have a json index file that has information about the files in this folder.</p> <p>Is there a way to give all users write permission to these files, but only if they use my scr...
1
2016-08-17T21:28:04Z
39,007,109
<p>You're program needs the the SUID bit set <a href="https://en.wikipedia.org/wiki/Setuid" rel="nofollow">https://en.wikipedia.org/wiki/Setuid</a>. I'm not sure if this can be done with a python script.</p>
0
2016-08-17T22:16:50Z
[ "python", "linux" ]
search for variable from list write line to file
39,006,599
<p>When going through a list with <code>for x in list</code>, I am having a problem with:</p> <pre><code>if x in Invalid_names_file: ISP_names_file.write(str(x)) </code></pre> <p>If I replace <code>if</code> with <code>for</code> then I get the entire contents of <code>Invalid_names_file</code> written into <code...
0
2016-08-17T21:31:38Z
39,006,694
<p><code>Invalid_names_file</code> is an iterator. So after first <code>if x in ...</code> this iterator is empty and all following tests results in <code>False</code>. Read your file into a list first and then test each line with the <code>in</code> operator and not only the list elements.</p> <pre><code>def isp_emai...
0
2016-08-17T21:39:35Z
[ "python" ]
search for variable from list write line to file
39,006,599
<p>When going through a list with <code>for x in list</code>, I am having a problem with:</p> <pre><code>if x in Invalid_names_file: ISP_names_file.write(str(x)) </code></pre> <p>If I replace <code>if</code> with <code>for</code> then I get the entire contents of <code>Invalid_names_file</code> written into <code...
0
2016-08-17T21:31:38Z
39,006,750
<p>A not so elegant solution, running in O(N) run time, but having it check in regards to if x is contained in a readline. Sorry in advance for the not so elegant solution and hope it works.</p> <pre><code>def isp_email_names(): with open('Invalid_names_file', 'r') as Invalid_names_file: with open('ISP_nam...
0
2016-08-17T21:44:15Z
[ "python" ]
search for variable from list write line to file
39,006,599
<p>When going through a list with <code>for x in list</code>, I am having a problem with:</p> <pre><code>if x in Invalid_names_file: ISP_names_file.write(str(x)) </code></pre> <p>If I replace <code>if</code> with <code>for</code> then I get the entire contents of <code>Invalid_names_file</code> written into <code...
0
2016-08-17T21:31:38Z
39,023,805
<p>final code that works-></p> <pre><code>def isp_email_names(): with open('Invalid_names_file', 'r') as Invalid_names_file: with open('ISP_names_file', 'w') as ISP_names_file: for x in one_ip_each(): for line in Invalid_names_file: if x in line: ...
0
2016-08-18T17:03:43Z
[ "python" ]
Automatic Legend Placement in Bokeh
39,006,611
<p>Does Bokeh have the functionality to automatically position a legend in a plot, <a href="http://matplotlib.org/1.3.0/examples/pylab_examples/legend_auto.html" rel="nofollow">similar to Matplotlib</a>?</p>
0
2016-08-17T21:32:17Z
39,006,816
<p>Yes. Just set the legend.location attribute as one of the enumerable locations (i.e. 'top_left' or 'bottom_right'):</p> <p><a href="http://bokeh.pydata.org/en/latest/docs/reference/models/annotations.html#bokeh.models.annotations.Legend.location" rel="nofollow">http://bokeh.pydata.org/en/latest/docs/reference/model...
0
2016-08-17T21:51:14Z
[ "python", "bokeh" ]
Splitting a list of file names in a predefined ratio
39,006,647
<p>I am trying to form an optimized approach to splitting a list of file names(examples shortly) in a x:y ratio based on the file names. This file list was procured using os.scandir (better performance vs os.listdir, src: <a href="https://docs.python.org/3.5/library/os.html#os.scandir" rel="nofollow">Python Docs scandi...
-2
2016-08-17T21:34:57Z
39,007,920
<p>If I understand the situation correctly, your trying to partition the same proportion of each filename prefix's files. Your current method selects the correct proportion from the whole set of files, but it doesn't consider the different filename prefixes, so it may not get them in the correct proportion (though it w...
0
2016-08-17T23:49:26Z
[ "python", "list" ]
Splitting a list of file names in a predefined ratio
39,006,647
<p>I am trying to form an optimized approach to splitting a list of file names(examples shortly) in a x:y ratio based on the file names. This file list was procured using os.scandir (better performance vs os.listdir, src: <a href="https://docs.python.org/3.5/library/os.html#os.scandir" rel="nofollow">Python Docs scandi...
-2
2016-08-17T21:34:57Z
39,237,188
<p>I figured out a good solution to this problem.</p> <pre><code>all_file_names = {} # ObjList is a list of objects but we only need # file_name from that object for our solution for x in ObjList: if x.file_name not in all_file_names: all_file_names[x.file_name] = 1 else: all_file_names[x.f...
0
2016-08-30T21:14:00Z
[ "python", "list" ]
If statement always True Jinja2 Template
39,006,653
<p>I'm not sure what exactly the problem is but the concept is when my function execute it should fetch a query list from database and if It doesnt contain any object it should return False and the else part should execute</p> <p>The first part works but even when my database is empty it passes True,</p> <pre><code>{...
0
2016-08-17T21:35:27Z
39,006,974
<p>The problem is that a query is lazy, i.e., it doesn't execute until you begin iterating over it. Therefore it has no idea how many records are in it at the point you're testing its truthiness. By default most objects in Python are truthy, and this applies to queries as well.</p> <p>To work around this, use:</p> <p...
1
2016-08-17T22:04:58Z
[ "python", "model-view-controller", "flask", "jinja2", "backend" ]
How to get all of the "ids" within a python array
39,006,669
<p>So I am pulling some json data using an API and it initially looks like this:</p> <pre><code>{ "result": { "elements": [ { "id": "SV_3s0FmbrNancSmsB", "name": "Test Survey", "ownerId": "sdfsdfasdf", "lastModified": "2016-08-09T21:33:27Z", "isActive": false }, { "id": "SV_dgJOVyJvwZR05...
0
2016-08-17T21:36:54Z
39,006,696
<p>This should work. Im sure there is a more elegant way with map or list comprehension.</p> <pre><code>ids = [] for elem in data['result']['elements']: ids.append(elem['id']) </code></pre> <p>If you want to evaluate this lazily, make a generator comprehension!</p> <p><code>ids = (element['id'] for element in da...
1
2016-08-17T21:39:52Z
[ "python", "arrays", "json" ]
How to get all of the "ids" within a python array
39,006,669
<p>So I am pulling some json data using an API and it initially looks like this:</p> <pre><code>{ "result": { "elements": [ { "id": "SV_3s0FmbrNancSmsB", "name": "Test Survey", "ownerId": "sdfsdfasdf", "lastModified": "2016-08-09T21:33:27Z", "isActive": false }, { "id": "SV_dgJOVyJvwZR05...
0
2016-08-17T21:36:54Z
39,006,699
<p>You can use this oneliner:</p> <pre><code>ids = [element['id'] for element in data['result']['elements']] </code></pre>
2
2016-08-17T21:40:01Z
[ "python", "arrays", "json" ]
How to get all of the "ids" within a python array
39,006,669
<p>So I am pulling some json data using an API and it initially looks like this:</p> <pre><code>{ "result": { "elements": [ { "id": "SV_3s0FmbrNancSmsB", "name": "Test Survey", "ownerId": "sdfsdfasdf", "lastModified": "2016-08-09T21:33:27Z", "isActive": false }, { "id": "SV_dgJOVyJvwZR05...
0
2016-08-17T21:36:54Z
39,006,714
<p>How about:</p> <pre><code>ids = [element['id'] for element in data['result']['elements']] </code></pre>
2
2016-08-17T21:40:55Z
[ "python", "arrays", "json" ]
deploying kik bot to heroku not working
39,006,692
<p>I've been trying to deploy my kik api to heroku, but it just isn't working. I've set up my procfile, my requirements.txt file, my runtime.txt file, and it shows up on my machine as running fine. However, when I open the kik app on my phone and try to message the bot, the messages aren't sent and it is not echoing my...
0
2016-08-17T21:39:28Z
39,021,935
<p>I figured out the issue. I had set the wrong environmental variables for my heroku deployment, so it threw a keyerror because it couldn't find the key and stopped the process. </p>
0
2016-08-18T15:20:15Z
[ "python", "heroku", "flask", "bots", "kik" ]
Return multiple instances from an object in python
39,006,706
<p>This question has no doubt been asked before, but I am not entirely sure how to search for it (since I do not know what it is called). So apologies in advance.</p> <p>Alas, my problem is that I have a huge amount of objects </p> <pre><code>for i in range(1000): M = subParts[0].get(parts['thing'][i]) </code></p...
2
2016-08-17T21:40:32Z
39,006,790
<pre><code>def getdata(m): return [m.getItem1(), m.getItem2(), m.getItem3(), m.getItem4()] myDict = {i: getdata(subParts[0].get(parts['thing'][i])) for i in range(1000)} </code></pre>
3
2016-08-17T21:48:03Z
[ "python", "dictionary", "optimization" ]
Return multiple instances from an object in python
39,006,706
<p>This question has no doubt been asked before, but I am not entirely sure how to search for it (since I do not know what it is called). So apologies in advance.</p> <p>Alas, my problem is that I have a huge amount of objects </p> <pre><code>for i in range(1000): M = subParts[0].get(parts['thing'][i]) </code></p...
2
2016-08-17T21:40:32Z
39,006,958
<p>Assuming that <code>parts['thing']</code> is an ordered sequence that can be iterated over, you can use <code>map</code> to call <code>subParts[0].get</code> on each element of <code>parts['thing']</code> so iterating over each <code>M</code> object could be done like this:</p> <pre><code>for M in map(subParts[0].g...
1
2016-08-17T22:03:13Z
[ "python", "dictionary", "optimization" ]
Implement dragMoveEvent on QWidget in pyqt5?
39,006,733
<p>does anyone know how I can implement the dragMove event on my QWidget? So basically what I want is to move my mouse over the Widget hold down my mouse button and drag it. While dragging, the widget should not be moved it should only capture the mouse coordinates while the mouse is pressed.</p> <p>I have already goo...
1
2016-08-17T21:42:50Z
39,012,849
<p>I think you are looking for <a href="http://doc.qt.io/qt-5/qwidget.html#mousePressEvent" rel="nofollow">mousePressEvent</a> rather than <a href="http://doc.qt.io/qt-5/qwidget.html#dragMoveEvent" rel="nofollow">dragMoveEvent</a>. You would need to subclass <code>QWidget</code> and implement the <code>mousePressEvent<...
0
2016-08-18T08:02:45Z
[ "python", "user-interface", "pyqt", "pyqt5" ]
Implement dragMoveEvent on QWidget in pyqt5?
39,006,733
<p>does anyone know how I can implement the dragMove event on my QWidget? So basically what I want is to move my mouse over the Widget hold down my mouse button and drag it. While dragging, the widget should not be moved it should only capture the mouse coordinates while the mouse is pressed.</p> <p>I have already goo...
1
2016-08-17T21:42:50Z
39,030,627
<p>This has got nothing to do with dragging. What you actually need to do is enable mouse-tracking and then monitor mouse-move events.</p> <p>Here's a simple demo:</p> <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets class Window(QtWidgets.QWidget): def __init__(self): super(Window, self).__init__()...
0
2016-08-19T03:23:56Z
[ "python", "user-interface", "pyqt", "pyqt5" ]
How can I access the data in an XML node when using ElementTree
39,006,735
<p>i am parsing the XML located at this link:</p> <p><a href="http://python-data.dr-chuck.net/comments_42.xml" rel="nofollow">XML File to Parse</a></p> <p>I need to access the data inside the node and it seems like the program I have written is telling me that there is nothing inside the node. Here is my code:</p> ...
0
2016-08-17T21:42:58Z
39,011,824
<p>A few comments on your approaches:</p> <blockquote> <pre><code>for count in comments.findall('count'): print comments.find('count').text </code></pre> </blockquote> <p><code>comments.findall('count')</code> returns an empty list because <code>comments</code> does not have any immediate child elements with the ...
1
2016-08-18T07:01:56Z
[ "python", "xml", "xml-parsing", "string-parsing" ]
Matching a Pattern in a Region in Sikuli is very slow
39,006,769
<p>I am automating a computer game using Sikuli as a hobby project and to hopefully get good enough to make scripts to help me at my job. In a certain small region, (20x20 pixels) one of 15 characters will appear. Right now I have these 15 images defined as variables, and then using an <code>if</code>, <code>elif</code...
1
2016-08-17T21:45:52Z
39,008,510
<p>Sikuli operates by scanning a Screen or a part of a screen and attempting to match a set pattern. Naturally, the smaller the pattern is, the more time it will consume to match it. There few ways to improve the detection time:</p> <ol> <li>Region and Pattern manipulation (bound region size)</li> <li>Functions settin...
1
2016-08-18T01:16:01Z
[ "python", "automation", "ocr", "sikuli", "sikuli-ide" ]
XGBoost installation via Anaconda 1.5.1 fails on OS X
39,006,804
<p>I have GCC installed via Homebrew using <code>brew install gcc --without-multilib</code>. When I tried to use <code>pip install xgboost</code> in Anaconda 1.5.1 on OS X El Capitan 10.11.6 and Conda 4.1.11 running Python 3.5.2, I get the following output and error:</p> <pre><code>Collecting xgboost Using cached x...
0
2016-08-17T21:50:32Z
39,007,799
<p>I solved this by following the <a href="https://github.com/dmlc/xgboost/blob/master/doc/build.md" rel="nofollow">Python Package Installation instructions.</a> I now have the package without a pip installation.</p>
0
2016-08-17T23:34:31Z
[ "python", "anaconda" ]
Why does this code not work for all inputs
39,006,826
<p>I am trying to write python code that takes two strings as input and checks if all the characters of the second string are present in the first string. If so, then the output is the second string. If not, the output is the string "This does not work". I have tested this procedure for a variety of inputs, and it typi...
0
2016-08-17T21:52:18Z
39,006,981
<p>You could do this as a more elegant solution, assuming that you strictly want all of the second string characters to be present in first.</p> <pre><code>def fix_machine(first, second): for character in second: if character not in first: return False return second </code></pre> <p>This r...
0
2016-08-17T22:05:30Z
[ "python" ]
Why does this code not work for all inputs
39,006,826
<p>I am trying to write python code that takes two strings as input and checks if all the characters of the second string are present in the first string. If so, then the output is the second string. If not, the output is the string "This does not work". I have tested this procedure for a variety of inputs, and it typi...
0
2016-08-17T21:52:18Z
39,006,986
<p>As far as I understood you just want to compare two strings containing different characters.</p> <p>For doing so, I would suggest converting both strings to a <code>set</code> which then provides (in contrast to a <code>list</code>) order-less comparison of its elements.</p> <pre><code>def check_string(first_str, ...
0
2016-08-17T22:05:41Z
[ "python" ]
Why does this code not work for all inputs
39,006,826
<p>I am trying to write python code that takes two strings as input and checks if all the characters of the second string are present in the first string. If so, then the output is the second string. If not, the output is the string "This does not work". I have tested this procedure for a variety of inputs, and it typi...
0
2016-08-17T21:52:18Z
39,007,038
<p>I agree that you should step through that code with a debugger (maybe try PyCharm if you don't have an IDE set up yet) to see what went wrong. Would be hard to explain whats going wrong but I think it has something to do with <code>first_element = product[0:n]</code>. This will return increasingly larger segments of...
0
2016-08-17T22:11:09Z
[ "python" ]
python-docx add horizontal line
39,006,878
<p>Is it possible to add a single horizontal line spanning the entire page width after a paragraph?</p> <p>By using the <code>add_header</code> such a line is created after the header:</p> <pre><code> document.add_heading('Test', 0) </code></pre> <p>I'd need such a line between two paragraphs in the document, so is...
0
2016-08-17T21:57:11Z
39,009,362
<p>This is not supported directly yet by the <code>python-docx</code> API.</p> <p>However, you can achieve this effect by creating a paragraph style that has this border setting in the "template" document you open to create a new document, e.g.</p> <pre><code>document = Document('template-with-style.docx') </code></p...
1
2016-08-18T03:05:49Z
[ "python", "python-docx" ]
Display python data on node.js when python is still running
39,006,939
<p>I have a long running python script, and I want to use a node.js to display the data python prints(becasue I will make it a server and send data to somewhere else), I used python-shell, it doesn't display anything until the whole python finished, it there any way to display 'partial' output?</p> <pre><code>var pshe...
0
2016-08-17T22:01:45Z
39,007,825
<p>The easiest way is to setup a server with node js and just send requests with the data that is suppose to be printed. I am giving this solution of course in the prior knowledge that you have control of what is printed. ( You didn't mention if the output is coming from a script that you wrote or it is coming from ano...
0
2016-08-17T23:37:13Z
[ "javascript", "python", "node.js" ]
Django url not found upon submitting form
39,006,956
<p>My apologies if the question is stupid, I am a newbie to this. I am creating a django web application. I have created a form inside it. When I submit the form, it says 'url' not found even though the same URL loads fine for the first time when opening the form. This is whats confusing me. Here is my code:</p> <pre>...
0
2016-08-17T22:03:10Z
39,007,250
<p>You have <code>action="/create_recipe_rule/"</code>, which is missing the recipe id.</p> <p>One option is to simply remove the action from the form, then your browser will submit the request to the current url.</p> <pre><code>&lt;form method="post"&gt; </code></pre> <p>If you do want to include the form action, t...
1
2016-08-17T22:31:53Z
[ "python", "django", "forms" ]
error of no log results dumped to file by running an executable file from Python subprosess
39,006,982
<p>This question is related to my previous question.</p> <p><a href="http://stackoverflow.com/questions/38928330/error-of-running-an-executable-file-from-python-subprosess">Error of running an executable file from Python subprosess</a></p> <p>I am trying to run an executable file (a linear programming solver CLP.exe)...
0
2016-08-17T22:05:37Z
39,007,186
<p>You can replace your default stdout descriptor with your log file descriptor. Try this</p> <pre><code>with open('log.txt', 'w+') s fid: subprocess.check_call([arg1,...,arg8],stdout = fid, stderr=subprocess.STDOUT, shell = False) </code></pre>
0
2016-08-17T22:25:30Z
[ "python", "python-3.x", "subprocess", "pydev" ]
Python flask: how to avoid users from browsing static directory
39,006,985
<p>I followed digital ocean <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps" rel="nofollow">tutorial</a> to deploy my Flask application using Apache server. Now the problem is when a user visits <code>mywebsite.com/static</code>, all the files in the static d...
0
2016-08-17T22:05:40Z
39,007,113
<p>You can prevent generation of directory indexes with the <code>Option -Indexes</code> directive:</p> <pre><code> &lt;Directory /var/www/FlaskApp/FlaskApp/static/&gt; Order allow,deny Allow from all Options -Indexes &lt;/Directory&gt; </code></pre> <p>Alternatively, you can place the ...
0
2016-08-17T22:16:58Z
[ "python", "apache" ]
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"username"}
39,007,011
<p>Here's the method I wrote with selenium to login to my webpage:</p> <pre><code>def login(self, username, password): driver.switch_to.default_content() driver.switch_to.frame("iframe") driver.find_element_by_id("username").send_keys(username) driver.find_element_by_id("password").send_keys(password) ...
-2
2016-08-17T22:08:29Z
39,009,429
<p>I would have guessed that repeating the line <code>driver.switch_to.frame("iframe")</code> a few times would have worked. Technically that id is not unique on the page so I would try using an index instead. From the HTML you provided, it looks like the <code>IFRAME</code> you want is the first one each time. The bel...
0
2016-08-18T03:14:02Z
[ "python", "selenium", "robotframework" ]