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
Connection being reset by client
37,800,846
<p>So I am trying to have my computer to communicate with a device and I am getting an error of the Ethernet connection reset. The output from the server side looks like this</p> <p><code>Calling accept on socket Accepted connection socket csock:10 Received Ethernet connection from ip: 186.142.1.23 Warning - ...
0
2016-06-13T23:47:06Z
37,804,585
<p>The client immediately closes the connection whithout waiting or trying to read anything. So when the server tries to write something into the socket, it fails because the client has already closed it.</p> <p>You should implement a minimal logic in the client (at least sleep some time and then read) to do your test...
0
2016-06-14T06:34:16Z
[ "python", "sockets", "networking" ]
I am getting a syntax error when trying to lock a label in ClearCase in a python script
37,800,861
<p>I am new to python and I am trying to execute a <code>cleartool lock</code> command.</p> <p>Here is my code:</p> <pre><code> def lock_label(lname): os.system('cleartool lock lbtype:' + lname'@vob:/cm_data/jupsw') </code></pre> <p>lname is my variable name</p>
-2
2016-06-13T20:18:37Z
37,800,862
<p>You are missing the plus sign between your lname variable and the <code>'@vob...</code> part of your string:</p> <pre><code> def lock_label(lname): os.system('cleartool lock lbtype:' + lname + '@vob:/cm_data/jupsw') </code></pre> <p>Each time you alternate between a literal string value and a variable name dur...
2
2016-06-13T20:33:37Z
[ "python" ]
What is surface.blit() function in python ? what does it do? how it works?
37,800,894
<p>I am a beginner in Python and i am not clear about the function surface.blit() method. what does it do? how it works? i have come accross the following points as to how to create it.</p> <ul> <li>Create a canvas of desired size</li> <li>Create a surface of smaller size containing the object to be displayed.</li> <l...
-1
2016-06-13T23:52:48Z
37,805,623
<p>Putting this in real terms may help, although as simply put as possible -> <strong>blitting is drawing</strong></p> <p>Going through each of the steps you have mentioned:</p> <ul> <li>Create a canvas of a desired size</li> </ul> <p>This is our window, created by <code>screen = pygame.display.set_mode((width,heigh...
0
2016-06-14T07:29:42Z
[ "python", "canvas", "pygame", "blit" ]
pip install netmiko error
37,800,898
<p>sudo -H pip install netmiko Collecting netmiko</p> <h2>----</h2> <p>Installing collected packages: setuptools, idna, ipaddress, enum34, cryptography, paramiko, scp, pyyaml, netmiko Found existing installation: setuptools 1.1.6 Uninstalling setuptools-1.1.6: Exception: Traceback (most recent call last): Fil...
-3
2016-06-13T23:53:39Z
37,819,316
<p>Yes, I would first decouple from the MacOS system Python (i.e. install a separate Python from the system Python).</p> <p><a href="http://docs.python-guide.org/en/latest/starting/install/osx/" rel="nofollow">http://docs.python-guide.org/en/latest/starting/install/osx/</a></p> <p>Then install Netmiko using that Pyth...
1
2016-06-14T18:14:14Z
[ "python", "python-2.7" ]
Fit a curve to the boundary of a scatterplot
37,800,958
<p>I'm trying to fit a curve to the boundary of a scatterplot. <a href="http://i.stack.imgur.com/OMTHl.png" rel="nofollow">See this image for reference</a>. <a href="http://i.stack.imgur.com/OMTHl.png" rel="nofollow"><img src="http://i.stack.imgur.com/OMTHl.png" alt="enter image description here"></a></p> <p>I have ac...
3
2016-06-14T00:00:36Z
39,759,756
<p>I found the problem really interesting, so I decided to give it a try. I don't know about pythonic or natural, but I think I've found a more accurate way of fitting an edge to a data set like yours while using information from <em>every</em> point.</p> <p>First off, let's generate a random data that looks like the ...
0
2016-09-29T00:58:47Z
[ "python", "pandas", "scipy", "curve-fitting" ]
parsing CSV to pandas dataframes (one-to-many unmunge)
37,801,063
<p>I have a csv file imported to a pandas dataframe. It probably came from a database export that combined a one-to-many parent and detail table. The format of the csv file is as follows:</p> <pre><code>header1, header2, header3, header4, header5, header6 sample1, property1,,,average1,average2 ,,detail1,detail2,, ,,d...
1
2016-06-14T00:13:57Z
37,801,155
<p>You can use the fact that the first <code>column</code> seems to be empty unless it's a new <code>sample</code> record to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html" rel="nofollow"><code>.fillna(method='ffill')</code></a> and then <a href="http://pandas.pydata.org/pan...
0
2016-06-14T00:26:41Z
[ "python", "csv", "pandas", "dataframe", "panels" ]
parsing CSV to pandas dataframes (one-to-many unmunge)
37,801,063
<p>I have a csv file imported to a pandas dataframe. It probably came from a database export that combined a one-to-many parent and detail table. The format of the csv file is as follows:</p> <pre><code>header1, header2, header3, header4, header5, header6 sample1, property1,,,average1,average2 ,,detail1,detail2,, ,,d...
1
2016-06-14T00:13:57Z
38,236,627
<p>The answer above got me going in the right direction. With further work, the following was used. It turns out I needed to use two columns as a compound key to uniquely identify samples.</p> <pre><code>df.header1 = df.header1.fillna(method='ffill') df.header2 = df.header2.fillna(method='ffill') grouped = df.groupby...
0
2016-07-07T02:10:38Z
[ "python", "csv", "pandas", "dataframe", "panels" ]
Python list unpacking, is this expensive? Is it inefficient?
37,801,069
<p>Suppose I have a Python function that returns multiple elements, for example <code>myfoo0()</code></p> <pre><code>def myfoo0(): return([1, 2, 3]) </code></pre> <p>and that this is used as:</p> <pre><code>fit = myfoo0(); </code></pre> <p>Now, consider a function that used some of the entries of <code>fit</code...
0
2016-06-14T00:15:07Z
37,801,140
<p>There are some misconceptions here:</p> <ol> <li><p><code>fit = myfoo0();</code> doesn't copy anything. <code>fit</code> is merely a reference to the list returned by <code>myfoo0()</code>, not a copy.</p></li> <li><p><code>[a, b, c] = myfoo0();</code> doesn't create a new list as well. On the otherhand, you have 3...
2
2016-06-14T00:25:20Z
[ "python" ]
Can't get my Labels to update in tkinter
37,801,111
<p>I'm trying to create a program in where you put a word in a box, press add, and this word goes to a list, which is also displayed on the right side. When I press the forward button the first thing on teh list is deleted. Problem is I can't get the labels to update when I press teh buttons / edit the list...</p> <p>...
-2
2016-06-14T00:21:55Z
37,810,109
<p>Is this the sort of thing you were looking for ?</p> <pre><code>from tkinter import * root = Tk() root.title('Speakers List') root.minsize(800, 600) speakers = ['50'] spe = speakers[0] def add(): entry=e.get() speakers.append(entry) listdisplay.config(text=speakers) return def forward(): if...
0
2016-06-14T11:00:28Z
[ "python", "tkinter", "labels" ]
duplicate a tensorflow graph
37,801,137
<p>What is the best way of duplicating a TensorFlow graph and keep it uptodate?</p> <p>Ideally I want to put the duplicated graph on another device (e.g. from GPU to CPU) and then time to time update the copy.</p>
5
2016-06-14T00:24:58Z
37,885,614
<p>I'll try to go with a pretty simplified answer, to see if the general approach is what OP is describing:</p> <p>I'd implement it via the tf.train.Saver object. </p> <p>Suppose you have your weights in a variable W1, W2, and b1</p> <pre><code>mysaver = tf.train.Saver(({'w1': W1, 'w2': W2, 'b1': b1})) </code></pre>...
1
2016-06-17T15:47:21Z
[ "python", "tensorflow" ]
duplicate a tensorflow graph
37,801,137
<p>What is the best way of duplicating a TensorFlow graph and keep it uptodate?</p> <p>Ideally I want to put the duplicated graph on another device (e.g. from GPU to CPU) and then time to time update the copy.</p>
5
2016-06-14T00:24:58Z
37,886,053
<p><strong>Short answer:</strong> You probably want <a href="https://www.tensorflow.org/versions/master/how_tos/variables/index.html#saving-and-restoring">checkpoint files</a>.</p> <hr> <p><strong>Long answer:</strong></p> <p>Let's be clear about the setup here. I'll assume that you have two devices, A and B, and yo...
6
2016-06-17T16:13:12Z
[ "python", "tensorflow" ]
Issues connecting vgg19 in tensorflow
37,801,193
<p>I am having an issue getting my VGG19 neural network to connect. Here is the whole graph:</p> <pre><code>class VGG(object): def __init__(self, n_classes=252): self.input_data = tf.placeholder(dtype=tf.float32, name='input_data', shape=(5, 224, 224, 3)) with tf.variable_scope("group1"): ...
1
2016-06-14T00:32:22Z
37,806,014
<p>This is totally normal, your implementation if fine.</p> <p>VGG uses 5 max pooling with stride 2 and <code>padding='SAME'</code>, which reduces the feature map size by 2 in height and 2 in width (if it is divisible by 2).</p> <p>You specify an input image of size 224x224:</p> <pre><code>self.input_data = tf.place...
0
2016-06-14T07:48:41Z
[ "python", "tensorflow", "deep-learning" ]
Issues connecting vgg19 in tensorflow
37,801,193
<p>I am having an issue getting my VGG19 neural network to connect. Here is the whole graph:</p> <pre><code>class VGG(object): def __init__(self, n_classes=252): self.input_data = tf.placeholder(dtype=tf.float32, name='input_data', shape=(5, 224, 224, 3)) with tf.variable_scope("group1"): ...
1
2016-06-14T00:32:22Z
37,806,347
<p>I think your problem is, that you tried to reshape pool5 into the size of the fully connected layer 4096. But those 4096 are only the amount of neurons that fc layer has but not its number of inputs. I tried to change your code accordingly.</p> <pre><code> with tf.variable_scope("conv16"): se...
0
2016-06-14T08:05:54Z
[ "python", "tensorflow", "deep-learning" ]
passing command line options having multiple suboptions to python script -- shell script
37,801,209
<p>I have the following options:</p> <pre><code>python runscript.py -O start -a "-a "\"-o \\\"-f/dev/sda1 -b256k -Q8\\\" -l test -p maim\"" </code></pre> <p>runscript takes <code>-O</code> and <code>-a</code> and then sends remaining to shell script 1</p> <p>shell script 1 takes option -a and should consider remaini...
0
2016-06-14T00:34:50Z
37,801,937
<p>The command you gave is bit confusing. I am generalizing the scenario. Is this something you meant?</p> <p><code>python runscript.py -p1 v1 -p2 v2 -p3 v3</code></p> <ol> <li><code>runscript.py</code> will take all given parameters.</li> <li>and calls <code>shellsript_1.sh</code> with selected params say <code>-p2 ...
0
2016-06-14T02:14:47Z
[ "python", "linux", "bash", "shell" ]
passing command line options having multiple suboptions to python script -- shell script
37,801,209
<p>I have the following options:</p> <pre><code>python runscript.py -O start -a "-a "\"-o \\\"-f/dev/sda1 -b256k -Q8\\\" -l test -p maim\"" </code></pre> <p>runscript takes <code>-O</code> and <code>-a</code> and then sends remaining to shell script 1</p> <p>shell script 1 takes option -a and should consider remaini...
0
2016-06-14T00:34:50Z
37,836,073
<p>The conventional way to do this in UNIX is to split the argument list about a pivot (usually --) such that the main script consumes all the arguments to the left of the pivot and leaves the remaining arguments for the other script(s). If you have flexibility in your calling function, I'd recommend doing it this way...
0
2016-06-15T12:53:41Z
[ "python", "linux", "bash", "shell" ]
Merging two or more columns which don't overlap
37,801,230
<p>Follow up to this post: <a href="http://stackoverflow.com/questions/37800486/merging-two-columns-which-dont-overlap-and-create-new-columns/37800550?noredirect=1#comment63066935_37800550">Merging two columns which don&#39;t overlap and create new columns</a></p> <pre><code>import pandas as pd df1 = pd.DataFrame([["...
1
2016-06-14T00:37:10Z
37,801,248
<p>Not sure what's happening here, but if I do</p> <pre><code>df1.merge(df2, on=['Year', 'Quarter', 'Value'], how='outer').dropna() </code></pre> <p>I get:</p> <pre><code> Year Quarter Value 0 2014 q2 2.0 1 2013 q1 1.0 2 2016 q1 3.0 3 2015 q1 3.0 </code></pre> <p>You may want ...
2
2016-06-14T00:40:09Z
[ "python", "pandas", "dataframe", "merge" ]
Merging two or more columns which don't overlap
37,801,230
<p>Follow up to this post: <a href="http://stackoverflow.com/questions/37800486/merging-two-columns-which-dont-overlap-and-create-new-columns/37800550?noredirect=1#comment63066935_37800550">Merging two columns which don&#39;t overlap and create new columns</a></p> <pre><code>import pandas as pd df1 = pd.DataFrame([["...
1
2016-06-14T00:37:10Z
37,801,257
<p>pandas <code>concat</code> is much better suited for this.</p> <pre><code>pd.concat([df1, df2]).reset_index(drop=True) Year Quarter Value 0 2014 q2 2 1 2013 q1 1 2 2016 q1 3 3 2015 q1 3 </code></pre> <p><code>concat</code> is intended to place one dataframe adjacent...
2
2016-06-14T00:42:01Z
[ "python", "pandas", "dataframe", "merge" ]
Merging two or more columns which don't overlap
37,801,230
<p>Follow up to this post: <a href="http://stackoverflow.com/questions/37800486/merging-two-columns-which-dont-overlap-and-create-new-columns/37800550?noredirect=1#comment63066935_37800550">Merging two columns which don&#39;t overlap and create new columns</a></p> <pre><code>import pandas as pd df1 = pd.DataFrame([["...
1
2016-06-14T00:37:10Z
37,801,715
<p>You're looking for the append feature:</p> <pre><code>df_final = df1.append(df2) </code></pre>
1
2016-06-14T01:45:35Z
[ "python", "pandas", "dataframe", "merge" ]
How to split file into smaller by first number in second column
37,801,260
<p>So my data looks like: </p> <pre><code>1 3456542 5 may 2014 2 1245678 4 may 2014 3 4256876 2 may 2014 4 5643156 6 may 2014 ..... </code></pre> <p>The goal is to sort it by the 2nd column then separate the rows based on the first number in the 2nd column (i.e. 3456542 goes to subs_3.txt, 1245678 goes to sub...
0
2016-06-14T00:42:40Z
37,801,360
<p>You could use <a href="https://docs.python.org/2/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> to group the lines that go to same file together and then just loop over the groups in order to write the files:</p> <pre><code>from itertools import groupby for k, g in grou...
0
2016-06-14T00:57:27Z
[ "python", "text", "io" ]
Reducing the rows of a dataframe by adding observed values
37,801,272
<p>I have experimental data for a number of microscope slides. For each slide I have taken a number of photographic images, and on each image I have a number of specimens. I would like to know show many specimens I have for each slide:</p> <p>eg: <strong>On slide 0, I have four specimens in total</strong> (three in im...
3
2016-06-14T00:44:28Z
37,801,421
<p>You can get the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.nunique.html" rel="nofollow"><code>.nunique()</code></a> <code>Specimen</code> for each <code>.groupby(['Slide', 'Image')</code> like so:</p> <pre><code>uniques = df.groupby(['Slide', 'Image'])['Specimen'].nunique() </code>...
1
2016-06-14T01:05:45Z
[ "python", "pandas", "group-by" ]
Reducing the rows of a dataframe by adding observed values
37,801,272
<p>I have experimental data for a number of microscope slides. For each slide I have taken a number of photographic images, and on each image I have a number of specimens. I would like to know show many specimens I have for each slide:</p> <p>eg: <strong>On slide 0, I have four specimens in total</strong> (three in im...
3
2016-06-14T00:44:28Z
37,801,675
<p>The groupby feature allows you to essentially "pivot" the results like you would in excel:</p> <pre><code>df = df.groupby(['Slide','Image']).Specimen.nunique() </code></pre> <p>The .nunique() function will give you the number of unique values per image per slide. You can then use .reset_index() on this series to c...
2
2016-06-14T01:40:56Z
[ "python", "pandas", "group-by" ]
Python/Pandas convert string to time only
37,801,321
<p>I have the following Pandas dataframe in Python 2.7.</p> <pre><code>import pandas as pd trial_num = [1,2,3,4,5] sail_rem_time = ['11:33:11','16:29:05','09:37:56','21:43:31','17:42:06'] dfc = pd.DataFrame(zip(*[trial_num,sail_rem_time]),columns=['Temp_Reading','Time_of_Sail']) print dfc </code></pre> <p>The datafra...
0
2016-06-14T00:51:59Z
37,801,617
<p>If you just want a simple conversion you can do the below:</p> <pre><code>import datetime as dt dfc.Time_of_Sail = dfc.Time_of_Sail.astype(dt.datetime) </code></pre> <p>or you could add a holder string to your time column as below, and then convert afterwards using an apply function:</p> <pre><code>dfc.Time_of_S...
0
2016-06-14T01:33:43Z
[ "python", "datetime", "pandas", "dataframe" ]
Python/Pandas convert string to time only
37,801,321
<p>I have the following Pandas dataframe in Python 2.7.</p> <pre><code>import pandas as pd trial_num = [1,2,3,4,5] sail_rem_time = ['11:33:11','16:29:05','09:37:56','21:43:31','17:42:06'] dfc = pd.DataFrame(zip(*[trial_num,sail_rem_time]),columns=['Temp_Reading','Time_of_Sail']) print dfc </code></pre> <p>The datafra...
0
2016-06-14T00:51:59Z
37,802,012
<p>These two lines:</p> <pre><code>dfc['Time_of_Sail'] = pd.to_datetime(dfc['Time_of_Sail']) dfc['Time_of_Sail'] = [time.time() for time in dfc['Time_of_Sail']] </code></pre> <p>Can be written as: </p> <pre><code>dfc['Time_of_Sail'] = pd.to_datetime(dfc['Time_of_Sail'],format= '%H:%M:%S' ).dt.time </code></pre>
2
2016-06-14T02:24:40Z
[ "python", "datetime", "pandas", "dataframe" ]
Changing the number of tick marks using locator params in matplotlib
37,801,424
<p>I'm trying to control the number of tick marks on my graphs using locator params. I want a graph that has five vertical lines plus the two edges of the graphs (ie 7 values total on the x and y axes). </p> <p>I've been using locator params and trying to set nbins = 7, but that doesn't work. Unless I use extreme valu...
4
2016-06-14T01:06:07Z
39,255,383
<p>If anyone is interested in knowing the answer, I figured out a way that works. using <code>np.lispace</code> creates the right number of bins. I used </p> <pre><code>ax6.set_yticks(np.linspace(0,1,7)) </code></pre>
0
2016-08-31T17:13:52Z
[ "python", "matplotlib", "axes" ]
Python: If element not in list, add to new list
37,801,451
<p>I have an ugly looking function and figured there must be a more Pythonic way of doing this (the capital letter variables are strings):</p> <pre><code>def get_missing_header_fields(header): missing_fields = [] if FIRST_NAME not in header: missing_fields.append(FIRST_NAME) if LAST_NAME not in hea...
0
2016-06-14T01:10:02Z
37,801,484
<p>Just use a comprehension</p> <pre><code>def get_missing_header_fields(header): # Completing the tuple is an exercise for the reader fields = (FIRST_NAME, LAST_NAME, ..., TITLE) return [field for field in fields if field not in header] </code></pre> <p>or even a set</p> <pre><code>def get_missing_heade...
3
2016-06-14T01:14:45Z
[ "python" ]
Python: If element not in list, add to new list
37,801,451
<p>I have an ugly looking function and figured there must be a more Pythonic way of doing this (the capital letter variables are strings):</p> <pre><code>def get_missing_header_fields(header): missing_fields = [] if FIRST_NAME not in header: missing_fields.append(FIRST_NAME) if LAST_NAME not in hea...
0
2016-06-14T01:10:02Z
37,801,485
<p>You can use sets for this:</p> <pre><code>FIELDS = set([FIRST_NAME, LAST_NAME, EMAIL, etc...]) def get_missing_header_fields(header): return FIELDS.difference(header) </code></pre> <p>Sets are <code>iterables</code> and support membership tests which is usually sufficient for most usecases. If you really need a...
4
2016-06-14T01:14:45Z
[ "python" ]
Metric Conversion calc error
37,801,458
<p>Here is my code for my python tkinter metric conversion calculator. I have an issue when trying to convert the data when it runs in length. The error is unhashable. Any help is greatly appreciated :) and suggestions will be taken fully into account. I believe the error is in the Logic class, just don't know exactly ...
1
2016-06-14T01:11:01Z
37,805,888
<p>Take a look at these lines:</p> <pre><code>m = v * metre_dict[self.measurements] k = m / metre_dict[self.measurements1] </code></pre> <p><code>self.measurements</code> and <code>self.measurements1</code> are StringVars. In order to get their string value you need to call <code>get()</code> method:</p> <pre><code>...
0
2016-06-14T07:41:57Z
[ "python", "user-interface", "tkinter", "metric" ]
How to divide one existing model on django in two or more
37,801,467
<p>first of all sorry for my bad english.</p> <p>I have a problem, i get a django app to make some changes and one of the things i have to do is divide the models. Because some of the models in the app are tooooo big. But i can't loose the database and the info on it because some of the models have more than 2000 obje...
-1
2016-06-14T01:12:15Z
37,801,846
<p>You can do this by writing your <a href="https://docs.djangoproject.com/en/1.9/howto/writing-migrations/#migrations-that-add-unique-fields" rel="nofollow">own migrations</a>.</p> <p>step1: Create new models without deleting original models.</p> <p>step2: Then run makemigrations.</p> <pre><code>python manage.py ma...
2
2016-06-14T02:03:44Z
[ "python", "sql", "django", "models" ]
[Django][MultipleChoiceField] Passing checkboxes values to server
37,801,530
<p>could you let me know how to pass my checkbox values to server?<Br> <br> views.py<br></p> <pre><code>def viewtest(request): if request.method == "POST": form=testForm(request.POST) if(form.is_valid(): form.save() elif request.method == "GET": form=testForm() return re...
0
2016-06-14T01:20:51Z
37,824,520
<p>there was my silly stuff. because I've used getting POST data as request.POST['workday']. it was wrong. I SHOULD USE form.cleaned_data.get("workday"). that's for my solution. But don't know what is different yet.</p>
-1
2016-06-15T01:04:33Z
[ "python", "django", "forms", "checkbox", "multiplechoicefield" ]
How can I create repetitive form elements in a DRY way with Flask-WTForms?
37,801,634
<p>I have a WTForms form where I want the user to be able to upload up to 10 images, and also give the images captions and credits. Currently I declare all 10 sets of fields, but this seems redundant. Is there a way to create form fields with dynamic names, so I could create them in a loop?</p> <pre><code>class MyForm...
2
2016-06-14T01:35:30Z
37,803,520
<p>You can get what you're looking for by combining <a href="https://wtforms.readthedocs.io/en/latest/fields.html#wtforms.fields.FormField" rel="nofollow"><code>FormField</code></a> with <a href="https://wtforms.readthedocs.io/en/latest/fields.html#wtforms.fields.FieldList" rel="nofollow"><code>FieldList</code></a>:</p...
2
2016-06-14T05:20:50Z
[ "python", "flask", "wtforms", "flask-wtforms" ]
Getting TypeError: 'builtin_function_or_method' object is not subscriptable' while coding small program
37,801,668
<p>Hi i have only been coding for a short time and am trying to code a program that counts the vowels in a sentence and then returns that number to the user at the moment i am getting the error:</p> <p>TypeError: 'builtin_function_or_method' object is not subscriptable'</p> <pre><code>vowel = "aeiou" vcount = 0 index...
0
2016-06-14T01:40:09Z
37,801,853
<p>Over here:</p> <pre><code>sen = sen.lower </code></pre> <p>You set <code>sen</code> not to a lowercase version of the original string, but to the string method that accomplishes this. To actually run the method and return the lowercased string, you need to call it with <code>()</code>:</p> <pre><code>sen = sen.lo...
0
2016-06-14T02:04:31Z
[ "python" ]
Correctly managing postgresql connections in celery task for Flask-SQLAlchemy and Celery
37,801,766
<p>I'm using Flask-SQLAlchemy, Celery and uWSGI.</p> <p>I know that Flask-SQLAlchemy automatically manages the session for you. I'm not sure how this works with Celery workers, but it seems that when I run a task a second time, I get the following error: DatabaseError: (psycopg2.DatabaseError) server closed the connec...
0
2016-06-14T01:51:36Z
38,023,795
<p>Okay. I figured it out, for every process that's using an application context, you must use a new application context. Before, in my <code>app/__init__.py</code> I was simply creating the application globally like so:</p> <pre><code>from flask import Flask app = Flask(__name__) </code></pre> <p>I then changed my a...
0
2016-06-25T00:24:32Z
[ "python", "postgresql", "flask", "celery", "flask-sqlalchemy" ]
Using .loc with a column of values
37,801,768
<p>Suppose I have a slice of a column within a dataframe <code>df</code> where I want to replace float values with other float values. Only the values to replace are from another dataframe, `newdf.</p> <p>I've tried using</p> <p><code>df.loc[row index condition, [column to replace vals]] = newdf[column]</code></p> <...
0
2016-06-14T01:52:18Z
37,801,791
<p>The value from <code>newdf</code> need to align with the <code>index</code> of <code>df</code>. If <code>newdf</code> has the exact number of values you want to insert, you can try using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.values.html" rel="nofollow"><code>.values</code></...
2
2016-06-14T01:55:04Z
[ "python", "numpy", "pandas", "dataframe" ]
AttributeError: 'module' object has no attribute 'webdriver'
37,801,823
<blockquote> <p><strong>AttributeError</strong>: 'module' object has no attribute 'webdriver'</p> </blockquote> <p>why this error happen when write </p> <pre><code>import selenium </code></pre> <p>and when write code like this no error happen</p> <pre><code>from selenium import webdriver </code></pre>
0
2016-06-14T02:00:17Z
37,801,999
<p>You get an error because <code>webdriver</code> is a module inside the <code>selenium</code> module, and you can't access modules without an explicit import statement.</p> <p>If you take a look at <code>help(selenium)</code>, you'll see there are two modules and one non-module contained inside.</p> <pre><code>PACK...
0
2016-06-14T02:23:24Z
[ "python", "python-2.7", "selenium", "selenium-webdriver" ]
python3 tkinter gui not responding
37,801,847
<p>Hi I am new to programming and I apologize if this is an obvious mistake. I am writing a gui on tkinter using python 3.5 on Mac OsX El Capitan. Here is the code so far:</p> <pre><code>from tkinter import * from tkinter import ttk class GUI(object): def __init__(self, master): master.title("Title") ...
0
2016-06-14T02:03:48Z
37,802,103
<p>You should not use pack() and grid() as this will generate a geometry manager conflict as pointed out in this error:</p> <pre><code>_tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack </code></pre> <p>try changing:</p> <pre><code> self.frame1.pack() </code></pre> ...
3
2016-06-14T02:40:42Z
[ "python", "osx", "python-3.x", "user-interface", "tkinter" ]
python3 tkinter gui not responding
37,801,847
<p>Hi I am new to programming and I apologize if this is an obvious mistake. I am writing a gui on tkinter using python 3.5 on Mac OsX El Capitan. Here is the code so far:</p> <pre><code>from tkinter import * from tkinter import ttk class GUI(object): def __init__(self, master): master.title("Title") ...
0
2016-06-14T02:03:48Z
37,802,784
<p>The only problem with your code is that you forgot to <em>attach</em> the two labels to the the main widget <code>self.frame1</code>.</p> <p>To fix that, modify them as follow:</p> <pre><code>#Attach the 2 labels to self.frame1 ttk.Label(self.frame1,text="Organism").grid(row=1, column=0) ttk.Label(self.frame1,tex...
0
2016-06-14T04:05:37Z
[ "python", "osx", "python-3.x", "user-interface", "tkinter" ]
Why am I getting multiple outputs with this decorated function?
37,801,932
<p>I've recently made a move from C/C++ to Python. Having difficulties in understanding closures and decorators.</p> <p>Declared the functions as such (an online blog had this piece code as an example)</p> <pre><code>def outer(some_func): def inner(): print "Before Foo" ret = some_func() r...
0
2016-06-14T02:14:17Z
37,802,039
<p>Consider what <code>foo</code> refers to in each statement of <code>foo=outer(foo)</code>. Initially you define foo to be a function that always returns 1. Once you call <code>foo=outer(foo)</code> though, it now has a new value. Try to imagine replacing the foo on the right side of the assignment with what foo woul...
1
2016-06-14T02:28:54Z
[ "python", "python-decorators" ]
Why am I getting multiple outputs with this decorated function?
37,801,932
<p>I've recently made a move from C/C++ to Python. Having difficulties in understanding closures and decorators.</p> <p>Declared the functions as such (an online blog had this piece code as an example)</p> <pre><code>def outer(some_func): def inner(): print "Before Foo" ret = some_func() r...
0
2016-06-14T02:14:17Z
37,802,063
<p>You're decorating the decorated function again. <code>outer</code> takes in a function and returns closure which of course is function by itself. There's nothing preventing you to pass the returned function as a parameter to the following call like you're doing in your example.</p> <p>If you change your code to pri...
1
2016-06-14T02:31:52Z
[ "python", "python-decorators" ]
Why am I getting multiple outputs with this decorated function?
37,801,932
<p>I've recently made a move from C/C++ to Python. Having difficulties in understanding closures and decorators.</p> <p>Declared the functions as such (an online blog had this piece code as an example)</p> <pre><code>def outer(some_func): def inner(): print "Before Foo" ret = some_func() r...
0
2016-06-14T02:14:17Z
37,823,614
<p>question hoebenkr, I don't understand how when you're assigning the variable ret to the parameter of the function, you <strong>call</strong> the function. Is that the de-facto standard for declaring a variable to a function? It promptly runs in python?</p>
0
2016-06-14T23:13:29Z
[ "python", "python-decorators" ]
How do I deploy python/django which was created with virtualenvwrapper?
37,801,967
<p>I have learned the importance and value in using virtualenvwrapper and virtualenv on my development system. I have an Ubuntu 16 desktop that I use for development. Oh, btw, I don't want to use a PaaS like Heroku since I pay for VPS hosting already.</p> <p>With virtualenvwrapper I just use the command workon and ...
0
2016-06-14T02:18:47Z
37,802,026
<p>Read:</p> <ul> <li><a href="http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html" rel="nofollow">http://blog.dscpl.com.au/2014/09/using-python-virtual-environments-with.html</a></li> <li><a href="http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html" rel="nofollow">http://...
3
2016-06-14T02:26:36Z
[ "python", "django", "apache", "mod-wsgi", "vps" ]
Django rest framework: testing update action doesn't return 400 if request data is invalid
37,802,030
<p>I'm writing unit tests for a particular viewset, and am finding that the response isn't as expected. The <a href="http://www.django-rest-framework.org/api-guide/generic-views/#updatemodelmixin" rel="nofollow">docs</a> suggest that incorrect data will result in status code 400, but I get 200...</p> <pre><code> def t...
0
2016-06-14T02:26:59Z
37,827,123
<p>Serializers discard data from unknown or read-only fields. So both tests will return 400 and will end end being "{}" after validation.</p>
1
2016-06-15T05:52:37Z
[ "python", "django", "django-rest-framework" ]
Why does adding this __init__() method break my Django model?
37,802,041
<p>This question is a follow-up to one I asked earlier <a href="http://stackoverflow.com/questions/37782083/how-can-i-force-2-fields-in-a-django-model-to-share-the-same-default-value"><strong>here</strong></a>.</p> <p>I have a Django model as follows:</p> <pre><code>class MyModel(models.Model): my_field1 = models...
0
2016-06-14T02:29:04Z
37,802,102
<p>You don't need to use <code>__init__</code> in Django models, instead use <code>Meta</code> class </p> <pre><code>class MyModel(models.Model): my_field1 = models.DateTimeField(default=datetime.utcnow, editable=False) my_field2 = models.DateTimeField() class Meta: verbose_name = 'My Model' ...
0
2016-06-14T02:40:20Z
[ "python", "django", "constructor" ]
Why does adding this __init__() method break my Django model?
37,802,041
<p>This question is a follow-up to one I asked earlier <a href="http://stackoverflow.com/questions/37782083/how-can-i-force-2-fields-in-a-django-model-to-share-the-same-default-value"><strong>here</strong></a>.</p> <p>I have a Django model as follows:</p> <pre><code>class MyModel(models.Model): my_field1 = models...
0
2016-06-14T02:29:04Z
37,802,435
<p>Using <strong>init</strong> is discouraged. According to Django docs:</p> <p><a href="https://docs.djangoproject.com/en/1.9/ref/models/instances/#creating-objects" rel="nofollow">https://docs.djangoproject.com/en/1.9/ref/models/instances/#creating-objects</a></p> <pre><code>from django.db import models class Book...
0
2016-06-14T03:23:33Z
[ "python", "django", "constructor" ]
Why does adding this __init__() method break my Django model?
37,802,041
<p>This question is a follow-up to one I asked earlier <a href="http://stackoverflow.com/questions/37782083/how-can-i-force-2-fields-in-a-django-model-to-share-the-same-default-value"><strong>here</strong></a>.</p> <p>I have a Django model as follows:</p> <pre><code>class MyModel(models.Model): my_field1 = models...
0
2016-06-14T02:29:04Z
37,803,967
<p>Although, you're strongly advised to use a <code>classmethod</code> or a custom manager in the docs, your code would not work because you have modified the calling signature of the <code>superclass</code>, which should have been:</p> <pre><code>super(MyModel, self).__init__(*args, **kwargs) </code></pre> <p>You ca...
1
2016-06-14T05:56:46Z
[ "python", "django", "constructor" ]
Raspberry pi serial communication-python write command issue
37,802,078
<p>I use PC to control extral device, and this device is serial port communicate with PC, and it works good. I can send the commands to device from PC to device. The belwo is command structure.Python versio is 2.7.</p> <pre><code>Initialize=[0xEE,0x01,0x01] ser.write(Initialize) </code></pre> <p>Now, I use the raspb...
1
2016-06-14T02:33:55Z
37,815,178
<p>Thanks for your answer. It works now. The belwo is correct command.</p> <pre><code>x=bytearray(Initialize) ser.write(x) </code></pre>
0
2016-06-14T14:41:14Z
[ "python", "serial-port", "raspberry-pi" ]
Setting up a local server using a domain socket with python?
37,802,093
<p>I would like to set up a server on my computer and have another process on my computer connect to the server using a domain socket. I've looked at various python guides but I can't seem to find a straight answer! Here's my code this far.</p> <p>Client:</p> <pre><code>import socket; s = socket.socket(socket.AF_UNIX...
0
2016-06-14T02:37:45Z
37,803,200
<p>To answer the question you ask about the error you're getting, the <a href="https://docs.python.org/2/library/socket.html" rel="nofollow">documentation</a> says:</p> <blockquote> <p>A single string is used for the AF_UNIX address family. A pair (host, port) is used for the AF_INET address family</p> </blockquote>...
3
2016-06-14T04:48:33Z
[ "python", "sockets" ]
How to know if a git hook is being called from not within the terminal/command line
37,802,305
<p>I have a git hook that is running whenever some one commits to their local repository.</p> <p>Some people are committing from the terminal and some people are committing from SourceTree or SmartGit or some other 3rd party application.</p> <p>SourceTree behaves differently when it comes to hooks. For example, error...
9
2016-06-14T03:07:35Z
37,913,001
<p>I was able to solve the problem using this python code. It simply checks the environment variables for any occurrences of third party git clients. I don't know if it's the best solution or if it will work all the time - but it meets my needs for now.</p> <pre><code>is_terminal = True for key in os.environ: if ...
5
2016-06-19T23:50:22Z
[ "python", "git", "githooks", "atlassian-sourcetree" ]
Using a function to do a %change on a dataset
37,802,466
<p>I am on python using pandas but running into this issue. I am having a dataset that has the countries on the columns and dates(my months) on the rows. The data consists of the population of an item.</p> <p>I am required to calculate the % change of population month by month is there a function that I can use to get...
0
2016-06-14T03:27:35Z
37,802,632
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pct_change.html" rel="nofollow"><code>pct_change</code></a>:</p> <pre><code>df.pct_change() </code></pre>
1
2016-06-14T03:47:19Z
[ "python", "pandas" ]
Using a function to do a %change on a dataset
37,802,466
<p>I am on python using pandas but running into this issue. I am having a dataset that has the countries on the columns and dates(my months) on the rows. The data consists of the population of an item.</p> <p>I am required to calculate the % change of population month by month is there a function that I can use to get...
0
2016-06-14T03:27:35Z
37,802,633
<p>First order the data by month (if it isn't already), and then use the <code>.shift()</code> function for pandas dataframes</p> <pre><code>df['pct_change'] = (df.US - df.US.shift(1) ) / df.US </code></pre> <p><code>.shift()</code> allows you to shift rows up or down depending on the argument.</p>
0
2016-06-14T03:47:29Z
[ "python", "pandas" ]
Regex to match '#attribute value' or 'attribute value' of linux configuration files but not '# a comment'
37,802,570
<p>Linux has these configuration files like sshd_config:</p> <pre><code># Package generated configuration file # See the sshd_config(5) manpage for details # What ports, IPs and protocols we listen for #A b #Port 1234 # Use these options to restrict which interfaces/protocols sshd will bind to #ListenAddress :: #List...
0
2016-06-14T03:39:57Z
37,802,669
<p>You can use negative lookahead assertion:</p> <pre><code>re.findall('^(?!#\s).*', s, re.MULTILINE) </code></pre> <p>For input given int the question it will provide following output:</p> <pre><code>['', '#A b', '#Port 1234', '#ListenAddress ::', '#ListenAddress 0.0.0.0', 'Protocol 2', 'HostKey /etc/ssh/ssh_...
0
2016-06-14T03:52:28Z
[ "python", "regex", "linux" ]
efficient counting/sorting with lists and csv files
37,802,675
<p>I am trying to read a csv file and trying to write logic for printing out in the certain format. I have done it as below and i wish to ask you if I could have done it better. My logic below:</p> <pre><code>import csv, urllib2 url = 'http://winterolympicsmedals.com/medals.csv' ... for country in countryList: s...
1
2016-06-14T03:53:26Z
37,802,707
<p>You're using a list comprehension to append to another list. A list comprehension <em>produces</em> a list so you could replace:</p> <p><code>aList =[] [aList.append(tuple(row)) for row in cr]</code></p> <p>with</p> <p><code>aList = [tuple(row) for row in cr]</code></p>
1
2016-06-14T03:56:16Z
[ "python", "list" ]
efficient counting/sorting with lists and csv files
37,802,675
<p>I am trying to read a csv file and trying to write logic for printing out in the certain format. I have done it as below and i wish to ask you if I could have done it better. My logic below:</p> <pre><code>import csv, urllib2 url = 'http://winterolympicsmedals.com/medals.csv' ... for country in countryList: s...
1
2016-06-14T03:53:26Z
37,802,896
<p>This will give you a data-frame of the results you are looking for</p> <pre><code>import pandas as pd df = pd.read_csv('http://winterolympicsmedals.com/medals.csv') counts = df.groupby('NOC')['Medal'].value_counts().unstack() </code></pre> <p>Or if you only want to use the standard library:</p> <pre><code>import ...
0
2016-06-14T04:18:17Z
[ "python", "list" ]
efficient counting/sorting with lists and csv files
37,802,675
<p>I am trying to read a csv file and trying to write logic for printing out in the certain format. I have done it as below and i wish to ask you if I could have done it better. My logic below:</p> <pre><code>import csv, urllib2 url = 'http://winterolympicsmedals.com/medals.csv' ... for country in countryList: s...
1
2016-06-14T03:53:26Z
37,803,056
<p>You could consider using a Counter.</p> <pre><code>from collections import Counter, namedtuple ... Result = namedtuple('Result', ['country','medal']) aList = [Result(country=row[4],medal=row[7]) for row in cr] medal_counts = Counter(alist) </code></pre> <p>And then sort and print out the results however you desir...
2
2016-06-14T04:33:14Z
[ "python", "list" ]
import and read all files from a folder Python
37,802,712
<p>Hi everyone i am beginner with python and i have a problem with my code i would like to import and read all the .BVH file from a specific folder but the program takes only the first one from the folder.Here is my code.I use blender for visualization. </p> <pre><code>import bpy # This module gives access to blender ...
0
2016-06-14T03:56:50Z
37,802,795
<p>You're not using the actual file in the for loop. You're just using the same hardcoded path each time.</p> <p>Maybe you want something like the below?</p> <p>I renamed <code>files</code> to <code>file_path</code> to better represent what's in that variable. Then I used that value in the call to <code>import_anim.b...
2
2016-06-14T04:07:06Z
[ "python", "import", "blender" ]
import and read all files from a folder Python
37,802,712
<p>Hi everyone i am beginner with python and i have a problem with my code i would like to import and read all the .BVH file from a specific folder but the program takes only the first one from the folder.Here is my code.I use blender for visualization. </p> <pre><code>import bpy # This module gives access to blender ...
0
2016-06-14T03:56:50Z
37,802,842
<p>You are using <code>files</code> for both counting and holding the current file path in each iteration. And in the iteration you don't input the current file path to <code>import_anim</code>, you just used a hard coded file path. Also, <code>++</code> is not a valid syntax. </p> <pre><code>files = 0 for file_path ...
1
2016-06-14T04:12:47Z
[ "python", "import", "blender" ]
How to extract Regression predictor of Scikit-learn to implement into C++?
37,802,891
<p>I did some training using Random Forest Regression (or any kind of regressions) of Scikit-learn and got the predictor:</p> <pre><code>predictor = RandomForestRegressor(n_estimators=n_estimators) predictor.fit(X_train, Y_train) </code></pre> <p>How can I extract information in <code>predictor</code> to implement in...
0
2016-06-14T04:18:09Z
37,803,070
<p>The <a href="http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html" rel="nofollow">sklearn documentation for RFR</a> says that you have</p> <pre><code> property estimators_ : list of DecisionTreeRegressor </code></pre> <p>From <a href="http://scikit-learn.org/stable/modules/g...
0
2016-06-14T04:34:59Z
[ "python", "c++", "scikit-learn", "regression", "random-forest" ]
How to implement the state value function?
37,803,003
<p>I'm watching the Berkely CS 294 course about Deep Reinforcement Learning. However, I meet some troubles on the assignment. I tried to implement the equation below. I think it is quite simple but I failed to obtain the expected result as showed in the comments. There must be something that I misunderstood. Details ar...
1
2016-06-14T04:27:33Z
37,824,823
<p>Actually, the assignment 2 provided the solution, if someone else is learning this course online and meet some troubles, try to find some tips from the next assignment.</p>
0
2016-06-15T01:50:46Z
[ "python", "reinforcement-learning" ]
kivy windows package spec with kv file and back ground image
37,803,035
<p>I converted the kivy application to stand alone application by referring the official documentation and some external source.</p> <p>This is my spec file</p> <pre><code># -*- mode: python -*- from kivy.deps import sdl2, glew block_cipher = None a = Analysis(['..\\WordCalc\\main.py'], pathex=['E:\\p...
0
2016-06-14T04:31:05Z
37,823,257
<p>Open the folder in dist and check if you have the images available. If the images are present, your path to them is bad(absolute maybe?).</p> <p>If they are not present, your <code>Tree</code> might be a problem, but not necessarily. If you use images from outside of <code>main.py</code> folder, you need to add the...
1
2016-06-14T22:37:28Z
[ "python", "windows", "package", "kivy" ]
Remove non-business days rows from pandas dataframe
37,803,040
<p>I have a dataframe with second timeseries data of wheat in <code>df</code>.</p> <pre><code>df = wt["WHEAT_USD"] 2016-05-02 02:00:00+02:00 4.780 2016-05-02 02:01:00+02:00 4.777 2016-05-02 02:02:00+02:00 4.780 2016-05-02 02:03:00+02:00 4.780 2016-05-02 02:04:00+02:00 4.780 Name: closeAsk, dtype: float...
2
2016-06-14T04:31:50Z
37,803,222
<p>One simple solution is to slice out the days not in Monday to Friday:</p> <pre><code>In [11]: s[s.index.dayofweek &lt; 5] Out[11]: 2016-05-02 00:00:00 4.780 2016-05-02 00:01:00 4.777 2016-05-02 00:02:00 4.780 2016-05-02 00:03:00 4.780 2016-05-02 00:04:00 4.780 Name: closeAsk, dtype: float64 </code></...
1
2016-06-14T04:50:59Z
[ "python", "pandas" ]
How to write maximum value of tree view in odoo?
37,803,100
<p>I have one tree view have 3 columns . I wanted to get maximum of each column in function field ?</p> <pre><code>class feeder_data(osv.Model): _name = "feeder.data" _rec_name= "company_id1" _columns = { 'company_id1': fields.many2one('res.company', 'Substation', required=True), 'combine2'...
1
2016-06-14T04:37:39Z
37,804,235
<p>Use Built in Max function.</p> <p>Help on built-in function max in module <strong>builtin</strong>:</p> <pre><code>max(...) max(iterable[, key=func]) -&gt; value max(a, b, c, ...[, key=func]) -&gt; value With a single iterable argument, return its largest item. With two or more arguments, return t...
-1
2016-06-14T06:14:46Z
[ "python", "xml", "openerp" ]
How to write maximum value of tree view in odoo?
37,803,100
<p>I have one tree view have 3 columns . I wanted to get maximum of each column in function field ?</p> <pre><code>class feeder_data(osv.Model): _name = "feeder.data" _rec_name= "company_id1" _columns = { 'company_id1': fields.many2one('res.company', 'Substation', required=True), 'combine2'...
1
2016-06-14T04:37:39Z
37,804,723
<p>First, create the max function in your model:</p> <pre><code>def _get_max_of_tree(self,cr,uid,ids,context=None): res={} for o in self.browse(cr, uid, ids, context): res[o.id] = max(0.col1 , o.col2, o.col3) return res </code></pre> <p>then create a function field for it</p> <pre><code>_columns ...
2
2016-06-14T06:42:35Z
[ "python", "xml", "openerp" ]
Control QLoggingCategory in PyQt 5.6
37,803,152
<p>Some log output from Qt is controlled by <a href="http://doc.qt.io/qt-5/qloggingcategory.html" rel="nofollow">the category logging</a> (eg. The JavaScript console output on <code>QWebEnginePage</code>).</p> <p>The <code>QLoggingCategory</code> in C++ can be used for that, but there isn't the same class in PyQt5.</p...
1
2016-06-14T04:43:02Z
37,903,256
<p>Not a straight solution, but you can create something like this:</p> <pre><code>class MyPage (QtWebEngineWidgets.QWebEnginePage): def javaScriptConsoleMessage(self, level, message, lineNumber, sourceId): #Send the log entry to Python's logging or do whatever you want logging.info("level: {}, sou...
0
2016-06-19T01:52:51Z
[ "python", "qt", "pyqt", "pyqt5", "qt5.6" ]
python urllib.request - headers that are likely to work
37,803,365
<p>Working on a little script to fetch info from websites. I'm having trouble with HTTP errors.</p> <pre><code>req = urllib.request.Request(lnk['href'], headers={'User-Agent': 'Mozilla/5.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}) page = urllib.request.urlopen(req) </code></pre...
0
2016-06-14T05:07:27Z
37,803,474
<p>The following set of headers seems to be working for most tested. If anyone else has suggestions, please offer them. I'm also interested in good solutions for trying different headers if one set doesn't work.</p> <pre><code>req = urllib.request.Request(lnk['href'], headers={'User-Agent': 'Mozilla/5.0 (Macintosh;...
0
2016-06-14T05:17:09Z
[ "python", "web-scraping", "http-headers", "urllib" ]
python urllib.request - headers that are likely to work
37,803,365
<p>Working on a little script to fetch info from websites. I'm having trouble with HTTP errors.</p> <pre><code>req = urllib.request.Request(lnk['href'], headers={'User-Agent': 'Mozilla/5.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}) page = urllib.request.urlopen(req) </code></pre...
0
2016-06-14T05:07:27Z
37,803,481
<p>I tried your code and I get the same error like expected.</p> <p>I also tried it with the User-Agent my Chrome-Browser provides, this seems to work</p> <pre><code>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36 </code></pre> <p>.. and also run a test wi...
0
2016-06-14T05:17:29Z
[ "python", "web-scraping", "http-headers", "urllib" ]
Django 1.9.7 in VS2015 Django Shell django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet
37,803,418
<p>I'm a newcomer to Django. I was following a tutorial from MVA and i got stuck on one module where Django Shell was to be used to import a table(class) from the models.py file and use queries on it. When i try to import the table using the code</p> <pre><code> from app.models import Artist </code></pre> <p>It re...
0
2016-06-14T05:12:09Z
37,913,622
<p>The solution posted by dmitryro worked for me using the Django Management Console in VisualStudio Running Python 3.4.4 and Django 1.9.7</p> <blockquote> <blockquote> <p>import django django.setup()</p> </blockquote> </blockquote>
0
2016-06-20T01:43:29Z
[ "python", "django", "python-3.x", "visual-studio-2015", "django-1.9" ]
Held out training and validation set in gridsearchcv sklearn
37,803,463
<p>I see that in gridsearchcv best parameters are determined based on <code>cross-validation</code>, but what I really want to do is to determine the best parameters based on <code>one held out validation set</code> instead of <code>cross validation</code>. </p> <p>Not sure if there is a way to do that. I found some s...
0
2016-06-14T05:16:07Z
37,903,972
<p>I did come up with an answer to my own question through the use of PredefinedSplit</p> <pre><code>for i in range(len(doc_train)-1): train_ind[i] = -1 for i in range(len(doc_val)-1): val_ind[i] = 0 ps = PredefinedSplit(test_fold=np.concatenate((train_ind,val_ind))) </code></pre> <p>and then in the gridsea...
0
2016-06-19T04:33:10Z
[ "python", "text", "parameters", "scikit-learn", "classification" ]
Manage Multiple Threads in Python
37,803,493
<p>Function gen() generates a string, which is a command to be passed into os.system().</p> <p>I need to start 20 threads at the same time, call gen() for each thread, and run the command gen() gives me in each thread. (parallel)</p> <p>Once a command finishes executing in a thread, I want to call gen() again to gene...
0
2016-06-14T05:18:15Z
37,803,536
<p>Take a look at <a href="https://pymotw.com/2/threading/" rel="nofollow">this</a>, hope this helps.</p> <p>Its actually not that hard</p> <p>but keep in mind when working with threads which use the same variable to use <a href="http://effbot.org/zone/thread-synchronization.htm#locks" rel="nofollow">locks</a>!</p>
1
2016-06-14T05:22:17Z
[ "python", "multithreading", "operating-system" ]
collections deque constructor
37,803,574
<p>Can you explain the this constructor of deque:</p> <pre><code>import collections buff = collections.deque([], 100) </code></pre> <p>I saw it's documentation but couldn't find this form being used anywhere.</p>
0
2016-06-14T05:25:19Z
37,803,695
<blockquote> <p>class collections.deque([iterable[, maxlen]])</p> <p>Returns a new deque object initialized left-to-right (using append()) with data from iterable. If iterable is not specified, the new deque is empty.</p> </blockquote> <p>In your example , <code>buff = collections.deque([], 100)</code>,</p>...
1
2016-06-14T05:34:49Z
[ "python", "collections", "deque" ]
Tensorflow cnn error: logits and labels must be same size:
37,803,628
<p>I'm trying to create a CNN using Tensorflow that classifies images into <strong>16 classes</strong>. </p> <p>My original image size is 72x72x1, and my network is structured like this:</p> <pre><code># Network n_input = dim n_output = nclass # 16 weights = { 'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32...
0
2016-06-14T05:29:22Z
37,805,770
<p>Its hard to tell from what you provided, but it seems like you feed inputs with a batch size of 6, but only provide one label for them. Where does your data come from?</p>
0
2016-06-14T07:36:10Z
[ "python", "neural-network", "tensorflow", "conv-neural-network" ]
Tensorflow cnn error: logits and labels must be same size:
37,803,628
<p>I'm trying to create a CNN using Tensorflow that classifies images into <strong>16 classes</strong>. </p> <p>My original image size is 72x72x1, and my network is structured like this:</p> <pre><code># Network n_input = dim n_output = nclass # 16 weights = { 'wc1': tf.Variable(tf.random_normal([5, 5, 1, 32...
0
2016-06-14T05:29:22Z
37,806,158
<p>Given your code (and guessing what is missing in it), I think you have these parameters and results (correct me if wrong):</p> <ul> <li><code>batch_size</code>: 1</li> <li><code>num_classes</code>: 16</li> <li>labels <code>y</code>: type int, shape <code>[batch_size, 1]</code></li> <li>outputs <code>_pred</code>: t...
1
2016-06-14T07:56:24Z
[ "python", "neural-network", "tensorflow", "conv-neural-network" ]
How to write equals method
37,803,637
<p>Situation: I'm trying to get a good handle on the doubly-linked structure. I've got a decent grip on the methods so far. I want to be able to create two objects for this class and check if every item in it is equal. I don't have any syntax errors, and the error I'm getting is kind of confusing. So here's what I have...
1
2016-06-14T05:30:24Z
37,803,811
<p><code>zip(self.other)</code> only gives you as many elements as the shorter of the two lists. It discards the extra part of the longer list. So for <code>[] == [100]</code>, <code>zip</code> doesn't give any elements, and your code returns True without checking anything.</p> <p>You could just do a check at the be...
0
2016-06-14T05:44:33Z
[ "python", "linked-list" ]
How to write equals method
37,803,637
<p>Situation: I'm trying to get a good handle on the doubly-linked structure. I've got a decent grip on the methods so far. I want to be able to create two objects for this class and check if every item in it is equal. I don't have any syntax errors, and the error I'm getting is kind of confusing. So here's what I have...
1
2016-06-14T05:30:24Z
37,803,821
<p><code>zip</code> only goes as far as the shortest list. You want <code>itertools.zip_longest</code>, and you don't want <code>.val</code> (your iterator returns the actual values already). Try this:</p> <pre><code>def __eq__(self, other): for val1, val2 in zip_longest(self, other): if val1 != val2: ...
2
2016-06-14T05:45:24Z
[ "python", "linked-list" ]
Accessing all the elments of a specific key in list of dictionary python
37,803,723
<p>I have a dictionary like this.</p> <pre><code>data1 = {"00:08:22:24:f8:02": {"cities" : [ {'name': 'Bhubaneswar', 'count': 12, 'date':14/05/2016}, {'name': 'Kolkata', 'count': 4, 'date': 15/05/2016}, {'name': 'Mumbai', 'count': 6, 'date' : 1...
2
2016-06-14T05:36:55Z
37,804,477
<p>Because I don't know the exact format that you wanted to achieve I had to make some fairly pronounced guess work. I hope this helps in anyway. Good luck</p> <pre><code>import datetime data1 = {"00:08:22:24:f8:02": {"cities" : [{'name': 'Bhubanesw...
0
2016-06-14T06:28:23Z
[ "python", "dictionary" ]
AttributeError, 'dict' object has no attribute 'iteritems'; Flask-SQLAlchemy error while committing to database
37,803,745
<p>I've been trying to get this to run for a while but seemingly to no avail. I have a webapp that requests the user input data, which is then committed to the db. When I hit add through the browser, the data is passed to the db however Werkzeug spits a number of errors back, which I've detailed below in the trace.</p>...
1
2016-06-14T05:39:05Z
37,803,859
<p>In Python3 <code>dict.items()</code> does the same thing that <code>dict.iteritems()</code> did in Python2. Just replace <code>iteritems()</code> with <code>items()</code>!</p>
0
2016-06-14T05:49:05Z
[ "python", "flask" ]
Django SItemap Index NoReverseMatch at /sitemap.xml
37,803,947
<p>I'm trying to implement Sitemap Index but I'm getting the below error on sitemap.xml. sitemap-posts.xml and sitemap-categories.xml works fine.</p> <p><strong>Error</strong></p> <pre><code>NoReverseMatch at /sitemap.xml Reverse for 'django.contrib.sitemaps.views.sitemap' with arguments '()' and keyword arguments '...
0
2016-06-14T05:54:59Z
37,811,558
<p>Change name from 'django.contrib.sitemaps.views.sitemap1' to 'sitemaps'. Apparently it uses that name for resolution. </p> <pre><code>name='django.contrib.sitemaps.views.sitemap1' </code></pre> <p>My urls look exactly like this and it works right, when I changed the name, I got an error close to yours.</p> <pre><...
0
2016-06-14T12:06:45Z
[ "python", "django" ]
Python csv column names from rows and assign to columns
37,804,006
<p>I bet there is a simple way to do this but I can't figure it out. I have a series of data from various races. The problem is that all the data is combined and there are different lap distances and times. What I'd like to do is dynamically input data into columns for each race. Here's how gross the data can be</p> <...
-1
2016-06-14T05:58:58Z
37,804,595
<p>A working solution below. A couple notes:</p> <ol> <li>I used <a href="http://docs.python-tablib.org/en/latest/" rel="nofollow">tablib</a>, my favorite library for things like CSV manipulation, and <a href="https://github.com/SethMMorton/natsort" rel="nofollow">natsort</a> to sort the columns ("300m" &lt; "2000m")....
0
2016-06-14T06:34:47Z
[ "python", "csv", "pandas" ]
Python csv column names from rows and assign to columns
37,804,006
<p>I bet there is a simple way to do this but I can't figure it out. I have a series of data from various races. The problem is that all the data is combined and there are different lap distances and times. What I'd like to do is dynamically input data into columns for each race. Here's how gross the data can be</p> <...
-1
2016-06-14T05:58:58Z
37,806,080
<p>While off the internet I also took a stab a the specification that "sat in the question" ;-)</p> <pre><code>#! /usr/bin/env python """Learn by example - grass roots parser for kind of serialized race reports, where records are separated by a pipe (|), fields of result records separated y a dash (-) and some meaning...
0
2016-06-14T07:51:41Z
[ "python", "csv", "pandas" ]
pandas and resample compared to the len of another dataframe
37,804,096
<p>I have two dataframes that stretches over the same period</p> <pre><code>"2016-05-13" to "2016-05-19" </code></pre> <p><code>dfone</code> and <code>dftwo</code></p> <p><code>dfone</code> length is <code>29542</code> <code>dftwo</code> length is <code>11637</code></p> <p>I'd like to makeout the corrcoef, but I ne...
0
2016-06-14T06:05:18Z
37,804,699
<p>I think you can first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.resample.html" rel="nofollow"><code>resample</code></a> by <code>minutes</code> (because no seconds in sample) and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.join.html" rel=...
0
2016-06-14T06:40:54Z
[ "python", "pandas" ]
PyEZ: 'EntryPoint' object has no attribute 'resolve'
37,804,107
<p>PyEZ user are facing issue with respect to subject line error</p> <pre><code>from jnpr.junos import Device &gt;&gt;&gt; dev = Device(host='xxx',user='xxxx',passwd='xxx') &gt;&gt;&gt; dev.open() No handlers could be found for logger "ncclient.transport.ssh" Traceback (most recent call last): File "&lt;stdin&gt;", ...
1
2016-06-14T06:05:58Z
37,804,221
<p>Install cryptography 1.2.1 using below command</p> <pre><code>sudo pip install cryptography==1.2.1 </code></pre> <p>or upgrade distribute</p> <pre><code>sudo pip install -U distribute </code></pre> <p>Ref:</p> <p><a href="https://github.com/mozilla/sops/issues/67">https://github.com/mozilla/sops/issues/67</a></...
5
2016-06-14T06:13:42Z
[ "python", "pyez" ]
PyEZ: 'EntryPoint' object has no attribute 'resolve'
37,804,107
<p>PyEZ user are facing issue with respect to subject line error</p> <pre><code>from jnpr.junos import Device &gt;&gt;&gt; dev = Device(host='xxx',user='xxxx',passwd='xxx') &gt;&gt;&gt; dev.open() No handlers could be found for logger "ncclient.transport.ssh" Traceback (most recent call last): File "&lt;stdin&gt;", ...
1
2016-06-14T06:05:58Z
37,851,377
<p>The "python-pip" package installs an old version of distribute/setuptools that is incompatible with versions of cryptography >= 1.3.</p> <p>The cryptography library specifies a dependency on setuptools >= 11.3: <a href="https://github.com/pyca/cryptography/blob/master/setup.py#L40" rel="nofollow">https://github.com...
2
2016-06-16T06:24:44Z
[ "python", "pyez" ]
Python RegExp, get group without certan word
37,804,175
<p>I have text like:</p> <pre><code>qwerqwer asdf foo bar %abc anchor one %abc anchor one thow foo bar %abc anchor one two three %abc anchor </code></pre> <p>Now I have regexp <code>(.+)\n\%\w+\sanchor</code>, but it gives me <code>('qwerqwer asdf foo bar', 'one thow foo bar', 'one', 'one two three')</code> I want...
0
2016-06-14T06:10:37Z
37,804,270
<pre><code>(.+?)(?: foo bar)?\n\%\w+\sanchor </code></pre> <p>You need to use reluctant modifier (<code>+?</code>) so it won't eat <code>foo bar</code> and also add a optional <code>foo bar</code> at the end of line</p> <p><a href="https://regex101.com/r/fU2jA5/1" rel="nofollow">https://regex101.com/r/fU2jA5/1</a></p...
0
2016-06-14T06:17:17Z
[ "python", "regex" ]
How can we use tqdm in a parallel execution with joblib?
37,804,279
<p>I want to run a function in parallel, and wait until all parallel nodes are done, using joblib. Like in the example:</p> <pre><code>from math import sqrt from joblib import Parallel, delayed Parallel(n_jobs=2)(delayed(sqrt)(i ** 2) for i in range(10)) </code></pre> <p>But, I want that the execution will be seen in...
0
2016-06-14T06:17:42Z
37,822,544
<p>If your problem consists of many parts, you could split the parts into <code>k</code> subgroups, run each subgroup in parallel and update the progressbar in between, resulting in <code>k</code> updates of the progress.</p> <p>This is demonstrated in the following example from the documentation.</p> <pre><code>&gt;...
2
2016-06-14T21:37:06Z
[ "python", "parallel-processing", "joblib", "tqdm" ]
Custom "contains" method for list
37,804,280
<p>I'd like to get a better handle on the doubly-linked structure. The goal in this scenario is to append a range of values to the end of a list. I then would like to test for a value I know should be in the list, this should return true, and vice versa for a value that I know shouldn't be in the list. So here's what I...
0
2016-06-14T06:17:47Z
37,804,417
<p>Your implementation is wrong. Your <code>__contains__</code> function only returns true if <strong>all</strong> values in your linked list are equal to a given test value. I.e. it'd only be true if all values in your linked list are equal to one another <em>as well</em>:</p> <pre><code>&gt;&gt;&gt; value = 'foo' &g...
2
2016-06-14T06:25:33Z
[ "python", "doubly-linked-list" ]
twitter crawling hashtag with api for using python
37,804,307
<p>i want to crawling 10000 tweet in twitter, contain particular word with hashtag.</p> <p>for example, contain hashtag, #love like this.</p> <p>and crawl all hashtag in tweet.</p> <p>for example, one tweet exist like this.</p> <p>[i am sleepy #boring #tired #sleep]</p> <p>and i want to crawl data, and see result ...
0
2016-06-14T06:19:00Z
37,804,408
<p>As it seems you are using Python 3.0+ and so you can't use <code>print "Hello world"</code>, you need to use <code>print("Hello world")</code> so just change your print calls to have parentheses. </p>
1
2016-06-14T06:25:07Z
[ "python", "twitter", "tweepy", "hashtag" ]
Reading integer from arduino using pyserial
37,804,315
<p>I am sending integer value from arduino and reading it in Python using pyserial The arduino code is:</p> <pre><code>Serial.write(integer) </code></pre> <p>And the pyserial is:</p> <pre><code>ser=serial.Serial ('com3',9600,timeout =1) X=ser.read(1) print(X) </code></pre> <p>But it doesn't print anything except b...
0
2016-06-14T06:19:36Z
37,804,700
<p>You probably need to use a start bit.</p> <p>The problem might be that the arduino has already written the integer by the time pyserial is running?</p> <p>So write a character from pyserial to arduino to signal start like </p> <pre><code> ser=serial.Serial ('com3',9600,timeout =1) ser.write(b'S') X=ser...
0
2016-06-14T06:40:56Z
[ "python", "arduino", "pyserial" ]
Reading integer from arduino using pyserial
37,804,315
<p>I am sending integer value from arduino and reading it in Python using pyserial The arduino code is:</p> <pre><code>Serial.write(integer) </code></pre> <p>And the pyserial is:</p> <pre><code>ser=serial.Serial ('com3',9600,timeout =1) X=ser.read(1) print(X) </code></pre> <p>But it doesn't print anything except b...
0
2016-06-14T06:19:36Z
37,805,569
<p>That is the not the right way to read an <code>Integer</code> from Arduino. <code>Integer</code> is a 32-bit type while your serial port would be set to <strong>EIGHTBITS</strong> <em>(Both in pyserial and Arduino. Correct me if I'm wrong)</em> in byte size, therefore you have to write the <code>Character</code> ver...
0
2016-06-14T07:27:19Z
[ "python", "arduino", "pyserial" ]
Error while running MRJOB on AWS
37,804,327
<p>I put the mrjob.conf file in /home directory and tried to run the job from command and I am getting this error:</p> <blockquote> <p>File "/Users/bimalthapa/anaconda/lib/python2.7/site-packages/mrjob-0.4.6- py2.7.egg/mrjob/conf.py", line 283, in conf_object_at_path with open(conf_path) as f: IOError: [Err...
0
2016-06-14T06:20:49Z
38,152,994
<p>python mr_statistics.py -r emr s3://bimalucmbucket/inputFile.txt --output-dir=s3://bimalucmbucket/output --no-output -c ~/mrjob.conf</p>
0
2016-07-01T19:48:27Z
[ "python", "amazon-web-services", "bigdata", "mrjob" ]
Python matplotlib logarithmic autoscale
37,804,331
<p>I need to get a x,y plot with a logarithmic scale on the x-axes. When I zoom in the x-axes should autoscale as the (not logarithmic) y-axes.</p> <pre><code>plt.xscale('log') plt.grid(True) plt.autoscale(True,True,True) plt.legend(loc='best') plt.show() </code></pre> <p><a href="http://i.stack.imgur.com/pWSZm.png" ...
0
2016-06-14T06:20:55Z
37,804,470
<p>If you look at the documentation the function is like- </p> <pre><code>matplotlib.pyplot.autoscale(enable=True, axis='both', tight=None) </code></pre> <p>What you are sending is an invalid argument...</p> <p>just make it </p> <pre><code>plt.autoscale(True, axis = 'both') </code></pre> <p>And about tight - </p> ...
1
2016-06-14T06:28:04Z
[ "python", "matplotlib" ]
how to find k in k-means when there is a mix of categorical and numerical data?
37,804,531
<p>I am using a variation of k-means called k-prototype clustering as implemented in the kmodes package, which works when there is a mixture of categorical and numerical data.</p> <p><a href="https://github.com/nicodv/kmodes" rel="nofollow">https://github.com/nicodv/kmodes</a></p> <p>How do I find the appropriate num...
-1
2016-06-14T06:31:27Z
37,804,988
<p>Appropriate number of clusters in kmodes can be found in the same manner as in KMeans. The techniques of <a href="http://scikit-learn.org/stable/modules/clustering.html#silhouette-coefficient" rel="nofollow">Silhouette Coefficient</a> can be used for kmodes. But the <code>metric</code> should not be used as <code>eu...
1
2016-06-14T06:58:06Z
[ "python", "python-2.7", "machine-learning", "cluster-analysis", "k-means" ]
Showing data in Bootstrap list-group in Django template
37,804,535
<p>I have data of cars and I want them to be shown in Bootstraps list-group. Problem is that I want one car brand to be shown <strong>only once.</strong></p> <pre><code>{u'cars': [{u'brand': u'Ford', u'model': u'Focus'}, {u'brand': u'u'Ford', u'model': u'Fiesta'}, {u'brand': u'u'Toyota', u'model': u'Hilux'}] </code></...
0
2016-06-14T06:31:51Z
37,805,507
<p>I would do something like this to clean up the data in your view:</p> <pre><code>cars_seen = set() for i in readable_json["cars"]: car_identifier = '{}-{}'.format(i['brand'], i['model']) if not car_identifier in cars_seen: cars.append({ 'brand': i['brand'], 'model': i['model'...
0
2016-06-14T07:23:26Z
[ "python", "django", "twitter-bootstrap", "django-templates" ]
How to send automatic email notification by checking with date in odoo
37,804,566
<p>I have a calendar module there I have fields like <code>start date</code> and <code>end date</code>. I want to sent an email if the current date is more that end date of calendar to attendees of calendar module i.e calendar.event. Any ideas how this can be done? </p>
-1
2016-06-14T06:33:25Z
37,810,984
<p>yes, you can do this via automatic action by install base_action_rule module.</p> <p>after installed that, you can create a a</p>
0
2016-06-14T11:40:45Z
[ "python", "xml", "openerp" ]
Is it possible to connect to signals in a Gtk/GObject app without a reference to the sender widget?
37,804,574
<p>I'm building a Gtk app in Python (Lutris, available on Github) where I emit a custom signal in a part of the app and I would like to connect to that signal in a totally different part of the app where the receiver doesn't have a reference to the widget that emitted the signal.</p> <p>I was looking for a way to have...
0
2016-06-14T06:33:48Z
37,805,399
<p>After researching a bit more on the issue I found a solution that would work.</p> <p>On the receiving widget, instead of <code>connect</code>, <code>GObject.add_emission_hook</code> can be used to have something like:</p> <pre><code>GObject.add_emission_hook(SenderType, 'signal-name', on_signal_callback) </code></...
0
2016-06-14T07:18:05Z
[ "python", "gtk" ]
How do I get strings which starts with number as start of line and ends with 5 digit number
37,804,658
<p>I have text like:</p> <pre><code>asf aSD ikugfr jddc ghddfj gjn dfxg sdgal fghfh 16 rgjodrisgj frth fghsdf, dfghdf dfhgdh gho h ghdof 67676 szdgfads 2 adf dojosd hsh fghs, zfgdf dhgdzsfb dfgdz, dzgdzfvg 47564 asdgasdg asdg 4334 ersga errr ertgerfd ertera erers qereadf erfesfdc wefadfe, sfsdgfg-43647 </code></...
3
2016-06-14T06:37:57Z
37,804,743
<p>Your <code>^[0-9](.*)(?&lt;=,)*\n?(.*\D\d{5}\D)</code> regex matches the start of a string/line, then 1 digit, then 0+ any characters (except newlines if DOTALL mode is not used), then <code>(?&lt;=,)*</code> is supposed to check 0+ times if the preceding character is a comma (which does not make much sense though P...
4
2016-06-14T06:43:40Z
[ "python", "regex" ]
PREFERRED_URL_SCHEME doesn't seem to work in Jinja2 Flask Template
37,804,802
<p>I am implementing FB login on my webapp here <a href="https://www.glifft.com." rel="nofollow">www.glifft.com</a> but I can't seem to get the redirect right. The redirect after logging in should be to <a href="https://www.glifft.com/myglifft" rel="nofollow">https://www.glifft.com/myglifft</a>. I'm using the url_for()...
2
2016-06-14T06:47:11Z
37,805,135
<p>The PREFERRED_URL_SCHEME seems to be buggy for me too. If you have very few url_for calls, the passing _scheme='https' can be considered. So, the line would be,</p> <pre><code>location.href = "{{ url_for('myglifft', _external=True, _scheme='https') }}"; </code></pre>
2
2016-06-14T07:05:55Z
[ "python", "flask", "jinja2", "facebook-login" ]
Python - How to Compare a column value of one row with value in next row
37,804,840
<p>I want to compare the S.No. of different rows, if it is same then I want to calculate the datetime difference and print details.(If datetime difference is not possible then only date difference would also be fine.)</p> <p>Input </p> <pre><code>S.No. Datetime Details 1 2010/6/7 19:01 asd 1 2010/...
-7
2016-06-14T06:49:31Z
37,806,322
<p>Use groupby (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html</a>)</p> <p>Assume your input is saved in a pandas Dataframe (or equivalently save it into csv and read it usi...
0
2016-06-14T08:04:42Z
[ "python", "pandas" ]
Python: functools.partial returns error
37,804,866
<p>I am encountering a problem using <code>functools.partial</code>.</p> <p><strong>My code:</strong></p> <pre><code>selected_words = ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate'] def awsome_count(x,i): if selected_words[i] in x: y=1 else:...
1
2016-06-14T06:50:51Z
37,805,012
<p>You gave your <code>partial()</code> object one <em>positional</em> argument:</p> <pre><code>functools.partial(awsome_count, 0) </code></pre> <p>That argument is applied <strong>first</strong>; additional positional arguments are added to that one, so your call:</p> <pre><code>partialfun(products[2]['word_count']...
3
2016-06-14T06:59:35Z
[ "python", "partial", "functools" ]
Weird thing while solving n-queens
37,805,133
<p>So, I was solving n-queens problem and wrote this backtracking solution.</p> <pre><code>def isSafe(row, col, board): print board for i in range(col): if board[row][i] == 'Q': print 'faled here' return False r_row = row-1 c_col = col-1 while r_row &gt;= 0 and c_co...
1
2016-06-14T07:05:52Z
37,805,238
<p>The issue is <code>board = [[0]*5]*5</code>. This gives you five copies of <strong>the same list</strong> of five zeros.</p> <p>One possible fix:</p> <pre><code>board = [x[:] for x in [[0] * 5] * 5] </code></pre>
2
2016-06-14T07:10:18Z
[ "python", "algorithm", "backtracking" ]
How can I fix this NoReverseMatch error?
37,805,184
<pre><code>Error Message:*&lt;br/&gt;&lt;br/&gt; NoReverseMatch at / Reverse for 'get_travel_details' with arguments '()' and keyword arguments '{u'origin': u'bus_terminals.Bus_Terminal_Id', u'destination': u'bus_terminals.Bus_Terminal_Id', u'travel_date': u'travel_date'}' not found. 1 pattern(s) tried: ['(?P&lt; trave...
1
2016-06-14T07:07:39Z
37,805,410
<p>Your url is still passing in strings, that include a <code>.</code>, which isn't included in your regex. I doubt that you actually want the dot and have a string id so just remove the quotes..</p> <p>So change</p> <pre><code>{% url 'brats:get_travel_details' travel_date='travel_date' origin='bus_terminals.Bus_Term...
0
2016-06-14T07:18:34Z
[ "python", "django" ]
How can I fix this NoReverseMatch error?
37,805,184
<pre><code>Error Message:*&lt;br/&gt;&lt;br/&gt; NoReverseMatch at / Reverse for 'get_travel_details' with arguments '()' and keyword arguments '{u'origin': u'bus_terminals.Bus_Terminal_Id', u'destination': u'bus_terminals.Bus_Terminal_Id', u'travel_date': u'travel_date'}' not found. 1 pattern(s) tried: ['(?P&lt; trave...
1
2016-06-14T07:07:39Z
37,805,695
<p><strong>tl;dr</strong></p> <p>To fix the error, remove the following line from your main urls:</p> <pre><code>url(r'^(?P&lt;travel_date&gt;\w+)/travel_date/(?P&lt;origin&gt;\w+)/origin/(?P&lt;destination&gt;\w+)/destination$', include('bus_reservation_system.urls')), </code></pre> <hr> <p><strong>Explanation</st...
0
2016-06-14T07:33:05Z
[ "python", "django" ]
How would I click something in urllib2
37,805,359
<p>This is a text box and I am wondering if it is possible to click it</p> <pre><code>&lt;input type="text" id="FirstName" class="form-control" name="FirstName" data-bind="inputWithPlaceholder: firstName, value: firstName, css: { 'has-error': showError(firstName) }, hasFocus: firstName.focused, tooltip: { target: '#La...
-1
2016-06-14T07:16:16Z
37,805,863
<p>It's not clear what you want.</p> <p>1) If you want just to get the text/tag, use the lxml library</p> <pre><code>from lxml import html page = requests.get('http://econpy.pythonanywhere.com/ex/001.html') # or just get the page using urllib2 library tree = html.fromstring(page.content) buyers = tree.xpath('//div...
1
2016-06-14T07:41:00Z
[ "python", "python-2.7", "python-3.x", "urllib2", "urllib" ]