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
python imshow, set certain value to defined color
37,719,304
<p>I have a RGB Image, which I plot with matplotlib.pyplot.imshow and it works fine. But now I want to change the plot, that where the value of the picture is e.g 1, the color of the plot should change to white at all this positions.</p> <p>Is there a way to do this?</p>
0
2016-06-09T07:20:34Z
37,720,602
<p>Assuming that your image is a single-channel image rather than a three-channel image, the required task can be performed by defining a palette that maps indices (e.g. gray level intensities or picture values) into colors:</p> <pre><code>import numpy as np palette = np.array([[ 0, 0, 0], # black ...
0
2016-06-09T08:27:11Z
[ "python", "image", "colors", "imshow" ]
Running all test files in python from one function using "assert" without exiting "for loop" on test failure
37,719,570
<p>I am working on test runner which reads ".test" file from a given directory.</p> <p>Structure of ".test" is:</p> <pre><code>---TEMPLATE--- template content ---CONTEXT--- context to render on template ---RESULT--- expected result of the template. </code></pre> <p>There are 'n' no. of test file in my test directory...
1
2016-06-09T07:32:23Z
37,723,315
<p>You can follow below code of snippet to solve your problem.</p> <pre><code>suite = unittest.TestSuite() def test_main(self): self.assertEquals(self.result, self.expected_output) def test_method(self): """ """ # -- code to get tests objects to have all .tests content for index, fname in tests....
1
2016-06-09T10:24:34Z
[ "python", "unit-testing", "travis-ci", "testcase" ]
Detecting Peaks in a FFT Plot
37,719,613
<p>I was wondering how is it possible to detect new peaks within an FFT plot in Python. let's say i have this simple Plot:<a href="http://i.stack.imgur.com/V8d5V.png" rel="nofollow"><img src="http://i.stack.imgur.com/V8d5V.png" alt="enter image description here"></a> And i want to automatically measure the 'Similarity'...
2
2016-06-09T07:34:39Z
37,720,267
<p>There are many ways to find peaks, and even to interpolate their sub-sample location. Once you have the peaks, just check if you find a new one.</p> <p>You can use the <a href="https://pypi.python.org/pypi/PeakUtils" rel="nofollow"><code>peakutils</code></a> package to find the peaks. You can set there the threshol...
1
2016-06-09T08:10:16Z
[ "python", "python-2.7", "plot", "fft", "similarity" ]
Pyfst installation on windows 7 fails
37,719,652
<p>I have been struggling to install <a href="http://pyfst.github.io/" rel="nofollow">Pyfst</a> for days. After resolving the issue with vcvarsall and installing Visual Studio C++ tools, I ran into another issue, for which I cannot find the answer online (for <strong>Windows 7</strong>). I am trying to install it with ...
0
2016-06-09T07:36:32Z
38,538,842
<p>You might have better luck using the Python bindings that are included in OpenFST 1.5+.</p> <p><a href="http://www.openfst.org/twiki/bin/view/FST/PythonExtension" rel="nofollow">http://www.openfst.org/twiki/bin/view/FST/PythonExtension</a></p>
0
2016-07-23T06:22:18Z
[ "python", "pycharm", "openfst" ]
Flask app : The requested URL was not found on the server
37,719,685
<p>Why doesn't my add function work?</p> <pre><code>from flask import Flask from flask import request app = Flask(__name__) @app.route('/') @app.route('/&lt;name&gt;') def index(name="Mona"): #name= request.args.get('name', name) return "Hello from {}".format(name) @app.route('/add/num1/num2') def add(num1, nu...
-1
2016-06-09T07:38:31Z
37,719,797
<p>Changed the add method to the following and now it is working:</p> <pre><code>@app.route('/add/&lt;int:num1&gt;/&lt;int:num2&gt;') def add(num1, num2): return '{} + {} = {}'.format(num1, num2, num1 + num2) </code></pre> <p>Update: On a further note, if you want not to receive 404 error when entering floats, he...
1
2016-06-09T07:45:00Z
[ "python", "python-3.x", "flask" ]
how to read files from multiple folders in python
37,719,833
<p>my folder organization looks like below. Type 1 and Type 2 folders contains same files but I want to only read the files from 'type 2' folder. Is there any simple way to do that?</p> <p>I have used this code but not able to read: </p> <pre><code>for file in os.listdir('Type 2'): print file </code></pre> <p><a...
1
2016-06-09T07:46:34Z
37,719,925
<p>IIUC you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow"><code>read_csv</code></a> in folders <code>Type 2</code>, use <a href="https://docs.python.org/3/library/glob.html#glob.glob" rel="nofollow"><code>glob</code></a>:</p> <pre><code>files = glob.glob('main...
2
2016-06-09T07:52:03Z
[ "python", "file", "pandas", "dataframe", "folders" ]
Linear optimizations model with specified types for variable
37,719,873
<p>Is there any implementation of linear optimization model in python which allows explicitly define the types of my variables. For example I want my variable to be only integers. I can define this when using lpSolve in R like:</p> <pre><code> set.type(model, 1:18,type = "integer") </code></pre> <p>but I need to b...
1
2016-06-09T07:49:18Z
37,721,526
<p>Since IP (Integer Programming) and LP (Linear Programming) are solved with very different algorithms it's legitimate that some solvers don't allow to mix both (IMO): IP has an exponential complexity and LP a polynomial complexity. Your problem is a MILP (Mixed Integer Linear Programming) which has thus an exponentia...
2
2016-06-09T09:09:25Z
[ "python", "optimization", "scipy", "lpsolve" ]
How to form a matrix from submatrices?
37,719,889
<p>Let's say that I have these 4 submatrices:</p> <pre><code>print(A[0]) print(A[1]) print(A[2]) print(A[3]) [[ 0. 1. 2.] [ 6. 7. 8.] [ 12. 13. 14.]] [[ 3. 4. 5.] [ 9. 10. 11.] [ 15. 16. 17.]] [[ 18. 19. 20.] [ 24. 25. 26.] [ 30. 31. 32.]] [[ 21. 22. 23.] [ 27. 28. 29.] [ 33. ...
1
2016-06-09T07:49:56Z
37,720,193
<p>With <code>A</code> as the input array containing those sub-matrices, you could use some <code>reshaping</code> and permute dimensions with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.transpose.html" rel="nofollow"><code>np.transpose</code></a>, like so -</p> <pre><code>A.reshape(2,2,3...
1
2016-06-09T08:05:49Z
[ "python", "arrays", "numpy", "matrix", "vector" ]
Ansible: How to inform a python script about the outcome of a task?
37,719,943
<p>I have simple playbook to fetch and copy files from a share to remote windows clients:</p> <pre><code>- name: Test chocolatey module hosts: win_clones vars_files: - /fullpath/hosts_vars tasks: - name: Fetching and copying the file on the client ... win_get_url: url: 'ftp://172.20.0.5/choco...
1
2016-06-09T07:53:05Z
37,723,194
<p>You can set <code>stdout_callback = json</code> via <a href="http://docs.ansible.com/ansible/intro_configuration.html#stdout-callback" rel="nofollow">configuration</a> file or env variable <code>ANSIBLE_STDOUT_CALLBACK</code>.<br> <code>ansible-playbook</code> will print huge json file with execution result to stdou...
2
2016-06-09T10:19:57Z
[ "python", "ansible" ]
Ansible: How to inform a python script about the outcome of a task?
37,719,943
<p>I have simple playbook to fetch and copy files from a share to remote windows clients:</p> <pre><code>- name: Test chocolatey module hosts: win_clones vars_files: - /fullpath/hosts_vars tasks: - name: Fetching and copying the file on the client ... win_get_url: url: 'ftp://172.20.0.5/choco...
1
2016-06-09T07:53:05Z
37,725,206
<p>You can run the playbook from the Python API (though it's more code and Ansible doesn't officially support it for external callers). Use the example from <a href="http://docs.ansible.com/ansible/developing_api.html#python-api-2-0" rel="nofollow">Python API 2.0</a> as a baseline, and instead of loading a play, load ...
2
2016-06-09T11:51:38Z
[ "python", "ansible" ]
Memory usage for transformation on RDD's in alluxio/tachyon for spark
37,719,969
<p>Lets say we create an RDD from alluxio memory</p> <pre><code>rdd1 = sc.textFile("alluxio://.../file1.txt") rdd2 = rdd1.map(...) </code></pre> <p>Does <code>rdd2</code> reside on <code>alluxio</code> or on <code>spark</code>'s heap.</p> <p>Also would an operation like (both pairRDD's on alluxio) <code>pairRDD1.jo...
0
2016-06-09T07:54:08Z
38,015,591
<p>Spark transformations are evaluated in a lazy fashion. That means <code>map()</code> will not be evaluated until a result is required, and will not consume any Spark memory. An RDD will only consume Spark memory if you explicitly call <code>cache()</code> on the RDD.</p> <p>Therefore, when you are joining 2 RDDs fr...
1
2016-06-24T14:16:58Z
[ "python", "apache-spark", "pyspark", "tachyon" ]
ElasticSearch 2.2 - No search output
37,720,006
<p>I am playing around with ES 2.2 trying to index some binary files (docx,pdf,xls ... ). I am running ES 2.2 with the attachment mapper plugin on a Azure VM. </p> <p>What I did so far:</p> <p>Created a text index:</p> <pre><code>curl -X PUT "${host}/test" -d '{ "settings" : { "index" : { "number_of_shards" : 1, "...
0
2016-06-09T07:55:53Z
37,735,087
<p>I think this is due to the standard <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-tokenizers.html" rel="nofollow">tokenizer</a> in elasticsearch. The string "aWNoIGJpbiBpbSBkb2t1bWVudA==\n" in "file" breaks down into separate strings. So when you search for it won't have the exac...
0
2016-06-09T19:56:31Z
[ "python", "azure", "elasticsearch" ]
ElasticSearch 2.2 - No search output
37,720,006
<p>I am playing around with ES 2.2 trying to index some binary files (docx,pdf,xls ... ). I am running ES 2.2 with the attachment mapper plugin on a Azure VM. </p> <p>What I did so far:</p> <p>Created a text index:</p> <pre><code>curl -X PUT "${host}/test" -d '{ "settings" : { "index" : { "number_of_shards" : 1, "...
0
2016-06-09T07:55:53Z
37,745,332
<p>I reviewed and compared the documents for ES <a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.2/binary.html" rel="nofollow">2.2</a> &amp; <a href="https://www.elastic.co/guide/en/elasticsearch/reference/1.3/mapping-attachment-type.html" rel="nofollow">1.3</a>. It seems that the <code>Binary datatyp...
0
2016-06-10T09:58:52Z
[ "python", "azure", "elasticsearch" ]
Can't connect to slave with Python's modbus_tk
37,720,022
<p>I'm currently trying to develop an application that uses the Modbus-RTU protocol, and I have to use <em>modbus_tk</em> in Python 2.7.</p> <p>I'm supposed to use bits of code from another application which is able to communicate with the micro-controller via modbus. It works on that app when I run the following code...
1
2016-06-09T07:56:51Z
37,723,086
<p>Found it !</p> <p>I updated the library and set the parameters of the constructor correctly. This works fine know.</p>
0
2016-06-09T10:15:03Z
[ "python", "connection", "modbus" ]
Can't connect to slave with Python's modbus_tk
37,720,022
<p>I'm currently trying to develop an application that uses the Modbus-RTU protocol, and I have to use <em>modbus_tk</em> in Python 2.7.</p> <p>I'm supposed to use bits of code from another application which is able to communicate with the micro-controller via modbus. It works on that app when I run the following code...
1
2016-06-09T07:56:51Z
37,725,584
<p>The right repository for this library is <a href="https://github.com/ljean/modbus-tk" rel="nofollow">https://github.com/ljean/modbus-tk</a> It requires PySerial 2.7</p>
1
2016-06-09T12:08:10Z
[ "python", "connection", "modbus" ]
Executing a php script located on server via ajax
37,720,024
<p>I have a website hosted on server, now what I want is to run a .php script (Also located on the same server) when someone presses the submit button in the website.<br></p> <p>Following is the ajax code <br></p> <pre><code>$.ajax({url: "/test.php", success: function(response){ console.log("Success",response...
2
2016-06-09T07:56:56Z
37,720,240
<p>In this case it's recommended to use <code>mkdir</code> within <code>try...catch</code> function and capture the error if it's the case.</p> <p>On the other hand <a href="http://php.net/manual/en/function.mkdir.php" rel="nofollow"><code>mkidr</code></a> will return a boolean value: <code>true</code> if the director...
2
2016-06-09T08:08:43Z
[ "javascript", "php", "jquery", "python", "ajax" ]
Executing a php script located on server via ajax
37,720,024
<p>I have a website hosted on server, now what I want is to run a .php script (Also located on the same server) when someone presses the submit button in the website.<br></p> <p>Following is the ajax code <br></p> <pre><code>$.ajax({url: "/test.php", success: function(response){ console.log("Success",response...
2
2016-06-09T07:56:56Z
37,720,274
<p>Revise your <strong>php.ini</strong> in the server, the tag <strong>disable_functions</strong> = "..." and making sure that mkdir not this included in the list.</p>
1
2016-06-09T08:10:32Z
[ "javascript", "php", "jquery", "python", "ajax" ]
python: shift column in pandas dataframe conditionally on one column up by one
37,720,206
<p>I've got a pandas dataframe. I want to 'lag' one of my column conditionally on an other columns. Typically below, i want to lag gdp based on y previous "real" value.</p> <p>Typically first entry will be 0 because we are looking for y = 0.</p> <p>Second entry will be 2 because we are looking for y = 1</p> <p>Third...
-1
2016-06-09T08:06:39Z
37,720,682
<p>You do not need the <code>shift</code> method, you can simply do a lookup. I make <code>y</code> the index of a simple series, and use <code>.loc</code> to access the values:</p> <pre><code>df['y_prev'] = df['y'] - 1 df[['y', 'gdp']].set_index('y', drop=True).loc[df['y_prev'] </code></pre> <p>Output:</p> <pre><co...
0
2016-06-09T08:30:53Z
[ "python", "pandas", "dataframe" ]
python: shift column in pandas dataframe conditionally on one column up by one
37,720,206
<p>I've got a pandas dataframe. I want to 'lag' one of my column conditionally on an other columns. Typically below, i want to lag gdp based on y previous "real" value.</p> <p>Typically first entry will be 0 because we are looking for y = 0.</p> <p>Second entry will be 2 because we are looking for y = 1</p> <p>Third...
-1
2016-06-09T08:06:39Z
37,720,898
<p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollow"><code>map</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.squeeze.html" rel="nofollow"><code>squeeze</code></a>:</p> <pre><code>df['y_prev'] = df...
0
2016-06-09T08:40:14Z
[ "python", "pandas", "dataframe" ]
tracking maximum value in dataframe column
37,720,221
<p>I want to produce a column <code>B</code> in a dataframe that tracks the maximum value reached in column <code>A</code> since row Index 0.</p> <pre><code> A B Index 0 1 1 1 2 2 2 3 3 3 2 3 4 1 3 5 3 3 6 4 4 7 ...
2
2016-06-09T08:07:34Z
37,720,255
<p>You're looking for <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.cummax.html#pandas.Series.cummax" rel="nofollow"><code>cummax</code></a>:</p> <pre><code>In [257]: df['B'] = df['A'].cummax() df Out[257]: A B Index 0 1 1 1 2 2 2 3 3 3 2 3 4 1...
4
2016-06-09T08:09:30Z
[ "python", "pandas" ]
Scrapy parse to pipeline
37,720,329
<p>For example I want to crawl three similar urls:</p> <pre><code>https://example.com/book1 https://example.com/book2 https://example.com/book3 </code></pre> <p><strong>What I want is in the pipeline.py, that I create 3 files named book1, book2 and book3, and write the 3 books' data correctly and separately</strong> ...
0
2016-06-09T08:13:10Z
37,720,953
<p>Smith, If you want to know book name in pipeline.py. there are two options either you make a item field for book_file_name and populate it accordingly as you want. or you can extract it from url field which is also a item field and can access in pipline.py </p>
0
2016-06-09T08:42:43Z
[ "python", "scrapy" ]
Python None check (redis)
37,720,394
<p>I am coding an module using redis-py, here I have a problem :</p> <pre><code>def get_users_from_usergroup(usergroup): get_result = r_server.hmget('usergroups', usergroup) if get_result is not None: print('users from the given usegroup [' + usergroup + '] are :') print(get_result) return (get_result) els...
0
2016-06-09T08:16:06Z
37,720,424
<pre><code>&gt;&gt;&gt; [None] is None False </code></pre> <p>is the answer to your question. Try to change your condition to:</p> <pre><code>if get_result[0]: # there are results else: # there are no results </code></pre>
1
2016-06-09T08:17:42Z
[ "python", "redis-py" ]
Python: read and write into files, and modify them with a function
37,720,471
<p>I have a file named <code>Energy_vs_volume.dat</code> that looks like:</p> <pre><code> # volume energy 64 -180.001 63 -180.002 62 -180.005 . . . . . . </code></pre> <p>I've already written a python script named <code>calculate.py</code> tha...
-1
2016-06-09T08:20:09Z
37,721,964
<p>Hopefully this is understandable.</p> <pre><code># open the files volume_energy = open('Energy_vs_volume.dat') volume_pressure = open('Pressure_vs_volume.dat', 'w') # w for writing pressure_energy = open('Energy_vs_pressure.dat', 'w') # w for writing # write first lines of your created files # (still not sure abou...
1
2016-06-09T09:28:03Z
[ "python", "function", "file-io" ]
how to make python awaitable object
37,720,563
<p>In <strong>python 3.5.1</strong> one can make use of await/async, however, to use it (as I undestand), you need to have <em>awaitable object</em>. An awaitable object is an object that defines <code>__await__()</code> method returning an iterator. More info <a href="https://www.python.org/dev/peps/pep-0492/#await-ex...
0
2016-06-09T08:25:31Z
38,065,169
<p>I guess there is still no answer because the question is not pretty clear. You correctly said that </p> <blockquote> <p>An awaitable object is an object that defines <code>__await__()</code> method returning an iterator</p> </blockquote> <p>Not much to add here. Just write an iterator.</p> <p>The only thing you...
0
2016-06-28T00:18:47Z
[ "python", "websocket", "async-await", "pyserial", "python-3.5" ]
Efficient representing sub-graphs (data structure) in Python
37,720,588
<p>What is the efficient way of keeping and comparing generated sub-graphs from given input graph G in Python?</p> <p>Some details:</p> <ol> <li><p>Input graph G is a directed, simple graph with number of vertices varying from n=100-10000. Number of edges - it can be assumed that maximum would be 10% of complete grap...
0
2016-06-09T08:26:23Z
37,721,273
<p>The key point here is the data format of the graphs already generated by your algorithm. Does it contruct a new graph by adding vertices and edges ? Is it rewritable ? Does it uses a given format (matrix, adjacency list, vertices and nodes sets etc.)</p> <p>If you have the choice however, because your subgraph have...
0
2016-06-09T08:57:30Z
[ "python", "performance", "data-structures", "graph" ]
How to set a class or module attribute in a patchmonkey in py.test
37,720,593
<p>I'm starting a small project in Python and I want to create a unittest with py.test. I need to patch a <code>pymongo</code> module or a <code>MongoClient</code> class. So I tried something like this: </p> <pre><code>@pytest.fixture(scope='module') def mock_pymongo(monkeypatch): monkeypatch.setattr('pymongo', mo...
0
2016-06-09T08:26:39Z
37,742,533
<p>The <code>scope</code> argument doesn't specifiy what to patch - it specifies the lifetime of the fixture. With the default scope (<code>module</code>), the patching will happen before each test, and be reverted after the test. That's generally the behavior you want.</p>
0
2016-06-10T07:36:57Z
[ "python", "unit-testing", "py.test", "fixture" ]
Why isn't the string value updated?
37,720,619
<p>I was writing a for loop that would take a list of strings and add a new line to the end of the string if it doesn't already have one. </p> <p>My first thought was below, which didn't work:</p> <pre><code>for string in list : if not string.endswith('\n'): string += '\n' </code></pre> <p>I then came u...
2
2016-06-09T08:27:58Z
37,720,723
<p>Since string is an immutable object, in this code:</p> <pre><code>for string in list : if not string.endswith('\n'): string += '\n' </code></pre> <p>In every iteration the <code>string</code> variable gets assigned an element in <code>list</code>, then a new string is created with <code>'\n'</code> in...
2
2016-06-09T08:32:31Z
[ "python" ]
Python/Django: Schedule task in realtime
37,720,652
<p>I want to execute some task (function) within my Django application at a specified duration from when a call is made to that. Something like:</p> <pre><code>... some code async_run_func(time_interval=15_mins) # Async call. Code within the function # should be executed after ...
-1
2016-06-09T08:29:29Z
37,720,831
<p>Celery has the option of enqueuing at a specific time:</p> <pre><code>your_async_function.apply_async(args=(your, args, tuple), kwargs={your: kwargs}, countdown=15 * 60) </code></pre> <p>Or use the subtask syntax, to curry all args and then delay</p> ...
1
2016-06-09T08:37:01Z
[ "python", "django", "multithreading", "django-celery" ]
Python/Django: Schedule task in realtime
37,720,652
<p>I want to execute some task (function) within my Django application at a specified duration from when a call is made to that. Something like:</p> <pre><code>... some code async_run_func(time_interval=15_mins) # Async call. Code within the function # should be executed after ...
-1
2016-06-09T08:29:29Z
37,723,009
<p><a href="http://docs.celeryproject.org/en/latest/userguide/calling.html#eta-and-countdown" rel="nofollow">ETA and Countdown</a> are options to perform this using <a href="http://ask.github.io/celery/userguide/" rel="nofollow">django-celery</a>.</p>
0
2016-06-09T10:11:19Z
[ "python", "django", "multithreading", "django-celery" ]
Python/Django: Schedule task in realtime
37,720,652
<p>I want to execute some task (function) within my Django application at a specified duration from when a call is made to that. Something like:</p> <pre><code>... some code async_run_func(time_interval=15_mins) # Async call. Code within the function # should be executed after ...
-1
2016-06-09T08:29:29Z
37,726,823
<p>What about using <code>sched</code> module? Simple and efficient.</p> <pre><code>import sched, time sc = sched.scheduler(time.time, time.sleep) sc.enter(15, 1, async_run_func, ()) sc.run </code></pre>
1
2016-06-09T13:04:15Z
[ "python", "django", "multithreading", "django-celery" ]
CSV string to decimal in python list
37,720,666
<p>I am using an API that returns what appears to be a CSV string that i need to parse for two decimal numbers and then need to append those numbers to separate lists as decimal numbers (also while ignoring the timestamp at the end):</p> <pre><code>returned_string_from_API = '0,F,F,1.139520,1.139720,0,0,20160608163132...
1
2016-06-09T08:30:20Z
37,720,944
<p>Fastest way is to use regular expression. Readability is another issue..</p> <pre><code>import re returned_string_from_API = '0,F,F,1.139520,1.139720,0,0,20160608163132000' decimal_lowest_in_string = [] decimal_highest_in_string = [] re_check = re.compile(r"[0-9]+\.\d*") m = re_check.findall(returned_string_from_...
1
2016-06-09T08:42:21Z
[ "python", "csv" ]
CSV string to decimal in python list
37,720,666
<p>I am using an API that returns what appears to be a CSV string that i need to parse for two decimal numbers and then need to append those numbers to separate lists as decimal numbers (also while ignoring the timestamp at the end):</p> <pre><code>returned_string_from_API = '0,F,F,1.139520,1.139720,0,0,20160608163132...
1
2016-06-09T08:30:20Z
37,720,958
<p>1) The version which does not rely on cvs</p> <pre><code>returned_string_from_API = '0,F,F,1.139520,1.139720,0,0,20160608163132000' def isfloat(value): try: float(value) return True except ValueError: return False float_numbers = filter(isfloat, returned_string_from_API.split(',')) </code></pre> ...
1
2016-06-09T08:43:02Z
[ "python", "csv" ]
CSV string to decimal in python list
37,720,666
<p>I am using an API that returns what appears to be a CSV string that i need to parse for two decimal numbers and then need to append those numbers to separate lists as decimal numbers (also while ignoring the timestamp at the end):</p> <pre><code>returned_string_from_API = '0,F,F,1.139520,1.139720,0,0,20160608163132...
1
2016-06-09T08:30:20Z
37,720,970
<p>Split the string by comma:</p> <pre><code>&gt;&gt;&gt; string_values = returned_string_from_API.split(',') &gt;&gt;&gt; string_values ['0', 'F', 'F', '1.139520', '1.139720', '0', '0', '20160608163132000'] </code></pre> <p>Get the values from string:</p> <pre><code>&gt;&gt;&gt; string_values[3:5] ['1.139520', '1.1...
2
2016-06-09T08:43:50Z
[ "python", "csv" ]
How to pick key words from a list, after appending a .csv file to that list?
37,720,728
<p>I need to be able to pick keywords from an Excel CSV file, I've appended the file to a list. The program is a Phone Troubleshoot, and I need the input ("The screen won't turn on") to have the same output as if I inputted ("The display is blank").</p> <pre><code>"Troubleshooting Program to give the user a solution t...
0
2016-06-09T08:32:37Z
37,727,336
<p>Are you trying to build a keyword dictionary or retriving a sentence problem ? In both case, you need to associate a problem to keywords.</p> <p>A basic approch to get keywords is to split the sentence in words (using s.split()) and update keyword list with the most used of them... <a href="https://docs.python.org/...
0
2016-06-09T13:26:25Z
[ "python", "list", "keyword" ]
PyQt5 Weird window position issue
37,720,733
<p>The codes above, weirdly have an issue. I don't understand why but if I set <code>y</code> size of the window more than <code>923</code>, the window is not placed at the middle of the screen. It goes to the top-left corner of the screen.</p> <pre><code>from PyQt5.QtWidgets import QApplication,QDesktopWidget,QMainWi...
2
2016-06-09T08:32:42Z
37,836,110
<p>Try this solution from this answer: <a href="http://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen">PyQt4 center window on active screen</a></p> <pre><code>def center(self): frameGm = self.frameGeometry() screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.deskto...
0
2016-06-15T12:55:49Z
[ "python", "python-3.4", "pyqt5" ]
Emacs: How do I set flycheck to Python 3?
37,720,869
<p>I've installed flycheck for Emacs Python on Ubuntu 15.04.</p> <p>However, when using the tool it reports false positives like <code>print(item, end=' ')</code> is wrong syntax due to <code>end</code>.</p> <p>I know this is Python 3 syntax, and that the syntax error is caused by flycheck is set up for Python 2.</p>...
0
2016-06-09T08:38:37Z
37,730,904
<p>Flycheck simply calls the pylint executable that should be somewhere in your path. If that executable was installed by pip for python2 then pylint will check python2 syntax if it was installed for pip (sometimes called pip3) for python3 then pylint will check python3 syntax.</p> <p>How to proceed depends on a numbe...
0
2016-06-09T15:56:22Z
[ "python", "emacs" ]
Emacs: How do I set flycheck to Python 3?
37,720,869
<p>I've installed flycheck for Emacs Python on Ubuntu 15.04.</p> <p>However, when using the tool it reports false positives like <code>print(item, end=' ')</code> is wrong syntax due to <code>end</code>.</p> <p>I know this is Python 3 syntax, and that the syntax error is caused by flycheck is set up for Python 2.</p>...
0
2016-06-09T08:38:37Z
39,024,637
<p>Flycheck has a number of checkers for each <a href="https://flycheck.readthedocs.io/en/latest/languages.html" rel="nofollow" title="supported languages">supported language</a> (and many more <a href="https://flycheck.readthedocs.io/en/latest/community/extensions.html" rel="nofollow" title="list of extensions provide...
0
2016-08-18T17:54:02Z
[ "python", "emacs" ]
(Django) Where my method for model management should be in?
37,720,901
<h2>Situation</h2> <p>I'm making my website using <code>Django</code>. I'm trying to make it structful.</p> <p><code>Django</code> provides <code>User</code> and <code>Group</code> in <code>django.contrib.models</code>.</p> <p>In my app <code>board</code>, there are <code>Board</code> model.</p> <p>Each <code>Board...
0
2016-06-09T08:40:25Z
37,721,087
<p>My solution would be to have a <code>available_for(user)</code> method in the <code>BoardManager</code> or the <code>BoardQuerySet</code> (depending on which one you decide to be the base for development, each can be automatically configured/generated from the other).</p> <p>You will be able to chain it with other ...
0
2016-06-09T08:49:05Z
[ "python", "django" ]
Unpacking tuple in Python 2.7
37,721,012
<p>Actually working on a project where the homemade local DB api return all the result of SQL requests in tuples.</p> <p>Like that :</p> <pre><code>result = ( (result1.1, result1.2... ), (result2.1, .... ) .... ) </code></pre> <p>The problem is : when they unpack the tuple, we get many, many... ( many ) ValueErrors,...
1
2016-06-09T08:45:51Z
37,721,450
<ol> <li>Use Better Data Structure</li> </ol> <p>You should consider to use proper data like list of Classes / Objects then you don't need to "unpack" them like this</p> <ol start="2"> <li>Play with data Part 1</li> </ol> <pre class="lang-py prettyprint-override"><code>for subValue in a: my = GetValueOrDefault(...
2
2016-06-09T09:06:01Z
[ "python", "tuples", "args", "kwargs" ]
Unpacking tuple in Python 2.7
37,721,012
<p>Actually working on a project where the homemade local DB api return all the result of SQL requests in tuples.</p> <p>Like that :</p> <pre><code>result = ( (result1.1, result1.2... ), (result2.1, .... ) .... ) </code></pre> <p>The problem is : when they unpack the tuple, we get many, many... ( many ) ValueErrors,...
1
2016-06-09T08:45:51Z
37,721,708
<p>For Python3: use asterisk syntax</p> <pre><code>result = ((1,2), (3,4), (5,6)) a, *_ = result # a == (1,2) # _ == [(3,4),(5,6)] </code></pre> <p>For Python2: use slices</p> <pre><code>result = ((1,2), (3,4), (5,6)) a, b = result[:2] # a == (1,2) # b == (3,4) </code></pre>
2
2016-06-09T09:17:35Z
[ "python", "tuples", "args", "kwargs" ]
JSEncrypt to PyCrypto RSA encryption not possible
37,721,113
<p>I'm trying to encrypt a string in Javascript using RSA (public key) And I want to decrypt that string in Python (2.7) with my private key.</p> <p>The Libraries I am using are <a href="https://github.com/travist/jsencrypt" rel="nofollow">JSEncrypt</a> and PyCrypto The Problem here is, that PyCrypto has problems to d...
0
2016-06-09T08:50:08Z
37,724,977
<p>The python code you posted only does the low level decryption, the encrypted data returned by the jsencrypt also <a href="https://github.com/travist/jsencrypt/blob/9e43644e5448e57c584004e8548b594dc9be6db7/bin/jsencrypt.js#L1354" rel="nofollow">contains pkcs1 padding</a>.</p> <p>Instead of using the raw RSA key to e...
1
2016-06-09T11:41:05Z
[ "python", "python-2.7", "rsa", "pycrypto", "jsencrypt" ]
How to manipulate this Dataframe in pandas
37,721,170
<p><a href="http://i.stack.imgur.com/rD1Xc.png" rel="nofollow"><img src="http://i.stack.imgur.com/rD1Xc.png" alt="enter image description here"></a></p> <p>I want to manipulate the above pandas Dataframe to find the percentage of 'Days to 1st login &lt; 14 days" by each 'Sales Chain' and grouped by every day, to have ...
0
2016-06-09T08:53:00Z
37,722,690
<p>You can have the counts (instead of the percentage) with:</p> <pre><code>dataframe['amount'] = 1 output = dataframe.groupby(['Opened','Sales chain', 'Days to 1st login &lt; 14 days'],as_index = False).sum() </code></pre> <p>Then calculating the percentage seems relatively easy. If your dataframe isn't to big, you...
0
2016-06-09T09:58:19Z
[ "python", "pandas", "dataframe" ]
How to manipulate this Dataframe in pandas
37,721,170
<p><a href="http://i.stack.imgur.com/rD1Xc.png" rel="nofollow"><img src="http://i.stack.imgur.com/rD1Xc.png" alt="enter image description here"></a></p> <p>I want to manipulate the above pandas Dataframe to find the percentage of 'Days to 1st login &lt; 14 days" by each 'Sales Chain' and grouped by every day, to have ...
0
2016-06-09T08:53:00Z
37,723,715
<p>You can use crosstab</p> <pre><code>In [29]: df Out[29]: Opened Sales Chain Days to 1st login &lt;14 0 140936 02.05.2015 Others Yes 1 140937 02.05.2015 Others No 2 140938 02.05.2015 Aspa No 3 140939 02.05.2015 Others ...
0
2016-06-09T10:43:56Z
[ "python", "pandas", "dataframe" ]
Aligning text using format in a QTextEdit in Python
37,721,194
<p>I want to display text in a QTextEdit. I use the format() function to align the text and make it look like a clean table. Although I get a perfect result when displaying the text in the shell, the text doesn't seem to align in the QTextEdit, like if the width of a character varies. I mainly see the difference when t...
1
2016-06-09T08:53:58Z
37,722,649
<p>I was using the default font that doesn't have a fixed width, hence the non alignment. Setting the font to a fixed width font like 'monospace' solved my problem :</p> <pre><code>fixed_font = QFont("monospace") fixed_font.setStyleHint(QFont.TypeWriter) my_text_edit.setFont(fixed_font) </code></pre> <p>I used "setSt...
2
2016-06-09T09:56:08Z
[ "python", "qt", "format", "qtextedit" ]
Boto3 updating multiple values
37,721,245
<p>in the boto3 documentation updating an item is described by this example:</p> <pre><code>table.update_item( Key={ 'username': 'janedoe', 'last_name': 'Doe' }, UpdateExpression='SET age = :val1', ExpressionAttributeValues={ ':val1': 26 } ) </code></pre> <p>But what am i s...
0
2016-06-09T08:56:07Z
38,578,076
<p>Yes, that's the way to do. Even many actions can be done in single expression as shown <a href="http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html#DynamoDB.Table.update_item" rel="nofollow">here</a>. For ex: multiple 'PUT' and 'DELETE' in single expression.</p> <p><img src="http://i.stack.imgur...
1
2016-07-25T21:59:22Z
[ "python", "amazon-dynamodb", "aws-lambda", "boto3" ]
Ansible - putting facts in SQLite via Callback
37,721,314
<p>Working with Ansible 2.0.2.0. Trying to put two facts into a sqlite database. To achieve it, i'm working with a callback plugin. This is the python script so far;</p> <pre><code>import os import time import sqlite3 import json from ansible.plugins.callback import CallbackBase dbname = '/etc/ansible/test.db' TIME_...
1
2016-06-09T08:59:00Z
37,724,307
<p>Working code. Remove <code>CREATE TABLE</code> if not needed.</p> <pre><code>from ansible.plugins.callback import CallbackBase import os import time import sqlite3 dbname = './test.db' TIME_FORMAT='%Y-%m-%d %H:%M:%S' try: con = sqlite3.connect(dbname) cur = con.cursor() cur.execute('CREATE TABLE `test...
1
2016-06-09T11:10:11Z
[ "python", "sqlite", "callback", "ansible" ]
motion-notify-event not triggering
37,721,544
<p>Basically what i need to achieve with this is to bypass the bug which doesn't identify the mouse over the top bar as being inside the window. As you can see with the code below, if you put the mouse on top bar the window turns half-transparent as if the mouse aren't there (<code>mouse_enter()</code> doesn't get call...
0
2016-06-09T09:10:01Z
37,722,488
<p>You likely need to call <code>win.add_events()</code> with the Python equivalent of <code>GDK_POINTER_MOTION_MASK</code>.</p>
2
2016-06-09T09:50:15Z
[ "python", "gtk" ]
How to set non-model field property to all the objects in ManyToMany Relation?
37,721,579
<p>I have a django model, with ManyToMany relation, and through a recursive function I am trying to set a custom property on the main model and all the models in the ManyToMany fields, but ManyToMany related model property is not getting reflected into the templates.</p> <p>Here is my code snippet:</p> <pre><code>def...
0
2016-06-09T09:11:28Z
37,721,984
<p>Making use of model functions is a simple solution to it, nice and clean.</p>
1
2016-06-09T09:28:54Z
[ "python", "django" ]
Disable GPIO by default and temporarily activate it via python script
37,721,586
<p>I'm using a Raspberry Pi 2 with DietPi and plugged in an alarm module into the GPIO 14 (Pin 08).</p> <p>I would now like to disable this Pin by default and only allow it to turn on temporarily within my python script. </p> <p>So far I've tried using RPi.GPIO which hasn't worked and unexport/export but this only en...
-1
2016-06-09T09:11:59Z
37,723,572
<p>I don't have my rpi with me, but you can try using this. First function exports, 3 following check time</p> <pre><code>import time import sys def unexport(gpio): value = open("/sys/class/gpio/unexport","w") value.write(gpio) value.close() def checkHours: return int(time.strftime("%l")) def checkMinutes...
0
2016-06-09T10:36:43Z
[ "python", "raspberry-pi", "raspbian", "raspberry-pi2", "gpio" ]
Disable GPIO by default and temporarily activate it via python script
37,721,586
<p>I'm using a Raspberry Pi 2 with DietPi and plugged in an alarm module into the GPIO 14 (Pin 08).</p> <p>I would now like to disable this Pin by default and only allow it to turn on temporarily within my python script. </p> <p>So far I've tried using RPi.GPIO which hasn't worked and unexport/export but this only en...
-1
2016-06-09T09:11:59Z
37,725,706
<p>Since posting this question I've figured out this way to disable and enable the pin/gpio through python:</p> <pre><code>import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(8, GPIO.OUT) try: while True: GPIO.output(8,1) time.sleep(0.5) GPIO.output(8,0) time.sleep(0.5) excep...
0
2016-06-09T12:13:25Z
[ "python", "raspberry-pi", "raspbian", "raspberry-pi2", "gpio" ]
Why is the logistic regression implementation in Python incorrect?
37,721,595
<p>I have implemented logistic regression in Python. I think there is some bug in the code. I am not able to get the correct accuracy for the testset. Here is the code:</p> <pre><code>from __future__ import division import numpy as np from math import * import os, sys class LogisticRegressionModel: def __init__...
0
2016-06-09T09:12:17Z
37,724,281
<p>Assuming that your training data is a list containing pairs like <code>([feature1,...,featuren], label)</code>, the following code seems to work fine for me. It's a modification of your code, except that I put things in array form where it was appropriate:</p> <pre><code>from __future__ import division import numpy...
1
2016-06-09T11:08:58Z
[ "python", "machine-learning", "logistic-regression" ]
Guassian image filtering plots with low stdev. values
37,721,773
<p>I'm generating some basic Gaussian filtering demonstrations, but am getting peculiar output plots, in that they aren't linearly blurred. The below code imports any image and then applies a Gaussian filter of std (sigma) value 1, size 5.</p> <p>I think it may be a finite vs infinite filter array assumption problem, ...
2
2016-06-09T09:20:40Z
37,723,414
<p>Look like a problem of 8-bit <a href="https://en.wikipedia.org/wiki/Integer_overflow" rel="nofollow">integer overflow</a>. You can work on float images, and avoid such problems: <code>arr = np.array(im, dtype=np.float32)</code>.</p> <p>BTW, why not use <a href="http://docs.scipy.org/doc/scipy-0.15.1/reference/gener...
2
2016-06-09T10:30:14Z
[ "python", "plot", "gaussian", "convolution" ]
Python relative/absolute import (again)
37,721,780
<p>This topic has been covered several times but I still can't get my package to work. Here is the situation: I've got a package in which a <code>logging</code> module takes care of setting up the logging. So clearly, <code>mypackage.logging</code> conflicts with Python <code>logging</code> from the standard library.</...
4
2016-06-09T09:20:58Z
37,777,703
<p>The way I deal with this specific issue of using a custom logging module is to import all the logging functions into my custom module. Now you can also reimplement module level functions with customized versions as well.</p> <p>For example:</p> <pre><code>"""logging - Setup logging for mypackage.""" import copy ...
0
2016-06-12T18:29:02Z
[ "python", "python-3.x", "python-import", "relative-import" ]
Custom xticks for multiple subplots?
37,721,851
<p>Using Matplotlib, I have two subplots and I want them to have the same custom string xticks.</p> <p>Here is a minimal example what I tried so far:</p> <pre><code>import matplotlib.pyplot as plt f, axs = plt.subplots(ncols=2, sharex=True) plt.xticks(range(6), [str(x)+"foo" for x in range(6)], rotation='45') for i i...
3
2016-06-09T09:23:36Z
37,722,582
<p>If <code>sharex</code> is not principal use this code:</p> <pre><code>import matplotlib.pyplot as plt f, axs = plt.subplots(ncols=2) for i in range(2): ax = axs[i] ax.set_xticks(range(6)) ax.set_xticklabels([str(x)+"foo" for x in range(6)], rotation=45) ax.plot(range(6), range(6)) plt.show() </code>...
1
2016-06-09T09:54:02Z
[ "python", "matplotlib" ]
Running celery worker from inside the project
37,721,914
<p>I have an application which has the follow structure:</p> <pre><code>proj/ __init__.py script1.py script2.py celery.py ... </code></pre> <p>The problem is that the project was initially written with the root directory inside the proj. I.e. import don't start with <code>import proj.script1</code...
0
2016-06-09T09:26:02Z
37,723,749
<p>So the workaround for me was to put <code>celery.py</code> inside another directory and then run worker while being in <code>proj/</code>.</p> <p>Current directory structure:</p> <pre><code>proj/ __init__.py script1.py script2.py Celery/ celery.py ... </code></pre> <p>Not very beautifu...
0
2016-06-09T10:45:34Z
[ "python", "import", "path", "celery" ]
How to revert a vertical numpy array (1D) to its usual horizontal default form?
37,721,971
<p>Ok, it has been asked many times how to convert a 1D numpy array to a vertical one. The most used option is, if</p> <pre><code>In [2]: a = np.array([1, 2, 3, 4]) In [3]: a Out[3]: array([1, 2, 3, 4]) </code></pre> <p>we usually do:</p> <pre><code>In [5]: a = a[ : , np.newaxis] In [6]: a Out[6]: array([[1], [...
2
2016-06-09T09:28:11Z
37,722,133
<p>Along side the <code>np.squeeze()</code> that removes the single-dimensional entries from the shape of an array, you can use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.hstack.html" rel="nofollow"><code>np.hstack()</code></a> (Stack arrays in sequence horizontally) or <code>np.concatena...
0
2016-06-09T09:35:47Z
[ "python", "arrays", "numpy" ]
How to revert a vertical numpy array (1D) to its usual horizontal default form?
37,721,971
<p>Ok, it has been asked many times how to convert a 1D numpy array to a vertical one. The most used option is, if</p> <pre><code>In [2]: a = np.array([1, 2, 3, 4]) In [3]: a Out[3]: array([1, 2, 3, 4]) </code></pre> <p>we usually do:</p> <pre><code>In [5]: a = a[ : , np.newaxis] In [6]: a Out[6]: array([[1], [...
2
2016-06-09T09:28:11Z
37,722,636
<p>There is no such thing as a horizontal or vertical 1D array in numpy. A 1D array is just a 1D array. It is OK if you want to call a 2D array with shape, <code>(4, 1)</code>, a "vertical" array. Then a 2D array with shape, <code>(1, 4)</code>, would be a "horizontal" array. In that case the transpose will work as...
3
2016-06-09T09:55:37Z
[ "python", "arrays", "numpy" ]
GRPC: remote error and missing parameters from message
37,722,002
<p>I am running a simple python server application with grpc. This is the server code:</p> <p>class Classifier(grpc_cl.BetaClassifierServicer):</p> <pre><code>def __init__(self): default_config = self.getDefaultConfig() self.engine_config = default_config["engine"] self.port = default_config["daemon"]["po...
0
2016-06-09T09:29:46Z
38,467,971
<p><code>grpc.framework.interfaces.face.face.RemoteError</code> indicates that an exception occurred on the server while processing the request.</p> <p>In your case, protobuf parameters need to be specified by keyword, ie</p> <p><code>return grpc_cl.CategoryReply(error)</code></p> <p>should be </p> <p><code>return ...
0
2016-07-19T20:30:54Z
[ "python", "grpc" ]
adding tuple elements in a list
37,722,047
<pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] </code></pre> <p>I need:</p> <pre><code>result=[(2,4),(3,8),(4,5),(11,3)] </code></pre> <p>using for loop I was able to add tuples having the same first element.</p> <pre><code>&gt;&gt;&gt; result = [] l1 = [(2, 1), (3, 2), (4, 5)] l2 = [(2, 3), (3, 6), (11,...
3
2016-06-09T09:31:44Z
37,722,201
<p>It can be easily done by using dict formed with <code>l1</code> and iterating over <code>l2</code>, see working code snippet below:</p> <pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] result = dict(l1) for y in l2: result[y[0]] = result.get(y[0],0) + y[1] result = result.items() print result #[(11, ...
2
2016-06-09T09:38:02Z
[ "python", "list", "tuples" ]
adding tuple elements in a list
37,722,047
<pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] </code></pre> <p>I need:</p> <pre><code>result=[(2,4),(3,8),(4,5),(11,3)] </code></pre> <p>using for loop I was able to add tuples having the same first element.</p> <pre><code>&gt;&gt;&gt; result = [] l1 = [(2, 1), (3, 2), (4, 5)] l2 = [(2, 3), (3, 6), (11,...
3
2016-06-09T09:31:44Z
37,722,220
<p>There's no need to go through the elements of <code>l2</code> for all elements of <code>l1</code> if I understand what you're going for. Just use <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow"><strong><code>zip</code></strong></a> (or <strong><a href="https://docs.python.org/2/library/...
2
2016-06-09T09:38:39Z
[ "python", "list", "tuples" ]
adding tuple elements in a list
37,722,047
<pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] </code></pre> <p>I need:</p> <pre><code>result=[(2,4),(3,8),(4,5),(11,3)] </code></pre> <p>using for loop I was able to add tuples having the same first element.</p> <pre><code>&gt;&gt;&gt; result = [] l1 = [(2, 1), (3, 2), (4, 5)] l2 = [(2, 3), (3, 6), (11,...
3
2016-06-09T09:31:44Z
37,722,278
<p>Seems natural to use a dictionary to keep track of which keys are already used. You can reduce the code size by using <code>defaultdict</code>:</p> <pre><code>import collections l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] d = collections.defaultdict(int) for x,y in l1 + l2: d[x] += y print sorted(d.items()...
1
2016-06-09T09:41:16Z
[ "python", "list", "tuples" ]
adding tuple elements in a list
37,722,047
<pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] </code></pre> <p>I need:</p> <pre><code>result=[(2,4),(3,8),(4,5),(11,3)] </code></pre> <p>using for loop I was able to add tuples having the same first element.</p> <pre><code>&gt;&gt;&gt; result = [] l1 = [(2, 1), (3, 2), (4, 5)] l2 = [(2, 3), (3, 6), (11,...
3
2016-06-09T09:31:44Z
37,723,034
<p>So many ways to achieve the same goal... I like it!</p> <p>Here is my solution.</p> <pre><code>l1=[(2,1),(3,2),(4,5)] l2=[(2,3),(3,6),(11,3)] d1 = dict(l1) d2 = dict(l2) result = [] for k in d1: if k in d2: result.append((k,d1[k]+d2[k])) else: result.append((k,d1[k])) for k in d2: if...
2
2016-06-09T10:12:36Z
[ "python", "list", "tuples" ]
re.search().TypeError: cannot use a string pattern on a bytes-like object
37,722,051
<pre><code>import urllib.request import re f = urllib.request.urlopen('http://www.geekynu.cn/') html = f.read() title = re.search('&lt;title&gt;(.*?)&lt;/title&gt;', html) print(title) #print(title.decode('utf-8')) //I had try to solve by this code. </code></pre> <p>[python 3.5] when I use <code>re.search()</code>to...
1
2016-06-09T09:31:50Z
37,722,109
<p><code>re</code> needs byte patterns (not string) to search bytes-like objects. Append a <code>b</code> to your search pattern like so: <code>b'&lt;title&gt;(.*?)&lt;/title&gt;'</code></p>
0
2016-06-09T09:34:43Z
[ "python", "python-3.x" ]
How to increment counter column through Cassandra python-driver ORM
37,722,056
<p>I`m using this <a href="https://datastax.github.io/python-driver/object_mapper.html" rel="nofollow">python driver</a>. How can i increment counter using ORM in correct way?</p> <p>Maybe smth like <code>update(counter_value__add=1)</code> or <code>obj.counter_value += 1</code>?</p> <p>I try to avoid this manual qu...
0
2016-06-09T09:32:00Z
37,722,213
<p><a href="https://datastax-oss.atlassian.net/browse/PYTHON-333" rel="nofollow">Resolved issue</a> which tell, that correct way is <code>obj.counter_value += 1</code> But its deprecated!</p> <p><strong>Right way is:</strong></p> <pre><code>CounterModel(pk=pk, ck=ck).update(counter_field=1, another_counter=-2) </code...
0
2016-06-09T09:38:27Z
[ "python", "orm", "cassandra", "counter", "cqlengine" ]
Not playing any video file in python GUI
37,722,066
<p>The following code is for opening a <code>filedialogue</code>. But it does not play any video file.</p> <p>It just returns the video file address but in not playing the file.</p> <pre><code>from Tkinter import Tk import cv2 import numpy as np from tkFileDialog import askopenfilename Tk().withdraw() filename = ask...
-3
2016-06-09T09:32:53Z
37,723,984
<p>With Tkinter and OpenCV this code is working for me. </p> <p>if i am using .avi and .mpg format, .mov and .mp4 just print the file path.</p> <pre><code>from Tkinter import Tk from tkFileDialog import askopenfilename import cv2 Tk().withdraw() filename = askopenfilename() print(filename) cap = cv2.VideoCapture(f...
1
2016-06-09T10:56:14Z
[ "python", "opencv", "tkinter" ]
Not playing any video file in python GUI
37,722,066
<p>The following code is for opening a <code>filedialogue</code>. But it does not play any video file.</p> <p>It just returns the video file address but in not playing the file.</p> <pre><code>from Tkinter import Tk import cv2 import numpy as np from tkFileDialog import askopenfilename Tk().withdraw() filename = ask...
-3
2016-06-09T09:32:53Z
37,724,014
<p>I think the problem is your frame rate. You set it to 0.001 sec, so maybe your video just ended really fast. Try increasing it:</p> <pre><code>from tkinter import Tk from tkinter import filedialog import cv2 Tk().withdraw() filename = filedialog.askopenfilename() print(filename) cap = cv2.VideoCapture(filename) ...
0
2016-06-09T10:57:28Z
[ "python", "opencv", "tkinter" ]
Facebook Marketing API: Potential reach of a Facebook campaign
37,722,078
<p>We can run Facebook advert using python SDK. I want to know the potential reach of target audience. Is there any command available or any other way?</p>
0
2016-06-09T09:33:34Z
37,741,202
<p>To get the Reach Estimates of a targeting specification using ad account.</p> <pre><code>account = AdAccount('act_&lt;AD_ACCOUNT_ID&gt;') targeting_spec = { 'geo_locations': { 'countries': ['US'], }, 'age_min': 20, 'age_max': 40, } params = { 'currency': 'USD', 'optimize_for': AdSet....
0
2016-06-10T06:22:03Z
[ "python", "facebook-sdk-3.0", "facebook-marketing-api" ]
Select several part of 2-d array by the attribute of another array
37,722,082
<p>Here is my question. </p> <ul> <li><p><strong>a</strong> is a 2-d numpy array in the shape of 100x100 containing finite numbers</p></li> <li><p><strong>b</strong> is a 2-d bool array in the shape of 100x100 containing <strong>True and False</strong> </p></li> </ul> <p>My target: </p> <blockquote> <p>Select s...
2
2016-06-09T09:33:40Z
37,722,457
<p>That's because you are transposing the index array. Also you don't need to convert the result of <code>np.where()</code> to numpy array, just pass it as index to first array. </p> <p>Here is an example:</p> <pre><code>&gt;&gt;&gt; b = np.random.choice([0, 1], size=(10,10)) &gt;&gt;&gt; b array([[0, 0, 0, 1, 0, 1, ...
1
2016-06-09T09:48:40Z
[ "python", "arrays", "numpy" ]
Load a tiff stack in a numpy array with python
37,722,139
<p>Hallo Stack Overflow community, </p> <p>I am having a little issue with .tif files. I am sure it is only a minor problem that I can´t get around (keep in mind, I am a relatively new programmer).</p> <p>Basically: I have prepared .tif files that are 64x64xn in size (n up until 1000). The image is only a single fil...
1
2016-06-09T09:35:54Z
37,777,208
<p>I am not sure if there is a way to get PIL to open multiple slices of a tiff stack. </p> <p>If you are not bound to using PIL, however, an alternative is <a href="http://scikit-image.org/" rel="nofollow">scikit-image</a>, which opens multiple slices from a tiff stack by default. Here is some sample code of how to l...
1
2016-06-12T17:38:30Z
[ "python", "arrays", "image", "numpy", "tiff" ]
sklearn - Cannot call inverse_transform of MultiLabelBinarizer right away
37,722,197
<p>After instanciating a <code>MultiLabelBinarizer</code>, I need its <code>inverse_transform</code> method for a matrix that I built elsewhere. Unfortunately,</p> <pre><code>import numpy as np from sklearn.preprocessing import MultiLabelBinarizer mlb = MultiLabelBinarizer(classes=['a', 'b', 'c']) A = np.array([[1, 0...
2
2016-06-09T09:37:48Z
37,723,668
<p>it appears to be implemented as is <a href="https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/preprocessing/label.py#L636" rel="nofollow">https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/preprocessing/label.py#L636</a>, .fit is the only method that defines the classes_ attribute. c...
1
2016-06-09T10:41:36Z
[ "python", "python-2.7", "scikit-learn" ]
sklearn - Cannot call inverse_transform of MultiLabelBinarizer right away
37,722,197
<p>After instanciating a <code>MultiLabelBinarizer</code>, I need its <code>inverse_transform</code> method for a matrix that I built elsewhere. Unfortunately,</p> <pre><code>import numpy as np from sklearn.preprocessing import MultiLabelBinarizer mlb = MultiLabelBinarizer(classes=['a', 'b', 'c']) A = np.array([[1, 0...
2
2016-06-09T09:37:48Z
37,727,575
<p>If you want to set the attribute <code>classes_</code> within the instance of <code>MultiLabelBinarizer</code>, you can also do a quick hack like this:</p> <pre><code>mlb = MultiLabelBinarizer().fit(['a', 'b', 'c']) </code></pre> <p>Because like marmouset said, only <code>fit</code> and <code>fit_transorm</code> s...
2
2016-06-09T13:36:41Z
[ "python", "python-2.7", "scikit-learn" ]
creating a dynamic editing tool in wxpython?
37,722,403
<p>I am new to python. I am trying to create a GUI that can be used edit an image namely, cropping and changing colour of background of the image, using wxpython.</p> <p>Can someone guide me where i can find information to tackle this? I have taken a look at the wx wiki but there isnt much on dynamic widgets that can ...
0
2016-06-09T09:45:55Z
37,725,551
<p>I suggest you to download wxPython Docs and Demo. <a href="https://sourceforge.net/projects/wxpython/files/wxPython/3.0.2.0/wxPython3.0-win32-docs-demos-3.0.2.0.exe/download?use_mirror=netassist" rel="nofollow">https://sourceforge.net/projects/wxpython/files/wxPython/3.0.2.0/wxPython3.0-win32-docs-demos-3.0.2.0.exe/...
0
2016-06-09T12:06:46Z
[ "python", "wxpython" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,733
<p>Try this:</p> <pre><code>def replace_not_first(str, word, replace): str_arr = str.split(word) return str_arr[0] + word + replace.join(str_arr[1:]) str = "change the string in the sentence and the save" print(replace_not_first(str, 'the', 'hello')) </code></pre> <p>prints: <code>change the string in hello ...
1
2016-06-09T10:00:12Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,764
<p>This should work</p> <pre><code>string = "change the string in the sentence and the save" the_arr = string.split("the") print the_arr[0] + "the" + "hello".join(the_arr[1:])` </code></pre>
1
2016-06-09T10:01:20Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,804
<p>Try the following one liner solution.</p> <pre><code>string = 'change the string in the sentence and the save' new_string = string[:string.find('the')+3] + string[string.find('the')+3:].replace('the', 'hello') </code></pre>
1
2016-06-09T10:02:45Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,818
<p>I hope this will do the job.</p> <pre><code>str = str.partition('the')[0] + str.partition('the')[1] + str.partition('the')[-1].replace('the','hello') </code></pre>
1
2016-06-09T10:03:34Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,820
<pre><code>&gt;&gt;&gt; str = "change the string in the sentence and the save" &gt;&gt;&gt; str.replace('the', 'hello') &gt;&gt;&gt; str.replace('hello', 'the',1) </code></pre>
1
2016-06-09T10:03:36Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,954
<p>I would split the string from right with the word you're going to replace use <a href="https://docs.python.org/3/library/stdtypes.html#str.rsplit" rel="nofollow"><code>str.rsplit()</code></a> function, but only split <a href="https://docs.python.org/3/library/stdtypes.html#str.count" rel="nofollow"><code>s.count('th...
3
2016-06-09T10:09:09Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,722,982
<p>You can split the string into parts: </p> <pre><code>string = "change the string in the sentence and the save" splitString = string.split() firstIndex = splitString.index('the') part1 = ' '.join(splitString[:firstIndex+1]) part2 = ' '.join(splitString[firstIndex+1:]).replace('the','hello') newString = part1 +...
0
2016-06-09T10:10:13Z
[ "python" ]
String replace without replacing the first instance
37,722,539
<p>I have a string and I want to replace <code>the</code> every time after its second occurrence only. </p> <pre><code>s = "change the string in the sentence and the save" </code></pre> <p>I would like the replace the word <code>the</code> to <code>hello</code>. But except the first one.</p> <p>Output should be:</...
1
2016-06-09T09:52:19Z
37,723,186
<p>Try this:</p> <pre><code>&gt;&gt;&gt; s = "change the string in the sentence and the save" &gt;&gt;&gt; s.split("the",1)[0]+"the" + s.split("the",1)[1].replace("the","hello") 'change the string in hello sentence and hello save' </code></pre>
1
2016-06-09T10:19:41Z
[ "python" ]
Modifying List Values
37,722,565
<p>I am a bit puzzled by the behavior of two functions i wrote for the modification of a list that is given as input. In my mind, both should be doing the same thing but this is not the case. Take a look:</p> <pre><code>def headerFormat1(list1): char_to_remove = ['(', ')'] list2 = list1[:] list1 = [] f...
0
2016-06-09T09:52:54Z
37,722,846
<p>You are changing list1[i] every time with original headers Check below code it works</p> <pre><code>def headerFormat1(list1): char_to_remove = ['(', ')'] list2 = list1[:] list1 = [] for headers in list2: headers = headers.replace(' ', '_') for character in char_to_remove: ...
1
2016-06-09T10:04:58Z
[ "python", "list", "python-3.x" ]
Dynamic ConfigParser (Python)
37,722,657
<p>I'm wondering if there is a way to deal with dynamic config files using Python's ConfigParser. By dynamic, I mean that the config file isn't fixed in structure.</p> <p>For example, I could have the config file below.</p> <pre><code>[SectionA] FieldA1 = stringA1 FieldA2 = stringA2 FieldA3 = stringA3 [SectionB] Fie...
2
2016-06-09T09:56:36Z
37,723,170
<p>from <a href="https://pymotw.com/2/ConfigParser/" rel="nofollow">pymotw.com</a></p> <pre><code>from configparser import SafeConfigParser parser = SafeConfigParser() parser.read('config.ini') for section_name in parser.sections(): print ('Section:', section_name) print (' Options:', parser.options(section...
1
2016-06-09T10:19:07Z
[ "python", "parsing", "config" ]
How to create this tabular data structure with numpy?
37,722,693
<p>I have several two-column tables that i want to join together with numpy. Each table has x and y columns. I need all the x columns joined together, with the y values matched up to the corresponding x. If an x value doesn't have a corresponding y, it should be None.</p> <p>I'm not so good at explaining, so an exampl...
2
2016-06-09T09:58:23Z
37,722,923
<p>You can use <a href="http://pandas.pydata.org/" rel="nofollow"><code>pandas</code></a> to do this easily by pass the arrays as values in a dict with the column names defined as <code>x</code> and <code>y1</code> and <code>y2</code> respectively for each df:</p> <pre><code>In [280]: import pandas as pd import numpy ...
2
2016-06-09T10:07:43Z
[ "python", "numpy" ]
Scrapy crawl multiple pages error filtered duplicate
37,722,748
<p>Just started using scrapy, and I am trying to do a generic sort of search engine through the whole database page by page and grab certain links that has what I need, but I am getting this error when I try to go to the next page. Not exactly sure how to go to the next page either, would appreciate any help with the c...
1
2016-06-09T10:00:39Z
37,723,725
<p>You can use the parameter dont_filter = True in your request:</p> <pre><code>if next_page: url = response.urljoin(next_page[0]) yield scrapy.Request(url, callback=self.parse, dont_filter=True) </code></pre> <p>But you will run into an infinite loop, since it seems that <strong>your xpath is retrieving th...
0
2016-06-09T10:44:16Z
[ "python", "scrapy" ]
Find missing integers in a series of lists
37,722,792
<p><p>Hi there, I found this really helpful topic on <a href="http://stackoverflow.com/questions/16974047/efficient-way-to-find-missing-elements-in-an-integer-sequence">finding missing elements in a list of integers</a>. <br>I found the second answer most useful and am applying it now to my code:</p> <pre><code>def mi...
1
2016-06-09T10:02:18Z
37,722,997
<p>First off, as a more pythonic way you can use following function in order to detect your missing items, then use a list comprehension to apply the function on your lists:</p> <pre><code>&gt;&gt;&gt; from itertools import chain &gt;&gt;&gt; def missing(iterable): ... return chain.from_iterable(range(i+1, j) for ...
1
2016-06-09T10:10:55Z
[ "python" ]
Find missing integers in a series of lists
37,722,792
<p><p>Hi there, I found this really helpful topic on <a href="http://stackoverflow.com/questions/16974047/efficient-way-to-find-missing-elements-in-an-integer-sequence">finding missing elements in a list of integers</a>. <br>I found the second answer most useful and am applying it now to my code:</p> <pre><code>def mi...
1
2016-06-09T10:02:18Z
37,723,179
<p>Just <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow"><code>map</code></a> your existing function onto the series of lists:</p> <pre><code>&gt; lsts = [[716, 717, 718, 719, 720, 721], [761, 762, 763, 764, 765, 766, 767, 768], [988, 989, 990, 993, 994]] &gt; map(missi...
1
2016-06-09T10:19:26Z
[ "python" ]
unable to pickle scipy.spatial.KDTree objects
37,722,991
<p>I have a code where I build a huge tree and I need to save it for later use. Unluckily it seems I cannot pickle <code>scipy.spatial.KDTree</code> objects.</p> <p>In fact, when I run this:</p> <pre><code>import pickle import scipy.spatial tree=scipy.spatial.KDTree([[1,2,3]]) pickle.dump(tree,open('tree.p','wb')) </...
1
2016-06-09T10:10:44Z
37,723,174
<p>Use cKDTree instead of KDTree as follows:</p> <pre><code>import pickle import scipy.spatial tree=scipy.spatial.cKDTree([[1,2,3]]) pickle.dump(tree,open('tree.p','wb')) </code></pre>
3
2016-06-09T10:19:16Z
[ "python", "scipy", "pickle" ]
Can't change webcam resolution with OpenCV in Python (Windows)
37,722,992
<p>I'm using Microsoft LifeCam HD 3000. Default resolution is 640x480, but supports 1280x720. </p> <p>Common code for changing resolution for OpenCV does no effect:</p> <pre><code>video_capture = cv2.VideoCapture(0) print video_capture.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280) print video_capture.set(cv2.cv.CV_CA...
1
2016-06-09T10:10:47Z
37,831,780
<p>Finally I found an issue in OpenCV sources and solved it.</p> <p>MS Lifecam HD3000 works only in YUY2 format and also requires exact resolution to be requested or it simply rejects it (some cameras just choose the closest one). </p> <p>I had to modify 'cap_dshow.cpp' to calculate resolution request in correct way ...
0
2016-06-15T09:44:13Z
[ "python", "opencv" ]
Set executable permission from Windows host on Linux filesystem
37,723,041
<p>I have a python script which runs on a Windows machine. On this machine I have mounted a Samba filesystem (on a Linux host).</p> <p>When I now try to change file permissions on the filesystem with <code>os.chmod(S_IXUSR)</code> it doesn't set the excutable permission, since it is hardcoded in Windows to not do anyt...
0
2016-06-09T10:12:57Z
37,723,343
<p>Short answer: No.</p> <p>Slightly longer answer: It would perhaps not be impossible to write a Windows Samba driver which supports this, but you seem to be asking for an existing solution.</p>
0
2016-06-09T10:26:10Z
[ "python" ]
How to manage mod_wsgi logs in apache?
37,723,215
<p>I am working on flask application and i have used mod_wsgi and Apache to host the flask app. I have setup the logging in app it, but i observe that there are same logs are getting written in apache/logs/error.log like </p> <pre><code>[wsgi:error] ... BACK TO THE BROWSER [wsgi:error] ... Selected records from table...
1
2016-06-09T10:20:38Z
37,751,925
<p>I typically add an ErrorLog to my VirtualHost. Here's an example Apache VirtualHost I use:</p> <pre><code>&lt;VirtualHost *:443&gt; ServerName yourservername.com ErrorLog /home/yourusername/apache_errors.log WSGIDaemonProcess yourproject-https python-home=/home/yourusername/.virtualenvs/yourproject WSGISc...
0
2016-06-10T15:26:59Z
[ "python", "flask", "mod-wsgi", "apache2.4" ]
pip error while installing Python: "Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS"
37,723,236
<p>I downloaded the Python 3.5 source code and ran the following:</p> <pre><code>$ tar -xf Python-3.5.2.tar.xz $ ./configure --with-ensurepip=upgrade $ make $ sudo make altinstall </code></pre> <p>It proceeded well until <code>make</code>. When <code>sudo make altinstall</code> ran, it printed:</p> <p><code>Ignoring...
6
2016-06-09T10:21:07Z
37,723,517
<p>You are most likely not compiling Python with SSL/TLS support - this is likely because you don't have the SSL development libraries installed on your system. </p> <p>Install the following dependency, and then re-configure and re-compile Python 3.5. </p> <p><strong>Ubuntu</strong></p> <pre><code>apt-get install li...
11
2016-06-09T10:34:26Z
[ "python", "install" ]
update the row in MySQL, without ORM
37,723,344
<p>Why I got the value of uid </p> <p>in flask debug console and while using </p> <pre><code>&lt;input id="userId" name="userId" type="text" value= {{ un[usernumber][0] }} &gt; </code></pre> <p>but get the error when use with mysql.connection.cursor() ?</p> <p>Please help me to figure out why this happen and fix it...
0
2016-06-09T10:26:12Z
37,723,637
<p>You <strong>must not</strong> do this. See <a href="https://xkcd.com/327/" rel="nofollow">Little Jonny Tables</a> as to why.</p> <p>Please use the facilities of the DB API that are intended to stop attacks like this. Apart from the security benefit, your code will be simpler and easier to understand as a result.</p...
0
2016-06-09T10:39:53Z
[ "python", "mysql", "flask" ]
How to extract list of lists in python django request.POST
37,723,519
<p>I have posted data from ajax, data include csrfmiddlewaretoken(string), rcount(int) and list of prices. POSTED Data to Django view looks like this.</p> <pre><code>&lt;QueryDict: {u'prices[2][]': [u'2128', u'5', u'06/09/2016', u'12:00 AM'], u'prices[0][]': [u'2147', u'5', u'06/09/2016', u'12:00 AM'], u'rcount': [u'5...
0
2016-06-09T10:34:29Z
37,723,625
<p>It fails because there is no <code>'prices'</code> key in the dictionary you provided.<br> There are instead keys <code>'prices[2][]'</code>, <code>'prices[0][]'</code> and <code>'prices[1][]'</code>. These are ordinary strings. </p> <p>You should check the way that this data get posted. </p>
1
2016-06-09T10:39:13Z
[ "python", "ajax", "django", "post" ]
How to extract list of lists in python django request.POST
37,723,519
<p>I have posted data from ajax, data include csrfmiddlewaretoken(string), rcount(int) and list of prices. POSTED Data to Django view looks like this.</p> <pre><code>&lt;QueryDict: {u'prices[2][]': [u'2128', u'5', u'06/09/2016', u'12:00 AM'], u'prices[0][]': [u'2147', u'5', u'06/09/2016', u'12:00 AM'], u'rcount': [u'5...
0
2016-06-09T10:34:29Z
37,725,625
<p>In continuation to my comments on your original question, you can format data in such a way</p> <pre><code>var records = new Array(); records.push({'key1': 2128, 'key2': 5, 'key3': '06/09/2016', 'key4': '12:00 AM'}) </code></pre> <p>You can push N number of records into your <strong>records</strong> array like th...
1
2016-06-09T12:10:15Z
[ "python", "ajax", "django", "post" ]
Restarting a for-loop with a changed iterator on an exception
37,723,582
<p>I have a block of code which works like for every ID in my Dataframe, it should perform the "TRY" block code and for errors , go to exception, and my data will be changed, and after performing except code,it should again go back to the for loop, but it seems like the Dataframe under the for loop doesn't get updated ...
0
2016-06-09T10:37:25Z
37,726,571
<p>Probably not the solution to your <em>actual</em> problem (since that may solved better differently, but hard to tell), this is one way to re-run a loop with an updated list/data-frame/iterator/whatever:</p> <pre><code>mylist = [-1, 0, 1, 2] while True: print('---:', mylist) for x in mylist: print(x...
1
2016-06-09T12:52:54Z
[ "python", "loops", "for-loop", "try-except" ]
Error when using Inception on TensorFlow (Same output for all pictures)
37,723,808
<p>I'm trying to traing a network on cifar-10 dataset, but on instead of using the pictures I want to use the features from Inceptions' one before last layer.</p> <p>So I wrote a little peace pf code to pass all the pictures in Inception and get the features, here it is:</p> <pre><code>def run_inference_on_images(ima...
1
2016-06-09T10:48:07Z
37,737,113
<p>Not sure. But you might try to move your line </p> <pre><code>features_tensor = sess.graph.get_tensor_by_name('pool_3:0') </code></pre> <p>as</p> <pre><code>features_tensor = tf.get_tensor_by_name('pool_3:0') </code></pre> <p>out from the inference part to the model creation part</p>
0
2016-06-09T22:19:01Z
[ "python", "tensorflow", "deep-learning" ]
Error when using Inception on TensorFlow (Same output for all pictures)
37,723,808
<p>I'm trying to traing a network on cifar-10 dataset, but on instead of using the pictures I want to use the features from Inceptions' one before last layer.</p> <p>So I wrote a little peace pf code to pass all the pictures in Inception and get the features, here it is:</p> <pre><code>def run_inference_on_images(ima...
1
2016-06-09T10:48:07Z
37,807,618
<p>I was able to solve this issue. It seems that Inception doesn't work with numPy arrays like I thought, so I coverted the array to a JPEG picture and only then fed it to the network.</p> <p>Below is the code which works (rest is the same):</p> <pre><code>def run_inference_on_images(images): # Creates graph from s...
0
2016-06-14T09:09:14Z
[ "python", "tensorflow", "deep-learning" ]
Monitoring webpage with live auction
37,723,881
<p>I was wondering, is there a tool for monitoring pages ? To be precise, let's say I would like to monit a webpage with live auctions of cars. Just to get item and price, and I can only monit it live. Unfortunetely prices are not visible before and after auction.</p> <p>One auction (one car - live bidding) lasts for ...
1
2016-06-09T10:51:14Z
37,726,422
<p>The most straight forward way is to download the page with <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a> library every given interval and parse the html page with <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup4</a> library. There are s...
1
2016-06-09T12:46:32Z
[ "python", "web-scraping", "webpage" ]
Pandas resample does not work properly
37,723,906
<p>I am getting a weird behaviour from pandas, I want to resample my minute data to hourly data (using mean). My data looks as follows:</p> <pre><code>Data.head() AAA BBB Time 2009-02-10 09:31:00 86.34 101.00 2009-02-10 09:36:00 86.57 100.50 2009-02-10 09:38:0...
0
2016-06-09T10:52:08Z
37,725,203
<p>The behaviour you show is the expected behaviour for older pandas versions (pandas &lt; 0.18). Newer pandas versions have a changed resample API, of which you see here one of the tricky cases.</p> <p>Before v0.18, <code>resample</code> used the <code>how</code> keyword to specify how to resample, and returned a res...
2
2016-06-09T11:51:29Z
[ "python", "pandas" ]
Method is not allowed for the requested URL
37,723,919
<pre><code>from flask import * from flask_restful import * import sqlite3 import database @app.route('/admin') def admin(): """ hanldes the admin page for user entry """ db = database.database() db.create() db.table('admin') #data = db.print_database('admin') #return render_template ("mylogin...
1
2016-06-09T10:52:36Z
37,724,033
<p>Change your html to this:</p> <pre><code>&lt;h2&gt;welcome admin&lt;/h2&gt; &lt;form action="{{ url_for('admin_post') }}" method ="POST"&gt; &lt;input type = "text" name = "text"&gt; &lt;input type = "submit" name ="my-form" value = "Send"&gt; &lt;/form&gt; </code></pre> <p>What you're basically doing is sen...
1
2016-06-09T10:58:24Z
[ "python", "html", "flask" ]