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 |
|---|---|---|---|---|---|---|---|---|---|
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,153 | <p>you can see <a href="http://groups.google.com.sg/group/comp.lang.python/browse_thread/thread/ae048e3a99f1d04b/f43385cdccd633df?hl=en&lnk=gst&q=why+tuples#f43385cdccd633df" rel="nofollow">here</a> for some discussion on this</p>
| 1 | 2010-02-01T01:17:12Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,170 | <ol>
<li><p>immutable objects can allow substantial optimization; this is presumably why strings are also immutable in Java, developed quite separately but about the same time as Python, and just about everything is immutable in truly-functional languages.</p></li>
<li><p>in Python in particular, only immutables can be... | 98 | 2010-02-01T01:23:20Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,172 | <blockquote>
<p>if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in the first place?</p>
</blockquote>
<p>In this particular case, there probably isn't a point. This is a non-issue, because this isn't one of the cases where you'd consider using a tuple.</p>
<p>As... | 18 | 2010-02-01T01:23:45Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,236 | <p>None of the answers above point out the real issue of tuples vs lists, which many new to Python seem to not fully understand.</p>
<p>Tuples and lists serve different purposes. Lists store homogenous data. You can and should have a list like this:</p>
<pre><code>["Bob", "Joe", "John", "Sam"]
</code></pre>
<p>The r... | 31 | 2010-02-01T01:50:23Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,274 | <p>They are important since they guarantee the caller that the object they pass won't be mutated.
If you do this:</p>
<pre><code>a = [1,1,1]
doWork(a)
</code></pre>
<p>The caller has no guarantee of the value of <strong>a</strong> after the call.
However, </p>
<pre><code>a = (1,1,1)
doWorK(a)
</code></pre>
<p>Now y... | 3 | 2010-02-01T02:01:54Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,283 | <p>I've always found having two completely separate types for the same basic data structure (arrays) to be an awkward design, but not a real problem in practice. (Every language has its warts, Python included, but this isn't an important one.)</p>
<blockquote>
<p>Why does anyone care if a variable lives at a differ... | 7 | 2010-02-01T02:06:06Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,174,539 | <p>Your question (and follow-up comments) focus on whether the id() changes during an assignment. Focusing on this follow-on effect of the difference between immutable object replacement and mutable object modification rather than the difference itself is perhaps not the best approach.</p>
<p>Before we continue, make ... | 1 | 2010-02-01T03:42:13Z | [
"python",
"tuples"
] |
Why do we need tuples in Python (or any immutable data type)? | 2,174,124 | <p>I've read several python tutorials (Dive Into Python, for one), and the language reference on Python.org - I don't see why the language needs tuples.</p>
<p>Tuples have no methods compared to a list or set, and if I must convert a tuple to a set or list to be able to sort them, what's the point of using a tuple in ... | 102 | 2010-02-01T01:08:15Z | 2,176,034 | <p>As gnibbler offered in a comment, Guido had an <a href="http://aspn.activestate.com/ASPN/Mail/Message/python-list/1566320">opinion</a> that is not fully accepted/appreciated: âlists are for homogeneous data, tuples are for heterogeneous dataâ. Of course, many of the opposers interpreted this as meaning that all ... | 6 | 2010-02-01T10:41:30Z | [
"python",
"tuples"
] |
Having trouble with py.test remote | 2,174,238 | <p>I love py.test and am trying to get the remote test execution feature to work so I can run tests on a remote machine. There is very little doc and I am getting frustrated with it. Any help figuring out what I am doing wrong is appreciated. Here is my command line on the main server:</p>
<pre><code>c:\Python26\Sc... | 2 | 2010-02-01T01:51:06Z | 3,254,052 | <p>Could you try to rerun with latest versions of pytest and pytest-xdist? </p>
| 1 | 2010-07-15T09:05:08Z | [
"python",
"py.test"
] |
django error ,about django-sphinx | 2,174,400 | <pre><code>from django.db import models
from djangosphinx.models import SphinxSearch
class MyModel(models.Model):
search = SphinxSearch() # optional: defaults to db_table
# If your index name does not match MyModel._meta.db_table
# Note: You can only generate automatic configurations from the ./manage.py s... | 0 | 2010-02-01T02:57:15Z | 2,174,778 | <p>The error is about the environment. Django cannot find your settings file; Are you doing </p>
<p><code>python manage.py runserver</code></p>
<p>itself, or something else?</p>
| 0 | 2010-02-01T05:09:43Z | [
"python",
"django",
"django-sphinx"
] |
django error ,about django-sphinx | 2,174,400 | <pre><code>from django.db import models
from djangosphinx.models import SphinxSearch
class MyModel(models.Model):
search = SphinxSearch() # optional: defaults to db_table
# If your index name does not match MyModel._meta.db_table
# Note: You can only generate automatic configurations from the ./manage.py s... | 0 | 2010-02-01T02:57:15Z | 4,054,847 | <p>I know what the problem is :)</p>
<p>You are trying to run this script as stand-alone. But since you use django models. all of them have to be imported in your <code>namespace</code>. This is what is the error. It clearly days <code>ImportError</code>.</p>
<p>To solve - go to your django-project directory & th... | 1 | 2010-10-29T18:40:11Z | [
"python",
"django",
"django-sphinx"
] |
In the Python version of Google App Engine, what is the easiest way to mock or subclass the File class so that software written to access files does not throw an exception? | 2,174,596 | <p>I would like to run some code on the Python version of Google App Engine that uses the built in File type. Iâm looking for the easiest way to stop GAE from throwing errors due to illegal access. Has anyone already sub-classed or mocked File to read and write to memory rather than to the disk? I donât need persis... | 1 | 2010-02-01T04:03:14Z | 2,174,601 | <pre><code>import __builtin__
import StringIO
class File(StringIO.StringIO):
def __init__(self, *a, **k): pass
__builtin__.file = __builtin__.open = File
</code></pre>
<p>You'll surely want finer-grained simulation, but this works as a very rough first cut.</p>
| 5 | 2010-02-01T04:06:13Z | [
"python",
"google-app-engine"
] |
unpredicted output binary search tree in python | 2,174,679 | <pre><code>class Node():
def __init__(self,data, left=None, right=None):
self.data = data
self.left = left
self.right = right
class BSTree():
def __init__(self):
self.root = None
def add(self,data):
if self.root is None:
self.root = Node(data)
... | 1 | 2010-02-01T04:36:09Z | 2,174,696 | <pre><code> def __add(self,node,data):
if node is None:
return Node(data)
else:
if data < node.data:
node.left = self.__add(node.left,data)
elif data > node.data:
node.right = self.__add(node.right,data)
</code></pre>
<p>... | 3 | 2010-02-01T04:40:33Z | [
"python",
"binary-tree"
] |
unpredicted output binary search tree in python | 2,174,679 | <pre><code>class Node():
def __init__(self,data, left=None, right=None):
self.data = data
self.left = left
self.right = right
class BSTree():
def __init__(self):
self.root = None
def add(self,data):
if self.root is None:
self.root = Node(data)
... | 1 | 2010-02-01T04:36:09Z | 2,179,152 | <p>I figured out the answer. Thank you to danben for guidance in getting there! It was a combination of what he was saying and looking at some other implementations on my own. Here is what I came up with in case anyone was wondering.</p>
<pre><code>class Node():
def __init__(self,data, left=None, right=None):
... | 0 | 2010-02-01T18:43:25Z | [
"python",
"binary-tree"
] |
PyGTK: How do I make a custom widget look like a gtk.Notebook tab? | 2,174,873 | <p>I'm writing a program and I need some extra functionality from the gtk.Notebook widget, so I have taken to creating my own.</p>
<p>My only problem is styling my tabs so that they look like the tabs in gtk.Notebook and will change according to the user's theme.</p>
<p>I really don't know where to start so any advic... | 0 | 2010-02-01T05:43:14Z | 2,212,682 | <p>I solved the problem eventually by getting the colours from gtk.Notebook's style.</p>
| 0 | 2010-02-06T09:42:20Z | [
"python",
"coding-style",
"tabs",
"pygtk"
] |
PyGTK: How do I make a custom widget look like a gtk.Notebook tab? | 2,174,873 | <p>I'm writing a program and I need some extra functionality from the gtk.Notebook widget, so I have taken to creating my own.</p>
<p>My only problem is styling my tabs so that they look like the tabs in gtk.Notebook and will change according to the user's theme.</p>
<p>I really don't know where to start so any advic... | 0 | 2010-02-01T05:43:14Z | 2,786,548 | <p>Just for the record, if you are going to create something similar to a gtk.Notebook, I'll recomment you to subclass gtk.Notebook to save a lot of work.</p>
| 0 | 2010-05-07T06:10:31Z | [
"python",
"coding-style",
"tabs",
"pygtk"
] |
Making wxPython GUI launch on a different screen from Eclipse | 2,174,904 | <p>I currently have a dual-monitor setup with Eclipse on monitor 2. When I run the code that launches the wxPython GUI, I would like for this GUI to appear on monitor 1. Currently, the GUI consistently appears on monitor 2, covering Eclipse, and I have to drag it to monitor 1 every time. Is there a solution to this pro... | 0 | 2010-02-01T05:50:51Z | 2,174,947 | <p>I'm not entirely sure, but I think I remember reading something about windows sticking to the same monitor as the process that spawned them. Therefore, it might be a worthwhile experiment to edit your code in eclipse (on monitor 2) and have a command prompt window open on monitor 1 from which you can run the python ... | 1 | 2010-02-01T06:03:35Z | [
"python",
"eclipse",
"wxpython"
] |
Making wxPython GUI launch on a different screen from Eclipse | 2,174,904 | <p>I currently have a dual-monitor setup with Eclipse on monitor 2. When I run the code that launches the wxPython GUI, I would like for this GUI to appear on monitor 1. Currently, the GUI consistently appears on monitor 2, covering Eclipse, and I have to drag it to monitor 1 every time. Is there a solution to this pro... | 0 | 2010-02-01T05:50:51Z | 2,182,198 | <p>The best kludge I found was the Kubuntu global shortcut "Ctrl-Shift-Space". This moves a window to the other screen, mitigating the hassle of dragging with the mouse.</p>
| 0 | 2010-02-02T06:10:56Z | [
"python",
"eclipse",
"wxpython"
] |
Making wxPython GUI launch on a different screen from Eclipse | 2,174,904 | <p>I currently have a dual-monitor setup with Eclipse on monitor 2. When I run the code that launches the wxPython GUI, I would like for this GUI to appear on monitor 1. Currently, the GUI consistently appears on monitor 2, covering Eclipse, and I have to drag it to monitor 1 every time. Is there a solution to this pro... | 0 | 2010-02-01T05:50:51Z | 2,189,730 | <p>Kludge #2: If I run the code from Eclipse on screen 2 then click someplace on screen 1 before the GUI appears, the GUI will appear on screen 1.</p>
| 0 | 2010-02-03T04:32:56Z | [
"python",
"eclipse",
"wxpython"
] |
Opening POSTed file with PIL Image | 2,174,938 | <p>Using WSGI, webob and PIL, I'm trying to use <code>Image.open()</code> on a file directly from the request. However, <code>Image.open()</code> always throws the exception "cannot identify image file". The image is the only field, no other POST or GET variables are used. The file is coming from a standard HTML upl... | 1 | 2010-02-01T06:01:12Z | 2,179,034 | <p>I'm not famaliar with webob, but my guess is that body_file contains the contents of the entire post and not just your image. The <a href="http://pythonpaste.org/webob/reference.html#request-body" rel="nofollow">docs</a> seem to confirm this.</p>
<p>What's in req.POST['nameOfFileControl']? Does that have a file h... | 3 | 2010-02-01T18:23:41Z | [
"python",
"mod-wsgi",
"webob"
] |
Migrating from Javadoc to Python Documentation | 2,175,040 | <p>So I've gotten somewhat used to Javadoc style documentation. Looking through various examples of Python code, I'm finding that, at first blush, the documentation <em>seems</em> to be missing a lot of information.</p>
<p>The good: vary rarely do you see self-evident bits of documentation. Docstrings are usually a pa... | 6 | 2010-02-01T06:26:41Z | 2,175,074 | <p>The <a href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> format was designed in response to the need for Python documentation that could be embedded in docstrings, so the best thing is to <strong>learn reST and format your docstrings with that format</strong>. You might find, as I did, that you th... | 9 | 2010-02-01T06:37:25Z | [
"python",
"documentation",
"python-sphinx"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 2,175,096 | <p>You can split on a range of characters using the <code>re</code> module.</p>
<pre><code>>>> import re
>>> r = re.compile('[ \t\n\r:]+')
>>> r.split("abc:def ghi")
['abc', 'def', 'ghi']
</code></pre>
| 22 | 2010-02-01T06:41:49Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 2,175,126 | <p>you can turn the ":" to space, and do the split.eg</p>
<pre><code>>>> f=open("/proc/net/dev")
>>> for line in f:
... line=line.replace(":"," ").split()
... print len(line)
</code></pre>
<p>no regex needed (for this case)</p>
| 1 | 2010-02-01T06:50:34Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 2,175,135 | <p>Python doesn't have an <code>sscanf</code> equivalent built-in, and most of the time it actually makes a whole lot more sense to parse the input by working with the string directly, using regexps, or using a parsing tool. </p>
<p>Probably mostly useful for translating C, people have implemented <code>sscanf</code>,... | 22 | 2010-02-01T06:51:50Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 2,176,352 | <p>If the separators are ':', you can split on ':', and then use x.strip() on the strings to get rid of any leading or trailing whitespace. int() will ignore the spaces.</p>
| 0 | 2010-02-01T11:38:34Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 2,180,718 | <p>You can parse with module <code>re</code> using <a href="http://docs.python.org/library/re.html#regular-expression-syntax">named groups</a>. It won't parse the substrings to their actual datatypes (e.g. <code>int</code>) but it's very convenient when parsing strings.</p>
<p>Given this sample line from <code>/proc/n... | 12 | 2010-02-01T23:02:59Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 3,546,379 | <p>Upvoted orip's answer. I think it is sound advice to use re module. The Kodos application is helpful when approaching a complex regexp task with Python. </p>
<p><a href="http://kodos.sourceforge.net/home.html" rel="nofollow">http://kodos.sourceforge.net/home.html</a></p>
| 1 | 2010-08-23T09:46:34Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 4,157,213 | <p>There is an ActiveState recipe which implements a basic scanf
<a href="http://code.activestate.com/recipes/502213-simple-scanf-implementation/" rel="nofollow">http://code.activestate.com/recipes/502213-simple-scanf-implementation/</a></p>
| 2 | 2010-11-11T17:21:51Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 11,085,456 | <p>When I'm in a C mood, I usually use zip and list comprehensions for scanf-like behavior. Like this:</p>
<pre><code>input = '1 3.0 false hello'
(a, b, c, d) = [t(s) for t,s in zip((int,float,bool,str),input.split())]
print (a, b, c, d)
</code></pre>
<p>Note that for more complex format strings, you do need to use ... | 33 | 2012-06-18T14:55:37Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 12,848,777 | <p>There is a <a href="https://gist.github.com/1488598" rel="nofollow">Python 2 implementation by odiak</a>.</p>
| 0 | 2012-10-11T21:28:21Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
sscanf in Python | 2,175,080 | <p>I'm looking for an equivalent to <code>sscanf()</code> in Python. I want to parse <code>/proc/net/*</code> files, in C I could do something like this:</p>
<pre><code>int matches = sscanf(
buffer,
"%*d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %*X %*X:%*X %*X:%*X %*X %*d %*d %ld %*512s\n",
local_a... | 42 | 2010-02-01T06:38:38Z | 12,852,181 | <p>There is also the <a href="http://pypi.python.org/pypi/parse"><code>parse</code></a> module.</p>
<p><code>parse()</code> is designed to be the opposite of <code>format()</code> (the newer string formatting function in Python 2.6 and higher).</p>
| 21 | 2012-10-12T04:18:49Z | [
"python",
"parsing",
"split",
"sscanf",
"procfs"
] |
Error when using Django SVN version | 2,175,286 | <p>I've written some code that works fine when I use Django 1.1, but raises an exception when I use the SVN version:</p>
<pre><code>class TribeForm(forms.ModelForm):
slug = forms.SlugField(max_length=20,
help_text = _("a short version of the name consisting only of letters, numbers, underscores and hyphens... | -1 | 2010-02-01T07:39:15Z | 2,175,389 | <p>It's saying error_message was an unexpected keyword argument. Try error_messages instead: <a href="http://docs.djangoproject.com/en/dev/ref/forms/fields/#error-messages" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/forms/fields/#error-messages</a></p>
| 0 | 2010-02-01T08:16:53Z | [
"python",
"django"
] |
Error when using Django SVN version | 2,175,286 | <p>I've written some code that works fine when I use Django 1.1, but raises an exception when I use the SVN version:</p>
<pre><code>class TribeForm(forms.ModelForm):
slug = forms.SlugField(max_length=20,
help_text = _("a short version of the name consisting only of letters, numbers, underscores and hyphens... | -1 | 2010-02-01T07:39:15Z | 8,601,860 | <p>Error message passed from one error message to un unlimited number and 's' was added. Error messages are not expected to be added as a dictionary, not a string.</p>
| 0 | 2011-12-22T09:32:10Z | [
"python",
"django"
] |
Selecting distinct column values in SQLAlchemy/Elixir | 2,175,355 | <p>In a little script I'm writing using SQLAlchemy and Elixir, I need to get all the distinct values for a particular column. In ordinary SQL it'd be a simple matter of</p>
<pre><code>SELECT DISTINCT `column` FROM `table`;
</code></pre>
<p>and I know I could just run that query "manually," but I'd rather stick to the... | 22 | 2010-02-01T08:05:09Z | 2,175,393 | <p>You can query column properties of mapped classes and the Query class has a generative <code>distinct()</code> method:</p>
<pre><code>for value in Session.query(Table.column).distinct():
pass
</code></pre>
| 43 | 2010-02-01T08:17:32Z | [
"python",
"sql",
"sqlalchemy",
"python-elixir"
] |
Selecting distinct column values in SQLAlchemy/Elixir | 2,175,355 | <p>In a little script I'm writing using SQLAlchemy and Elixir, I need to get all the distinct values for a particular column. In ordinary SQL it'd be a simple matter of</p>
<pre><code>SELECT DISTINCT `column` FROM `table`;
</code></pre>
<p>and I know I could just run that query "manually," but I'd rather stick to the... | 22 | 2010-02-01T08:05:09Z | 9,288,171 | <pre><code>for user in session.query(users_table).distinct():
print user.posting_id
</code></pre>
| 2 | 2012-02-15T05:10:05Z | [
"python",
"sql",
"sqlalchemy",
"python-elixir"
] |
Selecting distinct column values in SQLAlchemy/Elixir | 2,175,355 | <p>In a little script I'm writing using SQLAlchemy and Elixir, I need to get all the distinct values for a particular column. In ordinary SQL it'd be a simple matter of</p>
<pre><code>SELECT DISTINCT `column` FROM `table`;
</code></pre>
<p>and I know I could just run that query "manually," but I'd rather stick to the... | 22 | 2010-02-01T08:05:09Z | 35,718,413 | <p>For this class:</p>
<pre><code>class Assurance(db.Model):
name = Column(String)
</code></pre>
<p>you can do this:</p>
<pre><code>assurances = []
for assurance in Assurance.query.distinct(Assurance.name):
assurances.append(assurance.name)
</code></pre>
<p>and you will have the list of distinct values</p>
| 1 | 2016-03-01T08:56:48Z | [
"python",
"sql",
"sqlalchemy",
"python-elixir"
] |
Problem deploying Django-Mingus with Flup and Cherokee. Strange admin behaviour | 2,175,377 | <p>I have a django-mingus blog running perfectly fine with the integrated development web server of django. It's installed in a virtualenv.</p>
<p>Once deployed using the django app wizard of cherokee 0.99.42 the admin pannel is displaying a strange behaviour. Sometimes all apps are displayed in the admin pannel somet... | 1 | 2010-02-01T08:13:38Z | 2,236,822 | <p>I dropped all tables from the database, upgraded to last version of django-mingus after having deleted some dependencies to get them clean installed and I launched the scgi process using a shell script that activate the virtual environment before.
Now everything seems to be stable.</p>
| 0 | 2010-02-10T12:48:03Z | [
"python",
"django",
"cherokee",
"scgi"
] |
Implementing chat system with in Web browser | 2,175,513 | <p>We want to have web based application to track the issues, knowledge management and chat system. Once the user logged in, user can chat with the service engineers.</p>
<p>We will be using Ajax for Chat within the browser. But the server-side we are not sure how to implement chat? The chat history must be saved for ... | 0 | 2010-02-01T08:46:33Z | 2,175,566 | <p>Have you considered using Erlang? It would probably require very little work to get going.</p>
<p>I don't know of any complete systems for what you want, but Erlang is <a href="http://learnyousomeerlang.com/contents" rel="nofollow">very easy to learn</a> and there is <a href="http://tamale.net/erlang/erlchat.shtml"... | 1 | 2010-02-01T09:00:02Z | [
".net",
"php",
"python",
"ruby-on-rails",
"design"
] |
Implementing chat system with in Web browser | 2,175,513 | <p>We want to have web based application to track the issues, knowledge management and chat system. Once the user logged in, user can chat with the service engineers.</p>
<p>We will be using Ajax for Chat within the browser. But the server-side we are not sure how to implement chat? The chat history must be saved for ... | 0 | 2010-02-01T08:46:33Z | 2,176,205 | <p>Oh. If I have to implement something like this, I would take a XMPP (Jabber) server. Why to reinvent?</p>
<p>There are two servers that are pretty stable and feature rich: <a href="http://www.ejabberd.im/" rel="nofollow">ejabberd</a> (implemented in Erlang) and OpenFire (implemented in Java). Personally I prefer <a... | 4 | 2010-02-01T11:12:15Z | [
".net",
"php",
"python",
"ruby-on-rails",
"design"
] |
Implementing chat system with in Web browser | 2,175,513 | <p>We want to have web based application to track the issues, knowledge management and chat system. Once the user logged in, user can chat with the service engineers.</p>
<p>We will be using Ajax for Chat within the browser. But the server-side we are not sure how to implement chat? The chat history must be saved for ... | 0 | 2010-02-01T08:46:33Z | 2,176,316 | <p>We run an XMPP (jabber) server called <a href="http://www.igniterealtime.org/projects/openfire/" rel="nofollow">OpenFire</a>, which has a web-chat extension called FastPath. The one downside is that it forces us all to use the same client (Spark) or risk chat requests that reach non-Spark clients to vanish. But it i... | 2 | 2010-02-01T11:31:58Z | [
".net",
"php",
"python",
"ruby-on-rails",
"design"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,175,805 | <p>This really says it all: </p>
<blockquote>
<p>As the maintainer of PyObjC for nearly
15 years, I will say it bluntly. Use
Objective-C. You will need to know
Objective-C to really understand Cocoa
anyway and PyObjC is just going to add
a layer of bugs & issues that are
alien to 99% of Cocoa program... | 18 | 2010-02-01T09:53:42Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,175,826 | <p>This is something I've been wondering myself, and although I hope someone comes by with more experience, from what I know you will not be seriously constrained by Python itself. Along with Java and GCC, Python is an excellent way to write native cross-platform applications. Once you get the hang of it you should be ... | 0 | 2010-02-01T09:58:45Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,175,875 | <p>Second class citizen seems a bit strong. The Objective-C API's are available from Python as well, should you need them, and that's mostly if you want to make Cocoa apps. But then they are restricted to OS X anyway. Personally, I have no interest in building apps that isn't cross-platform, but that's me. That also me... | 2 | 2010-02-01T10:10:06Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,175,930 | <p>Yes.</p>
<p>For one thing, as you note, all the documentation is written for Objective-C, which is a very different language.</p>
<p>One difference is method name. In Objective-C, when you send a message to (Python would say âcall a method ofâ) an object, the method name (selector) and arguments are mixed:</p>... | 36 | 2010-02-01T10:21:28Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,176,187 | <p><strong>DO NOT ATTEMPT</strong> to avoid learning objective-C if you're going to write apps for the Mac. The purpose of PyObjC and the other language bindings is to let you re-use existing libraries in your apps, not to let you avoid learning the native tools. </p>
| 3 | 2010-02-01T11:10:02Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,176,578 | <p>You're going to need Objective-C: that's what all the tutorials, documentation, sample code, and everything is written in. In addition to a wilder variety of people being able to help you.</p>
<p>So learn ObjC first. If, on your second or third project, or a year down the road, you start a project that needs a Pyth... | 0 | 2010-02-01T12:30:39Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 2,182,286 | <p>Just as an extra option, consider that <a href="http://wxpython.org/" rel="nofollow">wxPython</a> can produce some pretty good applications on Mac as well as on Linux and Windows. For the most part you can get native appearance but maintain portability with little or no attention to platform-specific issues.</p>
<... | 0 | 2010-02-02T06:39:26Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
What are the downsides of using Python instead of Objective-C? | 2,175,573 | <p>I know some Python and I'm really impressed by the language's ease of use. From what I've seen of Objective-C it looks a lot less pretty, but it seems to be the <em>lingua franca</em> for Mac OS X development (which means it has better documentation). </p>
<p>I'm thinking about starting Mac development - will using... | 14 | 2010-02-01T09:01:26Z | 3,759,939 | <p>No you dont need to know Objective C you dont need to use PyObjC , and you wont be a second class citizent. </p>
<p>Unless you want to do something extremely specific to the MAC platform , coding in Objective C or using PyObjC is a really bad idea. </p>
<p>The reason is obvious, once you go the objc route you say ... | 0 | 2010-09-21T11:43:26Z | [
"python",
"cocoa",
"osx",
"pyobjc"
] |
PostgreSQL problem in Django | 2,175,615 | <p>I have a Django application and I'm using postgres. I try to execute the bollowing line in one of my tests: </p>
<pre><code>print BillingUser.objects.all()
</code></pre>
<p>And I get the following error:</p>
<blockquote>
<p>"current transaction is aborted, commands ignored until end of transaction block."</p>
<... | 0 | 2010-02-01T09:15:41Z | 2,175,633 | <p>From the log it looks like you are trying to insert an item with a duplicate ID which throws an error and the rest of your code can't access the DB anymore. Fix that query, and it should work.</p>
| 0 | 2010-02-01T09:20:06Z | [
"python",
"sql",
"django",
"postgresql"
] |
PostgreSQL problem in Django | 2,175,615 | <p>I have a Django application and I'm using postgres. I try to execute the bollowing line in one of my tests: </p>
<pre><code>print BillingUser.objects.all()
</code></pre>
<p>And I get the following error:</p>
<blockquote>
<p>"current transaction is aborted, commands ignored until end of transaction block."</p>
<... | 0 | 2010-02-01T09:15:41Z | 2,175,927 | <p>You insert data in some of your test functions. After invalid insert DB connections is in fail state. You need to rollback transaction or turn it off completely. See django docs on <a href="http://docs.djangoproject.com/en/1.1/topics/db/transactions/#topics-db-transactions" rel="nofollow">transactions</a> and <a hre... | 0 | 2010-02-01T10:21:20Z | [
"python",
"sql",
"django",
"postgresql"
] |
PostgreSQL problem in Django | 2,175,615 | <p>I have a Django application and I'm using postgres. I try to execute the bollowing line in one of my tests: </p>
<pre><code>print BillingUser.objects.all()
</code></pre>
<p>And I get the following error:</p>
<blockquote>
<p>"current transaction is aborted, commands ignored until end of transaction block."</p>
<... | 0 | 2010-02-01T09:15:41Z | 2,216,376 | <p>Ok... looking at the PostgreSQL log, it does look that you are doing a wrong insert that will abort the transaction... now, looking at your code I think the problems lies here:</p>
<p>at lines 78-81</p>
<pre><code> currency = Currency.objects.all()[2]
if not Wallet.objects.filter(user=user):
wallet ... | 1 | 2010-02-07T08:12:49Z | [
"python",
"sql",
"django",
"postgresql"
] |
mercurial - I want to add some custom code to be run after commit | 2,175,788 | <p>where could I place code to be run after every commit I make with mercurial? Specifically, I would like to maintain a file called <strong>latest</strong> inside the .hg folder in the root of my project - that file will hold the revision number and hash code for the most recent commit. On that same topic, how can I g... | 3 | 2010-02-01T09:50:10Z | 2,175,806 | <p><a href="http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html" rel="nofollow">http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html</a></p>
<p>specifically you seem to want the commit hook which there is a tutorial for</p>
<p>of course it sounds like what you really want ... | 5 | 2010-02-01T09:54:22Z | [
"python",
"mercurial",
"automation",
"customization"
] |
Python: Execute multiple Scripts simultaneously from same Interpreter | 2,176,053 | <p>I have a <strong>python script</strong>, which is executing again <strong>4-5 python scripts</strong>.
For performance reasons i want to use same interpreter for executing all the script.</p>
<p>How could I handle this issue?</p>
| 1 | 2010-02-01T10:44:34Z | 2,176,058 | <p>The currently executing interpreter is available in <code>sys.executable</code>. You can just pass that explicitly to subprocess.Popen as the first argument, or pass it as the 'executable' argument.</p>
| 0 | 2010-02-01T10:45:41Z | [
"python"
] |
Python: Execute multiple Scripts simultaneously from same Interpreter | 2,176,053 | <p>I have a <strong>python script</strong>, which is executing again <strong>4-5 python scripts</strong>.
For performance reasons i want to use same interpreter for executing all the script.</p>
<p>How could I handle this issue?</p>
| 1 | 2010-02-01T10:44:34Z | 2,176,146 | <p>The obvious solution (which may require a little tweaking) is to just call the main function of each script from a master script. E.g., if script1.py contains:</p>
<pre><code>#!/usr/bin/python
def main():
// Do something
if __name__ == "__main__":
main()
</code></pre>
<p>put in master.py</p>
<pre><code>#!/u... | 8 | 2010-02-01T11:01:03Z | [
"python"
] |
Python: Execute multiple Scripts simultaneously from same Interpreter | 2,176,053 | <p>I have a <strong>python script</strong>, which is executing again <strong>4-5 python scripts</strong>.
For performance reasons i want to use same interpreter for executing all the script.</p>
<p>How could I handle this issue?</p>
| 1 | 2010-02-01T10:44:34Z | 2,177,244 | <p>Maybe you're looking for the <a href="http://docs.python.org/library/functions.html#execfile" rel="nofollow"><code>execfile</code></a> function in Python 2.x.</p>
<p>In Python 3 it was removed, but <a href="http://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3-0">there are simple ... | 3 | 2010-02-01T14:17:10Z | [
"python"
] |
Python: Execute multiple Scripts simultaneously from same Interpreter | 2,176,053 | <p>I have a <strong>python script</strong>, which is executing again <strong>4-5 python scripts</strong>.
For performance reasons i want to use same interpreter for executing all the script.</p>
<p>How could I handle this issue?</p>
| 1 | 2010-02-01T10:44:34Z | 5,222,644 | <p>I don't think this is recommended, but worst case scenario you could make the system 'run' each script from within another:</p>
<pre><code>import os
os.system('python script1.py')
os.system('python script2.py')
os.system('python script3.py')
os.system('python script4.py')
</code></pre>
| 0 | 2011-03-07T17:02:45Z | [
"python"
] |
Django admin authentication failure | 2,176,172 | <p>logging into django admin fails when 'log in' button is pressed first
time, but pressing "back" and "log in' again - logs the user in
successfully.</p>
<p>I am deploying Django app with zc.buildout here, with a setup similar
to what is described here <a href="http://www.meppum.com/2009/jan/17/installing-django-ubun... | 1 | 2010-02-01T11:05:46Z | 2,176,256 | <p>Your settings are incorrect. Django believes that it runs on port 80. Look at this line in the first HTTP response:</p>
<pre><code>Location: http://127.0.0.1/admin/
</code></pre>
<p>Unfortunately, I can't understand right now why this happens. I prefer just to step throught the relevant Django code with a debugger... | 1 | 2010-02-01T11:21:55Z | [
"python",
"django",
"apache",
"nginx",
"buildout"
] |
Django admin authentication failure | 2,176,172 | <p>logging into django admin fails when 'log in' button is pressed first
time, but pressing "back" and "log in' again - logs the user in
successfully.</p>
<p>I am deploying Django app with zc.buildout here, with a setup similar
to what is described here <a href="http://www.meppum.com/2009/jan/17/installing-django-ubun... | 1 | 2010-02-01T11:05:46Z | 2,178,048 | <p>@Eugene Morozov has pointed out the end result of the problem, but I think the solution lies deeper.</p>
<p>The <code>Location</code> header being returned is incorrect:</p>
<pre><code>Location: http://127.0.0.1/admin/
</code></pre>
<p>This is clearly missing the port number. Unfortunately, it is hard to tell ex... | 1 | 2010-02-01T16:03:35Z | [
"python",
"django",
"apache",
"nginx",
"buildout"
] |
Django admin authentication failure | 2,176,172 | <p>logging into django admin fails when 'log in' button is pressed first
time, but pressing "back" and "log in' again - logs the user in
successfully.</p>
<p>I am deploying Django app with zc.buildout here, with a setup similar
to what is described here <a href="http://www.meppum.com/2009/jan/17/installing-django-ubun... | 1 | 2010-02-01T11:05:46Z | 2,193,295 | <p>Euge, James,</p>
<p>thanks a lot for your help once again!</p>
<p>The solution turned out to be described <a href="http://forum.slicehost.com/comments.php?DiscussionID=3065" rel="nofollow">here</a>: changing <code>proxy_set_headerHost $host;</code> to <code>proxy_set_headerHost $host:$server_port;</code> did the t... | 1 | 2010-02-03T16:01:59Z | [
"python",
"django",
"apache",
"nginx",
"buildout"
] |
Can Django ORM do an ORDER BY on a specific value of a column? | 2,176,346 | <p>I have a table 'tickets' with the following columns</p>
<ul>
<li>id - primary key - auto increment</li>
<li>title - varchar(256)</li>
<li>status - smallint(6) - Can have any value between 1 and 5, handled by Django</li>
</ul>
<p>When I'll do a <code>SELECT *</code> I want the rows with <code>status = 4</code> at t... | 13 | 2010-02-01T11:37:39Z | 2,176,471 | <pre><code>q = Ticket.objects.extra(select={'is_top': "status = 4"})
q = q.extra(order_by = ['-is_top'])
</code></pre>
| 17 | 2010-02-01T12:08:41Z | [
"python",
"mysql",
"django",
"orm"
] |
Hiding axis text in matplotlib plots | 2,176,424 | <p>I'm trying to plot a figure without tickmarks or numbers on either of the axes (I use axes in the traditional sense, not the matplotlib nomenclature!). An issue I have come across is where matplotlib adjusts the x(y)ticklabels by subtracting a value N, then adds N at the end of the axis.</p>
<p>This may be vague, b... | 137 | 2010-02-01T11:56:52Z | 2,176,591 | <p>Instead of hiding each element, you can hide the whole axis:</p>
<pre><code>frame1.axes.get_xaxis().set_visible(False)
frame1.axes.get_yaxis().set_visible(False)
</code></pre>
<p>Or, you can set the ticks to an empty list:</p>
<pre><code>frame1.axes.get_xaxis().set_ticks([])
frame1.axes.get_yaxis().set_ticks([])
... | 204 | 2010-02-01T12:34:02Z | [
"python",
"matplotlib",
"plot"
] |
Hiding axis text in matplotlib plots | 2,176,424 | <p>I'm trying to plot a figure without tickmarks or numbers on either of the axes (I use axes in the traditional sense, not the matplotlib nomenclature!). An issue I have come across is where matplotlib adjusts the x(y)ticklabels by subtracting a value N, then adds N at the end of the axis.</p>
<p>This may be vague, b... | 137 | 2010-02-01T11:56:52Z | 16,758,931 | <p>If you want to hide just the axis text keeping the grid lines:</p>
<pre><code>frame1.axes.xaxis.set_ticklabels([])
frame1.axes.yaxis.set_ticklabels([])
</code></pre>
<p>Doing <code>set_visible(False)</code> or <code>set_ticks([])</code> will also hide the grid lines.</p>
| 94 | 2013-05-26T11:48:34Z | [
"python",
"matplotlib",
"plot"
] |
Hiding axis text in matplotlib plots | 2,176,424 | <p>I'm trying to plot a figure without tickmarks or numbers on either of the axes (I use axes in the traditional sense, not the matplotlib nomenclature!). An issue I have come across is where matplotlib adjusts the x(y)ticklabels by subtracting a value N, then adds N at the end of the axis.</p>
<p>This may be vague, b... | 137 | 2010-02-01T11:56:52Z | 28,198,278 | <p>Somewhat of an old thread but, this seems to be a faster method using the latest version of matplotlib:</p>
<p>set the major formatter for the x-axis</p>
<pre><code>ax.xaxis.set_major_formatter(plt.NullFormatter())
</code></pre>
| 22 | 2015-01-28T17:11:18Z | [
"python",
"matplotlib",
"plot"
] |
How do I convert a string to a buffer in Python 3.1? | 2,176,511 | <p>I am attempting to pipe something to a <code>subprocess</code> using the following line:</p>
<pre><code>p.communicate("insert into egg values ('egg');");
TypeError: must be bytes or buffer, not str
</code></pre>
<p>How can I convert the string to a buffer?</p>
| 9 | 2010-02-01T12:17:21Z | 2,176,556 | <p>You can convert it to bytes with <a href="http://docs.python.org/3.1/library/stdtypes.html#str.encode" rel="nofollow"><code>encode</code></a> method:</p>
<pre><code>>>> "insert into egg values ('egg');".encode('ascii') # ascii is just an example
b"insert into egg values ('egg');"
</code></pre>
| 5 | 2010-02-01T12:26:38Z | [
"python",
"python-3.x"
] |
How do I convert a string to a buffer in Python 3.1? | 2,176,511 | <p>I am attempting to pipe something to a <code>subprocess</code> using the following line:</p>
<pre><code>p.communicate("insert into egg values ('egg');");
TypeError: must be bytes or buffer, not str
</code></pre>
<p>How can I convert the string to a buffer?</p>
| 9 | 2010-02-01T12:17:21Z | 2,177,392 | <p>The correct answer is:</p>
<pre><code>p.communicate(b"insert into egg values ('egg');");
</code></pre>
<p>Note the leading b, telling you that it's a string of bytes, not a string of unicode characters. Also, if you are reading this from a file:</p>
<pre><code>value = open('thefile', 'rt').read()
p.communicate(va... | 10 | 2010-02-01T14:38:16Z | [
"python",
"python-3.x"
] |
Filter files in a very large folder | 2,177,250 | <p>I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?</p>
<p>Here's my code:</p>
<pre><c... | 6 | 2010-02-01T14:18:01Z | 2,177,293 | <pre><code>import os,shutil
os.chdir("/mydir/")
numlines=20
destination = os.path.join("/destination","dir1")
for file in os.listdir("."):
if os.path.isfile(file):
flag=0
for n,line in enumerate(open(file)):
if n > numlines:
flag=1
break
if fla... | 0 | 2010-02-01T14:24:27Z | [
"python",
"file-io"
] |
Filter files in a very large folder | 2,177,250 | <p>I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?</p>
<p>Here's my code:</p>
<pre><c... | 6 | 2010-02-01T14:18:01Z | 2,177,294 | <p>A couple thoughts. First, you might use the <a href="http://docs.python.org/library/glob.html" rel="nofollow"><code>glob</code></a> module to get smaller groups of files. Second, sorting by line count is going to be very time consuming, as you have to open every file and count lines. If you can partition by byte ... | 2 | 2010-02-01T14:24:35Z | [
"python",
"file-io"
] |
Filter files in a very large folder | 2,177,250 | <p>I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?</p>
<p>Here's my code:</p>
<pre><c... | 6 | 2010-02-01T14:18:01Z | 2,177,454 | <p>you might try using <a href="http://docs.python.org/library/glob.html" rel="nofollow"><code>glob.iglob</code></a> that returns an iterator:</p>
<pre><code>topdir = os.path.join('/somedir', 'labels', '*')
for filename in glob.iglob(topdir):
if filelen(filename) > 15:
#do stuff
</code></pre>
<p>Als... | 4 | 2010-02-01T14:48:26Z | [
"python",
"file-io"
] |
Filter files in a very large folder | 2,177,250 | <p>I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?</p>
<p>Here's my code:</p>
<pre><c... | 6 | 2010-02-01T14:18:01Z | 2,178,280 | <p>how about using a shell script? you could pick one file at a time:</p>
<pre><code>for f in `ls`;
loop
if `wc -l f`>20; then
mv f newfolder
fi
end loop
</code></pre>
<p>ppl please correct if i am wrong in any way</p>
| 0 | 2010-02-01T16:32:33Z | [
"python",
"file-io"
] |
Filter files in a very large folder | 2,177,250 | <p>I have a folder with 100k text files. I want to put files with over 20 lines in another folder. How do I do this in python? I used os.listdir, but of course, there isn't enough memory for even loading the filenames into memory. Is there a way to get maybe 100 filenames at a time?</p>
<p>Here's my code:</p>
<pre><c... | 6 | 2010-02-01T14:18:01Z | 2,183,819 | <p>The currently accepted answer just plain doesn't work. This function:</p>
<pre><code>def many_line(fname, many=15):
for i, line in enumerate(line):
if i > many:
return True
return False
</code></pre>
<p>has two problems: Firstly, the <code>fname</code> arg is not used and the file is... | 0 | 2010-02-02T12:08:03Z | [
"python",
"file-io"
] |
Individually labeled bars for bar graphs in matplotlib / Python | 2,177,504 | <p>I am trying to create bar graphs of letter frequency in Python. I thought the best way to accomplish this would be matplotlib, but I have been unable to decipher the documentation. Is it possible to label the bars of a matplotlib.pyplot.hist plot with one letter per bar, instead of a numerical axis? I think it must ... | 11 | 2010-02-01T14:55:14Z | 2,177,537 | <p>Sure is! You just need to reset the tick labels.</p>
<p>EDIT with answer and picture (can be done similarly with <code>hist</code>):</p>
<pre><code>x = scipy.arange(4)
y = scipy.array([4,7,6,5])
f = pylab.figure()
ax = f.add_axes([0.1, 0.1, 0.8, 0.8])
ax.bar(x, y, align='center')
ax.set_xticks(x)
ax.set_xticklabel... | 24 | 2010-02-01T15:00:58Z | [
"python",
"label",
"plot",
"matplotlib",
"histogram"
] |
How to actually build 64-bit Python on OS X 10.6.2 | 2,177,705 | <p>Why? I want to do this because installation of SciPy recommends it, and I thought it would be a good learning experience. This question has been asked before (e.g. <a href="http://stackoverflow.com/questions/2111283">here</a>). The preferred answer seems to be to use MacPorts, but as I say, I'd like to understand... | 3 | 2010-02-01T15:24:06Z | 2,177,972 | <p>Your <code>./configure</code> option is not correct. <code>--enable-universalsdk</code> should be set to the correct SDK, not <code>/</code>!
That's why <code>gcc</code> got confused, see the option <code>-isysroot</code>.
So, check what SDKs you have in <code>/Developer/SDKs</code>, and set the correct one.</p>
<... | 1 | 2010-02-01T15:54:07Z | [
"python",
"osx"
] |
How to actually build 64-bit Python on OS X 10.6.2 | 2,177,705 | <p>Why? I want to do this because installation of SciPy recommends it, and I thought it would be a good learning experience. This question has been asked before (e.g. <a href="http://stackoverflow.com/questions/2111283">here</a>). The preferred answer seems to be to use MacPorts, but as I say, I'd like to understand... | 3 | 2010-02-01T15:24:06Z | 2,202,153 | <p>In order to choose an answer as correct, I'm paraphrasing comments above:</p>
<p>As noticed by Virgil Dupras, there <em>was</em> a typo in this flag:</p>
<pre><code>--with-universal-archs=intel
</code></pre>
<p>It originates from the file <code>Mac/readme</code>, but I should've caught it before posting.
Also I r... | 1 | 2010-02-04T18:28:46Z | [
"python",
"osx"
] |
Python: How do I disallow imports of a class from a module? | 2,177,817 | <p>I tried:</p>
<pre><code>__all__ = ['SpamPublicClass']
</code></pre>
<p>But, of course that's just for:</p>
<pre><code>from spammodule import *
</code></pre>
<p>Is there a way to block importing of a class. I'm worried about confusion on the API level of my code that somebody will write:</p>
<pre><code>from spam... | 2 | 2010-02-01T15:37:08Z | 2,177,877 | <p>Start the names of private classes with and underscore, so that it will be clear just by the name that it is not for public use. That will not actually prevent anybody from importing the class, but it shouldn't happen by accident. It's a well established convention that names starting with an underscore are "interna... | 5 | 2010-02-01T15:45:20Z | [
"python",
"import",
"python-module",
"python-import"
] |
Python: How do I disallow imports of a class from a module? | 2,177,817 | <p>I tried:</p>
<pre><code>__all__ = ['SpamPublicClass']
</code></pre>
<p>But, of course that's just for:</p>
<pre><code>from spammodule import *
</code></pre>
<p>Is there a way to block importing of a class. I'm worried about confusion on the API level of my code that somebody will write:</p>
<pre><code>from spam... | 2 | 2010-02-01T15:37:08Z | 2,177,890 | <p>The convention is to use a _ as a prefix:</p>
<pre><code>class PublicClass(object):
pass
class _PrivateClass(object):
pass
</code></pre>
<p>The following:</p>
<pre><code>from module import *
</code></pre>
<p>Will not import the _PrivateClass.</p>
<p>But this will not prevent them from importing it. Th... | 9 | 2010-02-01T15:46:36Z | [
"python",
"import",
"python-module",
"python-import"
] |
Python: How do I disallow imports of a class from a module? | 2,177,817 | <p>I tried:</p>
<pre><code>__all__ = ['SpamPublicClass']
</code></pre>
<p>But, of course that's just for:</p>
<pre><code>from spammodule import *
</code></pre>
<p>Is there a way to block importing of a class. I'm worried about confusion on the API level of my code that somebody will write:</p>
<pre><code>from spam... | 2 | 2010-02-01T15:37:08Z | 2,177,905 | <p><strong>There is no way to actually block access to the contents of a module</strong> or the contents of a class for that matter in Python. <strong>This sort of thing is handled by convention</strong> name your class <code>_SimilarSpamClass</code> (with a leading underscore) to indicate to callers that this is an im... | 4 | 2010-02-01T15:47:36Z | [
"python",
"import",
"python-module",
"python-import"
] |
How can I step into pdb to diagnose this error on a production server? ProgrammingError(1110, "Column 'about' specified twice" | 2,177,929 | <pre><code>ProgrammingError(1110, "Column 'about' specified twice"
/usr/local/lib/python2.5/site-packages/MySQLdb/connections.py
errorclass
<class '_mysql_exceptions.ProgrammingError'>
errorvalue
ProgrammingError(1110, "Column 'about' specified twice")
</code></pre>
<p>This error seems to be happen... | 1 | 2010-02-01T15:49:31Z | 2,178,568 | <p>If you're asking how to break into pdb, add this line in your code where you want to drop into the debugger:</p>
<pre><code>import pdb; pdb.set_trace()
</code></pre>
<p>If you need to know how to have a stdout on your production server, I don't know that.</p>
| 0 | 2010-02-01T17:10:06Z | [
"python",
"django",
"pdb"
] |
Drawing anti-aliased lines in wx? | 2,178,268 | <p>I've got a program that draws my mouse movements on a window.
The only problem is the line is very rough, and i would like it (not where two different lines link, but the actual line) to be anti-aliased and to fall-off nicely. Is there a way to do that?</p>
| 2 | 2010-02-01T16:30:53Z | 2,180,012 | <p><a href="http://www.wxpython.org/docs/api/wx.lib.wxcairo-module.html" rel="nofollow">wxcairo</a> can anti-alias your lines</p>
| 2 | 2010-02-01T20:53:56Z | [
"python",
"line",
"wx"
] |
Drawing anti-aliased lines in wx? | 2,178,268 | <p>I've got a program that draws my mouse movements on a window.
The only problem is the line is very rough, and i would like it (not where two different lines link, but the actual line) to be anti-aliased and to fall-off nicely. Is there a way to do that?</p>
| 2 | 2010-02-01T16:30:53Z | 3,409,771 | <p>You can also use OpenGL to anti-alias your lines.</p>
<p>Or you can write your own routine: <a href="http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm" rel="nofollow">http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm</a></p>
| 0 | 2010-08-04T20:59:28Z | [
"python",
"line",
"wx"
] |
JPype - Issue importing & calling methods! | 2,178,532 | <p>Here I'm attaching my code below</p>
<pre><code>from jpype import *
from javax.swing import JFrame
classpath = "-Djava.class.path=praat.jar"
startJVM(getDefaultJVMPath(),"-ea",classpath)
frame = javax.swing.JFrame("Hello JPype")
label = javax.swing.JLabel("Hello JPype!", JLabel.CENTER)
frame.add(label)
frame.se... | 1 | 2010-02-01T17:04:16Z | 2,178,803 | <p>Add the Java runtime library (<code>rt.jar</code>) to the classpath and try again. The error indicates, that JFrame can't be found but it is inside <code>rt.jar</code>.</p>
| 1 | 2010-02-01T17:46:52Z | [
"java",
"python"
] |
JPype - Issue importing & calling methods! | 2,178,532 | <p>Here I'm attaching my code below</p>
<pre><code>from jpype import *
from javax.swing import JFrame
classpath = "-Djava.class.path=praat.jar"
startJVM(getDefaultJVMPath(),"-ea",classpath)
frame = javax.swing.JFrame("Hello JPype")
label = javax.swing.JLabel("Hello JPype!", JLabel.CENTER)
frame.add(label)
frame.se... | 1 | 2010-02-01T17:04:16Z | 2,180,556 | <p>If you import <code>JFrame</code> into the local namespace, use it without the full namespace:</p>
<pre><code>frame = JFrame("Hello Jython")
</code></pre>
<p>Same with JLabel, but remember to import it first.</p>
<p>To use the full namespace you need <code>import javax.swing</code> instead of <code>from javax.swi... | 0 | 2010-02-01T22:31:27Z | [
"java",
"python"
] |
Python: penalty for sleeping threads | 2,178,563 | <p>this question relates to performance penalities that may or may not arise from having a large number of sleeping python threads on a webserver.</p>
<p>Background: I am implementing an online shop using django/satchmo. A requirement is for delayed payment. The customer can reserve a product and allow a third party t... | 6 | 2010-02-01T17:09:20Z | 2,178,793 | <p>I see no reason why this shouldn't work. The underlying code for Timer (in threading.py) simply uses time.sleep. Once it's been waiting for awhile, it basically runs a loop with time.sleep(0.05) This should result in CPU usage of basically 0%, even with hundreds of threads. Here's a simple example, where I noticed 0... | 6 | 2010-02-01T17:45:43Z | [
"python",
"performance",
"multithreading"
] |
Python: penalty for sleeping threads | 2,178,563 | <p>this question relates to performance penalities that may or may not arise from having a large number of sleeping python threads on a webserver.</p>
<p>Background: I am implementing an online shop using django/satchmo. A requirement is for delayed payment. The customer can reserve a product and allow a third party t... | 6 | 2010-02-01T17:09:20Z | 2,178,856 | <p>Usually, sleeping threads have no overhead aside from the memory allocated for their stacks and other private data. Modern Operating System scheduling algorithms have complexity O(1) so even a running thread does not introduce overhead, other than memory footprint.
At the same time, it is hard to imagine efficient ... | 3 | 2010-02-01T17:55:39Z | [
"python",
"performance",
"multithreading"
] |
Python: penalty for sleeping threads | 2,178,563 | <p>this question relates to performance penalities that may or may not arise from having a large number of sleeping python threads on a webserver.</p>
<p>Background: I am implementing an online shop using django/satchmo. A requirement is for delayed payment. The customer can reserve a product and allow a third party t... | 6 | 2010-02-01T17:09:20Z | 2,179,963 | <p>100 threads is no problem, but as <a href="http://stackoverflow.com/questions/2178563/python-penalty-for-sleeping-threads#comment2126680_2178563">tgray pointed out</a>, what happens if the server goes down (Power cut, Planned Maintenance, Hardware failure, etc.)?</p>
<p>You need to store the unreservation informati... | 4 | 2010-02-01T20:48:53Z | [
"python",
"performance",
"multithreading"
] |
Using python properties in django models? | 2,178,688 | <p>My problem relates to this question: <a href="http://stackoverflow.com/questions/1390556/default-ordering-for-m2m-items-by-intermediate-model-field-in-django">http://stackoverflow.com/questions/1390556/default-ordering-for-m2m-items-by-intermediate-model-field-in-django</a></p>
<pre><code>class Group(models.Model):... | 0 | 2010-02-01T17:29:29Z | 2,179,348 | <p>If it's a one-off, you can exclude the _members field when you create the modelform:</p>
<pre><code>class GroupForm(ModelForm):
class Meta:
model=Group
exclude = {'_members',}
</code></pre>
<p>If you do this a lot, you might consider creating a subclass of ModelForm and override the init method... | 0 | 2010-02-01T19:11:47Z | [
"python",
"django-models"
] |
In python, sorting on date field, field may sometimes be null | 2,178,931 | <p>I am having a hard time coming up with a slick way to handle this sort. I have data coming back from a database read. I want to sort on the accoutingdate. However, accoutingdate may sometimes be null. I am currently doing the following:</p>
<pre><code>results = sorted(results, key=operator.itemgetter('accountin... | 16 | 2010-02-01T18:09:17Z | 2,178,976 | <p>You could use a custom sorting function that treats <code>None</code> specially:</p>
<pre><code>def nonecmp(a, b):
if a is None and b is None:
return 0
if a is None:
return -1
if b is None:
return 1
return cmp(a, b)
results = sorted(results, cmp=nonecmp, ...)
</code></pre>
<p>This treats <code... | 9 | 2010-02-01T18:16:10Z | [
"python",
"sorting"
] |
In python, sorting on date field, field may sometimes be null | 2,178,931 | <p>I am having a hard time coming up with a slick way to handle this sort. I have data coming back from a database read. I want to sort on the accoutingdate. However, accoutingdate may sometimes be null. I am currently doing the following:</p>
<pre><code>results = sorted(results, key=operator.itemgetter('accountin... | 16 | 2010-02-01T18:09:17Z | 2,179,053 | <p>Using a <code>key=</code> function is definitely right, you just have to decide how you want to treat the <code>None</code> values -- pick a <code>datetime</code> value that you want to treat as the equivalent of <code>None</code> for sorting purposes. E.g.:</p>
<pre><code>import datetime
mindate = datetime.date(d... | 23 | 2010-02-01T18:26:52Z | [
"python",
"sorting"
] |
py2app and xml.etree.ElementTree | 2,179,159 | <p>I'm trying to build an app that uses some xml data using Python's built-in xml.etree.ElementTree class. It works properly when I run from the command line, but when I build it, I get an error "ImportError: No module etree.ElementTree." I'm guessing this is because I'm not importing that module correctly, but I haven... | 2 | 2010-02-01T18:44:31Z | 2,179,355 | <p>If you're using macports (or fink etc.) make sure that <code>py2app</code> is using the correct interpreter. You may have to install a new version to work with 2.6.x (on OS X 10.5, <code>py2app</code> uses 2.4.x).</p>
<p>If that doesn't work my steps for working through path problems are:</p>
<ol>
<li>Start up the... | 0 | 2010-02-01T19:12:45Z | [
"python",
"xml",
"py2app"
] |
py2app and xml.etree.ElementTree | 2,179,159 | <p>I'm trying to build an app that uses some xml data using Python's built-in xml.etree.ElementTree class. It works properly when I run from the command line, but when I build it, I get an error "ImportError: No module etree.ElementTree." I'm guessing this is because I'm not importing that module correctly, but I haven... | 2 | 2010-02-01T18:44:31Z | 2,184,717 | <p>After reinstalling and updating macholib, modulegraph, py2app, and setuptools to no avail, I did a little more digging and found the following error in the modulegraph module:</p>
<pre><code>graphmodule.find_modules.find_modules(includes=['xml.etree'])
Traceback (most recent call last):
File "<stdin>", li... | 1 | 2010-02-02T14:28:58Z | [
"python",
"xml",
"py2app"
] |
py2app and xml.etree.ElementTree | 2,179,159 | <p>I'm trying to build an app that uses some xml data using Python's built-in xml.etree.ElementTree class. It works properly when I run from the command line, but when I build it, I get an error "ImportError: No module etree.ElementTree." I'm guessing this is because I'm not importing that module correctly, but I haven... | 2 | 2010-02-01T18:44:31Z | 4,628,074 | <p>Since the comment doesn't have good formating,</p>
<p>In find_modules.py I changed </p>
<pre><code>REPLACEPACKAGES = {
'_xmlplus': 'xml',
}
</code></pre>
<p>To</p>
<pre><code>REPLACEPACKAGES = {
#'_xmlplus': 'xml',
}
</code></pre>
<p>And the xml import worked.</p>
| 1 | 2011-01-07T16:57:56Z | [
"python",
"xml",
"py2app"
] |
python chaining | 2,179,241 | <p><strong>Updated</strong></p>
<p>Let's say I have:</p>
<pre><code>dic={"z":"zv", "a":"av"}
## why doesn't the following return a sorted list of keys?
keys=dic.keys().sort()
</code></pre>
<p>I know I could do the following and have the proper result:</p>
<pre><code>dic={"z":"zv", "a":"av"}
keys=dic.keys()
skeys=ke... | 1 | 2010-02-01T18:56:41Z | 2,179,265 | <p>sort() modifies the contents of the existing list. it doesn't return a list. <a href="http://docs.python.org/tutorial/datastructures.html">See the manual</a>.</p>
| 13 | 2010-02-01T18:58:16Z | [
"python"
] |
python chaining | 2,179,241 | <p><strong>Updated</strong></p>
<p>Let's say I have:</p>
<pre><code>dic={"z":"zv", "a":"av"}
## why doesn't the following return a sorted list of keys?
keys=dic.keys().sort()
</code></pre>
<p>I know I could do the following and have the proper result:</p>
<pre><code>dic={"z":"zv", "a":"av"}
keys=dic.keys()
skeys=ke... | 1 | 2010-02-01T18:56:41Z | 2,179,283 | <p><code>.sort</code> doesn't return the list. You could do:</p>
<pre><code>keys = sorted(dic.keys())
</code></pre>
| 15 | 2010-02-01T18:59:49Z | [
"python"
] |
Dynamically import a callable given the full module path? | 2,179,251 | <pre><code>>>> import_path('os.path.join')
<function join at 0x22d4050>
</code></pre>
<p>What is the simplest way to write <code>import_path</code> (in Python 2.6 and above)? Assume that the <em>last</em> component is always a callable in a module/package.</p>
| 3 | 2010-02-01T18:57:30Z | 2,179,312 | <p>Try</p>
<pre><code>def import_path(name):
(mod,mem) = name.rsplit('.',1)
m = __import__(mod, fromlist=[mem])
return getattr(m, mem)
</code></pre>
<p>Works at least for</p>
<pre><code>>>> import_path('os.walk')
<function walk at 0x7f23c24f8848>
</code></pre>
<p>and now</p>
<pre><code>>>... | 0 | 2010-02-01T19:04:50Z | [
"python",
"import",
"module",
"introspection"
] |
Dynamically import a callable given the full module path? | 2,179,251 | <pre><code>>>> import_path('os.path.join')
<function join at 0x22d4050>
</code></pre>
<p>What is the simplest way to write <code>import_path</code> (in Python 2.6 and above)? Assume that the <em>last</em> component is always a callable in a module/package.</p>
| 3 | 2010-02-01T18:57:30Z | 2,179,334 | <p>Apparently the following works:</p>
<pre><code>>>> p = 'os.path.join'
>>> a, b = p.rsplit('.', 1)
>>> getattr(__import__(a, fromlist=True), b)
<function join at 0x7f8799865230>
</code></pre>
| 0 | 2010-02-01T19:08:56Z | [
"python",
"import",
"module",
"introspection"
] |
Dynamically import a callable given the full module path? | 2,179,251 | <pre><code>>>> import_path('os.path.join')
<function join at 0x22d4050>
</code></pre>
<p>What is the simplest way to write <code>import_path</code> (in Python 2.6 and above)? Assume that the <em>last</em> component is always a callable in a module/package.</p>
| 3 | 2010-02-01T18:57:30Z | 2,179,380 | <p>This seems to be what you want:</p>
<pre><code>def import_path(name):
modname, _, attr = name.rpartition('.')
if not modname:
# name was just a single module name
return __import__(attr)
m = __import__(modname, fromlist=[attr])
return getattr(m, attr)
</code></pre>
<p>To make it wor... | 4 | 2010-02-01T19:16:45Z | [
"python",
"import",
"module",
"introspection"
] |
Enable Unicode "globally" in Python | 2,179,253 | <p>is it possible to avoid having to put this in every page? </p>
<pre><code> # -*- coding: utf-8 -*-
</code></pre>
<p>I'd really like Python to default to this. Thanks in advance!</p>
| 2 | 2010-02-01T18:57:42Z | 2,179,340 | <p>This is a feature of Python 3.0</p>
<p>It was one of the things that was done in Python 3 because it would break backward compatibility, so you won't find such a global option in 2.x</p>
| 1 | 2010-02-01T19:10:19Z | [
"python",
"unicode"
] |
Enable Unicode "globally" in Python | 2,179,253 | <p>is it possible to avoid having to put this in every page? </p>
<pre><code> # -*- coding: utf-8 -*-
</code></pre>
<p>I'd really like Python to default to this. Thanks in advance!</p>
| 2 | 2010-02-01T18:57:42Z | 2,179,350 | <p>In Python 3, the default encoding is UTF-8, so you won't need to set it explicitly anymore. There isn't a way to 'globally' set the default source encoding, though, and history has shown that such global options are generally a bad idea. (For instance, the -U and -Q options to Python, and sys.setdefaultencoding() ba... | 8 | 2010-02-01T19:11:59Z | [
"python",
"unicode"
] |
Enable Unicode "globally" in Python | 2,179,253 | <p>is it possible to avoid having to put this in every page? </p>
<pre><code> # -*- coding: utf-8 -*-
</code></pre>
<p>I'd really like Python to default to this. Thanks in advance!</p>
| 2 | 2010-02-01T18:57:42Z | 2,179,419 | <p>It's a very bad idea for Python 2 because you will be expecting behavior which is only preset on your dev machine. Which means that when your library goes out to someone else, or to a host server, or elsewhere, any use of it will flood the logs with <code>UnicodeDecodeError</code>s.</p>
| 0 | 2010-02-01T19:23:57Z | [
"python",
"unicode"
] |
Python method to boost function | 2,179,345 | <p>I have a method exported to Python using boost python that takes a boost::function as an argument.</p>
<p>From what I have read boost::python should support boost::function without much fuss, but when I try to call the function with a python method it gives me this error</p>
<pre><code>Boost.Python.ArgumentError: ... | 5 | 2010-02-01T19:11:19Z | 2,181,710 | <p>Got an answer on the python mailing list, and after a bit of reworking and more research I got exactly what I wanted :)</p>
<p>I did see that post before mithrandi but I did not like the idea of having to declare the functions like that. With some fancy wrappers and a bit of python magic this can work and look goo... | 10 | 2010-02-02T03:27:30Z | [
"c++",
"python",
"boost",
"boost-python"
] |
Using Jython with Django? | 2,179,395 | <p>I am planning to use Jython with Django. I want to know how stable the Jython project is, how easy to use it is, and how large its developer community is.</p>
| 4 | 2010-02-01T19:19:42Z | 2,181,008 | <p>I have not used Django with Jython, so I can't speak to that specific issue, but I've used Jython for other things and I've found it quite stable of late, and just as easy as plain Python. I believe the "core committers" in Jython are substantially fewer than in C-Python (maybe 1/3 the number or less), if that's wh... | 3 | 2010-02-02T00:09:01Z | [
"python",
"jython"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.