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 |
|---|---|---|---|---|---|---|---|---|---|
Center Google Map Based on geocoded IP | 1,365,722 | <p>Basically whenever someones opens up my (Google) map I want it default to their approximate location.</p>
<p>Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)?</p>
| 5 | 2009-09-02T03:38:31Z | 1,367,223 | <p>You can use Google API's built-in <a href="http://code.google.com/apis/ajax/documentation/#ClientLocation">ClientLocation</a> object:</p>
<pre><code>if (GBrowserIsCompatible())
{
var map = new google.maps.Map2(document.getElementById("mapdiv"));
if (google.loader.ClientLocation)
{
... | 6 | 2009-09-02T11:46:53Z | [
"javascript",
"python",
"django",
"google-maps"
] |
Center Google Map Based on geocoded IP | 1,365,722 | <p>Basically whenever someones opens up my (Google) map I want it default to their approximate location.</p>
<p>Is there an easy way to do it with Google's API or do I have to write a custom code (this is python based app)?</p>
| 5 | 2009-09-02T03:38:31Z | 6,348,822 | <p>IP Address Geocoding API for Google Maps: <a href="http://web3o.blogspot.com/2011/06/ip-address-geocoding-api-for-google.html" rel="nofollow">http://web3o.blogspot.com/2011/06/ip-address-geocoding-api-for-google.html</a></p>
| 0 | 2011-06-14T19:17:47Z | [
"javascript",
"python",
"django",
"google-maps"
] |
Managing multiple Twisted client connections | 1,365,737 | <p>I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the li... | 6 | 2009-09-02T03:45:01Z | 1,365,747 | <p>Since each of your clients needs to update a database, instinctively I think I'd piggyback off the <code>connection pool</code> -- see <a href="http://www.rexx.com/~dkuhlman/twisted%5Fpatterns.html#connection-pooling" rel="nofollow">here</a> for more (the whole doc is recommended for some important design patterns t... | 3 | 2009-09-02T03:49:39Z | [
"python",
"twisted"
] |
Managing multiple Twisted client connections | 1,365,737 | <p>I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the li... | 6 | 2009-09-02T03:45:01Z | 1,408,498 | <p>The best option is really just to do the obvious thing here. Don't have a loop, or a repeating timed call; just have handlers that do the right thing.</p>
<p>Keep a central connection-management object around, and make event-handling methods feed it the information it needs to keep going. When it starts, make 5 o... | 4 | 2009-09-11T00:52:04Z | [
"python",
"twisted"
] |
Managing multiple Twisted client connections | 1,365,737 | <p>I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the li... | 6 | 2009-09-02T03:45:01Z | 5,399,173 | <p>I don't know if you are forced to use Twisted, otherwise you might want to give <a href="http://www.gevent.org/" rel="nofollow">Gevent</a> a try.</p>
| -1 | 2011-03-22T23:34:54Z | [
"python",
"twisted"
] |
Python long filename support broken in Windows | 1,365,797 | <p>I write Python script to copy files; unfortunately it keeps failing because filename is too long(>256). Is there anyway to deal with that problem?</p>
<p>I'm using Python 2.5.4 and Windows XP.</p>
<p>Cheers,</p>
| 3 | 2009-09-02T04:15:52Z | 1,365,807 | <p>Use <a href="http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maximum%5Fpath%5Flength">paths beginning with the string <code>\\?\</code></a>.</p>
| 6 | 2009-09-02T04:19:51Z | [
"python"
] |
Python long filename support broken in Windows | 1,365,797 | <p>I write Python script to copy files; unfortunately it keeps failing because filename is too long(>256). Is there anyway to deal with that problem?</p>
<p>I'm using Python 2.5.4 and Windows XP.</p>
<p>Cheers,</p>
| 3 | 2009-09-02T04:15:52Z | 1,365,823 | <p>Have you tried the workarounds suggested in <a href="http://mail.python.org/pipermail/python-bugs-list/2007-March/037810.html" rel="nofollow">this</a> old thread, exp. the "magic prefix" trick? I don't know if the underyling issue (that we're not using the right one out of the many available Windows APIs for files)... | 1 | 2009-09-02T04:23:01Z | [
"python"
] |
Python long filename support broken in Windows | 1,365,797 | <p>I write Python script to copy files; unfortunately it keeps failing because filename is too long(>256). Is there anyway to deal with that problem?</p>
<p>I'm using Python 2.5.4 and Windows XP.</p>
<p>Cheers,</p>
| 3 | 2009-09-02T04:15:52Z | 1,365,827 | <p>In order to use the <code>\\?\</code> prefix (as already proposed), you also need to make sure you use Unicode strings as filenames, not regular (byte) strings.</p>
| 5 | 2009-09-02T04:25:06Z | [
"python"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,838 | <p>First off, if you want to do web with Python, the <a href="http://www.djangoproject.com/" rel="nofollow">Django</a> framework seems like the best choice.</p>
<p>From some quick Googling, the best IDE for Django would be <a href="http://kubasik.net/blog/2009/03/12/finally-a-django-ide-with-real-code-completion-and-t... | 1 | 2009-09-02T04:30:22Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,847 | <p>See <a href="http://stackoverflow.com/questions/81584/what-ide-to-use-for-python">this</a> question about Python IDEs.</p>
<p>I use Eclipse + PyDev.</p>
| 2 | 2009-09-02T04:34:41Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,849 | <p>I really like gedit and a terminal. You'll more than likely need to make a few <a href="http://grigio.org/textmate%5Fgedit%5Ffew%5Fsteps" rel="nofollow">tweaks</a> and maybe install a plugin or two. gedit also has a Python console window plugin if you like that kind of integration. (Edit -> Preferences -> Plugins, t... | 0 | 2009-09-02T04:35:50Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,852 | <p>If you are willing to pay Wing IDE (<a href="http://www.wingware.com/" rel="nofollow">http://www.wingware.com/</a>) is the best (IMO)
They have trial versions and a basic version free (<a href="https://wingware.com/wing101" rel="nofollow">https://wingware.com/wing101</a>)</p>
| 0 | 2009-09-02T04:36:30Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,860 | <p>Consider <a href="http://www.wingware.com/doc/howtos/django" rel="nofollow">Wing IDE</a> -- IMHO the best commercial IDE for Python, it does support Django if that's what you want (as, apparently, do 80% of Python-based websites; personally, I prefer <a href="http://werkzeug.pocoo.org/" rel="nofollow">werkzeug</a> a... | 3 | 2009-09-02T04:41:42Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 1,365,891 | <p><strong><a href="http://monodevelop.com/" rel="nofollow">Mono Develop</a></strong></p>
<p>If you've been using visual studio, then I'd guess that mono develop would be the closest thing. As far as I know, its the best attempt around to be a linux version of visual studio. A quick Google search gives several resul... | 0 | 2009-09-02T04:56:09Z | [
"python",
"ide",
"editor"
] |
.NET developer moving to ubuntu for development | 1,365,830 | <p>I've been developing in .NET now for about 3 years. I love the visual studio IDE and sadly I won't be able to use it anymore.</p>
<p>Could someone save me hours of searching the web and reading reviews, and suggest the 'standard' or most popular IDE/Text editor for linux that will get me up and running quickly?</p>... | 3 | 2009-09-02T04:26:23Z | 29,961,165 | <p>You can still develop .NET on linux.<br>
Microsoft's <a href="https://code.visualstudio.com" rel="nofollow">Visual Studio Code</a> is an Integrated Development Environment (IDE) with support for Mac, Linux and Windows.</p>
| 1 | 2015-04-30T07:06:26Z | [
"python",
"ide",
"editor"
] |
Diff django model objects with ManyToMany fields | 1,365,963 | <p>I have a situation where I need to notify some users when something in DB changes. My idea is to catch <code>pre_save</code> and <code>post_save</code> signal and make some kind of diff and mail that. Generally it works good, but I don't know how to get diff for m2m fields. </p>
<p>At the moment I have something li... | 1 | 2009-09-02T05:26:41Z | 1,367,520 | <p>First of all, you don't need to use deepcopy for this. Re-querying the sender from the database returns a "fresh" object.</p>
<pre><code>def pre_save(sender, **kwargs):
pk = kwargs['instance'].pk
instance = sender.objects.get(pk=pk)
tracking[sender] = instance
</code></pre>
<p>You can get a list of all... | 6 | 2009-09-02T12:51:15Z | [
"python",
"django",
"diff",
"models"
] |
random.choice not random | 1,366,047 | <p>I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use</p>
<pre><code> chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
</code></pre>
<p>to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the se... | 13 | 2009-09-02T06:06:22Z | 1,366,192 | <p>To avoid the problem, you can use a sequence of cookies, that are guaranteed to be different (you can e.g. use a set). Each time you give a cookie to someone, you take it from the sequence and you add another to it. Another option is to generate a UUID and use that as a cookie.</p>
<p>Another way to avoid the probl... | -4 | 2009-09-02T06:59:59Z | [
"python",
"random"
] |
random.choice not random | 1,366,047 | <p>I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use</p>
<pre><code> chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
</code></pre>
<p>to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the se... | 13 | 2009-09-02T06:06:22Z | 1,366,234 | <p>It shouldn't be generating duplicates.</p>
<pre><code>import random
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def gen():
return ''.join([random.choice(chars) for x in range(32)])
test = [gen() for i in range(100000)]
print len(test), len(set(test)) # 100000 100000
</code></pre>
... | 12 | 2009-09-02T07:11:52Z | [
"python",
"random"
] |
random.choice not random | 1,366,047 | <p>I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use</p>
<pre><code> chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
</code></pre>
<p>to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the se... | 13 | 2009-09-02T06:06:22Z | 1,366,249 | <p>This is definitely not a normal collision scenario:</p>
<ul>
<li>32 characters with 62 options per character is equivalent to 190 bits (log2(62) * 32)</li>
<li>According to the birthday paradox, you should be receiving a collision naturally once every 2**95 cookies, which means never</li>
</ul>
<p>Could this be a... | 3 | 2009-09-02T07:17:25Z | [
"python",
"random"
] |
random.choice not random | 1,366,047 | <p>I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use</p>
<pre><code> chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
</code></pre>
<p>to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the se... | 13 | 2009-09-02T06:06:22Z | 1,366,286 | <p>I had to erase my original answer, which suggested that generator is not seeded from <code>/dev/urandom</code>, since its <a href="http://svn.python.org/projects/python/branches/py3k/Lib/random.py" rel="nofollow">source</a> (for Python 3.x) clearly says that it is:</p>
<pre><code>def seed(self, a=None):
"""Init... | 0 | 2009-09-02T07:30:57Z | [
"python",
"random"
] |
random.choice not random | 1,366,047 | <p>I'm using Python 2.5 on Linux, in multiple parallel FCGI processes. I use</p>
<pre><code> chars = string.ascii_letters + string.digits
cookie = ''.join([random.choice(chars) for x in range(32)])
</code></pre>
<p>to generate distinct cookies. Assuming that the RNG is seeded from /dev/urandom, and that the se... | 13 | 2009-09-02T06:06:22Z | 1,370,961 | <ol>
<li><p>I don't know how your FCGI processes are being spawned, but is it possible that it's using fork() after the Python interpreter has started (and the random module has been imported by something), hence effectively seeding two processes' <code>random._inst</code>s from the same source?</p></li>
<li><p>Maybe p... | 1 | 2009-09-03T01:05:05Z | [
"python",
"random"
] |
Django session expiry? | 1,366,146 | <p>From django's documentation, I became under the impression that calling:</p>
<pre><code>request.session.set_expiry(300)
</code></pre>
<p>from one view would cause the session to expire after five minutes <em>inactivity</em>; however, this is not the behavior that I'm experiencing in django trunk. If I call this me... | 11 | 2009-09-02T06:42:14Z | 1,371,117 | <p>As the author of those methods, I can see that the documentation isn't very clear regarding this. Your observations are correct: only requests which cause the session to be altered is considered "activity".</p>
<p>You can use the <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/#session-save-every... | 25 | 2009-09-03T02:16:31Z | [
"python",
"django"
] |
Django session expiry? | 1,366,146 | <p>From django's documentation, I became under the impression that calling:</p>
<pre><code>request.session.set_expiry(300)
</code></pre>
<p>from one view would cause the session to expire after five minutes <em>inactivity</em>; however, this is not the behavior that I'm experiencing in django trunk. If I call this me... | 11 | 2009-09-02T06:42:14Z | 13,105,909 | <p>A simple middleware would probably do better than setting this up in every view. This is what I used.</p>
<pre><code>class SessionExpiry(object):
""" Set the session expiry according to settings """
def process_request(self, request):
if getattr(settings, 'SESSION_EXPIRY', None):
reques... | 3 | 2012-10-28T02:32:23Z | [
"python",
"django"
] |
What would cause a zip file to not be recognized on Google App Engine's when it reads properly in my local GAE sdk | 1,366,274 | <p>My code executes successfully when I run it locally, but when I upload it to GAE and attempt to run it throws me a BadZipfile: File is not a zip file, or ends with a comment</p>
<pre><code>raw_file = urllib2.urlopen(url)
buffer = cStringIO.StringIO(raw_file.read())
z = zipfile.ZipFile(buffer)
</code></pre>
<p>zipp... | 3 | 2009-09-02T07:25:49Z | 1,366,670 | <p>The maximum size you can fetch using urlfetch (App Engine's API for making HTTP requests to other sites) is 1MB, so your file is getting truncated. The dev_appserver doesn't enforce the 1MB limit.</p>
| 2 | 2009-09-02T09:27:46Z | [
"python",
"google-app-engine",
"zipfile"
] |
Anyone get python26 install in Snow Leopard via Macports? | 1,366,542 | <p>I got build error after run in Snow Leopard (MacPort v.1.8.0)</p>
<pre><code>sudo port install python26
</code></pre>
<p>any workaround please?</p>
<pre><code>Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_por... | 3 | 2009-09-02T08:54:48Z | 1,366,613 | <p>There are apparently problems with Python via Macports on Snow Leopard, see <a href="http://www.reddit.com/r/Python/comments/9fm2w/snow%5Fleopard%5Fmacports%5Fwarning%5Fpython%5Fports%5Fbroken/" rel="nofollow">this thread</a>. From there, <a href="http://www.reddit.com/r/Python/comments/9fm2w/snow%5Fleopard%5Fmacpor... | 4 | 2009-09-02T09:13:22Z | [
"python",
"osx-snow-leopard",
"macports"
] |
How to convert tab separated, pipe separated to CSV file format in Python | 1,366,775 | <p>I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.</p>
<p>Thanks in advanc... | 4 | 2009-09-02T09:52:09Z | 1,366,827 | <p>Like this</p>
<pre><code>from __future__ import with_statement
import csv
import re
with open( input, "r" ) as source:
with open( output, "wb" ) as destination:
writer= csv.writer( destination )
for line in input:
writer.writerow( re.split( '[\t|]', line ) )
</code></pre>
| 0 | 2009-09-02T10:06:57Z | [
"python",
"csv"
] |
How to convert tab separated, pipe separated to CSV file format in Python | 1,366,775 | <p>I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.</p>
<p>Thanks in advanc... | 4 | 2009-09-02T09:52:09Z | 1,366,845 | <pre><code>for line in open("file"):
line=line.strip()
if "|" in line:
print ','.join(line.split("|"))
else:
print ','.join(line.split("\t"))
</code></pre>
| 0 | 2009-09-02T10:11:36Z | [
"python",
"csv"
] |
How to convert tab separated, pipe separated to CSV file format in Python | 1,366,775 | <p>I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.</p>
<p>Thanks in advanc... | 4 | 2009-09-02T09:52:09Z | 1,366,894 | <p>I fear that you can't identify the delimiter without knowing what it is. The problem with CSV is, that, <a href="http://catb.org/esr/writings/taoup/html/ch05s02.html#id2901882" rel="nofollow">quoting ESR</a>:</p>
<blockquote>
<p>the Microsoft version of CSV is a textbook example of how not to design a textual fil... | 6 | 2009-09-02T10:24:32Z | [
"python",
"csv"
] |
How to convert tab separated, pipe separated to CSV file format in Python | 1,366,775 | <p>I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.</p>
<p>Thanks in advanc... | 4 | 2009-09-02T09:52:09Z | 1,366,956 | <p>I would suggest taking some of the example code from the existing answers, or perhaps better use the <code>csv</code> module from python and change it to first assume tab separated, then pipe separated, and produce two output files which are comma separated. Then you visually examine both files to determine which o... | 0 | 2009-09-02T10:41:29Z | [
"python",
"csv"
] |
How to convert tab separated, pipe separated to CSV file format in Python | 1,366,775 | <p>I have a text file (.txt) which could be in tab separated format or pipe separated format, and I need to convert it into CSV file format. I am using python 2.6. Can any one suggest me how to identify the delimiter in a text file, read the data and then convert that into comma separated file.</p>
<p>Thanks in advanc... | 4 | 2009-09-02T09:52:09Z | 1,373,954 | <p>Your strategy could be the following:</p>
<ul>
<li>parse the file with BOTH a tab-separated csv reader and a pipe-separated csv reader</li>
<li>calculate some statistics on resulting rows to decide which resultset is the one you want to write. An idea could be counting the total number of fields in the two recordse... | 1 | 2009-09-03T14:59:56Z | [
"python",
"csv"
] |
Django: retrieve all galleries containing one public photo at least | 1,366,943 | <p>excuse me for my ugly english) !</p>
<p>Imagine these very simple models :</p>
<pre><code>class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True)
</code></pre... | 1 | 2009-09-02T10:38:01Z | 1,367,441 | <p>This should do it:</p>
<p><strong>Edit, updated to add count:</strong></p>
<pre><code>SELECT `gallery`.*, 'a'.'count'
FROM `gallery`
inner join (
select `gallery`.`id`, count(*) as count
from `gallery_photos`
INNER JOIN `photo` ON (`gallery_photos`.`photo_id` = `photo`.`id`)
where `photo`.`is_p... | 0 | 2009-09-02T12:36:41Z | [
"python",
"sql",
"django",
"django-models",
"count"
] |
Django: retrieve all galleries containing one public photo at least | 1,366,943 | <p>excuse me for my ugly english) !</p>
<p>Imagine these very simple models :</p>
<pre><code>class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True)
</code></pre... | 1 | 2009-09-02T10:38:01Z | 1,367,445 | <p>I would try:</p>
<pre><code>Gallery.objects.filter(photos__is_public=True).annotate(Count('photos'))
</code></pre>
<p>I believe you just got your filter ordering wrong but I have not set up your models to test that assumption.</p>
<p>Try number two:</p>
<pre><code>Gallery.objects.exclude(photos__is_public=False)... | 0 | 2009-09-02T12:36:56Z | [
"python",
"sql",
"django",
"django-models",
"count"
] |
Django: retrieve all galleries containing one public photo at least | 1,366,943 | <p>excuse me for my ugly english) !</p>
<p>Imagine these very simple models :</p>
<pre><code>class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True)
</code></pre... | 1 | 2009-09-02T10:38:01Z | 1,369,274 | <p>This?</p>
<pre>
Gallery.objects.filter(photos__is_public=True)\
.annotate(Count('photos__is_public'))
</pre>
| 0 | 2009-09-02T18:09:02Z | [
"python",
"sql",
"django",
"django-models",
"count"
] |
Django: retrieve all galleries containing one public photo at least | 1,366,943 | <p>excuse me for my ugly english) !</p>
<p>Imagine these very simple models :</p>
<pre><code>class Photo(models.Model):
is_public = models.BooleanField('Public', default=False)
class Gallery(models.Model):
photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True)
</code></pre... | 1 | 2009-09-02T10:38:01Z | 1,371,865 | <p>The django documentation is at </p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#order-of-annotate-and-filter-clauses" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/db/aggregation/#order-of-annotate-and-filter-clauses</a></p>
<p>and my experience says that the following quer... | 0 | 2009-09-03T07:18:39Z | [
"python",
"sql",
"django",
"django-models",
"count"
] |
Python (Imaging library): Resample string as argument | 1,367,029 | <p>Python beginner question. Code below should explain my problem:</p>
<pre><code>import Image
resolution = (200,500)
scaler = "Image.ANTIALIAS"
im = Image.open("/home/user/Photos/DSC00320.JPG")
im.resize(resolution , scaler)
</code></pre>
<p>RESULT:</p>
<pre><code>Traceback (most recent call last):
File "<s... | 2 | 2009-09-02T11:03:37Z | 1,367,056 | <p>As you said, <code>im.resize(resolution , Image.ANTIALIAS)</code> is the solution</p>
<p>You have to take care than this is different than <code>im.resize(resolution , "Image.ANTIALIAS")</code>.</p>
<p>In your example, the variable <code>scaler</code> has the string <code>"Image.ANTIALIAS"</code> as a value, that ... | 2 | 2009-09-02T11:10:16Z | [
"python",
"python-imaging-library"
] |
Python (Imaging library): Resample string as argument | 1,367,029 | <p>Python beginner question. Code below should explain my problem:</p>
<pre><code>import Image
resolution = (200,500)
scaler = "Image.ANTIALIAS"
im = Image.open("/home/user/Photos/DSC00320.JPG")
im.resize(resolution , scaler)
</code></pre>
<p>RESULT:</p>
<pre><code>Traceback (most recent call last):
File "<s... | 2 | 2009-09-02T11:03:37Z | 1,367,066 | <p>Well, then Image.ANTIALIAS is not a string, so don't treat it as one:</p>
<pre><code>scaler = Image.ANTIALIAS
</code></pre>
| 7 | 2009-09-02T11:13:50Z | [
"python",
"python-imaging-library"
] |
Python (Imaging library): Resample string as argument | 1,367,029 | <p>Python beginner question. Code below should explain my problem:</p>
<pre><code>import Image
resolution = (200,500)
scaler = "Image.ANTIALIAS"
im = Image.open("/home/user/Photos/DSC00320.JPG")
im.resize(resolution , scaler)
</code></pre>
<p>RESULT:</p>
<pre><code>Traceback (most recent call last):
File "<s... | 2 | 2009-09-02T11:03:37Z | 1,367,072 | <p>As @ThibThib said using "Image.ANTIALIAS" is not the same thing as Image.ANTIALIAS.
But if you always expect to get the resample value as a string you could do the following:</p>
<pre><code>scaler = 'ANTIALIAS'
resample = {
'ANTIALIAS': Image.ANTIALIAS,
'BILINEAR': Image.BILINEAR,
'BICUBIC': Image.BICUB... | 3 | 2009-09-02T11:14:34Z | [
"python",
"python-imaging-library"
] |
How to download a webpage in every five minutes? | 1,367,189 | <p>I want to download a list of web pages. I know wget can do this. However downloading every URL in every five minutes and save them to a folder seems beyond the capability of wget.
Does anyone knows some tools either in java or python or Perl which accomplishes the task?</p>
<p>Thanks in advance.</p>
| 1 | 2009-09-02T11:39:32Z | 1,367,209 | <p>Write a bash script that uses wget and put it in your crontab to run every 5 minutes. (*/5 * * * *)</p>
<p>If you need to keep a history of all these web pages, set a variable at the beginning of your script with the current unixtime and append it to the output filenames.</p>
| 5 | 2009-09-02T11:44:31Z | [
"python",
"download",
"webpage",
"wget",
"web-crawler"
] |
How to download a webpage in every five minutes? | 1,367,189 | <p>I want to download a list of web pages. I know wget can do this. However downloading every URL in every five minutes and save them to a folder seems beyond the capability of wget.
Does anyone knows some tools either in java or python or Perl which accomplishes the task?</p>
<p>Thanks in advance.</p>
| 1 | 2009-09-02T11:39:32Z | 1,367,219 | <p>Sounds like you'd want to <a href="http://www.scrounge.org/linux/cron.html" rel="nofollow">use cron with wget</a>
<hr/>
But if you're set on using python:</p>
<pre><code>import time
import os
wget_command_string = "wget ..."
while true:
os.system(wget_command_string)
time.sleep(5*60)
</code></pre>
| 7 | 2009-09-02T11:45:52Z | [
"python",
"download",
"webpage",
"wget",
"web-crawler"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 1,371,363 | <p>swap may not be the red herring previously suggested. How big is the python process in question just before the <code>ENOMEM</code>?</p>
<p>Under kernel 2.6, <code>/proc/sys/vm/swappiness</code> controls how aggressively the kernel will turn to swap, and <code>overcommit*</code> files how much and how precisely th... | 8 | 2009-09-03T03:55:58Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 1,376,124 | <blockquote>
<p>munmap(0xb7d28000, 4096) = 0<br />
write(2, "OSError", 7) = 7 </p>
</blockquote>
<p>I've seen sloppy code that looks like this:</p>
<pre><code>serrno = errno;
some_Syscall(...)
if (serrno != errno)
/* sound alarm: CATROSTOPHIC ERROR !!! */
</code></pre>
<p>You sho... | 0 | 2009-09-03T21:43:09Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 1,377,174 | <p>I continue to suspect that your customer/user has some kernel module or driver loaded which
is interfering with the <code>clone()</code> system call (perhaps some obscure security enhancement,
something like LIDS but more obscure?) or is somehow filling up some of the kernel data
structures that are necessary for <c... | 5 | 2009-09-04T04:02:46Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 7,263,866 | <p>Have you tried using:</p>
<pre><code>(status,output) = commands.getstatusoutput("ps aux")
</code></pre>
<p>I thought this had fixed the exact same problem for me.
But then my process ended up getting killed instead of failing to spawn, which is even worse..</p>
<p>After some testing I found that this only occurre... | 2 | 2011-08-31T21:47:43Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 13,329,386 | <p>As a general rule (i.e. in vanilla kernels), <code>fork</code>/<code>clone</code> failures with <code>ENOMEM</code> <a href="https://github.com/torvalds/linux/blob/master/kernel/fork.c"><strong>occur specifically</strong></a> because of either <strong>an honest to God out-of-memory condition</strong> (<code>dup_mm</... | 50 | 2012-11-11T07:30:08Z | [
"python",
"linux",
"memory"
] |
Python subprocess.Popen "OSError: [Errno 12] Cannot allocate memory" | 1,367,373 | <p><strong>Note:</strong> This question was originally asked <a href="http://stackoverflow.com/questions/1216794/python-subprocess-popen-erroring-with-oserror-errno-12-cannot-allocate-memory">here</a> but the bounty time expired even though an acceptable answer was not actually found. I am re-asking this question inclu... | 62 | 2009-09-02T12:23:43Z | 26,416,752 | <p>Looking at the output of <code>free -m</code> it seems to me that you actually do not have swap memory available. I am not sure if in Linux the swap always will be available automatically on demand, but I was having the same problem and none of the answers here really helped me. Adding some swap memory however, fixe... | 5 | 2014-10-17T01:58:12Z | [
"python",
"linux",
"memory"
] |
Reading a website with asyncore | 1,367,453 | <p>I would like to read a website asynchronously, which isnt possible with urllib as far as I know. Now I tried reading with with plain sockets, but HTTP is giving me hell.
I run into all kind of funky encodings, for example transfer-encoding: chunked, have to parse all that stuff manually, and I feel like coding C, no... | 7 | 2009-09-02T12:39:25Z | 1,367,499 | <p>You can implement an asynchronous call yourself. For each call, start a new thread (or try to get one from a pool) and use a callback to process it.</p>
<p>You can do this very nicely with a decorator:</p>
<pre><code>def threaded(callback=lambda *args, **kwargs: None, daemonic=False):
"""Decorate a function t... | 7 | 2009-09-02T12:47:16Z | [
"python",
"web-services",
"sockets"
] |
Reading a website with asyncore | 1,367,453 | <p>I would like to read a website asynchronously, which isnt possible with urllib as far as I know. Now I tried reading with with plain sockets, but HTTP is giving me hell.
I run into all kind of funky encodings, for example transfer-encoding: chunked, have to parse all that stuff manually, and I feel like coding C, no... | 7 | 2009-09-02T12:39:25Z | 1,367,941 | <p>Have you looked at <a href="http://asynchttp.sourceforge.net/">http://asynchttp.sourceforge.net/</a>? </p>
<p>"Asynchronous HTTP Client for Python</p>
<p>The 'asynchttp'' module is a logical extension of the Python library 'asynchat' module which is built on the 'asyncore' and 'select' modules. Our goal is to prov... | 5 | 2009-09-02T14:09:07Z | [
"python",
"web-services",
"sockets"
] |
Reading a website with asyncore | 1,367,453 | <p>I would like to read a website asynchronously, which isnt possible with urllib as far as I know. Now I tried reading with with plain sockets, but HTTP is giving me hell.
I run into all kind of funky encodings, for example transfer-encoding: chunked, have to parse all that stuff manually, and I feel like coding C, no... | 7 | 2009-09-02T12:39:25Z | 1,372,289 | <p>The furthest I came was using modified asynchttp, that codeape suggested. I have tried to use both asyncore/asynchat and asynchttp, with lots of pain. It took me far too long to try to fix all the bugs in it (there's a method handle_read, nearly copied from asyncore, only badly indented and was giving me headaches w... | 1 | 2009-09-03T09:03:20Z | [
"python",
"web-services",
"sockets"
] |
Reading a website with asyncore | 1,367,453 | <p>I would like to read a website asynchronously, which isnt possible with urllib as far as I know. Now I tried reading with with plain sockets, but HTTP is giving me hell.
I run into all kind of funky encodings, for example transfer-encoding: chunked, have to parse all that stuff manually, and I feel like coding C, no... | 7 | 2009-09-02T12:39:25Z | 5,132,953 | <p>Asyncore simple HTTP client example is pretty straightforward :) </p>
<p><a href="http://docs.python.org/library/asyncore.html" rel="nofollow">http://docs.python.org/library/asyncore.html</a></p>
<pre><code>import asyncore, socket
class HTTPClient(asyncore.dispatcher):
def __init__(self, host, path):
... | 1 | 2011-02-27T11:31:30Z | [
"python",
"web-services",
"sockets"
] |
How to decorate a method inside a class? | 1,367,514 | <p>Am attempting to decorate a method inside a class but python is throwing an error on me.
My class looks like this:</p>
<pre><code>from pageutils import formatHeader
myPage(object):
def __init__(self):
self.PageName = ''
def createPage(self):
pageHeader = self.createHeader()
@formatHeader #... | 35 | 2009-09-02T12:50:19Z | 1,367,530 | <p>Python automatically passes the class instance as reference. (The <code>self</code> argument which is seen in all class methods).</p>
<p>You could do:</p>
<pre><code>def formatHeader(fn):
def wrapped(self=None):
return '<div class="page_header">'+fn(self)+'</div>'
return wrapped
</code>... | 27 | 2009-09-02T12:52:30Z | [
"python",
"decorator"
] |
How to decorate a method inside a class? | 1,367,514 | <p>Am attempting to decorate a method inside a class but python is throwing an error on me.
My class looks like this:</p>
<pre><code>from pageutils import formatHeader
myPage(object):
def __init__(self):
self.PageName = ''
def createPage(self):
pageHeader = self.createHeader()
@formatHeader #... | 35 | 2009-09-02T12:50:19Z | 1,367,567 | <p>You are omitting the self parameter which is present in the undecorated function (createHeader in your case).</p>
<pre><code>def formatHeader(fn):
from functools import wraps
@wraps(fn)
def wrapper(self):
return '<div class="page_header">'+fn(self)+'</div>'
return wrapper
</code>... | 42 | 2009-09-02T13:01:30Z | [
"python",
"decorator"
] |
How to count possibilities in python lists | 1,367,550 | <p>Given a list like this:</p>
<pre><code>num = [1, 2, 3, 4, 5]
</code></pre>
<p>There are 10 three-element combinations:</p>
<pre><code>[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
</code></pre>
<p>How can I generate this list?</p>
| 3 | 2009-09-02T12:57:47Z | 1,367,582 | <p>Use <a href="http://docs.python.org/library/itertools.html#itertools.combinations" rel="nofollow">itertools.combinations</a>:</p>
<pre><code>import itertools
num = [1, 2, 3, 4, 5]
combinations = []
for combination in itertools.combinations(num, 3):
combinations.append(int("".join(str(i) for i in combination)))... | 10 | 2009-09-02T13:04:29Z | [
"python"
] |
How to count possibilities in python lists | 1,367,550 | <p>Given a list like this:</p>
<pre><code>num = [1, 2, 3, 4, 5]
</code></pre>
<p>There are 10 three-element combinations:</p>
<pre><code>[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
</code></pre>
<p>How can I generate this list?</p>
| 3 | 2009-09-02T12:57:47Z | 1,367,592 | <p>I believe you are looking for the <a href="http://en.wikipedia.org/wiki/Binomial%5Fcoefficient" rel="nofollow">binomial coefficient</a>:</p>
| 2 | 2009-09-02T13:06:09Z | [
"python"
] |
How to count possibilities in python lists | 1,367,550 | <p>Given a list like this:</p>
<pre><code>num = [1, 2, 3, 4, 5]
</code></pre>
<p>There are 10 three-element combinations:</p>
<pre><code>[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
</code></pre>
<p>How can I generate this list?</p>
| 3 | 2009-09-02T12:57:47Z | 1,367,598 | <p>You are talking about <a href="http://en.wikipedia.org/wiki/Combination" rel="nofollow">combinations</a>. There are <em>n!/(k! * (n - k)!)</em> ways to take <em>k</em> elements from a list of <em>n</em> elements. So:</p>
<pre><code>>>> num = [1, 2, 3, 4, 5]
>>> fac = lambda n: 1 if n < 2 else n... | 5 | 2009-09-02T13:07:27Z | [
"python"
] |
How to count possibilities in python lists | 1,367,550 | <p>Given a list like this:</p>
<pre><code>num = [1, 2, 3, 4, 5]
</code></pre>
<p>There are 10 three-element combinations:</p>
<pre><code>[123, 124, 125, 134, 135, 145, 234, 235, 245, 345]
</code></pre>
<p>How can I generate this list?</p>
| 3 | 2009-09-02T12:57:47Z | 1,367,601 | <p><a href="http://docs.python.org/library/itertools.html#itertools.combinations" rel="nofollow"><code>itertools.combinations()</code></a>:</p>
<blockquote>
<p>Return r length subsequences of elements from the input iterable.</p>
<p>Combinations are emitted in lexicographic sort order. So, if the input iterable... | 2 | 2009-09-02T13:08:05Z | [
"python"
] |
How to create objects dynamically in an elegant way in python? | 1,367,819 | <p>I have two classes that I would like to merge into a composite. These two classes will continue to be used standalone and I don't want to modify them.
For some reasons, I want to let my composite class creating the objects. I am thinking about something like the code below (it is just an example) but I think it is ... | 4 | 2009-09-02T13:50:01Z | 1,368,196 | <p>You could shorten it by removing type-checking <code>_make_object</code>, and letting class constructors take care of the default arguments, e.g.</p>
<pre><code>class Composite(Parent):
def __init__(self, x, list_of_classes, list_of_args):
Parent.__init__(self, x)
self._objs = [
the_... | 3 | 2009-09-02T14:52:47Z | [
"python"
] |
Python methods: default parameter values are evaluated ONCE | 1,367,883 | <p>I've found a strange issue with subclassing and dictionary updates in New-Style Classes:</p>
<pre><code>Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
>>> class a(object):
... def __init__(self, props={}):
... self.props = props
...
>>> class ... | 3 | 2009-09-02T14:00:28Z | 1,367,927 | <p>Your problem is in this line:</p>
<pre><code>def __init__(self, props={}):
</code></pre>
<p>{} is an mutable type. And in python default argument values are only evaluated once. That means all your instances are sharing the same dictionary object!</p>
<p>To fix this change it to:</p>
<pre><code>class a(object):
... | 5 | 2009-09-02T14:06:30Z | [
"python",
"dictionary",
"super"
] |
Python methods: default parameter values are evaluated ONCE | 1,367,883 | <p>I've found a strange issue with subclassing and dictionary updates in New-Style Classes:</p>
<pre><code>Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
>>> class a(object):
... def __init__(self, props={}):
... self.props = props
...
>>> class ... | 3 | 2009-09-02T14:00:28Z | 1,367,928 | <p><code>props</code> should not have a default value like that. Do this instead:</p>
<pre><code>class a(object):
def __init__(self, props=None):
if props is None:
props = {}
self.props = props
</code></pre>
<p>This is a common python <a href="http://www.ferg.org/projects/python%5Fgotc... | 7 | 2009-09-02T14:06:48Z | [
"python",
"dictionary",
"super"
] |
Python methods: default parameter values are evaluated ONCE | 1,367,883 | <p>I've found a strange issue with subclassing and dictionary updates in New-Style Classes:</p>
<pre><code>Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
>>> class a(object):
... def __init__(self, props={}):
... self.props = props
...
>>> class ... | 3 | 2009-09-02T14:00:28Z | 1,367,938 | <p>The short version: Do this:</p>
<pre><code>class a(object):
def __init__(self, props=None):
self.props = props if props is not None else {}
class b(a):
def __init__(self, val = None):
super(b, self).__init__()
self.props.update({'arg': val})
class c(b):
def __init__(self, val):... | 1 | 2009-09-02T14:08:43Z | [
"python",
"dictionary",
"super"
] |
simplifying data structures and condition statements in python code | 1,367,913 | <p>I was wondering if there are any ways to simplify the following piece of Code. As you can see, there are numerous dicts being used as well as condition statements to weed out bad input data. Note that the trip rate values are not all inputed yet, the dicts are just copied and pasted for now</p>
<p><strong>EDIT</str... | 2 | 2009-09-02T14:05:33Z | 1,368,036 | <p>Well, where to start? Here is just a first observation:</p>
<p>You have a lot of data there, and it seems code and data are mixed into each other.</p>
<p>Data and Code should be separate. Data is an external source, something you modify or read in. You could probably adapt your code to quickly parse Data from a go... | 5 | 2009-09-02T14:26:25Z | [
"python",
"data-structures",
"conditional"
] |
simplifying data structures and condition statements in python code | 1,367,913 | <p>I was wondering if there are any ways to simplify the following piece of Code. As you can see, there are numerous dicts being used as well as condition statements to weed out bad input data. Note that the trip rate values are not all inputed yet, the dicts are just copied and pasted for now</p>
<p><strong>EDIT</str... | 2 | 2009-09-02T14:05:33Z | 1,368,110 | <p>As well with kaizer's suggestion about data and code, here are some simple cleanups:</p>
<p>The code</p>
<pre><code>if y >= 5:
y_1 = 5
y_2 = 5
else:
y_1 = int( math.floor( y ) )
y_2 = int( math.ceil( y ) )
</code></pre>
<p>can be written as</p>
<pre><code>min(5, int(math.floor(y))
... | 2 | 2009-09-02T14:41:05Z | [
"python",
"data-structures",
"conditional"
] |
Java equivalent of a Python functionality -> set(string) | 1,368,181 | <p>I want to mimic a Python functionality in Java.
In Python if I want unique characters in a string I can do just,</p>
<pre><code>text = "i am a string"
print set(text) # o/p is set(['a', ' ', 'g', 'i', 'm', 'n', 's', 'r', 't'])
</code></pre>
<p>How can I do this in Java trivially or directly? </p>
| 2 | 2009-09-02T14:51:34Z | 1,368,214 | <pre><code>String str = "i am a string";
System.out.println(new HashSet<String>(Arrays.asList(str.split(""))));
</code></pre>
<p>EDIT: For those who object that they aren't exactly equivalent because str.split will include an empty string in the set, we can do it even more verbose:</p>
<pre><code>String str = "... | 7 | 2009-09-02T14:54:58Z | [
"java",
"python",
"set"
] |
How do I unit test Django Views? | 1,368,255 | <p>I want to begin integrating unit tests into my Django projects and I've discovered unit testing a view to be tricky because of the way Django implements views with functions. </p>
<p>For example, each function is a view/page in Django if the function has a URL.</p>
<p>How do I unit test Django views?</p>
| 8 | 2009-09-02T15:02:23Z | 1,368,389 | <p>I'm not sure how testing a view is tricky.</p>
<p>You just use the <a href="https://docs.djangoproject.com/en/dev/topics/testing/tools/#the-test-client" rel="nofollow">test client</a>.</p>
<p>Code coverage is easy. You reason how how a URL request maps to a code path and make the appropriate URL requests.</p>
<p... | 9 | 2009-09-02T15:26:45Z | [
"python",
"django",
"unit-testing",
"views"
] |
How do I unit test Django Views? | 1,368,255 | <p>I want to begin integrating unit tests into my Django projects and I've discovered unit testing a view to be tricky because of the way Django implements views with functions. </p>
<p>For example, each function is a view/page in Django if the function has a URL.</p>
<p>How do I unit test Django views?</p>
| 8 | 2009-09-02T15:02:23Z | 1,368,848 | <p>django.test.client should have everything you need for basic unit testing of the view. I also really like <a href="http://twill.idyll.org/" rel="nofollow">twill</a> and <a href="http://seleniumhq.org/" rel="nofollow">selenium</a> for testing the full stack. </p>
| 2 | 2009-09-02T16:44:29Z | [
"python",
"django",
"unit-testing",
"views"
] |
How do I unit test Django Views? | 1,368,255 | <p>I want to begin integrating unit tests into my Django projects and I've discovered unit testing a view to be tricky because of the way Django implements views with functions. </p>
<p>For example, each function is a view/page in Django if the function has a URL.</p>
<p>How do I unit test Django views?</p>
| 8 | 2009-09-02T15:02:23Z | 1,368,999 | <p>You could try <a href="http://github.com/42/tddspry/tree/master" rel="nofollow">tddspry</a> - collection of helpers to test Django with nosetests and twill. Nose also have coverage plugin which generate pretty reports of the coverage. </p>
| 0 | 2009-09-02T17:09:36Z | [
"python",
"django",
"unit-testing",
"views"
] |
python file-like buffer object | 1,368,261 | <p>I've written a buffer class that provides a File-like interface with <code>read</code>, <code>write</code>, <code>seek</code>, <code>tell</code>, <code>flush</code> methods to a simple string in memory. Of course it is incomplete (e.g. I didn't write <code>readline</code>). It's purpose is to be filled by a backgrou... | 12 | 2009-09-02T15:03:03Z | 1,368,272 | <p>You can use the standard Python modules <a href="http://docs.python.org/2/library/stringio.html" rel="nofollow"><code>StringIO</code></a> or <a href="http://docs.python.org/2/library/stringio.html#module-cStringIO" rel="nofollow"><code>cStringIO</code></a> to obtain an in-memory buffer which implements the <a href="... | 18 | 2009-09-02T15:04:48Z | [
"python",
"io",
"buffer"
] |
python file-like buffer object | 1,368,261 | <p>I've written a buffer class that provides a File-like interface with <code>read</code>, <code>write</code>, <code>seek</code>, <code>tell</code>, <code>flush</code> methods to a simple string in memory. Of course it is incomplete (e.g. I didn't write <code>readline</code>). It's purpose is to be filled by a backgrou... | 12 | 2009-09-02T15:03:03Z | 1,368,274 | <p>I think you might be looking for <code>StringIO</code>.</p>
| 6 | 2009-09-02T15:04:57Z | [
"python",
"io",
"buffer"
] |
pywikipedia login.py socket.error: (10060, 'Operation timed out') | 1,368,266 | <p>I'm totally new to python, so hopefully someone can help if I'm doing something obviously wrong. I'm trying to create and run a simple pywikipedia bot on vocabularies.referata.com, a semantic mediawiki site. I downloaded the pywikipedia distro and created a family file:</p>
<pre><code>import config, family, urllib ... | 0 | 2009-09-02T15:03:34Z | 1,369,062 | <p>I'm not familiar w/ pywikipedia =p, but the problem is at least about connection rather than python: the socket connection fails to be established at the beginning.</p>
<ul>
<li>Is the post url, <code>address</code> in the login.py L178 , correct? Any typo or misconfiguration? </li>
<li>Is the url accessible? You c... | 0 | 2009-09-02T17:23:52Z | [
"python",
"mediawiki",
"pywikipedia"
] |
pywikipedia login.py socket.error: (10060, 'Operation timed out') | 1,368,266 | <p>I'm totally new to python, so hopefully someone can help if I'm doing something obviously wrong. I'm trying to create and run a simple pywikipedia bot on vocabularies.referata.com, a semantic mediawiki site. I downloaded the pywikipedia distro and created a family file:</p>
<pre><code>import config, family, urllib ... | 0 | 2009-09-02T15:03:34Z | 1,375,566 | <p>Works for me, sorry. I just created an account, and used your family file. It seems to be on your side.</p>
<pre><code>$ python login.py -v -v -family:explicator -lang:en
Pywikipediabot [http] trunk/pywikipedia (r6858, May 08 2009, 15:23:29)
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3]
WARNING... | 0 | 2009-09-03T19:49:58Z | [
"python",
"mediawiki",
"pywikipedia"
] |
How does Django determine if an uploaded image is valid? | 1,368,724 | <p>I'm trying to add images to my models in my Django app.</p>
<p>models.py</p>
<pre><code>class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
</code></pre>
<p>In development mode, every time I try to ... | 3 | 2009-09-02T16:21:21Z | 1,368,786 | <p>According to Django's source code. Those three lines are responsible for verifying images:</p>
<pre><code>from PIL import Image
trial_image = Image.open(file)
trial_image.verify()
</code></pre>
<p>The image type could be unsupported by PIL. Check the list of supported formats <a href="http://www.pythonware.com/lib... | 11 | 2009-09-02T16:30:35Z | [
"python",
"django",
"python-imaging-library"
] |
How does Django determine if an uploaded image is valid? | 1,368,724 | <p>I'm trying to add images to my models in my Django app.</p>
<p>models.py</p>
<pre><code>class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
</code></pre>
<p>In development mode, every time I try to ... | 3 | 2009-09-02T16:21:21Z | 1,368,795 | <p>I looked into the Django source, in <code>django/forms/fields.py</code>, in the <code>ImageField</code> class. Django actually does use PIL to determine when an image is valid.</p>
| 0 | 2009-09-02T16:32:53Z | [
"python",
"django",
"python-imaging-library"
] |
How does Django determine if an uploaded image is valid? | 1,368,724 | <p>I'm trying to add images to my models in my Django app.</p>
<p>models.py</p>
<pre><code>class ImageMain(models.Model):
"""This is the Main Image of the product"""
product = models.ForeignKey(Product)
photo = models.ImageField(upload_to='products')
</code></pre>
<p>In development mode, every time I try to ... | 3 | 2009-09-02T16:21:21Z | 1,369,729 | <p>Did you try uploading image format like gif or png? It might be that your PIL was not built with the jpeg lib properly. I had a similar issue with Django on Ubuntu. If you have ever seen the error message <code>decoder jpeg not available</code>, check this <a href="http://effbot.org/zone/pil-decoder-jpeg-not-avail... | 2 | 2009-09-02T19:46:02Z | [
"python",
"django",
"python-imaging-library"
] |
Split a list of dates by another list of dates | 1,368,802 | <p>I have a number of nodes in a network. The nodes send status information every hour to indicate that they are alive. So i have a list of Nodes and the time when they were last alive. I want to graph the number of alive nodes over the time.</p>
<p>The list of nodes is sorted by the time they were last alive but i ca... | 1 | 2009-09-02T16:34:16Z | 1,368,905 | <p>The python <a href="http://docs.python.org/library/bisect.html" rel="nofollow">bisect module</a> will find the correct index for you, and you can deduct the number of items before and after.</p>
<p>If I'm understanding right, that would be O(dates) * O(log(seen))</p>
<p><hr /></p>
<p>Edit 1</p>
<p>It should be p... | 1 | 2009-09-02T16:53:04Z | [
"python",
"performance"
] |
Split a list of dates by another list of dates | 1,368,802 | <p>I have a number of nodes in a network. The nodes send status information every hour to indicate that they are alive. So i have a list of Nodes and the time when they were last alive. I want to graph the number of alive nodes over the time.</p>
<p>The list of nodes is sorted by the time they were last alive but i ca... | 1 | 2009-09-02T16:34:16Z | 1,368,951 | <p>this generator traverses the list only once:</p>
<pre><code>def get_alive(seen, dates):
c = len(seen)
for date in dates:
for s in seen[-c:]:
if s >= date: # replaced your > for >= as it seems to make more sense
yield c
break
else:
c -= 1
</code></pre>
| 2 | 2009-09-02T16:59:53Z | [
"python",
"performance"
] |
Split a list of dates by another list of dates | 1,368,802 | <p>I have a number of nodes in a network. The nodes send status information every hour to indicate that they are alive. So i have a list of Nodes and the time when they were last alive. I want to graph the number of alive nodes over the time.</p>
<p>The list of nodes is sorted by the time they were last alive but i ca... | 1 | 2009-09-02T16:34:16Z | 1,369,460 | <p>I took SilentGhosts generator solution a bit further using explicit iterators. This is the linear time solution i was thinking of. </p>
<pre><code>def splitter( items, breaks ):
""" assuming `items` and `breaks` are sorted """
c = len( items )
items = iter(items)
item = items.next()
breaks = it... | 1 | 2009-09-02T18:45:35Z | [
"python",
"performance"
] |
Rose diagrams in Google Chart | 1,368,822 | <p>I searched around for ways to make rose diagrams (circular histograms) in Google Chart. The API has only radar diagrams, so it seems not technically possible (am I correct?). This <a href="http://www.carloslabs.com/node/18" rel="nofollow">wind rose example</a> was the closest I came to a solution.</p>
<p>Because I ... | 1 | 2009-09-02T16:39:08Z | 1,644,195 | <p>Well, it looks like no-one has any other examples. I DID decide to play around with this to see what else is possible and created a quick proof of concept for <a href="http://rose-clock.mettadore.com" rel="nofollow">time-based rose diagrams</a>. It's just a silly thing to show your relative Twitter posting amount by... | 1 | 2009-10-29T14:39:14Z | [
"python",
"google-visualization",
"histogram"
] |
Default encoding of exception messages | 1,369,089 | <p>The following code examines the behaviour of the <code>float()</code> method when fed a non-ascii symbol:</p>
<pre><code>import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float(): ' follow... | 6 | 2009-09-02T17:27:16Z | 1,369,177 | <p>The ASCII encoding only includes the bytes with values <code><= 127</code>. The range of characters represented by these bytes is identical in most encodings; in other words, "A" is <code>chr(65)</code> in ASCII, in latin-1, in UTF-8, and so on.</p>
<p>The one half symbol, however, is not part of the ASCII chara... | 2 | 2009-09-02T17:49:23Z | [
"python",
"exception",
"encoding",
"python-2.x"
] |
Default encoding of exception messages | 1,369,089 | <p>The following code examines the behaviour of the <code>float()</code> method when fed a non-ascii symbol:</p>
<pre><code>import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float(): ' follow... | 6 | 2009-09-02T17:27:16Z | 1,369,247 | <p>From experimenting with you code snippet, it would seem I have the same behavior on my platform (Py2.6 on OS X 10.5).</p>
<p>Since you established that e[0] is encoded with <code>latin-1</code>, the correct way to convert it <code>unicode</code> is to do <code>.decode('latin-1')</code>, and <em>not</em> <code>unico... | 0 | 2009-09-02T18:04:17Z | [
"python",
"exception",
"encoding",
"python-2.x"
] |
Default encoding of exception messages | 1,369,089 | <p>The following code examines the behaviour of the <code>float()</code> method when fed a non-ascii symbol:</p>
<pre><code>import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float(): ' follow... | 6 | 2009-09-02T17:27:16Z | 1,369,335 | <p>e[0] isn't encoded with latin-1; it just so happens that the byte \xbd, when decoded as latin-1, is the character U+00BD.</p>
<p>The conversion occurs in <code>Objects/floatobject.c</code>.</p>
<p>First, the unicode string must be converted to a byte string. This is performed using <code>PyUnicode_EncodeDecimal()<... | 8 | 2009-09-02T18:19:54Z | [
"python",
"exception",
"encoding",
"python-2.x"
] |
Default encoding of exception messages | 1,369,089 | <p>The following code examines the behaviour of the <code>float()</code> method when fed a non-ascii symbol:</p>
<pre><code>import sys
try:
float(u'\xbd')
except ValueError as e:
print sys.getdefaultencoding() # in my system, this is 'ascii'
print e[0].decode('latin-1') # u'invalid literal for float(): ' follow... | 6 | 2009-09-02T17:27:16Z | 1,369,357 | <p>Very good question!</p>
<p>I took the liberty to dig into Python's source code, which is a mere command away on properly set up linux distributions (<code>apt-get source python2.5</code>)</p>
<p><em>Damn</em>, John Millikin beat me to it. That's right, <code>PyUnicode_EncodeDecimal</code> is the answer it does thi... | 5 | 2009-09-02T18:23:23Z | [
"python",
"exception",
"encoding",
"python-2.x"
] |
Managing Python Path When Moving Code from Development Computer to Target | 1,369,159 | <p>I have a python project with this directory structure and these files:</p>
<pre><code>/home/project_root
|---__init__.py
|---setup
|---__init__.py
|---configs.py
|---test_code
|---__init__.py
|---tester.py
</code></pre>
<p>The tester script imports from setup/configs.py with the referen... | 3 | 2009-09-02T17:45:17Z | 1,369,185 | <p>Try explicitly setting your python path <em>in your scripts</em>. If you don't want to have to change it, you could always add something like "../" to the path in tester. That is to say:</p>
<pre><code>sys.path.append("../")
</code></pre>
| 0 | 2009-09-02T17:51:04Z | [
"python",
"path",
"pythonpath"
] |
Managing Python Path When Moving Code from Development Computer to Target | 1,369,159 | <p>I have a python project with this directory structure and these files:</p>
<pre><code>/home/project_root
|---__init__.py
|---setup
|---__init__.py
|---configs.py
|---test_code
|---__init__.py
|---tester.py
</code></pre>
<p>The tester script imports from setup/configs.py with the referen... | 3 | 2009-09-02T17:45:17Z | 1,369,186 | <p>Stick this in the tester script right before the <code>import setup.configs</code></p>
<pre><code>import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.path.pardir))
</code></pre>
<p><code>sys.path</code> is a list of all the directories the python interpreter looks for when importing ... | 4 | 2009-09-02T17:51:19Z | [
"python",
"path",
"pythonpath"
] |
Managing Python Path When Moving Code from Development Computer to Target | 1,369,159 | <p>I have a python project with this directory structure and these files:</p>
<pre><code>/home/project_root
|---__init__.py
|---setup
|---__init__.py
|---configs.py
|---test_code
|---__init__.py
|---tester.py
</code></pre>
<p>The tester script imports from setup/configs.py with the referen... | 3 | 2009-09-02T17:45:17Z | 1,369,435 | <blockquote>
<p>(I don't want to rely on the .bashrc file to set the PYTHONPATH for the target machine -- the code is for a Django application, and will eventually be run by www-data. And, I know that the apache configuration for Django includes a specification of the PYTHONPATH, but I don't want to use that here as ... | 0 | 2009-09-02T18:39:59Z | [
"python",
"path",
"pythonpath"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,369,338 | <p><em>(This solution is in PHP -- but you can probably do that directly from the command-line, I suppose, with somekind of grep or anything)</em></p>
<p>Considering your dates are in the <code>YYYY-MM-DD</code> format, and that they are at the beginning of each line, you just have to compare the lines alphabetically ... | 2 | 2009-09-02T18:20:19Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,369,393 | <p>Well, you could probably <em>somehow</em> make it work with grep, but sed is more suited for the task:</p>
<pre><code>sort < file.csv | sed -ne /^2009-09-04/,/^2009-09-09/p
</code></pre>
| 3 | 2009-09-02T18:28:58Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,369,399 | <p>Python</p>
<pre><code>import csv
import datetime
start= datetime.datetime(2009,9,4)
end= datetime.datetime(2009,9,9)
source= csv.DictReader( open("someFile","rb") )
for row in source:
dt = datetime.datetime.strptime(row['date'],"%Y-%m-%d")
if start <= dt <= end:
print row # depends on what "... | 4 | 2009-09-02T18:31:12Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,369,576 | <p>awk solution is similar to sed:</p>
<pre><code>awk '/^2009-09-04/,/^2009-09-09/ {next} {print}' filename
</code></pre>
<p>Without hardcoding the dates:</p>
<pre><code>awk -v start='^2009-09-04' -v stop='^2009-09-09' '
$0 ~ start, $0 ~ stop {next}
{print}
' date.data
</code></pre>
| 1 | 2009-09-02T19:10:48Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,371,548 | <p>Using <a href="http://www.r-project.org" rel="nofollow">R</a></p>
<pre><code>> d <- read.csv("http://dpaste.com/88980/plain/", sep=",", header=T)
> r1 <- rownames(d[d$date == "2009-09-04",])
> r2 <- rownames(d[d$date == "2009-09-09",])
> d[rownames(d) %in% r1:r2,]
date test time avail
... | 0 | 2009-09-03T05:24:32Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,381,076 | <p>Perl:</p>
<blockquote>
<pre><code>perl -F/,/ -ane '
print if $F[0] ge "2009-09-04"
&& $F[0] le "2009-09-09"' filename
</code></pre>
</blockquote>
| 0 | 2009-09-04T19:20:32Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
How do I extract a date range from a csv using perl/php/grep/etc? | 1,369,287 | <p>Is there a way to take text like below (if it was already in an array or a file) and have it strip the lines with a specified date range? </p>
<p>For instance if i wanted every line from 2009-09-04 until 2009-09-09 to be pulled out (maybe this can be done with grep?) how would I go about doing so? </p>
<pre><code>... | 1 | 2009-09-02T18:10:42Z | 1,381,095 | <p>You can use <a href="http://www.perl.com/pub/a/2004/06/18/variables.html" rel="nofollow">perl's flip flop</a> to extract a line range.</p>
| 1 | 2009-09-04T19:24:31Z | [
"php",
"python",
"ruby",
"perl",
"grep"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,369,409 | <p>Removing spaces, commas and dashes will be ambiguous . It will be better to replace them with a single space.</p>
<p>Take for example this address</p>
<pre><code>56 5th avenue
</code></pre>
<p>And this</p>
<pre><code>5, 65th avenue
</code></pre>
<p>with your method both of them will be:</p>
<pre><code>565THAV
... | 2 | 2009-09-02T18:33:46Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,369,651 | <p>This should be helpful in building your dictionary of abbreviations:</p>
<p><a href="http://www.usps.com/ncsc/lookups/usps%5Fabbreviations.html" rel="nofollow">http://www.usps.com/ncsc/lookups/usps%5Fabbreviations.html</a></p>
| 2 | 2009-09-02T19:27:55Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,370,350 | <p>First, simplify the address string by collapsing all whitespace to a single space between each word, and forcing everything to lower case (or upper case if you prefer):</p>
<pre><code>adr = " ".join(adr.tolower().split())
</code></pre>
<p>Then, I would strip out things like "st" in "41st Street" or "nd" in "42nd S... | 1 | 2009-09-02T21:54:37Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,372,808 | <p>I had to do this once. I converted everything to lowercase, computed each address's Levenshtein distance to every other address, and ordered the results. It worked very well, but it was quite time-consuming.</p>
<p>You'll want to use an implementation of Levenshtein in C rather than in Python if you have a large da... | 0 | 2009-09-03T11:18:35Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,377,318 | <p>I regularly inspect addresses for duplication where I work, and I have to say, I find Soundex highly unsuitable. It's both too slow and too eager to match things. I have similar issues with Levenshtein distance.</p>
<p>What has worked best for me is to sanitize and tokenize the addresses (get rid of punctuation, ... | 0 | 2009-09-04T05:07:04Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
strategies for finding duplicate mailing addresses | 1,369,289 | <p>I'm trying to come up with a method of finding duplicate addresses, based on a similarity score. Consider these duplicate addresses:</p>
<pre><code>addr_1 = '# 3 FAIRMONT LINK SOUTH'
addr_2 = '3 FAIRMONT LINK S'
addr_3 = '5703 - 48TH AVE'
adrr_4 = '5703- 48 AVENUE'
</code></pre>
<p>I'm planning on applying some s... | 4 | 2009-09-02T18:11:03Z | 1,927,502 | <p>In order to do this right, you need to standardize your addresses according to USPS standards (your address examples appear to be US based). There are many direct marketing service providers that offer <a href="http://en.wikipedia.org/wiki/CASS" rel="nofollow">CASS</a> (Coding Accuracy Support System) certification ... | 1 | 2009-12-18T10:52:44Z | [
"python",
"duplicates",
"street-address",
"similarity",
"mailing"
] |
Aliasing a class in Python | 1,369,534 | <p>I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:</p>
<pre><code>class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
def calc_a... | 1 | 2009-09-02T18:59:52Z | 1,369,564 | <p>Are you looking for something along these lines?</p>
<pre><code>dispatch = {0: level0, 1: level1, 2:level2}
dispatch[offset].calc_algorithm
</code></pre>
<p>Keys (and <code>offset</code>), obviously, could come from command line.</p>
| 11 | 2009-09-02T19:06:50Z | [
"python",
"class"
] |
Aliasing a class in Python | 1,369,534 | <p>I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:</p>
<pre><code>class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
def calc_a... | 1 | 2009-09-02T18:59:52Z | 1,369,704 | <pre><code>dispatch = {0:level0, 1:level1, 2:level2}
algo = dispatch[offset]() # "calling" a class constructs an instance.
algo.calc_algorithm()
</code></pre>
<p>If you like introspection more:</p>
<pre><code>class_name = "level%d" % offset
klass = globals()[class_name]
algo = klass()
algo.calc_algorithm()
</code><... | 4 | 2009-09-02T19:41:50Z | [
"python",
"class"
] |
Aliasing a class in Python | 1,369,534 | <p>I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:</p>
<pre><code>class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
def calc_a... | 1 | 2009-09-02T18:59:52Z | 1,370,918 | <p>The key is thatâââunlike in some other languages where classes are âspecialâ and you'd have to have some unusual means of âaliasingâ themâââin Python, classes are themselves first-class objects which are referenced by perfectly normal variables.</p>
<p>So âaâ can be aliased as âbâ as sim... | 3 | 2009-09-03T00:50:28Z | [
"python",
"class"
] |
Aliasing a class in Python | 1,369,534 | <p>I am writing a class to implement an algorithm. This algorithm has three levels of complexity. It makes sense to me to implement the classes like this:</p>
<pre><code>class level0:
def calc_algorithm(self):
# level 0 algorithm
pass
# more level0 stuff
class level1(level0):
def calc_a... | 1 | 2009-09-02T18:59:52Z | 1,372,684 | <p>Personally, I wouldn't create 3 classes, but one class with 3 different calculation methods, and dinamically change the official calculation method (the calculation interface) as needed.
For example:</p>
<pre><code>class algorithm:
def __init__(self, level = 0):
self.level = level
self.calcFunctions ... | 2 | 2009-09-03T10:40:19Z | [
"python",
"class"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.