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
How to get field names when running plain sql query in django
805,660
<p>In one of my django views I query database using plain sql (not orm) and return results. </p> <pre><code>sql = "select * from foo_bar" cursor = connection.cursor() cursor.execute(sql) rows = cursor.fetchall() </code></pre> <p>I am getting the data fine, but not the column names. How can I get the field names of th...
5
2009-04-30T06:49:33Z
805,778
<p>According to <a href="http://www.python.org/dev/peps/pep-0249/" rel="nofollow">PEP 249</a>, you can try using <code>cursor.description</code>, but this is not entirely reliable.</p>
7
2009-04-30T07:30:21Z
[ "python", "django" ]
How to get field names when running plain sql query in django
805,660
<p>In one of my django views I query database using plain sql (not orm) and return results. </p> <pre><code>sql = "select * from foo_bar" cursor = connection.cursor() cursor.execute(sql) rows = cursor.fetchall() </code></pre> <p>I am getting the data fine, but not the column names. How can I get the field names of th...
5
2009-04-30T06:49:33Z
14,215,488
<p>I have found a nice solution in Doug Hellmann's blog:</p> <p><a href="http://doughellmann.com/2007/12/30/using-raw-sql-in-django.html" rel="nofollow">http://doughellmann.com/2007/12/30/using-raw-sql-in-django.html</a></p> <pre><code>from itertools import * from django.db import connection def query_to_dicts(query...
3
2013-01-08T12:58:21Z
[ "python", "django" ]
How to get field names when running plain sql query in django
805,660
<p>In one of my django views I query database using plain sql (not orm) and return results. </p> <pre><code>sql = "select * from foo_bar" cursor = connection.cursor() cursor.execute(sql) rows = cursor.fetchall() </code></pre> <p>I am getting the data fine, but not the column names. How can I get the field names of th...
5
2009-04-30T06:49:33Z
25,330,129
<p>On the <a href="https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly" rel="nofollow">Django docs</a>, there's a pretty simple method provided (which does indeed use <code>cursor.description</code>, as Ignacio answered).</p> <pre><code>def dictfetchall(cursor): "Returns all rows fro...
4
2014-08-15T16:15:44Z
[ "python", "django" ]
how to avoid hard-coding urls in webapp templates
805,751
<p>I'm developing software on google app engine. I'm using the webapp framework. is there any way to avoid hard-coding urls in the html templates? django provides a solution, but I couldn't find one for webapp. thanks in advance..</p>
3
2009-04-30T07:20:16Z
806,422
<p>WebApp is really very basic.</p> <p>Django <code>url</code> templatetag is closely tied to its idea of URL resolving by matching regex patterns. As WebApp does not have any serious URL resolver, I imagine this would be really hard task to implement something in this line.</p> <p>But you are not totally out of luck...
1
2009-04-30T11:12:41Z
[ "python", "google-app-engine", "url", "templates", "web-applications" ]
how to avoid hard-coding urls in webapp templates
805,751
<p>I'm developing software on google app engine. I'm using the webapp framework. is there any way to avoid hard-coding urls in the html templates? django provides a solution, but I couldn't find one for webapp. thanks in advance..</p>
3
2009-04-30T07:20:16Z
5,691,622
<p>Webapp uses Django templates so: check out <a href="http://docs.djangoproject.com/en/1.3/ref/templates/builtin/#ref-templates-builtin-tags" rel="nofollow">Django templates here</a></p> <p>The Django solution <em>is</em> the web app solution.</p>
0
2011-04-17T05:08:25Z
[ "python", "google-app-engine", "url", "templates", "web-applications" ]
Sphinx automated image numbering/captions?
805,943
<p>Is there a way to automatically generate an image/figure caption using sphinx?</p> <p>I currently have rest-sphinx files I'm converting to html and (latex)pdf using sphinx.</p> <p>I'd like an easy way for users to reference a specific image in the resulting html/pdf files. For example, if a user is refering to the...
3
2009-04-30T08:37:39Z
806,080
<p>Sphinx consumes reStructuredText as templated by <a href="http://jinja.pocoo.org/2/documentation/" rel="nofollow">Jinja</a>. According to the Sphinx documentation though, you <a href="http://sphinx.pocoo.org/templating.html" rel="nofollow">have other templating options</a>.</p> <p>You should be able to use Jinja's ...
2
2009-04-30T09:23:29Z
[ "python", "templates", "python-sphinx" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,004
<p>Several years ago, I more or less learned web app programming on the job. C was the main language I knew, so I wrote the (fairly large-scale) web app in C. Bad mistake. C's string handling and memory management is tedious, and together with my lack of experience in web apps, it quickly became a hard-to-maintain proj...
20
2009-04-30T09:00:35Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,037
<p>Using C++ is likely to result in a radically faster application than PHP, Perl or Python and somewhat faster than C# or Java - unless it spends most of its time waiting for the DB, in which case there won't be a difference. This is actually the most common case.</p> <p>On the other hand, due to the reasons benhoyt ...
11
2009-04-30T09:08:44Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,042
<p>You can use FastCGI with PHP/Python/Ruby/Perl to get runtime performance that should be enough until your site grows really big. And even then, you can make architectural improvements (database tuning, caching etc) to scale even more without abandoning scripting languages. Some pretty large sites are done in PHP/Pyt...
2
2009-04-30T09:09:41Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,135
<p>I think that someone should be a pioneer in Webapp/C++ topic, to test the ground and provide proof of concept solutions.</p> <p>With arrival of STL and development of Boost parsing text happened to be extremely easy with C++. Two years ago, if I would have to parse CSV data I would use Python or PHP. Now I use C++ ...
8
2009-04-30T09:39:25Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,181
<p>Having a FastCGI web application (no matter C++, PHP, Perl, Python, Ruby etc.) gives you better initial startup time than a CGI application. By <em>initial startup time</em> I mean the time elapsed between the time the web server receives the request and the time the the first code line you've written is run, so the...
4
2009-04-30T09:50:21Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,195
<p>scripting languages may be slower than C, but is this a problem? almost never. and if the performance becomes a problem, you start to translate only the critical parts.</p> <p>twitter/ruby is a good example; ruby is slow. some of the language features (that make ruby nice in the first place) just prevent different ...
30
2009-04-30T09:54:56Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,257
<p>If you want to be able to implement web services in an existing running process (e.g. daemon), which is written in C/C++. It makes sense to make that process implement the FastCGI protocol for that interface. Get Apache to deal with HTTP (2-way SSL etc) to the outside world and field requests through FastCGI through...
6
2009-04-30T10:10:36Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,293
<p>The question is "where's the value created?"</p> <p>If you think the value is created in Memory management, careful class design and getting the nightly build to work, then use C++. You'll get to spend lots of time writing a lot of code to do important things like deleting objects that are no longer referenced.</p...
7
2009-04-30T10:21:35Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,412
<p>There are people who asked this before: <a href="http://cppcms.sourceforge.net/wikipp/en/page/main" rel="nofollow">http://cppcms.sourceforge.net/wikipp/en/page/main</a></p> <p>CppCMS project provides a framework for web development using C++.</p> <p>You can take a look on following benchmarks to understand what is...
3
2009-04-30T11:07:42Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
806,988
<p>There is a middle ground here. Python (and I believe Perl and Ruby) allow you to call functions from C. 99 times out of 100, you won't need to. But it's nice to know that the option is there if you need it.</p> <p>Usually for webapps, the speed of the programming language simply isn't an issue. In the time it t...
3
2009-04-30T13:45:47Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
1,321,663
<p>Too bad there are no benchmarks of C/C++ vs Perl CGI.<br /> Without FastCGI I think C/C++ would be a lot faster, with FastCGI possibly it'll be faster (but maybe a little less - all the initialization part is executed once).<br /> Again this is very <em>application</em> dependent, so some sort of benchmarks for diff...
1
2009-08-24T10:47:50Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
1,470,204
<p>Well... You will save memory and CPU power with C/C++ vs Python/Perl/Ruby/Java/.NET. If the resources saved by using C/C++ represents a large fraction of the total resources available (a FastCGI running on the embedded board of a robot), then yeah, C/C++. Else, why bother ?</p>
2
2009-09-24T07:20:51Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
1,979,362
<p>Probably someone of you could be interesting in Wt [1], a web toolkit entirely written in C++. It could be an alternative to cppCMS. I'm trying both in these christmas holidays..</p> <p>[1] <a href="http://www.webtoolkit.eu/wt" rel="nofollow">http://www.webtoolkit.eu/wt</a></p>
2
2009-12-30T10:00:47Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
9,231,448
<p>C++ is a strongly typed language...i.e. you can declare ints, floats, etc....generally you can program more efficiently than you can with weakly typed languages. Facebook reported a 50% improvement when switching from PHP to C++. I would consider scripting languages to be prototyping languages...when you want prod...
1
2012-02-10T16:48:03Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
9,242,626
<p>My every search through Google indicates C/C++ gives best performance for web apps that need functionality such as searching for information in web pages or getting information from a database. </p>
0
2012-02-11T18:04:15Z
[ "php", "c++", "python", "perl", "fastcgi" ]
FastCGI C++ vs. A Script Language (PHP/Python/Perl)
805,957
<p>What are the ups and downs of using FastCGI C++ vs. PHP/Python/Perl to do the same job. </p> <p>Any performance or design pitfalls or using one over the other? Even your opinions are welcome. (Tell me why one or the other rocks, or one or the other sucks). </p>
19
2009-04-30T08:43:03Z
9,242,979
<p>There are some new answers for this.</p> <ol> <li>If you need a compiled application, you might find that <a href="http://golang.org" rel="nofollow">Google's Go language</a> is a nice compiled language with modern features.</li> <li>Writing an application in a scripting language (I use Perl) can be done through fra...
0
2012-02-11T18:44:30Z
[ "php", "c++", "python", "perl", "fastcgi" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
806,286
<p>What's the format of the data in the arrays? Couldn't you just iterate through the arrays, convert them into a string (via some reproducible means) and then feed that into your hash via update?</p> <p>e.g.</p> <pre><code>import hashlib m = hashlib.md5() # or sha1 etc for value in array: # array contains the data ...
3
2009-04-30T10:17:59Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
806,342
<p>Thanks to John Montgomery I think I have found a solution, and I think it has less overhead than converting every number in possibly <em>huge</em> arrays to strings:</p> <p>I can create a byte-view of the arrays and use these to update the hash. And somehow this seems to give the same digest as directly updating us...
23
2009-04-30T10:42:19Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
1,315,493
<p>array.data is always hashable, because it's a buffer object. easy :) (unless you care about the difference between differently-shaped arrays with the exact same data, etc.. (ie this is suitable unless shape, byteorder, and other array 'parameters' must also figure into the hash)</p>
1
2009-08-22T08:29:55Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
5,463,871
<p>Here is how I do it in <a href="http://luispedro.org/software/jug" rel="nofollow" title="jug homepage">jug</a> (git HEAD at the time of this answer):</p> <pre><code>e = some_array_object M = hashlib.md5() M.update('np.ndarray') M.update(pickle.dumps(e.dtype)) M.update(pickle.dumps(e.shape)) try: buffer = e.data...
2
2011-03-28T19:14:09Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
5,465,268
<p>There is a package for memoizing functions that use numpy arrays as inputs <a href="http://packages.python.org/joblib/memory.html" rel="nofollow">joblib</a>. Found from <a href="http://stackoverflow.com/questions/5362781/numpy-ndarray-memoization">this</a> question. </p>
3
2011-03-28T21:27:04Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
19,457,314
<p>Fastest by some margin seems to be:</p> <blockquote> <blockquote> <blockquote> <p>hash(iter(a))</p> </blockquote> </blockquote> </blockquote> <p>a is a numpy ndarray.</p> <p>Obviously not secure hashing, but it should be good for caching etc.</p>
1
2013-10-18T19:08:40Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
How to hash a large object (dataset) in Python?
806,151
<p>I would like to calculate a hash of a Python class containing a dataset for Machine Learning. The hash is meant to be used for caching, so I was thinking of <code>md5</code> or <code>sha1</code>. The problem is that most of the data is stored in NumPy arrays; these do not provide a <code>__hash__()</code> member. Cu...
25
2009-04-30T09:43:57Z
35,059,367
<p>Using Numpy 1.10.1 and python 2.7.6, you can now simply hash numpy arrays using hashlib if the array is C-contiguous (use <code>numpy.ascontiguousarray()</code> if not), e.g.</p> <pre><code>&gt;&gt;&gt; h = hashlib.md5() &gt;&gt;&gt; arr = numpy.arange(101) &gt;&gt;&gt; h.update(arr) &gt;&gt;&gt; print(h.hexdigest(...
1
2016-01-28T10:50:28Z
[ "python", "hash", "numpy", "sha1", "pickle" ]
Can I encrypt email and decrypt it back using python default library set?
806,739
<p>Of course similar questions have been asked in stackoverflow but I don't want to use any third party library like Crypto or something. So I need to generate a ciphertext from a user email and decrypt it back to plaintext. How can I do this in python?</p>
6
2009-04-30T12:54:26Z
806,765
<p>Yes, you can. Read <a href="http://www.amk.ca/python/code/crypto.html" rel="nofollow">http://www.amk.ca/python/code/crypto.html</a> You'll find an answer there ;)</p> <p>You're question is not concrete enough to say more. You may want to read <a href="http://en.wikipedia.org/wiki/Cryptography#Modern_cryptography" ...
3
2009-04-30T12:59:17Z
[ "python", "encryption" ]
Can I encrypt email and decrypt it back using python default library set?
806,739
<p>Of course similar questions have been asked in stackoverflow but I don't want to use any third party library like Crypto or something. So I need to generate a ciphertext from a user email and decrypt it back to plaintext. How can I do this in python?</p>
6
2009-04-30T12:54:26Z
806,955
<p>A third-party system is your best bet.<br /> If you really can't/don't want to use a third-party, maybe something simple would suffice.</p> <p>One of the simpler algorithms is the <a href="http://en.wikipedia.org/wiki/Tiny%5FEncryption%5FAlgorithm" rel="nofollow">Tiny Encryption Algorithm</a> (TEA). <a href="http:...
4
2009-04-30T13:38:11Z
[ "python", "encryption" ]
Can I encrypt email and decrypt it back using python default library set?
806,739
<p>Of course similar questions have been asked in stackoverflow but I don't want to use any third party library like Crypto or something. So I need to generate a ciphertext from a user email and decrypt it back to plaintext. How can I do this in python?</p>
6
2009-04-30T12:54:26Z
815,176
<p>If what you mean is that you want to roll your own encryption system, you could try using the built-in hmac and hashlib modules. (hashlib is new for 2.5, so if you must use an earlier Python, your hash choices are the older md5 and sha modules.)</p> <p>If you are opposed to <em>installing</em> a third-party librar...
1
2009-05-02T16:47:55Z
[ "python", "encryption" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
806,912
<p>Django's built-in authentication works the way you want.</p> <p>Their login pages include a <code>next</code> query string which is the page to return to after login.</p> <p>Look at <a href="http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.login_required">http://docs.djangoproject.c...
13
2009-04-30T13:30:58Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
806,918
<p>See django docs for <a href="http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.login" rel="nofollow">views.login()</a>, you supply a 'next' value (as a hidden field) on the input form to redirect to after a successful login.</p>
0
2009-04-30T13:31:30Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
807,044
<p>I linked to the login form by passing the current page as a GET parameter and then used 'next' to redirect to that page. Thanks!</p>
1
2009-04-30T13:58:45Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
808,096
<p>This may not be a "best practice", but I've successfully used this before:</p> <pre><code>return HttpResponseRedirect(request.META.get('HTTP_REFERER','/')) </code></pre>
24
2009-04-30T17:22:31Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
1,711,592
<p>You do not need to make an extra view for this, the functionality is already built in.</p> <p>First each page with a login link needs to know the current path, and the easiest way is to add the request context preprosessor to settings.py (the 4 first are default), then the request object will be available in each r...
105
2009-11-10T22:09:23Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
2,388,056
<p>I encountered the same problem. This solution allows me to keep using the generic login view:</p> <pre><code>urlpatterns += patterns('django.views.generic.simple', (r'^accounts/profile/$', 'redirect_to', {'url': 'generic_account_url'}), ) </code></pre>
1
2010-03-05T16:00:32Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
9,110,314
<p>In <code>registration/login.html</code> (nested within <code>templates</code> folder) if you insert the following line, the page will render like Django's original admin login page:</p> <pre><code>{% include "admin/login.html" %} </code></pre> <p><b>Note: The file should contain above lines only.</b></p>
1
2012-02-02T09:59:51Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
13,595,154
<p>To support full urls with param/values you'd need:</p> <pre><code>?next={{ request.get_full_path|urlencode }} </code></pre> <p>instead of just:</p> <pre><code>?next={{ request.path }} </code></pre>
17
2012-11-27T23:33:01Z
[ "python", "django" ]
Django: Redirect to previous page after login
806,835
<p>I'm trying to build a simple website with login functionality very similar to the one here on SO. The user should be able to browse the site as an anonymous user and there will be a login link on every page. When clicking on the login link the user will be taken to the login form. After a successful login the user s...
129
2009-04-30T13:14:14Z
16,597,099
<p>You can also do this</p> <pre><code>&lt;input type="hidden" name="text" value="{% url 'dashboard' %}" /&gt; </code></pre>
-2
2013-05-16T20:42:24Z
[ "python", "django" ]
Python equivalent of Perl's while (<>) {...}?
807,173
<p>I write a lot of little scripts that process files on a line-by-line basis. In Perl, I use</p> <pre><code>while (&lt;&gt;) { do stuff; } </code></pre> <p>This is handy because it doesn't care where the input comes from (a file or stdin).</p> <p>In Python I use this</p> <pre><code>if len(sys.argv) == 2: # the...
20
2009-04-30T14:23:46Z
807,190
<p>The fileinput module in the standard library is just what you want:</p> <pre><code>import fileinput for line in fileinput.input(): ... </code></pre>
48
2009-04-30T14:26:51Z
[ "python", "stdin" ]
Python equivalent of Perl's while (<>) {...}?
807,173
<p>I write a lot of little scripts that process files on a line-by-line basis. In Perl, I use</p> <pre><code>while (&lt;&gt;) { do stuff; } </code></pre> <p>This is handy because it doesn't care where the input comes from (a file or stdin).</p> <p>In Python I use this</p> <pre><code>if len(sys.argv) == 2: # the...
20
2009-04-30T14:23:46Z
807,196
<pre><code>import fileinput for line in fileinput.input(): process(line) </code></pre> <p>This iterates over the lines of all files listed in sys.argv[1:], defaulting to sys.stdin if the list is empty.</p>
15
2009-04-30T14:27:48Z
[ "python", "stdin" ]
Python equivalent of Perl's while (<>) {...}?
807,173
<p>I write a lot of little scripts that process files on a line-by-line basis. In Perl, I use</p> <pre><code>while (&lt;&gt;) { do stuff; } </code></pre> <p>This is handy because it doesn't care where the input comes from (a file or stdin).</p> <p>In Python I use this</p> <pre><code>if len(sys.argv) == 2: # the...
20
2009-04-30T14:23:46Z
807,210
<p><a href="http://docs.python.org/library/fileinput.html">fileinput</a> defaults to stdin, so would make it slightly more concise.</p> <p>If you do a lot of command-line stuff, though, this <a href="http://code.activestate.com/recipes/276960/">piping hack</a> is very neat.</p>
7
2009-04-30T14:31:06Z
[ "python", "stdin" ]
Where is the phpMailer php class equivalent for Python?
807,302
<p>i'm new with python.. Actually, i'm trying to send featured email with python: html body, text alternative body, and attachment.</p> <p>So, i've found this <a href="http://code.activestate.com/recipes/67083/" rel="nofollow" title="tutorial 1">tutorial</a> and adapted it with the gmail authentication (tutorial found...
3
2009-04-30T14:48:42Z
807,362
<p>I recommend reading the <a href="http://james.apache.org/server/rfclist/smtp/rfc0821.txt" rel="nofollow">SMTP rfc</a>. A google search shows that this can easily be done by using the MimeMultipart class which you are importing but never using. Here are <a href="http://docs.python.org/library/email-examples.html" rel...
0
2009-04-30T15:00:06Z
[ "python", "email", "phpmailer" ]
Where is the phpMailer php class equivalent for Python?
807,302
<p>i'm new with python.. Actually, i'm trying to send featured email with python: html body, text alternative body, and attachment.</p> <p>So, i've found this <a href="http://code.activestate.com/recipes/67083/" rel="nofollow" title="tutorial 1">tutorial</a> and adapted it with the gmail authentication (tutorial found...
3
2009-04-30T14:48:42Z
807,475
<p>Django includes the class you need in core, <a href="http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types" rel="nofollow">docs here</a></p> <pre><code>from django.core.mail import EmailMultiAlternatives subject, from_email, to = 'hello', 'from@example.com', 'to@example.com' text_con...
2
2009-04-30T15:22:33Z
[ "python", "email", "phpmailer" ]
Where is the phpMailer php class equivalent for Python?
807,302
<p>i'm new with python.. Actually, i'm trying to send featured email with python: html body, text alternative body, and attachment.</p> <p>So, i've found this <a href="http://code.activestate.com/recipes/67083/" rel="nofollow" title="tutorial 1">tutorial</a> and adapted it with the gmail authentication (tutorial found...
3
2009-04-30T14:48:42Z
807,988
<p>If you can excuse some blatant self promotion, I wrote a <a href="http://pypi.python.org/pypi/mailer/0.3" rel="nofollow">mailer module</a> that makes sending email with Python fairly simple. No dependencies other than the Python smtplib and email libraries.</p> <p>Here's a simple example for sending an email with a...
5
2009-04-30T16:56:26Z
[ "python", "email", "phpmailer" ]
Where is the phpMailer php class equivalent for Python?
807,302
<p>i'm new with python.. Actually, i'm trying to send featured email with python: html body, text alternative body, and attachment.</p> <p>So, i've found this <a href="http://code.activestate.com/recipes/67083/" rel="nofollow" title="tutorial 1">tutorial</a> and adapted it with the gmail authentication (tutorial found...
3
2009-04-30T14:48:42Z
895,352
<p>Maybe you can try with <strong>turbomail</strong> python-turbomail.org</p> <p>It's more easy and useful :) </p> <pre><code>import turbomail # ... message = turbomail.Message("from@example.com", "to@example.com", subject) message.plain = "Hello world!" turbomail.enqueue(message) </code></pre>
1
2009-05-21T21:45:25Z
[ "python", "email", "phpmailer" ]
Where is the phpMailer php class equivalent for Python?
807,302
<p>i'm new with python.. Actually, i'm trying to send featured email with python: html body, text alternative body, and attachment.</p> <p>So, i've found this <a href="http://code.activestate.com/recipes/67083/" rel="nofollow" title="tutorial 1">tutorial</a> and adapted it with the gmail authentication (tutorial found...
3
2009-04-30T14:48:42Z
2,276,417
<p>Just want to point to <a href="http://lamsonproject.org/" rel="nofollow">Lamson Project</a> which was what I was looking for when I found this thread. I did some more searching and found it. It's:</p> <blockquote> <p>Lamson's goal is to put an end to the hell that is "e-mail application development". Rather than ...
2
2010-02-16T21:18:21Z
[ "python", "email", "phpmailer" ]
Django m2m queries, distinct Users for a m2m relationship of a Model
807,470
<p>I have a model Model with a m2m field : </p> <pre><code>user = .. fk user ... watchers = models.ManyToManyField(User, related_name="boardShot_watchers", null=True) </code></pre> <p>How do i select all distinct Users involved in this watchers relationship for all my entries of type Model ?</p> <p>I dont think...
1
2009-04-30T15:21:37Z
807,562
<p>Not in your current model. If you want to have explicit access to the joining table, you need to make it part of the Django object model. The docs explain how to do this:</p> <p><a href="http://www.djangoproject.com/documentation/models/m2m_intermediary/" rel="nofollow">http://www.djangoproject.com/documentation/mo...
2
2009-04-30T15:37:33Z
[ "python", "django", "orm", "m2m" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
807,874
<p>have a look at <a href="http://docs.python.org/library/struct.html?highlight=struct#struct.pack%5Finto" rel="nofollow"><code>struct.pack_into</code></a></p>
3
2009-04-30T16:38:02Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
807,881
<p>See: <a href="http://docs.python.org/library/struct.html">Python's struct module</a></p> <pre><code>import struct s = struct.pack('f'*len(floats), *floats) f = open('file','wb') f.write(s) f.close() </code></pre>
9
2009-04-30T16:39:05Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
807,890
<p>struct.pack() looks like what you need.</p> <p><a href="http://docs.python.org/library/struct.html" rel="nofollow">http://docs.python.org/library/struct.html</a></p>
3
2009-04-30T16:40:14Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
808,049
<p>The array module in the standard library may be more suitable for this task than the struct module which everybody is suggesting. Performance with 200 MB of data should be <em>substantially</em> better with array.</p> <p>If you'd like to take at a variety of options, try profiling on your system with <a href="http...
10
2009-04-30T17:12:01Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
808,139
<p>Alex is absolutely right, it's more efficient to do it this way:</p> <pre><code>from array import array output_file = open('file', 'wb') float_array = array('d', [3.14, 2.7, 0.0, -1.0, 1.1]) float_array.tofile(output_file) output_file.close() </code></pre> <p>And then read the array like that:</p> <pre><code>inpu...
24
2009-04-30T17:32:59Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
809,216
<p>I'm not sure how <a href="http://numpy.scipy.org/">NumPy</a> will compare performance-wise for your application, but it may be worth investigating.</p> <p>Using <a href="http://numpy.scipy.org/">NumPy</a>:</p> <pre><code>from numpy import array a = array(floats,'float32') output_file = open('file', 'wb') a.tofile(...
7
2009-04-30T21:33:52Z
[ "python", "file-io" ]
How to output list of floats to a binary file in Python
807,863
<p>I have a list of floating-point values in Python:</p> <pre><code>floats = [3.14, 2.7, 0.0, -1.0, 1.1] </code></pre> <p>I would like to write these values out to a binary file using IEEE 32-bit encoding. What is the best way to do this in Python? My list actually contains about 200 MB of data, so something "not too...
17
2009-04-30T16:35:43Z
34,164,133
<p>I ran into a similar issue while inadvertently writing a 100+ GB csv file. The answers here were extremely helpful but, to get to the bottom of it, <a href="https://gist.github.com/deanmalmgren/fd1714799dc5b5643b87#file-write_profiler-py" rel="nofollow">I profiled all of the solutions mentioned and then some</a>. Al...
0
2015-12-08T19:15:14Z
[ "python", "file-io" ]
Decoding problems in Django and lxml
808,275
<p>I have a strange problem with lxml when using the deployed version of my Django application. I use lxml to parse another HTML page which I fetch from my server. This works perfectly well on my development server on my own computer, but for some reason it gives me <code>UnicodeDecodeError</code> on the server.</p> ...
3
2009-04-30T18:02:13Z
808,455
<p>Since modifying site.py is not an ideal solution try this at the start of your program:</p> <pre><code>import sys reload(sys) sys.setdefaultencoding("utf-8") </code></pre>
-2
2009-04-30T18:41:18Z
[ "python", "django", "utf-8", "lxml", "decoding" ]
Decoding problems in Django and lxml
808,275
<p>I have a strange problem with lxml when using the deployed version of my Django application. I use lxml to parse another HTML page which I fetch from my server. This works perfectly well on my development server on my own computer, but for some reason it gives me <code>UnicodeDecodeError</code> on the server.</p> ...
3
2009-04-30T18:02:13Z
815,780
<p>"\x85why hello there!" is not a utf-8 encoded string. You should try decoding the webpage before passing it to lxml. Check what encoding it uses by looking at the http headers when you fetch the page maybe you find the problem there.</p>
3
2009-05-02T22:32:06Z
[ "python", "django", "utf-8", "lxml", "decoding" ]
Decoding problems in Django and lxml
808,275
<p>I have a strange problem with lxml when using the deployed version of my Django application. I use lxml to parse another HTML page which I fetch from my server. This works perfectly well on my development server on my own computer, but for some reason it gives me <code>UnicodeDecodeError</code> on the server.</p> ...
3
2009-04-30T18:02:13Z
861,850
<p>Doesn't syntax such as <code>u"\x85why hello there!"</code> help? </p> <p>You may find the following resources from the official Python documentation helpful:</p> <ul> <li><a href="http://docs.python.org/tutorial/introduction.html#unicode-strings" rel="nofollow">Python introduction, Unicode Strings</a></li> <li><a...
0
2009-05-14T06:31:39Z
[ "python", "django", "utf-8", "lxml", "decoding" ]
Printing XML into HTML with python
808,529
<p>I have a TextEdit widget in PyQt that I use to print out a log in HTML. I use HTML so I can separate entries into color categories (red for error, yellow for debug, blue for message, etc), but this creates a problem. Most of the debug messages are XML. When I use appendHtml on the widget, it strips out all the tags....
0
2009-04-30T19:01:10Z
808,577
<p>A cdata section might help.</p> <p><a href="http://reference.sitepoint.com/javascript/CDATASection" rel="nofollow">http://reference.sitepoint.com/javascript/CDATASection</a></p> <p><a href="http://en.wikipedia.org/wiki/CDATA" rel="nofollow">http://en.wikipedia.org/wiki/CDATA</a></p>
0
2009-04-30T19:12:48Z
[ "python", "html", "xml" ]
Printing XML into HTML with python
808,529
<p>I have a TextEdit widget in PyQt that I use to print out a log in HTML. I use HTML so I can separate entries into color categories (red for error, yellow for debug, blue for message, etc), but this creates a problem. Most of the debug messages are XML. When I use appendHtml on the widget, it strips out all the tags....
0
2009-04-30T19:01:10Z
808,603
<p><a href="http://docs.python.org/library/cgi.html#cgi.escape" rel="nofollow"><code>cgi.escape</code></a> can help you. It will convert the characters <code>'&amp;'</code>, <code>'&lt;'</code> and <code>'&gt;'</code> in the string to HTML-safe sequences. That is enough to prevent interpretation of xml tags.</p> <pre>...
4
2009-04-30T19:18:04Z
[ "python", "html", "xml" ]
Parsing files with Python
808,621
<p>What type of Python objects should I use to parse files with a specific syntax? Also what sort of loop should be followed to make it through the file. Should one pass be sufficient? Two, three?</p>
-3
2009-04-30T19:21:28Z
808,641
<p>how complex the syntax is? are you inventing a new one or not?</p> <p>for a complex language, consider bison bindings like lex + pybison.</p> <p>if you can decide what syntax to use, try YAML.</p>
1
2009-04-30T19:25:32Z
[ "python", "parsing", "object" ]
Parsing files with Python
808,621
<p>What type of Python objects should I use to parse files with a specific syntax? Also what sort of loop should be followed to make it through the file. Should one pass be sufficient? Two, three?</p>
-3
2009-04-30T19:21:28Z
808,650
<p>You should offer more information about your aims ...</p> <ul> <li>What kind of file</li> <li>What structure? Tab separated? XML - like?</li> <li>What kind of encoding?</li> <li>Whats the target structure?</li> <li>Do you need to reparse the file in a regular time period (like an interpreter)?</li> </ul>
2
2009-04-30T19:27:09Z
[ "python", "parsing", "object" ]
Parsing files with Python
808,621
<p>What type of Python objects should I use to parse files with a specific syntax? Also what sort of loop should be followed to make it through the file. Should one pass be sufficient? Two, three?</p>
-3
2009-04-30T19:21:28Z
808,652
<p>It does not depend on your programming language (python) if your parser will have one, two, three or n passes. It depends on the grammar of the syntax you are trying to parse.</p> <p>If the syntax is complex enough I would recommend LEX/YACC combo as Francis said.</p>
0
2009-04-30T19:27:21Z
[ "python", "parsing", "object" ]
Parsing files with Python
808,621
<p>What type of Python objects should I use to parse files with a specific syntax? Also what sort of loop should be followed to make it through the file. Should one pass be sufficient? Two, three?</p>
-3
2009-04-30T19:21:28Z
808,713
<p>It depends on the grammar. You can use <a href="http://pyparsing.wikispaces.com/" rel="nofollow">pyparsing</a> instead of implementing your own parser. It is very easy to use. </p>
3
2009-04-30T19:49:04Z
[ "python", "parsing", "object" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
808,701
<p>This sounds like a great use of <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython">IronPython</a>.</p> <p>It's fairly easy to set up a simple scripting host from C# to allow calls into IronPython scripts, as well as allowing IronPython to call into your C# code. There are samples and examples o...
11
2009-04-30T19:45:40Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
808,730
<p>I don't know what you mean with </p> <blockquote> <p>"extend" or interact with the program</p> </blockquote> <p>so I can't answer your question. Can you give an example?</p> <p>There is an open source interactive C# shell in mono: <a href="http://www.mono-project.com/CsharpRepl" rel="nofollow">http://www.mono-p...
0
2009-04-30T19:52:54Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
808,786
<p>Python as an extension language is called "Embedding Python".</p> <p>you can call a python module from c++ by bascially calling the python intepreter and have it execute the python source. This is called <a href="http://www.python.org/doc/2.5.2/ext/embedding.html" rel="nofollow">embedding</a>.</p> <p>It works from...
1
2009-04-30T20:05:49Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
808,812
<p>Here is a link to a blog post about adding IronRuby to script a C# application.</p> <p><a href="http://blog.jimmy.schementi.com/2008/11/adding-scripting-to-c-silverlight-app.html" rel="nofollow">http://blog.jimmy.schementi.com/2008/11/adding-scripting-to-c-silverlight-app.html</a></p> <p>The principles would also ...
1
2009-04-30T20:15:16Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
809,017
<p>I was looking solution for the same problem, and found IronTextBox: <a href="http://www.codeproject.com/KB/edit/irontextbox2.aspx" rel="nofollow">http://www.codeproject.com/KB/edit/irontextbox2.aspx</a></p> <p>It needs a little tuning for current versions, but seems to be everything I needed. First made it compile,...
3
2009-04-30T20:53:52Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it
808,692
<p>I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My qu...
13
2009-04-30T19:43:36Z
1,052,679
<p>If your goal is to avoid learning a new language you can use <a href="http://www.csscript.net" rel="nofollow">CSScript.Net</a> and embedded scripts written in C# or VB into you application. With CSScript you get full access to the CLR. Three different models of script execution are supported so that you can execut...
1
2009-06-27T11:33:14Z
[ "c#", "python", ".net", "ironpython", "python.net" ]
Python - Threading and a While True Loop
808,746
<p>I have a thread that appends rows to self.output and a loop that runs until self.done is True (or the max execution time is reached).</p> <p>Is there a more efficient way to do this other than using a while loop that constantly checks to see if it's done. The while loop causes the CPU to spike to 100% while it's ru...
9
2009-04-30T19:57:07Z
808,764
<p>Use time.sleep(seconds) to create a brief pause after each iteration of the while loop to relinquish the cpu. You will have to set the time you sleep during each iteration based on how important it is that you catch the job quickly after it's complete.</p> <p>Example:</p> <pre><code>time.clock() while True: i...
0
2009-04-30T20:01:13Z
[ "python", "multithreading", "loops" ]
Python - Threading and a While True Loop
808,746
<p>I have a thread that appends rows to self.output and a loop that runs until self.done is True (or the max execution time is reached).</p> <p>Is there a more efficient way to do this other than using a while loop that constantly checks to see if it's done. The while loop causes the CPU to spike to 100% while it's ru...
9
2009-04-30T19:57:07Z
808,775
<p>You have to use a synchronization primitive here. Look here: <a href="http://docs.python.org/library/threading.html" rel="nofollow">http://docs.python.org/library/threading.html</a>.</p> <p>Event objects seem very simple and should solve your problem. You can also use a condition object or a semaphore.</p> <p>I do...
0
2009-04-30T20:02:55Z
[ "python", "multithreading", "loops" ]
Python - Threading and a While True Loop
808,746
<p>I have a thread that appends rows to self.output and a loop that runs until self.done is True (or the max execution time is reached).</p> <p>Is there a more efficient way to do this other than using a while loop that constantly checks to see if it's done. The while loop causes the CPU to spike to 100% while it's ru...
9
2009-04-30T19:57:07Z
808,778
<p>use mutex module or event/semaphore</p>
0
2009-04-30T20:03:57Z
[ "python", "multithreading", "loops" ]
Python - Threading and a While True Loop
808,746
<p>I have a thread that appends rows to self.output and a loop that runs until self.done is True (or the max execution time is reached).</p> <p>Is there a more efficient way to do this other than using a while loop that constantly checks to see if it's done. The while loop causes the CPU to spike to 100% while it's ru...
9
2009-04-30T19:57:07Z
808,780
<p>Use a semaphore; have the working thread release it when it's finished, and block your appending thread until the worker is finished with the semaphore.</p> <p>ie. in the worker, do something like <code>self.done = threading.Semaphore()</code> at the beginning of work, and <code>self.done.release()</code> when fini...
1
2009-04-30T20:04:28Z
[ "python", "multithreading", "loops" ]
Python - Threading and a While True Loop
808,746
<p>I have a thread that appends rows to self.output and a loop that runs until self.done is True (or the max execution time is reached).</p> <p>Is there a more efficient way to do this other than using a while loop that constantly checks to see if it's done. The while loop causes the CPU to spike to 100% while it's ru...
9
2009-04-30T19:57:07Z
808,820
<p>Are your threads appending to self.output here, with your main task consuming them? If so, this is a tailor-made job for <a href="http://docs.python.org/library/queue.html">Queue.Queue</a>. Your code should become something like:</p> <pre><code>import Queue # Initialise queue as: queue = Queue.Queue() Finished =...
11
2009-04-30T20:16:46Z
[ "python", "multithreading", "loops" ]
Find all IPs on an HTML Page
809,037
<p>I want to get an HTML page with python and then print out all the IPs from it. I will define an IP as the following:</p> <p><strong>x</strong>.<strong>x</strong>.<strong>x</strong>.<strong>x</strong>:<strong>y</strong></p> <p>Where: x = a number between 0 and 256. y = a number with &lt; 7 digits.</p> <p>Thanks.<...
0
2009-04-30T20:57:12Z
809,061
<p>The basic approach would be:</p> <ul> <li>Use <a href="http://docs.python.org/library/urllib2.html" rel="nofollow"><code>urllib2</code></a> to download the contents of the page</li> <li>Use a <a href="http://docs.python.org/library/re.html" rel="nofollow">regular expression</a> to extract IPv4-like addresses</li> <...
1
2009-04-30T21:01:45Z
[ "python", "regex", "screen-scraping", "extract" ]
Find all IPs on an HTML Page
809,037
<p>I want to get an HTML page with python and then print out all the IPs from it. I will define an IP as the following:</p> <p><strong>x</strong>.<strong>x</strong>.<strong>x</strong>.<strong>x</strong>:<strong>y</strong></p> <p>Where: x = a number between 0 and 256. y = a number with &lt; 7 digits.</p> <p>Thanks.<...
0
2009-04-30T20:57:12Z
809,109
<p>Try:</p> <pre><code>re.compile("\d?\d?\d.\d?\d?\d.\d?\d?\d.\d?\d?\d:\d+").findall(urllib2.urlopen(url).read()) </code></pre>
0
2009-04-30T21:12:25Z
[ "python", "regex", "screen-scraping", "extract" ]
Find all IPs on an HTML Page
809,037
<p>I want to get an HTML page with python and then print out all the IPs from it. I will define an IP as the following:</p> <p><strong>x</strong>.<strong>x</strong>.<strong>x</strong>.<strong>x</strong>:<strong>y</strong></p> <p>Where: x = a number between 0 and 256. y = a number with &lt; 7 digits.</p> <p>Thanks.<...
0
2009-04-30T20:57:12Z
809,123
<blockquote> <p>Right. The only part I cant do is the regular expression one. – das 9 mins ago If someone shows me that, I will be fine. – das 8 mins ago</p> </blockquote> <pre><code>import re ip = re.compile(r"\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?):\d{1,6}\b") junk = " 1.1.1....
3
2009-04-30T21:14:43Z
[ "python", "regex", "screen-scraping", "extract" ]
Find all IPs on an HTML Page
809,037
<p>I want to get an HTML page with python and then print out all the IPs from it. I will define an IP as the following:</p> <p><strong>x</strong>.<strong>x</strong>.<strong>x</strong>.<strong>x</strong>:<strong>y</strong></p> <p>Where: x = a number between 0 and 256. y = a number with &lt; 7 digits.</p> <p>Thanks.<...
0
2009-04-30T20:57:12Z
809,129
<p>Not to turn this into a who's-a-better-regex-author-war but...</p> <pre><code>(\d{1,3}\.){3}\d{1,3}\:\d{1,6} </code></pre>
0
2009-04-30T21:15:45Z
[ "python", "regex", "screen-scraping", "extract" ]
Find all IPs on an HTML Page
809,037
<p>I want to get an HTML page with python and then print out all the IPs from it. I will define an IP as the following:</p> <p><strong>x</strong>.<strong>x</strong>.<strong>x</strong>.<strong>x</strong>:<strong>y</strong></p> <p>Where: x = a number between 0 and 256. y = a number with &lt; 7 digits.</p> <p>Thanks.<...
0
2009-04-30T20:57:12Z
12,188,252
<p><strong><a href="http://regexr.com?3202m" rel="nofollow">In action</a></strong>:</p> <pre><code>\b(?: # A.B.C in A.B.C.D:port (?: 25[0-5] | 2[0-4][0-9] | 1[0-9][0-9] | [1-9]?[0-9] )\. ){3} (?: # D in A.B.C.D:port 25[0-5] | 2[0-4][0-9] | 1[0-9][...
0
2012-08-30T00:17:38Z
[ "python", "regex", "screen-scraping", "extract" ]
Django Manager Chaining
809,210
<p>I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the specific example that I'm working on:</p> <p>I have multiple abstract model classes that I use to provide small, specific functionali...
28
2009-04-30T21:33:29Z
813,277
<p>See this snippet on Djangosnippets: <a href="http://djangosnippets.org/snippets/734/">http://djangosnippets.org/snippets/734/</a></p> <p>Instead of putting your custom methods in a manager, you subclass the queryset itself. It's very easy and works perfectly. The only issue I've had is with model inheritance, you a...
20
2009-05-01T21:04:31Z
[ "python", "django", "django-models", "django-managers" ]
Django Manager Chaining
809,210
<p>I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the specific example that I'm working on:</p> <p>I have multiple abstract model classes that I use to provide small, specific functionali...
28
2009-04-30T21:33:29Z
813,550
<p>I spent a while trying to come up with a way to build a nice factory to do this, but I'm running into a lot of problems with that.</p> <p>The best I can suggest to you is to chain your inheritance. It's not very generic, so I'm not sure how useful it is, but all you would have to do is:</p> <pre><code>class Global...
2
2009-05-01T22:26:05Z
[ "python", "django", "django-models", "django-managers" ]
Django Manager Chaining
809,210
<p>I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the specific example that I'm working on:</p> <p>I have multiple abstract model classes that I use to provide small, specific functionali...
28
2009-04-30T21:33:29Z
814,254
<p>Here is the specific solution to my problem using the custom QuerySetManager by Simon that Scott linked to.</p> <pre><code>from django.db import models from django.contrib import admin from django.db.models.query import QuerySet from django.core.exceptions import FieldError class MixinManager(models.Manager): ...
6
2009-05-02T06:00:37Z
[ "python", "django", "django-models", "django-managers" ]
Django Manager Chaining
809,210
<p>I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the specific example that I'm working on:</p> <p>I have multiple abstract model classes that I use to provide small, specific functionali...
28
2009-04-30T21:33:29Z
12,682,136
<p>Another option worth considering is the PassThroughManager:</p> <p><a href="https://django-model-utils.readthedocs.org/en/latest/managers.html#passthroughmanager" rel="nofollow">https://django-model-utils.readthedocs.org/en/latest/managers.html#passthroughmanager</a></p>
2
2012-10-01T22:41:21Z
[ "python", "django", "django-models", "django-managers" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
809,402
<p>Adapted from here <a href="http://mail.python.org/pipermail/python-list/2000-June/039873.html">http://mail.python.org/pipermail/python-list/2000-June/039873.html</a></p> <pre><code>from math import * def erfcc(x): """Complementary error function.""" z = abs(x) t = 1. / (1. + 0.5*z) r = t * exp(-z*z-...
15
2009-04-30T22:23:28Z
[ "python", "statistics" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
809,406
<p>Here's an example:</p> <pre><code>&gt;&gt;&gt; from scipy.stats import norm &gt;&gt;&gt; norm.cdf(1.96) array(0.97500210485177952) </code></pre> <p>If you need the inverse CDF:</p> <pre><code>&gt;&gt;&gt; norm.ppf(norm.cdf(1.96)) array(1.9599999999999991) </code></pre>
63
2009-04-30T22:24:02Z
[ "python", "statistics" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
3,525,548
<p>To build upon Unknown's example, the Python equivalent of the function normdist() implemented in a lot of libraries would be:</p> <pre><code>def normcdf(x, mu, sigma): t = x-mu; y = 0.5*erfcc(-t/(sigma*sqrt(2.0))); if y&gt;1.0: y = 1.0; return y def normpdf(x, mu, sigma): u = (x-mu)/abs...
11
2010-08-19T19:35:08Z
[ "python", "statistics" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
12,955,360
<p>As Google gives this answer for the search <strong>netlogo pdf</strong>, here's the netlogo version of the above python code</p> <pre> ;; Normal distribution cumulative density function to-report normcdf [x mu sigma] let t x - mu let y 0.5 * erfcc [ - t / ( sigma * sqrt 2.0)] if ( y...
-4
2012-10-18T13:02:40Z
[ "python", "statistics" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
29,273,201
<p>It may be too late to answer the question but since Google still leads people here, I decide to write my solution here.</p> <p>That is, since Python 2.7, the <strong>math</strong> library has integrated the error function <strong>math.erf(x)</strong></p> <p>The erf() function can be used to compute traditional sta...
8
2015-03-26T07:40:44Z
[ "python", "statistics" ]
How to calculate cumulative normal distribution in Python
809,362
<p>I am looking for a function in Numpy or Scipy (or any rigorous Python library) that will give me the cumulative normal distribution function in Python.</p>
48
2009-04-30T22:13:11Z
33,824,283
<p>Alex's answer shows you a solution for standard normal distribution (mean = 0, standard deviation = 1). If you have normal distribution with <code>mean</code> and <code>std</code> (which is <code>sqr(var)</code>) and you want to calculate:</p> <pre><code>from scipy.stats import norm # cdf(x &lt; val) print norm.cd...
1
2015-11-20T10:24:57Z
[ "python", "statistics" ]
distributed/faster python unit tests
809,564
<p>I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?</p>
4
2009-04-30T23:25:02Z
809,629
<p>Profile them to see what really is slow. You may be able to solve this problem with out distribution. If the tests are truly unit tests then I see not many problems with running the tests across multiple execution engines.</p>
2
2009-04-30T23:49:30Z
[ "python", "unit-testing" ]
distributed/faster python unit tests
809,564
<p>I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?</p>
4
2009-04-30T23:25:02Z
809,937
<p>The first part of the solution to this problem is to only run the tests one needs to run. Between commits to a shared branch, one runs only those tests that one's new work interacts with; that should take all of five seconds. If one adopts this model, it becomes vital to make a point of running the entire test sui...
1
2009-05-01T02:14:55Z
[ "python", "unit-testing" ]
distributed/faster python unit tests
809,564
<p>I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?</p>
4
2009-04-30T23:25:02Z
810,002
<p>While coding, only run the tests of the class that You have just changed, not all the tests in the whole project.</p> <p>Still, it is a good practice to run all tests before You commit Your code (but the Continuous Integration server can do it for You).</p>
1
2009-05-01T02:45:58Z
[ "python", "unit-testing" ]
distributed/faster python unit tests
809,564
<p>I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?</p>
4
2009-04-30T23:25:02Z
811,222
<p>See py.test, which has the ability to pass unit tests off to a group of machines, or Nose, which (as of trunk, not the currently released version) supports running tests in parallel with the multiprocessing module.</p>
3
2009-05-01T12:52:28Z
[ "python", "unit-testing" ]
distributed/faster python unit tests
809,564
<p>I have a lot of python unit tests for a project and it's getting to the point where it takes a long time to run them. I don't want to add more because I know they're going to make things slower. How do people solve this problem? Is there any easy way to distribute the test execution over a cluster?</p>
4
2009-04-30T23:25:02Z
814,552
<p>You can't frequently run all your tests, because they're too slow. This is an inevitable consequence of your project getting bigger, and won't go away. Sure, you may be able to run the tests in parallel and get a nice speedup, but the problem will just come back later, and it'll never be as it was when your project ...
4
2009-05-02T09:46:16Z
[ "python", "unit-testing" ]
Any gotchas using unicode_literals in Python 2.6?
809,796
<p>We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding:</p> <pre> from __future__ import unicode_literals </pre> <p>into our <code>.py</code> files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious...
91
2009-05-01T00:56:37Z
826,710
<p>I did find that if you add the <code>unicode_literals</code> directive you should also add something like:</p> <pre><code> # -*- coding: utf-8 </code></pre> <p>to the first or second line your .py file. Otherwise lines such as:</p> <pre><code> foo = "barré" </code></pre> <p>result in an an error such as:</p> ...
11
2009-05-05T20:09:56Z
[ "python", "unicode", "python-2.6", "unicode-literals" ]
Any gotchas using unicode_literals in Python 2.6?
809,796
<p>We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding:</p> <pre> from __future__ import unicode_literals </pre> <p>into our <code>.py</code> files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious...
91
2009-05-01T00:56:37Z
827,449
<p>The main source of problems I've had working with unicode strings is when you mix utf-8 encoded strings with unicode ones.</p> <p>For example, consider the following scripts.</p> <p>two.py</p> <pre><code># encoding: utf-8 name = 'helló wörld from two' </code></pre> <p>one.py</p> <pre><code># encoding: utf-8 f...
94
2009-05-05T23:52:06Z
[ "python", "unicode", "python-2.6", "unicode-literals" ]
Any gotchas using unicode_literals in Python 2.6?
809,796
<p>We've already gotten our code base running under Python 2.6. In order to prepare for Python 3.0, we've started adding:</p> <pre> from __future__ import unicode_literals </pre> <p>into our <code>.py</code> files (as we modify them). I'm wondering if anyone else has been doing this and has run into any non-obvious...
91
2009-05-01T00:56:37Z
1,789,107
<p>Also in 2.6 (before python 2.6.5 RC1+) unicode literals doesn't play nice with keyword arguments (<a href="http://bugs.python.org/issue4978">issue4978</a>):</p> <p>The following code for example works without unicode_literals, but fails with TypeError: <code>keywords must be string</code> if unicode_literals is use...
16
2009-11-24T10:10:01Z
[ "python", "unicode", "python-2.6", "unicode-literals" ]