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 |
|---|---|---|---|---|---|---|---|---|---|
Merge sorted lists in python | 1,158,128 | <p>I have a bunch of sorted lists of objects, and a comparison function</p>
<pre><code>class Obj :
def __init__(p) :
self.points = p
def cmp(a, b) :
return a.points < b.points
a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]
result = magic... | 10 | 2009-07-21T09:21:00Z | 1,158,294 | <p>One line solution using sorted:</p>
<pre><code>def magic(*args):
return sorted(sum(args,[]), key: lambda x: x.points)
</code></pre>
<p>IMO this solution is very readable.</p>
<p>Using heapq module, it could be more efficient, but I have not tested it. You cannot specify cmp/key function in heapq, so you have to... | 0 | 2009-07-21T10:01:19Z | [
"python",
"arrays",
"merge",
"sorting"
] |
Merge sorted lists in python | 1,158,128 | <p>I have a bunch of sorted lists of objects, and a comparison function</p>
<pre><code>class Obj :
def __init__(p) :
self.points = p
def cmp(a, b) :
return a.points < b.points
a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]
result = magic... | 10 | 2009-07-21T09:21:00Z | 1,159,492 | <p>Here you go: a fully functioning merge sort for lists (adapted from my sort <a href="http://github.com/hughdbrown/algorithm/blob/05307be15669de0541cd4e91c03b610d440b4290/mergesort.py" rel="nofollow">here</a>):</p>
<pre><code>def merge(*args):
import copy
def merge_lists(left, right):
result = []
... | 0 | 2009-07-21T14:18:02Z | [
"python",
"arrays",
"merge",
"sorting"
] |
Merge sorted lists in python | 1,158,128 | <p>I have a bunch of sorted lists of objects, and a comparison function</p>
<pre><code>class Obj :
def __init__(p) :
self.points = p
def cmp(a, b) :
return a.points < b.points
a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]
result = magic... | 10 | 2009-07-21T09:21:00Z | 1,159,612 | <p>I like Roberto Liffredo's answer. I didn't know about heapq.merge(). Hmmmph.</p>
<p>Here's what the complete solution looks like using Roberto's lead:</p>
<pre><code>class Obj(object):
def __init__(self, p) :
self.points = p
def __cmp__(self, b) :
return cmp(self.points, b.points)
def _... | 1 | 2009-07-21T14:37:47Z | [
"python",
"arrays",
"merge",
"sorting"
] |
Merge sorted lists in python | 1,158,128 | <p>I have a bunch of sorted lists of objects, and a comparison function</p>
<pre><code>class Obj :
def __init__(p) :
self.points = p
def cmp(a, b) :
return a.points < b.points
a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]
result = magic... | 10 | 2009-07-21T09:21:00Z | 1,159,623 | <p>I asked a similar question and got some excellent answers:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/969709/joining-a-set-of-ordered-integer-yielding-python-iterators">Joining a set of ordered-integer yielding Python iterators</a></li>
</ul>
<p>The best solutions from that question are variants of t... | 0 | 2009-07-21T14:39:37Z | [
"python",
"arrays",
"merge",
"sorting"
] |
Merge sorted lists in python | 1,158,128 | <p>I have a bunch of sorted lists of objects, and a comparison function</p>
<pre><code>class Obj :
def __init__(p) :
self.points = p
def cmp(a, b) :
return a.points < b.points
a = [Obj(1), Obj(3), Obj(8), ...]
b = [Obj(1), Obj(2), Obj(3), ...]
c = [Obj(100), Obj(300), Obj(800), ...]
result = magic... | 10 | 2009-07-21T09:21:00Z | 15,893,551 | <p>Below is an example of a function that runs in O(n) comparisons. </p>
<p>You could make this faster by making a and b iterators and incrementing them.</p>
<p>I have simply called the function twice to merge 3 lists:</p>
<pre><code>def zip_sorted(a, b):
'''
zips two iterables, assuming they are already sor... | 0 | 2013-04-09T04:51:05Z | [
"python",
"arrays",
"merge",
"sorting"
] |
django - QuerySet recursive order by method | 1,158,267 | <p>I may have a classic problem, but I didn't find any snippet allowing me to do it.</p>
<p>I want to sort this model by its fullname.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models.CharField(max_length=128)
def get_fullnam... | 1 | 2009-07-21T09:55:50Z | 1,158,879 | <p>This might work:</p>
<pre><code>ProductType.objects.alL().order_by('parent__name', 'name')
</code></pre>
| 0 | 2009-07-21T12:25:23Z | [
"python",
"django",
"order"
] |
django - QuerySet recursive order by method | 1,158,267 | <p>I may have a classic problem, but I didn't find any snippet allowing me to do it.</p>
<p>I want to sort this model by its fullname.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models.CharField(max_length=128)
def get_fullnam... | 1 | 2009-07-21T09:55:50Z | 1,158,972 | <p>I would probably create a denomalised field and order on that. Depending on your preferences you might wnat to override .save(), or use a signal to poplate the denormalised field.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models... | 2 | 2009-07-21T12:47:10Z | [
"python",
"django",
"order"
] |
django - QuerySet recursive order by method | 1,158,267 | <p>I may have a classic problem, but I didn't find any snippet allowing me to do it.</p>
<p>I want to sort this model by its fullname.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models.CharField(max_length=128)
def get_fullnam... | 1 | 2009-07-21T09:55:50Z | 1,159,096 | <p>agreed :</p>
<p>ProductType.objects.all().order_by('parent__name', 'name')</p>
<p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields</a></p>
| 0 | 2009-07-21T13:14:17Z | [
"python",
"django",
"order"
] |
django - QuerySet recursive order by method | 1,158,267 | <p>I may have a classic problem, but I didn't find any snippet allowing me to do it.</p>
<p>I want to sort this model by its fullname.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models.CharField(max_length=128)
def get_fullnam... | 1 | 2009-07-21T09:55:50Z | 1,159,340 | <p>I would definitely explore the route you mentioned as 1) above:</p>
<pre><code>ProductType.objects.order_by('parent__name', 'name')
</code></pre>
<p>Why is it erroring with an infinite loop? Is your example data referencing itself? </p>
| 0 | 2009-07-21T13:52:45Z | [
"python",
"django",
"order"
] |
django - QuerySet recursive order by method | 1,158,267 | <p>I may have a classic problem, but I didn't find any snippet allowing me to do it.</p>
<p>I want to sort this model by its fullname.</p>
<pre><code>class ProductType(models.Model):
parent = models.ForeignKey('self', related_name='child_set')
name = models.CharField(max_length=128)
def get_fullnam... | 1 | 2009-07-21T09:55:50Z | 1,159,406 | <p>Or, if what you're trying to do is to generate a tree structure, have a look at <a href="http://code.google.com/p/django-mptt/" rel="nofollow">django-mptt</a>. It also allows for ordering on a manually set order.</p>
| 1 | 2009-07-21T14:04:15Z | [
"python",
"django",
"order"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,418 | <p>Lua. It has a very small footprint, is rather fast, and I found it (subjectively) to have the most pleasant API to interact with C.</p>
<p>If you want to touch the Lua objects from C - it's quite easy using the built-in APIs. If you want to touch C data from Lua - it's a bit more work, typically you'd need to make ... | 17 | 2009-07-21T10:39:24Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,423 | <p>Lua is designed for exactly this purpose, and fairly easy to work with.</p>
<p>Another thing worth looking at would be <a href="http://doc.trolltech.com/4.5/qtscript.html" rel="nofollow">QtScript</a>, which is Javascript based, although this would involve some work to "qt-ify" your app.</p>
| 3 | 2009-07-21T10:40:53Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,502 | <p>Here's the document from the Python website for embedding Python 2.6...</p>
<p><a href="http://docs.python.org/extending/embedding.html">http://docs.python.org/extending/embedding.html</a></p>
| 7 | 2009-07-21T10:57:52Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,517 | <p>Most scripting language allow embedding in C and usually allow you to expose certain objects or even functions from your C code to the script so it can manipulate the objects and call the functions.</p>
<p>As said Lua is designed for this purpose embedding, using the interpreter you can expose objects to the script... | 1 | 2009-07-21T11:01:50Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,540 | <p>Some useful links:</p>
<ul>
<li><a href="http://docs.python.org/extending/embedding.html">Embedding Python</a></li>
<li>Embedding Lua: <a href="http://www.lua.org/manual/5.1/manual.html#3">http://www.lua.org/manual/5.1/manual.html#3</a>, <a href="http://www.ibm.com/developerworks/opensource/library/l-embed-lua/inde... | 16 | 2009-07-21T11:06:47Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,158,771 | <p>You may also want to take a look at <a href="http://www.swig.org/" rel="nofollow">SWIG</a>, the Simplified Wrapper and Interface Generator. As one would guess, it generates much of the boiler plate code to interface your C/C++ code to the scripting engine (which can be quite cumbersome to do manually).</p>
<p>It s... | 3 | 2009-07-21T12:03:25Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,160,486 | <p>You might take a look at <a href="http://rads.stackoverflow.com/amzn/click/1931841578" rel="nofollow">Game Scripting Mastery</a>. As i am interested in the high level aspect of computer games aswell this book has been recommended to me very often. </p>
<p>Unfortunately the book seems to be out of print (at least in... | 1 | 2009-07-21T17:10:58Z | [
"python",
"c",
"scripting",
"lua"
] |
How to implement a scripting language into a C application? | 1,158,396 | <p>I have a C application and I want to include a Scripting Language to put certain functionality into scripts. I just have no experience with that and don't know exactly where to start (Still learning C and trying to understand the application).</p>
<p>How does embedding and communication between my app and the scrip... | 14 | 2009-07-21T10:32:13Z | 1,162,177 | <p>Lua is totally optimized for exactly this sort of embedding. A good starting point is Roberto Ierusalimschy's book <em>Programming in Lua</em>; you can get the <a href="http://www.lua.org/pil/">previous edition free online</a>.</p>
<p><strong>How does your script know about the properties of your C object?</strong... | 8 | 2009-07-21T22:54:44Z | [
"python",
"c",
"scripting",
"lua"
] |
Changing palette's of 8-bit .png images using python PIL | 1,158,736 | <p>I'm looking for a fast way to apply a new palette to an existing 8-bit .png image. How can I do that? Is the .png re-encoded when I save the image? (Own answer: it seems so)</p>
<p>What I have tried (edited):</p>
<pre><code>import Image, ImagePalette
output = StringIO.StringIO()
palette = (.....) #long palette of ... | 2 | 2009-07-21T11:51:54Z | 1,159,577 | <p><code>im.palette</code> is not callable -- it's an instance of the <code>ImagePalette</code> class, in mode <code>P</code>, otherwise <code>None</code>. <code>im.putpalette(...)</code> is a method, so callable: the argument must be a sequence of 768 integers giving R, G and B value at each index.</p>
| 1 | 2009-07-21T14:32:27Z | [
"python",
"image-processing",
"python-imaging-library"
] |
Changing palette's of 8-bit .png images using python PIL | 1,158,736 | <p>I'm looking for a fast way to apply a new palette to an existing 8-bit .png image. How can I do that? Is the .png re-encoded when I save the image? (Own answer: it seems so)</p>
<p>What I have tried (edited):</p>
<pre><code>import Image, ImagePalette
output = StringIO.StringIO()
palette = (.....) #long palette of ... | 2 | 2009-07-21T11:51:54Z | 1,199,832 | <p>Changing palette's without decoding and (re)encoding does not seem possible. The method in the question seems best (for now). If performance is important, encoding to GIF seems a lot faster.</p>
| 0 | 2009-07-29T12:13:39Z | [
"python",
"image-processing",
"python-imaging-library"
] |
Changing palette's of 8-bit .png images using python PIL | 1,158,736 | <p>I'm looking for a fast way to apply a new palette to an existing 8-bit .png image. How can I do that? Is the .png re-encoded when I save the image? (Own answer: it seems so)</p>
<p>What I have tried (edited):</p>
<pre><code>import Image, ImagePalette
output = StringIO.StringIO()
palette = (.....) #long palette of ... | 2 | 2009-07-21T11:51:54Z | 1,214,765 | <p>If you want to change just the palette, then PIL will just get in your way. Luckily, the PNG file format was designed to be easy to deal with when you only are interested in some of the data chunks. The format of the <a href="http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.PLTE" rel="nofollow">PLTE chunk</a... | 4 | 2009-07-31T20:39:56Z | [
"python",
"image-processing",
"python-imaging-library"
] |
backport function modifiers to python2.1 | 1,159,023 | <p>I have some code I developed in python 2.4++ and you bet, I have to backport it to python 2.1!</p>
<p>function decorators were so attractive that I have used @classmethod at a few spots, without taking notice of the fact that it is only available starting at version 2.4. the same functionality is offered by functi... | 3 | 2009-07-21T12:57:51Z | 1,159,137 | <p>If just the @classmethod need to be backported to Python 2.1.<br />
There is a <a href="http://code.activestate.com/recipes/113645/" rel="nofollow">recipe of Classmethod emulation in python2.1</a><br />
Hope this help.</p>
| 1 | 2009-07-21T13:22:43Z | [
"python",
"syntax",
"backport"
] |
backport function modifiers to python2.1 | 1,159,023 | <p>I have some code I developed in python 2.4++ and you bet, I have to backport it to python 2.1!</p>
<p>function decorators were so attractive that I have used @classmethod at a few spots, without taking notice of the fact that it is only available starting at version 2.4. the same functionality is offered by functi... | 3 | 2009-07-21T12:57:51Z | 1,159,463 | <p>Just like in my old recipe for 2.1 staticmethod:</p>
<pre><code>class staticmethod:
def __init__(self, thefunc): self.f = thefunc
def __call__(self, *a, **k): return self.f(*a, **k)
</code></pre>
<p>you should be able to do a 2.1 classmethod as:</p>
<pre><code>class classmethod:
def __init__(self, the... | 2 | 2009-07-21T14:12:57Z | [
"python",
"syntax",
"backport"
] |
How to Replace a column in a CSV file in Python? | 1,159,524 | <p>I have 2 csv files. I need to replace a column in one file with a column from the other file but they have to stay sorted according to an ID column.</p>
<p>Here's an example:</p>
<p>file1: </p>
<pre><code>ID, transect, 90mdist ... | 5 | 2009-07-21T14:23:23Z | 1,159,627 | <p>The <a href="http://docs.python.org/library/csv.html">CSV Module</a> in the Python Library is what you need here.</p>
<p>It allows you to read and write CSV files, treating lines a tuples or lists of items.</p>
<p>Just read in the file with the corrected values, store the in a dictionary keyed with the line's ID.<... | 7 | 2009-07-21T14:40:21Z | [
"python",
"csv"
] |
How to Replace a column in a CSV file in Python? | 1,159,524 | <p>I have 2 csv files. I need to replace a column in one file with a column from the other file but they have to stay sorted according to an ID column.</p>
<p>Here's an example:</p>
<p>file1: </p>
<pre><code>ID, transect, 90mdist ... | 5 | 2009-07-21T14:23:23Z | 1,159,672 | <p>Once you have your csv lists, one easy way to replace a column in one matrix with another would be to transpose the matrices, replace the row, and then transpose back your edited matrix. Here is an example with your data:</p>
<pre><code>csv1 = [['1', 'a', '10'], ['2', 'b', '20'], ['3', 'c', '30']]
csv2 = [['1', 'a... | 0 | 2009-07-21T14:49:46Z | [
"python",
"csv"
] |
How to Replace a column in a CSV file in Python? | 1,159,524 | <p>I have 2 csv files. I need to replace a column in one file with a column from the other file but they have to stay sorted according to an ID column.</p>
<p>Here's an example:</p>
<p>file1: </p>
<pre><code>ID, transect, 90mdist ... | 5 | 2009-07-21T14:23:23Z | 1,159,811 | <p>If you're only doing this as a one-off, why bother with Python at all? Excel or OpenOffice Calc will open the two CSV files for you, then you can just cut and paste the column from one to the other. </p>
<p>If the two lists of IDs are not exactly the same then a simple VB macro would do it for you.</p>
| 0 | 2009-07-21T15:09:09Z | [
"python",
"csv"
] |
How to Replace a column in a CSV file in Python? | 1,159,524 | <p>I have 2 csv files. I need to replace a column in one file with a column from the other file but they have to stay sorted according to an ID column.</p>
<p>Here's an example:</p>
<p>file1: </p>
<pre><code>ID, transect, 90mdist ... | 5 | 2009-07-21T14:23:23Z | 1,160,807 | <p>Try this:</p>
<pre><code>from __future__ import with_statement
import csv
def twiddle_csv(file1, file2):
def mess_with_record(record):
record['90mdist'] = 2 * int(record['90mdist']) + 30
with open(file1, "r") as fin:
with open(file2, "w") as fout:
fields = ['ID', 'transect', '9... | 2 | 2009-07-21T18:15:02Z | [
"python",
"csv"
] |
How to use a custom site-package using pth-files for Python 2.6? | 1,159,650 | <p>I'm trying to setup a custom site-package directory (Python 2.6 on Windows Vista). For example the directory should be '~\lib\python2.6' ( C:\Users\wierob\lib\python2.6). Hence calling 'setup.py install' should copy packages to C:\Users\wierob\lib\python2.6.</p>
<p>Following the instructions <a href="http://peak.te... | 0 | 2009-07-21T14:45:37Z | 1,159,941 | <p>According to <a href="http://docs.python.org/library/site.html" rel="nofollow">documentation</a> you should put paths to .pth file so maybe entering:</p>
<pre><code>C:\Users\wierob\lib\python2.6
</code></pre>
<p>will work</p>
| 0 | 2009-07-21T15:27:09Z | [
"python"
] |
How to use a custom site-package using pth-files for Python 2.6? | 1,159,650 | <p>I'm trying to setup a custom site-package directory (Python 2.6 on Windows Vista). For example the directory should be '~\lib\python2.6' ( C:\Users\wierob\lib\python2.6). Hence calling 'setup.py install' should copy packages to C:\Users\wierob\lib\python2.6.</p>
<p>Following the instructions <a href="http://peak.te... | 0 | 2009-07-21T14:45:37Z | 1,160,480 | <p>The pth-file seems to be ignored if encoded in UTF-8 with BOM.</p>
<p>Saving the pth-file in ANSI or UTF-8 without BOM works.</p>
| 1 | 2009-07-21T17:09:17Z | [
"python"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,708 | <p>I would not do this - in my opinion these questions weaken the security, so as a user I always try to provide another semi-password as an answer - for you it would like mashed. Well, it is mashed, but that is exactly what I want to do.</p>
<p>Btw. I am not sure about the fact, that you can query the answers. Since ... | 38 | 2009-07-21T14:55:51Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,716 | <p>There's no way to do this with a regex. Actually, I can't think of a reasonable way to do this at all -- where would you draw the line between suspicious and unsuspicious? I, for once, often answer the security questions with an obfuscated answer. After all, my mother's maiden name isn't the hardest thing to find ou... | 6 | 2009-07-21T14:56:27Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,720 | <p>You could look for patterns that don't make sense phonetically. Such as:</p>
<p>'q' not followed by a 'u'.</p>
<p>asdf</p>
<p>qwer</p>
<p>zxcv</p>
<p>asdlasd</p>
<p>Basically, try mashing on your own keyboard, see what you get, and plug that in your filter. Also plug in various grammatical rules. However, sinc... | 0 | 2009-07-21T14:57:02Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,726 | <p>If you can find a list of letter-pair probabilities in English, you could construct an approximate probability for the word not being a "real" English word, using the least possible pairs and pairs that are not in the list. Unfortunately, if you have names or other "non-words" then you can't force them to be Englis... | 3 | 2009-07-21T14:57:53Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,738 | <p>You could check for a capital letter at the start.... that will get you some false positives for sure.</p>
<p>A quick google gave me <a href="http://www.namebase.org/csvdump.html" rel="nofollow">this</a>, you could compare each against a name in that list.</p>
<p>Obviously only works for the security question you ... | 2 | 2009-07-21T14:59:17Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,741 | <p>You're probably better off analyzing n-gram distribution, similar to language detection.</p>
<p><a href="http://code.activestate.com/recipes/326576/" rel="nofollow">This code</a> is an example of language detection using trigrams. My guess is the keyboard smashing trigrams are pretty unique and don't appear in norm... | 4 | 2009-07-21T14:59:57Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,757 | <p>If your question is ever something related to a real, human name, this is impossible. Consider Asian names typed with roman characters; they may very well trip whatever filter you come up with, but are still perfectly legitimate.</p>
| 2 | 2009-07-21T15:02:24Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,866 | <h1>The whole approach of security questions is quite flawed.</h1>
<p>I have always found <strong>people put security answers weaker than the passwords they use</strong>.<br />
Security questions are just one more link in a security chain -- the weaker link! </p>
<p>IMO, a better way to go would be to <strong>allow ... | 11 | 2009-07-21T15:16:30Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,159,915 | <p>Maybe you could check for an abundance of consonants. So for example, in your example <code>lakdsjflkaj</code> there are 2 vowels ( a ) and 9 consonants. Usually the probability of hitting a vowel when randomly pressing keys is much lower than the one of hitting a consonant. </p>
| 3 | 2009-07-21T15:22:22Z | [
"python",
"regex",
"fraud-prevention"
] |
Regex for keyboard mashing | 1,159,690 | <p>When signing up for new accounts, web apps often ask for the answer to a 'security question', i.e. Dog's name, etc.</p>
<p>I'd like to go through our database and look for instances where users just mashed the keyboard instead of providing a legitimate answer - this is a high indicator of an abusive/fraudulent acco... | 5 | 2009-07-21T14:52:25Z | 1,160,107 | <p>Instead of regular expressions, why not just compare with a list of known good values? For example, compare Mother's maiden name with census data, or pet name with any of the pet name lists you can find online. For a much simpler version of this, just do a Google search for whatever is entered. Legitimate names s... | 0 | 2009-07-21T15:52:45Z | [
"python",
"regex",
"fraud-prevention"
] |
How do I do cross-project refactorings with ropemacs? | 1,160,057 | <p>I have a file structure that looks something like this:</p>
<pre><code>project1_root/
tests/
...
src/
.ropeproject/
project1/
... (project1 source code)
project2_root/
tests/
...
src/
.ropeproject/
project2/
... (project2 sourc... | 3 | 2009-07-21T15:46:33Z | 1,202,929 | <p>The documention on ropemacs and ropemode seems to be very sparse (the homepage <a href="http://rope.sourceforge.net/ropemacs.html" rel="nofollow">http://rope.sourceforge.net/ropemacs.html</a> only point to the mercurial repos, which I checked out and read through the code), but it seems you can give a specific .rope... | 3 | 2009-07-29T20:45:32Z | [
"python",
"emacs",
"elisp",
"ropemacs",
"rope"
] |
Python Math Library Independent of C Math Library and Platform Independent? | 1,160,061 | <p>Does the built-in Python math library basically use C's math library or does Python have a C-independent math library? Also, is the Python math library platform independent?</p>
| 3 | 2009-07-21T15:46:56Z | 1,160,104 | <p>at the bottom of <a href="http://docs.python.org/library/math.html" rel="nofollow">the page it says</a>:</p>
<blockquote>
<p><strong>Note:</strong> The <code>math</code> module consists mostly of thin wrappers around the platform C <code>math</code> library functions. Behavior in exceptional cases is loosely spec... | 5 | 2009-07-21T15:52:11Z | [
"python"
] |
Python Math Library Independent of C Math Library and Platform Independent? | 1,160,061 | <p>Does the built-in Python math library basically use C's math library or does Python have a C-independent math library? Also, is the Python math library platform independent?</p>
| 3 | 2009-07-21T15:46:56Z | 1,162,934 | <p>Python uses the C library it is linked against. On Windows, there is no 'platform C library'.. and indeed there are multiple versions of MicrosoftCRunTimeLibrarys (MSCRTs) around on any version.</p>
| 2 | 2009-07-22T03:33:02Z | [
"python"
] |
redirect browser in SimpleHTTPServer.py? | 1,160,329 | <p>I am partially through implementing the functionality of <a href="http://hg.python.org/cpython/file/tip/Lib/SimpleHTTPServer.py" rel="nofollow">SimpleHTTPServer.py</a> in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect brows... | 2 | 2009-07-21T16:39:40Z | 1,160,372 | <p>It simplifies things to treat the trailing / as irrelevant when the user does a GET on a directory, so that (say) <code>http://www.foo.com/bar</code> and <code>http://www.foo.com/bar/</code> have exactly the same effect. Simplest (though not fastest, see Souders' books;-) is to have the former cause a redirect to t... | 3 | 2009-07-21T16:47:06Z | [
"python",
"scheme",
"racket"
] |
redirect browser in SimpleHTTPServer.py? | 1,160,329 | <p>I am partially through implementing the functionality of <a href="http://hg.python.org/cpython/file/tip/Lib/SimpleHTTPServer.py" rel="nofollow">SimpleHTTPServer.py</a> in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect brows... | 2 | 2009-07-21T16:39:40Z | 1,160,445 | <p>Imagine you serve a page</p>
<pre><code>http://mydomain.com/bla
</code></pre>
<p>that contains</p>
<pre><code><a href="more.html">Read more...</a>
</code></pre>
<p>On click, the user's browser would retrieve <code>http://mydomain.com/more.html</code>. Had you instead served</p>
<pre><code>http://myd... | 3 | 2009-07-21T17:02:28Z | [
"python",
"scheme",
"racket"
] |
Where are Man -pages for the module MySQLdb in Python? | 1,160,345 | <p>I would like to get <a href="http://docs.python.org/" rel="nofollow">Python's documentation</a> for MySQLdb in Man -format such that I can read them in terminal.</p>
<p><strong>Where are Man -pages for MySQLdb in Python?</strong></p>
| 1 | 2009-07-21T14:05:54Z | 1,160,373 | <p>You may have to convert it yourself. MySQLdb doesn't come with man pages (as far as I know) but the documentation can be accessed e.g. from the <a href="http://mysql-python.sourceforge.net/" rel="nofollow">project page</a>. The user guide has a format reasonably similar to a man page so you could probably try to wor... | 1 | 2009-07-21T16:47:17Z | [
"python",
"mysql"
] |
Where are Man -pages for the module MySQLdb in Python? | 1,160,345 | <p>I would like to get <a href="http://docs.python.org/" rel="nofollow">Python's documentation</a> for MySQLdb in Man -format such that I can read them in terminal.</p>
<p><strong>Where are Man -pages for MySQLdb in Python?</strong></p>
| 1 | 2009-07-21T14:05:54Z | 1,160,424 | <p>Have you tried using pydoc? Try running the following command.</p>
<pre><code>pydoc MySQLdb
</code></pre>
<p>That should give you something close to what you're looking for.</p>
| 2 | 2009-07-21T16:57:06Z | [
"python",
"mysql"
] |
models.py getting huge, what is the best way to break it up? | 1,160,579 | <p>Directions from my supervisor:
"I want to avoid putting any logic in the <code>models.py</code>. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes that use the models classes, or wrap them."</p>
<p>I feel like this is the wrong way to go. I feel tha... | 72 | 2009-07-21T17:27:11Z | 1,160,607 | <p>Django is designed to let you build many small applications instead of one big application.</p>
<p>Inside every large application are many small applications struggling to be free.</p>
<p>If your <code>models.py</code> feels big, you're doing too much. Stop. Relax. Decompose.</p>
<p>Find smaller, potentially r... | 49 | 2009-07-21T17:32:43Z | [
"python",
"django",
"django-models",
"models"
] |
models.py getting huge, what is the best way to break it up? | 1,160,579 | <p>Directions from my supervisor:
"I want to avoid putting any logic in the <code>models.py</code>. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes that use the models classes, or wrap them."</p>
<p>I feel like this is the wrong way to go. I feel tha... | 72 | 2009-07-21T17:27:11Z | 1,160,735 | <p>It's natural for model classes to contain methods to operate on the model. If I have a Book model, with a method <code>book.get_noun_count()</code>, that's where it belongs--I don't want to have to write "<code>get_noun_count(book)</code>", unless the method actually intrinsically belongs with some other package. ... | 81 | 2009-07-21T18:02:38Z | [
"python",
"django",
"django-models",
"models"
] |
models.py getting huge, what is the best way to break it up? | 1,160,579 | <p>Directions from my supervisor:
"I want to avoid putting any logic in the <code>models.py</code>. From here on out, let's use that as only classes for accessing the database, and keep all logic in external classes that use the models classes, or wrap them."</p>
<p>I feel like this is the wrong way to go. I feel tha... | 72 | 2009-07-21T17:27:11Z | 1,160,973 | <p>I can't quite get which of many possible problems you might have. Here are some possibilities with answers:</p>
<ul>
<li><p>multiple models in the same file</p>
<p>Put them into separate files. If there are dependencies, use import to pull in the
additional models.</p></li>
<li><p>extraneous logic / utility funct... | 4 | 2009-07-21T18:42:12Z | [
"python",
"django",
"django-models",
"models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 1,160,696 | <p>There is no explicit Django support for postgreSQL schemas.</p>
<blockquote>
<p>When using Django (0.95), we had to add a search_path to the Django database connector for PostgreSQL, because Django didn't support specifying the schema that the tables managed by the ORM used.</p>
</blockquote>
<p>Taken from: </p>... | 2 | 2009-07-21T17:54:34Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 1,163,591 | <p>I've had some success just saying</p>
<pre><code>db_table = 'schema\".\"tablename'
</code></pre>
<p>in the Meta class, but that's really ugly. And I've only used it in limited scenarios - it may well break if you try something complicated. And as said earlier, it's not really supported...</p>
| 1 | 2009-07-22T07:21:09Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 1,628,855 | <p>I've been using:</p>
<pre><code>db_table = '"schema"."tablename"'
</code></pre>
<p>in the past without realising that only work for read-only operation. When you try to add new record it would fail because the sequence would be something like "schema.tablename"_column_id_seq.</p>
<pre><code>db_table = 'schema\".\... | 18 | 2009-10-27T05:02:51Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 1,912,906 | <p>It's a bit more complicated than tricky escaping. Have a look at Ticket <a href="http://code.djangoproject.com/ticket/6148" rel="nofollow">#6148</a> in Django for perhaps a solution or at least a patch. It makes some minor changes deep in the django.db core but it will hopefully be officially included in django.
Aft... | 10 | 2009-12-16T07:18:15Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 15,327,663 | <p>I know that this is a rather old question, but a different solution is to alter the SEARCH_PATH.</p>
<h2>Example</h2>
<p>Lets say you have three tables.</p>
<ol>
<li><code>schema1.table_name_a</code></li>
<li><code>schema2.table_name_b</code></li>
<li><code>table_name_c</code></li>
</ol>
<p>You could run the com... | 0 | 2013-03-10T21:10:36Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 18,391,525 | <p>As mentioned in the following ticket:
<a href="https://code.djangoproject.com/ticket/6148">https://code.djangoproject.com/ticket/6148</a>, we could set <code>search_path</code> for the django user.</p>
<p>One way to achieve this is to set <code>search_path</code> via <code>psql</code> client, like</p>
<pre><code>A... | 7 | 2013-08-22T21:58:38Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 28,452,103 | <p>Maybe this will help.</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'OPTIONS': {
'options': '-c search_path=your_schema'
},
'NAME': 'your_name',
'USER': 'your_user',
'PASSWORD': 'your_password',
'... | 7 | 2015-02-11T10:35:48Z | [
"python",
"django",
"postgresql",
"django-models"
] |
How to use schemas in Django? | 1,160,598 | <p>I whould like to use postgreSQL schemas with django, how can I do this?</p>
| 11 | 2009-07-21T17:30:53Z | 35,471,197 | <p>I just developed a package for this problem: <a href="https://github.com/ryannjohnson/django-schemas" rel="nofollow">https://github.com/ryannjohnson/django-schemas</a>.</p>
<p>After some configuration, you can simply call <code>set_db()</code> on your models:</p>
<pre><code>model_cls = UserModel.set_db(db='db_alia... | 3 | 2016-02-18T01:38:51Z | [
"python",
"django",
"postgresql",
"django-models"
] |
Django - last insert id | 1,161,149 | <p>I can't get the last insert id like I usually do and I'm not sure why.</p>
<p>In my view:</p>
<pre><code>comment = Comments( ...)
comment.save()
comment.id #returns None
</code></pre>
<p>In my Model:</p>
<pre><code>class Comments(models.Model):
id = models.IntegerField(primary_key=True)
</code></pre>
<p>Has... | 5 | 2009-07-21T19:12:17Z | 1,161,210 | <p>Do you want to specifically set a new IntegerField called id as the primary key? Because Django already does that for you for free...</p>
<p>That being said, have you tried removing the id field from your comment model?</p>
| 1 | 2009-07-21T19:23:48Z | [
"python",
"django"
] |
Django - last insert id | 1,161,149 | <p>I can't get the last insert id like I usually do and I'm not sure why.</p>
<p>In my view:</p>
<pre><code>comment = Comments( ...)
comment.save()
comment.id #returns None
</code></pre>
<p>In my Model:</p>
<pre><code>class Comments(models.Model):
id = models.IntegerField(primary_key=True)
</code></pre>
<p>Has... | 5 | 2009-07-21T19:12:17Z | 1,161,217 | <p>Are you setting the value of the <code>id</code> field in the <code>comment = Comments( ...)
</code> line? If not, why are you defining the field instead of just letting Django take care of the primary key with an AutoField?</p>
<p>If you specify in IntegerField as a primary key as you're doing in the example Djan... | 7 | 2009-07-21T19:25:00Z | [
"python",
"django"
] |
Django - last insert id | 1,161,149 | <p>I can't get the last insert id like I usually do and I'm not sure why.</p>
<p>In my view:</p>
<pre><code>comment = Comments( ...)
comment.save()
comment.id #returns None
</code></pre>
<p>In my Model:</p>
<pre><code>class Comments(models.Model):
id = models.IntegerField(primary_key=True)
</code></pre>
<p>Has... | 5 | 2009-07-21T19:12:17Z | 1,161,262 | <p>To define an automatically set primary key use AutoField:</p>
<pre><code>class Comments(models.Model):
id = models.AutoField(primary_key=True)
</code></pre>
| 2 | 2009-07-21T19:31:16Z | [
"python",
"django"
] |
Django - last insert id | 1,161,149 | <p>I can't get the last insert id like I usually do and I'm not sure why.</p>
<p>In my view:</p>
<pre><code>comment = Comments( ...)
comment.save()
comment.id #returns None
</code></pre>
<p>In my Model:</p>
<pre><code>class Comments(models.Model):
id = models.IntegerField(primary_key=True)
</code></pre>
<p>Has... | 5 | 2009-07-21T19:12:17Z | 19,051,158 | <p>Simply do </p>
<pre><code>c = Comment.object.latest()
</code></pre>
<p>That should return you the last inserted comment</p>
<pre><code>c.pk
12 #last comment saved.
</code></pre>
| 2 | 2013-09-27T12:47:00Z | [
"python",
"django"
] |
win32api.dll Will Not Install | 1,161,178 | <p>I am trying to start a Buildbot Buildslave on a Windows XP virtual machine:</p>
<pre><code>python buildbot start .
ImportError: No module named win32api.
</code></pre>
<p>Google tells me that win32api is win32api.dll. I downloaded the file from www.dll-files.com and followed the guide found on that site (<a href... | 2 | 2009-07-21T19:18:02Z | 1,162,307 | <p>win32api belongs <a href="http://sourceforge.net/projects/pywin32/files/">Python for Windows extensions</a>, Aka Pywn32.<br />
have u installed it?</p>
| 5 | 2009-07-21T23:33:03Z | [
"python",
"windows",
"dll",
"twisted",
"buildbot"
] |
win32api.dll Will Not Install | 1,161,178 | <p>I am trying to start a Buildbot Buildslave on a Windows XP virtual machine:</p>
<pre><code>python buildbot start .
ImportError: No module named win32api.
</code></pre>
<p>Google tells me that win32api is win32api.dll. I downloaded the file from www.dll-files.com and followed the guide found on that site (<a href... | 2 | 2009-07-21T19:18:02Z | 1,162,900 | <p>Install ActivePython (<a href="http://www.activestate.com/activepython/" rel="nofollow">http://www.activestate.com/activepython/</a>) - it's a Python distro that comes bundled with the Windows dlls. It's what everyone else does.</p>
| 0 | 2009-07-22T03:14:36Z | [
"python",
"windows",
"dll",
"twisted",
"buildbot"
] |
how do I read everything currently in a subprocess.stdout pipe and then return? | 1,161,580 | <p>I'm using python's subprocess module to interact with a program via the stdin and stdout pipes. If I call the subprocesses readline() on stdout, it hangs because it is waiting for a newline.</p>
<p>How can I do a read of all the characters in the stdout pipe of a subprocess instance? If it matters, I'm running in... | 1 | 2009-07-21T20:28:25Z | 1,161,599 | <p>You should loop using read() against a set number of characters. </p>
| 2 | 2009-07-21T20:32:09Z | [
"python",
"linux"
] |
how do I read everything currently in a subprocess.stdout pipe and then return? | 1,161,580 | <p>I'm using python's subprocess module to interact with a program via the stdin and stdout pipes. If I call the subprocesses readline() on stdout, it hangs because it is waiting for a newline.</p>
<p>How can I do a read of all the characters in the stdout pipe of a subprocess instance? If it matters, I'm running in... | 1 | 2009-07-21T20:28:25Z | 1,161,615 | <p>Someone else appears to have had the same problem, you can see the related discussion <a href="http://stackoverflow.com/questions/375427/non-blocking-read-on-a-stream-in-python">here</a>. </p>
<p>If you are running on Linux you can use select to wait for input on the process' stdout. Alternatively you change the mo... | 4 | 2009-07-21T20:36:52Z | [
"python",
"linux"
] |
Add data to Django form class using modelformset_factory | 1,161,618 | <p>I have a problem where I need to display a lot of forms for detail data for a hierarchical data set. I want to display some relational fields as labels for the forms and I'm struggling with a way to do this in a more robust way. Here is the code...</p>
<pre><code>class Category(models.Model):
name = models.Char... | 0 | 2009-07-21T20:37:45Z | 1,161,982 | <p>Well, I figured out the answer to my own question. I've overridden the init class on the form and accessed the instance of the model form. Works exactly as I wanted and it was easy.</p>
<pre><code>class BudgetValueForm(forms.ModelForm):
item = forms.ModelChoiceField(queryset=Item.objects.all(),widget=forms.Hid... | 3 | 2009-07-21T21:59:38Z | [
"python",
"django",
"django-forms"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,161,679 | <p>It'll depend on the project and the target audience.</p>
<p>If you're building an open source application/plug-in/library, stick with the PEP guidelines.</p>
<p>If this is a project for your company, stick with the company conventions, or something similar.</p>
<p>If this is your own personal project, then use wh... | 2 | 2009-07-21T20:52:16Z | [
"python",
"naming-conventions",
"notation"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,161,691 | <blockquote>
<p>(<strong>Almost every Python programmer will say</strong> it makes the code less readable, but I've become used to it and code written without these labels is the code that is less readable for me)</p>
</blockquote>
<p>FTFY.</p>
<p>Seriously though, it will help you but confuse and annoy other Pytho... | 8 | 2009-07-21T20:55:07Z | [
"python",
"naming-conventions",
"notation"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,161,696 | <p>I violate PEP8 in my code. I use: </p>
<ul>
<li>lowercaseCamelCase for methods and functions</li>
<li>_prefixedWithUnderscoreLowercaseCamelCase for "private" methods</li>
<li>underscore_spaced for variables (any)</li>
<li>_prefixed_with_underscore_variables for "private" self variables (attributes)</li>
<li>Capital... | 4 | 2009-07-21T20:55:35Z | [
"python",
"naming-conventions",
"notation"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,162,250 | <p>Use PEP-8. It is almost universal in the Python world.</p>
| 6 | 2009-07-21T23:16:28Z | [
"python",
"naming-conventions",
"notation"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,162,282 | <p>There exists a handy pep-8 compliance script you can run against your code:</p>
<p><a href="http://github.com/cburroughs/pep8.py/tree/master" rel="nofollow">http://github.com/cburroughs/pep8.py/tree/master</a></p>
| 3 | 2009-07-21T23:26:15Z | [
"python",
"naming-conventions",
"notation"
] |
Python Notation? | 1,161,658 | <p>I've just started using Python and I was thinking about which notation I should use. I've read the <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP 8</a> guide about notation for Python and I agree with most stuff there except function names (which I prefer in mixedCase style).</p>
<p>In C++ I ... | 2 | 2009-07-21T20:47:24Z | 1,165,299 | <p>You should simply be consistent with your naming conventions in your own code. However, if you intend to release your code to other developers you should stick to PEP-8.</p>
<p>For example the 4 spaces vs. 1 tab is a big deal when you have a collaborative project. People submitting code to a source repository with... | 1 | 2009-07-22T13:36:39Z | [
"python",
"naming-conventions",
"notation"
] |
Google Wave Sandbox | 1,161,660 | <p>Is anyone developing robots and/or gadgets for <a href="http://wave.google.com/" rel="nofollow">Google Wave</a>? </p>
<p>I have been a part of the sandbox development for a few days and I was interested in seeing what others have thought about the <a href="http://code.google.com/apis/wave/" rel="nofollow">Google Wa... | 3 | 2009-07-21T20:47:59Z | 1,161,806 | <p>Go to <a href="http://code.google.com/apis/wave/" rel="nofollow">Google Wave developers</a> and read the blogs, forums and all your questions will be answered including a recent post for a gallery of Wave apps. You will also find other developers to play in the sandbox with.</p>
| 2 | 2009-07-21T21:16:17Z | [
"java",
"python",
"google-app-engine",
"google-wave"
] |
Google Wave Sandbox | 1,161,660 | <p>Is anyone developing robots and/or gadgets for <a href="http://wave.google.com/" rel="nofollow">Google Wave</a>? </p>
<p>I have been a part of the sandbox development for a few days and I was interested in seeing what others have thought about the <a href="http://code.google.com/apis/wave/" rel="nofollow">Google Wa... | 3 | 2009-07-21T20:47:59Z | 1,174,595 | <p>I haven't tried the gadgets, but from the little I've looked at them, they seem pretty straight-forward. They're implemented in a template-ish way and you can easily keep states in them, allowing more complex things such as <a href="http://en.wiktionary.org/wiki/RSVP" rel="nofollow">RSVP</a> lists and even games.</p... | 2 | 2009-07-23T21:27:10Z | [
"java",
"python",
"google-app-engine",
"google-wave"
] |
Google Wave Sandbox | 1,161,660 | <p>Is anyone developing robots and/or gadgets for <a href="http://wave.google.com/" rel="nofollow">Google Wave</a>? </p>
<p>I have been a part of the sandbox development for a few days and I was interested in seeing what others have thought about the <a href="http://code.google.com/apis/wave/" rel="nofollow">Google Wa... | 3 | 2009-07-21T20:47:59Z | 1,175,722 | <p>I have been working on Gadgets, using the <a href="http://code.google.com/apis/wave/guide.html" rel="nofollow">Wave API</a>. It's pretty easy to work with. For the most part, you can use javascript inside an XML file. You just need to have the proper tags for the XML file. Below is a sample of what a Gadget would lo... | 2 | 2009-07-24T04:11:59Z | [
"java",
"python",
"google-app-engine",
"google-wave"
] |
Why can't I import this Zope component in a Python 2.4 virtualenv? | 1,161,670 | <p>I'm trying to install Plone 3.3rc4 with plone.app.blob and repoze but nothing I've tried has worked so far. For one attempt I've pip-installed repoze.zope2, Plone, and plone.app.blob into a virtualenv. I have <a href="http://svn.zope.org/Zope/trunk/lib/python/DocumentTemplate/?rev=96249" rel="nofollow">this version ... | -1 | 2009-07-21T20:50:12Z | 1,164,126 | <p>I must say I doubt DocumentTemplate from Zope will work standalone. You are welcome to try though. :-)</p>
<p>Note that <a href="https://github.com/zopefoundation/DocumentTemplate/blob/master/src/DocumentTemplate/DT_Util.py#L32-L34" rel="nofollow">DT_Util imports C extensions</a>:</p>
<pre><code>from DocumentTempl... | 1 | 2009-07-22T09:36:17Z | [
"python",
"virtualenv",
"zope"
] |
python docstrings | 1,161,810 | <p>ok so I decided to learn python (perl, c, c++, java, objective-c, ruby and a bit of erlang and scala under my belt). and I keep on getting the following error when I try executing this:</p>
<pre><code>Tue Jul 21{stevenhirsch@steven-hirschs-macbook-pro-2}/projects/python:-->./apache_logs.py
File "./apache_log... | 1 | 2009-07-21T21:17:43Z | 1,161,821 | <p>What version of Python do you have? In Python 3, <a href="http://docs.python.org/3.1/whatsnew/3.0.html#print-is-a-function"><code>print</code> was changed to work like a function</a> rather than a statement, i.e. <code>print('Hello World')</code> instead of <code>print 'Hello World'</code></p>
<p>I can recommend yo... | 5 | 2009-07-21T21:19:57Z | [
"python",
"syntax-error"
] |
Retrieving Raw_Input from a system ran script | 1,161,959 | <p>I'm using the OS.System command to call a python script.</p>
<p>example:</p>
<pre><code>OS.System("call jython script.py")
</code></pre>
<p>In the script I'm calling, the following command is present:</p>
<pre><code>x = raw_input("Waiting for input")
</code></pre>
<p>If I run script.py from the command line I c... | 0 | 2009-07-21T21:52:35Z | 1,162,165 | <p>Your question is a bit unclear. What is the process calling your Python script and how is it being run? If the parent process has no standard input, the child won't have it either.</p>
| 0 | 2009-07-21T22:52:15Z | [
"python",
"jython"
] |
Retrieving Raw_Input from a system ran script | 1,161,959 | <p>I'm using the OS.System command to call a python script.</p>
<p>example:</p>
<pre><code>OS.System("call jython script.py")
</code></pre>
<p>In the script I'm calling, the following command is present:</p>
<pre><code>x = raw_input("Waiting for input")
</code></pre>
<p>If I run script.py from the command line I c... | 0 | 2009-07-21T21:52:35Z | 1,162,243 | <p>The problem is the way you run your child script. Since you use os.system() the script's input channel is closed immediately and the raw_input() prompt hits an EOF (end of file). And even if that didn't happen, you wouldn't have a way to actually send some input text to the child as I assume you'd want given that yo... | 2 | 2009-07-21T23:14:22Z | [
"python",
"jython"
] |
limit output from a sort method | 1,162,142 | <p>if my views code is:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)
</code></pre>
<p>what is the argument that will limit the result to 50 tags?</p>
<p>I'm assuming this:</p>
<pre><code>.... limit=50)
</code></pre>
<p>is incorrect.</p>
<p>more complete code follow... | 0 | 2009-07-21T22:46:32Z | 1,162,159 | <p>You'll probably find that a slice works for you:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)[:50]
</code></pre>
| 1 | 2009-07-21T22:50:21Z | [
"python",
"django",
"itertools"
] |
limit output from a sort method | 1,162,142 | <p>if my views code is:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)
</code></pre>
<p>what is the argument that will limit the result to 50 tags?</p>
<p>I'm assuming this:</p>
<pre><code>.... limit=50)
</code></pre>
<p>is incorrect.</p>
<p>more complete code follow... | 0 | 2009-07-21T22:46:32Z | 1,162,213 | <p>The general idea of what you want is a <code>take</code>, I believe. From <a href="http://docs.python.org/library/itertools.html" rel="nofollow">the itertools documentation</a>:</p>
<pre><code>def take(n, iterable):
"Return first n items of the iterable as a list"
return list(islice(iterable, n))
</code></... | 0 | 2009-07-21T23:08:20Z | [
"python",
"django",
"itertools"
] |
limit output from a sort method | 1,162,142 | <p>if my views code is:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)
</code></pre>
<p>what is the argument that will limit the result to 50 tags?</p>
<p>I'm assuming this:</p>
<pre><code>.... limit=50)
</code></pre>
<p>is incorrect.</p>
<p>more complete code follow... | 0 | 2009-07-21T22:46:32Z | 1,162,595 | <p>what about <a href="http://docs.python.org/library/heapq.html#heapq.nlargest" rel="nofollow">heapq.nlargest</a>:<br />
Return a list with the n largest elements from the dataset defined by iterable.key, if provided, specifies a function of one argument that is used to extract a comparison key from each element in th... | 2 | 2009-07-22T01:26:51Z | [
"python",
"django",
"itertools"
] |
limit output from a sort method | 1,162,142 | <p>if my views code is:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)
</code></pre>
<p>what is the argument that will limit the result to 50 tags?</p>
<p>I'm assuming this:</p>
<pre><code>.... limit=50)
</code></pre>
<p>is incorrect.</p>
<p>more complete code follow... | 0 | 2009-07-21T22:46:32Z | 1,181,142 | <p>I think I was pretty much barking up the wrong tree. What I was trying to accomplish was actually very simple using a template filter (slice) which I didn't know I could do.
The code was as follows:</p>
<pre><code>{% for arttag in arttags|slice:":50" %}
</code></pre>
<p>Yes, I feel pretty stupid, but I'm glad I go... | 0 | 2009-07-25T03:48:12Z | [
"python",
"django",
"itertools"
] |
limit output from a sort method | 1,162,142 | <p>if my views code is:</p>
<pre><code>arttags = sorted(arttags, key=operator.attrgetter('date_added'), reverse=True)
</code></pre>
<p>what is the argument that will limit the result to 50 tags?</p>
<p>I'm assuming this:</p>
<pre><code>.... limit=50)
</code></pre>
<p>is incorrect.</p>
<p>more complete code follow... | 0 | 2009-07-21T22:46:32Z | 1,181,199 | <p>You might also want to add [:50] to each of the <code>objects.order_by.filter</code> calls. Doing that will mean you only ever have to sort 150 items in-memory in Python instead of possibly many more.</p>
| 0 | 2009-07-25T04:25:50Z | [
"python",
"django",
"itertools"
] |
How can I get DNS records for a domain in python? | 1,162,230 | <p>How do I get the DNS records for a zone in python? I'm looking for data similar to the output of <code>dig</code>.</p>
| 7 | 2009-07-21T23:11:15Z | 1,162,308 | <p>Try the <code>dnspython</code> library:</p>
<ul>
<li><a href="http://www.dnspython.org/">http://www.dnspython.org/</a></li>
</ul>
<p>You can see some examples here:</p>
<ul>
<li><a href="http://www.dnspython.org/examples.html">http://www.dnspython.org/examples.html</a></li>
</ul>
| 9 | 2009-07-21T23:33:22Z | [
"python",
"dns"
] |
How can I get DNS records for a domain in python? | 1,162,230 | <p>How do I get the DNS records for a zone in python? I'm looking for data similar to the output of <code>dig</code>.</p>
| 7 | 2009-07-21T23:11:15Z | 1,164,260 | <p>Your other option is <a href="http://pydns.sourceforge.net/" rel="nofollow">pydns</a> but the last release is as of 2008 so dnspython is probably a better bet (I only mention this in case dnspython doesn't float your boat).</p>
| 2 | 2009-07-22T10:08:20Z | [
"python",
"dns"
] |
How can I get DNS records for a domain in python? | 1,162,230 | <p>How do I get the DNS records for a zone in python? I'm looking for data similar to the output of <code>dig</code>.</p>
| 7 | 2009-07-21T23:11:15Z | 24,532,658 | <p>A simple example from <a href="http://c0deman.wordpress.com/2014/06/17/find-nameservers-of-domain-name-python/" rel="nofollow">http://c0deman.wordpress.com/2014/06/17/find-nameservers-of-domain-name-python/</a> :</p>
<pre><code>import dns.resolver
domain = 'google.com'
answers = dns.resolver.query(domain,'NS')
for... | 0 | 2014-07-02T13:38:34Z | [
"python",
"dns"
] |
What is the benefit of private name mangling in Python? | 1,162,234 | <p>Python provides <a href="http://docs.python.org/reference/expressions.html#atom-identifiers">private name mangling</a> for class methods and attributes.</p>
<p>Are there any concrete cases where this feature is required, or is it just a carry over from Java and C++?</p>
<p><strong>Please describe a use case where ... | 10 | 2009-07-21T23:11:31Z | 1,162,241 | <p>The name mangling is there to prevent accidental external attribute access. Mostly, it's there to make sure that there are no name clashes.</p>
| 0 | 2009-07-21T23:14:04Z | [
"python",
"private-members",
"name-mangling"
] |
What is the benefit of private name mangling in Python? | 1,162,234 | <p>Python provides <a href="http://docs.python.org/reference/expressions.html#atom-identifiers">private name mangling</a> for class methods and attributes.</p>
<p>Are there any concrete cases where this feature is required, or is it just a carry over from Java and C++?</p>
<p><strong>Please describe a use case where ... | 10 | 2009-07-21T23:11:31Z | 1,162,248 | <p>It's partly to prevent accidental <em>internal</em> attribute access. Here's an example:</p>
<p>In your code, which is a library:</p>
<pre><code>class YourClass:
def __init__(self):
self.__thing = 1 # Your private member, not part of your API
</code></pre>
<p>In my code, in which I'm inheri... | 22 | 2009-07-21T23:16:00Z | [
"python",
"private-members",
"name-mangling"
] |
What is the benefit of private name mangling in Python? | 1,162,234 | <p>Python provides <a href="http://docs.python.org/reference/expressions.html#atom-identifiers">private name mangling</a> for class methods and attributes.</p>
<p>Are there any concrete cases where this feature is required, or is it just a carry over from Java and C++?</p>
<p><strong>Please describe a use case where ... | 10 | 2009-07-21T23:11:31Z | 1,162,251 | <p>From <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a>:</p>
<blockquote>
<p>If your class is intended to be subclassed, and you have attributes that you do not want subclasses to use, consider naming them with double leading underscores and no trailing underscores. This invokes Python's name mangling ... | 15 | 2009-07-21T23:16:38Z | [
"python",
"private-members",
"name-mangling"
] |
Easiest way to pop up interactive Python console? | 1,162,277 | <p>My application has a Python interpreter embedded in it. However there's currently not any way to inspect anything about Python directly. I'd like to be able to pop up an interactive shell at various points to inspect what's going on in Python.</p>
<p>I've found several similar questions which pointed me to code.Int... | 2 | 2009-07-21T23:25:18Z | 1,162,325 | <p>What have you tried with IPython? Is it the snippets from the documentation:</p>
<ul>
<li><a href="http://ipython.scipy.org/doc/manual/html/interactive/reference.html#embedding-ipython" rel="nofollow">Embedding IPython</a> (IPython docs)</li>
</ul>
<p>How about some of the code samples from elsewhere:</p>
<ul>
<... | 1 | 2009-07-21T23:39:11Z | [
"python",
"debugging"
] |
Easiest way to pop up interactive Python console? | 1,162,277 | <p>My application has a Python interpreter embedded in it. However there's currently not any way to inspect anything about Python directly. I'd like to be able to pop up an interactive shell at various points to inspect what's going on in Python.</p>
<p>I've found several similar questions which pointed me to code.Int... | 2 | 2009-07-21T23:25:18Z | 1,162,883 | <p>I know this isn't what you're asking, but when I've wanted to debug compiled Python (using Py2Exe), I've been very pleased to realize that I can add breakpoints to the exe and it will actually stop there when I start the executable from a console window. Simply add:</p>
<pre><code>import pdb
pdb.set_trace()
</code... | 1 | 2009-07-22T03:08:27Z | [
"python",
"debugging"
] |
What's the right way to use Unicode metadata in setup.py? | 1,162,338 | <p>I was writing a setup.py for a Python package using setuptools and wanted to include a non-ASCII character in the long_description field:</p>
<pre><code>#!/usr/bin/env python
from setuptools import setup
setup(...
long_description=u"...", # in real code this value is read from a text file
...)
</code></... | 7 | 2009-07-21T23:43:53Z | 1,178,429 | <pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
setup(name="fudz",
description="fudzily",
version="0.1",
long_description=u"bläh bläh".encode("UTF-8"), # in real code this value is read from a text file
py_modules=["fudz"],
author="David Fraser",
... | 3 | 2009-07-24T15:29:14Z | [
"python",
"unicode",
"setuptools"
] |
What's the right way to use Unicode metadata in setup.py? | 1,162,338 | <p>I was writing a setup.py for a Python package using setuptools and wanted to include a non-ASCII character in the long_description field:</p>
<pre><code>#!/usr/bin/env python
from setuptools import setup
setup(...
long_description=u"...", # in real code this value is read from a text file
...)
</code></... | 7 | 2009-07-21T23:43:53Z | 1,182,262 | <p>You need to change your unicode long description <code>u"bläh bläh bläh"</code> to a normal string <code>"bläh bläh bläh"</code> and add an encoding header as the second line of your file:</p>
<pre><code>#!/usr/bin/env python
# encoding: utf-8
...
...
</code></pre>
<p>Obviously, you need to save the file wit... | 1 | 2009-07-25T15:02:47Z | [
"python",
"unicode",
"setuptools"
] |
What's the right way to use Unicode metadata in setup.py? | 1,162,338 | <p>I was writing a setup.py for a Python package using setuptools and wanted to include a non-ASCII character in the long_description field:</p>
<pre><code>#!/usr/bin/env python
from setuptools import setup
setup(...
long_description=u"...", # in real code this value is read from a text file
...)
</code></... | 7 | 2009-07-21T23:43:53Z | 1,439,009 | <p>It is apparently a distutils bug that has been fixed in python 2.6: <a href="http://mail.python.org/pipermail/distutils-sig/2009-September/013275.html" rel="nofollow">http://mail.python.org/pipermail/distutils-sig/2009-September/013275.html</a></p>
<p>Tarek suggests to patch post_to_server. The patch should pre-pr... | 5 | 2009-09-17T13:51:15Z | [
"python",
"unicode",
"setuptools"
] |
Python Hangs When Importing Swig Generated Wrapper | 1,162,461 | <p>Python is 'hanging' when I try to import a c++ shared library into the windows version of python 2.5 and I have no clue why.</p>
<p>On Linux, everything works fine. We can compile all of our C++ code, generate swig wrapper classes. They compile and can be imported and used in either python 2.5 or 2.6. Now, we ar... | 3 | 2009-07-22T00:29:21Z | 1,196,976 | <p>A technique I've used is to insert a "hard" breakpoint (<code>__asm int 3</code>) in the module init function. Then either run it through a debugger or just run it and let the windows debugger pop when the interrupt is called.</p>
<p>You can download a nice windows debugger from Microsoft <a href="http://www.micros... | 1 | 2009-07-28T21:54:50Z | [
"python",
"cygwin",
"swig"
] |
lxml retrieving odd items with cssselector | 1,162,580 | <p>In my test document I have a few classes labeled "item", currently I'm using the following to parse everything in the html file with this class with</p>
<pre><code>Selection = html.cssselect(".item")
</code></pre>
<p>I'd like it to select all the odd items, like this in javascript using JQuery</p>
<pre><code>Sele... | 1 | 2009-07-22T01:20:03Z | 1,215,852 | <p>The "odd" and "even" features are part of a selector named "nth-child()"; take a look at the CSS selector specification for more details:</p>
<pre><code>http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#nth-child-pseudo
</code></pre>
<p>Therefore, you should be able to get exactly the behavior you want (and it... | 1 | 2009-08-01T04:43:27Z | [
"python",
"css",
"html-parsing",
"lxml"
] |
Iterate over a string 2 (or n) characters at a time in Python | 1,162,592 | <p>Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like <code>"+c-R+D-E"</code> (there are a few extra letters).</p>
<p>I ended up with this, which works, but it looks ugly. I ended up commenting what it was doing because it felt non-obvious. It almost seems pyth... | 21 | 2009-07-22T01:24:53Z | 1,162,600 | <pre><code>>>> s = "+c-R+D-e"
>>> s
'+c-R+D-e'
>>> s[::2]
'+-+-'
>>>
</code></pre>
| 1 | 2009-07-22T01:28:28Z | [
"python",
"iteration"
] |
Iterate over a string 2 (or n) characters at a time in Python | 1,162,592 | <p>Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like <code>"+c-R+D-E"</code> (there are a few extra letters).</p>
<p>I ended up with this, which works, but it looks ugly. I ended up commenting what it was doing because it felt non-obvious. It almost seems pyth... | 21 | 2009-07-22T01:24:53Z | 1,162,624 | <p>Maybe this would be cleaner?</p>
<pre><code>s = "+c-R+D-e"
for i in xrange(0, len(s), 2):
op, code = s[i:i+2]
print op, code
</code></pre>
<p>You could perhaps write a generator to do what you want, maybe that would be more pythonic :)</p>
| 12 | 2009-07-22T01:35:35Z | [
"python",
"iteration"
] |
Iterate over a string 2 (or n) characters at a time in Python | 1,162,592 | <p>Earlier today I needed to iterate over a string 2 characters at a time for parsing a string formatted like <code>"+c-R+D-E"</code> (there are a few extra letters).</p>
<p>I ended up with this, which works, but it looks ugly. I ended up commenting what it was doing because it felt non-obvious. It almost seems pyth... | 21 | 2009-07-22T01:24:53Z | 1,162,627 | <pre><code>from itertools import izip_longest
def grouper(iterable, n, fillvalue=None):
args = [iter(iterable)] * n
return izip_longest(*args, fillvalue=fillvalue)
def main():
s = "+c-R+D-e"
for item in grouper(s, 2):
print ' '.join(item)
if __name__ == "__main__":
main()
##output
##+ c
##- ... | 4 | 2009-07-22T01:36:58Z | [
"python",
"iteration"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.