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
listlengths
1
5
decimal.Decimal is not iterable error
38,361,458
<p>I have a simple script that takes a list containing 3 columns of data. The second column of data contains currency values with a leading dollar sign. I have stripped away the dollar sign from the second column, now I need to add up the values. I'm getting a "decimal.Decimal is not iterable" error. Here is the co...
0
2016-07-13T20:51:25Z
38,361,491
<p><code>sum()</code> takes an iterable. Just change your code to <code>total += dollar_dec</code></p>
0
2016-07-13T20:53:32Z
[ "python" ]
decimal.Decimal is not iterable error
38,361,458
<p>I have a simple script that takes a list containing 3 columns of data. The second column of data contains currency values with a leading dollar sign. I have stripped away the dollar sign from the second column, now I need to add up the values. I'm getting a "decimal.Decimal is not iterable" error. Here is the co...
0
2016-07-13T20:51:25Z
38,361,522
<pre><code>total = sum(dollar_dec) </code></pre> <p>sum() takes an iterable (a list, for example) and adds up all the values. You are passing it a single number, which is an error. You probably want</p> <pre><code>total = Decimal('0.0') ... total += dollar_dec </code></pre> <p>Which will keep a running total.</p> ...
1
2016-07-13T20:54:51Z
[ "python" ]
decimal.Decimal is not iterable error
38,361,458
<p>I have a simple script that takes a list containing 3 columns of data. The second column of data contains currency values with a leading dollar sign. I have stripped away the dollar sign from the second column, now I need to add up the values. I'm getting a "decimal.Decimal is not iterable" error. Here is the co...
0
2016-07-13T20:51:25Z
38,361,784
<p>Say, you have the following file content:</p> <pre><code>content = """\ one $1.50 two $3.00 three $4.50""" </code></pre> <p>You can use the in-place operator <code>+=</code> to calculate the total:</p> <pre><code>from decimal import Decimal import io total = Decimal(0) with io.StringIO(content) as fd: for li...
1
2016-07-13T21:10:52Z
[ "python" ]
How do I locate python command line tools after installing to (non-root) user account?
38,361,505
<p>On my work server I run <code>sudo pip install httpie</code> which allows me to execute <code>http google.com</code>.</p> <p>On my school server I run <code>pip install --user httpie</code>. When I attempt to use the utility, I get a <code>http: command not found</code> error. I know that the package is installed a...
2
2016-07-13T20:54:02Z
38,361,546
<p>Typically they'll be installed to <code>~/.local/bin</code>.</p> <p>Add that to your path:</p> <p><code>export PATH="$PATH":/home/grads/me/.local/bin</code></p> <p>And you should be able to run the command like you expect.</p>
1
2016-07-13T20:56:10Z
[ "python", "command-line-interface", "httpie" ]
Fill the missing date values in a Pandas Dataframe column
38,361,526
<p>I'm using Pandas to store stock prices data using Data Frames. There are 2940 rows in the dataset. The Dataset snapshot is displayed below:</p> <p><a href="http://i.stack.imgur.com/ptPzP.png" rel="nofollow"><img src="http://i.stack.imgur.com/ptPzP.png" alt="enter image description here"></a></p> <p>The time series...
2
2016-07-13T20:55:01Z
38,361,725
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html" rel="nofollow"><code>resample</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.tseries.resample.Resampler.ffill.html" rel="nofollow"><code>ffill</code></a> or <a hre...
2
2016-07-13T21:07:30Z
[ "python", "numpy", "pandas", "time-series" ]
Skip header after the first time CSV file is written into (Python)
38,361,582
<p>The following script for writing to a CSV file is going to run on a server which will automate the run.</p> <pre><code> d = {'col1': a, col2': b, col3': c,} df = pandas.DataFrame(d, index = [0]) with open('foo.csv', 'a') as f: df.to_csv(f, index = False) </code></pre> <p>The problem is, ...
2
2016-07-13T20:58:26Z
38,361,891
<p>try this:</p> <pre><code>filename = '/path/to/file.csv' df.to_csv(filename, index=False, mode='a', header=(not os.path.exists(filename))) </code></pre>
1
2016-07-13T21:20:36Z
[ "python", "csv", "pandas", "dataframe", "header" ]
Search a dictionary criteria with terms and return key
38,361,639
<p>I have a dictionary with a criteria and I want to return one key if any one of the terms matches with the criteria. Here's what my code looks like so far: </p> <pre><code>import re import pyodbc keyword_dictionary = { 'Animals' : {'animal', 'dog', 'cat'}, 'Art' : {'art', 'sculpture', 'fearns','graphic','di...
2
2016-07-13T21:01:46Z
38,361,820
<p>I don't know what the pyodbc or cursor part of this code is, but I have tried running the following and it works. I'm not sure if it's exactly what you want though as it's returning the answers in a list and I might have miss interpreted the form of the "terms" input.</p> <pre><code>import re keyword_dictionary = ...
1
2016-07-13T21:14:52Z
[ "python", "dictionary" ]
Search a dictionary criteria with terms and return key
38,361,639
<p>I have a dictionary with a criteria and I want to return one key if any one of the terms matches with the criteria. Here's what my code looks like so far: </p> <pre><code>import re import pyodbc keyword_dictionary = { 'Animals' : {'animal', 'dog', 'cat'}, 'Art' : {'art', 'sculpture', 'fearns','graphic','di...
2
2016-07-13T21:01:46Z
38,361,842
<p>Your code splits the searcher into single letters, you need to split by spaces. The rest seems OK.</p> <p>Example:</p> <pre><code>searcher = 'wendy bought a dog' # result: single letters for word in searcher: print word # result: words for word in searcher.split(' '): print word </code></pre>
1
2016-07-13T21:17:04Z
[ "python", "dictionary" ]
Search a dictionary criteria with terms and return key
38,361,639
<p>I have a dictionary with a criteria and I want to return one key if any one of the terms matches with the criteria. Here's what my code looks like so far: </p> <pre><code>import re import pyodbc keyword_dictionary = { 'Animals' : {'animal', 'dog', 'cat'}, 'Art' : {'art', 'sculpture', 'fearns','graphic','di...
2
2016-07-13T21:01:46Z
38,361,882
<p>Set operations are the way to go here:</p> <pre><code>def matcher(keywords, searcher): for sentence in searcher: sentence= set(sentence.split()) # split sentence into words for key,words in keywords.iteritems(): if sentence &amp; words: # if these two sets of words intersect, output ...
2
2016-07-13T21:19:46Z
[ "python", "dictionary" ]
Search a dictionary criteria with terms and return key
38,361,639
<p>I have a dictionary with a criteria and I want to return one key if any one of the terms matches with the criteria. Here's what my code looks like so far: </p> <pre><code>import re import pyodbc keyword_dictionary = { 'Animals' : {'animal', 'dog', 'cat'}, 'Art' : {'art', 'sculpture', 'fearns','graphic','di...
2
2016-07-13T21:01:46Z
38,362,027
<p>I'd think the easiest way to solve this is to <a href="http://stackoverflow.com/questions/483666/python-reverse-inverse-a-mapping">reverse the keys and values</a> of <code>keyword_dictionary</code> and perform a search on every word.</p> <p>I put a simple example of this on <a href="https://repl.it/Cbla/2" rel="nof...
1
2016-07-13T21:30:34Z
[ "python", "dictionary" ]
default() method in Python
38,361,769
<p>I am making an Encoder for converting python objects to json and when researching I see a lot of solutions that include a <code>default</code> method. I'm not an expert in Python, but definitely not a novice either, and I'm wondering if I somehow missed that there is a <code>default</code> method that gets run auto...
1
2016-07-13T21:10:00Z
38,361,858
<p><code>JSONEncoder</code> has a <code>default</code> method which gets called if it doesn't know how to coerce a particular object into valid JSON. The default implementation just raises <code>TypeError</code> (because it doesn't know how to coerce the type). However, when <em>you</em> override the default method, ...
2
2016-07-13T21:18:15Z
[ "python", "default", "encoder" ]
default() method in Python
38,361,769
<p>I am making an Encoder for converting python objects to json and when researching I see a lot of solutions that include a <code>default</code> method. I'm not an expert in Python, but definitely not a novice either, and I'm wondering if I somehow missed that there is a <code>default</code> method that gets run auto...
1
2016-07-13T21:10:00Z
38,361,867
<p>Runnning <code>dir(JSONEncoder)</code> gives us:</p> <pre><code>['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__'...
2
2016-07-13T21:18:44Z
[ "python", "default", "encoder" ]
default() method in Python
38,361,769
<p>I am making an Encoder for converting python objects to json and when researching I see a lot of solutions that include a <code>default</code> method. I'm not an expert in Python, but definitely not a novice either, and I'm wondering if I somehow missed that there is a <code>default</code> method that gets run auto...
1
2016-07-13T21:10:00Z
38,361,872
<p>I think this method is defined in <code>json.JSONEncoder</code> as described <a href="https://docs.python.org/2.7/library/json.html" rel="nofollow">here</a>. <code>default(o)</code> should return a serializable version of the given object or pass it to its superclass. </p>
1
2016-07-13T21:19:08Z
[ "python", "default", "encoder" ]
Approximation polynomial fit to given data
38,361,792
<p>I'm facing a problem with aproximation polynomial fit. A more detailed review of my problem is shown <a href="http://stackoverflow.com/questions/38285811/smoothing-higher-order-polynomials-and-nonlinear-r-squared">HERE</a>. Basically I want to smooth the mid section of the polynomial that I got through long mathemat...
1
2016-07-13T21:11:49Z
38,361,952
<p>You are trying to fit a polynomial on regular data which is in exp-exp scale, and only plot it in log-log, where it looks like a polynomial. You will not be able to represent such relation with a polynomial. Preprocess everything to be in log scale in the first place, fit polynomial there, and if you want to go back...
4
2016-07-13T21:24:59Z
[ "python", "python-3.x", "math", "polynomial-math", "smoothing" ]
Python dict get function not doing the right thing?
38,361,803
<p>I thought that the <code>.get(key, default=?)</code> function will look at the <code>default</code> part only if <code>key</code> is not in the dict.</p> <p>What I want to do is, see if a key exists in my main dictionary, if not, see if it exists in backup dictionary, and raise KeyError if it is neither in main or ...
2
2016-07-13T21:13:24Z
38,361,832
<p>The arguments to a function call are evaluated before the call is made. When you use <code>backupDict[key]</code> as an argument, that has to be evaluated so the result can be passed to <code>get</code>. The <code>default</code> argument is always <em>evaluated</em>; it's just not always <em>returned</em>.</p> <p...
4
2016-07-13T21:15:37Z
[ "python", "dictionary" ]
Python dict get function not doing the right thing?
38,361,803
<p>I thought that the <code>.get(key, default=?)</code> function will look at the <code>default</code> part only if <code>key</code> is not in the dict.</p> <p>What I want to do is, see if a key exists in my main dictionary, if not, see if it exists in backup dictionary, and raise KeyError if it is neither in main or ...
2
2016-07-13T21:13:24Z
38,361,925
<p>Yes, the <a href="https://docs.python.org/2/library/stdtypes.html?highlight=dict.get#dict.get" rel="nofollow">dict.get</a> function return <code>default</code> if the key is not in the dictionary. But <code>default</code> is evaluated.</p> <p>You can use an intermediate dictionary like this.</p> <pre><code>main = ...
2
2016-07-13T21:22:53Z
[ "python", "dictionary" ]
I am trying to get an entry as an integer in Python
38,361,806
<p>Here is my code: </p> <pre><code>from Tkinter import * import tkMessageBox import tkSimpleDialog def blank(row, column): blank = Label(text=" ") blank.grid(row=row, column=column) def prtent(): distEnt.getint() print distEnt root = Tk() #title root.title("Trip Time Calculator") label = Label(t...
1
2016-07-13T21:13:47Z
38,363,457
<pre><code>print distEnt </code></pre> <p>This is your problem... <code>distEnt</code> is an Entry(), not a number. I believe it should look like...</p> <pre><code>dist = distEnt.getint() print dist </code></pre> <p>For a bit more explanation...</p> <p>the Entry() distEnt is the actual component that is displayed ...
0
2016-07-13T23:48:21Z
[ "python", "python-2.7" ]
Can I write a .zip consisting of TemporaryFiles?
38,361,839
<p>I have a program that will output a .zip file consisting of a number of .html files to the user. I don't need the .html files to exist anywhere outside of the .zip, so my thought was to make them TemporaryFiles using the tempfile module. How do I write a .zip of TempFile (assuming that's possible)? </p> <p>If I can...
1
2016-07-13T21:16:43Z
38,362,178
<p>The best way to create a zip file is to store every required files (your HTML) files in a (temporary) directory. Then you can compress the directory.</p> <p>Say, you store your ZIP file in <code>work_dir</code> and you a a function <code>write_html</code> used to write your HTML file, you can compress your HTML fil...
1
2016-07-13T21:41:53Z
[ "python", "zip", "temporary-files" ]
In Scrapy, how to loop over several start_urls which are themselves scraped
38,361,893
<p>I'm trying to collect data on houses for sale in Amsterdam on <a href="http://www.funda.nl/koop/amsterdam/" rel="nofollow">http://www.funda.nl/koop/amsterdam/</a>. The main page shows only a limited number of houses, and at the bottom there is a pager which looks like this:</p> <p><a href="http://i.stack.imgur.com/...
1
2016-07-13T21:21:00Z
38,366,250
<p>You are over-complicating the issue here -- you don't need to know the max page.</p> <p>Scrapy has url dupefilter so you can use linkextractor to extract all visible pages every time and scrapy will be smart enough not to visit the pages it has been to unless you force it.</p> <p>So all you need here is two Rules ...
0
2016-07-14T05:40:15Z
[ "python", "scrapy" ]
Pymongo insert_many BulkWriteError
38,361,916
<p>I am trying to insert the following list of dictionaries named <code>posts</code> to mongo, and got a <code>BulkWriteError: batch op errors occurred</code> error which I don't know how to fix.</p> <p><code>posts:</code> </p> <pre><code>[{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680', 'Records': [ {'DATE': '0...
2
2016-07-13T21:22:23Z
38,366,263
<p><a href="http://i.stack.imgur.com/SIZQQ.png" rel="nofollow">Here is output</a> in this output records are store which are in list.</p> <pre><code>from pymongo import MongoClient client = MongoClient('localhost', 27017) db = client['post'] posts = [{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680', 'Records': [ ...
0
2016-07-14T05:40:59Z
[ "python", "mongodb", "pymongo", "bulkinsert" ]
Pymongo insert_many BulkWriteError
38,361,916
<p>I am trying to insert the following list of dictionaries named <code>posts</code> to mongo, and got a <code>BulkWriteError: batch op errors occurred</code> error which I don't know how to fix.</p> <p><code>posts:</code> </p> <pre><code>[{'#AUTHID': 'fffafe151f07a30a0ede2038a897b680', 'Records': [ {'DATE': '0...
2
2016-07-13T21:22:23Z
38,390,266
<p>I just solved this issue by chance. The reason is that I executed three insert_many parallelly. </p> <p>In "/Library/Python/2.7/site-packages/pymongo/bulk.py" which raise the BulkWriteError, I saw on a variable named "sock_info". So I guessed is that parallel execution should be blamed. After executing insert_many ...
0
2016-07-15T07:27:23Z
[ "python", "mongodb", "pymongo", "bulkinsert" ]
Executing VBAscript from Python
38,361,949
<p>I am in need of some help in regards to win32com.client. I have the code working as far as creating the macro from Python and using Excel but I would like this code to also run the vbascript.</p> <p>Thank you guys for all of your wonderful feedback!</p> <pre><code>import pyodbc import win32com.client as win32 xl...
3
2016-07-13T21:24:53Z
38,362,340
<p>You should be able to use Excel's <code>Application.Run</code> method:</p> <pre><code>xl.Run "Download_Standard_BOM" </code></pre> <p><strong>EDIT</strong> If you need to refer to ADO, then you can either use late-binding, like this:</p> <pre><code>Dim cnn As Object 'ADODB.Connection Dim rst As Object 'ADODB.Reco...
1
2016-07-13T21:53:59Z
[ "python", "excel", "vba", "win32com" ]
How do I replace a character in a string that repeats many times with a different character in python?
38,362,026
<p>How do I replace a character in a string that repeats many times with a different character in python?</p> <p>My code has a massive table in it that looks like this:</p> <p>A B C D E F G H I J</p> <p>1 - - - - - - - - - -</p> <p>2 - - - - - - - - - -</p> <p>3 - - - - - - - - - -</p> <p>4 - - - - - - - - - -</p...
2
2016-07-13T21:30:25Z
38,362,048
<p>Just use <code>str.replace</code>:</p> <pre><code>text = text.replace('-', 'X') </code></pre>
2
2016-07-13T21:31:47Z
[ "python", "string" ]
How do I replace a character in a string that repeats many times with a different character in python?
38,362,026
<p>How do I replace a character in a string that repeats many times with a different character in python?</p> <p>My code has a massive table in it that looks like this:</p> <p>A B C D E F G H I J</p> <p>1 - - - - - - - - - -</p> <p>2 - - - - - - - - - -</p> <p>3 - - - - - - - - - -</p> <p>4 - - - - - - - - - -</p...
2
2016-07-13T21:30:25Z
38,362,145
<p>You can parse over the text and do a if/else check - my answer will be a general answer on how to approach the problem - </p> <p>There are many ways to parse strings, but the "split" method is often useful:</p> <p><a href="http://www.tutorialspoint.com/python/string_split.htm" rel="nofollow">http://www.tutorialspo...
0
2016-07-13T21:38:50Z
[ "python", "string" ]
How do I set font size of the figure title in gnuplot-py?
38,362,075
<p>I have a working plot with this title:</p> <pre><code>g.title('eta_n as a Function of Time') </code></pre> <p>The default font size is fine for axis labels, but I want a larger size for the plot title.</p> <pre><code>g.title('eta_n as a Function of Time', font=',18') failed. </code></pre> <p>I'm working on an im...
3
2016-07-13T21:33:35Z
38,395,159
<p><code>gnuplot-py</code> uses a very old syntax for setting the title's font which was already deprecated with version 4.4. Until version 4.6 this syntax could be enabled using a flag at compile time, but since version 5.0 the syntax isn't supported any more.</p> <p>You must send the complete command to get it worki...
1
2016-07-15T11:36:52Z
[ "python", "gnuplot" ]
Python SimpleHTTPServer serve a subdirectory
38,362,148
<p>Is it possible to serve a subdirectory instead of the current directory with SimpleHTTPServer ?</p> <p>I use it from the command-line like so:</p> <pre><code>python -m SimpleHTTPServer 5002 </code></pre> <p>The reason I would like to use this is that I have a <code>target</code> folder which I delete from time to...
2
2016-07-13T21:39:06Z
38,362,463
<p>Well, to serve the parent directory, just change the current working directory before running your Python script (<code>python -m SimpleHTTPServer 5002</code>).</p> <p>You can write your own script, eg.: 'my_server.py':</p> <pre><code>import SimpleHTTPServer import os def main(): pwd = os.getcwd() try: ...
0
2016-07-13T22:03:07Z
[ "python", "simplehttpserver" ]
How to create complex arguments with Zeep (SOAP client for Python) and nest data?
38,362,158
<p>I need to pass some nested data to my SOAP client, I think I know how to create the complex arguments...</p> <pre><code>id = ucmdb.get_type('ns17:ID') </code></pre> <p>Now I want to give some "arguments" to this 'ci', how can I do this? I'll show what I mean with an example using the old Suds which I know how to u...
2
2016-07-13T21:40:09Z
38,725,082
<p>Have a look at the section "Using SOAP headers" in <a href="http://docs.python-zeep.org/en/latest/in-depth.html" rel="nofollow">http://docs.python-zeep.org/en/latest/in-depth.html</a>.</p> <p>I was able to use that info to write a script that integrates with Zuora, and needs complex types in the Soap Header. See <a...
0
2016-08-02T15:46:21Z
[ "python", "soap", "soap-client", "python-3.5" ]
Map Reduce with multiprocessing
38,362,198
<pre><code>import multiprocessing data = range(10) def map_func(i): return [i] def reduce_func(a,b): return a+b p = multiprocessing.Pool(processes=4) p.map(map_func, data) </code></pre> <p>How can I use <code>reduce_func()</code> as a reduce function for the paralelised <code>map_func()</code>.</p> <p>Her...
0
2016-07-13T21:43:05Z
38,362,783
<p>According to the documentation, <code>multiprocessing.Pool.map()</code> blocks until the result is ready. Randomness is not possible. To achieve a random processing order, use the <code>imap_unordered()</code> method:</p> <pre><code>from functools import reduce result = p.imap_unordered(map_func, data) final_resul...
1
2016-07-13T22:31:23Z
[ "python", "mapreduce" ]
Pandas DataFrame naming only 1 column
38,362,278
<p>Is there a way with Pandas Dataframe to name only the first or first and second column even if there's 4 columns :</p> <p>Here</p> <pre><code>for x in range(1, len(table2_query) + 1): if x == 1: cursor.execute(table2_query[x]) df = pd.DataFrame(data=cursor.fetchall(), columns=['Q', col_name[x-1...
1
2016-07-13T21:48:36Z
38,362,682
<p>Consider the <code>df</code>:</p> <pre><code>df = pd.DataFrame(np.arange(8).reshape(2, 4), columns=list('ABCD')) df </code></pre> <p><a href="http://i.stack.imgur.com/hJQ0r.png" rel="nofollow"><img src="http://i.stack.imgur.com/hJQ0r.png" alt="enter image description here"></a></p> <p>then use <code>rename</code>...
3
2016-07-13T22:22:49Z
[ "python", "pandas", "dataframe" ]
Split big object into smaller sub objects in instance
38,362,338
<p>What is the pythonic way to handle large objects? In my example I could have one big class creating one instance with many attributes or I could group some of them together (See class Car and class Motor):</p> <pre><code>class Car(object): color = "red" def __init__(self, num_wheels): self.burst =...
0
2016-07-13T21:53:36Z
38,362,691
<p>If you use large numbers of instances, you can used <a href="https://docs.python.org/2/reference/datamodel.html?highlight=__slots__#slots" rel="nofollow"><strong>slots</strong></a> to reduce memory footprint.</p>
0
2016-07-13T22:23:40Z
[ "python", "class", "instance", "subobject" ]
Using itertools.product in place of double-nested for loop in Python 3
38,362,368
<p>The following code works, but appears verbose. </p> <pre><code>def gen(l): for x in range(l[0]): for y in range(l[1]): for z in range(l[2]): yield [x, y, z] l = [1, 2, 3] print(list(gen(l))) &gt;&gt;&gt;[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2]] </cod...
2
2016-07-13T21:55:33Z
38,362,395
<p>You need to pass the elements of the <code>map</code> iterator to <code>product</code> separately with <code>*</code>:</p> <pre><code>for x, y, z in product(*map(range, l)) </code></pre> <p>Incidentally, with another <code>map</code> call, you could save another line, skip the overhead of a Python generator, and d...
5
2016-07-13T21:58:48Z
[ "python", "python-3.x", "generator", "itertools", "cartesian-product" ]
How can I connect to a server using python sockets inside a Docker container?
38,362,415
<p>I am new to Docker and I am trying to run my python program in a container.</p> <p>My program needs to connect to a server through a socket in order to work fine. I have created my program's docker image and its respective container, but when it gets to the following line it fails, and I have no idea why. </p> <pr...
0
2016-07-13T22:00:00Z
38,362,668
<p>Unless you've set it up in your <code>/etc/hosts</code> file of your docker container, it's unlikely that you're going to have the proper hostname setup.</p> <p>Luckily for you, Docker provides a nice way to expose this sort of information between two containers - environment variables. They're automatically expose...
0
2016-07-13T22:21:42Z
[ "python", "sockets", "docker" ]
subclassing dict; dict.update returns incorrrect value - python bug?
38,362,420
<p>I needed to make a class that extended dict and ran into an interesting problem illustrated by the dumb example in the image below.</p> <p><a href="http://i.stack.imgur.com/0ClOH.png" rel="nofollow"><img src="http://i.stack.imgur.com/0ClOH.png" alt="subclassing_dict_problem"></a></p> <p>Why is <code>d.update()</co...
5
2016-07-13T22:00:15Z
38,534,939
<p>This is an example of the <a href="https://en.wikipedia.org/wiki/Open/closed_principle">open-closed-principle</a> (the class is open for extension but closed for modification). It is good thing to have because it allows subclassers to extend or override a method without unintentionally triggering behavior changes i...
6
2016-07-22T20:41:43Z
[ "python", "python-2.7", "dictionary" ]
Numeric Keyboard
38,362,460
<p>I would like to design a numeric keyboard and I do not know which function to use to have real time display when I clicked a button, say 1 is displayed in the textctrl when the button 1 is clicked like a calculator display. And it can display like 1234 when 1234 buttons are clicked in series. And I wonder how can I ...
0
2016-07-13T22:02:58Z
38,370,932
<pre><code>import wx class iCal(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "Text") panel = MainPanel(self) class MainPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent=parent) self.frame = parent self.text_1 = wx.T...
0
2016-07-14T09:48:57Z
[ "python", "wxpython", "real-time" ]
Odoo extension and inheritance
38,362,501
<p>Odoo has three types of inheritance, and I have at least that number of questions.</p> <p><strong>1. 'Normal' Inheritance (_inherit)</strong></p> <p>This is relatively intuitive to me - but why don't they just do it in the pythonic way: </p> <pre><code>ChildClass(ParentClass): </code></pre> <p>Why do they have t...
1
2016-07-13T22:06:55Z
38,365,681
<p><strong>_inherit</strong></p> <p>While this term comes into the picture it means that you are going to extend something to that current model. Whatever fields and methods you describe over there those will be appended to that model which you have specified in <strong>_inherit</strong>.</p> <p><strong>_inherits</st...
0
2016-07-14T04:47:16Z
[ "python", "inheritance", "openerp", "odoo-9" ]
Odoo extension and inheritance
38,362,501
<p>Odoo has three types of inheritance, and I have at least that number of questions.</p> <p><strong>1. 'Normal' Inheritance (_inherit)</strong></p> <p>This is relatively intuitive to me - but why don't they just do it in the pythonic way: </p> <pre><code>ChildClass(ParentClass): </code></pre> <p>Why do they have t...
1
2016-07-13T22:06:55Z
38,376,610
<p>I have been just messing around with the inheritance myself, below are examples of odoo 'classical' inheritance (pass _inherit and _name to child) and odoo 'extension,' only pass _inherit to child</p> <p>_inherits (delegation) is so wacky I'm not even going to test it out. I don't see how I would ever use it - the ...
0
2016-07-14T14:15:01Z
[ "python", "inheritance", "openerp", "odoo-9" ]
How to View Code (for Scraping) of Interactive Graph with Hover
38,362,531
<p>I would like to scrape an interactive plot that displays different information based on where the pointer is hovering. This website is what I am interested in: <a href="https://www.pelotoncycle.com/workout/c52db950f5ec4fde85cb3997c52db8db" rel="nofollow">https://www.pelotoncycle.com/workout/c52db950f5ec4fde85cb3997c...
0
2016-07-13T22:09:22Z
38,365,489
<p>What happens is that another element containing the hover is overlayed on the chart for each point. The good news is that for each hover, a single CSS selector can be created. The hover appears in the ending <code>&lt;g&gt;</code> tag of the performance chart and the data can be gathered by getting all the points yo...
1
2016-07-14T04:26:40Z
[ "python", "selenium", "web-scraping", "screen-scraping" ]
Context processors and manual rendering
38,362,572
<p>In my Django app I need to refresh part of a page via an Ajax call. The associated view returns a <code>JsonResponse</code> object, where one key in the context is the re-rendered HTML.</p> <p>Something like this:</p> <pre><code>def myview(request): ... tmpl8 = template.loader.get_template('page-table.html...
3
2016-07-13T22:12:12Z
38,364,078
<p>Try to pass <code>request</code> to <code>render()</code> method:</p> <pre><code>new_body = tmpl8.render({ 'rows': MyModel.custom_query() }, request) </code></pre>
1
2016-07-14T01:19:40Z
[ "python", "django", "django-templates" ]
Context processors and manual rendering
38,362,572
<p>In my Django app I need to refresh part of a page via an Ajax call. The associated view returns a <code>JsonResponse</code> object, where one key in the context is the re-rendered HTML.</p> <p>Something like this:</p> <pre><code>def myview(request): ... tmpl8 = template.loader.get_template('page-table.html...
3
2016-07-13T22:12:12Z
38,364,440
<p>Let's see what the <a href="https://docs.djangoproject.com/en/1.9/topics/templates/#django.template.backends.base.Template.render" rel="nofollow">render</a> documentation says:</p> <blockquote> <p>Template.render(context=None, request=None)<br> Renders this template with a given context.</p> <p>If contex...
2
2016-07-14T02:13:02Z
[ "python", "django", "django-templates" ]
Assign/map colors to the points in Seaborn.regplot (Python 3)
38,362,573
<p>I have a <code>seaborn</code> plot that I want to annotate with colors (preferably with a legend as well witht he color mapping). I see that the <code>regplot</code> has a <code>color</code> method. I don't know how to take use of this. </p> <p>I set up my I tried a few different ways by either giving the <code>...
1
2016-07-13T22:12:17Z
38,363,155
<p>Use <code>scatter_kws</code>:</p> <pre><code>import pandas as pd import numpy as np import matplotlib.pylab as plt import seaborn as sns np.random.seed(0) # Create dataframe DF_0 = pd.DataFrame(np.random.random((100,2)), columns=["x","y"]) DF_0['color'] = ["#91FF61"]*25 + ["#BA61FF"]*25 + ["#91FF61"]*25 + ["#BA6...
1
2016-07-13T23:10:16Z
[ "python", "pandas", "matplotlib", "seaborn" ]
Getting all attributes to appear on python's `__dict__` method
38,362,638
<p>Please consider the following python example:</p> <pre><code>In [3]: class test(object): ...: attribute='3' ...: def __init__(self): ...: self.other='4' ...: In [4]: b=test() In [5]: b.attribute Out[5]: '3' In [6]: b.__dict__ Out[6]: {'other': '4'} </code></pre> <p>Why is it...
0
2016-07-13T22:18:26Z
38,362,658
<p><code>b.__dict__</code> is only a mapping of attributes on <code>b</code>, not on <code>b</code>'s class (notice that <code>__init__</code> isn't there either). The attributes on <code>b</code>'s class are on the class's <code>__dict__</code>.</p> <pre><code>&gt;&gt;&gt; class test(object): ... attribute = 1 ......
2
2016-07-13T22:20:26Z
[ "python", "class", "attributes" ]
Getting all attributes to appear on python's `__dict__` method
38,362,638
<p>Please consider the following python example:</p> <pre><code>In [3]: class test(object): ...: attribute='3' ...: def __init__(self): ...: self.other='4' ...: In [4]: b=test() In [5]: b.attribute Out[5]: '3' In [6]: b.__dict__ Out[6]: {'other': '4'} </code></pre> <p>Why is it...
0
2016-07-13T22:18:26Z
38,362,674
<p><code>attribute</code> is not an instance attribute but a class attribute (can be seen in the <em>mappingproxy</em> <code>test.__dict__</code>). </p> <p>You can get <code>attribute</code> in the instance <code>__dict__</code> if you update the value of <code>attribute</code> from the instance:</p> <pre><code>&gt;&...
1
2016-07-13T22:22:18Z
[ "python", "class", "attributes" ]
Getting all attributes to appear on python's `__dict__` method
38,362,638
<p>Please consider the following python example:</p> <pre><code>In [3]: class test(object): ...: attribute='3' ...: def __init__(self): ...: self.other='4' ...: In [4]: b=test() In [5]: b.attribute Out[5]: '3' In [6]: b.__dict__ Out[6]: {'other': '4'} </code></pre> <p>Why is it...
0
2016-07-13T22:18:26Z
38,362,684
<p>Try typing:</p> <pre><code>test.__dict__ </code></pre> <p>And it shows a key with 'attribute'. This happens exactly because attribute is a class variable not an instance variable.</p>
0
2016-07-13T22:22:59Z
[ "python", "class", "attributes" ]
How to index a day's range of rows in a Dataframe, using a datetime.date?
38,362,699
<p>My multi-indexed data frame is as follows:</p> <pre><code>df.head() Output Unit Timestamp 1 2016-06-01 00:00:00 225894.9 2016-06-01 01:00:00 225895.9 2016-06-01 02:00:00 225896.9 2016-06-01 03:00:00 225897.9 2016-...
1
2016-07-13T22:24:27Z
38,362,958
<p>When you pass a string that looks like a datetime to the pandas selector <code>ix</code>, it uses it like a condition and returns all elements that satisfy. In this case, the string you are using evaluates to a day. Pandas runs <code>ix</code> and returns all rows within that day. When you pass the datetime objec...
2
2016-07-13T22:46:04Z
[ "python", "pandas" ]
How to index a day's range of rows in a Dataframe, using a datetime.date?
38,362,699
<p>My multi-indexed data frame is as follows:</p> <pre><code>df.head() Output Unit Timestamp 1 2016-06-01 00:00:00 225894.9 2016-06-01 01:00:00 225895.9 2016-06-01 02:00:00 225896.9 2016-06-01 03:00:00 225897.9 2016-...
1
2016-07-13T22:24:27Z
38,363,494
<p>Let me suggest you a different method rather than using ix. Why don't you directly use a range query?</p> <pre><code>df = df[df.index.get_level_values('Unit') == 6 &amp; (df.index.get_level_values('Timestamp') &gt;= tenth &amp; (df.index.get_level_values('Timestamp') &lt;= tenth)] </code></pre> <...
1
2016-07-13T23:53:39Z
[ "python", "pandas" ]
python2.7 manage.py runserver
38,362,702
<p>I'm using <strong>python 2.7</strong> and am having trouble running the server. I have entered </p> <p><code>python2.7 manage.py runserver</code> and got the following error message </p> <pre><code>Traceback (most recent call last): File "manage.py", line 8, in &lt;module&gt; from django.core.management impo...
0
2016-07-13T22:24:42Z
38,362,782
<p>Do you have the django package installed? go to your command line and type "pip list" and see if django is in the list. </p> <p>If it is not, "pip install django" should allow you to download and install the package. </p>
1
2016-07-13T22:31:19Z
[ "python", "django", "python-2.7" ]
pysftp -- paramiko SSHException, Bad host key from server
38,362,714
<p>I'm trying to connect to a remote host via <code>pysftp</code>:</p> <pre><code>try: with pysftp.Connection(inventory[0], username='transit', private_key='~/.ssh/id_rsa.sftp', port=8055) as sftp: sftp.put('/home/me/test.file') except Exception, err: print sys.exc_info() ...
3
2016-07-13T22:25:58Z
38,399,163
<h1>Workaround</h1> <p>This seems to be some sort of bug with the <code>pysftp</code> wrapper... I'm not sure. Reverting to native <code>paramiko</code> got me connected just fine, so I'm going with that for now. Current working code:</p> <pre><code>rsa_key = paramiko.RSAKey.from_private_key_file('~/.ssh/the_key', pa...
3
2016-07-15T14:51:41Z
[ "python", "ssh", "sftp", "paramiko", "pysftp" ]
IndexError: index 43770 is out of bounds for axis 0 with size 37550
38,362,833
<p>When I run:</p> <pre><code>im = np.zeros((37550, 59759)) location = [(23913, 43770), (23914, 43731), (23914, 43734), (23916, 43734), (23916, 43740), (23917, 43740), (23917, 43742), (23918, 43743), (23918, 43745), (23919, 43746), (23919, 43748), (23920, 43750), (23920, 43763)...
2
2016-07-13T22:35:30Z
38,362,916
<p>Instead of <code>(x, y)</code> pairs (i.e. <code>[(x1, y1), (x2, y2), ...]</code>), you need to pass something like <code>[(x1, x2, ...), (y1, y2, ...)]</code>. It was not what I was expecting, too (see a similar question <a href="http://stackoverflow.com/q/36989390/2285236">here</a>). <a href="http://stackoverflow....
2
2016-07-13T22:42:38Z
[ "python", "numpy" ]
How to remove multi indexing from a pandas pivot table for easy visualisation
38,363,078
<p>When creating pivot tables there is often multi level indexing (two or more levels of index which show up as columns.</p> <p>In these cases the object that the pivot function returns is still a dataframe but to my limited knowledge it is difficult to chart in this multi index form.</p> <p>How do you go from a pivo...
-1
2016-07-13T23:00:39Z
38,376,443
<p>Vamsi I tried reset the index multiple times on my industry pivot table example (above) and no matter how many times I reset the index I'm still left with a dataframe which has a multi index which makes it hard for me to graph/chart.</p>
0
2016-07-14T14:07:16Z
[ "python", "pandas", "histogram", "plotly" ]
How to type response to raw input on terminal via batch file?
38,363,108
<p>I'm trying to write a batch file that will automatically run a python script. After <code>python main.py</code> is executed, the script asks for what serial port the user is using (using the raw input function in python). </p> <p>I want to automatize the process by trying all the different COM ports until we find t...
0
2016-07-13T23:04:33Z
38,363,626
<p>Try a pipe, which directs the output of one command to the input of another:</p> <pre><code>echo COM3 | main.py </code></pre> <p>Ideally, however, your <code>main.py</code> would be written to take the port on the command line, instead of prompting for it (or only prompting if it's not found on the command line). ...
0
2016-07-14T00:12:09Z
[ "python", "windows", "batch-file" ]
np.loadtxt not overwritting files
38,363,124
<p>I am importing a list that is not being overwritting by np.loadtxt. I have 6 text files that are being added into the same array, but what I would like to do is overwrite this array and print a new graph per file. Unfortunately it's printing a new image with one graph ontop of the other per file until it reaches the...
0
2016-07-13T23:07:07Z
38,363,274
<p>I think the issue is with your plotting code. If I understand you correctly, you want each plot to be its own figure. Unless you make explicitly tell matplotlib otherwise, it will continue to add all your plots to the same axes.</p> <p>Try adding a call to plt.figure() at the end of your loop.</p> <p>Or, you can...
1
2016-07-13T23:23:02Z
[ "python", "python-2.7", "python-3.x", "numpy", "while-loop" ]
How can I add a dictionary of parameters into a subprocess call in python?
38,363,138
<p>Let's say there is a dictionary called <code>dict</code> in which <code>dict['var1'] = '1'</code> and <code>dict['var2'] = '2'</code> ... I am trying to find a way to add it to a subprocess call to trigger a make file. Currently I have:</p> <pre><code>subprocess.Popen(["make", "make.mk"], **dict) </code></pre> <p>...
2
2016-07-13T23:08:22Z
38,363,171
<p>If I understand correctly, I think this is what you're looking for:</p> <pre><code>d = { 'var1': '1', 'var2': '2' } subprocess.Popen(["make", "make.mk"] + [k + "=" + v for k, v in d.items()]) </code></pre> <p>(My understanding is that you want to execute a command like <code>make make.mv var1=1 var2=2</code>.)</p>...
0
2016-07-13T23:11:32Z
[ "python" ]
PyQT5 QtGui doesn't contain QPushbutton
38,363,262
<p>This is the simple line of code for creating the Button Object</p> <pre><code> btn = QtGui.QPushButton('Button') </code></pre> <p>and gives out this error </p> <pre><code> AttributeError: module 'PyQt5.QtGui' has no attribute 'QPushbutton' </code></pre> <p>These are my imports</p> <pre><code> ...
0
2016-07-13T23:21:32Z
38,363,556
<p>PyQt5 is not compitible with PyQt4, so it's very unlikely that you'll be able to run a PyQt4 application with PyQt5 without making some changes. For details, see: <a href="http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html" rel="nofollow">Differences Between PyQt4 and PyQt5</a>.</p> <p>As to the specific...
2
2016-07-14T00:03:16Z
[ "python", "python-import", "pyqt5" ]
Image scraped as HTML page with urlretrieve
38,363,276
<p>I'm trying to scrape <a href="http://i9.mangareader.net/one-piece/3/one-piece-1668214.jpg" rel="nofollow">this image</a> using urllib.urlretrieve.</p> <pre><code>&gt;&gt;&gt; import urllib &gt;&gt;&gt; urllib.urlretrieve('http://i9.mangareader.net/one-piece/3/one-piece-1668214.jpg', path) # path was previo...
0
2016-07-13T23:23:12Z
38,363,632
<p>It's because the owner of the server hosting that image is deliberately blocking access from Python's <code>urllib</code>. That's why it's working with <code>requests</code>. You can also do it with pure Python, but you'll have to give it an HTTP <code>User-Agent</code> header that makes it look like something other...
0
2016-07-14T00:13:59Z
[ "python", "web-scraping", "urllib" ]
Python - Iterrow through pandas dataframe and assign and conditionally update datetime variable
38,363,359
<p>I'm a Python novice and was wondering if anyone could help me.</p> <p>I want to iterate through datetime column in a pandas data frame, while for each iteration update a variable with the most recent time. Let's assume this is my data:</p> <pre><code> Time 06:12:50 06:13:51 06:13:51 06:13:50 06:14:51 06:14:49 <...
0
2016-07-13T23:32:11Z
38,363,450
<p>Every time through the loop you are writing over the variable <code>index</code> before checking the inequality, so</p> <pre><code>if index &gt;= row['Time']: </code></pre> <p>is not only always <code>True</code>, but you always set index equal to the current time prior to checking this inequality. Based on the pa...
0
2016-07-13T23:47:37Z
[ "python", "loops", "datetime", "if-statement", "pandas" ]
Django Models not showing in Admin.py
38,363,474
<p>I have looked through the other answers extensively, but I just know this is going to turn out to be a silly oversight on my part.</p> <p>I am a noob on an AWS Bitnami stack. Just trying to make of simple model show up in my admin.</p> <p>Models.py:</p> <pre><code> from __future__ import unicode_literals fro...
3
2016-07-13T23:50:30Z
38,373,763
<p>Sorry for the trouble.</p> <p>I forgot to reload / restart apache and my changes weren't showing up. </p> <p>Thank you everyone for your help!</p>
0
2016-07-14T12:05:39Z
[ "python", "django", "amazon-ec2", "bitnami" ]
How do I name a division operation in a TensorFlow graph?
38,363,515
<p>I am writing a language model in TensorFlow, following the example in <code>ptb_word_lm.py</code>. I calculate the batch cost like so:</p> <pre class="lang-py prettyprint-override"><code> loss = tf.nn.seq2seq.sequence_loss_by_example([logits], [tf.reshape(y, [-1]...
2
2016-07-13T23:56:31Z
38,364,558
<p><a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/math_ops.html#div" rel="nofollow"><code>tf.div</code></a>, <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/math_ops.html#truediv" rel="nofollow"><code>tf.truediv</code></a>, and <a href="https://www.tensorflow.org/versions/r0.9/api_d...
1
2016-07-14T02:29:34Z
[ "python", "tensorflow" ]
Why hash function on two different objects return same value?
38,363,640
<p>I used Spyder, run Python 2.7.</p> <p>Just found interesting things:</p> <ol> <li>hash(-1) and hash(-2) both return -2, is there a problem? I though hash function on different object should return different values. I read previous posts that -1 is reserved as an error in Python.</li> <li>hash('s') returns 18351423...
3
2016-07-14T00:15:11Z
38,363,706
<p>-1 is not "reserved as an error" in Python. Not sure what that would even mean. There are a huge number of programs you couldn't write simply and clearly if you weren't allowed to use -1.</p> <p>"Is there a problem?" No. Hash functions do not need to return a different hash for every object. In fact, this is not po...
1
2016-07-14T00:24:26Z
[ "python", "hash" ]
Python selenium get inside a #document
38,363,643
<p>How can I keep looking for elements in a #document:</p> <pre><code>&lt;div&gt; &lt;iframe&gt; #document &lt;html&gt; &lt;body&gt; &lt;div&gt; Element I want to find &lt;/div&gt; &lt;/body&gt; ...
1
2016-07-14T00:15:17Z
38,363,681
<p>I think your problem is not with the <code>a#</code>document but with <code>iframe</code>.</p> <pre><code>from selenium import webdriver driver = webdriver.Firefox() iframe = driver.find_elements_by_tag_name('iframe')[0] driver.switch_to_frame(iframe) driver.find_element_by_xpath("//div") </code></pre>
0
2016-07-14T00:21:38Z
[ "python", "selenium", "iframe", "scraper" ]
Celery: How '|' operator works while chaining multi tasks?
38,363,664
<p>I know <code>|</code> is a bitwise 'Or' operator but it makes me wonder that how it works in case of celery while chaining multiple tasks.</p> <pre><code>(first_task.s(url) | second_tasks.s()).apply_async() </code></pre> <p>I know that second task would take result of the first function as args but how's that poss...
1
2016-07-14T00:18:10Z
38,363,699
<p>They are likely using operator overloading as <code>__or__(self, other)</code>: <a href="http://www.rafekettler.com/magicmethods.html" rel="nofollow">http://www.rafekettler.com/magicmethods.html</a></p> <p>I don't know the implementation details of Celery, but just to give you an idea:</p> <pre><code>class Task(ob...
0
2016-07-14T00:23:37Z
[ "python", "celery", "djcelery" ]
Celery: How '|' operator works while chaining multi tasks?
38,363,664
<p>I know <code>|</code> is a bitwise 'Or' operator but it makes me wonder that how it works in case of celery while chaining multiple tasks.</p> <pre><code>(first_task.s(url) | second_tasks.s()).apply_async() </code></pre> <p>I know that second task would take result of the first function as args but how's that poss...
1
2016-07-14T00:18:10Z
38,364,694
<p>As mentioned above, Celery overrides the <code>__or__</code> operator, specifically as follows:</p> <pre><code>def __or__(self, other): if isinstance(other, group): other = maybe_unroll_group(other) if not isinstance(self, chain) and isinstance(other, chain): return chain((self, ) + other.ta...
0
2016-07-14T02:46:48Z
[ "python", "celery", "djcelery" ]
Mongoengine AttributeError
38,363,726
<p>I'm trying to code authorization for app using Flask-Mongoengine and Flask-Login. And I'm getting this weird error:</p> <pre><code>File "/usr/lib/python3.5/site-packages/mongoengine/base/document.py", line 188, in __setattr__ super(BaseDocument, self).__setattr__(name, value) File "/usr/lib/python3.5/site-pac...
0
2016-07-14T00:27:21Z
38,805,437
<p>The fix for this issue, is that you need to invoke the constructor of the super class like this </p> <pre><code>class User(db.Document): email = db.StringField(required=True) first_name = db.StringField(max_lenght=40, required=True) last_name = db.StringField(max_lenght=40, required=True) password =...
0
2016-08-06T14:40:02Z
[ "python", "flask", "mongoengine", "flask-mongoengine" ]
Python 3.5 UnicodeDecodeError for a file in utf-8 (language is 'ang', Old English)
38,363,747
<p>this is my first time using StackOverflow to ask a question, but you've collectively saved so many of my projects over the years that I feel at home already.</p> <p>I'm using Python3.5 and nltk to parse the Complete Corpus of Old English, which was published to me as 77 text files and an XML doc that designates the...
3
2016-07-14T00:29:31Z
38,377,439
<p>Unicode is not supported in NLTK. At all. I suspect that if it's old English, it will need to make use of some strange letters.</p> <p>There is, however, a solution that can minimize headaches. There's a library that's considerably more modern and powerful than NLTK, called <code>spacy</code>. <a href="http://spacy...
0
2016-07-14T14:51:52Z
[ "python", "python-3.x", "utf-8", "nltk" ]
Python 3.5 UnicodeDecodeError for a file in utf-8 (language is 'ang', Old English)
38,363,747
<p>this is my first time using StackOverflow to ask a question, but you've collectively saved so many of my projects over the years that I feel at home already.</p> <p>I'm using Python3.5 and nltk to parse the Complete Corpus of Old English, which was published to me as 77 text files and an XML doc that designates the...
3
2016-07-14T00:29:31Z
38,379,644
<p>Your conversion technique didn't work because you never read and wrote the file back out again. </p> <p><code>0x80</code> is not a valid byte in UTF-8 or any iso-8859-* character set. It is valid in Windows codepages, but only Unicode can support Old English characters, so you have some very broken data.</p> <p>To...
1
2016-07-14T16:35:19Z
[ "python", "python-3.x", "utf-8", "nltk" ]
python - using BaseHTTPRequestHandler with UnixStreamServer causes exception
38,363,758
<p>I'm trying to create a basic HTTP server bound to a Unix Domain Socket, but using a BaseHTTPRequestHandler subclass with UnixStreamServer is creating an exception that suggests they cannot work together.</p> <p>Toy server.py:</p> <pre><code>from SocketServer import UnixStreamServer from BaseHTTPServer import BaseH...
0
2016-07-14T00:31:18Z
38,403,244
<p>I ended up subclassing UnixStreamServer and overriding get_request (which is one of the TCPServer methods intended to be overridden):</p> <pre><code>class UnixHTTPServer(UnixStreamServer): def get_request(self): request, client_address = self.socket.accept() # BaseHTTPRequestHandler expects a tuple with t...
0
2016-07-15T18:50:36Z
[ "python", "sockets", "unix-domain-sockets", "basehttprequesthandler" ]
deploying django app to heroku
38,363,846
<p>I am a complete newbie to python/coding/webdevelopment, and am running into and error during deployment process. </p> <p>I coded a matchmaking app using Python/django. I am attempting to deploy this app using Heroku. I followed all the directions in term s of setting up server, initializing git repo, created Profil...
0
2016-07-14T00:43:42Z
38,364,557
<p>It seems you didn't migrate, can you try:</p> <pre><code>heroku run python manage.py migrate </code></pre> <p>And you don't have to <code>heroku run python manage.py makemigrations</code> since migration scripts are already there</p>
0
2016-07-14T02:29:29Z
[ "python", "django", "heroku", "database-migration", "makemigrations" ]
deploying django app to heroku
38,363,846
<p>I am a complete newbie to python/coding/webdevelopment, and am running into and error during deployment process. </p> <p>I coded a matchmaking app using Python/django. I am attempting to deploy this app using Heroku. I followed all the directions in term s of setting up server, initializing git repo, created Profil...
0
2016-07-14T00:43:42Z
38,366,803
<p>try to run these two commands</p> <pre><code>heroku run python manage.py migrate auth heroku run python manage.py migrate </code></pre>
0
2016-07-14T06:18:19Z
[ "python", "django", "heroku", "database-migration", "makemigrations" ]
Python dictionary get distinct list counts
38,363,913
<p>I've been working with trying to get an output in which Dictionary values are distinct lists with a count. </p> <p>Here is my input data:</p> <pre><code>event = [{'1a': ['tv', 'energy star tv']}, {'2a':['tv', 'energy star tv']}, {'3a':['tv', 'brand']}] </code></pre> <p>Here is my desired output:</p> <pre><code>...
1
2016-07-14T00:53:51Z
38,363,997
<p><code>{'tv': ['energy star tv', 2],['brand', 1]}</code> isn't legal python, assume you mean a list of lists as the value, or a more appropriate data structure like a dictionary.</p> <p>You can use a <code>collections.Counter()</code> to simplify the problem:</p> <pre><code>from collections import Counter event = [...
1
2016-07-14T01:08:04Z
[ "python", "dictionary" ]
Python dictionary get distinct list counts
38,363,913
<p>I've been working with trying to get an output in which Dictionary values are distinct lists with a count. </p> <p>Here is my input data:</p> <pre><code>event = [{'1a': ['tv', 'energy star tv']}, {'2a':['tv', 'energy star tv']}, {'3a':['tv', 'brand']}] </code></pre> <p>Here is my desired output:</p> <pre><code>...
1
2016-07-14T00:53:51Z
38,365,979
<p>this code:</p> <pre><code>event = [{'1a': ['tv', 'energy star tv']}, {'2a':['tv', 'energy star tv']}, {'3a':['tv', 'brand']}] e_dict = {} for key, value in [d.values()[0] for d in event]: if key in e_dict: if value in e_dict[key]: e_dict[key][value] = e_dict[key][value]+1 else: ...
0
2016-07-14T05:15:23Z
[ "python", "dictionary" ]
Python encrypt a string using an alternate alphabet
38,363,917
<p>I'm unsure on how to make this work. I need to encrypt a string given a different alphabet.</p> <pre><code>def substitute(string, ciphertext): alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" encrypted = [] list(alphabet) list(ciphertext) encrypted = "" for x in string: if x.isalpa(): ...
-1
2016-07-14T00:54:44Z
38,364,249
<p>Try this out:</p> <pre><code>def substitute(string, ciphertext): alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") # list() returns a list, ciphertext = list(ciphertext) # it doesn't change (mutate) the variable encrypted = [] # Not sure why you were storing the empty string here, # but s...
1
2016-07-14T01:44:17Z
[ "python", "string", "encryption" ]
Double index python pandas
38,363,994
<p>I am currently trying to change a csv into a dataframe with pandas from python and modify it in order for it to have a format like the following:</p> <pre><code>Year Country Serie1 Serie2 ... Afganistan Something Something Something 1970 Columbia Sth ...
2
2016-07-14T01:07:56Z
38,364,551
<pre><code>import pandas as pd import re todo2 = pd.read_csv("GS.csv") todo2.columns = [re.sub(r'(\d+) \[YR\1\]', r'\1', col) for col in todo2.columns] melted = pd.melt(todo2, id_vars=['Series Name', 'Country Name'], var_name='Year') result = melted.set_index(['Series Name', 'Year', 'Country Name'])['value'].unstack('...
2
2016-07-14T02:28:54Z
[ "python", "csv", "pandas", "indexing", "dataframe" ]
Double index python pandas
38,363,994
<p>I am currently trying to change a csv into a dataframe with pandas from python and modify it in order for it to have a format like the following:</p> <pre><code>Year Country Serie1 Serie2 ... Afganistan Something Something Something 1970 Columbia Sth ...
2
2016-07-14T01:07:56Z
38,364,730
<p><a href="https://stackoverflow.com/questions/38363994/double-index-python-pandas/38364551#38364551">The above answer from unubtu</a> has the correct way of doing this. However, answering your original question </p> <p>1) The correct syntax is <code>GS.set_index(['Year', 'Country'])</code> rather than <code>GS.set_i...
0
2016-07-14T02:50:46Z
[ "python", "csv", "pandas", "indexing", "dataframe" ]
why doesn't Series.dtype return a type of datetime
38,364,050
<p><a href="http://i.stack.imgur.com/oRNlR.png" rel="nofollow"><img src="http://i.stack.imgur.com/oRNlR.png" alt="enter image description here"></a></p> <p>I had a variable tradeDate 。the type of it's value is datetime.however ,when i run tradeDate.dtype ,it gives me Out[12]: dtype('O') ,why not datetime. or how d...
-1
2016-07-14T01:14:51Z
38,365,052
<p>Pandas uses numpy's datetime dtypes called <a href="https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html" rel="nofollow"><code>datetime64</code></a> which is different from the datetime types in python's standard library module <a href="https://docs.python.org/3/library/datetime" rel="nofollow"><code>date...
1
2016-07-14T03:37:11Z
[ "python", "numpy", "pandas" ]
Using the end argument for print
38,364,118
<p>I do understand that this question has been asked many time and I have looked through the community for a clear answer to my question. I understand that (<code>end=' '</code>) is used to print everything on the same line. However I am trying print everything in that list on the same line after a string.</p> <p>my c...
-6
2016-07-14T01:24:51Z
38,364,140
<p>Your code is illegal as you trying to assign a value inside a <code>tuple</code> - <code>(x, end='')</code>, with this tuple being passed to the format operator <code>%</code>. What you probably meant is:</p> <pre><code>print('Numbers: %d ' % x, end='') </code></pre> <p>But this would print: <code>Numbers: 1 Numb...
0
2016-07-14T01:28:40Z
[ "python", "python-3.x", "formatting" ]
in python, how do you denote required parameters and optional parameters in code?
38,364,162
<p>especially when there are so many parameters (10+ 20+). </p> <p>What are good ways of enforcing <code>required/optional</code> parameters to a function?</p> <p>What are some good books that deal with this kind of questions for python?<br> (like effective c++ for c++)</p> <p>** EDIT **</p> <p>I think it's very u...
-1
2016-07-14T01:31:42Z
38,364,199
<p>Parameters can be required or optional depending on how they appear in the function definition:</p> <pre><code>def myfunction(p1, p2, p3=False, p4=5) </code></pre> <p>In this definition, parameters <code>p1</code> and <code>p2</code> are required. <code>p3</code> is optional and will acquire the value <code>False...
1
2016-07-14T01:37:51Z
[ "python", "function" ]
in python, how do you denote required parameters and optional parameters in code?
38,364,162
<p>especially when there are so many parameters (10+ 20+). </p> <p>What are good ways of enforcing <code>required/optional</code> parameters to a function?</p> <p>What are some good books that deal with this kind of questions for python?<br> (like effective c++ for c++)</p> <p>** EDIT **</p> <p>I think it's very u...
-1
2016-07-14T01:31:42Z
38,364,200
<p>If a function parameter is not required, you can set it equal to None.</p> <pre><code>def hello(first_name, last_name=None): print "Hello " + first_name </code></pre> <p>Or as John Gordon said, you can set a parameter with a default value the same way.</p> <p>Note that optional parameters need to be defined a...
1
2016-07-14T01:38:01Z
[ "python", "function" ]
in python, how do you denote required parameters and optional parameters in code?
38,364,162
<p>especially when there are so many parameters (10+ 20+). </p> <p>What are good ways of enforcing <code>required/optional</code> parameters to a function?</p> <p>What are some good books that deal with this kind of questions for python?<br> (like effective c++ for c++)</p> <p>** EDIT **</p> <p>I think it's very u...
-1
2016-07-14T01:31:42Z
38,364,393
<p><strong>One way is to have your required parameters be named like <code>func(a, b, c=1)</code> and this would denote required because the code will error out at runtime if missing any. Then for the optional parameters you would then use Python's <code>args</code> and <code>kwargs</code>.</strong></p> <p><strong>Of ...
0
2016-07-14T02:06:22Z
[ "python", "function" ]
if chain vs. exception in python
38,364,167
<p>I am writing a reader of <a href="https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/software" rel="nofollow">DS18B20 sensors</a> using <code>subprocess.Popen</code> and parsing the output of a device file through <code>cat</code> command. Since the result may be unpredictable (1...
0
2016-07-14T01:32:04Z
38,364,315
<p>I would definitely yank your first if statement. If you want your function to only accept a list, then only pass a list. For future reference, <code>isinstance</code> is preferable to <code>type(o) == cls</code>.</p> <p>The second if statement should just be <code>if lines</code>.</p> <p>Your third if statement co...
1
2016-07-14T01:53:42Z
[ "python", "raspberry-pi" ]
Unknown CUDA error when importing theano
38,364,170
<p>In python, after importing theano, I get the following:</p> <pre><code>In [1]: import theano WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: Unable to get the number of gpus available: unknown error) </code></pre> <p>I'm running this on ubuntu 14.04 and I have an old gpu...
1
2016-07-14T01:33:11Z
38,366,981
<p>I feel your pain. I spent a few days ploughing through all the CUDA related errors.</p> <p>Firstly, update to a more recent driver. eg, 361. (CLEAN INSTALL IT!) Then completely wipe cuda and cudnn from your harddrive with</p> <pre><code>sudo rm -rf /usr/local/cuda </code></pre> <p>or wherever else you installed i...
1
2016-07-14T06:30:16Z
[ "python", "cuda", "ubuntu-14.04", "theano-cuda" ]
PyQt - Create signals at runtime
38,364,184
<p>I have this piece of code in PyQt4:</p> <pre><code>def _settings_value_changed(self, key, value): signal_name = "%s(PyQt_PyObject)" % key.replace("/", "_") self.emit(SIGNAL(signal_name), value) </code></pre> <p>I'm trying to migrate that portion of code to PyQt5 . We know that PyQt5 signals must be defined...
0
2016-07-14T01:35:14Z
38,380,509
<p>No, you cannot define signals dynamically. But the code you posted doesn't seem to benefit in any way from using signals, so this looks like a good opportunity for you to remove it altogether.</p> <p>Instead, just call the slots directly, using <code>getattr</code>:</p> <pre><code>def _settings_value_changed(self,...
0
2016-07-14T17:24:31Z
[ "python", "qt", "pyqt", "signals" ]
Rearrange data in table
38,364,279
<p>I have a following DataFrame: <br/> <br/> <code> dis Country Price 0 0.8 US 500 1 0.8 England 1000 2 0.8 Spain 1500 3 0.8 Portugal 600 4 0.8 Germany 900 5 0.9 US 2200 6 0.9 England 3000 7 0.9 Spain 600 8...
2
2016-07-14T01:48:02Z
38,364,412
<p>Assuming <code>pandas</code>, you can use <code>set_index</code> and <code>unstack</code> to do what you are looking to do, as long as there are no repeats in the indexes:</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; df = pd.DataFrame({'dis': [0.8, 0.8, 0.9, 0.9], 'Country':['US', 'England', 'US', '...
2
2016-07-14T02:08:54Z
[ "python" ]
Rearrange data in table
38,364,279
<p>I have a following DataFrame: <br/> <br/> <code> dis Country Price 0 0.8 US 500 1 0.8 England 1000 2 0.8 Spain 1500 3 0.8 Portugal 600 4 0.8 Germany 900 5 0.9 US 2200 6 0.9 England 3000 7 0.9 Spain 600 8...
2
2016-07-14T01:48:02Z
38,364,428
<p>Assuming that you already know the row and column names given of your output table and that your input is a text file of tab seperated values I would do something like this,</p> <pre><code>afile = open("input.csv","r") content = [k.split("\t") for k in afile.read().slit("\n")] #If you already have a list of lists t...
1
2016-07-14T02:11:15Z
[ "python" ]
Unspool frequency table by list comprehension
38,364,299
<p>Here's a frequency table implemented as a list.</p> <pre><code>table = [1,3,2] </code></pre> <p>The desired output is a list of individual values.</p> <pre><code>unspooled = [0, 1, 1, 1, 2, 2] </code></pre> <p>The following syntax will get the job done.</p> <pre><code>sum((freq*[score] for score, freq in enume...
0
2016-07-14T01:51:02Z
38,364,342
<p>I believe this would work:</p> <pre><code>unspooled = [ind for ind in range(len(table)) for val in range(table[ind])] </code></pre>
2
2016-07-14T01:59:31Z
[ "python", "list-comprehension" ]
Unspool frequency table by list comprehension
38,364,299
<p>Here's a frequency table implemented as a list.</p> <pre><code>table = [1,3,2] </code></pre> <p>The desired output is a list of individual values.</p> <pre><code>unspooled = [0, 1, 1, 1, 2, 2] </code></pre> <p>The following syntax will get the job done.</p> <pre><code>sum((freq*[score] for score, freq in enume...
0
2016-07-14T01:51:02Z
38,364,612
<p>You can use <a href="https://docs.python.org/3/library/functions.html#enumerate" rel="nofollow"><code>enumerate</code></a> to return the index and item from <code>table</code>:</p> <pre><code>&gt;&gt;&gt; table = [1,3,2] &gt;&gt;&gt; [i for i, x in enumerate(table) for _ in range(x)] [0, 1, 1, 1, 2, 2] </code></pre...
2
2016-07-14T02:37:37Z
[ "python", "list-comprehension" ]
Unspool frequency table by list comprehension
38,364,299
<p>Here's a frequency table implemented as a list.</p> <pre><code>table = [1,3,2] </code></pre> <p>The desired output is a list of individual values.</p> <pre><code>unspooled = [0, 1, 1, 1, 2, 2] </code></pre> <p>The following syntax will get the job done.</p> <pre><code>sum((freq*[score] for score, freq in enume...
0
2016-07-14T01:51:02Z
38,364,634
<pre><code>table = [1,3,2] res = reduce( lambda x,y:x+y, [ [i]*frq for i,frq in enumerate(table)] ) output: [0, 1, 1, 1, 2, 2] </code></pre>
0
2016-07-14T02:39:22Z
[ "python", "list-comprehension" ]
Image slideshow with movepy
38,364,329
<p>I am trying to make a basic image slideshow using <code>moviepy</code>.</p> <p>Ive am to display a single image but am trying to work out how to make multiple images show up after each other and add a duration to each.</p> <p>I have this:</p> <pre><code>clip1 = ImageClip('image.jpg').set_duration(10) clip1.write_...
0
2016-07-14T01:57:08Z
38,367,099
<p>Worked it out for myself.</p> <pre><code>from moviepy.editor import * ic_1 = ImageClip('image1.jpg').set_duration(2) ic_2 = ImageClip('image2.jpg').set_duration(1) video = concatenate([ic_1, ic_2], method="compose") video.write_videofile('test.mp4', fps=24) </code></pre>
0
2016-07-14T06:38:12Z
[ "python", "moviepy" ]
Python take output from for loop and assign it elsewhere
38,364,392
<p>Re-posted with testable code as an example.</p> <p>Hello all. Can you guys and gals please help me figure this out? I have been trying to take the output of a for loop and use it to print a summary page. I want each iteration from the for loop to be a column next to the last iteration. Can you please help achieve t...
1
2016-07-14T02:06:20Z
38,364,896
<p>Pick the number of columns you wants, print on one line with a tab after each element, and go to the next line each time you've printed the desired number of elements for each line.</p> <p>If your goal is to have two columns, set desiredColumns to two. If your goal is two rows, set desiredColumns to the total numbe...
0
2016-07-14T03:15:50Z
[ "python", "loops", "iteration" ]
How to install Openpyxl with pip
38,364,404
<p>I have windows 10 (64 bit). I want to utilize the <code>Openpyxl</code> package to start learning how to interact with excel and other spreadsheets. </p> <p>I installed Python with <code>"windowsx86-64web-basedinstaller"</code> I have a 64 bit OS, was I mistaken when trying to install this version? </p> <p><a href...
-1
2016-07-14T02:08:02Z
38,375,757
<p>You need to ensure that <code>C:\Python35\Sripts</code> is in your system path. Follow the top answer instructions <a href="http://stackoverflow.com/questions/6318156/adding-python-path-on-windows-7">here</a> to do that: </p> <p>You run the command in windows command prompt, not in the python interpreter that you h...
0
2016-07-14T13:36:39Z
[ "python", "python-3.x", "pip", "openpyxl" ]
Python & Matplotlib: Make 3D plot interactive in Jupyter Notebook
38,364,435
<p>I use Jupyter Notebook to make analysis of datasets. There are a lot of plots in the notebook, and some of them are 3d plots. </p> <p><a href="http://i.stack.imgur.com/cPwoQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/cPwoQ.png" alt="enter image description here"></a></p> <p>I'm wondering if it is possi...
1
2016-07-14T02:11:57Z
38,364,478
<p>I use mat-lab for interactive 3d plots... This implementation is for linux with OCtave installed XD <a href="https://github.com/Krewn/KPlot/blob/gh-pages/KPlot.py#L298" rel="nofollow">https://github.com/Krewn/KPlot/blob/gh-pages/KPlot.py#L298</a> and won't quite get you there in the browser, It will however give you...
0
2016-07-14T02:17:44Z
[ "python", "matplotlib", "ipython-notebook", "jupyter-notebook" ]
Python & Matplotlib: Make 3D plot interactive in Jupyter Notebook
38,364,435
<p>I use Jupyter Notebook to make analysis of datasets. There are a lot of plots in the notebook, and some of them are 3d plots. </p> <p><a href="http://i.stack.imgur.com/cPwoQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/cPwoQ.png" alt="enter image description here"></a></p> <p>I'm wondering if it is possi...
1
2016-07-14T02:11:57Z
38,865,534
<p>try: </p> <p><code>%matplotlib notebook</code></p> <p>see <a href="http://stackoverflow.com/users/2937831/jakevdp">jakevdp</a> reply <a href="http://stackoverflow.com/a/33440743/1204331">here</a></p>
3
2016-08-10T06:13:13Z
[ "python", "matplotlib", "ipython-notebook", "jupyter-notebook" ]
Python & Matplotlib: Make 3D plot interactive in Jupyter Notebook
38,364,435
<p>I use Jupyter Notebook to make analysis of datasets. There are a lot of plots in the notebook, and some of them are 3d plots. </p> <p><a href="http://i.stack.imgur.com/cPwoQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/cPwoQ.png" alt="enter image description here"></a></p> <p>I'm wondering if it is possi...
1
2016-07-14T02:11:57Z
38,877,632
<p>For 3-D visualization <a href="https://github.com/jovyan/pythreejs" rel="nofollow">pythreejs</a> is the best way to go probably in the notebook. It leverages the interactive widget infrastructure of the notebook, so connection between the JS and python is seamless.</p> <p>A more advanced library is <a href="https:/...
1
2016-08-10T15:24:48Z
[ "python", "matplotlib", "ipython-notebook", "jupyter-notebook" ]
Is there any way I can download OpenCV on Raspberry Pi 3 Model B on a Windows laptop?
38,364,467
<p>So, I am trying to install OpenCV with Python 3 onto my Raspberry Pi 3 Model B. The problem is, the commands are in Linux, and I need to install it using Windows. Is there any way I can install it using windows, or is it absolutely necessary to use Linux?</p> <p>The link to the Linux commands: <a href="http://www.p...
0
2016-07-14T02:16:27Z
38,364,521
<p>Your Raspberry Pi should be running Linux, which means that you do need to run the Linux commands.</p> <p>From a Windows computer, you can remotely access and run commands on your Raspberry Pi through a program such as PuTTy. There's a lot of tutorials on the topic available on the internet. </p> <p>Let us know if...
0
2016-07-14T02:24:59Z
[ "python", "opencv", "raspberry-pi3" ]
Is there any way I can download OpenCV on Raspberry Pi 3 Model B on a Windows laptop?
38,364,467
<p>So, I am trying to install OpenCV with Python 3 onto my Raspberry Pi 3 Model B. The problem is, the commands are in Linux, and I need to install it using Windows. Is there any way I can install it using windows, or is it absolutely necessary to use Linux?</p> <p>The link to the Linux commands: <a href="http://www.p...
0
2016-07-14T02:16:27Z
38,364,528
<p>If you don't have a keyboard and monitor for your pi Use putty to ssh to to it over the network. Once logged in to the shell use the commands provided on this link to install open cv and python. <a href="http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/" rel="nofollow">h...
0
2016-07-14T02:25:46Z
[ "python", "opencv", "raspberry-pi3" ]
Is there any way I can download OpenCV on Raspberry Pi 3 Model B on a Windows laptop?
38,364,467
<p>So, I am trying to install OpenCV with Python 3 onto my Raspberry Pi 3 Model B. The problem is, the commands are in Linux, and I need to install it using Windows. Is there any way I can install it using windows, or is it absolutely necessary to use Linux?</p> <p>The link to the Linux commands: <a href="http://www.p...
0
2016-07-14T02:16:27Z
38,364,597
<p>The easiest way will be to connect your Raspberry Pi to a monitor or TV via HDMI, plug in a keyboard/mouse on USB, and then execute the commands directly on the Pi which is running Linux (ether NOOBS or Raspbian OSs depending on what's on your SD card).</p> <p>You will need to use the Raspi-Config tool on the termi...
1
2016-07-14T02:34:31Z
[ "python", "opencv", "raspberry-pi3" ]
Dynamic scenario dispatcher for Python Behave
38,364,568
<p>I am running multiple scenarios and would like to incorporate some sort of dynamic scenario dispatcher which would allow me to have specific steps to execute after a test is done based on the scenario executed. When I was using PHPUnit, I used to be able to subclass the TestCase class and add my own setup and teardo...
0
2016-07-14T02:30:40Z
38,364,788
<p><code>after_scenario</code> passes both the scenario to the function. You can then dispatch on the scenario name or any of its tags. For example, with tags, you could define your scenario as</p> <pre><code>@clean_up Scenario: Something ... </code></pre> <p>And your after listener as</p> <pre><code>def after_s...
0
2016-07-14T02:58:25Z
[ "python", "bdd", "scenarios", "python-behave" ]
Dynamic scenario dispatcher for Python Behave
38,364,568
<p>I am running multiple scenarios and would like to incorporate some sort of dynamic scenario dispatcher which would allow me to have specific steps to execute after a test is done based on the scenario executed. When I was using PHPUnit, I used to be able to subclass the TestCase class and add my own setup and teardo...
0
2016-07-14T02:30:40Z
38,643,609
<p>What I've been doing might give you an idea:</p> <p>In the before_all specify a list in the context (eg context.teardown_items =[]).</p> <p>Then in the various steps of various scenarios add to that list (accounts, orders or whatever)</p> <p>Then in the after_all I login as a superuser and clean everything up I s...
0
2016-07-28T17:58:37Z
[ "python", "bdd", "scenarios", "python-behave" ]
Something Wrong with Spark RDD
38,364,637
<p>I have a weird spark RDD, I am not sure what is wrong or how to go about troubleshooting. I am running Spark 1.6.2 with python 3.4.3 through an ipython notebook. </p> <p>Here is how I am pulling in the data:</p> <pre><code>sqlContext = SQLContext(sc) hdfs = 'hdfs://192.168.1.213:54310/TEMP/*' def make_Row(item):...
0
2016-07-14T02:39:38Z
38,377,594
<p>The RDD API does not have a <code>show()</code> method, hence the error in #1. You need to either convert to a dataframe (as you do in #2) or use something like:</p> <pre><code>raw_data.take(5) </code></pre> <p>to get a list of your row objects. </p> <p>Re #3, the toDF method is a little finicky depending on th...
0
2016-07-14T14:58:02Z
[ "python", "apache-spark", "rdd" ]
Something Wrong with Spark RDD
38,364,637
<p>I have a weird spark RDD, I am not sure what is wrong or how to go about troubleshooting. I am running Spark 1.6.2 with python 3.4.3 through an ipython notebook. </p> <p>Here is how I am pulling in the data:</p> <pre><code>sqlContext = SQLContext(sc) hdfs = 'hdfs://192.168.1.213:54310/TEMP/*' def make_Row(item):...
0
2016-07-14T02:39:38Z
38,404,722
<p>Number 1 has already been answered: RDD does not have a <code>show()</code> method. </p> <p>Number 3: Try <code>raw_data.toDF().describe(['cat']).show()</code></p>
0
2016-07-15T20:41:25Z
[ "python", "apache-spark", "rdd" ]
clang: error: unsupported option '-fopenmp' with compile spams-python lib
38,364,804
<p>I'm trying to install the spams-python toolbox for optimize sparse representation problems.</p> <blockquote> <p>The download page-> <a href="http://spams-devel.gforge.inria.fr/downloads.html" rel="nofollow">http://spams-devel.gforge.inria.fr/downloads.html</a></p> <p>The package link -> <a href="http://spa...
0
2016-07-14T03:01:51Z
38,365,164
<p>Apparently you need to upgrade clang, as <a href="http://openmp.llvm.org" rel="nofollow">it supports OpenMP starting from version 3.8.0</a>. If you're using Apple's development environment, you may have to wait until Apple gets around to upgrading it, though you could first try making sure that Xcode is up to date.<...
2
2016-07-14T03:51:41Z
[ "python", "osx", "clang" ]
Python MySql make array of a Query
38,364,860
<p>I have a MySql query, everything works fine, but I want to make an array of each row to be used out of the query</p> <p>Here is my code:</p> <pre><code>db = MySQLdb.connect(host="127.0.0.1", user="root", passwd="", db="seliso") cursor = db.cursor() cursor.execute("SELECT * FROM usuarios WHERE contador = " + "'" ...
1
2016-07-14T03:08:50Z
38,364,950
<p>You can get that with:</p> <pre><code>for i in zip(*results): print(list(i)) </code></pre> <p>Further, you should not use string concatenation like that for reasons of <a href="https://en.wikipedia.org/wiki/SQL_injection" rel="nofollow">SQL injection</a>. Instead do:</p> <pre><code>cursor.execute("SELECT * FR...
0
2016-07-14T03:22:59Z
[ "python", "mysql", "arrays", "mysql-python" ]