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 |
|---|---|---|---|---|---|---|---|---|---|
List of strings, get common substring of n elements, Python | 37,527,585 | <p>My problem is maybe similar to <a href="http://stackoverflow.com/questions/37514193/count-the-number-of-occurrences-of-n-length-not-given-string-in-string-python">this</a>, but another situation.
Consider this list in input :</p>
<pre><code>['ACCCACCCGTGG','AATCCC','CCCTGAGG']
</code></pre>
<p>And the other input... | 0 | 2016-05-30T14:00:32Z | 37,529,807 | <pre><code>import operator
LL = ['ACCCACCCGTGG','AATCCC','CCCTGAGG']
def createLenList(n,LL):
stubs = {}
for l in LL:
for i,e in enumerate(l):
stub = l[i:i+n]
if len(stub) == n:
if stub not in stubs: stubs[stub] = 1
else: stubs[st... | 3 | 2016-05-30T16:01:27Z | [
"python",
"string",
"substring"
] |
Matplotlib: global "switch off" for plotting? | 37,527,616 | <p>I often run experiment scripts that plot various plots and images as they process a video sequence, so that I can monitor/debug the progress. Sometimes I would like to not show the plots so that it processes the video faster. I could just add a switch in my code, but my code is changing with each experiment. So I wo... | 0 | 2016-05-30T14:02:19Z | 37,528,144 | <p><a href="http://matplotlib.org/users/shell.html#controlling-interactive-updating" rel="nofollow">This</a> suggests that turning the interactive mode off should do the trick:</p>
<blockquote>
<p>The interactive property of the pyplot interface controls whether a
figure canvas is drawn on every pyplot command. If... | 0 | 2016-05-30T14:29:16Z | [
"python",
"matplotlib"
] |
From string to pyqt object as variable | 37,527,674 | <p>i have a lot of checkboxes (like 500) which state i want to save. Their names are like:
pr0, pr1, pr2 etc.</p>
<p>What i want to do is:</p>
<pre><code>try:
if self.ui.pr0.isChecked():
pr0 = 1
else:
pr0 = 0
except:
pr0 = 0
</code></pre>
<p>is there a way to put variable into line number... | 0 | 2016-05-30T14:05:00Z | 37,527,807 | <p>You can use the <a href="https://docs.python.org/2/library/functions.html#getattr" rel="nofollow">getattr</a> function from the standard library.</p>
<pre><code>for i in range(500):
var_name = "pr%i" % i
var_value = getattr(self.ui, "pr%i" % i).isChecked()
print "%s has value: %s" % (var_name, var_value)
</co... | 1 | 2016-05-30T14:12:00Z | [
"python",
"variables",
"pyqt"
] |
From string to pyqt object as variable | 37,527,674 | <p>i have a lot of checkboxes (like 500) which state i want to save. Their names are like:
pr0, pr1, pr2 etc.</p>
<p>What i want to do is:</p>
<pre><code>try:
if self.ui.pr0.isChecked():
pr0 = 1
else:
pr0 = 0
except:
pr0 = 0
</code></pre>
<p>is there a way to put variable into line number... | 0 | 2016-05-30T14:05:00Z | 37,552,009 | <p>A more general way would be to use <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qobject.html#findChildren" rel="nofollow"><code>QObject.findChildren</code></a> to dynamically get a list of all checkboxes.</p>
<pre><code>checkboxes = self.ui.findChildren(QtGui.QCheckBox, QtCore.QRegExp(r'pr\d+'))
values = {}
for ... | 1 | 2016-05-31T17:23:05Z | [
"python",
"variables",
"pyqt"
] |
Flask get viewport size | 37,527,706 | <p>a short question: Is there a way to get my browsers viewport size by Flask?</p>
<p>I'm designing a page for many devices, for example: normal PC, iphone etc...</p>
<p>Thank you, FFodWindow</p>
| 1 | 2016-05-30T14:07:04Z | 37,527,918 | <p>That's not really possible until you have a request from the user and explicitly provide that data in the request (or use the UserAgent to map certain devices to viewport sizes, but the user can change the UserAgent so this isn't necessarily reliable).</p>
<p>Flask solely runs on the server, and thus has no idea wh... | 0 | 2016-05-30T14:18:03Z | [
"python",
"html",
"flask"
] |
Python 3 UnicodeEncodeError for characters and smileys in Tweets | 37,527,719 | <p>I'm making a Twitter API, I get tweets about a specific word (right now it's 'flafel'). Everything is fine except this tweet</p>
<blockquote>
<p>b'And when I\'m thinking about getting the chili sauce on my flafel
and the waitress, a Pinay, tells me not to get it cos "hindi yan
masarap."\xf0\x9f\x98\x82'</p>
<... | -2 | 2016-05-30T14:07:35Z | 37,529,595 | <p>The problem could arise at the moment you try to use the unicode character <code>\U0001f602</code> on Windows. Python-3 is fine for converting it from utf-8 to full unicode an back again, but windows is not able to display it.</p>
<p>I tried this piece of code in different ways on a Windows 7 box:</p>
<pre><code>&... | 1 | 2016-05-30T15:49:45Z | [
"python",
"python-3.4",
"tweepy",
"python-unicode"
] |
Python 3 UnicodeEncodeError for characters and smileys in Tweets | 37,527,719 | <p>I'm making a Twitter API, I get tweets about a specific word (right now it's 'flafel'). Everything is fine except this tweet</p>
<blockquote>
<p>b'And when I\'m thinking about getting the chili sauce on my flafel
and the waitress, a Pinay, tells me not to get it cos "hindi yan
masarap."\xf0\x9f\x98\x82'</p>
<... | -2 | 2016-05-30T14:07:35Z | 37,530,609 | <p>As I mentioned in the comments, you can get the names of Unicode codepoints using the standard <a href="https://docs.python.org/3/library/unicodedata.html#module-unicodedata" rel="nofollow">unicodedata</a> module. Here's a small demo:</p>
<pre><code>import unicodedata as ud
test = ('And when I\'m thinking about ge... | 1 | 2016-05-30T16:59:19Z | [
"python",
"python-3.4",
"tweepy",
"python-unicode"
] |
from urllib3 HTTPSConnectionPool request_encode_body certificate issue | 37,527,810 | <p>I'm trying to sent a request on https url to get data, the domain needs security certificate when I try to execute it on the browser.</p>
<p><strong>But my issue is how to call the url on my python code to get the response data?
I've write the follwing code:</strong></p>
<pre><code>conn = HTTPSConnectionPool(BETTI... | 0 | 2016-05-30T14:12:11Z | 37,530,300 | <p>Please understand the your Chrome certificate store is not the same certificate store that is used by your Python application.</p>
<p>It would be much easier if you could only get a valid SSL certificate instead of trying to make self-signed ones to work.</p>
<p>Also, be sure you do upgrade your Python and urllib.... | 1 | 2016-05-30T16:37:43Z | [
"python",
"ssl"
] |
How to select from drop down box using selenium webdriver | 37,527,831 | <p>I am trying to select <strong>Channel</strong> in a webpage from Drop Down Box using selenimum webdriver (Python). HTML is given below:</p>
<pre><code> <iframe id="page" frameborder="0" src="DashBoard.htm" onfocus="this.blur()" scrolling="no" cellspacing="0" border="0" name="page" style="width: 1076px; height:... | 0 | 2016-05-30T14:13:31Z | 37,527,943 | <p>yes please try with xpath</p>
<pre><code>driver.find_element_by_xpath("//*[@id='setting_2G']/table/tbody/tr[5]/td[2]/select").send_keys("12")
</code></pre>
<p><strong>UPDATE</strong></p>
<p>so in that case you have to switch to frame then <strong>(Please note i am a java guy so below answer is in java for python ... | 0 | 2016-05-30T14:19:04Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Keras, cost function for cyclic outputs? | 37,527,832 | <p>Right now I am trying to get a neural net to colorize images. I want to do it in the HSV color space. The issue with this is that the hue channel is cyclic. The normalized values for hue are between 0 and 1. Say for instance the model predicts 0.99 but the actual hue is 0.01. With normal mean squared error loss... | 1 | 2016-05-30T14:13:35Z | 37,531,337 | <p>The true distance from predicted hue <code>A</code> to actual hue <code>B</code> is really the minimum of 3 terms: </p>
<ol>
<li><code>(A - B)^2</code> (distance if you don't wrap around)</li>
<li><code>(A - B + 1)^2</code> (distance if you wrap around to the left)</li>
<li><code>(A - B - 1)^2</code> (distance if y... | 1 | 2016-05-30T17:55:29Z | [
"python",
"neural-network",
"keras"
] |
Pycharm: Attribute Error | 37,527,884 | <p>I have a project in Pycharm:</p>
<p>ProjectName (set as SourceRoot)</p>
<pre><code>|_package1
|- __init__.py
- package1.py
|_package2
|- __init__.py
- secondpythonfile.py
</code></pre>
<p>The firstpythonfile.py contains the function placementfunction().</p>
<p>From secondpythonfile.py I want to call ... | 0 | 2016-05-30T14:16:28Z | 37,528,354 | <p>Ok, I figured it out. Pycharm didn't like the fact that my package name 'package1' was the same as the file name package1.py inside. As soon as I changed it it worked.</p>
| 0 | 2016-05-30T14:41:03Z | [
"python",
"import",
"module",
"pycharm",
"attributeerror"
] |
Sorting data from a table | 37,527,900 | <p>I'm working on a new version of a module and I need to create a new table for that, but I'm facing a little issue that is driving me crazy.</p>
<p>Here is my relevant python code:</p>
<pre><code>import psycopg2, sys, psycopg2.extras, time
order = 4419
try:
con = psycopg2.connect(host='localhost', database='D... | 0 | 2016-05-30T14:17:07Z | 37,530,806 | <p>Its seems you have two tables. This way you only making 2 trips to the database vs many. </p>
<p>Do a fetches -- to get data from tables</p>
<p>Table one</p>
<pre><code>ID ORDER PRODUCT QTY CAT
12811 4419 "Crudo GR" 1.0 1
12812 4419 "Salame e Grana GR" ... | 1 | 2016-05-30T17:13:36Z | [
"python",
"python-2.7",
"sorting",
"psycopg2"
] |
Sorting data from a table | 37,527,900 | <p>I'm working on a new version of a module and I need to create a new table for that, but I'm facing a little issue that is driving me crazy.</p>
<p>Here is my relevant python code:</p>
<pre><code>import psycopg2, sys, psycopg2.extras, time
order = 4419
try:
con = psycopg2.connect(host='localhost', database='D... | 0 | 2016-05-30T14:17:07Z | 37,593,281 | <p>Temporary solved with the HUGE help of @Merlin, he drove me to the right direction but I needed to arrange the code. The big trick was to select the lines in DESC from table.</p>
<pre><code>po_lines = '''SELECT pos_order_line.id, pos_order_line.order_id, product_template.name, pos_order_line.qty, product_template.p... | 0 | 2016-06-02T13:28:11Z | [
"python",
"python-2.7",
"sorting",
"psycopg2"
] |
Can't decode extremely simple JSON in python | 37,528,099 | <p>I keep getting 'JSON could not be decoded' when I run this extremely simple piece of code:</p>
<pre><code>import json
dic = {'John':0}
test = open('testjson.json','w+')
json.dump(dic,test)
datos = json.load(test)
</code></pre>
<p>The file is written correctly as when I open it I can see the JSON just fine, proble... | 0 | 2016-05-30T14:27:17Z | 37,528,147 | <p>You should seek back to the start of the file before reading it again: </p>
<pre><code>test.seek(0)
datos = json.load(test)
</code></pre>
| 0 | 2016-05-30T14:29:19Z | [
"python",
"json",
"decode"
] |
Can't decode extremely simple JSON in python | 37,528,099 | <p>I keep getting 'JSON could not be decoded' when I run this extremely simple piece of code:</p>
<pre><code>import json
dic = {'John':0}
test = open('testjson.json','w+')
json.dump(dic,test)
datos = json.load(test)
</code></pre>
<p>The file is written correctly as when I open it I can see the JSON just fine, proble... | 0 | 2016-05-30T14:27:17Z | 37,528,416 | <p>Why not just load the json from <code>dic</code>?</p>
<pre><code>datos = json.dumps(dic)
</code></pre>
<p>You don't have to load it from file.</p>
| 0 | 2016-05-30T14:43:57Z | [
"python",
"json",
"decode"
] |
searching and appending to line in python | 37,528,135 | <p>I'm trying to write a program to edit config files and the text is broken up into "paragraphs" </p>
<p>I want to search the file and find the "correct" paragraph - easy can do it with regex. </p>
<p>but from there I want to go down a few lines into say the middle of the paragraph/chunk of text and append to the e... | 0 | 2016-05-30T14:28:53Z | 37,528,449 | <p>You could read the file into a string and then use string splitting. Let's say you have three lines:</p>
<pre><code>config item one: True
config item two: "A"
config item three: 42
</code></pre>
<p>Using the answers from this question <a href="http://stackoverflow.com/questions/743806/split-string-into-a-list-in-p... | 0 | 2016-05-30T14:45:44Z | [
"python",
"regex",
"python-2.7"
] |
searching and appending to line in python | 37,528,135 | <p>I'm trying to write a program to edit config files and the text is broken up into "paragraphs" </p>
<p>I want to search the file and find the "correct" paragraph - easy can do it with regex. </p>
<p>but from there I want to go down a few lines into say the middle of the paragraph/chunk of text and append to the e... | 0 | 2016-05-30T14:28:53Z | 37,530,105 | <p>So I managed to get something working (just need to add a loop to write Ar to a file)</p>
<pre><code>Ar = []
file = open("path/To/File", "r")
for line in file:
Ar.append(line)
pattern = "(\s*hostgroup_name\s*"+host_group+"\s*)"
p1 = re.compile(patt... | 0 | 2016-05-30T16:23:10Z | [
"python",
"regex",
"python-2.7"
] |
How to download a specific file type from all subdirectories of an FTP server? | 37,528,170 | <p>I am trying to download all <code>.laz</code> files from the FTP host <code>gis.arkansas.gov</code> (more details <a href="http://gis.arkansas.gov/?page_id=7813" rel="nofollow">here</a>). Looking at the <a href="https://docs.python.org/2.7/library/ftplib.html" rel="nofollow"><code>ftplib</code></a> documentation, I ... | 0 | 2016-05-30T14:30:26Z | 37,529,135 | <p>There's no magic.</p>
<p>You have to:</p>
<ul>
<li>recurse into the subdirectories,</li>
<li>list their contents one by one,</li>
<li>filter all <code>.laz</code> files,</li>
<li>call <code>retrbinary</code> for each.</li>
</ul>
| 0 | 2016-05-30T15:21:08Z | [
"python",
"download",
"ftp",
"ftplib"
] |
Designing a customized search page | 37,528,183 | <p>I am trying to find the best way to design the following search page in my website:</p>
<p>I have a database of pre-calculated measurements for a huge number of neurons.
Each measurment object holds more than 20 fields for each neuron.
The search page should provide a range of two values [min-max] for each fieldin ... | 1 | 2016-05-30T14:31:06Z | 37,530,494 | <ul>
<li>Make a <code>ModelForm</code> based on your <code>Measurement</code> model. (say <code>MeasurementModelForm</code>)</li>
<li>Pass them as two different context variable.
<code>context["form1"] = MeasurementModelForm()</code> and <code>context["form2"] = MeasurementModelForm()</code></li>
<li><p>Render both for... | 0 | 2016-05-30T16:51:02Z | [
"python",
"django"
] |
How to get the home page URL link | 37,528,213 | <p>Let's say I am on the webpage
<code>https://company.slack.com/messages/@user1/</code></p>
<p>How could I get the URL of home page of the company/website in Java/Python which is <code>https://slack.com/</code>
(in this case)</p>
<p>Now this seems so easy for some cases, but I want to generalise this & unable to... | 2 | 2016-05-30T14:32:35Z | 37,528,292 | <p>You can use something like this:</p>
<pre><code>URL aURL = new URL("https://company.slack.com/messages/@user1/");
System.out.println(aURL.getProtocol() + "://" + aURL.getHost());
</code></pre>
<p>Which prints:</p>
<pre><code>https://company.slack.com
</code></pre>
<p>This works for other URLs too. See <a href="h... | 1 | 2016-05-30T14:38:03Z | [
"java",
"python",
"url"
] |
How to make migrations for a reusable Django app? | 37,528,286 | <p>I am making a reusable Django app without a project. This is the directory structure:</p>
<pre><code>/
/myapp/
/myapp/models.py
/myapp/migrations/
/myapp/migrations/__init__.py
</code></pre>
<p>When I run <code>django-admin makemigrations</code> I get the following error:</p>
<pre><code>django.core.exceptions.Imp... | 0 | 2016-05-30T14:37:48Z | 37,529,361 | <p>You need a functional Django project (with your app installed in it) to make migrations. </p>
<p>A common way to do this is to have a "test" project which contains the bare necessities of a Django project, that you can run to make migrations etc. The migrations will be created in the right place inside your app dir... | 1 | 2016-05-30T15:34:52Z | [
"python",
"django",
"migration"
] |
removing unicode bullets with regex (python) - not finding bullet | 37,528,299 | <p>I searched around the forums a bit, attempted to remove bullets with every solution that seemed to apply.</p>
<p>"Fremont · Full Time"</p>
<p>Any idea on how I can slice the string to extract just "Fremont"?</p>
<p>I currently have this to remove bullets, but I get the following two errors:</p>
<pre><code>strin... | -1 | 2016-05-30T14:38:21Z | 37,528,415 | <p><strong>This will do it</strong></p>
<pre><code>import string
string_to_replace = "Fremont · Full Time"
regex = '\xc2\xb7'
string.replace(string_to_replace, regex, '')
</code></pre>
<p><strong>How I found this out</strong></p>
<pre><code>>>> a = "Fremont · Full Time"
>>> a.split()
['Fremont', ... | 1 | 2016-05-30T14:43:53Z | [
"python",
"regex",
"unicode"
] |
removing unicode bullets with regex (python) - not finding bullet | 37,528,299 | <p>I searched around the forums a bit, attempted to remove bullets with every solution that seemed to apply.</p>
<p>"Fremont · Full Time"</p>
<p>Any idea on how I can slice the string to extract just "Fremont"?</p>
<p>I currently have this to remove bullets, but I get the following two errors:</p>
<pre><code>strin... | -1 | 2016-05-30T14:38:21Z | 37,529,306 | <p>If you want to split that string into <code>"Fremont"</code> and <code>"Full Time"</code> just use:</p>
<pre><code>>>> import re
>>> re.split(u"\s*·\s*", u"Fremont · Full Time")
[u'Fremont', u'Full Time']
</code></pre>
| 0 | 2016-05-30T15:31:38Z | [
"python",
"regex",
"unicode"
] |
How to load second .ui into self with PyQt4.uic.loadUi? | 37,528,339 | <p>I'm creating an application which loads a couple of .ui files. The first one is of type QMainWindow and the others are of type QWidget.</p>
<p>I can't figure out how to load the second UI (<code>module.ui</code>) into self, making widgets accessible through <code>self.<widget_name></code>.</p>
<p>How can thi... | 0 | 2016-05-30T14:40:25Z | 37,575,498 | <p>You need to create a widget to load the ui file onto</p>
<pre><code>self.widget = QWidget(self)
uic.loadUi('module.ui', self.widget)
self.widget.label.setText('Hello')
</code></pre>
<p>That being said, it would probably be better if you created a separate class for the other widget.</p>
<pre><code>class MyWidget... | 1 | 2016-06-01T17:44:31Z | [
"python",
"pyqt4",
"pyqt5"
] |
KeyError: "Stemming algorithm not found" using Snowballstemmer for Arabic | 37,528,371 | <p>I installed this stemmer for arabic language <a href="http://www.arabicstemmer.com/python/" rel="nofollow">Here</a>. I was running it with this code :</p>
<pre><code>from snowballstemmer import stemmer
ar_stemmer = stemmer("arabic")
ar_stemmer.stemWord(u"ÙØ³Ù
ÙØªÙ
ÙÙØ§")
</code></pre>
<p>And when I run it, I g... | 3 | 2016-05-30T14:41:49Z | 37,528,549 | <p>I once worked with SnowballStemmer,
this was the way it worked for me:</p>
<pre><code>>>> from nltk.stem import SnowballStemmer
>>> print(" ".join(SnowballStemmer.languages)) # See which languages are supported
danish dutch english finnish french german hungarian
italian norwegian porter portugue... | 0 | 2016-05-30T14:51:01Z | [
"python",
"arabic",
"stemming",
"snowball",
"arabic-support"
] |
KeyError: "Stemming algorithm not found" using Snowballstemmer for Arabic | 37,528,371 | <p>I installed this stemmer for arabic language <a href="http://www.arabicstemmer.com/python/" rel="nofollow">Here</a>. I was running it with this code :</p>
<pre><code>from snowballstemmer import stemmer
ar_stemmer = stemmer("arabic")
ar_stemmer.stemWord(u"ÙØ³Ù
ÙØªÙ
ÙÙØ§")
</code></pre>
<p>And when I run it, I g... | 3 | 2016-05-30T14:41:49Z | 37,528,556 | <p>Simple: snowballstemmer doesn't support arabic.</p>
<p>You can find the supported languages here: <a href="https://pypi.python.org/pypi/snowballstemmer" rel="nofollow">snowballstemmer</a></p>
<p>The solution is to use another stemmer. Try ISRIStemmer from nltk.stem.isri, for example. And take a look at this topic:... | 0 | 2016-05-30T14:51:28Z | [
"python",
"arabic",
"stemming",
"snowball",
"arabic-support"
] |
KeyError: "Stemming algorithm not found" using Snowballstemmer for Arabic | 37,528,371 | <p>I installed this stemmer for arabic language <a href="http://www.arabicstemmer.com/python/" rel="nofollow">Here</a>. I was running it with this code :</p>
<pre><code>from snowballstemmer import stemmer
ar_stemmer = stemmer("arabic")
ar_stemmer.stemWord(u"ÙØ³Ù
ÙØªÙ
ÙÙØ§")
</code></pre>
<p>And when I run it, I g... | 3 | 2016-05-30T14:41:49Z | 37,531,491 | <p>Don't install the version of snowballstemmer from PyPi cause it doesn't support Arabic yet. Install the version provided in the <a href="http://www.arabicstemmer.com/python/" rel="nofollow">link</a>. It has <a href="http://www.arabicstemmer.com/" rel="nofollow">this Arabic stemmer</a> inside. You can do this by down... | 4 | 2016-05-30T18:07:44Z | [
"python",
"arabic",
"stemming",
"snowball",
"arabic-support"
] |
How to remove all text between the outer parentheses in a string? | 37,528,373 | <p>When I have a string like this:</p>
<pre><code>s1 = 'stuff(remove_me)'
</code></pre>
<p>I can easily remove the parentheses and the text within using</p>
<pre><code># returns 'stuff'
res1 = re.sub(r'\([^)]*\)', '', s1)
</code></pre>
<p>as explained <a href="http://stackoverflow.com/questions/640001/how-can-i-rem... | 2 | 2016-05-30T14:41:51Z | 37,528,473 | <p><code>re</code> matches are eager so they try to match as much text as possible, for the simple test case you mention just let the regex run:</p>
<pre><code>>>> re.sub(r'\(.*\)', '', 'stuff(remove(me))')
'stuff'
</code></pre>
| 2 | 2016-05-30T14:46:57Z | [
"python",
"regex",
"parentheses"
] |
How to remove all text between the outer parentheses in a string? | 37,528,373 | <p>When I have a string like this:</p>
<pre><code>s1 = 'stuff(remove_me)'
</code></pre>
<p>I can easily remove the parentheses and the text within using</p>
<pre><code># returns 'stuff'
res1 = re.sub(r'\([^)]*\)', '', s1)
</code></pre>
<p>as explained <a href="http://stackoverflow.com/questions/640001/how-can-i-rem... | 2 | 2016-05-30T14:41:51Z | 37,528,524 | <p>If you are sure that the parentheses are initially balanced, just use the <em>greedy</em> version:</p>
<pre><code>re.sub(r'\(.*\)', '', s2)
</code></pre>
| 1 | 2016-05-30T14:49:39Z | [
"python",
"regex",
"parentheses"
] |
How to remove all text between the outer parentheses in a string? | 37,528,373 | <p>When I have a string like this:</p>
<pre><code>s1 = 'stuff(remove_me)'
</code></pre>
<p>I can easily remove the parentheses and the text within using</p>
<pre><code># returns 'stuff'
res1 = re.sub(r'\([^)]*\)', '', s1)
</code></pre>
<p>as explained <a href="http://stackoverflow.com/questions/640001/how-can-i-rem... | 2 | 2016-05-30T14:41:51Z | 37,528,585 | <p><a href="https://regex101.com/r/kQ2jS3/1" rel="nofollow">https://regex101.com/r/kQ2jS3/1</a></p>
<pre><code>'(\(.*\))'
</code></pre>
<p>This captures the <code>furthest</code> parentheses, and everything in between the parentheses.</p>
<p>Your old regex captures the first parentheses, and everything between to th... | 0 | 2016-05-30T14:52:46Z | [
"python",
"regex",
"parentheses"
] |
How to remove all text between the outer parentheses in a string? | 37,528,373 | <p>When I have a string like this:</p>
<pre><code>s1 = 'stuff(remove_me)'
</code></pre>
<p>I can easily remove the parentheses and the text within using</p>
<pre><code># returns 'stuff'
res1 = re.sub(r'\([^)]*\)', '', s1)
</code></pre>
<p>as explained <a href="http://stackoverflow.com/questions/640001/how-can-i-rem... | 2 | 2016-05-30T14:41:51Z | 37,531,494 | <p>As mentioned before, you'd need a <a href="http://www.rexegg.com/regex-recursion.html" rel="nofollow">recursive regex</a> for matching arbitrary levels of nesting but if you know there can only be a maximum of one level of nesting have a try with this pattern:</p>
<pre><code>\((?:[^)(]|\([^)(]*\))*\)
</code></pre>
... | 1 | 2016-05-30T18:07:50Z | [
"python",
"regex",
"parentheses"
] |
How to remove all text between the outer parentheses in a string? | 37,528,373 | <p>When I have a string like this:</p>
<pre><code>s1 = 'stuff(remove_me)'
</code></pre>
<p>I can easily remove the parentheses and the text within using</p>
<pre><code># returns 'stuff'
res1 = re.sub(r'\([^)]*\)', '', s1)
</code></pre>
<p>as explained <a href="http://stackoverflow.com/questions/640001/how-can-i-rem... | 2 | 2016-05-30T14:41:51Z | 37,538,815 | <p><strong>To remove nested parentheses correctly with a regular expression in Python</strong>, you need to install the PyPi <code>regex</code> module and run the following regex:</p>
<pre><code>\((?>[^()]++|(?R))*\)
</code></pre>
<p>See the <a href="https://regex101.com/r/yB8tY9/1" rel="nofollow">regex demo at re... | 1 | 2016-05-31T06:55:55Z | [
"python",
"regex",
"parentheses"
] |
String indices must be integers error | 37,528,517 | <p>I am looking to parse out json obtained from following code:</p>
<pre><code>import json
from watson_developer_cloud import ToneAnalyzerV3Beta
import urllib.request
import codecs
reader = codecs.getreader("utf-8")
tone_analyzer = ToneAnalyzerV3Beta(
url='https://gateway.watsonplatform.net/tone-analyzer/api',
... | 0 | 2016-05-30T14:49:21Z | 37,528,595 | <p><code>json.dumps()</code> converts an object into a string. So, <code>data</code> is a string. So, you can't index it with <code>'document_tone'</code> key (it's not a <code>dict</code>). Maybe you meant <code>json.loads()</code>? Or maybe <code>tone_analyzer.tone()</code> already returns a <code>dict</code> and the... | 1 | 2016-05-30T14:53:35Z | [
"python"
] |
Override table using bq command line | 37,528,572 | <p>I have a Python script (shown below) that runs the query in 'query.txt' and uploads it to google big query. This script has to run every 5 minutes. First time it does correctly, but for the second time, it throws the error "table already exists". I have to override the table if it already exists. I do not find any o... | 0 | 2016-05-30T14:52:05Z | 37,528,817 | <p>run <code>bq help query</code> and check <code>replace</code> flag</p>
<p>--[no]replace: If true, erase existing contents before loading new data.
(default: 'false')</p>
| 0 | 2016-05-30T15:05:53Z | [
"python",
"google-bigquery"
] |
python multiprocessing pool.map hangs | 37,528,646 | <p>I cannot make even the simplest of examples of parallel processing using the multiprocessing package run in python 2.7 (using spyder as a UI on windows) and I need help figuring out the issue. I have run conda update so all of the packages should be up to date and compatible. </p>
<p>Even the first example in the ... | 1 | 2016-05-30T14:56:40Z | 37,529,749 | <p>After installing spyder on my virtualmachine, it seems to be a spyder specific bug. Example 1 works in IDLE, executed via the command line, executed from within spyder (first saved and then executed), but not when executed line by line in spyder.</p>
<p>I would suggest simply to create a new file in spyder, add the... | 1 | 2016-05-30T15:57:51Z | [
"python",
"dictionary",
"multiprocessing",
"hang",
"pool"
] |
Regular Expression Findall Stopping Search in First Occur | 37,528,650 | <p>I am trying to find a certain string with RegEx.
I want to find "something starting with 'f' and ending with first 2" (it must contain only one 2). In this example I want to find <code>result = "fdba12"</code> but the code at below is giving me <code>'fdba12312'</code> (containing two 2). How can I stop searching wh... | 2 | 2016-05-30T14:56:45Z | 37,528,741 | <p>The problem is that your regex contains a <code>\w*</code> pattern that can also match the adjoining <code>2</code> pattern. There are 2 ways to achieve what you need: 1) using a lazy quantifier suggested by rock321987, and 2) use a reverse shorthand char class inside a negated character class <code>[^...]</code> an... | 1 | 2016-05-30T15:02:16Z | [
"python",
"regex",
"search",
"find",
"findall"
] |
Python Pygame won't quit | 37,528,737 | <p>The code colors a pixel one by one and essentially prints a picture. I can't get it to quit though if I press the X to close or if I press Esc. I've put all the pg.event.get() code outside the main while loop, inside the main while loop, inside the secondary for loop, inside the tertiary for loop. I've ran it using ... | 1 | 2016-05-30T15:01:57Z | 37,541,116 | <p>You're doing the whole pixel transformation without checking for events. Here's your flow in pseudo code:</p>
<pre><code>loop until break:
check events
loop through pixels
transform pixels
break
</code></pre>
<p>Instead, you should ditch the <code>while loop</code>, make <code>check_for_quit</... | 1 | 2016-05-31T08:54:13Z | [
"python",
"pygame",
"exit"
] |
Python Pygame won't quit | 37,528,737 | <p>The code colors a pixel one by one and essentially prints a picture. I can't get it to quit though if I press the X to close or if I press Esc. I've put all the pg.event.get() code outside the main while loop, inside the main while loop, inside the secondary for loop, inside the tertiary for loop. I've ran it using ... | 1 | 2016-05-30T15:01:57Z | 37,541,253 | <p>During the pixel transformation loop you are not running the anything to detect events. You were on the right track about moving the loops about.</p>
<p>if you shift the event checking code into the pixel transformation loop you can poll events while generating the pixels</p>
<p>Example:</p>
<pre><code>for i in r... | 0 | 2016-05-31T09:01:08Z | [
"python",
"pygame",
"exit"
] |
Python Pygame won't quit | 37,528,737 | <p>The code colors a pixel one by one and essentially prints a picture. I can't get it to quit though if I press the X to close or if I press Esc. I've put all the pg.event.get() code outside the main while loop, inside the main while loop, inside the secondary for loop, inside the tertiary for loop. I've ran it using ... | 1 | 2016-05-30T15:01:57Z | 37,574,963 | <p>First, your event loop looks weird. I think you should use either <code>for event in pg.event.get():</code> or <code>keys = pg.key.get_pressed()</code> but not both. </p>
<p>I'm not sure if you just want to create a background surface or a build-up effect. Also, you should've explained what the variables <code>redd... | 0 | 2016-06-01T17:12:12Z | [
"python",
"pygame",
"exit"
] |
Python Pygame won't quit | 37,528,737 | <p>The code colors a pixel one by one and essentially prints a picture. I can't get it to quit though if I press the X to close or if I press Esc. I've put all the pg.event.get() code outside the main while loop, inside the main while loop, inside the secondary for loop, inside the tertiary for loop. I've ran it using ... | 1 | 2016-05-30T15:01:57Z | 37,594,719 | <p>Thank you all for your help, I did move the event loops into the for loop reorganised them by seperating the key event as below. This worked for me. Regarding the image, the goal of this was to display the image pixel by pixel soo that's why I blitted each loop. Anyway,Appreciate your comments. Next time I think a q... | 0 | 2016-06-02T14:28:00Z | [
"python",
"pygame",
"exit"
] |
python pandas dataframe index match | 37,528,762 | <p>In a python pandas dataframe "df", I have the following three columns:</p>
<pre><code>song_id | user_id | play_count
</code></pre>
<p>I have a rating table I invented based on play_count (how many times a user listened to a song):</p>
<pre><code>play_count | rating
1-33 | 1
34-66 | 2
67-99 | 3
... | 0 | 2016-05-30T15:03:08Z | 37,529,103 | <p>I think if you change your <code>play_count</code> tables to use min/max values, like this:</p>
<p><code>playcount</code>:</p>
<pre><code>min | max | rating
1 |33 | 1
34 |66 | 2
67 |99 | 3
100 |199 | 4
200 |np.inf | 5
</code></pre>
<p>of course you need to <code>import numpy as np</code></p>
<p>Th... | 0 | 2016-05-30T15:19:26Z | [
"python",
"if-statement",
"pandas",
"dataframe"
] |
python pandas dataframe index match | 37,528,762 | <p>In a python pandas dataframe "df", I have the following three columns:</p>
<pre><code>song_id | user_id | play_count
</code></pre>
<p>I have a rating table I invented based on play_count (how many times a user listened to a song):</p>
<pre><code>play_count | rating
1-33 | 1
34-66 | 2
67-99 | 3
... | 0 | 2016-05-30T15:03:08Z | 37,529,129 | <p>You need the endpoints of those ranges like you would need in Excel:</p>
<pre><code>import numpy as np
bins = [1, 33, 66, 99, 199, np.inf]
</code></pre>
<p>Then you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow">pd.cut</a> to find the corresponding rating:</p... | 3 | 2016-05-30T15:20:54Z | [
"python",
"if-statement",
"pandas",
"dataframe"
] |
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") | 37,528,782 | <p>I use Scrapy and wnat to insert the Data in my database.</p>
<p>in my database.py i have</p>
<pre><code>def __init__(self, host='', user='', password='', database=''):
self.__host = 'localhost'
self.__user = 'root'
self.__password = 'mypass'
self.__database = 'drive'
## End def __init__
de... | 0 | 2016-05-30T15:04:09Z | 37,528,906 | <p>Try adding Grant Option at the end:</p>
<pre><code>GRANT all privileges on dbx.* to 'x'@'localhost' IDENTIFIED BY 'x' WITH GRANT OPTION;
</code></pre>
| 0 | 2016-05-30T15:09:54Z | [
"python",
"mysql",
"xampp",
"scrapy",
"mysql-error-1045"
] |
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") | 37,528,782 | <p>I use Scrapy and wnat to insert the Data in my database.</p>
<p>in my database.py i have</p>
<pre><code>def __init__(self, host='', user='', password='', database=''):
self.__host = 'localhost'
self.__user = 'root'
self.__password = 'mypass'
self.__database = 'drive'
## End def __init__
de... | 0 | 2016-05-30T15:04:09Z | 37,529,000 | <p>Check if you are correctly setting the root password, but remember you can reset the password.</p>
<p>First things first. </p>
<p>Stop mysql server</p>
<pre><code>sudo /etc/init.d/mysql stop
</code></pre>
<p>Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables wh... | 1 | 2016-05-30T15:15:18Z | [
"python",
"mysql",
"xampp",
"scrapy",
"mysql-error-1045"
] |
Storing multiple function values in a string/array (Python) | 37,528,903 | <p>I am attempting to store multiple function values in an array, in order to graph a function in python.</p>
<p>For the example, let's define that the function is y= x^2 and the argument values wanted are 1,2 and 3. The code I attempted is the following :</p>
<pre><code>def ExampleFunction (x):
return x**2
A... | 2 | 2016-05-30T15:09:50Z | 37,529,008 | <p>Use a list comprehension:</p>
<pre><code>results = [ExampleFunction(x) for x in range(3)]
</code></pre>
| 2 | 2016-05-30T15:15:50Z | [
"python",
"string",
"function"
] |
Storing multiple function values in a string/array (Python) | 37,528,903 | <p>I am attempting to store multiple function values in an array, in order to graph a function in python.</p>
<p>For the example, let's define that the function is y= x^2 and the argument values wanted are 1,2 and 3. The code I attempted is the following :</p>
<pre><code>def ExampleFunction (x):
return x**2
A... | 2 | 2016-05-30T15:09:50Z | 37,529,012 | <p>This code answer :</p>
<pre><code>def ExampleFunction (x):
list_fn = []
for item in x :
list_fn.append(item**2)
return list_fn
ArgumentValues=range(3)
FunctionValues=ExampleFunction(ArgumentValues)
</code></pre>
<p>Or this code :</p>
<pre><code>def ExampleFunction (x):
return x**2
... | 1 | 2016-05-30T15:15:55Z | [
"python",
"string",
"function"
] |
Storing multiple function values in a string/array (Python) | 37,528,903 | <p>I am attempting to store multiple function values in an array, in order to graph a function in python.</p>
<p>For the example, let's define that the function is y= x^2 and the argument values wanted are 1,2 and 3. The code I attempted is the following :</p>
<pre><code>def ExampleFunction (x):
return x**2
A... | 2 | 2016-05-30T15:09:50Z | 37,530,522 | <p>This is the perfect usage for <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow"><code>map</code></a>.</p>
<pre><code>map(lambda x: x**2, range(3))
# [0, 1, 4]
</code></pre>
<p>In Python 3.X, <code>map</code> will return a <code>map object</code> instead of a list, so if you want to reus... | 1 | 2016-05-30T16:52:17Z | [
"python",
"string",
"function"
] |
Django: Getting m2m related objects in signals | 37,528,922 | <p>I was kind of trying to see similar questions (<a href="http://stackoverflow.com/questions/23795811/django-accessing-manytomany-fields-from-post-save-signal">Django accessing ManyToMany fields from post_save signal</a>), but still don't see how to get the updated related objects list.</p>
<p>E.g. I have following m... | 0 | 2016-05-30T15:10:42Z | 37,529,580 | <p><code>m2m_changed</code> signals are fired at several stages in the save/update process, and there is an <code>action</code> argument supplied to the signal handler that tells you what stage it is in. From the <a href="https://docs.djangoproject.com/en/1.9/ref/signals/#m2m-changed" rel="nofollow">documentation</a>:<... | 0 | 2016-05-30T15:48:41Z | [
"python",
"django"
] |
Cant understand theano scan applied to grad behaviour | 37,528,925 | <p>So here's the thing: I have to code below, and when I apply the grad wrt A everything runs fine and it computes the gradients correctly. However, if I do <code>wrt=i</code> then it gives me a DisconnectedInputError. Why is that, and how could I go about differentiating with respect to i?</p>
<pre><code>def step(i, ... | 0 | 2016-05-30T15:10:46Z | 37,548,257 | <p>To differentiate wrt to i you need to declare the whole i array before the scan operation and use the whole array to calculate the gradient wrt to it.</p>
<pre><code>i_array = T.arange(2,6)
def step(i, A):
return A*i, i
A = T.scalar("A")
A.tag.test_value = 5.0
outputs, _ = theano.scan(step, sequences=i_array... | 0 | 2016-05-31T14:18:06Z | [
"python",
"theano"
] |
Exists a list where every item is a member? | 37,528,948 | <p>I'm currently trying to write an abstraction for some Spark Streaming jobs that each have a portion of code which the the same between all of them (hence the need for an abstraction). </p>
<p>The format of each job is in this format:</p>
<pre><code>dStream \
.filter(lambda rec: rec[self.EVENT_KEY_VALUE[0]]... | 0 | 2016-05-30T15:12:21Z | 37,529,261 | <p>If I understand correctly, you just want to mock the <code>__contains__</code> operator. So maybe something like:</p>
<pre><code>class MockList(list):
def __contains__(self, item):
return True
</code></pre>
| 2 | 2016-05-30T15:29:09Z | [
"python",
"list",
"membership"
] |
Exists a list where every item is a member? | 37,528,948 | <p>I'm currently trying to write an abstraction for some Spark Streaming jobs that each have a portion of code which the the same between all of them (hence the need for an abstraction). </p>
<p>The format of each job is in this format:</p>
<pre><code>dStream \
.filter(lambda rec: rec[self.EVENT_KEY_VALUE[0]]... | 0 | 2016-05-30T15:12:21Z | 37,529,319 | <p>If I understand you correctly, you need a list-like object, claiming that it contains any object.</p>
<p>You need to define a <a href="https://docs.python.org/3/reference/datamodel.html#emulating-container-types" rel="nofollow">list-like class</a>.</p>
<p>The simplest solution I can think about is a dirty hack:</p... | 1 | 2016-05-30T15:32:30Z | [
"python",
"list",
"membership"
] |
Elasticsearch - field_value_factor, missing parameter | 37,529,203 | <p>So i finally have setup the elasticsearch database and imported data into it.</p>
<p>Sometimes when i try to request data from frontend, i get 500 error( not all the time, just sometimes ).</p>
<p>I tried to request data from POSTMAN( to see the ES error message ).</p>
<p>I got:</p>
<pre><code>{
"error": "Sear... | 0 | 2016-05-30T15:25:17Z | 37,529,249 | <p>In at least one document, the field <code>lang_en</code> is null, empty or simply non-existent.</p>
<p>You need to modify your <code>field_value_factor</code> function in order to tell it what to do in such as case, by using the <code>missing</code> setting with whatever default value makes sense (0, 1, etc):</p>
... | 1 | 2016-05-30T15:28:38Z | [
"python",
"amazon-web-services",
"elasticsearch",
"go"
] |
Elasticsearch - field_value_factor, missing parameter | 37,529,203 | <p>So i finally have setup the elasticsearch database and imported data into it.</p>
<p>Sometimes when i try to request data from frontend, i get 500 error( not all the time, just sometimes ).</p>
<p>I tried to request data from POSTMAN( to see the ES error message ).</p>
<p>I got:</p>
<pre><code>{
"error": "Sear... | 0 | 2016-05-30T15:25:17Z | 37,544,683 | <p>The problem was with the dumb AWS ES version 1.5.2.</p>
<p>My solution: Create EC2 instance and deploy Elasticsearch manualy.</p>
| 1 | 2016-05-31T11:37:27Z | [
"python",
"amazon-web-services",
"elasticsearch",
"go"
] |
How to pass the reference from inside one object to the constructor of another | 37,529,207 | <p>Let's say I am inside an object (object1) and I want to pass its reference to another object (object2) I created inside it.</p>
<p>Inside object1:</p>
<pre><code># ...
self.object2Reference = object2(self)
# ...
</code></pre>
<p>Code of object2:</p>
<pre><code>class object2:
def __init__(self, object1Referen... | -2 | 2016-05-30T15:25:30Z | 37,529,384 | <p><strong>To pass the current object to another object it declares for use.</strong></p>
<p>The code:</p>
<pre><code>class Object2:
def __init__(self, object1):
self.object1 = object1
self.object1.print_something()
class Object1:
def __init__(self):
self.object2 = Object2(self)
... | 3 | 2016-05-30T15:36:22Z | [
"python",
"constructor"
] |
Schedule selenium to run on a remote server | 37,529,209 | <p>I need to run selenium on a remote server since the server doesn't have a screen I'm using PhantomJS as a web driver. this is the code I Have:</p>
<pre><code>import time
import os,sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
from selenium import webdriver
url = 'https://wiki.python.org/moin/HowTo/So... | 0 | 2016-05-30T15:25:34Z | 37,530,176 | <p>You do not need a read GUI on the server in order to run Selenium with any browser. Selenium can easily run on any server with real browsers like Chrome or Firefox.</p>
<p>Here is some code that should help you make it working:</p>
<pre><code>from pyvirtualdisplay import Display
display = Display(visible=0, size=(... | 2 | 2016-05-30T16:28:29Z | [
"python",
"selenium",
"phantomjs",
"remote-server"
] |
Schedule selenium to run on a remote server | 37,529,209 | <p>I need to run selenium on a remote server since the server doesn't have a screen I'm using PhantomJS as a web driver. this is the code I Have:</p>
<pre><code>import time
import os,sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
from selenium import webdriver
url = 'https://wiki.python.org/moin/HowTo/So... | 0 | 2016-05-30T15:25:34Z | 37,530,242 | <p>If you want your script to continue executing even if you lose connection to the server, you can easily do this with terminal software like <a href="https://tmux.github.io/" rel="nofollow">Tmux</a> or <a href="https://www.gnu.org/software/screen/" rel="nofollow">screen</a></p>
| 1 | 2016-05-30T16:33:54Z | [
"python",
"selenium",
"phantomjs",
"remote-server"
] |
Which encoding is in use by csv.DictReader when reading csv? | 37,529,214 | <p>I have a csv file saved encoded as UTF-8. </p>
<p>It contains non-ascii chars [umlauts].</p>
<p>I am reading the file using:</p>
<pre><code>csv.DictReader(<file>,delimiter=<delimiter>).
</code></pre>
<p>My questions are: </p>
<ol>
<li>In which encoding is the file being read? </li>
<li><p>I noticed ... | 1 | 2016-05-30T15:25:59Z | 37,530,103 | <p>How about using instances and classes in order to achieve this?</p>
<p>You can store the shared dictionary at the class level and also make it load Unicode text files, and even detect their encoding, with or without use of BOM file masks.</p>
<p>Long time ago I wrote a simple library which overrides the default <c... | 0 | 2016-05-30T16:22:55Z | [
"python",
"python-2.7",
"csv",
"encoding",
"utf-8"
] |
Which encoding is in use by csv.DictReader when reading csv? | 37,529,214 | <p>I have a csv file saved encoded as UTF-8. </p>
<p>It contains non-ascii chars [umlauts].</p>
<p>I am reading the file using:</p>
<pre><code>csv.DictReader(<file>,delimiter=<delimiter>).
</code></pre>
<p>My questions are: </p>
<ol>
<li>In which encoding is the file being read? </li>
<li><p>I noticed ... | 1 | 2016-05-30T15:25:59Z | 37,563,421 | <p>In Python 2.7, the CSV module does not apply any decoding - it opens the file in binary mode and returns bytes strings.</p>
<p>Use <a href="https://github.com/jdunck/python-unicodecsv" rel="nofollow">https://github.com/jdunck/python-unicodecsv</a>, which decodes on the fly.</p>
<p>Use it like:</p>
<pre><code>with... | 0 | 2016-06-01T08:32:55Z | [
"python",
"python-2.7",
"csv",
"encoding",
"utf-8"
] |
local variable 'request' referenced before assignment | 37,529,236 | <p>So, here's my ajax call to a specific route in my flask app:</p>
<pre><code> $.ajax({
url: '/addfriend',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(obj.user),
success: function(results) {
console.log(results);
$('#u-' + obj.... | -1 | 2016-05-30T15:27:53Z | 37,529,480 | <p>You need to import <code>request</code> first.</p>
<pre><code>from flask import request
@app.route('/addfriend', methods=['POST'])
def addFriend():
if request.method == 'POST':
data = json.loads(request.data)
print data
</code></pre>
<p>And you probably want to give you data object a different name.</p... | 0 | 2016-05-30T15:41:59Z | [
"python",
"ajax",
"flask"
] |
Plot sum over time | 37,529,263 | <p><a href="https://stackoverflow.com/questions/3034162/plotting-a-cumulative-graph-of-python-datetimes">"Plotting a cumulative graph of python datetimes"</a> provides great methods to use matplotlib to plot a list of datetimes (see below) as a cumulative count over time:</p>
<pre><code>[
datetime.datetime(2015, 1... | 0 | 2016-05-30T15:29:17Z | 37,536,878 | <p>All you need to do is split the <code>x</code> and <code>y</code> axes, and then accumulate the y-values using either <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.cumsum.html" rel="nofollow"><code>np.cumsum</code></a> or <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc... | 2 | 2016-05-31T04:32:49Z | [
"python",
"datetime",
"matplotlib",
"plot",
"graph"
] |
What's the best practice in the workflow of writing and running python files with Vim? | 37,529,278 | <p>Currently, I write pythons files in Vim, and run it with jupyter qtconsole. The advantage of this way is that I could work with Vim so get all the benefits of Vim. </p>
<p>I could run the python directly in Vim using the pymode plugins, but in this way I cannot see and manipulate the output variables, and the figu... | 0 | 2016-05-30T15:29:58Z | 37,530,465 | <p>I find an <a href="http://stackoverflow.com/questions/3438531/ipython-workflow-edit-run">answer</a> which solves my problem by using ipython extension autoreload.</p>
<pre><code>%load_ext autoreload
%autoreload 2
</code></pre>
<p>Then I do not have to restart kernel any more.</p>
| 0 | 2016-05-30T16:48:40Z | [
"python",
"vim"
] |
Unable to get max value using annotate | 37,529,366 | <p>here is the models.py </p>
<pre><code>class StoreProduct(models.Model):
product = models.ForeignKey('products.Product')
category = models.ForeignKey('products.Category')
store = models.ForeignKey('Store')
price = models.IntegerField(null=True , blank=True)
quantity = models.IntegerField(null=Tru... | 0 | 2016-05-30T15:35:06Z | 37,529,600 | <p>You should use <code>aggregate</code> as <code>annotate</code> only adds objects to your query</p>
<pre><code> storeproduct = StoreProduct.objects.filter(product=item).aggregate(max_discount=Max('discount'))
</code></pre>
<p><code>storeproduct['max_discount']</code> will return the maximum discount value and can ... | 2 | 2016-05-30T15:49:53Z | [
"python",
"django",
"django-models",
"django-views"
] |
Radiobutton only shows one option | 37,529,428 | <p>I'm not sure what I'm doing wrong, but it seems that my radiobutton only shows one option instead of two options(which is what I originally wanted).</p>
<pre><code>PLAYERS = [("Black", "black"),
("White", "white")]
def first_player(self) -> str:
self.firstplayer = tkinter.StringVar(value = 'blac... | 0 | 2016-05-30T15:39:01Z | 37,529,607 | <p>You are placing both radiobuttons in the same place: row 1, column 0. The first one it thus invisible because it is under the second one. If you want the label and two radiobuttons on the same row but different columns, the solution is to give them all the same row, and different columns.</p>
<p>There are many ways... | 2 | 2016-05-30T15:50:09Z | [
"python",
"user-interface",
"tkinter",
"radio-button"
] |
Dynamic Point Manipulation in 3D Matplotlib | 37,529,469 | <p>In trying to manipulate a graph in matplotlib, I came across something interesting. when using the plot function, x and y coordinates can be modified through aliasing, however the z cannot. Is this easily explained?
I have included a small example, note that I was trying to get the point to move in a helix along t... | 0 | 2016-05-30T15:41:19Z | 37,529,811 | <p>This is indeed interesting.. <code>Line3D</code> is derived from <code>Line2D</code>, so functions like <code>get_xdata</code> or <code>set_xdata</code> are also not available in the <code>z</code> direction. Looking into the source code (<code>art3d.py</code>), it seems that the <code>z</code> values are completely... | 0 | 2016-05-30T16:02:12Z | [
"python",
"matplotlib"
] |
How is data augmentation implemented in Tensorflow? | 37,529,571 | <p>Based on the <a href="https://www.tensorflow.org/versions/r0.8/tutorials/deep_cnn/index.html#convolutional-neural-networks" rel="nofollow">Tensorflow tutorial for ConvNet</a>, some points are not readily apparent to me:</p>
<ul>
<li>are the images being distorted actually <strong>added</strong> to the pool of origi... | 1 | 2016-05-30T15:48:04Z | 37,529,929 | <blockquote>
<p>are the images being distorted actually added to the pool of original images?</p>
</blockquote>
<p>It depends on the definition of the pool. In tensorflow, you have <code>ops</code> which are basic objects in your network graph. here, data production is an op itself. Thus you do not have a finite set... | 3 | 2016-05-30T16:10:48Z | [
"python",
"machine-learning",
"neural-network",
"tensorflow",
"conv-neural-network"
] |
Comparing dates of two pandas Dataframes and adding values if dates are similar? | 37,529,587 | <p>I have two dataframes with different number of rows, one has daily values and the second one has hourly values. I wanted to compare them and if the dates match then I would like to add daily values infront of hourly values of the same day. The dataframes are;</p>
<pre><code>import pandas as pd
df1 = pd.read_csv('C:... | 1 | 2016-05-30T15:49:07Z | 37,530,483 | <p>You can just use <code>pd.concat</code> and <code>fillna(method='ffill')</code> because the <code>date</code> values match the first value on any day:</p>
<pre><code>df1 = pd.DataFrame(data={'day': np.random.randint(low=50, high=100, size=10), 'date':pd.date_range(date(2016,1,1), freq='D', periods=10)})
da... | 0 | 2016-05-30T16:50:02Z | [
"python",
"datetime",
"pandas",
"dataframe"
] |
Comparing dates of two pandas Dataframes and adding values if dates are similar? | 37,529,587 | <p>I have two dataframes with different number of rows, one has daily values and the second one has hourly values. I wanted to compare them and if the dates match then I would like to add daily values infront of hourly values of the same day. The dataframes are;</p>
<pre><code>import pandas as pd
df1 = pd.read_csv('C:... | 1 | 2016-05-30T15:49:07Z | 37,531,973 | <p>you can set index to <code>df1.Datetime.dt.date</code> for the <code>df1</code> DF and then you can join it with <code>df2</code>:</p>
<pre><code>In [46]: df1.set_index(df1.Datetime.dt.date).join(df2.set_index('Datetime')).reset_index(drop=True)
Out[46]:
Datetime Value No_of_people
0 2016-02-02 21:00... | 1 | 2016-05-30T18:44:18Z | [
"python",
"datetime",
"pandas",
"dataframe"
] |
Creating a dynamic function referring to different entries in a dictionary in Python 3 | 37,529,725 | <p>I have the following function:</p>
<pre><code>def mapLocation1():
if rooms[1]["mapLoc"] == rooms[currentRoom]["mapLoc"]:
#return(stuff)
elif "item" in rooms[1]:
#return(stuff)
else:
#return(stuff)
</code></pre>
<p>This particular function can see use several times in my program up to perhaps three doze... | 1 | 2016-05-30T15:57:03Z | 37,529,870 | <p>How about using instances and classes in order to achieve this?</p>
<p>You can store the shared dictionary at the class level and also implement different behaviour for each object.</p>
| 0 | 2016-05-30T16:07:03Z | [
"python",
"python-3.x",
"dictionary",
"dynamic"
] |
Python regex to match variable pattern | 37,529,837 | <p>I'm trying to write a python regex matching two patterns:
the first one is <code>scratch_alpha</code>
and the second one is <code>scratch_alpha1*12</code> (where 12 can be any decimal number)
and I'd like to put the value after <code>*</code> inside a variable and if scratch_alpha is detected with <code>*</code> aft... | 1 | 2016-05-30T16:04:54Z | 37,529,909 | <p>Try this regex: <code>([^*]+)\*(\d+)</code></p>
<ul>
<li>Group one: all characters until <code>*</code></li>
<li>Group two: all numbers after <code>*</code></li>
</ul>
<p><a href="https://regex101.com/r/gD5yP5/2" rel="nofollow">Regex demo 1</a></p>
<hr>
<h1>UPDATE</h1>
<p>To meet your requirements for patterns ... | 4 | 2016-05-30T16:09:22Z | [
"python",
"regex"
] |
Python regex to match variable pattern | 37,529,837 | <p>I'm trying to write a python regex matching two patterns:
the first one is <code>scratch_alpha</code>
and the second one is <code>scratch_alpha1*12</code> (where 12 can be any decimal number)
and I'd like to put the value after <code>*</code> inside a variable and if scratch_alpha is detected with <code>*</code> aft... | 1 | 2016-05-30T16:04:54Z | 37,529,933 | <p>No need of <code>*</code> in first group,</p>
<pre><code>([a-zA-Z0-9\_]+)(\*\d+)?
</code></pre>
<p>Also you may change <code>(\*\d+)?</code> to <code>(\*(\d+))?</code> if you want characters before & after <code>*</code> separately.</p>
| 2 | 2016-05-30T16:10:58Z | [
"python",
"regex"
] |
Python regex to match variable pattern | 37,529,837 | <p>I'm trying to write a python regex matching two patterns:
the first one is <code>scratch_alpha</code>
and the second one is <code>scratch_alpha1*12</code> (where 12 can be any decimal number)
and I'd like to put the value after <code>*</code> inside a variable and if scratch_alpha is detected with <code>*</code> aft... | 1 | 2016-05-30T16:04:54Z | 37,529,955 | <p>This happens because inside your first parentheses you have put a <code>+</code>, which means <strong>minimum</strong> of one or more occurrences. And since your second parentheses has a <code>?</code>, the second group is optional. Hence, it is omitted as your first parentheses can match your whole string and the s... | 1 | 2016-05-30T16:12:50Z | [
"python",
"regex"
] |
Does pyFFTW allow to preserve the input array | 37,529,935 | <p>I would like to know whether there's a possiblity to enforce <strong>pyFFTW</strong> (wrapper around FFTW) the <strong>input vector to be preserved</strong> during forward r2c transform.</p>
<p>At least in <strong>original FFTW</strong> the <strong>FFTW_PRESERVE_INPUT</strong> seems to be a default option (look at ... | 1 | 2016-05-30T16:11:19Z | 37,541,037 | <p>Yes, all the defaults are used unless explicitly requested - this means that unless you request <code>DESTROY_INPUT</code>, then <code>PRESERVE_INPUT</code> is implicit, <em>except</em> in the case where you have a multi-dimensional c2r transform, in which case the input will be destroyed (this is documented in the ... | 1 | 2016-05-31T08:50:24Z | [
"python",
"python-3.x",
"fft",
"fftw",
"pyfftw"
] |
how to change HTML attribute that contain hyphen | 37,529,938 | <p>I want to change value of table header's <code>aria-label</code> attribute using <code>execute_script</code></p>
<p><code>HTML</code> of target element:</p>
<pre><code><th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="Activate to sort column ascending">Company</th>
</code></pre>
<p>... | 3 | 2016-05-30T16:11:26Z | 37,529,954 | <p>Remove the dot.</p>
<pre><code>driver.execute_script('document.getElementsByTagName("th")[1]["aria-label"]="Activate to sort column descending";')
</code></pre>
<p>In JavaScript, <code>a.foo</code> is equivalent to <code>a["foo"]</code>, but the former syntax is only allowed if <code>foo</code> is a valid identifi... | 3 | 2016-05-30T16:12:47Z | [
"javascript",
"python",
"html",
"selenium",
"selenium-webdriver"
] |
how to change HTML attribute that contain hyphen | 37,529,938 | <p>I want to change value of table header's <code>aria-label</code> attribute using <code>execute_script</code></p>
<p><code>HTML</code> of target element:</p>
<pre><code><th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="Activate to sort column ascending">Company</th>
</code></pre>
<p>... | 3 | 2016-05-30T16:11:26Z | 37,531,038 | <p>Since <code>aria-label</code> is an attribute, you should use <code>.setAttribute(...)</code> :</p>
<pre class="lang-py prettyprint-override"><code>driver.execute_script("document.getElementsByTagName('th')[1].setAttribute('aria-label', 'Activate to sort column descending');")
</code></pre>
| 3 | 2016-05-30T17:31:28Z | [
"javascript",
"python",
"html",
"selenium",
"selenium-webdriver"
] |
I installed both python 2.7 and 3.5, but python 3.5 does not work well | 37,529,960 | <p>In terminal, I can run <code>py -2</code> successfully.
Nevertheless, </p>
<pre><code>C:\Users\user>py -3
Fatal Python error: Py_Initialize: unable to load the file system codec
File "C:\Python27\lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: inva... | 2 | 2016-05-30T16:13:13Z | 37,530,895 | <p>You can try setting python path.</p>
<pre><code>C:\Users\user>set PATH=C:\Program Files\Python 3.5;%PATH%
C:\Users\user>set PYTHONPATH=%PYTHONPATH%;C:\python_lib_path
C:\Users\user>python
</code></pre>
| 1 | 2016-05-30T17:20:49Z | [
"python",
"python-2.7",
"python-3.x"
] |
No module named bidi.algorithm | 37,529,964 | <p>I download this <a href="https://pypi.python.org/pypi/python-bidi" rel="nofollow">here</a>, run it with: </p>
<pre><code>python setup.py test
</code></pre>
<p>in my cmd, I have python 2.7 but i get this error:</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\CLIENT\Desktop\IMPLEMENTATION\Affichag... | 1 | 2016-05-30T16:13:34Z | 37,531,967 | <p>You should install python-bidi using this command:</p>
<pre><code>easy_install python-bidi
</code></pre>
<p>or</p>
<pre><code>pip install python-bidi
</code></pre>
| 2 | 2016-05-30T18:43:53Z | [
"python",
"module",
"arabic"
] |
Django - using my context in render_to_response | 37,529,969 | <p>Is there a way to call all my user data? without using all the template variables in my views</p>
<p><strong>Templates:</strong></p>
<pre><code> {% csrf_token %}
<h1>Welcome {{user.full_name}} {{user.last_name}}</h1>
<h1>{{user.email}}</h1>
</code></pre>
<p>so in my views I'll use less c... | 0 | 2016-05-30T16:13:50Z | 37,530,446 | <p>For django version 1.8 or more you can directly access {{user}} in template. However you can add the following in the TEMPLATE_CONTEXT_PROCESSOR of your settings to access {{user}} directly in the template.</p>
<pre><code>'django.contrib.auth.context_processors.auth',
</code></pre>
| 1 | 2016-05-30T16:47:25Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Django - using my context in render_to_response | 37,529,969 | <p>Is there a way to call all my user data? without using all the template variables in my views</p>
<p><strong>Templates:</strong></p>
<pre><code> {% csrf_token %}
<h1>Welcome {{user.full_name}} {{user.last_name}}</h1>
<h1>{{user.email}}</h1>
</code></pre>
<p>so in my views I'll use less c... | 0 | 2016-05-30T16:13:50Z | 37,530,596 | <p>You can use a dict-like object that defines <code>__contains__</code> and <code>__getitem__</code>, but uses attribute access to set properties, eg.:</p>
<pre><code>from django import shortcuts, template
from django.contrib.auth.decorators import login_required
class Page(dict):
# see http://stackoverflow.com/... | 1 | 2016-05-30T16:58:29Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Selecting rows from a pandas DataFrame with an arbitrary number of conditions | 37,529,973 | <p>I have a pandas DataFrame, and I want to select rows for which a certain set of values are True. </p>
<pre><code>df = DataFrame([[True, True, True], [True, False, True], [True, True, False]], index=['a', 'b', 'c'], columns=['val1', 'val2', 'other'])#, columns=['val1', 'other'])
# example DataFrame:
val1 v... | 0 | 2016-05-30T16:14:10Z | 37,530,026 | <p>Use <code>.all(axis=1)</code> (see <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.any.html" rel="nofollow">docs</a>):</p>
<pre><code>df[df.loc[:, df.columns.str.contains('val')].all(axis=1)]
</code></pre>
<p>Sample data for illustration:</p>
<pre><code>df = pd.DataFrame(data=np.ra... | 1 | 2016-05-30T16:18:09Z | [
"python",
"numpy",
"pandas"
] |
Selecting rows from a pandas DataFrame with an arbitrary number of conditions | 37,529,973 | <p>I have a pandas DataFrame, and I want to select rows for which a certain set of values are True. </p>
<pre><code>df = DataFrame([[True, True, True], [True, False, True], [True, True, False]], index=['a', 'b', 'c'], columns=['val1', 'val2', 'other'])#, columns=['val1', 'other'])
# example DataFrame:
val1 v... | 0 | 2016-05-30T16:14:10Z | 37,532,212 | <p>you can do it using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.filter.html" rel="nofollow">filter()</a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.all.html" rel="nofollow">all()</a> functions:</p>
<pre><code>In [194]: df[df.filter(like='val'... | 1 | 2016-05-30T19:03:03Z | [
"python",
"numpy",
"pandas"
] |
python facebook-sdk fan_count issue | 37,530,001 | <p>I cannot figure out how to get fan_count from a page.
I always get this error </p>
<pre><code>Traceback (most recent call last):
File "./facebook_api.py", line 37, in <module>
facebook_graph.get_object('somepublicpage')['fan_count']
KeyError: 'fan_count'
</code></pre>
<p>The object only contains id/name an... | 0 | 2016-05-30T16:16:22Z | 37,530,405 | <p>Since v2.4 of the Graph API, you have to specify the fields you want to get returned. This would be the correct API call:</p>
<p><code>/{page-id}?fields=name,fan_count</code></p>
<p>It is called "Declarative Fields".</p>
| 1 | 2016-05-30T16:44:58Z | [
"python",
"facebook"
] |
Django migration not working with postgresql? | 37,530,019 | <p>I have models : </p>
<pre><code>class Keyword(models.Model):
keyword_name = models.CharField(max_length=40)
keyword_category = models.ForeignKey(Category, null=True)
class Category(models.Model):
category_name = models.CharField(max_length=40)
active = models.BooleanField(default=False)
</code></pr... | 0 | 2016-05-30T16:17:44Z | 37,539,629 | <p>IMO, from the error message, the models seem to be registered in the <code>admin.py</code>.</p>
<p>Delete the code in <code>admin.py</code> and try the migration again.</p>
| 0 | 2016-05-31T07:36:37Z | [
"python",
"django",
"postgresql",
"sqlite"
] |
Executing Python Program from an Android Smart Device using SSH | 37,530,081 | <p>I am trying to execute a Python Program (which is running on my Raspberry Pi) remotely from an Android Phone via SSH.
On the Android-Side I am using the JSch library and basically the code explained here:
<a href="http://droid-lernen.de/raspberry-pi-mit-dem-smartphone-steuern-teil-1/" rel="nofollow">http://droid-ler... | 2 | 2016-05-30T16:21:35Z | 37,530,513 | <p>When you SSH into a linux box, it creates a new process for the SSH. All processes you run from the terminal run as child processes of the SSH process you established. If the SSH process is terminated, the OS will send a Hangup signal to all the children of the SSH process, and this will cause those process to exit ... | 0 | 2016-05-30T16:51:45Z | [
"python",
"matplotlib",
"ssh",
"raspberry-pi",
"jsch"
] |
Executing Python Program from an Android Smart Device using SSH | 37,530,081 | <p>I am trying to execute a Python Program (which is running on my Raspberry Pi) remotely from an Android Phone via SSH.
On the Android-Side I am using the JSch library and basically the code explained here:
<a href="http://droid-lernen.de/raspberry-pi-mit-dem-smartphone-steuern-teil-1/" rel="nofollow">http://droid-ler... | 2 | 2016-05-30T16:21:35Z | 38,009,796 | <p>I guess it happens because you send an sudo command and your Raspberry Pi is expecting an password.</p>
<p>Try to use a command like this: <code>echo <password> | sudo -S python myprogram.py</code>.</p>
<p>You can also ask the author of this article. Maybe he can give you an more dedicated answer.</p>
| 0 | 2016-06-24T09:19:28Z | [
"python",
"matplotlib",
"ssh",
"raspberry-pi",
"jsch"
] |
Where do I put and how to use Table() calls in a project with SQLAlchemy Core and flask? | 37,530,143 | <p>So I want to use SQLAlchemy Core and flask in an application. I have read through the documentation and a lot of tutorials how to structure your application. All of the SQLAlchemy Core tutorials put the Database description directly into the app.py file of the application. I'd like to put this Database description i... | 0 | 2016-05-30T16:25:37Z | 37,538,983 | <p>Let's do it one step at a time. Minimal application:</p>
<pre><code>from sqlalchemy import ...
from flask import ...
from flask.ext.sqlalchemy import ...
app = Flask()
db = SQLAlchemy()
class Foo(db.Model):
...
@app.route(...)
def foo():
Foo.query.filter(...)
return ...
</code></pre>
<p>Let's move t... | 0 | 2016-05-31T07:04:49Z | [
"python",
"sqlalchemy",
"flask-sqlalchemy"
] |
Placing a new value into a section of a big Python bitarray | 37,530,161 | <p>Using Python 2.7 and bitarray 0.8.1 to hold several sequenced register values (registers can be from 16 to 512 Byte long).
I want to set a value to a specific part of this bitarray?</p>
<p>For example:</p>
<pre><code>from bitarray import bitarray
BYTE = [False, False,False, False, False, False, False, False]
reg =... | 0 | 2016-05-30T16:27:31Z | 37,530,304 | <p>using slice assignment.</p>
<pre><code>bin_of_aa = "{:b}".format(0xaa)
reg[2048:2055] = bitarray(bin_of_aa,endian="big")
</code></pre>
| 0 | 2016-05-30T16:37:58Z | [
"python",
"slice",
"bitmask",
"bitarray"
] |
Learning Rate Decay in Lasagne | 37,530,184 | <p>I am using nesterov momentum for updating the weights of a Convolutional Neural Network. I am using Lasagne for building a CNN. How to implement learning rate decay for every epoch?</p>
<pre><code>prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_v... | 0 | 2016-05-30T16:28:59Z | 37,534,237 | <p>I think you missing something:</p>
<pre><code>prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_var)
params = lasagne.layers.get_all_params(network, trainable=True)
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate, momentum=0... | 0 | 2016-05-30T22:15:15Z | [
"python",
"theano",
"deep-learning",
"lasagne"
] |
Learning Rate Decay in Lasagne | 37,530,184 | <p>I am using nesterov momentum for updating the weights of a Convolutional Neural Network. I am using Lasagne for building a CNN. How to implement learning rate decay for every epoch?</p>
<pre><code>prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.categorical_crossentropy(prediction, target_v... | 0 | 2016-05-30T16:28:59Z | 37,595,487 | <p>Define your learning rate as a graph element</p>
<pre><code>...
learning_rate = T.scalar(name='learning_rate')
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate, momentum=0.9)
...
</code></pre>
<p>Add your learning rate node to train_fn</p>
<pre><code>train_fn = theano.function([input_var_1,... | 1 | 2016-06-02T15:01:57Z | [
"python",
"theano",
"deep-learning",
"lasagne"
] |
String decoder not working properly | 37,530,249 | <p>I am converting letters in a string to their corresponding numbers and printing YES if the result is divisible by 6 or NO. For eg, ab is 12 and will give YES. The program is working fine for small strings but gives wrong answer for very long inputs. I tried to change the datatype for integers to long but nothing ... | -1 | 2016-05-30T16:34:28Z | 37,530,531 | <p>Your code seems to work as in "tests correctly whether a number is divisible by 6" if the input does not have any extra character like whitespace, CR, tab, etc. The URL you supplied is not working, so I could not see the failing test.</p>
<p>Two major errors in your code:</p>
<p>1) you are subtracting 96 - why? If... | 1 | 2016-05-30T16:53:20Z | [
"python",
"python-2.7",
"encoding",
"decoding",
"modulus"
] |
String decoder not working properly | 37,530,249 | <p>I am converting letters in a string to their corresponding numbers and printing YES if the result is divisible by 6 or NO. For eg, ab is 12 and will give YES. The program is working fine for small strings but gives wrong answer for very long inputs. I tried to change the datatype for integers to long but nothing ... | -1 | 2016-05-30T16:34:28Z | 37,638,683 | <p>The problem with the code appeared to be that the long int is possibly not long enough to hold the integer value of the string, decoded as given.</p>
<p>So, the problem can be simplified by applying the mathematical rules of divisibility.</p>
<p>Check if the corresponding digit for the last letter of the string is... | -1 | 2016-06-05T05:12:43Z | [
"python",
"python-2.7",
"encoding",
"decoding",
"modulus"
] |
String decoder not working properly | 37,530,249 | <p>I am converting letters in a string to their corresponding numbers and printing YES if the result is divisible by 6 or NO. For eg, ab is 12 and will give YES. The program is working fine for small strings but gives wrong answer for very long inputs. I tried to change the datatype for integers to long but nothing ... | -1 | 2016-05-30T16:34:28Z | 37,643,579 | <pre><code>dic = {}
for i in xrange(97,123):
dic[chr(i)] = str(i-96)
str = raw_input()
new_str = ""
for i in xrange(len(str)):
new_str += dic[str[i]]
val = 0
for i in xrange(len(new_str)):
val = ( (val*10)%6 + ((int(new_str[i]))%6) )%6 # without modular arithmetic val will turn to long data type
print "N... | 0 | 2016-06-05T15:29:30Z | [
"python",
"python-2.7",
"encoding",
"decoding",
"modulus"
] |
transparent widgets inside transparent frame pyqt5 | 37,530,276 | <p>I have a problem solving an issue for my program. When I create a transparent Widget that holds some other widgets, they become transparent too and I don't understand why.</p>
<pre><code>from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
class MainFrame(QtWidgets.QWidget):
def __init__(self, parent=None)... | 0 | 2016-05-30T16:36:03Z | 37,532,344 | <p>I believe you are looking for this:</p>
<pre><code>self.setAttribute(Qt.WA_TranslucentBackground)
</code></pre>
<p>The full code adapted from your example is this:</p>
<pre><code>import sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt
class MainFrame(QtWidgets.QWidget):
def __init__(self, parent=... | 1 | 2016-05-30T19:13:52Z | [
"python",
"pyqt5"
] |
AttributeError: 'Graph' object has no attribute 'cypher' | 37,530,309 | <p>I am working on migration of data from postgres to Graph Database manually.</p>
<p>I have wrote script below:</p>
<pre><code>import psycopg2
from py2neo import authenticate, Graph
authenticate("localhost:7474", "neo4j", "password")
n4j_graph = Graph("http://localhost:7474/db/data/")
try:
conn=psycopg2.conne... | 4 | 2016-05-30T16:38:15Z | 37,594,389 | <p>I had this problem too. In my case I was looking at the <a href="http://py2neo.org/2.0/" rel="nofollow">py2neo <strong>v2</strong></a> documentation but on my machine was installed <a href="http://py2neo.org/v3/index.html" rel="nofollow">py2neo <strong>v3</strong></a>. You should check your <strong>py2neo</strong> v... | 3 | 2016-06-02T14:13:06Z | [
"python",
"neo4j",
"cypher",
"graph-databases",
"py2neo"
] |
Convert curl command to http request in python | 37,530,378 | <p>I'm new on REST API's and I'm unable to make run an http request.</p>
<p>If I try the curl command it works by terminal:</p>
<pre><code>curl \
--request POST \
--header "X-OpenAM-Username: user" \
--header "X-OpenAM-Password: password" \
--header "Content-Type: application/json" \
--data "{}" \
http://openam... | 0 | 2016-05-30T16:42:45Z | 37,530,490 | <p>You are doing everything correct, except POST method just do this:</p>
<pre><code>r = requests.post('http://openam.sp.com:8095/openamSP/json/authenticate', headers=headers, params=data)
</code></pre>
<p>The method URL receives is POST method not GET.</p>
| 2 | 2016-05-30T16:50:32Z | [
"python",
"django",
"http",
"curl"
] |
Virtualenv doesn't work on RedHat | 37,530,575 | <p>I'm trying to figure out why I cannot create a virtualenv on RedHat. Here's my command line :</p>
<pre><code>python /opt/rh/python27/root/usr/bin/virtualenv-2.7 -p /opt/rh/python27/ /home/myuser/tpa/
</code></pre>
<p>.</p>
<pre><code>/opt/rh/python27/root/usr/bin/virtualenv-2.7 : Is here to setup the version of v... | 0 | 2016-05-30T16:56:30Z | 37,530,802 | <p>-p expects a python executable, not an installation directory. Give it the name of a python executable in your $PATH or the full path the the python executable you want to run.</p>
| 1 | 2016-05-30T17:13:14Z | [
"python",
"virtualenv",
"redhat",
"fedora"
] |
Python matplotlib plot3d contour length | 37,530,582 | <p>Is there a way to get contour lengths with matplotlib for a scatter? I have columns (x_vals, y_vals, z_vals) and I want to get the length of contours of z_val = z_0.</p>
| 2 | 2016-05-30T16:57:06Z | 37,533,932 | <p>The main idea is set desirable level for a contour line, extract coordinates from a contour line and get total length of it.</p>
<pre><code>import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
def randrange(n, vmin, vmax):
return (vma... | 1 | 2016-05-30T21:40:07Z | [
"python",
"matplotlib",
"contour"
] |
Boolean indexing on specific data | 37,530,618 | <p>I'm trying to find out how to Boolean index in pandas with a set range, like list slicing in Python.</p>
<pre><code>mydata = [{'name': 'John', 'age': 75, 'height': 1.78},
{'name': 'Paul', 'age': 22, 'height': 1.71},
{'name': 'John', 'age': 45, 'height': 1.81}]
df = pandas.DataFrame(mydata)
df = df.set_index('n... | 0 | 2016-05-30T16:59:51Z | 37,530,666 | <p>Here is how you can print all indexes equal to 'John' up to the third item in the data frame:</p>
<pre><code>print df[0:3].ix['John']
</code></pre>
| 2 | 2016-05-30T17:03:10Z | [
"python",
"pandas"
] |
Odoo/Python how to redirect to a website | 37,530,660 | <p>In my form view each record should have an icon with a redirection to a specific website. For Example:</p>
<p>Record 1 | www.test.com/a</p>
<p>Record 2 | www.test.com/b</p>
<p>How is it possible to create such a redirection on click?</p>
<p>I tried a button - but I dont know how to redirect in the action:</p>
<... | 0 | 2016-05-30T17:02:48Z | 37,531,757 | <p>you can use "ir.actions.act_url":</p>
<pre><code>return {
'type': 'ir.actions.act_url',
'url': '/forum/%s/question/%s' % (self.forum_id.id, self.id),
'target': 'self',
'res_id': self.id,
}
</code></pre>
<p>check <code>website_forum/models/forum.py</code> for instance.</p>
| 3 | 2016-05-30T18:27:22Z | [
"python",
"redirect",
"browser",
"tabs",
"openerp"
] |
How to prevent a gap between two canvas in python | 37,530,764 | <p>This code produces two canvases in a window. However Python does not stick them one to another but places a gap between them. This gap gets even wider when I resize the window.</p>
<pre><code>from Tkinter import *
class App:
def __init__(self,master):
master.title('Python Canvas Testing')
master... | 2 | 2016-05-30T17:10:23Z | 37,533,237 | <p>Both widgets have <code>expand</code> set to <code>True</code>,so they each are assigned some of the extra space. If you want only one to get the extra space, set <code>expand</code> to <code>False</code> for the other one. If you want them both to be given some of the extra space, be sure to set <code>fill</code> t... | 1 | 2016-05-30T20:26:55Z | [
"python",
"tkinter",
"pack",
"tkinter-canvas"
] |
How to prevent a gap between two canvas in python | 37,530,764 | <p>This code produces two canvases in a window. However Python does not stick them one to another but places a gap between them. This gap gets even wider when I resize the window.</p>
<pre><code>from Tkinter import *
class App:
def __init__(self,master):
master.title('Python Canvas Testing')
master... | 2 | 2016-05-30T17:10:23Z | 37,533,283 | <p>I don't know how to make it work with pack. But you can do it with the grid manager. To have expandable widget with grid, you need to set two things. First, the "sticky" parameter allows the widget to fill the space inside his cell in the grid ('ew' fills horizontally, 'nsew' fills in both directions). Second, the w... | 1 | 2016-05-30T20:29:58Z | [
"python",
"tkinter",
"pack",
"tkinter-canvas"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.