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 tool to balance parentheses, quotes, and brackets
2,104,227
<p>Does anyone know of an already-written Python script, tool, or editor that will check for unbalanced multi-line tokens? (parentheses, quotes, {}, [], etc.)</p> <p>I've been writing Python code in IDLE, and every so often I'll get "EOF token in multi-line statement" and start swearing, because it means that somewher...
1
2010-01-20T19:20:10Z
2,104,252
<p>If you use the vim text editor, there is a <a href="http://www.vim.org/scripts/script.php?script_id=790" rel="nofollow">syntax highlighter for Python</a> that might be of some help. Vim's python indenting rules also line up a new line with an unmatched open parenthesis from the previous line. That's been my visual...
0
2010-01-20T19:23:56Z
[ "python" ]
Django/Python: How do you start a new process in Python?
2,104,235
<p>After a customer uploads an image I want to re-size an image to 8 different sizes and then send them up to S3 and save them to the file system. Obviously this could take a long time (seconds) and I would want to do it in a "multithreaded" way (I quote that because I don't care if it's actually multithreaded or if it...
3
2010-01-20T19:21:39Z
2,104,258
<p>If you want to call an external process, use the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow"><code>subprocess</code></a> module. </p> <p>If on the other hand you want to side-step the GIL and spin of some Python task, use the <a href="http://docs.python.org/library/multiprocessing.html"...
2
2010-01-20T19:24:35Z
[ "python", "django", "multithreading" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,322
<pre><code>list1 = [1,2,3,4]; list2 = [0,3,3,6] print set(list2) - set(list1) </code></pre>
8
2010-01-20T19:37:49Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,336
<pre><code>&gt;&gt; items = [1,2,3,4] &gt;&gt; Z = [3,4,5,6] &gt;&gt; print list(set(items)-set(Z)) [1, 2] </code></pre>
30
2010-01-20T19:39:40Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,343
<pre><code>&gt;&gt;&gt; item = set([0,1,2,3,4,5,6,7,8,9]) &gt;&gt;&gt; z = set([2,3,4]) &gt;&gt;&gt; print item - z set([0, 1, 5, 6, 7, 8, 9]) </code></pre>
2
2010-01-20T19:40:21Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,346
<p>If you run a loop taking items from z, how do you expect them not to be in z? IMHO it would make more sense comparing items from a different list to z.</p>
3
2010-01-20T19:40:33Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,348
<p>Your code is not doing what I think you think it is doing. The line <code>for item in z:</code> will iterate through <code>z</code>, each time making <code>item</code> equal to one single element of <code>z</code>. The original <code>item</code> list is therefore overwritten before you've done anything with it.</p> ...
63
2010-01-20T19:40:49Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,350
<p>No, z is undefined. item contains a list of integers.</p> <p>I think what you're trying to do is this:</p> <pre><code>#z defined elsewhere item = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in item: if i not in z: print i </code></pre> <p>As has been stated in other answers, you may want to try using sets.</p>
2
2010-01-20T19:41:07Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,357
<p>Your code is a no-op. By the definition of the loop, "item" has to be in Z. A "For ... in" loop in Python means "Loop though the list called 'z', each time you loop, give me the next item in the list, and call it 'item'"</p> <p><a href="http://docs.python.org/tutorial/controlflow.html#for-statements" rel="nofollow...
2
2010-01-20T19:41:38Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
2,104,360
<p>You are reassigning item to the values in z as you iterate through z. So the first time in your for loop, item = 0, next item = 1, etc... You are never checking one list against the other.</p> <p>To do it very explicitly:</p> <pre><code>&gt;&gt;&gt; item = [0,1,2,3,4,5,6,7,8,9] &gt;&gt;&gt; z = [0,1,2,3,4,5,6,7]...
0
2010-01-20T19:42:07Z
[ "python", "list" ]
Finding elements not in a list
2,104,305
<p>So heres my code:</p> <pre><code>item = [0,1,2,3,4,5,6,7,8,9] for item in z: if item not in z: print item </code></pre> <p>Z contains a list of integers. I want to compare item to Z and print out the numbers that are not in Z when compared to item. I can print the elemtens that are in Z when compared ...
25
2010-01-20T19:35:13Z
37,708,886
<p>Using list comprehension:</p> <pre><code>print [x for x in item if x not in Z] </code></pre> <p>or using filter function :</p> <pre><code>filter(lambda x: x not in Z, item) </code></pre>
1
2016-06-08T17:13:49Z
[ "python", "list" ]
Python/Django: Can a process keep running after the user sees the "Thanks. You're done!" page
2,104,313
<p>I'm trying to understand threading better. If I create a program that allows people to upload a photo and then I create a new process to resize the image in a hundred ways (taking 5 seconds or longer), and the main program returns a response HTML page to the user saying "Thanks. You're done!", can the other process ...
0
2010-01-20T19:36:02Z
2,104,451
<p>Considering a Message or Job Queue is a good idea when you have background processing to do. This way you won't have to write your own code to handle job scheduling, priority etc. You can also add more servers to the queue when the first one starts running out of capacity.There's a package called <a href="http://cel...
8
2010-01-20T19:53:35Z
[ "python", "django", "multithreading" ]
Iterating over a large Django queryset while the data is changing elsewhere
2,104,404
<p>Iterating over a queryset, like so:</p> <pre><code>class Book(models.Model): # &lt;snip some other stuff&gt; activity = models.PositiveIntegerField(default=0) views = models.PositiveIntegerField(default=0) def calculate_statistics(): self.activity = book.views * 4 book.save() def c...
2
2010-01-20T19:48:35Z
2,104,804
<p>The following will do the job for you in Django 1.1, no loop necessary:</p> <pre><code>from django.db.models import F Book.objects.all().update(activity=F('views')*4) </code></pre> <p>You can have a more complicated calculation too:</p> <pre><code>for book in Book.objects.all().iterator(): Book.objects.filter...
2
2010-01-20T20:42:42Z
[ "python", "django", "django-models" ]
Iterating over a large Django queryset while the data is changing elsewhere
2,104,404
<p>Iterating over a queryset, like so:</p> <pre><code>class Book(models.Model): # &lt;snip some other stuff&gt; activity = models.PositiveIntegerField(default=0) views = models.PositiveIntegerField(default=0) def calculate_statistics(): self.activity = book.views * 4 book.save() def c...
2
2010-01-20T19:48:35Z
2,106,088
<p>No matter how you solve this, beware of transaction-related issues. E.g. default transaction isolation level is set to REPEATABLE READ, at least for MySQL backend. This, plus the fact that both Django and db backend work in a specific autocommit mode with an ongoing transaction means, that even if you use (very nice...
1
2010-01-21T00:22:07Z
[ "python", "django", "django-models" ]
Iterating over a large Django queryset while the data is changing elsewhere
2,104,404
<p>Iterating over a queryset, like so:</p> <pre><code>class Book(models.Model): # &lt;snip some other stuff&gt; activity = models.PositiveIntegerField(default=0) views = models.PositiveIntegerField(default=0) def calculate_statistics(): self.activity = book.views * 4 book.save() def c...
2
2010-01-20T19:48:35Z
2,107,448
<p>In addition to what others have said if you are iterating over a large queryset you should use iterator():</p> <pre><code>Book.objects.filter(stuff).order_by(stuff).iterator() </code></pre> <p>this will cause Django to not cache the items as it iterates (which could use a ton of memory for a large result set).</p>...
2
2010-01-21T07:03:01Z
[ "python", "django", "django-models" ]
MemoryLoadError when trying to run py2exe application
2,104,611
<p>I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:</p> <pre><code>C:\Documents and Settings\Administrator\Desktop\dist&gt;.\backend.exe install T...
5
2010-01-20T20:15:14Z
2,339,976
<p>You can do the dll and dependency check manually. When you generate the exe i am sure you have noticed that it prints out the dll's that are required/used. Check on the system, where the exe is not working, if the dll's exist and if they are the same version.</p> <p>One other thing. Are you copying the whole dist f...
1
2010-02-26T07:00:54Z
[ "python", "windows", "py2exe" ]
MemoryLoadError when trying to run py2exe application
2,104,611
<p>I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:</p> <pre><code>C:\Documents and Settings\Administrator\Desktop\dist&gt;.\backend.exe install T...
5
2010-01-20T20:15:14Z
2,344,571
<p>Are you doing the py2exe conversion on a 64bit/vista?</p> <p>I've been writing my code on a vista64bit, and the .exe files I create usually do not work on 32bit XP (those are the two machines i have on hand). </p> <p>The .exe helpfully throws out a text file with the traceback, and it appears that the 64bit window...
1
2010-02-26T20:22:49Z
[ "python", "windows", "py2exe" ]
MemoryLoadError when trying to run py2exe application
2,104,611
<p>I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:</p> <pre><code>C:\Documents and Settings\Administrator\Desktop\dist&gt;.\backend.exe install T...
5
2010-01-20T20:15:14Z
4,074,960
<p>same question as <a href="http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failedBlockquote">http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed</a>.</p> <p>look at setup.py, just excludes these dlls which are included in the system.</p> <pr...
6
2010-11-02T04:41:27Z
[ "python", "windows", "py2exe" ]
MemoryLoadError when trying to run py2exe application
2,104,611
<p>I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:</p> <pre><code>C:\Documents and Settings\Administrator\Desktop\dist&gt;.\backend.exe install T...
5
2010-01-20T20:15:14Z
38,156,144
<p>Just for anyone who will come to here in the future. If you are using any kind of win32 library and u stuck with this type of errors you can do the following steps:</p> <ul> <li>The problem issue is that there is a conflict between win32 functions dll files and the py2exe automatically dll files. So to solve this c...
0
2016-07-02T03:12:26Z
[ "python", "windows", "py2exe" ]
Adding arrays with different number of dimensions
2,104,643
<p>Let's say I have a 2D Numpy array:</p> <pre><code>&gt;&gt;&gt; a = np.random.random((4,6)) </code></pre> <p>and I want to add a 1D array to each row:</p> <pre><code>&gt;&gt;&gt; c = np.random.random((6,)) &gt;&gt;&gt; a + c </code></pre> <p>This works. Now if I try adding a 1D array to each column, I get an erro...
7
2010-01-20T20:19:54Z
2,104,699
<p>This is a distinctive feature of numpy called <a href="http://docs.scipy.org/doc/numpy/reference/ufuncs.html#broadcasting" rel="nofollow">broadcasting</a>. It is done using four rules which are a bit complicated in formulation but are rather intuitive once understood:</p> <blockquote> <ol> <li>All input arrays ...
8
2010-01-20T20:28:23Z
[ "python", "numpy" ]
Adding arrays with different number of dimensions
2,104,643
<p>Let's say I have a 2D Numpy array:</p> <pre><code>&gt;&gt;&gt; a = np.random.random((4,6)) </code></pre> <p>and I want to add a 1D array to each row:</p> <pre><code>&gt;&gt;&gt; c = np.random.random((6,)) &gt;&gt;&gt; a + c </code></pre> <p>This works. Now if I try adding a 1D array to each column, I get an erro...
7
2010-01-20T20:19:54Z
2,105,229
<p>Let me see if I get it...</p> <pre><code>&gt;&gt;&gt; from numpy import ones, newaxis &gt;&gt;&gt; A = ones((4,3)) # 4 rows x 3 cols &gt;&gt;&gt; A.shape (4, 3) &gt;&gt;&gt; A array([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.]]) &gt;&gt;&gt; &gt;&gt;&gt; ones((4,1)) ...
1
2010-01-20T21:43:48Z
[ "python", "numpy" ]
lxml and loops to create xml rss in python
2,104,751
<p>I have been using lxml to create the xml of rss feed. But I am having trouble with the tags and cant really figure out how to to add a dynamic number of elements. Given that lxml seems to just have functions as parameters of functions, I cant seem to figure out how to loop for a dynamic number of items without ...
2
2010-01-20T20:36:34Z
2,105,960
<p><a href="http://codespeak.net/lxml/tutorial.html#the-element-class" rel="nofollow">This lxml tutorial</a> says:</p> <hr> <p>To create child elements and add them to a parent element, you can use the <code>append()</code> method:</p> <pre><code>&gt;&gt;&gt; root.append( etree.Element("child1") ) </code></pre> <p>...
4
2010-01-20T23:53:19Z
[ "python", "lxml" ]
lxml and loops to create xml rss in python
2,104,751
<p>I have been using lxml to create the xml of rss feed. But I am having trouble with the tags and cant really figure out how to to add a dynamic number of elements. Given that lxml seems to just have functions as parameters of functions, I cant seem to figure out how to loop for a dynamic number of items without ...
2
2010-01-20T20:36:34Z
2,106,106
<p>Jason has answered your question; but – just FYI – you can pass any number of function arguments dynamically as a list: <code>E.channel(*args)</code>, where <code>args</code> would be <code>[E.title(</code>...<code>), E.link(</code>...<code>),</code>...<code>]</code>. Similarly, keyword arguments can be passed u...
5
2010-01-21T00:27:17Z
[ "python", "lxml" ]
lxml and loops to create xml rss in python
2,104,751
<p>I have been using lxml to create the xml of rss feed. But I am having trouble with the tags and cant really figure out how to to add a dynamic number of elements. Given that lxml seems to just have functions as parameters of functions, I cant seem to figure out how to loop for a dynamic number of items without ...
2
2010-01-20T20:36:34Z
2,111,456
<pre><code>channel = E.channel(E.title("Page Title"), E.link(""),E.description("")) for (title, link, description) in container: try: mytitle = E.title(title) mylink = E.link(link) mydesc = E.description(description) item = E.item(mytit...
2
2010-01-21T17:39:36Z
[ "python", "lxml" ]
Load and Reuse Django Template Filters
2,104,767
<p>Is it possible to load a django template tag/filter to use as a function in one of my template tags?</p> <p>I'm trying to load up some of the django.contrib.humanize filters so I can apply them to the results of some of my custom template tags. I can't seem to import them at all, and I don't want to have to rewrit...
0
2010-01-20T20:38:39Z
2,104,791
<p>Template tags are just Python functions; you can import their module and call them with impunity, the only requirement being that you pass them appropriate arguments. The <code>django.contrib.humanize.templatetags.humanize</code> module has separate functions to do the work, so it's even easier in that specific case...
3
2010-01-20T20:41:18Z
[ "python", "django", "templatetags" ]
QObject (QPlainTextEdit) & Multithreading issues
2,104,779
<p>Im currently trying to learn Networking with Python asyncore and pyqt4.</p> <p>I coded a small server, which basically listens on some port, and resends all messages it recieves to the sender.</p> <p>Since both qts <code>QApplication.exec_()</code> and <code>asyncore.loop()</code> are functions which never return ...
2
2010-01-20T20:40:00Z
2,104,992
<p>It appears you're trying to access QtGui classes from a thread other than the main thread. Like in some other GUI toolkits (e.g. Java Swing), that's not allowed. From the <a href="http://doc.qt.io/qt-4.8/threads-qobject.html" rel="nofollow">Threads and QObjects</a> web page:</p> <blockquote> <p>Although QObject i...
4
2010-01-20T21:09:55Z
[ "python", "multithreading", "qt4", "pyqt4", "asyncore" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
2,104,800
<pre><code>reduce(lambda x, y: x * y, list, 1) </code></pre>
32
2010-01-20T20:42:25Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
2,105,155
<p>Without using lambda:</p> <pre><code>from operator import mul reduce(mul, list, 1) </code></pre> <p>it is better and faster. With python 2.7.5</p> <pre><code>from operator import mul import numpy as np import numexpr as ne # from functools import reduce # python3 compatibility a = range(1, 101) %timeit reduce(la...
89
2010-01-20T21:33:16Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
2,105,189
<pre><code>import operator reduce(operator.mul, list, 1) </code></pre>
14
2010-01-20T21:38:20Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
2,124,590
<p>I remember some long discussions on comp.lang.python (sorry, too lazy to produce pointers now) which concluded that <strong>your original <code>product()</code> definition is the most Pythonic</strong>.</p> <p>Note that the proposal is not to write a for loop every time you want to do it, but to write a function on...
6
2010-01-23T20:30:31Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
9,114,648
<p>The intent of this answer is to provide a calculation that is useful in certain circumstances -- namely when a) there are a large number of values being multiplied such that the final product may be extremely large or extremely small, and b) you don't really care about the exact answer, but instead have a number of ...
5
2012-02-02T15:07:14Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
13,792,206
<p>if you just have numbers in your list:</p> <pre><code>from numpy import prod prod(list) </code></pre>
20
2012-12-09T21:47:59Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
15,142,974
<p>This also works though its cheating</p> <pre><code>def factorial(n): x=[] if n &lt;= 1: return 1 else: for i in range(1,n+1): p*=i x.append(p) print x[n-1] </code></pre>
-2
2013-02-28T18:30:35Z
[ "python" ]
Returning the product of a list
2,104,782
<p>Is there a more concise, efficient or simply pythonic way to do the following?</p> <pre><code>def product(list): p = 1 for i in list: p *= i return p </code></pre> <p>EDIT:</p> <p>I actually find that this is marginally faster than using operator.mul:</p> <pre><code>from operator import mul #...
85
2010-01-20T20:40:10Z
32,132,067
<p>Well if you really wanted to make it one line without importing anything you could do:</p> <pre><code>eval('*'.join(str(item) for item in list)) </code></pre> <p>But don't.</p>
3
2015-08-21T03:49:25Z
[ "python" ]
why no color output with Python?
2,104,785
<p>I have a batch file which calls .Net solution to build the project. On the dos console window, the warning and error will be in different color, green and red, looks nice. When the batch file called from Python, no color at all, all in a single color. Is it possible to get the same colorful result with python? my ca...
0
2010-01-20T20:40:59Z
2,104,852
<p>Some programs test to see if they're actually connected to a console/terminal, and suppress attribute changes if they're not in order to make it easier to parse/process the output. I know that on *nix systems you can use <code>unbuffer</code> to fool the program, but I don't know if there's a Windows equivalent.</p>...
3
2010-01-20T20:49:07Z
[ "python" ]
why no color output with Python?
2,104,785
<p>I have a batch file which calls .Net solution to build the project. On the dos console window, the warning and error will be in different color, green and red, looks nice. When the batch file called from Python, no color at all, all in a single color. Is it possible to get the same colorful result with python? my ca...
0
2010-01-20T20:40:59Z
2,105,000
<p>If this were UNIX, I'd suggest you don't get the output in a variable but just let the program print it out (ie. don't pass <code>stdout</code> to subprocess). Maybe you can try that once?</p>
0
2010-01-20T21:11:14Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,818
<p>Works just fine for me...</p> <pre><code>&gt;&gt;&gt; data = [ ... [5,3,0,0,7,0,0,0,0], ... [6,0,0,1,9,5,0,0,0], ... [0,9,8,0,0,0,0,6,0], ... [8,0,0,0,6,0,0,0,3], ... [4,0,0,8,0,3,0,0,1], ... [7,0,0,0,2,0,0,0,6], ... [0,6,0,0,0,0,2,8,0], ... [0,0,0,4,1,9,0,0,5], ... [0,0,0,0,8,0,0,7,9] ... ] &gt;&gt;&gt; element = ...
1
2010-01-20T20:45:10Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,824
<p>You seem to have tabbed out your last line, which gives me an error in the Python interpreter. If I remove that tab, it works.</p> <p>Your array <code>data</code> has changed. Maybe you aren't printing it out so you don't know that it changed?</p>
1
2010-01-20T20:45:26Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,826
<p>What version of python are you running? Can you try it from the command line and post the results, like below? It seems to be working for me. I basically copied and pasted straight from your post.</p> <pre><code>Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "cr...
1
2010-01-20T20:46:03Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,837
<p>The only thing wrong I see in your code is that the very last line is at a different indentation level. Putting it at the same level of the rest of the code works fine. :)</p> <p>You may also be interested in the pprint module:</p> <pre><code>&gt;&gt;&gt; from pprint import pprint &gt;&gt;&gt; pprint(data) [[4, 3,...
1
2010-01-20T20:47:25Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,896
<p>Ah... now that you've posted all your code, it makes much more sense...</p> <p>The reason it's not working the way you expected is because 'element' doesn't exist outside the context of the loop. You'll need to store the value you want to use in a variable that exists in the correct scope.</p>
0
2010-01-20T20:55:54Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,906
<p>It still works with the edited code. I changed the last few lines of your code to this:</p> <pre><code>print "before =", data[x][y] print "element =", element data[x][y] = element print "after =", data[x][y] </code></pre> <p>And those print this:</p> <pre><code>before = 0 element = 9 after = 9 </code></pre> <p...
0
2010-01-20T20:57:29Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,918
<p><code>for</code> loops in Python do not create a new scope; the name you use to hold the current value in the loop will persist after the loop is done, and will retain the last value it had while the loop was running.</p>
0
2010-01-20T20:58:33Z
[ "python" ]
Python: Replacing item in a list of lists
2,104,796
<p>Heres my code:</p> <pre><code>data = [ [5,3,0,0,7,0,0,0,0], [6,0,0,1,9,5,0,0,0], [0,9,8,0,0,0,0,6,0], [8,0,0,0,6,0,0,0,3], [4,0,0,8,0,3,0,0,1], [7,0,0,0,2,0,0,0,6], [0,6,0,0,0,0,2,8,0], [0,0,0,4,1,9,0,0,5], [0,0,0,0,8,0,0,7,9] ] element = 4 x = 0 y = 0 data[x][y] = element </code></pre> <p>I want to replace t...
1
2010-01-20T20:41:48Z
2,104,965
<p>You need to break for look as soon as you find the necessary element:</p> <pre><code>item = [1,2,3,4,5,6,7,8,9] for element in item: if element not in z: print element break data[x][y] = element print data[x][y] </code></pre>
1
2010-01-20T21:05:30Z
[ "python" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
2,104,947
<p><code>int</code> and <code>long</code> were "unified" <a href="http://www.python.org/dev/peps/pep-0237/">a few versions back</a>. Before that it was possible to overflow an int through math ops.</p> <p>3.x has further advanced this by eliminating int altogether and only having long.</p> <p>Python 2: <code>sys.maxi...
51
2010-01-20T21:01:54Z
[ "python", "integer" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
2,104,953
<p>This <a href="http://www.python.org/dev/peps/pep-0237/">PEP</a> should help. </p> <p>Bottom line is that you really shouldn't have to worry about it in python versions > 2.4</p>
7
2010-01-20T21:02:57Z
[ "python", "integer" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
2,104,962
<p>On my machine:</p> <pre><code>&gt;&gt;&gt; print type(1&lt;&lt;30) &lt;type 'int'&gt; &gt;&gt;&gt; print type(1&lt;&lt;31) &lt;type 'long'&gt; &gt;&gt;&gt; print type(0x7FFFFFFF) &lt;type 'int'&gt; &gt;&gt;&gt; print type(0x7FFFFFFF+1) &lt;type 'long'&gt; </code></pre> <p>Python uses ints (32 bit signed integers, ...
2
2010-01-20T21:05:11Z
[ "python", "integer" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
2,105,040
<p>It manages them because <code>int</code> and <code>long</code> are sibling class definitions. They have appropriate methods for +, -, *, /, etc., that will produce results of the appropriate class.</p> <p>For example</p> <pre><code>&gt;&gt;&gt; a=1&lt;&lt;30 &gt;&gt;&gt; type(a) &lt;type 'int'&gt; &gt;&gt;&gt; b=...
0
2010-01-20T21:19:03Z
[ "python", "integer" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
5,082,547
<p>Interesting. On my 64-bit (i7 Ubuntu) box:</p> <pre><code>&gt;&gt;&gt; print type(0x7FFFFFFF) &lt;type 'int'&gt; &gt;&gt;&gt; print type(0x7FFFFFFF+1) &lt;type 'int'&gt; </code></pre> <p>Guess it steps up to 64 bit ints on a larger machine.</p>
2
2011-02-22T18:55:13Z
[ "python", "integer" ]
How does Python manage int and long?
2,104,884
<p>Does anybody know how Python manage internally int and long types? </p> <ul> <li>Does it choose the right type dynamically? </li> <li>What is the limit for an int?</li> <li>I am using Python 2.6, Is is different with previous versions?</li> </ul> <p>How should I understand the code below?</p> <pre><code>&gt;&gt;&...
55
2010-01-20T20:54:09Z
38,544,599
<p>From python 3.x, the unified integer libries are even more smarter than older versions. On my (i7 Ubuntu) box I got the following,</p> <pre><code>&gt;&gt;&gt; type(math.factorial(30)) &lt;class 'int'&gt; </code></pre> <p>For implementation details refer <code>Include/longintrepr.h, Objects/longobject.c and Modules...
0
2016-07-23T17:27:12Z
[ "python", "integer" ]
Django queryset that returns all unassigned fks
2,104,921
<p>I have 2 models with a 1-1 relation (essentially a resource pool). For the example code, I will simply use nuts and bolts. There will be many more nuts (available resources) than bolts (which will each require 1 nut). However, if a nut can only be assigned to one bolt.</p> <p>The constraint is easy enough to set...
2
2010-01-20T20:58:46Z
2,105,019
<p>Try this:</p> <pre><code>self.fields['nut'].queryset = Nut.objects.exclude( pk__in=Bolt.objects.values('nut').query) </code></pre> <p><strong>Update</strong>:</p> <p>Of three expressions generating the same sql query:</p> <pre><code>pk__in=Bolt.objects.values('nut') pk__in=Bolt.objects.values_list('nut') pk_...
4
2010-01-20T21:15:43Z
[ "python", "django", "django-models" ]
Django queryset that returns all unassigned fks
2,104,921
<p>I have 2 models with a 1-1 relation (essentially a resource pool). For the example code, I will simply use nuts and bolts. There will be many more nuts (available resources) than bolts (which will each require 1 nut). However, if a nut can only be assigned to one bolt.</p> <p>The constraint is easy enough to set...
2
2010-01-20T20:58:46Z
2,105,029
<pre><code>Nut.objects.filter(bolt=None) </code></pre>
1
2010-01-20T21:17:16Z
[ "python", "django", "django-models" ]
In Jinja2, how can I use macros in combination with block tags?
2,104,957
<p>I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments.</p> <p>My base template cont...
10
2010-01-20T21:03:49Z
2,105,535
<p>Blocks are only definable at a template's top level. If you extend a template, any values set in the child template using a <code>set</code> tag will be accessible from the template it is extending. For example, if you have a template named <code>layout.html</code>:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//...
18
2010-01-20T22:32:24Z
[ "python", "django", "templates", "django-templates", "jinja2" ]
Anyway of making Django CMS pages to be only accessible (site side) to only a select few?
2,104,986
<p>I've installed Django CMS (http://www.django-cms.org/) and it's almost perfect. I've been chatting on the IRC #django-cms group and it's been confirmed to me that I can't have access restricted to the pages I make in Django CMS to only a select few on the site side.</p> <p>I know of the CMS_PERMISSIONS setting, but...
1
2010-01-20T21:08:52Z
2,106,029
<p>I don't know Django CMS, but you could do such filtering in middleware - i.e. you could check incoming URL and redirect to login page if current user doesn't have permissions to view it.</p> <p><a href="http://docs.djangoproject.com/en/1.1/topics/http/middleware/" rel="nofollow">http://docs.djangoproject.com/en/1.1...
1
2010-01-21T00:11:53Z
[ "python", "django", "permissions", "authorization", "django-cms" ]
Anyway of making Django CMS pages to be only accessible (site side) to only a select few?
2,104,986
<p>I've installed Django CMS (http://www.django-cms.org/) and it's almost perfect. I've been chatting on the IRC #django-cms group and it's been confirmed to me that I can't have access restricted to the pages I make in Django CMS to only a select few on the site side.</p> <p>I know of the CMS_PERMISSIONS setting, but...
1
2010-01-20T21:08:52Z
8,455,993
<p>Use the 'View restrictions' panel in the admin page. This is documented <a href="https://django-cms.readthedocs.org/en/2.3.3/advanced/permissions_reference.html" rel="nofollow">here</a>.</p>
3
2011-12-10T10:54:28Z
[ "python", "django", "permissions", "authorization", "django-cms" ]
Facebook Page details and the RESTful API?
2,104,996
<p>Hi I have a list of Facebook Page urls</p> <pre><code>eg... http://www.facebook.com/daftpunk http://www.facebook.com/DavidGuetta ... </code></pre> <p>What's the best way to:</p> <ul> <li><p>Check if these urls are <strong><em>actually</em></strong> for Facebook Pages and <strong><em>not</em></strong> Profiles</p>...
2
2010-01-20T21:10:46Z
2,105,098
<p>You can use <a href="http://scrapy.org/" rel="nofollow">scrapy</a> or <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> to scrape the content.</p>
0
2010-01-20T21:27:16Z
[ "python", "facebook", "pyfacebook" ]
Facebook Page details and the RESTful API?
2,104,996
<p>Hi I have a list of Facebook Page urls</p> <pre><code>eg... http://www.facebook.com/daftpunk http://www.facebook.com/DavidGuetta ... </code></pre> <p>What's the best way to:</p> <ul> <li><p>Check if these urls are <strong><em>actually</em></strong> for Facebook Pages and <strong><em>not</em></strong> Profiles</p>...
2
2010-01-20T21:10:46Z
2,105,145
<p>use <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a> or <a href="http://github.com/sciyoshi/pyfacebook/" rel="nofollow">pyfacebook</a> to fetch the content</p> <p>use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> or <a href="http://codespeak...
2
2010-01-20T21:32:17Z
[ "python", "facebook", "pyfacebook" ]
Facebook Page details and the RESTful API?
2,104,996
<p>Hi I have a list of Facebook Page urls</p> <pre><code>eg... http://www.facebook.com/daftpunk http://www.facebook.com/DavidGuetta ... </code></pre> <p>What's the best way to:</p> <ul> <li><p>Check if these urls are <strong><em>actually</em></strong> for Facebook Pages and <strong><em>not</em></strong> Profiles</p>...
2
2010-01-20T21:10:46Z
2,105,685
<p>The # of fans is in an a tag with the class 'FanManager'. you can use Beautiful Soup to get the contents of this a tag, and regular expressions to get the data from the string (ex: 1,000,000 fans) as an int or whatever you would like.</p> <p>To see if the page exists, check some of the tags to see if you are on the...
1
2010-01-20T22:56:59Z
[ "python", "facebook", "pyfacebook" ]
Facebook Page details and the RESTful API?
2,104,996
<p>Hi I have a list of Facebook Page urls</p> <pre><code>eg... http://www.facebook.com/daftpunk http://www.facebook.com/DavidGuetta ... </code></pre> <p>What's the best way to:</p> <ul> <li><p>Check if these urls are <strong><em>actually</em></strong> for Facebook Pages and <strong><em>not</em></strong> Profiles</p>...
2
2010-01-20T21:10:46Z
2,109,746
<p>Without scraping any content (which is against Facebook's terms of service anyway):</p> <ol> <li>Extract the username part of the URL i.e. the bit after the www.facebook.com/</li> <li>Do an FQL query of the form <code>select fan_count from page where username='michaeljackson'</code></li> <li>If a result is return,...
3
2010-01-21T14:06:36Z
[ "python", "facebook", "pyfacebook" ]
os.walk() python: xml representation of a directory structure, recursion
2,104,997
<p><br> So I am trying to use os.walk() to generate an XML representation of a directory structure. I seem to be getting a ton of duplicates. It properly places directories within each other and files in the right place for the first portion of the xml file; however, after it does it correctly it then continues travers...
4
2010-01-20T21:10:48Z
2,105,050
<p>Remove the two lines:</p> <pre><code> for subdir in dirs: xmlOutput+=self.dirToXML(os.path.join(root,subdir)) </code></pre> <p>you are recursing into the subdirectories; but that's redundant, because os.walk recurses itself.</p>
6
2010-01-20T21:20:31Z
[ "python", "xml", "recursion", "directory-structure", "os.walk" ]
os.walk() python: xml representation of a directory structure, recursion
2,104,997
<p><br> So I am trying to use os.walk() to generate an XML representation of a directory structure. I seem to be getting a ton of duplicates. It properly places directories within each other and files in the right place for the first portion of the xml file; however, after it does it correctly it then continues travers...
4
2010-01-20T21:10:48Z
2,105,425
<p>I was attempting to use os.walk, but I saw that it didn't work with the recursive tree structure that I wanted to create in xml. I modified my code as follows and it produce the result I need: </p> <pre><code>def dirToXML(self,directory): curdir = os.getcwd() os.chdir(directory) xmlOutput=""...
0
2010-01-20T22:16:10Z
[ "python", "xml", "recursion", "directory-structure", "os.walk" ]
os.walk() python: xml representation of a directory structure, recursion
2,104,997
<p><br> So I am trying to use os.walk() to generate an XML representation of a directory structure. I seem to be getting a ton of duplicates. It properly places directories within each other and files in the right place for the first portion of the xml file; however, after it does it correctly it then continues travers...
4
2010-01-20T21:10:48Z
2,105,761
<p>I'd recommend against using <code>os.walk()</code>, since you have to do so much to massage its output. Instead, just use a recursive function that uses <code>os.listdir()</code>, <code>os.path.join()</code>, <code>os.path.isdir()</code>, etc.</p> <pre><code>import os from xml.sax.saxutils import escape as xml_esc...
6
2010-01-20T23:10:10Z
[ "python", "xml", "recursion", "directory-structure", "os.walk" ]
unicode in powershell with python? alternative shells in windows?
2,105,022
<p>I want a shell that supports unicode in windows, powershell as it ships doesn't seem to. Powershell V2 (win7 x64) :</p> <pre><code>PS C:\&gt; powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\&gt; python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 ...
3
2010-01-20T21:16:14Z
2,105,176
<p>Maybe you should try <strong><a href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;ved=0CDkQFjAA&amp;url=http%3A%2F%2Fipython.scipy.org%2F&amp;ei=RXdXS9eWCcGksAaM0-SJCg&amp;usg=AFQjCNGWMLKT-bLapq-ZjBY7zxV_vh0caA&amp;sig2=XdqMFEhneClcCyJRWhZE4w" rel="nofollow">ipython</a></strong>?</p>
0
2010-01-20T21:36:17Z
[ "python", "windows", "unicode", "powershell" ]
unicode in powershell with python? alternative shells in windows?
2,105,022
<p>I want a shell that supports unicode in windows, powershell as it ships doesn't seem to. Powershell V2 (win7 x64) :</p> <pre><code>PS C:\&gt; powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\&gt; python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 ...
3
2010-01-20T21:16:14Z
2,105,656
<p>The Windows console subsystem is not Unicode but code page based. You can play around with setting the code page:</p> <pre><code>PS&gt; chcp 65001 PS&gt; ipy64.exe &gt;&gt;&gt; print unichr(0x3a9) Ω </code></pre> <p>I couldn't get (0xf12) to give the right character with that codepage. Perhaps it is available o...
4
2010-01-20T22:51:04Z
[ "python", "windows", "unicode", "powershell" ]
unicode in powershell with python? alternative shells in windows?
2,105,022
<p>I want a shell that supports unicode in windows, powershell as it ships doesn't seem to. Powershell V2 (win7 x64) :</p> <pre><code>PS C:\&gt; powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\&gt; python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 ...
3
2010-01-20T21:16:14Z
2,108,158
<p>The PowerShell itself is Unicode, but the clasic console has problems with Unicode. But PowerShell ISE is definitely Unicode.</p> <p>Try this:</p> <pre><code>PS C:\&gt; $a = [char]0xf12 PS C:\&gt; echo $a </code></pre> <p>This is Python not playing nice.</p> <p>You can try <code>chcp 65001</code> before starting...
1
2010-01-21T09:39:21Z
[ "python", "windows", "unicode", "powershell" ]
unicode in powershell with python? alternative shells in windows?
2,105,022
<p>I want a shell that supports unicode in windows, powershell as it ships doesn't seem to. Powershell V2 (win7 x64) :</p> <pre><code>PS C:\&gt; powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\&gt; python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 ...
3
2010-01-20T21:16:14Z
2,109,809
<p>Note that, when issuing <code>chcp 65001</code> in a Windows console the font <em>must</em> be Lucida Console and <em>not</em> any of the bitmap fonts. Theoretically, other monospaced ttf fonts should work, but they don't (practically). It's an issue of attributes that MS checks in monospaced fonts intended for the ...
0
2010-01-21T14:15:56Z
[ "python", "windows", "unicode", "powershell" ]
unicode in powershell with python? alternative shells in windows?
2,105,022
<p>I want a shell that supports unicode in windows, powershell as it ships doesn't seem to. Powershell V2 (win7 x64) :</p> <pre><code>PS C:\&gt; powershell Windows PowerShell Copyright (C) 2009 Microsoft Corporation. All rights reserved. PS C:\&gt; python Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 ...
3
2010-01-20T21:16:14Z
6,318,472
<p>Both the normal Windows console and PowerShell ISE support Unicode. See the blog posts by Michael Kaplan for details:</p> <ul> <li><a href="http://www.siao2.com/2010/05/07/10008232.aspx" rel="nofollow">http://www.siao2.com/2010/05/07/10008232.aspx</a></li> <li><a href="http://www.siao2.com/2010/04/07/9989346.aspx" ...
0
2011-06-11T20:49:51Z
[ "python", "windows", "unicode", "powershell" ]
SOAP Message size it greater than allowed limit [SECURITY.MSGSIZE v 1.0]? How?
2,105,037
<p>I'm trying to help a colleague run <a href="http://en.wikipedia.org/wiki/Soatest" rel="nofollow">SOATest</a> (a web services client that makes testing SOAP services easy) on a WCF web service operation, and for "big" responses, we are seeing this error:</p> <pre><code>SOAP Message size it greater than allowed limit...
1
2010-01-20T21:18:31Z
2,118,895
<p>We were able to get an answer to this error on the <a href="http://forums.parasoft.com/index.php?showtopic=2169" rel="nofollow">SOATest forums</a>.</p> <p>SECURITY.MSGSIZE is one of the default SOAP Policy rule checks available to be added to a response. Here's a <a href="http://imgur.com/41xM6.png" rel="nofollow">...
0
2010-01-22T16:53:38Z
[ "python", "soap", "policy", "rule" ]
how many characters are there in line in a console?
2,105,090
<p>How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)</p>
3
2010-01-20T21:26:30Z
2,105,139
<p>I don't know specifically in <code>python</code>,<br> but in a shell the environment variable <code>$COLUMNS</code> contains the information you want.</p>
3
2010-01-20T21:31:09Z
[ "python", "shell" ]
how many characters are there in line in a console?
2,105,090
<p>How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)</p>
3
2010-01-20T21:26:30Z
2,105,152
<p><a href="http://docs.python.org/library/curses.html#curses.tigetnum" rel="nofollow"><code>curses.tigetnum('cols')</code></a></p>
3
2010-01-20T21:33:08Z
[ "python", "shell" ]
how many characters are there in line in a console?
2,105,090
<p>How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)</p>
3
2010-01-20T21:26:30Z
2,105,183
<p>You can use the <a href="http://linux.die.net/man/1/tput" rel="nofollow"><code>tput</code></a> utility to query the number of lines and columns available in the terminal. You can execute it using <a href="http://docs.python.org/3.1/library/subprocess.html#subprocess.Popen" rel="nofollow"><code>subprocess.Popen</code...
2
2010-01-20T21:37:36Z
[ "python", "shell" ]
how many characters are there in line in a console?
2,105,090
<p>How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)</p>
3
2010-01-20T21:26:30Z
2,106,249
<p>on *nix only</p> <pre><code>&gt;&gt;&gt; import sys,struct,fnctl,termios &gt;&gt;&gt; fd = sys.stdin.fileno() &gt;&gt;&gt; s = struct.pack("HH", 0,0) &gt;&gt;&gt; size=fcntl.ioctl(fd, termios.TIOCGWINSZ,s) &gt;&gt;&gt; struct.unpack("HH", size)[-1] 157 </code></pre>
0
2010-01-21T01:08:43Z
[ "python", "shell" ]
OOP Design - In Python, is this a quality OO Design or an epic fail?
2,105,376
<p>In a system that accepts orders which have payments which have gateway transactions should the objects be like this:</p> <pre><code>class Order(object): ... Inside init ... self.total_in_dollars = &lt;Dollar Amount&gt; self.is_paid = &lt;Boolean Value&gt; class Payment(object): ... ...
1
2010-01-20T22:08:03Z
2,105,412
<p>Give the objects constructors that take the appropriate other object that you want it to refer to, then make the fields into properties that verify the type you assign to them.</p>
2
2010-01-20T22:14:59Z
[ "python", "django", "oop" ]
OOP Design - In Python, is this a quality OO Design or an epic fail?
2,105,376
<p>In a system that accepts orders which have payments which have gateway transactions should the objects be like this:</p> <pre><code>class Order(object): ... Inside init ... self.total_in_dollars = &lt;Dollar Amount&gt; self.is_paid = &lt;Boolean Value&gt; class Payment(object): ... ...
1
2010-01-20T22:08:03Z
2,105,973
<p>You appear to be assigning what should obviously be <strong>instance</strong> variables as <strong>class</strong> variables, which is clearly a very wrong tack to take. IOW, the variables should be <code>self.total_in_dollars</code> (for instance of <code>Order</code>) and so forth, assigned in <code>__init__</code...
6
2010-01-20T23:58:00Z
[ "python", "django", "oop" ]
OOP Design - In Python, is this a quality OO Design or an epic fail?
2,105,376
<p>In a system that accepts orders which have payments which have gateway transactions should the objects be like this:</p> <pre><code>class Order(object): ... Inside init ... self.total_in_dollars = &lt;Dollar Amount&gt; self.is_paid = &lt;Boolean Value&gt; class Payment(object): ... ...
1
2010-01-20T22:08:03Z
2,106,119
<p>I would approach this differently - by writing the some code for dealing with Orders, Payments etc. This would clarify my design needs, e.g. it would turn out that Payment.amount could be greater that Order.total_in_dollars, because of some processing fees. But then, it could turn out that maybe those processing fee...
2
2010-01-21T00:32:46Z
[ "python", "django", "oop" ]
Error Installing Gitosis on Fedora Core
2,105,390
<p>I'm trying to follow these instructions on installing gitosis:</p> <p><a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way" rel="nofollow">http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way</a></p> <p>and these:</p> <p><a href="http://www.webtop.com.a...
2
2010-01-20T22:10:39Z
2,105,407
<p>Make sure you're running that command as the git user, and make sure that the git user owns the /home/git directory. </p> <p>Are you running <em>git clone <strong>git</strong>@yourserver:gitosis-admin.git</em> ?</p> <p>It sounds like one of those things is not the case.</p>
0
2010-01-20T22:13:35Z
[ "python", "linux", "git", "fedora", "gitosis" ]
SVN serve and PySVN Error message: Expected FS format between '1' and '3'; found format '4'
2,105,456
<p>For research purposes, I copied a SVN repo to my Windows machine using svnsync so I can replay on my machine without loading the actual server.</p> <p>I've been using PySVN in scripts to control the revision number I want the repo to be in and have been using it fine so far. Now I got a repo from a different projec...
2
2010-01-20T22:21:34Z
2,105,712
<p>Which version of ubuntu you have? 9.04? It does not have subversion 1.6 afair.</p> <p>What versions do</p> <pre><code>dpkg -l subversion dpkg -l python-svn </code></pre> <p>report?</p>
1
2010-01-20T23:01:50Z
[ "python", "svn", "ubuntu", "pysvn" ]
Wrap C++ lib with Cython
2,105,508
<p>I'm new to Cython and I'm tring to use Cython to wrap a C/C++ static library. I made a simply example as following.</p> <p>Test.h: </p> <pre><code>#ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif </code></pre> <p>Test.cpp</p> <pre><code>#include "test.h" int add(int a, int...
13
2010-01-20T22:27:05Z
2,105,951
<p>I think you can fix this specific problem by specifying the right <code>library_dirs</code> (where you actually <strong>put</strong> libtest.a -- apparently it's not getting found), but I think then you'll have another problem -- your entry points are not properly declared as <code>extern "C"</code>, so the function...
2
2010-01-20T23:49:35Z
[ "python", "cython" ]
Wrap C++ lib with Cython
2,105,508
<p>I'm new to Cython and I'm tring to use Cython to wrap a C/C++ static library. I made a simply example as following.</p> <p>Test.h: </p> <pre><code>#ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif </code></pre> <p>Test.cpp</p> <pre><code>#include "test.h" int add(int a, int...
13
2010-01-20T22:27:05Z
2,106,051
<p>If your C++ code is only used by the wrapper, another option is to let the setup compile your .cpp file, like this:</p> <pre><code>from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("test", ["test.pyx", "te...
20
2010-01-21T00:15:55Z
[ "python", "cython" ]
Wrap C++ lib with Cython
2,105,508
<p>I'm new to Cython and I'm tring to use Cython to wrap a C/C++ static library. I made a simply example as following.</p> <p>Test.h: </p> <pre><code>#ifndef TEST_H #define TEST_H int add(int a, int b); int multipy(int a, int b); #endif </code></pre> <p>Test.cpp</p> <pre><code>#include "test.h" int add(int a, int...
13
2010-01-20T22:27:05Z
21,440,618
<p>Your <code>Test.pyx</code> file isn't doing what you expect. The <code>print add(2,3)</code> line <em>will not</em> call the <code>add()</code> C++ function; you have to explicitly create a wrapper function to do that. Cython doesn't create wrappers for you automatically.</p> <p>Something like this is probably wh...
3
2014-01-29T19:23:55Z
[ "python", "cython" ]
Graceful exiting of a program in Python?
2,105,509
<p>Hey all, I have a script that runs as a </p> <pre><code>while True: doStuff() </code></pre> <p>What is the best way to communicate with this script if I need to stop it but I don't want to kill it if it is in the middle of an operation?</p> <p>Thanks!</p>
6
2010-01-20T22:28:04Z
2,105,524
<p>I think the most elegant would be:</p> <pre><code>keep_running = true while keep_running: dostufF() </code></pre> <p>and then <code>dostuff()</code> can set <code>keep_running = false</code> whenever in no longer wants to keep running, then the while loop ends, and everything cleans up nicely.</p>
5
2010-01-20T22:30:46Z
[ "python" ]
Graceful exiting of a program in Python?
2,105,509
<p>Hey all, I have a script that runs as a </p> <pre><code>while True: doStuff() </code></pre> <p>What is the best way to communicate with this script if I need to stop it but I don't want to kill it if it is in the middle of an operation?</p> <p>Thanks!</p>
6
2010-01-20T22:28:04Z
2,105,538
<p>The best way is to rewrite the script so it doesn't use <code>while True:</code>.</p> <p>Sadly, it's impossible to conjecture a good way to terminate this.</p> <p>You could use the Linux signals.</p> <p>You could use a timer and stop after a while.</p> <p>You could have <code>dostuff</code> return a value and st...
5
2010-01-20T22:32:27Z
[ "python" ]
Graceful exiting of a program in Python?
2,105,509
<p>Hey all, I have a script that runs as a </p> <pre><code>while True: doStuff() </code></pre> <p>What is the best way to communicate with this script if I need to stop it but I don't want to kill it if it is in the middle of an operation?</p> <p>Thanks!</p>
6
2010-01-20T22:28:04Z
2,105,575
<p>If that's a console aplication and exiting by pressing Ctrl+C is ok, could that solve your problem?</p> <pre><code>try: while True: doStuff() except KeyboardInterrupt: doOtherStuff() </code></pre> <p>I guess the problem with that approach is that you wouldn't have any control exactly when and where in doSt...
2
2010-01-20T22:38:24Z
[ "python" ]
Graceful exiting of a program in Python?
2,105,509
<p>Hey all, I have a script that runs as a </p> <pre><code>while True: doStuff() </code></pre> <p>What is the best way to communicate with this script if I need to stop it but I don't want to kill it if it is in the middle of an operation?</p> <p>Thanks!</p>
6
2010-01-20T22:28:04Z
2,105,600
<p>And I'm assuming you mean killing from outside the python script.</p> <p>The way I've found easiest is</p> <pre><code>@atexit.register def cleanup() sys.unlink("myfile.%d" % os.getpid() ) f = open("myfile.%d" % os.getpid(), "w" ) f.write("Nothing") f.close() while os.path.exists("myfile.%d" % os.getpid() ): d...
7
2010-01-20T22:42:24Z
[ "python" ]
Graceful exiting of a program in Python?
2,105,509
<p>Hey all, I have a script that runs as a </p> <pre><code>while True: doStuff() </code></pre> <p>What is the best way to communicate with this script if I need to stop it but I don't want to kill it if it is in the middle of an operation?</p> <p>Thanks!</p>
6
2010-01-20T22:28:04Z
2,106,074
<p>The signal module can trap signals and react accordingly?</p>
-1
2010-01-21T00:18:34Z
[ "python" ]
iterable long-object?
2,105,569
<p>This is a problem from euler-project. No.13 </p> <pre><code>import math #no.13 sum = [] number = 0 a = 3710728753390210279879799822083759024651013574025046376937677490009712648124896970078050417018260538743249861995247410594742333095130581237266173096299194221336357416157252243056330181107240615490825023067588207...
2
2010-01-20T22:37:20Z
2,105,585
<p>I am not sure what the overall goal of your program is but the error you are getting is because in the line:</p> <pre><code>a = int(''.join(str(i) for i in a)) </code></pre> <p>You are trying to iterate over a <code>long</code> and in <code>Python</code> as the error message indicates a <code>long</code> is not a...
3
2010-01-20T22:40:15Z
[ "python", "long-integer", "iterable" ]
iterable long-object?
2,105,569
<p>This is a problem from euler-project. No.13 </p> <pre><code>import math #no.13 sum = [] number = 0 a = 3710728753390210279879799822083759024651013574025046376937677490009712648124896970078050417018260538743249861995247410594742333095130581237266173096299194221336357416157252243056330181107240615490825023067588207...
2
2010-01-20T22:37:20Z
2,105,606
<p>I assume you are trying to solve <a href="http://projecteuler.net/index.php?section=problems&amp;id=13" rel="nofollow">Project Euler #13</a>.</p> <p>Your variable <code>a</code> should be a list of integers, not one big long integer:</p> <pre><code>a = [ 37107287533902102798797998220837590246510135740250, ...
2
2010-01-20T22:43:00Z
[ "python", "long-integer", "iterable" ]
iterable long-object?
2,105,569
<p>This is a problem from euler-project. No.13 </p> <pre><code>import math #no.13 sum = [] number = 0 a = 3710728753390210279879799822083759024651013574025046376937677490009712648124896970078050417018260538743249861995247410594742333095130581237266173096299194221336357416157252243056330181107240615490825023067588207...
2
2010-01-20T22:37:20Z
2,106,040
<p>As the OP knows, but maybe others don't, the problem statement is: "work out the first ten digits of the sum of the following one-hundred 50-digit numbers," followed naturally by 100 50-digit integers.</p> <p>The problem is designed to make it difficult to simply add the numbers together.</p> <p>Now, there is som...
0
2010-01-21T00:13:23Z
[ "python", "long-integer", "iterable" ]
iterable long-object?
2,105,569
<p>This is a problem from euler-project. No.13 </p> <pre><code>import math #no.13 sum = [] number = 0 a = 3710728753390210279879799822083759024651013574025046376937677490009712648124896970078050417018260538743249861995247410594742333095130581237266173096299194221336357416157252243056330181107240615490825023067588207...
2
2010-01-20T22:37:20Z
2,112,363
<p>Your second code snippet is really close. A smaller version of what you're doing is:</p> <pre><code>a = """12345""".split() b = [int(x) for x in a] </code></pre> <p>b now equals ['12345'], a list with a single string in it. That's why b[1] raises an error, because it's asking for the second element in a one-elemen...
1
2010-01-21T19:52:44Z
[ "python", "long-integer", "iterable" ]
name 'times' is used prior to global declaration - But IT IS declared!
2,105,611
<p>I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is that IT IS declared, right on the beggining, as <code>times = []</code> (yes, it's a list) and then again, on the fu...
13
2010-01-20T22:43:56Z
2,105,637
<p>The global declaration is when you declare that <code>times</code> is <code>global</code></p> <pre><code>def timeit(): global times # &lt;- global declaration # ... </code></pre> <p>If a variable is declared <code>global</code>, it can't be used before the declaration.</p> <p>In this case, I don't think y...
14
2010-01-20T22:48:05Z
[ "python", "python-3.x", "global-variables" ]
name 'times' is used prior to global declaration - But IT IS declared!
2,105,611
<p>I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is that IT IS declared, right on the beggining, as <code>times = []</code> (yes, it's a list) and then again, on the fu...
13
2010-01-20T22:43:56Z
2,105,647
<p>From the Python documentation:</p> <pre><code>Names listed in a global statement must not be used in the same code block textually preceding that global statement. </code></pre> <p><a href="http://docs.python.org/reference/simple_stmts.html#global">http://docs.python.org/reference/simple_stmts.html#global</a></p> ...
12
2010-01-20T22:49:23Z
[ "python", "python-3.x", "global-variables" ]
name 'times' is used prior to global declaration - But IT IS declared!
2,105,611
<p>I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is that IT IS declared, right on the beggining, as <code>times = []</code> (yes, it's a list) and then again, on the fu...
13
2010-01-20T22:43:56Z
2,105,674
<p>From the <a href="http://docs.python.org/reference/simple_stmts.html#the-global-statement" rel="nofollow">Python Docs</a></p> <blockquote> <p>Names listed in a global statement must not be used in the same code block textually preceding that global statement.</p> </blockquote>
2
2010-01-20T22:54:21Z
[ "python", "python-3.x", "global-variables" ]
name 'times' is used prior to global declaration - But IT IS declared!
2,105,611
<p>I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is that IT IS declared, right on the beggining, as <code>times = []</code> (yes, it's a list) and then again, on the fu...
13
2010-01-20T22:43:56Z
2,105,684
<p>This program should work but may not work exactly as you intended. Please take note of the changes.</p> <pre><code>import time times = [] def timeit(): input("Press ENTER to start: ") start_time = time.time() input("Press ENTER to stop: ") end_time = time.time() the_time = round(end_time - sta...
1
2010-01-20T22:56:45Z
[ "python", "python-3.x", "global-variables" ]
name 'times' is used prior to global declaration - But IT IS declared!
2,105,611
<p>I'm coding a small program to time and show, in a ordered fashion, my Rubik's cube solvings. But Python (3) keeps bothering me about times being used prior to global declaration. But what's strange is that IT IS declared, right on the beggining, as <code>times = []</code> (yes, it's a list) and then again, on the fu...
13
2010-01-20T22:43:56Z
39,765,977
<p>For the main program, you can declare it on the top. Ther will be no warning. But, as said, the global mention is not useful here. Each variable put in the main program is in the global space. In functions, you must declare that you want use the global space for it with this keyword.</p>
0
2016-09-29T09:05:29Z
[ "python", "python-3.x", "global-variables" ]
WMI querying issues in Python
2,105,668
<p>I've recently been working on a Squish test script, and trying to do something like what's described in the solution at: <a href="http://stackoverflow.com/questions/938733/python-total-memory-used/938800#938800">http://stackoverflow.com/questions/938733/python-total-memory-used/938800#938800</a></p> <p>The relevant...
2
2010-01-20T22:52:49Z
4,008,056
<p>The WMI syntax seems to have changed from the examples. Try using subset.WorkingSet instead of subset['WorkingSet']</p>
2
2010-10-24T11:45:14Z
[ "python", "wmi", "wmi-query" ]
App Engine urlfetch is raising exceptions when i think it should not be
2,105,971
<p>I've written my first Python application with the App Engine APIs, it is intended to monitor a list of servers and notify me when one of them goes down, by sending a message to my iPhone using Prowl, or sending me an email, or both.</p> <p>Problem is, a few times a week it notifies me a server is down even when it ...
3
2010-01-20T23:57:16Z
2,106,173
<p>other folks have been reporting issues with the fetch service (e.g. <a href="http://code.google.com/p/googleappengine/issues/detail?id=1902&amp;q=urlfetch&amp;colspec=ID%20Type%20Status%20Priority%20Stars%20Owner%20Summary%20Log%20Component" rel="nofollow">http://code.google.com/p/googleappengine/issues/detail?id=19...
2
2010-01-21T00:47:55Z
[ "python", "google-app-engine", "monitoring" ]
Search_fields in django python
2,106,084
<p>I was wondering how I am able to use a foreign key to preform a search for example</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 127) def __unicode__(self): return self.name + " - "...
6
2010-01-21T00:21:12Z
2,106,162
<p>You can specify related field searches in the admin <code>search_fields</code> the same way you do on Django querysets. Check on the <a href="https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields" rel="nofollow">documentation</a>. For the <code>LotComments</code> obje...
14
2010-01-21T00:44:30Z
[ "python", "django-admin" ]
Search_fields in django python
2,106,084
<p>I was wondering how I am able to use a foreign key to preform a search for example</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 127) def __unicode__(self): return self.name + " - "...
6
2010-01-21T00:21:12Z
21,474,255
<p>For referencing the foreign key use <code>__</code> (two underscores):</p> <pre><code>from CMS.Inventory.models import Product class ProductAdmin(admin.ModelAdmin): search_fields=['name__name', 'description', 'code', 'lot_no' ] admin.site.register(Product, padmin) </code></pre>
1
2014-01-31T07:02:09Z
[ "python", "django-admin" ]
Search_fields in django python
2,106,084
<p>I was wondering how I am able to use a foreign key to preform a search for example</p> <pre><code>class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 127) def __unicode__(self): return self.name + " - "...
6
2010-01-21T00:21:12Z
32,028,116
<p>Adding to the previous answers. I would like to suggest <a href="https://github.com/modlinltd/django-advanced-filters" rel="nofollow">Django Admin advance filters</a></p> <p>User this plugin to add advance search and save advance search support. Also in your case foreign key fields can be mapped to a name.</p> <pr...
2
2015-08-15T18:45:41Z
[ "python", "django-admin" ]
PyQt post installation question
2,106,178
<p>I successfully installed PyQt in both mac and PC. To do so I had to install mingw (on PC), Xcode (on MAC) and Qt4.6 library. Now that I have PyQt working perfectly, I would like to uninstall mingw, Xcode and Qt Library from both mac and PC. </p> <p>I know I can remove Xcode and mingw, but what care should I take be...
3
2010-01-21T00:50:59Z
2,184,315
<p>You can remove the <code>demos</code> and <code>examples</code> directories inside your qt installation directory... they take up over 1GB of space and are not required. I would leave the rest there, unless you are really worried about space.</p> <p>If you <em>do</em> try to clean up the QT installation directory, ...
1
2010-02-02T13:29:20Z
[ "python", "pyqt4" ]