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
multiprocessing of video frames in python
38,203,239
<p>I am new to multiprocessing in python. I want to extract features from each frame of hour long video files. Processing each frame takes on the order of 30 ms. I thought multiprocessing was a good idea because each frame is processed independentle of all other frames.</p> <p>I want to store the results of the featur...
4
2016-07-05T12:16:59Z
38,205,204
<p>Parallel processing in (regular) python is a bit of a pain: in other languages we'd just use threads but the GIL makes that problematic, and using multiprocessing has a big overhead in moving data around. I've found that fine-grained parallelism is (relatively) hard to do, whilst processing 'chunks' of work that tak...
1
2016-07-05T13:48:48Z
[ "python", "multiprocessing" ]
Expand pandas DataFrame column into multiple rows
38,203,352
<p>If I have a <code>DataFrame</code> such that:</p> <pre><code>pd.DataFrame( {"name" : "John", "days" : [[1, 3, 5, 7]] }) </code></pre> <p>gives this structure:</p> <pre><code> days name 0 [1, 3, 5, 7] John </code></pre> <p>How do expand it to the following?</p> <pre><co...
3
2016-07-05T12:22:22Z
38,203,536
<p>You could use <code>df.itertuples</code> to iterate through each row, and use a list comprehension to reshape the data into the desired form:</p> <pre><code>import pandas as pd df = pd.DataFrame( {"name" : ["John", "Eric"], "days" : [[1, 3, 5, 7], [2,4]]}) result = pd.DataFrame([(d, tup.name) for t...
5
2016-07-05T12:31:35Z
[ "python", "pandas" ]
Expand pandas DataFrame column into multiple rows
38,203,352
<p>If I have a <code>DataFrame</code> such that:</p> <pre><code>pd.DataFrame( {"name" : "John", "days" : [[1, 3, 5, 7]] }) </code></pre> <p>gives this structure:</p> <pre><code> days name 0 [1, 3, 5, 7] John </code></pre> <p>How do expand it to the following?</p> <pre><co...
3
2016-07-05T12:22:22Z
38,203,624
<p>another solution:</p> <pre><code>In [139]: (df.apply(lambda x: pd.Series(x.days), axis=1) .....: .stack() .....: .reset_index(level=1, drop=1) .....: .to_frame('day') .....: .join(df['name']) .....: ) Out[139]: day name 0 1 John 0 3 John 0 5 John 0 7 John </code></pre>...
0
2016-07-05T12:34:58Z
[ "python", "pandas" ]
Expand pandas DataFrame column into multiple rows
38,203,352
<p>If I have a <code>DataFrame</code> such that:</p> <pre><code>pd.DataFrame( {"name" : "John", "days" : [[1, 3, 5, 7]] }) </code></pre> <p>gives this structure:</p> <pre><code> days name 0 [1, 3, 5, 7] John </code></pre> <p>How do expand it to the following?</p> <pre><co...
3
2016-07-05T12:22:22Z
38,203,702
<p>Here's something with NumPy -</p> <pre><code>lens = [len(item) for item in df['days']] df_out = pd.DataFrame( {"name" : np.repeat(df['name'].values,lens), "days" : np.hstack(df['days']) }) </code></pre> <p>As pointed in <a href="http://stackoverflow.com/a/38203536/3293881"><code>@unut...
3
2016-07-05T12:39:21Z
[ "python", "pandas" ]
Expand pandas DataFrame column into multiple rows
38,203,352
<p>If I have a <code>DataFrame</code> such that:</p> <pre><code>pd.DataFrame( {"name" : "John", "days" : [[1, 3, 5, 7]] }) </code></pre> <p>gives this structure:</p> <pre><code> days name 0 [1, 3, 5, 7] John </code></pre> <p>How do expand it to the following?</p> <pre><co...
3
2016-07-05T12:22:22Z
38,203,763
<p>Probably somehow like this:</p> <pre><code>df2 = pd.DataFrame(columns = df.columns) for i,r in df.iterrows(): for e in r.days: new_r = r.copy() new_r.days = e df2 = df2.append(new_r) df2 </code></pre>
1
2016-07-05T12:41:59Z
[ "python", "pandas" ]
Expand pandas DataFrame column into multiple rows
38,203,352
<p>If I have a <code>DataFrame</code> such that:</p> <pre><code>pd.DataFrame( {"name" : "John", "days" : [[1, 3, 5, 7]] }) </code></pre> <p>gives this structure:</p> <pre><code> days name 0 [1, 3, 5, 7] John </code></pre> <p>How do expand it to the following?</p> <pre><co...
3
2016-07-05T12:22:22Z
38,203,933
<p>A 'native' pandas solution - we unstack the column into a series, then join back on based on index:</p> <pre><code>import pandas as pd #import x2 = x.days.apply(lambda x: pd.Series(x)).unstack() #make an unstackeded series, x2 x.drop('days', axis = 1).join(pd.DataFrame(x2.reset_index(level=0, drop=True))) #drop the...
0
2016-07-05T12:49:54Z
[ "python", "pandas" ]
python wx to show popup after main screen has been initialized
38,203,455
<p>I want to show a popup above my main screen like so:</p> <pre><code>|´´´´´´´´´´´´´´´´´´´´´´| | I WANT TO BE SHOWN.| | |´´´´´´´´´´´´´| | | | I AM A | | | | POPUP | | | |_____________| | |______________________| </code></pre> <p>The problem is that ...
0
2016-07-05T12:27:07Z
39,627,793
<p>That's because "parent" window shows after calling Show method. When you initialize frame, <strong>init</strong> is called and dialog is created. <code>frame.Show(true)</code> is called when <strong>init</strong> finishes executing, so when dialog is dismissed. Your code should look like that</p> <pre><code>class A...
0
2016-09-21T23:02:25Z
[ "python", "dialog", "wx" ]
API call field delete with delete_values parameter not working
38,203,543
<p>When performing an API call to delete a field in an app, the field is deleted at the template level. However the <em>delete_values</em> parameters is not doing the job when setting it up to <em>true</em></p> <pre><code>## my python code using the requests library url = 'https://api.podio.com/app/16200981/field/1256...
1
2016-07-05T12:31:56Z
38,203,924
<p>The "delete_values" parameter has to be in the URL and not in the body.</p> <pre><code>https://api.podio.com/app/16200981/field/125619360?delete_values=true </code></pre> <p>so the code</p> <pre><code>url = 'https://api.podio.com/app/16200981/field/125619360' data = {'delete_values': True} request = requests.dele...
2
2016-07-05T12:49:26Z
[ "python", "podio" ]
How to hide a field in editable mode in odoo
38,203,651
<p>In <strong>odoo v8</strong>, I want some fields to be shown only in view mode but when the user clicks on edit or create, then those fields should be invisible (<strong>Only visible in view mode</strong>).</p>
0
2016-07-05T12:36:13Z
38,238,138
<p>There is an openerp class called "oe_read_only".</p> <p>This will allow you to view the field only when reading the form not in edit mode of the form.</p> <p>Sample Code:</p> <pre><code>&lt;field name="name" class="oe_read_only"/&gt; </code></pre>
0
2016-07-07T05:34:04Z
[ "python", "xml", "odoo-8" ]
Returning config.read() from function
38,203,698
<p>I have a config.py which reads in multiple config files.</p> <pre><code>from ConfigParser import * def zones_config(): zones_config = ConfigParser() zones = zones_config.sections() zones_config.read('zones.ini'), zones def settings_config(): settings_config = ConfigParser() settings_config.read('setting...
0
2016-07-05T12:39:10Z
38,203,830
<p><code>settings_config</code> is a function, and <code>.get()</code> is a method of the ConfigParser object. This should explain it more clearly:</p> <pre><code>def settings_config_function(): settings_config_object = ConfigParser() settings_config_object.read('settings.ini') return settings_config_object </co...
5
2016-07-05T12:44:54Z
[ "python", "configparser" ]
Encoding in .sas7dbat
38,203,988
<p>I am trying to import a sas dataset(.sas7bdat format) using pandas function <code>read_sas</code>(version 0.17) but it is giving me the following error:</p> <blockquote> <p>UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 12: ordinal not in range(128)</p> </blockquote>
-1
2016-07-05T12:52:31Z
38,210,473
<p>I was not able to import the file using read_sas but importing the file using sas7bdat has worked. </p> <pre><code> {!pip install sas7bdat from sas7bdat import SAS7BDAT f=SAS7BDAT('foo.sas7bdat').to_data_frame()} </code></pre>
0
2016-07-05T18:43:00Z
[ "python", "pandas", "encoding", "sas" ]
How do I set ylim for subplots using Pandas dataframe?
38,204,071
<p>I have more than thee columns for data frame. I can set the bottom graph using ax=plt.gca(), but how do I set the limit for other subplots? </p> <p>Below is the code I use for the plotting.</p> <pre><code>SomeDataFrame.plot(subplots=True, style=style, title='%s' % macID.upper(), grid=True, legend=True,) ax = plt.g...
2
2016-07-05T12:56:49Z
38,204,402
<p><code>SomeDataFrame.plot()</code> returns a list of the subplots it created. Using this return value you can access and manipulate them.</p> <pre><code>mysubplots = SomeDataFrame.plot(subplots=True, style=style, title='%s' % macID.upper(), grid=True, legend=True,) firstplot = mysubplots[0] firstplot.set_ylim=([lowl...
1
2016-07-05T13:13:08Z
[ "python", "pandas", "matplotlib", "subplot" ]
Writing a multidimensional structured numpy array to hdf5 one field at a time with h5py raises a numpy broadcasting error
38,204,212
<p>I'm trying to figure out how to write a multidimensional structed numpy array to an hdf5 file one field at a time with h5py, but I am getting an error about broadcasting arrays of different shape. I do need to separate the steps of creating the dataset, and writing the data into the dataset as in the example.</p> ...
2
2016-07-05T13:03:19Z
38,215,306
<p>Your script runs fine on my machine (PY3), h5py version 2.6.0. Looks like you have 2.5.</p> <blockquote> <p>It must be a bug in v2.5.0 that was fixed in v2.6.0. </p> </blockquote>
0
2016-07-06T01:51:23Z
[ "python", "arrays", "numpy", "multidimensional-array", "h5py" ]
Add value to every "other" field ((i+j)%2==0) of numpy array
38,204,283
<p>I have an <code>m</code>-by-<code>n</code> numpy array, and I'd like to add 1.0 to all entries <code>[i, j]</code> when <code>(i + j) % 2 == 0</code>, i.e., "to every other square".</p> <p>I could of course simply iterate over the fields</p> <pre><code>import numpy as np a = np.random.rand(5, 4) for i in range...
8
2016-07-05T13:06:42Z
38,204,424
<p>Here's one way using <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>NumPy broadcasting</code></a> -</p> <pre><code>a[(np.arange(a.shape[0])[:,None] + np.arange(a.shape[1]))%2==0] += 1 </code></pre> <p><strong>Explanation :</strong> We basically create two arrays that a...
5
2016-07-05T13:14:11Z
[ "python", "arrays", "numpy", "matrix" ]
Add value to every "other" field ((i+j)%2==0) of numpy array
38,204,283
<p>I have an <code>m</code>-by-<code>n</code> numpy array, and I'd like to add 1.0 to all entries <code>[i, j]</code> when <code>(i + j) % 2 == 0</code>, i.e., "to every other square".</p> <p>I could of course simply iterate over the fields</p> <pre><code>import numpy as np a = np.random.rand(5, 4) for i in range...
8
2016-07-05T13:06:42Z
38,205,288
<p>One can build a mask for "every other" element, and apply the addition on the mask.</p> <pre><code># Create mask m00 = np.zeros(a.shape[0], dtype=bool) m00[0::2] = True m01 = np.zeros(a.shape[1], dtype=bool) m01[0::2] = True m0 = np.logical_and.outer(m00, m01) m10 = np.zeros(a.shape[0], dtype=bool) m10[1::2] = T...
1
2016-07-05T13:53:27Z
[ "python", "arrays", "numpy", "matrix" ]
Add value to every "other" field ((i+j)%2==0) of numpy array
38,204,283
<p>I have an <code>m</code>-by-<code>n</code> numpy array, and I'd like to add 1.0 to all entries <code>[i, j]</code> when <code>(i + j) % 2 == 0</code>, i.e., "to every other square".</p> <p>I could of course simply iterate over the fields</p> <pre><code>import numpy as np a = np.random.rand(5, 4) for i in range...
8
2016-07-05T13:06:42Z
38,205,532
<p>You can easily do the operation in two steps, like</p> <pre><code>import numpy as np a = np.zeros((5, 14)) # Even rows, odd columns a[::2, 1::2] += 1 # Odd rows, even columns a[1::2, ::2] += 1 print a </code></pre>
5
2016-07-05T14:04:52Z
[ "python", "arrays", "numpy", "matrix" ]
Returning lists of instances makes no difference? And what about performance?
38,204,284
<p>I have just realised that for a specific module in my programme, return or not a list of instances makes no difference at all. With fixed seed the results are identical.</p> <p>Thus, I would like to know:</p> <ol> <li><p>It seems to be better programming practice to include a return statement. Is that correct?</p>...
2
2016-07-05T13:06:49Z
38,204,510
<p>In principle, not returning anything is faster. In practice, it won't matter and is a useless micro-optimization.</p> <p>Python does not move around objects, it moves <em>references</em> to objects (which are stored in names). If you have a C++ background, think of <code>return a,b,c</code> giving back an array of ...
3
2016-07-05T13:18:28Z
[ "python", "performance", "return" ]
Make a new pandas.dataframe column as filtered other column
38,204,322
<p>I have a pandas.Dataframe object in the following format: </p> <pre><code>Symb Bid Ask ESU6 207000 207025 YMU6 12793 12797 ESU6 207025 207050 YMU6 12795 12797 </code></pre> <p>But I want to re-configure the object to look like the following format:</p> <pre><code>Bid.ESU6 Ask.ESU...
2
2016-07-05T13:08:49Z
38,204,868
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a>:</p> <pre><code>df1 = df.pivot_table(columns='Symb', values=['Bid','Ask'], index=df.index) df1.sort_index(axis=1, level=1, inplace=True) df1.columns = ['.'.join(col) for co...
1
2016-07-05T13:33:11Z
[ "python", "pandas" ]
Viewing a portion of a very large CSV file?
38,204,346
<p>I have a ~1.0gb CSV file, and when trying to load it into Excel just to view, Excel crashes. I don't know the schema of the file, so it's difficult for me to load it into R or Python. The file contains restaurant reviews and has commas in it.</p> <p>How can I open just a portion of the file (say, the first 100 rows...
0
2016-07-05T13:10:08Z
38,204,766
<p>In my version of excel the open dialogs do not seem to offer a "read only these many lines" option, only a start at line (used to skip headers I guess).</p> <p>So if you have no head binary at hand on your platform, but python a simplistic working solution for your case should be (hard coded 100 lines aka rows):</p...
1
2016-07-05T13:28:47Z
[ "python", "excel", "csv" ]
Viewing a portion of a very large CSV file?
38,204,346
<p>I have a ~1.0gb CSV file, and when trying to load it into Excel just to view, Excel crashes. I don't know the schema of the file, so it's difficult for me to load it into R or Python. The file contains restaurant reviews and has commas in it.</p> <p>How can I open just a portion of the file (say, the first 100 rows...
0
2016-07-05T13:10:08Z
38,206,084
<p>If you want to do somewhat more selective fishing for particular rows, then the python <code>csv</code> module will allow you to read the csv file row by row into Python data structures. Consult the documentation.</p> <p>This may be useful if just grabbing the first hundred lines reveals nothing about many of the c...
1
2016-07-05T14:30:43Z
[ "python", "excel", "csv" ]
'file' object has no attribute '__getitem__' and a missing module
38,204,366
<p>I am getting error with this code!! First the xreadlines module does not exist anymore so i commented the line. Now when i run this code it gives error:</p> <pre><code>Traceback (most recent call last): File "/home/integrand/projects/testproject2/testenv/Paragraph.py", line 58, in &lt;module&gt; show_paragrap...
-1
2016-07-05T13:11:03Z
38,204,626
<p>You can't use subscription on an iterator (which is what <code>file.xreadlines()</code> returns). If you need random access to different lines, just use <code>file.readlines()</code> or <code>list(file)</code> instead.</p> <p>Note that <code>file.xreadlines()</code> has been deprecated since Python 2.3 (released 13...
0
2016-07-05T13:23:12Z
[ "python", "python-2.7", "compiler-errors", "runtime-error" ]
Beautifying raw weather results to something more readable
38,204,399
<p>I am creating a weather app using the <code>pyowm</code> module and I managed to get the temperature of <em>xyz</em> place but the thing is it is not so appealing to others because it's just raw results and I want to make it readable. Below is the code and its output.</p> <pre><code>import pyowm owm = pyowm.OWM('my...
0
2016-07-05T13:13:03Z
38,204,638
<p>You don’t need regex, regex is for detecting patterns in strings and whatnot. What you want is to construct a string out of data. There are many, many ways to accomplish this, but the easiest is probably</p> <pre><code>'\n'.join(key + ':' + str(v) for k, v in result.items()) </code></pre> <p>If you want to use a...
2
2016-07-05T13:23:49Z
[ "python", "python-3.x", "openweathermap" ]
Python Regex help required
38,204,533
<p>I am trying to extract data from a text file. For ex in line '35 of Jon 2013 trans. (P) ' I am trying to extract (35, 2013, (P)). </p> <p>In this 35 is document number and 2015 is document year, (P) denotes priority document. </p> <p>Document Numbers are followed by Document year and they have (P) in end if docume...
4
2016-07-05T13:19:24Z
38,204,754
<p>Try this regex:</p> <pre><code>(\d+) of [a-zA-Z]+ (\d+) [a-zA-Z.]+(?:[,]? (\(P\)))? </code></pre>
2
2016-07-05T13:28:22Z
[ "python", "regex" ]
Python Regex help required
38,204,533
<p>I am trying to extract data from a text file. For ex in line '35 of Jon 2013 trans. (P) ' I am trying to extract (35, 2013, (P)). </p> <p>In this 35 is document number and 2015 is document year, (P) denotes priority document. </p> <p>Document Numbers are followed by Document year and they have (P) in end if docume...
4
2016-07-05T13:19:24Z
38,204,943
<p>This works as you want it:</p> <pre><code>import re reg = r'(\d+)[^\d]*(\d+)[^\d|\(]*(\(P\))*' line = '35 of Jon 2013 trans. (P) 31 of Sansa 2014 filled 3232 of Arya 2014 empty 345 of Bran 2011 sealed, (P)' print 'Output by reg' for _ in re.findall(reg, line, re.IGNORECASE): print _ </code></pre>
3
2016-07-05T13:36:23Z
[ "python", "regex" ]
How to XOR two binary strings in python
38,204,582
<p>I need to do XOR operation between two binary strings.</p> <pre><code>xor("00110011", "11001100") = "11111111" </code></pre> <p>i am currently using this function</p> <pre><code>def xor(x, y): ans = "" for i in xrange(len(x)): if x[i] == "0" and y[i] == "1" or x[i] == "1" and y[i] == "0": ...
-2
2016-07-05T13:21:33Z
38,204,679
<pre><code>def xor(x, y): return '{0:b}'.format(int(x, 2) ^ int(y, 2)) </code></pre> <p>Credits to <a href="http://stackoverflow.com/questions/19414093/how-to-xor-binary-with-python">this answer</a>. Contrary to popular belief, <a href="https://wiki.python.org/moin/BitwiseOperators" rel="nofollow">Python does have...
4
2016-07-05T13:25:35Z
[ "python", "xor" ]
How to XOR two binary strings in python
38,204,582
<p>I need to do XOR operation between two binary strings.</p> <pre><code>xor("00110011", "11001100") = "11111111" </code></pre> <p>i am currently using this function</p> <pre><code>def xor(x, y): ans = "" for i in xrange(len(x)): if x[i] == "0" and y[i] == "1" or x[i] == "1" and y[i] == "0": ...
-2
2016-07-05T13:21:33Z
38,204,713
<p>If you <em>must</em> use strings of <code>'0'</code> and <code>'1'</code> characters, just use a mapping:</p> <pre><code>_xormap = {('0', '1'): '1', ('1', '0'): '1', ('1', '1'): '0', ('0', '0'): '0'} def xor(x, y): return ''.join([_xormap[a, b] for a, b in zip(x, y)]) </code></pre> <p>otherwise, just convert t...
4
2016-07-05T13:26:54Z
[ "python", "xor" ]
How to XOR two binary strings in python
38,204,582
<p>I need to do XOR operation between two binary strings.</p> <pre><code>xor("00110011", "11001100") = "11111111" </code></pre> <p>i am currently using this function</p> <pre><code>def xor(x, y): ans = "" for i in xrange(len(x)): if x[i] == "0" and y[i] == "1" or x[i] == "1" and y[i] == "0": ...
-2
2016-07-05T13:21:33Z
38,204,962
<p>If you need to reinvent the whell</p> <pre><code>def alternative_xor(x, y): a = int(x) b = int(y) return (a &amp; ~b) | (~a &amp; b) </code></pre>
-2
2016-07-05T13:37:14Z
[ "python", "xor" ]
Subsorting list of mappings
38,204,797
<p>I have a mapping like the following</p> <pre><code>mapping = [ "key1", "key2", "key3", "key4", "key5#1", "key5#4", "key5#2", "key5#3", "key6#1", "key6#2" ] </code></pre> <p>and a list of lists, e.g. <code>[['val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val...
-1
2016-07-05T13:30:16Z
38,205,151
<p>You can use <code>itertools.groupby</code> here. The idea is to create a dict using the keys from mapping and initially each key will be initialized to a list of <code>None</code>'s of the size of number of repetitions of a key.</p> <pre><code>from itertools import groupby dct = {} for k, g in groupby(mapping, lamb...
2
2016-07-05T13:46:19Z
[ "python", "list", "python-3.x", "dictionary", "mapping" ]
Subsorting list of mappings
38,204,797
<p>I have a mapping like the following</p> <pre><code>mapping = [ "key1", "key2", "key3", "key4", "key5#1", "key5#4", "key5#2", "key5#3", "key6#1", "key6#2" ] </code></pre> <p>and a list of lists, e.g. <code>[['val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val...
-1
2016-07-05T13:30:16Z
38,205,176
<p>Is this what you're asking for?</p> <pre><code>for i, key in enumerate(mapping): if '#' in key: key, order = key.split('#') result.setdefault(key, []).insert(int(order) - 1, row[i]) else: result[key] = row[i] </code></pre> <p>Notes:</p> <ol> <li>Use <code>enumerate</code> - <code>f...
0
2016-07-05T13:47:36Z
[ "python", "list", "python-3.x", "dictionary", "mapping" ]
Subsorting list of mappings
38,204,797
<p>I have a mapping like the following</p> <pre><code>mapping = [ "key1", "key2", "key3", "key4", "key5#1", "key5#4", "key5#2", "key5#3", "key6#1", "key6#2" ] </code></pre> <p>and a list of lists, e.g. <code>[['val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val...
-1
2016-07-05T13:30:16Z
38,205,214
<p>Sounds like a job for <code>groupby</code> and list slicing. Note that you’re missing a comma in <code>row</code> after <code>val9</code>.</p> <pre><code>def split_key(k): if '#' in k: return k.split('#')[0] else: return k def group_keys(keys): for K, G in groupby(keys, key=split_key)...
0
2016-07-05T13:49:15Z
[ "python", "list", "python-3.x", "dictionary", "mapping" ]
scrapy1.1 Crawled 0 pages but i can get data with scrapy shell command
38,205,011
<p>I've been trying to study the Scrapy tutorial and after running the command at the project top level , I get the following output:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-ove...
-1
2016-07-05T13:39:56Z
38,205,040
<p>It is not <code>strat_urls</code>, it is <code>start_urls</code> and it needs to be an <em>iterable</em> (usually, it is a list) with urls as items:</p> <pre><code>class DmozSpider(scrapy.Spider): name = 'dmoz' allowed_domains = ['dmoz.org'] start_urls = ['http://www.dmoz.org/Computers/Programming/Langu...
1
2016-07-05T13:41:18Z
[ "python", "scrapy", "data-extraction", "scrapy-shell" ]
Python - Type error upon evaluating string match
38,205,132
<p>I'm trying to normalize some data. In my dataframe, if the columns begin with the same prefix, they belong together (fe. <code>ab_000</code> and <code>ab_001</code> belong together, however <code>ac_000</code> does not belong to the previous two). So I'm trying to normalize the belonging columns with an l1 normaliza...
1
2016-07-05T13:45:25Z
38,205,343
<p>It looks like one of your data.columns is type int.</p> <p><strong>getitem</strong>() is called when you use operator []. </p> <p>For example, when <code>tmp = columns[2]</code>, <code>columns.__getitem__(2)</code> is called.</p>
0
2016-07-05T13:55:58Z
[ "python", "pandas" ]
Plotting date labels with mpld3
38,205,238
<p>I need help with this. The plot is fine but when I'm hovering over the points I get the S&amp;P price as y (which is right) but instead of the date as x I get a timestamp. Is there anyone able to fix it? Thanks!</p> <pre><code>import matplotlib.pyplot as plt import mpld3 from mpld3 import plugins import pandas.io....
0
2016-07-05T13:50:34Z
38,552,815
<p>This probably isn't the best method but it works :</p> <pre><code>series = ax.plot(price) date_axis = [pd.to_datetime(str(date)).strftime('%Y.%m.%d') for date in series[0].get_data()[0]] labels = [(date, " {0}".format(val)) for date, val in zip(date_axis, series[0].get_data()[1])] </code></pre> <p>So in steps to...
0
2016-07-24T13:57:51Z
[ "python", "datetime", "mpld3" ]
Pandas append dataframe without creating new columns
38,205,289
<p>I have two dataframes that look like this:</p> <pre><code>df1= A B 1 A1 B1 2 A2 B2 3 A3 B3 df2 = A C 4 A4 C4 5 A5 C5 </code></pre> <p>I would like to append <code>df2</code> to <code>df1</code>, like so:</p> <pre><code> A B 1 A1 B1 2 A2 B2 3 A3 B3 4 A4 NaN 5 A5 NaN </code...
2
2016-07-05T13:53:27Z
38,205,485
<p>You can first filter columns for appending by <code>subset</code>:</p> <pre><code>print (df2[['A']]) A 4 A4 5 A5 print (pd.concat([df1, df2[['A']]])) A B 1 A1 B1 2 A2 B2 3 A3 B3 4 A4 NaN 5 A5 NaN print (df1.append(df2[['A']])) A B 1 A1 B1 2 A2 B2 3 A3 B3 4 A4 NaN 5 A5 ...
1
2016-07-05T14:02:44Z
[ "python", "pandas", "dataframe", "append", "concat" ]
Pandas append dataframe without creating new columns
38,205,289
<p>I have two dataframes that look like this:</p> <pre><code>df1= A B 1 A1 B1 2 A2 B2 3 A3 B3 df2 = A C 4 A4 C4 5 A5 C5 </code></pre> <p>I would like to append <code>df2</code> to <code>df1</code>, like so:</p> <pre><code> A B 1 A1 B1 2 A2 B2 3 A3 B3 4 A4 NaN 5 A5 NaN </code...
2
2016-07-05T13:53:27Z
38,205,701
<p>Actually the solution is in an obscure corner of <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html" rel="nofollow">this page</a>. Here's the code to use:</p> <pre><code>pd.concat([df1,df2],join_axes=[df1.columns]) </code></pre>
0
2016-07-05T14:12:37Z
[ "python", "pandas", "dataframe", "append", "concat" ]
Plotly R not working with Jupyter notebook
38,205,353
<p>I want to incorporate Plotly graphs in my Jupyter notebook but I'm getting a 404 error when I try to display a graph:</p> <p><a href="http://i.stack.imgur.com/A6vvN.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/A6vvN.jpg" alt="Error"></a></p> <p>According to this <a href="http://stackoverflow.com/question...
0
2016-07-05T13:56:26Z
38,224,360
<p>Do you have a plotly account? You may need to login into it within your notebook with something similar to this: </p> <pre><code>import plotly plotly.tools.set_config_file(plotly_domain='domain') from plotly import __version__ from plotly.offline import download_plotlyjs, init_notebook_mode, iplot import plotly.p...
0
2016-07-06T12:44:52Z
[ "python", "jupyter", "plotly" ]
Plotly R not working with Jupyter notebook
38,205,353
<p>I want to incorporate Plotly graphs in my Jupyter notebook but I'm getting a 404 error when I try to display a graph:</p> <p><a href="http://i.stack.imgur.com/A6vvN.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/A6vvN.jpg" alt="Error"></a></p> <p>According to this <a href="http://stackoverflow.com/question...
0
2016-07-05T13:56:26Z
38,346,658
<p>I have the same issue in MacOS. In the console, it can be seen that it's looking for .html.embed but the file which is created is .html. I have tried, 1) reinstalling Pandocs 2) Had to reinstall Cairo as package pbdZMQ was not getting installing properly.</p> <p>This is the workaround I did,</p> <pre><code>p &lt;-...
0
2016-07-13T08:40:11Z
[ "python", "jupyter", "plotly" ]
What's the most efficient way to sleep in Python?
38,205,364
<p>What would be better ?</p> <p><code>time.sleep(delayTime)</code> </p> <p>or</p> <p><code>select.select([],[],[],delayTime)</code></p> <p>Are they equivalent ? Is select more efficient?</p>
2
2016-07-05T13:56:58Z
38,205,666
<p>Pretty simple to hackup a test in python with called to <code>timeit</code>, but I love ipython for quick tests (<a href="http://ipython.org/" rel="nofollow">http://ipython.org/</a>). Here's my results:</p> <pre><code>$ ipython import time,select %timeit time.sleep(0) 1000000 loops, best of 3: 655 ns per loop %ti...
1
2016-07-05T14:10:42Z
[ "python", "performance", "select", "time", "sleep" ]
What's the most efficient way to sleep in Python?
38,205,364
<p>What would be better ?</p> <p><code>time.sleep(delayTime)</code> </p> <p>or</p> <p><code>select.select([],[],[],delayTime)</code></p> <p>Are they equivalent ? Is select more efficient?</p>
2
2016-07-05T13:56:58Z
38,205,678
<p>How you defining the efficiency? In most of the cases, the sleep and select have been using to observe if there space/buffer. If the space is not available, then we have option to wait and see when the buffer will be empty and we can execute our action. The sleep() internally select(). So, I think it matters with wh...
1
2016-07-05T14:11:21Z
[ "python", "performance", "select", "time", "sleep" ]
What's the most efficient way to sleep in Python?
38,205,364
<p>What would be better ?</p> <p><code>time.sleep(delayTime)</code> </p> <p>or</p> <p><code>select.select([],[],[],delayTime)</code></p> <p>Are they equivalent ? Is select more efficient?</p>
2
2016-07-05T13:56:58Z
38,205,795
<p>The answer depends on what your trying to achieve:</p> <p><strong>time.sleep(delayTime)</strong>:<br></p> <ul> <li>Action: Suspend execution of the current thread for the given number of seconds.</li> <li>Any caught signal will terminate the sleep() following execution of that signal’s catching routine</li> </ul...
2
2016-07-05T14:16:52Z
[ "python", "performance", "select", "time", "sleep" ]
python openpyxl time insert without date
38,205,409
<p>I have a value that I want to insert into excel as time formatted like HH:MM If I use</p> <pre><code> cellFillTime = Style(fill = PatternFill(start_color=shiftColor,end_color=shiftColor,fill_type='solid'), border = Border(left=Side(style='thin'),right=Side(style='thin'),top=...
0
2016-07-05T13:59:12Z
38,305,929
<p>So the final catch was also adding the right time format for cells with hours and also to the cell that contains the SUM formula</p> <pre><code> _cell.number_format='[h]:mm;@' </code></pre>
0
2016-07-11T11:35:21Z
[ "python", "excel", "time", "openpyxl" ]
scipy.integrate.trapz and discontinuous functions
38,205,462
<p>The function <code>scipy.integrate.trapz</code> uses <em>Newton-Cotes formula of order 1</em> as it said in the scipy documentation. However, in the derivation of this formula it is usually assumed that</p> <ul> <li>the integrand is a continuous function and</li> <li>the points, in which the value of the integrand ...
1
2016-07-05T14:01:27Z
38,214,611
<p>The effect of repeating an x-value in <code>trapz</code> is the same as splitting the interval of integration at that value, and applying <code>trapz</code> separately to each part: </p> <pre><code>from scipy.integrate import trapz trapz([0, 0, 2, 2], [0, 1, 1, 2]) trapz([0, 0], [0, 1]) + trapz([2, 2], [1, 2]) </co...
1
2016-07-05T23:57:34Z
[ "python", "scipy", "integral" ]
Pandas: How to create a multi-indexed pivot
38,205,540
<p>I have a set of experiments defined by two variables: <code>scenario</code> and <code>height</code>. For each experiment, I take 3 measurements: result 1, 2 and 3. The dataframe that collects all the results looks like this:</p> <pre><code>import numpy as np import pandas as pd df = pd.DataFrame() df['Scenario']=...
2
2016-07-05T14:05:11Z
38,206,263
<p>You can first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a> with <a href="http://panda...
1
2016-07-05T14:38:33Z
[ "python", "pandas", "dataframe", "pivot", "multi-index" ]
How to commit df to SQL database using pyodbc?
38,205,545
<p>I have a connection to a database (using pyodbc) and I need to commit a df to a new table. I've done this with SQL, but don't know how to do it with a df. Any ideas on how to alter the below code to make it work for a df?</p> <p>code for SQL:</p> <pre><code>import pyodbc import pandas as pd conn= pyodbc.con...
1
2016-07-05T14:05:27Z
38,206,245
<p>The documentation for <code>to_sql()</code> clearly states:</p> <blockquote> <p><strong>con : SQLAlchemy engine or DBAPI2 connection (legacy mode)</strong></p> <p>Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported.</p> </blockquote> <p...
0
2016-07-05T14:37:40Z
[ "python", "sql", "pandas" ]
SQLAlchemy, Declarative, PostgreSQL: cannot create tables
38,205,603
<p>I created a number of classes I want to persist to the database. I would like to be able to run the app with a specific flag to take all those classes and create the corresponding tables in my db. To that end, I'm trying to import the classes and then call the <code>Base.metadata.create_all(engine)</code> method. Ho...
0
2016-07-05T14:08:22Z
38,207,369
<p>You already created <code>Base</code> in <code>Item.py</code>, just import it in <code>main.py</code>:</p> <p>If <code>main.py</code> and <code>Item.py</code> are on the same folder, then in <code>main.py</code>:</p> <p><code>from Item import Base, Item</code></p> <p>And remove all imports inside <code>main</code...
2
2016-07-05T15:32:15Z
[ "python", "postgresql", "sqlalchemy" ]
Regex string matching python issue
38,205,682
<p>i am trying to learn how to use regular expression in order to filter strings, especially i am trying to filter the following string:</p> <blockquote> <p>some text \n {{Information \n | region = [[Western]] \n | image = image187a.jpg{{!}} \n| .... \n }} \n some text</p> </blockquote> <p>What i would like to do ...
0
2016-07-05T14:11:36Z
38,205,914
<p>This gives you the text inside the Information "Tag":</p> <pre><code>import re text = "some text \n {{Information \n | region = [[Western]] \n | .... \n }} \n some text" result = re.search(r'{{Information (.*)}}', text, flags=re.DOTALL) print(result.groups()[0] </code></pre>
0
2016-07-05T14:22:43Z
[ "python", "regex" ]
Regex string matching python issue
38,205,682
<p>i am trying to learn how to use regular expression in order to filter strings, especially i am trying to filter the following string:</p> <blockquote> <p>some text \n {{Information \n | region = [[Western]] \n | image = image187a.jpg{{!}} \n| .... \n }} \n some text</p> </blockquote> <p>What i would like to do ...
0
2016-07-05T14:11:36Z
38,205,986
<p>You need to use a lazy quantifier between the delimiters so that it can match additional characters that span multiple lines. Adding multi-line mode is making it so that <code>^</code> and <code>$</code> match the beginning and end of the same line. Remove that. A useful mode though would be dot-all.</p> <pre><code...
0
2016-07-05T14:26:22Z
[ "python", "regex" ]
Regex string matching python issue
38,205,682
<p>i am trying to learn how to use regular expression in order to filter strings, especially i am trying to filter the following string:</p> <blockquote> <p>some text \n {{Information \n | region = [[Western]] \n | image = image187a.jpg{{!}} \n| .... \n }} \n some text</p> </blockquote> <p>What i would like to do ...
0
2016-07-05T14:11:36Z
38,206,038
<p>I prefer using re.search() to re.split() for this, as you are trying to search for a pattern. You might try something like this:</p> <pre><code>import re some_text = 'some text \n {{Information \n | region = [[Western]] \n | .... \n }} \n some text' rx_match = re.search(r'{{Information(?P&lt;info&gt;.*?)}}', some...
0
2016-07-05T14:28:28Z
[ "python", "regex" ]
python: how to delete registry key (and subkeys) from HKLM (getting error 5)
38,205,784
<p>I'm trying to delete certain registry keys, via python script.<br> i have no problems reading and deleting keys from the "HKEY_CURRENT_USER", but trying to do the same from the "HKEY_LOCAL_MACHINE", gives me the dreaded <strong>WindowsError: [Error 5] Access is denied</strong>.<br> i'm running the script via the IDL...
1
2016-07-05T14:16:04Z
38,866,730
<p>Figured it out!<br> turns out the registry key wasn't empty and contained multiple subkeys.<br> i had to enumerate and delete the subkeys first, and only then i was able to delete the main key from HKLM. (also added "try...except", so it wouldn't break the whole code, it case there were problems).</p>
0
2016-08-10T07:22:53Z
[ "python", "registry", "winreg" ]
How to fix Firefox stopping when using selenium?
38,206,159
<p>Using Firefox 47.1 on Windows 10, I try to run the selenium example 2 given <a href="https://pypi.python.org/pypi/selenium#downloads" rel="nofollow">here</a>. When starting the script, a new Firefox window opens and after a while the following error is shown in the PyCharm console:</p> <pre><code>selenium.common.ex...
0
2016-07-05T14:34:01Z
38,227,917
<p>This looks like a compatibility issue. Note that there will always be a gap between the last browser version and Selenium support. For Firefox I would not recommend going above version 43.</p> <p>All Firefox releases can be found <a href="https://ftp.mozilla.org/pub/firefox/releases/" rel="nofollow">here</a>.</p> ...
0
2016-07-06T15:32:26Z
[ "python", "selenium", "firefox", "selenium-webdriver" ]
Can not infer schema for type: <type 'str'>
38,206,240
<p>I have the following Python code that uses Spark:</p> <pre><code>from pyspark.sql import Row def simulate(a, b, c): dict = Row(a=a, b=b, c=c) df = sqlContext.createDataFrame(dict) return df df = simulate("a","b",10) df.collect() </code></pre> <p>I am creating a <code>Row</code> object and I want to save it...
0
2016-07-05T14:37:25Z
38,206,398
<p>It is pointless to create single element data frame. If you want to make it work despite that use list: <code>df = sqlContext.createDataFrame([dict])</code></p>
1
2016-07-05T14:44:27Z
[ "python", "apache-spark", "pyspark" ]
How to alter plot axes in seaborn scatterplot matrix, sns.pairplot()
38,206,270
<p>I have the following plot with <code>sns.pairplot()</code></p> <pre><code>import seaborn as sns sns.set() df = pd.read_csv('filename.csv') sns.pairplot(df, hue="B") </code></pre> <p><a href="http://i.stack.imgur.com/9j9pD.png" rel="nofollow"><img src="http://i.stack.imgur.com/9j9pD.png" alt="enter image descripti...
1
2016-07-05T14:38:48Z
38,225,415
<p>You can access an array of matplotlib <code>Axes</code> at the <code>.axes</code> attribute of the object that <code>pairplot</code> returns.</p>
0
2016-07-06T13:36:55Z
[ "python", "pandas", "matplotlib", "dataframe", "seaborn" ]
Python run bash command which saves data to file
38,206,282
<p>I'm trying to run a bash-command in python where the bash-command saves data to a file rather than displaying it. An example of such command is</p> <pre><code>$ echo 'foo' &gt; bar.txt </code></pre> <p>currently my code looks like the following</p> <pre><code>process = subprocess.Popen(bashCommand.split(), stdout...
0
2016-07-05T14:39:15Z
38,206,336
<p>Use <code>print()</code>. Simple as that. Anything that would normally be printed to the console will instead be printed to a file, because of the <code>&gt;</code> command.</p> <pre><code>~$ python3.5 your_script.py &gt; bar.txt </code></pre> <p>If you do not want to run your python script with <code>&gt;</code>,...
0
2016-07-05T14:41:39Z
[ "python", "bash" ]
Python run bash command which saves data to file
38,206,282
<p>I'm trying to run a bash-command in python where the bash-command saves data to a file rather than displaying it. An example of such command is</p> <pre><code>$ echo 'foo' &gt; bar.txt </code></pre> <p>currently my code looks like the following</p> <pre><code>process = subprocess.Popen(bashCommand.split(), stdout...
0
2016-07-05T14:39:15Z
38,206,873
<p>By default, <code>subprocess.Popen()</code> does not run the command via the shell, and therefore I/O redirection operators have no special meaning -- they are treated as ordinary arguments. The easiest way to achieve what you're after is to make it use the shell. With <code>Popen()</code>, you would pass <code>sh...
0
2016-07-05T15:06:10Z
[ "python", "bash" ]
Python SimpleCookie and JSON Value
38,206,300
<p>I've run into some problems using Python's <code>SimpleCookie</code> when using a JSON string as a value.</p> <pre><code>In [1]: from http.cookies import SimpleCookie In [2]: cookie = SimpleCookie('x=1; json={"myVal":1}; y=2') In [3]: cookie.keys() Out[3]: dict_keys(['x']) In [4]: cookie = SimpleCookie('x=1; y=2...
0
2016-07-05T14:40:10Z
38,206,689
<p>Currently you're trying to use an object as the value, not a JSON string representation of that object. You need to escape the JSON string within your argument string, as follows:</p> <pre><code>&gt;&gt;&gt; from http.cookies import SimpleCookie &gt;&gt;&gt; cookie = SimpleCookie(r'x=1; json="{\"myVal\":1}"; y=2') ...
2
2016-07-05T14:57:35Z
[ "python", "python-3.x", "cookies", "httpcookie" ]
Python SimpleCookie and JSON Value
38,206,300
<p>I've run into some problems using Python's <code>SimpleCookie</code> when using a JSON string as a value.</p> <pre><code>In [1]: from http.cookies import SimpleCookie In [2]: cookie = SimpleCookie('x=1; json={"myVal":1}; y=2') In [3]: cookie.keys() Out[3]: dict_keys(['x']) In [4]: cookie = SimpleCookie('x=1; y=2...
0
2016-07-05T14:40:10Z
38,206,698
<p>This includes <code>'json'</code> as a key in Python 3.3.2 and earlier:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; from http.cookies import SimpleCookie &gt;&gt;&gt; cookie = SimpleCookie('x=1; json=json.dumps({"myVal":1}); y=2') &gt;&gt;&gt; cookie.keys() dict_keys(['y', 'x', 'json']) </code></pre> <p>H...
0
2016-07-05T14:58:13Z
[ "python", "python-3.x", "cookies", "httpcookie" ]
Popen chaining with command sequence
38,206,311
<p>On Windows I successfully run this:</p> <pre><code>cmd = ["gfortran", "test.f90", "-o", "test.exe", "&amp;&amp;", "test.exe"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) print(p.stdout.read()) </code></pre> <p>On Ubuntu I change <code>cmd</code> to:</p> <pre><code>cmd = ["gfortran", "test.f90", ...
0
2016-07-05T14:40:47Z
38,206,510
<p>This is what the docs state:</p> <blockquote> <p>On POSIX with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for...
1
2016-07-05T14:50:04Z
[ "python", "python-3.x" ]
Popen chaining with command sequence
38,206,311
<p>On Windows I successfully run this:</p> <pre><code>cmd = ["gfortran", "test.f90", "-o", "test.exe", "&amp;&amp;", "test.exe"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) print(p.stdout.read()) </code></pre> <p>On Ubuntu I change <code>cmd</code> to:</p> <pre><code>cmd = ["gfortran", "test.f90", ...
0
2016-07-05T14:40:47Z
38,206,680
<p>It's impossible. When <code>cmd</code> is a list, it has different meaning when shell is True. <a href="https://docs.python.org/2/library/subprocess.html#popen-constructor" rel="nofollow">Quoting docs</a>:</p> <blockquote> <p>If args is a sequence, the first item specifies the command string, and any additional...
2
2016-07-05T14:57:22Z
[ "python", "python-3.x" ]
Popen chaining with command sequence
38,206,311
<p>On Windows I successfully run this:</p> <pre><code>cmd = ["gfortran", "test.f90", "-o", "test.exe", "&amp;&amp;", "test.exe"] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) print(p.stdout.read()) </code></pre> <p>On Ubuntu I change <code>cmd</code> to:</p> <pre><code>cmd = ["gfortran", "test.f90", ...
0
2016-07-05T14:40:47Z
38,206,963
<p>It appears that you are using <code>shell=True</code> to allow you to do <code>&amp;&amp;</code> on the command line. This is not strictly necessary if you are already using <code>subprocess</code> anyway:</p> <pre><code>cmd1 = ["gfortran", "test.f90", "-o", "test.exe"] cmd2 = ["test.exe"] if not subprocess.call(cm...
0
2016-07-05T15:10:31Z
[ "python", "python-3.x" ]
How save specific user instance into database using django views
38,206,406
<p>I created models called Interview, Users, Interview_interviewer like wise... Interview_interviewer table has foreign keys from other models. I just want to save data from both 2 tables to Interview_interviewer(Without django forms) table which is many to many table. So I just created the views and template for it. W...
0
2016-07-05T14:45:05Z
38,206,772
<p>Try using <a href="https://docs.djangoproject.com/en/1.9/topics/http/urls/#named-groups" rel="nofollow">named groups</a> in your url patterns</p> <pre><code>urlurl(r'^hod/hod_vacancy/test/part2/inter_list/?P&lt;iid&gt;[0-9]+)/?P&lt;pid&gt;[0-9]+/$', hod_inter_interviewer_2, name="inter2"), </code></pre> <p>If that...
0
2016-07-05T15:02:07Z
[ "python", "django", "django-models", "django-views" ]
Python celery - how to wait for all subtasks in chord
38,206,416
<p>I am unit testing celery tasks. I have chain tasks that also have groups, so a chord is resulted.</p> <p>The test should look like:</p> <ul> <li>run celery task ( delay )</li> <li>wait for task and all subtasks</li> <li>assert</li> </ul> <p>I tried the following:</p> <pre><code>def wait_for_result(result): r...
0
2016-07-05T14:45:34Z
38,371,718
<p>Have you tried chord + callback ?</p> <p><a href="http://docs.celeryproject.org/en/latest/userguide/canvas.html#chords" rel="nofollow">http://docs.celeryproject.org/en/latest/userguide/canvas.html#chords</a></p> <pre><code>&gt;&gt;&gt; callback = tsum.s() &gt;&gt;&gt; header = [add.s(i, i) for i in range(100)] &gt...
0
2016-07-14T10:25:14Z
[ "python", "celery", "celery-task", "chord" ]
Django: remove duplicates from order by -count query
38,206,575
<p><strong>I want to have a list with the most picked Player objects, descending.</strong></p> <p>I have the following table structure:</p> <p><kbd>id</kbd><kbd>player_id</kbd><kbd>formation_id</kbd><br> <kbd>1</kbd><kbd>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</kbd><kbd>1&nbsp;...
0
2016-07-05T14:52:39Z
38,207,609
<p>You need GROUP BY expression generated by Django, as described in this question:</p> <p><a href="http://stackoverflow.com/questions/19101665/django-how-to-do-select-count-group-by-and-order-by">Django: how to do SELECT COUNT(*) GROUP BY and ORDER BY</a></p> <p>so your line of code will be something similar to</p> ...
1
2016-07-05T15:45:06Z
[ "python", "sql", "django", "postgresql" ]
Hide tick labels and offset in matplotlib
38,206,582
<p>I have two subplots that share the same x-axis. I removed the xticklabels of the upper subplot, but the offset "1e7" remains visible. How can I hide it?</p> <p>Here is the code I used :</p> <pre><code>import matplotlib.pyplot as plt import numpy as np plt.figure() s1 = plt.subplot(2,1,1) s1.plot(np.arange(0,1e8,1...
0
2016-07-05T14:52:52Z
38,207,800
<p>I finally find the answer on <a href="https://github.com/matplotlib/matplotlib/issues/4445" rel="nofollow">https://github.com/matplotlib/matplotlib/issues/4445</a>. I need to add the following line to my code :</p> <pre><code>plt.setp(s1.get_xaxis().get_offset_text(), visible=False) </code></pre>
0
2016-07-05T15:55:37Z
[ "python", "matplotlib", "plot" ]
Hide tick labels and offset in matplotlib
38,206,582
<p>I have two subplots that share the same x-axis. I removed the xticklabels of the upper subplot, but the offset "1e7" remains visible. How can I hide it?</p> <p>Here is the code I used :</p> <pre><code>import matplotlib.pyplot as plt import numpy as np plt.figure() s1 = plt.subplot(2,1,1) s1.plot(np.arange(0,1e8,1...
0
2016-07-05T14:52:52Z
38,207,992
<p>An alternative is to use <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots" rel="nofollow"><code>plt.subplots</code></a> to create the subplots, and use <code>sharex=True</code> as an option there. This automatically turns off all <code>ticklabels</code> and the <code>offset_text</code> f...
1
2016-07-05T16:06:59Z
[ "python", "matplotlib", "plot" ]
Django, filter query set through multiple entry_set.all() relationships
38,206,587
<pre><code>class Server(models.Model): client = models.ForeignKey(Client, on_delete=models.CASCADE) ... class Schedule(models.Model): client = models.ForeignKey(Client, on_delete=models.CASCADE) ... class LineItem(models.Model): schedule = models.ForeignKey(Schedule, on_delete=models.CASCADE) ...
-1
2016-07-05T14:53:04Z
38,208,620
<p>Rather than following the reverse relationship <code>model_set</code> managers. You can follow the <code>ForeignKey</code> relationships by using the double underscore notation from the Django ORM</p> <pre><code>line_items = LineItem.objects.filter(schedule__client=server.client) </code></pre>
0
2016-07-05T16:44:29Z
[ "python", "django", "django-models", "django-queryset" ]
How to update module path that is already installed? Odoo
38,206,614
<p>I am looking for a way to update the currently installed module's path. I want to move the module from one <code>addons</code> folder to a different one and my attempt to just move the module and then <code>Update Modules List</code> gives me nothing. The module is not found and only a grayed out module name is left...
1
2016-07-05T14:54:25Z
38,218,401
<p>In your <code>openerp-server.conf</code> file on line <code>addons_path</code> add your custom path, just put comma and place your path. </p> <p>Restart server after that, update module list.</p>
1
2016-07-06T07:27:53Z
[ "python", "database", "module", "path", "openerp" ]
Strange output using random python
38,206,642
<p>i have this problem where i sort a list based on randomness. how the algorithm works is two select a random number between 0 to N-1 (N is length of list) and swap with a iterating index.</p> <p>i have two different algorithms like this.</p> <pre><code>import random def algo1(xx): for i in xrange(len(xx)): ...
0
2016-07-05T14:55:48Z
38,206,822
<p>You are modifying the list (I am assuming you’re on python 2.7) in place. Thus, when you shuffle the <code>k</code> with <code>algo2</code>, you are also affecting <code>z1</code>. All three lists are really the same object. You need to create a list copy, for example <code>algo1(k[:])</code>.</p> <p>I would also...
2
2016-07-05T15:04:08Z
[ "python", "variables", "random" ]
Strange output using random python
38,206,642
<p>i have this problem where i sort a list based on randomness. how the algorithm works is two select a random number between 0 to N-1 (N is length of list) and swap with a iterating index.</p> <p>i have two different algorithms like this.</p> <pre><code>import random def algo1(xx): for i in xrange(len(xx)): ...
0
2016-07-05T14:55:48Z
38,206,825
<p>Your function alters <code>k</code> and returns a reference to it. There is no new <code>list</code> being created.</p> <p>The difference in what you are seeing is:</p> <ul> <li><p>When you <strong>print</strong>, you show the <em>current state</em> of what <code>algoX</code> has returned (which is a reference to ...
2
2016-07-05T15:04:15Z
[ "python", "variables", "random" ]
Strange output using random python
38,206,642
<p>i have this problem where i sort a list based on randomness. how the algorithm works is two select a random number between 0 to N-1 (N is length of list) and swap with a iterating index.</p> <p>i have two different algorithms like this.</p> <pre><code>import random def algo1(xx): for i in xrange(len(xx)): ...
0
2016-07-05T14:55:48Z
38,206,871
<p>As you're passing, modifying and returning the same variable (list) <code>k</code> to both functions, you're modifying the same data each time.</p> <p>Try using:</p> <pre><code>print("z1", id(z1)) print("z2", id(z2)) print("k", id(k)) </code></pre> <p>This will return the identity of the variable. You'll notice t...
1
2016-07-05T15:06:07Z
[ "python", "variables", "random" ]
Strange output using random python
38,206,642
<p>i have this problem where i sort a list based on randomness. how the algorithm works is two select a random number between 0 to N-1 (N is length of list) and swap with a iterating index.</p> <p>i have two different algorithms like this.</p> <pre><code>import random def algo1(xx): for i in xrange(len(xx)): ...
0
2016-07-05T14:55:48Z
38,206,982
<p>Try this:</p> <pre><code>z1 = algo1(k) print z1 z2 = algo2(k) print z2 print z1 print k </code></pre> <p>You are simply overwrite the same list. Google for "python Immutable vs Mutable types" to understand this behaviour.</p>
1
2016-07-05T15:11:09Z
[ "python", "variables", "random" ]
Python: Parallelizing GPU and CPU work
38,206,695
<p>Processing batches for my ML models takes too much time so I am considering parallelizing them.</p> <p>Right now preprocessing routine grabs data from SSD, does preprocessing and form a data structure for learning. All this time ML training process waits. Then ML process takes this data and uses it to train the mod...
1
2016-07-05T14:58:10Z
38,206,971
<p>TensorFlow's Python binding is very diligent about releasing the global interpreter lock as soon as possible. For instance, it does not hold the lock when the control has transferred to the C++ library in the <code>tf.Session</code>'s <code>run</code> method. What you describe is a very common pattern in TensorFlow....
1
2016-07-05T15:10:51Z
[ "python", "multithreading", "concurrency", "parallel-processing", "tensorflow" ]
Merge Spark RDDs from bad JSON
38,206,756
<p>I have a lot json files, however they aren't formatted correctly for Spark. I don't want to write code to specifically convert them to the correct format by normalizing each dict on each line. </p> <p>Instead I am hoping to use spark to parse their content. I have the following</p> <pre><code>import json import o...
0
2016-07-05T15:01:19Z
38,207,252
<p>Use flatMap instead of map to do exactly that :)</p>
1
2016-07-05T15:25:57Z
[ "python", "json", "apache-spark", "rdd" ]
SSH through Python with ~/.ssh/config file
38,206,787
<p>I'm trying to create a script that uses SSH in Python to log in to a remote machine. My script is then supposed to call a certain rest API from that machine, and then returns the response to the original client.</p> <p>I can't use subprocesses so that's sadly out of the question. I tried using Paramiko and Fabric b...
0
2016-07-05T15:02:52Z
38,212,211
<p>Yes, I have done something similar.</p> <p>Here is a working sample program that uses SSH in Python to log in to a remote machine, then calls a certain rest API from that machine, then returns the response to the original client.</p> <pre><code>import paramiko from xml.etree import ElementTree as ET import sys my...
0
2016-07-05T20:31:18Z
[ "python", "ssh" ]
Python sort a complicated list in list
38,206,812
<p>My list: </p> <pre><code>a = [[["a", 0], ["b", 7], ['c', 3]], 9, [['d', 0], ['e', 5], ['f', 7]], 5, [['g', 8], ['h', 3]], 3, [['i', 0], ['j', 1], ['k', 3]], 3] </code></pre> <p>I want to sort the list by the number after "]]," as the list above like: 9, 5, 3 and 3. I tried: </p> <pre><code>a.sort(key=lambda x: x[...
0
2016-07-05T15:03:52Z
38,206,953
<p>Your problem is your ints aren’t associated with the list; currently you have <code>[list, int, list, int, list, int, ...]</code> instead of <code>[(list, int), (list, int), (list, int), ...]</code>. If your list is generated by your code, try rewriting it to output list–int pairs. Otherwise, try regenerating a ...
5
2016-07-05T15:09:42Z
[ "python" ]
Python sort a complicated list in list
38,206,812
<p>My list: </p> <pre><code>a = [[["a", 0], ["b", 7], ['c', 3]], 9, [['d', 0], ['e', 5], ['f', 7]], 5, [['g', 8], ['h', 3]], 3, [['i', 0], ['j', 1], ['k', 3]], 3] </code></pre> <p>I want to sort the list by the number after "]]," as the list above like: 9, 5, 3 and 3. I tried: </p> <pre><code>a.sort(key=lambda x: x[...
0
2016-07-05T15:03:52Z
38,206,984
<pre><code>a = [[["a", 0], ["b", 7], ['c', 3]], 9, [['d', 0], ['e', 5], ['f', 7]], 5, [['g', 8], ['h', 3]], 3, [['i', 0], ['j', 1], ['k', 3]], 3] </code></pre> <p>In this list of yours, the numbers and the inner-lists are independent elements of the main lists. S, there is no sorting possible - it is "apples" and "ora...
0
2016-07-05T15:11:11Z
[ "python" ]
myThread issue, outdate issue?
38,206,820
<p>When i run a script, it executes except for the threading...I get this error:</p> <pre><code>Traceback (most recent call last): File "script.py", line 133, in &lt;module&gt; thread = myThread(i, "Thread " + str(i), i); File "script.py", line 100, in __init__ self.name = name File "/usr/lib/python2...
-1
2016-07-05T15:04:02Z
38,208,130
<pre><code>class myThread (threading.Thread): def __init__(self, threadID, name, counter): threading.Thread.__init__(self) self.threadID = threadID self.name = name self.counter = counter def run(self): print "[+] Starting " + self.name connect(self.name, self.counter...
1
2016-07-05T16:15:04Z
[ "python", "multithreading" ]
How to handle authentication popup with Selenium WebDriver using python?
38,206,849
<p>In <a href="http://stackoverflow.com/questions/24304752/how-to-handle-authentication-popup-with-selenium-webdriver-using-java">this question</a> an answer is given on how to handle authentication popup with Selenium WebDriver using <em>Java</em>. Now, can this be used also for python? It looks like the python driver...
1
2016-07-05T15:05:16Z
38,207,120
<p>Indeed there is no such class in python selenium library, but you can easly navigate to given alert and input user and password using other means.</p> <pre><code>wait = WebDriverWait(driver, 10) alert = wait.until(ExpectedConditions.alert_is_present()) alert = driver.switch_to_alert() alert.send_keys('username') al...
0
2016-07-05T15:18:13Z
[ "java", "python", "selenium" ]
Python: how to unittest a class that reads a command line arg?
38,206,894
<p>I want to write unit tests for a Python script. The script itself runs correctly.</p> <p>The script consists of one class, which reads a value from the command line into a class variable.</p> <p>When I import the class into my test file, I get the error 'list index out of range' at the point where the class reads ...
1
2016-07-05T15:07:20Z
38,207,075
<p>Generally, unit testing is helpful in figuring out the boundaries of your classes. If your class is hard to unit test, you should think: "how can I make it easier to test?" Almost always this leads to better structured classes.</p> <p>One of these symptoms is that you have external dependencies, like sys.argv, that...
2
2016-07-05T15:15:46Z
[ "python", "unit-testing", "pycharm", "command-line-arguments" ]
Merging two datetime-indexed pandas.dataframe objects
38,206,895
<p>I have two datetime-indexed pandas.dataframe objects:</p> <p>object1: </p> <pre><code> DateTime Bid.ESU6 Ask.ESU6 2016-06-28 08:30:00 207000 207025 2016-06-28 08:30:11 206975 207000 2016-06-28 08:30:21 207000 207050 </code></pre> <p>object2:</p> ...
2
2016-07-05T15:07:22Z
38,208,153
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reindex.html" rel="nofollow"><code>reindex</code></a> on <code>object2</code> with <code>method='nearest'</code> prior to doing the <code>join</code>:</p> <pre><code>object1 = object1.join(object2.reindex(object1.index, meth...
3
2016-07-05T16:15:49Z
[ "python", "pandas" ]
Scrape site based on span text
38,206,927
<p>I am trying to scrape only "MLB" scores from the following site: www.scoresandodds.com/pgrid_20160628.html?sort=rot</p> <p>A section of the HTML code looks like:</p> <pre><code>&lt;div xmlns:dat="http://scoresandodds.com/dataset-main" class="section"&gt; &lt;div class="heading"&gt;&lt; span class="league"&gt;MLB&l...
1
2016-07-05T15:08:36Z
38,206,957
<p>Locate the <code>MLB</code> "label" and get the first following <code>table</code> only via <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-all-next-and-find-next" rel="nofollow"><code>find_next()</code></a>:</p> <pre><code>mlb_table = soup.find("span", class_="league", text="MLB").find_next("t...
2
2016-07-05T15:10:13Z
[ "python", "web-scraping", "beautifulsoup" ]
Python: Can't Find Module When Running Script Within a Script
38,207,061
<p>I created a Python program A for which I later wrote another Python program B that called A using the subprocess library. I had a module foo installed in A which worked perfectly fine until I started calling the program from B. Now, I get the error:</p> <pre><code>ImportError: no module named foo </code></pre> <p>...
1
2016-07-05T15:14:48Z
38,207,593
<p>I tried adding the path to the Levenshtein module in PYTHONPATH (it already existed in PATH), and that solved my problem; though I don't entirely understand why. Thanks to those who contributed advice.</p> <p><strong>EDIT</strong></p> <p>Found the real answer to my problem here: <a href="http://stackoverflow.com/...
0
2016-07-05T15:44:22Z
[ "python", "import", "subprocess" ]
best way to create a numpy array from a list and additional individual values
38,207,188
<p>I want to create an array from list entries and some additional individual values.</p> <p>I am using the following approach which seems clumsy:</p> <pre><code>x=[1,2,3] y=some_variable1 z=some_variable2 x.append(y) x.append(z) arr = np.array(x) #print arr --&gt; [1 2 3 some_variable1 some_variable2] </code></pre>...
3
2016-07-05T15:22:05Z
38,207,236
<p>You can use list addition to add the variables all placed in a list to the larger one, like so:</p> <pre><code>arr = np.array(x + [y, z]) </code></pre>
3
2016-07-05T15:25:09Z
[ "python", "arrays", "python-2.7", "numpy" ]
best way to create a numpy array from a list and additional individual values
38,207,188
<p>I want to create an array from list entries and some additional individual values.</p> <p>I am using the following approach which seems clumsy:</p> <pre><code>x=[1,2,3] y=some_variable1 z=some_variable2 x.append(y) x.append(z) arr = np.array(x) #print arr --&gt; [1 2 3 some_variable1 some_variable2] </code></pre>...
3
2016-07-05T15:22:05Z
38,208,158
<p>Appending or concatenating lists is fine, and probably fastest.</p> <p>Concatenating at the array level works as well</p> <pre><code>In [456]: np.hstack([x,y,z]) Out[456]: array([1, 2, 3, 4, 5]) </code></pre> <p>This is compact, but under the covers it does</p> <pre><code>np.concatenate([np.array(x),np.array([y]...
1
2016-07-05T16:16:05Z
[ "python", "arrays", "python-2.7", "numpy" ]
Switch frames with selenium and phantomJS
38,207,202
<p>I need to open the search windows on this page.</p> <p><a href="https://permits.losgatosca.gov/CitizenAccess/default.aspx" rel="nofollow">https://permits.losgatosca.gov/CitizenAccess/default.aspx</a></p> <p>With firefox is working just fine, but when I try to do the same with phantomJS i got an error.</p> <p>This...
1
2016-07-05T15:22:56Z
38,207,272
<p>This is what you should try:</p> <ul> <li>upgrade both <code>selenium</code> and <code>PhantomJS</code> to the latest versions</li> <li><p>add a <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">wait</a> before switching to frame:</p> <pre><code>from selenium.webdriver.common...
1
2016-07-05T15:27:12Z
[ "python", "selenium", "iframe", "phantomjs" ]
Make python script processing large number of files faster
38,207,449
<p>I have written a python script which takes input as a directory and lists all files in that directory, it then decompresses each of these files and does some extra processing it. The code is very straightforward, uses a list of files from os.listdir( directory ) and for each file in the list it decompresses it and t...
0
2016-07-05T15:35:57Z
38,209,871
<p>Note os.system() is synchronous, i.e. python waits for the task to complete before going to the next line.</p> <p>Here is a simplification of what I do on Windows 7 and Python 2.66<br> You should be able to easily modify this for your needs.<br> 1. create and run a process for each task I want to run in paralle...
0
2016-07-05T18:05:46Z
[ "python", "scripting" ]
Using (conf) file to exchange variables between python scripts?
38,207,486
<p>I'd like to have one python script running (sometimes) that will read button presses (from a wiimote) and update a conf file such that another python script can use that file to adjust lighting brightness. </p> <p>I'm guessing the <em>best</em> way to have two python scripts exchange/share variables would be to use...
0
2016-07-05T15:38:19Z
38,207,641
<p>Socket could be a good idea to exchange data between to Python programs, it's lightweight and doesn't require anything else than Python to run. It can also handle large amount of data without hassle.</p>
0
2016-07-05T15:46:25Z
[ "python" ]
Python: Count no of elements from list of list and feed to Matrix?
38,207,491
<p>Given a list of list's, where each list is of the length</p> <pre><code> M = [[1,2,3,4,4,5,1,2,9,0], [3,2,1,0,5,6,2,4,6,7], [4,5,5,2,1,2,3,4,2,4], [7,5,6,2,6,7,8,8,8,1] ] </code></pre> <p>I want to count the number of repetition's of an element and feed it into a separate matrix.</p> <p>Let's call each list as a ...
1
2016-07-05T15:38:35Z
38,219,165
<p>I changed the function <code>Vfinal</code> to <code>Vfinal2</code>. </p> <p>This makes the code faster</p> <pre><code>def Vfinal2(s_t,Matrix): V = np.zeros((s_t,len(Matrix))) for i,row in enumerate(Matrix): a = np.bincount(row) b=np.zeros(s_t) b[:len(a)]=a ...
2
2016-07-06T08:10:51Z
[ "python", "python-3.x", "for-loop", "counter", "python-xarray" ]
PyQt4: Only the last signal is being processed
38,207,511
<p>I ran into a strange problem when working on my project. I have a GUI and a QTextEdit that serves as a status browser. When a button is clicked, I want the QTextEdit to display a 10 second countdown while another function is happening in a separate thread. Even though I emit a signal every second, the QTextEdit hang...
0
2016-07-05T15:39:51Z
38,223,366
<p><code>time.sleep()</code> blocks the Qt main loop so it can't process window redraw events. Use a <code>QTimer</code> to periodically call a method which emits your signal so that control is returned to the Qt event loop regularly.</p>
1
2016-07-06T11:53:46Z
[ "python", "pyqt4" ]
What are the efficient ways to loop over vectors along a specified axis in numpy ndarray?
38,207,528
<p>I'm processing data by looping over vectors along an axis (could be any axis) of numpy ndarray (could be of any dimensions).</p> <p>I didn't work on array directly because the data are not perfect. It requires quality control on each vector. If not good, the vector will be filled by zeros (or nan) and not have a re...
3
2016-07-05T15:40:51Z
38,207,882
<p>Have you considered <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.nditer.html#numpy.nditer" rel="nofollow"><code>numpy.nditer</code></a>?</p> <p>See also <a href="http://docs.scipy.org/doc/numpy/reference/arrays.nditer.html#arrays-nditer" rel="nofollow">Iterating over arrays</a>.</p> <p>EDIT: ...
1
2016-07-05T15:59:51Z
[ "python", "arrays", "numpy" ]
What are the efficient ways to loop over vectors along a specified axis in numpy ndarray?
38,207,528
<p>I'm processing data by looping over vectors along an axis (could be any axis) of numpy ndarray (could be of any dimensions).</p> <p>I didn't work on array directly because the data are not perfect. It requires quality control on each vector. If not good, the vector will be filled by zeros (or nan) and not have a re...
3
2016-07-05T15:40:51Z
38,212,957
<p>The best way to test efficiency is to do time tests on realistic examples. But <code>%timeit</code> (ipython) tests on toy examples are a start.</p> <p>Based on experience from answering similar 'if you must iterate' questions, there isn't much difference in times. <code>np.frompyfunc</code> has a modest speed ed...
2
2016-07-05T21:21:54Z
[ "python", "arrays", "numpy" ]
how to run every unittest in a test suite individually?
38,207,597
<p>I am using PyCharm to run a fairly sized test suite (1800 fast tests). Modifying a test recently, I realized my test would not break. The do break when I run those tests individually, but if I run the whole test suite they will always pass. This is due to this type of incorrect mocking of classes some previous co-wo...
0
2016-07-05T15:44:37Z
38,207,866
<h2>Start a single test from the console</h2> <p>See the post <a href="http://stackoverflow.com/questions/15971735/running-single-test-from-unittest-testcase-via-command-line">Running single test from unittest.TestCase via command line</a>.</p> <h2>Start it using pyCharm</h2> <p>Supposing you have already a test for...
1
2016-07-05T15:59:05Z
[ "python", "unit-testing", "pycharm" ]
how to run every unittest in a test suite individually?
38,207,597
<p>I am using PyCharm to run a fairly sized test suite (1800 fast tests). Modifying a test recently, I realized my test would not break. The do break when I run those tests individually, but if I run the whole test suite they will always pass. This is due to this type of incorrect mocking of classes some previous co-wo...
0
2016-07-05T15:44:37Z
38,210,367
<p>There is another possibility for you to start the test methods in pyCharm individually. Run the complete test once. The "Run" window opens and on the left side there is a "TestResult" box wich logs each individual test. Wait for pyCharm having completet all the tests. Then rightclick the test method you want to exec...
0
2016-07-05T18:37:07Z
[ "python", "unit-testing", "pycharm" ]
Extract Data from PDF with Incorrect Structural OCR
38,207,687
<p>I have a regular inflow of invoice pdfs. I extract the data from these pdfs for various manipulations and storage.</p> <p>Here's an example section:<a href="http://i.stack.imgur.com/hF4z8.png" rel="nofollow"><img src="http://i.stack.imgur.com/hF4z8.png" alt="enter image description here"></a></p> <p>The first ste...
0
2016-07-05T15:48:56Z
38,211,953
<p>Rather than try to recast the data, just work with what you have. You are getting two groups of lines, the first group containing the left half the the line of data, the second group containing the right half. <code>itertools.groupby</code> is great for splitting up rows by some grouping criterion. In this case, you...
1
2016-07-05T20:14:36Z
[ "python", "parsing", "pdf", "ocr", "apache-tika" ]
Can't change my ImageView to data retrieved from stream in Swift
38,207,881
<p>I'm trying to retrieve a picture over an inputstream and then set my ImageView to that picture. Below is my code for how to retrieve the inputstream and read the data.</p> <pre><code> let bufferSize = 1024 var buffer = Array&lt;UInt8&gt;(repeating: 0, count: bufferSize) while (inputStream.hasBytesAvailable...
0
2016-07-05T15:59:46Z
38,243,242
<p>So, to accumulate the data fragment into one Data, you need to write something like this:</p> <pre><code> let bufferSize = 1024 var buffer = Array&lt;UInt8&gt;(repeating: 0, count: bufferSize) //You need to assign an actual Data to the variable. //With initial value given, you have no need to work wi...
1
2016-07-07T10:32:17Z
[ "python", "swift", "uiimageview", "buffer", "twisted" ]
Can't change my ImageView to data retrieved from stream in Swift
38,207,881
<p>I'm trying to retrieve a picture over an inputstream and then set my ImageView to that picture. Below is my code for how to retrieve the inputstream and read the data.</p> <pre><code> let bufferSize = 1024 var buffer = Array&lt;UInt8&gt;(repeating: 0, count: bufferSize) while (inputStream.hasBytesAvailable...
0
2016-07-05T15:59:46Z
38,245,090
<p>My mistake was not sending each byte of the file. When i changed my server code to: </p> <pre><code>with open("/home/pi/Documents/server/foo.jpg", "rb") as f: byte = f.read() print "Done reading" while byte: self.transport.write(byte) byte = f.read(1) print "Done sending" f.close() ...
0
2016-07-07T12:08:31Z
[ "python", "swift", "uiimageview", "buffer", "twisted" ]
Most efficient solution for sharing code between two django projects
38,207,914
<p>I have to find a solution for sharing code between two big Django projects. The main things to share are models and serializers and template tags. I've came up with 3 different solutions and I need you to find pro and cons to be able to make a choice.</p> <p>I'll list you the solutions I found:</p> <h1>git submodu...
0
2016-07-05T16:01:55Z
38,208,333
<p>I will go with python package, after all this is what it is for.</p>
1
2016-07-05T16:27:15Z
[ "python", "django", "git", "django-rest-framework" ]
Most efficient solution for sharing code between two django projects
38,207,914
<p>I have to find a solution for sharing code between two big Django projects. The main things to share are models and serializers and template tags. I've came up with 3 different solutions and I need you to find pro and cons to be able to make a choice.</p> <p>I'll list you the solutions I found:</p> <h1>git submodu...
0
2016-07-05T16:01:55Z
38,209,913
<p>I will definitely go with the second option you listed - packaging your app. If you follow steps in the <a href="https://docs.djangoproject.com/en/1.9/intro/reusable-apps/#packaging-your-app" rel="nofollow">Packaging your app</a> part of official Django tutorial, you'll get tar.gz file which will allow you to includ...
1
2016-07-05T18:08:45Z
[ "python", "django", "git", "django-rest-framework" ]
Error in loadNamespace(name) Cairo
38,207,942
<p>It's my first time using <code>R</code> in <code>jupyter</code>. I've installed everything like <code>jupyter</code>, <code>python</code>, <code>R</code> and <code>lRkernel</code>. I can use just typing or calculation in jupyter but whenever I want to use a graph library like <code>plot</code> or <code>ggplot2</code...
1
2016-07-05T16:03:51Z
38,773,030
<p>I had the precise same issue and fixed it by installing Cairo package: <code> install.packages("Cairo")` library(Cairo) </code> Thanks to my collegue Bartek for providing this solution</p>
1
2016-08-04T16:42:42Z
[ "python", "jupyter", "cairo" ]
Finding a number in a string on a specific line in Python
38,207,954
<p>I am pushed with the challenge of creating a program that reads a text file. This program also needs to find certain things in the text file, I have already figured out how to do a basic read and search on the file. After it does the basic read and search it takes the most relevant information, and puts it into its ...
0
2016-07-05T16:04:54Z
38,208,074
<p>You can use regular expression capture groups to extract the overscan type and the number after the equal sign. </p> <pre><code>a = 'overscan_left=20' b = re.match('overscan_([^=]+)=([0-9]+)',a) if b: print b.groups() </code></pre> <p>output:</p> <pre><code>('left', '20') </code></pre> <p>You would need to c...
1
2016-07-05T16:11:53Z
[ "python", "raspberry-pi", "raspbian", "readfile" ]
Finding a number in a string on a specific line in Python
38,207,954
<p>I am pushed with the challenge of creating a program that reads a text file. This program also needs to find certain things in the text file, I have already figured out how to do a basic read and search on the file. After it does the basic read and search it takes the most relevant information, and puts it into its ...
0
2016-07-05T16:04:54Z
38,208,321
<p>To parse your config file into a <code>dict</code> you can use</p> <pre><code>def read_config(conf): config = {} for line in conf: line = line.strip() if line.startswith('#'): continue varname, value = line.split('=') config[varname] = value return config </co...
4
2016-07-05T16:26:41Z
[ "python", "raspberry-pi", "raspbian", "readfile" ]