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 |
|---|---|---|---|---|---|---|---|---|---|
TypeError: 'module' object is not callable in Spacy Python | 39,318,400 | <p>I want to print <code>Parse Tree</code> using <code>Spacy</code>. But the code below is giving the error </p>
<blockquote>
<p>en_nlp = spacy.language('English')
TypeError: 'module' object is not callable</p>
</blockquote>
<p>The error is on this <code>en_nlp = spacy.loads('en')</code> line. I tried to shake of... | 0 | 2016-09-04T15:14:25Z | 39,318,532 | <pre><code>Is it spacy.load('en') or spacy.loads('en') ?
</code></pre>
<p>The official doc <a href="https://spacy.io/docs/" rel="nofollow">https://spacy.io/docs/</a> says :
spacy.load('en').
It may be the problem.</p>
| 0 | 2016-09-04T15:28:15Z | [
"python",
"nlp",
"spacy"
] |
Error using Arabic Wordnet in nltk | 39,318,499 | <p>I am using NLTK Wordnet for Arabic language. When I run the following code :</p>
<pre><code># -*- coding: UTF-8 -*-
from nltk.corpus import wordnet as wn
print wn.synsets('bank')[0].lemma_names('arb')
print wn.synsets('ضÙÙÙÙØ©', lang='arb')0].hypernyms()0].lemma_names(lang='arb') #PROBLEM HERE
</code></pre>
... | 0 | 2016-09-04T15:24:28Z | 39,318,610 | <p>Your code assumes that word <code>'ضÙÙÙÙØ©'</code> will find a conceptual relationship using <code>synsets</code> and that the first item in the set will have hypernym(s). That may not be true. You can instead check if the results returned are non-empty before <em>indexing</em>:</p>
<pre><code>word_synsets = w... | 0 | 2016-09-04T15:35:35Z | [
"python",
"nltk",
"wordnet"
] |
Python restFUL web service - routing to a specific function in a file | 39,318,569 | <p>I am implementing a simple API in python using werkzeug. I have created a simple application 'localhost'. I want to execute a function after a GET request. I am confused with URL routing. I have gone through <a href="http://werkzeug.pocoo.org/docs/0.11/routing/" rel="nofollow">this</a> tutorial and implemented routi... | 0 | 2016-09-04T15:31:14Z | 39,318,791 | <p>If you want to use a function from an external library first of all you have to import the external library </p>
<pre><code>import foo #your library
</code></pre>
<p>And then for calling a function "foo_function" you have to call this function using:</p>
<pre><code>foo.foo_function(args) #where args are declared ... | 0 | 2016-09-04T15:55:23Z | [
"python",
"web-services",
"rest",
"http",
"werkzeug"
] |
Python restFUL web service - routing to a specific function in a file | 39,318,569 | <p>I am implementing a simple API in python using werkzeug. I have created a simple application 'localhost'. I want to execute a function after a GET request. I am confused with URL routing. I have gone through <a href="http://werkzeug.pocoo.org/docs/0.11/routing/" rel="nofollow">this</a> tutorial and implemented routi... | 0 | 2016-09-04T15:31:14Z | 39,319,371 | <blockquote>
<p>The endpoint is typically a string and can be used to uniquely
identify the URL</p>
</blockquote>
<p>So it doesn't bind a function to a url, you have to do it yourself.
After this line</p>
<pre><code>endpoint, args = urls.match()
</code></pre>
<p>you can put some kind of control statements to run... | 0 | 2016-09-04T16:59:11Z | [
"python",
"web-services",
"rest",
"http",
"werkzeug"
] |
File not uploading with Flask-wtforms in cookiecutter-flask app | 39,318,572 | <p>I am having a problem getting a file upload to work in a <a href="https://github.com/sloria/cookiecutter-flask">cookiecutter-flask</a> app (v. 0.10.1). Right now, it is not saving the file uploaded.</p>
<p>Cookiecutter-Flask by default installs WTForms and Flask-WTForms. I have tried adding Flask-Uploads to this bu... | 10 | 2016-09-04T15:31:19Z | 39,530,150 | <p>Looking through the documentation, the link you provided indicates that the <code>data</code> field of <code>csv</code> is an instance of <code>werkzeug.datastructures.FileStorage</code>. The documentation for <a href="http://werkzeug.pocoo.org/docs/0.11/datastructures/#werkzeug.datastructures.FileStorage.save" rel=... | 0 | 2016-09-16T11:15:55Z | [
"python",
"flask",
"flask-wtforms",
"flask-uploads"
] |
File not uploading with Flask-wtforms in cookiecutter-flask app | 39,318,572 | <p>I am having a problem getting a file upload to work in a <a href="https://github.com/sloria/cookiecutter-flask">cookiecutter-flask</a> app (v. 0.10.1). Right now, it is not saving the file uploaded.</p>
<p>Cookiecutter-Flask by default installs WTForms and Flask-WTForms. I have tried adding Flask-Uploads to this bu... | 10 | 2016-09-04T15:31:19Z | 39,531,721 | <p>Try this:</p>
<pre><code>from flask import request
if uploadform.validate_on_submit():
if 'csv' in request.files:
csv = request.files['csv']
csv.save('uploads/csvs/' + csv.filename)
</code></pre>
| 0 | 2016-09-16T12:36:35Z | [
"python",
"flask",
"flask-wtforms",
"flask-uploads"
] |
File not uploading with Flask-wtforms in cookiecutter-flask app | 39,318,572 | <p>I am having a problem getting a file upload to work in a <a href="https://github.com/sloria/cookiecutter-flask">cookiecutter-flask</a> app (v. 0.10.1). Right now, it is not saving the file uploaded.</p>
<p>Cookiecutter-Flask by default installs WTForms and Flask-WTForms. I have tried adding Flask-Uploads to this bu... | 10 | 2016-09-04T15:31:19Z | 39,602,539 | <p>The main reason of your problem lands here:</p>
<pre><code>def validate(self):
"""Validate the form."""
initial_validation = super(UploadForm, self).validate()
if not initial_validation:
return False
</code></pre>
<p>so in <code>validate</code> method of <code>UploadForm</code> class.</p>
<p>L... | 0 | 2016-09-20T19:42:36Z | [
"python",
"flask",
"flask-wtforms",
"flask-uploads"
] |
Get short version of error message with requests | 39,318,631 | <p>I'm using requests and I need a shortened description of the exception,</p>
<pre><code> try:
resp = requests.get(url)
except Exception, e:
data['error'] = str(e)
</code></pre>
<p>e.g for a connection error, <code>str(e)</code> becomes <code>('Connection aborted.', error(61, 'Connection refus... | 0 | 2016-09-04T15:38:19Z | 39,319,191 | <p>The <code>Exception</code> class is the base class of all user-defined exceptions (it a recommandation).</p>
<p>This class inherits the <code>BaseException</code> which has a <a href="https://docs.python.org/2/library/exceptions.html#exceptions.BaseException" rel="nofollow"><code>args</code></a> attributes.
This a... | 0 | 2016-09-04T16:40:25Z | [
"python",
"python-requests"
] |
Bokeh plots not showing in nbviewer | 39,318,640 | <p>I am working on some visualizations using Bokeh in a Jupyter (ipython) notebook. Though the plots run well within my notebook, it is important for me to make them accessible for users not running the code. I was counting on nbviewer for this, but am having trouble. </p>
<p>Using a simple plot for example, I get thi... | 0 | 2016-09-04T15:39:26Z | 39,334,594 | <p>The notebook is an extremely difficult and challenging environment to develop and test Bokeh for. There have been some recent regressions and work to fix them, please refer to GitHub issues <a href="https://github.com/bokeh/bokeh/issues/5014" rel="nofollow">#5014</a> and <a href="https://github.com/bokeh/bokeh/issue... | 0 | 2016-09-05T16:31:16Z | [
"python",
"plot",
"jupyter",
"bokeh"
] |
Selenium Python Chromedriver Change File Download Path | 39,318,701 | <p>I'm looking for a way to save different files to different locations in python using chromedriver. The code below sets chrome to download to folder_path without pop the download location dialogue first.
After clicking and downloading one file into folder_path (I skipped pasting this part of code cause I have no iss... | 1 | 2016-09-04T15:46:26Z | 39,318,889 | <p>No, you have to re-instantiate WebDriver if you want to download to a different directory. Depending on what exactly do you need to do, a workaround described in the first answer <a href="http://stackoverflow.com/a/23897531/1733471">here</a> might be suitable for you (download to a temporary directory then move file... | 0 | 2016-09-04T16:05:34Z | [
"python",
"google-chrome",
"selenium",
"download",
"selenium-chromedriver"
] |
How can I notify RxPY observers on separate threads using asyncio? | 39,318,723 | <p>(Note: The background for this problem is pretty verbose, but there's an SSCCE at the bottom that can be skipped to)</p>
<h2>Background</h2>
<p>I'm trying to develop a Python-based CLI to interact with a web service. In my codebase I have a <code>CommunicationService</code> class that handles all direct communicat... | 1 | 2016-09-04T15:48:23Z | 39,329,176 | <p>I can see two problems with your code:</p>
<ul>
<li>asyncio is not thread-safe, unless you use <a href="https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.call_soon_threadsafe" rel="nofollow">call_soon_threadsafe</a> or <a href="https://docs.python.org/3/library/asyncio-task.html?hig... | 1 | 2016-09-05T11:00:20Z | [
"python",
"multithreading",
"python-3.x",
"python-asyncio",
"rx-py"
] |
QTreeWidget - excluding top level items from sort | 39,318,827 | <p>I have a 2-level QTreeWidget. The top level only has one column and is just used for grouping the second level, which holds the actual multi-column data.</p>
<p>When I sort by clicking on a header (or any other way, really), I only want the second level to be sorted, as the top-level items have a fixed order set el... | 2 | 2016-09-04T15:59:21Z | 39,320,200 | <p>You can use the <a href="http://doc.qt.io/qt-5/qtreewidgetitem.html#sortChildren" rel="nofollow"><code>sortChildren</code></a> method of QTreeWidgetItem(s) like this:</p>
<pre><code>sort_column = 1
# Iterate top-level elements
for index in range(tree.topLevelItemCount()):
# Obtain the actual top-level item
... | 1 | 2016-09-04T18:30:33Z | [
"python",
"sorting",
"pyqt",
"pyqt4",
"qtreewidget"
] |
QTreeWidget - excluding top level items from sort | 39,318,827 | <p>I have a 2-level QTreeWidget. The top level only has one column and is just used for grouping the second level, which holds the actual multi-column data.</p>
<p>When I sort by clicking on a header (or any other way, really), I only want the second level to be sorted, as the top-level items have a fixed order set el... | 2 | 2016-09-04T15:59:21Z | 39,334,199 | <p>I found a solution based on the answer for <a href="http://stackoverflow.com/questions/33676893/qt-qtreewidget-disabling-interaction-for-a-single-column">this</a> question. Catch the sectionClicked signal and check if the clicked column is the first one. If so, force the static sort direction and then manually sort ... | 0 | 2016-09-05T16:03:13Z | [
"python",
"sorting",
"pyqt",
"pyqt4",
"qtreewidget"
] |
QTreeWidget - excluding top level items from sort | 39,318,827 | <p>I have a 2-level QTreeWidget. The top level only has one column and is just used for grouping the second level, which holds the actual multi-column data.</p>
<p>When I sort by clicking on a header (or any other way, really), I only want the second level to be sorted, as the top-level items have a fixed order set el... | 2 | 2016-09-04T15:59:21Z | 39,335,184 | <p>The simplest solution is to create a subclass of <code>QTreeWidgetItem</code> and reimplement its <code>__lt__</code> method so that it always returns <code>False</code>. Qt uses a stable sort algorithm, so this means the items will always retain their original order. This subclass should be used for the top-level i... | 2 | 2016-09-05T17:19:09Z | [
"python",
"sorting",
"pyqt",
"pyqt4",
"qtreewidget"
] |
Creating node in py2neo shows up blank in Neo4j | 39,318,900 | <p>I am new to Neo4j and py2neo. I used the GraphObject model like so:</p>
<pre><code>class Capability(GraphObject):
__primarykey__ = "term"
term = Property()
child_of = RelatedTo("Capability")
parent_to = RelatedTo("Capability")
</code></pre>
<p>After I create a "Capability":</p>
<pre><code>c = Ca... | 0 | 2016-09-04T16:06:47Z | 39,357,682 | <p>After hours of trying to figure out what I don't fully understand regarding Neo4j and the question above - I finally figured it out: "Capability" is some sort of reserved word!</p>
<p>Once I changed the class name from "Capability" to "CapabilityZ" it started working as expected. Ouch. </p>
<p>Still confused since... | 0 | 2016-09-06T20:54:13Z | [
"python",
"neo4j",
"graph-databases",
"py2neo"
] |
Json response data doesn't append to div | 39,318,907 | <p>I dont understand what is the problem with the success function as the ajax call works fine and the data is processed in the view, but in the success function, data doesn't get appended to the div.</p>
<p>My jquery</p>
<pre><code>$(document).ready(function() {
$('#other').click(function() {
var filename... | 0 | 2016-09-04T16:07:12Z | 39,325,595 | <p>Since you commented that you're response is getting printed to the command prompt I assume that you're success function is getting called exactly how it should. Just in case please add following line to your ajax call to log error and if any please comment it.</p>
<pre><code>error: function(xhr, status, error) {
... | 0 | 2016-09-05T07:21:28Z | [
"javascript",
"jquery",
"python",
"html",
"django"
] |
Maintain generator object across function calls | 39,318,953 | <p>let me highlight the problem with the following code:</p>
<pre><code>def genny():
yield 1
yield 2
yield 3
def middleman(input_gen=None):
if input_gen:
gen = input_gen
else:
gen = genny()
return [next(gen), gen]
if __name__ == '__main__':
pro_list = middleman()
pro_... | 1 | 2016-09-04T16:14:18Z | 39,319,326 | <p>It's a bit hard to say without the larger context to which your example (which is understandably a toy example), is referring.</p>
<p>In general, it's perfectly fine to return multiple values from a function (although a <a href="http://stackoverflow.com/questions/354883/how-do-you-return-multiple-values-in-python">... | 1 | 2016-09-04T16:54:22Z | [
"python",
"generator"
] |
Geany - Python execution error: "is not recognized as an internal or external command" | 39,318,985 | <p>I'm trying to run my scripts in Geany and get the following message:</p>
<pre><code>"'C:\Users\Krishn' is not recognized as an internal or external command, operable program or batch file"
</code></pre>
<p>Please see my build configuration as below:</p>
<pre><code>Compile - C:\Users\Krishn Patel\AppData\Local\Pro... | 0 | 2016-09-04T16:18:12Z | 39,319,028 | <p>The problem is you have a space in your windows user name<code>Krishn Patel</code>. You should escape that space by putting <code>^</code> behind it or putting the command between <code>"</code>.
<a href="http://superuser.com/questions/279008/how-do-i-escape-spaces-in-command-line-in-windows-without-using-quotation-... | 1 | 2016-09-04T16:22:48Z | [
"python",
"python-3.x",
"geany"
] |
Geany - Python execution error: "is not recognized as an internal or external command" | 39,318,985 | <p>I'm trying to run my scripts in Geany and get the following message:</p>
<pre><code>"'C:\Users\Krishn' is not recognized as an internal or external command, operable program or batch file"
</code></pre>
<p>Please see my build configuration as below:</p>
<pre><code>Compile - C:\Users\Krishn Patel\AppData\Local\Pro... | 0 | 2016-09-04T16:18:12Z | 39,322,315 | <p>Setting to default resolved the issue
Exec : python "%f"</p>
| 0 | 2016-09-04T23:23:54Z | [
"python",
"python-3.x",
"geany"
] |
How to use a wildcard in python to check for any extension | 39,319,019 | <p>I am trying to check the input to see if it has any extension here is the code I used:</p>
<pre><code>filename=input()
if "." in filename:
print ("There is")
</code></pre>
<p>However this will return "there is" even if the input is ends with just a full stop.<br>
Is there any way to check if the input has an... | 0 | 2016-09-04T16:21:53Z | 39,319,112 | <p>An easy option would be to check for "." in <code>filename</code> with the last character removed:</p>
<pre><code>if len(filename)>1 and "." in filename[:-1]:
print("there is")
</code></pre>
<p>This would allow "file..", which may or may not be what you want. Another idea would be, to split <code>filename<... | 2 | 2016-09-04T16:32:15Z | [
"python",
"wildcard"
] |
How to use a wildcard in python to check for any extension | 39,319,019 | <p>I am trying to check the input to see if it has any extension here is the code I used:</p>
<pre><code>filename=input()
if "." in filename:
print ("There is")
</code></pre>
<p>However this will return "there is" even if the input is ends with just a full stop.<br>
Is there any way to check if the input has an... | 0 | 2016-09-04T16:21:53Z | 39,319,123 | <p>I used the <code>find</code> function to locate the character <code>.</code> in <code>me</code>. If the character doesn't exist in <code>me</code>, the function returns <code>-1</code>. Then, with the index of the <code>.</code> character, I see if there are any characters after that index with <code>len(me[index + ... | 0 | 2016-09-04T16:33:21Z | [
"python",
"wildcard"
] |
How to use a wildcard in python to check for any extension | 39,319,019 | <p>I am trying to check the input to see if it has any extension here is the code I used:</p>
<pre><code>filename=input()
if "." in filename:
print ("There is")
</code></pre>
<p>However this will return "there is" even if the input is ends with just a full stop.<br>
Is there any way to check if the input has an... | 0 | 2016-09-04T16:21:53Z | 39,319,628 | <p>Split the string on the dot and check to see if there was anything after it.</p>
<pre><code>s = 'aaa.'
if s.strip().split('.')[-1]:
print('extension')
else:
print('no extension')
s = 'aaa.bbb'
if s.strip().split('.')[-1]:
print('extension')
else:
print('no extension')
</code></pre>
| 0 | 2016-09-04T17:28:59Z | [
"python",
"wildcard"
] |
is "from flask import request" identical to "import requests"? | 39,319,070 | <p>In other words, is the flask request class identical to the requests library?</p>
<p>I consulted:</p>
<p><a href="http://flask.pocoo.org/docs/0.11/api/" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/</a></p>
<p><a href="http://docs.python-requests.org/en/master/" rel="nofollow">http://docs.python-requests.o... | -1 | 2016-09-04T16:26:46Z | 39,319,106 | <p>No these are not only completely different libraries, but completely different purposes.</p>
<p>Flask is a web framework which clients make requests to. The Flask <code>request</code> object contains the data that the client (eg a browser) has sent to your app - ie the URL parameters, any POST data, etc.</p>
<p>Th... | 4 | 2016-09-04T16:31:48Z | [
"python",
"flask",
"python-requests"
] |
is "from flask import request" identical to "import requests"? | 39,319,070 | <p>In other words, is the flask request class identical to the requests library?</p>
<p>I consulted:</p>
<p><a href="http://flask.pocoo.org/docs/0.11/api/" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/</a></p>
<p><a href="http://docs.python-requests.org/en/master/" rel="nofollow">http://docs.python-requests.o... | -1 | 2016-09-04T16:26:46Z | 39,322,497 | <p>Just want to add something that I think it might be useful, when we use:
<code>from some_module import something</code>, it means we import just a part of the module, <code>something</code> might be a function for example, so if we need only one function from a specific module, it is better to import just that one f... | 2 | 2016-09-04T23:58:41Z | [
"python",
"flask",
"python-requests"
] |
How to convert to Bytes Simply | 39,319,071 | <p>With the file size given to me in MegaBytes (MB) I go ahead and convert it to Bytes:</p>
<pre><code>in_MB = 999.991
in_KB = in_MB * 1024**2
</code></pre>
<p>The resulted value is: 1048566562.82</p>
<p>To verify my calculation is correct I navigate to <a href="https://www.google.com/?ion=1&espv=2#q=1048566562.... | 0 | 2016-09-04T16:26:52Z | 39,319,116 | <p><a href="https://en.wikipedia.org/wiki/Binary_prefix" rel="nofollow">Check out</a> the difference between Mebibyte (1024*1024 Byte) and Megabyte(1000*1000 Byte).</p>
<p>your calculation is correct:<br>
<a href="https://www.google.com/?ion=1&espv=2#q=1048566562.82%20Bytes%20to%20Mebibyte" rel="nofollow"> Google ... | 2 | 2016-09-04T16:32:37Z | [
"python"
] |
How to convert to Bytes Simply | 39,319,071 | <p>With the file size given to me in MegaBytes (MB) I go ahead and convert it to Bytes:</p>
<pre><code>in_MB = 999.991
in_KB = in_MB * 1024**2
</code></pre>
<p>The resulted value is: 1048566562.82</p>
<p>To verify my calculation is correct I navigate to <a href="https://www.google.com/?ion=1&espv=2#q=1048566562.... | 0 | 2016-09-04T16:26:52Z | 39,319,270 | <p>You didn't make a mistake. Historically, memory and disk sizes were calculated using binary (base 2) numbers (2 ^ 20 or 1,048,576 bytes in a megabyte). Google is using the more recent decimal (base 10) representation of a megabyte (10 ^ 6 or 1,000,000) bytes.</p>
<pre><code>>>> megabyte_size = 999.991
>... | 1 | 2016-09-04T16:49:14Z | [
"python"
] |
What is the difference between request.GET['q'] ,request.GET('q'),and request.GET('q',) | 39,319,117 | <p>What is the difference between request.GET['q'] ,request.GET('q'),and request.GET('q',).Thanks</p>
<pre><code>def search(request):
if 'q' in request.GET and request.GET['q']:
q=request.GET['q']
books=Book.objects.filter(title__icontains=q)
return render(request,'search_results.html',{'bo... | -1 | 2016-09-04T16:32:41Z | 39,319,148 | <p><code>if 'q' in request.GET and request.GET['q']</code> it just check for dictionary contains that <code>q</code> key. But it looks ugly. You can do it more pythonic: </p>
<pre><code>q = request.GET.get('q') # returns None if q not in GET
if q:
do your logic
</code></pre>
| 1 | 2016-09-04T16:35:19Z | [
"python",
"django"
] |
Can't read data on TensorFlow | 39,319,197 | <p>Prior to this I converted my input images to TFRecords files. Now I have the following methods that I've mostly gathered from the tutorials and modified a little:</p>
<pre><code>def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features... | 0 | 2016-09-04T16:41:03Z | 39,319,342 | <p>It looks like you are missing a call to <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/train.html#start_queue_runners" rel="nofollow"><code>tf.train.start_queue_runners()</code></a>, which starts the background threads that drive the input pipeline (e.g. some of these are the threads implied by <... | 1 | 2016-09-04T16:57:05Z | [
"python",
"tensorflow"
] |
GtkOverlay hides GtkTextView | 39,319,292 | <p>I'm trying to develop an application using <code>Gtk</code>, and I have run into a problem using <code>GtkOverlay</code>. If I have a <code>GtkOverlay</code> with a <code>GtkTextView</code> that was added using the standard container <code>add</code> method, the text is hidden. However, all other widgets, say for ex... | 1 | 2016-09-04T16:51:21Z | 39,320,180 | <p>I don't know on what system your a running this example but it is working fine for me. The only caveat is that the top button appears over the bottom button and the <code>TextView</code> widget so I have to manually resize the <code>Window</code> to see the text. You can see a screen cast of my situation in this vid... | 1 | 2016-09-04T18:27:41Z | [
"python",
"user-interface",
"haskell",
"gtk"
] |
How do I use a cookie session with pyramid & beaker to properly store a session_id? | 39,319,295 | <p>I am using the pyramid framework with beaker as a back-end for session management, and I want to store a session_id within a signed cookie. The session-id is associated with a real user_id, and the association mappings will be stored in something like redis. Can I simply use the configuration below to achieve this? ... | 1 | 2016-09-04T16:51:50Z | 39,326,333 | <p>The Pyramid Community Cookbook is not official documentation. It is a collection of user-contributed recipes. That one in particular is targeted toward users of the web framework Pylons who are migrating solutions to Pyramid.</p>
<p>Instead you should look at the official documentation on <a href="http://docs.pylon... | 1 | 2016-09-05T08:12:53Z | [
"python",
"session",
"pyramid",
"beaker"
] |
Remove \n from python string | 39,319,412 | <p>I have scraped a webpage using beautiful soup.
I'm trying to get rid of a '<code>\n</code>' character which isnt eliminated despite whatever I try. </p>
<p>My effort so far:</p>
<pre><code>wr=str(loc[i-1]).strip()
wr=wr.replace(r"\[|'u|\\n","")
print(wr)
</code></pre>
<p>Output:</p>
<pre><code> [u'\nWong; Vo... | -1 | 2016-09-04T17:03:44Z | 39,319,482 | <p>You need to escape the backslash or use a raw string. Otherwise, it's a newline character, not a literal <code>\n</code></p>
<p>Also, I don't think beautifulsoup is outputting unicode strings. You see the string representation in python as <code>u'blah'</code></p>
<p>And you shouldn't need a list of elements to re... | 0 | 2016-09-04T17:11:38Z | [
"python",
"parsing",
"strip"
] |
Remove \n from python string | 39,319,412 | <p>I have scraped a webpage using beautiful soup.
I'm trying to get rid of a '<code>\n</code>' character which isnt eliminated despite whatever I try. </p>
<p>My effort so far:</p>
<pre><code>wr=str(loc[i-1]).strip()
wr=wr.replace(r"\[|'u|\\n","")
print(wr)
</code></pre>
<p>Output:</p>
<pre><code> [u'\nWong; Vo... | -1 | 2016-09-04T17:03:44Z | 39,319,639 | <p>You need to escape the newline character (double "\"):</p>
<pre><code>rep=["[","u'","\\n"]
for r in rep:
wr=wr.replace(r,"")
</code></pre>
<p>This is the same as @cricket_007's answer, however, the second part from his answer does not work for me. To my knowledge, str.replace() does not support these kind of r... | 1 | 2016-09-04T17:30:49Z | [
"python",
"parsing",
"strip"
] |
DataFrame Groupby while maintaining original DataFrame | 39,319,556 | <p>I have a DataFrame that has 9 columns which are encoded values for Day of the week(1-7), Week of the Year(1-52), Month of the Year (1-12), Time bin (every 3 hours), Salary Day(0,1) and Holiday(0,1) and Amount(real number). The time is placed in a time bin e.g. 15:00 is placed in 6th time bin and 7:34 is placed in t... | 0 | 2016-09-04T17:21:40Z | 39,319,588 | <p>You can reset the index on temp and then do an outer merge with the original feature dataframe on all the columns you grouped by.</p>
<pre><code>result = features.merge(temp.reset_index(), on=["Day", "Week", "Month", "Time", "Salary", "Holiday"])
</code></pre>
| 0 | 2016-09-04T17:25:15Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
DataFrame Groupby while maintaining original DataFrame | 39,319,556 | <p>I have a DataFrame that has 9 columns which are encoded values for Day of the week(1-7), Week of the Year(1-52), Month of the Year (1-12), Time bin (every 3 hours), Salary Day(0,1) and Holiday(0,1) and Amount(real number). The time is placed in a time bin e.g. 15:00 is placed in 6th time bin and 7:34 is placed in t... | 0 | 2016-09-04T17:21:40Z | 39,319,617 | <p>You can use <code>transform</code> to return a column of the same size of the original data frame, from <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html" rel="nofollow">the docs</a>:</p>
<blockquote>
<p>The transform method returns an object that is indexed the same (same
size) as the one being... | 1 | 2016-09-04T17:28:04Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
Is there any way to let sympy simplify root(-1, 3) to -1? | 39,319,584 | <pre><code>root(-1, 3).simplify()
(-1)**(1/3)//Output
</code></pre>
<p>This is not what I want, any way to simplify this to -1?</p>
| 4 | 2016-09-04T17:24:50Z | 39,319,682 | <p>Try </p>
<pre><code>real_root(-1, 3)
</code></pre>
<p>It's referred to in the doc string of the root function too.</p>
<p>The reason is simple: sympy, like many symbolic algebra systems, takes the complex plane into account when calculating "the root". There are 3 complex numbers that, when raised to the power of... | 8 | 2016-09-04T17:35:21Z | [
"python",
"sympy"
] |
Change all values exceeding threshold to the negative of itself | 39,319,812 | <p>I have an array with a bunch of rows and three columns. I have this code below which changes every value exceeding the threshold, to 0. Is there a trick to make the replace value to the negative of which number exceeds the threshold? Lets say i have an array <code>np.array([[1,2,3],[4,5,6],[7,8,9]])</code>. I choose... | 0 | 2016-09-04T17:48:26Z | 39,319,949 | <p>Try this</p>
<pre><code>In [37]: arr = np.array([[1,2,3],[4,5,6],[7,8,9]])
In [38]: arr[:, column_id] *= (arr[:, column_id] > threshold) * -2 + 1
In [39]: arr
Out[39]:
array([[ 1, 2, 3],
[ 4, 5, 6],
[-7, 8, 9]])
</code></pre>
<hr>
<p>Sorry for editing later. I recommend below, which may b... | 2 | 2016-09-04T18:04:38Z | [
"python",
"numpy"
] |
Change all values exceeding threshold to the negative of itself | 39,319,812 | <p>I have an array with a bunch of rows and three columns. I have this code below which changes every value exceeding the threshold, to 0. Is there a trick to make the replace value to the negative of which number exceeds the threshold? Lets say i have an array <code>np.array([[1,2,3],[4,5,6],[7,8,9]])</code>. I choose... | 0 | 2016-09-04T17:48:26Z | 39,320,610 | <pre><code> import numpy as np
x= list(np.arange(1,10))
b = []
for i in x:
if i > 4:
b.append(-i)
else:
b.append(i)
print(b)
e = np.array(b).reshape(3,3)
print('changed array')
print(e[:,0])
output :
[1, 2, 3, 4, -5, -6, -7, -8, -9]
... | 0 | 2016-09-04T19:19:14Z | [
"python",
"numpy"
] |
Translating email templates in Django | 39,319,837 | <p>I have an HTML template which I send through email using a Django installation. I'm trying to translate the content of the template (I've loaded i18n and all strings are in po files), but I keep getting the email rendered in English. </p>
<p>I have the following code:</p>
<pre><code>htmly = get_template(self.html_... | 1 | 2016-09-04T17:51:10Z | 39,319,923 | <p>You don't seem to be actually activating the translation anywhere; all you've done is send a string, "es", as the LANGUAGE_CODE variable. In order to actually make things translated, you need to <a href="https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#explicitly-setting-the-active-language" rel="nofo... | 1 | 2016-09-04T18:01:37Z | [
"python",
"django",
"email",
"internationalization",
"translation"
] |
Running multiple (i.e. normal and reversed) iterators simultaneously in a "for" loop | 39,319,851 | <p>Haven't found a satisfactory answer so far, hence posting this as a new question. </p>
<p>I have to do the following:</p>
<p>I have a parameter, e.g. <code>test_num = 5</code>.
Now, in a single iteration of a <code>for</code> loop, I want the iterator to run both forwards and backwards simultaneously.</p>
<p>So a... | -2 | 2016-09-04T17:52:55Z | 39,319,892 | <p>Looks like your code is pretty good but you only need 1 iterator.</p>
<pre><code>for x in range(5):
print(str(x)+'_'+str(5-x))
</code></pre>
<p>That will give you the right idea</p>
| 1 | 2016-09-04T17:58:18Z | [
"python",
"for-loop",
"iterator"
] |
Running multiple (i.e. normal and reversed) iterators simultaneously in a "for" loop | 39,319,851 | <p>Haven't found a satisfactory answer so far, hence posting this as a new question. </p>
<p>I have to do the following:</p>
<p>I have a parameter, e.g. <code>test_num = 5</code>.
Now, in a single iteration of a <code>for</code> loop, I want the iterator to run both forwards and backwards simultaneously.</p>
<p>So a... | -2 | 2016-09-04T17:52:55Z | 39,319,926 | <p>If you really want to use two iterators, try using the <code>zip()</code> function:</p>
<pre><code>for i,j in zip(range(5), range(5, 0, -1)):
print "Forward is {0}, backward is {1}".format(i, j)
#Forward is 0, backward is 5.
#Forward is 1, backward is 4.
#Forward is 2, backward is 3.
#Forward is 3, backward is ... | 0 | 2016-09-04T18:02:05Z | [
"python",
"for-loop",
"iterator"
] |
Running multiple (i.e. normal and reversed) iterators simultaneously in a "for" loop | 39,319,851 | <p>Haven't found a satisfactory answer so far, hence posting this as a new question. </p>
<p>I have to do the following:</p>
<p>I have a parameter, e.g. <code>test_num = 5</code>.
Now, in a single iteration of a <code>for</code> loop, I want the iterator to run both forwards and backwards simultaneously.</p>
<p>So a... | -2 | 2016-09-04T17:52:55Z | 39,319,972 | <p>fastest solution:</p>
<pre><code>test_num = 5
for i in range(test_num):
print("Forward is %d, backward is %d."%(i, test_num-i))
</code></pre>
<p>another fast solution(my solution if you wont use <code>test_num-i</code> expression) :</p>
<pre><code>test_num = 5
for i,j in enumerate(range(test_num,0,-1)):
p... | 0 | 2016-09-04T18:07:05Z | [
"python",
"for-loop",
"iterator"
] |
python regex find matched string | 39,319,897 | <p>I am trying to find the matched string in a string using regex in Python. The <code>string</code> looks like this:</p>
<pre><code>band 1 # energy -53.15719532 # occ. 2.00000000
ion s p d tot
1 0.000 0.995 0.000 0.995
2 0.000 0.000 0.000 0.000
tot 0.000 0.996 0.000 0.996
band ... | 1 | 2016-09-04T17:59:02Z | 39,319,931 | <p>You don't want the <code>DOTALL</code> flag. Remove it and use <a href="https://docs.python.org/2/library/re.html#re.MULTILINE" rel="nofollow"><code>MULTILINE</code></a> instead.</p>
<pre><code>pattern = re.compile(r'^\s*tot(.*)', re.MULTILINE)
</code></pre>
<p>This matches all lines that start with <code>tot</cod... | 4 | 2016-09-04T18:02:41Z | [
"python",
"regex"
] |
python regex find matched string | 39,319,897 | <p>I am trying to find the matched string in a string using regex in Python. The <code>string</code> looks like this:</p>
<pre><code>band 1 # energy -53.15719532 # occ. 2.00000000
ion s p d tot
1 0.000 0.995 0.000 0.995
2 0.000 0.000 0.000 0.000
tot 0.000 0.996 0.000 0.996
band ... | 1 | 2016-09-04T17:59:02Z | 39,319,969 | <p>You are using re.DOTALL, which means that the dot "." will match anything, even newlines, in essence finding both "tot"-s and everything that follows until the next newline:</p>
<pre><code> tot
1 0.000 0.995 0.000 0.995
</code></pre>
<p>and</p>
<pre><code>tot 0.000 0.996 0.000 ... | 1 | 2016-09-04T18:06:42Z | [
"python",
"regex"
] |
python regex find matched string | 39,319,897 | <p>I am trying to find the matched string in a string using regex in Python. The <code>string</code> looks like this:</p>
<pre><code>band 1 # energy -53.15719532 # occ. 2.00000000
ion s p d tot
1 0.000 0.995 0.000 0.995
2 0.000 0.000 0.000 0.000
tot 0.000 0.996 0.000 0.996
band ... | 1 | 2016-09-04T17:59:02Z | 39,319,992 | <p>The alternative solution using <code>re.findall</code> function with specific regex pattern:</p>
<pre><code># str is your inital string
result = re.findall('tot [0-9 .]+(?=\n|$)', str)
print(result)
</code></pre>
<p>The output:</p>
<pre><code>['tot 0.000 0.996 0.000 0.996', 'tot 0.000 0.996 0.000 0.996']
... | 1 | 2016-09-04T18:09:04Z | [
"python",
"regex"
] |
Python 3 - float(X) * i = int(Z) | 39,320,068 | <p>I have a very large number, both before and after the decimal, but for this I'll just call it 4.58.</p>
<p>I want to know the number, Y, that will yield me an integer if multiplied by X and not any sort of float number.</p>
<p>Here is my code:</p>
<pre><code>from decimal import *
setcontext(ExtendedContext)
getco... | -4 | 2016-09-04T18:16:20Z | 39,320,106 | <p>Well think of what if you wanted to reach <code>z = 1</code> and then use the fact that <code>z == z * 1</code> to scale the answer. For any float <code>x != 0.0</code>, <code>y = 1/x</code> will yield <code>z = 1</code>, so for arbitrary integer <code>z</code>, just use <code>y = z/x</code>.</p>
| 0 | 2016-09-04T18:19:54Z | [
"python",
"python-3.x",
"loops",
"math",
"floating-point"
] |
Python 3 - float(X) * i = int(Z) | 39,320,068 | <p>I have a very large number, both before and after the decimal, but for this I'll just call it 4.58.</p>
<p>I want to know the number, Y, that will yield me an integer if multiplied by X and not any sort of float number.</p>
<p>Here is my code:</p>
<pre><code>from decimal import *
setcontext(ExtendedContext)
getco... | -4 | 2016-09-04T18:16:20Z | 39,320,131 | <p>I'm not a Python programmer, but what about <a href="https://docs.python.org/3/library/functions.html#round" rel="nofollow">round</a> function?</p>
| 0 | 2016-09-04T18:22:04Z | [
"python",
"python-3.x",
"loops",
"math",
"floating-point"
] |
Python 3 - float(X) * i = int(Z) | 39,320,068 | <p>I have a very large number, both before and after the decimal, but for this I'll just call it 4.58.</p>
<p>I want to know the number, Y, that will yield me an integer if multiplied by X and not any sort of float number.</p>
<p>Here is my code:</p>
<pre><code>from decimal import *
setcontext(ExtendedContext)
getco... | -4 | 2016-09-04T18:16:20Z | 39,320,761 | <p>If I understand your question correctly, you want to find the smallest integer (i) that can be multiplied to a non-integer number (n) so that:</p>
<p>i*n is an integer</p>
<p>I would do this by finding the factors of the numerator and denominator for n. In your example, if n = 4.58, then you can extract 458 for t... | 1 | 2016-09-04T19:36:20Z | [
"python",
"python-3.x",
"loops",
"math",
"floating-point"
] |
imputing missing values using a predictive model | 39,320,135 | <p>I am trying to impute missing values in Python and <code>sklearn</code> does not appear to have a method beyond average (mean, median, or mode) imputation. <a href="http://docs.orange.biolab.si/2/reference/rst/Orange.feature.imputation.html#Orange.feature.imputation.Model" rel="nofollow">Orange imputation model</a> ... | 2 | 2016-09-04T18:23:01Z | 39,322,615 | <p>It seems the issue is that a missing value in Orange is represented as <code>?</code> or <code>~</code>. Oddly enough, the <code>Orange.data.Table(numpy.ndarray)</code> constructor does not infer that <code>numpy.nan</code> should be converted to <code>?</code> or <code>~</code> and instead converts them to <code>1.... | 1 | 2016-09-05T00:28:10Z | [
"python",
"python-2.7",
"scikit-learn",
"orange",
"imputation"
] |
imputing missing values using a predictive model | 39,320,135 | <p>I am trying to impute missing values in Python and <code>sklearn</code> does not appear to have a method beyond average (mean, median, or mode) imputation. <a href="http://docs.orange.biolab.si/2/reference/rst/Orange.feature.imputation.html#Orange.feature.imputation.Model" rel="nofollow">Orange imputation model</a> ... | 2 | 2016-09-04T18:23:01Z | 39,333,351 | <p>In Orange v2 you can pass numpy masked arrays into the Orange.data.Table constructor. Modifying your example:</p>
<pre class="lang-python prettyprint-override"><code>import Orange
import numpy as np
tmp = np.array([[1, 2, np.nan, 5, 8, np.nan], [40, 4, 8, 1, 0.2, 9]])
tmp_masked = np.ma.masked_array(tmp, mask=np.i... | 0 | 2016-09-05T15:04:36Z | [
"python",
"python-2.7",
"scikit-learn",
"orange",
"imputation"
] |
Update a label in tkinter from a button press | 39,320,190 | <p>My question is regarding GUI programming in python by using tkinter. I believe this is Python 3x. </p>
<p>My question: While we're executing a program to run the GUI, can a button update a label? More specifically, is there a way to change the labels displayed text after pushing the button? I have consulted stack o... | 0 | 2016-09-04T18:29:23Z | 39,320,291 | <p>What you have to do is to bind a Button event to the copytextButton object like so:</p>
<pre><code>copytextButton.bind('<Button-1>', copytext)
</code></pre>
<p>This means that a callback function - copytext() will be called when you left-click the button.</p>
<p>A slight modification is needed in the functi... | 0 | 2016-09-04T18:40:46Z | [
"python",
"tkinter"
] |
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with | 39,320,283 | <p>Currently working to use Python to login with Twitter.</p>
<p>Twitter's login page is <a href="https://twitter.com/login" rel="nofollow">here</a>. The source code where the Username and Password input fields are:</p>
<pre><code><div class="LoginForm-input LoginForm-username">
<input
type="text"
class=... | 1 | 2016-09-04T18:39:50Z | 39,323,178 | <p>You should try using <code>WebDriverWait</code> to wait until element visible before interaction to the element as below :-</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expecte... | 1 | 2016-09-05T02:29:46Z | [
"python",
"selenium"
] |
How to pip install a celery task module | 39,320,288 | <p>I have a django REST API setup on one machine (currently in test on local machine but will be on a web server eventually). Let's call this machine "client". I also have a computing server to run CPU-intensive tasks that requires a long execution time. Let's call this machine "run-server".</p>
<p>"run-server" runs a... | 0 | 2016-09-04T18:40:32Z | 39,334,680 | <p>I managed to make it work on my own. The structure above just works. Instead of <code>celery multi start workername -A tasks -l info</code>, you simply replace with <code>celery multi start workername -A proj.tasks -l info</code> and everything works. The same version of the module have to be installed within django... | 0 | 2016-09-05T16:38:52Z | [
"python",
"django",
"rabbitmq",
"celery"
] |
python - ImportError: No module named scipy on Mac | 39,320,344 | <p>It's been so hard to find solution for this problem.</p>
<p>I've been reading on the internet and found this questions on Stackoverflow:</p>
<p><a href="http://stackoverflow.com/questions/29223187/importerror-no-module-named-scipy-after-installing-the-scipy-package">Solution #1</a> and <a href="http://stackoverflo... | 0 | 2016-09-04T18:46:28Z | 39,325,706 | <p>I believe that your issue may be how you are running your code - OS-X can have <strong>both</strong> the system python and a user python installation.</p>
<p>From the command prompt, (the same one that pip tells you that you already have scipy installed), try running your script, <em>which I will assume is called <... | 0 | 2016-09-05T07:30:24Z | [
"python",
"pip",
"homebrew"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,390 | <p>If there is no element in the list, then your <code>i</code> gets bigger and bigger until it becomes <code>i = len(a)</code>. At this point <code>a[i]</code> throws an <code>IndexError</code> since you went above the list size. Simple fix would be to use <code>while i < len(a):</code> instead of <code>while found... | 2 | 2016-09-04T18:52:00Z | [
"python"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,391 | <p>You need to add a condition that <code>if (i == len(a)-1): return False</code>.
Because the index can not exceed the length of list <code>a</code>.</p>
| 1 | 2016-09-04T18:52:02Z | [
"python"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,425 | <p>That's because you are going outside the bounds of the list.</p>
<p>You should add a check so you can return when <code>i > len(a)</code>.</p>
| 2 | 2016-09-04T18:56:14Z | [
"python"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,426 | <pre><code>def is_member(x):
a = [1,5,3,9,4,100]
i = 0
found = False
while found == False:
if i >= len(a):
return False # end of list reached
if x == a[i]:
found = True
break
i += 1
if found == True:
return "True"
else:
... | 1 | 2016-09-04T18:56:15Z | [
"python"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,796 | <p>Try something like this instead:</p>
<pre><code>def is_member(x):
a = [1,5,3,9,4,100]
for i in a:
if i == x:
return "True"
return "False"
</code></pre>
<p>Here we iterate over a, and if any member <code>== x</code> we return "True" right away. If we have not returned by the end of ... | 1 | 2016-09-04T19:40:08Z | [
"python"
] |
Comparing member of a list in Python | 39,320,362 | <p>I'm writing a function (the long way) to test if a number I type in is in the list. I don't want to use the 'in' function. The question is why it only works when I type in numbers that are in the list and I get an error in line <code>if x == a[i]:</code> when a number is not in the list.</p>
<pre><code>def is_membe... | 0 | 2016-09-04T18:48:29Z | 39,320,873 | <p>You can also use a for loop to avoid the index error, try this</p>
<pre><code>def is_member(x):
a = [1,5,3,9,4,100]
for i in range(len(a)):
if x == a[i]:
return True
return False
</code></pre>
| 2 | 2016-09-04T19:48:52Z | [
"python"
] |
ggplot2 plots not rendering points if alpha in geom_points is set to other value than 1 in anaconda | 39,320,372 | <p>I am trying to use R through Anaconda python. rpy2 is installed. The problem I am running into is when I set alpha to a value other than 1 in geom_point the points do not show in the plot but will show if alpha is set to 1. Am I missing something? Here is the code that I am running (Ubuntu16.04):</p>
<pre><code>fro... | 0 | 2016-09-04T18:49:25Z | 39,332,017 | <p>This can happen if the R "graphics device" is not able to handle alpha transparency (this is most likely settled at build time, depending on the libraries used to compile the R devices).</p>
<p>For PNG, try specifying the use of /cairo/:</p>
<pre><code># rpy2 version 2.8.4 of later
# (see https://bitbucket.org/rp... | 1 | 2016-09-05T13:47:08Z | [
"python",
"anaconda"
] |
ggplot2 plots not rendering points if alpha in geom_points is set to other value than 1 in anaconda | 39,320,372 | <p>I am trying to use R through Anaconda python. rpy2 is installed. The problem I am running into is when I set alpha to a value other than 1 in geom_point the points do not show in the plot but will show if alpha is set to 1. Am I missing something? Here is the code that I am running (Ubuntu16.04):</p>
<pre><code>fro... | 0 | 2016-09-04T18:49:25Z | 39,440,578 | <p>I still haven't managed to get ggplot2 to render correctly on the display ( I am not sure if this is a bug in rpy2 or something else). However, I can get ggplot2 to render correctly to file in this case png--I also tested tiff but not pdf or ps. Below is the code. Matplotlib opens the file, reads the image and displ... | 0 | 2016-09-11T20:56:25Z | [
"python",
"anaconda"
] |
Saving wide and deep tensorflow model | 39,320,405 | <p>I'm playing with <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py" rel="nofollow">Wide and Deep learning example from Tensorflow</a>. I would like to save the trained classifier to be used for prediction tasks later on but I don't really see how. The <co... | -1 | 2016-09-04T18:53:33Z | 39,332,892 | <p>Are you looking for <a href="https://www.tensorflow.org/versions/r0.10/how_tos/variables/index.html#saving-and-restoring" rel="nofollow">https://www.tensorflow.org/versions/r0.10/how_tos/variables/index.html#saving-and-restoring</a>?</p>
<p>Specifically <strong>Saving Variables</strong> and <strong>Restoring Variab... | 0 | 2016-09-05T14:35:58Z | [
"python",
"tensorflow"
] |
Saving wide and deep tensorflow model | 39,320,405 | <p>I'm playing with <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py" rel="nofollow">Wide and Deep learning example from Tensorflow</a>. I would like to save the trained classifier to be used for prediction tasks later on but I don't really see how. The <co... | -1 | 2016-09-04T18:53:33Z | 39,358,945 | <p>The checkpoint saving section of <a href="https://www.tensorflow.org/versions/r0.10/tutorials/monitors/index.html" rel="nofollow">this doc</a> should answer your question.</p>
| 1 | 2016-09-06T22:54:39Z | [
"python",
"tensorflow"
] |
How can I determine when Bloomd will scale the bloom filter? | 39,320,415 | <p>I'm using Bloomd and its scalable bloom filter to store/check billions of urls for our broad crawler. It was working very good for first 1-1.5 billion urls and it has been using around 16 GB of memory but it seems that more than 2 billion urls will be added to it soon and I would like to understand when Bloomd will ... | 1 | 2016-09-04T18:54:52Z | 39,336,306 | <p>Your filter is using only 34% of its capacity (size/capacity = 1859303638/5461000000).</p>
| 0 | 2016-09-05T18:59:15Z | [
"python",
"web-scraping",
"web-crawler",
"bloom-filter"
] |
Google AppEngine - Pull Queue - Impossible to delete task: "project name is invalid" | 39,320,437 | <p>I have create a pull queue in the GAE that works fine, I'm able to add elements from the app & retrieve them from my instance with the code below:</p>
<pre><code>from apiclient.discovery import build
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
PRO... | 0 | 2016-09-04T18:57:12Z | 39,320,792 | <p>Should be <code>"s~my-project"</code> if your app is in North America, or <code>"e~my-project"</code> if in Europe.</p>
| 1 | 2016-09-04T19:39:48Z | [
"python",
"google-app-engine",
"pull-queue"
] |
Account Kit: Error verifying the token in the 'access_token' | 39,320,588 | <p>I'm trying to retrieve an access token for an authentication code. I'm using the following format:</p>
<p>GET <a href="https://graph.accountkit.com/v1.0/access_token?grant_type=authorization_code&code=AUTH_CODE&access_token=AA|APP_ID|APP_SECRET" rel="nofollow">https://graph.accountkit.com/v1.0/access_token?... | 1 | 2016-09-04T19:17:08Z | 39,321,277 | <p>They use a different app secret for AccountKit versus the rest of Facebook.</p>
| 0 | 2016-09-04T20:37:37Z | [
"python",
"facebook",
"api",
"http",
"facebook-graph-api"
] |
Account Kit: Error verifying the token in the 'access_token' | 39,320,588 | <p>I'm trying to retrieve an access token for an authentication code. I'm using the following format:</p>
<p>GET <a href="https://graph.accountkit.com/v1.0/access_token?grant_type=authorization_code&code=AUTH_CODE&access_token=AA|APP_ID|APP_SECRET" rel="nofollow">https://graph.accountkit.com/v1.0/access_token?... | 1 | 2016-09-04T19:17:08Z | 40,061,771 | <p>The error is Because of the Facebook App Configuration.</p>
<p>I followed this tutorial regarding <a href="http://mycodde.blogspot.com/2016/10/facebook-accountkit-login-using-mobile.html" rel="nofollow">accountkit setup</a></p>
<p>It shows the solution as below</p>
<p><a href="https://i.stack.imgur.com/W9lPK.png"... | 0 | 2016-10-15T16:55:48Z | [
"python",
"facebook",
"api",
"http",
"facebook-graph-api"
] |
alternating control flow with conditionals or preprocessor | 39,320,598 | <p>Given this code:</p>
<pre><code>for i in range(5):
foo(i)
bar(i)
</code></pre>
<p>I want to add some code between the two <code>print</code> lines such that I can break the loop into two, but only if a certain flag is true, i.e.:</p>
<pre><code>for i in range(5):
foo(i)
if debug: {
continue
for i in rang... | 1 | 2016-09-04T19:18:07Z | 39,320,926 | <p>If I understand correctly, you want to either call functions in batches (all possible args for first function, then all possible args for second function etc) in first case, and arguments in batches in second case (so all function for first arg, then all functions for second arg etc.)</p>
<p>I'd say you have to do ... | 0 | 2016-09-04T19:56:08Z | [
"python"
] |
alternating control flow with conditionals or preprocessor | 39,320,598 | <p>Given this code:</p>
<pre><code>for i in range(5):
foo(i)
bar(i)
</code></pre>
<p>I want to add some code between the two <code>print</code> lines such that I can break the loop into two, but only if a certain flag is true, i.e.:</p>
<pre><code>for i in range(5):
foo(i)
if debug: {
continue
for i in rang... | 1 | 2016-09-04T19:18:07Z | 39,321,591 | <p>Preprocessor derivatives change your code before it ever gets to run. In the C family of languages, for example, the compiler substitutes all expressions within <a href="https://en.wikipedia.org/wiki/C_preprocessor" rel="nofollow">preprocessor</a> blocks before compilation.</p>
<p>In your example, <code>debug</code... | -1 | 2016-09-04T21:19:16Z | [
"python"
] |
alternating control flow with conditionals or preprocessor | 39,320,598 | <p>Given this code:</p>
<pre><code>for i in range(5):
foo(i)
bar(i)
</code></pre>
<p>I want to add some code between the two <code>print</code> lines such that I can break the loop into two, but only if a certain flag is true, i.e.:</p>
<pre><code>for i in range(5):
foo(i)
if debug: {
continue
for i in rang... | 1 | 2016-09-04T19:18:07Z | 39,322,101 | <p>Hmmm we can always store mid-air result in list </p>
<pre><code>n = range(10)
if debug:
n = list(map(lambda x: foo(x),n))+list(map(lambda x: bar(x),n))
else:
n = list(map(lambda x: [foo(x),bar(x)],n))
</code></pre>
| 0 | 2016-09-04T22:40:03Z | [
"python"
] |
Theano: when was the filter_flip parameter for conv2d introduced? (TypeError: __init__() got an unexpected keyword argument 'filter_flip') | 39,320,675 | <p>When was the <code>filter_flip</code> parameter for <code>theano.tensor.nnet.conv2d()</code> introduced in Theano? (i.e., which is the minimum Theano version that supports it?)</p>
<p>My version (<code>0.7.0.dev-8d3a67b73fda49350d9944c9a24fc9660131861c</code>) doesn't have it: </p>
<pre><code>File "/usr/local/lib... | 0 | 2016-09-04T19:25:48Z | 39,321,863 | <p>It appears in <a href="https://github.com/Theano/Theano/blob/rel-0.8.0/theano/tensor/nnet/__init__.py#L35" rel="nofollow">version 0.8.0</a>.</p>
<p>Note that in that release the implementation of <code>theano.tensor.nnet.conv2d()</code> found in <code>theano/tensor/nnet/conv.py</code> <a href="https://github.com/Th... | 1 | 2016-09-04T22:00:48Z | [
"python",
"theano"
] |
Search txt file for varying keyword - then assign to variable | 39,320,765 | <p>I need to search a txt file for keywords in format "i-0xxxyyyzzzz" - where xyz are varying alphanumeric characters.
I would like to then assign each match assigned. Currently I can get as far as:</p>
<pre><code> f = open("file.txt", "r")
searchlines = f.readlines()
f.close()
for i, line in enumerate(searchlines):
... | -2 | 2016-09-04T19:37:22Z | 39,320,971 | <p>I suggest using regular expressions:</p>
<pre><code>import re
token_regex = re.compile('i\-0[0-9a-z]*')
for line in open('file.txt'): // Note: 'r' is the default
// You might find the token several times in the line
matches = token_regex.findall(line)
if matches:
print '\n'.join(matches)
</code></pre... | 0 | 2016-09-04T20:01:04Z | [
"python",
"file",
"search",
"keyword"
] |
Plot date and data continuously matplotlib | 39,320,890 | <p>I have written the following piece of code that collects the data from a file, timestamps it and plots it. I have the working code below:</p>
<pre><code>temp_data=0
x=[datetime.now() + timedelta(hours=-i) for i in range(5)]
y=[temp_data+i for i in range(len(x))]
while True:
f=open("/sys/class/thermal/thermal_z... | 2 | 2016-09-04T19:51:37Z | 39,321,181 | <p>You could open a figure and hold it.</p>
<pre><code>temp_data=0
x=[datetime.now() + timedelta(hours=-i) for i in range(5)]
y=[temp_data+i for i in range(len(x))]
plt.figure() ###### Create figure
while True:
f=open("/sys/class/thermal/thermal_zone0/temp", "r")
#timestamp the data
temp_time=datetime.no... | 1 | 2016-09-04T20:26:05Z | [
"python",
"matplotlib",
"plot"
] |
Django django.contrib.sites where to put migration? | 39,320,897 | <p>the django doc says to change the sites name and domain in the django.contrib.sites framework one should use a migration [1].</p>
<p>But they forgot to mention where I should put this migration. I tried to create a directory named "sites" and a directory named "django.contrib.sites". But no matter in which director... | 0 | 2016-09-04T19:52:17Z | 39,321,347 | <p>Each app in a Django project must have a unique <a href="https://docs.djangoproject.com/en/1.10/ref/applications/#django.apps.AppConfig.label" rel="nofollow">label</a>. Naming your app <code>sites</code> isn't a good idea - it will clash with the <code>django.contrib.sites</code> app unless you change the label in t... | 1 | 2016-09-04T20:45:58Z | [
"python",
"django",
"django-models"
] |
django - can't view data on django admin page | 39,320,906 | <p>Here are the models I am working with:</p>
<pre><code>class Customer(models.Model):
customer_id = models.AutoField(primary_key=True, unique=True)
full_name = models.CharField(max_length=50)
user_email = models.EmailField(max_length=50)
user_pass = models.CharField(max_length=30)
def __str__(sel... | 0 | 2016-09-04T19:53:42Z | 39,320,960 | <p>You don't need to override <code>cleaned_data</code> in your case. Because you already using <code>ModelForm</code> which create <code>CustomerDetail</code> instance after <code>save</code> method called.<br>
View might look like this: </p>
<pre><code>def create_profile(request):
if request.method == 'POST':... | 0 | 2016-09-04T19:59:49Z | [
"python",
"django",
"django-forms",
"modelform"
] |
Python: Matplotlib twin() issue: plotting spread | 39,320,927 | <p>I'm having some issue getting my code to run. The two lines in question are as follows (the code runs fine without them). </p>
<pre><code>ax1_2 = ax1.twinx()
ax1_2.fill_between(date, 0, (ask-bid), alpha = 3, facecolor='g')
</code></pre>
<p>I'm looking to twin their x's and show another plot ontop of my current gra... | 1 | 2016-09-04T19:56:16Z | 39,325,723 | <p>From our comments to the OP, your <code>alpha</code> value is too big. It has to be between 0 and 1. See <a href="http://stackoverflow.com/questions/4320021/matplotlib-transparent-line-plots">here</a> or the <a href="http://matplotlib.org/api/artist_api.html#matplotlib.artist.Artist.set_alpha" rel="nofollow">doc</... | 1 | 2016-09-05T07:32:07Z | [
"python",
"matplotlib"
] |
Filtering serializer response data | 39,321,008 | <p>I have a ManyToMany relation with tag and items:</p>
<pre><code>class Tag(BaseModel):
name = models.CharField(max_length=255) # ToDo Change max length
description = models.TextField(blank=True, null=True)
class Item(BaseModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
image = models.Ima... | 0 | 2016-09-04T20:04:03Z | 39,321,109 | <p>You probaply using serializer for <code>Tag</code> model and declare it in <code>ItemSerializer</code> so view is showing full <code>TagSerializer</code> info.<br>
If you want to show only <code>pk</code> field, just use default representation, don't declare special serializer for <code>Tag</code> in <code>ItemSeria... | 0 | 2016-09-04T20:15:23Z | [
"python",
"django",
"django-rest-framework"
] |
Filtering serializer response data | 39,321,008 | <p>I have a ManyToMany relation with tag and items:</p>
<pre><code>class Tag(BaseModel):
name = models.CharField(max_length=255) # ToDo Change max length
description = models.TextField(blank=True, null=True)
class Item(BaseModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
image = models.Ima... | 0 | 2016-09-04T20:04:03Z | 39,321,126 | <p>use <code>PrimaryKeyRelatedField</code> DRF field in your serializer</p>
<p>Example</p>
<pre><code>class ItemSerializer(serializers.ModelSerializer):
tags = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
model = Item
fields = ('tags', 'image',.....other fields)
<... | 2 | 2016-09-04T20:18:06Z | [
"python",
"django",
"django-rest-framework"
] |
Tabulate - How to Cascade tables | 39,321,014 | <p>I'd like to display two tables next to another using tabulate.</p>
<p>My approach:</p>
<pre><code>test_table1 = tabulate([['Alice', 24], ['Bob', 19]])
test_table2 = tabulate([['Hans', 45], ['John', 38]])
master_headers = ["table1", "table2"]
master_table = tabulate([[test_table1, test_table2]],
... | 3 | 2016-09-04T20:04:48Z | 39,321,613 | <p>I don't really know if this is the best choice that you get, but that's what i came up with</p>
<pre><code>test_table1 = str(tabulate([['Alice', 24], ['Bob', 19]])).splitlines()
test_table2 = str(tabulate([['Hans', 45], ['John', 38]])).splitlines()
master_headers = ["table1", "table2"]
master_table = tabulate([list... | 1 | 2016-09-04T21:23:01Z | [
"python",
"python-3.x"
] |
Python tarfile: how to use tar+gzip compression with follow symbolic link? | 39,321,031 | <p>How could I use tar+gzip compression with "follow symbolic link" feature in Python 3.4? The problem is:</p>
<ul>
<li>tarfile.open() supports "w:gz" mode but does not support "dereference" option</li>
<li>tarfile.tarfile() supports "dereference" but does not support "w:gz" mode</li>
</ul>
<p>Code:</p>
<pre><code>.... | 2 | 2016-09-04T20:07:28Z | 39,321,142 | <p><a href="https://docs.python.org/3/library/tarfile.html#tarfile.open" rel="nofollow"><code>tarfile.open</code></a> is a shortcut for the <a href="https://docs.python.org/3/library/tarfile.html#tarfile.TarFile.open" rel="nofollow"><code>TarFile.open</code></a> classmethod, that in turn calls the <a href="https://docs... | 1 | 2016-09-04T20:19:53Z | [
"python",
"gzip",
"tar",
"dereference",
"tarfile"
] |
How can I interpolate accelerometer data in pandas into fixed sampling rate? | 39,321,207 | <p>I have a frame with accelerometer data, collected from an iPhone device. The avg sampling rate is 100Hz, but I'd like to have a fixed one with all the data (x, y, z) interpolated. Is that possible in pandas?</p>
<p>For example, here is the head of my df:</p>
<pre><code>ts x y z
0.00696... | 0 | 2016-09-04T20:29:31Z | 39,321,447 | <p>Index your dataframe with <code>ts</code>:</p>
<pre><code>df = df.set_index('ts')
</code></pre>
<p>Create the index you need:</p>
<pre><code>index2 = pd.Index(pd.np.arange(0.00, 1.00, .01))
</code></pre>
<p>Merge it with the current index and reindex the dataframe to get additional rows:</p>
<pre><code>df = df.... | 1 | 2016-09-04T20:58:22Z | [
"python",
"pandas"
] |
How can I interpolate accelerometer data in pandas into fixed sampling rate? | 39,321,207 | <p>I have a frame with accelerometer data, collected from an iPhone device. The avg sampling rate is 100Hz, but I'd like to have a fixed one with all the data (x, y, z) interpolated. Is that possible in pandas?</p>
<p>For example, here is the head of my df:</p>
<pre><code>ts x y z
0.00696... | 0 | 2016-09-04T20:29:31Z | 39,321,588 | <p>There's probably a more efficient way to do this, but you could use scipy to interpolate each column to the time array of interest, and then create a new dataframe from the interpolated data.</p>
<pre><code>import numpy as np
import pandas as pd
from scipy import interpolate
# define the time points of interest
fs... | 1 | 2016-09-04T21:18:54Z | [
"python",
"pandas"
] |
Detecting location of translucent black rectangluar area in image matrix Python OpenCV | 39,321,336 | <p>Say I have an image like this:</p>
<p><a href="http://i.stack.imgur.com/G5AlE.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/G5AlE.jpg" alt="enter image description here"></a></p>
<p>I want the <strong>location of the start and end points of the black strip in the image matrix</strong>.</p>
<p>I have trie... | 1 | 2016-09-04T20:44:09Z | 39,322,600 | <p>These lines will always return -1000 + the original point</p>
<pre><code>x1 = int(x0 + 1000*(-b))
x2 = int(x0 - 1000*(-b))
</code></pre>
<p>As you only get into this loop if <code>int(b) == 1:</code></p>
<p>Which means that you need to print the x0 directly, since the above lines will always be <code>(x0 + (-1000... | 1 | 2016-09-05T00:25:09Z | [
"python",
"opencv",
"image-processing",
"opencv-contour"
] |
I have a list of files, I want to iterate and import functions from those files, so as to work on them one by one, python | 39,321,351 | <p>I have a list of files, using command in python <code>from filename import *</code> , works for a single file as I am giving the exact name of the file, but if I want to use it as <code>from list[i] import *</code> to iterate over a list and importing function from files one after the another to work on it, it does... | -2 | 2016-09-04T20:46:09Z | 39,321,473 | <p>If you're looking for dynamic imports, you're looking for the <code>__import__</code> function.</p>
<pre><code>for modl in ('foo', 'bar', 'baz', 'bat',):
__import__('parent.' + modl)
</code></pre>
| 1 | 2016-09-04T21:02:13Z | [
"python",
"file",
"file-handling"
] |
I have a list of files, I want to iterate and import functions from those files, so as to work on them one by one, python | 39,321,351 | <p>I have a list of files, using command in python <code>from filename import *</code> , works for a single file as I am giving the exact name of the file, but if I want to use it as <code>from list[i] import *</code> to iterate over a list and importing function from files one after the another to work on it, it does... | -2 | 2016-09-04T20:46:09Z | 39,321,499 | <p>Use <a href="https://docs.python.org/3/library/importlib.html#importlib.import_module" rel="nofollow">importlib</a> for that:</p>
<pre><code>from importlib import import_module
module_list = [import_module("test.mod{}".format(i)) for i in range(20)]
# OR
module_list = []
for i in range(20):
module_list.appen... | 3 | 2016-09-04T21:05:53Z | [
"python",
"file",
"file-handling"
] |
Why is the order of dict and dict.items() different? | 39,321,424 | <pre><code>>>> d = {'A':1, 'b':2, 'c':3, 'D':4}
>>> d
{'A': 1, 'D': 4, 'b': 2, 'c': 3}
>>> d.items()
[('A', 1), ('c', 3), ('b', 2), ('D', 4)]
</code></pre>
<p>Does the order get randomized twice when I call d.items()? Or does it just get randomized differently? Is there any alternate way t... | 3 | 2016-09-04T20:55:17Z | 39,321,645 | <p>You seem to have tested this on IPython. IPython uses its own specialized pretty-printing facilities for various types, and the pretty-printer for dicts sorts the keys before printing (if possible). The <code>d.items()</code> call doesn't sort the keys, so the output is different.</p>
<p>In an ordinary Python sessi... | 9 | 2016-09-04T21:26:10Z | [
"python",
"python-2.7",
"dictionary",
"ipython"
] |
I want to slice my pandas data frame with a variable that contains a pd.date_range, but it is returning Nan for my data | 39,321,474 | <p>I have loaded data from yahoo finance which includes the headings date, open, high, low, close, volume, adj close. The date is my index for the data frame, and I want to be able to sort this data using the index(date).</p>
<p>The variable month will give an array of the dates that I need, and it will print. The pro... | 0 | 2016-09-04T21:02:26Z | 39,324,384 | <p>Your index is not of type datetime but object. Convert it before using it:</p>
<pre><code>df = df.reset_index()
df.Date = pd.to_datetime(df.Date)
df = df.set_index('Date')
</code></pre>
| 0 | 2016-09-05T05:27:49Z | [
"python",
"pandas",
"dataframe",
"slice"
] |
AttributeError: 'list' object has no attribute 'isdigit' | 39,321,495 | <p>I want to extract POS in pandas. I do as below</p>
<pre><code>import pandas as pd
from nltk.tag import pos_tag
df = pd.DataFrame({'pos': ['noun', 'Alice', 'good', 'well', 'city']})
s = df['pos']
tagged_sent = pos_tag(s.str.split())
</code></pre>
<p>but get a traceback:</p>
<pre><code>Traceback (most recent call l... | 0 | 2016-09-04T21:05:24Z | 39,321,547 | <p>The expression <code>s.str.split()</code> is a <code>list</code> of strings, not a string (expected by <code>pos_tag</code>. Because <code>isdigit</code> is a method of <code>str</code>. </p>
| 0 | 2016-09-04T21:13:30Z | [
"python",
"nltk",
"pos-tagger"
] |
AttributeError: 'list' object has no attribute 'isdigit' | 39,321,495 | <p>I want to extract POS in pandas. I do as below</p>
<pre><code>import pandas as pd
from nltk.tag import pos_tag
df = pd.DataFrame({'pos': ['noun', 'Alice', 'good', 'well', 'city']})
s = df['pos']
tagged_sent = pos_tag(s.str.split())
</code></pre>
<p>but get a traceback:</p>
<pre><code>Traceback (most recent call l... | 0 | 2016-09-04T21:05:24Z | 39,321,548 | <p>You can actually pass <code>Series</code> object to the <code>pos_tag()</code> method directly:</p>
<pre><code>s = df['pos']
tagged_sent = pos_tag(s) # or pos_tag(s.tolist())
print(tagged_sent)
</code></pre>
<p>Prints:</p>
<pre><code>[('noun', 'JJ'), ('Alice', 'NNP'), ('good', 'JJ'), ('well', 'RB'), ('city', 'NN... | 2 | 2016-09-04T21:13:31Z | [
"python",
"nltk",
"pos-tagger"
] |
how to process an upload file in Flask? | 39,321,540 | <p>I have a simple Flask app and I would like for it to process an uploaded excel file and display it's data in the webpage. So far I got a page to upload the excel file.</p>
<p>main.py</p>
<pre><code>from flask import Flask, render_template, send_file, request
from flask_uploads import UploadSet, configure_uploads,... | -1 | 2016-09-04T21:12:09Z | 39,321,640 | <p>You can use <a href="http://pandas.pydata.org/" rel="nofollow">pandas</a> module and first convert the excel file.</p>
<pre><code>import pandas as pd
data_xls = pd.read_excel('your_workbook.xls', 'Sheet1', index_col=None)
data_xls.to_csv('your_csv.csv', encoding='utf-8')
</code></pre>
<p>Pandas is spectacular for ... | 1 | 2016-09-04T21:25:54Z | [
"python",
"html",
"flask"
] |
Can't pickle an RSA key to send over a socket | 39,321,606 | <p>I have a list with a public key and a username that I want to send over a socket.</p>
<p>I found
<a href="http://stackoverflow.com/questions/24423162/how-to-send-an-array-over-a-socket-in-python">how to send an array over a socket in python</a> but using pickling won't work either.</p>
<p>My code:</p>
<pre><code... | 0 | 2016-09-04T21:20:43Z | 39,321,751 | <p>You are trying to send a <a href="https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey" rel="nofollow"><code>RSAPublicKey</code> instance</a>, but this is a data structure managed by SSL, not Python. Because you interact with it through a CFFI... | 0 | 2016-09-04T21:44:37Z | [
"python",
"sockets",
"python-3.x",
"pickle"
] |
How do I get rid of local variable referenced before assignment error? | 39,321,717 | <p>I'm trying to make a simple program that generates a board on which you move around as X.
Code:</p>
<pre><code>from msvcrt import getch
import os
board = []
for x in range(20):
board.append(["O"] * 20)
def print_board(board):
for row in board:
print " ".join(row)
def keys(coordx, coordy):
g... | -2 | 2016-09-04T21:38:07Z | 39,321,745 | <p>Once you call <code>play</code>, you never make any assignments to either <code>coordX</code> or <code>coordY</code>, which would explain why they never change.</p>
| 1 | 2016-09-04T21:43:27Z | [
"python",
"python-2.7"
] |
Globale Variables with Bottlpy (in background) | 39,321,833 | <p>i need to use global variables in my program with either flask or bottle running as a webservice. so far im using bottle as a thread with a snippet i found here: <a href="http://stackoverflow.com/questions/13021762/starting-python-bottle-in-a-thread-process-and-another-daemon-next-to-it">Starting python bottle in a ... | 1 | 2016-09-04T21:56:59Z | 39,353,690 | <p>You're returning an <code>int</code> from <code>hello</code>, but you need to return an iterable (of strings).</p>
<p>Tip: add <code>debug=True</code> to your call to <code>run</code> to get better error info in your response.</p>
<p><code>t = Process(target=run(host='0.0.0.0', port=8080, debug=True))</code></p>
| 0 | 2016-09-06T16:24:00Z | [
"python",
"bottle"
] |
SpaCy, Parsing, Tagging - Output as List | 39,321,886 | <p>I am using spacy for nlp and I have issue printing/outputing results in a concise form. At the moment every output from (token.pos_) goes to a new line.</p>
<p>I was hoping to get it to print, as a list. I can do this in nltk/stanford pos, but spacy's documentation is very obfuscated. I cant seem to find out how th... | 1 | 2016-09-04T22:03:37Z | 39,352,133 | <p>Instead of printing, one could add the results to a list, e.g.</p>
<pre><code>listOfPos = []
for token in words:
listOfPos.append(token.pos_)
print listOfPos
</code></pre>
| 0 | 2016-09-06T14:57:09Z | [
"python",
"spacy"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,321,946 | <p>As mentioned the comments, you can't write <code>for x in</code> followed by a number. I guess what you want is <code>for x in range(my_nums)</code> rather than <code>for x in my_nums</code>.</p>
| 0 | 2016-09-04T22:12:53Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,321,962 | <p>You should be doing this.</p>
<pre><code>def playlist():
nums1 = []
for nums in range(10):
# Get random list of 10 numbers
my_nums = random.randint(10, 90)
nums1.append(my_nums)
print my_nums
even = []
odd = []
for x in nums1:
if x % 2 == 0:
even... | 2 | 2016-09-04T22:15:30Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,321,999 | <p>Creating list with randoms</p>
<pre><code>n = [random.randint(10,90) for x in range(10)]
</code></pre>
<p>Getting even and odds:</p>
<pre><code>even = [x for x in n if x % 2 == 0]
odd = [x for x in n if x % 2 == 1]
</code></pre>
| 2 | 2016-09-04T22:22:21Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,322,177 | <p>This is ultimately what I needed:</p>
<pre><code>def playlist():
nums = []
for nums1 in range(10):
# Get random list of 10 numbers
my_nums = random.randint(10, 90)
nums.append(my_nums)
print (my_nums,end=' ')
even = []
odd = []
for x in nums:
if x % 2 == 0:
even.append(x)
else:
odd... | 0 | 2016-09-04T22:57:47Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,322,255 | <p>There are a few things you seem to have misunderstood:</p>
<ul>
<li><code>range(10)</code> will give you (something that looks like) this list <code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]</code>.
<ul>
<li>You can use it with a for-loop to do something 10 times</li>
</ul></li>
<li><code>random.randint(10, 90)</code> will g... | 0 | 2016-09-04T23:12:58Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Python: Summing Odd/Even Random Numbers Generates TypeError: 'int' object is not iterable | 39,321,898 | <p>Yes, this question has been asked, but I cannot seem to apply the answers to my problem. There are several parts to this problem, and this is the biggest obstacle I've hit.</p>
<p>I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even... | 0 | 2016-09-04T22:05:31Z | 39,332,862 | <p>Following code works:</p>
<pre><code>"""
I need to generate a random list of 10 numbers between 10 & 90. From those random numbers, I need to sum the totals of both the even and odd numbers.
"""
from random import randint
MIN = 10
MAX = 90
sum_odds = sum_evens = 0
for i in range(10):
r... | 0 | 2016-09-05T14:34:29Z | [
"python",
"random",
"range",
"typeerror",
"iterable"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.