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
Plotting 3D surface in python
39,414,278
<p>Although there are several sources on how to plot 3D surfaces with XYZ format. I have a CSV file from a scanning laser that provides no coordinate information on X and Y, just Z coordinates of a rectangular grid.</p> <p>The file is 800 x 1600 with just z coordinates. Excel can plot it very easily with surface plot,...
0
2016-09-09T14:46:36Z
39,415,557
<p>You just need to create arrays of the <code>X</code> and <code>Y</code> coordinates. We can do this with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html" rel="nofollow"><code>numpy.meshgrid</code></a>. In the example below, I set the cell size to 1., but you can easily scale that by ...
0
2016-09-09T16:02:01Z
[ "python", "matplotlib", "plot", "surface" ]
Adding javascript to a Django redirect (HttpResponse)
39,414,365
<p>I am using a redirect in Django <code>from django.shortcuts import redirect</code></p> <p>What I want, is for the user to be displayed a Javascript alert message before being redirected.</p> <p>Here is what I've got so far:</p> <pre><code>response = redirect("someUrl") response.write('&lt;script&gt;alert(\'You mu...
0
2016-09-09T14:51:29Z
39,414,471
<p>You are getting confused between frontend and backend. When this view is requested by the user, the server (via Django's <a href="https://docs.djangoproject.com/en/1.10/_modules/django/http/response/#HttpResponseRedirect" rel="nofollow"><code>HTTPResponseRedirect</code></a>) is sending a <a href="https://en.wikipedi...
1
2016-09-09T14:56:53Z
[ "python", "django", "redirect", "httpresponse" ]
Adding javascript to a Django redirect (HttpResponse)
39,414,365
<p>I am using a redirect in Django <code>from django.shortcuts import redirect</code></p> <p>What I want, is for the user to be displayed a Javascript alert message before being redirected.</p> <p>Here is what I've got so far:</p> <pre><code>response = redirect("someUrl") response.write('&lt;script&gt;alert(\'You mu...
0
2016-09-09T14:51:29Z
39,415,401
<p>You can use <code>js appproach</code> <code>window.location</code></p> <pre><code>url = 'someUrl' resp_body = '&lt;script&gt;alert("You must remove an item before adding another");\ window.location="%s"&lt;/script&gt;' % url return HttpResponse(resp_body) </code></pre>
0
2016-09-09T15:51:16Z
[ "python", "django", "redirect", "httpresponse" ]
Is there a way to prevent pandas to_json from adding \?
39,414,370
<p>I am trying to send a pandas dataframe to_json and I am having some issues with the date. I am getting an addtional \ so that my records look like <code>Updated:09\/06\/2016 03:09:44</code>. Is it possible to not have this additional \ added? I am assuming that it is an escape character of some sort but I haven't...
2
2016-09-09T14:51:48Z
39,415,510
<p>The JSON ouput you obtained is indeed correct and is the right behavior.</p> <p>Allowing <code>\/</code> helps when embedding JSON in a <code>&lt;script&gt;</code> tag, which doesn't allow <code>&lt;/</code> inside strings. Hence, in JSON <code>/</code> and <code>\/</code> are equivalent.</p> <p>One workaround wou...
3
2016-09-09T15:58:19Z
[ "python", "json", "pandas", "to-json" ]
python patch with side_effect on Object's method is not called with self
39,414,429
<p>I encounter a surprising behaviour of the side_effect parameter in patch.object where the function replacing the original does not receive <code>self</code></p> <pre class="lang-py prettyprint-override"><code>class Animal(): def __init__(self): self.noise = 'Woof' def make_noise(self): retu...
0
2016-09-09T14:54:45Z
39,414,488
<p><code>self</code> is only supplied for <em>bound methods</em> (because functions are <a href="https://docs.python.org/3/howto/descriptor.html" rel="nofollow">descriptors</a>). A <code>Mock</code> object is not such a method, and the <code>side_effect</code> function is not bound, so <code>self</code> is indeed not g...
0
2016-09-09T14:57:53Z
[ "python", "unit-testing", "mocking" ]
django class based view multiple form validatiton
39,414,456
<p>I'm currently trying to have <b>two</b> forms on a single page. I'm using Class Based Views.</p> <pre><code>class TaskDetailView(FormMixin, generic.DetailView): model = Task template_name="tasks/detail.html" form_class = NoteForm form_class2 = DurationForm def get_context_data(self, **kwargs): ...
0
2016-09-09T14:56:03Z
39,414,527
<p>Your <code>post</code> method doesn't do anything with the second form. You'd need to instantiate it and check its validity as you do with the first one.</p>
0
2016-09-09T14:59:58Z
[ "python", "django", "forms" ]
django class based view multiple form validatiton
39,414,456
<p>I'm currently trying to have <b>two</b> forms on a single page. I'm using Class Based Views.</p> <pre><code>class TaskDetailView(FormMixin, generic.DetailView): model = Task template_name="tasks/detail.html" form_class = NoteForm form_class2 = DurationForm def get_context_data(self, **kwargs): ...
0
2016-09-09T14:56:03Z
39,415,039
<p>A quite simple way of having multiple forms on one page would be to define some hidden parameter to differentiate between your POST actions, like:</p> <pre><code>&lt;input name="formType" type="hidden" value="note"&gt; </code></pre> <p>In your CBV post method, you could:</p> <pre><code>form_type = request.POST.ge...
0
2016-09-09T15:28:56Z
[ "python", "django", "forms" ]
how to convert type of variables in python?
39,414,492
<p>Suppose</p> <pre><code> type(a) = &lt;type 'numpy.ndarray'&gt; </code></pre> <p>now I have another variable <code>b</code> (maybe a <code>&lt;type 'list'&gt;</code>), I want to convert it into the same type of <code>a</code>. How to do this? For example, </p> <pre><code> &gt;&gt;&gt; type(a) &lt;type 'n...
-1
2016-09-09T14:57:57Z
39,414,570
<p>To convert a <code>list</code> into a python array, use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html" rel="nofollow"><code>numpy.asarray</code></a>. For example:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; a = [1, 2, 3, 4] &gt;&gt;&gt; a = np.asarray(a) &gt;&gt;&gt...
1
2016-09-09T15:03:29Z
[ "python" ]
how to convert type of variables in python?
39,414,492
<p>Suppose</p> <pre><code> type(a) = &lt;type 'numpy.ndarray'&gt; </code></pre> <p>now I have another variable <code>b</code> (maybe a <code>&lt;type 'list'&gt;</code>), I want to convert it into the same type of <code>a</code>. How to do this? For example, </p> <pre><code> &gt;&gt;&gt; type(a) &lt;type 'n...
-1
2016-09-09T14:57:57Z
39,414,717
<p>Presumably you don't <em>just</em> want to convert the type; you also want to preserve the existing value. (Otherwise you could just assign <code>b</code> to an empty object of the new type and be done with it.)</p> <p>Very generally, you would call the new type's constructor, passing in the old value. For exampl...
0
2016-09-09T15:11:45Z
[ "python" ]
How to write/print the lines breaks of a attribute of a json on Pyhon
39,414,569
<p>I have a little problema here.</p> <p>I have the follow situation:</p> <ul> <li>I have the following json file</li> </ul> <blockquote> <p>{ <br/> &nbsp;&nbsp;&nbsp;"name":"whatever",<br/> &nbsp;&nbsp;&nbsp;"lyric":"here comes the music <br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;another line <br/> &nbsp;...
-1
2016-09-09T15:03:17Z
39,453,606
<p>I have got the answer, basicaly what I did was a replace over a json.dumps:</p> <pre><code>with open(file, "r") as data_file: json_data=data_file.read() data_file.close() json_data["name"]="song's real name" with open(outputfile) jsonFile.write(json.dumps(data,indent=4, sort_keys=True, separators=(',', ': ...
0
2016-09-12T15:14:56Z
[ "python", "json" ]
Python Error's when I try to optimize those lines of code
39,414,574
<p>I use python 2.7, I want to reduce and optimize this code lines but I have a problem, could anybody help me please? </p> <p>I have this list <code>B = [[0, Act1, XX1, u'P-Um'],.....[0, Act100, ZZ30, u'D- MOM']]</code> </p> <ol> <li>I want to take only the 4th value from B </li> <li>Take just the part after hyphen ...
-3
2016-09-09T15:03:40Z
39,414,753
<p>You can use a list comprehension:</p> <pre><code> B=[[B_element[0],B_element[1],B_element[2],B_element[3].split('-',1)[1].lstrip()] for B_element in B] </code></pre>
0
2016-09-09T15:14:02Z
[ "python" ]
Python Error's when I try to optimize those lines of code
39,414,574
<p>I use python 2.7, I want to reduce and optimize this code lines but I have a problem, could anybody help me please? </p> <p>I have this list <code>B = [[0, Act1, XX1, u'P-Um'],.....[0, Act100, ZZ30, u'D- MOM']]</code> </p> <ol> <li>I want to take only the 4th value from B </li> <li>Take just the part after hyphen ...
-3
2016-09-09T15:03:40Z
39,414,790
<p>I'm not seeing the many ways you've tried, but your code does have a handful of missteps. Even after correcting the indentation errors, your first variant iterates over an index which you don't need four times, and strips every entry twice (only using the result the second time). The second version fails firstly bec...
0
2016-09-09T15:16:04Z
[ "python" ]
Python Error's when I try to optimize those lines of code
39,414,574
<p>I use python 2.7, I want to reduce and optimize this code lines but I have a problem, could anybody help me please? </p> <p>I have this list <code>B = [[0, Act1, XX1, u'P-Um'],.....[0, Act100, ZZ30, u'D- MOM']]</code> </p> <ol> <li>I want to take only the 4th value from B </li> <li>Take just the part after hyphen ...
-3
2016-09-09T15:03:40Z
39,414,791
<p>You don't have to index the items of B to iterate over them. This may help.</p> <pre><code>&gt;&gt;&gt; Act1 = XX1 = Act100 = ZZ30 = None # simply to avoid NameError exceptions &gt;&gt;&gt; B = [[0, Act1, XX1, u'P-Um'],[0, Act100, ZZ30, u'D- MOM']] &gt;&gt;&gt; result = [b[3].split('-')[1].strip() for b in B] &gt;&...
0
2016-09-09T15:16:07Z
[ "python" ]
How using select Query in Python?
39,414,642
<p>How can i use a <strong>SELECT</strong> Query in Python ?</p> <p><em>I just need a very sample example !</em></p> <p>Example in PHP :</p> <pre><code>$query = $db_connection -&gt; prepare ("SELECT * FROM table WHERE name = :name"); $query -&gt; execute (array (":name" =&gt; $name)); $rows = $query -&gt; ...
-2
2016-09-09T15:07:21Z
39,415,244
<p>The Answer :</p> <pre><code>query = ("""SELECT * FROM table WHERE name = '%s'""" % (name)) cursor.execute (query) results = cursor.fetchall() for row in results: id = row[0] print (id) </code></pre>
0
2016-09-09T15:41:12Z
[ "python", "select" ]
GAE Flask global variable persistent across browsers
39,414,664
<p>Here's my Flask setup:</p> <p><code>main.py</code></p> <pre><code>from flask import Flask from app.views import main_bp app = Flask(__name__) app.register_blueprint(main_bp, url_prefix='') </code></pre> <p><code>app.config.py</code> (Shortened with "..." for this example)</p> <pre><code>CONFIG = { 'SITE_NAM...
-1
2016-09-09T15:08:44Z
39,414,953
<p>As davidism pointed out, I should not be storing variables that change per session as a global. I will instead decide on these variables after loading pertinent session variables like UID and Session ID.</p> <p>Thanks.</p> <p>Update: Athough, I find it interesting that Flask documentation would advocate setting gl...
0
2016-09-09T15:24:09Z
[ "python", "google-app-engine", "flask" ]
Error when trying to redefine the division operator with __div__
39,414,772
<p>Why does numpy throw an exception for the following code? <code>foo/3</code> works fine.</p> <pre><code>import numpy as np class item(object): def __init__(self, val = 0.0): self._val = val @property def value(self): return self._val def __add__(self, other): return item(sel...
3
2016-09-09T15:15:11Z
39,415,190
<p>I need to define <code>__truediv__</code>. The documentation says: </p> <blockquote> <p>object.<code>__div__</code>(self, other) </p> <p>object.<code>__truediv__</code>(self, other) </p> <p>The division operator (/) is implemented by these methods. The <code>__truediv__()</code> method is used when <c...
3
2016-09-09T15:38:18Z
[ "python", "python-2.7", "numpy" ]
Django Rest Create with a Writable Nested Serializer
39,415,005
<p>I'm trying to perform a create in Django Rest Framework using a writable nested serializer.</p> <p>With the code bellow I can create a ScriptQuestion but I can't add a RecordedInterview into it. Django says OrderedDict is None.</p> <p>What am I doing wrong?</p> <p>Thanks in advance</p> <pre><code>#models.py cla...
0
2016-09-09T15:26:27Z
39,415,462
<p>I cannot add a comment because of low reputation. SO adding as an answer. I think you should use 'serializers.ModelSerializer' instead of 'serializers.HyperLinkedModelSerializer'</p>
1
2016-09-09T15:55:14Z
[ "python", "django", "nested", "django-rest-framework" ]
Django Rest Create with a Writable Nested Serializer
39,415,005
<p>I'm trying to perform a create in Django Rest Framework using a writable nested serializer.</p> <p>With the code bellow I can create a ScriptQuestion but I can't add a RecordedInterview into it. Django says OrderedDict is None.</p> <p>What am I doing wrong?</p> <p>Thanks in advance</p> <pre><code>#models.py cla...
0
2016-09-09T15:26:27Z
39,419,600
<p>Oh, I could make it.</p> <p>For someone in the future, just add "id = serializers.CharField()" in the Serializer</p> <pre><code>class InterviewTitleSerializer(serializers.ModelSerializer): id = serializers.CharField() class Meta: model = RecordedInterview fields = ('id', 'title') e...
0
2016-09-09T20:58:19Z
[ "python", "django", "nested", "django-rest-framework" ]
How can I prevent a logged in user from accessing a 'Log In' or 'Sign Up' page in Django version 1.9?
39,415,019
<p>I'm pretty new to Python.</p> <p>My problem is that I want to restrict users who are already logged in from being able to visit the log in and sign up pages.</p> <p>Essentially, what I'm looking for is something like the @login_required decorator, that will allow access to these pages for users who are <strong>not...
2
2016-09-09T15:27:59Z
39,415,109
<p>Since you are using a class-based view, you can use the <a href="https://docs.djangoproject.com/en/1.10/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin">UserPassesTestMixin</a> and in the check method test that the user is anonymous:</p> <pre><code>class signup_view(UserPassesTestMixin, View): ...
5
2016-09-09T15:32:54Z
[ "python", "django" ]
How can I prevent a logged in user from accessing a 'Log In' or 'Sign Up' page in Django version 1.9?
39,415,019
<p>I'm pretty new to Python.</p> <p>My problem is that I want to restrict users who are already logged in from being able to visit the log in and sign up pages.</p> <p>Essentially, what I'm looking for is something like the @login_required decorator, that will allow access to these pages for users who are <strong>not...
2
2016-09-09T15:27:59Z
39,416,220
<p>i guess you can add a middleware something like this : your_app/middlewares/user_restriction_middleware.py</p> <p>and that files be like:</p> <pre><code>class UserRestrictionMiddleware: def process_request(self, request): if request.user.is_authenticated(): request_path = request.path_i...
0
2016-09-09T16:43:06Z
[ "python", "django" ]
Python - Iterating over Arguments passed to a Function
39,415,030
<p>Suppose I have the following example:</p> <pre><code>class foo: ... def bar(self, w, x, y, z, ...): self.w = w self.x = x self.y = y self.z = z ... </code></pre> <p>I wish to reduce the n-number of attribute assignment lines in <code>bar()</code> to one assignment line set using...
3
2016-09-09T15:28:32Z
39,415,454
<p>The <a href="https://docs.python.org/3/reference/datamodel.html#object.__setattr__" rel="nofollow"><code>__setattr__</code></a> attribute only assigns one attribute at a time, if you want to assign multiple attribute, you can use <code>**kwargs</code> in your function header and for limiting the number of arguments ...
-1
2016-09-09T15:54:44Z
[ "python", "arguments", "variable-assignment", "setattr" ]
Python - Iterating over Arguments passed to a Function
39,415,030
<p>Suppose I have the following example:</p> <pre><code>class foo: ... def bar(self, w, x, y, z, ...): self.w = w self.x = x self.y = y self.z = z ... </code></pre> <p>I wish to reduce the n-number of attribute assignment lines in <code>bar()</code> to one assignment line set using...
3
2016-09-09T15:28:32Z
39,415,544
<p>Use <code>locals()</code> and you can get all the arguments (and any other local variables):</p> <pre><code>class foo: def bar(self, w, x, y, z): argdict = {arg: locals()[arg] for arg in ('w', 'x', 'y', 'z')} for key, value in argdict.iteritems(): setattr(self, key, value) .....
0
2016-09-09T16:00:27Z
[ "python", "arguments", "variable-assignment", "setattr" ]
how to get the attribute value from tags html with python 3.5.2
39,415,106
<p>hi i have a problem with python 3.5.2 i don't know where is the problem when i want to get the value of atribute a get all tags (atribute + value) but i want just the value of title ?? this is my code</p> <pre><code>from bs4 import BeautifulSoup as bs import requests url = "http://bestofgeeks.com/en/" html = requ...
-2
2016-09-09T15:32:43Z
39,415,183
<p>If you just want the text from the "a" tags, since all your web links are stored in <code>tagss</code>, just iterate and print like shown below: </p> <pre><code>for t in tagss: print t.text.strip() </code></pre>
0
2016-09-09T15:37:53Z
[ "python", "html", "beautifulsoup" ]
how to get the attribute value from tags html with python 3.5.2
39,415,106
<p>hi i have a problem with python 3.5.2 i don't know where is the problem when i want to get the value of atribute a get all tags (atribute + value) but i want just the value of title ?? this is my code</p> <pre><code>from bs4 import BeautifulSoup as bs import requests url = "http://bestofgeeks.com/en/" html = requ...
-2
2016-09-09T15:32:43Z
39,415,230
<p>If you meant you want the contents of the <code>titre</code> attribute:</p> <pre><code>tagss = [tag.get('titre') for tag in soup.findAll('a',{'class':'titre_post'})] </code></pre>
0
2016-09-09T15:40:33Z
[ "python", "html", "beautifulsoup" ]
Selecting all Columns based on Row value in a Dataframe Pandas
39,415,232
<blockquote> <p>I have a similar df1 with thousand columns and thousands rows. I would like to do a random sampling based on a condition in cells in row 1 (date0) Basically i would like to filter the columns and return them and the Datetime index based on the condition if the cell on date0 row is equal to V1 ...
0
2016-09-09T15:40:38Z
39,416,950
<p>You want to include <code>date0</code> as part of the column index.</p> <pre><code>df1 = df.T.set_index('date0', append=True).T df1 </code></pre> <p><a href="http://i.stack.imgur.com/WFJx3.png" rel="nofollow"><img src="http://i.stack.imgur.com/WFJx3.png" alt="enter image description here"></a></p> <p>Then you can...
2
2016-09-09T17:35:41Z
[ "python", "pandas", "random", "dataframe" ]
Download and install scapy for windows for python 3.5?
39,415,278
<p>I installed python 3.5 for my windows 8.1 computer. I need to install scapy for this version (I deleted all the files of the last one). How do i download and install it? can't find anything that help me to do that no matter how i searched.</p>
0
2016-09-09T15:43:15Z
39,415,327
<p><s> Use pip from the command line:</s></p> <p><s> pip install scrapy</s></p> <p>Apologies, realised that according to the docs scrapy is not supported on Windows with Python 3.x due to missing dependency (Twisted)</p> <p>Source: <a href="http://doc.scrapy.org/en/latest/intro/install.html" rel="nofollow">http:/...
1
2016-09-09T15:46:40Z
[ "python", "download", "install", "python-3.5", "scapy" ]
Python pandas: change one column conditional on another
39,415,286
<p>How can I reverse the sign in the quantity column whenever the side column has a sell? All other values should not be changed. The following is simply not working, it has no effect.</p> <pre><code>df[df['side'] == 'Sell']['quantity'] = df[df['side'] == 'Sell']['quantity'] * -1 </code></pre>
3
2016-09-09T15:43:37Z
39,415,469
<p>Refer to the <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#different-choices-for-indexing" rel="nofollow">Pandas indexing documentation</a>, and never use chain indexing per your example when setting values.</p> <pre><code>df.loc[df.side == 'Sell', 'quantity'] *= -1 </code></pre>
3
2016-09-09T15:55:50Z
[ "python", "pandas" ]
calculate catalan numbers up to a billion
39,415,300
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p> <pre><code> from numpy import division C=1 n=0 while C&lt;=10000000000: print (C) C=(4*n+2)/(n+2)*C ...
0
2016-09-09T15:44:41Z
39,415,416
<p>Try this:</p> <pre><code>from scipy.special import factorial C = 1 n = 0 while C &lt;= 10000000000: print(C) C = factorial(2*n, exact=True)/(factorial((n+1), exact=True)*factorial(n, exact=True)) n = n + 1 </code></pre> <p>It works for me :)</p>
0
2016-09-09T15:52:58Z
[ "python" ]
calculate catalan numbers up to a billion
39,415,300
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p> <pre><code> from numpy import division C=1 n=0 while C&lt;=10000000000: print (C) C=(4*n+2)/(n+2)*C ...
0
2016-09-09T15:44:41Z
39,415,434
<h3>The problem</h3> <p>Your mathematical definition of Catalan numbers is incorrect when translated into code.</p> <p>This is because of operator precedence in programming languages such as Python.</p> <p>Multiplication and division both have the same precedence, so they are computed left to right. What happens is ...
0
2016-09-09T15:54:06Z
[ "python" ]
calculate catalan numbers up to a billion
39,415,300
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p> <pre><code> from numpy import division C=1 n=0 while C&lt;=10000000000: print (C) C=(4*n+2)/(n+2)*C ...
0
2016-09-09T15:44:41Z
39,415,487
<p>This is solved using recursion:</p> <pre><code>def catalan(n): if n &lt;=1 : return 1 res = 0 for i in range(n): res += catalan(i) * catalan(n-i-1) return res for i in range(10000000000): print (catalan(i)) </code></pre> <p>you can read more about Catalan numbers <a href="htt...
0
2016-09-09T15:56:56Z
[ "python" ]
calculate catalan numbers up to a billion
39,415,300
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p> <pre><code> from numpy import division C=1 n=0 while C&lt;=10000000000: print (C) C=(4*n+2)/(n+2)*C ...
0
2016-09-09T15:44:41Z
39,415,490
<pre><code> C=(4*n+2)/(n+2)*C </code></pre> <p>This applies the calculation in the wrong order. Because you are using integer arithmetic, <code>(4*n+2)/(n+2)</code> loses information if you have not already factored in <code>C</code>. The correct calculation is:</p> <pre><code> C=C*(4*n+2)/(n+2) </cod...
1
2016-09-09T15:57:05Z
[ "python" ]
calculate catalan numbers up to a billion
39,415,300
<p>I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended.</p> <pre><code> from numpy import division C=1 n=0 while C&lt;=10000000000: print (C) C=(4*n+2)/(n+2)*C ...
0
2016-09-09T15:44:41Z
39,415,497
<p>Based on this expression for <a href="https://en.wikipedia.org/wiki/Catalan_number" rel="nofollow">Catalan Numbers</a>:</p> <p><a href="http://i.stack.imgur.com/sfa7X.png" rel="nofollow"><img src="http://i.stack.imgur.com/sfa7X.png" alt="enter image description here"></a></p> <pre><code>from math import factorial ...
0
2016-09-09T15:57:39Z
[ "python" ]
Marker colour still not showing up
39,415,554
<p>The markers produced by the following are just showing up as grey:</p> <pre><code>plt.style.use('ggplot') ax1.scatter(x , y , edgecolor='black' , color='black' , marker='x' , label='Cluster 1') </code></pre>
1
2016-09-09T16:01:43Z
39,417,730
<p>The marker probably looked grey because of the small line width, which can be controlled with the <code>linewidths</code> property:</p> <pre><code>plt.scatter(1, 1, s=300, edgecolor='black', color='black', marker='x') plt.scatter(2, 2, s=300, edgecolor='black', color='black', marker='x', l...
2
2016-09-09T18:30:06Z
[ "python", "pandas", "matplotlib" ]
How to know node execution (before, middle, after calls) using DFS
39,415,724
<p>Let's say I implemented a simple version of an iterative DFS like this:</p> <pre><code>import sys import traceback def dfs(graph, start): visited, stack = [], [start] while stack: node = stack.pop() if node not in visited: visited.append(node) childs = reversed(gra...
1
2016-09-09T16:12:19Z
39,420,245
<p>You were really close with your recursive attempt actually.<br> I added comments for the small tweaks I made. </p> <pre><code>import sys, traceback def dfs(graph, node): print '{0}_start'.format(node) # need this right at the top if node not in graph: print '{0}_end'.format(node) # need to record...
2
2016-09-09T21:56:20Z
[ "python", "depth-first-search" ]
How to know node execution (before, middle, after calls) using DFS
39,415,724
<p>Let's say I implemented a simple version of an iterative DFS like this:</p> <pre><code>import sys import traceback def dfs(graph, start): visited, stack = [], [start] while stack: node = stack.pop() if node not in visited: visited.append(node) childs = reversed(gra...
1
2016-09-09T16:12:19Z
39,420,269
<p>I suspect this does what you want.</p> <pre><code>graphs = [ { 'A': ['B', 'C'], 'B': ['D'] } ] def dfs(graph, start): print '{}_start'.format(start) try: for child in graph[start]: dfs(graph, child) print '{}_middle'.format(start) ...
1
2016-09-09T21:58:10Z
[ "python", "depth-first-search" ]
How to know node execution (before, middle, after calls) using DFS
39,415,724
<p>Let's say I implemented a simple version of an iterative DFS like this:</p> <pre><code>import sys import traceback def dfs(graph, start): visited, stack = [], [start] while stack: node = stack.pop() if node not in visited: visited.append(node) childs = reversed(gra...
1
2016-09-09T16:12:19Z
39,421,419
<p>As the other answers have shown, the main issue with your current recursive code is the base case:</p> <pre><code>if node not in graph: return </code></pre> <p>This incorrectly skips the output when there are no children from a node. Get rid of those lines and, just use <code>enumerate(graph.get(start, []))</c...
2
2016-09-10T00:41:40Z
[ "python", "depth-first-search" ]
Getting wrong texture by glBindTexture
39,415,739
<p>I have two textures in .png format (floor and wall), I load them during the initialization, and choose before rendering by <code>glBindTexture</code>, but I get this: <a href="http://i.stack.imgur.com/ViC4F.png" rel="nofollow">screen_shot_1</a> instead of this: <a href="http://i.stack.imgur.com/6XkUW.png" rel="nofol...
0
2016-09-09T16:13:36Z
39,422,615
<p>These are some things I noticed in your code that may or may not be related to your texturing issues:</p> <ul> <li>For your glTexParameterf calls, I saw you used GL_NEAREST. This will lead to pixelated textures. If you are not working with pixel art, you might want to consider GL_LINEAR for your final parameter as ...
1
2016-09-10T04:38:39Z
[ "python", "opengl", "pygame", "pyopengl" ]
Tranpose Rows to Columns while keeping part of dataframe in tact
39,415,851
<p>I am trying to move some of my rows and make the them columns, but keep a large portion of the dataframe the same. </p> <p>My Dataframe looks something like this:</p> <pre><code>ID Thing Level1 Level2 Time OAttribute IsTrue Score Value 1 bicycle value value 9:30 whatever yes 1 type1 2 non...
3
2016-09-09T16:20:44Z
39,416,345
<p>Something like this?</p> <pre><code>In [112]: df Out[112]: ID Thing Level1 Level2 Time OAttribute IsTrue Score Value 0 1 bicycle value value 9:30 whatever yes 1 type1 1 2 non-cycle value value 1:30 whatever no 2 type2 2 3 bicycle value value 2:30 whatever ...
2
2016-09-09T16:51:27Z
[ "python", "pandas", "dataframe" ]
Tranpose Rows to Columns while keeping part of dataframe in tact
39,415,851
<p>I am trying to move some of my rows and make the them columns, but keep a large portion of the dataframe the same. </p> <p>My Dataframe looks something like this:</p> <pre><code>ID Thing Level1 Level2 Time OAttribute IsTrue Score Value 1 bicycle value value 9:30 whatever yes 1 type1 2 non...
3
2016-09-09T16:20:44Z
39,416,787
<p><strong><em>Option 1</em></strong><br> Use <code>merge</code></p> <pre><code>df_ = df[['ID', 'Value']].dropna().set_index('Value', append=True).ID.unstack() df.drop('Value', 1).merge(df_, right_index=True, left_index=True, how='left').fillna('') </code></pre> <p><a href="http://i.stack.imgur.com/2YKUK.png" rel="n...
3
2016-09-09T17:23:55Z
[ "python", "pandas", "dataframe" ]
Python encoding issue while reading a file
39,415,856
<p>I am trying to read a file that contains this character in it "ë". The problem is that I can not figure out how to read it no matter what I try to do with the encoding. When I manually look at the file in textedit it is listed as a unknown 8-bit file. If I try changing it to utf-8, utf-16 or anything else it eit...
0
2016-09-09T16:21:09Z
39,420,503
<p>Credit for this answer goes to RadLexus for figuring out the proper encoding and also to Mad Physicist who pointed me in the right track even if I did not consider all possible encodings. </p> <p>The issue is apparently a Mac will convert the .txt file to mac_roman. If you use that encoding it will work perfectly...
1
2016-09-09T22:23:18Z
[ "python", "python-2.7" ]
Processing html text nodes with scrapy and XPath
39,415,890
<p>I'm using scrapy to process documents like this one:</p> <pre><code>... &lt;div class="contents"&gt; some text &lt;ol&gt; &lt;li&gt; more text &lt;/li&gt; ... &lt;/ol&gt; &lt;/div&gt; ... </code></pre> <p>I want to collect all the text inside the contents area into a...
0
2016-09-09T16:22:58Z
39,419,761
<p>If <code>n</code> is not an <code>ol</code> element, <code>self::ol</code> yields an empty node set. What is <code>n.xpath(...)</code> supposed to return when the result of the expression is an empty node set?</p> <p>An empty node set is "falsy" in XPath, but you're not evaluating it as a boolean in XPath, only in ...
0
2016-09-09T21:11:25Z
[ "python", "xpath", "scrapy" ]
Processing html text nodes with scrapy and XPath
39,415,890
<p>I'm using scrapy to process documents like this one:</p> <pre><code>... &lt;div class="contents"&gt; some text &lt;ol&gt; &lt;li&gt; more text &lt;/li&gt; ... &lt;/ol&gt; &lt;/div&gt; ... </code></pre> <p>I want to collect all the text inside the contents area into a...
0
2016-09-09T16:22:58Z
39,446,213
<p>Scrapy's Selectors use <code>lxml</code> under the hood, but <a href="https://bugs.launchpad.net/lxml/+bug/996134" rel="nofollow"><code>lxml</code> doesn't work with XPath calls on text nodes</a>. </p> <pre><code>&gt;&gt;&gt; import scrapy &gt;&gt;&gt; s = scrapy.Selector(text='''&lt;div class="contents"&gt; ... ...
1
2016-09-12T08:31:03Z
[ "python", "xpath", "scrapy" ]
Python Plugin for Notepad++
39,415,924
<p>I installed PythonScript_1.0.8.0 for notepad++, saved my first script as Test.py and filled it as follows:</p> <pre><code> Editor.selectAll() Editor.paste() notepad.runPluginCommand('NPPExport', 'Copy RTF to clipboard') </code></pre> <p>However when running, I got the following error:</p> <blockqu...
-1
2016-09-09T16:25:11Z
39,415,966
<p>You need to use <code>editor</code> instead of <code>Editor</code>. <code>Editor</code> is the class and <code>editor</code> is the instance. Example:</p> <pre><code>editor.selectAll() </code></pre>
2
2016-09-09T16:28:16Z
[ "python", "notepad++" ]
How to average hourly observations stored on a .csv file into daily observations?
39,415,988
<p>I have a .csv file (mydb.csv) with the following entries (+1 million rows). The 7th row of this table contains dates. The dates repeat themselves many times, because this dataset contains hourly records.</p> <pre><code>QTEwOA==,81881,-7.610773,-72.681333,220,A108,2016-06-11,08,21.4,95,994.3,3.3,0,0,, QTEwOA==,81881...
-2
2016-09-09T16:29:40Z
39,416,517
<p>You can use the <code>pandas</code> library in python to do it very quickly. It would look like that:</p> <pre><code>import pandas as pd df = pd.read_csv("initial.csv") avgd_df = df.groupby('date').mean() avgd_df.to_csv("averaged.csv") </code></pre>
0
2016-09-09T17:04:27Z
[ "python", "sqlite", "csv", "numpy" ]
breaking a complex string ('2,3-5,50-60,70') into list inplace
39,415,993
<p>complexstring: '2,3-5,50-52,70'</p> <p>output required: [2,3,4,5,50,51,52,70]</p> <p>Here is what I attempted and succeeded</p> <pre><code>a = '2,3-5,50-52,70' data = [] [data.extend(range(int(r.split('-')[0]),int(r.split('-')[1])+1)) if r.find('-') != -1 else data.append(int(r)) for r in a.split(',')] print data...
3
2016-09-09T16:29:53Z
39,416,092
<p>Oneliner:</p> <pre><code>a = '2,3-5,50-52,70' data = sum([[int(x)] if x.isdigit() else list(range(int(x.split('-')[0]),1+int(x.split('-')[1]))) for x in a.split(",")],[]) print(data) </code></pre> <p>variant without <code>isdigit</code>:</p> <pre><code>data = sum([list(range(int(x.split('-')[0]),1+int(x.split('-'...
2
2016-09-09T16:35:51Z
[ "python", "python-2.7", "list-comprehension" ]
breaking a complex string ('2,3-5,50-60,70') into list inplace
39,415,993
<p>complexstring: '2,3-5,50-52,70'</p> <p>output required: [2,3,4,5,50,51,52,70]</p> <p>Here is what I attempted and succeeded</p> <pre><code>a = '2,3-5,50-52,70' data = [] [data.extend(range(int(r.split('-')[0]),int(r.split('-')[1])+1)) if r.find('-') != -1 else data.append(int(r)) for r in a.split(',')] print data...
3
2016-09-09T16:29:53Z
39,416,193
<p>I doubt it's possible to do it with a single list comprehension. You could abuse <code>sum()</code> and do other horrible things in one line, though:</p> <pre><code>sum([range(*(2 * map(int, c.split('-')))[:2]) + [int(c.split('-')[-1])] for c in text.split(',')], []) </code></pre> <p>A cleaner way would be to use ...
3
2016-09-09T16:41:44Z
[ "python", "python-2.7", "list-comprehension" ]
Send XLS with Spyne
39,416,001
<p>I have a problem.. </p> <p>I want to send XLS throught webservices with spyne, but I need, that if this URL</p> <pre><code>http://127.0.0.1:5000/download/file?A=1 </code></pre> <p>will be pressed, whole XLS will download. Is this possible?</p> <p>Here is mine code:</p> <pre><code>class xlsDownload(spyne.Service...
0
2016-09-09T16:30:34Z
39,457,091
<p>So, this is it in Flask</p> <pre><code>@app.route("/download/file") def xlsDownload(A): GetXLS(A) response = Response(bytearray(open("file.xls", "rb").read())) response.headers["Content-Type"] = "application/vnd.ms-excel" response.headers["Content-Disposition"] = "attachment; filename = file.xls" ...
0
2016-09-12T19:06:33Z
[ "python", "excel", "web-services", "spyne" ]
matplotlib not displaying image on Jupyter Notebook
39,416,004
<p>I am using ubuntu 14.04 and coding in jupyter notebook using anaconda2.7 and everything else is up to date . Today I was coding, every thing worked fine. I closed the notebook and when I reopened it, every thing worked fine except that the image was not being displayed.</p> <pre><code>%matplotlib inline import nump...
1
2016-09-09T16:30:36Z
39,416,963
<p>You need to tell matplotlib to actually show the image. Add this at the end of your segment:</p> <pre><code>plt.show() </code></pre>
0
2016-09-09T17:36:49Z
[ "python", "image", "matplotlib", "jupyter" ]
Border for tkinter Label
39,416,021
<p>Not really relevant but i'm building a calendar and I have a lot of Label widgets, and therefore it will look alot nicer if I had some borders for them!</p> <p>I have seen you can do this for other widgets such as Button, Entry and Text.</p> <p>Minimal code:</p> <pre><code>from tkinter import * root = Tk() L1 =...
0
2016-09-09T16:31:47Z
39,416,145
<p>If you want a border, the option is <code>borderwidth</code>. You can also choose the relief of the border (<code>"flat"</code>, <code>"raised"</code>, <code>"sunken"</code>, <code>"ridge"</code>, <code>"solid"</code>, <code>"groove"</code>).</p> <p>For example:</p> <pre><code>l1 = Label(root, text="This", borderw...
1
2016-09-09T16:38:35Z
[ "python", "tkinter" ]
Optimizing for loop in python
39,416,026
<p>I have a dataframe (df) with distance traveled and I have assigned a label based on certain conditions.</p> <pre><code>distance=[0,0.0001,0.20,1.23,4.0] df = pd.DataFrame(distance,columns=["distance"]) df['label']=0 for i in range(0, len(df['distance'])): if (df['distance'].values[i])&lt;=0.10: d...
3
2016-09-09T16:31:58Z
39,416,489
<p>Comes with a warning about setting a value on a copy of a slice, but maybe someone can suggest a cleaner alternative? </p> <p>Just based on fancy indexing to get the sub-array based on distance and then writing the values you want to it.</p> <pre><code>df.loc[:, "label"][df.loc[:, "distance"] &lt;= 0.1] = 1 df.loc...
0
2016-09-09T17:02:51Z
[ "python", "pandas", "for-loop", "optimization" ]
Optimizing for loop in python
39,416,026
<p>I have a dataframe (df) with distance traveled and I have assigned a label based on certain conditions.</p> <pre><code>distance=[0,0.0001,0.20,1.23,4.0] df = pd.DataFrame(distance,columns=["distance"]) df['label']=0 for i in range(0, len(df['distance'])): if (df['distance'].values[i])&lt;=0.10: d...
3
2016-09-09T16:31:58Z
39,416,568
<p>In general, you shouldn't loop over DataFrames unless it's absolutely necessary. You'll usually get much better performance using a built-in Pandas function that's already been optimized, or by using a vectorized approach. </p> <p>In this case, you can use <code>loc</code> and <a href="http://pandas.pydata.org/pan...
3
2016-09-09T17:08:21Z
[ "python", "pandas", "for-loop", "optimization" ]
Optimizing for loop in python
39,416,026
<p>I have a dataframe (df) with distance traveled and I have assigned a label based on certain conditions.</p> <pre><code>distance=[0,0.0001,0.20,1.23,4.0] df = pd.DataFrame(distance,columns=["distance"]) df['label']=0 for i in range(0, len(df['distance'])): if (df['distance'].values[i])&lt;=0.10: d...
3
2016-09-09T16:31:58Z
39,416,804
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow"><code>cut</code></a> by assigning labels to the bins:</p> <pre><code>pd.cut(df.distance, [-np.inf, 0.1, 0.5, np.inf], labels=[1,2,3]) 0 1 1 1 2 2 3 3 4 3 </code></pre>
1
2016-09-09T17:24:47Z
[ "python", "pandas", "for-loop", "optimization" ]
How to exclude a part of a Django template file from processing?
39,416,053
<p>I have a Django template file that has a couple of <strong>enormous</strong> strings in it (images encoded in Base64). When I use the Django templating engine, it chokes and takes 5 minutes to render the template. Is there a way to exclude a part of a template, with something like:</p> <pre><code>{% ignore %} &lt...
1
2016-09-09T16:33:42Z
39,416,156
<p>Use <strong><code>verbatim</code></strong> tag!</p> <p>From django docs <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/#verbatim" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/templates/builtins/#verbatim</a></p> <blockquote> <p><strong>verbatim</strong></p> <p>Stops the te...
1
2016-09-09T16:39:07Z
[ "python", "django", "django-templates" ]
Automate webpage tasks without having to have a browser open?
39,416,083
<p>I know about tampermonkey/greasemonkey and have used it a fair bit, but now my task is to write a program that runs in the background and automates mundane tasks (clicking buttons, typing into input fields etc.) on a specific webpage. Running a browser in the background takes too much RAM and processing power, so I'...
0
2016-09-09T16:35:34Z
39,416,196
<p>It depends on whether you want a script that interacts with a web UI, or a script that automates web requests. Do you <em>really</em> need to click buttons and type into input fields? Presumably, the data from those buttons and input fields is eventually sent to a web server. You could skip the entire UI and just...
0
2016-09-09T16:42:00Z
[ "python", "selenium", "automation" ]
From local HTML file, shutdown down computer with Python/AJAX
39,416,144
<p>Been working with this for a while and found a few helpful things, but I'm not good with AJAX yet... </p> <p>I'm working to make a chromium-browser kiosk on the Raspberry Pi (which has been fine) but when in kiosk mode, there's not a "shutdown" button. I'm displaying a local HTML file in the chromium-browser and I ...
2
2016-09-09T16:38:34Z
39,416,396
<p>Probably the easiest way would be to run a local web server that listens for a request and then shuts down the computer. Instead of just displaying a local HTML file, actually serve it from flask. This gives you much more freedom, since you can run the commands server-side (even though the server and client are th...
2
2016-09-09T16:55:07Z
[ "python", "html", "ajax", "raspberry-pi", "shutdown" ]
Get the facebook's posts' likes and share posts counts using HTTP request
39,416,162
<p>I want to get post's likes count using <code>HTTP</code> request. I am doing in this way </p> <pre><code>https://graph.facebook.com/10153608167431961?fields=likes.limit(0).summary(true)?access_token=EAANep**** </code></pre> <p>and getting the error </p> <blockquote> <p>{ "error": { "message": "Synt...
-1
2016-09-09T16:39:48Z
39,417,081
<p>Correct:</p> <pre><code>https://graph.facebook.com/10153608167431961?fields=likes.limit(0).summary(true)&amp;access_token=xxx </code></pre> <p>You can´t have more than one questionmark, separate the different parameter with <code>&amp;</code>.</p>
0
2016-09-09T17:44:44Z
[ "python", "facebook", "facebook-graph-api" ]
Prevent serializer creating duplicate items (update_or_create on Nested items)
39,416,230
<p>When I post via the API, I want the serializer not duplicated a tag if one exists with the same name.</p> <p>I tried adding "unique" to the model field of "name" in the class Tag but this did not work- it wouldn't allow me to create other Movie's that linked to a tag which exists.</p> <ul> <li><p>Check if the fiel...
0
2016-09-09T16:44:02Z
39,423,814
<p>You'll have to write custom create method for your models. <a href="http://www.django-rest-framework.org/topics/3.0-announcement/#writable-nested-serialization" rel="nofollow">Here is why.</a></p>
1
2016-09-10T07:39:58Z
[ "python", "django", "django-rest-framework" ]
How to capture all letters from different languages in python?
39,416,362
<p>I have a corpus of different texts from different languages.<br> I want to capture all characters. I use <strong>python 2.7</strong> and <strong>defaultencodingsetting</strong> is <strong>utf-8</strong>.<br> I do not know why when I use this code for German umlaut it prints out German umlaut correctly : </p> <pr...
-1
2016-09-09T16:52:31Z
39,416,498
<p>You <em>already</em> have UTF-8 encoded data. There are no string literal characters to escape in your bytestring. You are looking at the <code>repr()</code> output of a string where non-printable ASCII characters are shown as escape sequences because that makes the value easily copy-pastable in an ASCII-safe way. T...
4
2016-09-09T17:03:08Z
[ "python", "unicode" ]
How to update a composite list as contents of member lists are changed?
39,416,382
<p>Let's say I have:</p> <pre><code>friendlies = [] enemies = [] everyone = [friendlies + enemies] </code></pre> <p>And I say:</p> <pre><code>friendlies.append("something") </code></pre> <p>so that friendlies now contains:</p> <pre><code>["something"] </code></pre> <p>What is the pythonic way to make it so that <...
0
2016-09-09T16:53:35Z
39,416,431
<p>Maintain a reference to <code>friendlies</code> and <code>enemies</code> in the composite list:</p> <pre><code>everyone = [friendlies, enemies] # ^ </code></pre> <p>Index 0 and 1 of the compisite list will reference <code>friendlies</code> and <code>enemies</code> respectively. </p> <p><code>f...
3
2016-09-09T16:58:00Z
[ "python", "list", "python-3.x", "data-structures" ]
How to update a composite list as contents of member lists are changed?
39,416,382
<p>Let's say I have:</p> <pre><code>friendlies = [] enemies = [] everyone = [friendlies + enemies] </code></pre> <p>And I say:</p> <pre><code>friendlies.append("something") </code></pre> <p>so that friendlies now contains:</p> <pre><code>["something"] </code></pre> <p>What is the pythonic way to make it so that <...
0
2016-09-09T16:53:35Z
39,416,464
<p>If you sum now you lose reference. Create a list of lists to maintain references</p> <p>Hacky way of doing that:</p> <pre><code>friendlies = [] enemies = [] everyone = [friendlies,enemies] # not sum, sublists enemies.append("something") print(sum(everyone,[])) # sum sublists to a new list </code></pre>
2
2016-09-09T17:00:43Z
[ "python", "list", "python-3.x", "data-structures" ]
Python String Slicing from known word in string
39,416,503
<p>I'm trying to read a variable which is written by another function (outside of my control), to look for the presence of a known word and then to copy a sub string beginning at the known word and ending either at the end of the line or a <code>|</code> delimiter. So I want to write to this variable based on a simple ...
0
2016-09-09T17:03:30Z
39,416,728
<p>I'd use regex and the <code>in</code> word to check if <code>devices</code> has 'box1'. If so then simply append it to the new <code>devices</code> string</p> <pre><code>import re devices='box5|box6_standard|box9|box8_ex_345|box1_182' area = "3" if area == "3": tdevices = "box2|box3" if 'box1' in devices: ...
0
2016-09-09T17:19:13Z
[ "python", "string", "slice" ]
Python if else statement not working in reduce lambda function
39,416,588
<p>I'm new to <code>lambda</code> and <code>reduce</code> in Python and I don't understand why this function doesn't work:</p> <pre><code>def my_func(str): symbols = ['_', '-'] return reduce(lambda x, y: ' ' + y if x in symbols else x + y, str) my_func('foo_bar-baz') # 'foo_bar-baz' </code></pre> <p>I expec...
-2
2016-09-09T17:10:11Z
39,416,674
<p>You seem to be confused about the order of the arguments to <code>reduce</code>'s function argument. The first argument is the running total, the second is the new data. In your example, <code>x</code> is the built-up string, <code>y</code> is the new character.</p> <p>Try this:</p> <pre><code>def my_func(str): ...
5
2016-09-09T17:16:09Z
[ "python", "lambda", "reduce" ]
limited number of user-initiated background processes
39,416,623
<p>I need to allow users to submit requests for very, very large jobs. We are talking 100 gigabytes of memory and 20 hours of computing time. This costs our company a lot of money, so it was stipulated that only 2 jobs could be running at any time, and requests for new jobs when 2 are already running would be rejected ...
9
2016-09-09T17:12:55Z
39,446,293
<p>First of all you need to limit concurrency on your worker (<a href="http://docs.celeryproject.org/en/latest/userguide/workers.html#starting-the-worker" rel="nofollow">docs</a>):</p> <pre><code>celery -A proj worker --loglevel=INFO --concurrency=2 -n &lt;worker_name&gt; </code></pre> <p>This will help to make sure ...
3
2016-09-12T08:36:41Z
[ "python", "django", "asynchronous", "celery", "background-process" ]
limited number of user-initiated background processes
39,416,623
<p>I need to allow users to submit requests for very, very large jobs. We are talking 100 gigabytes of memory and 20 hours of computing time. This costs our company a lot of money, so it was stipulated that only 2 jobs could be running at any time, and requests for new jobs when 2 are already running would be rejected ...
9
2016-09-09T17:12:55Z
39,447,549
<p>I have two solutions for this particular case, one an out of the box solution by celery, and another one that you implement yourself.</p> <ol> <li>You can do something like this with celery workers. In particular, you <strong>only create two worker processes with concurrency=1</strong> (or well, one with concurrenc...
8
2016-09-12T09:46:39Z
[ "python", "django", "asynchronous", "celery", "background-process" ]
limited number of user-initiated background processes
39,416,623
<p>I need to allow users to submit requests for very, very large jobs. We are talking 100 gigabytes of memory and 20 hours of computing time. This costs our company a lot of money, so it was stipulated that only 2 jobs could be running at any time, and requests for new jobs when 2 are already running would be rejected ...
9
2016-09-09T17:12:55Z
39,476,477
<p><strong>First</strong></p> <p>You need the first part of <a href="http://stackoverflow.com/a/39447549/4151886">SpiXel's solution</a>. According to him, "<strong>you only create two worker processes with concurrency=1</strong>".</p> <p><strong>Second</strong></p> <p>Set the <a href="http://docs.celeryproject.org/e...
2
2016-09-13T18:10:50Z
[ "python", "django", "asynchronous", "celery", "background-process" ]
Checking if a variable is existent within a list
39,416,667
<p>I am currently using the code</p> <pre><code>names = ["Bob", "Joe", "Jack"] name = raw_input("Please enter your name.") print ("Hello", name) </code></pre> <p>And I want to create an if statement that checks if the inputed name is in the list of names. I assume there is some command to check this, and I couldn't f...
0
2016-09-09T17:15:35Z
39,416,699
<p>Use the <code>in</code> operator.</p> <pre><code>if name in names: print ('The entered name is in the list of names.') else: print ('The entered name is not in the list of names.') </code></pre>
2
2016-09-09T17:17:28Z
[ "python", "list", "input", "global-variables" ]
struggling to implement a switch/case statement in python
39,416,686
<p>since there is no <code>switch/case</code> in python, i am trying to implement the same in my sample program with the help of the following link: <a href="http://www.pydanny.com/why-doesnt-python-have-switch-case.html" rel="nofollow">why python doesnt have switch-case</a></p> <p>below is my code:</p> <pre><code>#s...
0
2016-09-09T17:16:40Z
39,416,730
<p>When you call <code>switcher.get(action_id, sys.exit(0))</code>, the 2nd argument is evalulated before the result can be passed in to <code>.get()</code>, which results in the program terminating immediately.</p>
2
2016-09-09T17:19:16Z
[ "python" ]
struggling to implement a switch/case statement in python
39,416,686
<p>since there is no <code>switch/case</code> in python, i am trying to implement the same in my sample program with the help of the following link: <a href="http://www.pydanny.com/why-doesnt-python-have-switch-case.html" rel="nofollow">why python doesnt have switch-case</a></p> <p>below is my code:</p> <pre><code>#s...
0
2016-09-09T17:16:40Z
39,416,896
<p>Your code is broken in two ways, the first way is:</p> <pre><code>def action_type(action_id, dir_path): print "action id is, ", action_id def whatever(): # all code here never runs # action_type() exits here </code></pre> <p>this inner function <code>whatever()</code> is defined, you never ca...
1
2016-09-09T17:30:34Z
[ "python" ]
Trouble reading from PLC with pymodbus
39,416,757
<p>I'm having some trouble reading registers from my WAGO 750-881 PLC using pymodbus, python 2.7, and Windows. I can read just fine with the Modbus Poll utility so I think the problem is in my python code. Using the following code I get the error: <code>runfile('C:/Users/Mike/modbustest2.py', wdir='C:/Users/Mike') Exce...
0
2016-09-09T17:21:34Z
39,416,999
<p>You're getting an ExceptionResponse object back, with the exception code 'IllegalValue'.</p> <p>The most likely cause is you're reading a register the PLC doesn't think exists.</p> <p>Of course there's no registers attribute on this object because it's not a ReadHoldingRegisters response.</p>
1
2016-09-09T17:39:39Z
[ "python", "python-2.7", "modbus", "plc", "modbus-tcp" ]
Unable to install the python module aubio from github, or from pip
39,416,823
<p>For pip: </p> <p>In my command prompt I type in: </p> <pre><code>C:/Python/Scripts/pip install aubio </code></pre> <p>Recommended by this site: </p> <p><a href="http://aubio.readthedocs.io/en/latest/python_module.html" rel="nofollow">http://aubio.readthedocs.io/en/latest/python_module.html</a></p> <p>And get th...
0
2016-09-09T17:26:01Z
39,416,979
<p>So this isn't the whole answer, but it will help anyone who comes here in the future. </p> <p>I installed Github and not git. That's why the git command isn't recognized. </p> <p>The correct place for installation[WINDOWS] is: <a href="https://git-for-windows.github.io/" rel="nofollow">https://git-for-windows.gith...
0
2016-09-09T17:38:22Z
[ "python", "audio", "module", "pip" ]
OPEN CV - Change Pixel Coordinates
39,416,881
<p>AS the title suggests I have an image, whose pixel coordinates I want to change using a mathematical function. So far, I have the following code which works but is very time consuming because of the nested loop. Do you have any suggestions to make it faster? To be quantitative, it takes about 2-2.5 minutes to comple...
0
2016-09-09T17:29:19Z
39,417,869
<p>There may be a way to get numpy to do some vectorized work for you, but one easy speedup is to not re-calculate some of the values every time you loop (I'm assuming a,b,c, and d are not changing in the loop). I'm curious what the speedup would be, can you report back?</p> <pre><code>imgcor = np.zeros(img.shape, dty...
0
2016-09-09T18:40:36Z
[ "python", "python-2.7", "opencv", "image-processing", "transform" ]
Decoding ASN1 UPER in Python
39,416,902
<p>I need to decode ASN1 message using python. I looked into the pyasn1 library but it doesn't support UPER. What can I use to decode ASN1 UPER in python</p>
0
2016-09-09T17:31:15Z
39,425,820
<p><strong>Got the Schema?</strong></p> <p>Assuming you have the ASN.1 schema for the data you're trying to decode, you could start by taking a look at the <a href="http://taste.tuxfamily.org/wiki/index.php?title=ASN.1_generators" rel="nofollow">TASTE framework from the European Space Agency</a>. This is a large appli...
0
2016-09-10T11:56:34Z
[ "python", "decode", "asn.1" ]
Regex capturing group within non-capturing group
39,416,911
<p>In Python, how do you capture a group within a non-capturing group? Put in another way, how do you repeat a non-capturing sub-pattern that contains a capturing group?</p> <p>An example of this would be to capture all of the package names on an import string. E.g. the string:</p> <blockquote> <p>import pandas, os...
2
2016-09-09T17:32:13Z
39,417,275
<p>Your question is phrased strictly about regex, but if you're willing to use a <a href="https://en.wikipedia.org/wiki/Recursive_descent_parser" rel="nofollow">recursive descent parser</a> (e.g., <a href="http://pyparsing.wikispaces.com/" rel="nofollow"><code>pyparsing</code></a>), many things that require expertise i...
1
2016-09-09T17:59:28Z
[ "python", "regex" ]
Regex capturing group within non-capturing group
39,416,911
<p>In Python, how do you capture a group within a non-capturing group? Put in another way, how do you repeat a non-capturing sub-pattern that contains a capturing group?</p> <p>An example of this would be to capture all of the package names on an import string. E.g. the string:</p> <blockquote> <p>import pandas, os...
2
2016-09-09T17:32:13Z
39,417,415
<p>A repeated capturing group will <em>only</em> capture the last iteration. This is why you need to restructure your regex to work with <code>re.findall</code>.</p> <pre><code>\s* (?: (?:^from\s+ ( # Base (from (base) import ...) (?:[a-zA-Z_][a-zA-Z_0-9]* # Variable name (?:\.[a-zA-Z_][a-zA-Z_0-...
0
2016-09-09T18:08:48Z
[ "python", "regex" ]
Regex capturing group within non-capturing group
39,416,911
<p>In Python, how do you capture a group within a non-capturing group? Put in another way, how do you repeat a non-capturing sub-pattern that contains a capturing group?</p> <p>An example of this would be to capture all of the package names on an import string. E.g. the string:</p> <blockquote> <p>import pandas, os...
2
2016-09-09T17:32:13Z
39,418,673
<p>You can use your <code>import\s+(?:([a-zA-Z0-9=]+),*\s*)*</code> regex (I just fixed the <code>0-9</code> range to match any digit and included <code>=</code> to the end) and access the Group 1 capture stack using <a href="https://pypi.python.org/pypi/regex" rel="nofollow">PyPi regex module</a>:</p> <pre><code>&gt;...
0
2016-09-09T19:39:05Z
[ "python", "regex" ]
Python version of Arduino's Serial.available
39,416,966
<p>I'm trying to run an infinite loop in which the extension and movement of a linear actuator is controlled. The extension amount is controlled by user input with a value from 0 to 9, i.e. if I hit 9 and enter, the actuator will extend to maximum extension and if I hit 5 and enter, the actuator will go back to 50% ext...
0
2016-09-09T17:36:54Z
39,417,013
<p>From <a href="https://pythonhosted.org/pyserial/pyserial_api.html" rel="nofollow">the documentation</a>:</p> <pre><code> in_waiting Getter: Get the number of bytes in the input buffer Type: int Return the number of bytes in the receive buffer. </code></pre>
0
2016-09-09T17:40:29Z
[ "python", "embedded-linux", "pyserial" ]
Python version of Arduino's Serial.available
39,416,966
<p>I'm trying to run an infinite loop in which the extension and movement of a linear actuator is controlled. The extension amount is controlled by user input with a value from 0 to 9, i.e. if I hit 9 and enter, the actuator will extend to maximum extension and if I hit 5 and enter, the actuator will go back to 50% ext...
0
2016-09-09T17:36:54Z
39,417,258
<p>Answering my own question - I noticed I screwed up on the logic in my head a bit. I was trying to use the same internal serial port (the one I was using the execute the python script) to input information. Obviously this won't work. This is also why my inWaiting function was giving strange results.</p> <p>Essential...
0
2016-09-09T17:58:00Z
[ "python", "embedded-linux", "pyserial" ]
Tkinter: why do both windows open?
39,417,091
<p>I started looking at some Tkinter tutorials. I always like to mess around with code before going on with the next chapter: for instance I tried to open more than one independent root.</p> <pre><code>from Tkinter import * def main(): root1, root2 = Tk(), Tk() root1.title("First window") root2.title("Sec...
0
2016-09-09T17:45:16Z
39,417,968
<p><strong>EDIT: Removed incorrect answer, added answer below</strong></p> <p>The short of why are confused is that the behavior of your code is undefined. Really, it isn't running as differently as you think. Try running this code:</p> <pre><code>from Tkinter import * def main(): root1, root2 = Tk(), Tk() r...
1
2016-09-09T18:46:15Z
[ "python", "loops", "methods", "tkinter" ]
SQLAlchemy automap - adding methods to automapped Model
39,417,143
<p>I have a preexisting database that I'm using with SQLAlchemy, so I'm using automap to get the Models from the database. What is the best way to add methods to these classes? For example, for a User class, I'd like to add methods such as verifying the password. Also, I'd like to add methods for flask-login (UserMixin...
1
2016-09-09T17:49:26Z
39,417,527
<p><a href="http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html#specifying-classes-explicitly" rel="nofollow">Specify your classes explicitly</a> beforehand, and define your methods as you would normally:</p> <pre><code>Base = automap_base() class User(Base): __tablename__ = 'user' def verify_pa...
0
2016-09-09T18:16:50Z
[ "python", "flask", "sqlalchemy", "flask-sqlalchemy" ]
How do I set up a login system in pyramid using mysql as database to store email and password?
39,417,217
<p>I have gone through this <a href="http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authentication.html" rel="nofollow">http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authentication.html</a> but it does not give any clue how to add database to this to store email and pa...
1
2016-09-09T17:55:23Z
39,419,969
<p>The introduction to the Quick Tutorial describes its purpose and intended audience. Authentication and persistent storage are not covered in the same lesson, but in two different lessons.</p> <p>Either you can combine learning from previous steps (not recommended) or you can take a stab at the <a href="http://docs...
3
2016-09-09T21:29:02Z
[ "python", "authentication", "pyramid" ]
How do I set up a login system in pyramid using mysql as database to store email and password?
39,417,217
<p>I have gone through this <a href="http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authentication.html" rel="nofollow">http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/authentication.html</a> but it does not give any clue how to add database to this to store email and pa...
1
2016-09-09T17:55:23Z
40,026,258
<p>Here are a few suggestions regarding switching from SQLite to MySQL. In your <code>development.ini</code> (and/or <code>production.ini</code>) file, change from SQLite to MySQL:</p> <pre><code># sqlalchemy.url = sqlite:///%(here)s/MyProject.sqlite [comment out or remove this line] sqlalchemy.url = mysql://MySQLUse...
0
2016-10-13T16:23:24Z
[ "python", "authentication", "pyramid" ]
Why does Python default to ASCII encoding?
39,417,311
<p>I've run into lots of bugs in Python due to the default ASCII encoding. I always have to remember to switch it to utf8</p> <p>I wanted to know, is there any reason or benefit to a default ASCII encoding? It seems strictly worse than utf8, and causes annoying bugs. Am I missing something by always switching to utf8?...
1
2016-09-09T18:01:59Z
39,417,340
<p>Because Python 2 Unicode was built (back in 1999-2000) before UTF-8 was ubiquitous. ASCII on the other hand was understood by almost all target platforms using 8-bit codecs.</p> <p>If you look at the <a href="https://en.wikipedia.org/wiki/UTF-8" rel="nofollow">Wikipedia UTF-8 adoption graph</a>, you'll see that UTF...
4
2016-09-09T18:04:36Z
[ "python", "utf-8", "character-encoding", "ascii" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,373
<p>Follow the <a href="https://docs.python.org/3/glossary.html#term-eafp" rel="nofollow">EAFP approach</a>, try to convert it to decimal via <a href="https://docs.python.org/3/library/functions.html#int" rel="nofollow"><code>int()</code></a> and handle the <code>ValueError</code>:</p> <pre><code>try: int(binary, 2...
6
2016-09-09T18:06:30Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,379
<p>Use <code>all()</code></p> <pre><code> all(x in '10' for x in binary_string) </code></pre>
2
2016-09-09T18:06:40Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,383
<p>Maybe <code>all(x in "01" for x in binary)</code>.</p>
1
2016-09-09T18:07:01Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,393
<p>If you <em>must</em> avoid using <code>int(binary, 2)</code> and handle the exception, you could use the <a href="https://docs.python.org/2/library/functions.html#any" rel="nofollow"><code>all()</code> function</a> with a <a href="https://docs.python.org/2/tutorial/classes.html#generator-expressions" rel="nofollow">...
3
2016-09-09T18:07:30Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,451
<p>Following is for 2.7.9, just look for a 3.4.4 parallel:</p> <pre><code>import re binary = raw_input("enter binary number") if re.match("^[01]*$", binary): print "ok" </code></pre>
0
2016-09-09T18:11:45Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,550
<p>You could check if the sum of occurrences of '0' and '1' is equal to the length of the string.</p> <pre><code> binary.count('0') + binary.count('1') == len(binary) </code></pre>
0
2016-09-09T18:18:45Z
[ "python" ]
Python 3.4.4 How to verify if a string is only made of 0 and 1
39,417,335
<p>I'm doing a binary to decimal converter in python 3.4.4 and it's pretty much finished except for the fact that I would like to check that the binary number entered by the user is indeed a binary number (check if the string is only made of o and 1) but I'm unsure what to do.</p> <p>here's the program:</p> <pre><cod...
4
2016-09-09T18:04:04Z
39,417,664
<p>I suppose checking the input string for correctness is best done with regular expressions. The code that would help you is the following:</p> <pre><code>import re binary = input("Enter a binary number") len_bin = len(binary) result = 0 if re.search("^[0-1]+$", binary) is not None: for position in range(len_bi...
0
2016-09-09T18:25:33Z
[ "python" ]
OpenCV: getting error for resizing- 1428: error: (-215) ssize.area() > 0
39,417,407
<pre><code>while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) </code></pre> <blockquote> <p>1428: error: (-215) ssize.area() > 0</p> </blockquote>
-2
2016-09-09T18:08:31Z
39,422,937
<p>The error is suggesting that the <code>frame</code> you extracted from the camera has zero size. So it is recommended to check the size and data of <code>frame</code> from <code>cap.read()</code> before doing any processing.</p>
1
2016-09-10T05:36:05Z
[ "python", "opencv" ]
numpy.where for 2+ specific values
39,417,419
<p>Can the numpy.where function be used for more than one specific value?</p> <p>I can specify a specific value:</p> <pre><code>&gt;&gt;&gt; x = numpy.arange(5) &gt;&gt;&gt; numpy.where(x == 2)[0][0] 2 </code></pre> <p>But I would like to do something like the following. It gives an error of course.</p> <pre><code>...
1
2016-09-09T18:09:09Z
39,417,516
<p>You can use the <code>numpy.in1d</code> function with <code>numpy.where</code>:</p> <pre><code>import numpy numpy.where(numpy.in1d(x, [2,3])) # (array([2, 3]),) </code></pre>
3
2016-09-09T18:16:10Z
[ "python", "numpy" ]
numpy.where for 2+ specific values
39,417,419
<p>Can the numpy.where function be used for more than one specific value?</p> <p>I can specify a specific value:</p> <pre><code>&gt;&gt;&gt; x = numpy.arange(5) &gt;&gt;&gt; numpy.where(x == 2)[0][0] 2 </code></pre> <p>But I would like to do something like the following. It gives an error of course.</p> <pre><code>...
1
2016-09-09T18:09:09Z
39,417,519
<p>I guess <code>np.ind1d</code> might help you, instead:</p> <pre><code>&gt;&gt;&gt; x = np.arange(5) &gt;&gt;&gt; np.in1d(x, [3,4]) array([False, False, False, True, True], dtype=bool) &gt;&gt;&gt; np.argwhere(_) array([[3], [4]]) </code></pre>
1
2016-09-09T18:16:29Z
[ "python", "numpy" ]
numpy.where for 2+ specific values
39,417,419
<p>Can the numpy.where function be used for more than one specific value?</p> <p>I can specify a specific value:</p> <pre><code>&gt;&gt;&gt; x = numpy.arange(5) &gt;&gt;&gt; numpy.where(x == 2)[0][0] 2 </code></pre> <p>But I would like to do something like the following. It gives an error of course.</p> <pre><code>...
1
2016-09-09T18:09:09Z
39,417,652
<p>If you only need to check for a few values you can:</p> <pre><code>import numpy as np x = np.arange(4) ret_arr = np.where([x == 1, x == 2, x == 4, x == 0])[1] print "Ret arr = ",ret_arr </code></pre> <p>Output:</p> <pre><code>Ret arr = [1 2 0] </code></pre>
1
2016-09-09T18:25:02Z
[ "python", "numpy" ]
Modifying string in a text file
39,417,479
<p>I am using a text file to store the last time data was pulled from an API.</p> <p>After I check if new data should be pulled I am updating the last datapoint with this Python 2.7 code:</p> <pre><code>if pullAgain == True: # open last time again lasttimedata = open('lasttimemultiple.txt', 'a+') for item in ...
0
2016-09-09T18:13:52Z
39,417,763
<h2>You were first asking for editing a list.</h2> <p>There is two ways for doing that:</p> <p><strong>Keep a counter to know witch element to edit:</strong></p> <pre><code>for index, item in enumerate(splitData): splitData[item] = new_value </code></pre> <p>But your are editing the list while iterating, and th...
1
2016-09-09T18:32:00Z
[ "python", "python-2.7" ]
How to make a list of lists in Python?
39,417,488
<p>Assume,</p> <pre><code>range(len(column)) = 4 column = ['AAA', 'CTC', 'GTC', 'TTC'] for i in range(len(column)): a = list(column[i]) </code></pre> <p>Outside of this loop I want a variable,say x to be assigned such that it gives the following output. </p> <pre><code> ['A', 'A', 'A'] ['C', 'T', 'C'] ['G', 'T...
1
2016-09-09T18:14:23Z
39,417,569
<p>I believe you are in need of a list of lists</p> <p>Code:</p> <pre><code>column = ['AAA', 'CTC', 'GTC', 'TTC'] x=[] for i in range(len(column)): a = list(column[i]) x.append(a) print x </code></pre> <p>Output:</p> <pre><code>[['A', 'A', 'A'], ['C', 'T', 'C'], ['G', 'T', 'C'], ['T', 'T', 'C']] </code></p...
2
2016-09-09T18:19:52Z
[ "python", "python-2.7", "for-loop", "return" ]
How to make a list of lists in Python?
39,417,488
<p>Assume,</p> <pre><code>range(len(column)) = 4 column = ['AAA', 'CTC', 'GTC', 'TTC'] for i in range(len(column)): a = list(column[i]) </code></pre> <p>Outside of this loop I want a variable,say x to be assigned such that it gives the following output. </p> <pre><code> ['A', 'A', 'A'] ['C', 'T', 'C'] ['G', 'T...
1
2016-09-09T18:14:23Z
39,417,576
<p>It's not completely clear what kind of comparison you want to do once you've formatted your data, but this is something </p> <pre><code>import numpy as np alt_col = [list(y) for y in column] x = np.asarray(alt_col) </code></pre> <p>you can then compare whatever you want within the array</p> <pre><code>print al...
1
2016-09-09T18:20:18Z
[ "python", "python-2.7", "for-loop", "return" ]
How to make a list of lists in Python?
39,417,488
<p>Assume,</p> <pre><code>range(len(column)) = 4 column = ['AAA', 'CTC', 'GTC', 'TTC'] for i in range(len(column)): a = list(column[i]) </code></pre> <p>Outside of this loop I want a variable,say x to be assigned such that it gives the following output. </p> <pre><code> ['A', 'A', 'A'] ['C', 'T', 'C'] ['G', 'T...
1
2016-09-09T18:14:23Z
39,417,832
<p>You can easily create <code>x</code> without using <code>numpy</code> or other external module:</p> <pre><code>column = ['AAA', 'CTC', 'GTC', 'TTC'] x = [list(column[i]) for i in range(len(column))] print(x) </code></pre> <p>Output:</p> <pre class="lang-none prettyprint-override"><code>[['A', 'A', 'A'], ['C', 'T'...
1
2016-09-09T18:37:44Z
[ "python", "python-2.7", "for-loop", "return" ]
How to make a list of lists in Python?
39,417,488
<p>Assume,</p> <pre><code>range(len(column)) = 4 column = ['AAA', 'CTC', 'GTC', 'TTC'] for i in range(len(column)): a = list(column[i]) </code></pre> <p>Outside of this loop I want a variable,say x to be assigned such that it gives the following output. </p> <pre><code> ['A', 'A', 'A'] ['C', 'T', 'C'] ['G', 'T...
1
2016-09-09T18:14:23Z
39,418,462
<pre><code>inputs = ['ABC','DEF','GHI'] # list of inputs outputs = [] # creates an empty list to be populated for i in range(len(inputs)): # steps through each item in the list outputs.append([]) # adds a list into the output list, this is done for each item in the input list for j in range(len(inputs[i])): # s...
1
2016-09-09T19:25:06Z
[ "python", "python-2.7", "for-loop", "return" ]
running adb with python: executing a program and ending it
39,417,505
<p>I am trying to perform adb interactions through python code. I have an endless executable on the android device which i would like to start and after 10 seconds kill it. right now, i can get the program to start but cannot kill it other the manually pressing ctrl+c.</p> <pre><code>procID = subprocess.Popen(["adb", ...
-1
2016-09-09T18:15:34Z
39,417,632
<p>You are just killing the adb shell session, which won't kill the running application. If you would like to kill the running Android application, you have to stop the app over the adb shell. For details have a look at this <a href="https://stackoverflow.com/questions/17829606/android-adb-stop-application-command-like...
0
2016-09-09T18:23:53Z
[ "android", "python", "subprocess", "adb", "pexpect" ]
convert string to other type in python
39,417,539
<p>Hi everyone I have a simple problem but I don't find the solution, I have a function that returns something like that</p> <pre><code>[[4, 'adr', 0, 0, 1, '2016-04-05T13:00:01'], [115, 'adr', 0, 0, 1, '2016-04-05T14:00:01'], [226, 'adr', 0, 0, 1, '2016-04-05T15:00:01'], [337, 'adr', 0, 0, 1, '2016-04-05T16:00:01']] ...
0
2016-09-09T18:17:38Z
39,417,606
<p>The easiest, and most dangerous, solution would be to do</p> <pre><code>eval( data ) </code></pre> <p>Dangerous because you have to trust there is nothing malicious in that data.</p> <p>You could write a regex to verify that the string/data is properly formatted; not knowing what that format is, I can't help with...
1
2016-09-09T18:22:13Z
[ "python", "python-2.7" ]