title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Passing kwargs from template to view? | 1,269,544 | <p>As you may be able to tell from my questions, I'm new to both python and django. I would like to allow dynamic filter specifications of query sets from my templates using <code>**kwargs</code>. I'm thinking like a select box of a bunch of kwargs. For example:</p>
<pre><code> <select id="filter">
<opti... | 1 | 2009-08-13T01:09:18Z | 1,270,117 | <p>Rather than face the horrible dangers of SQL injection, why not just assign a value to each select option and have your form-handling view run the selected query based on the value.</p>
<p>Passing the parameters for a DB query from page to view is just asking for disaster. Django is built to avoid this sort of thin... | 1 | 2009-08-13T05:04:41Z | [
"python",
"django"
] |
Passing kwargs from template to view? | 1,269,544 | <p>As you may be able to tell from my questions, I'm new to both python and django. I would like to allow dynamic filter specifications of query sets from my templates using <code>**kwargs</code>. I'm thinking like a select box of a bunch of kwargs. For example:</p>
<pre><code> <select id="filter">
<opti... | 1 | 2009-08-13T01:09:18Z | 1,298,226 | <p>Concerning your update: FilterSpecs are unfortunately one of those (rare) pieces of Django that lack public documentation. As such, there is no guarantee that they will keep working as they do.</p>
<p>Another approach would be to use Alex Gaynor's <a href="http://lazypython.blogspot.com/2009/02/announcing-django-fi... | 0 | 2009-08-19T07:05:45Z | [
"python",
"django"
] |
Get information from related object in generic list view | 1,269,625 | <p>So, I've been noodling about with Django's generic views, specifically the <code>object_list</code> view. I have this in my <code>urls.py</code>:</p>
<pre><code>from django.conf.urls.defaults import *
from django.views.generic import list_detail
from diplomacy.engine.models import Game
game_info = {
"queryset... | 0 | 2009-08-13T01:45:28Z | 1,269,733 | <p>If <code>Turn.game</code> points to the associated <code>Game</code> object, then <code>{{game.turn_set.all}}</code> should return the set of <code>Turn</code> objects for that game. </p>
<p>You may need to add a Meta class to the <code>Turn</code> model to order from newest to oldest.</p>
<pre><code>Class Meta:
... | 0 | 2009-08-13T02:32:11Z | [
"python",
"django",
"django-templates",
"django-views"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,269,820 | <p>I am not an expert at C++ optimization, but I believe the speed difference may be due to the fact that Python lists have preallocated more space at the beginning while your C++ vectors must reallocate and possibly copy every time it grows.</p>
<p>As for GMan's comment about find, I believe that the Python "in" oper... | 1 | 2009-08-13T03:06:01Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,269,839 | <p>It looks like you're passing vectors by value to other functions. This will be a significant slowdown because the program will actually make a full copy of your vector before it passes it to your function. To get around this, pass a constant reference to the vector instead of a copy. So instead of: </p>
<pre><code>... | 16 | 2009-08-13T03:14:40Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,269,842 | <p>I can see that you have quite a few heap allocations that are unnecessary</p>
<p>For example:</p>
<pre><code>while(!next)
{
char* buffer = new char[10];
</code></pre>
<p>This doesn't look very optimized. So, you probably want to have the array pre-allocated and using it inside your loop. This is a basi... | 7 | 2009-08-13T03:15:41Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,269,845 | <p>Here's some food for thought: If given the choice of running a 1979 algorithm for finding prime numbers in a 2009 computer or a 2009 algorithm on a 1979 computer, which would you choose?</p>
<p>The new algorithm on ancient hardware would be the better choice by a huge margin. Have a look at your "helper" functions.... | 0 | 2009-08-13T03:16:18Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,269,998 | <p>For 100000 elements, the Python code took 6.9 seconds while the C++ originally took above 37 seconds.</p>
<p>I did some basic optimizations on your code and managed to get the C++ code above 100 times faster than the Python implementation. It now does 100000 elements in 0.06 seconds. That is 617 times faster than t... | 144 | 2009-08-13T04:14:59Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,270,015 | <p>Well, I also gave it a once-over. I didn't test or even compile, though.</p>
<p>General rules for numerical programs:</p>
<ul>
<li><p>Never process numbers as text. That's what makes lesser languages than Python slow, so if you do it in C, the program will be slower than Python.</p></li>
<li><p>Don't use data stru... | 3 | 2009-08-13T04:22:10Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,270,032 | <p>There are quite a few optimizations possible:</p>
<p>(1) Use const references </p>
<pre><code>bool inVector(int inQuestion, const vector<int>& known)
{
for(vector<int>::const_iterator it = known.begin(); it != known.end(); ++it)
if(*it == inQuestion)
return true;
return false;
}
... | 0 | 2009-08-13T04:29:59Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,271,103 | <p>With similar optimizations as PotatoSwatter I got time for 10000 numbers down from 1.063 seconds to 0.062 seconds (except I replaced itoa with standard sprintf in the original). </p>
<p>With all the memory optimizations (don't pass containers by value - in C++ you have to explicitly decide whether you want a copy o... | 0 | 2009-08-13T10:02:48Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,271,927 | <p><strong>There's a new, radically faster version as <a href="http://stackoverflow.com/questions/1269795/unusual-speed-difference-between-python-and-c/1275074#1275074">a separate answer</a>, so this answer is deprecated.</strong></p>
<hr>
<p>I rewrote your algorithm by making it cache whenever it finds the number to... | 19 | 2009-08-13T13:25:13Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,272,569 | <p>Here's a C# version:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Text;
namespace CSharp
{
class Program
{
static void Main (string [] args)
{
while (true)
{
Console.Write ("Pick an upper bound: ");
String
input = Console.ReadLine ()... | 0 | 2009-08-13T15:07:34Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,275,074 | <p>This is my second answer; which <strong>caches things like sum of squares</strong> for values <code><= 10**6</code>:</p>
<pre><code> happy_list[sq_list[x%happy_base] + sq_list[x//happy_base]]
</code></pre>
<p>That is, </p>
<ul>
<li>the number is split into 3 digits + 3 digits</li>
<li>the <strong>precom... | 6 | 2009-08-13T22:51:01Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,275,866 | <p>Here is another way that relies on memorising all the numbers already explored.
I obtain a factor x4-5, which is oddly stable against DrAsik's code for 1000 and 1000000, I expected the cache to be more efficient the more numbers we were exploring. Otherwise, the same kind of classic optimizations have been applied. ... | 1 | 2009-08-14T03:11:06Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,281,089 | <p>Just to get a little more closure on this issue by seeing how fast I could truely find these numbers, I wrote a multithreaded C++ implementation of Dr_Asik's algorithm. There are two things that are important to realize about the fact that this implementation is multithreaded.</p>
<ol>
<li><p>More threads does not ... | 2 | 2009-08-15T03:39:31Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,282,449 | <p><strong>Other optimizations</strong>: by using arrays and direct access using the loop index rather than searching in a vector, and by caching prior sums, the following code (inspired by Dr Asik's answer but probably not optimized at all) runs <strong><em>2445</em></strong> times faster than the original C++ code, a... | 2 | 2009-08-15T17:49:37Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 1,283,788 | <pre><code>
#!/usr/bin/env python
import timeit
upperBound = 0
def calcMain():
known = set()
for i in xrange(0,upperBound+1):
next = False
current = i
history = set()
while not next:
squaresum=0
while current > 0:
current, digit = div... | 0 | 2009-08-16T08:37:07Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 3,979,841 | <p>Why is everyone using a vector in the c++ version? Lookup time is O(N).</p>
<p>Even though it's not as efficient as the python set, use std::set. Lookup time is O(log(N)).</p>
| 0 | 2010-10-20T15:57:11Z | [
"c++",
"python",
"algorithm",
"performance"
] |
Unusual Speed Difference between Python and C++ | 1,269,795 | <p>I recently wrote a short algorithm to calculate <a href="http://en.wikipedia.org/wiki/Happy%5FNumbers">happy numbers</a> in python. The program allows you to pick an upper bound and it will determine all the happy numbers below it. For a speed comparison I decided to make the most direct translation of the algorithm... | 35 | 2009-08-13T02:58:19Z | 10,529,801 | <p>Stumbled over this page whilst bored and thought I'd golf it in js. The algorithm is my own, and I haven't checked it thoroughly against anything other than my own calculations (so it could be wrong). It calculates the first 1e7 happy numbers and stores them in h. If you want to change it, change both the 7s. </p>
... | 1 | 2012-05-10T08:03:55Z | [
"c++",
"python",
"algorithm",
"performance"
] |
mechanize (python) click on a javascript type link | 1,270,274 | <p>is it possible to have mechanize follow an anchor link that is of type javascript?</p>
<p>I am trying to login into a website in python using mechanize and beautifulsoup.</p>
<p>this is the anchor link</p>
<pre><code><a id="StaticModuleID15_ctl00_SkinLogin1_Login1_Login1_LoginButton" href="javascript:WebForm_D... | 3 | 2009-08-13T06:01:00Z | 1,270,296 | <p>I don't think this is possible with the mechanize module: it doesn't have the ability to interact with JavaScript: its purely Python and HTTP based.</p>
<p>That said, you may be intested in <a href="http://github.com/davisp/python-spidermonkey/tree/master" rel="nofollow">python-spidermonkey</a> module, which it see... | 4 | 2009-08-13T06:11:01Z | [
"javascript",
"python",
"mechanize"
] |
mechanize (python) click on a javascript type link | 1,270,274 | <p>is it possible to have mechanize follow an anchor link that is of type javascript?</p>
<p>I am trying to login into a website in python using mechanize and beautifulsoup.</p>
<p>this is the anchor link</p>
<pre><code><a id="StaticModuleID15_ctl00_SkinLogin1_Login1_Login1_LoginButton" href="javascript:WebForm_D... | 3 | 2009-08-13T06:01:00Z | 15,416,360 | <p>You may set cookies using cookielib</p>
<pre><code>import mechanize
import cookielib
# add headers to your browser also
browser = mechanize.Browser()
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
cj = cookielib.LWPCooki... | 0 | 2013-03-14T17:37:38Z | [
"javascript",
"python",
"mechanize"
] |
About Python's Mixed Numeric Data Types converting results up to the most complicated operand | 1,270,403 | <p>A little background: I'm in the process of learning Python through O'Reilly's, "Learning Python" book, I've had some experience in Java.</p>
<p>Anyway, upon reading Chapter 5 (I'm still in the middle of it, actually) I have come across a question with the way Python treats results of Mixed Numeric expressions. In ... | 0 | 2009-08-13T06:48:45Z | 1,270,465 | <blockquote>
<p>"If you have a decimal place in your expression, you know it's going to be a floating point number, if you have something like 3+4j, you know it's going to be a complex number."</p>
</blockquote>
<p>That <em>is</em> the "hierarchy of Numeric Literals". I'm not really sure what more you want. Furtherm... | 5 | 2009-08-13T07:08:18Z | [
"python",
"numeric"
] |
About Python's Mixed Numeric Data Types converting results up to the most complicated operand | 1,270,403 | <p>A little background: I'm in the process of learning Python through O'Reilly's, "Learning Python" book, I've had some experience in Java.</p>
<p>Anyway, upon reading Chapter 5 (I'm still in the middle of it, actually) I have come across a question with the way Python treats results of Mixed Numeric expressions. In ... | 0 | 2009-08-13T06:48:45Z | 1,270,494 | <p>Suppose you had a unified numeric type and you typed the following statements:</p>
<pre><code>a = 42
b = 42.24
c = 4 + 2j
</code></pre>
<p>How would this be any different from what you get today?</p>
<p>This is already valid Python. The only difference is that <code>type(a)</code>, <code>type(b)</code>, <code>ty... | 2 | 2009-08-13T07:17:27Z | [
"python",
"numeric"
] |
About Python's Mixed Numeric Data Types converting results up to the most complicated operand | 1,270,403 | <p>A little background: I'm in the process of learning Python through O'Reilly's, "Learning Python" book, I've had some experience in Java.</p>
<p>Anyway, upon reading Chapter 5 (I'm still in the middle of it, actually) I have come across a question with the way Python treats results of Mixed Numeric expressions. In ... | 0 | 2009-08-13T06:48:45Z | 1,270,701 | <p>Don't think i really understood question:</p>
<ol>
<li><p>Do you mean that operation result should be explictly specified?
you can do it with explict cast</p>
<p>float(1+0.5)</p>
<p>int(1+0.5)</p>
<p>complex(1+0.5)</p></li>
<li><p>Do you mean that operators should accept only same type operands?</p>
<p>1+2</p>
... | 0 | 2009-08-13T08:09:22Z | [
"python",
"numeric"
] |
Python standard library to POST multipart/form-data encoded data | 1,270,518 | <p>I would like to POST multipart/form-data encoded data.
I have found an external module that does it: <a href="http://atlee.ca/software/poster/index.html">http://atlee.ca/software/poster/index.html</a>
however I would rather avoid this dependency. Is there a way to do this using the standard libraries?</p>
<p>thank... | 17 | 2009-08-13T07:24:00Z | 1,270,548 | <p>The standard library <a href="http://bugs.python.org/issue3244">does not currently support that</a>. There is <a href="http://code.activestate.com/recipes/146306/">cookbook recipe</a> that includes a fairly short piece of code that you just may want to copy, though, along with long discussions of alternatives.</p>
| 17 | 2009-08-13T07:31:14Z | [
"python",
"encoding",
"post",
"urllib",
"multipart"
] |
Python standard library to POST multipart/form-data encoded data | 1,270,518 | <p>I would like to POST multipart/form-data encoded data.
I have found an external module that does it: <a href="http://atlee.ca/software/poster/index.html">http://atlee.ca/software/poster/index.html</a>
however I would rather avoid this dependency. Is there a way to do this using the standard libraries?</p>
<p>thank... | 17 | 2009-08-13T07:24:00Z | 1,270,574 | <p>You can't do this with the stdlib quickly. Howevewr, see the <code>MultiPartForm</code> class in this PyMOTW. You can probably use or modify that to accomplish whatever you need:</p>
<ul>
<li><a href="http://pymotw.com/2/urllib2/" rel="nofollow">PyMOTW: urllib2 - Library for opening URLs.</a></li>
</ul>
| 5 | 2009-08-13T07:37:51Z | [
"python",
"encoding",
"post",
"urllib",
"multipart"
] |
Python standard library to POST multipart/form-data encoded data | 1,270,518 | <p>I would like to POST multipart/form-data encoded data.
I have found an external module that does it: <a href="http://atlee.ca/software/poster/index.html">http://atlee.ca/software/poster/index.html</a>
however I would rather avoid this dependency. Is there a way to do this using the standard libraries?</p>
<p>thank... | 17 | 2009-08-13T07:24:00Z | 18,888,633 | <p>It's an old thread but still a popular one, so here is my contribution using only standard modules.</p>
<p>The idea is the same than <a href="http://code.activestate.com/recipes/146306/" rel="nofollow">here</a> but support Python 2.x and Python 3.x.
It also has a body generator to avoid unnecessarily memory usage.<... | 7 | 2013-09-19T07:28:28Z | [
"python",
"encoding",
"post",
"urllib",
"multipart"
] |
how to print python location(where python is install) in the output | 1,270,537 | <p>Lets say Python is installed in the location <code>"C:\TOOLS\COMMON\python\python252"</code> .</p>
<p>I want to print this location in the output of my program. Please let me know which is the function for doing this.</p>
| 8 | 2009-08-13T07:28:44Z | 1,270,552 | <p>Try:</p>
<pre><code>>>> import sys
>>> print sys.prefix
</code></pre>
<p>See the documentation for the <a href="http://docs.python.org/library/sys.html" rel="nofollow"><code>sys</code> module</a> for more details.</p>
| 1 | 2009-08-13T07:32:10Z | [
"python",
"path"
] |
how to print python location(where python is install) in the output | 1,270,537 | <p>Lets say Python is installed in the location <code>"C:\TOOLS\COMMON\python\python252"</code> .</p>
<p>I want to print this location in the output of my program. Please let me know which is the function for doing this.</p>
| 8 | 2009-08-13T07:28:44Z | 1,270,554 | <p>you can use</p>
<pre><code>import sys, os
os.path.dirname(sys.executable)
</code></pre>
<p>but remember than in Unix systems the "installation" of a program is usually distributed along the following folders:</p>
<ul>
<li>/usr/bin (this is what you'll probably get)</li>
<li>/usr/lib</li>
<li>/usr/share</li>
<li>e... | 9 | 2009-08-13T07:33:33Z | [
"python",
"path"
] |
how to print python location(where python is install) in the output | 1,270,537 | <p>Lets say Python is installed in the location <code>"C:\TOOLS\COMMON\python\python252"</code> .</p>
<p>I want to print this location in the output of my program. Please let me know which is the function for doing this.</p>
| 8 | 2009-08-13T07:28:44Z | 1,270,558 | <p>Maybe either of these will satisfy you:</p>
<pre><code>>>> import sys
>>> print sys.prefix
/usr
>>> print sys.path
['', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2',
'/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload',
'/usr/local/lib/python2.... | 4 | 2009-08-13T07:34:36Z | [
"python",
"path"
] |
Python Get Docstring Without Going into Interactive Mode | 1,270,615 | <p>I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.</p>
<p>How do I get the docstring of an object and <strong>not</strong> have Python grab focus?</p>
| 5 | 2009-08-13T07:49:52Z | 1,270,621 | <p>Any docstring is available through the <code>.__doc__</code> property:</p>
<pre><code>>>> print str.__doc__
</code></pre>
<p>In python 3, you'll need parenthesis for printing:</p>
<pre><code>>>> print(str.__doc__)
</code></pre>
| 7 | 2009-08-13T07:50:59Z | [
"python",
"interactive"
] |
Python Get Docstring Without Going into Interactive Mode | 1,270,615 | <p>I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.</p>
<p>How do I get the docstring of an object and <strong>not</strong> have Python grab focus?</p>
| 5 | 2009-08-13T07:49:52Z | 1,270,639 | <p>You can use <code>dir(</code>{insert class name here}<code>)</code> to get the contents of a class and then iterate over it, looking for methods or other stuff. This example looks in a class <code>Task</code>for methods starting with the name <code>cmd</code> and gets their docstring:</p>
<pre><code>command_help = ... | 3 | 2009-08-13T07:54:18Z | [
"python",
"interactive"
] |
Python Get Docstring Without Going into Interactive Mode | 1,270,615 | <p>I want to grab the docstring in my commandline application, but every time I call the builtin help() function, Python goes into interactive mode.</p>
<p>How do I get the docstring of an object and <strong>not</strong> have Python grab focus?</p>
| 5 | 2009-08-13T07:49:52Z | 26,030,930 | <p><code>.__doc__</code> is the best choice. However, You can also use <code>inspect.getdoc</code> to get <code>docstring</code>. One advantage of using this is, it removes indentation from docstrings that are indented to line up with blocks of code.</p>
<p><strong>Example:</strong></p>
<pre><code>In [21]: def foo():... | 0 | 2014-09-25T05:06:44Z | [
"python",
"interactive"
] |
django unit testing and global fixtures | 1,270,657 | <p>I'm working on a web project in Django, and I'm using the python unittest framework. For every app I have some fixtures. This means, that every app has some identical tables in fixtures. I would like to share fixtures between apps and testcases, because otherwise if I change a model, I will have to change all json f... | 3 | 2009-08-13T08:00:20Z | 1,270,709 | <p>I would highly recommend looking into Django's <a href="http://docs.djangoproject.com/en/dev/topics/testing/" rel="nofollow">Testing architecture</a>. Check out TestCase.fixtures especially; this is far more advanced and Django-specific than unittest.</p>
| 1 | 2009-08-13T08:10:30Z | [
"python",
"django",
"unit-testing"
] |
django unit testing and global fixtures | 1,270,657 | <p>I'm working on a web project in Django, and I'm using the python unittest framework. For every app I have some fixtures. This means, that every app has some identical tables in fixtures. I would like to share fixtures between apps and testcases, because otherwise if I change a model, I will have to change all json f... | 3 | 2009-08-13T08:00:20Z | 1,270,976 | <p>I can't think of anything wrong with using global fixtures as long as you delete them in your <code>tearDown</code> method (or <code>teardown_test_environment</code> method - see below).</p>
<p>I am not sure if you are asking to find out how to do this. If so there are two ways that I can think of. </p>
<ol>
<li><... | 1 | 2009-08-13T09:28:56Z | [
"python",
"django",
"unit-testing"
] |
django unit testing and global fixtures | 1,270,657 | <p>I'm working on a web project in Django, and I'm using the python unittest framework. For every app I have some fixtures. This means, that every app has some identical tables in fixtures. I would like to share fixtures between apps and testcases, because otherwise if I change a model, I will have to change all json f... | 3 | 2009-08-13T08:00:20Z | 5,206,157 | <p>Do not use static fixtures, it is a bad automated tests pattern. Use dynamic fixtures.</p>
<p><a href="https://github.com/paulocheque/django-dynamic-fixture" rel="nofollow">Django Dynamic Fixture</a> has options to create global fixtures. Check its <a href="https://github.com/paulocheque/django-dynamic-fixture/wiki... | 2 | 2011-03-05T19:14:49Z | [
"python",
"django",
"unit-testing"
] |
Why does import of ctypes raise ImportError? | 1,270,738 | <pre><code>Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\ctypes\__init__.... | 3 | 2009-08-13T08:18:24Z | 1,270,756 | <p>It seems you have another struct.py in your path somewhere.</p>
<p>Try this to see where python finds your struct module:</p>
<pre><code>>>> import inspect
>>> import struct
>>> inspect.getabsfile(struct)
'c:\\python26\\lib\\struct.py'
</code></pre>
| 8 | 2009-08-13T08:23:35Z | [
"python",
"ctypes",
"python-2.6",
"importerror"
] |
Most concise way to check whether a list is empty or contains only None? | 1,270,920 | <p>Most concise way to check whether a list is empty or contains only None?</p>
<p>I understand that I can test:</p>
<pre><code>if MyList:
pass
</code></pre>
<p>and:</p>
<pre><code>if not MyList:
pass
</code></pre>
<p>but what if the list has an item (or multiple items), but those item/s are None:</p>
<pr... | 6 | 2009-08-13T09:13:24Z | 1,270,937 | <p>If you are concerned with elements in the list which evaluate as true:</p>
<pre><code>if mylist and filter(None, mylist):
print "List is not empty and contains some true values"
else:
print "Either list is empty, or it contains no true values"
</code></pre>
<p>If you want to strictly check for <code>None</... | 2 | 2009-08-13T09:19:15Z | [
"python",
"list",
"types"
] |
Most concise way to check whether a list is empty or contains only None? | 1,270,920 | <p>Most concise way to check whether a list is empty or contains only None?</p>
<p>I understand that I can test:</p>
<pre><code>if MyList:
pass
</code></pre>
<p>and:</p>
<pre><code>if not MyList:
pass
</code></pre>
<p>but what if the list has an item (or multiple items), but those item/s are None:</p>
<pr... | 6 | 2009-08-13T09:13:24Z | 1,270,938 | <p>One way is to use <a href="http://docs.python.org/3.1/library/functions.html#all"><code>all</code></a> and a list comprehension:</p>
<pre><code>if all(e is None for e in myList):
print('all empty or None')
</code></pre>
<p>This works for empty lists as well. More generally, to test whether the list only contai... | 15 | 2009-08-13T09:19:45Z | [
"python",
"list",
"types"
] |
Most concise way to check whether a list is empty or contains only None? | 1,270,920 | <p>Most concise way to check whether a list is empty or contains only None?</p>
<p>I understand that I can test:</p>
<pre><code>if MyList:
pass
</code></pre>
<p>and:</p>
<pre><code>if not MyList:
pass
</code></pre>
<p>but what if the list has an item (or multiple items), but those item/s are None:</p>
<pr... | 6 | 2009-08-13T09:13:24Z | 1,270,939 | <p>You can use the <code>all()</code> function to test is all elements are None:</p>
<pre><code>a = []
b = [None, None, None]
all(e is None for e in a) # True
all(e is None for e in b) # True
</code></pre>
| 9 | 2009-08-13T09:19:47Z | [
"python",
"list",
"types"
] |
Most concise way to check whether a list is empty or contains only None? | 1,270,920 | <p>Most concise way to check whether a list is empty or contains only None?</p>
<p>I understand that I can test:</p>
<pre><code>if MyList:
pass
</code></pre>
<p>and:</p>
<pre><code>if not MyList:
pass
</code></pre>
<p>but what if the list has an item (or multiple items), but those item/s are None:</p>
<pr... | 6 | 2009-08-13T09:13:24Z | 1,270,962 | <p>You can directly compare lists with <code>==</code>:</p>
<pre><code>if x == [None,None,None]:
if x == [1,2,3]
</code></pre>
| 4 | 2009-08-13T09:25:10Z | [
"python",
"list",
"types"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 1,270,970 | <p>Try to use a filename relative to the current files path. Example for './my_file':</p>
<pre><code>fn = os.path.join(os.path.dirname(__file__), 'my_file')
</code></pre>
| 128 | 2009-08-13T09:27:28Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 1,270,975 | <p>You can use the build in <code>__file__</code> variable. It contains the path of the current file. I would implement getBaseOfProject in a module in the root of your project. There I would get the path part of <code>__file__</code> and would return that. This method can then be used everywhere in your project.</p>
| 0 | 2009-08-13T09:28:40Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 1,271,027 | <pre><code>import os
cwd = os.getcwd()
path = os.path.join(cwd, "my_file")
f = open(path)
</code></pre>
<p>You also try to normalize your <code>cwd</code> using <code>os.path.abspath(os.getcwd())</code>. More info <a href="http://docs.python.org/library/os.path.html" rel="nofollow">here</a>.</p>
| 1 | 2009-08-13T09:40:27Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 1,271,580 | <p>I often use something similar to this:</p>
<pre><code>import os
DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'datadir'))
# if you have more paths to set, you might want to shorten this as
here = lambda x: os.path.abspath(os.path.join(os.path.dirname(__file__), x))
DATA_DIR = here('datadir')
... | 6 | 2009-08-13T12:11:19Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 4,874,611 | <p>I spent a long time figuring out the answer to this, but I finally got it (and it's actually really simple):</p>
<pre><code>import sys
import os
sys.path.append(os.getcwd() + '/your/subfolder/of/choice')
# now import whatever other modules you want, both the standard ones,
# as the ones supplied in your subfolders... | -2 | 2011-02-02T12:43:48Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
Python - how to refer to relative paths of resources when working with code repository | 1,270,951 | <p>We are working with a code repository which is deployed both to windows and linux, sometimes on different directories.
How should one of the modules inside the project refer to one of the non-python resources in the project (CSV file, etc.)?
If we do something like</p>
<pre><code>thefile=open('test.csv')
</code></p... | 89 | 2009-08-13T09:22:30Z | 9,177,940 | <p>If you are using setup tools or distribute (a setup.py install) then the "right" way to access these packaged resources seem to be using package_resources.</p>
<p>In your case the example would be</p>
<pre><code>import pkg_resources
my_data = pkg_resources.resource_string(__name__, "foo.dat")
</code></pre>
<p>Whi... | 23 | 2012-02-07T14:24:07Z | [
"python",
"path",
"repository",
"project",
"relative"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,270,999 | <pre><code>line = line[2:]
</code></pre>
| 2 | 2009-08-13T09:34:34Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,003 | <p><a href="http://docs.python.org/tutorial/introduction.html#strings">String slicing</a> will help you:</p>
<pre><code>>>> a="Some very long string"
>>> a[2:]
'me very long string'
</code></pre>
| 19 | 2009-08-13T09:35:00Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,005 | <p>Just use line[2:]</p>
| 0 | 2009-08-13T09:35:46Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,007 | <p>You were off to a good start. Try this in your loop:</p>
<pre><code>for line in lines:
line = line[2:]
# do something here
</code></pre>
<p>The [2:] is called "<a href="http://docs.python.org/tutorial/introduction.html#strings">slice</a>" syntax, it essentially says "give me the part of this sequence which... | 42 | 2009-08-13T09:36:11Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,029 | <p>Instead of using a for loop, you might be happier with a a list comprehension:</p>
<pre><code>[line[2:] for line in lines]
</code></pre>
<p><hr /></p>
<p>Just as a curiosity, do check the <code>cut</code> unix tool.</p>
<pre><code>$ cut -c2- filename
</code></pre>
<p>The slicing syntax for -c is quite similar t... | 10 | 2009-08-13T09:41:14Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,030 | <p>Just as a tip, you can shorten your program to </p>
<pre><code>for line in open('M:/file.txt'):
line = line[2:]
</code></pre>
<p>And if you need to carry the line number too, use</p>
<pre><code>for i, line in enumerate(open('M:/file.txt.')):
line = line[2:]
</code></pre>
| 10 | 2009-08-13T09:41:37Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,271,045 | <pre><code>for line in open("file"):
print line[2:]
</code></pre>
| 2 | 2009-08-13T09:44:27Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,272,548 | <p>If you want to modify a file's contents, not just process the string, try <code>fileinput</code>'s <code>inplace</code> parameter:</p>
<pre><code># strip_2_chars.py
import fileinput
for line in fileinput.input(inplace=1):
print line[2:]
</code></pre>
<p>Then, on the command line:</p>
<pre><code>python strip_2_c... | 3 | 2009-08-13T15:03:31Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,274,307 | <p>You'll find python has some great ways to deal with strings. Some other useful string methods you might want to check out are ones like split(), replace(), and startswith()/endswith().</p>
| 1 | 2009-08-13T20:13:42Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,311,668 | <p>It may be interesting to know that there is a subtle, yet important difference between:</p>
<pre><code>file = open( filename )
lines = file.readlines()
for line in lines:
do something
</code></pre>
<p>and</p>
<pre><code>file = open( filename )
for line in file:
do something
</code></pre>
<p>The first solu... | 3 | 2009-08-21T12:32:33Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 1,359,481 | <p>Since you are learning Python, I would like to add that, given the tools offered by Python (slicing, split, replace and all the other which have been mention), you will find that for many tasks regex are overkill. So the </p>
<pre><code>import re
</code></pre>
<p>at the beginning of your example may or may not be ... | 0 | 2009-08-31T21:21:23Z | [
"python"
] |
How to remove two chars from the beginning of a line | 1,270,990 | <p>I'm a complete Python noob. How can I remove two characters from the beginning of each line in a file? I was trying something like this:</p>
<pre><code>#!/Python26/
import re
f = open('M:/file.txt')
lines=f.readlines()
i=0;
for line in lines:
line = line.strip()
#do something here
</code></pre>
| 21 | 2009-08-13T09:31:53Z | 38,113,402 | <p>Not very efficient but yes it does work. Looks pretty complex.</p>
<pre><code>print line[-(len(line)-2):]
</code></pre>
| -1 | 2016-06-30T03:16:12Z | [
"python"
] |
Resize a figure automatically in matplotlib | 1,271,023 | <p>Is there a way to automatically resize a figure to properly fit contained plots in a matplotlib/pylab image? </p>
<p>I'm creating heatmap (sub)plots that differ in aspect ratio according to the data used.</p>
<p>I realise I could calculate the aspect ratio and manually set it, but surely there's an easier way? </... | 20 | 2009-08-13T09:38:46Z | 1,271,192 | <p>Do you mean changing the size of the image or the area that is visable within a plot?</p>
<p>The size of a figure can be set with <a href="http://matplotlib.sourceforge.net/api/figure%5Fapi.html" rel="nofollow">Figure.set_figsize_inches</a>.
Also the <a href="http://www.scipy.org/Cookbook/Matplotlib/AdjustingImageS... | 3 | 2009-08-13T10:31:09Z | [
"python",
"matplotlib"
] |
Resize a figure automatically in matplotlib | 1,271,023 | <p>Is there a way to automatically resize a figure to properly fit contained plots in a matplotlib/pylab image? </p>
<p>I'm creating heatmap (sub)plots that differ in aspect ratio according to the data used.</p>
<p>I realise I could calculate the aspect ratio and manually set it, but surely there's an easier way? </... | 20 | 2009-08-13T09:38:46Z | 1,278,685 | <p>Use <strong>bbox_inches='tight'</strong></p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
X = 10*np.random.rand(5,3)
fig = plt.figure(figsize=(15,5),facecolor='w')
ax = fig.add_subplot(111)
ax.imshow(X, cmap=cm.jet)
plt.savefig("image.png",bbox_inches='tight',dpi=100)... | 26 | 2009-08-14T15:57:48Z | [
"python",
"matplotlib"
] |
Resize a figure automatically in matplotlib | 1,271,023 | <p>Is there a way to automatically resize a figure to properly fit contained plots in a matplotlib/pylab image? </p>
<p>I'm creating heatmap (sub)plots that differ in aspect ratio according to the data used.</p>
<p>I realise I could calculate the aspect ratio and manually set it, but surely there's an easier way? </... | 20 | 2009-08-13T09:38:46Z | 10,448,306 | <p>just use aspect='auto' when you call imshow</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
X = 10*np.random.rand(5,3)
plt.imshow(X, aspect='auto')
</code></pre>
<p>it works even if it is just for showing and not saving</p>
| 10 | 2012-05-04T11:51:06Z | [
"python",
"matplotlib"
] |
How to change the "Event" portlet in Plone 3 | 1,271,057 | <p>I am trying to customize the "Event" portlet in Plone 3 that shows the upcoming events. The "view" link in the footer of that portlet goes to the /events URL. But my site is multi-lingual so that URL is not always correct. For example, the correct URL for Dutch events should be /evenementen.</p>
<p>In my setup I us... | 1 | 2009-08-13T09:47:59Z | 1,271,573 | <p>The events portlet uses a view to provide it with data, and the expression 'view/all_events_link' calls a <a href="http://dev.plone.org/plone/browser/plone.app.portlets/trunk/plone/app/portlets/portlets/events.py#L75" rel="nofollow" title="events view source code">method on that view</a> to provide it with a link. Y... | 1 | 2009-08-13T12:08:18Z | [
"python",
"portlet",
"plone",
"zope"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 1,271,323 | <p>I'd go with IronPython and this article : <a href="http://www.blackwasp.co.uk/MapDriveLetter.aspx" rel="nofollow">Mapping a Drive Letter Programmatically</a>. Or you could use the Win32 API directly.</p>
| 2 | 2009-08-13T11:12:35Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 1,271,485 | <p>Here are a couple links which show use of the win32net module that should provide the functionality you need.</p>
<p><a href="http://docs.activestate.com/activepython/2.4/pywin32/html/win32/help/win32net.html" rel="nofollow">http://docs.activestate.com/activepython/2.4/pywin32/html/win32/help/win32net.html</a>
<a h... | 2 | 2009-08-13T11:46:02Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 1,272,040 | <p>I don't have a server to test with here at home, but maybe you could simply use the standard library's subprocess module to execute the appropriate NET USE command?</p>
<p>Looking at NET HELP USE from a windows command prompt, looks like you should be able to enter both the password and user id in the net use comma... | 2 | 2009-08-13T13:42:57Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 1,860,152 | <p>Assuming that you import necessary libraries, This was a part of an RPC server where the client requested the server to map a drive locally...</p>
<pre><code>#Small function to check the availability of network resource.
def isAvailable(path):
winCMD = 'IF EXIST ' + path + ' echo YES'
cmdOutPut = subprocess... | 2 | 2009-12-07T14:00:50Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 2,093,830 | <p>Okay, Here's another method...</p>
<p>This one was after going through win32wnet. Let me know what you think...</p>
<pre><code>def mapDrive(drive, networkPath, user, password, force=0):
print networkPath
if (os.path.exists(drive)):
print drive, " Drive in use, trying to unmap..."
if force:
... | 4 | 2010-01-19T13:38:46Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 19,171,820 | <p>Building off of @Anon's suggestion:</p>
<pre><code># Drive letter: M
# Shared drive path: \\shared\folder
# Username: user123
# Password: password
import subprocess
# Disconnect anything on M
subprocess.call(r'net use m: /del', shell=True)
# Connect to shared drive, use drive letter M
subprocess.call(r'net use m:... | 9 | 2013-10-04T01:39:49Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 20,201,066 | <p>I had trouble getting this line to work: </p>
<p>win32wnet.WNetAddConnection2(win32netcon.RESOURCETYPE_DISK, drive, networkPath, None, user, password)</p>
<p>But was successful with this:</p>
<p>win32wnet.WNetAddConnection2(1, 'Z:', r'\UNCpath\share', None, 'login', 'password') </p>
| 0 | 2013-11-25T19:01:44Z | [
"python",
"windows",
"mapping",
"drive"
] |
What is the best way to map windows drives using Python? | 1,271,317 | <p>What is the best way to map a network share to a windows drive using Python?
This share also requires a username and password.</p>
| 11 | 2009-08-13T11:09:36Z | 21,732,529 | <p>If you want to map the current login user, i think subprocess solve your problem. But is you want to control different mappings for different users, from a single master account. You could do this from the register of windows</p>
<p>The idea is to load the profile of a given user.</p>
<pre><code>import win32api
im... | 0 | 2014-02-12T15:41:21Z | [
"python",
"windows",
"mapping",
"drive"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 1,271,349 | <p>If GrzegorzOledzki's answer won't suffice, you could probably use <code>send()</code> to accomplish your goal. See <a href="http://www.python.org/dev/peps/pep-0342/" rel="nofollow">PEP-0342</a> for more details on enhanced generators and yield expressions.</p>
<p>UPDATE: Also see <a href="http://docs.python.org/lib... | 4 | 2009-08-13T11:17:40Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 1,271,353 | <p>Generators can't be rewound. You have the following options:</p>
<ol>
<li><p>Run the generator function again, restarting the generation:</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
y = FunctionWithYield()
for x in y: print(x)
</code></pre></li>
<li><p>Store the generator results in a data structur... | 71 | 2009-08-13T11:18:29Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 1,271,459 | <p>Probably the most simple solution is to wrap the expensive part in an object and pass that to the generator:</p>
<pre><code>data = ExpensiveSetup()
for x in FunctionWithYield(data): pass
for x in FunctionWithYield(data): pass
</code></pre>
<p>This way, you can cache the expensive calculations.</p>
<p>If you can k... | 16 | 2009-08-13T11:39:50Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 1,271,481 | <p>Another option is to use the <code>itertools.tee()</code> function to create a second version of your generator:</p>
<pre><code>y = FunctionWithYield()
y, y_backup = tee(y)
for x in y:
print(x)
for x in y_backup:
print(x)
</code></pre>
<p>This could be beneficial from memory usage point of view if the orig... | 47 | 2009-08-13T11:44:17Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 1,271,699 | <p>I'm not sure what you meant by expensive preparation, but I guess you actually have</p>
<pre><code>data = ... # Expensive computation
y = FunctionWithYield(data)
for x in y: print(x)
#here must be something to reset 'y'
# this is expensive - data = ... # Expensive computation
# y = FunctionWithYield(data)
for x in ... | 0 | 2009-08-13T12:38:04Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 18,455,731 | <p>It can be done by code object. Here is the example.</p>
<pre><code>code_str="y=(a for a in [1,2,3,4])"
code1=compile(code_str,'<string>','single')
exec(code1)
for i in y: print i
</code></pre>
<p>1
2
3
4</p>
<pre><code>for i in y: print i
exec(code1)
for i in y: print i
</code></pre>
<p>1
2
3
4</p>
| -3 | 2013-08-27T01:56:15Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 19,403,253 | <pre><code>>>> def gen():
... def init():
... return 0
... i = init()
... while True:
... val = (yield i)
... if val=='restart':
... i = init()
... else:
... i += 1
>>> g = gen()
>>> g.next()
0
>>> g.next()
1
>&g... | 17 | 2013-10-16T12:21:14Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 35,840,651 | <p>You can define a function that returns your generator</p>
<pre><code>def f():
def FunctionWithYield(generator_args):
code here...
return FunctionWithYield
</code></pre>
<p>Now you can just do as many times as you like:</p>
<pre><code>for x in f()(generator_args): print(x)
for x in f()(generator_args): pr... | 0 | 2016-03-07T09:55:55Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 39,392,965 | <p>From <a href="https://docs.python.org/3/library/itertools.html#itertools.tee" rel="nofollow">official documentation of tee</a>:</p>
<blockquote>
<p>In general, if one iterator uses most or all of the data before
another iterator starts, it is faster to use list() instead of tee().</p>
</blockquote>
<p>So it's ... | 1 | 2016-09-08T13:59:22Z | [
"python",
"generator",
"yield"
] |
Reseting generator object in Python | 1,271,320 | <p>I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.</p>
<pre><code>y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
</code></pre>
<p>Of ... | 73 | 2009-08-13T11:10:48Z | 39,564,774 | <p>I want to offer a different solution to an old problem</p>
<pre><code>class ReusableGenerator:
def __init__(self, generator_factory):
self.generator_factory = generator_factory
def __iter__(self):
return self.generator_factory()
squares = ReusableGenerator(lambda: (x * x for x in range(5))... | 0 | 2016-09-19T03:04:43Z | [
"python",
"generator",
"yield"
] |
ImportError: no module named py2exe | 1,271,337 | <p>I get this error when I try to use one of the py2exe samples with py2exe.</p>
<pre><code>File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
</code></pre>
<p>I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The py... | 9 | 2009-08-13T11:14:34Z | 1,271,366 | <p>If you have any other versions of Python installed, it may be that another Python version is the default Python. Could this be the case? I believe the default Python installation is determined from a registry setting.</p>
| 2 | 2009-08-13T11:20:45Z | [
"python",
"py2exe"
] |
ImportError: no module named py2exe | 1,271,337 | <p>I get this error when I try to use one of the py2exe samples with py2exe.</p>
<pre><code>File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
</code></pre>
<p>I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The py... | 9 | 2009-08-13T11:14:34Z | 1,271,495 | <p>Sounds like something has installed Python 2.4.3 behind your back, and set that to be the default.</p>
<p>Short term, try running your script explicitly with Python 2.6 like this:</p>
<pre><code>c:\Python26\python.exe setup.py ...
</code></pre>
<p>Long term, you need to check your system PATH (which it sounds lik... | 7 | 2009-08-13T11:47:55Z | [
"python",
"py2exe"
] |
ImportError: no module named py2exe | 1,271,337 | <p>I get this error when I try to use one of the py2exe samples with py2exe.</p>
<pre><code>File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
</code></pre>
<p>I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The py... | 9 | 2009-08-13T11:14:34Z | 1,968,540 | <p>Seems like you need to download proper <a href="http://sourceforge.net/projects/py2exe/">py2exe</a> distribution. </p>
<p>Check out if your <code>c:\Python26\Lib\site-packages\</code> contains <code>py2exe</code> folder.</p>
| 5 | 2009-12-28T08:26:58Z | [
"python",
"py2exe"
] |
ImportError: no module named py2exe | 1,271,337 | <p>I get this error when I try to use one of the py2exe samples with py2exe.</p>
<pre><code>File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
</code></pre>
<p>I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The py... | 9 | 2009-08-13T11:14:34Z | 7,202,892 | <p>I had the exact same issue and I just managed to get it solved - so I thought I would share my solution.</p>
<p>It turned out that my installation of CollabNet SVN contained an old version of Python that interfered with my recent Python2.7 installation.</p>
<p>Replacing CollabNet SVN with VisualSVN (including a co... | 3 | 2011-08-26T09:43:59Z | [
"python",
"py2exe"
] |
ImportError: no module named py2exe | 1,271,337 | <p>I get this error when I try to use one of the py2exe samples with py2exe.</p>
<pre><code>File "setup.py", line 22, in ?
import py2exe
ImportError: no module named py2exe
</code></pre>
<p>I've installed py2exe with the installer, and I use python 2.6. I have downloaded the correct installer from the site (The py... | 9 | 2009-08-13T11:14:34Z | 9,928,563 | <p>For the record, my very similar problem was caused by using a <em>Cygwin</em> prompt. Using as standard <em>cmd.exe</em> shell instead worked (given all paths and correctly installed versions of python).</p>
<p>This was because (stupid me) the Cygwin install had pulled down it's own version of <code>/usr/bin/python... | 0 | 2012-03-29T15:28:20Z | [
"python",
"py2exe"
] |
Is there an equivalent of Pythons range(12) in C#? | 1,271,378 | <p>This crops up every now and then for me: I have some C# code badly wanting the <code>range()</code> function available in Python.</p>
<p>I am aware of using</p>
<pre><code>for (int i = 0; i < 12; i++)
{
// add code here
}
</code></pre>
<p>But this brakes down in functional usages, as when I want to do a Lin... | 31 | 2009-08-13T11:22:57Z | 1,271,388 | <p>You're looking for the <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx"><code>Enumerable.Range</code></a> method:</p>
<pre><code>var mySequence = Enumerable.Range(0, 12);
</code></pre>
| 60 | 2009-08-13T11:24:19Z | [
"c#",
"python",
"range"
] |
Is there an equivalent of Pythons range(12) in C#? | 1,271,378 | <p>This crops up every now and then for me: I have some C# code badly wanting the <code>range()</code> function available in Python.</p>
<p>I am aware of using</p>
<pre><code>for (int i = 0; i < 12; i++)
{
// add code here
}
</code></pre>
<p>But this brakes down in functional usages, as when I want to do a Lin... | 31 | 2009-08-13T11:22:57Z | 1,271,394 | <pre><code>Enumerable.Range(start, numElements);
</code></pre>
<p>Sample <a href="http://www.hookedonlinq.com/RangeOperator.ashx" rel="nofollow">here</a>.</p>
| 6 | 2009-08-13T11:24:48Z | [
"c#",
"python",
"range"
] |
Is there an equivalent of Pythons range(12) in C#? | 1,271,378 | <p>This crops up every now and then for me: I have some C# code badly wanting the <code>range()</code> function available in Python.</p>
<p>I am aware of using</p>
<pre><code>for (int i = 0; i < 12; i++)
{
// add code here
}
</code></pre>
<p>But this brakes down in functional usages, as when I want to do a Lin... | 31 | 2009-08-13T11:22:57Z | 1,271,399 | <p>Enumerable.Range(0,12);</p>
| 4 | 2009-08-13T11:25:53Z | [
"c#",
"python",
"range"
] |
Is there an equivalent of Pythons range(12) in C#? | 1,271,378 | <p>This crops up every now and then for me: I have some C# code badly wanting the <code>range()</code> function available in Python.</p>
<p>I am aware of using</p>
<pre><code>for (int i = 0; i < 12; i++)
{
// add code here
}
</code></pre>
<p>But this brakes down in functional usages, as when I want to do a Lin... | 31 | 2009-08-13T11:22:57Z | 23,062,619 | <p>Just to complement everyone's answers, I thought I should add that <code>Enumerable.Range(0, 12);</code> is closer to Python's <code>xrange(12)</code> because it's an enumerable.</p>
<p>If anyone is looking specifically for a list or an array:</p>
<pre><code>Enumerable.Range(0, 12).ToList();
</code></pre>
<p>or</... | 10 | 2014-04-14T14:22:09Z | [
"c#",
"python",
"range"
] |
python db insert | 1,271,502 | <p>I am in facing a performance problem in my code.I am making db connection a making a select query and then inserting in a table.Around 500 rows in one select query ids populated .Before inserting i am running select query around 8-9 times first and then inserting then all using cursor.executemany.But it is taking 2... | 0 | 2009-08-13T11:49:32Z | 1,271,815 | <p>I don't really understand why you're doing this.</p>
<p>It seems that you want to insert a subset of rows from "assd" into one table, and another subset into another table?</p>
<p>Why not just do it with two SQL statements, structured like this:</p>
<pre><code>insert into tab1 select * from assd where asd_id = 42... | 3 | 2009-08-13T12:59:47Z | [
"python"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 1,271,873 | <p>You will need to add the <code>DEBUG</code> flag to your <code>context_processors</code>.</p>
<p>There may not even be an alternative way. At least, none that I know of.</p>
| 0 | 2009-08-13T13:12:51Z | [
"python",
"django",
"templates"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 1,271,914 | <p>Assuming you haven't set <code>TEMPLATE_CONTEXT_PROCESSORS</code> to some other value in <code>settings.py</code>, Django will automatically load the <code>debug</code> context preprocessor (as noted <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/#id1">here</a>). This means that you will have access... | 51 | 2009-08-13T13:23:07Z | [
"python",
"django",
"templates"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 1,272,312 | <p>If you haven't already, it always helps to see if/how others have dealt with same issue on djangosnippets. The most recent snippet working with analytics tag is 1656:
<a href="http://www.djangosnippets.org/snippets/1656/" rel="nofollow">http://www.djangosnippets.org/snippets/1656/</a></p>
<p>What is nice about this... | 5 | 2009-08-13T14:28:01Z | [
"python",
"django",
"templates"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 13,609,888 | <p>If modifying <code>INTERNAL_IPS</code> is not possible/suitable, you can do this with a context processor:</p>
<p>in <code>myapp/context_processors.py</code>:</p>
<pre><code>from django.conf import settings
def debug(context):
return {'DEBUG': settings.DEBUG}
</code></pre>
<p>in <code>settings.py</code>:</p>
... | 41 | 2012-11-28T16:32:40Z | [
"python",
"django",
"templates"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 37,531,987 | <p><strong>Django 1.9</strong> <code>settings.py</code>:</p>
<pre><code>INTERNAL_IPS = (
'127.0.0.1',
)
</code></pre>
<p>Templates:</p>
<pre><code>{% if debug %}
</code></pre>
<p><a href="https://docs.djangoproject.com/en/1.9/ref/settings/#std:setting-INTERNAL_IPS" rel="nofollow">https://docs.djangoproject.com/... | 4 | 2016-05-30T18:45:21Z | [
"python",
"django",
"templates"
] |
How to check the TEMPLATE_DEBUG flag in a django template? | 1,271,631 | <p>Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?</p>
<p>I would like to disable my google analytics script when I am running my django app on my development machine. Something like a {% if debug %} template tag would be perfect. Unfortunately, I didn't find something lik... | 43 | 2009-08-13T12:25:06Z | 39,074,975 | <p><code>{% if debug %}</code> can do the trick but only if you pass <code>RequestContext</code> instead of <code>Context</code>. Additionally, <code>debug</code> is not a boolean flag, its a function that when evaluated while <code>DEBUG = True</code> return some debugging information. This can be unnecessary overhead... | 0 | 2016-08-22T08:46:48Z | [
"python",
"django",
"templates"
] |
How to get started with Sessions in Google App Engine / Django? | 1,271,892 | <p>I'm new to Python / GAE / Django. I get that with GAE there are no in-memory sessions per se... but I think I want something equivalent. I <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">read</a> that Django sessions <a href="http://code.google.com/appengine/articles/appengine%5Fh... | 5 | 2009-08-13T13:17:31Z | 1,273,704 | <p>The gaeutilities library comes with a session management class that works well:</p>
<ul>
<li><a href="http://gaeutilities.appspot.com/" rel="nofollow">http://gaeutilities.appspot.com/</a></li>
</ul>
| 1 | 2009-08-13T18:18:32Z | [
"python",
"django",
"google-app-engine"
] |
How to get started with Sessions in Google App Engine / Django? | 1,271,892 | <p>I'm new to Python / GAE / Django. I get that with GAE there are no in-memory sessions per se... but I think I want something equivalent. I <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">read</a> that Django sessions <a href="http://code.google.com/appengine/articles/appengine%5Fh... | 5 | 2009-08-13T13:17:31Z | 1,273,792 | <p>The reason django sessions are not supported by App engine out of the box is because django uses database table (model) based sessions, and the django ORM is not supported on appengine.</p>
<p>A solution to this is to make django models work out of the box on appengine. And it has been done by patching django code,... | 3 | 2009-08-13T18:34:59Z | [
"python",
"django",
"google-app-engine"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.