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
Matplotlib contour map colorbar
39,144,381
<p>I am plotting my data into a contour map. The computations work on the translated values, so I need to put it back to its original value. On the fourth line of the code, is the re-translation process. However, when I plotted it the colorbar shows the relative values, and just a note of the shift value at the top of ...
0
2016-08-25T11:44:08Z
39,144,965
<p>Matplotlib doesn't know about your <code>shift</code> variable. It is choosing to plot it that way because the changes you are trying to visualize are 10^(-6) of the background value. </p> <p>You can force the colorbar to have tick marks at specific locations as they do in <a href="http://matplotlib.org/examples/...
1
2016-08-25T12:10:44Z
[ "python", "matplotlib", "colorbar" ]
Matplotlib plot_surface transparency artefact
39,144,482
<p>I'm trying to plot a surface in 3D from a set of data which specifies the z-values. I get some weird transparency artefact though, where I can see through the surface, even though I set alpha=1.0.</p> <p>The artefact is present both when plotting and when saved to file (both as png and pdf): <a href="http://i.stack...
1
2016-08-25T11:49:04Z
39,145,791
<p>Matplotlib is not a "real" 3D engine. This is a very well known problem and once in a while a similar question to yours appears appears (see <a href="http://stackoverflow.com/questions/37488379/matplotlib-3dplot-extra-lines-when-dimensions-not-equal/37489040#37489040">this</a> and <a href="http://stackoverflow.com/q...
2
2016-08-25T12:49:17Z
[ "python", "numpy", "matplotlib" ]
Imported a Python module; why does a reassigning a member in it also affect an import elsewhere?
39,144,498
<p>I am seeing Python behavior that I don't understand. Consider this layout:</p> <pre><code>project | main.py | test1.py | test2.py | config.py </code></pre> <p>main.py:</p> <pre><code>import config as conf import test1 import test2 print(conf.test_var) test1.test1() print(conf.test_var) test2.test2() </co...
18
2016-08-25T11:49:35Z
39,144,632
<p>You edited the <code>test_var</code> in <code>test1.py</code> and then just printed it again using <code>test2.py</code>. Importing again does not change the fact than you assigned new value to the variable - it does not "reset" the value to the first one.</p>
3
2016-08-25T11:55:14Z
[ "python", "import" ]
Imported a Python module; why does a reassigning a member in it also affect an import elsewhere?
39,144,498
<p>I am seeing Python behavior that I don't understand. Consider this layout:</p> <pre><code>project | main.py | test1.py | test2.py | config.py </code></pre> <p>main.py:</p> <pre><code>import config as conf import test1 import test2 print(conf.test_var) test1.test1() print(conf.test_var) test2.test2() </co...
18
2016-08-25T11:49:35Z
39,144,647
<p>no, you're changing with <code>test1()</code> in the config.py a constant value. This won't be resetted. Since you print it in <code>test2()</code>, the modified value gets printed again.</p>
1
2016-08-25T11:55:53Z
[ "python", "import" ]
Imported a Python module; why does a reassigning a member in it also affect an import elsewhere?
39,144,498
<p>I am seeing Python behavior that I don't understand. Consider this layout:</p> <pre><code>project | main.py | test1.py | test2.py | config.py </code></pre> <p>main.py:</p> <pre><code>import config as conf import test1 import test2 print(conf.test_var) test1.test1() print(conf.test_var) test2.test2() </co...
18
2016-08-25T11:49:35Z
39,144,651
<p>You changed the value of <code>test_var</code> when you ran <code>test1</code>, and so it was already changed when you ran <code>test2</code>.</p> <p>That variable will not reset for every file in which you import it. It will be one value for everything.</p>
3
2016-08-25T11:56:04Z
[ "python", "import" ]
Imported a Python module; why does a reassigning a member in it also affect an import elsewhere?
39,144,498
<p>I am seeing Python behavior that I don't understand. Consider this layout:</p> <pre><code>project | main.py | test1.py | test2.py | config.py </code></pre> <p>main.py:</p> <pre><code>import config as conf import test1 import test2 print(conf.test_var) test1.test1() print(conf.test_var) test2.test2() </co...
18
2016-08-25T11:49:35Z
39,144,686
<p>Python caches imported modules. The second <code>import</code> call doesn't reload the file.</p>
26
2016-08-25T11:57:29Z
[ "python", "import" ]
Imported a Python module; why does a reassigning a member in it also affect an import elsewhere?
39,144,498
<p>I am seeing Python behavior that I don't understand. Consider this layout:</p> <pre><code>project | main.py | test1.py | test2.py | config.py </code></pre> <p>main.py:</p> <pre><code>import config as conf import test1 import test2 print(conf.test_var) test1.test1() print(conf.test_var) test2.test2() </co...
18
2016-08-25T11:49:35Z
39,144,726
<p>test2.py</p> <pre><code>import config as conf def test2(): print(id(conf.test_var)) print(conf.test_var) </code></pre> <p>test1.py</p> <pre><code>import config as conf def test1(): conf.test_var = 'test1' print(id(conf.test_var)) </code></pre> <p>Change code like this. </p> <p>And run <code>ma...
7
2016-08-25T11:59:31Z
[ "python", "import" ]
Run a script in Python several times and save the output
39,144,597
<p>I have a script called <code>script.py</code> in python which chooses some random values from some distributions with given mean and standard deviation and then do some calculations with these values. I'm doing this for seven different distributions in a loop of 2000 time steps. After some extra calculations, <code>...
0
2016-08-25T11:53:36Z
39,145,019
<p>You could run it 100 time using <strong>parallel</strong> - if you have a multi core server with multi CPU's it will genuinely run them all in parallel. </p> <p>Off the top of my head something like this should work.</p> <pre><code> parallel -j 100 python script.py &gt; script.out </code></pre>
0
2016-08-25T12:13:40Z
[ "python" ]
Having a wrong Output in topic modelling
39,144,787
<p>I have tried topic modelling in python . But its displaying wrong output. I have provided sample example and codes below.</p> <pre><code>## Documents doc1 = "Sugar is bad to consume. My sister likes to have sugar, but not my father." doc2 = "My father spends a lot of time driving my sister around to dance practice...
0
2016-08-25T12:02:18Z
39,146,033
<p>The problem happens because of you didn't tokenize your documents before removing the stop words. Instead you iterate through each character and remove the characters that are stopwords, e.g. "a", "i":</p> <pre><code>&gt;&gt;&gt; from nltk.corpus import stopwords &gt;&gt;&gt; stop = stopwords.words('english') &gt;&...
2
2016-08-25T12:58:52Z
[ "python", "nltk", "topic-modeling" ]
Add a ScrollView to kivy Popup
39,144,853
<p>I am trying to add a ScrollView to a Popup which opens when button is clicked on the main interface. But the scrollview is not displaying the content properly. How can I fix this?</p> <pre><code>from kivy.uix.gridlayout import GridLayout from kivy.uix.button import Button from kivy.uix.popup import Popup from kivy....
0
2016-08-25T12:05:45Z
39,147,431
<p>Pass <code>size_hint_y=None</code> to the button constructor and it should work.</p>
1
2016-08-25T14:02:17Z
[ "python", "popup", "scrollview", "kivy" ]
NLTK - nltk.tokenize.RegexpTokenizer - regex not working as expected
39,144,991
<p>I am trying to Tokenize text using RegexpTokenizer.</p> <p><strong>Code:</strong></p> <pre><code>from nltk.tokenize import RegexpTokenizer #from nltk.tokenize import word_tokenize line = "U.S.A Count U.S.A. Sec.of U.S. Name:Dr.John Doe J.Doe 1.11 1,000 10--20 10-20" pattern = '[\d|\.|\,]+|[A-Z][\.|A-Z]+\b[\.]*|[\...
3
2016-08-25T12:12:05Z
39,145,213
<p>If you mod your regex</p> <pre><code>pattern = '[USA\.]{4,}|[\w]+|[\S]' </code></pre> <p>Then </p> <pre><code>pattern = '[USA\.]{4,}|[\w]+' tokenizer = RegexpTokenizer(pattern) print (''+str(tokenizer.tokenize(line))) </code></pre> <p>You get the output that you wanted</p> <pre><code>['U.S.A', 'Count', 'U.S.A.'...
0
2016-08-25T12:22:20Z
[ "python", "regex", "nlp", "nltk", "tokenize" ]
NLTK - nltk.tokenize.RegexpTokenizer - regex not working as expected
39,144,991
<p>I am trying to Tokenize text using RegexpTokenizer.</p> <p><strong>Code:</strong></p> <pre><code>from nltk.tokenize import RegexpTokenizer #from nltk.tokenize import word_tokenize line = "U.S.A Count U.S.A. Sec.of U.S. Name:Dr.John Doe J.Doe 1.11 1,000 10--20 10-20" pattern = '[\d|\.|\,]+|[A-Z][\.|A-Z]+\b[\.]*|[\...
3
2016-08-25T12:12:05Z
39,145,251
<p>The point is that your <code>\b</code> was a backspace character, you need to use a raw string literal. Also, you have literal pipes in the character classes that would also mess your output.</p> <p>This works as expected:</p> <pre><code>&gt;&gt;&gt; pattern = r'[\d.,]+|[A-Z][.A-Z]+\b\.*|\w+|\S' &gt;&gt;&gt; token...
4
2016-08-25T12:23:56Z
[ "python", "regex", "nlp", "nltk", "tokenize" ]
Checking Valid Country Names Python Pandas
39,145,153
<p>I got a column that contains countries. I was wondering, is there a way to check if the column contains any invalid country names and print them out?</p> <pre><code> Column1 Hong Kong United States of America Malaysia Thailand Canada ...
-1
2016-08-25T12:19:27Z
39,145,394
<p>You can start with pycountry is it a module - however it is inaccurate !! it contains 249 countries - where as the UN currently lists 241.</p> <p>This is what I currently use</p> <pre><code>class nation(object): def __init__(self, un_code, un_name, un_3_str): self._code = int(un_code) self._nam...
1
2016-08-25T12:31:10Z
[ "python", "pandas" ]
Puppet Dependency file failing in local Vagrant Environmnet
39,145,182
<p>Below is my Puppet code for a Python Django App.</p> <pre><code>class ltp ($project_dir = '/vagrant') { exec { "install_project_dependencies": cwd =&gt; $project_dir, command =&gt; "/usr/bin/python setup.py install &gt; /tmp/setuplog 2&gt;&amp;1", timeout =&gt; 0, ...
0
2016-08-25T12:20:43Z
39,145,306
<p>The error is this </p> <pre><code>==&gt; clips: Notice: /Stage[main]/Ltp/Exec[create_ba_database]/returns: ERROR: database "burson_clips" already exists ==&gt; clips: Error: echo "psql -c 'create database burson_clips;'" | sudo su postgres returned 1 instead of one of [0] </code></pre> <p>your db already exists ...
1
2016-08-25T12:26:59Z
[ "python", "django", "vagrant", "puppet", "vagrant-provision" ]
"""TypeError: only length-1 arrays can be converted to Python scalars""" when trying to make run a counter on Pi3 with 7segment display
39,145,284
<p>I'm currrently working on a simple count program for RPi-3 with a seven-segment-Display. I have two ways of counting from one to ten, one manually, always lighting up the single segments I need, and another way, which is based on a numpy matrix. </p> <p>The manual way works fine but I have Problems with the matrix ...
1
2016-08-25T12:25:25Z
39,147,279
<p>I have changed my strategy and now use an numpy array. Now I have a working code:</p> <pre><code>import RPi.GPIO as GPIO import time import numpy GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(31, GPIO.OUT) GPIO.setup(32, GPIO.OUT) GPIO.setup(33, GPIO.OUT) GPIO.setup(35, GPIO.OUT) GPIO.setup(...
1
2016-08-25T13:55:15Z
[ "python", "arrays", "numpy", "matrix", "gpio" ]
How to change the background color of RawTurtle
39,145,285
<p>I wrote a python script, which should open a Tkinter window with a canvas and let turtle draw in this canvas. Now I want to change the background color of the canvas, but it stays always white (default settings of <code>RawTurtle</code>?). Is there any possibility to draw on a background with another color?</p> <pr...
0
2016-08-25T12:25:42Z
39,146,635
<p>You can supply a <code>turtle.TurtleScreen</code> (provides a <code>bgcolor</code> method) to <code>turtle.RawTurtle</code> instead of directly using <code>Canvas</code> :</p> <pre><code>ccanvas = Canvas(root, width = 800, height = 480) turtle_screen = turtle.TurtleScreen(ccanvas) turtle_screen.bgcolor("black") c...
0
2016-08-25T13:26:24Z
[ "python", "canvas", "tkinter", "background-color", "turtle-graphics" ]
Python error: "socket.error: [Errno 11] Resource temporarily unavailable" when sending image
39,145,357
<p>I want to make a program that accesses images from files, encodes them, and sends them to an server. Than the server is supposed to decode the image, and save it to file. I tested the image encoding itself, and it worked, so the problem lies in the server and client connection.</p> <p>Here is the server:</p> <pre>...
1
2016-08-25T12:29:37Z
39,145,994
<p>In the server you are setting the remote socket (that returned by <code>accept()</code>) to non-blocking mode, which means that I/O on that socket will terminate immediately by an exception if there is no data to read.</p> <p>There will usually be a period of time between establishing the connection with the server...
1
2016-08-25T12:56:49Z
[ "python", "image", "sockets" ]
Row operations within a group of a pandas dataframe
39,145,468
<p>I have a pandas dataframe and I need to perform various operations between rows that belong to the same group, e.g. find the difference between them. For example, I have the following:</p> <pre><code> var1 var2 1 7 1 10 1 15 2 3 2 9 2 5 </code></pre> <p>and I want to get t...
1
2016-08-25T12:34:23Z
39,145,559
<p>You want to use <code>transform</code> on the <code>groupby</code> object to add a new column back to the original df:</p> <pre><code>In [58]: df['var3'] = df.groupby('var1')['var2'].transform(lambda x: x.diff()) df Out[58]: var1 var2 var3 0 1 7 NaN 1 1 10 3.0 2 1 15 5.0 3 ...
1
2016-08-25T12:38:36Z
[ "python", "pandas" ]
Handle json-string with array properly
39,145,636
<p>I would like to find a way to handle json - input that contains arrays in Python. What I have is the following:</p> <pre><code>import json def main(): jsonString = '{"matrix":[["1","2"],["3","4"]]}' jsonMatrix = json.loads(jsonString) Matrix = jsonMatrix["matrix"] term1 = Matrix[0][0] # yield...
0
2016-08-25T12:41:51Z
39,145,706
<pre><code>import json def main(): jsonString = '{"matrix":[["1","2"],["3","4"]]}' jsonMatrix = json.loads(jsonString) # convert entire matrix to integers Matrix = [[int(v) for v in row] for row in jsonMatrix["matrix"]] term1 = Matrix[0][0] # yields: 1 term2 = Matrix[0][1] # yields:...
0
2016-08-25T12:45:02Z
[ "python", "json" ]
Handle json-string with array properly
39,145,636
<p>I would like to find a way to handle json - input that contains arrays in Python. What I have is the following:</p> <pre><code>import json def main(): jsonString = '{"matrix":[["1","2"],["3","4"]]}' jsonMatrix = json.loads(jsonString) Matrix = jsonMatrix["matrix"] term1 = Matrix[0][0] # yield...
0
2016-08-25T12:41:51Z
39,145,793
<p>This is pretty basic, sorry but you can convert the string into integers by any one of the following methods.</p> <pre><code>new=map(int,Matrix[0]) term1=new[0] term2=new[1] </code></pre> <p>Convert the strings into numbers and then use them</p> <pre><code>term1=int(Matrix[0][0]) term2=int(Matrix[0]...
0
2016-08-25T12:49:22Z
[ "python", "json" ]
set time limitations for timer
39,145,662
<p>Is there are nicer way to write the code like this?</p> <pre><code># ugly piece of code seconds = 0 if seconds &lt; 0 else seconds seconds = 86399 if seconds &gt;= 86400 else seconds </code></pre> <p>I mean - I need to setup the strict possible range of seconds</p>
0
2016-08-25T12:42:48Z
39,145,711
<pre><code>seconds = max(0, min(86399, seconds)) </code></pre>
4
2016-08-25T12:45:44Z
[ "python", "time" ]
set time limitations for timer
39,145,662
<p>Is there are nicer way to write the code like this?</p> <pre><code># ugly piece of code seconds = 0 if seconds &lt; 0 else seconds seconds = 86399 if seconds &gt;= 86400 else seconds </code></pre> <p>I mean - I need to setup the strict possible range of seconds</p>
0
2016-08-25T12:42:48Z
39,145,873
<p>Maybe something like this:</p> <pre><code>def check(start, end, sec): return end if sec &gt; end else start if sec &lt; start else sec </code></pre>
0
2016-08-25T12:52:35Z
[ "python", "time" ]
Finding Missing Elements among a range of number lines
39,145,665
<p>Let's say I have a list of ranges (ie. <code>[[1,100][102, 200], etc]]</code>. I want to find the number of missing elements in the total range. I have a working algorithm below:</p> <pre><code>def missing(numranges): (minimum, maximum) = (min(map(lambda x: x[0], numranges)), max(map(l...
-2
2016-08-25T12:43:01Z
39,145,818
<p>Here I am assuming based on your example that your list is in increasing order and your ranges will not overlap</p> <pre><code>&gt;&gt;&gt; l = [[1, 50] ,[55, 90], [95, 100]] &gt;&gt;&gt; sum([l[i+1][0]-m[1]-1 for i, m in enumerate(l[:-1])]) 8 </code></pre> <p><strong>Logic</strong>: I am subtracting index 0 of th...
0
2016-08-25T12:50:21Z
[ "python", "python-2.7" ]
Finding Missing Elements among a range of number lines
39,145,665
<p>Let's say I have a list of ranges (ie. <code>[[1,100][102, 200], etc]]</code>. I want to find the number of missing elements in the total range. I have a working algorithm below:</p> <pre><code>def missing(numranges): (minimum, maximum) = (min(map(lambda x: x[0], numranges)), max(map(l...
-2
2016-08-25T12:43:01Z
39,145,883
<p>You can do something like this,</p> <pre><code>In [22]: input_list = [range(1,100),range(102, 200)] In [23]: total_list = sum(input_list,[]) In [24]: master_total_list = range(min(total_list),max(total_list)+1) In [25]: [i for i in master_total_list if i not in total_list] Out[25]: [100, 101] </code></pre>
0
2016-08-25T12:52:51Z
[ "python", "python-2.7" ]
Finding Missing Elements among a range of number lines
39,145,665
<p>Let's say I have a list of ranges (ie. <code>[[1,100][102, 200], etc]]</code>. I want to find the number of missing elements in the total range. I have a working algorithm below:</p> <pre><code>def missing(numranges): (minimum, maximum) = (min(map(lambda x: x[0], numranges)), max(map(l...
-2
2016-08-25T12:43:01Z
39,145,967
<p>Try sets to solve this:</p> <pre><code>test = set(range(1, 100 + 1) + range(102, 200 + 1)) missing = list(set(range(min(test), max(test))) - test) print (missing) </code></pre>
0
2016-08-25T12:55:42Z
[ "python", "python-2.7" ]
Finding Missing Elements among a range of number lines
39,145,665
<p>Let's say I have a list of ranges (ie. <code>[[1,100][102, 200], etc]]</code>. I want to find the number of missing elements in the total range. I have a working algorithm below:</p> <pre><code>def missing(numranges): (minimum, maximum) = (min(map(lambda x: x[0], numranges)), max(map(l...
-2
2016-08-25T12:43:01Z
39,146,023
<p>See this code </p> <pre><code>l=[[1, 50], [55, 90], [95, 100]] res=[] for item in l : res.extend(range(item[0],item[1])) print [k for k in range(max(res)) if k not in res] </code></pre> <p>Output :</p> <pre><code>[0, 50, 51, 52, 53, 54, 90, 91, 92, 93, 94] </code></pre>
0
2016-08-25T12:58:14Z
[ "python", "python-2.7" ]
numpy ND array: take index'ed elements along a certain axis (ND choose)
39,145,736
<p>I obtain indices along a certain axis. For example like this with 2D and axis=-1 :</p> <pre><code>&gt;&gt;&gt; axis = -1 &gt;&gt;&gt; a = rand(5, 3) - 0.5; a array([[ 0.49970414, -0.14251437, 0.2881351 ], [ 0.3280437 , 0.33766112, 0.4263927 ], [ 0.37377502, 0.05392274, -0.4647834 ], [-0.09...
0
2016-08-25T12:46:34Z
39,147,174
<p>Now I found a simple solution myself:</p> <pre><code>def choose_axis(inds, a, axis=-1): return np.choose(inds, np.rollaxis(a, axis)) &gt;&gt;&gt; choose_axis(axisinds, a, -1) array([ 0.49970414, 0.4263927 , -0.4647834 , -0.29381079, 0.15729681]) </code></pre> <p><strong>Edit:</strong> However this approach ...
0
2016-08-25T13:50:35Z
[ "python", "arrays", "numpy" ]
masking a series with a boolean array
39,145,795
<p>This has given me a lot of trouble, and I am perplexed by the incompatibility of numpy arrays with pandas series. When I create a boolean array using a series, for instance</p> <pre><code>x = np.array([1,2,3,4,5,6,7]) y = pd.Series([1,2,3,4,5,6,7]) delta = np.percentile(x, 50) deltamask = x- y &gt; delta </code></...
6
2016-08-25T12:49:25Z
39,168,021
<p><strong>Fancy Indexing</strong></p> <p>As numpy currently stands, fancy indexing in numpy works as follows:</p> <ol> <li><p>If the thing between brackets is a <code>tuple</code> (whether with explicit parens or not), the elements of the tuple are indices for different dimensions of <code>x</code>. For example, bot...
1
2016-08-26T13:53:58Z
[ "python", "pandas", "numpy" ]
Append the data to existing json file
39,146,072
<p>I have an existing JSON file and trying to add string into file. But as soon as I write a JSON file the new line characters do disappear in the JSON file and format gets changed.</p> <p>Below is the code:</p> <pre><code>#!/usr/bin/python import json userinput = raw_input('Enter the name of a file a you want to re...
0
2016-08-25T13:01:01Z
39,146,315
<p>JSON doesn't need a particular layout, but for slightly less bad human readability you can supply <code>indent=2</code></p> <pre><code>import sys import json userinput = raw_input('Enter the name of a file a you want to read: ') with open(userinput) as json_data: data = json.load(json_data) print(data['cla...
0
2016-08-25T13:11:46Z
[ "python", "json", "file-io" ]
Append the data to existing json file
39,146,072
<p>I have an existing JSON file and trying to add string into file. But as soon as I write a JSON file the new line characters do disappear in the JSON file and format gets changed.</p> <p>Below is the code:</p> <pre><code>#!/usr/bin/python import json userinput = raw_input('Enter the name of a file a you want to re...
0
2016-08-25T13:01:01Z
39,146,317
<p>You can set the <code>indent</code> argument to function <a href="http://fs22.clicknupload.net:182/d/j25yr2vjlvyd7tr7wha4fmcqat5tjxz36erbscvht55bn7tqnpldh3gdc3hrjyvypfd4voij/m.S02E08.480p.u766145.Rapidmoviez.com.rar" rel="nofollow"><code>json.dumps()</code></a> to an integer representing the number of spaces to inde...
0
2016-08-25T13:11:53Z
[ "python", "json", "file-io" ]
Python pandas grouping issue
39,146,135
<p>Am i doing something wrong here or is there a bug here.</p> <p>df2 is a copy/slice of df1. But the minute i attempt to group it by column A and get the last value of the grouping from column C, creating a new column 'NewMisteryColumn', df1 also gets a new 'NewMisteryColumn'</p> <p>The end result in df2 is correct....
0
2016-08-25T13:03:29Z
39,146,912
<p>The problem is that df2 is just another reference to the DataFrame.</p> <pre><code>df2 = df1 df3 = df1.copy() df1 is df2 # True df1 is df3 # False </code></pre> <p>You can also verify the ids...</p> <pre><code>id(df1) id(df2) # Same as id(df1) id(df3) # Different! </code></pre>
1
2016-08-25T13:38:34Z
[ "python", "pandas", "dataframe", "grouping" ]
Pass just one field via AJAX with Flask
39,146,220
<p>I have a VERY simple HTML form with just one <code>&lt;input type='text'&gt;</code> field, an email address, that I need to pass back to a Python script via AJAX. I can't seem to receive the value on the other end. (And can all the JSON encoding/decoding be avoided, since there's just one field?)</p> <p>Here's the ...
0
2016-08-25T13:07:03Z
39,146,496
<p>JSON.stringify is used to turn an object into a JSON-formatted string, but you don't have an object, just a string. Try this: </p> <pre><code>var d = { email: $('#email').val() }; </code></pre> <p><code>JSON.stringify(d)</code> will now turn that into a JSON-formatted string:</p> <p><code>{email: "myemail@gmail.c...
1
2016-08-25T13:20:27Z
[ "javascript", "jquery", "python", "json", "ajax" ]
rest framework 'user_code' is an invalid keyword argument for this function Request Method: POST Request
39,146,292
<p>I`m trying to create a new BCodes on save BDetail in the same endpoint but when i test, throw framework 'user_code' is an invalid keyword argument for this function Request Method: POST Request.</p> <p>BCodes model</p> <pre><code>class BCodes(models.Model): user_code = models.IntegerField() building_code ...
0
2016-08-25T13:10:39Z
39,147,231
<p>The error is in create method of BDetailSerializerSimple</p> <p>before</p> <pre><code>def create(self, validated_data): code = BCodes.objects.create(**validated_data['b_codes']) detail_data = validated_data.pop('b_codes') detail = BDetail.objects.create(b_codes=code, **detail_data) ...
0
2016-08-25T13:53:28Z
[ "python", "django", "django-models", "django-rest-framework", "django-rest-framework-gis" ]
How to call a function inside a function ?Odoo9 Validation
39,146,304
<p>I have a added a boolean field in <code>product.pricelist.item</code></p> <pre><code>class product_pricelist_item(models.Model): _inherit = 'product.pricelist.item' myfield = fields.Boolean(string="CheckMark") </code></pre> <p>Now there are multiple lines in <code>product.pricelist.item</code>.</p> <p>(V...
1
2016-08-25T13:11:14Z
39,149,380
<p>With <code>self</code> we can call method of current class.</p> <p>Try with following code:</p> <p>Replace code </p> <pre><code>counter = _get_counter(self) </code></pre> <p>with</p> <pre><code>counter = self._get_counter() </code></pre>
2
2016-08-25T15:36:17Z
[ "python", "validation", "openerp", "odoo-9" ]
How to call a function inside a function ?Odoo9 Validation
39,146,304
<p>I have a added a boolean field in <code>product.pricelist.item</code></p> <pre><code>class product_pricelist_item(models.Model): _inherit = 'product.pricelist.item' myfield = fields.Boolean(string="CheckMark") </code></pre> <p>Now there are multiple lines in <code>product.pricelist.item</code>.</p> <p>(V...
1
2016-08-25T13:11:14Z
39,164,970
<p>The loop in <code>_get_counter</code> does not affect the result and the search did not depend on records so you can use: </p> <pre><code>def _get_counter(self): pricelist_obj = self.env['product.pricelist.item'] counter = len(pricelist_obj.search_read([('myfield', '=', True)], ['myfield'])) return co...
1
2016-08-26T11:12:35Z
[ "python", "validation", "openerp", "odoo-9" ]
Trouble sending boto3 filtered data to a list
39,146,327
<p>I've generated a working boto3 instance filter using anaconda python 2.7. I need to assign the IP addresses and instance names to a list for further processing.</p> <p>Code looks like this:</p> <pre><code>for instance in instances: print(instance.id, instance.instance_type, instance.key_name, instance.private_...
0
2016-08-25T13:12:39Z
39,146,438
<p>this doesn't exist but you have a cryptic error because you are reusing your <code>tagged</code> variable which is an instance of <code>ec2.instancesCollection</code></p> <pre><code> tagged.collections.OrderedDict() </code></pre> <p>(and would do nothing anyway since it's not affected)</p> <p>you (probably) want/...
0
2016-08-25T13:17:54Z
[ "python", "anaconda", "boto3" ]
scikit-learn joblib: Permission error importing, run in Serial mode
39,146,371
<p>The following permission error occurs when I try importing joblib from script or <code>python -c 'import joblib'</code>:</p> <pre><code>/usr/local/lib/python2.7/dist-packages/joblib//joblib_multiprocessing_helpers.py:29: UserWarning: [Errno 13] Permission denied. joblib will operate in serial mode warnings.w...
0
2016-08-25T13:14:36Z
39,147,538
<p>Found it by looking a in the joblib source code:</p> <p>The problem was that semaphoring was not enabled on my system: Joblib checks for multiprocessing.Semaphore() and it turns out that only root had read/write permission on shared memory in /dev/shm. Fixed it as per <a href="http://stackoverflow.com/questions/200...
0
2016-08-25T14:07:34Z
[ "python", "permissions", "scikit-learn", "python-import", "joblib" ]
Python - SSL: CERTIFICATE_VERIFY_FAILED
39,146,397
<p>I have a python script that uses the VirusTotal API. It has been working with no problems, but all of a sudden when I run the script I am getting the following error:</p> <blockquote> <pre><code>urllib2.URLError: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)&gt; </code><...
0
2016-08-25T13:15:50Z
39,150,585
<blockquote> <p>I believe it may be our web proxy that is causing the issue. Is there a way to prevent it from verifying the cert?</p> </blockquote> <p>If you assume that a SSL intercepting proxy is denying the connection then you have to fix the problem at the proxy, i.e. there is no way to instruct the proxy to n...
0
2016-08-25T16:38:56Z
[ "python", "ssl", "certificate" ]
Python - SSL: CERTIFICATE_VERIFY_FAILED
39,146,397
<p>I have a python script that uses the VirusTotal API. It has been working with no problems, but all of a sudden when I run the script I am getting the following error:</p> <blockquote> <pre><code>urllib2.URLError: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)&gt; </code><...
0
2016-08-25T13:15:50Z
39,286,586
<p>There are two possibilities, </p> <ol> <li>You are using a self-signed certificate. Browsers don not trust on such certificate, so be sure that you are using CA-signed trusted certificate. </li> <li>If you are using CA-signed trusted the certificate that you should have to check for install CA chain certificates (R...
0
2016-09-02T07:24:17Z
[ "python", "ssl", "certificate" ]
Slicing pandas dataframe by looking for character "in" string
39,146,784
<p>I want to extract a set of rows from a dataframe based on whether a string in that row contains a given substring.</p> <p>For example, say I have</p> <p><code>testdf = pd.DataFrame({'A':['abc','efc','abz'], 'B':[4,5,6]})</code>.</p> <p>I want to get the rows containing the substring <code>'ab'</code> in column <c...
2
2016-08-25T13:32:47Z
39,146,805
<p>use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html" rel="nofollow"><code>str.contains</code></a>:</p> <pre><code>In [67]: testdf[testdf['A'].str.contains('ab')] Out[67]: A B 0 abc 4 2 abz 6 </code></pre> <p>What you tried doesn't make sense firstly:</p> <...
3
2016-08-25T13:33:48Z
[ "python", "python-2.7", "pandas" ]
How Do I Build a Class with in a Class in Python
39,146,957
<p>I am trying to model services and I am having some issue. What I am trying to do is I would want something such as this in code:</p> <pre><code>&gt;&gt;&gt; service = Service() &gt;&gt;&gt; service.name = "Instance1" &gt;&gt;&gt; service.name.color = "red" &gt;&gt;&gt; service.name.color.enabled = True </code></pre...
-1
2016-08-25T13:40:40Z
39,147,069
<p>You should be looking at composition, not nested classes.</p> <pre><code>class Color: def __init__(self, name): self.name = name class Service: def __init__(self, color_obj): self.color_obj = color_obj service = Service(Color("yellow")) print(service.color_obj.name) &gt;&gt; "yellow" <...
-1
2016-08-25T13:45:21Z
[ "python", "class" ]
How Do I Build a Class with in a Class in Python
39,146,957
<p>I am trying to model services and I am having some issue. What I am trying to do is I would want something such as this in code:</p> <pre><code>&gt;&gt;&gt; service = Service() &gt;&gt;&gt; service.name = "Instance1" &gt;&gt;&gt; service.name.color = "red" &gt;&gt;&gt; service.name.color.enabled = True </code></pre...
-1
2016-08-25T13:40:40Z
39,147,140
<p>It's not against convention to have other objects as values of attributes of your class. </p> <p>The best thing you can do it declare your desired classes - in your example these would be <code>class Color</code>, which would have a boolean attribute <code>enabled</code>.</p>
0
2016-08-25T13:48:58Z
[ "python", "class" ]
How Do I Build a Class with in a Class in Python
39,146,957
<p>I am trying to model services and I am having some issue. What I am trying to do is I would want something such as this in code:</p> <pre><code>&gt;&gt;&gt; service = Service() &gt;&gt;&gt; service.name = "Instance1" &gt;&gt;&gt; service.name.color = "red" &gt;&gt;&gt; service.name.color.enabled = True </code></pre...
-1
2016-08-25T13:40:40Z
39,147,510
<p>I'd avoid having nested classes, for example:</p> <pre><code>class Color: def __init__(self, name, enabled=False): self.name = name self.enabled = enabled def __str__(self): return self.name class Service: def __init__(self, name): self.name = name self.palet...
0
2016-08-25T14:06:15Z
[ "python", "class" ]
How Do I Build a Class with in a Class in Python
39,146,957
<p>I am trying to model services and I am having some issue. What I am trying to do is I would want something such as this in code:</p> <pre><code>&gt;&gt;&gt; service = Service() &gt;&gt;&gt; service.name = "Instance1" &gt;&gt;&gt; service.name.color = "red" &gt;&gt;&gt; service.name.color.enabled = True </code></pre...
-1
2016-08-25T13:40:40Z
39,147,575
<p>If you mean nested <em>instances</em>, you just create them in the relevant <code>__init__</code> code (or subsequently)</p> <pre><code>&gt;&gt;&gt; class LR( object): ... def __init__(self, L=None, R=None): ... self.left = L ... self.right = R &gt;&gt;&gt; class Thing(object): ... def __init__(self): ...
0
2016-08-25T14:09:05Z
[ "python", "class" ]
How to print a list without brackets
39,146,973
<p>I have a list with float values. I want to remove the the brackets from the list.</p> <pre><code>Floatlist = [14.715258933890,10.215953824,14.8171645397,10.2458542714719] print (", ".join(Floatlist)) but i am getting an following error : TypeError: sequence item 0: expected string, float found </code></pre> <p>bu...
0
2016-08-25T13:41:24Z
39,147,018
<p>You need to convert the elements to strings.</p> <pre><code>print (", ".join(map(str, Floatlist))) </code></pre> <p>or </p> <pre><code>print (", ".join(str(f) for f in Floatlist))) </code></pre>
3
2016-08-25T13:43:06Z
[ "python" ]
How to print a list without brackets
39,146,973
<p>I have a list with float values. I want to remove the the brackets from the list.</p> <pre><code>Floatlist = [14.715258933890,10.215953824,14.8171645397,10.2458542714719] print (", ".join(Floatlist)) but i am getting an following error : TypeError: sequence item 0: expected string, float found </code></pre> <p>bu...
0
2016-08-25T13:41:24Z
39,147,026
<p><code>.join</code> only operates on iterables that yield strings. It doesn't convert to strings implicitly for you -- You need to do that yourself:</p> <pre><code>','.join([str(f) for f in FloatList]) </code></pre> <hr> <p><sup><sup><code>','.join(str(f) for f in FloatList)</code> also works (notice the missing ...
3
2016-08-25T13:43:16Z
[ "python" ]
How to print a list without brackets
39,146,973
<p>I have a list with float values. I want to remove the the brackets from the list.</p> <pre><code>Floatlist = [14.715258933890,10.215953824,14.8171645397,10.2458542714719] print (", ".join(Floatlist)) but i am getting an following error : TypeError: sequence item 0: expected string, float found </code></pre> <p>bu...
0
2016-08-25T13:41:24Z
39,147,060
<p>You just make a for statement:</p> <pre><code>for i in Floatlist: print(i, ', ', end='') </code></pre> <p>Hope that helps</p> <p>P.S: This snippet code only works in Python3</p>
1
2016-08-25T13:44:41Z
[ "python" ]
How to print a list without brackets
39,146,973
<p>I have a list with float values. I want to remove the the brackets from the list.</p> <pre><code>Floatlist = [14.715258933890,10.215953824,14.8171645397,10.2458542714719] print (", ".join(Floatlist)) but i am getting an following error : TypeError: sequence item 0: expected string, float found </code></pre> <p>bu...
0
2016-08-25T13:41:24Z
39,147,187
<p>Just to print:</p> <pre><code>print(str(Floatlist).strip('[]')) #out: 14.71525893389, 10.215953824, 14.8171645397, 10.2458542714719 </code></pre>
1
2016-08-25T13:51:22Z
[ "python" ]
ArcGIS Raster Calculator Error in Python For-Loop
39,147,079
<p>I am performing a simple for-loop in ArcGIS calculator through python. I want to generate transition maps using cover classes from year one (r2005) to year two (r2009). Here is the code:</p> <pre><code># Importing libraries import arcpy, sys, string, os, arcgisscripting, dircache import numpy as np from arcpy impo...
1
2016-08-25T13:45:59Z
39,167,520
<p>You know that the value <code>14</code> works, but you are getting a <code>TypeError</code> with whatever the loop over <code>classes</code> is returning. The type of <code>14</code> is <code>int</code>, so try typecasting <code>i</code> and <code>j</code> to <code>int</code> before making the comparison:</p> <pre...
0
2016-08-26T13:28:27Z
[ "python", "for-loop", "arcgis", "raster" ]
Dask: is it safe to pickle a dataframe for later use?
39,147,120
<p>I have a database-like object containing many dask dataframes. I would like to work with the data, save it and reload it on the next day to continue the analysis. </p> <p>Therefore, I tried saving dask dataframes (not computation results, just the "plan of computation" itself) using pickle. Apparently, it works (at...
1
2016-08-25T13:48:07Z
39,147,916
<p>Generally speaking it is <em>usually</em> safe. However there are a few caveats:</p> <ol> <li>If your dask.dataframe contains custom functions, such as with with <code>df.apply(lambda x: x)</code> then the internal function will not be pickleable. However it will still be serializable with <a href="https://github...
1
2016-08-25T14:23:27Z
[ "python", "dask" ]
May I display the field from other table in the template in Django 1.10?
39,147,192
<p>May I display the field from other table in the template in Django 1.10?</p> <p>I have 3 tables as the following models.py</p> <pre><code>import datetime from django.db import models from django.forms import ModelForm from django.utils import timezone from django.utils.encoding import python_2_unicode_compatible ...
2
2016-08-25T13:51:37Z
39,147,302
<p>Templates don't have the access to the database, so they can't execute a query (and that's basically what you want)</p> <p>However, I can see that you have a foreign key to <code>Tbl_Province</code> in <code>Contact</code> and you can use that instead - just write <code>{% contact.province.province_name %}</code> (...
0
2016-08-25T13:56:09Z
[ "python", "django" ]
Selenium in Python How use a If - else code if an element is not present
39,147,245
<p>All, I am in need of some serious " dumbed down " examples of how to write code in Python that will do something if a element is there or not there. I'm new to programing and I have reviewed a days worth of posts and I can't seem to figure it out.... </p> <p>Here is what I am trying to do. </p> <pre><code>from se...
0
2016-08-25T13:54:01Z
39,147,358
<p>you can catch the exception and act accordingly:</p> <pre><code>try: elem = driver.find_element_by_partial_link_text('Create Activity') if elem.is_displayed(): elem.click() # this will click the element if it is there print("FOUND THE LINK CREATE ACTIVITY! and Clicked it!") except NoSuchElem...
5
2016-08-25T13:58:45Z
[ "python", "selenium" ]
Selenium in Python How use a If - else code if an element is not present
39,147,245
<p>All, I am in need of some serious " dumbed down " examples of how to write code in Python that will do something if a element is there or not there. I'm new to programing and I have reviewed a days worth of posts and I can't seem to figure it out.... </p> <p>Here is what I am trying to do. </p> <pre><code>from se...
0
2016-08-25T13:54:01Z
39,147,742
<p><code>find_element</code> returns either element or throws <code>NoSuchElementException</code>, So for best way to determine element is present with if condition, You should try using <code>find_elements</code> instead of catching exception because it's returns either list of <code>WebElement</code> or empty list, s...
1
2016-08-25T14:15:35Z
[ "python", "selenium" ]
Seaborn and plotly violin plots in Jupyter Notebook kill kernel
39,147,350
<p>I am trying to generate a violin plot using seaborn 0.7.1 in a Jupyter notebook. Boxplot works fine for the same data, but violinplot causes the kernel to "die unexpectedly."</p> <p>I have also tried using plotly 1.12.9 to do a violin plot (following the example on the plotly website), but that also kills the kerne...
0
2016-08-25T13:58:24Z
39,171,409
<p>Given the error message below:</p> <pre><code>Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so. </code></pre> <p>I was able to resolve it by updating numpy to 1.11.1 and scipy to 0.17.1.</p>
0
2016-08-26T17:06:44Z
[ "python", "matplotlib", "plotly", "seaborn", "violin-plot" ]
Euclidean distance of points coordinates in pandas dataframe
39,147,379
<p>I have a pandas dataframe with six columns, first three columns contain <em>x</em>, <em>y</em> and <em>z</em> reference coordinate, and the next three - coordinates of some point. I want to put euclidean distance between those two points in new column of the dataframe. I think about using <code>numpy.linalg.norm</co...
2
2016-08-25T13:59:36Z
39,147,447
<p>You might not need any fancy magic here:</p> <pre><code>df['dist'] = np.sqrt( (df.x1-df.x2)**2 + (df.y1-df.y2)**2 + (df.z1-df.z2)**2) </code></pre>
1
2016-08-25T14:03:00Z
[ "python", "pandas", "numpy", "dataframe" ]
Queryset is returned inside children key
39,147,407
<p>I wanted to list all the reviews along with the replies to specific review of specific restaurant but i could only list the review. While trying to fetch all the replies to its specific review, i called the children() which is defined in Review model. It returned queryset. On the other hand i want all the specific r...
0
2016-08-25T14:01:14Z
39,148,108
<p>Add another serializer that can serialize your children.</p> <pre><code>class ReviewSeraializerChild(serializers.ModelSerializer): class Meta: model = Review class ReviewSeraializer(serializers.ModelSerializer): reply_count = serializers.SerializerMethodField() children = ReviewSeraializerChil...
1
2016-08-25T14:32:27Z
[ "python", "django", "python-3.x", "django-rest-framework" ]
How to undo action in OpenAI Gym?
39,147,440
<p>In OpenAI Gym, I would like to know the next states for different actions on the same state. For example, I want to get s_1, s_2 where the dynamics of my environment are:</p> <p>(s, a_1) -> s_1, (s, a_2) -> s_2</p> <p>I can not find a method that undoes an action, or shows me the next state without changing the en...
0
2016-08-25T14:02:33Z
39,158,935
<p>I found a method named set_state that does exactly this. It can be found at: <a href="https://github.com/openai/gym/blob/master/gym/envs/mujoco/mujoco_env.py" rel="nofollow">https://github.com/openai/gym/blob/master/gym/envs/mujoco/mujoco_env.py</a></p>
0
2016-08-26T05:34:50Z
[ "python", "reinforcement-learning" ]
The error says that user_input is undefined, what to do?
39,147,475
<p>The code is below. Please help.</p> <pre><code>num1 = float(raw_input("Enter a number")) num2 = float(raw_input("Enter another number")) while True: print("Select one of the following options") print("'Add' for addition") print("'Subtract' for subtraction") print("'Multiply' for multipication") ...
0
2016-08-25T14:04:03Z
39,147,607
<p>you are using incorrect equality assignment. == instead of =</p> <pre><code>user_input == raw_input("Enter your choice: ") </code></pre> <p>should be </p> <pre><code>user_input = raw_input("Enter your choice: ") </code></pre>
1
2016-08-25T14:10:14Z
[ "python" ]
The error says that user_input is undefined, what to do?
39,147,475
<p>The code is below. Please help.</p> <pre><code>num1 = float(raw_input("Enter a number")) num2 = float(raw_input("Enter another number")) while True: print("Select one of the following options") print("'Add' for addition") print("'Subtract' for subtraction") print("'Multiply' for multipication") ...
0
2016-08-25T14:04:03Z
39,147,611
<pre><code>user_input == raw_input("Enter your choice: ") </code></pre> <p>should be</p> <pre><code>user_input = raw_input("Enter your choice: ") </code></pre> <p>with only one equal character</p>
1
2016-08-25T14:10:20Z
[ "python" ]
The error says that user_input is undefined, what to do?
39,147,475
<p>The code is below. Please help.</p> <pre><code>num1 = float(raw_input("Enter a number")) num2 = float(raw_input("Enter another number")) while True: print("Select one of the following options") print("'Add' for addition") print("'Subtract' for subtraction") print("'Multiply' for multipication") ...
0
2016-08-25T14:04:03Z
39,147,633
<p>Change</p> <pre><code>user_input == raw_input("Enter your choice: ") </code></pre> <p>to</p> <pre><code>user_input = raw_input("Enter your choice: ") </code></pre>
0
2016-08-25T14:11:16Z
[ "python" ]
multiply a number from a list and a number from a text file?
39,147,480
<p>I am currently trying to multiply a number from a list with a number from a text file however I get the error= <code>Can't multiply sequence by non-int of type 'NonType'</code> , </p> <p>Does anyone have a better method for doing this ?</p> <pre><code>text_file =open("read_it.txt", "r") pricetxt=print(text_file.re...
0
2016-08-25T14:04:35Z
39,147,860
<p>The <code>print()</code> returns None and you are preserving it in <code>pricetxt()</code>. Also you need to convert the result which is a string to <code>int</code> (if it's a correct data). Also note that you better to use a <code>with</code> statement for opening the file, because it will close the file automatic...
1
2016-08-25T14:20:48Z
[ "python", "python-3.x", "numbers" ]
Smooth large data in 3D plot
39,147,482
<p>I have made a 3D plot in Python using matplotlib and Axes3D. It looks pretty good, but it has a lot of jagged edges due to how much data I am plotting. I have tried scipy interpolation methods on the data, but the <code>plot_surface</code> command does not like the type given back. I haven't been able to find out mu...
0
2016-08-25T14:04:42Z
39,153,543
<p>I ended up convolving my data by a 2d array of ones and dividing by the length of the new array.</p> <pre><code>def movingaverage(interval, window_size, mindb): window= numpy.ones((int(window_size),int(window_size)))/(float(window_size)**2) return scipy.signal.convolve2d(interval, window, 'same', fillvalue=...
0
2016-08-25T19:43:19Z
[ "python", "matplotlib", "plot", "3d" ]
Annotate seaborn Factorplot
39,147,492
<p>I would like to visualize 2 boolean informations stored as columns in one seaborn FactorPlot.</p> <p>Here is my df :</p> <p><a href="http://i.stack.imgur.com/KTG5j.png" rel="nofollow"><img src="http://i.stack.imgur.com/KTG5j.png" alt="enter image description here"></a></p> <p>I would like to visualize both of <co...
2
2016-08-25T14:05:20Z
39,152,639
<p>You could make use of <a href="http://matplotlib.org/users/annotations_intro.html" rel="nofollow"><code>plt.annotate</code></a> method provided by <code>matplotlib</code> to make annotations for the <code>factorplot</code> as shown:</p> <p><strong>Setup:</strong> </p> <pre><code>df = pd.DataFrame({'groups':['A', '...
2
2016-08-25T18:45:13Z
[ "python", "pandas", "matplotlib", "seaborn" ]
Is there an iterative way to create tk.Frames and configure them?
39,147,545
<p>Right now I have:</p> <pre><code># create window frames self.f1 = tk.Frame(self.root) self.f2 = tk.Frame(self.root) self.f3 = tk.Frame(self.root) self.f4 = tk.Frame(self.root) self.f5 = tk.Frame(self.root) self.f6 = tk.Frame(self.root) # place frames on window for f in (self.f1, self.f2...
1
2016-08-25T14:07:46Z
39,147,561
<p>Add every new <code>Frame</code> to the list and then iterate over list.</p> <pre><code>frames = [] self.f1 = tk.Frame(self.root) frames.append(self.f1) # Do that for all frames for f in frames: f.configure(bg="white") f.configure(width=self.width, height=self.height, bg="white") f.place(x=0, y=0) </c...
2
2016-08-25T14:08:28Z
[ "python", "python-2.7", "tkinter" ]
python - modify part of a masked array inside a function
39,147,576
<p>I need to modify part of a masked array inside a function eg:</p> <pre><code>import numpy.ma as ma arr_2d = ma.masked_all((5,5)) arr_3d = ma.masked_all((5,5,5)) arr_3d[0,1] = 5 def func1(arr, val): arr[:] = val </code></pre> <p>looks simple enough but then...</p> <pre><code>&gt;&gt;&gt; func1(arr_3d[0], 1) ...
0
2016-08-25T14:09:06Z
39,150,403
<p>The warning in a recent numpy is:</p> <pre><code>In [738]: func1(A[1],1) /usr/local/bin/ipython3:2: MaskedArrayFutureWarning: setting an item on a masked array which has a shared mask will not copy the mask and also change the original mask array in the future. Check the NumPy 1.11 release notes for more informat...
0
2016-08-25T16:28:52Z
[ "python", "arrays", "numpy", "masked-array" ]
Set WTForms submit button to icon
39,147,578
<p>I want a submit button that displays an icon rather than text. The button is a field in a WTForms form. I am using Bootstrap and Open Iconic for styling and icons. How do I set the submit field to display an icon?</p> <pre><code>class MyForm(Form): submit = SubmitField('') </code></pre> <pre><code>{{ form...
1
2016-08-25T14:09:09Z
39,150,281
<p>The example you linked is using macros provided by Flask-Bootstrap. The macros make it easy to construct forms with Bootstrap, but might not be flexible. For example, they probably don't support using Open Iconic icons instead.</p> <p>Typically, you don't need to specify the submit button in the form, as it doesn...
0
2016-08-25T16:21:33Z
[ "python", "flask", "jinja2", "wtforms", "iconic" ]
How to append values to a list of lists using other list of lists and doing mathematical operations
39,147,612
<p>I have several lists of lists:</p> <pre><code>crt = [[80, 90, 6, 5.4, 8, 5], [65, 58, 2, 9.7, 1, 1], [83, 60, 4, 7.2, 4, 7], [40, 80, 10, 7.5, 7, 10], [52, 72, 6, 2, 3, 8], [94, 96, 7, 3.6, 5, 6]] nc = [[1, 2, 3, 4, 5, 6], [1, 1, 1, 1, 1, 1], [-1, 1, -1, -1, -1, 1], [2, 3, 5, 6, 1, 6], [10, 0, 0.5, 1,...
0
2016-08-25T14:10:27Z
39,148,912
<p>Does this answer your question?</p> <pre><code>pref_indic = [] for x in range(len(crt)): if nc[3][x] == 1: prolist = [] for y in range(len(DivMatrix[x])): prolist2 = [] for z in range(len(DivMatrix[x][y])): if DivMatrix[x][y][z] &lt;= 0: ...
0
2016-08-25T15:12:47Z
[ "python", "list", "if-statement", "for-loop", "append" ]
How to append values to a list of lists using other list of lists and doing mathematical operations
39,147,612
<p>I have several lists of lists:</p> <pre><code>crt = [[80, 90, 6, 5.4, 8, 5], [65, 58, 2, 9.7, 1, 1], [83, 60, 4, 7.2, 4, 7], [40, 80, 10, 7.5, 7, 10], [52, 72, 6, 2, 3, 8], [94, 96, 7, 3.6, 5, 6]] nc = [[1, 2, 3, 4, 5, 6], [1, 1, 1, 1, 1, 1], [-1, 1, -1, -1, -1, 1], [2, 3, 5, 6, 1, 6], [10, 0, 0.5, 1,...
0
2016-08-25T14:10:27Z
39,149,268
<p>here is your code, modified just enough to do what you want (I guess, not sure):</p> <pre><code>pref_indic = [] for x in range(len(crt)): if (nc[3][x] == 1): prolist = [] for y in range(len(DivMatrix[x])): prolist2 = [] for z in range(len(DivMatrix[x][y])): ...
0
2016-08-25T15:31:26Z
[ "python", "list", "if-statement", "for-loop", "append" ]
Profile cpu and memory usage during py.test execution
39,147,678
<p>I am facing the following project. I want to create pictures showing the cpu and memory level during the execution of a set of performance test suites. I would appreciate any suggestion.</p> <p>Currently the only approach I am considering is to use the command top or the python module <a href="https://pypi.python.o...
0
2016-08-25T14:13:11Z
39,216,968
<p>There are a whole bunch of ways of doing this, ranging from getting broad system statistics and then averaging them (top), to using processor hardware counters (e.g. using Intel VTune).</p> <p>psutil seems perfectly fine. My only comment is to make sure you take many measurements and then average them to get rid of...
1
2016-08-30T00:05:49Z
[ "python", "memory", "cpu-usage", "py.test" ]
Python: ImportError: cannot import name 'BeautifulSoup'
39,147,715
<p>I have always used R and now trying to switch to Python. I'm using Pycharm and found this error when running the following code:</p> <pre><code>import pandas as pd from bs4 import BeautifulSoup example1 = BeautifulSoup(train["review"][0],"lxml") print (example1.get_text()) </code></pre> <p>When I run it I have: <...
0
2016-08-25T14:14:21Z
39,159,068
<p>Oh,I think you should check your file name or folder name.If there is a name that is already used in bs4 module,you will got ImportError.</p> <p>Hope this helps.</p>
0
2016-08-26T05:45:47Z
[ "python", "python-3.x", "console", "pycharm" ]
Selecting audio device for playback via Python
39,147,723
<p>How to get a list of audio devices in linux (like <code>aplay -L</code>) and select audio device for the output? are there any libs to import? Are they already imported? </p>
1
2016-08-25T14:14:47Z
39,148,338
<p>I searched high and low for what you are asking for when writing a sound equaliser and never found a satisfactory answer.<br> There is an alsaaudio library available:</p> <pre><code>import alsaaudio #alternative method pure python for device_number, card_name in enumerate(alsaaudio.cards()): print device_numb...
1
2016-08-25T14:43:56Z
[ "python", "linux", "python-3.x", "audio" ]
SQLalchemy - query by like for float column
39,147,924
<p>I want to query my database for records like a float variable (map coordinates) from an ajax.(querying float column). i'm not sure if the like method can query data types other than strings, because this didn't work...</p> <pre><code>data = json.loads(request.data) markers = session.query(Markers) \ ...
2
2016-08-25T14:23:50Z
39,152,989
<p>You need to cast float to string</p> <pre><code>from sqlalchemy import cast, String markers = session.query(Markers) \ .filter(cast(Markers.lat, String()).like('%' + data['lat'] + '%')) </code></pre>
1
2016-08-25T19:07:41Z
[ "python", "postgresql", "sqlalchemy" ]
Errno 13 Permission denied with Django on a directory I don't want to use
39,147,935
<p>I have this error appearing in my Django app on my production server :</p> <blockquote> <p>[Errno 13] Permission denied: '/var/www/.config'</p> </blockquote> <p>I never asked to access to this unexisting file or directory in my code. The server is running in a different directory defined in my httpd.conf and I h...
1
2016-08-25T14:24:25Z
39,148,146
<p>Restart the server or restart the service of django.<br> That is important, because the services in the background have to know the new location of the configuration. <br> I guess it works on python, because the library is loading the actual settings and the background service is using the old one.</p> <p>Hope I co...
0
2016-08-25T14:34:11Z
[ "python", "django", "apache", "python-3.x", "biopython" ]
Errno 13 Permission denied with Django on a directory I don't want to use
39,147,935
<p>I have this error appearing in my Django app on my production server :</p> <blockquote> <p>[Errno 13] Permission denied: '/var/www/.config'</p> </blockquote> <p>I never asked to access to this unexisting file or directory in my code. The server is running in a different directory defined in my httpd.conf and I h...
1
2016-08-25T14:24:25Z
39,148,897
<p>In facts, <code>Entrez.parse</code> is calling the <strong>DataHandler</strong> objects. This objects try to write in the user directory with something like : </p> <pre><code>home = os.path.expanduser('~') directory = os.path.join(home, '.config', 'biopython') local_xsd_dir = os.path.join(directory, 'Bio', 'Entrez'...
1
2016-08-25T15:12:16Z
[ "python", "django", "apache", "python-3.x", "biopython" ]
Python, select a specific line
39,147,958
<p>I want to read a textfile using python and print out specific lines. The problem is that I want to print a line which starts with the word "nominal" (and I know how to do it) and the line following this which is not recognizable by some specific string. Could you point me to some lines of code that are able to do th...
0
2016-08-25T14:25:36Z
39,148,098
<p>In good faith and under the assumption that this will help you start coding and showing some effort, here you go:</p> <pre><code>file_to_read = r'myfile.txt' with open(file_to_read, 'r') as f_in: flag = False for line in f_in: if line.startswith('nominal'): print(line) flag ...
0
2016-08-25T14:32:09Z
[ "python" ]
Python, select a specific line
39,147,958
<p>I want to read a textfile using python and print out specific lines. The problem is that I want to print a line which starts with the word "nominal" (and I know how to do it) and the line following this which is not recognizable by some specific string. Could you point me to some lines of code that are able to do th...
0
2016-08-25T14:25:36Z
39,148,647
<p>If the file isn't too large, you can put it all in a list:</p> <pre><code>def printLines(fname): with open(fname) as f: lines = f.read().split('\n') if len(lines) == 0: return None if lines[0].startswith('Nominal'): print(lines[0]) for i, line in enumerate(lines[1:]): ...
0
2016-08-25T14:59:31Z
[ "python" ]
Hex to a String Python
39,147,995
<p>I would like to convert </p> <p>the hex value </p> <pre><code>a = 0x32 </code></pre> <p>to a string <code>d = 32</code></p> <p>Bascially I have a numpy array </p> <pre><code>msg = np.array[2, 50] </code></pre> <p>I need to convert both values to hex --- <code>[0x02 , 0x32]</code> then print the hex values as...
-2
2016-08-25T14:27:38Z
39,148,109
<p><code>hex()</code> will give you hex string. Then discard first 2 characters</p> <pre><code>&gt;&gt;&gt; hex(a) '0x32' &gt;&gt;&gt; hex(a)[2:] '32' &gt;&gt;&gt; </code></pre> <p>Looking at the link to duplicate, it seems numpy is giving you the L at the end since you are running 64bit linux. so do this:</p> <p...
0
2016-08-25T14:32:29Z
[ "python", "string", "numpy", "hex" ]
Condensing repeat code with a "for" statement using strings - Python
39,148,047
<p>I am very new with "for" statements in Python, and I can't get something that I think should be simple to work. My code that I have is: </p> <pre><code>import pandas as pd df1 = pd.DataFrame({'Column1' : pd.Series([1,2,3,4,5,6])}) df2 = pd.DataFrame({'Column1' : pd.Series([1,2,3,4,5,6])}) df3 = pd.DataFrame({'Colu...
1
2016-08-25T14:29:38Z
39,151,048
<p>It is "restricted" to generate variables in for loop (you can do that, but it's better to avoid. See other posts: <a href="http://stackoverflow.com/questions/6181935/how-do-you-create-different-variable-names-while-in-a-loop-python">post_1</a>, <a href="http://stackoverflow.com/questions/13603215/using-a-loop-in-pyt...
2
2016-08-25T17:07:16Z
[ "python", "pandas", "for-loop" ]
Condensing repeat code with a "for" statement using strings - Python
39,148,047
<p>I am very new with "for" statements in Python, and I can't get something that I think should be simple to work. My code that I have is: </p> <pre><code>import pandas as pd df1 = pd.DataFrame({'Column1' : pd.Series([1,2,3,4,5,6])}) df2 = pd.DataFrame({'Column1' : pd.Series([1,2,3,4,5,6])}) df3 = pd.DataFrame({'Colu...
1
2016-08-25T14:29:38Z
39,749,385
<p>Figured out a better way to do this that fits my needs. This is mainly so that I will be able to find my method.</p> <pre><code># Change/Add animals and conditions here, make sure they match up directly Animal = ['26','45','46','47','51','58','64','65', '69','72','84'] Cond = ['Stomach','Intestine','Stomach','Stom...
0
2016-09-28T13:45:40Z
[ "python", "pandas", "for-loop" ]
Python multiprocessing for shared memory with an array of lists
39,148,106
<p>I need to know if there is a way to share memory for an array of bool lists:</p> <pre><code>s = Array( 'x' , range(10000000)) </code></pre> <p>What do I have to write instead of x to make it an array of lists whose size is 64. Then I have to manipulate "s" in two different processes like these:</p> <pre><code>#F...
0
2016-08-25T14:32:21Z
39,163,440
<p>Python <code>Multiprocessing</code> module allows 2 types of shared variables : <code>Array</code>, which is a simple 1D array of a single dtype, and <code>Value</code>, which is just a single value.</p> <p>You can design your own shared variables using ctype, if you know your way in C : see the <a href="https://do...
0
2016-08-26T09:51:45Z
[ "python", "multiprocessing", "shared-memory", "python-multiprocessing" ]
join polygons without overlay (and plot)
39,148,200
<p>I'm trying to join a set of polygons to create a single polygon. These polygons (they are not closed as in the last point being equal to the first), their edges are exactly equal at some point:</p> <pre><code>poly1 = [(0,0), (1,0), (1,0.25), (1, 0.5), (1,0.75), (1,1), (0,1)] poly2 = [(2,0), (2,0.25), (1,0.25), (1,0...
0
2016-08-25T14:37:32Z
39,153,528
<p>I think the problem is that your second Polygon has a self-join.</p> <pre><code>poly1 = Polygon([(0,0), (1,0), (1,0.25), (1, 0.5), (1,0.75), (1,1), (0,1)]) poly2 = Polygon([(2,0), (2,0.25), (1,0.25), (1,0.5), (1,0.75), (2,1)]) poly2_corrected = Polygon([(2,0), (1,0.25), (1,0.5), (1,0.75), (2,1)]) </code></pre> <p>...
0
2016-08-25T19:42:34Z
[ "python", "shapely" ]
Approximating Numerical 2nd Derivative with Python
39,148,258
<p>To preface this question, I understand that it could be done better. But this is a question in a class of mine and I must approach it this way. We cannot use any built in functions or packages.</p> <p>I need to write a function to approximate the numerical value of the second derivative of a given function using fi...
3
2016-08-25T14:39:44Z
39,148,345
<p>you can pass the function as any other "variable":</p> <pre><code>def f(x): return 2*x*x + 4 def d2(fn, x0, h): return (fn(x0+h) - 2*fn(x0) + fn(x0-h))/(h*h) print(d2(f, 6, 0.1)) </code></pre>
3
2016-08-25T14:44:32Z
[ "python" ]
Approximating Numerical 2nd Derivative with Python
39,148,258
<p>To preface this question, I understand that it could be done better. But this is a question in a class of mine and I must approach it this way. We cannot use any built in functions or packages.</p> <p>I need to write a function to approximate the numerical value of the second derivative of a given function using fi...
3
2016-08-25T14:39:44Z
39,148,439
<p>you can't pass a literal expression, you need a function (or a lambda).</p> <pre><code>def d2(f, x0, h = 1e-9): func = f if isinstance(f, str): # quite insecure, use only with controlled input func = eval ("lambda x:%s" % (f,)) return (func(x0+h) - 2*func(x0) + func(x0-h))/(2*h) </code></pre> ...
0
2016-08-25T14:48:54Z
[ "python" ]
Using ac2git followed by bitbucket
39,148,266
<p>I am using ac2git to convert my accurev depot to git repository. I am able to successfully make the conversion however when I follow the steps after creating the new repository I am unable to push the changes representing the accurev transactions that are now commits.</p> <p>What I mean is I loose the history, I am...
0
2016-08-25T14:39:59Z
39,153,982
<p>Your first step is to create a repository in BitBucket. Then you simply need to follow BitBucket's instructions:</p> <pre><code>cd /path/to/my/repo git remote add origin http://****@bitbucket.******.git git push -u origin --all # pushes up the repo and its refs for the first time git push origin --tags # pushes up ...
1
2016-08-25T20:12:30Z
[ "python", "git", "bitbucket" ]
Using ac2git followed by bitbucket
39,148,266
<p>I am using ac2git to convert my accurev depot to git repository. I am able to successfully make the conversion however when I follow the steps after creating the new repository I am unable to push the changes representing the accurev transactions that are now commits.</p> <p>What I mean is I loose the history, I am...
0
2016-08-25T14:39:59Z
39,311,340
<p>I'm not 100% certain that this is what has happened but it is worth noting that the <strong>ac2git</strong> script stores a lot of metadata under <code>refs/ac2git/*</code> refs, including a refs that will store a <code>hist.xml</code>, <code>streams.xml</code> and <code>diff.xml</code> in their commit history for e...
0
2016-09-03T21:07:57Z
[ "python", "git", "bitbucket" ]
ImportError: No module named _mysql
39,148,410
<p>I'm trying to use the Python module MySQL-python to connect to an external MySQL database from an AWS EC2 instance running amazon linux.</p> <p>This is the code I'm trying to run:</p> <pre><code>db=_mysql.connect(host="hostname",user="dbuser",passwd="dbpassword",db="database") db.query("""SELECT id, field1 FROM te...
3
2016-08-25T14:47:49Z
39,148,708
<p>Only a workaround, but one that worked for me in situations where I could not easily call "sudo pip install".</p> <p>What you (often, not always) can do:</p> <ol> <li>Turn to a system where that python module you are looking for works</li> <li>Identify its "location", for example, after installing enum34 on my ubu...
1
2016-08-25T15:02:39Z
[ "python", "linux", "amazon-web-services", "amazon-ec2", "mysql-python" ]
How to replace a list of strings in a text where some of them are substrings of other in python?
39,148,421
<p>I have a text containing some words that I would like to tag, and the words to be tagged are contained in a List. The problem is that some of those words are substrings of others, but I want to tag the longest recognized string from the list.</p> <p>For example, if my text is "foo and bar are different from foo bar...
1
2016-08-25T14:48:16Z
39,149,494
<p>If I understood your problem correctly, then this is something you are looking for :-</p> <pre><code>text = "foo and bar are different from foo bar." words = ["foo", "bar", "foo bar"] add_tag = lambda var : "&lt;tag&gt;"+var+"&lt;/tag&gt;" result = '' # for final string for var in text.split(): if var in w...
0
2016-08-25T15:41:14Z
[ "python", "regex", "string", "substring" ]
How to replace a list of strings in a text where some of them are substrings of other in python?
39,148,421
<p>I have a text containing some words that I would like to tag, and the words to be tagged are contained in a List. The problem is that some of those words are substrings of others, but I want to tag the longest recognized string from the list.</p> <p>For example, if my text is "foo and bar are different from foo bar...
1
2016-08-25T14:48:16Z
39,150,190
<p>A simple way to achieve that would be to sort <code>words</code> by length in the reversed order and then create a regular expression <code>word1|word2|...</code>. Since the re engine always takes the first match, longer strings will be catched first.</p> <pre><code>import re def tag_it(text, words): return re...
0
2016-08-25T16:16:30Z
[ "python", "regex", "string", "substring" ]
What's the correct way to change a value that is imported by other modules?
39,148,446
<p>I have my entry point script take a CLI option argument using <code>argsparser</code> and that looks something like this:</p> <pre><code> import some_module if __name__== "__main__": parser = argparse.ArgumentParser(description='Nemo Node.') parser.add_argument('-t', '--test', dest='testing'...
0
2016-08-25T14:49:14Z
39,149,169
<p>Since <code>some_module.TESTING</code> is set immediately after import, <em>that's</em> the value you want to update, not <code>settings.TESTING</code>.</p> <pre><code>import some_module if __name__== "__main__": parser = argparse.ArgumentParser(description='Nemo Node.') parser.add_argument('-t', '--test',...
0
2016-08-25T15:25:47Z
[ "python" ]
What is being called when doing int() and float()?
39,148,472
<p>I understand that when I do:</p> <pre><code>&gt;&gt;&gt; int(4.0) &gt;&gt;&gt; int('10') </code></pre> <p>The <code>__init__()</code> method from the class of the argument (in the example, <code>float</code> and <code>str</code>, respectively), will be called.</p> <p>I wonder what will happen if I do <code>int()<...
-2
2016-08-25T14:50:54Z
39,149,008
<p>in python <a href="http://stackoverflow.com/a/865963/3220135">everything is an object</a>, so when you call:</p> <p><code>x = int(y)</code> then constructor <code>int.__new__(cls, value=y)</code> is called.</p> <p>this returns an int object and assigns it to <code>x</code>.</p> <p><code>x</code> may have a method...
0
2016-08-25T15:18:10Z
[ "python", "constructor", "int" ]
Python importing modules in CMD
39,148,477
<p>Hello thanks for looking. </p> <p>i am trying to import third party modules but having a hard time. </p> <p>I have already done the edit to the environment variable and i get python to show up in cmd but I can not find the correct syntax to do the install. </p> <p>based on the python org site i should use pytho...
0
2016-08-25T14:51:14Z
39,148,594
<p>you are trying to give command line arguments within the interpreter...</p> <p>If PIP is installed, you don't need to invoke the interpreter at all. Simply call:</p> <pre><code>C:\Users\T****J&gt;pip install send2trash </code></pre> <p>from the command prompt.</p> <p>otherwise, if you are using the pip module, y...
1
2016-08-25T14:57:09Z
[ "python", "python-3.5", "python-3.5.2" ]
Python importing modules in CMD
39,148,477
<p>Hello thanks for looking. </p> <p>i am trying to import third party modules but having a hard time. </p> <p>I have already done the edit to the environment variable and i get python to show up in cmd but I can not find the correct syntax to do the install. </p> <p>based on the python org site i should use pytho...
0
2016-08-25T14:51:14Z
39,148,711
<p><code>pip</code> is a program itself, similar to how <code>npm</code>, <code>bundler</code> or <code>nuget</code> works.</p> <p>What you are currently doing is firing up the Python interpreter, and writing the call to pip from there, it doesn't work like that.</p> <p>What you're looking to do is to install a packa...
0
2016-08-25T15:02:49Z
[ "python", "python-3.5", "python-3.5.2" ]
Parse custom XML to JSON or Pandas DataFrame. (Python)
39,148,524
<p>The following is my xml document.</p> <pre><code>&lt;BizTalk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Body&gt; &lt;QUEUE&gt; &lt;FILTER FILTERNAME="CorrectAddress" VALUE="1" /&gt; &lt;FILTER FILTERNAME="DaysSinceLastTracking" VALUE="0" /&gt; ...
0
2016-08-25T14:53:29Z
39,149,617
<p>Cool, I found a solution to this. I did the following:</p> <pre><code>df = pd.DataFrame() etree = ET.fromstring(xml_data) # root = etree.getroot() for node in etree.findall('.//FILTER'): parent = node.attrib.get('FILTERNAME') child = node.attrib.get('VALUE') col_name = parent val = child df[c...
0
2016-08-25T15:47:40Z
[ "python", "json", "xml", "pandas", "xml-parsing" ]
how to change python version used by apache?
39,148,616
<p>When I launch my CGI (common gateway interface) by using this code: </p> <pre><code># -*- coding: utf-8 -*- import cgi import os import json import cgitb cgitb.enable() from sklearn.feature_extraction.text import CountVectorizer print 'Content-type: text/html' print print '&lt;html&gt;&lt;head&gt;&lt;title&...
0
2016-08-25T14:58:27Z
39,148,966
<p>You should have a first line like <code>#! /usr/bin/python</code> (called Shebang line) in your script. You have to change that line to point to the python executable you actually want. For Windows have a look at <a href="https://docs.python.org/3/using/windows.html?highlight=shebang#shebang-lines" rel="nofollow">th...
0
2016-08-25T15:15:53Z
[ "python", "html", "apache", "path", "cgi" ]
How Can I Run Python Class in aws lambda environment?
39,148,782
<p>I have a python class include some methods and I want to run it in Lambda Function and test it. I have a problem with executing in lambda environment .I didn't find any example for using class in Lambda function.I have some error for modifying handler and importing Modules .Is it possible using class in lambda Funct...
-1
2016-08-25T15:06:21Z
39,610,969
<p>I have also the same doubt how to run the below code in aws lambda using function.</p> <hr> <p>import base64 import hashlib</p> <p>from Crypto import Random from Crypto.Cipher import AES</p> <p>class AESCipher(object):</p> <pre><code>def __init__(self, key): self.bs = 32 self.key = hashlib.sha256(AESCip...
1
2016-09-21T08:13:12Z
[ "python", "amazon-web-services", "aws-lambda" ]
How to trigger next package installation by "no command line activity" in Python
39,148,826
<p>I build installation wizard to application in Python. Recognising all commands included - requires, prior to running - installing of about 20 different packages (project uses different calculation types, like: SVM, FFT, 3D harmonics, K-nearest neighbours, and additional packages for utilising command line and for GU...
0
2016-08-25T15:08:46Z
39,150,256
<p>The default state of most things in programming is to wait for a function/method/process to return before moving on. For example, if you use <a href="https://docs.python.org/3.5/library/subprocess.html#subprocess.run" rel="nofollow">subprocess.run()</a> to run each command involved in installing, it will wait for th...
0
2016-08-25T16:20:25Z
[ "python", "installation", "install", "installer", "wizard" ]
How do I send emails using django-simple-email-confirmation?
39,148,845
<p>I have just started using <a href="https://github.com/mfogel/django-simple-email-confirmation" rel="nofollow">django-simple-email-confirmation</a>. They have an example of how to use it, which invokes a <code>send_email</code> method, as below:</p> <pre><code>email = 'original@here.com' user = User.objects.create_u...
0
2016-08-25T15:09:52Z
39,149,410
<p>The <code>send_email</code> in the example looks like a typo. It looks to me as if they are using <a href="https://docs.djangoproject.com/en/1.10/topics/email/#send-mail" rel="nofollow"><code>send_mail</code></a> from Django. Try adding the following import:</p> <pre><code>from django.core.mail import send_mail </c...
0
2016-08-25T15:37:24Z
[ "python", "django", "email" ]
Regular expression for parsing numbers in python
39,148,905
<p>Could anyone help me with the following scenario? </p> <p>NFL season is approaching and I am working on a python script to scrape spreads off a website for analysis. </p> <p>scenario one: spread comes in the form -3+3</p> <p>scenario two: spread comes in the form -3.5+3.5</p> <pre><code>import re s1 = '-3+3' ...
2
2016-08-25T15:12:29Z
39,149,027
<p>You can use <code>re.findall()</code> with <code>'(.\d(?:\.\d+)?)'</code> as your regex, which uses an optional group for matching the decimal part:</p> <pre><code>&gt;&gt;&gt; re.findall(r'(.\d+(?:\.\d+)?)', s1) ['-3', '+3'] &gt;&gt;&gt; re.findall(r'(.\d+(?:\.\d+)?)', s2) ['-3.5', '+3.5'] </code></pre>
3
2016-08-25T15:18:34Z
[ "python", "regex" ]
Regular expression for parsing numbers in python
39,148,905
<p>Could anyone help me with the following scenario? </p> <p>NFL season is approaching and I am working on a python script to scrape spreads off a website for analysis. </p> <p>scenario one: spread comes in the form -3+3</p> <p>scenario two: spread comes in the form -3.5+3.5</p> <pre><code>import re s1 = '-3+3' ...
2
2016-08-25T15:12:29Z
39,149,743
<p>As I said in the comments, this regular expression will grab any pairs of numbers, optionally preceded by +/-, with a decimal or not. </p> <pre><code>([-+]?\d+(?:\.\d+)?)([-+]?\d+(?:\.\d+)?) </code></pre> <p>Also, if you are going to be using the same regular expression more than once (and especially if you will b...
2
2016-08-25T15:53:12Z
[ "python", "regex" ]
Regular expression for parsing numbers in python
39,148,905
<p>Could anyone help me with the following scenario? </p> <p>NFL season is approaching and I am working on a python script to scrape spreads off a website for analysis. </p> <p>scenario one: spread comes in the form -3+3</p> <p>scenario two: spread comes in the form -3.5+3.5</p> <pre><code>import re s1 = '-3+3' ...
2
2016-08-25T15:12:29Z
39,150,108
<p>Here's an example that works with multiple digit numbers:</p> <pre><code>import re NUMBERS_RE = '[\-\+]\d*\.?\d+' s1 = '-3+3' s2 = '-3.5+3.5-12.56+300.9998-.2+5' print re.findall(NUMBERS_RE, s1) print re.findall(NUMBERS_RE, s2) </code></pre> <p>This outputs:</p> <pre><code>['-3', '+3'] ['-3.5', '+3.5', '-12.56...
0
2016-08-25T16:12:42Z
[ "python", "regex" ]