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
NoReverseMatch at /accounts/login/ form action query?
39,439,048
<p>Im trying to learn django, but i cant find the answer to this anywhere, or at-least not in simple terms! im trying to implement the included login view in my project and ive tried using the example html that the documentation uses and i get this error.</p> <pre><code>Template error: In template C:\Users\Owner\Doc...
-1
2016-09-11T17:58:53Z
39,439,239
<p>Action="{% url 'login' %} : this means when you submit the form it will take you search for the url named 'login' in your urls.py and execute the view. but there isnt anything named login in your urls.py.you can try to edit the last line of urls.py as : url(r'^accounts/login/$', auth_views.login, name='login...
0
2016-09-11T18:19:41Z
[ "python", "django" ]
How do I get the index of a column by name?
39,439,054
<p>Given a <code>DataFrame</code></p> <pre><code>&gt;&gt;&gt; df x y z 0 1 a 7 1 2 b 5 2 3 c 7 </code></pre> <p>I would like to find the index of the column by name, e.g., <code>x</code> -> 0, <code>z</code> -> 2, &amp;c.</p> <p>I can do</p> <pre><code>&gt;&gt;&gt; list(df.columns).index('y') 1 </code...
1
2016-09-11T17:59:40Z
39,439,067
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_loc.html" rel="nofollow"><code>Index.get_loc</code></a>:</p> <pre><code>print (df.columns.get_loc('z')) 2 </code></pre> <p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.se...
1
2016-09-11T18:00:58Z
[ "python", "python-2.7", "pandas" ]
Fitting with monte carlo in python
39,439,079
<p>Hello I use a python package called <code>emcee</code> to fit a function to some data points. The fit looks great, but when I want to plot the value of each parameter at each step I get this: <a href="http://i.stack.imgur.com/t0cpX.png" rel="nofollow"><img src="http://i.stack.imgur.com/t0cpX.png" alt="enter image de...
0
2016-09-11T18:02:19Z
39,725,212
<p>I would not say that your function is converging faster than the <code>emcee</code> line-fitting example you're linked to. In the example, the walkers start exploring the most likely values in the parameter space almost immediately, whereas in your case it takes more than 200 iterations to reach the high probability...
2
2016-09-27T12:52:32Z
[ "python", "curve-fitting", "montecarlo" ]
Odd behavior when multiplying numpy array by a constant (e.g. 1/100)
39,439,279
<p>I create the following random array and I multiply it times a constant but get an unexpected result (zeros instead of the answer I expect):</p> <pre><code>In [4]: A = np.random.rand(1,11) In [5]: A Out[5]: array([[ 0.15138551, 0.41573765, 0.0212214 , 0.44955909, 0.27013062, 0.37835199, 0.89712845, ...
-1
2016-09-11T18:24:15Z
39,439,298
<p>You are using python2 and <code>1/100</code> is integer division, resulting in <code>0</code>.</p> <p>Use floating points:</p> <pre><code>A * (1.0/100) </code></pre> <p>or use a future import:</p> <pre><code>from __future__ import division </code></pre> <p>to enable floating point division for integers, too.</p...
4
2016-09-11T18:26:27Z
[ "python", "numpy", "python-2.x" ]
What's the most efficient algorithm for topologically sorting a (special case of a) directed acyclic graph?
39,439,366
<p>I have a data set that is a special case of a directed acyclic graph (DAG). The nodes in my DAG have either 0 or 1 arcs. All arcs are equally weighted (that is, the only information contained in an arc is the node it points at, no "distance" or "cost" or "weight").</p> <p>My users will input nodes in a semi-random ...
0
2016-09-11T18:33:38Z
39,439,453
<p>So far this is the best algorithm I've been able to come up with:</p> <pre><code>def topo_sort(nodes): objects = {} # maps node names back to node objects graph = OrderedDict() # maps node names to arc names output = [] for node in nodes: objects[node.name] = node graph[no...
0
2016-09-11T18:44:58Z
[ "python", "algorithm", "python-3.x", "directed-acyclic-graphs", "topological-sort" ]
subprocess.Popen executes .sh differently then subprocess.call
39,439,385
<p>I'm trying to run parsey mcparseface from a subprocess. I get different results when running Popen vs call and I'm wondering why this is. This works.</p> <pre><code>process = subprocess.Popen("./syntaxnet/demo.sh", cwd="/home/kahless/models/syntaxnet") </code></pre> <p>This does not.</p> <pre><code>process = subp...
0
2016-09-11T18:35:53Z
39,439,476
<p>Are you sure it ever finishes?</p> <p>Looks like your code hangs. Perhaps it takes user input?</p> <p><code>subprocess.call()</code> waits until it finishes so as <code>wait()</code> and <code>communicate()</code></p>
0
2016-09-11T18:46:58Z
[ "python" ]
Subtract value from netCDF dimension
39,439,534
<p>How can I use nco tools or any other netcdf toolkit to subtract a specific value from one of the dimensions in a netCDF?</p> <p>E.g.</p> <pre><code>ncdump –v time –t file.nc </code></pre> <p>gives me:</p> <pre><code>time = 10, 11, 12, 13 … </code></pre> <p>How can I subtract 10 from each value in the time...
0
2016-09-11T18:54:15Z
39,441,641
<p>Nothing is more concise than <a href="http://nco.sf.net/nco.html#ncap2" rel="nofollow" title="ncap2">ncap2</a> for this:</p> <p>ncap2 -s 'time-=10' in.nc out.nc</p> <p>ncap2 will subtract any value except 13, because that would bring bad luck.</p>
2
2016-09-11T23:30:59Z
[ "python", "netcdf", "nco" ]
Explanation for the second case that made contextlib.nested to be deprecated (Python documentation)
39,439,594
<p><code>context.nested</code> is deprecated, I'm trying to understand the rationale behind this and after reading the documentation for a quite long time, I couldn't see an example to make the second issue clear: </p> <blockquote> <p>Secondly, if the <code>__enter__()</code> method of one of the inner context manag...
2
2016-09-11T19:01:19Z
39,440,017
<p>In your example, you have the context manager <code>B</code> raising exception in the <code>__exit__</code> method. But the quote describes the inner exception being raised by the <code>__enter__</code> method. I was able to reproduce a <code>RuntimeError</code> by moving the raised exception to the <code>__enter_...
1
2016-09-11T19:47:58Z
[ "python" ]
Python module installed by issues while importing on Mac OS
39,439,622
<p>I installed <code>beautifulsoup4</code> module in <code>python2.7</code>, but import is failing.</p> <p>python module is installed under this directory.</p> <pre><code>$ls -l /Library/Python/2.7/site-packages total 1080 -rw-r--r-- 1 root wheel 119 Aug 22 2015 README drwxr-xr-x 9 root wheel 306 Sep ...
0
2016-09-11T19:03:29Z
39,439,662
<p>The module is called <code>bs4</code>, not <code>beautifulsoup4</code>, try with:</p> <pre><code>import bs4 </code></pre>
0
2016-09-11T19:07:23Z
[ "python", "osx", "python-2.7" ]
Python module installed by issues while importing on Mac OS
39,439,622
<p>I installed <code>beautifulsoup4</code> module in <code>python2.7</code>, but import is failing.</p> <p>python module is installed under this directory.</p> <pre><code>$ls -l /Library/Python/2.7/site-packages total 1080 -rw-r--r-- 1 root wheel 119 Aug 22 2015 README drwxr-xr-x 9 root wheel 306 Sep ...
0
2016-09-11T19:03:29Z
39,439,670
<p>Try this:</p> <pre><code> from bs4 import BeautifulSoup </code></pre>
0
2016-09-11T19:08:09Z
[ "python", "osx", "python-2.7" ]
python how to know the object attributes(methods) and how to know the hierarchy of the dict
39,439,629
<p>I am working with the caffe Python wrapper. I have two questions about using Python to access the data details.</p> <p>I first loaded the caffe net definition by:</p> <pre><code>net = caffe.Net('deploy_full.prototxt',caffe.TEST) </code></pre> <p>I know the net will be a object in Python, and I want to know the at...
1
2016-09-11T19:03:46Z
39,439,938
<p>Usually in that case I would just go and check <code>BlobVec</code> class source code and find out <code>__iter__</code> method implementation and all other. But in your case it will not so helpful since <code>caffe._caffe.BlobVec</code> is actually points to <a href="https://github.com/BVLC/caffe/blob/master/python...
0
2016-09-11T19:38:54Z
[ "python", "object" ]
How to print a file line by line in specific interval continuously using python?
39,439,678
<p>I have a file with 4 website names as shown below. I want to print each website name one by one continuously, in specific interval.</p> <p>sample.txt:</p> <pre><code>facebook.com gmail.com test.com yahoo.com </code></pre> <p>I have tried with following code. But its print website names only once. I wanted to webs...
1
2016-09-11T19:08:46Z
39,439,698
<p>You just need to loop over each line:</p> <pre><code>for line in test: print line </code></pre> <p>Instead of while True:</p> <p>Complete:</p> <pre><code>from time import sleep with open ("sample.txt", 'r') as test: for line in test print line sleep(3) </code></pre>
1
2016-09-11T19:10:41Z
[ "python", "python-2.7" ]
How to print a file line by line in specific interval continuously using python?
39,439,678
<p>I have a file with 4 website names as shown below. I want to print each website name one by one continuously, in specific interval.</p> <p>sample.txt:</p> <pre><code>facebook.com gmail.com test.com yahoo.com </code></pre> <p>I have tried with following code. But its print website names only once. I wanted to webs...
1
2016-09-11T19:08:46Z
39,439,712
<p>Your file object which returns an <em>iterator</em> got exhausted after the first round of calls to <code>readline()</code>. You should instead read the entire file into a list and iterate over that list successively. </p> <pre><code>from time import sleep with open ("sample.txt") as test: lines = test.readli...
1
2016-09-11T19:11:55Z
[ "python", "python-2.7" ]
How to print a file line by line in specific interval continuously using python?
39,439,678
<p>I have a file with 4 website names as shown below. I want to print each website name one by one continuously, in specific interval.</p> <p>sample.txt:</p> <pre><code>facebook.com gmail.com test.com yahoo.com </code></pre> <p>I have tried with following code. But its print website names only once. I wanted to webs...
1
2016-09-11T19:08:46Z
39,439,730
<p>The problem is that, after <code>readline()</code> reaches the end of the file, it will continue to return empty lines. You need something that ends the loop so that you can start over on the beginning of the file:</p> <pre><code>from time import sleep while True: with open ("sample.txt", 'r') as test: ...
1
2016-09-11T19:14:07Z
[ "python", "python-2.7" ]
How to grab a programs PID using python
39,439,687
<p>i'm trying to grab openvpn pid then check to see if its running but this code doesnt seem to work. it tells me 'pid' isn't an integer when the output is '432'</p> <pre><code>import psutil import time import os import subprocess proc = subprocess.Popen(["pgrep openvpn"], stdout=subprocess.PIPE, shell=True) (out, er...
0
2016-09-11T19:09:42Z
39,439,704
<p><code>'432'</code> is not an integer; it's a string that holds digits. Convert it to an integer using <code>int()</code>.</p>
1
2016-09-11T19:11:21Z
[ "python", "linux", "psutil" ]
For loop with increasing variable
39,439,724
<p>I am writing a for loop to quickly obtain user data for a set. To keep the data useful, each has to have it's own variable it saves to. So far, I have:</p> <pre><code>hey = ['11', '12', '13', '14'] x = 0 for i in hey: x += 1 showtimesx = raw_input('NOG &gt;') print showtimesx print "" print "Showtim...
-1
2016-09-11T19:13:07Z
39,439,753
<p>You want to use lists:</p> <pre><code>hey = ['11', '12', '13', '14'] showtimes = [raw_input('NOG &gt;') for i in hey] print "" print "Showtime at 11: " + showtimes[0] print "Showtime at 12: " + showtimes[1] print "Showtime at 13: " + showtimes[2] print "Showtime at 14: " + showtimes[3] </code></pre>
0
2016-09-11T19:15:44Z
[ "python" ]
For loop with increasing variable
39,439,724
<p>I am writing a for loop to quickly obtain user data for a set. To keep the data useful, each has to have it's own variable it saves to. So far, I have:</p> <pre><code>hey = ['11', '12', '13', '14'] x = 0 for i in hey: x += 1 showtimesx = raw_input('NOG &gt;') print showtimesx print "" print "Showtim...
-1
2016-09-11T19:13:07Z
39,439,849
<p>The reason is that for each loop that your <code>for</code> does, <code>showtimesx</code> gets overwritten. This code blow will help:</p> <pre><code>hey = ['11', '12', '13', '14'] x = 0 showtimesx = [] for n in hey : for i in n: x += 1 showtimesx.append(input('NOG &gt;')) #Adds the user's input ...
0
2016-09-11T19:27:12Z
[ "python" ]
For loop with increasing variable
39,439,724
<p>I am writing a for loop to quickly obtain user data for a set. To keep the data useful, each has to have it's own variable it saves to. So far, I have:</p> <pre><code>hey = ['11', '12', '13', '14'] x = 0 for i in hey: x += 1 showtimesx = raw_input('NOG &gt;') print showtimesx print "" print "Showtim...
-1
2016-09-11T19:13:07Z
39,440,751
<h1>List Approach</h1> <p>If you have to iterate through a and perform an operation with each value, try <a href="https://docs.python.org/2.3/whatsnew/section-enumerate.html" rel="nofollow"><code>enumerate()</code>, which will return both the value from your list and its position in the list</a>.<br> This will also al...
0
2016-09-11T21:19:01Z
[ "python" ]
How to show results from a Biopython Pubmed search in a Gtk.TextView?
39,439,729
<p>I want to search Pubmed using Biopython (the code is in the Biopython documentation) and display the results (title, authors, source) of each record in a Gtk.TextView. The code works when just printed but when I try to use the TextView, only the first record is shown. If anyone knows why this is the case, I'd apprec...
0
2016-09-11T19:14:01Z
39,561,232
<p>As written in my comment: Your <code>for</code> loop produces one long line without linebreaks, and <code>Gtk.TextView</code> does not wrap the line.</p> <p>From the <a href="http://python-gtk-3-tutorial.readthedocs.io/en/latest/textview.html" rel="nofollow">Python GTK+ 3 tutorial</a>:</p> <blockquote> <p>Anothe...
1
2016-09-18T18:33:20Z
[ "python", "gtk", "biopython", "pubmed" ]
how to limit input in while loop need serious looking into
39,439,813
<p>how can i limit the input for srj imbetween 1 and 0 and it just restarts the whole program</p> <pre><code>def gen0(): # input all the initial data while True: # this will loop infinitely if needed try: # this will try to take a float from the user j=int(input('how many juveniles ar...
-3
2016-09-11T19:23:07Z
39,439,852
<p>put the if statement <code>if srj &gt; 1 or srj &lt; 0:gen0()</code> before the <code>break</code> line<br> :^)</p>
-1
2016-09-11T19:27:38Z
[ "python", "while-loop" ]
how to limit input in while loop need serious looking into
39,439,813
<p>how can i limit the input for srj imbetween 1 and 0 and it just restarts the whole program</p> <pre><code>def gen0(): # input all the initial data while True: # this will loop infinitely if needed try: # this will try to take a float from the user j=int(input('how many juveniles ar...
-3
2016-09-11T19:23:07Z
39,439,887
<p>Since you are breaking within a <code>try</code>/<code>except</code>, you can simple <code>raise</code> a <code>ValueError</code> if the data is incorrect.</p> <pre><code>if srj &gt; 1.0 or srj &lt; 0.0: raise ValueError </code></pre>
0
2016-09-11T19:31:59Z
[ "python", "while-loop" ]
How can I get auto-indentation to work with Python 2.7 on Xcode 7.3?
39,439,814
<p>I've used <a href="https://vandadnp.wordpress.com/2014/10/20/building-and-running-python-scripts-with-xcode-6-1/" rel="nofollow">this guide</a> to set up Xcode to build Python scripts. When I press return, the cursor always goes back to the beginning of the new line, even though automatic indenting based on syntax i...
0
2016-09-11T19:23:09Z
39,439,995
<p>I would suggest running Python on something else imho. Something like PyCharm or IPython. The problem with Xcode is that Python is not one of the native languages for it. So Xcode doesn't know the proper formatting for Pythons syntax. Not to mention that debugging and other features might not work well on Xcode. </...
0
2016-09-11T19:45:24Z
[ "python", "xcode", "python-2.7" ]
How to immediately re-raise an exception thrown in any of the worker threads?
39,439,868
<p>I'm using <code>ThreadPoolExecutor</code> and need to abort the whole computation in case any of the worker threads fails.</p> <p><strong>Example 1.</strong> This prints <em>Success</em> regardless of the error, since <code>ThreadPoolExecutor</code> does not re-raise exceptions automatically.</p> <pre><code>from c...
0
2016-09-11T19:29:23Z
39,440,263
<p>I think, I'll implement it like that:</p> <p>I the main process, I create 2 queues:</p> <ol> <li>One to report exceptions,</li> <li>One to notify cancellation.</li> </ol> <p>::</p> <pre><code>import multiprocessing as mp error_queue = mp.Queue() cancel_queue = mp.Queue() </code></pre> <p>I create each <code>Th...
0
2016-09-11T20:18:13Z
[ "python", "multithreading", "python-3.x", "exception", "threadpoolexecutor" ]
How to immediately re-raise an exception thrown in any of the worker threads?
39,439,868
<p>I'm using <code>ThreadPoolExecutor</code> and need to abort the whole computation in case any of the worker threads fails.</p> <p><strong>Example 1.</strong> This prints <em>Success</em> regardless of the error, since <code>ThreadPoolExecutor</code> does not re-raise exceptions automatically.</p> <pre><code>from c...
0
2016-09-11T19:29:23Z
39,440,411
<p>First of all, we have to submit the tasks before requesting their results. Otherwise, the threads are not even running in parallel:</p> <pre><code>futures = [] with ThreadPoolExecutor() as executor: futures.append(executor.submit(good_task)) futures.append(executor.submit(bad_task)) for future in futures: ...
0
2016-09-11T20:36:39Z
[ "python", "multithreading", "python-3.x", "exception", "threadpoolexecutor" ]
How to handle UTF8 string from Pythons imaplib
39,439,967
<p>Python imaplib sometimes returns strings that looks like this:</p> <pre><code>=?utf-8?Q?Repertuar_wydarze=C5=84_z_woj._Dolno=C5=9Bl=C4=85skie?= </code></pre> <p>What is the name for this notation?</p> <p>How can I decode (or should I say encode?) it to UTF8?</p>
1
2016-09-11T19:41:55Z
39,440,002
<p><strong>In short:</strong></p> <pre><code>&gt;&gt;&gt; from email.header import decode_header &gt;&gt;&gt; msg = decode_header('=?utf-8?Q?Repertuar_wydarze=C5=84_z_woj._Dolno=C5=9Bl=C4=85skie?=')[0][0].decode('utf-8') &gt;&gt;&gt; msg 'Repertuar wydarze\u0144 z woj. Dolno\u015bl\u0105skie' </code></pre> <p>My comp...
1
2016-09-11T19:46:17Z
[ "python", "utf-8", "imaplib" ]
joining two pandas dataframes on date and
39,440,004
<p>I am trying to join two dataframes however after merging the two dataframes i get NaN for all the columns from one of the DataFrames (Master) but the column heading are there. </p> <p>Below is the structure of each dataframe</p> <pre><code>b.columns Index(['Date', 'Ticker', 'Price'], dtype='object') Master.column...
0
2016-09-11T19:46:36Z
39,440,466
<p>this might be expected behavior. you have specified <code>how = 'left'</code> which means you are looking for key combinations from your left dataframe only. If there aren't exact(!) key matches in the right dataframe, you are going to get NaN's in the joined table. You can find more info on this argument <a href="h...
0
2016-09-11T20:44:30Z
[ "python", "pandas" ]
How to allow Flask-Admin to accept JSON for record creation
39,440,048
<p>I would like to know if it is possible to use <code>Flask-Admin</code> with the python <code>requests</code> library to create new records in the database from a script. An example would be as such:</p> <pre><code>import requests new_userdata = {'username': 'testuser', 'confirmed_at': None, 'login_count': 0, 'last...
-1
2016-09-11T19:52:31Z
39,440,478
<p>You're sending form data, but you're also saying that the content type is JSON. If you were actually sending JSON data, you would either need to call <code>json.dumps</code>, or you would pass <code>json=</code> instead of <code>data=</code>. Just remove the header and send form data, as it's obviously sufficient ...
0
2016-09-11T20:45:30Z
[ "python", "json", "flask", "python-requests", "flask-admin" ]
How can I make this code not print an entire list and just a single name and time
39,440,090
<pre><code>from lxml import html import requests page = requests.get('http://www.runningzone.com/wp-content/uploads/2016/09/Turtle-Krawl-Overall-Results-2016.html') tree = html.fromstring(page.content) x=2 while True: xpathName = "/html/body/div[2]/table/tbody/tr['x']/td[4]//text()" xpathTime = "/html/body/di...
0
2016-09-11T19:58:10Z
39,440,144
<p><code>'x'</code> does not interpolate the <code>x</code> variable into the string. You need to do something like this:</p> <pre><code>xpathName = "/html/body/div[2]/table/tbody/tr[%d]/td[4]//text()" % (x,) xpathTime = "/html/body/div[2]/table/tbody/tr[%d]/td[9]//text()" % (x,) </code></pre> <p>Also, as @grael men...
1
2016-09-11T20:04:06Z
[ "python" ]
Use a list or array in Python?
39,440,132
<p>I need to store information for 6 items and their respective length, width and cost values and then work out some values based on user input.</p> <p>With the help of jcusick, I have now the code below. </p> <p>I now need help for the items marked in the comments (#).</p> <p>You do not need to write the complete c...
0
2016-09-11T20:02:30Z
39,440,196
<p>I might consider creating a <a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a> for each of the variables your are interested in (length, width, cost). Then you could always query the specific dictionary depending on what the user answers:</p> <pre><code>cost ...
1
2016-09-11T20:11:18Z
[ "python", "python-3.x" ]
Use a list or array in Python?
39,440,132
<p>I need to store information for 6 items and their respective length, width and cost values and then work out some values based on user input.</p> <p>With the help of jcusick, I have now the code below. </p> <p>I now need help for the items marked in the comments (#).</p> <p>You do not need to write the complete c...
0
2016-09-11T20:02:30Z
39,440,265
<p>I would suggest you look into Pandas and implement this more specifically using DataFrames as they are perfect for what you are doing. Like mentioned by the other guys. Make sure your indentations are formatted correctly. If you don't want to use DataFrames which imho are perfect for what you are doing. I would sug...
0
2016-09-11T20:18:29Z
[ "python", "python-3.x" ]
Use a list or array in Python?
39,440,132
<p>I need to store information for 6 items and their respective length, width and cost values and then work out some values based on user input.</p> <p>With the help of jcusick, I have now the code below. </p> <p>I now need help for the items marked in the comments (#).</p> <p>You do not need to write the complete c...
0
2016-09-11T20:02:30Z
39,440,667
<p>I think pandas might be overkill for a small piece of code like this. For your particular example, arrays would be a faster storage method. I would go so far as to say, though, that a list is probably the more pythonic way to handle this particular scale. Your performance won't be terribly affected either way here, ...
1
2016-09-11T21:07:52Z
[ "python", "python-3.x" ]
parsing a large json file and retrieving values in python
39,440,146
<p>I have one large json file of the format - </p> <pre><code>{ "x": "", "y": { "a": { "-3": { "id": -2, "rut": "abc", }, "-1": { "id": -1, "rut": "cdf", } } } } </code></pr...
0
2016-09-11T20:04:34Z
39,440,193
<p>import json from pprint import pprint</p> <pre><code>with open('file.json') as data_file: data = json.load(data_file) pprint([item['id'] for item in data['y']['a'].values()]) </code></pre> <p>Is it what you are looking for?</p>
2
2016-09-11T20:10:57Z
[ "python", "json" ]
parsing a large json file and retrieving values in python
39,440,146
<p>I have one large json file of the format - </p> <pre><code>{ "x": "", "y": { "a": { "-3": { "id": -2, "rut": "abc", }, "-1": { "id": -1, "rut": "cdf", } } } } </code></pr...
0
2016-09-11T20:04:34Z
39,440,199
<p>It is a bit unclear what your problem/error is, but my gess is that you want to simply iterate over all the available values to get your 'id' fields. It would look something like that:</p> <pre><code>for x in data['y']['a']: try: print(x['id']) except IndexError: #In case 'id' isn't present in that ...
1
2016-09-11T20:11:40Z
[ "python", "json" ]
parsing a large json file and retrieving values in python
39,440,146
<p>I have one large json file of the format - </p> <pre><code>{ "x": "", "y": { "a": { "-3": { "id": -2, "rut": "abc", }, "-1": { "id": -1, "rut": "cdf", } } } } </code></pr...
0
2016-09-11T20:04:34Z
39,440,320
<p>Did you mean to use values() ?</p> <p>However, to get the all 'id's:</p> <pre><code>sub_data = data['y']['a'] for i in sub_data: print(sub_data['id']) </code></pre>
0
2016-09-11T20:26:38Z
[ "python", "json" ]
Error while saving image using Django Rest Framework with angularjs
39,440,153
<p>I have two models Blogs, Photo. In Photo model I have fields 'blogs' as foreign key to Blogs model.</p> <p>models.py:</p> <pre><code>def content_file_name(instance, filename): custt=str(datetime.now()) return '/'.join(['content', instance.blogs.slug,custt, filename]) class Photo(models.Model): blogs =...
0
2016-09-11T20:05:19Z
39,481,410
<p>In js:</p> <pre><code>headers: { 'Content-Type': undefined} </code></pre> <p>This solves the problem.</p>
0
2016-09-14T01:58:20Z
[ "python", "angularjs", "django", "django-rest-framework" ]
Django Form - Passing Values
39,440,219
<p>I have the following form and can't seem to use the "self.currentSelectedTeam1" as the initial value for team1 as can be seen at the bottom. When I do try this I get the following error:</p> <pre><code>team1 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,initial=self.curentSelec...
0
2016-09-11T20:13:50Z
39,440,260
<p>This doesn't work becasue the fields <code>team1</code> and <code>team2</code> are created before <code>__init__</code> is called because they're instance members.</p> <p>This means that <code>self.curentSelectedTeam1</code> and <code>self.curentSelectedTeam2</code> aren't available yet and are most likely <code>No...
2
2016-09-11T20:18:06Z
[ "python", "django" ]
Django Form - Passing Values
39,440,219
<p>I have the following form and can't seem to use the "self.currentSelectedTeam1" as the initial value for team1 as can be seen at the bottom. When I do try this I get the following error:</p> <pre><code>team1 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,initial=self.curentSelec...
0
2016-09-11T20:13:50Z
39,440,271
<p>The problem is in <code>self</code> keyword in team1 and team2 variables. The thing is they are on the class-level, and the self is available on the instance level(inside methods, excluding static methods and class methods)</p> <p>To make it work you need to do the same with <code>self.fields['team1'].queryset</co...
2
2016-09-11T20:19:20Z
[ "python", "django" ]
How to return a string from pandas.DataFrame.info()
39,440,253
<p>I would like to display the output from <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.info.html" rel="nofollow"><code>pandas.DataFrame.info()</code></a> on a <code>tkinter</code> text widget so I need a string. However <code>pandas.DataFrame.info()</code> returns <code>NoneType</cod...
2
2016-09-11T20:17:36Z
39,440,325
<p>In the documentation you linked, there's a <code>buf</code> argument:</p> <blockquote> <p>buf : writable buffer, defaults to sys.stdout</p> </blockquote> <p>So one option would be to pass a StringIO instance:</p> <pre><code>&gt;&gt;&gt; import io &gt;&gt;&gt; buf = io.StringIO() &gt;&gt;&gt; df.info(buf=buf) &g...
4
2016-09-11T20:27:40Z
[ "python", "pandas" ]
Replacing an item in list with items of another list without using dictionaries
39,440,360
<p>I am developing a function in python. Here is my content:</p> <pre><code>list = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] </code></pre> <p>So I want that my list becomes like this after replacement</p> <pre><code>list = ['cow','banana','cream','mango'] </code></pre> <p>I am...
4
2016-09-11T20:30:54Z
39,440,392
<p>First off, never use python built-in names and keywords as your variable names. (change the <code>list</code> to <code>ls</code>)</p> <p>You don't need loop, find the index then chain the slices:</p> <pre><code>In [107]: from itertools import chain In [108]: ls = ['cow','orange','mango'] In [109]: to_replace =...
3
2016-09-11T20:34:43Z
[ "python", "list" ]
Replacing an item in list with items of another list without using dictionaries
39,440,360
<p>I am developing a function in python. Here is my content:</p> <pre><code>list = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] </code></pre> <p>So I want that my list becomes like this after replacement</p> <pre><code>list = ['cow','banana','cream','mango'] </code></pre> <p>I am...
4
2016-09-11T20:30:54Z
39,440,428
<pre><code>def replace_item(list, to_replace, replace_with): index = list.index(to_replace) # the index where should be replaced list.pop(index) # pop it out for value_to_add in reversed(replace_with): list.insert(index, value_to_add) # insert the new value at the right place return list </code>...
-1
2016-09-11T20:39:01Z
[ "python", "list" ]
Replacing an item in list with items of another list without using dictionaries
39,440,360
<p>I am developing a function in python. Here is my content:</p> <pre><code>list = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] </code></pre> <p>So I want that my list becomes like this after replacement</p> <pre><code>list = ['cow','banana','cream','mango'] </code></pre> <p>I am...
4
2016-09-11T20:30:54Z
39,440,477
<p>This approach is fairly simple and has similar performance to @TadhgMcDonald-Jensen's <code>iter_replace()</code> approach (3.6 µs for me):</p> <pre><code>lst = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] def replace_item(lst, to_replace, replace_with): return sum((replace...
5
2016-09-11T20:45:23Z
[ "python", "list" ]
Replacing an item in list with items of another list without using dictionaries
39,440,360
<p>I am developing a function in python. Here is my content:</p> <pre><code>list = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] </code></pre> <p>So I want that my list becomes like this after replacement</p> <pre><code>list = ['cow','banana','cream','mango'] </code></pre> <p>I am...
4
2016-09-11T20:30:54Z
39,440,524
<p>Modifying a list whilst iterating through it is usually problematic because the indices shift around. I recommend to abandon the approach of using a for-loop.</p> <p>This is one of the few cases where a <code>while</code> loop can be clearer and simpler than a <code>for</code> loop:</p> <pre><code>&gt;&gt;&gt; li...
5
2016-09-11T20:51:32Z
[ "python", "list" ]
Replacing an item in list with items of another list without using dictionaries
39,440,360
<p>I am developing a function in python. Here is my content:</p> <pre><code>list = ['cow','orange','mango'] to_replace = 'orange' replace_with = ['banana','cream'] </code></pre> <p>So I want that my list becomes like this after replacement</p> <pre><code>list = ['cow','banana','cream','mango'] </code></pre> <p>I am...
4
2016-09-11T20:30:54Z
39,440,668
<p>A simple way of representing a rule like this is with a generator, when the <code>to_replace</code> is seen different items are produced:</p> <pre><code>def iter_replace(iterable, to_replace, replace_with): for item in iterable: if item == to_replace: yield from replace_with else: ...
3
2016-09-11T21:08:14Z
[ "python", "list" ]
Process finished with exit code 0
39,440,518
<p>I have this:</p> <pre><code>import math class Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0) def calculate_distance(self, other_point): return math.sqrt( (self.x - other_point.x)**2 +(self.y - other_point.y)**2) # how to use it: point1 = Point() ...
1
2016-09-11T20:51:09Z
39,440,611
<p>There is a window called "python console". The output of your script should be there...</p>
0
2016-09-11T21:00:36Z
[ "python" ]
Process finished with exit code 0
39,440,518
<p>I have this:</p> <pre><code>import math class Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0) def calculate_distance(self, other_point): return math.sqrt( (self.x - other_point.x)**2 +(self.y - other_point.y)**2) # how to use it: point1 = Point() ...
1
2016-09-11T20:51:09Z
39,440,635
<p>Try this:</p> <pre><code>import math class Point: def move(self, x, y): self.x = x self.y = y def reset(self): self.move(0, 0) def calculate_distance(self, other_point): return math.sqrt((self.x - other_point.x)**2 +(self.y - other_point.y)**2) # how to use it: poi...
2
2016-09-11T21:03:46Z
[ "python" ]
Python-flask: How to redirect and then do task?
39,440,533
<p>Suppose you these functions where a is some function that takes a while to do.</p> <pre><code>def a(): sleep(5) return True @app.route('/') def b(): a() return flask.redirect("http://someurl.com") </code></pre> <p>How would you get the same functionality but redirect first, then do the function? I'...
-1
2016-09-11T20:52:23Z
39,536,565
<p>Once you return a method (redirect in this case) it just dies, it can't keep running any code.</p> <p>The only possible way to do this is to run the long task asynchronously. A very popular framework often used for this purpose is Celery. Check out their <a href="http://docs.celeryproject.org/en/latest/getting-star...
0
2016-09-16T16:51:23Z
[ "python", "asynchronous", "flask" ]
Matrix to Vector with python/numpy
39,440,633
<p>Numpy <code>ravel</code> works well if I need to create a vector by reading by rows or by columns. However, I would like to transform a matrix to a 1d array, by using a method that is often used in image processing. This is an example with initial matrix <code>A</code> and final result <code>B</code>:</p> <pre><cod...
1
2016-09-11T21:03:35Z
39,440,945
<p>I've been using numpy for several years, and I've never seen such a function.</p> <p>Here's one way you could do it (not necessarily the most efficient):</p> <pre><code>In [47]: a Out[47]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) In [48]: np.concatenate...
3
2016-09-11T21:45:46Z
[ "python", "numpy" ]
Matrix to Vector with python/numpy
39,440,633
<p>Numpy <code>ravel</code> works well if I need to create a vector by reading by rows or by columns. However, I would like to transform a matrix to a 1d array, by using a method that is often used in image processing. This is an example with initial matrix <code>A</code> and final result <code>B</code>:</p> <pre><cod...
1
2016-09-11T21:03:35Z
39,440,952
<p>I found discussion of zigzag scan for MATLAB, but not much for <code>numpy</code>. One project appears to use a hardcoded indexing array for 8x8 blocks</p> <p><a href="https://github.com/lot9s/lfv-compression/blob/master/scripts/our_mpeg/zigzag.py" rel="nofollow">https://github.com/lot9s/lfv-compression/blob/maste...
1
2016-09-11T21:46:28Z
[ "python", "numpy" ]
Where does brew install the Python headers?
39,440,709
<p>I am trying to compile a simple "Hello, World!" in Cython. In a file I have:</p> <pre><code>print("Hello, World!") </code></pre> <p>I run:</p> <pre><code>cython hello_world.pyx </code></pre> <p>To get the <code>hello_world.c</code> file. I then try:</p> <pre><code>gcc -c hello_world.c </code></pre> <p>Which gi...
2
2016-09-11T21:13:03Z
39,440,927
<p>Going off from @sr3z's comment, doing:</p> <pre><code>gcc -c random_sum.c -I/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/include/python3.5m </code></pre> <p>Creates <code>random_sum.o</code>.</p>
0
2016-09-11T21:43:33Z
[ "python", "python-3.x", "homebrew", "cython" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,440,780
<p>You should check for the largest and smallest numbers inside the loop. First check if its a number - if yes, carry on and see if it is bigger than your current <code>largest</code> variable value (start with 0). If yes, replace it. See, if its smaller than your <code>smallest</code> value (start with the first numbe...
0
2016-09-11T21:21:43Z
[ "python" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,440,832
<p>You're on the right track with your current implementation, but there is some issues in the order of your operations, and where the operations are taking place. Trace through your program step by step, and try to see why your <code>None</code> assignment may be causing some issues, among other small things. </p>
1
2016-09-11T21:27:32Z
[ "python" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,440,878
<p>Let me give you a hint here, every time your <code>while</code> loop takes in a input, it sets the values of <code>largest</code> and <code>smallest</code> to <code>None</code>. Where should you initialize them?</p>
0
2016-09-11T21:34:06Z
[ "python" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,440,894
<p>You are being asked to keep a running max and running min, the same way you could keep a running total. You just update the running &lt;whatever> inside the loop, then discard the user's most recent input. In the case of running total, the code would look like <code>tot = tot + newinput</code> and you could then dis...
1
2016-09-11T21:36:06Z
[ "python" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,441,119
<p>I sense that your confusion partly stems from how the user is expected to give the input. One could interpret the instructions in two ways.</p> <ol> <li><p>The user writes <code>4 5 7 randomword [ENTER]</code></p></li> <li><p>The user writes <code>4 [ENTER] 5 [ENTER] 7 [ENTER] randomword [ENTER]</code></p></li> </o...
0
2016-09-11T22:11:10Z
[ "python" ]
Python Coursera Assignement
39,440,723
<p>I am trying to learn Python through a course on Courser, and so far having a feeling I am not going to be able to.</p> <p>I don't want an answer to the assignment, I want someone to push me in the right direction. Because Im stuck and the online tutors there are not being any help just repeating the obvious that i...
0
2016-09-11T21:15:22Z
39,458,769
<p>I figured it out I think, and the thing that was killing my code was the continue statement if I am not wrong</p> <p>here is what i got, and please leave comments if I got it wrong</p> <pre><code>largest = None smallest = None while True: inpt = raw_input("Enter a number: ") if inpt == "done" : break ...
0
2016-09-12T21:04:36Z
[ "python" ]
AttributeError: 'NoneType' object has no attribute 'find_all' (Many of the other questions asked weren't applicable)
39,440,830
<p>I've seen this Error asked on here a few times but the solutions really weren't clear to me. </p> <p>I am just starting out with BeautifulSoup so this question may be a bit trivial.</p> <p>I am looking to extract the second table in the following website:</p> <p><a href="http://www.espnfc.com/player/45843/lionel-...
-6
2016-09-11T21:27:12Z
39,440,925
<p>It means you try to call <code>find_all</code> on the value <code>None</code>. That could be <code>row.tbody</code> for example, perhaps because there is no <code>&lt;tbody&gt;</code> in the actual HTML.</p> <p>Keep in mind that the <code>&lt;tbody&gt;</code> element is <em>implied</em>. It'll be visible in your br...
1
2016-09-11T21:42:55Z
[ "python", "beautifulsoup" ]
Convert a string of bytes into a python string
39,440,917
<p>I made an array of bytes like so:</p> <pre><code>import array signal = array.array('b', "bird") print array array('b', [98, 105, 114, 100]) </code></pre> <p>I want to convert that back into <code>"bird"</code>.</p> <p>How would I do that? </p>
0
2016-09-11T21:41:04Z
39,440,946
<p>Join the ASCII-to-char array with <code>""</code> to create a string:</p> <p>Python 2:</p> <pre><code>import array signal = array.array('b', "bird") print("".join(chr(x) for x in signal)) </code></pre> <p>Python 3 (<code>bytes</code> needs encoding because it's now REAL binary):</p> <pre><code>import array sig...
0
2016-09-11T21:45:50Z
[ "python", "arrays", "byte", "ascii" ]
Django - Type Error: expected string or bytes-like object
39,440,918
<p>I've seen other questions about this error but none of them were able to help so I figured I make on myself. As per the title, I keep getting this type error and I have run out of ideas as to why it is occurring. </p> <p>I am making an app that involves a Gallery object that adds Photo objects. What I have been spe...
2
2016-09-11T21:41:21Z
39,494,022
<p>Well I was able to solve it on my own!</p> <p>My problem was the way I was overriding the Photo model's save method:</p> <pre><code>def save(self, *args, **kwargs): if self.slug is None: self.slug = slugify(self.title) super(Photo, self).save(*args, **kwargs) </code></pre> <p>For some reason it wa...
0
2016-09-14T15:12:53Z
[ "python", "django" ]
Django self referential m2m field causes causes missing attribtue error
39,440,959
<p>I get an error if I try to make a self-referential m2m Field. Am I missing something here?</p> <pre><code>class UserProfile(models.Model): following = models.ManyToManyField('self', related_name='followers') </code></pre> <p>somewhere else in a serializer:</p> <pre><code>def get_followers(user): return us...
1
2016-09-11T21:47:35Z
39,441,412
<p>By default, Django treats all <code>self</code> m2m relations as symmetrical, for example if I am your friend, you are my friend too. When relation is symmetrical, Django won't create reverse relation attribute to your model.</p> <p>If you want to define non-symmetrical relation, set <code>symmetrical=False</code> ...
0
2016-09-11T22:51:22Z
[ "python", "django", "django-models", "many-to-many" ]
Vertical spacing between xticklabel to the bottom of x-axis
39,440,972
<p>I am wondering if there could be any way to change the spacing between xticklabel (i.e. $\widetilde{M}) and the bottom of x-axis? In my case the spacing is too small so that the tilde above M (left bar) becomes invisible. BTW I am using pandas' plot function to generate the bar plot.</p> <p><a href="http://i.stack....
0
2016-09-11T21:49:22Z
39,441,111
<p>Since Pandas uses the Matplotlib library for all the plotting, you can change this setting through rcParams. First import:</p> <pre><code>from matplotlib import rcParams </code></pre> <p>and then (before plotting anything) change the padding above the xticks:</p> <pre><code>rcParams['xtick.major.pad'] = 20 </code...
1
2016-09-11T22:10:08Z
[ "python", "pandas", "numpy", "matplotlib" ]
Vertical spacing between xticklabel to the bottom of x-axis
39,440,972
<p>I am wondering if there could be any way to change the spacing between xticklabel (i.e. $\widetilde{M}) and the bottom of x-axis? In my case the spacing is too small so that the tilde above M (left bar) becomes invisible. BTW I am using pandas' plot function to generate the bar plot.</p> <p><a href="http://i.stack....
0
2016-09-11T21:49:22Z
39,441,147
<p>Assuming you <code>import matplotlib.pyplot as plt</code> You can manipulate the pyplot object via the tick_params method and <code>pad</code> arg. E.g.:</p> <pre><code>plt.tick_params(pad=10) </code></pre>
1
2016-09-11T22:15:35Z
[ "python", "pandas", "numpy", "matplotlib" ]
Django models: form with infinite group of fields repetition
39,440,986
<p>I'm studying django these days and I need your help to find a solution to this problem about form construction.</p> <p>Let's say I have an entity called 'Activity' just made up by:</p> <pre><code>- title: just a char field - ActivityYears: a couple of start-end years that can be repeated multiple times </code></pr...
0
2016-09-11T21:51:24Z
39,441,049
<p>You'll likely want to use two separate models with a <code>Foreign Key</code> relationship. For example:</p> <pre><code>class Activity(Model): id = AutoField(editable=False, primary_key=True, unique=True) title = CharField(default="Activity") class ActivityYear(Model): id = AutoField(editable=False, pr...
3
2016-09-11T22:01:06Z
[ "python", "django" ]
How to pass a function with a argument in a basic decorator using Python?
39,441,031
<p>I am reading about decorators and have learned quite a bit from <a href="http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/" rel="nofollow">Simeons blog</a> I had success before when there was no arguments passed in the function like this: decorator(func). I think my issue is decorator(func(arg...
0
2016-09-11T21:58:30Z
39,441,071
<p>Give the function to the decorator as an argument; the decorator returns a new function; then call this returned function with <code>user_input</code> as an argument:</p> <pre><code>camel_case(read)(user_input) </code></pre>
0
2016-09-11T22:03:58Z
[ "python", "python-decorators" ]
How to pass a function with a argument in a basic decorator using Python?
39,441,031
<p>I am reading about decorators and have learned quite a bit from <a href="http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/" rel="nofollow">Simeons blog</a> I had success before when there was no arguments passed in the function like this: decorator(func). I think my issue is decorator(func(arg...
0
2016-09-11T21:58:30Z
39,441,076
<p>THe decorator takes a function: <code>camel_case(read)</code>. If you're trying to apply <code>camel_case</code> to the <code>read(user_input)</code> function, try this:</p> <pre><code>camel_case(read)(user_input) </code></pre> <p><code>camel_case(read)</code> returns the decorated function, which you then call ...
2
2016-09-11T22:04:14Z
[ "python", "python-decorators" ]
Python: writing function mult(a,b) for a*b with only add/sub/neg, recursion error for testing (-a,b)
39,441,073
<p>I have this so far - but if I test with (-a, b), python gives me a recursion error. Please help, not sure why this isn't working. All other tests work here.</p> <pre><code>def mult(a, b): """ mult returns the product of two inputs inputs: n and m are integers output: result of multiplying n and m """ i...
-1
2016-09-11T22:04:00Z
39,441,230
<p>Python has a limit to the number of recursions. You may just be hitting into it. See the following answer:</p> <p><a href="http://stackoverflow.com/questions/3323001/maximum-recursion-depth">Maximum recursion depth?</a></p>
1
2016-09-11T22:25:11Z
[ "python", "function", "python-3.x", "recursion", "multiplication" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,441,171
<p>First off, your requested results are not valid python. I'm going to assume that the following format would work for you:</p> <pre><code>my_new_list = [ ((0,3),2), ((4,4),3), ((5,5),4), ((6,7),2), ((8,9),4), ((10,10),3) ] </code></pre> <p>Given that, you can first transform <code>my_list</code> into a list of <co...
0
2016-09-11T22:18:34Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,441,321
<p>Like most problems involving cascading consecutive duplicates, you can still use <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow">groupby()</a> for this. Just group indices by the value at each index.</p> <pre><code>values = [2,2,2,2,3,4,2,2,4,4,3] result = [] for key, gr...
3
2016-09-11T22:37:45Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,441,324
<p>You could use enumerate with a generator function</p> <pre><code>def seq(l): it = iter(l) # get first element and set the start index to 0. start, prev = 0, next(it) # use enumerate to track the rest of the indexes for ind, ele in enumerate(it, 1): # if last seen element is not the same ...
1
2016-09-11T22:37:48Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,441,378
<p>Here's a generator-based solution similar to Padraic's. However it avoids <code>enumerate()</code>-based index tracking and thus is probably faster for huge lists. I didn't worry about your desired output formatting, either.</p> <pre><code>def compress_list(ilist): """Compresses a list of integers""" left...
0
2016-09-11T22:45:37Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,441,549
<p>Here is a lazy version that works on any sequence, and yields slices. Thus it's generic and memory efficient.</p> <pre><code>def compress(seq): start_index = 0 previous = None n = 0 for i, x in enumerate(seq): if previous and x != previous: yield previous, slice(start_index, i) ...
1
2016-09-11T23:15:35Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,442,002
<p>Some good answers here, and thought I would offer an alternative. We iterate through the list of numbers and keep an updating <code>current</code> value, associated with a list of indicies for that value <code>current_indicies</code>. We then look-ahead one element to see if the consecutive number <strong>differs</s...
1
2016-09-12T00:38:30Z
[ "python", "list" ]
"Compressing" a list of integers
39,441,074
<p>I have a list of integers as follows:</p> <pre><code>my_list = [2,2,2,2,3,4,2,2,4,4,3] </code></pre> <p>What I want is to have this as a list os strings, indexed and 'compressed', that is, with each element indicated by its position in the list and with each successive duplicate element indicated as a range, like ...
1
2016-09-11T22:04:02Z
39,445,885
<p>Construct the list with number of consecutive occurences with the item. Then iterate the list and get the list with the range of index of each item.</p> <pre><code>from itertools import groupby new_list = [] for k, g in groupby([2,2,2,2,3,4,2,2,4,4,3]): sum_each = 0 for i in g: sum_each += 1 ##Cons...
1
2016-09-12T08:09:02Z
[ "python", "list" ]
How to break a sentence in python depending on fullstop '.'?
39,441,157
<p>I writing a script in python in which I have the following string:</p> <pre><code>a = "write This is mango. write This is orange." </code></pre> <p>I want to break this string into sentences and then add each sentence as an item of a list so it becomes:</p> <pre><code>list = ['write This is mango.', 'write This i...
-1
2016-09-11T22:16:49Z
39,441,188
<p>One approach is <a href="https://docs.python.org/2/library/re.html#re.split" rel="nofollow"><code>re.split</code></a> with <em>positive lookbehind</em> assertion:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; a = "write This is mango. write This is orange." &gt;&gt;&gt; re.split(r'(?&lt;=\w\.)\s', a) ['write T...
1
2016-09-11T22:20:44Z
[ "python", "list" ]
How to break a sentence in python depending on fullstop '.'?
39,441,157
<p>I writing a script in python in which I have the following string:</p> <pre><code>a = "write This is mango. write This is orange." </code></pre> <p>I want to break this string into sentences and then add each sentence as an item of a list so it becomes:</p> <pre><code>list = ['write This is mango.', 'write This i...
-1
2016-09-11T22:16:49Z
39,441,195
<p>you should look in to the NLTK for python. Here's a sample from NLTK.org</p> <pre><code>&gt;&gt;&gt; import nltk &gt;&gt;&gt; sentence = """At eight o'clock on Thursday morning ... Arthur didn't feel very good.""" &gt;&gt;&gt; tokens = nltk.word_tokenize(sentence) &gt;&gt;&gt; tokens ['At', 'eight', "o'clock", 'on'...
1
2016-09-11T22:21:32Z
[ "python", "list" ]
How to break a sentence in python depending on fullstop '.'?
39,441,157
<p>I writing a script in python in which I have the following string:</p> <pre><code>a = "write This is mango. write This is orange." </code></pre> <p>I want to break this string into sentences and then add each sentence as an item of a list so it becomes:</p> <pre><code>list = ['write This is mango.', 'write This i...
-1
2016-09-11T22:16:49Z
39,441,202
<p>You know about <code>string.split</code>? It can take a multicharacter split criterion:</p> <pre><code>&gt;&gt;&gt; "wer. wef. rgo.".split(". ") ['wer', 'wef', 'rgo.'] </code></pre> <p>But it's not very flexible about things like amount of white space. If you can't control how many spaces come after the full stop,...
0
2016-09-11T22:22:10Z
[ "python", "list" ]
How to break a sentence in python depending on fullstop '.'?
39,441,157
<p>I writing a script in python in which I have the following string:</p> <pre><code>a = "write This is mango. write This is orange." </code></pre> <p>I want to break this string into sentences and then add each sentence as an item of a list so it becomes:</p> <pre><code>list = ['write This is mango.', 'write This i...
-1
2016-09-11T22:16:49Z
39,441,220
<p>This should work. Check out the .split() function here: <a href="http://www.tutorialspoint.com/python/string_split.htm" rel="nofollow">http://www.tutorialspoint.com/python/string_split.htm</a> </p> <pre><code> a = "write This is mango. write This is orange." print a.split('.', 1) </code></pre>
0
2016-09-11T22:23:41Z
[ "python", "list" ]
How to break a sentence in python depending on fullstop '.'?
39,441,157
<p>I writing a script in python in which I have the following string:</p> <pre><code>a = "write This is mango. write This is orange." </code></pre> <p>I want to break this string into sentences and then add each sentence as an item of a list so it becomes:</p> <pre><code>list = ['write This is mango.', 'write This i...
-1
2016-09-11T22:16:49Z
39,441,592
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;code&gt;a.split()&lt;/code&gt;</code></pre> </div> </div> </p> <p>a.split() seems like a simple way of doing it, but y...
0
2016-09-11T23:22:56Z
[ "python", "list" ]
change list of tuples to 2 lists - Python
39,441,191
<p>I have a list of tuples (in this case its coordinates for latitude and longitude)</p> <pre><code>[(51.69768233153901, -5.039923897568534), (52.14847612092221, 0.33689512047881015), (52.14847612092221, 0.33689512047881015), ....] </code></pre> <p>I am trying to get them into 2 separate lists (one for latitude and o...
1
2016-09-11T22:21:03Z
39,441,212
<p>Try this:</p> <pre><code>coords = [(51.69768233153901, -5.039923897568534), (52.14847612092221, 0.33689512047881015), (52.14847612092221, 0.33689512047881015)] lat, lon = map(list, zip(*coords)) </code></pre> <p>Adapted from this answer here <a href="http://stackoverflow.com/questions/19339/a-...
6
2016-09-11T22:23:14Z
[ "python", "tuples", "ipython" ]
change list of tuples to 2 lists - Python
39,441,191
<p>I have a list of tuples (in this case its coordinates for latitude and longitude)</p> <pre><code>[(51.69768233153901, -5.039923897568534), (52.14847612092221, 0.33689512047881015), (52.14847612092221, 0.33689512047881015), ....] </code></pre> <p>I am trying to get them into 2 separate lists (one for latitude and o...
1
2016-09-11T22:21:03Z
39,441,239
<p>If I make a list of tuples with a list comprehension like:</p> <pre><code>In [131]: ll = [(i,j) for i,j in zip(range(10),range(5,15))] In [132]: ll Out[132]: [(0, 5), (1, 6), (2, 7), (3, 8), (4, 9), (5, 10), (6, 11), (7, 12), (8, 13), (9, 14)] </code></pre> <p>I can easily split it into 2 list with 2 lis...
0
2016-09-11T22:26:20Z
[ "python", "tuples", "ipython" ]
change list of tuples to 2 lists - Python
39,441,191
<p>I have a list of tuples (in this case its coordinates for latitude and longitude)</p> <pre><code>[(51.69768233153901, -5.039923897568534), (52.14847612092221, 0.33689512047881015), (52.14847612092221, 0.33689512047881015), ....] </code></pre> <p>I am trying to get them into 2 separate lists (one for latitude and o...
1
2016-09-11T22:21:03Z
39,441,266
<p>Using list comprehension:</p> <pre><code>lats, lons = [[coord[index] for coord in coords] for index in (0,1)] </code></pre> <p>Note that using list comprehension is over a half order of magnitude faster than the <code>map-list-zip</code> approach for large coordinate lists:</p> <p><a href="http://i.stack.imgur.co...
-1
2016-09-11T22:29:51Z
[ "python", "tuples", "ipython" ]
Confused about modifying lists using two functions in Python
39,441,236
<p>I'm currently reading <em>Python Crash Course</em> by Eric Matthes and I'm having an incredibly difficult time understanding chapter 8 which is all about functions. I am stuck on exercise 8-10 which asks me to use a new function to change a list used in the previous exercise.</p> <p>Here is the exercise:</p> <pre>...
0
2016-09-11T22:25:44Z
39,441,273
<p>Ok, so you have an extra loop on the outside, remove that. The final code:</p> <pre><code>def show_magicians(names): """Print each magician name""" for name in names: msg = name.title() print(msg) magician_names = ['sonic', 'tails', 'knuckles'] show_magicians(magician_names) def make_great...
2
2016-09-11T22:31:34Z
[ "python" ]
Confused about modifying lists using two functions in Python
39,441,236
<p>I'm currently reading <em>Python Crash Course</em> by Eric Matthes and I'm having an incredibly difficult time understanding chapter 8 which is all about functions. I am stuck on exercise 8-10 which asks me to use a new function to change a list used in the previous exercise.</p> <p>Here is the exercise:</p> <pre>...
0
2016-09-11T22:25:44Z
39,441,294
<p>Change the second method to:</p> <pre><code>def make_great(list_magicians): """Add 'Great' to each name.""" i = 0 for magician_name in magician_names: list_magicians[i] += " the great!" i += 1 </code></pre> <p>Currently you are looping twice using two <code>for loops</code> causing it t...
1
2016-09-11T22:34:27Z
[ "python" ]
Confused about modifying lists using two functions in Python
39,441,236
<p>I'm currently reading <em>Python Crash Course</em> by Eric Matthes and I'm having an incredibly difficult time understanding chapter 8 which is all about functions. I am stuck on exercise 8-10 which asks me to use a new function to change a list used in the previous exercise.</p> <p>Here is the exercise:</p> <pre>...
0
2016-09-11T22:25:44Z
39,441,307
<p>Let's look at your <code>make_great</code> function:</p> <pre><code>def make_great(list_magicians): """Add 'Great' to each name.""" for magician_name in magician_names: for i in range(len(list_magicians)): list_magicians[i] += " the great!" </code></pre> <p>What does this do?</p> <p><c...
1
2016-09-11T22:36:07Z
[ "python" ]
Confused about modifying lists using two functions in Python
39,441,236
<p>I'm currently reading <em>Python Crash Course</em> by Eric Matthes and I'm having an incredibly difficult time understanding chapter 8 which is all about functions. I am stuck on exercise 8-10 which asks me to use a new function to change a list used in the previous exercise.</p> <p>Here is the exercise:</p> <pre>...
0
2016-09-11T22:25:44Z
39,441,403
<p>As another answerer said, your nested loops are doing basically the same thing, but for each time the outer loop runs, the inner loop runs. Both loops are trying to iterate over the list of magicians, one using the name the list goes by outside the function (<code>magician_names</code>) and one using the name the li...
1
2016-09-11T22:50:03Z
[ "python" ]
Python in-memory database overflow
39,441,278
<p>I couldn't find an answer online, so here it goes. I'm developing a SAAS that creates a temporary in-memory SQLITE3 database on the cloud for each user. The databases will not be stored, hence they are in-memory:</p> <pre><code>import sqlite3 conn = sqlite3.connect(':memory:') </code></pre> <p>My question is regar...
0
2016-09-11T22:31:44Z
39,441,341
<p>This <a href="https://www.sqlite.org/inmemorydb.html" rel="nofollow">documentation page</a> reads:</p> <blockquote> <p>The sole difference [between a temporary and an in-memory database] is that a ":memory:" database must remain in memory at all times whereas parts of a temporary database might be flushed to disk...
2
2016-09-11T22:40:57Z
[ "python", "database", "memory", "sqlite3" ]
Python lambda function "translation" causes recursion error
39,441,290
<p>While attempting to understand python lambda functions, I "translated" this function:</p> <pre><code>s = lambda y: y ** y; s(3) </code></pre> <p>Into this regular, defined function:</p> <pre><code>def power_of_self(y): return y ** y power_of_self(3) </code></pre> <p>When I tried running it as a script (<co...
0
2016-09-11T22:33:56Z
39,441,309
<p>The <code>...</code> means the python shell was waiting for more statements as part of the function. You need a blank line to end the function when entering an indented block from directly into the python shell.</p> <pre><code>&gt;&gt;&gt; def power_of_self(y): ... return y ** y ... &gt;&gt;&gt; power_of_self(...
3
2016-09-11T22:36:23Z
[ "python", "lambda" ]
Python lambda function "translation" causes recursion error
39,441,290
<p>While attempting to understand python lambda functions, I "translated" this function:</p> <pre><code>s = lambda y: y ** y; s(3) </code></pre> <p>Into this regular, defined function:</p> <pre><code>def power_of_self(y): return y ** y power_of_self(3) </code></pre> <p>When I tried running it as a script (<co...
0
2016-09-11T22:33:56Z
39,441,310
<p>Your function is still been defined in the shell. Hit an extra <kbd>Enter</kbd> before calling the function.</p>
1
2016-09-11T22:36:35Z
[ "python", "lambda" ]
Python 3 guessing game - int() argument error
39,441,314
<p>This is the code in its full extent at the moment:</p> <pre><code>import random import time from tkinter import * from tkinter import ttk mode_chosen = 0 def update_mode(): global mode_chosen mode_chosen = entry.get() mode() def mode(): if mode_chosen == "1": new_player() if mode_chos...
0
2016-09-11T22:36:58Z
39,442,553
<p>Okay, so.</p> <p>On line 77, you have</p> <p><code>guess = entry3.get</code></p> <p>entry3.get is a function. So instead it would be,</p> <p><code>guess = entry3.get()</code></p> <p>Sometimes you can use something like <code>print(type(entry3.get))</code> and it'll say</p> <p><code>&lt;class 'method'&gt; &lt;b...
0
2016-09-12T02:14:34Z
[ "python" ]
Replace all negative values in a list
39,441,323
<p>I'm trying to solve this problem on codewars and I'm completely stumped:</p> <pre><code>y = [-1, -1, 2, 8, -1, 4] z = [1,3,5] #to create [1,3,2,8,5,4] </code></pre> <p>How would I do this?</p> <p>I tried to do:</p> <pre><code>for e in range(len(y)): try: if y[e] &lt; 0: y[e] = z[e] ex...
3
2016-09-11T22:37:47Z
39,441,344
<p>You're trying to use the same index for both lists, which doesn't appear to be the correct behaviour from your example. For example, the -1 in <code>y</code> is at index 4, but is replaced by the 5 in <code>z</code> at index 2.</p> <pre><code>zindex = 0 for yindex in range(len(y)): if y[yindex] &lt; 0: ...
0
2016-09-11T22:41:12Z
[ "python", "python-3.x" ]
Replace all negative values in a list
39,441,323
<p>I'm trying to solve this problem on codewars and I'm completely stumped:</p> <pre><code>y = [-1, -1, 2, 8, -1, 4] z = [1,3,5] #to create [1,3,2,8,5,4] </code></pre> <p>How would I do this?</p> <p>I tried to do:</p> <pre><code>for e in range(len(y)): try: if y[e] &lt; 0: y[e] = z[e] ex...
3
2016-09-11T22:37:47Z
39,441,354
<p>Your code:</p> <pre><code>for e in range(len(y)): if y[e] &lt; 0: y[e] = z[e] </code></pre> <p>The problem with your code is let's say the 5th element is negative. You are attempting to set the 5th element of <code>y</code> to the 5th element of <code>z</code>. Instead, you should use a counter variable to tra...
0
2016-09-11T22:42:13Z
[ "python", "python-3.x" ]
Replace all negative values in a list
39,441,323
<p>I'm trying to solve this problem on codewars and I'm completely stumped:</p> <pre><code>y = [-1, -1, 2, 8, -1, 4] z = [1,3,5] #to create [1,3,2,8,5,4] </code></pre> <p>How would I do this?</p> <p>I tried to do:</p> <pre><code>for e in range(len(y)): try: if y[e] &lt; 0: y[e] = z[e] ex...
3
2016-09-11T22:37:47Z
39,441,362
<p>If you are sure that number of negative numbers is always equal with <code>z</code> you can convert <code>z</code> to an iterable and use a list comprehension for creating your new list:</p> <pre><code>In [9]: z = iter(z) In [10]: [next(z) if i &lt; 0 else i for i in y] Out[10]: [1, 3, 2, 8, 5, 4] </code></pre> <...
11
2016-09-11T22:43:21Z
[ "python", "python-3.x" ]
Replace all negative values in a list
39,441,323
<p>I'm trying to solve this problem on codewars and I'm completely stumped:</p> <pre><code>y = [-1, -1, 2, 8, -1, 4] z = [1,3,5] #to create [1,3,2,8,5,4] </code></pre> <p>How would I do this?</p> <p>I tried to do:</p> <pre><code>for e in range(len(y)): try: if y[e] &lt; 0: y[e] = z[e] ex...
3
2016-09-11T22:37:47Z
39,441,407
<p>One-liner. Emulate queue behavior using <code>pop()</code>. (<em>Note this consumes</em> <code>z</code>)</p> <pre><code>&gt;&gt;&gt; print([num if num &gt; 0 else z.pop(0) for num in y]) [1, 3, 2, 8, 5, 4] </code></pre>
4
2016-09-11T22:50:27Z
[ "python", "python-3.x" ]
Is it possible to use argparse for passing optional arguments without the dash symbol?
39,441,329
<p>I have a program which can take in a few different arguments, and depending on what the argument is that is passed, that function is called in the python program. I know how to use sys.arv, and I have used argparse before, however I am not sure how to go about accomplishing the following with argparse..</p> <p>Poss...
0
2016-09-11T22:38:27Z
39,441,370
<pre><code> parser.add_argument('foo', choices=['func1','func2','func3']) </code></pre> <p>will accept one string, and raise an error if that string is not one of the chocies. The results will be a namespace like</p> <pre><code> Namespace(foo='func1') </code></pre> <p>and</p> <pre><code> print(args.foo) # 'func1'...
1
2016-09-11T22:44:26Z
[ "python", "argparse" ]
How do you schedule cron jobs using APScheduler on Heroku?
39,441,337
<p>I am trying to use the APScheduler and SendGrid on Heroku to create a cron job for sending an email.</p> <p>Even though the add_job method call seems to be executing correctly, I am getting the following error.</p> <p>Below are the logs from heroku</p> <pre><code>2016-09-11T22:33:37.776867+00:00 heroku[clock.1]:...
1
2016-09-11T22:39:48Z
39,454,744
<p>You started a background scheduler but then allowed your main thread to exit, which also exits the clock process. This is the entire reason why <code>BlockingScheduler</code> exists. Have you not read Heroku's <a href="https://devcenter.heroku.com/articles/clock-processes-python" rel="nofollow">APScheduler instructi...
0
2016-09-12T16:22:53Z
[ "python", "heroku", "cron", "sendgrid", "apscheduler" ]
How to create three separate lists of values from a Python list of dictionaries where each dictionary has three keys
39,441,348
<p>I am new to Python. My question might come across as simple to experienced developers and coders but I haven't been able to find out an answer to this. </p> <p>I am retrieving some data through a database query. I have succeeded in organising each row returned by query as a dictionary having three keys and a corres...
2
2016-09-11T22:41:27Z
39,441,383
<pre><code># Defining lists dates = [] prices = [] item_numbers = [] # Loop through list for dictionary in your_list: dates.append(dictionary["Date"]) # Add the date to dates prices.append(dictionary["price"]) # Add the price to prices # Add item number to item_numbers item_numbers.append(dictionary["it...
1
2016-09-11T22:46:13Z
[ "python", "list", "dictionary" ]
How to create three separate lists of values from a Python list of dictionaries where each dictionary has three keys
39,441,348
<p>I am new to Python. My question might come across as simple to experienced developers and coders but I haven't been able to find out an answer to this. </p> <p>I am retrieving some data through a database query. I have succeeded in organising each row returned by query as a dictionary having three keys and a corres...
2
2016-09-11T22:41:27Z
39,441,384
<p>You could combine a listcomp and a dictcomp:</p> <pre><code>In [95]: ds Out[95]: [{'Date': 'date1', 'itemnumber': 'number1', 'price': 'price1'}, {'Date': 'date2', 'itemnumber': 'number2', 'price': 'price2'}] In [96]: {key: [subdict[key] for subdict in ds] for key in ds[0]} Out[96]: {'Date': ['date1', 'date2'], ...
3
2016-09-11T22:46:14Z
[ "python", "list", "dictionary" ]
How to create three separate lists of values from a Python list of dictionaries where each dictionary has three keys
39,441,348
<p>I am new to Python. My question might come across as simple to experienced developers and coders but I haven't been able to find out an answer to this. </p> <p>I am retrieving some data through a database query. I have succeeded in organising each row returned by query as a dictionary having three keys and a corres...
2
2016-09-11T22:41:27Z
39,441,386
<pre><code>for (field,values) in [(field, [result.get(field) for result in results] ) for field in results[0].keys()]: # this is ugly, but I can't see any other legal way to # dynamically set variables. eval "%s=%s" % (field, repr(value)) </code></pre> <p><em>Edited to not [illegally] m...
0
2016-09-11T22:46:35Z
[ "python", "list", "dictionary" ]
How to create three separate lists of values from a Python list of dictionaries where each dictionary has three keys
39,441,348
<p>I am new to Python. My question might come across as simple to experienced developers and coders but I haven't been able to find out an answer to this. </p> <p>I am retrieving some data through a database query. I have succeeded in organising each row returned by query as a dictionary having three keys and a corres...
2
2016-09-11T22:41:27Z
39,441,390
<p>Use <em>list comprehensions</em>:</p> <pre><code>date = [d['Date'] for d in list_of_dicts] price = [d['price'] for d in list_of_dicts] itemnumber = [d['itemnumber'] for d in list_of_dicts] </code></pre> <hr> <p>One could also do this in a less readable one liner:</p> <pre><code>date, price, itemnumber = zip(*[(d...
5
2016-09-11T22:47:33Z
[ "python", "list", "dictionary" ]
Django custom decorator user_passes_test() can it obtain url parameters?
39,441,429
<p>Can Django's <code>user_passes_test()</code> access view parameters?</p> <p>For example I have view that receives an <code>id</code> to retrieve specific record:</p> <pre><code>def property(request, id): property = Property.objects.get(id=int(id)) </code></pre> <p>The record has a field named user_id that con...
0
2016-09-11T22:55:26Z
39,441,690
<p>Typically, (using class based views), I'll handle this in the <code>get_queryset</code> method so it would be something like</p> <pre><code>class PropertyDetail(DetailView): def get_queryset(self): return self.request.user.property_set.all() </code></pre> <p>and that will give a 404 if the property isn...
1
2016-09-11T23:40:23Z
[ "python", "django" ]
Simplejson decoding error only occurs when performing over two iterations
39,441,433
<p>I'm trying to use the names module along with a wrapper for temp-mail.org (<a href="https://github.com/saippuakauppias/temp-mail" rel="nofollow">https://github.com/saippuakauppias/temp-mail</a>) for part of a project involving creating temporary email addresses. My code is as shown below and works fine unless n is g...
1
2016-09-11T22:55:59Z
39,441,567
<p>Okay so I looked over your problem.</p> <p>The package <a href="https://github.com/saippuakauppias/temp-mail" rel="nofollow">temp-mail</a> seems to make a request to temp-mail.ru <em>each</em> time you call <code>TempMail()</code> to get a list of available domains.</p> <p>You are encountering the API's <a href="h...
0
2016-09-11T23:19:15Z
[ "python", "json" ]