title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Python: Extract HTML from an XML file
1,814,923
<p>My XML file looks like this:</p> <pre><code> &lt;strings&gt; &lt;string&gt;Bla &lt;b&gt;One &amp;amp; Two&lt;/b&gt; Foo&lt;/string&gt; &lt;/strings&gt; </code></pre> <p>I want to extract the content of each &lt;string&gt; while maintaining the inner tags. That is, I would like to see the following Python st...
0
2009-11-29T07:38:31Z
1,814,964
<p>Regardless of the language, relatively simple XSLT template would do the trick.</p> <p>Something like defining patterns to tags you want to keep, converting to text others.</p> <p>You can of course use a recursive function with a compliant DOM implementation (minidom maybe?) and process tags by hand.</p> <p>(pseu...
0
2009-11-29T08:04:38Z
[ "python", "html", "xml", "lxml" ]
Python: Extract HTML from an XML file
1,814,923
<p>My XML file looks like this:</p> <pre><code> &lt;strings&gt; &lt;string&gt;Bla &lt;b&gt;One &amp;amp; Two&lt;/b&gt; Foo&lt;/string&gt; &lt;/strings&gt; </code></pre> <p>I want to extract the content of each &lt;string&gt; while maintaining the inner tags. That is, I would like to see the following Python st...
0
2009-11-29T07:38:31Z
1,815,027
<p>Not using parser, but just pure string manipulation</p> <pre><code>mystring=""" &lt;strings&gt; &lt;string&gt;Bla &lt;b&gt;One &amp;amp; Two&lt;/b&gt; Foo&lt;/string&gt; &lt;/strings&gt; """ for s in mystring.split("&lt;/string&gt;"): if "&lt;string&gt;" in s: i = s.index("&lt;string&gt;") ...
-1
2009-11-29T08:39:39Z
[ "python", "html", "xml", "lxml" ]
Python: Extract HTML from an XML file
1,814,923
<p>My XML file looks like this:</p> <pre><code> &lt;strings&gt; &lt;string&gt;Bla &lt;b&gt;One &amp;amp; Two&lt;/b&gt; Foo&lt;/string&gt; &lt;/strings&gt; </code></pre> <p>I want to extract the content of each &lt;string&gt; while maintaining the inner tags. That is, I would like to see the following Python st...
0
2009-11-29T07:38:31Z
1,816,305
<p>There may be a better way of conditionally handling objects returned by the <code>xpath()</code> function, but I'm not sufficiently conversant with <code>lxml</code> to know what it is, so I had to write a function to return the text value of a node. But that said, this shows a general approach to the problem:</p> ...
3
2009-11-29T18:28:44Z
[ "python", "html", "xml", "lxml" ]
What is wrong with my "digit finder" in python?
1,814,933
<p>I am learning python through the Project Euler problems. For <a href="http://projecteuler.net/index.php?section=problems&amp;id=40" rel="nofollow"> problem 40 </a> I wrote this code:</p> <pre><code>import math i = 1 counter = 0 while counter &lt;= 1000000: MMM = int(math.log(i, 10)) + 1 counter = counter +...
2
2009-11-29T07:45:04Z
1,814,990
<p>Floating point error somewhere along the way? It might be possible that at some point <code>math.log</code> is returning something that's barely less than (or greater, depending on the direction of your off-by-1 result) an integer boundary and thus <code>int()</code> is truncating it to the wrong value. Floating-poi...
4
2009-11-29T08:21:06Z
[ "python" ]
What is wrong with my "digit finder" in python?
1,814,933
<p>I am learning python through the Project Euler problems. For <a href="http://projecteuler.net/index.php?section=problems&amp;id=40" rel="nofollow"> problem 40 </a> I wrote this code:</p> <pre><code>import math i = 1 counter = 0 while counter &lt;= 1000000: MMM = int(math.log(i, 10)) + 1 counter = counter +...
2
2009-11-29T07:45:04Z
1,815,025
<p>I think this is the problem line</p> <pre><code>MMM = int(math.log(i, 10)) + 1 </code></pre> <p>Some examples</p> <pre><code>&gt;&gt;&gt; int(math.log(1000000, 10)) + 1 6 &gt;&gt;&gt; int(math.log(1000001, 10)) + 1 7 </code></pre> <p>Whereas I suspect you really wanted</p> <pre><code>&gt;&gt;&gt; len(str(100000...
3
2009-11-29T08:39:07Z
[ "python" ]
What is wrong with my "digit finder" in python?
1,814,933
<p>I am learning python through the Project Euler problems. For <a href="http://projecteuler.net/index.php?section=problems&amp;id=40" rel="nofollow"> problem 40 </a> I wrote this code:</p> <pre><code>import math i = 1 counter = 0 while counter &lt;= 1000000: MMM = int(math.log(i, 10)) + 1 counter = counter +...
2
2009-11-29T07:45:04Z
1,815,099
<p>The issue here is one of precision of floating point numbers which is not amazing. I gets fuzzier and fuzzier as the number of digits increase. This is the basic nature of floating point numbers, when you are doing this kind of math you need to be aware what precision you require. </p> <p>The standard library modul...
1
2009-11-29T09:37:04Z
[ "python" ]
List view is not refreshed if setTabText() is called
1,815,154
<p>Yes, I know this sounds crazy. But here's the situation.</p> <p>I composed a minimal code reproducing the bug. The code creates main window with <code>QTabWidget</code>, which, in turn, has one tab with <code>QListView</code> and a button. List view is connected to <code>QAbstractListModel</code>. Initially, list m...
0
2009-11-29T10:10:02Z
1,854,726
<p>Could not reproduce your problem using Linux, Qt 4.5.3, pyQt 4.5.4, python 2.5.2. </p> <p>I guess this is definitely version/platform-dependent. You should try Qt 4.5.3 + pyQt 4.5.4 + python 2.5.2 on MacOS. If you can reproduce the problem, it is more like a bug in MacOS qt port. If you can't you should try newer q...
0
2009-12-06T08:13:32Z
[ "python", "qt", "pyqt", "pyqt4" ]
Draw bold/italic text with PIL?
1,815,165
<p>How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.</p>
7
2009-11-29T10:16:04Z
1,815,170
<p>Many fonts use different TTF files for their bold/italic versions, so I'd imagine if you just specify that file it would work.</p>
3
2009-11-29T10:19:02Z
[ "python", "text", "fonts", "python-imaging-library", "draw" ]
Draw bold/italic text with PIL?
1,815,165
<p>How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.</p>
7
2009-11-29T10:16:04Z
1,815,171
<p>Use the bold/italic version of the font</p>
4
2009-11-29T10:19:17Z
[ "python", "text", "fonts", "python-imaging-library", "draw" ]
Draw bold/italic text with PIL?
1,815,165
<p>How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.</p>
7
2009-11-29T10:16:04Z
30,420,331
<p>Well, this is my first comment. Here we go.</p> <p>I'll try to clarify the procedure. At first What I did was use the "name" of the font like this</p> <pre><code>font = ImageFont.truetype("C:\Windows\Fonts\\Arial Negrita.ttf",25) </code></pre> <p>but only got some errors like this:</p> <pre><code> Traceback (...
1
2015-05-24T05:21:25Z
[ "python", "text", "fonts", "python-imaging-library", "draw" ]
Draw bold/italic text with PIL?
1,815,165
<p>How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only.</p>
7
2009-11-29T10:16:04Z
39,354,874
<p>A rather hacky solution to make a font bold if (for whatever reason) you don't have a separate bold version of the font is to print the same text several times with a slight offset.</p> <pre><code>andaleMono = ImageFont.truetype(ANDALE_MONO_PATH,16) text = "hello world" mainOffset = (50,50) xoff, yoff = mainOffset ...
1
2016-09-06T17:38:29Z
[ "python", "text", "fonts", "python-imaging-library", "draw" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,269
<p>For the finding</p> <pre><code>&gt;&gt;&gt; L = [('ba',4), ('hh',5), ('gg', 25)] &gt;&gt;&gt; [ i for i,l in enumerate(L) if l[0] == 'hh' ][0] 1 </code></pre> <p>You need to decide what to do if it is found multiple times or not at all - the above will throw <code>IndexError</code> if not found and return the firs...
3
2009-11-29T11:17:16Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,271
<p>to sort the list u can use a custom sort method some thing like this</p> <pre><code>x = [('ba',4), ('hh',5), ('gg', 25)] def sortMethod(x,y): if x[1] &lt; y[1]:return 1 elif x[1] &gt; y[1]:return -1 else: return 0 print x #unsorted x.sort(sortMethod) print x #sorted </code></pre>
1
2009-11-29T11:18:51Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,274
<p>First of, don't use <code>list</code> as the name for a variable, as it shadows the built-in <a href="http://docs.python.org/3.1/library/functions.html#list" rel="nofollow"><code>list</code></a> function.</p> <ol> <li><p>You can use <a href="http://docs.python.org/3.1/library/functions.html#enumerate" rel="nofollow...
5
2009-11-29T11:20:52Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,281
<p>you can also have your list in dictionary form</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] dict1 = dict(list1) print dict1['hh'] 5 </code></pre> <p>dicts are faster then list if you need to search like that.</p> <p>btw, overriding built-in type <code>list</code> to variables are not good idea <code>l...
1
2009-11-29T11:23:31Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,290
<p>For the sort, you should use itemgetter</p> <pre><code>&gt;&gt;&gt; import operator &gt;&gt;&gt; L = [('ba',4), ('hh',5), ('gg', 25)] &gt;&gt;&gt; sorted(L, key=operator.itemgetter(1)) [('ba', 4), ('hh', 5), ('gg', 25)] </code></pre>
1
2009-11-29T11:28:34Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,305
<p>I think Nick's sorting answer is good, but his find method unnecessarily iterates over the entire list, even after it has found a match. With a small change it can be fixed to stop iterating as soon as it finds the first element:</p> <pre><code>index = (i for i,l in enumerate(l) if l[0] == 'aa').next() </code></pre...
2
2009-11-29T11:36:29Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,364
<p>For the last question, convert list2 into a set:</p> <pre><code>&gt;&gt;&gt; list1 = [('ba',4), ('hh',5), ('gg', 25)] &gt;&gt;&gt; list2 = [('ja',40), ('hgh',88), ('hh', 2)] &gt;&gt;&gt; &gt;&gt;&gt; wanted = set(a for (a,b) in list2) &gt;&gt;&gt; for x in list1: ... if x[0] in wanted: ... print x ... ...
0
2009-11-29T12:13:12Z
[ "python", "list" ]
How do I check the index of a an element in a list? (Python)
1,815,258
<pre><code>list = [('ba',4), ('hh',5), ('gg', 25)] </code></pre> <p>How do I do:</p> <p>list.index('hh') ...and returns 1?</p> <p>Then, how do I sort it by the 25, 5, 4?</p> <p>What if I have 2 lists:</p> <pre><code>list1 = [('ba',4), ('hh',5), ('gg', 25)] list2 = [('ja',40), ('hgh',88), ('hh', 2)] </code></pre> ...
2
2009-11-29T11:13:08Z
1,815,432
<pre><code>from itertools import imap def find(iterable, item, key=None): """Find `item` in `iterable`. Return index of the found item or ``-1`` if there is none. Apply `key` function to items before comparison with `item`. ``key=None`` means an identity function. """ it = iter(iterable) if k...
1
2009-11-29T12:45:29Z
[ "python", "list" ]
Why can't I join this tuple in Python?
1,815,316
<pre><code>e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) </code></pre> <p>I have to join it so that I can write it into a text file.</p>
30
2009-11-29T11:41:34Z
1,815,318
<p>join() only works with strings, not with integers. Use ','.join(str(i) for i in e).</p>
7
2009-11-29T11:43:37Z
[ "python", "list", "tuples" ]
Why can't I join this tuple in Python?
1,815,316
<pre><code>e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) </code></pre> <p>I have to join it so that I can write it into a text file.</p>
30
2009-11-29T11:41:34Z
1,815,319
<p><code>join</code> only takes lists of strings, so convert them first</p> <pre><code>&gt;&gt;&gt; e = ('ham', 5, 1, 'bird') &gt;&gt;&gt; ','.join(map(str,e)) 'ham,5,1,bird' </code></pre> <p>Or maybe more pythonic</p> <pre><code>&gt;&gt;&gt; ','.join(str(i) for i in e) 'ham,5,1,bird' </code></pre>
62
2009-11-29T11:43:47Z
[ "python", "list", "tuples" ]
Why can't I join this tuple in Python?
1,815,316
<pre><code>e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) </code></pre> <p>I have to join it so that I can write it into a text file.</p>
30
2009-11-29T11:41:34Z
1,815,550
<p>Use the <a href="http://docs.python.org/library/csv.html" rel="nofollow"><code>csv</code></a> module. It will save a follow-up question about how to handle items containing a comma, followed by another about handling items containing the character that you used to quote/escape the commas.</p> <pre><code>import csv ...
2
2009-11-29T13:26:31Z
[ "python", "list", "tuples" ]
Why can't I join this tuple in Python?
1,815,316
<pre><code>e = ('ham', 5, 1, 'bird') logfile.write(','.join(e)) </code></pre> <p>I have to join it so that I can write it into a text file.</p>
30
2009-11-29T11:41:34Z
30,603,858
<p>You might be better off simply converting the tuple to a list first:</p> <p><code>e = ('ham', 5, 1, 'bird') liste = list(e) ','.join(liste)</code></p>
2
2015-06-02T18:32:20Z
[ "python", "list", "tuples" ]
How to pass an unicode char argument to ImageMagick?
1,815,427
<p>Suppose the char of "▣" is in somefont.ttf's glyph table. </p> <pre><code>char = unichr(9635) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', '-label:%s' % char, 'output.png']) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', ('-label:%s' % char).encode('utf-8'), 'ou...
0
2009-11-29T12:44:32Z
1,815,535
<ol> <li>Try to get it working by hand using ASCII labels in your console.</li> </ol> <pre> $ convert -font somefont.ttf -size 50x50 -label:A output.png convert: unrecognized option `-label:A' @ convert.c/ConvertImageCommand/1753. 1 ;( $ convert -font somefont.ttf -size 50x50 -label A output.png c...
0
2009-11-29T13:22:54Z
[ "python", "unicode" ]
How to pass an unicode char argument to ImageMagick?
1,815,427
<p>Suppose the char of "▣" is in somefont.ttf's glyph table. </p> <pre><code>char = unichr(9635) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', '-label:%s' % char, 'output.png']) subprocess.call(['convert', '-font', 'somefont.ttf', '-size', '50x50', ('-label:%s' % char).encode('utf-8'), 'ou...
0
2009-11-29T12:44:32Z
1,815,549
<p>According to <a href="http://www.imagemagick.org/Usage/text/#unicode" rel="nofollow">this link</a>, you need to pass the text encoded in UTF8. It will be able to draw the correct character outside ASCII range.</p>
1
2009-11-29T13:26:31Z
[ "python", "unicode" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,541
<p>The <code>sorted</code> function returns a <em>new</em> list so you will need to assign the results of the function like this:</p> <pre><code>new_list = sorted(statlist, key=lambda x: int(x[1])) </code></pre>
7
2009-11-29T13:24:08Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,545
<p>You can pass, key, and reverse to .sort function</p> <pre><code>&gt;&gt;&gt; x.sort(key=lambda x:x[1],reverse=True) &gt;&gt;&gt; x [('bzs', 66, 1), ('abc', 5, 1)] &gt;&gt;&gt; </code></pre>
3
2009-11-29T13:25:08Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,551
<pre><code>&gt;&gt;&gt; s = [('xyz', 8, 1), ('abc',5,1), ('bzs',66,1) ] &gt;&gt;&gt; s = sorted(s, key=lambda x: int(x[1])) &gt;&gt;&gt; s.reverse() &gt;&gt;&gt; print s [('bzs', 66, 1), ('xyz', 8, 1), ('abc', 5, 1)] </code></pre>
0
2009-11-29T13:26:54Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,552
<p>Use the <code>.sort</code> method for in place sorting:</p> <pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] statlist.sort(key=lambda x: int(x[1])) </code></pre> <p>If you do want to use <code>sorted</code>, then reassign the variable:</p> <pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] statlist = ...
7
2009-11-29T13:27:22Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,553
<pre><code>from operator import itemgetter statlist = [('abc',5,1), ('bzs',66,1), ... ] # statlist.sort modifiest the statlist, sorted returns a new one # reverse puts the largest items to the front statlist.sort(key=itemgetter(1), reverse=True) </code></pre>
2
2009-11-29T13:27:40Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,815,554
<p>for inplace sorting use</p> <pre><code>statlist.sort(key=lambda x: x[1]) </code></pre> <p>for creating other list, with sorted data use</p> <pre><code>otherlist = sorted( statlist, key=lambda x: x[1] ) </code></pre>
3
2009-11-29T13:27:41Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
1,817,834
<p>In response to alex's comment that he thought that sorted() worked "like the sort function":</p> <p>If it worked "like the sort function", it is unlikely to have been put in the library.</p> <p>In any case, there is no sort <em>function</em> ... you refer to the sort <em>method</em> of list objects.</p> <p>Simple...
1
2009-11-30T04:21:30Z
[ "python", "list", "tuples" ]
Why can't I sort this list?
1,815,528
<pre><code>statlist = [('abc',5,1), ('bzs',66,1), ... ] sorted(statlist, key=lambda x: int(x[1])) </code></pre> <p>I want to sort it by the integer largest to smallest. In this case, 5 and 66. But it doesn't seem to be working.</p>
3
2009-11-29T13:19:59Z
23,323,957
<p>Hey when ever I am saving something to an array I don't tend to worry about order and then at the end I use <code>sorted()</code> for example like this <code>statlist = sorted(statlist)</code> and if you wanted it largest to smallest <code>statlist = sorted(statlist, reverse = True)</code> That's the simple way of g...
0
2014-04-27T13:22:49Z
[ "python", "list", "tuples" ]
Compile IP2Location Python extension for Windows 7
1,815,689
<p>I want to compile / install the IP2Location Python extension found here:</p> <blockquote> <p>www.ip2location.com/python.aspx</p> </blockquote> <p>I tried following the instructions at these sites:</p> <blockquote> <p>eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/ bood...
1
2009-11-29T14:36:59Z
1,821,240
<p>Try adding <code>-lws2_32</code> option to linking command.</p> <p>BTW, there is another <a href="https://bitbucket.org/ods/ip2cc/" rel="nofollow">pure Python library</a> to get country from IP.</p>
1
2009-11-30T17:38:04Z
[ "python", "c", "windows" ]
Compile IP2Location Python extension for Windows 7
1,815,689
<p>I want to compile / install the IP2Location Python extension found here:</p> <blockquote> <p>www.ip2location.com/python.aspx</p> </blockquote> <p>I tried following the instructions at these sites:</p> <blockquote> <p>eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/ bood...
1
2009-11-29T14:36:59Z
1,835,554
<p>OK, so the full solution is:</p> <ol> <li>download stdint.h and put it in the IP2Location C Library folder: <a href="http://msinttypes.googlecode.com/svn/trunk/stdint.h" rel="nofollow">http://msinttypes.googlecode.com/svn/trunk/stdint.h</a></li> <li>open a dos prompt and execute "C:\Program Files\Microsoft Visual S...
2
2009-12-02T20:24:49Z
[ "python", "c", "windows" ]
What is the preferred technique to convert an object's properties to a sorted list of tuples?
1,815,693
<p>I'm working with an open-source library and they define a class like so:</p> <pre><code>class Provider(object): """ Defines for each of the supported providers """ DUMMY = 0 EC2 = 1 EC2_EU = 2 RACKSPACE = 3 SLICEHOST = 4 GOGRID = 5 VPSNET = 6 LINODE = 7 VCLOUD = 8 RIMUHOS...
1
2009-11-29T14:39:26Z
1,815,715
<p>If you are looking for class variables that are of the type integer, you could do it like this:</p> <pre><code>import inspect PROVIDER_CHOICES = inspect.getmembers(Foo, lambda x: isinstance(x, int)) </code></pre> <p>Check out the <a href="http://docs.python.org/library/inspect.html" rel="nofollow">inspect</a> modu...
6
2009-11-29T14:49:00Z
[ "python", "sorting" ]
What is the preferred technique to convert an object's properties to a sorted list of tuples?
1,815,693
<p>I'm working with an open-source library and they define a class like so:</p> <pre><code>class Provider(object): """ Defines for each of the supported providers """ DUMMY = 0 EC2 = 1 EC2_EU = 2 RACKSPACE = 3 SLICEHOST = 4 GOGRID = 5 VPSNET = 6 LINODE = 7 VCLOUD = 8 RIMUHOS...
1
2009-11-29T14:39:26Z
1,815,758
<p>If you worry about methods and other types of attributes just filter them out too.</p> <pre><code>PROVIDER_CHOICES = [(v,k) for k, v in vars(Provider).iteritems() if not k.startswith('_') and isinstance(v,int)] PROVIDER_CHOICES.sort( key=itemgetter(1) ) </code></pre> <p>You just have to r...
0
2009-11-29T15:08:19Z
[ "python", "sorting" ]
Get process argument info in windows with python/pywin32?
1,815,733
<p>In linux, I know with 'ps' you can get the arguments that a command was run with. I need the equivalent in windows</p> <p>Right now in python I'm doing <br><code>Process[i] = subprocess.Popen(cmd + " --daemon --config " + str(i) + ".conf", shell=False)</code></p> <p>But I'm doing this in a daemon that is meant to...
0
2009-11-29T14:59:33Z
1,816,791
<p><a href="http://stackoverflow.com/questions/440932/reading-command-line-arguments-of-another-process-win32-c-code">This one</a> might give you some inspiration.</p>
1
2009-11-29T21:11:12Z
[ "python", "api", "winapi", "process", "pywin32" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,764
<p>Why don't you just modify your output function based on whether the program is in quiet mode, so you only do the check once?</p> <pre><code>if QUIET: def DoOutput(stuff): pass else: def DoOutput(stuff): print(stuff) </code></pre> <p>Or, you could of course put the check for <code>QUIET</cod...
2
2009-11-29T15:10:41Z
[ "python" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,771
<p>If you want it quick and dirty and you want to get rid of <em>all</em> output then redirect stdout and stderr to /dev/null. Put:</p> <pre>sys.stdout = open("/dev/null", "a") sys.stderr = open("/dev/null", "a") </pre> <p>At the point where you detect --quiet.</p>
0
2009-11-29T15:12:32Z
[ "python" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,773
<p>You could use <a href="http://docs.python.org/library/logging.html"><code>logging</code></a> and assign those things that should not be printed if <code>QUIET</code> a different log level.</p> <p><strong>Edit:</strong> <a href="http://stackoverflow.com/questions/1815760/whats-an-easy-way-to-implement-a-quiet-option...
27
2009-11-29T15:13:45Z
[ "python" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,780
<pre><code>if QUIET: sys.stdout=open("/dev/null","w") ... print 'my output' </code></pre> <p>On Windows, use "nul" instead of "/dev/null"</p>
0
2009-11-29T15:15:53Z
[ "python" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,802
<p>can silence <strong>all</strong> the output by running it as <code>python myscript.py &gt; /dev/null</code></p> <p>change the output streams in the script:</p> <pre><code>if QUIET: sys.stdout = open(os.devnull,'a') sys.stderr = open(os.devnull,'a') print something </code></pre> <p>use a different print fu...
11
2009-11-29T15:27:21Z
[ "python" ]
What's an easy way to implement a --quiet option in a python script
1,815,760
<p>Am working on a command line python script - throughout the script, I have a lot of information I am <code>print</code>-ing to the terminal window so that I may follow along with what is happening.</p> <p>Using <code>OptionParser</code> I want to add a <code>--quiet</code> option so I can silence all the output. I...
12
2009-11-29T15:08:47Z
1,815,951
<p>You could replace stdout with a proxy that filters calls to write or writelines:</p> <pre><code>class FileProxy(object): def __init__(self, real_file, quiet_flag): self.real_file = real_file self.quiet_flag = quiet_flag def write(self, string): if not self.quiet_flag: se...
1
2009-11-29T16:21:08Z
[ "python" ]
How to create a generator/iterator with the Python C API?
1,815,812
<p>How do I replicate the following Python code with the Python C API?</p> <pre><code>class Sequence(): def __init__(self, max): self.max = max def data(self): i = 0 while i &lt; self.max: yield i i += 1 </code></pre> <p>So far, I have this:</p> <pre><code>#inc...
35
2009-11-29T15:30:12Z
1,815,839
<p>In <code>Sequence_data</code>, you must either return a new PyInt instance or throw a <code>StopIteration</code> exception which tells the code outside that there are no more values. See <a href="http://www.python.org/dev/peps/pep-0255/">PEP 255</a> for details and <a href="http://docs.python.org/tutorial/classes.ht...
6
2009-11-29T15:40:43Z
[ "python", "c", "iterator", "generator", "python-c-api" ]
How to create a generator/iterator with the Python C API?
1,815,812
<p>How do I replicate the following Python code with the Python C API?</p> <pre><code>class Sequence(): def __init__(self, max): self.max = max def data(self): i = 0 while i &lt; self.max: yield i i += 1 </code></pre> <p>So far, I have this:</p> <pre><code>#inc...
35
2009-11-29T15:30:12Z
1,816,961
<p>Below is a simple implementation of module <code>spam</code> with one function <code>myiter(int)</code> returning iterator:</p> <pre><code>import spam for i in spam.myiter(10): print i </code></pre> <p>prints numbers from 0 to 9.</p> <p>It is simpler then your case but shows main points: defining object with ...
51
2009-11-29T22:10:50Z
[ "python", "c", "iterator", "generator", "python-c-api" ]
Why does PIP install of python-couchdb experimental branch from SVN fail?
1,815,963
<p>I'm setting up a Fabric/virtualenv/pip automated deployment for a project and I need to install the latest experimental branch of python-couchdb. Naturally, I stick it in my pip requirements file, like so:</p> <pre><code>-e svn+http://couchdb-python.googlecode.com/svn/branches/experimental/httplib@195#egg=CouchDB-...
0
2009-11-29T16:25:54Z
1,817,014
<p>Per John Paulett's comment--you must indeed have subversion installed on the server in order to execute it on the server.</p> <p>I would like the egg delivered to my face chilled, if possible.</p>
1
2009-11-29T22:34:32Z
[ "python", "deployment", "virtualenv", "fabric", "pip" ]
want to develop a app in python which interacts with the web and posts on facebook , twitter and gtalk?
1,816,024
<p>i want to develop a python desktop app which interacts and posts its content on facebook , twitter or gtalk as a message . is it possible?... tutorials and ideas will help</p>
0
2009-11-29T16:46:27Z
1,816,029
<p>You can check out APIs of <a href="http://developers.facebook.com/" rel="nofollow">Facebook</a>, <a href="http://apiwiki.twitter.com/" rel="nofollow">Twitter</a> and <a href="http://code.google.com/apis/talk/" rel="nofollow">Gtalk</a></p>
2
2009-11-29T16:49:43Z
[ "python" ]
want to develop a app in python which interacts with the web and posts on facebook , twitter and gtalk?
1,816,024
<p>i want to develop a python desktop app which interacts and posts its content on facebook , twitter or gtalk as a message . is it possible?... tutorials and ideas will help</p>
0
2009-11-29T16:46:27Z
1,816,044
<p>The <a href="http://apiwiki.twitter.com/" rel="nofollow">Twitter API</a> will help you for Twitter, since it's intended to help you post messages. The Facebook API isn't actually what you want - it helps you write applications which run on Facebook, but doesn't necessarily help you communicate with Facebook the way...
5
2009-11-29T16:55:15Z
[ "python" ]
want to develop a app in python which interacts with the web and posts on facebook , twitter and gtalk?
1,816,024
<p>i want to develop a python desktop app which interacts and posts its content on facebook , twitter or gtalk as a message . is it possible?... tutorials and ideas will help</p>
0
2009-11-29T16:46:27Z
1,816,173
<p>If you can't find a facebook API to suit your needs, you'll have to make one from scratch. Try using the <a href="http://www.charlesproxy.com/" rel="nofollow">Charles web debugging proxy</a> to surf around facebook and post comments, add friends etc. It will reveal and log all the headers and GET/POST traffic. You c...
3
2009-11-29T17:45:03Z
[ "python" ]
How to convert seconds to hh:mm:ss with the Django's date template tag?
1,816,176
<p>Edit : is there a way to easily convert <code>{{ value|date:"Z" }}</code> to one of the +hh:mm or -hh:mm formats (because date:"Z" returns xxxx or -xxxx seconds).</p> <p>Show <a href="http://dev.w3.org/html5/spec/Overview.html#valid-global-date-and-time-string" rel="nofollow">this</a> for more explanations about th...
1
2009-11-29T17:46:02Z
1,816,686
<p>Instead of Z you need O (that's an "oh", not a "zero").</p> <pre><code>&gt;&gt;&gt; from django.template import * &gt;&gt;&gt; Template('{% now "Y-m-d\TH:i:sO" %}').render(Context()) u'2009-11-29T14:33:59-0600' </code></pre>
1
2009-11-29T20:36:58Z
[ "python", "django", "django-templates" ]
How to convert seconds to hh:mm:ss with the Django's date template tag?
1,816,176
<p>Edit : is there a way to easily convert <code>{{ value|date:"Z" }}</code> to one of the +hh:mm or -hh:mm formats (because date:"Z" returns xxxx or -xxxx seconds).</p> <p>Show <a href="http://dev.w3.org/html5/spec/Overview.html#valid-global-date-and-time-string" rel="nofollow">this</a> for more explanations about th...
1
2009-11-29T17:46:02Z
1,818,067
<p>Just clarifying here, it's the timezone offset that needs the colon, ie <code>2009-11-29T14:33:59-0600</code> in the above example should be <code>2009-11-29T14:33:59-06:00</code> to conform to the W3C guidelines.</p> <p>Looking at the code at <code>django/utils/dateformat.py</code>:</p> <pre><code> def O(self): ...
2
2009-11-30T06:02:38Z
[ "python", "django", "django-templates" ]
How to get the html source of a specific element with selenium?
1,816,232
<p>The page I'm looking at contains :</p> <pre><code>&lt;div id='1'&gt; &lt;p&gt; text 1 &lt;h1&gt; text 2 &lt;/h1&gt; text 3 &lt;p&gt; text 4 &lt;/p&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p>I want to get all the text in the div, except for the text that is in the <code>&lt;h&gt;</code>. (I want to get "text 1","...
7
2009-11-29T18:05:20Z
1,816,236
<p>What about using jQuery?</p> <p><strong>Edit:</strong></p> <p>First you have to add the required .JS files, for that go to www.jQuery.com.</p> <p>Then all you need to do is call a simple jQuery selector:</p> <pre><code>alert($("div#1").html()); </code></pre>
1
2009-11-29T18:07:07Z
[ "python", "selenium" ]
How to get the html source of a specific element with selenium?
1,816,232
<p>The page I'm looking at contains :</p> <pre><code>&lt;div id='1'&gt; &lt;p&gt; text 1 &lt;h1&gt; text 2 &lt;/h1&gt; text 3 &lt;p&gt; text 4 &lt;/p&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p>I want to get all the text in the div, except for the text that is in the <code>&lt;h&gt;</code>. (I want to get "text 1","...
7
2009-11-29T18:05:20Z
1,816,260
<p>Use xpath. From <code>selenium.py</code>:</p> <blockquote> <p>Without an explicit locator prefix, Selenium uses the following default strategies:</p> <ul> <li>\**dom**\ , for locators starting with "document."</li> <li>\**xpath**\ , for locators starting with "//"</li> <li>\**identifier**\ , otherwise<...
4
2009-11-29T18:14:55Z
[ "python", "selenium" ]
How to get the html source of a specific element with selenium?
1,816,232
<p>The page I'm looking at contains :</p> <pre><code>&lt;div id='1'&gt; &lt;p&gt; text 1 &lt;h1&gt; text 2 &lt;/h1&gt; text 3 &lt;p&gt; text 4 &lt;/p&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p>I want to get all the text in the div, except for the text that is in the <code>&lt;h&gt;</code>. (I want to get "text 1","...
7
2009-11-29T18:05:20Z
1,816,718
<p>The following code will give you the HTML in the div element:</p> <pre><code>sel = selenium('localhost', 4444, browser, my_url) html = sel.get_eval("this.browserbot.getCurrentWindow().document.getElementById('1').innerHTML") </code></pre> <p>then you can use BeautifulSoup to parse it and extract what you really wa...
8
2009-11-29T20:48:21Z
[ "python", "selenium" ]
How to get the html source of a specific element with selenium?
1,816,232
<p>The page I'm looking at contains :</p> <pre><code>&lt;div id='1'&gt; &lt;p&gt; text 1 &lt;h1&gt; text 2 &lt;/h1&gt; text 3 &lt;p&gt; text 4 &lt;/p&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p>I want to get all the text in the div, except for the text that is in the <code>&lt;h&gt;</code>. (I want to get "text 1","...
7
2009-11-29T18:05:20Z
35,824,416
<p>The selected answer does not work in Python 3 at the time of writing. Instead use this:</p> <pre><code>from selenium import webdriver wd = webdriver.Firefox() wd.get(url) return wd.execute_script('return window.document.getElementById('1').innerHTML') </code></pre>
0
2016-03-06T07:46:42Z
[ "python", "selenium" ]
Getting value of TextCtrl from a different wxPanel
1,816,353
<p>I was trying to get my first wxWindow application to work and I ran into following difficulty:<br> I create wxPanel and add a wxNotebook object to it. Then I add a page to notebook created from another wxPanel object. How do I access a value of TextCtrl from first wxPanel in the second one?</p> <pre><code>import wx...
2
2009-11-29T18:39:50Z
1,820,395
<p>One solution is to pass the control to the constructor of the tab, then you can directly reference it. For example:</p> <pre><code>class Tab1(wx.Panel): def __init__(self, parent, id, textCtrl1): wx.Panel.__init__(self, parent, id); self.textCtrl1 = textCtrl1 ... def Create_OnClick(self, event): t...
2
2009-11-30T15:14:52Z
[ "python", "wxpython" ]
Reloading a changed python file in emacs python shell
1,816,388
<p>In the emacs Python shell (I'm running 2.* Python) I am importing a .py file I'm working with and testing the code. If I change the code however I'm not sure how to import it again. </p> <p>From my reading so far it seems that </p> <pre><code>reload(modulename) </code></pre> <p>should work, but it doesn't seem to...
6
2009-11-29T18:49:50Z
1,816,438
<p>While <code>reload()</code> does work, it doesn't change references to classes, functions, and other objects, so it's easy to see an old version. A most consistent solution is to replace <code>reload()</code> with either <code>exec</code> (which means not using <code>import</code> in the first place) or restarting ...
15
2009-11-29T19:06:08Z
[ "python", "emacs" ]
Reloading a changed python file in emacs python shell
1,816,388
<p>In the emacs Python shell (I'm running 2.* Python) I am importing a .py file I'm working with and testing the code. If I change the code however I'm not sure how to import it again. </p> <p>From my reading so far it seems that </p> <pre><code>reload(modulename) </code></pre> <p>should work, but it doesn't seem to...
6
2009-11-29T18:49:50Z
1,816,464
<p>It seems to work for me:</p> <p>Make a file (in your PYTHONPATH) called test.py</p> <pre><code>def foo(): print('bar') </code></pre> <p>Then in the emacs python shell (or better yet, the ipython shell), type</p> <pre><code>&gt;&gt;&gt; import test &gt;&gt;&gt; test.foo() bar </code></pre> <p>Now modify test...
4
2009-11-29T19:11:24Z
[ "python", "emacs" ]
Python py2exe - memory load error
1,816,439
<p>I am creating a medium level application in Python. Everything works well now, and I am trying to make this a windows executable with py2exe. The executable is created fine, but when I try to run it, it fails with the following error.</p> <pre><code> File "zipextimporter.pyo", line 82, in load_module File "ffhan...
1
2009-11-29T19:06:32Z
1,816,495
<p>You're missing some DLL's in your build...</p> <p>First search your hard drive for the file <code>_pyAAC.pyd</code>. Make sure it is included (shipped) in your build.</p> <p>Then use <a href="http://www.dependencywalker.com/" rel="nofollow">'dependency walker'</a> on the .pyd file (in your py2exe compiled version!...
0
2009-11-29T19:24:13Z
[ "python", "py2exe" ]
Adding custom JS to a django admin field
1,816,444
<p>In a django application I have the following model:</p> <pre><code>class Appointment(models.Model): #some other fields #address fields zipcode=models.CharField(max_length=5) address=models.CharField(max_length=120) latitude=models.FloatField() longitude=models.FloatField() </code></pre> <p>...
6
2009-11-29T19:07:12Z
1,816,599
<p>There are several ways of doing this. You already mentioned some yourself.</p> <p>An option would be to override the template for the save page in your admin and add the needed code to the template. The needed media, Javascript, Css, etc, could be added using an inner Media class in your ModelAdmin class. This medi...
3
2009-11-29T20:02:29Z
[ "python", "django", "google-maps", "user-interface", "django-admin" ]
Adding custom JS to a django admin field
1,816,444
<p>In a django application I have the following model:</p> <pre><code>class Appointment(models.Model): #some other fields #address fields zipcode=models.CharField(max_length=5) address=models.CharField(max_length=120) latitude=models.FloatField() longitude=models.FloatField() </code></pre> <p>...
6
2009-11-29T19:07:12Z
1,816,992
<p>What is primarily being dealt with is client-side markup and client-side javascript. Being the case, it would seem that using a facility that's designed to handle those would be the proper choice. I'd also recommend making a custom admin widget. I've used this pattern myself. Depending on the size of the client-...
16
2009-11-29T22:24:14Z
[ "python", "django", "google-maps", "user-interface", "django-admin" ]
Python: How does inheritance of __slots__ in subclasses actually work?
1,816,483
<p>In the <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow">Python data model reference section on slots</a> there is a list of notes on using <code>__slots__</code>. I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> <p><strong>First...
40
2009-11-29T19:20:06Z
1,816,489
<p>My understanding is as follows:</p> <ul> <li><p>class <code>X</code> has no <code>__dict__</code> <code>&lt;-------&gt;</code> class <code>X</code> and its superclasses all have <code>__slots__</code> specified</p></li> <li><p>in this case, the actual slots of the class are comprised from the union of <code>__slots...
2
2009-11-29T19:22:38Z
[ "python", "inheritance", "subclass" ]
Python: How does inheritance of __slots__ in subclasses actually work?
1,816,483
<p>In the <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow">Python data model reference section on slots</a> there is a list of notes on using <code>__slots__</code>. I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> <p><strong>First...
40
2009-11-29T19:20:06Z
1,816,511
<pre><code>class WithSlots(object): __slots__ = "a_slot" class NoSlots(object): # This class has __dict__ pass </code></pre> <h2>First Item</h2> <pre><code>class A(NoSlots): # even though A has __slots__, it inherits __dict__ __slots__ = "a_slot" # from NoSlots, therefore __slots__ h...
9
2009-11-29T19:34:53Z
[ "python", "inheritance", "subclass" ]
Python: How does inheritance of __slots__ in subclasses actually work?
1,816,483
<p>In the <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow">Python data model reference section on slots</a> there is a list of notes on using <code>__slots__</code>. I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> <p><strong>First...
40
2009-11-29T19:20:06Z
1,816,513
<p>From the answer you linked:</p> <blockquote> <p>The proper use of <code>__slots__</code> is to save space in objects. Instead of having a dynamic dict...</p> </blockquote> <p>"When inheriting from a class without <code>__slots__</code>, the <code>__dict__</code> attribute of that class will always be accessible"...
3
2009-11-29T19:35:17Z
[ "python", "inheritance", "subclass" ]
Python: How does inheritance of __slots__ in subclasses actually work?
1,816,483
<p>In the <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow">Python data model reference section on slots</a> there is a list of notes on using <code>__slots__</code>. I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> <p><strong>First...
40
2009-11-29T19:20:06Z
1,816,648
<p>As others have mentioned, the sole reason for defining <code>__slots__</code> is to save some memory, when you have simple objects with a predefined set of attributes and don't want each to carry around a dictionary. This is meaningful only for classes of which you plan to have many instances, of course.</p> <p>Th...
75
2009-11-29T20:20:43Z
[ "python", "inheritance", "subclass" ]
Python: How does inheritance of __slots__ in subclasses actually work?
1,816,483
<p>In the <a href="http://docs.python.org/reference/datamodel.html#slots" rel="nofollow">Python data model reference section on slots</a> there is a list of notes on using <code>__slots__</code>. I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> <p><strong>First...
40
2009-11-29T19:20:06Z
39,002,394
<blockquote> <h1>Python: How does inheritance of <code>__slots__</code> in subclasses actually work?</h1> <p>I am thoroughly confused by the 1st and 6th items, because they seem to be contradicting each other. </p> </blockquote> <p>Those items don't actually contradict each other. The first regards subclasses o...
2
2016-08-17T16:58:41Z
[ "python", "inheritance", "subclass" ]
Dynamic URL's inside Google's AppEngine
1,816,529
<p>Good Afternoon,</p> <p>I'm currently trying to build something incredibly simple inside of the Google AppEngine. The goal is to build a simple photo sharing application that will connect back to my iPhone application. It's all a learning experience for both Python and Objective-C. </p> <p>(I've been a PHP progr...
3
2009-11-29T19:41:20Z
1,816,816
<p>A simple way to grab them all:</p> <pre><code>photos = Photo.gql('ORDER BY __key__') </code></pre> <p>For more, see <a href="http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html#Queries%5Fon%5FKeys" rel="nofollow">Queries on Keys</a> in the App Engine docs.</p> <p>Are you storing your pho...
3
2009-11-29T21:18:52Z
[ "python", "google-app-engine", "dynamic-url" ]
Getting Unique Foreign Keys in Django?
1,816,572
<p>Suppose my model looks like this:</p> <pre><code>class Farm(models.Model): name = ... class Tree(models.Model): farm = models.ForeignKey(Farm) </code></pre> <p>...and I get a <code>QuerySet</code> of <code>Tree</code> objects. How do I determine what farms are represented in that <code>QuerySet</code>?</p>
4
2009-11-29T19:55:34Z
1,816,583
<p>There might be a better way to do it with the Django ORM and keep it lazy but you can get what you want with regular python (off the top of my head):</p> <pre><code>&gt;&gt;&gt; set([ t.farm for t in qs ]) </code></pre>
4
2009-11-29T19:59:23Z
[ "python", "django", "django-models" ]
Getting Unique Foreign Keys in Django?
1,816,572
<p>Suppose my model looks like this:</p> <pre><code>class Farm(models.Model): name = ... class Tree(models.Model): farm = models.ForeignKey(Farm) </code></pre> <p>...and I get a <code>QuerySet</code> of <code>Tree</code> objects. How do I determine what farms are represented in that <code>QuerySet</code>?</p>
4
2009-11-29T19:55:34Z
1,816,820
<p>Here is a way to have the database do the work for you:</p> <pre><code>farms = qs.values_list('farm', flat=True).distinct() #values_list() is new in Django 1.0 </code></pre> <p>return value should evaluate to something like:</p> <pre><code>(&lt;Farm instance 1&gt;, &lt;Farm instance5&gt;) </code></pre> <p>were ...
0
2009-11-29T21:20:32Z
[ "python", "django", "django-models" ]
Getting Unique Foreign Keys in Django?
1,816,572
<p>Suppose my model looks like this:</p> <pre><code>class Farm(models.Model): name = ... class Tree(models.Model): farm = models.ForeignKey(Farm) </code></pre> <p>...and I get a <code>QuerySet</code> of <code>Tree</code> objects. How do I determine what farms are represented in that <code>QuerySet</code>?</p>
4
2009-11-29T19:55:34Z
1,817,003
<p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#in">http://docs.djangoproject.com/en/dev/ref/models/querysets/#in</a></p> <pre><code>Farm.objects.filter(tree__in=TreeQuerySet) </code></pre>
6
2009-11-29T22:29:00Z
[ "python", "django", "django-models" ]
Why does csvwriter.writerow() put a comma after each character?
1,816,880
<p>This code opens the url and appends the <code>/names</code> at the end and opens the page and prints the string to <code>test1.csv</code>:</p> <pre><code>import urllib2 import re import csv url = ("http://www.example.com") bios = [u'/name1', u'/name2', u'/name3'] csvwriter = csv.writer(open("/test1.csv", "a")) fo...
36
2009-11-29T21:45:43Z
1,816,897
<p>It expects a sequence (eg: a list or tuple) of strings. You're giving it a single string. A string happens to be a sequence of strings too, but it's a sequence of 1 character strings, which isn't what you want.</p> <p>If you just want one string per row you could do something like this:</p> <pre><code>csvwriter.wr...
63
2009-11-29T21:50:37Z
[ "python", "csv" ]
Why does csvwriter.writerow() put a comma after each character?
1,816,880
<p>This code opens the url and appends the <code>/names</code> at the end and opens the page and prints the string to <code>test1.csv</code>:</p> <pre><code>import urllib2 import re import csv url = ("http://www.example.com") bios = [u'/name1', u'/name2', u'/name3'] csvwriter = csv.writer(open("/test1.csv", "a")) fo...
36
2009-11-29T21:45:43Z
1,816,900
<p>This happens, because when group() method of a MatchObject instance returns only a single value, it returns it as a string. When there are multiple values, they are returned as a tuple of strings.</p> <p>If you are writing a row, I guess, csv.writer iterates over the object you pass to it. If you pass a single stri...
1
2009-11-29T21:52:28Z
[ "python", "csv" ]
Why does csvwriter.writerow() put a comma after each character?
1,816,880
<p>This code opens the url and appends the <code>/names</code> at the end and opens the page and prints the string to <code>test1.csv</code>:</p> <pre><code>import urllib2 import re import csv url = ("http://www.example.com") bios = [u'/name1', u'/name2', u'/name3'] csvwriter = csv.writer(open("/test1.csv", "a")) fo...
36
2009-11-29T21:45:43Z
1,816,905
<p>The csv.writer class takes an iterable as it's argument to writerow; as strings in Python are iterable by character, they are an acceptable argument to writerow, but you get the above output.</p> <p>To correct this, you could split the value based on whitespace (I'm assuming that's what you want)</p> <pre><code>cs...
5
2009-11-29T21:53:04Z
[ "python", "csv" ]
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
1,816,958
<p>I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:</p> <pre><code>import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) print pool.map(f, range(10)) if __name__== '_...
125
2009-11-29T22:08:35Z
1,816,969
<p>The problem is that multiprocessing must pickle things to sling them among processes, and bound methods are not picklable. The workaround (whether you consider it "easy" or not;-) is to add the infrastructure to your program to allow such methods to be pickled, registering it with the <a href="http://docs.python.or...
74
2009-11-29T22:16:14Z
[ "python", "multithreading", "multiprocessing", "pickle", "pool" ]
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
1,816,958
<p>I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:</p> <pre><code>import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) print pool.map(f, range(10)) if __name__== '_...
125
2009-11-29T22:08:35Z
6,975,654
<p>You could also define a <code>__call__()</code> method inside your <code>someClass()</code>, which calls <code>someClass.go()</code> and then pass an instance of <code>someClass()</code> to the pool. This object is pickleable and it works fine (for me)...</p>
22
2011-08-07T20:40:35Z
[ "python", "multithreading", "multiprocessing", "pickle", "pool" ]
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
1,816,958
<p>I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:</p> <pre><code>import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) print pool.map(f, range(10)) if __name__== '_...
125
2009-11-29T22:08:35Z
7,309,686
<p>Some limitations though to Steven Bethard's solution :</p> <p>When you register your class method as a function, the destructor of your class is surprisingly called every time your method processing is finished. So if you have 1 instance of your class that calls n times its method, members may disappear between 2 r...
14
2011-09-05T14:50:52Z
[ "python", "multithreading", "multiprocessing", "pickle", "pool" ]
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
1,816,958
<p>I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:</p> <pre><code>import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) print pool.map(f, range(10)) if __name__== '_...
125
2009-11-29T22:08:35Z
10,217,089
<p>There's another short-cut you can use, although it can be inefficient depending on what's in your class instances.</p> <p>As everyone has said the problem is that the <code>multiprocessing</code> code has to pickle the things that it sends to the sub-processes it has started, and the pickler doesn't do instance-met...
6
2012-04-18T20:01:54Z
[ "python", "multithreading", "multiprocessing", "pickle", "pool" ]
Can't pickle <type 'instancemethod'> when using python's multiprocessing Pool.map()
1,816,958
<p>I'm trying to use multiprocessing's Pool.map() function to divide out work simultaneously. When I use the following code, it works fine:</p> <pre><code>import multiprocessing def f(x): return x*x def go(): pool = multiprocessing.Pool(processes=4) print pool.map(f, range(10)) if __name__== '_...
125
2009-11-29T22:08:35Z
21,345,273
<p>All of these solutions are ugly because multiprocessing and pickling is broken and limited unless you jump outside the standard library.</p> <p>If you use a fork of <code>multiprocessing</code> called <code>pathos.multiprocesssing</code>, you can directly use classes and class methods in multiprocessing's <code>map...
34
2014-01-25T01:11:46Z
[ "python", "multithreading", "multiprocessing", "pickle", "pool" ]
Enable pylint in Netbeans
1,817,047
<p>How can I integrate pylint with netbeans?</p>
3
2009-11-29T22:46:39Z
1,818,377
<p>I haven't tried this myself, but this website:</p> <p><a href="http://jpydbg.sourceforge.net/" rel="nofollow">http://jpydbg.sourceforge.net/</a></p> <p>seems to document a method to get it working.</p>
1
2009-11-30T07:48:36Z
[ "python", "netbeans", "pylint" ]
Enable pylint in Netbeans
1,817,047
<p>How can I integrate pylint with netbeans?</p>
3
2009-11-29T22:46:39Z
1,881,618
<p>There's a PyLint plugin for <a href="http://eric-ide.python-projects.org/" rel="nofollow">Eric</a>. It's a nice little open source IDE for aimed particularly for Python and Ruby. Perhaps you will find it useful. </p>
0
2009-12-10T15:12:29Z
[ "python", "netbeans", "pylint" ]
Enable pylint in Netbeans
1,817,047
<p>How can I integrate pylint with netbeans?</p>
3
2009-11-29T22:46:39Z
1,897,207
<p>On the netbeans-python (nbpython) dev list there seems to be a whole thread about this: <a href="http://markmail.org/message/rrjcooygoleufje6" rel="nofollow">http://markmail.org/message/rrjcooygoleufje6</a></p> <p>So, seemingly, it's not ready yet.</p> <p>In light of that, you might want to check out the alternati...
0
2009-12-13T18:08:31Z
[ "python", "netbeans", "pylint" ]
get `object.__doc__` as raw string
1,817,064
<p>Is there a way to get <code>object.__doc__</code> as a raw string, apart from adding an 'r' in-front of the doctring itself in the source code?</p> <p>I have latex code inside and the '\r's, '\f's etc are creating problems.</p>
0
2009-11-29T22:54:01Z
1,817,070
<p>No, you have to add the r. If you don't add the r, there's no way you can be sure to get back the original string no matter what you do.</p> <p>If you don't like raw strings the other alternative is to escape your backslashes in the strings with an extra backslash.</p>
2
2009-11-29T22:58:07Z
[ "python", "pydoc" ]
get `object.__doc__` as raw string
1,817,064
<p>Is there a way to get <code>object.__doc__</code> as a raw string, apart from adding an 'r' in-front of the doctring itself in the source code?</p> <p>I have latex code inside and the '\r's, '\f's etc are creating problems.</p>
0
2009-11-29T22:54:01Z
1,817,077
<p>the difference between a raw string and otherwise is just a matter of source code literal syntax. once parsed, there is no 'raw' string object. the result of <code>repr(object.__doc__)</code> will always be such that you can copy and paste the result into a python source script and get the original string. </p> ...
2
2009-11-29T23:00:31Z
[ "python", "pydoc" ]
get `object.__doc__` as raw string
1,817,064
<p>Is there a way to get <code>object.__doc__</code> as a raw string, apart from adding an 'r' in-front of the doctring itself in the source code?</p> <p>I have latex code inside and the '\r's, '\f's etc are creating problems.</p>
0
2009-11-29T22:54:01Z
1,817,081
<p>There's no such Python type as "raw string" -- there are <em>raw string <strong>literals</strong></em>, which are just one <strong>syntax</strong> approach (out of many) to specify constants (i.e., literals) that are of string types. So "getting" something "as a raw string" just makes no sense. You can <strong>wri...
7
2009-11-29T23:01:33Z
[ "python", "pydoc" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,153
<p>If they're all within a single module, then they only live in that module's namespace and you don't have to worry about name clashes. (And you can still import them into other namesapaces)</p> <p>For example</p> <p>MyModWithContstants.py</p> <pre><code>x = 0 y = 0 def someFunc(): dosomethingwithconstants(x,y) ...
12
2009-11-29T23:35:36Z
[ "python" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,157
<p>You could simply declare these variables at the module level (i.e. the top level of the <code>.py</code> source file) and there will be no need to use <code>self</code> or anything like that. In that case I think the convention would be to give them uppercase names.</p> <p>By the way, I can't help but point out tha...
1
2009-11-29T23:35:57Z
[ "python" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,176
<p>Have you considered </p> <pre><code>global x, y, z x=0 y=1 z=2 </code></pre> <p>?</p>
0
2009-11-29T23:40:55Z
[ "python" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,185
<p>If these "variables" are truly constants declaring them at module level seems logical. If you have to modify them from inside a function you just have to declare them global in that function.</p>
1
2009-11-29T23:46:54Z
[ "python" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,195
<pre>import __builtin__ __builtin__.__dict__["X"] = 5</pre> <p>This will store the X constant in all modules executed until the interpreter exits.</p> <p>Remember though to use it with care, as other python developers are not likely to expect this. I use it mainly for storing the translation function '_'.</p>
-1
2009-11-29T23:54:09Z
[ "python" ]
Constants in python?
1,817,144
<p>I have the following variables declared in a lot of functions, as I need those values in each one of them. Is there anyway I can declare them at a global scope or something, such as I won't have to declare them in all my methods? I am using all this methods on instance methods of a class of mine.</p> <pre><code>x =...
3
2009-11-29T23:32:25Z
1,817,319
<p>In addition to the separate module trick, if I want them in the same module I'll often put them in a class, <a href="http://pypi.python.org/pypi/winpaths/0.1" rel="nofollow">like this</a>:</p> <pre><code>class PathConstants(object): CSIDL_DESKTOP = 0 CSIDL_PROGRAMS = 2 def get_desktop(): return _get_pa...
5
2009-11-30T00:38:04Z
[ "python" ]
Using super with a class method
1,817,183
<p><strong>I'm trying to learn myself the super() function in Python.</strong></p> <p>I though I got a grasp of it untill I came over this example (2.6) and found myself stuck.</p> <p><a href="http://www.cafepy.com/article/python%5Fattributes%5Fand%5Fmethods/python%5Fattributes%5Fand%5Fmethods.html#super-with-classme...
24
2009-11-29T23:45:58Z
1,817,242
<p>The example from the web page seems to work as published. Did you create a <code>do_something</code> method for the superclass as well but not make it into a classmethod? Something like this will give you that error:</p> <pre><code>&gt;&gt;&gt; class A(object): ... def do_something(cls): ... print cls...
3
2009-11-30T00:10:37Z
[ "python", "class", "object", "super", "class-method" ]
Using super with a class method
1,817,183
<p><strong>I'm trying to learn myself the super() function in Python.</strong></p> <p>I though I got a grasp of it untill I came over this example (2.6) and found myself stuck.</p> <p><a href="http://www.cafepy.com/article/python%5Fattributes%5Fand%5Fmethods/python%5Fattributes%5Fand%5Fmethods.html#super-with-classme...
24
2009-11-29T23:45:58Z
1,817,840
<p>Sometimes texts have to be read more for the flavor of the idea rather than for the details. This is one of those cases.</p> <p>In the <a href="http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#a-super-solution">linked page</a>, Examples 2.5, 2.6 and 2.7 should all use o...
31
2009-11-30T04:22:56Z
[ "python", "class", "object", "super", "class-method" ]
Using super with a class method
1,817,183
<p><strong>I'm trying to learn myself the super() function in Python.</strong></p> <p>I though I got a grasp of it untill I came over this example (2.6) and found myself stuck.</p> <p><a href="http://www.cafepy.com/article/python%5Fattributes%5Fand%5Fmethods/python%5Fattributes%5Fand%5Fmethods.html#super-with-classme...
24
2009-11-29T23:45:58Z
1,821,055
<p>I think I've understood the point now thanks to this beatiful site and lovely community.</p> <p>If you don't mind please correct me if I'm wrong on classmethods (which I am now trying to understand fully):</p> <pre><code> # EXAMPLE #1 >>> class A(object): ... def foo(cls): ... print cls ... foo...
0
2009-11-30T17:01:05Z
[ "python", "class", "object", "super", "class-method" ]
Using super with a class method
1,817,183
<p><strong>I'm trying to learn myself the super() function in Python.</strong></p> <p>I though I got a grasp of it untill I came over this example (2.6) and found myself stuck.</p> <p><a href="http://www.cafepy.com/article/python%5Fattributes%5Fand%5Fmethods/python%5Fattributes%5Fand%5Fmethods.html#super-with-classme...
24
2009-11-29T23:45:58Z
1,837,987
<p>I've updated the article to make it a bit clearer: <a href="http://www.cafepy.com/article/python%5Fattributes%5Fand%5Fmethods/python%5Fattributes%5Fand%5Fmethods.html#a-super-solution" rel="nofollow">Python Attributes and Methods # Super</a></p> <p>Your example using classmethod above shows what a class method is -...
2
2009-12-03T06:11:25Z
[ "python", "class", "object", "super", "class-method" ]
Beautifulsoup get value in table
1,817,184
<p>I am trying to scrape <a href="http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104" rel="nofollow">http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104</a> and get the "owner Name(s)" What I have works but is really ugly and not the best I am sure, so I am looking for a better way. Here is what ...
1
2009-11-29T23:46:14Z
1,817,239
<p>This is a slight improvement, but I couldn't figure out how to get rid of the three parents.</p> <pre><code>x[0].parent.parent.parent.findAll('td')[1].string </code></pre>
1
2009-11-30T00:08:25Z
[ "python", "screen-scraping", "beautifulsoup", "html-content-extraction" ]
Beautifulsoup get value in table
1,817,184
<p>I am trying to scrape <a href="http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104" rel="nofollow">http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104</a> and get the "owner Name(s)" What I have works but is really ugly and not the best I am sure, so I am looking for a better way. Here is what ...
1
2009-11-29T23:46:14Z
1,817,314
<p>(<strong>Edit</strong>: apparently the HTML the OP posted lies -- there is in fact no <code>tbody</code> tag to look for, even though he made it a point of including in that HTML. So, changing to use <code>table</code> instead of <code>tbody</code>).</p> <p>As there may be several table-rows you want (e.g., see the...
5
2009-11-30T00:36:16Z
[ "python", "screen-scraping", "beautifulsoup", "html-content-extraction" ]
Beautifulsoup get value in table
1,817,184
<p>I am trying to scrape <a href="http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104" rel="nofollow">http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104</a> and get the "owner Name(s)" What I have works but is really ugly and not the best I am sure, so I am looking for a better way. Here is what ...
1
2009-11-29T23:46:14Z
1,822,191
<p>This is Aaron DeVore's answer from the Beautifulsoup discussion group, It work well for me.</p> <pre><code>soup = BeautifulSoup(...) label = soup.find(text="Owner Name(s)") </code></pre> <p>Needs Tag.string to get to the actual name string</p> <pre><code>name = label.findNext('td').string </code></pre> <p>If you...
3
2009-11-30T20:23:16Z
[ "python", "screen-scraping", "beautifulsoup", "html-content-extraction" ]
Override default User model method
1,817,244
<p>I've been trying to override the default <code>__unicode__()</code> method for the django.contrib.auth.models User model but I can't get it to work.</p> <p>I tried it like this:</p> <pre><code>from django.db import models from django.contrib.auth.models import User class User(models.Model): def __unicode_...
3
2009-11-30T00:11:49Z
1,817,377
<p>You might want to look at Django's <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#id8" rel="nofollow">Proxy Model</a> concept. They even show an example using User as a base class.</p> <p>On the other hand, if you are trying to change the actual __unicode__() method in the actual User class, you pr...
4
2009-11-30T00:57:10Z
[ "python", "django" ]
In Pinax, how to invite when ACCOUNT_OPEN_SIGNUP = False?
1,817,270
<p>In Pinax, when</p> <pre><code>ACCOUNT_OPEN_SIGNUP = False </code></pre> <p>how does the admin invite more users to the system? </p> <p>How does one generate invitation codes? How do they work?</p>
3
2009-11-30T00:21:19Z
1,824,508
<p>The only way currently is to hit <code>/admin/invite_user/</code> as a site admin. Currently, you can only send out one invitation at a time. We are definitely going to improve this in 0.9. Suggestions welcome.</p>
2
2009-12-01T07:16:21Z
[ "python", "django", "pinax", "invite", "invitation" ]