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
In python how can I add a special case to a regex function?
39,693,490
<p>Say for example I want to remove the following strings from a string: </p> <pre><code>remove = ['\\u266a','\\n'] </code></pre> <p>And I have regex like this:</p> <pre><code>string = re.sub('[^A-Za-z0-9]+', '', string) </code></pre> <p>How can I add "remove" to my regex function?</p>
1
2016-09-26T01:25:12Z
39,693,578
<p>No need for a special case. Just call re.sub in a loop for each member of your remove list.</p>
0
2016-09-26T01:37:22Z
[ "python", "regex" ]
Import Error: No Module named common
39,693,497
<p>My folder structure in pycharm is as follows.</p> <pre><code>--python --concepts --common --myds.py --__init__.py --data_structures --test_ds.py </code></pre> <p>I have the following line in <code>test_ds.py</code></p> <pre><code>from common import my_ds </code></pre> <p>I get the fol...
0
2016-09-26T01:26:00Z
39,693,728
<p>You need to make your common folder into a python package in order to import it in python. I think you've tried to do it and created <code>init</code> file in your <code>common</code> folder but actually it must be <code>__init__.py</code>. Rename it like this and then your package will be visible to python.</p> <p...
0
2016-09-26T02:02:47Z
[ "python", "python-3.x", "pycharm" ]
Import Error: No Module named common
39,693,497
<p>My folder structure in pycharm is as follows.</p> <pre><code>--python --concepts --common --myds.py --__init__.py --data_structures --test_ds.py </code></pre> <p>I have the following line in <code>test_ds.py</code></p> <pre><code>from common import my_ds </code></pre> <p>I get the fol...
0
2016-09-26T01:26:00Z
39,693,734
<p>Try <code>from ..common import my_ds</code>. Also make sure that it has an <code>__init__.py</code> file in that directory (not required but it's good practice).</p> <p>As for the <code>..</code> they indicate that you're importing from the parent package to the one you're currently on.</p>
1
2016-09-26T02:03:19Z
[ "python", "python-3.x", "pycharm" ]
How to use the __init__ from the main object class in an inherited class?
39,693,512
<p>I have a program that I will be using inheritance in:</p> <pre><code>class Templates(object): def __init__(self, esd_user, start_date, summary, ticket_number, email_type): self.esd = esd_user self.strt_day = start_date self.sum = summary self.ticket = ticket_num...
0
2016-09-26T01:27:34Z
39,693,535
<p>If you don't need to add anything to the <code>__init__</code> for the subclasses, just don't implement it, and they'll inherit it automatically. Otherwise, you're a little off for cases where you need to do further initialization:</p> <pre><code>class PendingEmail(Templates): def __init__(self): super...
1
2016-09-26T01:31:14Z
[ "python", "python-2.7", "oop", "inheritance" ]
How to use the __init__ from the main object class in an inherited class?
39,693,512
<p>I have a program that I will be using inheritance in:</p> <pre><code>class Templates(object): def __init__(self, esd_user, start_date, summary, ticket_number, email_type): self.esd = esd_user self.strt_day = start_date self.sum = summary self.ticket = ticket_num...
0
2016-09-26T01:27:34Z
39,693,538
<p>Like any other method, classes automatically inherit <code>__init__</code> from their superclasses. What you want to achieve is already happening.</p>
0
2016-09-26T01:31:50Z
[ "python", "python-2.7", "oop", "inheritance" ]
How to use the __init__ from the main object class in an inherited class?
39,693,512
<p>I have a program that I will be using inheritance in:</p> <pre><code>class Templates(object): def __init__(self, esd_user, start_date, summary, ticket_number, email_type): self.esd = esd_user self.strt_day = start_date self.sum = summary self.ticket = ticket_num...
0
2016-09-26T01:27:34Z
39,693,542
<p>If you don't define an <code>__init__</code> method in your subclass, your base class <code>__init__</code> will still get called. If you define one, then you need to explicitly call it like you have described before/after any other actions you need. The first argument to super is the class where it is being called....
0
2016-09-26T01:32:04Z
[ "python", "python-2.7", "oop", "inheritance" ]
I have been using pyimgur to upload pictures and I would like to know how to delete them
39,693,682
<p>I have been using this code to upload pictures to imgur:</p> <pre><code>import pyimgur CLIENT_ID = "Your_applications_client_id" PATH = "A Filepath to an image on your computer" im = pyimgur.Imgur(CLIENT_ID) uploaded_image = im.upload_image(PATH, title="Uploaded with PyImgur") print(uploaded_image.title) print(up...
0
2016-09-26T01:55:01Z
39,693,789
<p>You can delete your images using the method <code>remove_images(list_images)</code>, <code>list_images</code> are the images we want to remove from the album, this method deletes images but no the album itself . If you want delete the album you can use <code>delete()</code> method. You can read the <a href="http://p...
0
2016-09-26T02:12:45Z
[ "python", "imgur" ]
Most efficient way to iterate through list of lists
39,693,722
<p>I'm currently collecting data from quandl and is saved as a list of lists. The list looks something like this (Price data):</p> <pre><code>['2', 1L, datetime.date(1998, 1, 2), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), '82.1900', '83.6200', '81.7500', '83.500...
0
2016-09-26T02:01:36Z
39,693,850
<p>Don't create a new list - rather, edit the old list in-place:</p> <pre><code>import math def screenData(L): for subl in L: for i,n in enumerate(subl): if math.isnan(n): subl[i] = 0 </code></pre> <p>The only way I can think of, to make this faster, would be with multiprocessing</p>
2
2016-09-26T02:22:38Z
[ "python", "performance", "list", "mysql-python", null ]
Most efficient way to iterate through list of lists
39,693,722
<p>I'm currently collecting data from quandl and is saved as a list of lists. The list looks something like this (Price data):</p> <pre><code>['2', 1L, datetime.date(1998, 1, 2), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), '82.1900', '83.6200', '81.7500', '83.500...
0
2016-09-26T02:01:36Z
39,694,794
<p>I haven't timed it but have you tried using <a href="https://docs.python.org/3.5/tutorial/datastructures.html#nested-list-comprehensions" rel="nofollow">nested list comprehension</a> with <a href="https://docs.python.org/3.5/reference/expressions.html#conditional-expressions" rel="nofollow">conditional expressions</...
2
2016-09-26T04:34:00Z
[ "python", "performance", "list", "mysql-python", null ]
Most efficient way to iterate through list of lists
39,693,722
<p>I'm currently collecting data from quandl and is saved as a list of lists. The list looks something like this (Price data):</p> <pre><code>['2', 1L, datetime.date(1998, 1, 2), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), datetime.datetime(2016, 9, 26, 1, 35, 3, 830563), '82.1900', '83.6200', '81.7500', '83.500...
0
2016-09-26T02:01:36Z
39,695,156
<p>how about this</p> <pre><code>import math def clean_nan(data_list,value=0): for i,x in enumerate(data_list): if math.isnan(x): data_list[i] = value return data_list </code></pre> <p>(the return is optional, as the modification was made in-place, but it is needed if used with <code>map...
0
2016-09-26T05:19:50Z
[ "python", "performance", "list", "mysql-python", null ]
VPython: File Read Error
39,693,881
<p>I'm using VIDLE and VPython. All I'm trying to do is read the values from "weather.txt." The values that I need to read start on the second line of the file, so I need to skip the first line. Here's a snippet of my code:</p> <pre><code>try: filename = "‪‪‪C:\Users\Ashley\Documents\weather.txt" except (...
1
2016-09-26T02:27:21Z
39,693,915
<p>Looks like you need to escape backslashes in the file path. It would also appear that there are invisible unicode characters at the start of your string.</p> <p>Try using: <code>filename = 'C:\\Users\\Ashley\\Documents\\weather.txt'</code></p> <p>Also, the first <code>try: except:</code> block isn't required, ther...
1
2016-09-26T02:32:42Z
[ "python" ]
VPython: File Read Error
39,693,881
<p>I'm using VIDLE and VPython. All I'm trying to do is read the values from "weather.txt." The values that I need to read start on the second line of the file, so I need to skip the first line. Here's a snippet of my code:</p> <pre><code>try: filename = "‪‪‪C:\Users\Ashley\Documents\weather.txt" except (...
1
2016-09-26T02:27:21Z
39,693,934
<p>The key is in the junk that you see in the error message which was prepended to your filename:</p> <pre><code>'\xe2\x80\xaa\xe2\x80\xaa\xe2\x80\xaaC:\Users\Ashley\Documents\weather.txt' </code></pre> <p>You can investigate what this means at a Python prompt:</p> <pre><code>&gt;&gt;&gt; '\xe2\x80\xaa\xe2\x80\xaa\x...
0
2016-09-26T02:35:48Z
[ "python" ]
Batch script to execute a Python script multiple times
39,693,902
<p>I need to run a Python script N times, so I created the following script:</p> <pre><code>@ECHO OFF cd PATH_TO_SCRIPT @set port=5682 set /P INPUT=Number of servers: FOR /L %%I IN (1, 1, %INPUT%) DO ( @set /a newport=%port%+1 start cmd /k &gt; start python server.py -i 192.168.1.2 -p %newport% ) pause </code...
1
2016-09-26T02:31:15Z
39,694,287
<pre><code>@ECHO OFF setlocal enabledelayedexpansion cd PATH_TO_SCRIPT set port=5682 set /P INPUT=Number of servers: set /a newport=%port% FOR /L %%I IN (1, 1, %INPUT%) DO ( set /a newport+=1 start cmd /k &gt; start python server.py -i 192.168.1.2 -p !newport! ) pause </code></pre> <p>Logic error : On each ite...
4
2016-09-26T03:28:29Z
[ "python", "windows", "batch-file" ]
Batch script to execute a Python script multiple times
39,693,902
<p>I need to run a Python script N times, so I created the following script:</p> <pre><code>@ECHO OFF cd PATH_TO_SCRIPT @set port=5682 set /P INPUT=Number of servers: FOR /L %%I IN (1, 1, %INPUT%) DO ( @set /a newport=%port%+1 start cmd /k &gt; start python server.py -i 192.168.1.2 -p %newport% ) pause </code...
1
2016-09-26T02:31:15Z
39,694,506
<p>As pointed out already, in your FOR loop, %newport% resolves to [empty] upon execution. It's because newport isn't set until AFTER cmd resolves %newport%, since the entire FOR loop is one statement. In other words, %newport% gets resolved before the commands in the loop are executed, which means it's not set yet, an...
1
2016-09-26T03:58:50Z
[ "python", "windows", "batch-file" ]
How to plot a defined function against one of its arguments in Python
39,693,925
<pre><code>from __future__ import division import numpy as np import matplotlib.pyplot as plt def f(x, t): #function for x'(t) = f(x,t) return -x def exact(t): #exact solution return np.exp(-t) def Rk4(x0, t0, dt): #Runge-Kutta Fourth Order Approximation t = np.arange(0, 1+dt, dt) n ...
1
2016-09-26T02:33:58Z
39,694,320
<p>The problem is that your return value <code>E</code> is not a single number, but a numpy array.</p> <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html" rel="nofollow">Vectorizing </a>many arrays would give you a list, vectorizing many numpy arrays does not work here.</p> <p>To com...
1
2016-09-26T03:34:32Z
[ "python", "numpy", "matplotlib", "runge-kutta" ]
Global Name 'q' not Defined - Python
39,694,066
<p>I have a program like :</p> <pre><code>class ABC: q = {} def update: self.state = (xx,xx) global q if self.state in q: // do something </code></pre> <p>I am getting the error :</p> <blockquote> <p>"NameError: global name 'q' is not defined"</p> </blockquote> <p>Im ...
0
2016-09-26T02:55:49Z
39,694,083
<p><code>q</code> isn't being declared as a global variable here - it's being declared as a class variable of class <code>ABC</code>.</p> <p>If you want <code>q</code> to be global, you should define it before you start declaring the class.</p>
0
2016-09-26T02:58:20Z
[ "python", "nameerror" ]
Global Name 'q' not Defined - Python
39,694,066
<p>I have a program like :</p> <pre><code>class ABC: q = {} def update: self.state = (xx,xx) global q if self.state in q: // do something </code></pre> <p>I am getting the error :</p> <blockquote> <p>"NameError: global name 'q' is not defined"</p> </blockquote> <p>Im ...
0
2016-09-26T02:55:49Z
39,694,118
<p>You can move <em>q</em> outside of the class:</p> <pre><code>q = {} class ABC: def update: self.state = (xx,xx) global q if self.state in q: # do something pass </code></pre> <p>or you can reference <em>q</em> as a class variable:</p> <pre><code>class ABC: ...
2
2016-09-26T03:04:34Z
[ "python", "nameerror" ]
This code scales each leaf by a factor, but i dont understand one part of the function
39,694,087
<pre><code>#checking if node is a leaf def is_leaf(item): return type(item) != tuple #performing function on every element in sequence def map(fn, seq): if seq == (): return () else: return (fn(seq[0]), ) + map(fn, seq[1:]) #scaling each leaf by factor def scale_tree(tree, factor): d...
1
2016-09-26T02:58:49Z
39,694,128
<p>Have a look at the <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow">definition</a> of the map function.</p> <p><code>map(scale_func, tree)</code> will apply every item of tree to the function <code>scale_func</code>.</p> <p>So the argument <code>subtree</code>will be sequentially assig...
2
2016-09-26T03:06:01Z
[ "python" ]
This code scales each leaf by a factor, but i dont understand one part of the function
39,694,087
<pre><code>#checking if node is a leaf def is_leaf(item): return type(item) != tuple #performing function on every element in sequence def map(fn, seq): if seq == (): return () else: return (fn(seq[0]), ) + map(fn, seq[1:]) #scaling each leaf by factor def scale_tree(tree, factor): d...
1
2016-09-26T02:58:49Z
39,694,152
<p>From a quick read, scale_tree is calling map on its return statement with scale_func and the argument <code>tree</code> as parameters. The map function will then call the function passed as the first argument (scale_func in this case) with the sequence passed as a second argument (tree in this case) as an argument t...
0
2016-09-26T03:08:48Z
[ "python" ]
Accessing property of dynamically created QStandardItems in PyQt5
39,694,111
<p>I'm having a problem determining whether or not the checkboxes that are dynamically created have been checked or unchecked by the user in a simple GUI I've created.</p> <p>I've adapted the relevant code and pasted it below. Although it may be easy to just create and name 4 QStandardItems, I'm dealing with many list...
0
2016-09-26T03:03:52Z
39,694,396
<p>It seems you want to get notified when the checkState of a item has been changed.</p> <p>In my opinion, there are possible two ways.</p> <p>First way, QModel will emit "dataChanged" to refresh the view, so you can connect the signal which means the checkState of a item might be changed.</p> <pre><code>model.dataC...
0
2016-09-26T03:44:37Z
[ "python", "pyqt", "pyqt5" ]
Accessing property of dynamically created QStandardItems in PyQt5
39,694,111
<p>I'm having a problem determining whether or not the checkboxes that are dynamically created have been checked or unchecked by the user in a simple GUI I've created.</p> <p>I've adapted the relevant code and pasted it below. Although it may be easy to just create and name 4 QStandardItems, I'm dealing with many list...
0
2016-09-26T03:03:52Z
39,695,425
<p>If you keep a reference to the list (or the model), you can search for the items by their text, and then get their check-state:</p> <pre><code>def print_action(self): model = self.list.model() for text in 'summer', 'autumn', 'winter', 'spring': items = model.findItems(text) if items: ...
0
2016-09-26T05:44:16Z
[ "python", "pyqt", "pyqt5" ]
Javascript regexp with unicode and punctuation
39,694,155
<p>I have the follow test case for splitting unicoded words but don't know how to do in it javascript.</p> <pre><code>describe("garden: utils", () =&gt; { it("should split correctly", () =&gt; { assert.deepEqual(segmentation('Hockey is a popular sport in Canada.'), [ 'Hockey', 'is', 'a', 'popular', 'sport'...
2
2016-09-26T03:09:13Z
39,694,445
<p>Pretty complicated given there's no negative look-behind assertions in JavaScript RegExp, and Unicode support is not official yet (only supported in Firefox by a flag at the moment). This uses a library (XRegExp) to handle the unicode classes. If you need the full normal regular expression, <strong><em>it's huge</em...
3
2016-09-26T03:50:29Z
[ "javascript", "python", "regex", "unicode", "punctuation" ]
Javascript regexp with unicode and punctuation
39,694,155
<p>I have the follow test case for splitting unicoded words but don't know how to do in it javascript.</p> <pre><code>describe("garden: utils", () =&gt; { it("should split correctly", () =&gt; { assert.deepEqual(segmentation('Hockey is a popular sport in Canada.'), [ 'Hockey', 'is', 'a', 'popular', 'sport'...
2
2016-09-26T03:09:13Z
39,694,457
<p>I found the answer but is is complex. Does anyone have another simple answer for this</p> <pre><code>module.exports = (string) =&gt; { const segs = string.split(/(\.{2,}|!|"|#|$|%|&amp;|'|\(|\)|\*|\+|,|-|\.|\/|:|;|&lt;|=|&gt;|\?|¿|@|[|]|\\|^|_|`|{|\||}|~| )/); return segs.filter((seg) =&gt; seg.trim() !== "")...
1
2016-09-26T03:53:05Z
[ "javascript", "python", "regex", "unicode", "punctuation" ]
Using variables as arguments for a command called by subprocess in Python 2.7.x
39,694,163
<p>I'm trying to create a basic function that will pass a filename and arguments to a program using <code>call()</code> from the <code>subprocess</code> module. The filename and arguments are variables. When I use <code>call()</code> it takes the variables but the called program reads their strings with <code>"</code> ...
0
2016-09-26T03:10:33Z
39,694,356
<p>Well, yes. That's exactly what the documentation says it does. Create and pass a list containing the command and all arguments instead.</p>
1
2016-09-26T03:40:35Z
[ "python", "python-2.7" ]
Using variables as arguments for a command called by subprocess in Python 2.7.x
39,694,163
<p>I'm trying to create a basic function that will pass a filename and arguments to a program using <code>call()</code> from the <code>subprocess</code> module. The filename and arguments are variables. When I use <code>call()</code> it takes the variables but the called program reads their strings with <code>"</code> ...
0
2016-09-26T03:10:33Z
39,694,774
<p><strong>EDIT</strong>: The solution suggested by <a href="http://stackoverflow.com/users/1248008/jonas-wielicki">Jonas Wielicki</a> is to make sure every single string that would normally be separated by spaces in shell syntax is listed as a separate item; That way <code>call()</code> will read them properly. <code>...
1
2016-09-26T04:32:41Z
[ "python", "python-2.7" ]
Convert string column to integer
39,694,192
<p>I have a dataframe like below</p> <pre><code> a b 0 1 26190 1 5 python 2 5 580 </code></pre> <p>I want to make column <code>b</code> to host only integers, but as you can see <code>python</code> is not int convertible, so I want to delete the row at index <code>1</code>. My expected out put has to...
2
2016-09-26T03:15:04Z
39,694,974
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html" rel="nofollow"><code>to_numeric</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.notnull.html" rel="nofollow"><code>notnull</code></a> and filter by <a href="http://pandas.py...
1
2016-09-26T04:59:13Z
[ "python", "string", "pandas", "numpy", "int" ]
Convert string column to integer
39,694,192
<p>I have a dataframe like below</p> <pre><code> a b 0 1 26190 1 5 python 2 5 580 </code></pre> <p>I want to make column <code>b</code> to host only integers, but as you can see <code>python</code> is not int convertible, so I want to delete the row at index <code>1</code>. My expected out put has to...
2
2016-09-26T03:15:04Z
39,700,526
<p>This should work</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame({'a' : [1, 5, 5], 'b' : [26190, 'python', 580]}) df a b 0 1 26190 1 5 python 2 5 580 df['b'] = np.where(df.b.str.contains('[a-z]') == True, np.NaN, df.b) df a b 0 1 26190 1 5 ...
0
2016-09-26T10:32:40Z
[ "python", "string", "pandas", "numpy", "int" ]
Difference between single and double bracket Numpy array?
39,694,318
<p>What is the difference between these two numpy objects?</p> <pre><code>import numpy as np np.array([[0,0,0,0]]) np.array([0,0,0,0]) </code></pre>
-2
2016-09-26T03:34:28Z
39,694,589
<p>When you defined an array with two brackets, what you were really doing was declaring an array with an array with 4 0's inside. Therefore, if you wanted to access the first zero you would be accessing <code>your_array[0][0]</code> while in the second array you would just be accessing <code>your array[0]</code>. Per...
1
2016-09-26T04:08:52Z
[ "python", "numpy" ]
Difference between single and double bracket Numpy array?
39,694,318
<p>What is the difference between these two numpy objects?</p> <pre><code>import numpy as np np.array([[0,0,0,0]]) np.array([0,0,0,0]) </code></pre>
-2
2016-09-26T03:34:28Z
39,694,829
<pre><code>In [71]: np.array([[0,0,0,0]]).shape Out[71]: (1, 4) In [72]: np.array([0,0,0,0]).shape Out[72]: (4,) </code></pre> <p>The former is a 1 x 4 two-dimensional array, the latter a 4 element one dimensional array.</p>
2
2016-09-26T04:38:03Z
[ "python", "numpy" ]
Difference between single and double bracket Numpy array?
39,694,318
<p>What is the difference between these two numpy objects?</p> <pre><code>import numpy as np np.array([[0,0,0,0]]) np.array([0,0,0,0]) </code></pre>
-2
2016-09-26T03:34:28Z
39,707,119
<p>The difference between single and double brackets starts with lists:</p> <pre><code>In [91]: ll=[0,1,2] In [92]: ll1=[[0,1,2]] In [93]: len(ll) Out[93]: 3 In [94]: len(ll1) Out[94]: 1 In [95]: len(ll1[0]) Out[95]: 3 </code></pre> <p><code>ll</code> is a list of 3 items. <code>ll1</code> is a list of 1 item; that ...
0
2016-09-26T15:47:01Z
[ "python", "numpy" ]
connect Python to MYSQL, obtain SP500 symbols
39,694,339
<p>The code is below:</p> <pre><code>#!/usr/bin/python # -*- coding: utf-8 -*- # insert_symbols.py #table name should be 's_master', password should be '*******', user name should be 's_user' from __future__ import print_function import datetime from math import ceil import bs4 import MySQLdb as mdb import request...
0
2016-09-26T03:37:37Z
39,695,291
<p>I think you don't create the table correctly.I write a sql file <code>init.sql</code>, and import it to the mysql database by using the following command:</p> <pre><code>mysql -u root -p &lt; init.sql </code></pre> <p>This is the content of the init.sql</p> <pre><code>create database if not exists s_master defaul...
0
2016-09-26T05:31:43Z
[ "python", "mysql", "web-scraping", "beautifulsoup" ]
loop through numpy arrays, plot all arrays to single figure (matplotlib)
39,694,357
<p>the functions below each plot a single numpy array<br /> plot1D, plot2D, and plot3D take arrays with 1, 2, and 3 columns, respectively</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def plot1D(data): x=np.arange(len(data)) plot2D(np.hstack((np....
1
2016-09-26T03:40:44Z
39,696,016
<p>To plot multiple data sets on the same axes, you can do something like this:</p> <pre><code>def plot2D_list(data,*args,**kwargs): # type: (object) -&gt; object #if 2d, make a scatter n = len(data) fig,ax = plt.subplots() #create figure and axes for i in range(n): #now plot data set i ...
0
2016-09-26T06:28:36Z
[ "python", "arrays", "numpy", "matplotlib" ]
Plot multivariate data in Python
39,694,360
<p>I have a data of human activity performing various leg movements. The data consists of X, Y, Z gyro sensor orientation. Data looks like below:</p> <p>Activity 1:</p> <p>timestamp, X rad/sec, y rad/sec, z rad/sec</p> <p>1474242172.0203, -0.440601, -2.377124 , -0.379635</p> <p>1474242...
0
2016-09-26T03:40:52Z
39,694,622
<p>in python, you could use <a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html" rel="nofollow">pylab</a> to plot in 3d using something like: <code>plt.plot(x_vals_list,y_vals_list,z_vals_list)</code> . If you have more than 3 dimensions you can use <a href="http://scikit-learn.org/stable/modules/generate...
1
2016-09-26T04:12:36Z
[ "python", "matplotlib", "plot", "plotly" ]
Deleting values from multiple arrays that have a particular value
39,694,363
<p>Lets say I have two arrays: <code>a = array([1,2,3,0,4,5,0])</code> and <code>b = array([1,2,3,4,0,5,6])</code>. I am interested in removing the instances where <code>a</code> and <code>b</code>are <code>0</code>. But I also want to remove the corresponding instances from both lists. Therefore what I want to end up ...
0
2016-09-26T03:41:29Z
39,694,557
<p>This is happening because when you return from np.delete, you get an array that is stored in b and a inside the loop. However, the arrays stored in the arrays variable are copies, not references. Hence, when you're updating the arrays by deleting them, it deletes with regard to the original arrays. The first loop wi...
1
2016-09-26T04:05:50Z
[ "python", "arrays", "numpy", "indexing" ]
Deleting values from multiple arrays that have a particular value
39,694,363
<p>Lets say I have two arrays: <code>a = array([1,2,3,0,4,5,0])</code> and <code>b = array([1,2,3,4,0,5,6])</code>. I am interested in removing the instances where <code>a</code> and <code>b</code>are <code>0</code>. But I also want to remove the corresponding instances from both lists. Therefore what I want to end up ...
0
2016-09-26T03:41:29Z
39,694,575
<p>A slow method involves operating over the whole list twice, first to build an intermediate list of indices to delete, and then second to delete all of the values at those indices:</p> <pre><code>import numpy as np a = np.array([1,2,3,0,4,5,0]) b = np.array([1,2,3,4,0,5,6]) arrays = [a, b] vals = [] for array in ...
0
2016-09-26T04:07:33Z
[ "python", "arrays", "numpy", "indexing" ]
Deleting values from multiple arrays that have a particular value
39,694,363
<p>Lets say I have two arrays: <code>a = array([1,2,3,0,4,5,0])</code> and <code>b = array([1,2,3,4,0,5,6])</code>. I am interested in removing the instances where <code>a</code> and <code>b</code>are <code>0</code>. But I also want to remove the corresponding instances from both lists. Therefore what I want to end up ...
0
2016-09-26T03:41:29Z
39,701,971
<p>Assuming both/all arrays always have the same length, you can use <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays" rel="nofollow">masks</a>:</p> <pre><code>ma = a != 0 # mask elements which are not equal to zero in a mb = b != 0 # mask elements which are not equal to ...
3
2016-09-26T11:45:48Z
[ "python", "arrays", "numpy", "indexing" ]
Deleting values from multiple arrays that have a particular value
39,694,363
<p>Lets say I have two arrays: <code>a = array([1,2,3,0,4,5,0])</code> and <code>b = array([1,2,3,4,0,5,6])</code>. I am interested in removing the instances where <code>a</code> and <code>b</code>are <code>0</code>. But I also want to remove the corresponding instances from both lists. Therefore what I want to end up ...
0
2016-09-26T03:41:29Z
39,708,622
<p>Building up on top of Christoph Terasa's answer, you can use array operations instead of for loops:</p> <pre><code>arrays = np.vstack([a,b]) # ...long list of arrays of equal length zeroind = (arrays==0).max(0) pos_arrays = arrays[:,~zeroind] # a 2d array only containing those columns where none of the lines cont...
0
2016-09-26T17:13:26Z
[ "python", "arrays", "numpy", "indexing" ]
Check for status of subprocess to kill audio playback in python
39,694,424
<p>Im currently using sox to apply effects to an audio file and play the file back. Currently I have the code set to create a new subprocess to play the file when button 1 is pressed and to kill the process when button 2 is pressed. </p> <p>What I want to do is change it so that if Button 1 is pressed multiple times i...
0
2016-09-26T03:47:59Z
39,695,058
<p>Use <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.poll" rel="nofollow"><code>p.poll()</code></a> to check if the process is still running.</p> <p>The code will look something like this (untested):</p> <pre><code>def Button_1(): if p.poll(): p.send_signal(signal.SIGNIT) ...
0
2016-09-26T05:08:07Z
[ "python", "subprocess", "kill", "sox" ]
Python requests caching authentication headers
39,694,438
<p>I have used python's requests module to do a POST call(within a loop) to a single URL with varying sets of data in each iteration. I have already used session reuse to use the underlying TCP connection for each call to the URL during the loop's iterations. </p> <p>However, I want to further speed up my processing b...
0
2016-09-26T03:49:24Z
39,698,040
<p>You can:</p> <ol> <li>do it as you described (if you want to make it faster then you can run it using multiprocessing) and e.g. add headers to session, not request.</li> <li>modify target server and allow to send one post request with multiple data (so you're going to limit time spent on connecting, etc)</li> <li>d...
0
2016-09-26T08:31:56Z
[ "python", "python-requests", "cache-control" ]
math.cos(x) not returning correct value?
39,694,465
<p>I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried:</p> <pre><code>import math print math.cos(math.degrees(-20)) </code></pre> <p>This o...
0
2016-09-26T03:54:08Z
39,694,480
<p>You need to input in radians, so do </p> <pre><code>math.cos(math.radians(-20)) </code></pre> <p>math.radians(-20) converts -20 degrees to radians.</p>
0
2016-09-26T03:56:01Z
[ "python", "math", "trigonometry" ]
math.cos(x) not returning correct value?
39,694,465
<p>I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried:</p> <pre><code>import math print math.cos(math.degrees(-20)) </code></pre> <p>This o...
0
2016-09-26T03:54:08Z
39,694,498
<p><code>math.degrees</code> takes a number of radians and <em>produces</em> a number of degrees. You need the opposite conversion - you have a number of degrees, and you need to produce a number of radians you can pass to <code>math.cos</code>. You need <code>math.radians</code>:</p> <pre><code>math.cos(math.radians(...
0
2016-09-26T03:57:57Z
[ "python", "math", "trigonometry" ]
math.cos(x) not returning correct value?
39,694,465
<p>I just started using python, and am having difficulty with a very basic program. I want to calculate the cosine of -20 degrees. It is my understanding that the default value is in radians, so this is the following code i tried:</p> <pre><code>import math print math.cos(math.degrees(-20)) </code></pre> <p>This o...
0
2016-09-26T03:54:08Z
39,694,521
<p>Per the <a href="https://docs.python.org/3.5/library/math.html#angular-conversion" rel="nofollow">Python documentation</a>:</p> <blockquote> <p><strong><code>math.degrees(x)</code></strong></p> <p>Convert angle <em>x</em> from radians to degrees.</p> </blockquote> <p>That means you are attempting to convert...
3
2016-09-26T04:00:20Z
[ "python", "math", "trigonometry" ]
Function returning false when it should be returning True. Encoding issue?
39,694,538
<p>I am currently working on a validation function that returns <code>True</code> or <code>False</code> based on an expression (if statement). The header is base64 decoded and then <code>json.loads</code> is used to convert it into a dict. Here is the method:</p> <pre><code> @staticmethod def verify(rel): ...
1
2016-09-26T04:02:41Z
39,695,638
<p>The issue here is your use of the <code>is</code> operator to check the equality of the strings. The <code>is</code> operator checks if its two arguments refer to the same object, which is not the behavior you want here. To check if the strings are equal, use the equality operator:</p> <pre><code> def verify(rel): ...
2
2016-09-26T06:01:59Z
[ "python", "json", "base64" ]
GET and PUT operation on HTTPS (with certificate error) in python
39,694,594
<p>I'm very new to python. The job assigned to me was to perform a put and get operation on one of the products web ui using python. I tried with the following code,</p> <pre><code>import urllib2 import ssl try: response = urllib2.urlopen('https://the product web ui address') print 'response headers: "%s"' ...
0
2016-09-26T04:09:20Z
39,694,768
<p>I got it. </p> <pre><code>import requests import sys try: r = requests.get("https://web ui address",verify=False) data = r.content f = open('myfile.xml','w') f.write(data) f.close() print "Status Code returned : " ,r.status_code except: print "Error Occured ",sys.exc_info()[0] </code><...
0
2016-09-26T04:32:20Z
[ "python", "ssl", "get", "httprequest", "put" ]
Running a previous line?
39,694,636
<p>i have a while true so that if there is not enough seats on the plane you can't book a flight, but i want to go back to a previous line of code (line 8) because when i do this:</p> <pre><code>while True: if b == maxpass and booking == "b" or booking == "book": print ("Sorry but the flight you want is cu...
0
2016-09-26T04:14:20Z
39,694,769
<p>It's not 100% clear what you are asking, but I suspect you want something like this:</p> <pre><code>class MyOwnError(Exception): def __init__(self, message): self.message = message def __str__(self): return repr(self.message) while flight != "X": try: seatsremain = 68 - b ...
1
2016-09-26T04:32:21Z
[ "python" ]
Building Fortran extension for Python 3.5 or C extension for 2.7
39,694,646
<p>I have a Python 2.7 project that has thus far been using gfortran and MinGW to build extensions. I use MinGW because it seems to support write statements and allocatable arrays in the Fortran code while MSVC does not.</p> <p>There is another project I would like to incorporate into my own (Netgen) but it is current...
2
2016-09-26T04:15:04Z
39,716,307
<p>I built Boost.Python libraries 1.61.0 from source for Python 2.7 using VC 14.0. Then used those in the build process for Netgen (again using VC 14.0) and pointed to the Python 2.7 library and include directories (as opposed to Python 3.5). This has thus far worked in Python 2.7 with my existing code.</p>
0
2016-09-27T05:01:23Z
[ "python", "c++", "boost", "fortran", "gfortran" ]
How to modify custom.xml within docx using python
39,694,652
<p>I've been using python-docx to programmatically change parts of a word document (*.docx) that needs to be updated monthly. My problem now lies with editing custom properties in the template, specifically the 'Date Completed' property.</p> <p><a href="http://i.stack.imgur.com/dAzdA.png" rel="nofollow">Custom templat...
0
2016-09-26T04:15:56Z
39,697,415
<p>This functionality hasn't been implemented yet. There's a feature request open for it and one user has done some work on it you can find linked to from there.</p> <p><a href="https://github.com/python-openxml/python-docx/issues/91" rel="nofollow">https://github.com/python-openxml/python-docx/issues/91</a></p> <p>I...
0
2016-09-26T07:54:29Z
[ "python", "xml", "lxml", "elementtree", "python-docx" ]
How to delete and return values from cursor in python
39,694,669
<p>PostgreSQL allows you to delete rows and return values of columns of the deleted rows using this syntax:</p> <pre><code>DELETE FROM [table_name] RETURNING [column_names] </code></pre> <p>I would like to use this syntax in Python with using <a href="https://github.com/psycopg/psycopg2" rel="nofollow">psycopg2</a> l...
0
2016-09-26T04:18:41Z
39,699,523
<p>You query runs inside of transaction (but it's better to double check that <code>autocommit</code> is set to False), that means that all the changes you make are visible only for you (actually, it depends on other transactions settings) until you commit these changes.</p> <p>Both options work in that case:</p> <pr...
0
2016-09-26T09:45:08Z
[ "python", "postgresql", "cursor", "psycopg2", "delete-operator" ]
Queryset filter with three-deep nested models (multiple one-to-many relationships)
39,694,670
<p>I'm trying to figure out how to filter some queries in Django with my models setup something like this:</p> <pre><code>class Team(models.Model): name = models.CharField() class TeamPosition(models.Model): description = models.CharField() team = models.ForeignKey(Team) class Player(models.Model): t...
2
2016-09-26T04:18:59Z
39,694,742
<p><strike>One question before answering: Is the line <code>carmodel = models.ForeignKey(Model)</code> ok? or should it be <code>ForeignKey(CarModel)</code> instead?</strike></p> <p>Try this query (this should give you all CarCompany objects whose CarModel's ModelYear's <code>last_availability</code> date is in the fu...
0
2016-09-26T04:29:10Z
[ "python", "django", "database" ]
linked list output not expected in Python 2.7
39,695,046
<p>Implement a linked list and I expect output to be <code>0, -1, -2, -3, ... etc.</code>, but it is <code>-98, -98, -98, -98, ... etc.</code>, wondering what is wrong in my code? Thanks.</p> <pre><code>MAXSIZE = 100 freeListHead = None class StackNode: def __init__(self, value, nextNode): self.value = va...
2
2016-09-26T05:06:47Z
39,695,130
<p>This is the problem:</p> <pre class="lang-py prettyprint-override"><code># initialization for nodes and link them to be a free list nodes=[StackNode(-1, None)] * MAXSIZE </code></pre> <p>When you use the multiply operator, it will create multiple <em>references</em> to the <strong>same</strong> object, as noted <a...
10
2016-09-26T05:16:27Z
[ "python", "python-2.7" ]
Calling a method that have return value in Python
39,695,167
<p>I'm new to python and came into this piece of code. From my previous programming knowledge, I'm assuming this method should return something(<code>results</code>). But why do some statements like <code>self.children[0].query(rect, results)</code> don't assign the return value to any variable while recursively callin...
1
2016-09-26T05:21:18Z
39,695,385
<p>You're right that the <code>query</code> function does return <code>results</code>, but it also <em>modifies</em> <code>results</code> on this line:</p> <pre><code>results.add(node.item) </code></pre> <p>A parameter used in this was is sometimes described as an "output parameter".</p> <p><code>query</code> is not...
2
2016-09-26T05:40:04Z
[ "python", "python-2.7", "python-3.x" ]
How print to printer with Popen and GUI tkinter
39,695,198
<p>I use code from <a href="http://stackoverflow.com/questions/12723818/print-to-standard-printer-from-python">this question</a> for printing to thermal EPSON TM-T82 printer but when I modified it with <code>tkinter</code> and <code>mainloop()</code> python not direcly printout my data until I close my layout GUI. I wa...
0
2016-09-26T05:23:52Z
39,695,826
<p>You are experiencing buffering. The <code>write</code> will write to a buffer which is not actually passed on to <code>lpr</code> until it fills up or you explicitly flush it.</p> <p>Running <code>lpr.communicate()</code> will flush it and allow <code>lpr</code> to run to completion.</p> <pre><code>lpr = subproce...
0
2016-09-26T06:15:12Z
[ "python", "printing", "tkinter" ]
What is the easiest way to get a list of the keywords in a string?
39,695,240
<p>For example:</p> <pre><code>str = 'abc{text}ghi{num}' </code></pre> <p>I can then do</p> <pre><code>print(str.format(text='def',num=5)) &gt; abcdefghi5 </code></pre> <p>I would like to do something like</p> <pre><code>print(str.keywords) # function does not exist &gt; ['text','num'] </code></pre> <p>What is th...
1
2016-09-26T05:27:32Z
39,695,322
<p>Check out the <a href="https://docs.python.org/3.5/library/string.html#string.Formatter" rel="nofollow"><code>string.Formatter</code> class</a>:</p> <pre><code>&gt;&gt;&gt; import string &gt;&gt;&gt; text = 'abc{text}ghi{num}' &gt;&gt;&gt; [t[1] for t in string.Formatter().parse(text)] ['text', 'num'] </code></pre>...
3
2016-09-26T05:34:27Z
[ "python", "string", "python-3.x", "formatting" ]
How do I find the rates TP, TN, FP, FN and measure the quality of segmented algorithm?
39,695,241
<p>Currently I am implementing a system that counts the number of passengers crossing a line of interest in a subway station. To measure the quality of the segmentation algorithm, I installed a video camera on the ceiling of the subway station and I recorded a video of 13 seconds.</p> <p>The video of 13 seconds contai...
0
2016-09-26T05:27:37Z
39,697,223
<p>The TP, TN, FP, FN in measure the quality of comparison between ground truth images and the output of your system. In your project you need to compare number of people who crossing a line and the computer by your program. </p>
0
2016-09-26T07:42:40Z
[ "python", "opencv", "computer-vision", "video-processing", "precision-recall" ]
How do I find the rates TP, TN, FP, FN and measure the quality of segmented algorithm?
39,695,241
<p>Currently I am implementing a system that counts the number of passengers crossing a line of interest in a subway station. To measure the quality of the segmentation algorithm, I installed a video camera on the ceiling of the subway station and I recorded a video of 13 seconds.</p> <p>The video of 13 seconds contai...
0
2016-09-26T05:27:37Z
39,739,458
<p>You definitely have to manually tag each time a man is crossing the line. This part is crucial in order to be able to evaluate your algorithm correctly. </p> <p>I suggest you create a groundtruth file which list all frame indices when someone cross the line. Your algorithm output should be of the same type - frame ...
1
2016-09-28T06:22:53Z
[ "python", "opencv", "computer-vision", "video-processing", "precision-recall" ]
confusion about a python recursion function
39,695,401
<p>I got a <code>print_backward</code> function code online, but I am so confusing about how it works and its output. </p> <p>The below is my code.</p> <pre><code>def print_backward(num): if num == 10: return num += 1 print(num) print_backward(num) print("yeah") print(num) prin...
0
2016-09-26T05:41:52Z
39,695,439
<p>On the first runs, the code does not go further than the inner call to <code>print_backward(num)</code>, that is 4 times (like an infinite recursion)</p> <p>When the argument reaches 10, all the functions return and it goes further, printing the original <code>num</code>+1 with which they were called.</p> <p>The h...
0
2016-09-26T05:45:51Z
[ "python", "recursion" ]
confusion about a python recursion function
39,695,401
<p>I got a <code>print_backward</code> function code online, but I am so confusing about how it works and its output. </p> <p>The below is my code.</p> <pre><code>def print_backward(num): if num == 10: return num += 1 print(num) print_backward(num) print("yeah") print(num) prin...
0
2016-09-26T05:41:52Z
39,695,484
<p>The function calling happens through stack. </p> <p>You call print_backward on 6. So stack will have 6. <br> Now you call it on 7 ---> So stack has 6,7 where 7 is top. <br> Now you call it on 8 ----> So stack is 6,7,8 <br> Now on 9, So stack is 6,7,8,9 <br> Now on 10, So stack is 6,7,8,9,10. <br></p> <p>Now when f...
0
2016-09-26T05:49:31Z
[ "python", "recursion" ]
confusion about a python recursion function
39,695,401
<p>I got a <code>print_backward</code> function code online, but I am so confusing about how it works and its output. </p> <p>The below is my code.</p> <pre><code>def print_backward(num): if num == 10: return num += 1 print(num) print_backward(num) print("yeah") print(num) prin...
0
2016-09-26T05:41:52Z
39,695,894
<p>Function call is actually a stack operation. And recursion is a special case of function call.</p> <p>Every time you call a function, the Return Address will be push into a stack, and when the function return, the program will pop the Return address from the top of stack, and program continue to execute from there....
1
2016-09-26T06:20:40Z
[ "python", "recursion" ]
confusion about a python recursion function
39,695,401
<p>I got a <code>print_backward</code> function code online, but I am so confusing about how it works and its output. </p> <p>The below is my code.</p> <pre><code>def print_backward(num): if num == 10: return num += 1 print(num) print_backward(num) print("yeah") print(num) prin...
0
2016-09-26T05:41:52Z
39,696,575
<p>For your case - <code>print_backward(6)</code> it took 4 calls (recursively) to hit return criteria i.e. <code>if num == 10</code> - during those calls the function printed:</p> <pre><code>7 # print_backward(6) - first call we made 8 # print_backward(7) - recursive 9 # print_backward(8) - recursive 10 # print_ba...
0
2016-09-26T07:02:46Z
[ "python", "recursion" ]
confusion about a python recursion function
39,695,401
<p>I got a <code>print_backward</code> function code online, but I am so confusing about how it works and its output. </p> <p>The below is my code.</p> <pre><code>def print_backward(num): if num == 10: return num += 1 print(num) print_backward(num) print("yeah") print(num) prin...
0
2016-09-26T05:41:52Z
39,697,202
<p>when print_backward(6) is called then</p> <pre><code>1 check for 10 2 increase 6 by one num = 7 3 print 7 4 call backward with 7 </code></pre> <p>for 6 print_backward is not completed yet and print_backward(7) is pushed on the top of stack. The remaining part</p> <pre><code>print("yeah") print(7) </code></pre> <...
0
2016-09-26T07:41:31Z
[ "python", "recursion" ]
How do i transfer a value from transient object to a non transient object in openerp 6
39,695,405
<pre><code>class stock_transfer(osv.osv): _inherit="stock.transfer" _columns={ 'psd_allow_logo':fields.boolean('Alow Logo'), } stock_transfer() class indent_report(osv.osv_memory): _inherit = "indent.report" _columns = { 'psd_allow_logo':fields.boolean('Alow Logo'), } ...
0
2016-09-26T05:42:23Z
39,695,795
<pre><code> self.pool.get('stock.transfer').write(cr,uid,active_ids[0],{'psd_allow_logo':rec.psd_allow_logo}) </code></pre> <p>adding that to indent.report solved the issue, i was missing active_ids</p>
0
2016-09-26T06:12:14Z
[ "python", "openerp-6" ]
Finding value of another attribute given an attribute
39,695,461
<p>I have a CSV that has multiple lines, and I am looking to find the <code>JobTitle</code> of a person, given their name. The CSV is now in a DataFrame <code>sal</code> as such:</p> <pre><code>id employee_name job_title 1 SOME NAME SOME TITLE </code></pre> <p>I'm trying to find the <code>JobTitl...
2
2016-09-26T05:47:45Z
39,695,485
<p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p> <pre><code>sal[sal.employee_name == 'name'] </code></pre> <p>If need select only some column, use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas...
2
2016-09-26T05:49:31Z
[ "python", "csv", "pandas" ]
Calculate the length of polyline from csv
39,695,481
<p>I'm still new to python. I need helps to calculate the length of polyline with simple distance calculation:</p> <pre><code> distance = sqrt( (x1 - x2)**2 + (y1 - y2)**2 ) </code></pre> <p>For instance my input csv looks like this. </p> <pre><code>id x y sequence 1 1.5 2.5 0 1 3.2 4.9...
-2
2016-09-26T05:48:51Z
39,699,432
<p>Polyline:</p> <p><a href="http://i.stack.imgur.com/vML5D.gif" rel="nofollow"><img src="http://i.stack.imgur.com/vML5D.gif" alt="enter image description here"></a></p> <p><strong>Distance between two points and the distance between a point and polyline:</strong></p> <pre><code>def lineMagnitude (x1, y1, x2, y2): ...
0
2016-09-26T09:40:54Z
[ "python", "csv", "distance" ]
querying panda df to filter rows where a column is not Nan
39,695,606
<p>I am new to python and using pandas.</p> <p>I want to query a dataframe and filter the rows where one of the columns is not <code>NaN</code>.</p> <p>I have tried:</p> <pre><code>a=dictionarydf.label.isnull() </code></pre> <p>but a is populated with <code>true</code> or <code>false</code>. Tried this </p> <pre><...
2
2016-09-26T05:59:32Z
39,695,625
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html" rel="nofollow"><code>dropna</code></a>:</p> <pre><code>df = df.dropna(subset=['label']) print (df) reference_word all_matching_words label review 10 airport biz - airport travel N 11 ...
2
2016-09-26T06:00:49Z
[ "python", "pandas", "indexing", null, "pandasql" ]
Scipy Write Audio Issue
39,695,645
<p>I'm doing an ICA application where I aim to separate signals from within a mixed signal observation. It seems to work in theory, when I look at the ICA recovered signal in numpy ndarray from, the signal is clearly visible. However, when I try to write this ndarray to a .wav for play back, the signal disappears altog...
1
2016-09-26T06:02:11Z
39,712,587
<p>It looks as though the array you're trying to write contains values in the range [-0.02, 0.02]. When you cast the array to 16bit ints before writing it to the WAV file, all of these values will be truncated to zero!</p> <p><code>wavfile.write</code> supports float32 arrays, so you could just skip the casting step a...
2
2016-09-26T21:19:30Z
[ "python", "audio", "scipy", "scikit-learn", "signal-processing" ]
Runge-Kutta 4th Order error approximation for varied time-steps
39,695,675
<pre><code>from __future__ import division import numpy as np import matplotlib.pyplot as plt def f(x, t): #function return -x def exact(t): #exact solution return np.exp(-t) def Rk4(x0, t0, dt): #Runge-Kutta Fourth Order Error t = np.arange(0, 1+dt, dt) n = len(t) x = np.array([...
2
2016-09-26T06:04:14Z
39,696,192
<p>A short test demonstrates</p> <pre><code>In [104]: import numpy as np In [105]: dt = 0.6 In [106]: np.arange(0, 1+dt, dt) Out[106]: array([ 0. , 0.6, 1.2]) </code></pre> <p>Thus to get meaningful results, either set <code>t[n-1]=1</code> at the start or compute the error as </p> <pre><code>E = abs(x[n-1]-exac...
1
2016-09-26T06:40:44Z
[ "python", "numerical-methods", "runge-kutta" ]
Python Flask app- leading zeros in TOTP error. (Python 2.7)
39,695,700
<p>I have written a python flask application in which app generate totp for validation. (Python 2.7)</p> <p>I use onetimepass library to validate totp against the application secret. code:</p> <pre><code> json_data=request.get_json() my_token=json_data['OTP'] is_valid = otp.valid_totp(token=my_token, secr...
3
2016-09-26T06:06:25Z
39,924,574
<p>Answer was simple as my_token was coming as string and i was converting it to a number. Adding this before converting to a number did the trick:</p> <p><code>my_token.lstrip("0") #removes leading characters</code></p>
0
2016-10-07T19:31:18Z
[ "python", "python-2.7", "flask", "otp", "octal" ]
django two apps with same urls in each url's.py file
39,695,836
<p>I have two apps in my django project one is "home" and other is "administrator". I am using home app for frontend of the site and administrator app for admin panel and the urls' for accessing both frontend and admin panel respectively are :-</p> <pre><code>www.domainname.com/home www.domainname.com/administrator </...
1
2016-09-26T06:16:35Z
39,695,902
<p>You can try adding a namespace to your urls</p> <pre><code>urlpatterns = [ url(r'^home/', include('home.urls', namespace='home')), url(r'^administrator/', include('administrator.urls', namespace='admin')) ] </code></pre> <p>Then you can access them like:</p> <pre><code>&lt;a href="{% url 'home:help' %}" &...
1
2016-09-26T06:21:24Z
[ "python", "django" ]
django two apps with same urls in each url's.py file
39,695,836
<p>I have two apps in my django project one is "home" and other is "administrator". I am using home app for frontend of the site and administrator app for admin panel and the urls' for accessing both frontend and admin panel respectively are :-</p> <pre><code>www.domainname.com/home www.domainname.com/administrator </...
1
2016-09-26T06:16:35Z
39,696,227
<pre><code>urlpatterns = [ url(r'^home/', include('home.urls')), url(r'^administrator/', include('administrator.urls')) ] </code></pre> <p>My suggestion</p> <p>Set Site URL in Settings.py </p> <p>Example : </p> <pre><code>SITE_URL = "http://localhost:8000/" </code></pre> <p>in Template you can pass the URL...
-1
2016-09-26T06:42:29Z
[ "python", "django" ]
unable to insert string or read-only buffer, not long
39,695,857
<p>I tried to venture off while following a python-flask tutorial and am having trouble figuring out an error. I tried browsing stack for 6 hours off and on and nothing out there related could help me out, possibly because I am a beginner...</p> <p>I gathered data from a form (all the data is passing through fine, I t...
1
2016-09-26T06:18:08Z
39,712,962
<p>Check all the variables <code>type</code> which are being inserted. </p> <p>I would guess one of them is suppose to be text or varchar, but is a <code>long</code>. </p> <p>Try converting the <code>long</code> to a <code>str</code> basically one of the numbers being inserted isnt text but might look like 37582L</p>...
0
2016-09-26T21:49:44Z
[ "python", "mysql" ]
implement stack with freelist feature in Python 2.7
39,695,969
<p>Design a stack with free list feature (i.e. after a node is popped, its space is reusable by future push operation, and kept in free list). The code is simplified and does not make sense in some perspective, and I just use below code to show the general idea of stack with free list (as a prototype).</p> <p>My quest...
-1
2016-09-26T06:25:19Z
39,697,103
<p>You could simplify your code by returning the <code>value</code> given to <code>push</code> instead of <code>StackNode</code> holding the value. There are no concerns of memory consumption since you can set <code>node.value</code> to <code>None</code> in <code>pop</code> before returning the result. Below is simple ...
1
2016-09-26T07:35:40Z
[ "python", "python-2.7", "stack" ]
What is the difference between calling a method from parent class using super() and using self?
39,696,077
<pre><code>class Car: def __init__(self, car_name, manufacturer, cost): self.__car_name=car_name self.__manufacturer=manufacturer self.__cost=cost def display_car_details(self): print(self.__car_name, self.__manufacturer, self.__cost) class Super_Car(Car): def __init__(self...
1
2016-09-26T06:33:04Z
39,696,128
<p>In your specific case, there is no difference. If the methods had the <em>same name</em>, you would not be calling the parent class using <code>self.…</code>, but your own method again, creating infinite recursion.</p> <p>With <code>super()</code>, the call is always going to the method in the parent class in <a ...
1
2016-09-26T06:36:52Z
[ "python", "python-3.x", "oop" ]
Boto3 and AWS Lambda - deleting snapshots older than
39,696,136
<p>I'm currently utilising AWS Lambda to create snapshots of my database and delete snapshots older than 6 days. I'm using the Boto3 library to interface with the AWS API. I'm using a CloudWatch rule to trigger the deletion code every day. </p> <p>Normally this is working fine, but I've come across an issue where at ...
0
2016-09-26T06:37:38Z
39,697,823
<p>Code looks perfectly fine and <a href="http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.describe_db_snapshots" rel="nofollow">you are following the documentation</a></p> <p>I would simply add</p> <pre><code> print(i['SnapshotCreateTime'], retentionDate) </code></pre> <p>in the for l...
1
2016-09-26T08:18:16Z
[ "python", "aws-lambda", "boto3" ]
Boto3 and AWS Lambda - deleting snapshots older than
39,696,136
<p>I'm currently utilising AWS Lambda to create snapshots of my database and delete snapshots older than 6 days. I'm using the Boto3 library to interface with the AWS API. I'm using a CloudWatch rule to trigger the deletion code every day. </p> <p>Normally this is working fine, but I've come across an issue where at ...
0
2016-09-26T06:37:38Z
39,714,087
<p>Due to the distributed nature of the CloudWatch Events and the target services, the delay between the time the scheduled rule is triggered and the time the target service honors the execution of the target resource might be several seconds. Your scheduled rule will be triggered within that minute but not on the prec...
0
2016-09-26T23:56:16Z
[ "python", "aws-lambda", "boto3" ]
Django: no such table snippets_snippet
39,696,148
<p>I'm following this Django Rest tutorial on serialization: <a href="http://www.django-rest-framework.org/tutorial/1-serialization/#getting-started" rel="nofollow">http://www.django-rest-framework.org/tutorial/1-serialization/#getting-started</a></p> <p>I followed it pretty much to the letter. It gives the above erro...
0
2016-09-26T06:38:18Z
39,697,724
<p>I believe the error refers to the models.py. Could you show the file so I can double check that too. Also there is a chance for unapllied migartions, double check if you've done this as well.</p>
0
2016-09-26T08:11:24Z
[ "python", "django", "serialization", "code-snippets" ]
Is there any Built in function for PHP Application same as compile() in python?
39,696,234
<p>I am looking for the builtin function or any integrated way in Apache or Php with same working as compile() in Python . for my PHP Application Is there any thing related to this ??</p>
3
2016-09-26T06:43:14Z
39,697,003
<p>First of all this is my first answer. :) </p> <p>As of I know, PHP is an interpreted language in which only that executable file(php.exe in your php installation directory) is compiled and your code is only interpreted and no inbuilt functions like python.</p> <p>If you still need compile as of in python, try <a h...
1
2016-09-26T07:27:56Z
[ "php", "python", "apache", "yii2" ]
How to deploy Flask application in google app engine with core python packages?
39,696,378
<p>I want to deploy below python structure in google app engine I want to know how to configure .yaml files for below flask application with core python packages and please suggest a better way to deploy code in google app engine.(I want to deploy all the packages in one location/directory)</p> <p>Packages:</p> <pre>...
0
2016-09-26T06:50:32Z
39,698,471
<h1>My suggestion.</h1> <p>1.Create application in Google admin console <a href="https://console.cloud.google.com/appengine?src=ac" rel="nofollow">google admin console</a></p> <ol start="2"> <li>Put app.yaml inside your project root directory </li> </ol> <p>sample code:</p> <pre><code>application: "Application name...
0
2016-09-26T08:54:53Z
[ "python", "google-app-engine", "flask" ]
Flask-WTForms RadioField custom validator message doesn't work
39,696,563
<p>In <code>Flask-WTForms</code>, we can give a custom message for each validator for each field. But for <code>RadioField</code> it shows the default message only. Below is an example.</p> <pre><code>&gt;&gt;&gt; from wtforms import Form, RadioField, TextField &gt;&gt;&gt; from wtforms.validators import * </code></pr...
1
2016-09-26T07:02:09Z
39,697,125
<p>You are right about that the process is different.</p> <p>So if you go do <a href="https://github.com/wtforms/wtforms/" rel="nofollow">source code</a> there is base <a href="https://github.com/wtforms/wtforms/blob/master/wtforms/fields/core.py#L23" rel="nofollow"><code>Field</code></a> class with <a href="https://g...
1
2016-09-26T07:36:53Z
[ "python", "flask", "flask-wtforms" ]
"PermissionError" thrown when typing "exit()" to leave the Python interpreter
39,696,606
<p>When I enter the python interpreter as a regular user with <code>python</code>. I see this:</p> <pre><code>Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. </code></pre> <p...
3
2016-09-26T07:04:18Z
39,697,033
<p>Having googled the error message, I found this issue: <a href="http://bugs.python.org/issue19891" rel="nofollow">http://bugs.python.org/issue19891</a></p> <p>It seems that the problem often has to do with the current user not having a home directory (which I think is logical for a user called python) or not having ...
2
2016-09-26T07:31:04Z
[ "python", "ubuntu", "anaconda", "sudo" ]
Passing variables between jython scripts and sharing SQL connection
39,696,692
<p>I have two jython scripts and I have created connection to Oracle database in the 1st script and declared some variables and I want to use that in 2nd script without having to write the getconnection string again in 2nd script and also have to use the data / variables from one script and pass it on to the other. Glo...
0
2016-09-26T07:09:05Z
39,867,205
<p>If all you want is sharing some common values e.g. target server name , you can </p> <p>1) create a new .py file which contains the variable</p> <pre><code># common.py DB=db.company.com </code></pre> <p>2) In your scripts, import the variable from the new .py file</p> <pre><code>from common import DB ... odbc....
0
2016-10-05T06:51:55Z
[ "python", "sql", "jython" ]
odoo is not recognizing python modules
39,696,708
<p>i have installed beautifulsoup4 using pip install BeautifulSoup and through normal python project it can import the module. (from bs4 import BeautifulSoup) but in odoo it get error no module name bs4 even though it is installed. does anyone have solution?</p>
0
2016-09-26T07:10:03Z
39,696,804
<p>Check to make sure odoo is using the Python installation you think it is (I'd guess it's not).</p> <pre><code>import sys print(sys.path) </code></pre> <p>Try that from a python prompt where <code>import bs4</code> works and from the odoo prompt where it doesn't. The difference should give you the answer.</p>
0
2016-09-26T07:15:58Z
[ "python", "windows", "openerp", "odoo-8" ]
How to pass an image to a subprocess in python
39,696,764
<p>The program is trying to read an image and then trying to pass the image to one of the subprocess for further preprocessing. I am trying to pass the image using subprocess args parameter.</p> <pre><code>import subprocess import base64 img =[] img.append(base64.b64encode(open('test.jpg', "rb").read())) output = sub...
0
2016-09-26T07:13:29Z
39,699,195
<p>I do it by using the <code>subprocess.Popen</code>:</p> <p>This is my directory structure:</p> <pre><code>. ├── main.py ├── src.jpg └── test1.py </code></pre> <p>In the following code, I change the size of the src.jpg and save it as a new file called <code>src.thumbnail</code>.</p> <p>This is...
1
2016-09-26T09:29:25Z
[ "python", "image-processing", "subprocess" ]
Which one is good practice about python formatted string?
39,696,818
<p>Suppose I have a file on <code>/home/ashraful/test.txt</code>. Simply I just want to open the file. Now my question is:</p> <p>which one is good practice?</p> <p><strong>Solution 1:</strong> </p> <pre><code>dir = "/home/ashraful/" fp = open("{0}{1}".format(dir, 'test.txt'), 'r') </code></pre> <p><strong>Solutio...
4
2016-09-26T07:16:31Z
39,696,863
<p>instead of concatenating string use <code>os.path.join</code> <code>os.path.expanduser</code> to generate the path and open the file. (assuming you are trying to open a file in your home directory)</p> <pre><code>with open(os.path.join(os.path.expanduser('~'), 'test.txt')) as fp: # do your stuff with file </cod...
14
2016-09-26T07:18:55Z
[ "python", "file" ]
Which one is good practice about python formatted string?
39,696,818
<p>Suppose I have a file on <code>/home/ashraful/test.txt</code>. Simply I just want to open the file. Now my question is:</p> <p>which one is good practice?</p> <p><strong>Solution 1:</strong> </p> <pre><code>dir = "/home/ashraful/" fp = open("{0}{1}".format(dir, 'test.txt'), 'r') </code></pre> <p><strong>Solutio...
4
2016-09-26T07:16:31Z
39,696,890
<p>I think the best way would be to us os.path.join() here</p> <pre><code>import os.path #… dir = '/home/ashraful/' fp = open(os.path.join(dir, 'test.txt'), 'r') </code></pre>
2
2016-09-26T07:21:10Z
[ "python", "file" ]
Which one is good practice about python formatted string?
39,696,818
<p>Suppose I have a file on <code>/home/ashraful/test.txt</code>. Simply I just want to open the file. Now my question is:</p> <p>which one is good practice?</p> <p><strong>Solution 1:</strong> </p> <pre><code>dir = "/home/ashraful/" fp = open("{0}{1}".format(dir, 'test.txt'), 'r') </code></pre> <p><strong>Solutio...
4
2016-09-26T07:16:31Z
39,696,960
<p>If your goal is to open files/directories, as others have mentioned, you should use the <code>os.path.join()</code> method. However, if you want to format string in Python -- as your question title suggests -- then your first approach should be preferred. To quote from <a href="https://www.python.org/dev/peps/pep-31...
4
2016-09-26T07:25:27Z
[ "python", "file" ]
Karger's min cut randomized contraction algorithm [implemented in Python]
39,696,923
<p>Here's my Python implementation for min cut algorithm-</p> <pre><code>def findMinCut(dict): replace_list = [] while len(dict.keys()) &gt; 2: #uniformly pick 2 values a,b= random.sample(dict.keys(),2) #keep record of all the replaced nodes replace_list.append(a) replace_list.append(b) i...
0
2016-09-26T07:22:25Z
39,698,513
<p>You run the algorithm <strong>N^2ln(N)</strong> times because only after running the algorithm, <strong>N^2ln(N)</strong> times, the <strong>probability of success is >= (N - 1)/(N).</strong></p> <p>David Krager's algorithm cannot determine the number of iterations after which the right min-cut is found, becuase it...
0
2016-09-26T08:56:22Z
[ "python", "algorithm", "minimum" ]
How to make a regular expression to take me href, src, css links python
39,697,024
<p>I need to take the links src, css, href, a html page and save them to a text file.</p> <p>I need to do with regular expressions (regex). Thanks!</p>
-2
2016-09-26T07:29:47Z
39,697,137
<pre><code>import re p = re.compile(ur'.*(src|css|href|a html).*') test_str1 = '&lt;a html&gt;' test_str2 = 'String without any tags' if re.match(p, test_str1) is not None: print test_str1 if re.match(p, test_str2) is not None: print test_str2 &gt;&gt; &lt;a html&gt; </code></pre> <p>Here is a solution for...
0
2016-09-26T07:37:38Z
[ "python" ]
Python Dictionary counting the values against each key
39,697,145
<p>I have a list of dictionaries that looks like this:</p> <pre><code>[{'id':1,'name':'Foo','age':20},{'id':2,'name':'Bar'}] </code></pre> <p>How can I get count of total values against each key i.e 3 against id:1</p>
0
2016-09-26T07:38:05Z
39,697,221
<p>You can use <code>len()</code> on dictionaries to get the number of keys:</p> <pre><code>&gt;&gt;&gt; a = [{'id':1,'name':'Foo','age':20},{'id':2,'name':'Bar'}] &gt;&gt;&gt; len(a[0]) 3 &gt;&gt;&gt; len(a[1]) 2 </code></pre>
3
2016-09-26T07:42:26Z
[ "python", "dictionary" ]
Python Dictionary counting the values against each key
39,697,145
<p>I have a list of dictionaries that looks like this:</p> <pre><code>[{'id':1,'name':'Foo','age':20},{'id':2,'name':'Bar'}] </code></pre> <p>How can I get count of total values against each key i.e 3 against id:1</p>
0
2016-09-26T07:38:05Z
39,697,295
<p>A more detailed problem description would have been helpful. For now I assume that you want the length of each dictionary in the list keyed against the value of the <code>id</code> key. In which case something like</p> <pre><code>val_counts = {d['id']: len(d) for d in dlist} </code></pre> <p>should meet your needs...
1
2016-09-26T07:47:09Z
[ "python", "dictionary" ]
Append duplicate items at the end of list whithout changing the order
39,697,245
<p>I am new to python and was trying to Append duplicate items at the end of list whithout changing the order</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(alist): p = len(alist) duplicate = False for i in range(0, p): for j in range (i + 1, p): if alis...
0
2016-09-26T07:44:07Z
39,697,655
<p>I think that in this case the creation of a new list is more efficient and clear in comparison with the permutations in the original list:</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(alist): filtered, duplicates = [], [] for element in alist: if element in filter...
2
2016-09-26T08:06:48Z
[ "python", "python-2.7", "scripting" ]
Append duplicate items at the end of list whithout changing the order
39,697,245
<p>I am new to python and was trying to Append duplicate items at the end of list whithout changing the order</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(alist): p = len(alist) duplicate = False for i in range(0, p): for j in range (i + 1, p): if alis...
0
2016-09-26T07:44:07Z
39,697,684
<p>You may use the Collections module to get <code>OrderedDict</code> for maintaining the order of elements.</p> <p>The technique we use here is to create a dictionary to store the number of occurrences of each element in the array and use the <code>dict</code> to lookup the number of occurrences for later use.</p> <...
0
2016-09-26T08:08:58Z
[ "python", "python-2.7", "scripting" ]
Append duplicate items at the end of list whithout changing the order
39,697,245
<p>I am new to python and was trying to Append duplicate items at the end of list whithout changing the order</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(alist): p = len(alist) duplicate = False for i in range(0, p): for j in range (i + 1, p): if alis...
0
2016-09-26T07:44:07Z
39,697,692
<p>I solved it this way. I also made some changes to make the code a bit more Pythonic.</p> <pre><code>test_list = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(a_list): list_length = len(a_list) duplicate = False checked = [] for i in range(list_length): if a_list.count(a_list[i]) &gt...
0
2016-09-26T08:09:14Z
[ "python", "python-2.7", "scripting" ]
Append duplicate items at the end of list whithout changing the order
39,697,245
<p>I am new to python and was trying to Append duplicate items at the end of list whithout changing the order</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56] def duplicate(alist): p = len(alist) duplicate = False for i in range(0, p): for j in range (i + 1, p): if alis...
0
2016-09-26T07:44:07Z
39,697,923
<p>Instead of checking values, compare on index.</p> <p>Please check this code:</p> <pre><code>testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56,32] print("Original list - ",testlist) tmp_list = [] exclude =[] for i in range(len(testlist)): if i == testlist.index(testlist[i]): tmp_list.append(testlist[i]...
0
2016-09-26T08:25:53Z
[ "python", "python-2.7", "scripting" ]
Any way to get the references of an object with Python C API?
39,697,274
<p>I want to check the references of an PyObject in C++. Any way to get the references of an object with Python C API? Like: gc.get_referrers(), is there similar API in C lib?</p> <p>I'm using Python C APIs to run Python scripts. So I want to debug ref leak problem in my C++ code.</p>
-2
2016-09-26T07:45:39Z
39,697,471
<p>A similar question has been answered here: <a href="http://stackoverflow.com/questions/26134455/how-to-get-reference-count-of-a-pyobject">How to get reference count of a PyObject?</a></p>
-1
2016-09-26T07:58:27Z
[ "python", "c" ]
Count how many attributes have a word as a substring of longer text value
39,697,349
<p>For example, if I have a data frame that looks like this:</p> <pre><code>id title 1 assistant 2 chief executive officer 3 director 4 chief operations officer 5 assistant manager 6 producer </code></pre> <p>If I wanted to find how many <code>title</code> have the word <strong>assistan...
0
2016-09-26T07:51:10Z
39,697,392
<p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.count.html" rel="nofollow"><code>str.count</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.sum.html" rel="nofollow"><code>sum</code></a>:</p> <pre><code>print (df.title.str.count('chief'...
1
2016-09-26T07:52:48Z
[ "python", "string", "pandas", "dataframe", "count" ]
How do I check for an empty nested list in Python?
39,697,570
<p>Say I have a list like </p> <pre><code>cata = [["Shelf", 12, "furniture", [1,1]], ["Carpet", 50, "furnishing", []]] </code></pre> <p>and I want to find out in each nested list if it's empty or not.</p> <p>I am aware of using for loops to iterate through the lists, and if statements to verify as I have in...
0
2016-09-26T08:02:42Z
39,697,734
<p>You're <code>return</code>ing from the function, that essentially means that you don't evaluate every element.</p> <p>Apart from that <code>for inner_2 in inner[3]:</code> will not do what you want because it won't execute for empty lists (<em>it doesn't have elements to iterate though!</em>). What you could do is ...
3
2016-09-26T08:11:46Z
[ "python", "list", "python-3.x", "if-statement", "for-loop" ]
how to iterate in a string in python?
39,697,591
<p>I want to make some montage in <code>ImageMagick</code> which is called by Python via <code>os.system()</code> with 100 jpegs files.</p> <p>Here's the command:</p> <pre><code>cmd='montage '+file[i]+' '+file[i+1]+' '+file[i+2]+' '+file[u+3]+' +file[i+4]+'...+file[i+99] </code></pre> <p>I would like to know how...
0
2016-09-26T08:03:52Z
39,697,622
<p>To join 100 strings with a space starting at <code>i</code>th index:</p> <pre><code>cmd = "montage " + " ".join(file[i:i+100]) </code></pre> <p>.. where <code>file[i:i+100]</code> will return a sub-sequence starting at i, and ending at (i + 100 - 1)</p>
5
2016-09-26T08:05:15Z
[ "python" ]
AWS lambda_handler error for set_contents_from_string to upload in S3
39,697,604
<p>Recently started working on python scripting for encrypting the data and uploading to S3 using aws lambda_handler function. From local machine to S3 it was executing fine (note: Opens all permissions for anyone from bucket side) when the same script executing from aws Lambda_handler (note: Opens all permissions for ...
1
2016-09-26T08:04:36Z
39,740,975
<p>Solved the problem it was due to policy='public-read' ,after removing this able to perform the upload and also a note if in IAM role if you still enable all S3 functions (i.e PutObject,getObject) upload can't work.Need to create a bucket policy for this particular role then only upload work smoothly.</p>
1
2016-09-28T07:38:08Z
[ "python", "amazon-web-services", "amazon-s3", "boto", "aws-lambda" ]
How do I correctly create a flask sqlalchemy many to many relationship with multiple foreign keys
39,697,616
<p>In the Flask sqlalchemy documentation an example of using a simple many to many relationship is given:</p> <pre><code>tags = db.Table('tags', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')), db.Column('page_id', db.Integer, db.ForeignKey('page.id')) ) class Page(db.Model): id = db.Column(db.In...
1
2016-09-26T08:05:07Z
39,706,002
<p>I think, you don't need another table for <code>tag_children</code>. Try to use <a href="http://docs.sqlalchemy.org/en/latest/orm/self_referential.html" rel="nofollow">SQLAlchemy</a> Adjacency Lists:</p> <pre><code>class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) parent_id = Column(Integer,...
0
2016-09-26T14:52:42Z
[ "python", "sqlalchemy", "relational-database", "flask-sqlalchemy" ]
Python Turtle Wait for Click
39,697,634
<p>I'd like to be able to pause and contemplate each step of this program, and move on to the next step by clicking the screen. Initially I tried adding a bunch of events, but then my brain kicked in and reminded me that this is not a procedural program and the first binding would remain the only one(!). Main program b...
0
2016-09-26T08:05:48Z
39,713,672
<p>How about OOP to the rescue! We subclass Turtle to make one that queues everything it's asked to do. Then we set an <code>onclick()</code> handler that pops one item off that queue and executes it:</p> <pre><code>import sys import turtle class QueuedTurtle(turtle.RawTurtle): _queue = [] _pen = None ...
1
2016-09-26T23:03:26Z
[ "python", "events", "recursion", "turtle-graphics" ]