title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
python string template: multiline substitution with correct indentation | 37,751,054 | <p>I'm using <a href="https://docs.python.org/2/library/string.html#template-strings" rel="nofollow"><code>string.Template</code></a>s to generate Python code. A template might looks like</p>
<pre><code>import numpy
def main():
${content}
return
</code></pre>
<p>When substituting <code>${content}</code> wi... | 0 | 2016-06-10T14:42:32Z | 37,751,902 | <p>I can think of a few options, no magic 'print this and correctly indent it' methods though.</p>
<p>1)
You can include the spaces/newlines in your multiline string like so:</p>
<pre><code>"""a = 1
b = 2
print(a + b)"""
</code></pre>
<p>2)
You could use <a href="https://github.com/hhatto/autopep8" rel="no... | 0 | 2016-06-10T15:25:41Z | [
"python",
"templates",
"newline"
] |
How do I insert my own values in Windrose.py? | 37,751,107 | <p>I have discovered <a href="http://youarealegend.blogspot.fr/2008/09/windrose.html" rel="nofollow">this</a> module that works great, I love the output.
I am trying to change the values of the random input, here:</p>
<pre><code>ws = random(500)*6
wd = random(500)*360
</code></pre>
<p>From <a href="https://pypi.pytho... | 1 | 2016-06-10T14:44:38Z | 37,756,786 | <p>Try this example and check values in lists <code>angles</code> and <code>length</code>, they have to be float or integer:</p>
<pre><code>from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
from numpy.random import random
from numpy import arange, array
angles = [10.,20... | 0 | 2016-06-10T20:34:49Z | [
"python",
"matplotlib",
"qgis"
] |
Python timing in order to trigger specific events | 37,751,123 | <p>In Python I would like to run a function calling a default action for 20 seconds. However, there are 5 specific timings within these 20 seconds when another function should be triggered. In order to simplify my code, I have replaced the "action" functions with simple printing commands. </p>
<p>Here is what I have s... | 1 | 2016-06-10T14:45:23Z | 37,752,076 | <p><a href="https://docs.python.org/2/library/time.html#time.time" rel="nofollow"><code>time.time()</code></a> returns second since epoch as a floating point number like:</p>
<pre><code>>>> import time
>>> time.time()
1465572505.891256
</code></pre>
<p>If your comparison:</p>
<p><code>time.time()-s... | 0 | 2016-06-10T15:34:51Z | [
"python",
"time",
"timer",
"timing",
"code-timing"
] |
Calculating percentile on pandas dataframe and assigning binary value to new column | 37,751,146 | <p>Take a dataframe with one column of imagined 'temperature' data:</p>
<pre><code>import pandas as pd
import numpy as np
dates = pd.date_range('20070101',periods=3200)
df = pd.DataFrame(data=np.random.randint(0,100,(3200,1)), columns =list('A'))
df['date'] = dates
df = df[['date','A']]
</code></pre>
<p>I want to as... | 1 | 2016-06-10T14:46:27Z | 37,751,700 | <p>@EdChum provided this answer:</p>
<p>create a new column <code>df['temp'] = ""</code> and applied this:</p>
<pre><code>df.loc[df['A'] > df['A'].quantile(0.9), 'temp'] = 1
df.loc[df['A'] < df['A'].quantile(0.1), 'temp'] = -1
</code></pre>
<p>Thanks!</p>
| 2 | 2016-06-10T15:14:21Z | [
"python",
"pandas",
"dataframe"
] |
Python: "exec open(external.py).read() in globals(), locals()" while allowing it to manipulate objects in main script | 37,751,173 | <h2>Background</h2>
<p>I am using the dreaded <code>exec open</code> in Python 2.7, to execute two other Python files (<code>file1.py</code> and <code>file2.py</code>) from within my main script (<code>main_file.py</code>).</p>
<p>I'm a novice programmer, and I do this because the external files are located in other ... | 0 | 2016-06-10T14:47:37Z | 37,751,386 | <p>Quoting from the <a href="https://docs.python.org/2/library/functions.html#execfile" rel="nofollow">docs</a>:</p>
<blockquote>
<p>This function is similar to the exec statement, but parses a file
instead of a string. It is different from the import statement in that
it does not use the module administration â... | 1 | 2016-06-10T14:57:58Z | [
"python",
"python-2.7",
"exec"
] |
Equivalent PyQt code for C++ Qt Snippet | 37,751,197 | <p>I'm using PyQt and understand enough OOP to get by comfortably in Python. However, the documentation and useful forum posts are all in C++. I know that the best route would probably be to just re-learn C++. I'm trying but It's taking a long time to sift through tutorials and find the information that I need, mostly ... | 2 | 2016-06-10T14:48:37Z | 37,759,490 | <p><code>SetTextInteraction</code> in the original code is a method of a subclass of <code>QGraphicsTextItem</code>, and <code>textCursor()</code> method is inherited from <code>QGraphicsTextItem</code>. Translation to PyQt is literal:</p>
<pre><code>class TextItem(QGraphicsTextItem):
def __init__(self, parent=None)... | 2 | 2016-06-11T02:56:31Z | [
"python",
"c++",
"qt",
"pyqt",
"code-translation"
] |
Equivalent PyQt code for C++ Qt Snippet | 37,751,197 | <p>I'm using PyQt and understand enough OOP to get by comfortably in Python. However, the documentation and useful forum posts are all in C++. I know that the best route would probably be to just re-learn C++. I'm trying but It's taking a long time to sift through tutorials and find the information that I need, mostly ... | 2 | 2016-06-10T14:48:37Z | 37,765,403 | <p>My Python and PyQt is rusty, but here's a translation with possible small errors in syntax:</p>
<pre><code>def SetTextInteraction(self, on, selectAll):
if on and self.textInteractionFlags() == Qt.NoTextInteraction:
self.setTextInteractionFlags(Qt.TextEditorInteraction)
self.setFocus(Qt.MouseFocu... | 1 | 2016-06-11T15:26:15Z | [
"python",
"c++",
"qt",
"pyqt",
"code-translation"
] |
How to get the indexes of column and row in a 2-dimensional matrix(list) that have the most given elements in using numpy in python | 37,751,231 | <p>For example, I have a 2-dimensional matrix:</p>
<pre><code>[0 0 0 0 5 0 0 0
0 5 0 0 5 0 0 0
0 0 5 5 5 5 5 0
5 0 0 0 5 0 0 5
0 5 0 0 0 0 5 0]
</code></pre>
<p>I want to get the indexes of the row and column with the most 5s. Which should be the third row and fifth column. I don't want to use for loop to get... | 1 | 2016-06-10T14:50:19Z | 37,751,506 | <p>Here's one way. <code>a</code> is the array and <code>elem</code> is the element to be checked:</p>
<pre><code>In [71]: a
Out[71]:
array([[0, 0, 5, 0, 5, 0, 0, 0],
[0, 5, 0, 0, 0, 5, 0, 5],
[0, 0, 5, 0, 5, 0, 5, 0],
[0, 5, 0, 0, 0, 5, 0, 5],
[0, 0, 0, 0, 0, 5, 0, 0]])
In [72]: elem = 5... | 3 | 2016-06-10T15:03:57Z | [
"python",
"arrays",
"numpy",
"matrix"
] |
How to get the indexes of column and row in a 2-dimensional matrix(list) that have the most given elements in using numpy in python | 37,751,231 | <p>For example, I have a 2-dimensional matrix:</p>
<pre><code>[0 0 0 0 5 0 0 0
0 5 0 0 5 0 0 0
0 0 5 5 5 5 5 0
5 0 0 0 5 0 0 5
0 5 0 0 0 0 5 0]
</code></pre>
<p>I want to get the indexes of the row and column with the most 5s. Which should be the third row and fifth column. I don't want to use for loop to get... | 1 | 2016-06-10T14:50:19Z | 37,751,555 | <pre><code>colnum = np.argmax([list(a[:,x]).count(5) for x in range(a.shape[1])])
colnum
Out[22]: 4
rownum = np.argmax([list(a[x,:]).count(5) for x in range(a.shape[0])])
rownum
Out[25]: 2
</code></pre>
<p>Number starts from 0</p>
| 1 | 2016-06-10T15:06:38Z | [
"python",
"arrays",
"numpy",
"matrix"
] |
Can't use Twilio with python | 37,751,347 | <p>I used the code from the Twilio website to <a href="https://www.twilio.com/docs/api/rest/sending-messages" rel="nofollow">send a text message using python</a>. I used real values, that I obtained during registration in the actual code. There aren't any XXXXXX in my program. </p>
<p>I removed the {{}} too. the code'... | 0 | 2016-06-10T14:56:20Z | 37,751,531 | <pre><code>account_sid = "{{ account_sid }}" # Your Account SID from www.twilio.com/console
</code></pre>
<p>This does not mean place the value in the <code>{{ }}</code>. It means replace that entire string with your value. </p>
| 4 | 2016-06-10T15:05:36Z | [
"python",
"python-2.7",
"twilio"
] |
How to filter through Model of a many-to-many field? | 37,751,422 | <p>I'm trying to implement a geofencing for a fleet of trucks. I have to associate a list of boundaries to a vehicle. On top of that one of the requirements is keep everything even once it is deleted for audit purposes. Therefore we have to implement soft delete on everything. This is where the problem lies. My many to... | 6 | 2016-06-10T14:59:50Z | 37,979,359 | <p>First problem: your use of <code>limit_choices_to</code> won't work because as the <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.ManyToManyField.limit_choices_to" rel="nofollow">documentation says</a>:</p>
<blockquote>
<p><code>limit_choices_to</code> has no effect when used o... | 4 | 2016-06-22T22:37:06Z | [
"python",
"django",
"model",
"many-to-many"
] |
How to filter through Model of a many-to-many field? | 37,751,422 | <p>I'm trying to implement a geofencing for a fleet of trucks. I have to associate a list of boundaries to a vehicle. On top of that one of the requirements is keep everything even once it is deleted for audit purposes. Therefore we have to implement soft delete on everything. This is where the problem lies. My many to... | 6 | 2016-06-10T14:59:50Z | 38,029,590 | <p>What about if you just do:</p>
<pre><code>class Vehicle(SoftDeleteModel):
#you can even remove that field
#routes = models.ManyToManyField('RouteBoundary', through='VehicleBoundaryMap', verbose_name=_('routes'),
# limit_choices_to={'active': True})
@property
def r... | 1 | 2016-06-25T14:37:08Z | [
"python",
"django",
"model",
"many-to-many"
] |
insert vriable into table QGIS | 37,751,472 | <p>I'm trying to insert some values in a data base table that I created with the following code:</p>
<pre><code>conn = db.connect('test.sqlite')
cur = conn.cursor()
sql= 'SELECT InitSpatialMetadata()'
cur.execute(sql)
conn.commit()
#connection to the DB
qid=QInputDialog()
tablefacette,ok=QInputDia... | 0 | 2016-06-10T15:02:08Z | 37,806,564 | <p>I would write like this instead:</p>
<pre><code>cur.execute("INSERT INTO %s (IDface, Xp1, Yp1, Zp1, Xp2, Yp2, Zp2, Xp3, Yp3, Zp3) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", %(table_name, Xp1[i], Yp1[i], Zp1[i], Xp2[i], Yp2[i], Zp2[i], Xp3[i], Yp3[i], Zp3[i]))
</code></pre>
| 0 | 2016-06-14T08:17:39Z | [
"python",
"sql",
"qgis"
] |
Escaping strings in Python subprocess.Popen | 37,751,656 | <p>I try to invoke an awk script in my python script. I use subprocess.Popen():</p>
<pre><code>awk -F"\t" 'NR<5{ print "SET", "\""$1"\"", "\""$2"|"$3"|"$4"\"" }' folder/file.tsv
</code></pre>
<p>This is the script: </p>
<pre><code>import os
import subprocess
goal_dir = os.path.join(os.getcwd(), "folder", "file.t... | 1 | 2016-06-10T15:11:31Z | 37,772,673 | <p>like this?</p>
<pre><code>subprocess.Popen(r'''awk -F"\t" 'NR<5{ print "SET", "\""$1"\"","\""$2"|"$3"|"$4"\"" }' %s''' % goal_dir, shell=True, stdout=subprocess.PIPE)
</code></pre>
<p>OR</p>
<pre><code>args = ["awk", '-F"\t"', r"""'NR<5{ print "SET", "\""$1"\"", "\""$2"|"$3"|"$4"\"" }'""", "{0}".format(goal... | 0 | 2016-06-12T09:27:02Z | [
"python",
"linux",
"awk"
] |
how to use django login | 37,751,775 | <p>I have the following code and I get an error saying: "the User object has no attribute POST"</p>
<pre><code>def login (request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_a... | 2 | 2016-06-10T15:18:18Z | 37,751,822 | <p>What happened is you try to call <code>login</code> of <code>from django.contrib.auth</code>, but you are also defining your own function called <code>login()</code>, you have a kind of name conflict here.</p>
<p>You should rename that to something else, e.g. <code>login_view()</code></p>
<pre><code>from django.co... | 3 | 2016-06-10T15:20:58Z | [
"python",
"django"
] |
how to use django login | 37,751,775 | <p>I have the following code and I get an error saying: "the User object has no attribute POST"</p>
<pre><code>def login (request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_a... | 2 | 2016-06-10T15:18:18Z | 37,752,014 | <p>I would advise adding a login form first</p>
<pre><code>class LoginForm(forms.Form):
username = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput)#hides password on input
</code></pre>
<p>then </p>
<pre><code>from django.http import HttpResponseRedirect,HttpResponse
from django.contrib... | 0 | 2016-06-10T15:31:56Z | [
"python",
"django"
] |
Append keeps on appending the same item, does not append the right ones, Python | 37,751,865 | <p>This is what I have imported:</p>
<pre><code>import random
import matplotlib.pyplot as plt
from math import log, e, ceil, floor
import numpy as np
from numpy import arange,array
import pdb
from random import randint
</code></pre>
<p>Here I define the function matrix(p,m)</p>
<pre><code>def matrix(p,m): ... | 1 | 2016-06-10T15:23:34Z | 37,757,239 | <blockquote>
<p>You're passing and storing by references not copies, so on the next iteration of your loop <code>MHops</code> alters your previously stored version in <code>d</code>. Use <code>import copy; d.append(copy.deepcopy(mat))</code> to instead store a copy which won't be altered later.</p>
</blockquote>
<p>... | 0 | 2016-06-10T21:12:34Z | [
"python",
"matlab",
"list",
"loops",
"montecarlo"
] |
Django REST Framework - Tutorial - Confused | 37,751,866 | <p>I'm going over Serializers (<code>serializers.Serializer</code>, <em>not</em> <code>serializers.ModelSerializer</code>) in the <a href="http://www.django-rest-framework.org/tutorial/1-serialization/" rel="nofollow">Tutorials</a> and I'm confused about one thing.</p>
<p>First off, we serialize the data into Python n... | 1 | 2016-06-10T15:23:42Z | 37,752,075 | <h2>OPTIONS method</h2>
<blockquote>
<p>The OPTIONS method allows a client to determine the <strong>options and/or requirements associated with a resource</strong>, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.
â RFC7231, Section 4.3.7.</p>
</blockquote>
... | 2 | 2016-06-10T15:34:50Z | [
"python",
"django",
"serialization",
"django-rest-framework"
] |
Downloading image with PIL and requests | 37,751,877 | <p>I am trying to download an original image (png format) by url, convert it on the fly (without saving to disc) and save as jpg. </p>
<p>The code is following:</p>
<pre><code>import os
import io
import requests
from PIL import Image
...
r = requests.get(img_url, stream=True)
if r.status_code == 200:
i = Image.op... | 1 | 2016-06-10T15:24:09Z | 37,752,185 | <p>When using <code>r.iter_content()</code>, you need to buffer the results somewhere. Unfortunately, I can't find any examples where the contents get appended to an object in memory--usually, <code>iter_content</code> is used when a file can't or shouldn't be loaded entirely in memory at once. However, you buffer it u... | 1 | 2016-06-10T15:40:25Z | [
"python",
"python-2.7",
"python-3.x",
"python-requests"
] |
Could not get link from html content using python | 37,751,894 | <p>Here is the URL that I'am using:</p>
<p><a href="http://www.protect-stream.com/PS_DL_xODN4o5HjLuqzEX5fRNuhtobXnvL9SeiyYcPLcqaqqXayD8YaIvg9Qo80hvgj4vCQkY95XB7iqcL4aF1YC8HRg_i_i" rel="nofollow">http://www.protect-stream.com/PS_DL_xODN4o5HjLuqzEX5fRNuhtobXnvL9SeiyYcPLcqaqqXayD8YaIvg9Qo80hvgj4vCQkY95XB7iqcL4aF1YC8HRg_i... | 1 | 2016-06-10T15:25:03Z | 37,752,172 | <p>This is not going to be trivial. The <code>k</code> parameter value is "hidden" deep inside a <code>script</code> element inside nested iframes. Here is a <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a> + <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" r... | 1 | 2016-06-10T15:39:40Z | [
"python",
"web-scraping",
"urllib2",
"urllib"
] |
How can I have a one to many relationship and join it using a different column? | 37,751,959 | <p>I'm working with 2 models.</p>
<pre><code>class Foo(db.Model):
id = db.Column(db.Integer, primary_key=True)
desc = db.Column(db.String(30))
bars = db.relationship('Bar', back_populates='foo')
class Bar(db.Model):
key_1 = db.Column(db.String('64'), primary_key=True)
key_2 = db.Column(db.String... | 0 | 2016-06-10T15:29:04Z | 37,754,816 | <p>You absolutely can indicate that one of the columns is both part of the composite <code>primary key</code> as well as a <code>foreign_key</code>. Of course, it also requires that those columns are of the same type. The code below should work just fine:</p>
<pre><code>class Foo(db.Model):
id = db.Column(db.Integ... | 0 | 2016-06-10T18:16:35Z | [
"python",
"sqlalchemy"
] |
Continue Processing requests after failure in python | 37,751,970 | <p>I have a script that runs and submits urls in a text file via GET to an API and saves the response to a text file. However, the for loop quits if I get a failure in the first section and does not continue passing the others. How can I still grab the failure and continue on with the others without the script exiting ... | 0 | 2016-06-10T15:29:52Z | 37,752,026 | <p>Use an <a href="https://docs.python.org/3/tutorial/errors.html" rel="nofollow">exception</a> to catch the failure and continue on. </p>
| 0 | 2016-06-10T15:32:30Z | [
"python",
"for-loop",
"httpresponse"
] |
Continue Processing requests after failure in python | 37,751,970 | <p>I have a script that runs and submits urls in a text file via GET to an API and saves the response to a text file. However, the for loop quits if I get a failure in the first section and does not continue passing the others. How can I still grab the failure and continue on with the others without the script exiting ... | 0 | 2016-06-10T15:29:52Z | 37,752,088 | <p>Use continue instead of exit()</p>
| 2 | 2016-06-10T15:35:40Z | [
"python",
"for-loop",
"httpresponse"
] |
Continue Processing requests after failure in python | 37,751,970 | <p>I have a script that runs and submits urls in a text file via GET to an API and saves the response to a text file. However, the for loop quits if I get a failure in the first section and does not continue passing the others. How can I still grab the failure and continue on with the others without the script exiting ... | 0 | 2016-06-10T15:29:52Z | 37,753,885 | <p>Now that your loop control is corrected, it must be working correctly. It will print out a failure message every time it gets an error response (not 200). If you're only seeing one error message, you're only getting one non-200 response from the other side. If that's not what you expect, the problem is on the server... | 0 | 2016-06-10T17:17:58Z | [
"python",
"for-loop",
"httpresponse"
] |
How to sum over two indices in python? | 37,751,995 | <p>Can someone help me out with the <code>sum</code> function ?</p>
<p>I am trying to sum over two indices. I want to obtain the following result:</p>
<pre><code>p_t[0, 0]+p_t[0, 1]+p_t[0, 2]+p_t[1, 0]+p_t[1, 1]+p_t[1, 2]+p_t[2,0]+p_t[2, 1]+p_t[2, 2]
</code></pre>
<p>, using this code:</p>
<pre><code>num_products=3... | 0 | 2016-06-10T15:31:12Z | 37,752,082 | <pre><code>sum(p_t[i][j] for i in range(len(p_t)) for j in range(len(p_t[i])))
</code></pre>
| 1 | 2016-06-10T15:35:33Z | [
"python",
"numpy",
"sum"
] |
How to sum over two indices in python? | 37,751,995 | <p>Can someone help me out with the <code>sum</code> function ?</p>
<p>I am trying to sum over two indices. I want to obtain the following result:</p>
<pre><code>p_t[0, 0]+p_t[0, 1]+p_t[0, 2]+p_t[1, 0]+p_t[1, 1]+p_t[1, 2]+p_t[2,0]+p_t[2, 1]+p_t[2, 2]
</code></pre>
<p>, using this code:</p>
<pre><code>num_products=3... | 0 | 2016-06-10T15:31:12Z | 37,752,157 | <pre><code>import numpy as np
from itertools import product
a =[[1,2,3],[4,5,6],[3,3,3]]
p_t = np.array(a)
num_products = 3
rslt1 = sum (p_t[i, j] for i,j in product(range(num_products), repeat=2))
rslt2= sum (p_t[i, j] for i in range(num_products) for j in range(num_products))
</code></pre>
<p><strong>Output:</str... | 0 | 2016-06-10T15:38:57Z | [
"python",
"numpy",
"sum"
] |
How to count every x number backwards from y to zero? | 37,752,036 | <p>I need help in python about making a code that will first ask a number for a starting number and then ask a number in which it will count spaces with that number until 0. </p>
<p>For example: input -10 and then input 2 and it will count from -10 to 0(0 not included) with 2 spaces: -10 -8 -6 -4 -2 </p>
<p>My Attemp... | -8 | 2016-06-10T15:32:50Z | 37,752,857 | <p>Here is my solution to your problem, I hope this helps!</p>
<pre><code>def count_for_me(start=None, step=None):
if not start:
start = int(input('Start number?: '))
if not step:
step = int(input('Steps between each iteration?: '))
return tuple(abs(x) if start > 0 else x for x in range(... | -1 | 2016-06-10T16:15:16Z | [
"python"
] |
How can I list all packages/modules available to Python from within a Python script? | 37,752,054 | <p>I have looked around and do not see a solution for this. What I would like to do is get a list of all packages available in Python at run-time.</p>
<p>I looked at these:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/1707709/list-all-the-modules-that-are-part-of-a-python-package">List all the modules tha... | 2 | 2016-06-10T15:33:49Z | 37,753,221 | <p>Alright, I was curious, and I digged a bit into <code>pkgutil</code>, and I came up with this, which is much simpler than I expected:</p>
<pre><code>list(pkgutil.iter_modules())
</code></pre>
<p>It lists all top-level packages/modules available either as regular files or zip packages, without loading them. It will... | 2 | 2016-06-10T16:37:24Z | [
"python",
"python-2.7",
"packages"
] |
Raspberry pi serial port data wrong | 37,752,086 | <p>I connected an Arduino Board to Raspberry through an USB port. With a Processing code i want to read 70 bytes sended by arduino. If i use this program on my PC windows it works, but with Raspberry the data that i get from Processing are different from the data sended by arduino. This is the Processing code to read t... | 1 | 2016-06-10T15:35:39Z | 37,763,065 | <p>Unplug your Arduino, search with <code>ls /dev/tty*</code> and plug it in. <br>If you now search again with <code>ls /dev/tty*</code> you will see a new device, for example <code>/dev/ttyACM0</code>. Additionally you need the arduino drivers to emulate the COM-Port <code>sudo apt-get update && sudo apt-get i... | 0 | 2016-06-11T11:12:33Z | [
"python",
"arduino",
"serial-port",
"raspberry-pi",
"processing"
] |
Set window size for xlsxwriter | 37,752,121 | <p>I cannot set the window size for created excel file with xlsxwriter and it always creates small window on OSX. Is there a way to set window size on xlsxwriter?</p>
| 2 | 2016-06-10T15:37:20Z | 37,752,631 | <p>There isn't an API to do it in XlsxWriter (you could open a feature request if you like).</p>
<p>In the meantime you can change these properties in the workbook object, shown below with the inbuilt defaults:</p>
<pre><code> workbook.window_width = 16095
workbook.window_height = 9660
</code></pre>
<p>I'm no... | 2 | 2016-06-10T16:03:33Z | [
"python",
"excel",
"osx",
"window",
"xlsxwriter"
] |
Pandas Multiindex Nested Sort and Percent | 37,752,146 | <p>Given this data frame and pivot table:</p>
<pre><code>import pandas as pd
df=pd.DataFrame({'County':['A','A','A','A','A','B','B','B','B','A','A','A','A','A','B','B','B','B'],
'Hospital':['a','b','c','d','e','a','b','c','e','a','b','c','d','e','a','b','c','e'],
'Enrollment':[44,55,42,... | 1 | 2016-06-10T15:38:24Z | 37,752,749 | <p>You could:</p>
<pre><code>df = pd.concat([df, df.groupby(level='County').apply(lambda x: x['2013'].div(x['2013'].sum())).reset_index(0, drop=True).to_frame('Percent')], axis=1)
top_3 = df.groupby(level='County')['Percent'].nlargest(3).reset_index(0, drop=True)
df = pd.concat([df.drop('Percent', axis=1), top_3], axi... | 1 | 2016-06-10T16:10:11Z | [
"python",
"sorting",
"pandas",
"pivot-table",
"percentage"
] |
Pandas Multiindex Nested Sort and Percent | 37,752,146 | <p>Given this data frame and pivot table:</p>
<pre><code>import pandas as pd
df=pd.DataFrame({'County':['A','A','A','A','A','B','B','B','B','A','A','A','A','A','B','B','B','B'],
'Hospital':['a','b','c','d','e','a','b','c','e','a','b','c','d','e','a','b','c','e'],
'Enrollment':[44,55,42,... | 1 | 2016-06-10T15:38:24Z | 37,754,426 | <p>So, I found that this works as well:</p>
<pre><code>d=d2.T
d['Percent']=round(d.iloc[:,-1]/d.iloc[:,-1].groupby(level=1).transform(sum),2)
d=d.sort_values(d.columns[-1],ascending=False).sortlevel(1, sort_remaining=False)
d=d.groupby(level=1).head(3)
d.T
</code></pre>
| 0 | 2016-06-10T17:52:08Z | [
"python",
"sorting",
"pandas",
"pivot-table",
"percentage"
] |
Tkinter ProgressBar and Os.Walk in Python 2.7 | 37,752,159 | <p>I have a working GUI with a wonky progress bar. My issues seems to be that I can't get the progress bar to step correctly based on the amount of items in the source directory. Any ideas?</p>
<pre><code>def Progress(self):
progress = Frame(self)
progress.pack(fill=X)
self.progressLine = ttk.Progressbar(p... | 1 | 2016-06-10T15:39:05Z | 37,752,501 | <p>When you do division in Python with 2 ints you are going to get back an int (whole number). So for example if you had 27 files:</p>
<pre><code>>>> 100 / 27
3
</code></pre>
<p>Now we can see there's a huge problem here, since <code>3 * 27 == 81</code>. So if we step by 3 for 27 files you're only going t... | 1 | 2016-06-10T15:56:35Z | [
"python",
"python-2.7",
"tkinter",
"progress-bar",
"os.walk"
] |
Creating background task to retrieve PyMongo DB in Flask for Analytics | 37,752,242 | <p>I am currently connecting to a remote mongodb to generate a dashboard in Flask. The db connection and load into Pandas occurs on each page request. </p>
<pre><code>@app.route("/")
#connects to db
#loads to pandas
#perform analysis and display
@app.route("/recent/")
#connects to db
#loads to pandas... | 0 | 2016-06-10T15:43:29Z | 37,758,612 | <p>One way to create background tasks use Celery. To install celery just <code>pip install celery</code> (in a virtualenv is ideal as usual). <a href="http://blog.miguelgrinberg.com/post/using-celery-with-flask" rel="nofollow">Here</a> is complete tutorial for the basics of that. <a href="https://github.com/miguelgrinb... | 2 | 2016-06-10T23:55:48Z | [
"python",
"mongodb",
"flask",
"pymongo"
] |
Create multiple plots from Pandas dataframe | 37,752,265 | <p>I have the following Pandas dataframe:</p>
<pre><code> data ={'Studentid'['SSmith','SSmith','SSmith','SSmith','PPeters','PPeters','PPeters'],
'LastName':['Smith','Smith','Smith','Smith','Peters','Peters','Peters'],
'FirstName':['S','S','S','S','P','P','P'],
'year':[2012,2013,2014,2014,2015,2015,2015]... | 1 | 2016-06-10T15:44:50Z | 37,752,403 | <p>Not tested. You were very close, you just need to define your <code>x</code> and <code>y</code> anew for each group.</p>
<p>--piRSquared (Now Tested)... it works.</p>
<pre><code>for i, group in df.groupby("Studentid"):
plt.figure()
x=group['DateProgress']
y=group['BookProgress']
plt.scatter(x,y)
... | 3 | 2016-06-10T15:51:06Z | [
"python",
"pandas",
"matplotlib"
] |
Python - grouping defaultdict values by hamming distance in keys | 37,752,332 | <p>I have a default dict with ~700 keys. The keys are in a format such as A_B_STRING. What I need to do is split the key by '_', and compare the distance between 'STRING' for each key, if A and B are identical. If the distance is <= 2, I want to group the lists for those keys into a single defaultdict key:value grou... | 4 | 2016-06-10T15:48:10Z | 37,754,681 | <p>I think I see one issue with your code consider this scenario:</p>
<pre><code>0: A_B_DATA1
1: A_B_DATA2
2: A_B_DATA3
All the valid comparisons are:
0 -> 1 * Combines under key 'A_B_DATA1'
0 -> 2 * Combines under key 'A_B_DATA1'
1 -> 2 * Combines under key 'A_B_DATA2' **opps
</code></pre>
<p>I wo... | 1 | 2016-06-10T18:08:31Z | [
"python",
"combinations",
"string-comparison",
"defaultdict",
"hamming-distance"
] |
How to pickle class objects into text file and read it back? | 37,752,338 | <pre><code>if __name__ == "__main__":
h1 = Person(5)
print (h1)
</code></pre>
<p>As shown above, I have a object <code>h1</code> of class <code>Person</code> needed to be saved as text file (.txt). I'm wondering how to fulfill this persistence and read it back?</p>
<p>Some users suggested to use pickle, I t... | 0 | 2016-06-10T15:48:25Z | 37,761,329 | <p>Here is a possible solution to get you started. I renamed the person instance name and changed the parameter to a name ;-)</p>
<pre><code>#! /usr/bin/env python
"""Note: Documentation clearly states, that classes can be pickled,
but only iff they "are defined at the top level of a module"."""
from __future__ import... | 1 | 2016-06-11T07:54:45Z | [
"python",
"python-3.x",
"persistence"
] |
no module named flaskext.uploads | 37,752,353 | <p>I'm trying to use flask-uploads for image upload feature in my flask app. </p>
<p>I used <code>pip install Flask-Uploads</code> to install and <code>pip install Flask-Uploads --upgrade</code> to upgrade the flask-uploads module.
But when I import it, it gives me an error, here's my import code:</p>
<pre><code>f... | 0 | 2016-06-10T15:49:20Z | 37,752,478 | <p><strong>Update</strong>: Suggested is the OP further drills down in changes of flask vs. flask-upload that introduced the incompatibility noted at the end of this troubleshooting aid / documentation. Maybe the maintainers of the packages even can provide answers, if the OP kindly asks them? When futher details are p... | 0 | 2016-06-10T15:54:47Z | [
"python",
"flask",
"flask-uploads"
] |
Data not passing back to Pandas from nested function | 37,752,368 | <p>I am trying to determine why the ultimate value produced by my function isn't being saved back to the new column I have instructed pandas to build. I have confirmed the if...elif statements are correct and function, and I have confirmed the calculations are occurring and generating the correct data. I am getting t... | 0 | 2016-06-10T15:49:54Z | 37,752,565 | <p>You forgot some <code>return</code> statements</p>
<pre><code>def Fin_adj(row, field):
if field == 'Cr':
if row[field] <= .7:
return Range_eval(row[field],0.,.69,.0,.25)
elif row[field] <= .9:
return Range_eval(row[field],.7,.89,.25,.5)
elif row[field] <=... | 0 | 2016-06-10T15:59:56Z | [
"python",
"python-3.x",
"pandas"
] |
Execute a python script using Popen with shell=False | 37,752,396 | <p>I would like to know if it's possible to execute this command </p>
<pre><code>cmd = "gnome-terminal -e 'python /path/to/file.py'"
p = subprocess.Popen(cmd,shell=True)
</code></pre>
<p>but with shell=False</p>
<p>I tried to run this command</p>
<pre><code>p = subprocess.Popen(["gnome-terminal","-e","python","/pa... | 0 | 2016-06-10T15:50:56Z | 37,752,514 | <p>As it is you're passing the command to <code>gnome-terminal</code>, not <code>python</code>.</p>
<pre><code>p = subprocess.Popen(["gnome-terminal","-e","python /path/to/file.py"],shell = False)
</code></pre>
| 2 | 2016-06-10T15:57:26Z | [
"python",
"shell",
"subprocess",
"popen",
"gnome"
] |
How do I extract only the file of a .tar.gz member? | 37,752,400 | <p>My goal is to unpack a <code>.tar.gz</code> file and not its sub-directories leading up to the file.</p>
<p>My code is based off this <a href="http://stackoverflow.com/questions/4917284/extract-files-from-zip-without-keeping-the-structure-using-python-zipfile">question</a> except instead of unpacking a <code>.zip</... | 1 | 2016-06-10T15:51:00Z | 37,753,786 | <p>This code has worked for me:</p>
<pre><code>import os
import shutil
import tarfile
with tarfile.open(fname, "r|*") as tar:
counter = 0
for member in tar:
if member.isfile():
filename = os.path.basename(member.name)
if filename != "myfile": # do your check
co... | 2 | 2016-06-10T17:11:51Z | [
"python",
"python-3.x",
"tar"
] |
Python - Error making migrations | 37,752,425 | <p>Im having trouble making some migrations to my Django Project.</p>
<p>Here's the code.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>from __future__ import unicode_literals
from dja... | 0 | 2016-06-10T15:51:57Z | 37,752,562 | <p>The variable md is not defined anywhere in your models, it must be models not md, if you want to with md you can change your import</p>
<pre><code>from django.db import models
</code></pre>
<p>to </p>
<p><code>from django.db import models as md</code></p>
| -1 | 2016-06-10T15:59:45Z | [
"python",
"django",
"migration",
"database-migration"
] |
Mocking builtin function open inside an imported module | 37,752,485 | <p>I want to test that the <code>ftp.storbinary()</code> function is called with the right arguments. This however is part of a different module from the one were the test live.</p>
<p>In the <code>io.py</code> module I have this method (which is part of a class):</p>
<pre><code>def to_ftp(self, output_path, file_nam... | 0 | 2016-06-10T15:55:17Z | 37,855,341 | <blockquote>
<p>AssertionError: Expected call: storbinary('STOR output.zip', )</p>
<p>Actual call: storbinary('STOR output.zip', <_io.TextIOWrapper name='./output/output.zip' mode='r' encoding='UTF-8'>)</p>
</blockquote>
<p>For the actual call <code>storbinary</code> was given <code><_io.TextIOWrapper...<... | 0 | 2016-06-16T09:36:47Z | [
"python",
"unit-testing",
"ftp",
"mocking"
] |
Using view context in model's _post_put_hook | 37,752,579 | <p>I've overridden <code>_post_put_hook()</code> on one of my NDB models and I want to change the way I process my result depending on the URL the original request was made to:</p>
<pre><code>def _post_put_hook(self, future):
key = future.get_result()
# Do some processing
if <model was made thanks to PO... | 0 | 2016-06-10T16:00:42Z | 37,758,212 | <p>How about setting an 'internal' (_) attribute on the model instance as a flag, string or function for the post hook to use? The attribute field will be ignored by NDB when persisting the data.</p>
<p>eg:</p>
<pre><code>class TestModel(ndb.Model):
xyz = ndb.StringProperty()
...
def _post_pu... | 1 | 2016-06-10T22:59:30Z | [
"python",
"django",
"google-app-engine",
"django-rest-framework"
] |
Using view context in model's _post_put_hook | 37,752,579 | <p>I've overridden <code>_post_put_hook()</code> on one of my NDB models and I want to change the way I process my result depending on the URL the original request was made to:</p>
<pre><code>def _post_put_hook(self, future):
key = future.get_result()
# Do some processing
if <model was made thanks to PO... | 0 | 2016-06-10T16:00:42Z | 37,758,315 | <p>I've solved this in (what I believe) is an async-safe way as follows:</p>
<p>In the view I want to have modified <code>_post_put_hook()</code> behavior for, where the future is instantiated:</p>
<pre><code>def some_processor(self):
...
future = foo.put_async()
future.my_flag = True # Add custom flag he... | 0 | 2016-06-10T23:09:58Z | [
"python",
"django",
"google-app-engine",
"django-rest-framework"
] |
Python Sympy substitute symbolic matrix for (into a) symbol | 37,752,589 | <pre><code>q_vec, omega_vec, q1, q2, q3, w1, w2, w3 = \
sym.symbols('q_vec, omega_vec, q1, q2, q3, w1, w2, w3')
q_0_dot_str = '.5 * dot(q_vec, omega_vec)'
q_0_dot_symp = sym.sympify(q_0_dot_str)
q_0_dot_symp = q_0_dot_symp.subs([(q_vec, sym.Matrix([q1, q2, q3]), \
(omega_vec, sym... | 1 | 2016-06-10T16:01:09Z | 37,799,968 | <p>You have a typo in the subs call. It should be </p>
<pre><code>q_0_dot_symp = q_0_dot_symp.subs([(q_vec, sym.Matrix([q1, q2, q3])), \
(omega_vec, sym.Matrix([w1, w2, w3]).T)])
</code></pre>
<p>instead of </p>
<pre><code>q_0_dot_symp = q_0_dot_symp.subs([(q_vec, sym.Matrix([q1, q2, q... | 0 | 2016-06-13T22:11:15Z | [
"python",
"matrix",
"sympy",
"lambdify"
] |
Loop over multiple folders from list with glob.glob | 37,752,734 | <p>How can I loop over a defined list of folders and all of the individual files inside each of those folders?</p>
<p>I'm trying to have it copy all the months in each year folder. But when I run it nothing happens..</p>
<pre><code>import shutil
import glob
P4_destdir = ('Z:/Source P4')
yearlist = ['2014','2015','... | 0 | 2016-06-10T16:09:21Z | 37,762,123 | <p>I think the problem might be that you require a <code>/</code> in you source path:</p>
<pre><code>import shutil
import glob
P4_destdir = ('Z:/Source P4/')
yearlist = ['2014','2015','2016'] # assuming these files are in the same directory as your code.
for year in yearlist:
for file in glob.glob(r'{0}/*.csv'... | 1 | 2016-06-11T09:29:20Z | [
"python",
"csv",
"glob",
"shutil"
] |
Python: show all html in html.fromstring | 37,752,751 | <p>I have been scraping a website that requires login and its not getting all the information to require. So I thought it would be best to go back to the start and show all the html it has pulled from the page</p>
<p>how could i do this? below is my initial idea but what am i missing to allow me to debug?</p>
<pre><c... | 0 | 2016-06-10T16:10:19Z | 37,752,776 | <p>Well, you can print out the <code>browser.page_source</code> once again:</p>
<pre><code>print(browser.page_source)
</code></pre>
<p>If the browser was closed after getting the <code>.page_source</code>, you can remember it into a variable and print it out later:</p>
<pre><code>browser.get('http://www.racingpost.c... | 1 | 2016-06-10T16:11:16Z | [
"python",
"html"
] |
Group Datetime in panda into three hourly intervals | 37,752,757 | <p>I want to modify this SO topic <a href="http://stackoverflow.com/questions/16266019/python-pandas-group-datetime-column-into-hour-and-minute-aggregations">here</a> to three hourly interval.
I have a database of events at minute resolution. I need to group them in three hourly, and extract the count of this grouping.... | 0 | 2016-06-10T16:10:33Z | 37,752,979 | <p>You haven't provided much detail, but you can use the 'TimeGrouper':</p>
<pre><code>df.groupby(pd.TimeGrouper(key='your_time_column', freq='3H')).count()
</code></pre>
<p>The <code>key</code> parameter is optional if your time is the index.</p>
| 1 | 2016-06-10T16:22:47Z | [
"python",
"datetime",
"pandas"
] |
In Tensorflow, is there an op / are there ops to accept a tensor (of filenames) and output images? | 37,752,780 | <p>I'd like to be able to read in batches of images. However, these batches must be constructed by a python script (they cannot be placed into a file ahead of time for various reasons). What's the most efficient way, in tensorflow to do the following:</p>
<p>(1) Provided: A python list of B variable-length strings tha... | 2 | 2016-06-10T16:11:30Z | 37,755,754 | <p>If you have the images as a byte array you can use something similar to this in your graph:</p>
<pre><code> jpegs = tf.placeholder(tf.string, shape=(None))
images = tf.map_fn(lambda jpeg : your_processing_fn(jpeg), jpegs,
dtype=tf.float32)
logits = your_inference_model(images,labels)
</code></p... | 0 | 2016-06-10T19:22:01Z | [
"python",
"tensorflow"
] |
In Tensorflow, is there an op / are there ops to accept a tensor (of filenames) and output images? | 37,752,780 | <p>I'd like to be able to read in batches of images. However, these batches must be constructed by a python script (they cannot be placed into a file ahead of time for various reasons). What's the most efficient way, in tensorflow to do the following:</p>
<p>(1) Provided: A python list of B variable-length strings tha... | 2 | 2016-06-10T16:11:30Z | 37,756,811 | <p>This is how I understand your problem:</p>
<ul>
<li>you have some images</li>
<li>you have a function <code>sample_batch()</code> which returns a batch of filenames of size <code>B</code></li>
<li>you want to read the images corresponding to these filenames and preprocess them</li>
<li>finally you output a batch of... | 1 | 2016-06-10T20:37:15Z | [
"python",
"tensorflow"
] |
django one app one model multiple databases | 37,752,807 | <p><br>
I am new to django webapp development and i am stuck with a problem. I have created 1 app with 1 model to insert data to the database using 1 form. I am going to use multiple databases for this. Each database will have 1 table(for now) with same structure. Now my problem is:<br><br>
<b>How can I use just 1 mode... | 0 | 2016-06-10T16:12:49Z | 37,774,283 | <p>Regardless of whether or not this is a good way to architect your application, you can tell Django which database to read and write with <em>using</em>:</p>
<pre><code>Person.objects.using('db1').create(...)
Person.objects.using('db2').create(...)
</code></pre>
<p>So you don't need to use a router, simply define t... | 2 | 2016-06-12T12:30:32Z | [
"python",
"django",
"postgresql",
"django-models",
"django-1.9"
] |
Index Error: string index out of range | 37,752,828 | <p>I am getting a </p>
<blockquote>
<pre><code>Traceback (most recent call last): File "H:\Documents\game.py", line 73, in <module>
if attemptThis[i] != target[i]: IndexError: string index out of range Press any key to continue . . .
</code></pre>
</blockquote>
<p>error when I run this code.</p>
<pre><co... | 3 | 2016-06-10T16:13:47Z | 37,754,230 | <p>It's more pythonic to loop over a collection directly instead of using indexing. Since I was curious about what your program was supposed to do I rewrote the other parts as well to make it run.</p>
<pre><code>import time, random, string
target = """
lMMMMMMMM
... | 3 | 2016-06-10T17:39:59Z | [
"python"
] |
How to plot contourf for two dimensional with single value of solution | 37,752,887 | <p>Please help,</p>
<p>I'm trying to plot some math model in 2 dimensional input variables. I was trying to plot contour.</p>
<pre><code> x1 = np.linspace(1,10,1)
x2 = np.linspace(1,10,1)
x, y = np.meshgrid(x1,x2)
</code></pre>
<p>I have done this, but the solution of the mathematics operations are complicated. Be... | 0 | 2016-06-10T16:17:37Z | 37,753,890 | <p>You need to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html" rel="nofollow">reshape</a> your output data. If i am not mistaken, your "solution" is currently a 1D array, each element of the array corresponds to (x,y) tuple. To plot a contour you need to have 2D array with dimensions di... | 0 | 2016-06-10T17:18:14Z | [
"python",
"python-2.7",
"plot"
] |
error in starting and connecting to neo4j from py2neo | 37,752,898 | <p>I am trying to connect to neo4j from py2neo:</p>
<pre><code> from py2neo.server import GraphServer
server=GraphServer()
server.start()
</code></pre>
<p>At this stage when I check the logs I see that the server is up and running:</p>
<pre><code> 2016-06-10 09:41:09.928-0600 INFO Initiating metrics..... | 0 | 2016-06-10T16:18:21Z | 37,768,293 | <p>Which versions of Python, Neo4j and py2neo are you using? Are they listed as supported versions on py2neo.org?</p>
| 0 | 2016-06-11T20:35:59Z | [
"python",
"neo4j",
"py2neo"
] |
error in starting and connecting to neo4j from py2neo | 37,752,898 | <p>I am trying to connect to neo4j from py2neo:</p>
<pre><code> from py2neo.server import GraphServer
server=GraphServer()
server.start()
</code></pre>
<p>At this stage when I check the logs I see that the server is up and running:</p>
<pre><code> 2016-06-10 09:41:09.928-0600 INFO Initiating metrics..... | 0 | 2016-06-10T16:18:21Z | 37,973,223 | <p>As a work around I have been starting Neo4j from linux itself using./bin/neo4j start and it remains started even when I log off from linux.</p>
| 0 | 2016-06-22T16:07:35Z | [
"python",
"neo4j",
"py2neo"
] |
How is cv_values_ computed in sklearn.linear::RidgeCV? | 37,752,899 | <p>The reproducible example to fix the discussion:</p>
<pre><code>from sklearn.linear_model import RidgeCV
from sklearn.datasets import load_boston
from sklearn.preprocessing import scale
boston = scale(load_boston().data)
target = load_boston().target
import numpy as np
alphas = np.linspace(1.0,200.0, 5)
fit0 = Ri... | 3 | 2016-06-10T16:18:26Z | 37,759,853 | <p>Quoting from the Sklearn documentation:</p>
<blockquote>
<p>Cross-validation values for each alpha (if store_cv_values=True and
cv=None). After fit() has been called, this attribute will contain the
mean squared errors (by default) or the values of the
{loss,score}_func function (if provided in the construc... | 3 | 2016-06-11T04:15:41Z | [
"python",
"scikit-learn"
] |
How is cv_values_ computed in sklearn.linear::RidgeCV? | 37,752,899 | <p>The reproducible example to fix the discussion:</p>
<pre><code>from sklearn.linear_model import RidgeCV
from sklearn.datasets import load_boston
from sklearn.preprocessing import scale
boston = scale(load_boston().data)
target = load_boston().target
import numpy as np
alphas = np.linspace(1.0,200.0, 5)
fit0 = Ri... | 3 | 2016-06-10T16:18:26Z | 37,850,143 | <p><a href="https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/linear_model/ridge.py#L1137" rel="nofollow">Let's look - it's open source after all</a></p>
<p>The first call to fit makes a call upwards to its parent, _BaseRidgeCV (line 997, in that implementation). We haven't provided a cross-validation ... | 2 | 2016-06-16T04:54:04Z | [
"python",
"scikit-learn"
] |
Dylib built on CI can't be loaded | 37,752,901 | <p>I'm building a Rust binary (<code>liblonlat_bng.dylib</code>) on Travis CI, pulling it into a Cython extension (in the same dir as the Cython source .c/.pyx), and testing it, also on Travis CI (in a different repo and build). However, tests of the Python package are failing, and I'm not sure why:</p>
<pre><code>---... | 0 | 2016-06-10T16:18:33Z | 37,757,642 | <p>There are two ways to fix this <em>without</em> using <code>install_name_tool</code>.<br>
Assuming that your dylib is in the same directory as your Cython extension (In this case, <code>cutil.so</code>)</p>
<ul>
<li>Compile your Rust binary with <code>rpath</code> support, and correctly set the rpath in your <code>... | 0 | 2016-06-10T21:53:56Z | [
"python",
"rust",
"cython",
"travis-ci"
] |
ValueError: Invalid placeholder in string | 37,752,903 | <p>I tried to make my own template for mutate_model.py script (<a href="http://salilab.org/modeller/wiki/Mutate%20model" rel="nofollow">http://salilab.org/modeller/wiki/Mutate%20model</a>) by using python string template where I substituted values for these five variables Model,resType,resPos,pdb,chain to replce and wr... | 0 | 2016-06-10T16:18:41Z | 37,754,677 | <p>It's erroring because you have an invalid template identifier in your string</p>
<pre><code>env.libs.parameters.read(file='$(LIB)/par.lib') # Notice the $(LIB)
</code></pre>
<p>From the docs</p>
<blockquote>
<p>$$ is an escape; it is replaced with a single $.</p>
</blockquote>
<p></p>
<blockquote>
<p>Any ... | 1 | 2016-06-10T18:08:05Z | [
"python",
"string",
"python-2.7",
"templates",
"stringtemplate"
] |
Stacked Bar Chart: incorrect height of bars and labels | 37,752,926 | <p><strong>In short:</strong></p>
<ul>
<li>Height of bars does not match the numbers.</li>
<li>Labels seem to be placed on the wrong height. (should be right in the middle of each bar)</li>
<li>On the very bottom I also see the '0' labels which I really don't want to see in the graph.</li>
</ul>
<p><strong>Explained:... | 2 | 2016-06-10T16:19:42Z | 37,770,099 | <p>To make what you want you have to sum heights of all previous bars in current column (list <code>bot_heights</code>), like here:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
newYearWeek =[201613, 201614, 201615, 201616, 201617, 201618, 201619, 201620, 201621, 201622]
uniqueNames = ['Word1', ... | 1 | 2016-06-12T02:08:16Z | [
"python",
"matplotlib"
] |
POST to google apis compute engine gives 400 | 37,752,982 | <p>I am building a small flask app to handle automatic deployment for another project I am working on. </p>
<p>This involves setting a gcloud firewall rule using googleapis.</p>
<p>I have followed the below documentation.</p>
<p><a href="https://cloud.google.com/compute/docs/reference/latest/firewalls/insert" rel="n... | 1 | 2016-06-10T16:22:56Z | 37,754,806 | <p>Figured it out. I removed. </p>
<pre><code>data = json.dumps(payload)
</code></pre>
<p>and changed</p>
<pre><code> r = requests.post("https://www.googleapis.com/compute/v1/projects/apollo-rocket-chat/global/firewalls?key={MY_API_KEY}", data=data, headers=headers)
</code></pre>
<p>to</p>
<pre><code> r = re... | 0 | 2016-06-10T18:15:41Z | [
"python",
"google-api",
"google-compute-engine"
] |
Making y>x using a while loop and random.randint (python 3.4.3) | 37,753,018 | <p>In this code I want to create ten random question however if the operating sign(+,- or*) is - then i want the first number to be bigger than the second(so the answer will be positive.However this doesn't seem to be working as i'm getting "-" questions where y is smaller than x. The aim of this code is for y,r and z ... | -2 | 2016-06-10T16:24:47Z | 37,753,059 | <p>You're comparing <code>r</code> with <code>1</code>, but you've assigned it the operator already. Compare with <code>'-'</code> instead.</p>
| 0 | 2016-06-10T16:27:15Z | [
"python",
"random",
"while-loop",
"python-3.4"
] |
Making y>x using a while loop and random.randint (python 3.4.3) | 37,753,018 | <p>In this code I want to create ten random question however if the operating sign(+,- or*) is - then i want the first number to be bigger than the second(so the answer will be positive.However this doesn't seem to be working as i'm getting "-" questions where y is smaller than x. The aim of this code is for y,r and z ... | -2 | 2016-06-10T16:24:47Z | 37,753,184 | <p>try this:</p>
<pre><code>import random
name=input("What is you name: ")
x=0
d=0
op=['+','-','*']
def easy():
global x
global d
y=random.randint(1,12)
z=random.randint(1,12)
r=op[random.randint(0,2)]
if (r=='-'): # << change from if (r==1)
while (y<=z): # << what if z ... | -1 | 2016-06-10T16:34:54Z | [
"python",
"random",
"while-loop",
"python-3.4"
] |
Making y>x using a while loop and random.randint (python 3.4.3) | 37,753,018 | <p>In this code I want to create ten random question however if the operating sign(+,- or*) is - then i want the first number to be bigger than the second(so the answer will be positive.However this doesn't seem to be working as i'm getting "-" questions where y is smaller than x. The aim of this code is for y,r and z ... | -2 | 2016-06-10T16:24:47Z | 37,753,502 | <p>Instead of looping to find a pair of values, why not generate them with the desired property?</p>
<pre><code>import random as rnd
smaller, larger = sorted([rnd.randint(1,11), rnd.randint(1,12)])
if larger == smaller:
larger += 1
</code></pre>
<p>Since the first value is generated on the range (1,11), if the t... | 0 | 2016-06-10T16:54:22Z | [
"python",
"random",
"while-loop",
"python-3.4"
] |
Determine clockwise vertexes that make up a face for a cube | 37,753,117 | <p>the title may seem a bit confusing however here is the scenario. I am writing a simple exporter in blender and I have the following information, I am trying to export a cube, I have the faces and the edges that make up the faces, along with which vertex makes up the edge. I am trying to assign the vertices in a cloc... | 0 | 2016-06-10T16:30:56Z | 37,828,061 | <p>OK, I am not sure, but below is some python code that I think is what you're looking for. Given the edges, it tries to orient all the faces in a "consistent" way. Note that the orientation of a given face is such that if you placed the cube so that only that face is visible, then the vertices are listed in clockwise... | 0 | 2016-06-15T06:53:37Z | [
"python",
"geometry",
"blender",
"algebra"
] |
Unable to use Pillow (not a valid WIN32 error) | 37,753,121 | <p>I am having a problem with running <code>pillow</code> for python 3.4.2.</p>
<p>I tried installing Pillow using 3 different files:<br>
<code>Pillow-3.2.0.win-amd64-py3.4.exe,
Pillow-3.2.0-cp34-cp34m-win_amd64.whl,
Pillow-3.2.0-cp34-none-win_amd64.whl.</code> </p>
<p>Every time I try to import Image or tkimage ... | 0 | 2016-06-10T16:31:06Z | 38,139,040 | <p>Solved:
I finally figured it out! I had a 32 bit and a 64 bit version of python installed. I had pillow installed to my 32 bit directory, so when python ran from 32 bit was why I got the win32 error. And when I ran python 64bit it said module not found. Uninstalled both and reinstalled the 64 bit to the normal insta... | 0 | 2016-07-01T07:01:55Z | [
"python",
"python-imaging-library",
"pillow"
] |
Python for Android : apk stuck on loading screen | 37,753,230 | <p>I am trying to convert my python 3 code into an apk using Python-For-Android's tool. They have recently added python 3 support albeit it being experimental. </p>
<p>It may be of importance to note that my whole program is written in pure python and uses no kivy frameworks, it's graphical interface is all done in tk... | 1 | 2016-06-10T16:37:59Z | 37,753,466 | <p>This is not a supported use of python-for-android. In order for your app to function, you need to interact with one of the available bootstraps - sdl2, pygame or webview. Kivy knows how to interact with the sdl2 and pygame bootstraps, and the webview bootstrap just uses an Android Webview to display content from a l... | 2 | 2016-06-10T16:52:38Z | [
"android",
"python",
"kivy"
] |
How to create dictionary of dictionaries from a dataframe using python's pandas | 37,753,255 | <p>I have the following dataframe directly from SQL query:</p>
<pre><code>Question tagID Answer
Primary purpose 62 Other
Primary purpose 226 Learn how to use
Primary purpose 227 Technical Support
Primary purpose 292 Purchase
Language 246 English
... | 0 | 2016-06-10T16:39:36Z | 37,753,423 | <p>You could use:</p>
<pre><code>df.set_index('Question').groupby(level='Question').apply(lambda x: x.set_index('tagID').squeeze().to_dict()).to_dict()
</code></pre>
<p>to get:</p>
<pre><code>{'Language': {248: 'German', 246: 'English', 247: 'French'}, 'Primary purpose': {226: 'Learn how to use', 227: 'Technical Sup... | 3 | 2016-06-10T16:50:16Z | [
"python",
"pandas"
] |
Importing variables from mathcad to excel | 37,753,322 | <p>I have a mathcad program with thousands of variables. Is there a way I can use Python or Visual Basic to loop over all the varibles in my mathcad program and then assign them and there values to an excel spreadsheet?</p>
<p>A python method is preferred as I have never used VB.</p>
| 0 | 2016-06-10T16:43:36Z | 37,847,104 | <p>I have no idea what mathcad is, but in Excel, if you click on Data, you will see that you can import From Text file, and From Other Sources. Do any of those make sense? Try one and see how you get along. </p>
<p>Also, if you want to automate the process, turn on the Macro Recorder and then click through all the ... | 0 | 2016-06-15T22:49:59Z | [
"python",
"excel-vba",
"mathcad"
] |
How to handle password management via PyNaCl? | 37,753,380 | <p>I have the following scenario:</p>
<p>given a Python application on some client machine which enables several users. It encrypts and decrypts user passwords. What would be the currently most recommended approach? </p>
<p>Attempts of using PyNaCl lead to the insight that it is not a good approach due to the fact th... | 0 | 2016-06-10T16:47:31Z | 37,772,728 | <p>PyNaCl supports multiple types of crypto primitives, but a password hashing scheme is none of them.</p>
<p>Using encryption for password storage is an anti-pattern. Where is the key stored to decrypt the encrypted password? If the key is stored somewhere in code or in some file in the file system, then the whole th... | 0 | 2016-06-12T09:33:43Z | [
"python",
"encryption",
"passwords"
] |
Restart celery worker consumer connection to broker | 37,753,443 | <p>I've found an example of how to restart worker connection in celery docs (<a href="http://docs.openquake.org/celery-2.4.6/userguide/workers.html#writing-your-own-remote-control-commands" rel="nofollow">http://docs.openquake.org/celery-2.4.6/userguide/workers.html#writing-your-own-remote-control-commands</a>):</p>
<... | 0 | 2016-06-10T16:51:31Z | 37,819,710 | <p>The worker internals was rewritten to use "bootsteps" in 3.1 (see <a href="http://docs.celeryproject.org/en/latest/userguide/extending.html" rel="nofollow">http://docs.celeryproject.org/en/latest/userguide/extending.html</a>)</p>
<p>I think best way to reset the broker connection from a remote control command would... | 0 | 2016-06-14T18:38:05Z | [
"python",
"celery"
] |
Python 2.x True & False returning True in very specific case | 37,753,447 | <p>I've searched everywhere for an answer to this, sorry if it's a very basic question. I am filtering Numpy arrays using a boolean Numpy array that is created by comparing values at the same indices in 3 different arrays. My comparison is comprised of 2 separate boolean statements, say x[i]==y[i] & x[i]!=z[i], for... | 0 | 2016-06-10T16:51:55Z | 37,753,563 | <blockquote>
<p>What am I missing?</p>
</blockquote>
<p>You're missing parentheses:</p>
<pre><code>(x[8]==y[8]) & (x[8]!=z[8])
</code></pre>
<p>Also, you should be doing this as a vectorized operation over the whole arrays, rather than by looping over indices. Hopefully, you're doing that in your real code, an... | 2 | 2016-06-10T16:58:16Z | [
"python",
"arrays",
"numpy",
"boolean"
] |
Python 2.x True & False returning True in very specific case | 37,753,447 | <p>I've searched everywhere for an answer to this, sorry if it's a very basic question. I am filtering Numpy arrays using a boolean Numpy array that is created by comparing values at the same indices in 3 different arrays. My comparison is comprised of 2 separate boolean statements, say x[i]==y[i] & x[i]!=z[i], for... | 0 | 2016-06-10T16:51:55Z | 37,753,572 | <p>do (x[8]==y[8]) & (x[8]!=z[8])
or even better
x[8]==y[8] and x[8]!=z[8]</p>
| -1 | 2016-06-10T16:58:56Z | [
"python",
"arrays",
"numpy",
"boolean"
] |
Find all indices of a value in a dictionary python | 37,753,473 | <p>I have a dictionary created from variables in a netCDF file. I have also sorted all of these variables in the order of time. There are repeated values for some of the keys. I want to find all of the indices for a specific value in one key and retrieve the corresponding indices from another key:</p>
<p>For example... | 0 | 2016-06-10T16:52:56Z | 37,753,746 | <p><strong>To return values from one key based on index of another key in a dict</strong></p>
<pre><code>test_dict = {}
test_dict['number'] = [12,14,12,13]
test_dict['number2'] = [20,21,22,23]
print([j for i,j in zip(test_dict['number'],test_dict['number2']) if i==12])
</code></pre>
<p>returns <code>[20,22]</code></p... | 1 | 2016-06-10T17:09:15Z | [
"python",
"dictionary"
] |
Interpreting numpy array obtained from tif file | 37,753,578 | <p>I need to work with some greyscale tif files and I have been using PIL to import them as images and convert them into numpy arrays:</p>
<pre><code> np.array(Image.open(src))
</code></pre>
<p>I want to have a transparent understanding of exactly what the values of these array correspond to and in particular, it ... | 0 | 2016-06-10T16:59:14Z | 37,755,638 | <p>A <a href="https://en.wikipedia.org/wiki/Tagged_Image_File_Format" rel="nofollow">TIFF</a> is basically a computer file format for storing raster graphics images. It has a lot of <a href="https://reference.wolfram.com/language/ref/format/TIFF.html" rel="nofollow">specs</a> and quick search on the web will get you th... | 1 | 2016-06-10T19:13:14Z | [
"python",
"image",
"numpy",
"tiff"
] |
How to iterate through a list and update values with .strip() | 37,753,662 | <p>If I have a list of strings and want to eliminate leading and trailing whitespaces from it, how can I use .strip() effectively to accomplish this?</p>
<p>Here is my code (python 2.7):</p>
<pre><code>for item in myList:
item = item.strip()
print item
for item in myList:
print item
</code></pre>
<p>The... | 0 | 2016-06-10T17:04:46Z | 37,753,701 | <p>I'm guessing you tried:</p>
<pre><code>map(str.strip, myList)
</code></pre>
<p>That creates a new list and returns it, leaving the original list unchanged. If you want to interact with the new list, you need to assign it to something. You could overwrite the old value if you want.</p>
<pre><code>myList = map(str.... | 3 | 2016-06-10T17:06:46Z | [
"python",
"python-2.7"
] |
How to iterate through a list and update values with .strip() | 37,753,662 | <p>If I have a list of strings and want to eliminate leading and trailing whitespaces from it, how can I use .strip() effectively to accomplish this?</p>
<p>Here is my code (python 2.7):</p>
<pre><code>for item in myList:
item = item.strip()
print item
for item in myList:
print item
</code></pre>
<p>The... | 0 | 2016-06-10T17:04:46Z | 37,753,731 | <p>I'm answering my own question here in the hopes that it saves someone from the couple hours of searching and experimentation it took me.</p>
<p>As it turns out the solution is fairly simple:</p>
<pre><code>index = 0
for item in myList:
myList[index] = item.strip()
index += 1
for item in myList:
print ... | 1 | 2016-06-10T17:07:55Z | [
"python",
"python-2.7"
] |
How to take a word from a dictionary by its definition | 37,753,680 | <p>I am creating a code where I need to take a string of words, convert it into numbers where <code>hi bye hi hello</code> would turn into <code>0 1 0 2</code>. I have used dictionary's to do this and this is why I am having trouble on the next part. I then need to compress this into a text file, to then decompress an... | 0 | 2016-06-10T17:05:41Z | 37,754,044 | <p>Yes, you can just use regular dicts and lists to store the data. And use <code>json</code> or <code>pickle</code> to persist the data to disk.</p>
<pre><code>import pickle
s = 'hi hello hi bye'
words = s.split()
d = {}
for word in word:
if word not in d:
d[word] = len(d)
data = [d[word] for word in w... | 0 | 2016-06-10T17:28:44Z | [
"python",
"dictionary"
] |
How to take a word from a dictionary by its definition | 37,753,680 | <p>I am creating a code where I need to take a string of words, convert it into numbers where <code>hi bye hi hello</code> would turn into <code>0 1 0 2</code>. I have used dictionary's to do this and this is why I am having trouble on the next part. I then need to compress this into a text file, to then decompress an... | 0 | 2016-06-10T17:05:41Z | 37,754,336 | <p>Because I don't know exactly how you have your keymap created the best I could do is guess. Here I have created 2 functions than can be used to write a string to a txt file based on a keymap and read a txt file and return a string based on a keymap. I hope this works for you or at least gives you a solid understandi... | 0 | 2016-06-10T17:46:10Z | [
"python",
"dictionary"
] |
How to take a word from a dictionary by its definition | 37,753,680 | <p>I am creating a code where I need to take a string of words, convert it into numbers where <code>hi bye hi hello</code> would turn into <code>0 1 0 2</code>. I have used dictionary's to do this and this is why I am having trouble on the next part. I then need to compress this into a text file, to then decompress an... | 0 | 2016-06-10T17:05:41Z | 37,771,544 | <p>TheLazyScripter gave a nice workaround solution for the problem, but the runtime characteristics are not good because for each reconstructed word you have to loop through the whole dict. </p>
<p>I would say you chose the wrong dict design: To be efficient, lookup should be done in one step, so you should have the n... | 0 | 2016-06-12T06:52:48Z | [
"python",
"dictionary"
] |
Interactively testing code sections in Eclipse with PyDev (how-to and best practices) | 37,753,703 | <p><strong>Some background:</strong> I am transitioning from using R + RStudio for all of my data analytic tasks to trying to use Python (pandas, mostly) + Eclipse with PyDev. Because of RStudio, I am accustomed to a workflow that involves writing some code, and testing sections I'm not sure about by running it chunk b... | 1 | 2016-06-10T17:06:47Z | 37,795,512 | <p>After you do Ctrl+Alt+Enter, you should be able to:</p>
<ol>
<li><p>Make Ctrl+Alt+Enter to execute the whole file on the console so that you can use its functions.</p></li>
<li><p>Put the cursor on any line and press F2 so that it'll execute that line on the console and will go to the next (so, you may write a bloc... | 2 | 2016-06-13T17:12:50Z | [
"python",
"eclipse",
"rstudio",
"pydev"
] |
OpenCV: drawKeypoints() in Python vs. Julia | 37,753,719 | <p>I'm rewriting this OpenCV program in Julia:</p>
<pre><code>import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate STAR detector
orb = cv2.ORB()
# find the keypoints with ORB
kp = orb.detect(img,None)
# compute the descriptors with ORB
kp, des = orb.compute... | 0 | 2016-06-10T17:07:35Z | 37,847,388 | <p>An equivalent line in Julia that works would be:</p>
<pre><code>img2 = cv2.drawKeypoints(img, kp, 0, color=(0,255,0), flags=0)
</code></pre>
<p>The change is in pos3, where you should provide an argument for <code>outImage</code>, though the scalar value <code>0</code> will do.</p>
| 0 | 2016-06-15T23:17:52Z | [
"python",
"julia-lang"
] |
Regex repeating string | 37,753,785 | <p>I need a regex for the following text.
I already tried many stuff, but always it only match the last two groups or it match 'someText 1 & someText 2 & someText 3 &' as one group...</p>
<pre><code>someText 1 & someText 2 & someText 3
someText 1 & someText 2 & someText 3 & someText 4
<... | -2 | 2016-06-10T17:11:45Z | 37,753,966 | <p>This works for the provided example text and desired results:</p>
<pre><code>\S+\s\d
\S+ match any non-white space character [^\r\n\t\f ]
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\s match any white space character [\r\n\t\f ]
\d match a digit [0-9]
<... | 0 | 2016-06-10T17:22:52Z | [
"python",
"regex"
] |
Regex repeating string | 37,753,785 | <p>I need a regex for the following text.
I already tried many stuff, but always it only match the last two groups or it match 'someText 1 & someText 2 & someText 3 &' as one group...</p>
<pre><code>someText 1 & someText 2 & someText 3
someText 1 & someText 2 & someText 3 & someText 4
<... | -2 | 2016-06-10T17:11:45Z | 37,754,545 | <p>If I'm reading properly, you're trying to capture an arbitrary number of '&' separated items, per line, into capture groups.</p>
<p>With pure regex, this isn't possible. Because regex operates as a state machine, you cannot have an arbitrary number of capture groups. Any given expression has a fixed number of c... | 0 | 2016-06-10T17:59:48Z | [
"python",
"regex"
] |
Regex repeating string | 37,753,785 | <p>I need a regex for the following text.
I already tried many stuff, but always it only match the last two groups or it match 'someText 1 & someText 2 & someText 3 &' as one group...</p>
<pre><code>someText 1 & someText 2 & someText 3
someText 1 & someText 2 & someText 3 & someText 4
<... | -2 | 2016-06-10T17:11:45Z | 37,756,360 | <p>I think <a href="http://stackoverflow.com/a/37754545/1394393">James</a> is on to something, but he didn't quite get there.</p>
<p>You shouldn't try to do this with pure regex. Keep things simple. First, you should just split your string by <code>&</code>:</p>
<pre><code>>>> s = 'someText 1 & someT... | 0 | 2016-06-10T20:05:16Z | [
"python",
"regex"
] |
Regex repeating string | 37,753,785 | <p>I need a regex for the following text.
I already tried many stuff, but always it only match the last two groups or it match 'someText 1 & someText 2 & someText 3 &' as one group...</p>
<pre><code>someText 1 & someText 2 & someText 3
someText 1 & someText 2 & someText 3 & someText 4
<... | -2 | 2016-06-10T17:11:45Z | 37,756,696 | <p>Given that you're using Python, you need the <a href="https://docs.python.org/2/library/re.html" rel="nofollow"><code>re</code></a> module and the <code>re.findall</code> method.</p>
<p>For example, you might use:</p>
<pre><code>import re
import fileinput
p1 = re.compile(r'\s*(\S[^&]*)\s+(&|$)')
for line... | 0 | 2016-06-10T20:27:38Z | [
"python",
"regex"
] |
Login failed during python Insert job with BigQuery API | 37,753,830 | <p>I am trying load local file to bigquery by setting up a server-server auth.
I've done following steps</p>
<ol>
<li>Created service account</li>
<li>Create JSON key file for this account</li>
<li><p>Activated service acount with </p>
<p>gcloud auth activate-service-account command</p></li>
<li><p>Logged in with </p... | 0 | 2016-06-10T17:15:10Z | 37,840,998 | <p>The problem is that any call to
<a href="https://www.googleapis.com/bigquery/v2/projects/project_id/jobs/" rel="nofollow">https://www.googleapis.com/bigquery/v2/projects/project_id/jobs/</a>* will cause the same problem</p>
<pre><code>{
"error": {
"errors": [
{
"domain": "global",
"reason": "requi... | 2 | 2016-06-15T16:32:30Z | [
"python",
"google-bigquery",
"google-api-python-client"
] |
Not able to understand where white spaces are or indentation is missing in Python code : Line 6: SyntaxError: bad input (' ') | 37,753,863 | <pre><code>def name_to_number(name):
if name=='rock'
number=0
elif name=='Spock'
number=1
elif name=='paper'
number=2
elif name=='lizard'
number=3
elif name=='scissors'
number=4
else
print'Not a valid input'
return number
</code></pre>
| 0 | 2016-06-10T17:16:36Z | 37,753,919 | <p>Try this:</p>
<pre><code>def name_to_number(name):
if name=='rock':
number=0
elif name=='Spock':
number=1
elif name=='paper':
number=2
elif name=='lizard':
number=3
elif name=='scissors':
number=4
else:
print 'Not a valid input'
return ... | 0 | 2016-06-10T17:20:02Z | [
"python"
] |
Not able to understand where white spaces are or indentation is missing in Python code : Line 6: SyntaxError: bad input (' ') | 37,753,863 | <pre><code>def name_to_number(name):
if name=='rock'
number=0
elif name=='Spock'
number=1
elif name=='paper'
number=2
elif name=='lizard'
number=3
elif name=='scissors'
number=4
else
print'Not a valid input'
return number
</code></pre>
| 0 | 2016-06-10T17:16:36Z | 37,754,355 | <p>You are missing the colon at the end of each <code>if</code> and <code>elif</code> statement.</p>
<p>This is invalid:</p>
<pre><code>if name == 'rock'
number = 0
</code></pre>
<p>Python uses the colon as an indication that the next line should be an indented block. If you miss this colon then python thinks th... | 0 | 2016-06-10T17:47:41Z | [
"python"
] |
Emacs: How do I detect which Python mode is running and select default Python interpreter? | 37,753,883 | <blockquote>
<p>Emacs: How do I detect which Python mode is running and select default Python interpreter?</p>
</blockquote>
<p>First of all, how do I see which Python mode is running?</p>
<p>I've read that multiple exist, like python-mode.el etc.</p>
<p>Secondly, pressing <code>C-c C-z</code> results in a <code>R... | 0 | 2016-06-10T17:17:53Z | 37,754,572 | <p>First off lets start off by finding out which python mode you're using. Generally unless you downloaded something and actively decided to use python-mode.el you won't be using it, instead you'll be using the great, built-in, python.el. If you didn't know this you could press <kbd> C-h m </kbd> to bring up the help m... | 1 | 2016-06-10T18:01:37Z | [
"python",
"python-2.7",
"emacs"
] |
Emacs: How do I detect which Python mode is running and select default Python interpreter? | 37,753,883 | <blockquote>
<p>Emacs: How do I detect which Python mode is running and select default Python interpreter?</p>
</blockquote>
<p>First of all, how do I see which Python mode is running?</p>
<p>I've read that multiple exist, like python-mode.el etc.</p>
<p>Secondly, pressing <code>C-c C-z</code> results in a <code>R... | 0 | 2016-06-10T17:17:53Z | 37,780,622 | <p>In your init file you can place the following:</p>
<pre><code>(setq python-shell-interpreter "/usr/bin/python3")
</code></pre>
<p>so that Emacs will use Python 3 instead of Python 2. Here's <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html" rel="nofollow">info on init files</a> in c... | 0 | 2016-06-13T01:08:35Z | [
"python",
"python-2.7",
"emacs"
] |
How to use SyntaxNet output to operate an executive command ,for example save a file in a folder, on Linux system | 37,753,980 | <p>having downloaded and trained <a href="https://github.com/tensorflow/models/tree/master/syntaxnet" rel="nofollow">SyntaxNet</a>, I am trying to write a program that can open new/existed files, for example AutoCAD files, and save the files in an specific directory by analyzing the text: <strong>open LibreOffice file... | 2 | 2016-06-10T17:24:03Z | 38,444,785 | <p>I am a beginner in Computer Science World and SyntaxNet. I wrote a simple SyntaxNet-Python algorithm which used SyntaxNet to analyze a text command a user inserts,"open the file book which I have written with laboratory writer with LibreOffice writer", and then analyzes SyntaxNet output with a python algorithm in o... | 8 | 2016-07-18T19:43:09Z | [
"python",
"xml",
"terminal",
"semantics",
"syntaxnet"
] |
PyZDDE - get ray trace information in global coordinates | 37,753,982 | <p>I have successfully traced a ray in Zemax using pyzdde. (using zGetTrace) However I need the information in global coordinates as opposed to local. is there a way to get that? Thanks.</p>
<p>-T</p>
<p>edit:</p>
<p>Here is the test code. The ray object returns the ray information in correct local coordinates. I ne... | 0 | 2016-06-10T17:24:12Z | 37,760,286 | <p>I think there are several ways of handling this (depending on the type of lens design). </p>
<p>For example, you could use the operand 'GLCZ' (Global vertex z-coordinate of the surface defined by Surf) in the following way to get the z-coordinate of the image surface (or the surface of interest) in the global coord... | 0 | 2016-06-11T05:29:17Z | [
"python"
] |
Trying to split a txt file into multiple variables | 37,754,020 | <p>So I'm making a program where it reads a text file and I need to separate all the info into their own variables. It looks like this: </p>
<pre><code>>1EK9:A.41,52; B.61,74; C.247,257; D.279,289
ENLMQVYQQARLSNPELRKSAADRDAAFEKINEARSPLLPQLGLGAD
YTYSNGYRDANGINSNATSASLQLTQSIFDMSKWRALTLQEKAAGIQ
DVTYQTDQQTLILNTATAYFNVL... | 0 | 2016-06-10T17:26:36Z | 37,754,263 | <p>I am not sure I completely understand the goal (and I think this post is more suitable for a comment, but I do not have enough privileges) but I think that the key to you solution is using <code>.split()</code>. You can then join the elements of the resulting list just by using + similar to this:</p>
<pre><code>>... | 0 | 2016-06-10T17:42:32Z | [
"python",
"bioinformatics"
] |
Trying to split a txt file into multiple variables | 37,754,020 | <p>So I'm making a program where it reads a text file and I need to separate all the info into their own variables. It looks like this: </p>
<pre><code>>1EK9:A.41,52; B.61,74; C.247,257; D.279,289
ENLMQVYQQARLSNPELRKSAADRDAAFEKINEARSPLLPQLGLGAD
YTYSNGYRDANGINSNATSASLQLTQSIFDMSKWRALTLQEKAAGIQ
DVTYQTDQQTLILNTATAYFNVL... | 0 | 2016-06-10T17:26:36Z | 37,754,517 | <p>I suggest you use the <a href="http://www.tutorialspoint.com/python/string_split.htm" rel="nofollow">split()</a> method.</p>
<p>split() allows you to specify the separator of your choice. Provided the sequence title (here 1EK9) is always separated from the rest of the sequence by a colon, you could first pass ":" a... | 0 | 2016-06-10T17:57:58Z | [
"python",
"bioinformatics"
] |
Trying to split a txt file into multiple variables | 37,754,020 | <p>So I'm making a program where it reads a text file and I need to separate all the info into their own variables. It looks like this: </p>
<pre><code>>1EK9:A.41,52; B.61,74; C.247,257; D.279,289
ENLMQVYQQARLSNPELRKSAADRDAAFEKINEARSPLLPQLGLGAD
YTYSNGYRDANGINSNATSASLQLTQSIFDMSKWRALTLQEKAAGIQ
DVTYQTDQQTLILNTATAYFNVL... | 0 | 2016-06-10T17:26:36Z | 37,754,661 | <p>I think what you are trying to do is extract certain parts of the sequence based on their identifiers given to you on the first line (the line starting with <code>></code>).</p>
<p>This line contains your title, then a sequence name and the data range you need to extract.</p>
<p>Try this:</p>
<pre><code>sequen... | 0 | 2016-06-10T18:06:47Z | [
"python",
"bioinformatics"
] |
Trying to split a txt file into multiple variables | 37,754,020 | <p>So I'm making a program where it reads a text file and I need to separate all the info into their own variables. It looks like this: </p>
<pre><code>>1EK9:A.41,52; B.61,74; C.247,257; D.279,289
ENLMQVYQQARLSNPELRKSAADRDAAFEKINEARSPLLPQLGLGAD
YTYSNGYRDANGINSNATSASLQLTQSIFDMSKWRALTLQEKAAGIQ
DVTYQTDQQTLILNTATAYFNVL... | 0 | 2016-06-10T17:26:36Z | 37,755,859 | <p>As the other answer may be very good to tackle the assumed problem in it's entirety - but the OP has requested for pointers or an example of the tpyical split-unsplit transform which is often so successful I hereby provide some ideas and working code to show this (based on the example of the question).</p>
<p>So le... | 0 | 2016-06-10T19:30:19Z | [
"python",
"bioinformatics"
] |
Trying to split a txt file into multiple variables | 37,754,020 | <p>So I'm making a program where it reads a text file and I need to separate all the info into their own variables. It looks like this: </p>
<pre><code>>1EK9:A.41,52; B.61,74; C.247,257; D.279,289
ENLMQVYQQARLSNPELRKSAADRDAAFEKINEARSPLLPQLGLGAD
YTYSNGYRDANGINSNATSASLQLTQSIFDMSKWRALTLQEKAAGIQ
DVTYQTDQQTLILNTATAYFNVL... | 0 | 2016-06-10T17:26:36Z | 37,777,313 | <p>So I'm assuming you are trying to process a Fasta like file and so the way I would do it is to first get the header and separate the pieces with Regex. Following that you can store the A:42.52 B... in a list for easy access. The code is as follows.</p>
<pre><code>import re
def processHeader(line):
positions =... | 0 | 2016-06-12T17:48:31Z | [
"python",
"bioinformatics"
] |
Values not appearing in CSV download | 37,754,033 | <p>I am using following python code to read from the text files in a folder and print in a CSV:</p>
<pre><code>file = glob.glob(path)
for fle in file:
# open the file and then call .read() to get the text
with open(fle) as f:
lines=f.readlines()
Date= (lines[6])
Title=(lines[8])
... | 0 | 2016-06-10T17:28:10Z | 37,754,793 | <p>I did manage to resolve the issue here is the modified code :</p>
<pre><code>for fle in file:
# open the file and then call .read() to get the text
data=tone_analyzer.tone(text='text')
# iterate through tone analysis data
tonename=[]; tonescore=[]
for cat in data['document_tone']['tone_catego... | 0 | 2016-06-10T18:14:56Z | [
"python",
"csv"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.