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
Can I store a python dictionary in google's BigTable datastore without serializing it explicitly?
1,953,784
<p>I have a python dictionary that I would like to store in Google's BigTable datastore (it is an attribute in a <code>db.Model</code> class).</p> <p>Is there an easy way to do this? i.e. using a <code>db.DictionaryProperty</code>? Or do I have to use pickle to serialize my dictionary? My dictionary is relatively str...
1
2009-12-23T16:21:50Z
1,954,843
<p>I assume that when you need to be able to reach the dict, it's all-at-once? You don't have to get values from inside the dict while it's in the datastore?</p> <p>If so, you'll have to serialize, but don't have to use pickle; we use simplejson instead. Then retrieving is a simple matter of overriding toBasicType(),...
1
2009-12-23T19:28:21Z
[ "python", "google-app-engine", "pickle" ]
deleting old folders with datetime function
1,953,958
<p>I am trying to delete old folders and I am asking does anyone know how to set up a variable that allows me to check the variable 'todaystr' which is today's date and minus 7 days of this string and store it another variable. I am wanting to automatically delete old files after a week. Below shows the variable 'today...
3
2009-12-23T16:51:05Z
1,953,983
<pre><code>import datetime import os import shutil threshold = datetime.datetime.now() + datetime.timedelta(days=-7) file_time = datetime.datetime.fromtimestamp(os.path.getmtime('/folder_name')) if file_time &lt; threshold: shutil.rmtree('/folder_name') </code></pre>
4
2009-12-23T16:54:35Z
[ "python" ]
deleting old folders with datetime function
1,953,958
<p>I am trying to delete old folders and I am asking does anyone know how to set up a variable that allows me to check the variable 'todaystr' which is today's date and minus 7 days of this string and store it another variable. I am wanting to automatically delete old files after a week. Below shows the variable 'today...
3
2009-12-23T16:51:05Z
1,957,912
<p>I relation to the above answer it works very well, the code I used was different in the end. I create the name of the folder with the current date, so when the nightly build runs it will only delete the folder named from 7 days ago. The code is as follows:</p> <pre><code>import datetime import os import calenda...
0
2009-12-24T11:10:42Z
[ "python" ]
Are CPython, IronPython, Jython scripts compatible with each other?
1,953,989
<p>I am pretty sure that python scripts will work in all three, but I want to make sure. I have read here and there about editors that can write CPython, Jython, IronPython and I am hoping that I am looking to much into the distinction.</p> <p>My situation is I have 3 different api's that I want to test. Each api pe...
7
2009-12-23T16:56:17Z
1,954,037
<p>The short answer is: Sometimes.</p> <p>Some projects built on top of IronPython may not work with CPython, and some CPython modules that are written in C (e.g. NumPy) will not work with IronPython.</p> <p>On a similar note, while Jython implements the language specification, it has several incompatibilities with C...
10
2009-12-23T17:04:13Z
[ "python", "testing", "ironpython", "jython", "boost-python" ]
Python instance method in C
1,954,494
<p>Consider the following Python (3.x) code:</p> <pre><code>class Foo(object): def bar(self): pass foo = Foo() </code></pre> <p>How to write the same functionality in C?</p> <p>I mean, how do I create an object with a method in C? And then create an instance from it?</p> <p><strong>Edit</strong>: Oh, so...
2
2009-12-23T18:25:06Z
1,954,532
<p>You can't! C does not have "classes", it only has <code>struct</code>s. And a <code>struct</code> cannot have code (methods or functions).</p> <p>You can, however, fake it with function pointers:</p> <pre><code>/* struct object has 1 member, namely a pointer to a function */ struct object { int (*class)(void);...
3
2009-12-23T18:31:05Z
[ "python", "c", "python-c-api" ]
Python instance method in C
1,954,494
<p>Consider the following Python (3.x) code:</p> <pre><code>class Foo(object): def bar(self): pass foo = Foo() </code></pre> <p>How to write the same functionality in C?</p> <p>I mean, how do I create an object with a method in C? And then create an instance from it?</p> <p><strong>Edit</strong>: Oh, so...
2
2009-12-23T18:25:06Z
1,954,766
<p>Here's a simple class (adapted from <a href="http://nedbatchelder.com/text/whirlext.html" rel="nofollow">http://nedbatchelder.com/text/whirlext.html</a> for 3.x):</p> <pre><code>#include "Python.h" #include "structmember.h" // The CountDict type. typedef struct { PyObject_HEAD PyObject * dict; int count;...
2
2009-12-23T19:14:43Z
[ "python", "c", "python-c-api" ]
Python instance method in C
1,954,494
<p>Consider the following Python (3.x) code:</p> <pre><code>class Foo(object): def bar(self): pass foo = Foo() </code></pre> <p>How to write the same functionality in C?</p> <p>I mean, how do I create an object with a method in C? And then create an instance from it?</p> <p><strong>Edit</strong>: Oh, so...
2
2009-12-23T18:25:06Z
1,954,771
<p>I suggest you start from the example source code <a href="http://svn.python.org/view/python/branches/py3k/Modules/xxmodule.c?revision=69214&amp;view=markup" rel="nofollow">here</a> -- it's part of Python 3's sources, and it exists specifically to show you, by example, how to perform what you require (and a few other...
2
2009-12-23T19:15:11Z
[ "python", "c", "python-c-api" ]
How can I run 2 servers at once in Python?
1,954,549
<p>I need to run 2 servers at once in Python using the threading module, but to call the function run(), the first server is running, but the second server does not run until the end of the first server.<br> This is the source code:</p> <pre><code>import os import sys import threading n_server = 0 n_server_lock = thr...
5
2009-12-23T18:33:37Z
1,954,616
<p>You don't want to <code>join()</code> in your <code>__init__</code> function. This is causing the system to block until each thread finishes.</p> <p>I would recommend you restructure your program so your main function looks more like the following:</p> <pre><code>if name == "__main__": servers = [MainServer(),...
6
2009-12-23T18:44:02Z
[ "python", "multithreading" ]
Django: writing a manager to filter query set results
1,954,664
<p>I have the following code:</p> <pre><code>class GroupDepartmentManager(models.Manager): def get_query_set(self): return super(GroupDepartmentManager, self).get_query_set().filter(group='1') class Department(models.Model): name = models.CharField(max_length=128) group = models.ForeignKey(Group) def __str__...
6
2009-12-23T18:55:47Z
1,956,255
<p>I have a hunch that replacing the default <code>Manager</code> on <code>objects</code> in this manner might not be good idea, especially if you're planning on using the admin site... Even if it helps you with your Employees, it won't help you at all when handling Departments. How about a second property providing a ...
4
2009-12-24T01:28:15Z
[ "python", "django", "manager" ]
Django: writing a manager to filter query set results
1,954,664
<p>I have the following code:</p> <pre><code>class GroupDepartmentManager(models.Manager): def get_query_set(self): return super(GroupDepartmentManager, self).get_query_set().filter(group='1') class Department(models.Model): name = models.CharField(max_length=128) group = models.ForeignKey(Group) def __str__...
6
2009-12-23T18:55:47Z
1,956,271
<p>You might want to reconsider the relationship between the groups and departments if you find that trying to create a custom manager is too complex. Managers excel at simplifying common queries, but flop at displaying complex relationships between models and instances of models. </p> <p>However, I think this artic...
2
2009-12-24T01:36:32Z
[ "python", "django", "manager" ]
Basics of SymPy
1,954,799
<p>I am just starting to play with <a href="http://www.google.com/search?hl=en&amp;q=site%3Aen.wikipedia.org+sympy&amp;cts=1261570105189&amp;aq=f&amp;oq=&amp;aqi=" rel="nofollow">SymPy</a> and I am a bit surprised by some of its behavior, for instance this is not the results I would expect:</p> <pre><code>&gt;&gt;&gt;...
4
2009-12-23T19:19:48Z
1,954,849
<p>Because they're not equal. Try this one:</p> <p>s.E**(s.I* s.pi)== s.I*s.I</p>
0
2009-12-23T19:29:48Z
[ "python", "sympy" ]
Basics of SymPy
1,954,799
<p>I am just starting to play with <a href="http://www.google.com/search?hl=en&amp;q=site%3Aen.wikipedia.org+sympy&amp;cts=1261570105189&amp;aq=f&amp;oq=&amp;aqi=" rel="nofollow">SymPy</a> and I am a bit surprised by some of its behavior, for instance this is not the results I would expect:</p> <pre><code>&gt;&gt;&gt;...
4
2009-12-23T19:19:48Z
1,954,913
<p>From the <a href="https://github.com/sympy/sympy/wiki/Faq#why-does-sympy-say-that-two-equal-expressions-are-unequal" rel="nofollow">FAQ</a>:</p> <p><strong>Why does SymPy say that two equal expressions are unequal?</strong></p> <p>The equality operator (==) tests whether expressions have identical form, not whethe...
9
2009-12-23T19:44:06Z
[ "python", "sympy" ]
How do I access a object's method when the method's name is in a variable?
1,954,840
<p>Say I have a class object named test.</p> <p>test has various methods, one of them is whatever() .</p> <p>I have a variable named method = "whatever"</p> <p>How can I access the method using the variable with test?</p> <p>Thanks!</p>
6
2009-12-23T19:27:41Z
1,954,846
<p>Get the attribute with <code>getattr</code>:</p> <pre><code>method = "whatever" getattr(test, method) </code></pre> <p>You can also call it:</p> <pre><code>getattr(test, method)() </code></pre>
9
2009-12-23T19:29:04Z
[ "python" ]
How do I access a object's method when the method's name is in a variable?
1,954,840
<p>Say I have a class object named test.</p> <p>test has various methods, one of them is whatever() .</p> <p>I have a variable named method = "whatever"</p> <p>How can I access the method using the variable with test?</p> <p>Thanks!</p>
6
2009-12-23T19:27:41Z
1,954,861
<p>To <em>access</em> the method, <code>getattr(test, test.method)</code>; this way you can bind it to a variable, return it as a function result, pass it as an argument, and so forth. To <em>call</em> it as well, append parenthesized arguments (just parentheses if there are no arguments), for example <code>getattr(te...
2
2009-12-23T19:31:54Z
[ "python" ]
call python modules from java classes?
1,954,887
<p>is it possible, by using jython to call jython classes from java code?</p> <p>If yes, how please?</p>
0
2009-12-23T19:38:56Z
1,954,901
<p>Yes - the <a href="http://wiki.python.org/jython/JythonFaq" rel="nofollow">Jython FAQ</a> has a <a href="http://wiki.python.org/jython/JythonFaq/EmbeddingJython" rel="nofollow">specific entry about this</a>.</p>
3
2009-12-23T19:41:56Z
[ "java", "python", "class", "module", "jython" ]
call python modules from java classes?
1,954,887
<p>is it possible, by using jython to call jython classes from java code?</p> <p>If yes, how please?</p>
0
2009-12-23T19:38:56Z
1,954,902
<p><a href="http://tssblog.blogs.techtarget.com/2007/11/21/using-python-within-java/" rel="nofollow">Nice article regarding this issue</a></p> <p>Or just try Jython</p> <p><a href="http://www.jython.org/" rel="nofollow">Jython Project Page</a></p>
3
2009-12-23T19:42:34Z
[ "java", "python", "class", "module", "jython" ]
Python: which XML parsing library will work out-of-the-box for Python 2.4 and up?
1,954,923
<p>How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?</p> <p>Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions?</p> <p><strong>Edit</strong>: the working-out-of-the-box requirement is in...
7
2009-12-23T19:45:22Z
1,954,949
<p>You can use <a href="http://docs.python.org/library/xml.dom.minidom.html" rel="nofollow">minidom</a></p>
1
2009-12-23T19:50:47Z
[ "python", "xml" ]
Python: which XML parsing library will work out-of-the-box for Python 2.4 and up?
1,954,923
<p>How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?</p> <p>Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions?</p> <p><strong>Edit</strong>: the working-out-of-the-box requirement is in...
7
2009-12-23T19:45:22Z
1,954,963
<p><a href="http://docs.python.org/library/xml.dom.minidom.html">minidom</a> is available in Python 2.0 and later.</p> <p>However, if I were you, I would strongly consider using <a href="http://effbot.org/downloads/">ElementTree</a> which is available in Python 2.5 and later. Its syntax is much more pleasant.</p> <p...
8
2009-12-23T19:54:53Z
[ "python", "xml" ]
Python: which XML parsing library will work out-of-the-box for Python 2.4 and up?
1,954,923
<p>How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?</p> <p>Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions?</p> <p><strong>Edit</strong>: the working-out-of-the-box requirement is in...
7
2009-12-23T19:45:22Z
1,954,967
<p>So, basically intersect the result of "xml" in these pages:</p> <ul> <li><a href="https://docs.python.org/release/2.4/modindex.html" rel="nofollow">https://docs.python.org/release/2.4/modindex.html</a></li> <li><a href="https://docs.python.org/release/2.5/modindex.html" rel="nofollow">https://docs.python.org/releas...
5
2009-12-23T19:56:35Z
[ "python", "xml" ]
Deploying Django at alwaysdata.com
1,955,189
<p>i new on django i tried this but i cant deploy. how can i do </p> <pre><code>#!/usr/bin/python import sys import os base = os.path.dirname(os.path.abspath(__file__)) + '/..' sys.path.append(base) os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings' import django.core.handlers.wsgi application = django.c...
9
2009-12-23T20:38:46Z
1,955,275
<p>You are trying to mix two different web server integration methods: fcgi (fast cgi) and wsgi.</p> <p>Your first snippet is for a wsgi interface with the web server and is the recommended method for integrating Django with Apache. Very good resources (including examples) to help you set this up correctly can be fou...
6
2009-12-23T20:57:53Z
[ "python", "django", "fastcgi" ]
Deploying Django at alwaysdata.com
1,955,189
<p>i new on django i tried this but i cant deploy. how can i do </p> <pre><code>#!/usr/bin/python import sys import os base = os.path.dirname(os.path.abspath(__file__)) + '/..' sys.path.append(base) os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings' import django.core.handlers.wsgi application = django.c...
9
2009-12-23T20:38:46Z
1,955,401
<p>Here's the <a href="http://wiki.alwaysdata.com/wiki/D%C3%A9ployer_une_application_Django">alwaysdata wiki entry</a> for setting up Django with fastcgi. Only down-side: it's written in French.</p> <p>Well, I don't speak French, but what it basically says is:</p> <ol> <li>Create a directory named <code>public</code>...
21
2009-12-23T21:25:41Z
[ "python", "django", "fastcgi" ]
Deploying Django at alwaysdata.com
1,955,189
<p>i new on django i tried this but i cant deploy. how can i do </p> <pre><code>#!/usr/bin/python import sys import os base = os.path.dirname(os.path.abspath(__file__)) + '/..' sys.path.append(base) os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings' import django.core.handlers.wsgi application = django.c...
9
2009-12-23T20:38:46Z
29,297,920
<p>We got now (since a couple of months) an article in english: <a href="https://help.alwaysdata.com/languages/python/django" rel="nofollow">Django on alwaysdata.com</a></p> <p>Regards,</p>
1
2015-03-27T10:00:15Z
[ "python", "django", "fastcgi" ]
python foreign character in csv
1,955,301
<p>I have a little csv which contains foreign characters, like Chinese. How can I display them in Chinese instead of those \xa5\\xa4\ string???</p> <p>Thanks</p>
0
2009-12-23T21:02:47Z
1,955,323
<p>Have you read the <a href="http://docs.python.org/library/csv.html" rel="nofollow">docs for the <code>csv</code> module</a>? It includes examples of how to wrap <code>csv</code> to handle Unicode data.</p>
3
2009-12-23T21:09:31Z
[ "python", "encode" ]
__getattr__ keeps returning None even when I attempt to return values
1,955,363
<p>Try running the following code:</p> <pre><code>class Test(object): def func_accepting_args(self,prop,*args): msg = "%s getter/setter got called with args %s" % (prop,args) print msg #this is prented return msg #Why is None returned? def __getattr__(self,name): if name.startswith("get_") or name.sta...
1
2009-12-23T21:17:29Z
1,955,380
<p><code>return_method()</code> doesn't return anything. It should return the result of the wrapped <code>func_accepting_args()</code>:</p> <pre><code>def return_method(*args): return self.func_accepting_args(prop,*args) </code></pre>
6
2009-12-23T21:20:15Z
[ "python", "metaprogramming" ]
__getattr__ keeps returning None even when I attempt to return values
1,955,363
<p>Try running the following code:</p> <pre><code>class Test(object): def func_accepting_args(self,prop,*args): msg = "%s getter/setter got called with args %s" % (prop,args) print msg #this is prented return msg #Why is None returned? def __getattr__(self,name): if name.startswith("get_") or name.sta...
1
2009-12-23T21:17:29Z
1,955,394
<p>Because return_method() doesn't return a value. It just falls out the bottom, hence you get None.</p>
1
2009-12-23T21:22:31Z
[ "python", "metaprogramming" ]
Why is this a python syntax error during an initialisation?
1,955,448
<p>This code:</p> <pre><code>class Todo: def addto(self, list_name="", text=""): """ Adds an item to the specified list. """ if list_name == "": list_name = sys.argv[2] text = ''.join(sys.argv[3:] todo_list = TodoList(getListFilename(list_name)) </code></pre> <p>produces a syntax error with the litt...
0
2009-12-23T21:34:05Z
1,955,453
<p>you need to close this )</p> <pre><code>text = ''.join(sys.argv[3:] </code></pre>
11
2009-12-23T21:35:35Z
[ "python", "syntax", "syntax-error" ]
How to redirect stderr in Python?
1,956,142
<p>I would like to log all the output of a Python script. I tried:</p> <pre><code>import sys log = [] class writer(object): def write(self, data): log.append(data) sys.stdout = writer() sys.stderr = writer() </code></pre> <p>Now, if I "print 'something' " it gets logged. But if I make for instance some...
12
2009-12-24T00:46:09Z
1,956,157
<p>You can't do anything in Python code that can capture errors during the compilation of that same code. How could it? If the compiler can't finish compiling the code, it won't run the code, so your redirection hasn't even taken effect yet.</p> <p>That's where your (undesired) subprocess comes in. You can write Py...
4
2009-12-24T00:53:25Z
[ "python", "redirect", "stderr" ]
How to redirect stderr in Python?
1,956,142
<p>I would like to log all the output of a Python script. I tried:</p> <pre><code>import sys log = [] class writer(object): def write(self, data): log.append(data) sys.stdout = writer() sys.stderr = writer() </code></pre> <p>Now, if I "print 'something' " it gets logged. But if I make for instance some...
12
2009-12-24T00:46:09Z
1,956,200
<p>I can't think of an easy way. The python process's standard error is living on a lower level than a python file object (C vs. python).</p> <p>You could wrap the python script in a second python script and use subprocess.Popen. It's also possible you could pull some magic like this in a single script:</p> <pre><c...
6
2009-12-24T01:09:22Z
[ "python", "redirect", "stderr" ]
How to redirect stderr in Python?
1,956,142
<p>I would like to log all the output of a Python script. I tried:</p> <pre><code>import sys log = [] class writer(object): def write(self, data): log.append(data) sys.stdout = writer() sys.stderr = writer() </code></pre> <p>Now, if I "print 'something' " it gets logged. But if I make for instance some...
12
2009-12-24T00:46:09Z
1,956,228
<p>I have a piece of software I wrote for work that captures stderr to a file like so:</p> <pre><code>import sys sys.stderr = open('C:\\err.txt', 'w') </code></pre> <p>so it's definitely possible.</p> <p>I believe your problem is that you are creating two instances of writer.</p> <p>Maybe something more like:</p> ...
14
2009-12-24T01:16:19Z
[ "python", "redirect", "stderr" ]
How to redirect stderr in Python?
1,956,142
<p>I would like to log all the output of a Python script. I tried:</p> <pre><code>import sys log = [] class writer(object): def write(self, data): log.append(data) sys.stdout = writer() sys.stderr = writer() </code></pre> <p>Now, if I "print 'something' " it gets logged. But if I make for instance some...
12
2009-12-24T00:46:09Z
35,260,955
<pre><code>import sys import tkinter # ******************************************** def mklistenconsswitch(*printf: callable) -&gt; callable: def wrapper(*fcs: callable) -&gt; callable: def newf(data): [prf(data) for prf in fcs] return newf stdoutw, stderrw = sys.stdout.write, sys....
0
2016-02-08T00:36:49Z
[ "python", "redirect", "stderr" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,956,259
<p>Something like:</p> <pre><code>name = data.Name or "Default Name" </code></pre>
1
2009-12-24T01:30:37Z
[ "python", "django", "idioms" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,956,260
<pre><code>displayname = firstname + lastname or username </code></pre> <p>will work if firstname and last name has 0 length blank string</p>
4
2009-12-24T01:30:44Z
[ "python", "django", "idioms" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,956,262
<p>Ok, I'm assuming you meant <code>__unicode__()</code> method. Try something like this (not tested, but real close to being correct):</p> <pre><code>from django.utils.encoding import smart_unicode def __unicode__(self): u = self.user if u.firstname and u.lastname: return u"%s %s" % (u.firstname, u.l...
2
2009-12-24T01:31:27Z
[ "python", "django", "idioms" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,956,274
<pre><code>displayname = firstname+' '+lastname if firstname and lastname else username </code></pre>
6
2009-12-24T01:38:35Z
[ "python", "django", "idioms" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,956,348
<p>My schema would have <code>None</code> as an unset first- or lastname, so Frederico's answer wouldn't work. So:</p> <pre><code>print ("%s %s" % (firstname, lastname) if not (firstname and lastname) else username ) </code></pre>
0
2009-12-24T02:15:36Z
[ "python", "django", "idioms" ]
Python - Idiom to check if string is empty, print default
1,956,249
<p>I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is?</p> <p>(The context is Django, for the <code>__unicode__(self)</code> function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't ...
6
2009-12-24T01:25:20Z
1,959,112
<p>I think this issue is better handled in the templates with something like:</p> <p>{{ user.get_full_name|default:user.username }}</p> <p>That uses Django's included "default" filter. There is also a "default_if_none" filter if you are specifically concerned about a None value, but want to allow a blank value (i.e. ...
4
2009-12-24T17:26:08Z
[ "python", "django", "idioms" ]
How to redirect stderr in Python? Via Python C API?
1,956,407
<p>This is a combination of my two recent questions:<br> [1] <a href="http://stackoverflow.com/questions/1954494/python-instance-method-in-c">http://stackoverflow.com/questions/1954494/python-instance-method-in-c</a><br> [2] <a href="http://stackoverflow.com/questions/1956142/how-to-redirect-stderr-in-python">http://st...
2
2009-12-24T02:43:48Z
1,956,422
<p>Just make a module object (you're doing that anyway, if you're using the C API!-) and make it have a suitable <code>write</code> function -- that module object will be suitable as the second argument to <code>PySys_SetObject</code>.</p> <p>In my answer to your other question I pointed you to <code>xxmodule.c</code>...
8
2009-12-24T02:51:44Z
[ "python", "c", "stdout", "python-c-api", "io-redirection" ]
How to redirect stderr in Python? Via Python C API?
1,956,407
<p>This is a combination of my two recent questions:<br> [1] <a href="http://stackoverflow.com/questions/1954494/python-instance-method-in-c">http://stackoverflow.com/questions/1954494/python-instance-method-in-c</a><br> [2] <a href="http://stackoverflow.com/questions/1956142/how-to-redirect-stderr-in-python">http://st...
2
2009-12-24T02:43:48Z
12,563,114
<p>Based on Alex's answer, here is fully working C code, without the Python "import aview", in Python 3 (so no Py_InitModule), and with stderr redirection : </p> <pre><code>#include &lt;functional&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;Python.h&gt; PyObject* aview_write(PyObject* self, Py...
3
2012-09-24T10:25:39Z
[ "python", "c", "stdout", "python-c-api", "io-redirection" ]
i don't know __iter__ in python,who can give me a good code example
1,956,623
<p>my code run wrong</p> <pre><code>class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
6
2009-12-24T04:08:26Z
1,956,645
<p>a. Spell it right: <strong>not</strong></p> <pre><code> def __iter(self): </code></pre> <p>but:</p> <pre><code> def __iter__(self): </code></pre> <p>with <code>__</code> before <strong>and</strong> after <code>iter</code>.</p> <p>b. Make the body right: <strong>not</strong></p> <pre><code>return 33 </code>...
17
2009-12-24T04:21:34Z
[ "python", "iterator" ]
i don't know __iter__ in python,who can give me a good code example
1,956,623
<p>my code run wrong</p> <pre><code>class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
6
2009-12-24T04:08:26Z
1,956,647
<p>You are using this language feature incorrectly.</p> <p><a href="http://docs.python.org/library/stdtypes.html#iterator-types" rel="nofollow">http://docs.python.org/library/stdtypes.html#iterator-types</a></p> <p>This above link will explain what the function should be used for.</p> <p>You can try to see documenta...
0
2009-12-24T04:22:22Z
[ "python", "iterator" ]
i don't know __iter__ in python,who can give me a good code example
1,956,623
<p>my code run wrong</p> <pre><code>class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
6
2009-12-24T04:08:26Z
1,956,648
<p>A few things about your code:</p> <ol> <li><code>__iter</code> should be <code>__iter__</code></li> <li>You're returning '33' in the <code>__iter__</code> function. You should actually be returning an <em>iterator object</em>. An iterator is an object which keeps returning different values when it's <code>next()</c...
5
2009-12-24T04:22:24Z
[ "python", "iterator" ]
i don't know __iter__ in python,who can give me a good code example
1,956,623
<p>my code run wrong</p> <pre><code>class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
6
2009-12-24T04:08:26Z
1,956,679
<p>Here is a code example that implements the xrange builtin:</p> <pre><code>class my_xrange(object): def __init__(self, start, end, skip=1): self.curval = int(start) self.lastval = int(end) self.skip = int(skip) assert(int(skip) != 0) def __iter__(self): return self ...
1
2009-12-24T04:33:09Z
[ "python", "iterator" ]
Determining version of easy_install/setuptools
1,956,646
<p>I'm trying to install couchapp, which uses easy_install - and is quite explicit in stating a particular version of easy_install/setuptools is needed: 0.6c6. I seem to have easy_install already on my Mac, but there's no command-line arguments to check the version. Instead of just installing a new version over the top...
22
2009-12-24T04:21:51Z
1,956,683
<p>One way would be to look at the actual source file for easy_install. Do</p> <pre><code>which easy_install </code></pre> <p>to see where it's located, and then use that path in</p> <pre><code>less path/to/easy_install </code></pre> <p>The second line in my easy_install script says:</p> <pre><code># EASY-INSTALL-...
17
2009-12-24T04:33:43Z
[ "python", "setuptools", "easy-install" ]
Determining version of easy_install/setuptools
1,956,646
<p>I'm trying to install couchapp, which uses easy_install - and is quite explicit in stating a particular version of easy_install/setuptools is needed: 0.6c6. I seem to have easy_install already on my Mac, but there's no command-line arguments to check the version. Instead of just installing a new version over the top...
22
2009-12-24T04:21:51Z
22,966,614
<p>This seems to get a lot of hits from google, so I thought I'd update for those folks. I was able to do:</p> <pre><code>easy_install --version </code></pre> <p>which produced the output</p> <pre><code>setuptools 3.4.3 </code></pre> <p>I believe this only works for some (newer?) versions of setuptools</p>
30
2014-04-09T15:03:37Z
[ "python", "setuptools", "easy-install" ]
Determining version of easy_install/setuptools
1,956,646
<p>I'm trying to install couchapp, which uses easy_install - and is quite explicit in stating a particular version of easy_install/setuptools is needed: 0.6c6. I seem to have easy_install already on my Mac, but there's no command-line arguments to check the version. Instead of just installing a new version over the top...
22
2009-12-24T04:21:51Z
35,544,096
<p>On Windows, where Python is in the Path:</p> <pre><code>python -m easy_install --version </code></pre> <p>For me, I get setuptools 7.0 as the response.</p>
1
2016-02-22T00:46:18Z
[ "python", "setuptools", "easy-install" ]
How to make Fabric execution follow the env.hosts list order?
1,956,717
<p>I have the following fabfile.py:</p> <pre><code>from fabric.api import env, run host1 = '192.168.200.181' host2 = '192.168.200.182' host3 = '192.168.200.183' env.hosts = [host1, host2, host3] def df_h(): run("df -h | grep sda3") </code></pre> <p>And I get the following output:</p> <pre><code>[192.168.200.1...
4
2009-12-24T04:45:09Z
1,956,790
<p>The exact reason that the order is not preserved from <code>env.hosts</code> is that there are three "levels" that the hosts to operate can be specified--env.hosts, the command line, and per function--which are merged together. In <code>fabric/main.py</code> on <a href="http://code.fabfile.org/repositories/entry/fa...
5
2009-12-24T05:10:10Z
[ "python", "fabric" ]
How to make Fabric execution follow the env.hosts list order?
1,956,717
<p>I have the following fabfile.py:</p> <pre><code>from fabric.api import env, run host1 = '192.168.200.181' host2 = '192.168.200.182' host3 = '192.168.200.183' env.hosts = [host1, host2, host3] def df_h(): run("df -h | grep sda3") </code></pre> <p>And I get the following output:</p> <pre><code>[192.168.200.1...
4
2009-12-24T04:45:09Z
6,605,060
<p>Just to update, newest Fabric 1.1+ (think even 1.0) dedupes in an order preserving way now. So this should be a non-issue now.</p>
1
2011-07-07T02:02:47Z
[ "python", "fabric" ]
How to make Fabric ignore offline hosts in the env.hosts list?
1,956,777
<p>This is related to my <a href="http://stackoverflow.com/questions/1956717/how-to-make-fabric-execution-follow-the-env-hosts-list-order">previous question</a>, but a different one. </p> <p>I have the following fabfile:</p> <pre><code>from fabric.api import * host1 = '192.168.200.181' offline_host2 = '192.168.200....
10
2009-12-24T05:06:03Z
1,956,810
<p>You're not using it improperly. You can even just provide <code>--warn-only=true</code> on the command line. <a href="http://docs.fabfile.org/0.9.0/usage/fab.html#cmdoption-w" rel="nofollow">It's the documented method suggested by the development team.</a></p>
1
2009-12-24T05:15:54Z
[ "python", "fabric" ]
How to make Fabric ignore offline hosts in the env.hosts list?
1,956,777
<p>This is related to my <a href="http://stackoverflow.com/questions/1956717/how-to-make-fabric-execution-follow-the-env-hosts-list-order">previous question</a>, but a different one. </p> <p>I have the following fabfile:</p> <pre><code>from fabric.api import * host1 = '192.168.200.181' offline_host2 = '192.168.200....
10
2009-12-24T05:06:03Z
2,561,727
<p>According to the <a href="http://docs.fabfile.org/0.9.0/usage/env.html#warn-only">Fabric documentation on warn_only</a>, </p> <blockquote> <p><code>env.warn_only</code> "specifies whether or not to warn, instead of abort, when <code>run</code>/<code>sudo</code>/<code>local</code> encounter error conditions.</p> <...
14
2010-04-01T15:53:25Z
[ "python", "fabric" ]
How to make Fabric ignore offline hosts in the env.hosts list?
1,956,777
<p>This is related to my <a href="http://stackoverflow.com/questions/1956717/how-to-make-fabric-execution-follow-the-env-hosts-list-order">previous question</a>, but a different one. </p> <p>I have the following fabfile:</p> <pre><code>from fabric.api import * host1 = '192.168.200.181' offline_host2 = '192.168.200....
10
2009-12-24T05:06:03Z
12,727,782
<p>Based on Matthew's answer, I came up with a decorator that accomplishes just that:</p> <pre><code>from __future__ import with_statement from paramiko import Transport from socket import getdefaulttimeout, setdefaulttimeout from fabric.api import run, cd, env, roles roledefs = { 'greece': [ 'alpha', ...
0
2012-10-04T12:54:54Z
[ "python", "fabric" ]
How to make Fabric ignore offline hosts in the env.hosts list?
1,956,777
<p>This is related to my <a href="http://stackoverflow.com/questions/1956717/how-to-make-fabric-execution-follow-the-env-hosts-list-order">previous question</a>, but a different one. </p> <p>I have the following fabfile:</p> <pre><code>from fabric.api import * host1 = '192.168.200.181' offline_host2 = '192.168.200....
10
2009-12-24T05:06:03Z
23,139,054
<p>As of version 1.4 Fabric has a <code>--skip-bad-hosts</code> option that can be set from the command line, or by setting the variable in your fab file.</p> <pre><code>env.skip_bad_hosts = True </code></pre> <p>Documentation for the option is here: <a href="http://docs.fabfile.org/en/latest/usage/fab.html#cmdoption...
12
2014-04-17T16:54:10Z
[ "python", "fabric" ]
How to remove blocks surrounded by curly brackets via python
1,956,970
<p>Sample text: <a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Italian%20War%20of%201542-1546&amp;redirects&amp;rvprop=content&amp;format=xml" rel="nofollow">String</a> -> content within the rev tag (via lxml).</p> <p>I'm trying to remove the {{BLOCKS}} within the text.</p> <p>I...
1
2009-12-24T06:10:45Z
1,956,996
<p>Set the dotall flag-- this allows . to match newlines.</p> <pre><code>p = re.compile('\{\{*.*\}\}', re.DOTALL) nonBracketedString = p.sub('', bracketedString) </code></pre>
1
2009-12-24T06:19:55Z
[ "python", "regex", "api", "wikipedia" ]
How to remove blocks surrounded by curly brackets via python
1,956,970
<p>Sample text: <a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Italian%20War%20of%201542-1546&amp;redirects&amp;rvprop=content&amp;format=xml" rel="nofollow">String</a> -> content within the rev tag (via lxml).</p> <p>I'm trying to remove the {{BLOCKS}} within the text.</p> <p>I...
1
2009-12-24T06:10:45Z
1,957,002
<p>Set the dotall flag.</p> <pre><code>p = re.compile('\{\{*.*?\}\}', re.DOTALL) nonBracketedString = p.sub('', bracketedString) </code></pre> <p>In the default mode, <code>.</code> matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.</p> <p><...
2
2009-12-24T06:22:01Z
[ "python", "regex", "api", "wikipedia" ]
How to remove blocks surrounded by curly brackets via python
1,956,970
<p>Sample text: <a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Italian%20War%20of%201542-1546&amp;redirects&amp;rvprop=content&amp;format=xml" rel="nofollow">String</a> -> content within the rev tag (via lxml).</p> <p>I'm trying to remove the {{BLOCKS}} within the text.</p> <p>I...
1
2009-12-24T06:10:45Z
1,959,195
<pre><code>&gt;&gt;&gt; import urllib2 &gt;&gt;&gt; import re &gt;&gt;&gt; s = "".join(urllib2.urlopen('http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;titles=Italian%20War%20of%201542-1546&amp;redirects&amp;rvprop=content&amp;format=xml').readlines()) &gt;&gt;&gt; p = re.compile('\{\{.*?\}\}', re...
1
2009-12-24T17:48:13Z
[ "python", "regex", "api", "wikipedia" ]
How to get latest timestamp in a column?
1,957,021
<p>I have a timestamp column in my t1 table. The format is as: <code>2009-12-24 06:17:34</code></p> <p>There are many entries as such.</p> <p>How do we query from views to get the latest timestamp</p>
1
2009-12-24T06:28:58Z
1,957,175
<pre><code>ModelClass.objects.latest(timestamp_field) </code></pre>
4
2009-12-24T07:12:10Z
[ "python", "django" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,957,065
<p>I think <a href="http://effbot.org/zone/python-compile.htm">Compiling Python Code</a> would be a good place to start:</p> <blockquote> <p>Python source code is automatically compiled into Python byte code by the CPython interpreter. Compiled code is usually stored in PYC (or PYO) files, and is regenerated...
22
2009-12-24T06:39:21Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,957,072
<p>python compile on the fly when you run it.</p> <p>Run a .py file by(linux): python abc.py</p>
1
2009-12-24T06:42:18Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,957,078
<p>python is an interpreted language, so you don't need to compile your scripts to make them run. The easiest way to get one running is to navigate to it's folder in a terminal and execute "python somefile.py". This depends on you having python installed from <a href="http://www.python.org/download/windows/" rel="nof...
1
2009-12-24T06:43:50Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,957,082
<p>You dont have to compile it. the first you use it (import) it is compiled by the CPython interpreter. But if you really want to compile there are several options.</p> <p>To compile to exe</p> <ul> <li><a href="http://www.py2exe.org/" rel="nofollow">py2exe</a></li> <li><a href="http://cx-freeze.sourceforge.net/" re...
5
2009-12-24T06:45:01Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,957,814
<p>Python, as a dynamic language, cannot be "compiled" into machine code statically, like C or COBOL can. You'll always need an interpreter to execute the code, which, by definition in the language, is a dynamic operation.</p> <p>You can "translate" source code in bytecode, which is just an intermediate process that t...
7
2009-12-24T10:42:15Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
1,959,779
<p>If you really want, you could always compile with Cython. This will generate C code, which you can then compile with any C compiler such as GCC.</p>
7
2009-12-24T21:11:23Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
5,377,594
<p>If you feel like experimenting, you could try <a href="http://nuitka.net/" rel="nofollow">Nuitka</a> by Kay Hayen, although it is still at its first steps.</p>
4
2011-03-21T12:30:03Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
24,822,065
<p>I've created <a href="http://www.slideshare.net/hithwen/multiplatform-binary-packaging-of-your-python-client-apps" rel="nofollow">a presentation</a> that gathers the process from compiling your python sources into c to package them for every platform (last slide contain links to more detailed instructions)</p>
0
2014-07-18T09:49:42Z
[ "python", "compilation" ]
Is it possible to compile a program written in Python?
1,957,054
<p>I am new to the Python programming language. I was wondering if it is possible to compile a program written in Python.</p>
20
2009-12-24T06:36:18Z
38,426,754
<p>I found <strong>several</strong> way to compile a python script into bytecode</p> <ol> <li><p>Using <code>py_compile.compile</code>:</p> <pre><code>import py_compile py_compile.compile('YourFileName.py') </code></pre></li> <li><p>Using <code>py_compile.main()</code>:</p> <p>It compiles several files at a time.</p...
0
2016-07-17T23:07:04Z
[ "python", "compilation" ]
why my "eval" function doesn't work ,i think it can be print 'b',but not
1,957,086
<pre><code>a='''b="ddd"''' eval(repr(a)) print str(a) print b </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
0
2009-12-24T06:45:44Z
1,957,121
<p>Use:</p> <pre><code>eval(compile(a,'&lt;string&gt;','exec')) </code></pre> <p>instead of:</p> <pre><code>eval(repr(a)) </code></pre> <p>Transcript:</p> <pre><code>&gt;&gt;&gt; a='''b="ddd"''' &gt;&gt;&gt; eval(compile(a,'&lt;string&gt;','exec')) &gt;&gt;&gt; print str(a) b="ddd" &gt;&gt;&gt; print b ddd </code>...
3
2009-12-24T06:54:11Z
[ "python", "eval", "exec" ]
why my "eval" function doesn't work ,i think it can be print 'b',but not
1,957,086
<pre><code>a='''b="ddd"''' eval(repr(a)) print str(a) print b </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
0
2009-12-24T06:45:44Z
1,957,253
<p><a href="http://docs.python.org/library/functions.html#eval" rel="nofollow">eval</a> is used to evaluate (get the result of) an expression. What you want is dynamic execution of Python code, which is done with <a href="http://docs.python.org/reference/simple%5Fstmts.html#exec" rel="nofollow">exec</a>:</p> <pre><cod...
2
2009-12-24T07:42:22Z
[ "python", "eval", "exec" ]
why my "eval" function doesn't work ,i think it can be print 'b',but not
1,957,086
<pre><code>a='''b="ddd"''' eval(repr(a)) print str(a) print b </code></pre> <p>Please try to use the code, rather than text, because my English is not very good, thank you</p>
0
2009-12-24T06:45:44Z
1,957,262
<p>Reconsider whether you really need to use <code>eval()</code>. For example, you can use <a href="http://diveintopython.net/html_processing/locals_and_globals.html" rel="nofollow"><code>globals()</code></a> like this:</p> <pre><code>&gt;&gt;&gt; globals()['b'] = 'ddd' &gt;&gt;&gt; print b ddd </code></pre> <p>But ...
0
2009-12-24T07:45:52Z
[ "python", "eval", "exec" ]
render_to_response gives TemplateDoesNotExist
1,957,089
<p>I am obtaining the path of template using </p> <pre><code>paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') </code></pre> <p>and calling it in another application where paymenthtml gets copied to payment_template</p> <pre><code>return render_to_response(self.payment_template, self...
8
2009-12-24T06:46:25Z
1,957,106
<p>i do not have a django here, but i think you should use / instead of \\ ?</p> <p>python helps you about the slashes across OSes</p>
2
2009-12-24T06:50:28Z
[ "python", "django", "django-templates" ]
render_to_response gives TemplateDoesNotExist
1,957,089
<p>I am obtaining the path of template using </p> <pre><code>paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') </code></pre> <p>and calling it in another application where paymenthtml gets copied to payment_template</p> <pre><code>return render_to_response(self.payment_template, self...
8
2009-12-24T06:46:25Z
1,957,108
<p>Are you <em>certain</em> that this file exists on your system?</p> <blockquote> <p><code>E:\testapp\template\payment.html</code></p> </blockquote> <p>This error message is pretty straightforward and is seen when Django tries to find your template file by path on the file system and cannot see it.</p> <p>If the ...
1
2009-12-24T06:50:55Z
[ "python", "django", "django-templates" ]
render_to_response gives TemplateDoesNotExist
1,957,089
<p>I am obtaining the path of template using </p> <pre><code>paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') </code></pre> <p>and calling it in another application where paymenthtml gets copied to payment_template</p> <pre><code>return render_to_response(self.payment_template, self...
8
2009-12-24T06:46:25Z
1,957,315
<p>It seems like Django will only load templates if they're in a directory you define in <code>TEMPLATE_DIRS</code>, even if they exist elsewhere.</p> <p>Try this in settings.py:</p> <pre><code>PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) # Other settings... TEMPLATE_DIRS = ( os.path.join(PROJECT_ROO...
21
2009-12-24T08:08:31Z
[ "python", "django", "django-templates" ]
render_to_response gives TemplateDoesNotExist
1,957,089
<p>I am obtaining the path of template using </p> <pre><code>paymenthtml = os.path.join(os.path.dirname(__file__), 'template\\payment.html') </code></pre> <p>and calling it in another application where paymenthtml gets copied to payment_template</p> <pre><code>return render_to_response(self.payment_template, self...
8
2009-12-24T06:46:25Z
4,639,763
<p>By the way: A tricky thing is, that django throws <code>TemplateDoesNotExist</code> even if the rendered template includes a template that doesn't exist - <code>{% include "some/template.html" %}</code>... this knowledge has cost me some time and nerves. </p>
11
2011-01-09T14:44:56Z
[ "python", "django", "django-templates" ]
efficient algorithm to perform spell check on HTML document
1,957,131
<p>I have a HTML document, a list of common spelling mistakes, and the correct spelling for each case. The HTML documents will be up to ~50 pages and there are ~30K spelling correction entries.</p> <p>What is an efficient way to correct all spelling mistakes in this HTML document? <br>(Note: my implementation will be ...
0
2009-12-24T06:57:19Z
1,957,417
<p>You are correct that the first approach will be MUCH faster than the second (additionally, I would recommend looking into <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">Tries</a> instead of a straight hash, the space savings will be quite dramatic for 30k words).</p> <p>To still be able to handle the mu...
3
2009-12-24T08:39:35Z
[ "python", "html", "algorithm", "performance", "spell-checking" ]
efficient algorithm to perform spell check on HTML document
1,957,131
<p>I have a HTML document, a list of common spelling mistakes, and the correct spelling for each case. The HTML documents will be up to ~50 pages and there are ~30K spelling correction entries.</p> <p>What is an efficient way to correct all spelling mistakes in this HTML document? <br>(Note: my implementation will be ...
0
2009-12-24T06:57:19Z
1,961,668
<p>I agree with Rob's suggestion of using a trie, based on characters, because I programmed a spelling correction algorithm ages ago based on having a dictionary of valid words stored as a trie. By using branch-and-bound I was able to suggest possibly correct spellings of misspelled words (by <a href="http://en.wikiped...
2
2009-12-25T18:37:56Z
[ "python", "html", "algorithm", "performance", "spell-checking" ]
How to make read-only data accessible by diff requests while the server is running (apache, mod_python)
1,957,148
<p>I am using Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 and I would like to preload the data I work with. </p> <p>Currently I read the data from a file on disk every time I get a request, then parse it and store it in an object. The data file is relatively large and I would like to parse/preload it ahead of ...
1
2009-12-24T07:03:21Z
1,957,160
<p>You don't say what form your data is in, but if a keystore will suffice then you can use shelve along with OS caching in order to hold the data in a preparsed format.</p>
0
2009-12-24T07:08:00Z
[ "python", "apache", "mod-python" ]
How to make read-only data accessible by diff requests while the server is running (apache, mod_python)
1,957,148
<p>I am using Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 and I would like to preload the data I work with. </p> <p>Currently I read the data from a file on disk every time I get a request, then parse it and store it in an object. The data file is relatively large and I would like to parse/preload it ahead of ...
1
2009-12-24T07:03:21Z
1,957,165
<p>Another option is to use <a href="http://semanchuk.com/philip/posix_ipc/" rel="nofollow">posix_ipc</a> to hold the data in shared memory, available to all processes.</p>
0
2009-12-24T07:08:58Z
[ "python", "apache", "mod-python" ]
How to make read-only data accessible by diff requests while the server is running (apache, mod_python)
1,957,148
<p>I am using Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 and I would like to preload the data I work with. </p> <p>Currently I read the data from a file on disk every time I get a request, then parse it and store it in an object. The data file is relatively large and I would like to parse/preload it ahead of ...
1
2009-12-24T07:03:21Z
1,977,118
<p>You could set a tmpfs (or ramfs) mount with the data and it will stay in RAM (tmpfs may send data to swap).</p>
1
2009-12-29T21:40:50Z
[ "python", "apache", "mod-python" ]
frames per seconds
1,957,237
<p>I want to limit the calculation-speed. There was a command for rate per second. Could anybody help me? doesn't rate() work in the newer version of Python? Thanks</p>
0
2009-12-24T07:35:50Z
1,957,270
<p>Using an event loop framework such as Twisted will allow you to schedule your next calculation in the future once you have completed the current calculation, and to sleep until that time.</p>
0
2009-12-24T07:50:54Z
[ "python" ]
frames per seconds
1,957,237
<p>I want to limit the calculation-speed. There was a command for rate per second. Could anybody help me? doesn't rate() work in the newer version of Python? Thanks</p>
0
2009-12-24T07:35:50Z
1,957,431
<p>Like Ignacio said, you can measure the time since the last calculation, calculate the time until the next, and sleep until then. You can also do it without any other framework, for example, with these functions:</p> <pre><code>from datetime import datetime import time t = datetime.now()[5] # milliseconds dt = # do...
1
2009-12-24T08:43:42Z
[ "python" ]
frames per seconds
1,957,237
<p>I want to limit the calculation-speed. There was a command for rate per second. Could anybody help me? doesn't rate() work in the newer version of Python? Thanks</p>
0
2009-12-24T07:35:50Z
1,966,537
<p>i found it again. There is a rate()-function in the visual-module. you can use it in the while-loop.</p>
0
2009-12-27T17:49:56Z
[ "python" ]
Why python super does not accept only instance?
1,957,251
<p>In python 2.x, super accepts the following cases</p> <pre><code>class super(object) | super(type) -&gt; unbound super object | super(type, obj) -&gt; bound super object; requires isinstance(obj, type) | super(type, type2) -&gt; bound super object; requires issubclass(type2, type) | Typical use to call a coo...
5
2009-12-24T07:41:47Z
1,957,267
<p>I can't provide a specific answer, but have you read the PEP's around the super keyword? I did a quick google search and it came up with PEP 367 and PEP 3135.</p> <p><a href="http://www.python.org/dev/peps/pep-0367/" rel="nofollow">http://www.python.org/dev/peps/pep-0367/</a></p> <p><a href="http://www.python.org...
3
2009-12-24T07:50:03Z
[ "python", "language-design" ]
Why python super does not accept only instance?
1,957,251
<p>In python 2.x, super accepts the following cases</p> <pre><code>class super(object) | super(type) -&gt; unbound super object | super(type, obj) -&gt; bound super object; requires isinstance(obj, type) | super(type, type2) -&gt; bound super object; requires issubclass(type2, type) | Typical use to call a coo...
5
2009-12-24T07:41:47Z
1,957,820
<p><code>super(ClassType, self).__init__()</code> is <em>not</em> redundant in a cooperative multiple inheritance scheme -- <code>ClassType</code> is not necessarily the type of <code>self</code>, but the class from which you want to do the cooperative call to <code>__init__</code>.</p> <p>In the class hierarchy <code...
6
2009-12-24T10:43:42Z
[ "python", "language-design" ]
Why do all twisted/wokkel xmpp examples ignore the proper usage of JID in the xmpp protocol?
1,957,255
<p>Okay, this isn't a question. All the examples of wokkel and twisted I have seen do not properly observe generated resources in the JID.</p> <p>Google talk clients built using wokkel/twisted generally break because they do not set the full JID on responses, resulting in (very hidden, low level) errors like:</p> <p>...
1
2009-12-24T07:43:45Z
2,590,641
<p>In this particular case, the better answer to the non-question is that you should not set the from address at all. Every server will happily fill in the blank for you, saving you from figuring out what JID your client has.</p>
5
2010-04-07T07:23:04Z
[ "python", "xmpp", "twisted", "google-talk" ]
Why do all twisted/wokkel xmpp examples ignore the proper usage of JID in the xmpp protocol?
1,957,255
<p>Okay, this isn't a question. All the examples of wokkel and twisted I have seen do not properly observe generated resources in the JID.</p> <p>Google talk clients built using wokkel/twisted generally break because they do not set the full JID on responses, resulting in (very hidden, low level) errors like:</p> <p>...
1
2009-12-24T07:43:45Z
20,735,156
<p>According to my experiment, it is not <code>self.parent.authenticator.jid.full()</code> but <code>self.parent.jid.full()</code>. Code snippet as below</p> <pre><code> reply = toResponse(msg, msg.getAttribute('type')) reply.addElement('body', content=unicode(msg.body)) reply["from"] = self.par...
0
2013-12-22T23:25:41Z
[ "python", "xmpp", "twisted", "google-talk" ]
i don't know why iter(not __iter__) function use in this place,what is the mean of iter in this code
1,957,329
<p>i don't know "self._iterator = iter(self._container)"in next code.</p> <p>in django.http :</p> <pre><code>class HttpResponse(object): def __iter__(self): self._iterator = iter(self._container) return self def next(self): chunk = self._iterator.next() if isinstance(chunk, un...
0
2009-12-24T08:12:14Z
1,957,625
<p><code>HttpResponse</code> is a class that can store string data. The data is stored in a member variable called <code>_container</code>.</p> <p>Suppose <code>hr</code> is an instance of <code>HttpResponse</code> with data inside it. When you call <code>iter(hr)</code> then you should get back an iterator. This i...
0
2009-12-24T09:55:20Z
[ "python", "iterator" ]
i don't know why iter(not __iter__) function use in this place,what is the mean of iter in this code
1,957,329
<p>i don't know "self._iterator = iter(self._container)"in next code.</p> <p>in django.http :</p> <pre><code>class HttpResponse(object): def __iter__(self): self._iterator = iter(self._container) return self def next(self): chunk = self._iterator.next() if isinstance(chunk, un...
0
2009-12-24T08:12:14Z
1,957,640
<p>An iterator can be iterated:</p> <pre><code>for item in mylist: print item for key,item in enumerate(mylist): print key,":",item for i in range(0,50): print i </code></pre> <p>To use <code>for item in X</code>, <code>X</code> must be <em>iterable</em>.</p> <p>You can make your class iterable by addi...
1
2009-12-24T09:59:32Z
[ "python", "iterator" ]
why dict objects are unhashable in python?
1,957,396
<p>I mean why cant we put key of dict as dict?</p> <p>that means we can't have dictionary having key as another dictionary...</p>
22
2009-12-24T08:34:01Z
1,957,403
<p>Short answer: because they are <strong>mutable containers</strong>.</p> <p>If a dict was hashed, its hash would change as you changed its contents.</p>
33
2009-12-24T08:36:25Z
[ "python", "dictionary" ]
why dict objects are unhashable in python?
1,957,396
<p>I mean why cant we put key of dict as dict?</p> <p>that means we can't have dictionary having key as another dictionary...</p>
22
2009-12-24T08:34:01Z
1,957,412
<p>None of the mutable container types in Python are <a href="http://docs.python.org/glossary.html#term-hashable" rel="nofollow">hashable</a>, because they are mutable and thus their hash value can change over their lifetime.</p>
1
2009-12-24T08:38:41Z
[ "python", "dictionary" ]
why dict objects are unhashable in python?
1,957,396
<p>I mean why cant we put key of dict as dict?</p> <p>that means we can't have dictionary having key as another dictionary...</p>
22
2009-12-24T08:34:01Z
1,958,261
<p>As others have said, the hash value of a dict changes as the contents change.</p> <p>However if you really need to use dicts as keys, you can subclass dict to make a hashable version.</p> <pre><code>&gt;&gt;&gt; class hashabledict(dict): ... def __hash__(self): ... return id(self) ... &gt;&gt;&gt; hd = ...
5
2009-12-24T13:00:31Z
[ "python", "dictionary" ]
why dict objects are unhashable in python?
1,957,396
<p>I mean why cant we put key of dict as dict?</p> <p>that means we can't have dictionary having key as another dictionary...</p>
22
2009-12-24T08:34:01Z
8,706,053
<p>This is easy to deal with. Wrap a dict in a frozenset before you hash it. Then, when you need to use it, convert it back to a dict.</p> <pre><code>&gt;&gt;&gt; unhashable = {'b': 'a', 'a': 'b'} &gt;&gt;&gt; hashable = frozenset(unhashable.items()) &gt;&gt;&gt; unhashable = dict(hashable) &gt;&gt;&gt; unhashable {'a...
10
2012-01-02T22:38:31Z
[ "python", "dictionary" ]
why dict objects are unhashable in python?
1,957,396
<p>I mean why cant we put key of dict as dict?</p> <p>that means we can't have dictionary having key as another dictionary...</p>
22
2009-12-24T08:34:01Z
32,001,043
<p>For maybe the wrong reasons I've ran into this problem a bunch of times; where I want to reference a full <code>dict</code> as a key to something. I don't need it to be mutable, but I do want to preserve and easily access the <code>dict</code>'s members.</p> <p>The easiest way I've found to make the <code>dict</cod...
0
2015-08-14T01:36:46Z
[ "python", "dictionary" ]
why my extjs combobox is not filled dynamically?
1,957,578
<p>Here is my Extjs onReady function</p> <pre><code>var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/loginjson.json' }), reader: new Ext.data.JsonReader( ...
1
2009-12-24T09:37:17Z
1,957,932
<p>I think the fields property of your JSON reader is not configured correctly. Try this:</p> <pre><code>reader: new Ext.data.JsonReader({ root: 'row' , fields:[{name: "dblist"}] }) </code></pre>
0
2009-12-24T11:18:29Z
[ "python", "django", "combobox", "extjs" ]
why my extjs combobox is not filled dynamically?
1,957,578
<p>Here is my Extjs onReady function</p> <pre><code>var store = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({ url: '/loginjson.json' }), reader: new Ext.data.JsonReader( ...
1
2009-12-24T09:37:17Z
1,958,368
<p>If you are expecting the ComboBox to behave more like an HTML select field then add to your ComboBox config the property:</p> <pre><code>triggerAction: 'all' </code></pre> <p>This will ensure that all items in the store will be displayed when the field's trigger button is clicked.</p> <p>The ComboBox config will ...
4
2009-12-24T13:43:34Z
[ "python", "django", "combobox", "extjs" ]
GUI runner in Eclipse for Python/IronPython
1,957,642
<p>As much as the console runner is nice, I enjoy the instant red/green view of a graphical runner such as NUnit or MSTest for quickly glancing at broken tests.</p> <p>Does such a tool exist for Eclipse? I've tried Google but only found some awful standalone versions.</p>
3
2009-12-24T10:00:05Z
1,962,618
<p><a href="http://pydev.org" rel="nofollow">PyDev</a> has a <a href="http://pydev.org/manual_adv_launch.html#unit-test-launch" rel="nofollow">feature</a> to quickly execute the unit tests from withing the IDE. It also allows selecting the unit test cases to run. But it displays the usual textual output, no graphical r...
1
2009-12-26T04:32:26Z
[ "python", "eclipse", "unit-testing", "ironpython" ]
How to override [] operator
1,957,780
<p>What is the name of the method to override the <code>[]</code> operator for a class?</p>
75
2009-12-24T10:35:24Z
1,957,793
<p>You need to use the <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fgetitem%5F%5F"><code>__getitem__</code> method</a>.</p> <pre><code>&gt;&gt;&gt; class MyClass: ... def __getitem__(self,index): ... return index * 2 ... &gt;&gt;&gt; myobj = MyClass() &gt;&gt;&gt; myobj[3] 6 </code...
102
2009-12-24T10:38:09Z
[ "python", "operator-overloading" ]
How to override [] operator
1,957,780
<p>What is the name of the method to override the <code>[]</code> operator for a class?</p>
75
2009-12-24T10:35:24Z
1,957,795
<p>You are looking for the <code>__getitem__</code> method. See <a href="http://docs.python.org/reference/datamodel.html" rel="nofollow">http://docs.python.org/reference/datamodel.html</a>, section 3.4.6</p>
8
2009-12-24T10:38:25Z
[ "python", "operator-overloading" ]
How to override [] operator
1,957,780
<p>What is the name of the method to override the <code>[]</code> operator for a class?</p>
75
2009-12-24T10:35:24Z
1,957,821
<p>To fully overload it you also need to implement the <code>__setitem__</code>and <code>__delitem__</code> methods.</p> <p><strong>edit</strong></p> <p>I almost forgot... if you want to completely emulate a list, you also need <code>__getslice__, __setslice__ and __delslice__</code>.</p> <p>There are all documented...
24
2009-12-24T10:43:52Z
[ "python", "operator-overloading" ]
Python2.4 and 2.6 behaves differently for os.path.getmtime() on Windows
1,957,866
<p>Getting two different modification time when calculated from different Python versions on Windows XP.</p> <p><strong>Python2.4</strong></p> <pre><code>C:\Copy of elisp&gt;c:\python24\python Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "licens...
4
2009-12-24T10:55:51Z
1,957,878
<blockquote> <p>There is a difference of 3600 seconds ...</p> </blockquote> <p>This should be the kicker. It's a timezone problem, pure and simple.</p> <p>Now all you have to do is find out why 2.4 and 2.6 are using different timezone information :-)</p>
2
2009-12-24T11:00:10Z
[ "python", "windows" ]
Python2.4 and 2.6 behaves differently for os.path.getmtime() on Windows
1,957,866
<p>Getting two different modification time when calculated from different Python versions on Windows XP.</p> <p><strong>Python2.4</strong></p> <pre><code>C:\Copy of elisp&gt;c:\python24\python Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "licens...
4
2009-12-24T10:55:51Z
1,959,093
<p>It's a bug in Microsoft's implementation of the C standard library. Python 2.4 used to use the stdlib <code>fstat</code> call to get file information, and hence could end up an hour out in locales that use DST.</p> <p>In Python 2.5 and later, <code>os.stat</code> calls the direct Win32-only API to get file informat...
2
2009-12-24T17:20:49Z
[ "python", "windows" ]
char to keycode in python
1,957,867
<p>I want to be able to translate a string to keycode to write it with Xlib (to simulate user action on linux). The keycode are not the ascii but the code you get when you do use xev on </p> <pre><code>linuxKeyPress event, serial 33, synthetic NO, window 0x6400001, root 0x13c, subw 0x0, time 51212100, (259,9), roo...
2
2009-12-24T10:55:57Z
1,958,045
<p>The keycodes depend not only on the keyboard hardware, but also on the user's preference for keyboard layout -- a user may use a dvorak layout on a qwerty keyboard, for example.</p> <p>The best solution would probably be to use python-xlib to find out the information per the user's keyboard preferences. I don't kno...
3
2009-12-24T11:47:37Z
[ "python", "linux", "keycode" ]
char to keycode in python
1,957,867
<p>I want to be able to translate a string to keycode to write it with Xlib (to simulate user action on linux). The keycode are not the ascii but the code you get when you do use xev on </p> <pre><code>linuxKeyPress event, serial 33, synthetic NO, window 0x6400001, root 0x13c, subw 0x0, time 51212100, (259,9), roo...
2
2009-12-24T10:55:57Z
1,958,086
<p>I've found <a href="http://www.shallowsky.com/software/crikey/pykey-0.1" rel="nofollow">this code</a> which is doing exactly what I wanted.</p> <p>It uses the function <code>display.keysym_to_keycode(Xlib.XK.string_to_keysym(char))</code></p>
4
2009-12-24T12:01:54Z
[ "python", "linux", "keycode" ]