title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How can I catch for a connection timeout error in Python's SMTPlib?
2,531,786
<p>The error being thrown is:</p> <pre><code>error: [Errno 110] Connection timed out </code></pre> <p>I'm not sure what to except for?</p> <pre><code> try: smtpObj = smtplib.SMTP('smtp.example.com') smtpObj.starttls() smtpObj.login('user','pass') smtpObj.sendmail(sender, receivers,...
0
2010-03-28T03:22:53Z
2,531,797
<p>I believe <code>socket.error</code> should work but if you post the code you're using, we can help you better. <code>smtplib.SMTPConnectError</code> should also be of interest.</p> <p>Try something like this:</p> <pre><code>try: server = smtplib.SMTP("something.com") except (socket.error, smtplib.SMTPConnectEr...
2
2010-03-28T03:28:17Z
[ "python", "error-handling", "smtplib" ]
How can I catch for a connection timeout error in Python's SMTPlib?
2,531,786
<p>The error being thrown is:</p> <pre><code>error: [Errno 110] Connection timed out </code></pre> <p>I'm not sure what to except for?</p> <pre><code> try: smtpObj = smtplib.SMTP('smtp.example.com') smtpObj.starttls() smtpObj.login('user','pass') smtpObj.sendmail(sender, receivers,...
0
2010-03-28T03:22:53Z
2,531,820
<p>You need to provide the exception class, not an instance thereof. That is to say, the code should look like </p> <pre><code>try: smtpObj = smtplib.SMTP('smtp.example.com') smtpObj.starttls() smtpObj.login('user','pass') smtpObj.sendmail(sender, receivers, message) print "Successfully sent email"...
3
2010-03-28T03:43:55Z
[ "python", "error-handling", "smtplib" ]
How to use a custom comparison function in Python 3?
2,531,952
<p>In <strong>Python 2.x</strong>, I could pass custom function to sorted and .sort functions</p> <pre><code>&gt;&gt;&gt; x=['kar','htar','har','ar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x) ['ar', 'har', 'htar', 'kar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x,cmp=customsort) ['kar', 'htar', 'har', 'ar'] </code></pre> <p>Becau...
34
2010-03-28T05:04:35Z
2,531,966
<p>Use the <code>key</code> argument instead. It takes a function that takes the value being processed and returns a single value giving the key to use to sort by.</p> <pre><code>sorted(x, key=somekeyfunc) </code></pre>
1
2010-03-28T05:13:37Z
[ "python", "sorting", "python-3.x" ]
How to use a custom comparison function in Python 3?
2,531,952
<p>In <strong>Python 2.x</strong>, I could pass custom function to sorted and .sort functions</p> <pre><code>&gt;&gt;&gt; x=['kar','htar','har','ar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x) ['ar', 'har', 'htar', 'kar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x,cmp=customsort) ['kar', 'htar', 'har', 'ar'] </code></pre> <p>Becau...
34
2010-03-28T05:04:35Z
2,531,971
<p>Use the <code>key</code> argument (and follow the <a href="http://code.activestate.com/recipes/576653-convert-a-cmp-function-to-a-key-function/">recipe</a> on how to convert your old <code>cmp</code> function to a <code>key</code> function).</p>
20
2010-03-28T05:15:53Z
[ "python", "sorting", "python-3.x" ]
How to use a custom comparison function in Python 3?
2,531,952
<p>In <strong>Python 2.x</strong>, I could pass custom function to sorted and .sort functions</p> <pre><code>&gt;&gt;&gt; x=['kar','htar','har','ar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x) ['ar', 'har', 'htar', 'kar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x,cmp=customsort) ['kar', 'htar', 'har', 'ar'] </code></pre> <p>Becau...
34
2010-03-28T05:04:35Z
2,532,009
<p>Instead of a customsort(), you need a function that translates each word into something that Python already knows how to sort. For example, you could translate each word into a list of numbers where each number represents where each letter occurs in your alphabet. Something like this:</p> <pre><code>my_alphabet =...
9
2010-03-28T05:35:35Z
[ "python", "sorting", "python-3.x" ]
How to use a custom comparison function in Python 3?
2,531,952
<p>In <strong>Python 2.x</strong>, I could pass custom function to sorted and .sort functions</p> <pre><code>&gt;&gt;&gt; x=['kar','htar','har','ar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x) ['ar', 'har', 'htar', 'kar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x,cmp=customsort) ['kar', 'htar', 'har', 'ar'] </code></pre> <p>Becau...
34
2010-03-28T05:04:35Z
2,532,156
<p>I don't know if this will help, but you may check out the <code>locale</code> module. It looks like you can set the locale to your language and use <code>locale.strcoll</code> to compare strings using your language's sorting rules.</p>
2
2010-03-28T07:03:06Z
[ "python", "sorting", "python-3.x" ]
How to use a custom comparison function in Python 3?
2,531,952
<p>In <strong>Python 2.x</strong>, I could pass custom function to sorted and .sort functions</p> <pre><code>&gt;&gt;&gt; x=['kar','htar','har','ar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x) ['ar', 'har', 'htar', 'kar'] &gt;&gt;&gt; &gt;&gt;&gt; sorted(x,cmp=customsort) ['kar', 'htar', 'har', 'ar'] </code></pre> <p>Becau...
34
2010-03-28T05:04:35Z
23,756,830
<p>Use the <code>key</code> keyword and <a href="https://docs.python.org/3/library/functools.html#functools.cmp_to_key">functools.cmp_to_key</a> to transform your comparison function:</p> <pre><code>sorted(x, key=functools.cmp_to_key(customsort)) </code></pre>
7
2014-05-20T10:08:22Z
[ "python", "sorting", "python-3.x" ]
Why won't numpy matrix let me print its rows?
2,532,012
<p>Okay this is probably a really dumb question, however it's really starting to hurt. I have a numpy matrix, and basically I print it out row by row. However I want to make each row be formatted and separated properly. </p> <pre><code>&gt;&gt;&gt; arr = numpy.matrix([[x for x in range(5)] for y in range(5)]) &gt;&gt...
3
2010-03-28T05:36:08Z
2,532,066
<pre><code>&gt;&gt;&gt; arr[0,] matrix([[0, 1, 2, 3, 4]]) &gt;&gt;&gt; len(arr[0,]) 1 </code></pre> <p>So arr[0,] is not a list or an 1-d array as you expected. On the other hand, your method works for the example matrix from the numpy tutorial:</p> <pre><code>&gt;&gt;&gt; def f(x,y): ... return 10*x+y ... &g...
0
2010-03-28T06:04:54Z
[ "python", "numpy" ]
Why won't numpy matrix let me print its rows?
2,532,012
<p>Okay this is probably a really dumb question, however it's really starting to hurt. I have a numpy matrix, and basically I print it out row by row. However I want to make each row be formatted and separated properly. </p> <pre><code>&gt;&gt;&gt; arr = numpy.matrix([[x for x in range(5)] for y in range(5)]) &gt;&gt...
3
2010-03-28T05:36:08Z
2,532,087
<p><code>arr</code> is returned as a <code>matrix</code> type, which may not be an iterable object that plays nicely with <code>join</code>.</p> <p>You could convert <code>arr</code> to a <code>list</code> with <a href="http://www.scipy.org/Numpy_Example_List#head-5ef91fc0cd39b7f607842fda59b9fb9e1423c1dd" rel="nofollo...
3
2010-03-28T06:18:02Z
[ "python", "numpy" ]
Why won't numpy matrix let me print its rows?
2,532,012
<p>Okay this is probably a really dumb question, however it's really starting to hurt. I have a numpy matrix, and basically I print it out row by row. However I want to make each row be formatted and separated properly. </p> <pre><code>&gt;&gt;&gt; arr = numpy.matrix([[x for x in range(5)] for y in range(5)]) &gt;&gt...
3
2010-03-28T05:36:08Z
2,532,255
<p>In numpy, slices of matrices are matrices (note the double braces <code>[[ ]]</code> in your example). An easy way around this is to get the array representation using the <code>.A</code> attribute.</p> <pre><code>'|'.join(map(str, arr.A[0,])) </code></pre> <p>produces what you want:</p> <pre><code>0|1|2|3|4 <...
1
2010-03-28T07:58:10Z
[ "python", "numpy" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
2,532,059
<p>Process each DNS label individually by excluding invalid characters and ensuring nonzero length.</p> <pre><code> def isValidHostname(hostname): disallowed = re.compile("[^a-zA-Z\d\-]") return all(map(lambda x: len(x) and not disallowed.search(x), hostname.split("."))) </code></pre>
-1
2010-03-28T06:01:46Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
2,532,344
<pre><code>import re def is_valid_hostname(hostname): if len(hostname) &gt; 255: return False if hostname[-1] == ".": hostname = hostname[:-1] # strip exactly one dot from the right, if present allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?&lt;!-)$", re.IGNORECASE) return all(allowed.match(...
31
2010-03-28T08:52:51Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
2,532,763
<p>If you're looking to validate the name of an existing host, the best way is to try to resolve it. You'll never write a regular expression to provide that level of validation.</p>
-4
2010-03-28T11:51:38Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
2,534,561
<p>I like the thoroughness of <a href="#2532344" rel="nofollow">Tim Pietzcker's answer</a>, but I prefer to offload some of the logic from regular expressions for readability. Honestly, I had to look up the meaning of those <code>(?</code> "extension notation" parts. Additionally, I feel the "double-negative" approach ...
1
2010-03-28T21:06:51Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
6,329,953
<pre><code>def is_valid_host(host): '''IDN compatible domain validator''' host = host.encode('idna').lower() if not hasattr(is_valid_host, '_re'): import re is_valid_host._re = re.compile(r'^([0-9a-z][-\w]*[0-9a-z]\.)+[a-z0-9\-]{2,15}$') return bool(is_valid_host._re.match(host)) </code>...
0
2011-06-13T11:42:42Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
33,214,423
<p>Here's a bit stricter version of <a href="http://stackoverflow.com/a/2532344/244297">Tim Pietzcker's answer</a> with the following additions:</p> <ul> <li>Limit the length of the hostname to 253 characters (after stripping the optional trailing <code>.</code>).</li> <li>Check that the hostname is not all-numeric, i...
1
2015-10-19T12:29:13Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
Validate a hostname string
2,532,053
<p>Following up to <a href="http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address">Regular expression to match hostname or IP Address?</a> and using <a href="http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names">Restrictions on valid host names</a> as a reference...
16
2010-03-28T05:58:52Z
33,715,765
<p>Per <a href="http://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx" rel="nofollow">The Old New Thing</a>, the maximum length of a DNS name is 253 characters. (One is allowed up to 255 octets, but 2 of those are consumed by the encoding.)</p> <pre><code>import re def validate_fqdn(dn): if dn.ends...
1
2015-11-15T02:32:30Z
[ "python", "regex", "validation", "hostname", "fqdn" ]
How to print gantt-charts generated on web using python?
2,532,137
<p>I want to print or save gantt-chart(in pdf format). These charts are generated on web after a particular input. Our chart is a plug-in for Trac. I have used Genshi library to generate charts.</p>
1
2010-03-28T06:55:18Z
2,532,384
<p>There's an open source python library for generating PDF files by <a href="http://www.reportlab.com/software/opensource/" rel="nofollow">Report Labs</a>. I've not used it myself, but other questions &amp; answers on SO have revolved around this library, <a href="http://www.reportlab.com/software/opensource/rl-toolki...
0
2010-03-28T09:08:14Z
[ "python", "pdf-generation", "trac", "genshi" ]
How to print gantt-charts generated on web using python?
2,532,137
<p>I want to print or save gantt-chart(in pdf format). These charts are generated on web after a particular input. Our chart is a plug-in for Trac. I have used Genshi library to generate charts.</p>
1
2010-03-28T06:55:18Z
2,650,049
<p>Can you give more information about your plugin? There is a <a href="http://trac-hacks.org/wiki/GanttChartPlugin" rel="nofollow">gantt chart plugin</a> on <a href="http://trac-hacks.org" rel="nofollow">trac-hacks.org</a>; is that the one you are using, or a custom one? If custom, is it available as Open Source som...
0
2010-04-16T01:34:10Z
[ "python", "pdf-generation", "trac", "genshi" ]
unittest tests reuse for family of classes
2,532,197
<p>I have problem organizing my <code>unittest</code> based class test for family of tests. For example assume I implement a "dictionary" interface, and have 5 different implementations want to testing.</p> <p>I do write one test class that tests a dictionary interface. But how can I nicely reuse it to test my all cla...
7
2010-03-28T07:30:15Z
2,532,480
<p>You could look at <a href="https://launchpad.net/testscenarios" rel="nofollow">testscenarios</a> which allows you to set a list called scenarios. The code then generates a version of the test class for each value/scenario in the list </p> <p>See <a href="http://bazaar.launchpad.net/~lifeless/testscenarios/trunk/ann...
0
2010-03-28T09:57:45Z
[ "python", "unit-testing" ]
unittest tests reuse for family of classes
2,532,197
<p>I have problem organizing my <code>unittest</code> based class test for family of tests. For example assume I implement a "dictionary" interface, and have 5 different implementations want to testing.</p> <p>I do write one test class that tests a dictionary interface. But how can I nicely reuse it to test my all cla...
7
2010-03-28T07:30:15Z
2,533,342
<p>The way I tackle this with standard <code>unittest</code> is by subclassing -- overriding data is as easy as overriding methods, after all.</p> <p>So, I have a base class for the tests:</p> <pre><code>class MappingTestBase(unittest.TestCase): dictype = None # write all the tests using self.dictype </code><...
5
2010-03-28T15:05:22Z
[ "python", "unit-testing" ]
In Google's Protocol Buffers, what is a suitable protocol file/model for Exceptions?
2,532,236
<p>Protocol Buffers doesn't have a native Exception type. What would a suitable .proto file for cross-language exceptions look like?</p>
6
2010-03-28T07:48:43Z
2,537,872
<p>The technical lead of Protocol Buffers, Kenton Varda, says in comment 9 on <a href="http://steve.vinoski.net/blog/2008/07/13/protocol-buffers-leaky-rpc/" rel="nofollow">this blog post</a>:</p> <blockquote> <p>If you need to return structured errors, then the right way to do it is to make your response type be...
4
2010-03-29T12:39:54Z
[ "java", "php", "python", "exception", "protocol-buffers" ]
motion computation from video using pyglet in python
2,532,261
<p>I am writing a simple motion detection program but i want it to be cross platform so im using python and the pyglet library since it provides a simple way to load videos in different formats (specially wmv and mpeg). So far i have the code given below which loads the movie and plays it in a window. Now i need to: 1)...
1
2010-03-28T08:00:56Z
2,535,414
<p>To me it seems like you have to skip the play function and manually step through the video/animation, maybe using source.get_animation().frames which is a list of frames where each frame is a simple image. I'm guessing this isn't really going to be pracitical with large videos but that is generally not something you...
0
2010-03-29T02:00:54Z
[ "python", "video-processing", "pyglet", "motion-detection" ]
How to change db in django depending on request.get_host()?
2,532,268
<p>I am creating multisites platform. Anybody can make simple site, with my platform. I plan to use django multidb support. One db for one site. And i need to change db settings depending on request.get_host(). I think that i's not good idea. Prompt other decisions? How it is realised on various designers of sites?</p...
2
2010-03-28T08:05:17Z
2,534,950
<p>You might want to reconsider using a separate db for reach site. In reviewing the multi-db source, it looks like you'll run into a few scalability issues, depending on how many sites you want to support:</p> <p>Currently all the databases are set up in <em>settings.py</em>. This could cause a few issues:</p> <ul> ...
1
2010-03-28T23:08:25Z
[ "python", "django", "django-middleware", "django-orm" ]
How to change db in django depending on request.get_host()?
2,532,268
<p>I am creating multisites platform. Anybody can make simple site, with my platform. I plan to use django multidb support. One db for one site. And i need to change db settings depending on request.get_host(). I think that i's not good idea. Prompt other decisions? How it is realised on various designers of sites?</p...
2
2010-03-28T08:05:17Z
5,369,262
<p>You can set up one site for each "site", with it's own settings file, listening to it's own socket, using the same codebase. I'm doing that and I can easily support more than 30 concurrent sites on a middle-size server. Maintainability of configurations and startup scripts is the only issue. </p>
0
2011-03-20T15:04:07Z
[ "python", "django", "django-middleware", "django-orm" ]
django views question
2,532,304
<p>In my django views i have the following </p> <pre><code>def create(request): query=header.objects.filter(id=a)[0] a=query.criteria_set.all() logging.debug(a.details) </code></pre> <p>I get an error saying 'QuerySet' object has no attribute 'details' in the debug statement .What is this error and what shou...
0
2010-03-28T08:21:44Z
2,532,305
<p><code>QuerySet.all()</code> returns a QuerySet. Index it or iterate over it if you want to access the individual models:</p> <pre><code>logging.debug(a[0].details) for m in a: logging.debug(m.details) </code></pre>
3
2010-03-28T08:23:23Z
[ "python", "django", "django-views", "django-queryset" ]
Python: ImportError no module named urllib
2,532,321
<p>I just rented a VPS from Linode which has python2.5 and ubuntu 8.04. When I run this command from <code>python</code> shell:</p> <pre><code>import urllib </code></pre> <p>I get:</p> <pre><code>ImportError: No module named urllib </code></pre> <p>What can be the reason? How can I add this module to python? Isn't ...
-1
2010-03-28T08:36:09Z
2,532,347
<p>I use a later OS, so I don't know if this will help, but just in case:</p> <pre><code>marcelo@localhost:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 9.10 Release: 9.10 Codename: karmic marcelo@localhost:~$ python Python 2.6.4rc2 (r264rc2:75497, Oct 20 20...
-1
2010-03-28T08:53:41Z
[ "python", "urllib", "importerror", "pythonpath" ]
Python: ImportError no module named urllib
2,532,321
<p>I just rented a VPS from Linode which has python2.5 and ubuntu 8.04. When I run this command from <code>python</code> shell:</p> <pre><code>import urllib </code></pre> <p>I get:</p> <pre><code>ImportError: No module named urllib </code></pre> <p>What can be the reason? How can I add this module to python? Isn't ...
-1
2010-03-28T08:36:09Z
2,532,363
<p>Ok, I resolved the issue. Somehow, python-tk package (which includes urllib) was missing.</p> <p>So the following line fixed the problem</p> <pre><code>apt-get install python-tk </code></pre>
1
2010-03-28T08:58:51Z
[ "python", "urllib", "importerror", "pythonpath" ]
Python: How do sets work
2,532,365
<p>I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are <code>o.id</code> and <code>o.area</code>. I want two objects to be equal if these two fields are the same. ie: <code>o1==o2</code> if and only if <code>o1.area==o2.area and o1.id==o2.id</code>.</p> <p>I...
25
2010-03-28T08:59:30Z
2,532,368
<p>Define the <code>__hash__</code> method to return a meaningful hash based on the id and area fields. E.g.:</p> <pre><code>def __hash__(self): return hash(self.id) ^ hash(self.area) </code></pre>
37
2010-03-28T09:01:05Z
[ "python", "hash", "set" ]
Python: How do sets work
2,532,365
<p>I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are <code>o.id</code> and <code>o.area</code>. I want two objects to be equal if these two fields are the same. ie: <code>o1==o2</code> if and only if <code>o1.area==o2.area and o1.id==o2.id</code>.</p> <p>I...
25
2010-03-28T08:59:30Z
2,533,387
<p>"TypeError: unhashable instance." error is probably due to old-style class definition i.e.: </p> <pre><code>class A: pass </code></pre> <p>Use new style instead:</p> <pre><code>class A(object): pass </code></pre> <p>If you override __cmp__ function you <strong>should</strong> override __hash__ for using your...
9
2010-03-28T15:19:51Z
[ "python", "hash", "set" ]
Django: Paginator + raw SQL query
2,532,475
<p>I'm using Django Paginator everywhere on my website and even wrote a special template tag, to make it more convenient. But now I got to a state, where I need to make a complex custom raw SQL query, that without a <code>LIMIT</code> will return about 100K records.</p> <p><strong>How can I use Django Pagintor with cu...
9
2010-03-28T09:54:59Z
2,532,497
<p>I don't know about Django 1.1 but if you can wait for 1.2 (which shouldn't be that long anymore) you can make use of <code>objects.raw()</code> as described in <a href="http://djangoadvent.com/1.2/smoothing-curve/" rel="nofollow">this article</a> and in the <a href="http://docs.djangoproject.com/en/dev/topics/db/sql...
2
2010-03-28T10:06:34Z
[ "python", "sql", "django", "pagination" ]
Django: Paginator + raw SQL query
2,532,475
<p>I'm using Django Paginator everywhere on my website and even wrote a special template tag, to make it more convenient. But now I got to a state, where I need to make a complex custom raw SQL query, that without a <code>LIMIT</code> will return about 100K records.</p> <p><strong>How can I use Django Pagintor with cu...
9
2010-03-28T09:54:59Z
2,532,552
<p>Looking at Paginator's source code, <a href="http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/core/paginator.py#L35">page() function</a> in particular, I think that it's only matter of implementing <a href="http://docs.python.org/reference/datamodel.html#object.__getslice__">slicing</a> on you...
7
2010-03-28T10:31:37Z
[ "python", "sql", "django", "pagination" ]
Django: Paginator + raw SQL query
2,532,475
<p>I'm using Django Paginator everywhere on my website and even wrote a special template tag, to make it more convenient. But now I got to a state, where I need to make a complex custom raw SQL query, that without a <code>LIMIT</code> will return about 100K records.</p> <p><strong>How can I use Django Pagintor with cu...
9
2010-03-28T09:54:59Z
36,022,955
<p>Here is a <code>RawPaginator</code> class I made that overrides <code>Paginator</code> to work with raw queries. It takes one additional argument, <code>count</code>, which is the total count or your query. It doesn't slice the <code>object_list</code> because you must paginate in your raw query via <code>OFFSET</co...
0
2016-03-15T21:54:14Z
[ "python", "sql", "django", "pagination" ]
mod_cgi , mod_fastcgi, mod_scgi , mod_wsgi, mod_python, FLUP. I don't know how many more. what is mod_php equivalent?
2,532,477
<p>I recently learnt Python. I liked it. I just wanted to use it for web development. This thought caused all the troubles. But I like these troubles :)</p> <p>Coming from PHP world where there is only one way standardized. I expected the same and searched for python &amp; apache.</p> <p><a href="http://stackoverflow...
10
2010-03-28T09:56:30Z
2,532,508
<p>There is no exact equivalent to mod_php in the Python world.</p> <ul> <li>FastCGI, SCGI, and AJP run the web app as a separate process (daemon), and pass messages between the web server and it.</li> <li>mod_python is used to embed Python code into the httpd process during any of the request phases.</li> <li>mod_wsg...
5
2010-03-28T10:09:59Z
[ "php", "python", "apache" ]
mod_cgi , mod_fastcgi, mod_scgi , mod_wsgi, mod_python, FLUP. I don't know how many more. what is mod_php equivalent?
2,532,477
<p>I recently learnt Python. I liked it. I just wanted to use it for web development. This thought caused all the troubles. But I like these troubles :)</p> <p>Coming from PHP world where there is only one way standardized. I expected the same and searched for python &amp; apache.</p> <p><a href="http://stackoverflow...
10
2010-03-28T09:56:30Z
2,532,536
<p>mod_python is the closest equivalent of mod_php, but this doesn't mean that mod_python will suit your needs. For each programming language you have to enumerate all the possible options and choose the one you'll need.</p> <p>For PHP, you have mod_php and mod_cgi, but from this two mod_cgi is inferior in almost all ...
4
2010-03-28T10:26:24Z
[ "php", "python", "apache" ]
mod_cgi , mod_fastcgi, mod_scgi , mod_wsgi, mod_python, FLUP. I don't know how many more. what is mod_php equivalent?
2,532,477
<p>I recently learnt Python. I liked it. I just wanted to use it for web development. This thought caused all the troubles. But I like these troubles :)</p> <p>Coming from PHP world where there is only one way standardized. I expected the same and searched for python &amp; apache.</p> <p><a href="http://stackoverflow...
10
2010-03-28T09:56:30Z
2,532,641
<p><code>mod_python</code> is the most like <code>mod_php</code> in what it does (ie. it tries to do everything). That's not necessarily a good thing and I wouldn't recommend writing applications to the native mod_python interfaces today.</p> <blockquote> <p>WSGI is some kind of optimized/improved inshort an efficie...
2
2010-03-28T11:00:47Z
[ "php", "python", "apache" ]
mod_cgi , mod_fastcgi, mod_scgi , mod_wsgi, mod_python, FLUP. I don't know how many more. what is mod_php equivalent?
2,532,477
<p>I recently learnt Python. I liked it. I just wanted to use it for web development. This thought caused all the troubles. But I like these troubles :)</p> <p>Coming from PHP world where there is only one way standardized. I expected the same and searched for python &amp; apache.</p> <p><a href="http://stackoverflow...
10
2010-03-28T09:56:30Z
2,532,642
<p>The standard way to deploy a Python application to the web is via WSGI. These days there's no reason to use anything else.</p> <p>mod_wsgi is the Apache module that supports WSGI. Other web servers will have different names for their WSGI modules.</p>
9
2010-03-28T11:01:11Z
[ "php", "python", "apache" ]
How do I make this simple list comprehension?
2,532,525
<p>I'm new to python, and I'm trying to get to know the list comprehensions better.<br> I'm not even really sure if list comprehension is the word I'm looking for, since I'm not generating a list. But I am doing something similar.</p> <p>This is what I am trying to do:</p> <p>I have a list of numbers, the length of w...
4
2010-03-28T10:19:35Z
2,532,541
<pre><code>import itertools nums = [1, 2, 3, 4, 5, 6] print [a + b + c for a, b, c in itertools.izip(*[iter(nums)] * 3)] </code></pre>
4
2010-03-28T10:29:06Z
[ "python", "list-comprehension" ]
How do I make this simple list comprehension?
2,532,525
<p>I'm new to python, and I'm trying to get to know the list comprehensions better.<br> I'm not even really sure if list comprehension is the word I'm looking for, since I'm not generating a list. But I am doing something similar.</p> <p>This is what I am trying to do:</p> <p>I have a list of numbers, the length of w...
4
2010-03-28T10:19:35Z
2,532,558
<p>See <a href="http://docs.python.org/library/functions.html#sum" rel="nofollow"><code>sum(iterable[, start]</code>)</a> builtin, and use it on slices.</p> <blockquote> <p>Sums start and the items of an iterable from left to right and returns the total. start defaults to 0. The iterable‘s items are normally numbe...
6
2010-03-28T10:34:04Z
[ "python", "list-comprehension" ]
How do I make this simple list comprehension?
2,532,525
<p>I'm new to python, and I'm trying to get to know the list comprehensions better.<br> I'm not even really sure if list comprehension is the word I'm looking for, since I'm not generating a list. But I am doing something similar.</p> <p>This is what I am trying to do:</p> <p>I have a list of numbers, the length of w...
4
2010-03-28T10:19:35Z
2,532,650
<pre><code>nums = [1, 2, 3, 4, 5, 6] map(sum, itertools.izip(*[iter(nums)]*3)) </code></pre>
1
2010-03-28T11:04:33Z
[ "python", "list-comprehension" ]
How to implement this mechanism:
2,532,664
<p>Hi<br> i want to implement a dynamic relation mechanism with python something like:</p> <pre><code>a:=10 b:=30 c:=a+b print c a+=20 print c </code></pre> <p>output:</p> <pre><code>40 60 </code></pre> <p>c is always result of a+b.<br> so if a or b change, then c automatically updates value. i write a code in C# a...
3
2010-03-28T11:11:43Z
2,532,671
<p>New-style Python classes support <a href="http://docs.python.org/library/functions.html#property" rel="nofollow">properties</a>.</p>
2
2010-03-28T11:14:08Z
[ "python" ]
How to implement this mechanism:
2,532,664
<p>Hi<br> i want to implement a dynamic relation mechanism with python something like:</p> <pre><code>a:=10 b:=30 c:=a+b print c a+=20 print c </code></pre> <p>output:</p> <pre><code>40 60 </code></pre> <p>c is always result of a+b.<br> so if a or b change, then c automatically updates value. i write a code in C# a...
3
2010-03-28T11:11:43Z
2,532,700
<p>something like this:</p> <pre><code>class C: def __init__(self): self.x = 0 self.y = 0 def get(self): return self.x + self.y def __str__(self): return self.__unicode__() def __unicode__(self): return str(self.get()) c = C() c.x = 1 print c c.y =2 print c </code></pre> <p>With new st...
1
2010-03-28T11:25:28Z
[ "python" ]
How to implement this mechanism:
2,532,664
<p>Hi<br> i want to implement a dynamic relation mechanism with python something like:</p> <pre><code>a:=10 b:=30 c:=a+b print c a+=20 print c </code></pre> <p>output:</p> <pre><code>40 60 </code></pre> <p>c is always result of a+b.<br> so if a or b change, then c automatically updates value. i write a code in C# a...
3
2010-03-28T11:11:43Z
2,532,727
<p>This is probably overkill, but it illustrates how you should create getters/setters in Python and achieve the functionality you want:</p> <pre><code>class Calc(object): def __init__(self, a = 0, b = 0): self._a = a self._b = b @property def a(self): return self._a @a.setter...
4
2010-03-28T11:36:26Z
[ "python" ]
How to implement this mechanism:
2,532,664
<p>Hi<br> i want to implement a dynamic relation mechanism with python something like:</p> <pre><code>a:=10 b:=30 c:=a+b print c a+=20 print c </code></pre> <p>output:</p> <pre><code>40 60 </code></pre> <p>c is always result of a+b.<br> so if a or b change, then c automatically updates value. i write a code in C# a...
3
2010-03-28T11:11:43Z
2,532,863
<p>In your situation, c actually is a function which must be called. You could use something like this:</p> <pre><code>a = 10 b = 30 c = lambda: a + b print c() a += 20 print c() </code></pre> <p>If you dislike that the method call is made explicit for c, you could use a general Calc object, which hides this impleme...
3
2010-03-28T12:27:14Z
[ "python" ]
Using Django CMS
2,532,840
<p>I know python and have just read a basic intro of django. I have to built something like a travel website with real time updates. Will django be sufficent for this? Somebody advised me to look at django-CMS, I couldn't find a very beginner's tutorial there. Should I opt for django-CMS? Also how much of django should...
0
2010-03-28T12:19:12Z
2,532,866
<p>From your brief description it sounds like the main part of you project will be something that manages travel information and displays it to visitors to a website. This definitely sounds like something Django would be perfect for.</p> <p>Django projects tend to be very modular, so the content management part of you...
2
2010-03-28T12:27:38Z
[ "python", "django", "content-management-system" ]
Using Django CMS
2,532,840
<p>I know python and have just read a basic intro of django. I have to built something like a travel website with real time updates. Will django be sufficent for this? Somebody advised me to look at django-CMS, I couldn't find a very beginner's tutorial there. Should I opt for django-CMS? Also how much of django should...
0
2010-03-28T12:19:12Z
30,400,944
<p>I would say no. Django CMS is well designed, if you change content frequently. It has nice features to build up a page. But that means it only shows its benefits, when you create a lot pages/subpages and so on. </p> <p>For a simple website that only presents data, without adding new pages/views, Django will suffice...
1
2015-05-22T15:48:17Z
[ "python", "django", "content-management-system" ]
A Question about using jython when run a receving socket in python
2,532,943
<p>I have not a lot of knowledge of python and network programming. Currently I am trying to implement a simple application which can receive a text message sent by the user, fetch some information from the google search api, and return the results via text message to the user. This application will continue to listeni...
2
2010-03-28T12:54:43Z
2,533,102
<p>The error states that you have tried to call <code>select</code> on a socket that is set (by default) to block waiting for input. The portable way to make it non-blocking is to find where <code>self.__sock</code> is created and call <a href="http://docs.python.org/library/socket.html#socket.socket.setblocking" rel="...
1
2010-03-28T13:44:05Z
[ "python", "sockets", "jython", "nonblocking" ]
A Question about using jython when run a receving socket in python
2,532,943
<p>I have not a lot of knowledge of python and network programming. Currently I am trying to implement a simple application which can receive a text message sent by the user, fetch some information from the google search api, and return the results via text message to the user. This application will continue to listeni...
2
2010-03-28T12:54:43Z
2,561,494
<p>As stated on the jython select documentaion page, only sockets in non-blocking mode can be multiplexed on jython, in contrast to cpython, where sockets can be either blocking or non-blocking.</p> <p><a href="http://wiki.python.org/jython/SelectModule#Onlysocketsinnon-blockingmodecanbemultiplexed" rel="nofollow">htt...
2
2010-04-01T15:23:57Z
[ "python", "sockets", "jython", "nonblocking" ]
Free Cryptography libraries
2,532,983
<p><br> What are the most stable and useful Cryptography libraries, that they are:</p> <ul> <li>written with/for python, c++, c#, .net</li> <li>opensource, GNU, or other free license</li> </ul>
2
2010-03-28T13:09:37Z
2,532,990
<p>Take a look at <a href="http://www.keyczar.org/" rel="nofollow">KeyCzar</a> </p> <blockquote> <p>Some features of Keyczar include:</p> <ul> <li>A simple API</li> <li>Key rotation and versioning</li> <li>Safe default algorithms, modes, and key lengths</li> <li>Automated generation of initialization ve...
1
2010-03-28T13:12:06Z
[ "c#", "c++", "python", "cryptography" ]
Free Cryptography libraries
2,532,983
<p><br> What are the most stable and useful Cryptography libraries, that they are:</p> <ul> <li>written with/for python, c++, c#, .net</li> <li>opensource, GNU, or other free license</li> </ul>
2
2010-03-28T13:09:37Z
2,532,999
<p>For C# and Java, there is <a href="http://www.bouncycastle.org" rel="nofollow">bouncycastle</a>. The granddaddy of crypto libraries is <a href="http://www.openssl.org" rel="nofollow">openssl</a>. For C++, another very mature library is <a href="http://www.cryptopp.com/" rel="nofollow">crypto++</a>.</p>
2
2010-03-28T13:14:03Z
[ "c#", "c++", "python", "cryptography" ]
Free Cryptography libraries
2,532,983
<p><br> What are the most stable and useful Cryptography libraries, that they are:</p> <ul> <li>written with/for python, c++, c#, .net</li> <li>opensource, GNU, or other free license</li> </ul>
2
2010-03-28T13:09:37Z
2,533,004
<p><a href="http://www.mozilla.org/projects/security/pki/nss/" rel="nofollow">NSS</a> works with C++, and has bindings for Java and Python, although I'm not sure if it has .NET/Mono bindings yet.</p>
0
2010-03-28T13:15:15Z
[ "c#", "c++", "python", "cryptography" ]
Free Cryptography libraries
2,532,983
<p><br> What are the most stable and useful Cryptography libraries, that they are:</p> <ul> <li>written with/for python, c++, c#, .net</li> <li>opensource, GNU, or other free license</li> </ul>
2
2010-03-28T13:09:37Z
2,533,095
<p>The standard Python library (implementing common ciphers like AES and RSA) is <a href="http://www.dlitz.net/software/pycrypto/" rel="nofollow">PyCrypto</a>. It doesn't support things like <a href="http://en.wikipedia.org/wiki/PKCS" rel="nofollow">PKCS</a> yet, however. There is a partial Python wrapper for the Crypt...
2
2010-03-28T13:42:08Z
[ "c#", "c++", "python", "cryptography" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
2,533,134
<p>I'm assuming you mean from the command-line. I've never seen initial values for command line prompts, they're usually of the form:</p> <pre><code> Folder [default] : </code></pre> <p>which in code is simply:</p> <pre><code> res = raw_input('Folder [default] : ') res = res or 'default' </code></pre> ...
14
2010-03-28T13:57:33Z
[ "python", "input" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
2,533,142
<p>The standard library functions <code>input()</code> and <code>raw_input()</code> don't have this functionality. If you're using Linux you can use the <a href="http://docs.python.org/library/readline.html"><code>readline</code></a> module to define an input function that uses a prefill value and advanced line editing...
43
2010-03-28T14:01:02Z
[ "python", "input" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
2,533,143
<p>If you do that, the user would have to delete the existing word. What about providing a default value if the user hits "return"?</p> <pre><code>&gt;&gt;&gt; default_folder = "My Documents" &gt;&gt;&gt; try: folder = input("folder name [%s]:" %default_folder) ... except SyntaxError: folder = default_folder </code><...
-2
2010-03-28T14:01:19Z
[ "python", "input" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
2,533,315
<p>I think that the best (the easiest and most portable) solution is a combination of @rlotun and @Stephen answers:</p> <pre><code>default = '/default/path/' dir = raw_input('Folder [%s]' % default) dir = dir or default </code></pre>
4
2010-03-28T14:56:04Z
[ "python", "input" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
5,888,246
<p>This works in windows.</p> <pre><code>import win32console _stdin = win32console.GetStdHandle(win32console.STD_INPUT_HANDLE) def input_def(prompt, default=''): keys = [] for c in unicode(default): evt = win32console.PyINPUT_RECORDType(win32console.KEY_EVENT) evt.Char = c evt.RepeatC...
7
2011-05-04T18:33:34Z
[ "python", "input" ]
Show default value for editing on Python input possible?
2,533,120
<p>Is it possible for python to accept input like this:</p> <pre> Folder name: Download </pre> <p>But instead of the user typing "Download" it is already there as a initial value. If the user wants to edit it as "Downloads" all he has to do is add a 's' and press enter.</p> <p>Using normal input command:</p> <pre><...
35
2010-03-28T13:51:45Z
22,433,301
<p>Not the best aproach but for the sake of sharing... You could use Javascript to get all sort of inputs in IPython Notebook. </p> <pre><code>from IPython.display import HTML newvar = "" htm = """ &lt;input id="inptval" style="width:60%;" type="text" value="This is an editable default value."&gt; &lt;button onclick="...
0
2014-03-16T05:22:53Z
[ "python", "input" ]
how to convert Python 3 to Python 2 code?
2,533,217
<p>I had written a program in Python 3, but now want to convert it into Python 2 code. Are there any utilities to do that automatically?</p>
14
2010-03-28T14:23:29Z
2,533,224
<p>You want <a href="http://wiki.python.org/moin/3to2"><code>3to2</code></a> for that.</p>
20
2010-03-28T14:24:40Z
[ "python", "python-3.x" ]
GAE/Django Templates (0.96) filters to get LENGTH of GqlQuery and filter it
2,533,306
<p>I pass the query with comments to my template:</p> <pre><code> COMM = CommentModel.gql("ORDER BY created") doRender(self,CP.template,{'CP':CP,'COMM':COMM, 'authorize':authorize()}) </code></pre> <p>And I want to output the number of comments as a result, and I try to do things like that:</p> <pre><code> ...
0
2010-03-28T14:53:43Z
2,533,428
<p>You could use <a href="http://code.google.com/appengine/docs/python/datastore/gqlqueryclass.html#GqlQuery_count" rel="nofollow">count</a> on your <code>GqlQuery</code> object, but a <code>GqlQuery</code> doesn't let you add <code>where</code> clauses and the like -- you need <a href="http://code.google.com/appengine...
1
2010-03-28T15:33:03Z
[ "python", "google-app-engine", "django-templates" ]
GAE/Django Templates (0.96) filters to get LENGTH of GqlQuery and filter it
2,533,306
<p>I pass the query with comments to my template:</p> <pre><code> COMM = CommentModel.gql("ORDER BY created") doRender(self,CP.template,{'CP':CP,'COMM':COMM, 'authorize':authorize()}) </code></pre> <p>And I want to output the number of comments as a result, and I try to do things like that:</p> <pre><code> ...
0
2010-03-28T14:53:43Z
2,533,469
<p>Call .fetch() on the query, returning a list of results, before passing it to the template. Any other solution - such as calling .count() - will result in executing the query multiple times, which wastes CPU and wall-clock time.</p> <p>Likewise, if you need to filter the query, you should do this in your own code, ...
3
2010-03-28T15:44:27Z
[ "python", "google-app-engine", "django-templates" ]
GAE/Django Templates (0.96) filters to get LENGTH of GqlQuery and filter it
2,533,306
<p>I pass the query with comments to my template:</p> <pre><code> COMM = CommentModel.gql("ORDER BY created") doRender(self,CP.template,{'CP':CP,'COMM':COMM, 'authorize':authorize()}) </code></pre> <p>And I want to output the number of comments as a result, and I try to do things like that:</p> <pre><code> ...
0
2010-03-28T14:53:43Z
3,376,379
<p>I'm not exactly sure what your trying to accomplish, but you could possibly benefit from URL Mapping, however it will require some extra code. The basic idea is that you would turn whatever value you want to filter against into a "directory". Examples will help:</p> <pre><code>&lt;a href="basepath/{{ value.tofilt...
0
2010-07-31T01:16:33Z
[ "python", "google-app-engine", "django-templates" ]
Python metaclass for enforcing immutability of custom types
2,533,367
<p>Having searched for a way to enforce immutability of custom types and not having found a satisfactory answer I came up with my own shot at a solution in form of a metaclass:</p> <pre><code>class ImmutableTypeException( Exception ): pass class Immutable( type ): ''' Enforce some aspects of the immutability co...
2
2010-03-28T15:15:03Z
2,533,392
<p>Special methods are always looked up on the <em>type</em>, not the <em>instance</em>. So <code>hasattr</code> must also be applied to the <strong>type</strong>. E.g.:</p> <pre><code>&gt;&gt;&gt; class A(object): pass ... &gt;&gt;&gt; class B(A): __eq__ = lambda *_: 1 ... &gt;&gt;&gt; class C(B): pass ... &gt;&...
3
2010-03-28T15:22:04Z
[ "python", "metaclass", "immutability" ]
Python metaclass for enforcing immutability of custom types
2,533,367
<p>Having searched for a way to enforce immutability of custom types and not having found a satisfactory answer I came up with my own shot at a solution in form of a metaclass:</p> <pre><code>class ImmutableTypeException( Exception ): pass class Immutable( type ): ''' Enforce some aspects of the immutability co...
2
2010-03-28T15:15:03Z
17,119,718
<p>This metaclass enforces "shallow" immutability. For example, it doesn't prevent</p> <pre><code>immutable_obj.attr.attrs_attr = new_value immutable_obj.attr[2] = new_value </code></pre> <p>Depending if attrs_attr is owned by the object or not, that might be considered to violate true immutability. E.g. it might res...
0
2013-06-15T02:44:07Z
[ "python", "metaclass", "immutability" ]
How to setup and teardown temporary django db for unit testing?
2,533,457
<p>I would like to have a python module containing some unit tests that I can pass to <code>hg bisect --command</code>. </p> <p>The unit tests are testing some functionality of a django app, but I don't think I can use <code>hg bisect --command manage.py test mytestapp</code> because <code>mytestapp</code> would have ...
8
2010-03-28T15:41:27Z
2,533,604
<p>You must use the internal Django TestCase to do so. </p> <pre><code>from django.test import TestCase class TestCase(TestCase): # before every call to setUp(), the db is automatically # set back to the state is was after the first syncdb then # all these fixture files will be loaded in the db f...
5
2010-03-28T16:31:06Z
[ "python", "django", "unit-testing", "mercurial" ]
How to setup and teardown temporary django db for unit testing?
2,533,457
<p>I would like to have a python module containing some unit tests that I can pass to <code>hg bisect --command</code>. </p> <p>The unit tests are testing some functionality of a django app, but I don't think I can use <code>hg bisect --command manage.py test mytestapp</code> because <code>mytestapp</code> would have ...
8
2010-03-28T15:41:27Z
2,533,957
<p>Cracked it. I now have one python file completely independent of any django app that can run unit tests with a test database:</p> <pre><code>#!/usr/bin/env python """Run a unit test and return result. This can be used with `hg bisect`. It is assumed that this file resides in the same dir as settings.py """ impor...
7
2010-03-28T18:13:39Z
[ "python", "django", "unit-testing", "mercurial" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
2,533,567
<p>It is the standard of <a href="http://en.wikipedia.org/wiki/Unix_time">Unix time.</a></p> <blockquote> <p>Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap se...
33
2010-03-28T16:21:11Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
2,533,568
<p>Yes, C (and its family). This is where Java took it too.</p>
1
2010-03-28T16:21:12Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
2,533,570
<p>January 1st, 1970 is the zero-point of <a href="http://en.wikipedia.org/wiki/Unix_time">POSIX time</a>.</p>
6
2010-03-28T16:21:36Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
2,533,744
<blockquote> <p>Is there any reason behind using date(January 1st, 1970) as standard for time manipulation? </p> </blockquote> <p>No reason that matters.</p> <p>Python's <code>time</code> module <em>is</em> the C library. Ask Ken Thompson why he chose that date for an epochal date. Maybe it was someone's birthday...
3
2010-03-28T17:10:43Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
16,132,913
<p><strong>Q)</strong> "Why are dates calculated from January 1st, 1970?"</p> <p><strong>A)</strong> It had to be as recent as possible, yet include <em>some</em> past. There was most likely no significant other reason as a lot of people feel that same way.</p> <p>They knew it posed a problem if they placed it too fa...
1
2013-04-21T15:38:51Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
26,374,367
<p>why its always 1st jan 1970 , Because - '1st January 1970' usually called as "epoch date" is the date when the time started for Unix computers, and that timestamp is marked as '0'. Any time since that date is calculated based on the number of seconds elapsed. In simpler words... the timestamp of any date will be dif...
1
2014-10-15T04:12:49Z
[ "java", "python", "programming-languages" ]
Why are dates calculated from January 1st, 1970?
2,533,563
<p>Is there any reason behind using date(January 1st, 1970) as default standard for time manipulation? I have seen this standard in Java as well as in Python. These two languages I am aware of. Are there other popular languages which follows the same standard?</p> <p>Please describe.</p>
28
2010-03-28T16:18:46Z
26,391,999
<p>The Question makes two false assumptions:</p> <ul> <li>All time-tracking in computing is done as a count-since-1970.</li> <li>Such tracking is standard. </li> </ul> <h1>Two Dozen Epochs</h1> <p>Time in computing is <em>not always</em> tracked from the beginning of 1970 <a href="http://en.wikipedia.org/wiki/Coordi...
10
2014-10-15T20:59:15Z
[ "java", "python", "programming-languages" ]
Automatically open files given as command line arguments in Python
2,533,673
<p>I have a lot of Perl scripts that looks something like the following. What it does is that it will automatically open any file given as a command line argument and in this case print the content of that file. If no file is given it will instead read from standard input.</p> <pre><code>while ( &lt;&gt; ) { print...
1
2010-03-28T16:47:39Z
2,533,707
<p>The <a href="http://docs.python.org/library/fileinput.html?highlight=fileinput#module-fileinput" rel="nofollow">fileinput</a> module in Python's standard library is designed exactly for this purpose, and I quote a bit of code from the URL I just gave:</p> <pre><code>import fileinput for line in fileinput.input(): ...
10
2010-03-28T16:59:03Z
[ "python", "file", "filenames", "command-line-arguments" ]
Counts of events grouped by date in python?
2,534,424
<p>This is no doubt another noobish question, but I'll ask it anyways:</p> <p>I have a data set of events with exact datetime in UTC. I'd like to create a line chart showing total number of events by day (date) in the specified date range. Right now I can retrieve the total data set for the needed date range, but then...
3
2010-03-28T20:29:54Z
2,534,472
<p>I can't see how that would be possible with single query as <a href="http://code.google.com/appengine/docs/python/datastore/gqlreference.html" rel="nofollow">GQL</a> has no support for GROUP BY or <a href="http://stackoverflow.com/questions/739220/does-gql-support-commonly-available-sql-style-aggregation">aggregatio...
0
2010-03-28T20:40:53Z
[ "python", "django", "google-app-engine" ]
Counts of events grouped by date in python?
2,534,424
<p>This is no doubt another noobish question, but I'll ask it anyways:</p> <p>I have a data set of events with exact datetime in UTC. I'd like to create a line chart showing total number of events by day (date) in the specified date range. Right now I can retrieve the total data set for the needed date range, but then...
3
2010-03-28T20:29:54Z
2,534,766
<p>You'll have to do the binning in-memory (i.e. after the datastore fetch).</p> <p>The <code>.date()</code> method of a <code>datetime</code> instance will facilitate your binning; it chops off the time element. Then you can use a dictionary to hold the bins:</p> <pre><code>bins = {} for event in Event.all().fetch(1...
1
2010-03-28T22:06:17Z
[ "python", "django", "google-app-engine" ]
Counts of events grouped by date in python?
2,534,424
<p>This is no doubt another noobish question, but I'll ask it anyways:</p> <p>I have a data set of events with exact datetime in UTC. I'd like to create a line chart showing total number of events by day (date) in the specified date range. Right now I can retrieve the total data set for the needed date range, but then...
3
2010-03-28T20:29:54Z
2,536,898
<p>In order to minimize the amount of work you do, you'll probably want to write a task that sums up the per-day totals once, so you can reuse them. I'd suggest using the <a href="http://blog.notdot.net/2010/03/Announcing-a-robust-datastore-bulk-update-utility-for-App-Engine" rel="nofollow">bulkupdate library</a> to ru...
0
2010-03-29T09:32:34Z
[ "python", "django", "google-app-engine" ]
How to display a PostScript file in a Python GUI application
2,534,474
<p>I would like to build a cross-platform GUI application in Python that displays PostScript files I generate, among some other stuff. What is the best way to accomplish this? Ideally I would be able to do things like zoom and pan the displayed graphic. </p> <p>Do any/some/all of the GUI toolkits have something I can ...
1
2010-03-28T20:41:24Z
2,534,523
<p>I asked pretty much the same question a little time ago. <a href="http://stackoverflow.com/questions/2435470/pdf-viewer-for-pyqt4-application">Here it is</a>. Hope it helps.</p> <p>Note: Poppler is highly undocumented. If you use Gtk for your GUI there are a few working examples. In Qt things are a little harder, a...
1
2010-03-28T20:54:51Z
[ "python", "user-interface", "postscript" ]
How to display a PostScript file in a Python GUI application
2,534,474
<p>I would like to build a cross-platform GUI application in Python that displays PostScript files I generate, among some other stuff. What is the best way to accomplish this? Ideally I would be able to do things like zoom and pan the displayed graphic. </p> <p>Do any/some/all of the GUI toolkits have something I can ...
1
2010-03-28T20:41:24Z
3,735,619
<p>In a word <a href="http://www.ghostscript.com" rel="nofollow"><strong>Ghostscript</strong></a>. It's been a while since I used it, but it's cross-platform and you can use it to generate image files which your app could then display, pan, and zoom. I used it to develop and test some pretty involved commercial Postscr...
1
2010-09-17T13:15:58Z
[ "python", "user-interface", "postscript" ]
Proper way to reload a python module from the console
2,534,480
<p>I'm debugging from the python console and would like to reload a module every time I make a change so I don't have to exit the console and re-enter it. I'm doing:</p> <pre><code>&gt;&gt;&gt; from project.model.user import * &gt;&gt;&gt; reload(user) </code></pre> <p>but I receive:</p> <pre><code>&gt;&gt;&gt;Name...
13
2010-03-28T20:43:27Z
2,534,492
<p>Unfortunately you've got to use:</p> <pre><code>&gt;&gt;&gt; from project.model import user &gt;&gt;&gt; reload(user) </code></pre> <p>I don't know off the top of my head of something which will automatically reload modules at the interactive prompt… But I don't see any reason one shouldn't exist (in fact, it wo...
3
2010-03-28T20:46:52Z
[ "python" ]
Proper way to reload a python module from the console
2,534,480
<p>I'm debugging from the python console and would like to reload a module every time I make a change so I don't have to exit the console and re-enter it. I'm doing:</p> <pre><code>&gt;&gt;&gt; from project.model.user import * &gt;&gt;&gt; reload(user) </code></pre> <p>but I receive:</p> <pre><code>&gt;&gt;&gt;Name...
13
2010-03-28T20:43:27Z
2,534,493
<p>You can't use reload() in a effective way.</p> <p>Python does not provide an effective support for reloading or unloading of previously imported modules; module references makes it impractical to reload a module because references could exist in many places of your program.</p> <p>Python 3 has removed reload() fe...
2
2010-03-28T20:46:54Z
[ "python" ]
Proper way to reload a python module from the console
2,534,480
<p>I'm debugging from the python console and would like to reload a module every time I make a change so I don't have to exit the console and re-enter it. I'm doing:</p> <pre><code>&gt;&gt;&gt; from project.model.user import * &gt;&gt;&gt; reload(user) </code></pre> <p>but I receive:</p> <pre><code>&gt;&gt;&gt;Name...
13
2010-03-28T20:43:27Z
2,534,513
<p>As asked, the best you can do is</p> <pre><code>&gt;&gt;&gt; from project.models.user import * &gt;&gt;&gt; import project # get module reference for reload &gt;&gt;&gt; reload(project.models.user) # reload step 1 &gt;&gt;&gt; from project.models.user import * # reload step 2 </code></pre> <p>it would be better an...
20
2010-03-28T20:53:06Z
[ "python" ]
Proper way to reload a python module from the console
2,534,480
<p>I'm debugging from the python console and would like to reload a module every time I make a change so I don't have to exit the console and re-enter it. I'm doing:</p> <pre><code>&gt;&gt;&gt; from project.model.user import * &gt;&gt;&gt; reload(user) </code></pre> <p>but I receive:</p> <pre><code>&gt;&gt;&gt;Name...
13
2010-03-28T20:43:27Z
2,534,656
<p>You could also try <a href="http://twistedmatrix.com/documents/10.0.0/api/twisted.python.rebuild.html" rel="nofollow"><code>twisted.python.rebuild.rebuild</code></a>.</p>
0
2010-03-28T21:32:47Z
[ "python" ]
Accessing php $_SESSION from python (wsgi) - is it possible?
2,534,525
<p>I've got a python/WSGI app which needs to check to see if a user has logged on to a PHP web app. The problem is that the PHP app checks if a user has logged on by comparing a value in the $_SESSION variable to a value in the cookie from the user's browser. I would prefer to avoid changing the behavior of the php app...
4
2010-03-28T20:55:12Z
2,534,558
<ol> <li><p>yep. session (in default) is a regular file. so all what you need is look over session directory and find file with name of session cookie value. then - you have to implement php-like serialize/unserialize and do whatever you want.</p></li> <li><p>nope</p></li> </ol>
2
2010-03-28T21:06:39Z
[ "php", "python", "session", "wsgi" ]
Accessing php $_SESSION from python (wsgi) - is it possible?
2,534,525
<p>I've got a python/WSGI app which needs to check to see if a user has logged on to a PHP web app. The problem is that the PHP app checks if a user has logged on by comparing a value in the $_SESSION variable to a value in the cookie from the user's browser. I would prefer to avoid changing the behavior of the php app...
4
2010-03-28T20:55:12Z
2,534,567
<p>Depends on the PHP app, if it's keeping session data in a database (MySQL maybe) you can just connect to the database and get the data, if it's using native PHP sessions you should look to the <code>session.save_path</code> config setting in php.ini, that's the place where the runtime saves files with the session da...
1
2010-03-28T21:08:59Z
[ "php", "python", "session", "wsgi" ]
Accessing php $_SESSION from python (wsgi) - is it possible?
2,534,525
<p>I've got a python/WSGI app which needs to check to see if a user has logged on to a PHP web app. The problem is that the PHP app checks if a user has logged on by comparing a value in the $_SESSION variable to a value in the cookie from the user's browser. I would prefer to avoid changing the behavior of the php app...
4
2010-03-28T20:55:12Z
32,904,637
<p>I'm currently in the process of trying to run a python server side by side with an existing Apache/php one. A custom solution I arrived at was to save the $_SESSION as an encrypted cookie, letting the php authentication operate as before, then share a private key between the two servers. </p> <p>Two issues: </p> <...
0
2015-10-02T09:48:28Z
[ "php", "python", "session", "wsgi" ]
Python inter-computer communication
2,534,527
<p>This whole topic is way out of my depth, so forgive my imprecise question, but I have two computers both connected to one LAN.</p> <p>What I want is to be able to communicate one string between the two, by running a python script on the first (the host) where the string will originate, and a second on the client co...
3
2010-03-28T20:55:38Z
2,534,540
<p>There are about a million ways.</p> <p>If I were doing it, I'd use the <code>SocketServer</code> library, because it's not <em>too</em> insane, fairly well documented, and most importantly, I've used it before.</p> <p>There are a couple of examples here: <a href="http://docs.python.org/library/socketserver.html#ex...
3
2010-03-28T21:01:27Z
[ "python" ]
Python inter-computer communication
2,534,527
<p>This whole topic is way out of my depth, so forgive my imprecise question, but I have two computers both connected to one LAN.</p> <p>What I want is to be able to communicate one string between the two, by running a python script on the first (the host) where the string will originate, and a second on the client co...
3
2010-03-28T20:55:38Z
2,534,582
<p>First, lets get the nomenclature straight. Usually the part that initiate the communication is the client, the parts that is waiting for a connection is a server, which then will receive the data from the client and generate a response. From your question, the "host" is the client and the "client" seems to be the se...
4
2010-03-28T21:12:51Z
[ "python" ]
Python inter-computer communication
2,534,527
<p>This whole topic is way out of my depth, so forgive my imprecise question, but I have two computers both connected to one LAN.</p> <p>What I want is to be able to communicate one string between the two, by running a python script on the first (the host) where the string will originate, and a second on the client co...
3
2010-03-28T20:55:38Z
2,534,778
<p>File share and polling filesystem every minute. No joke. Of course, it depends on what are requirements for your applications and what lag is acceptable but in practice using file shares is quite common.</p>
-2
2010-03-28T22:10:45Z
[ "python" ]
Python: UTF-8 problems (again...)
2,534,596
<p>I have a database which is synchronized against an external web source twice a day. This web source contains a bunch of entries, which have names and some extra information about these names.</p> <p>Some of these names are silly and I want to rename them when inserting them into my own database. To rename these sil...
0
2010-03-28T21:16:46Z
2,534,660
<p>The error you are receiving is due to the unicode string you want not being in the dictionary. Recall that in Python 2.x (I assume you are using that), the default string type is 8-bit, not unicode, so you are actually keying the dictionary with 8-bit strings. To declare a unicode string, use u"my unicode string". T...
4
2010-03-28T21:33:16Z
[ "python", "django", "encoding", "utf-8" ]
Django Sum all values with a distinct ForeignKey ID & zip them with fields from related table
2,534,783
<p>I would like to perform something similar to <a href="http://stackoverflow.com/questions/861310/summing-the-values-from-the-2nd-table-based-on-id-of-the-1st-table">this</a> (ie get the sum of distinct event amounts in a payment table then group the payments by event details and total money paid for them. Also gettin...
1
2010-03-28T22:12:02Z
2,545,339
<p>after some nerve cracking, the solution was to split the query into 2, i.e, one for grouping and summing and the other one for getting the matching values. </p> <p>For grouping and summing, refer <a href="http://stackoverflow.com/questions/629551/how-to-query-as-group-by-in-django">here</a></p>
0
2010-03-30T13:04:49Z
[ "python", "django", "postgresql", "django-models" ]
Drawing a clamped uniform cubic B-spline using Cairo
2,534,786
<p>I have a bunch of coordinates which are the control points of a clamped uniform cubic B-spline on the 2D plane. I would like to draw this curve using Cairo calls (in Python, using Cairo's Python bindings), but as far as I know, Cairo supports Bézier curves only. I also know that the segments of a B-spline between t...
2
2010-03-28T22:13:24Z
2,535,116
<p>Does <a href="http://www.infogoaround.org/JBook/bstobez.html" rel="nofollow">Converting B-spline curve to Bezier spline curve</a> help?</p>
2
2010-03-29T00:02:31Z
[ "python", "bezier", "cairo", "bezier-curve" ]
Drawing a clamped uniform cubic B-spline using Cairo
2,534,786
<p>I have a bunch of coordinates which are the control points of a clamped uniform cubic B-spline on the 2D plane. I would like to draw this curve using Cairo calls (in Python, using Cairo's Python bindings), but as far as I know, Cairo supports Bézier curves only. I also know that the segments of a B-spline between t...
2
2010-03-28T22:13:24Z
2,539,718
<p>Okay, so I searched a lot using Google and I think I came up with a reasonable solution that is suitable for my purposes. I'm posting it here - maybe it will be useful to someone else as well.</p> <p>First, let's start with a simple <code>Point</code> class:</p> <pre><code>from collections import namedtuple class...
5
2010-03-29T16:53:24Z
[ "python", "bezier", "cairo", "bezier-curve" ]
do the Python libraries have a natural dependence on the global namespace?
2,534,847
<p>I first ran into this when trying to determine the relative performance of two generators:</p> <pre><code>t = timeit.repeat('g.get()', setup='g = my_generator()') </code></pre> <p>So I dug into the timeit module and found that the setup and statement are evaluated with their own private, initially empty namespaces...
1
2010-03-28T22:37:21Z
2,534,876
<p>The <code>pickle</code> protocol(s) would have a serious problem picking classes and functions in the most general case; by pickling them "by name" instead, it makes the difficulty go away, but nds up requiring that they be bound to (and recoverable by) names that are top-level in a module (which, since a module is ...
3
2010-03-28T22:43:42Z
[ "python", "namespaces" ]
Deleting dirs after finishing a command prompt
2,534,917
<p>I have a python script that ends with running a program (iexpress.exe) in a dos prompt.<br> The program that runs in dos prompt, uses a dir called workdir. After the program has finished in the dos prompt I would like python to delete the dir. I have just made a simple solution of putting a delay of 30sec:</p> <pr...
0
2010-03-28T22:54:35Z
2,534,926
<p>Make the python program call the exe and not fall off the end</p> <p>ie call the exe using <a href="http://docs.python.org/py3k/library/subprocess.html" rel="nofollow">subprocess.Popen</a></p> <p>The when the exe finishes you are still in python</p>
0
2010-03-28T22:58:35Z
[ "python", "python-3.x", "cmd" ]
Thread Synchronization in Django
2,534,943
<p>Is there any way to block a critical area like with Java synchronized in Django?</p>
4
2010-03-28T23:05:28Z
2,534,966
<p>You can use locks to make sure that only one Thread will access a certain block of code at a time.</p> <p>To do this, you simply create a Lock object then acquire the lock before the block of code you want to synchronize. An example:</p> <pre><code>lock = Lock() lock.acquire() # will block if another thread ha...
5
2010-03-28T23:15:25Z
[ "python", "django", "synchronized" ]
Thread Synchronization in Django
2,534,943
<p>Is there any way to block a critical area like with Java synchronized in Django?</p>
4
2010-03-28T23:05:28Z
24,900,469
<p>Great article Justin, just one thing using python 2.5 makes this way easier</p> <p>In Python 2.5 and later, you can also use the with statement. When used with a lock, this statement automatically acquires the lock before entering the block, and releases it when leaving the block:</p> <p>from <strong>future</stron...
0
2014-07-23T01:29:57Z
[ "python", "django", "synchronized" ]
Rest Web Service with App Engine and Webapp
2,534,947
<p>I want to build a REST web service on app engine. Currently i have this:</p> <pre><code>from google.appengine.ext import webapp from google.appengine.ext.webapp import util class UsersHandler(webapp.RequestHandler): def get(self, name): self.response.out.write('Hello '+ name+'!') def main(): util.run_wsgi...
10
2010-03-28T23:06:30Z
2,534,984
<p>Sure, you can -- change your handler's <code>get</code> method to</p> <pre><code>def get(self, name=None): if name is None: """deal with the /rest/users case""" else: # deal with the /rest/users/(.*) case self.response.out.write('Hello '+ name+'!') </code></pre> <p>and your applica...
14
2010-03-28T23:21:01Z
[ "python", "google-app-engine", "rest", "web-applications" ]
Way to call super(MyClass, self).__init__() without MyClass?
2,535,037
<p>I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some <code>__class__</code> magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this.</p>
4
2010-03-28T23:35:57Z
2,535,050
<p>As far as I know, this isn't possible in 2.5. However, in 3.0, this was changed so that you can simply call <code>super().__init__()</code>.</p>
4
2010-03-28T23:39:16Z
[ "python", "syntax" ]
Way to call super(MyClass, self).__init__() without MyClass?
2,535,037
<p>I find this syntax astoundingly annoying. Every time I rename my class, I have to change this call for no apparent reason. Isn't there some <code>__class__</code> magic variable or something I can use at least? Interested in answers for Python 2.5, but it doesn't hurt to know if later versions fixed this.</p>
4
2010-03-28T23:35:57Z
2,535,053
<p>In Python 3.0, the <a href="http://docs.python.org/py3k/library/functions.html#super" rel="nofollow">super()</a> can be called without arguments to do the same thing.</p>
2
2010-03-28T23:40:16Z
[ "python", "syntax" ]