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
How do I write the index for a list of lists
38,730,635
<p>I have a list of 3 lists each containing a random integer between 1 and 9:</p> <pre><code>lists= [[1,3,5],[2,4,6],[7,8,9]] </code></pre> <p>I ask the user to select any single digit number. I am making a program that finds the number one less than the user inputs and then decides if the next number in the list (a...
0
2016-08-02T21:19:04Z
38,730,744
<p>I am a little confused by what you are trying to achieve but you can get the index along with the element in a for loop by using:</p> <pre><code>for index, value in enumerate(my_list): # Do stuff here </code></pre> <p>Or you can find the index of any element in a list with:</p> <pre><code>index = my_list.inde...
1
2016-08-02T21:26:51Z
[ "python", "list", "syntax" ]
How do I write the index for a list of lists
38,730,635
<p>I have a list of 3 lists each containing a random integer between 1 and 9:</p> <pre><code>lists= [[1,3,5],[2,4,6],[7,8,9]] </code></pre> <p>I ask the user to select any single digit number. I am making a program that finds the number one less than the user inputs and then decides if the next number in the list (a...
0
2016-08-02T21:19:04Z
38,730,788
<p>If I understand correctly, you want:</p> <pre><code>for x in lists: for i in range(len(x)): if x[i] == user_choice-1 and i &lt; len(x)-1: if x[i+1] &gt; x[i]: #Next value is bigger... else: #Next value is smaller... </code></pre>
1
2016-08-02T21:30:03Z
[ "python", "list", "syntax" ]
~/.bash_profile in OSX version 10.11.6 for virtualenv and Python
38,730,743
<p>So when I just write these commands in the terminal I get these errors:</p> <pre><code> /  L/F/P  Versions  export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3  ➶ 127  04:21:45 PM /  L/F/P  Versions  source /usr/local/bi...
0
2016-08-02T21:26:47Z
38,730,875
<p>It looks like you're using <code>fish</code> shell. Your bash profile is written using items that are apparently unsupported by fish, see specifically</p> <pre><code>Unsupported use of '&amp;&amp;'. In fish, please use 'COMMAND; and COMMAND'. </code></pre> <p>From when you tried to source your bash profile. You ma...
1
2016-08-02T21:36:03Z
[ "python", "opencv", ".bash-profile" ]
Django: changing image size and upload to S3
38,730,753
<p>I have inherited a Django Project and we have moved images to S3</p> <p>One of the models is a typical user profile</p> <pre><code>class Profile(UUIDBase): first_name = models.CharField(_("First Name"), max_length=20) last_name = models.CharField(_("Last Name"), max_length=20, null=True) profile_image...
6
2016-08-02T21:27:26Z
38,779,207
<p>The issue seems to be related to PIL's JPEG library:</p> <pre><code>&gt;&gt;&gt; u = User(email="root@groupon.com", password="sdfbskjfskjfskjdf") &gt;&gt;&gt; u.save() &gt;&gt;&gt; p = Profile(user=u, profile_image=create_image_file()) &gt;&gt;&gt; p.save() &gt;&gt;&gt; from django.core.files.storage import default...
0
2016-08-05T00:04:21Z
[ "python", "django", "amazon-s3", "python-imaging-library", "image-resizing" ]
Django: changing image size and upload to S3
38,730,753
<p>I have inherited a Django Project and we have moved images to S3</p> <p>One of the models is a typical user profile</p> <pre><code>class Profile(UUIDBase): first_name = models.CharField(_("First Name"), max_length=20) last_name = models.CharField(_("Last Name"), max_length=20, null=True) profile_image...
6
2016-08-02T21:27:26Z
38,811,226
<p>The problem is in django-storages. S3BotoStorageFile's _file attribute is a SpooledTemporaryFile which works for png files, but not jpg files. </p> <p>See: <a href="https://github.com/jschneier/django-storages/issues/155" rel="nofollow">https://github.com/jschneier/django-storages/issues/155</a></p>
0
2016-08-07T05:35:49Z
[ "python", "django", "amazon-s3", "python-imaging-library", "image-resizing" ]
Regex to extract all urls from string
38,730,782
<p>I have a string like this </p> <blockquote> <p><code>http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/</code></p> </blockquote> <p>I would like to extract all url / webaddress into a Array. for example </p> <p><code>urls...
-1
2016-08-02T21:29:31Z
38,730,916
<p>The problem is that your regex pattern is too inclusive. It includes all urls. You can use lookahead by using (?=)</p> <p>Try this:</p> <pre><code>re.findall("((www\.|http://|https://)(www\.)*.*?(?=(www\.|http://|https://|$)))", strings) </code></pre>
2
2016-08-02T21:39:14Z
[ "python", "regex" ]
Regex to extract all urls from string
38,730,782
<p>I have a string like this </p> <blockquote> <p><code>http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/</code></p> </blockquote> <p>I would like to extract all url / webaddress into a Array. for example </p> <p><code>urls...
-1
2016-08-02T21:29:31Z
38,731,035
<p>Your problem is that <code>http://</code> is being accepted as a valid part of a url. This is because of this token right here:</p> <pre><code>[$-_@.&amp;+] </code></pre> <p>or more specifically:</p> <pre><code>$-_ </code></pre> <p>This matches all characters with the range from <code>$</code> to <code>_</code>,...
0
2016-08-02T21:46:35Z
[ "python", "regex" ]
Regex to extract all urls from string
38,730,782
<p>I have a string like this </p> <blockquote> <p><code>http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/</code></p> </blockquote> <p>I would like to extract all url / webaddress into a Array. for example </p> <p><code>urls...
-1
2016-08-02T21:29:31Z
38,731,212
<p>A simple answer without getting into much complication:</p> <pre><code>import re url_list = [] for x in re.split("http://", l): url_list.append(re.split("https://",x)) url_list = [item for sublist in url_list for item in sublist] </code></pre> <p>In case you want to append the string <code>http://</code> and...
0
2016-08-02T22:02:54Z
[ "python", "regex" ]
Python 3.4 windows, pip install fails
38,730,867
<p>I am struggling with adding to my Python 34 installation:</p> <p>C:> pip install --upgrade pip<BR> Could not find any downloads that satisfy the requirement pip in c:\python34\lib \site-packages<BR> Collecting pip<BR> No distributions at all found for pip in c:\python34\lib\site-packages<BR></p> <p>What am I doi...
0
2016-08-02T21:35:25Z
38,730,957
<p>You need to run pip as a script and python will be the main executable.</p> <pre><code>python -m pip install -U pip </code></pre> <p>The recommended procedure will be to update from get-pip.py</p> <pre><code>curl https://bootstrap.pypa.io/get-pip.py | python </code></pre>
2
2016-08-02T21:41:50Z
[ "python", "windows", "pip" ]
Python 3.4 windows, pip install fails
38,730,867
<p>I am struggling with adding to my Python 34 installation:</p> <p>C:> pip install --upgrade pip<BR> Could not find any downloads that satisfy the requirement pip in c:\python34\lib \site-packages<BR> Collecting pip<BR> No distributions at all found for pip in c:\python34\lib\site-packages<BR></p> <p>What am I doi...
0
2016-08-02T21:35:25Z
38,767,497
<p>Seems I found the reason: the Windows computer is within a state agency behind a hefty firewall. I tried the same install with Python 3.4.3 from my laptop connected through my phone and had no problem at all. So, I think the firewall was in the way. Thanks for looking into this, @froost1999 and @Rockse .</p>
0
2016-08-04T12:35:17Z
[ "python", "windows", "pip" ]
Many-to-many relationship with different other objects, self and attributes in SQLAlchemy
38,731,062
<p>I am declaring a somewhat complicated model with SQLAlchemy. I have basic objects like (fields are not important in that case):</p> <pre><code>class A(Base): __tablename__ = 'as' class B(Base): __tablename__ = 'bs' </code></pre> <p>Now I want to declare a collection of such objects, which would be easy wi...
-1
2016-08-02T21:49:04Z
38,745,928
<p>The answer is to use <strong>joined table inheritance</strong> as described <a href="http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#joined-table-inheritance" rel="nofollow">here</a>.</p> <p>First, add a common parent class for the similar classes, with a field named type (or anything else) as a discrimin...
0
2016-08-03T14:06:09Z
[ "python", "orm", "sqlalchemy" ]
How to "merge" multiple pandas dataframes with the index as dataframe column?
38,731,071
<p>I have two pandas dataframes: one:</p> <pre><code>import pandas as pd df1 = pd.read_csv('filename1.csv') df1 A B 0 1 22 1 2 15 2 5 99 3 6 1 .... </code></pre> <p>and two</p> <pre><code>df2 = pd.read_csv('filename1.csv') df2 A B 0 1 6 1 3 52 2 4 15...
2
2016-08-02T21:49:45Z
38,731,184
<pre><code>files = ['file1', 'file2'] def read(f): f = f + '.csv' df = pd.read_csv(f, usecols=['A', 'B']) return df.drop_duplicates(subset=['A']).set_index('A').B pd.concat([read(f) for f in files], axis=1, keys=files) </code></pre> <p><a href="http://i.stack.imgur.com/vG4XW.png" rel="nofollow"><img src=...
3
2016-08-02T22:00:30Z
[ "python", "python-3.x", "pandas", "indexing", "dataframe" ]
Django(1.9.6) list_display works on dev not prod
38,731,104
<p>I am running a local version of django on my computer as well as a django droplet at DigitalOcean, both Django 1.9.6. However, everything I have done this far has been the same across these two environment, but when I tried to customize the admin screen, it only worked on my local env. </p> <p>The change I did was ...
0
2016-08-02T21:53:02Z
38,788,188
<p>I needed to restart gunicorn. Thanks to valentjedi for providing the answer in the comments. </p>
0
2016-08-05T11:29:52Z
[ "python", "django" ]
Mysterious "embedded null byte" error
38,731,132
<p>Working on a fairly large/complex Django project with a team, we occasionally see runserver crash with <code>ValueError: embedded null byte</code>. We restart runserver and it's fine - either for a few minutes or a few days. We can detect no pattern to what causes the crashes (seems totally random). Fortunately it's...
0
2016-08-02T21:55:17Z
38,731,324
<ul> <li>One of the <code>AppConfig</code> objects has null byte in its <code>path</code> attribute.</li> <li>One of the <code>LOCALE_PATHS</code> has null byte.</li> <li>One of the files is in the "wrong" encoding, so Django treats something has null byte (e. g. <code>AppConfig.path</code>).</li> <li>One of the files ...
0
2016-08-02T22:14:13Z
[ "python", "django" ]
Access Second Instance Of Key In Nested Dictionary In Python
38,731,133
<p>So I'm utilizing the <a href="https://github.com/simon-weber/gmusicapi" rel="nofollow">GMusicAPI</a> to try to interact with Google Play Music (I'm utilizing the MobileClient view) a bit. Unfortunately it's only in Python, a language I've never used before. I'm running a search, that will search for a given artist. ...
0
2016-08-02T21:55:24Z
38,731,167
<p>I think what you wish is:</p> <pre><code>ArtistSearch['artist_hits'][1]['artist']['name'] # ---^--- </code></pre> <p>because <code>ArtistSearch['artist_hits']</code> is the list, you want the second dictionary <code>[1]</code> and inside it the <code>['artist']['name']</code> field</p>
1
2016-08-02T21:59:09Z
[ "python", "dictionary", "nested", "key", "value" ]
Access Second Instance Of Key In Nested Dictionary In Python
38,731,133
<p>So I'm utilizing the <a href="https://github.com/simon-weber/gmusicapi" rel="nofollow">GMusicAPI</a> to try to interact with Google Play Music (I'm utilizing the MobileClient view) a bit. Unfortunately it's only in Python, a language I've never used before. I'm running a search, that will search for a given artist. ...
0
2016-08-02T21:55:24Z
38,731,260
<p>I think that the dictionary itself is not well formed, maybe you don't need the "artist" keyword. However could be useful access data in dictionary with something like:</p> <pre><code>for key,value in dictionary.iteritems(): print key,value </code></pre> <p>Rather than statically with numeric indices.</p>
0
2016-08-02T22:08:14Z
[ "python", "dictionary", "nested", "key", "value" ]
NameError: global name 'category' is not defined
38,731,247
<p>I am making a Hangman Game and having trouble. Ok every time I go to edit this and save my edits I get a red mark saying I need more details not just code so this is my more details. Please do not delete it or I cannot edit my post. :)</p> <p>My error is, </p> <blockquote> <p>"NameError: global name 'category' i...
0
2016-08-02T22:06:52Z
38,731,468
<p>You probably meant for <em>category</em> to be an argument of <code>choose_word()</code>. At the moment <code>pick_category()</code> returns the value of the local variable <em>category</em>, which is then ignored. Instead define <code>choose_word()</code> as:</p> <pre><code>def choose_word(category): ... </cod...
1
2016-08-02T22:27:27Z
[ "python", "nameerror" ]
How to calculate sum of prime numbers from list of integers in Python?
38,731,252
<p>I am struck and need help with this.. I want to find the sum of prime numbers from a given list of integers. Here are a few test cases for the same. </p> <pre><code>n([3,3,1,13]) 19 n([2,4,6,9,11]) 13 n([-3,0,1,6]) 0 </code></pre> <p>The Code that I have written is as follows but it fails with the test cases ...
1
2016-08-02T22:07:25Z
38,731,389
<p>This part is wrong:</p> <pre><code> for j in range(2, int(num**0.5)+1): if num%j != 0: sum1 = sum1 + num </code></pre> <p>you are summing <code>num</code> for each number in the range that didn't divide. you should sum just if <strong>all</strong> of them didn't divide.</p> <p>S...
5
2016-08-02T22:20:06Z
[ "python", "python-3.x" ]
How to calculate sum of prime numbers from list of integers in Python?
38,731,252
<p>I am struck and need help with this.. I want to find the sum of prime numbers from a given list of integers. Here are a few test cases for the same. </p> <pre><code>n([3,3,1,13]) 19 n([2,4,6,9,11]) 13 n([-3,0,1,6]) 0 </code></pre> <p>The Code that I have written is as follows but it fails with the test cases ...
1
2016-08-02T22:07:25Z
38,731,629
<p>Don't try to do everything in one function. I separated out the rest of the logic, but I'll leave isprime to you:</p> <pre><code>def isprime(x): # Replace this with your code # separate function so it can have its own tests return x in [3, 13, 11, 2] def sum_prime_numbers_in_list(l): return sum([x...
1
2016-08-02T22:42:07Z
[ "python", "python-3.x" ]
How to calculate sum of prime numbers from list of integers in Python?
38,731,252
<p>I am struck and need help with this.. I want to find the sum of prime numbers from a given list of integers. Here are a few test cases for the same. </p> <pre><code>n([3,3,1,13]) 19 n([2,4,6,9,11]) 13 n([-3,0,1,6]) 0 </code></pre> <p>The Code that I have written is as follows but it fails with the test cases ...
1
2016-08-02T22:07:25Z
38,769,444
<p>The Answer should be this. [You should try this code, in this link.<a href="https://gist.github.com/Jayhalani/aa7ddf085bea9d1057644a93753f8813" rel="nofollow">Gist</a>]</p> <pre><code>def sumprimes(n): sum1 = 0 for i in range(0,len(n)): num = n[i] if num &gt; 1: prime = True for j in range(2...
0
2016-08-04T13:57:43Z
[ "python", "python-3.x" ]
I can't understand how this (function?) works
38,731,273
<p>I'm pretty new to Python and I'm going through a starter book. The code isn't written in English so I tried my best to translate, hope you guys understand. It has this exercise where we calculate the taxes from the user salary:</p> <pre><code>salary = float(input("Enter your salary to taxes calculation: ")) base = ...
2
2016-08-02T22:09:50Z
38,731,333
<p>Please note that in case of salary 5000, the control will go to both the if statements. So it comes out as 700 from first, and 400 from second, therefore answer is 700+400. This also makes sense, as tax calculation is mostly partitioned in brackets, and is not a flat percentage on salary.</p>
5
2016-08-02T22:14:43Z
[ "python" ]
I can't understand how this (function?) works
38,731,273
<p>I'm pretty new to Python and I'm going through a starter book. The code isn't written in English so I tried my best to translate, hope you guys understand. It has this exercise where we calculate the taxes from the user salary:</p> <pre><code>salary = float(input("Enter your salary to taxes calculation: ")) base = ...
2
2016-08-02T22:09:50Z
38,731,354
<p>It flows on to the second function </p> <p>so if I sub in the numbers:</p> <pre><code>Salary = 5000 base = 5000 taxes = 0 if 5000 &gt; 3000: taxes = 0 + ((5000- 3000) * 0.35) # = 700 base = 3000 if 3000 &gt; 1000: taxes = 700 + ((3000 - 1000) * 0.20) # = 1100 </code></pre>
1
2016-08-02T22:16:40Z
[ "python" ]
I can't understand how this (function?) works
38,731,273
<p>I'm pretty new to Python and I'm going through a starter book. The code isn't written in English so I tried my best to translate, hope you guys understand. It has this exercise where we calculate the taxes from the user salary:</p> <pre><code>salary = float(input("Enter your salary to taxes calculation: ")) base = ...
2
2016-08-02T22:09:50Z
38,731,377
<p>Alright, let's walk through it with your example of 5000</p> <pre><code>salary = float(input("Enter your salary to taxes calculation: ")) base = salary # base = 5000 taxes = 0 if base &gt; 3000: # base is larger than 3000, so we enter the if statement taxes = taxes + ((base - 3000) * 0.35) # taxes = 0 + ...
3
2016-08-02T22:19:18Z
[ "python" ]
I can't understand how this (function?) works
38,731,273
<p>I'm pretty new to Python and I'm going through a starter book. The code isn't written in English so I tried my best to translate, hope you guys understand. It has this exercise where we calculate the taxes from the user salary:</p> <pre><code>salary = float(input("Enter your salary to taxes calculation: ")) base = ...
2
2016-08-02T22:09:50Z
38,731,398
<p>This is an economical equation which calculate tax for every part of salary. the procedure would be this: </p> <ul> <li>For amount greater than <code>3000</code> calculate 35% tax for this portion of salary.</li> <li>For amount greater than <code>1000</code> (and less than <code>3000</code>) calculate 20% tax for t...
0
2016-08-02T22:21:21Z
[ "python" ]
Looping over dictionary values, which are nested lists to convert into matrices
38,731,317
<p>I have the following problem:</p> <p>I have a dictionary where each K,V is as follows:</p> <p>k = 1 String </p> <p>v = nested lists in the following manner,</p> <p>inside V are A number of lists, inside each A list, there are B number of lists, inside each B list there are C number of entries.</p> <p>Eventually...
-1
2016-08-02T22:13:36Z
38,732,104
<p>The good news is: You already have your dictionary in the form you want! A list of lists <strong><em>is</em></strong> a 2D matrix.</p> <p>The bad news: It's not really so clear what errors you're having and where they are coming up. More detail on that would be helpful for people to come up with solutions.</p> <p>...
0
2016-08-02T23:36:26Z
[ "python", "loops", "dictionary", "matrix", "list-comprehension" ]
Tkinter, why does my code skip the first label update?
38,731,350
<p>I have a button that I want to press to process some excel data. This often takes a moment or two especially if the user uploads a number of large files. While the files are being processed, I want to display a note to the user that the files are processing and that the program has not frozen. Once the files are com...
0
2016-08-02T22:15:58Z
38,731,393
<p>In order for the screen to refresh, the event loop must be able to process a refresh event. Since your code is running, the event loop is frozen.</p> <p>A quick and dirty solution is to call <code>self.update_idletasks()</code>, which tells tkinter to handle all of the "idle" events, which includes events related t...
1
2016-08-02T22:20:35Z
[ "python", "python-3.x", "tkinter" ]
Requested modules not available: vtkRenderingOpenGL-cmake/OpenCVDetectVTK.cmake:6 (find_package)
38,731,358
<p>I am basically trying to install OpenCV3 with Python3.5. I have successfully gone through all the steps in <a href="http://www.pyimagesearch.com/2015/06/29/install-opencv-3-0-and-python-3-4-on-osx/" rel="nofollow">this tutorial</a> for <code>git checkout 3.1.0</code> of opencv. However when I enter this command:</p>...
0
2016-08-02T22:16:54Z
38,732,770
<p>It took me a good few hours to get this fixed. Here's what I did:</p> <pre><code>wget https://github.com/Itseez/opencv/archive/3.1.0.zip wget https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip unzip 3.1.0.zip unzip 3.1.0.zip.1 cd opencv-3.1.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D...
1
2016-08-03T01:05:33Z
[ "python", "osx", "opencv", "cmake", "opencv3.0" ]
Unstacking DataFrame with Multiple 'Value' Columns in Python Pandas
38,731,411
<p>Say I have a DataFrame that looks like this:</p> <pre><code> keys sample verify 0 foo a 1 1 bar b 2 2 monty c 3 3 foo d 4 4 bar e 5 5 monty f 6 </code></pre> <p>That I want in this f...
2
2016-08-02T22:22:38Z
38,731,568
<pre><code>df2 = df.set_index('keys').T.reset_index(drop=True) \ .T.groupby(level=0).apply(lambda df: df.reset_index(drop=True)) \ .stack().unstack(1).T df2.columns = df2.columns.set_levels((df2.columns.levels[1] + 1).astype(str), level=1) df2.columns = df2.columns.to_series().str.join('_') df2 </code></pre> ...
2
2016-08-02T22:35:36Z
[ "python", "pandas", "stack", "pivot-table" ]
How do I get this loop to work correctly when writing pandas df to xlsx?
38,731,480
<p>I have used <a href="http://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data">this code</a>, which is kind of working. Right now in the smaller 'rep_list' as it executes the first rep in the list which is CP is adds it, but then when it goes to AM it overwrites the...
0
2016-08-02T22:28:12Z
38,731,785
<p>Try using the following:</p> <pre><code>import pandas as pd import datetime from openpyxl import load_workbook now = datetime.datetime.now() currentDate = now.strftime("%Y-%m-%d") call_report = pd.read_excel("Ending 2016-07-30.xlsx", "raw_data") #rep_list = ["CP", "AM", "JB", "TT", "KE"] rep_list = ["CP", "AM"] ...
1
2016-08-02T23:00:24Z
[ "python", "pandas", "openpyxl" ]
How do I get this loop to work correctly when writing pandas df to xlsx?
38,731,480
<p>I have used <a href="http://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data">this code</a>, which is kind of working. Right now in the smaller 'rep_list' as it executes the first rep in the list which is CP is adds it, but then when it goes to AM it overwrites the...
0
2016-08-02T22:28:12Z
38,736,670
<p>If you use openpyxl 2.4 then you can <a href="http://openpyxl.readthedocs.io/en/latest/pandas.html" rel="nofollow">work with Pandas dataframes in directly in openpyxl</a>.</p>
0
2016-08-03T07:07:43Z
[ "python", "pandas", "openpyxl" ]
Add custom legend to bokeh Bar
38,731,491
<p>I have pandas series as:</p> <pre><code>&gt;&gt;&gt; etypes 0 6271 1 6379 2 399 3 110 4 4184 5 1987 </code></pre> <p>And I want to draw Bar chart in Bokeh: <code>p = Bar(etypes)</code>. However for legend I get just <code>etypes</code> index number, which I tried to decrypt with this dictionary...
2
2016-08-02T22:29:21Z
38,731,759
<p>Convert the series to a DataFrame, add the legend as a new column and then reference that column name in quotes for label. For example, if you call your DataFrame 'etypes', data column 'values', and your legend column 'legend':</p> <pre><code>p = Bar(etypes, values='values', label='legend') </code></pre> <p>If yo...
1
2016-08-02T22:57:59Z
[ "python", "pandas", "bokeh" ]
Django: How to call a function once a button is clicked?
38,731,497
<p>I have a method written in my views.py that sends a sub-process command.</p> <p>I want to be able to click a button on my Django application and it initiates the method I wrote.</p> <p>How can I do this?</p> <p>This is currently my function in my views.py</p> <pre><code> def send_command(request): out...
0
2016-08-02T22:29:54Z
38,731,991
<p>If you are not sending content which will be saved in the server you could change your button to behave like a url</p> <p>url.py</p> <pre><code>from views import send_command urlpatterns = [ url(r'^send_command$', send_command, name='send_command'), ] </code></pre> <p>html</p> <pre><code>&lt;a href="{% url ...
0
2016-08-02T23:25:07Z
[ "python", "html", "django", "methods", "views" ]
Recursively replace characters in string using Python
38,731,503
<pre><code>def replaceChar(myString, oldChar, newChar): # if myString has no characters left, return newString if myString == '': return newString elif myString[0] == oldChar: # then add newChar to newString else: # then add myString[0] to newString # Chop the first chara...
0
2016-08-02T22:30:19Z
38,731,761
<p>Obviously you would never actually use a recursive solution like this for this type of problem, but here it is anyway:</p> <pre><code>def replaceChar(inval, old, new): if inval == '': return '' if inval[0] == old: return new + replaceChar(inval[1:], old, new) return inval[0] + replaceCha...
1
2016-08-02T22:58:00Z
[ "python", "recursion" ]
Fastest Way to Compress Video Size Using Library or Algo
38,731,535
<p>I'm trying to compress high quality video into less size and I'm able to reduce the size of video that I've compressed using the following objective-c code:</p> <pre><code> - (BOOL)convertMovieToMP4:(NSString ) originalMovPath andStoragePath:(NSString ) compMovPath { NSURL *tmpSourceUrl = [NSURL...
8
2016-08-02T22:33:35Z
38,745,037
<p>Here is a document, which contains some RnD on video compression: <a href="https://drive.google.com/file/d/0BySTUFVtfzJmM3pYeVRiWmxSLVU/view" rel="nofollow">https://drive.google.com/file/d/0BySTUFVtfzJmM3pYeVRiWmxSLVU/view</a></p> <p>It also contains a sample code for quick compression of videos in objective-C. It ...
2
2016-08-03T13:28:45Z
[ "java", "python", "objective-c", "osx", "ffmpeg" ]
PyQt4 button click registering multiple times when clicked
38,731,543
<p>I am new to PyQt4 and after several searches I have not found info on the issue I am seeing in my GUI.</p> <p>The issue is that when a user clicks on getSingleItems button, the function runs the same amount of times that the user has clicked getAllItems. An example is if the user clicks getAllItems to populate the ...
0
2016-08-02T22:34:02Z
38,731,931
<p>Apparently you are are adding new connection to <code>getSingleItem.clicked</code> in each run of <code>getitems</code>, so the <code>clicked</code> signal gets connected multiple times to the same slot, which causes the behaviour you observe. </p> <p>Moving the line </p> <pre><code>self.getSingleItem.clicked.co...
1
2016-08-02T23:18:17Z
[ "python", "user-interface", "pyqt4" ]
How to update my forks of Evernote SDK for Python to track latest updates?
38,731,556
<p>First of all, I'm hoping that Evernote will start maintaining its Python SDK (<a href="https://github.com/evernote/evernote-sdk-python" rel="nofollow">evernote/evernote-sdk-python for Python 2</a> and <a href="https://github.com/evernote/evernote-sdk-python3" rel="nofollow">evernote/evernote-sdk-python3 for Python 3...
1
2016-08-02T22:34:47Z
38,732,275
<p>We haven't put too much work into our SDKs lately but we're hoping to change that in the coming weeks. As a first step we (finally) updated our <a href="https://dev.evernote.com/doc/reference/" rel="nofollow">API reference</a> (another, minor update coming soon) and the next step is our SDKs. There's a lot of work t...
1
2016-08-02T23:56:39Z
[ "python", "evernote" ]
Adding scss file type to new context menu of PyCharm
38,731,597
<p>The JetBrains IDE PyCharm supports scss files, but I can't figure out how to add it to the "New" context menu that pops up when right-clicking the directory where I want to add the file. I see alot of other file types, and looking at registering a new file type, I see scss is already there. But I can't figure out ho...
0
2016-08-02T22:39:06Z
38,791,478
<p>New SCSS files can be created via <code>File/New/Stylesheeet</code>. But you can create your own SCSS file template in <code>Preferences | Editor | File and code templates</code> (see <a href="https://www.jetbrains.com/help/pycharm/2016.1/creating-and-editing-file-templates.html" rel="nofollow">https://www.jetbrains...
1
2016-08-05T14:17:48Z
[ "python", "sass", "pycharm", "jetbrains" ]
Pad the exponential index with zeros
38,731,609
<p>Let's say I have a double precision value</p> <pre><code>a = 1.5838619160273860E-021 </code></pre> <p>Is there a way to create a string <code>b</code></p> <pre><code>b = '1.5838619160273860E-021' </code></pre> <p>Note the index has three digits here <code>E-021</code> instead of <code>E-21</code>. I know <code>f...
1
2016-08-02T22:40:23Z
38,732,242
<p>You need another case for when its +21 instead of -21</p> <pre><code>&gt;&gt;&gt; x = '1.5838619160273860E-21' &gt;&gt;&gt; a,b = x.split('E-') &gt;&gt;&gt; 'E-'.join((a,b.zfill(3))) '1.5838619160273860E-021' </code></pre>
0
2016-08-02T23:51:59Z
[ "python" ]
How to flatten a dictionary with nested sequences into a single sequence with all values and keys?
38,731,614
<p>I have a workable solution that returns a set:</p> <pre><code>&gt;&gt;&gt; a = {'a': {'1', '2', '3'}, 'b': {'4', '5', '6'}, 'c': {'7', '8', '9'}} &gt;&gt;&gt; def flatten_nested(a): temp = set( [value for value_set in a.values() for value in value_set] ) return temp | a.keys() ...
2
2016-08-02T22:40:56Z
38,731,658
<p>I guess more simple is this:</p> <pre><code>&gt;&gt;&gt; set.union(set(a), *a.values()) {'1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c'} </code></pre> <p>Or, here's the same thing via the bound method:</p> <pre><code>&gt;&gt;&gt; set(a).union(*a.values()) {'1', '2', '3', '4', '5', '6', '7', '8', '9', ...
3
2016-08-02T22:45:51Z
[ "python" ]
How to flatten a dictionary with nested sequences into a single sequence with all values and keys?
38,731,614
<p>I have a workable solution that returns a set:</p> <pre><code>&gt;&gt;&gt; a = {'a': {'1', '2', '3'}, 'b': {'4', '5', '6'}, 'c': {'7', '8', '9'}} &gt;&gt;&gt; def flatten_nested(a): temp = set( [value for value_set in a.values() for value in value_set] ) return temp | a.keys() ...
2
2016-08-02T22:40:56Z
38,731,757
<p>If the values are already sets then <a href="http://stackoverflow.com/a/38731658/2141635">wims answer</a> is the simplest, but to work for iterables like a list, tuples etc.. you would have to map to a set i.e <code>set(a).union(map(set, a.values())</code> or you could union the <a href="https://docs.python.org/3/li...
1
2016-08-02T22:57:54Z
[ "python" ]
Google App Engine - Issue authenticating deployed version of app
38,731,779
<p>I built a simple python application to be run on the Google App Engine. Code:</p> <pre><code>import webapp2 from oauth2client.contrib.appengine import AppAssertionCredentials from apiclient.discovery import build from googleapiclient import discovery from oauth2client.client import GoogleCredentials class MainPa...
0
2016-08-02T22:59:45Z
38,732,504
<p>To fix the "error while connecting to the server", follow the instructions listed in this answer: <a href="http://stackoverflow.com/questions/31651973/default-credentials-in-google-app-engine-invalid-credentials-error#_=_">http://stackoverflow.com/questions/31651973/default-credentials-in-google-app-engine-invalid-...
0
2016-08-03T00:28:43Z
[ "python", "google-app-engine", "google-api", "google-bigquery" ]
Where to Run Scripts at a PyCharm Debugger Breakpoint?
38,731,788
<p>When running the PyCharm debugger and having stopped at a break point, is there a console to run and display some computation with the local variable exposed to me?</p> <p>What I have in mind is the debugger setup in Matlab, where when stopped at a break point in a function, one can run scripts using the variables ...
1
2016-08-02T23:00:40Z
38,740,819
<p>If I have understood well what do you mean, yes, PyCharm provides you a console where you can run local scripts or just see the variable's value at breakpoint time.</p> <p>Start PyCharm debugger and at the bottom of your window you should see the main console.</p> <p>You have to press a botton named "Show Python P...
1
2016-08-03T10:20:12Z
[ "python", "pycharm" ]
Where to Run Scripts at a PyCharm Debugger Breakpoint?
38,731,788
<p>When running the PyCharm debugger and having stopped at a break point, is there a console to run and display some computation with the local variable exposed to me?</p> <p>What I have in mind is the debugger setup in Matlab, where when stopped at a break point in a function, one can run scripts using the variables ...
1
2016-08-02T23:00:40Z
38,767,434
<p>You can use <a href="https://www.jetbrains.com/help/pycharm/2016.1/adding-editing-and-removing-watches.html" rel="nofollow"><code>Evaluate Expression</code></a> and <a href="https://www.jetbrains.com/help/pycharm/2016.1/adding-editing-and-removing-watches.html" rel="nofollow"><code>Watches</code></a> features to run...
1
2016-08-04T12:31:40Z
[ "python", "pycharm" ]
Complex matrix in Python
38,731,796
<p>I have a problem with this Python code:</p> <pre><code>A = np.zeros((2*M + 2,nt)) A[1, :] = d[0,0] * np.ones((1,nt)) </code></pre> <p>where <code>d[0,0]</code> is complex. I received this error:</p> <pre><code>ComplexWarning: Casting complex values to real discards the imaginary part </code></pre> <p>during </p...
0
2016-08-02T23:01:45Z
38,731,862
<p>This is because by default <code>numpy</code> array holds zeros which is <code>int</code> type and you are trying to assign a complex array to integer array. If you write <code>A = np.zeros((2*M+2, nt), dtype=np.complex)</code> it should fix the problem. <code>dtype</code> parameter basically tells numpy to cast ele...
0
2016-08-02T23:09:28Z
[ "python", "python-2.7", "python-3.x" ]
Complex matrix in Python
38,731,796
<p>I have a problem with this Python code:</p> <pre><code>A = np.zeros((2*M + 2,nt)) A[1, :] = d[0,0] * np.ones((1,nt)) </code></pre> <p>where <code>d[0,0]</code> is complex. I received this error:</p> <pre><code>ComplexWarning: Casting complex values to real discards the imaginary part </code></pre> <p>during </p...
0
2016-08-02T23:01:45Z
38,731,921
<p>Are you trying to compute a <em>complex</em> valued array <code>A</code>, or a <em>real</em> valued array <code>A</code>? If the former, then declare <code>A</code> as:</p> <pre><code>A = np.zeros((2*M + 2,nt), dtype=complex) </code></pre> <p>Otherwise, cast your complex value <code>d[0, 0]</code> to a real using...
0
2016-08-02T23:17:32Z
[ "python", "python-2.7", "python-3.x" ]
I have a nested if statement and the inside statement nullifies the outter
38,731,820
<pre><code>board=[[1,0,8,5,12,16,24],[7,0,6,2,20,4,18],[13,0,9,10,22,23,17],[19,0,11,3,14,15,21]] def move(): while board[0][6]!= 0 and board[1][6]!=0 and board[2][6]!=0 and board[3][6]!=0: user_choice= int(raw_input('&gt;')) for lists in board: for i in range(len(lists)): if lists[i]== us...
2
2016-08-02T23:04:16Z
38,731,961
<p>Change the order in which you edit the board. First replace any other '8's by zero, then change the zero after a 7 to an 8.</p> <pre><code> for i in range(len(lists)-1): if lists[i]== user_choice-1 and lists[i+1]==0: for a in board: for j in range(len(a)): ...
0
2016-08-02T23:21:25Z
[ "python", "if-statement" ]
I have a nested if statement and the inside statement nullifies the outter
38,731,820
<pre><code>board=[[1,0,8,5,12,16,24],[7,0,6,2,20,4,18],[13,0,9,10,22,23,17],[19,0,11,3,14,15,21]] def move(): while board[0][6]!= 0 and board[1][6]!=0 and board[2][6]!=0 and board[3][6]!=0: user_choice= int(raw_input('&gt;')) for lists in board: for i in range(len(lists)): if lists[i]== us...
2
2016-08-02T23:04:16Z
38,732,084
<p>Not the most elegant solution in the world, but here is mine:</p> <pre><code>board = [ [1, 0, 8, 5, 12, 16, 24], [7, 0, 6, 2, 20, 4, 18], [13, 0, 9, 10, 22, 23, 17], [19, 0, 11, 3, 14, 15, 21] ] def print_board(): for row in board: print " ".join("{:2}".f...
0
2016-08-02T23:34:50Z
[ "python", "if-statement" ]
I have a nested if statement and the inside statement nullifies the outter
38,731,820
<pre><code>board=[[1,0,8,5,12,16,24],[7,0,6,2,20,4,18],[13,0,9,10,22,23,17],[19,0,11,3,14,15,21]] def move(): while board[0][6]!= 0 and board[1][6]!=0 and board[2][6]!=0 and board[3][6]!=0: user_choice= int(raw_input('&gt;')) for lists in board: for i in range(len(lists)): if lists[i]== us...
2
2016-08-02T23:04:16Z
38,732,213
<p>I think you will find things easier if you break the problem into smaller functions. Here a simple example:</p> <pre><code>board = [[1,0,8,5,12,16,24],[7,0,6,2,20,4,18],[13,0,9,10,22,23,17],[19,0,11,3,14,15,21]] # See if item is in lst. If so, return xy location def in_list(item, lst): for i in range(0, len(ls...
0
2016-08-02T23:48:28Z
[ "python", "if-statement" ]
How to get a random (bootstrap) sample from pandas multiindex
38,731,858
<p>I'm trying to create a bootstrapped sample from a multiindex dataframe in Pandas. Below is some code to generate the kind of data I need.</p> <pre><code>from itertools import product import pandas as pd import numpy as np df = pd.DataFrame({'group1': [1, 1, 1, 2, 2, 3], 'group2': [13, 18, 2...
3
2016-08-02T23:08:31Z
38,732,215
<p>Try:</p> <pre><code>df.unstack().sample(3, replace=True).stack() </code></pre> <p><a href="http://i.stack.imgur.com/KwgFP.png" rel="nofollow"><img src="http://i.stack.imgur.com/KwgFP.png" alt="enter image description here"></a></p>
2
2016-08-02T23:48:41Z
[ "python", "pandas", "sampling", "multi-index" ]
Seaborn jointplot hex option does not produce figure
38,731,897
<p>I am plotting a Pandas DataFrame as a Seaborn jointplot and would like to use the 'hex' function:</p> <pre><code>g = sns.jointplot("Xs", "Ys", data=PlotData, kind='hex', color="#4CB391") </code></pre> <p>The DataFrame is all floats and does not contain any NaNs:</p> <pre><code>In [34]: PlotData.describe() Out[34...
1
2016-08-02T23:13:51Z
38,732,478
<p>It seems like there is one pixel close to the mean (2, -0.5) that is colored. The standard deviation of your data set is also low, so perhaps the bins are too small and there are too many outliers to see the actual distribution. I would suggest either removing the outliers and trying again or explicitly setting the ...
2
2016-08-03T00:23:21Z
[ "python", "python-3.x", "pandas", "seaborn" ]
Can matplotlib only update the newest point to the figure?
38,731,903
<p>Is it possible for matplotlib only update the newest point to the figure instead of re-draw the whole figure? </p> <p>For example: this may be the fastest way for dynamic plotting</p> <pre><code>initiate: fig1 = Figure(figsize = (8.0,8.0),dpi = 100) axes1 = fig1.add_subplot(111) line1, = axes1.plot([],[],animated ...
1
2016-08-02T23:14:33Z
38,744,975
<p>Is only redrawing the entire figure the problem, i.e. it is ok to redraw the line itself as long as the figure is unchanged? Is the data known beforehand?</p> <p>If the answer to those questions are NO, and YES, then it might be worth looking into the <code>animate</code>-class for matplotlib. One example where t...
0
2016-08-03T13:26:09Z
[ "python", "opencv", "matplotlib" ]
Can matplotlib only update the newest point to the figure?
38,731,903
<p>Is it possible for matplotlib only update the newest point to the figure instead of re-draw the whole figure? </p> <p>For example: this may be the fastest way for dynamic plotting</p> <pre><code>initiate: fig1 = Figure(figsize = (8.0,8.0),dpi = 100) axes1 = fig1.add_subplot(111) line1, = axes1.plot([],[],animated ...
1
2016-08-02T23:14:33Z
38,903,254
<p>this is my (so far) little experience.<br> I started some month ago with Python(2.x) and openCV (2.4.13) as graphic library.I found in may first project that openCV for python works with numpy structure as much as matplotlib and (with slight difference) they can work together.</p> <p>I had to update some pixel afte...
0
2016-08-11T18:04:19Z
[ "python", "opencv", "matplotlib" ]
Get indicated string in list
38,731,927
<p>I got the list such as:</p> <pre><code>[Margaret, Peter, Julia-noCP-L,Parker-CP-T, Jessica, Monica-CP-T, Mark, Peter-noCP] </code></pre> <p>I want to obtain or objects which contain only CP in string:</p> <pre><code>['Parker-CP-T', 'Monica-CP-T'] </code></pre> <p>I made it in the following way:</p> <pre><code>...
0
2016-08-02T23:17:49Z
38,731,974
<p>Check out <a href="https://docs.python.org/3.4/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a>. With that you can do something like this:</p> <pre><code>headers_CP = [x for x in headers if 'CP' in x] </code></pre> <p>This will pull out all items in the list <code>headers</c...
0
2016-08-02T23:23:11Z
[ "python" ]
Get indicated string in list
38,731,927
<p>I got the list such as:</p> <pre><code>[Margaret, Peter, Julia-noCP-L,Parker-CP-T, Jessica, Monica-CP-T, Mark, Peter-noCP] </code></pre> <p>I want to obtain or objects which contain only CP in string:</p> <pre><code>['Parker-CP-T', 'Monica-CP-T'] </code></pre> <p>I made it in the following way:</p> <pre><code>...
0
2016-08-02T23:17:49Z
38,731,975
<p>One way is just accepting the items that are contain <code>-CP-</code> instead of checking the existence of <code>CP</code> and then filtering the result. You can do this within a <a href="http://python-3-patterns-idioms-test.readthedocs.io/en/latest/Comprehensions.html" rel="nofollow"><em>list comprehension</em></a...
0
2016-08-02T23:23:11Z
[ "python" ]
Python: Add egg or do pip install from the Jupyter notebook interface
38,732,053
<p>I am using a Jupyter notebook installed on a server. I am wondering is it possible to upload an egg file, or do a pip install from the notebook interface since I don't want to bother the system administrator for every single package I am experimenting. Thanks!</p> <p><a href="http://i.stack.imgur.com/0LF0z.png" rel...
0
2016-08-02T23:31:51Z
38,739,858
<p>There is already a page on this issue <a href="http://stackoverflow.com/questions/12332975/installing-python-module-within-code">here</a>.</p> <p>This is what you should be able to do in the notebook, if you want to install any given 'package':</p> <p>import pip pip.main(['install', 'package'])</p>
0
2016-08-03T09:37:54Z
[ "python", "jupyter-notebook" ]
Compare Django-taggit tags from multiple queries and list objects from matching tags
38,732,054
<p>I have a site that sells parts and tools. The site was originally built with separate models for tools and documents for those tools. The documents were just iterated over on a document page and linked to from the tool page. We use Django-taggit to tag everything, but I have tagged myself into a corner :) </p> ...
0
2016-08-02T23:31:53Z
38,732,548
<p>First of all, it's a bad practice placing your business logic in template - it should be done in view. Having said that, on to your question. First - the view (see comments in code):</p> <pre><code>def tool_detail(request, tool): contact_form(ContactForm, request) tags = Tool.tags.all() tool = get_objec...
1
2016-08-03T00:34:13Z
[ "python", "django", "django-models", "django-templates", "django-views" ]
ssh by a python cgi script is not working
38,732,098
<p>I have a couple of things to ask.I am getting following error while trying to ssh remote host from a python CGI.</p> <pre><code>Could not create directory '/var/www/.ssh'. Failed to add the RSA host key for IP address '17.172.221.39' to the list of known hosts (/var/www/.ssh/known_hosts). Permission denied (gssapi-...
0
2016-08-02T23:36:16Z
38,736,171
<p>Web server process is owned by apache user not as root.</p> <ol> <li>Make sure that apache user have password less access to other server</li> <li>SELinux should be disabled</li> </ol> <p>Refer : <a href="http://wccandlinux.blogspot.in/2016/07/how-to-run-ssh-command-from-apache.html" rel="nofollow">http://wccandli...
0
2016-08-03T06:41:20Z
[ "python", "linux", "apache", "ssh", "cgi" ]
How do reindex multilevel columns
38,732,188
<p>Version info:</p> <pre><code>print(sys.version) 3.5.1 |Anaconda 4.1.0 (64-bit)| (default, Jun 15 2016, 15:29:36) [MSC v.1900 64 bit (AMD64)] </code></pre> <p>I have columns in a data frame that look like this (latitude and longitude are multilevel columns):</p> <pre><code>+------------+---------------+-----------...
3
2016-08-02T23:45:38Z
38,732,337
<p>This will do the trick:</p> <pre><code>data2 = pd.DataFrame(data1.values, columns=newColumns) </code></pre> <p>And also this:</p> <pre><code>data1.columns = newColumns </code></pre>
2
2016-08-03T00:05:16Z
[ "python", "windows", "pandas" ]
Jupyter NoteBook: draw a graph on the Notebook instead of save the file to the disk
38,732,204
<p>I have the following code:</p> <p><a href="http://i.stack.imgur.com/SPvGB.png" rel="nofollow"><img src="http://i.stack.imgur.com/SPvGB.png" alt="enter image description here"></a></p> <p>Is it possible to print the graph just inside the Notebook instead of saving as a file? Thanks!</p>
0
2016-08-02T23:47:14Z
38,732,289
<p>Yes, use <code>matplotlib</code>:</p> <pre><code> import matplotlib.pyplot as plt nx.draw(G) plt.show() </code></pre> <p><a href="http://www.python-course.eu/networkx.php" rel="nofollow">source</a></p>
0
2016-08-02T23:57:46Z
[ "python", "jupyter-notebook" ]
Jupyter NoteBook: draw a graph on the Notebook instead of save the file to the disk
38,732,204
<p>I have the following code:</p> <p><a href="http://i.stack.imgur.com/SPvGB.png" rel="nofollow"><img src="http://i.stack.imgur.com/SPvGB.png" alt="enter image description here"></a></p> <p>Is it possible to print the graph just inside the Notebook instead of saving as a file? Thanks!</p>
0
2016-08-02T23:47:14Z
38,732,344
<p>Use draw in the following manner :</p> <pre><code>draw(G, show='ipynb') </code></pre> <p>If you want all graphs to be drawn inline, then you can set a global parameter.</p> <pre><code>from nxpd import nxpdParams nxpdParams['show'] = 'ipynb' draw(G) </code></pre> <p>But im not sure this will work with Jupyter, th...
0
2016-08-03T00:06:03Z
[ "python", "jupyter-notebook" ]
Jupyter NoteBook: draw a graph on the Notebook instead of save the file to the disk
38,732,204
<p>I have the following code:</p> <p><a href="http://i.stack.imgur.com/SPvGB.png" rel="nofollow"><img src="http://i.stack.imgur.com/SPvGB.png" alt="enter image description here"></a></p> <p>Is it possible to print the graph just inside the Notebook instead of saving as a file? Thanks!</p>
0
2016-08-02T23:47:14Z
38,735,487
<p>If you are looking to plot the plots inline inside your jupiter-notebook:</p> <pre><code>import matplotlib.pyplot as plt %matplotlib inline </code></pre> <p><a href="http://i.stack.imgur.com/xvagS.png" rel="nofollow"><img src="http://i.stack.imgur.com/xvagS.png" alt="Plotting inline in the notebook"></a></p>
1
2016-08-03T05:56:08Z
[ "python", "jupyter-notebook" ]
How do I loop through UID's in Firebase
38,732,279
<p>I am using Python to go through a Firebase DB to return an array of objects, then pick one at random and return its values. I've been using a small test JSON DB that I manually build and import into Firebase. When I do this, the DB's child node's are <code>0, 1, 2</code> etc... Using the code below - I can iterate t...
0
2016-08-02T23:57:00Z
38,751,033
<p>What needs to be done is to strip the dictionary <code>result</code> of the parent nodes using a <code>for-loop</code> and the <code>.items()</code> Python method - through the key-values (<code>k,v</code>) and <code>.append</code> the values (<code>v</code>). </p> <p>This strips the <code>result</code> of the pare...
0
2016-08-03T18:23:11Z
[ "python", "arrays", "json", "firebase", "firebase-database" ]
Can Python Staticmethod Call Another Local Method?
38,732,287
<p>In Python, within a class, can a staticmethod call on another local function/method defined within the same class?</p> <p>I tried the following code and obtained an error message saying foo1() is not defined.</p> <pre><code>class trialOne(object): @staticmethod def foo1(): a = 3.1 return a...
-2
2016-08-02T23:57:35Z
38,732,351
<pre><code>class Tester: def local(self): print "I'm a local!" @staticmethod def another_stat(): print "I'm a static!" @staticmethod def stat(inst): inst.local() Tester.another_stat() t = Tester() Tester.stat(t) # Out: # I'm a local! # I'm a static! </code></pre>...
1
2016-08-03T00:06:50Z
[ "python", "static-methods" ]
Set bottom, top, left, right tick visibility in matplotlibrc
38,732,407
<p><a href="http://stackoverflow.com/a/12998531/6421322">Here</a> is a question about turning off the ticks on a given side of a set of axes by using the <code>tick_params</code> method. I want to change the <code>top</code> and <code>right</code> properties to off by default in my <code>matplotlibrc</code> but I don't...
4
2016-08-03T00:14:18Z
38,744,038
<p>I'm pretty new to matplotlib myself, but i belive you can do something like this:</p> <pre><code>pl.tick_params(bottom="off", top="off") </code></pre>
1
2016-08-03T12:43:04Z
[ "python", "matplotlib" ]
Set bottom, top, left, right tick visibility in matplotlibrc
38,732,407
<p><a href="http://stackoverflow.com/a/12998531/6421322">Here</a> is a question about turning off the ticks on a given side of a set of axes by using the <code>tick_params</code> method. I want to change the <code>top</code> and <code>right</code> properties to off by default in my <code>matplotlibrc</code> but I don't...
4
2016-08-03T00:14:18Z
38,750,147
<p>After sleuthing around on the matplotlib github, I found what I was looking for: the <a href="https://github.com/matplotlib/matplotlib/blob/v2.x/matplotlibrc.template" rel="nofollow">upcoming version 2.x branch</a>, at the time I am writing this, has <code>xtick.top</code>, etcetera, as parameters in the new matplot...
1
2016-08-03T17:28:27Z
[ "python", "matplotlib" ]
How should I properly use Selenium
38,732,496
<p>I'm trying to get one number from Yahoo Finance (<a href="http://finance.yahoo.com/quote/AAPL/financials?p=AAPL" rel="nofollow">http://finance.yahoo.com/quote/AAPL/financials?p=AAPL</a>), Balance Sheet, Total Stockholder Equity. If I inspect the element I get this:</p> <pre><code>&lt;span data-reactid=".1doxyl2xoso...
1
2016-08-03T00:27:06Z
38,733,659
<p>Actually your all locator looks like invalid, try using <code>find_element_by_css_selector</code> as below :-</p> <pre><code>elem = browser.find_element_by_css_selector("span[data-reactid *= 'TOTAL_STOCKHOLDER_EQUITY']") </code></pre> <p>Note: <code>find_element_by_partial_text</code> is use to locate only <code>a...
1
2016-08-03T02:57:38Z
[ "python", "python-3.x", "selenium-webdriver", "web-scraping", "yahoo-finance" ]
TensorFlow Master and Worker Service
38,732,502
<p>I am trying to understand the exact roles of the master and worker service in TensorFlow.</p> <p>So far I understand that each TensorFlow task that I start is associated with a <code>tf.train.Server</code> instance. This instance exports a "master service" and "worker service" by implementing the <a href="https://w...
2
2016-08-03T00:28:05Z
38,749,421
<blockquote> <p>1st Question: Am I right that this means, that ONE task is only associated with ONE worker?</p> </blockquote> <p>This is the typical configuration, yes. Each <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/train.html#Server" rel="nofollow"><code>tf.train.Server</code></a> instanc...
2
2016-08-03T16:48:30Z
[ "python", "tensorflow" ]
Passing xPath translate function in Scrapy not working for special characters
38,732,516
<p>I'm building a Scrapy spider which takes the xpath query as an input parameter.</p> <p>The specific page I'm trying to scrape has line feeds, new lines and other characters within the price text field and I'm using the <code>translate()</code> function to remove them.</p> <p>The selector works fine with the transl...
0
2016-08-03T00:30:38Z
38,733,484
<p>Try using the <code>normalize-space()</code> XPath function in your selector:</p> <pre><code>scrapy crawl generic -a start_url=&lt;URL&gt; -a \ allowed_domains=danmurphys.com.au \ -a "xpath_string=normalize-space(//span[@class='price'][1]/text())" </code></pre> <p>In your <code>parse</code> method, you can...
0
2016-08-03T02:39:03Z
[ "python", "xpath", "scrapy" ]
My recursive solution in Python is appending and replacing all current items in answer list with the current list
38,732,529
<p>I am trying to implement a Python solution to the programming question of finding all subsets in an integer array. I should return an array that contains all subsets of the integer array with no duplicates and sorted.</p> <pre><code>def subsetHelper(cur_set, index, A, ans): if index &gt;= len(A): print ...
4
2016-08-03T00:32:21Z
38,732,712
<p>there are 2 problem here: the problem first is that you <code>ans.extend</code> instead of <code>ans.append</code>, once change that we get the second problem which is empty list at the end and the reason is that append only add to the list <code>ans</code> a reference to <code>cur_set</code> which you end up removi...
1
2016-08-03T00:55:21Z
[ "python", "list" ]
My recursive solution in Python is appending and replacing all current items in answer list with the current list
38,732,529
<p>I am trying to implement a Python solution to the programming question of finding all subsets in an integer array. I should return an array that contains all subsets of the integer array with no duplicates and sorted.</p> <pre><code>def subsetHelper(cur_set, index, A, ans): if index &gt;= len(A): print ...
4
2016-08-03T00:32:21Z
38,732,840
<p>The problem is you're re-using the cur_set list object between calls so even after <code>cur_set</code> has been added to <code>ans</code>, futures calls to <code>susetHelper</code> still modify the list, specifically future calls to <code>cur_set.pop()</code> empty the list. You can solve this problem by storing a ...
0
2016-08-03T01:17:20Z
[ "python", "list" ]
If myStr = 'test', why does myStr[4] produce error out of range but myStr[4:] does not?
38,732,601
<p>I'm using recursion to iterate through the values of a string. When I get past the last character, it's allowing me to use that index position as an empty string <code>""</code> instead of giving an error. Why is that?</p> <pre><code>myStr = 'test' print(myStr[4]) </code></pre> <p>produces an error</p> <pre><code...
3
2016-08-03T00:40:25Z
38,732,612
<p>Slicing is not bounds-checked by the built-in types. If the array indices are out of bounds, it will automatically truncate then at the right places.</p>
6
2016-08-03T00:42:53Z
[ "python", "recursion" ]
If myStr = 'test', why does myStr[4] produce error out of range but myStr[4:] does not?
38,732,601
<p>I'm using recursion to iterate through the values of a string. When I get past the last character, it's allowing me to use that index position as an empty string <code>""</code> instead of giving an error. Why is that?</p> <pre><code>myStr = 'test' print(myStr[4]) </code></pre> <p>produces an error</p> <pre><code...
3
2016-08-03T00:40:25Z
38,732,669
<p><a href="https://docs.python.org/3/tutorial/introduction.html#strings" rel="nofollow">Python 3.0 documentation </a>says about strings that</p> <blockquote> <p>Attempting to use an index that is too large will result in an error</p> </blockquote> <p>and</p> <blockquote> <p>out of range slice indexes are handle...
0
2016-08-03T00:49:10Z
[ "python", "recursion" ]
If myStr = 'test', why does myStr[4] produce error out of range but myStr[4:] does not?
38,732,601
<p>I'm using recursion to iterate through the values of a string. When I get past the last character, it's allowing me to use that index position as an empty string <code>""</code> instead of giving an error. Why is that?</p> <pre><code>myStr = 'test' print(myStr[4]) </code></pre> <p>produces an error</p> <pre><code...
3
2016-08-03T00:40:25Z
38,732,703
<p>Because array accesses are defined such that it's an error for a lone index to be out of range, but not for (part or all of) a slice to be. If any part of a slice is out of range, it simply yields no results, rather than triggering an error.</p>
0
2016-08-03T00:53:28Z
[ "python", "recursion" ]
How do I have two elements inside an index when using python list comprehensions?
38,732,615
<p>I am trying to fully capitalise a word as well as include its length in a new list, using list comprehension.</p> <p>For example if I entered <code>wordLengths(["hello","bye","greetings"])</code> I am wanting this output.</p> <pre><code>[("HELLO",5),("BYE",3),("GREETINGS",9)] </code></pre> <p>This is my current ...
1
2016-08-03T00:43:08Z
38,732,636
<p>You need to do the both in one list comprehension:</p> <pre><code>[(i.upper(), len(i)) for i in myWords] </code></pre>
4
2016-08-03T00:45:38Z
[ "python", "list-comprehension" ]
How do I have two elements inside an index when using python list comprehensions?
38,732,615
<p>I am trying to fully capitalise a word as well as include its length in a new list, using list comprehension.</p> <p>For example if I entered <code>wordLengths(["hello","bye","greetings"])</code> I am wanting this output.</p> <pre><code>[("HELLO",5),("BYE",3),("GREETINGS",9)] </code></pre> <p>This is my current ...
1
2016-08-03T00:43:08Z
38,732,637
<p>Your method is returning a tuple of two lists, and what you are actually trying to do is create a list of tuples.</p> <p>Your comprehension would simply be: </p> <pre><code>[(word.upper(), len(word)) for word in words] </code></pre> <p>So, your method can now be re-written as: </p> <pre><code>def wordLengths(myW...
2
2016-08-03T00:45:42Z
[ "python", "list-comprehension" ]
Drawing a cuboid to image
38,732,635
<p>I'm in the process of moving a significant application to Python from PHP. All is well, except one particular issue that I can't seem to get to the bottom of.</p> <p>The old application uses a PHP library Image_3D to draw some cuboids to an image (SVG, though that's not important) and display them on the web page.<...
0
2016-08-03T00:45:33Z
38,757,150
<p>You could use either VPython of matplotlib for this. In matplotlib I'd use a 3d box for your bars, and than another for the frame, and turn off the axes. Here's an examples:</p> <p><a href="http://i.stack.imgur.com/AsfX4.png" rel="nofollow"><img src="http://i.stack.imgur.com/AsfX4.png" alt="enter image descriptio...
1
2016-08-04T01:37:14Z
[ "python", "matplotlib" ]
Python Kivy Raspberrypi Error GPIO Channel
38,732,644
<p>Im create class for add widgets rectangle in many different positions my layout. Im runing return error GPIO most setup(), im configure port in line 11, whats problem in my code ?</p> <pre><code>&gt; Traceback (most recent call last): File "plantadeira.py", line 50, &gt; in &lt;module&gt; &gt; MainApp().ru...
0
2016-08-03T00:46:28Z
38,747,861
<p>The problem in your code is when you call:<br> <code>GPIO.wait_for_edge(int(pin), GPIO.RISING, timeout=1000)</code><br> you can not use <code>int(pin)</code> but rather <code>pin_1</code> which you defined before the class.<br> So you could call it like this instead:<br> <code>GPIO.wait_for_edge(pin_1, GPIO.RISIN...
0
2016-08-03T15:29:30Z
[ "python", "raspberry-pi", "kivy", "gpio" ]
Regular Expression to match multiple postive lookahead groups
38,732,671
<p>Here is the regex I have so far: </p> <pre><code>^(?=.*(option1|option2))(?=.*(option3|option4))(?=.*(option5|option6))(?=.*(option7|option8))(?=.*(option9|option10)).*$ </code></pre> <p>I am not hip on the regex language so I'll make my own definitions:</p> <p>category 1 is (option1|option2), category 2 is (opti...
2
2016-08-03T00:49:28Z
38,732,724
<p>I don't think this is implementable with regex, or if it is (maybe in some steps), it's not a proper way to go.</p> <p>Instead you can store your options in a set like:</p> <pre><code>options = {(option1, option2), (option3, option4), (option5, option6), (option7, option8), (option9, option10)} </code></pre> <p>T...
1
2016-08-03T00:57:39Z
[ "python", "regex", "regex-lookarounds" ]
Regular Expression to match multiple postive lookahead groups
38,732,671
<p>Here is the regex I have so far: </p> <pre><code>^(?=.*(option1|option2))(?=.*(option3|option4))(?=.*(option5|option6))(?=.*(option7|option8))(?=.*(option9|option10)).*$ </code></pre> <p>I am not hip on the regex language so I'll make my own definitions:</p> <p>category 1 is (option1|option2), category 2 is (opti...
2
2016-08-03T00:49:28Z
38,734,652
<p>Here's a regex that does what you want (in <code>VERBOSE</code> mode):</p> <pre><code>^ (?= .* (?: option1 | option2 ) () )? (?= .* (?: option3 | option4 ) () )? (?= .* (?: option5 | option6 ) () )? (?= .* (?: option7 | option8 ) () )? (?= .* (?: option9 | option10 ) () )? .*$ (?: \1\2\3 | \1\2\4 | \1\2\5 | \1\...
1
2016-08-03T04:52:46Z
[ "python", "regex", "regex-lookarounds" ]
Matasano challenge Python Set 1-> 3, unknown errors in code
38,732,699
<p>I'm trying to solve the Matasano challenge set 1-> 3 that is Single-byte XOR cipher and reverse it . I think i understand the concept to solve but my solution is giving some errors : </p> <pre><code> Traceback (most recent call last): File "C:\crypto\python\breakXor.py", line 59, in &lt;module&gt; print(transforma...
0
2016-08-03T00:52:54Z
38,732,716
<p>xor is expecting 2 lists; you are passing it a list and an integer.</p>
0
2016-08-03T00:56:10Z
[ "python", "cryptography" ]
Matasano challenge Python Set 1-> 3, unknown errors in code
38,732,699
<p>I'm trying to solve the Matasano challenge set 1-> 3 that is Single-byte XOR cipher and reverse it . I think i understand the concept to solve but my solution is giving some errors : </p> <pre><code> Traceback (most recent call last): File "C:\crypto\python\breakXor.py", line 59, in &lt;module&gt; print(transforma...
0
2016-08-03T00:52:54Z
38,733,056
<p>Your algorithm is wrong, the <code>scoreBoard</code> similar this, refs <a href="https://github.com/tomdeakin/Matasano-Crypto-Challenges/blob/master/textutils.py" rel="nofollow">Matasano-Crypto-Challenges from github</a></p> <pre><code>def scoreBoard(text): text = text.upper() frequencies = {} for lette...
0
2016-08-03T01:49:20Z
[ "python", "cryptography" ]
Is there way merge PDF files in reportlib with python3?
38,732,722
<p>I want to merge several PDF files and make single PDF file</p> <p>but I couldnt find API in reportilb width python </p> <p>How can I find that?</p> <p>I also use ubuntu OS is there any good utility for my question?</p>
2
2016-08-03T00:57:34Z
38,732,749
<p>Use <a href="https://www.pdflabs.com/tools/pdftk-server/" rel="nofollow">pdftk</a>, a nice command-line tool for this kind of thing.</p>
2
2016-08-03T01:02:19Z
[ "python", "ubuntu" ]
readline() returns bracket
38,732,799
<p>I wrote some codes to get some lines from .txt like below and its keep returning lines with brackets which I did not intend. Could you help me?</p> <p>codes:</p> <pre><code>#!/bin/python i=1 f=open("name.txt","r") while(i&lt;=225): x=f.readline().splitlines() print("mol new %s.bgf"%(x)) i+=1 f.close() </code></...
4
2016-08-03T01:09:52Z
38,732,847
<p>The <code>readline</code> function reads a single line from the file. Then you ask to split the line into a <strong><em>list</em></strong> of lines (which will give you a list of only one line since that's what you have).</p> <p>Don't split the <em>single line</em>. Instead <em>strip</em> the string (to remove lead...
3
2016-08-03T01:17:57Z
[ "python", "readline" ]
readline() returns bracket
38,732,799
<p>I wrote some codes to get some lines from .txt like below and its keep returning lines with brackets which I did not intend. Could you help me?</p> <p>codes:</p> <pre><code>#!/bin/python i=1 f=open("name.txt","r") while(i&lt;=225): x=f.readline().splitlines() print("mol new %s.bgf"%(x)) i+=1 f.close() </code></...
4
2016-08-03T01:09:52Z
38,732,860
<p>This is because <code>f.readline().splitlines()</code> returns the line in a list form containing a single element. </p> <p>Try this instead:</p> <pre><code>x = f.readline().splitlines() x = x[0] </code></pre>
1
2016-08-03T01:20:14Z
[ "python", "readline" ]
readline() returns bracket
38,732,799
<p>I wrote some codes to get some lines from .txt like below and its keep returning lines with brackets which I did not intend. Could you help me?</p> <p>codes:</p> <pre><code>#!/bin/python i=1 f=open("name.txt","r") while(i&lt;=225): x=f.readline().splitlines() print("mol new %s.bgf"%(x)) i+=1 f.close() </code></...
4
2016-08-03T01:09:52Z
38,732,890
<p>Making minimal changes to your code, try:</p> <pre><code>i=1 f=open("name.txt","r") while(i&lt;=225): x=f.readline().rstrip('\n') print("mol new %s.bgf"%(x)) i+=1 f.close() </code></pre> <p>This produces output like:</p> <pre><code>mol new 02.ala.r49r50.TRK820.no_0.rnd_1.c14421.f.c.bgf mol new 04.ala.r44r45.TR...
4
2016-08-03T01:24:51Z
[ "python", "readline" ]
readline() returns bracket
38,732,799
<p>I wrote some codes to get some lines from .txt like below and its keep returning lines with brackets which I did not intend. Could you help me?</p> <p>codes:</p> <pre><code>#!/bin/python i=1 f=open("name.txt","r") while(i&lt;=225): x=f.readline().splitlines() print("mol new %s.bgf"%(x)) i+=1 f.close() </code></...
4
2016-08-03T01:09:52Z
38,732,935
<p>You don't need to call the splitlines() method on the results of readline()<p> file.readline() returns one line of the file, including the trailing newline. <p> .splitlines() is getting rid of the newline by using it as a delimiter and giving you a LIST of lines with only 1 item. The brackets are coming from the st...
1
2016-08-03T01:31:15Z
[ "python", "readline" ]
Create object which has nested orderDict
38,732,803
<p>my store_categories_data has a nested orderDict like below</p> <pre><code>store_categories_data OrderedDict([('product', OrderedDict([('image', OrderedDict([('image', &lt;InMemoryUploadedFile: bag.jpg (image/jpeg)&gt;)])), ('name_of_product', 'Ladies Pink Bag'), ('description', 'description'), ('price', Decimal('...
1
2016-08-03T01:10:15Z
38,735,241
<p>assuming the nesting in your OrderedDict maps to foreign key relationships in a relational database, you just need to explicitly create all 3 records in order, from the inside out. Something like the below should be enough to carry it the rest of the way.</p> <p>Note: unpacking dicts to keyword args with <code>**</...
0
2016-08-03T05:39:12Z
[ "python", "django", "api", "python-3.x", "django-rest-framework" ]
Count number of characters for each line pyspark
38,732,846
<p>I am able to count total number of each character in the entire document.</p> <p>My document:</p> <pre><code>ATATCCCCGGGAT ATCGATCGATAT </code></pre> <p>Calculating total number of each characters in the document:</p> <pre><code>data=sc.textFile("data.txt") counts=data.flatMap(lambda x:[(c,1) for c in x]).reduce...
0
2016-08-03T01:17:43Z
38,749,464
<p>Try:</p> <pre><code>&gt;&gt;&gt; counts.values().sum() 25 </code></pre> <p>or</p> <pre><code>&gt;&gt;&gt; sum(counts.collectAsMap().values()) 25 </code></pre>
1
2016-08-03T16:50:56Z
[ "python", "apache-spark", "pyspark" ]
Count number of characters for each line pyspark
38,732,846
<p>I am able to count total number of each character in the entire document.</p> <p>My document:</p> <pre><code>ATATCCCCGGGAT ATCGATCGATAT </code></pre> <p>Calculating total number of each characters in the document:</p> <pre><code>data=sc.textFile("data.txt") counts=data.flatMap(lambda x:[(c,1) for c in x]).reduce...
0
2016-08-03T01:17:43Z
38,757,187
<p>If what you want is "Count the number of characters for each line with pyspark" and <strong>not</strong> the total number of each characters for each line, this will do the trick:</p> <pre><code>data.map(lambda x:len(x)).collect() &gt;&gt;&gt; [13, 12] </code></pre> <p>If you want the index of the line among the n...
0
2016-08-04T01:43:17Z
[ "python", "apache-spark", "pyspark" ]
Join and delete lines
38,732,944
<p>NOTE: The solution needs to be something I can embed in python. </p> <p>I have a file with 800,000+ lines. The lines are grouped. The beginning of each group of rows starts with "IMAGE" followed by one row that starts with "HISTO" and then at least one, but usually multiple, rows that start with "FRAG".</p> <p>I n...
-1
2016-08-03T01:33:22Z
38,733,003
<h3>Python solution</h3> <pre><code>with open('Input.txt') as f: for line in f: line = line.rstrip() if line.startswith('&gt;IMAGE'): img = line continue if line.startswith('&gt;HIST'): continue print('%s %s' % (img, line.lstrip('&gt;'))) </code><...
1
2016-08-03T01:40:48Z
[ "python" ]
Join and delete lines
38,732,944
<p>NOTE: The solution needs to be something I can embed in python. </p> <p>I have a file with 800,000+ lines. The lines are grouped. The beginning of each group of rows starts with "IMAGE" followed by one row that starts with "HISTO" and then at least one, but usually multiple, rows that start with "FRAG".</p> <p>I n...
-1
2016-08-03T01:33:22Z
38,733,582
<p>Try this solution:</p> <pre><code>with open('in.txt', 'r') as fin, open('out.txt', 'w') as fout: for line in fin: if line.startswith('HISTO'): continue elif line.startswith('IMAGE'): prefix = line.strip() elif line.startswith('FRAG'): fout.write(prefi...
0
2016-08-03T02:49:04Z
[ "python" ]
Generalized numpy point-matrix multiplication function that produces consistent outputs with inputs of varying shapes
38,732,961
<p>I want to make a generalized function that does point-matrix transformations with inputs of varying shapes, using the following definitions:</p> <ul> <li>Array <code>p</code> is an array of points of any shape, with leaf elements of xyz vectors such as: (Parent shape P,...,leaf xyz vector p)</li> <li>Array <code>M<...
2
2016-08-03T01:35:14Z
38,733,517
<p>I like to make test cases where dimensions differ as much as possible. So for example if <code>p</code> has a last dimension of <code>3</code>, the first will anything but 3. And if the last dimensions of <code>M</code> are <code>(4,4)</code> I'd avoid use of 4 in the other dimensions as well. That way if the cor...
0
2016-08-03T02:42:38Z
[ "python", "arrays", "numpy", "matrix" ]
Python import fails when called from PHP Page
38,732,974
<p>When I am running my code from the terminal I am getting the output. But when I am running the same from my php page using the following:</p> <pre><code>$command = escapeshellcmd($commandstring); $output = shell_exec($command); </code></pre> <p>It gives no output..no error..nothing..</p> <p>When I remove this imp...
0
2016-08-03T01:37:14Z
38,733,025
<p>You can try to add " 2>&amp;1" at the end of $commandstring, so the stderr will be redirect to stdout and will be catched by shell_exec(). Maybe some error message will appear.</p> <p>If this didn't solve your issue, try to run a simple "Hello world" python script from your PHP. You will know if the problem come fr...
0
2016-08-03T01:45:27Z
[ "php", "python" ]
Using openpyxl to search for a cell in one column and then to print out the row for that relevant cell
38,732,979
<p>For instance, I want to be able to type into my program via user input the data and then print the row relevant to that cell. Ideally, if 1/08/2016 was inputted into the program then it will run through column 'A' and then locates the relevant date. If date is found then it will print the date and then the relevant ...
0
2016-08-03T01:37:26Z
38,760,574
<p>If you only want to look in column A for the input I would do something like this:</p> <pre><code>for i in range(1,ws.max_row): if ws.cell(row=row, column=0).value == date: for j in range(i, ws.max_column): print (ws.cell(row=i, column=j).value) </code></pre> <p>Assuming you want to print e...
0
2016-08-04T07:04:34Z
[ "python", "excel", "openpyxl" ]
I am getting this error using django taggit "Can't call add with a non-instance manager"
38,733,072
<p>I'm trying to add a few tags to my post object when I save them, using django taggit. So I tried this</p> <pre><code> def panties(): from lxml import html pan_url = 'http://www.ideos.org' shtml = requests.get(pan_url, headers=headers) soup = BeautifulSoup(shtml.text, 'html5lib') ...
0
2016-08-03T01:51:41Z
38,735,096
<p>You are trying to add tags to the Post manager. You want to add tags to a Post instance.</p> <p>You need a saved Post instance before you can add the tags</p> <p>e.g.</p> <p><code>post_instance = Post.objects.get_or_create(foo=bar) tags = post_instance.tags.add("Musica", "video") </code></p>
1
2016-08-03T05:28:44Z
[ "python", "django", "django-taggit" ]
I am getting this error using django taggit "Can't call add with a non-instance manager"
38,733,072
<p>I'm trying to add a few tags to my post object when I save them, using django taggit. So I tried this</p> <pre><code> def panties(): from lxml import html pan_url = 'http://www.ideos.org' shtml = requests.get(pan_url, headers=headers) soup = BeautifulSoup(shtml.text, 'html5lib') ...
0
2016-08-03T01:51:41Z
38,750,035
<p>With the aide of @luke_aus answer I figured it out. this is just what my code looks like now for others who may want to see how to actually do it. It went from this.</p> <pre><code> for entry in entries: post = Post() post.title = entry['text'] title = post.title i...
0
2016-08-03T17:21:39Z
[ "python", "django", "django-taggit" ]
Django JSON AJAX data order not right when attached to table
38,733,160
<p>What I want is, at the front-end, when the button pressed, retrieve the data from the back-end using Ajax, then attach them to a table. I'm using Django 1.9.</p> <p>I managed to do so. However, each value does not match each column, just as the picture shows:</p> <p><img src="http://i.stack.imgur.com/cdxzC.png" al...
1
2016-08-03T02:00:45Z
38,735,769
<p>You can replace this</p> <pre><code>ntd.html(value); </code></pre> <p>with this</p> <pre><code>ntd.text(value) </code></pre> <p>Just try it,my brother.</p>
0
2016-08-03T06:15:23Z
[ "jquery", "python", "json", "ajax", "django" ]
Django JSON AJAX data order not right when attached to table
38,733,160
<p>What I want is, at the front-end, when the button pressed, retrieve the data from the back-end using Ajax, then attach them to a table. I'm using Django 1.9.</p> <p>I managed to do so. However, each value does not match each column, just as the picture shows:</p> <p><img src="http://i.stack.imgur.com/cdxzC.png" al...
1
2016-08-03T02:00:45Z
38,740,039
<p>One way to do it will be to create each row with td's with a class name that corresponds to the JSON object key for each object, then add the data from each object to the corresponding td.</p> <p>e.g. generate the table per ajax object (rather than per click as per this example) <a href="https://jsbin.com/sihudumer...
0
2016-08-03T09:46:14Z
[ "jquery", "python", "json", "ajax", "django" ]
Customising the output of items using django-autocomplete-light v3
38,733,177
<p>In earlier versions of django-autocomplete-light you could use a template to render each returned entry, which included the ability to insert custom HTML </p> <p>I can't figure out how to do that using the regular API, so I'm trying to add it in.</p> <p>So far I have a class like this which uses <code>mark_safe</c...
0
2016-08-03T02:03:10Z
39,628,226
<p>As always the answer is subclassing, in this case the tip is to override <code>get_result_title</code>:</p> <pre><code>class CustomisableAutocomplete(autocomplete.Select2QuerySetView): template_name = "autocomplete_light/item.html" def get_result_title(self, result): """Return the label of a result...
0
2016-09-22T00:00:42Z
[ "jquery", "python", "django", "django-autocomplete-light" ]
Using Requests Post to login to this site not working
38,733,204
<p>I know there are tons of threads and videos on how to do this, I've gone through them all and am in need of a little advanced guidance.</p> <p>I am trying to log into this webpage where I have an account so I can send a request to download a report.<br> First I send the <code>get</code> request to the login page, t...
0
2016-08-03T02:05:42Z
38,741,904
<p>You don't need to send separate requests for authorization and file download. You need to send single POST with specifying credentials. Also in most cases you don't need to send headers. In common your code should looks like follow:</p> <pre><code>from requests.auth import HTTPBasicAuth url_to_download = "http://s...
1
2016-08-03T11:10:06Z
[ "python", "post", "login", "python-requests" ]