title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python metaclasses vs class decorators | 1,779,372 | <p>What are the main differences between Python metaclasses and class decorators? Is there something I can do with one but not with the other?</p>
| 26 | 2009-11-22T17:39:39Z | 1,779,404 | <p>Decorators are much, much simpler and more limited -- and therefore should be preferred whenever the desired effect can be achieved with either a metaclass or a class decorator.</p>
<p>Anything you can do with a class decorator, you can of course do with a custom metaclass (just apply the functionality of the "deco... | 31 | 2009-11-22T17:49:49Z | [
"python",
"decorator",
"metaclass"
] |
Django: request.META['REMOTE_ADDR'] is always '127.0.0.1' | 1,779,464 | <p>I have an application running with debug=True on a remote host somewhere. Now somehow every time I access REMOTE_ADDR it returns 127.0.0.1 no matter where the request is from.</p>
<p>I'm not sure where to start and why this is happening.</p>
| 1 | 2009-11-22T18:10:35Z | 1,779,475 | <p>Do you have any kind of proxy, gateway, or load balancer running on that remote host? That's the sort of thing that would cause connections to appear to be from 127.0.0.1 (because that's where the immediate connection <em>is</em> from, as far as the web server is concerned).</p>
| 5 | 2009-11-22T18:14:53Z | [
"python",
"django",
"http"
] |
Django: request.META['REMOTE_ADDR'] is always '127.0.0.1' | 1,779,464 | <p>I have an application running with debug=True on a remote host somewhere. Now somehow every time I access REMOTE_ADDR it returns 127.0.0.1 no matter where the request is from.</p>
<p>I'm not sure where to start and why this is happening.</p>
| 1 | 2009-11-22T18:10:35Z | 2,315,326 | <p>If you are behind a proxy and running apache as the webserver you could use mod_rpaf. The proxy only needs to send X-Forwarded-For or X-Real-IP headers.</p>
<p><a href="http://stderr.net/apache/rpaf/" rel="nofollow">http://stderr.net/apache/rpaf/</a></p>
| 0 | 2010-02-23T00:25:48Z | [
"python",
"django",
"http"
] |
How do I save to a field that is specified in a variable? | 1,779,567 | <p>I want to do something like this:</p>
<pre>
# models.py
class Model(models.Model):
name_in_my_model = models.CharField(max_length=100)
# later
fieldname = 'name_in_my_model'
# this is what I want to do somehow:
obj = Model.objects.get(pk=1)
obj.fieldname = 'new name'
obj.save()
</pre>
<p>Is this possible?... | 0 | 2009-11-22T18:45:55Z | 1,779,579 | <p>You can use: <code>setattr(obj, fieldname, 'new name')</code>.</p>
| 5 | 2009-11-22T18:49:27Z | [
"python",
"django",
"django-models"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,779,645 | <p>One solution would be to craft a batch file that invokes the correct interpreter for a given application. THis way, you can install additional interpreters in separate folders.</p>
<p>Probably not perfect but it works.</p>
| 1 | 2009-11-22T19:10:10Z | [
"python",
"windows"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,779,655 | <p>Use batch files to run scripts, write in notepad for example:</p>
<pre>c:\python26\python.exe C:\Script_B\B.py</pre>
<p>and save it as runB.bat (or anything .bat). It will run with interpreter in c:\python26\python.exe file specified after a whitespace.</p>
| 2 | 2009-11-22T19:12:42Z | [
"python",
"windows"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,779,665 | <p>write a python script that mimics the way unix shells handle scirpts -- look at the first line and see if it matches #!(name-of-shell). Then have your python script exec that interpreter and feed it the rest of its arguments.</p>
<p>Then, associate .py with your script. </p>
| 0 | 2009-11-22T19:17:24Z | [
"python",
"windows"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,779,682 | <p>Have you considered <a href="http://www.py2exe.org/" rel="nofollow">compiling them to EXEs</a>? Once you do that, all you have to do is call the EXE, for which the machine does not require python to be installed. All the required modules etc are packaged with the distribution when you compile.</p>
| 1 | 2009-11-22T19:21:10Z | [
"python",
"windows"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,779,818 | <p><a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">VirtualEnv</a>. </p>
<blockquote>
<p>virtualenv is a tool to create
isolated Python environments.</p>
<p>The basic problem being addressed is
one of dependencies and versions, and
indirectly permissions. Imagine you
have an application t... | 7 | 2009-11-22T20:08:42Z | [
"python",
"windows"
] |
Python programs coexisting on Windows | 1,779,630 | <p>I'm looking for a way to let multiple Python programs coexist on the same Windows machine.</p>
<p>Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.</p>
<p>Trying to install all these dependencies o... | 3 | 2009-11-22T19:02:39Z | 1,783,090 | <p>It looks like the best solution is a batch file that sets the file association before running the appropriate version of Python, as mentioned in the comments to one of the answers here: <a href="http://stackoverflow.com/questions/1515850/how-to-run-both-python-2-6-and-3-0-on-the-same-windows-xp-box">http://stackover... | 0 | 2009-11-23T13:20:33Z | [
"python",
"windows"
] |
Making ORM with Python's Storm | 1,779,750 | <p>The question is based on <a href="http://stackoverflow.com/questions/1779239/converting-sql-commands-to-pythons-orm">the thread</a>, since I observed that Storm allows me reuse my SQL-schemas.</p>
<p><strong>How can you solve the following error message in Storm?</strong></p>
<p>The code is based on Jason's answer... | -1 | 2009-11-22T19:47:22Z | 1,779,790 | <p>I'll leave out the connection details because I'm not terribly familiar with Postgres.</p>
<pre><code>from storm.locals import *
class Courses(object):
__storm_table__ = 'courses'
pkey = Int(primary=True)
course_nro = Unicode()
course = Courses()
course.course_nro = 'abcd'
store.add(course)
store.comm... | 4 | 2009-11-22T19:57:41Z | [
"python",
"orm",
"storm-orm"
] |
Import Error on boost python hello program | 1,780,003 | <pre><code>#include <boost/python.hpp>
using namespace boost::python;
struct World{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
... | 12 | 2009-11-22T21:06:59Z | 1,780,022 | <p>Oh, I just saw this post:</p>
<blockquote>
<p><a href="http://stackoverflow.com/questions/1771063/help-needed-with-boost-python">help needed with boost python</a></p>
</blockquote>
<p>and problem solved</p>
| 3 | 2009-11-22T21:12:53Z | [
"python",
"boost"
] |
Import Error on boost python hello program | 1,780,003 | <pre><code>#include <boost/python.hpp>
using namespace boost::python;
struct World{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
... | 12 | 2009-11-22T21:06:59Z | 3,524,865 | <p>Solved this via <a href="http://stackoverflow.com/questions/1771063/help-needed-with-boost-python">http://stackoverflow.com/questions/1771063/help-needed-with-boost-python</a></p>
<pre><code>g++ -c -fPIC hello.cpp -o hello.o
g++ -shared -Wl,-soname,hello.so -o hello.so hello.o -lpython2.6 -lboost_python
</code></p... | 11 | 2010-08-19T18:12:42Z | [
"python",
"boost"
] |
Import Error on boost python hello program | 1,780,003 | <pre><code>#include <boost/python.hpp>
using namespace boost::python;
struct World{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
... | 12 | 2009-11-22T21:06:59Z | 18,279,672 | <p>same as other post here</p>
<pre><code>g++ -c -fPIC hello.cpp -o hello.o
g++ -shared -Wl,-soname,hello.so -o hello.so hello.o -lpython2.6 -lboost_python
</code></pre>
<p>But i want to stress the importance of the position of "-lpython2.6 -lboost_python". If you put them in front of input files (hello.o), they wil... | 3 | 2013-08-16T18:14:07Z | [
"python",
"boost"
] |
Python Windows Service Problems - Works when using debug argument but not while started as a service? | 1,780,066 | <p>hopefully someone here can shed some light on my issue :D</p>
<p>I've been creating a Windows XP service in python that is designed to monitor/repair selected Windows/Application/Service settings, atm I have been focusing on default DCOM settings.</p>
<p>The idea is to backup our default configuration within anoth... | 0 | 2009-11-22T21:30:55Z | 1,780,293 | <p>I am not an expert at this, but here are my two cents worth:</p>
<p><a href="http://www.firebirdsql.org/devel/python/docs/3.3.0/installation.html" rel="nofollow">This article</a> tells me that you might need to be logged in as someone with the required target system permissions. </p>
<p>However, I find that a litt... | 0 | 2009-11-22T22:41:32Z | [
"python",
"windows-services",
"wmi",
"py2exe",
"pywin32"
] |
Python Windows Service Problems - Works when using debug argument but not while started as a service? | 1,780,066 | <p>hopefully someone here can shed some light on my issue :D</p>
<p>I've been creating a Windows XP service in python that is designed to monitor/repair selected Windows/Application/Service settings, atm I have been focusing on default DCOM settings.</p>
<p>The idea is to backup our default configuration within anoth... | 0 | 2009-11-22T21:30:55Z | 1,904,283 | <p>So I guess it's time to admit my stupidity.... :P</p>
<p>It turns out this was not a python issue, py2exe issue, nor a WMI issue. :(</p>
<p>This was more or less a simple permission issue. So simple I overlooked it for the better part of a month. :(</p>
<p>Rule of thumb, if you want to create a service that calls... | 0 | 2009-12-14T23:30:00Z | [
"python",
"windows-services",
"wmi",
"py2exe",
"pywin32"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,208 | <p>If there are always two keys you can use:</p>
<pre><code>[{'key1':a, 'key2':b} for (a,b) in zip(d['key1'], d['key2'])]
</code></pre>
| 2 | 2009-11-22T22:20:30Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,215 | <pre><code>>>> a = {'key1': [1, 2, 3], 'key2': [4, 5, 6]}
>>> [dict((key, a[key][i]) for key in a.keys()) for i in range(len(a.values()[0]))]
[{'key2': 4, 'key1': 1}, {'key2': 5, 'key1': 2}, {'key2': 6, 'key1': 3}]
</code></pre>
| 1 | 2009-11-22T22:22:07Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,232 | <pre><code>d = {'key1': [1, 2, 3], 'key2': [4, 5, 6]}
keys = d.keys()
vals = zip(*[d[k] for k in keys])
l = [dict(zip(keys, v)) for v in vals]
print l
</code></pre>
<p>produces</p>
<pre><code>[{'key2': 4, 'key1': 1}, {'key2': 5, 'key1': 2}, {'key2': 6, 'key1': 3}]
</code></pre>
| 0 | 2009-11-22T22:25:02Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,244 | <p>Assuming the number of keys, and values per key, are both arbitrary and a priori unknown, it's simplest to get the result with for loops, of course:</p>
<pre><code> itit = thedict.iteritems()
k, vs = next(itit)
result = [{k: v} for v in vs]
for k, vs in itit:
for d, v in itertools.izip(result, vs):
... | 5 | 2009-11-22T22:28:49Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,245 | <pre><code>list(map( dict, zip(*([(key, val) for val in data[key]] for key in data.keys()))))
</code></pre>
| 1 | 2009-11-22T22:28:52Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,252 | <p><strong>Without for loop</strong>, Internal process of map is iterating actually, just without the word <strong><em>for</em></strong></p>
<pre><code>>>> x={'key1': [1, 2, 3], 'key2': [4, 5, 6]}
>>> map(lambda x,y:{'key1':x,'key2':y},x['key1'],x['key2'])
[{'key2': 4, 'key1': 1}, {'key2': 5, 'key1... | 1 | 2009-11-22T22:30:39Z | [
"python"
] |
Split dictionary of lists into list of dictionaries | 1,780,174 | <p>What i need to do is to convert something like this</p>
<pre><code>{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
</code></pre>
<p>into</p>
<pre><code>[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
</code></pre>
<p>The length of the value lists can vary!
What's the quickest way to do this (preferably... | 8 | 2009-11-22T22:11:55Z | 1,780,295 | <p><strong>Works for any number of keys</strong></p>
<pre><code>>>> map(dict, zip(*[[(k, v) for v in value] for k, value in d.items()]))
[{'key2': 4, 'key1': 1}, {'key2': 5, 'key1': 2}, {'key2': 6, 'key1': 3}]
</code></pre>
<p>For example:</p>
<pre><code>d = {'key3': [7, 8, 9], 'key2': [4, 5, 6], 'key1': [1... | 11 | 2009-11-22T22:41:55Z | [
"python"
] |
Tornado and Python 3.x | 1,780,303 | <p>I really like <a href="http://www.tornadoweb.org/">Tornado</a> and I would like to use it with Python 3, though it is written for Python versions 2.5 and 2.6.</p>
<p>Unfortunately it seems like the project's source doesn't come with a test suite. If I understand correctly the WSGI part of it wouldn't be that easy t... | 11 | 2009-11-22T22:45:06Z | 1,780,348 | <p>Software without a decent test suite is <a href="http://rads.stackoverflow.com/amzn/click/0131177052">legacy software</a> -- even if it has been released yesterday!-) -- so the first important step is to start building a test suite; I recommend Feathers' book in the URL, but you can start with <a href="http://www.ob... | 13 | 2009-11-22T23:01:01Z | [
"python",
"asynchronous",
"python-3.x",
"wsgi",
"tornado"
] |
Tornado and Python 3.x | 1,780,303 | <p>I really like <a href="http://www.tornadoweb.org/">Tornado</a> and I would like to use it with Python 3, though it is written for Python versions 2.5 and 2.6.</p>
<p>Unfortunately it seems like the project's source doesn't come with a test suite. If I understand correctly the WSGI part of it wouldn't be that easy t... | 11 | 2009-11-22T22:45:06Z | 1,780,477 | <p>Tornado is a good web framework over something that kind of looks like <a href="http://twistedmatrix.com/" rel="nofollow">twisted</a>, but doesn't have twisted's bug fixes or features. I did <a href="http://dustin.github.com/2009/09/12/tornado.html" rel="nofollow">a port to twisted</a> a while back that essentially... | 4 | 2009-11-22T23:59:52Z | [
"python",
"asynchronous",
"python-3.x",
"wsgi",
"tornado"
] |
Tornado and Python 3.x | 1,780,303 | <p>I really like <a href="http://www.tornadoweb.org/">Tornado</a> and I would like to use it with Python 3, though it is written for Python versions 2.5 and 2.6.</p>
<p>Unfortunately it seems like the project's source doesn't come with a test suite. If I understand correctly the WSGI part of it wouldn't be that easy t... | 11 | 2009-11-22T22:45:06Z | 6,326,762 | <p>first of all, I want to apologize for an answer to an outdated topic,
but once I found this topic through Google, I want to update important information!</p>
<p>In the Tornado 2.0 adds support for Python 3.2!</p>
<p><a href="https://github.com/facebook/tornado/blob/master/setup.py">https://github.com/facebook/tor... | 24 | 2011-06-13T04:45:53Z | [
"python",
"asynchronous",
"python-3.x",
"wsgi",
"tornado"
] |
How can I approximate Python's or operator for set comparison in Scala? | 1,780,459 | <p>After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.</p>
<p>Here's the whole problem. (Let's not compare lines o... | 6 | 2009-11-22T23:53:31Z | 1,780,514 | <p>Would this work? The <code>_</code> syntax is a partially applied function and by using a (lazy) <code>Stream</code>, I ensure that the evaluations in the <code>reduceLeft</code> (which I think is more appropriate than <code>foldLeft</code> here) only happen as required!</p>
<pre><code>def correct(word:String) = {
... | 4 | 2009-11-23T00:12:13Z | [
"python",
"scala",
"anonymous-function"
] |
How can I approximate Python's or operator for set comparison in Scala? | 1,780,459 | <p>After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.</p>
<p>Here's the whole problem. (Let's not compare lines o... | 6 | 2009-11-22T23:53:31Z | 1,780,844 | <p>I'm not sure why you're attempting to use lazy evaluation for <code>known</code> rather than simply using a stream as oxbow_lakes illustrated. A better way of doing what he did:</p>
<pre><code>def correct(word: String) = {
import Stream._
val str = cons(known(Set(word)),
cons(known(edits1(word)),... | 6 | 2009-11-23T02:37:02Z | [
"python",
"scala",
"anonymous-function"
] |
How can I approximate Python's or operator for set comparison in Scala? | 1,780,459 | <p>After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.</p>
<p>Here's the whole problem. (Let's not compare lines o... | 6 | 2009-11-22T23:53:31Z | 1,781,462 | <p>Iterators are also lazy (although not very functional since you can only iterate over them once.) So, you could do it like this: </p>
<pre><code> def correct(word: String) = {
val sets = List[String => Set[String]](
x => known(Set(x)), x => known(edits1(x)), known_edits2
).elements.map(_(wor... | 2 | 2009-11-23T06:41:37Z | [
"python",
"scala",
"anonymous-function"
] |
How can I approximate Python's or operator for set comparison in Scala? | 1,780,459 | <p>After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.</p>
<p>Here's the whole problem. (Let's not compare lines o... | 6 | 2009-11-22T23:53:31Z | 1,782,432 | <p>Scala 2.7-ready (including implicit performance work-around):</p>
<pre><code>class Or[A](one: Set[A]) {
def or(other: => Set[A]): Set[A] = if (one.isEmpty) other else one
}
implicit def toOr[A](one: Set[A]) = new Or(one)
def correct(word: String) = {
candidates = known(Set(word)) or known(edits1(word)) or... | 3 | 2009-11-23T11:04:01Z | [
"python",
"scala",
"anonymous-function"
] |
How can I approximate Python's or operator for set comparison in Scala? | 1,780,459 | <p>After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.</p>
<p>Here's the whole problem. (Let's not compare lines o... | 6 | 2009-11-22T23:53:31Z | 1,985,716 | <p>I've tried to implement a <a href="http://theyougen.blogspot.com/2009/12/peter-norvigs-spelling-corrector-in.html" rel="nofollow">short Scala implementation of the spelling corrector</a>. It's 15 lines without imports. The shortest replacement for Python's or is simple call by name parameter:</p>
<pre><code>def or[... | 0 | 2009-12-31T14:56:59Z | [
"python",
"scala",
"anonymous-function"
] |
How do I update an already existing row when using ModelForms? | 1,780,499 | <p>Greetings,</p>
<p>I have a question on how to update an existing row in my database when one of the fields is my primary key. I am using ModelForm and Django-Piston - my main goal here is to have RESTful Post send to my webservice. I am able to have initial Posts be sent correctly (i.e. that Primary key value doesn... | 7 | 2009-11-23T00:07:25Z | 1,780,554 | <p>To update an existing row (or object in ORM-speak), you have to tell the <code>ModelForm</code> what instance to use when instantiating it:</p>
<pre><code>f = DeviceModelForm(request.POST, instance=myobject)
</code></pre>
<p>I'm not sure where you get <code>myobject</code> from using piston, though, but your quest... | 5 | 2009-11-23T00:28:16Z | [
"python",
"django",
"modelform",
"piston"
] |
How do I update an already existing row when using ModelForms? | 1,780,499 | <p>Greetings,</p>
<p>I have a question on how to update an existing row in my database when one of the fields is my primary key. I am using ModelForm and Django-Piston - my main goal here is to have RESTful Post send to my webservice. I am able to have initial Posts be sent correctly (i.e. that Primary key value doesn... | 7 | 2009-11-23T00:07:25Z | 1,780,566 | <p>The <a href="http://docs.djangoproject.com/en/dev/topics/forms/modelforms/">django docs</a> give a simple example of how to create "a form to change an existing [[entity]]":</p>
<pre><code>>>> article = Article.objects.get(pk=1)
>>> form = ArticleForm(instance=article)
</code></pre>
<p>If as it s... | 9 | 2009-11-23T00:34:04Z | [
"python",
"django",
"modelform",
"piston"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 1,780,590 | <pre><code>def __iter__(self): return self.books.itervalues()
</code></pre>
| 19 | 2009-11-23T00:41:10Z | [
"python",
"iterator"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 1,780,592 | <p>Add this method to Library:</p>
<pre><code>def __iter__(self):
return self.books.itervalues()
</code></pre>
<p>This delegates iteration to the dict, which has an easy method to iterate values. Read about the iterator protocol, which consists of <code>__iter__</code> (on all iterables) and <code>next</code>(<cod... | 4 | 2009-11-23T00:41:38Z | [
"python",
"iterator"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 1,780,594 | <pre><code>>>> class Library(object):
... def __init__(self):
... self.books = { 'title' : object, 'title2' : object, 'title3' : object, }
... def __getitem__(self, i):
... return self.books[i]
... def __iter__(self):
... ... | 2 | 2009-11-23T00:41:48Z | [
"python",
"iterator"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 1,780,597 | <p>Have you considered using the <a href="http://www.python.org/doc/2.6.4/library/userdict.html" rel="nofollow">UserDict</a> mixin?</p>
| 0 | 2009-11-23T00:42:17Z | [
"python",
"iterator"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 1,780,602 | <p>You can return an iterator from your inner data:</p>
<pre><code>class Library (object):
...
def __iter__(self):
return self.books.itervalues()
</code></pre>
<p><code>itervalues()</code> returns an iterator to the values of the dictionary.</p>
<p>If you want more control, you can make <code>__iter__</code>... | 2 | 2009-11-23T00:43:23Z | [
"python",
"iterator"
] |
How do I use __getitem__ and __iter__ and return values from a dictionary? | 1,780,571 | <p>I have an object with a dictionary that I want to access via <code>__getitem__</code> as well as iterate over (values only, keys don't matter) but am not sure how to do it.</p>
<p>For example:</p>
<pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(se... | 9 | 2009-11-23T00:35:14Z | 14,108,762 | <p><strong>getitem</strong>(self,key), where key is a integer, as your self.books is a dictionary and you can not do self.books[integer]</p>
<p>e.g:</p>
<pre><code>>>>d = {'a':'sdsdsd','b':'sfsdsd'}
>>d[0]
</code></pre>
<p>d[0]
Traceback (most recent call last):
File "", line 1, in
KeyError: 0</p>
... | 0 | 2013-01-01T07:37:21Z | [
"python",
"iterator"
] |
Puzzling App Engine Datastore Issue (ListProperty) | 1,780,618 | <p>Ok so I have the same python code locally and in the gae cloud.</p>
<p>when I store an entity locally, the ListProperty field of set element type datetime.datetime looks like so in the Datastore Viewer:</p>
<pre><code>2009-01-01 00:00:00,2010-03-10 00:00:00
</code></pre>
<p>when I store same on the cloud, the vie... | 1 | 2009-11-23T00:49:51Z | 1,780,977 | <p>The problem your see is clearly a conversion to string (calling <code>__str__</code> or <code>__unicode__</code>) in the local case, while the representation (repr) of your data is displayed on the cloud. But this difference in printing out the results should not be the cause of your failed query on the cloud.</p>
... | 1 | 2009-11-23T03:32:16Z | [
"python",
"google-app-engine",
"gae-datastore",
"listproperty"
] |
Puzzling App Engine Datastore Issue (ListProperty) | 1,780,618 | <p>Ok so I have the same python code locally and in the gae cloud.</p>
<p>when I store an entity locally, the ListProperty field of set element type datetime.datetime looks like so in the Datastore Viewer:</p>
<pre><code>2009-01-01 00:00:00,2010-03-10 00:00:00
</code></pre>
<p>when I store same on the cloud, the vie... | 1 | 2009-11-23T00:49:51Z | 1,813,344 | <p>Ok long story short: it's now classed as a bug in the app engine dev server version and is no longer supported in the production cloud datastore.</p>
<p>Filled out a further explanation in a <a href="http://aleatory.clientsideweb.net/2009/11/28/google-app-engine-datastore-gotchas/" rel="nofollow">blog post</a>, che... | 2 | 2009-11-28T18:41:49Z | [
"python",
"google-app-engine",
"gae-datastore",
"listproperty"
] |
Ugly Code: Amusing comment? | 1,780,721 | <p>Here's a fragment of code I'm prototyping that should, by all accounts, never see the light of day. I'll refactor it and clean it up before I merge it into my project.</p>
<p>However, it seems to be working and I happened to be listening to Arlo Guthrie when I was working on it.</p>
<pre><code>#!/usr/bin/env pyth... | 1 | 2009-11-23T01:38:55Z | 1,780,749 | <p>If you could switch your current <code>a-b</code> syntax (which seems likely to get hopelessly confused by negative numbers!) to <code>a:b</code>, then Python's slice syntax would do the parsing for you -- you'd end up (e.g. through a fake class with an indexing method) with a tuple including slices and scalars:</p>... | 4 | 2009-11-23T01:53:48Z | [
"python",
"comments"
] |
Ugly Code: Amusing comment? | 1,780,721 | <p>Here's a fragment of code I'm prototyping that should, by all accounts, never see the light of day. I'll refactor it and clean it up before I merge it into my project.</p>
<p>However, it seems to be working and I happened to be listening to Arlo Guthrie when I was working on it.</p>
<pre><code>#!/usr/bin/env pyth... | 1 | 2009-11-23T01:38:55Z | 1,781,102 | <p>I posted a parser for this format <a href="http://stackoverflow.com/questions/1481192/pythonic-format-for-indices/1481267#1481267">here</a>.</p>
| 1 | 2009-11-23T04:32:57Z | [
"python",
"comments"
] |
Getting every odd variable in a list? | 1,780,763 | <p>If I make a list in Python and want to write a function that would return only odd numbers from a range 1 to x how would I do that?</p>
<p>For example, if I have list [1, 2, 3, 4] from 1 to 4 (4 ix my x), I want to return [1, 3].</p>
| 3 | 2009-11-23T02:03:21Z | 1,780,770 | <p>If you want to start with an arbitrary list:</p>
<pre><code>[item for item in yourlist if item % 2]
</code></pre>
<p>but if you're always starting with <code>range</code>, <code>range(1, x, 2)</code> is better!-)</p>
<p>For example:</p>
<pre><code>$ python -mtimeit -s'x=99' 'filter(lambda(t): t % 2 == 1, range(1... | 13 | 2009-11-23T02:06:41Z | [
"python"
] |
Getting every odd variable in a list? | 1,780,763 | <p>If I make a list in Python and want to write a function that would return only odd numbers from a range 1 to x how would I do that?</p>
<p>For example, if I have list [1, 2, 3, 4] from 1 to 4 (4 ix my x), I want to return [1, 3].</p>
| 3 | 2009-11-23T02:03:21Z | 1,780,829 | <p>What's wrong with:</p>
<pre><code>def getodds(lst):
return lst[1::2]
</code></pre>
<p>....???</p>
<p>(Assuming you want every other element from some arbitrary sequence ... all those which have odd indexes).</p>
<p>Alternatively if you want all items from a list of numbers where the value of that element is ... | 1 | 2009-11-23T02:31:10Z | [
"python"
] |
Getting every odd variable in a list? | 1,780,763 | <p>If I make a list in Python and want to write a function that would return only odd numbers from a range 1 to x how would I do that?</p>
<p>For example, if I have list [1, 2, 3, 4] from 1 to 4 (4 ix my x), I want to return [1, 3].</p>
| 3 | 2009-11-23T02:03:21Z | 1,900,019 | <p>To have a range of odd/even numbers up to and possibly including a number n, you can:</p>
<pre><code>def odd_numbers(n):
return range(1, n+1, 2)
def even_numbers(n):
return range(0, n+1, 2)
</code></pre>
<p>If you want a generic algorithm that will take the items with odd <em>indexes</em> from a sequence, ... | 0 | 2009-12-14T10:05:58Z | [
"python"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,780,909 | <p>List comprehension is the way to go:</p>
<pre><code>list1 = [1,2,3,4,5]
list2 = [i for i in list1 if i%2 == 0]
print list2 # => [2, 4]
</code></pre>
| 7 | 2009-11-23T03:06:19Z | [
"python",
"list"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,780,911 | <pre><code>list2 = [x for x in list1 if x%2 == 0]
</code></pre>
| 1 | 2009-11-23T03:06:37Z | [
"python",
"list"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,780,913 | <p>If you want to extend an existing <code>list2</code> (not necessarily initially empty):</p>
<pre><code>list2.extend(v for v in list1 if v % 2 == 0)
</code></pre>
<p>If there's no "initial value" for <code>list2</code>, and you just want to build it from scratch:</p>
<pre><code>list2 = [v for v in list1 if v % 2 =... | 3 | 2009-11-23T03:07:05Z | [
"python",
"list"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,780,915 | <p>You can use <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a>:</p>
<pre><code>list2 = [x for x in list1 if x % 2 == 0]
</code></pre>
| 3 | 2009-11-23T03:07:40Z | [
"python",
"list"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,781,040 | <pre><code>list2 = [i for i in list1 if not i%2]
</code></pre>
| 0 | 2009-11-23T04:02:03Z | [
"python",
"list"
] |
Adding even values to new list Python | 1,780,904 | <p>If I have a list and I want to create a list with only even values of the original list, how would I do that?</p>
<p>I originally have: </p>
<pre><code>list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
</code></pre>
| 0 | 2009-11-23T03:04:14Z | 1,789,992 | <p>I find this to be the most readable solution:</p>
<pre><code>list2 = filter(lambda x: x % 2 == 0: list1)
</code></pre>
<p>or if you have to use this function multiple times:</p>
<pre><code>is_even = lambda x: x % 2 == 0
list2 = filter(is_even, list1)
</code></pre>
| 0 | 2009-11-24T13:16:40Z | [
"python",
"list"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,935 | <pre><code>// string -> int
uint ret = 0;
for ( int i = 0; i < 4; ++i )
{
ret |= ( str[i] << ( i * 8 ) );
}
// int -> string
for ( int i = 0; i < 4; ++i )
{
str[i] = ( ret >> ( i * 8 ) ) & 0xff;
}
</code></pre>
| 3 | 2009-11-23T03:14:37Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,937 | <p>For Python, <a href="http://docs.python.org/library/struct.html?highlight=struct.pack#struct.pack">struct.unpack</a> does the job (to make a 4-byte string into an int -- <code>struct.pack</code> goes the other way):</p>
<pre><code>>>> import struct
>>> struct.unpack('i', 'isoy')[0]
2037347177
>... | 8 | 2009-11-23T03:15:27Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,938 | <p>Please take a look at the struct standard library module in Python's Manual. It has two functions for this: <code>struct.pack</code> and <code>struct.unpack</code>. You can use the 'L' (unsigned long) format character for this.</p>
| 2 | 2009-11-23T03:16:25Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,959 | <p>To 32-bit unsigned integer:</p>
<pre><code>uint x = BitConverter.ToUInt32(Encoding.ASCII.GetBytes("isoy"), 0); // 2037347177
</code></pre>
<p>To string:</p>
<pre><code>string s = Encoding.ASCII.GetString(BitConverter.GetBytes(x)); // "isoy"
</code></pre>
<p><a href="http://msdn.microsoft.com/en-us/library/s... | 10 | 2009-11-23T03:22:16Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,966 | <p>Aside from byte packing, you can also consider that your 26-character alphabet can be encoded as 0-25 instead of A-Z.</p>
<p>So without worrying about big and little endians, you can go from "letters" to a number like this:</p>
<pre><code>val=letter0+letter1*26+letter2*26*26+letter3*26*26*26;
</code></pre>
<p>to ... | 2 | 2009-11-23T03:24:27Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
How do I encode a 4-byte string as a single 32-bit integer? | 1,780,922 | <p>First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important. </p>
<p>I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not importan... | 2 | 2009-11-23T03:09:30Z | 1,780,997 | <p>Using PowerShell syntax you can do it this way (pretty much like dtb solution):</p>
<pre><code>PS> $x = [BitConverter]::ToUInt32([byte[]][char[]]'isoy', 0)
PS> [char[]][BitConverter]::GetBytes($x) -join ''
isoy
</code></pre>
<p>You do have to watch out for endian-ness on the Linux side. If it is running on ... | 3 | 2009-11-23T03:43:33Z | [
"c#",
"python",
"algorithm",
"powershell"
] |
Python unicode character in __str__ | 1,780,925 | <p>I'm trying to print cards using their suit unicode character and their values. I tried doing to following:</p>
<pre><code>def __str__(self):
return u'\u2660'.encode('utf-8')
</code></pre>
<p>like suggested in another <a href="http://stackoverflow.com/questions/1307014/python-str-versus-unicode">thread</a>, but... | 0 | 2009-11-23T03:11:28Z | 1,780,948 | <p>Depending on how you have encoded those "suit symbols" into a byte string, you'll need to make the unicode string back for it by mentioning the appropriate codec (for example, <code>thebytestr.decode('latin-1')</code> if latin-1 is how you encoded it!), before making the <code>utf-8</code> encoding of that unicode s... | 2 | 2009-11-23T03:19:07Z | [
"python",
"string",
"unicode"
] |
Python unicode character in __str__ | 1,780,925 | <p>I'm trying to print cards using their suit unicode character and their values. I tried doing to following:</p>
<pre><code>def __str__(self):
return u'\u2660'.encode('utf-8')
</code></pre>
<p>like suggested in another <a href="http://stackoverflow.com/questions/1307014/python-str-versus-unicode">thread</a>, but... | 0 | 2009-11-23T03:11:28Z | 1,780,961 | <p>Where does that <code>UnicodeEncodeError</code> occur exactly? I can think about two possible issues here:</p>
<ul>
<li><p>The <code>UnicodeEncodeError</code> occurs in you <code>__unicode__</code> method.</p></li>
<li><p>Your <code>__unicode__</code> method returns a byte string instead of a unicode object and tha... | 3 | 2009-11-23T03:22:31Z | [
"python",
"string",
"unicode"
] |
Python unicode character in __str__ | 1,780,925 | <p>I'm trying to print cards using their suit unicode character and their values. I tried doing to following:</p>
<pre><code>def __str__(self):
return u'\u2660'.encode('utf-8')
</code></pre>
<p>like suggested in another <a href="http://stackoverflow.com/questions/1307014/python-str-versus-unicode">thread</a>, but... | 0 | 2009-11-23T03:11:28Z | 30,923,644 | <p>I ran the same code and got</p>
<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>>>> u'\u2660'.encode('utf-8')
'\xe2\x99\xa0'
>>> print ('\xe2\x99\xa0')
ââ¢Â </code></pre>
</div>
</div>... | 0 | 2015-06-18T19:00:45Z | [
"python",
"string",
"unicode"
] |
Error while installing Poster (Python Module) | 1,781,158 | <p>I'm trying to install <a href="http://atlee.ca/software/poster/" rel="nofollow">Chris Atlee's python Poster library</a> so I can upload a file using a HTTP POST query from within my script.</p>
<p>On python 2.3, when I type <code># python setup.py install</code>, I get the following error. The install continues, bu... | 0 | 2009-11-23T04:52:32Z | 1,781,165 | <p>Python 2.3 didn't have support for decorators (that's what @classmethod is) or list comprehensions (which is the second error), so you're either going to have to find an older version of Poster, or stick with urllib/urllib2 for doing your HTTP work.</p>
<p>Actually, it looks like Poster was created around July, 200... | 0 | 2009-11-23T04:55:58Z | [
"python",
"post",
"http-post",
"httppostedfile",
"http-post-vars"
] |
PyQt: removeChild/addChild QGroupBox | 1,781,173 | <p>I am developing a system for a customer which is displayed in a set of tabs, and shows a table in the centralwidget with data extracted from a database.</p>
<p>Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table.</p>
<p>Here ... | 1 | 2009-11-23T04:59:01Z | 1,781,184 | <ol>
<li><p>It seems to contain a typo: addContainer_Bottun_Pressed</p>
<p>Wouldn't it be addContainer_Bott**o**n_Pressed instead?</p></li>
<li><p>You might need to call some kind of "relayout" method after changing the widgets on the fly. You should try to call this after removing/adding child widgets: <code>self.vBo... | 1 | 2009-11-23T05:03:25Z | [
"python",
"qt",
"pyqt"
] |
PyQt: removeChild/addChild QGroupBox | 1,781,173 | <p>I am developing a system for a customer which is displayed in a set of tabs, and shows a table in the centralwidget with data extracted from a database.</p>
<p>Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table.</p>
<p>Here ... | 1 | 2009-11-23T04:59:01Z | 1,786,544 | <p>I don't think calling removeWidget is necessary. Try just calling widget.deleteLater on whatever you want to delete. Then when you want to add it back, recreate it and use layout.insertWidget to put it in its proper place. Does that work?</p>
<p>It's working for me here on Windows XP... </p>
<pre><code>import ... | 2 | 2009-11-23T22:35:53Z | [
"python",
"qt",
"pyqt"
] |
PyQt: removeChild/addChild QGroupBox | 1,781,173 | <p>I am developing a system for a customer which is displayed in a set of tabs, and shows a table in the centralwidget with data extracted from a database.</p>
<p>Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table.</p>
<p>Here ... | 1 | 2009-11-23T04:59:01Z | 1,787,636 | <p>First of all thanks for all the input I received here. In the sequence is the source code working -- or at least working 80% perfectly well. </p>
<ul>
<li><p>80% - What it does: radioButton to delete groupBox; radioButton to say Hello; radioButton to say Nice;</p></li>
<li><p>20% - What it still doesn't do: radioBu... | 1 | 2009-11-24T03:43:31Z | [
"python",
"qt",
"pyqt"
] |
PyQt: removeChild/addChild QGroupBox | 1,781,173 | <p>I am developing a system for a customer which is displayed in a set of tabs, and shows a table in the centralwidget with data extracted from a database.</p>
<p>Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table.</p>
<p>Here ... | 1 | 2009-11-23T04:59:01Z | 1,794,265 | <p>Here is the final solution, working 100%:</p>
<ul>
<li><p>update as follows:</p>
<pre><code>def on_show(self):
print "addBox // radioButton1.isChecked : ", self.radioButton1.isChecked()
if not self.centralwidget.newGroupBox:
#self.addBox()
self.addwidget_centralwdg(self.globalMainWindow)
def ad... | 0 | 2009-11-25T02:20:39Z | [
"python",
"qt",
"pyqt"
] |
Python data structure/object to model static multidimensional table | 1,781,207 | <p>I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree.</p>
<p><strong>Example Form hierarchy:</strong></p>
<ul>
<li>MyForm
<ul>
<li>Question 1</li>
<li>Part 1
<ul>
... | 1 | 2009-11-23T05:10:43Z | 1,781,217 | <p>I'd store such hierarchical data in XML on the storage. You can use the <code>xml.etree.ElementTree</code> standard module to load such an XML file into a hierarchical data structure in Python, make changes to it, then save it back to a file. This way you don't have to bother with the actual data structure, since it... | 2 | 2009-11-23T05:13:52Z | [
"python",
"class",
"data-structures",
"data-modeling",
"inner-classes"
] |
Python data structure/object to model static multidimensional table | 1,781,207 | <p>I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree.</p>
<p><strong>Example Form hierarchy:</strong></p>
<ul>
<li>MyForm
<ul>
<li>Question 1</li>
<li>Part 1
<ul>
... | 1 | 2009-11-23T05:10:43Z | 1,781,385 | <p>There's nothing headachey or ill-supported about nested classes in Python, it's just they don't do anything. Don't expect to get a Java-inner-class-style link back to an owner instance automatically: nested classes are nothing but normal classes whose class object happens to be stored in the property of another clas... | 1 | 2009-11-23T06:12:20Z | [
"python",
"class",
"data-structures",
"data-modeling",
"inner-classes"
] |
Python data structure/object to model static multidimensional table | 1,781,207 | <p>I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree.</p>
<p><strong>Example Form hierarchy:</strong></p>
<ul>
<li>MyForm
<ul>
<li>Question 1</li>
<li>Part 1
<ul>
... | 1 | 2009-11-23T05:10:43Z | 1,795,333 | <p>Thought I'd share a bit of what I've learned from doing this using <strong>ElementTree</strong>, specifically the <strong>lxml</strong> implementation of <strong>ElementTree</strong> and <strong>lxml.objectify</strong> with some XPath. The XML could also be simplified to <code><part></code> and <code><ques... | 0 | 2009-11-25T07:56:14Z | [
"python",
"class",
"data-structures",
"data-modeling",
"inner-classes"
] |
Python for web scripting | 1,781,431 | <p>I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps â using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template... | 1 | 2009-11-23T06:28:45Z | 1,781,456 | <p>I think probably the easiest way for you to get started is to work with something like <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/" rel="nofollow">Django</a>. It's a top-to-bottom web development stack which provides you with everything you need to develop and run a backend server. Things can b... | 2 | 2009-11-23T06:40:02Z | [
"python",
"html",
"web-applications",
"fastcgi",
"template-engine"
] |
Python for web scripting | 1,781,431 | <p>I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps â using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template... | 1 | 2009-11-23T06:28:45Z | 1,781,525 | <p>Django is definitely not the easiest way.</p>
<p>check out pylons. <a href="http://pylonshq.com/" rel="nofollow">http://pylonshq.com/</a></p>
<p>also check sqlalchemy for sql related stuff. Very cool library.</p>
<p>On the other hand, you can always start with something very simple like mako for templating. <a hr... | 0 | 2009-11-23T07:06:32Z | [
"python",
"html",
"web-applications",
"fastcgi",
"template-engine"
] |
Python for web scripting | 1,781,431 | <p>I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps â using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template... | 1 | 2009-11-23T06:28:45Z | 1,784,843 | <p>You asked whether HTML is allowed within Python, which indicates that you still think too much in PHP terms about it. Contrary to PHP, Python was not designed to create dynamic web-pages. Instead, it was designed as a stand-alone, general-purpose programming language. Therefore you will not be able to put HTML into ... | 2 | 2009-11-23T17:53:51Z | [
"python",
"html",
"web-applications",
"fastcgi",
"template-engine"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,781,450 | <p>Python: <a href="http://docs.python.org/library/cgitb.html" rel="nofollow">cgitb</a>. At the top of your script, before other imports:</p>
<pre><code>import cgitb
cgitb.enable(False, '/home/me/www/myapp/logs/errors')
</code></pre>
<p>(âerrorsâ being a directory the web server user has write-access to.)</p>
| 3 | 2009-11-23T06:38:14Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,781,493 | <p>In Perl try <a href="http://perldoc.perl.org/CGI/Carp.html" rel="nofollow">CGI::Carp</a></p>
<pre><code>BEGIN {
use CGI::Carp qw(carpout);
use diagnostics;
open(LOG, ">errors.txt");
carpout(LOG);
close(LOG);
}
use CGI::Carp qw(fatalsToBrowser);
</code></pre>
| 3 | 2009-11-23T06:55:59Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,781,494 | <p>For Perl, just close and re-open <code>STDERR</code> to point to a file of your choice.</p>
<pre><code>close STDERR;
open STDERR, '>>', '/path/to/your/log.txt'
or die "Couldn't redirect STDERR: $!";
warn "this will go to log.txt";
</code></pre>
<p>Alternatively, you could look into a filehandle multiplex... | 4 | 2009-11-23T06:56:16Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,781,511 | <p>Python has the sys.<strong>stderr</strong> module that you might want to look into.</p>
<pre><code>>>>help(sys.__stderr__.read)
Help on built-in function read:
read(...)
read([size]) -> read at most size bytes, returned as a string.
If the size argument is negative or omitted, read until EOF i... | 0 | 2009-11-23T07:02:38Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,781,611 | <p>python:</p>
<pre><code>import sys
sys.stderr = open('file_path_with_write_permission/filename', 'a')
</code></pre>
| 2 | 2009-11-23T07:33:28Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,782,294 | <p>In my Perl CGI programs, I usually have</p>
<pre><code>BEGIN {
open(STDERR,'>>','stderr.log');
}
</code></pre>
<p>right after shebang line and "use strict;use warnings;". If you want, you may append $0 to file name. But this will not solve multiple programs problem, as several copies of one programs may be... | 0 | 2009-11-23T10:35:37Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
Redirecting CGI error output from STDERR to a file (python AND perl) | 1,781,436 | <p>I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."</p>
<p>For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a w... | 4 | 2009-11-23T06:31:27Z | 1,789,077 | <p>The solution I finally went with was similar to the following, near the top of all my scripts:</p>
<p>Perl:</p>
<pre><code>open(STDERR,">>","/path/to/my/cgi-error.log")
or die "Could not redirect STDERR: $OS_ERROR";
</code></pre>
<p>Python:</p>
<pre><code>sys.stderr = open("/path/to/my/cgi-error.log", ... | 2 | 2009-11-24T10:00:20Z | [
"python",
"perl",
"cgi",
"stderr",
"hostmonster"
] |
How to let a raw_input repeat until I want to quit? | 1,781,445 | <p>Say I want to use <code>raw_input</code> like this: </p>
<p><code>code = raw_input("Please enter your three-letter code or a blank line to quit: ")</code></p>
<p>under:</p>
<pre><code>if __name__=="__main__":
</code></pre>
<p>How can I let it repeat multiple times rather than just once every time I run the pro... | 6 | 2009-11-23T06:36:16Z | 1,781,463 | <pre><code>if __name__ == '__main__':
input = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
while input:
input = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
</code></pre>
| 1 | 2009-11-23T06:41:42Z | [
"python",
"raw-input"
] |
How to let a raw_input repeat until I want to quit? | 1,781,445 | <p>Say I want to use <code>raw_input</code> like this: </p>
<p><code>code = raw_input("Please enter your three-letter code or a blank line to quit: ")</code></p>
<p>under:</p>
<pre><code>if __name__=="__main__":
</code></pre>
<p>How can I let it repeat multiple times rather than just once every time I run the pro... | 6 | 2009-11-23T06:36:16Z | 1,781,499 | <p>best:</p>
<pre><code>if __name__ == '__main__':
while True:
entered = raw_input("Please enter your three-letter code or leave a blank line to quit: ")
if not entered: break
if len(entered) != 3:
print "%r is NOT three letters, it's %d" % (entered, len(entered))
continue
if not entered.... | 6 | 2009-11-23T06:58:12Z | [
"python",
"raw-input"
] |
How to let a raw_input repeat until I want to quit? | 1,781,445 | <p>Say I want to use <code>raw_input</code> like this: </p>
<p><code>code = raw_input("Please enter your three-letter code or a blank line to quit: ")</code></p>
<p>under:</p>
<pre><code>if __name__=="__main__":
</code></pre>
<p>How can I let it repeat multiple times rather than just once every time I run the pro... | 6 | 2009-11-23T06:36:16Z | 1,781,555 | <pre><code>while 1:
choice=raw_input("Enter: ")
if choice in ["Q","q"]: break
print choice
#do something else
</code></pre>
| 3 | 2009-11-23T07:17:25Z | [
"python",
"raw-input"
] |
How to let a raw_input repeat until I want to quit? | 1,781,445 | <p>Say I want to use <code>raw_input</code> like this: </p>
<p><code>code = raw_input("Please enter your three-letter code or a blank line to quit: ")</code></p>
<p>under:</p>
<pre><code>if __name__=="__main__":
</code></pre>
<p>How can I let it repeat multiple times rather than just once every time I run the pro... | 6 | 2009-11-23T06:36:16Z | 19,394,082 | <pre><code>def myInput():
return raw_input("Please enter your three-letter code or a blank line to quit: ")
for code in iter(myInput, ""):
if len(code) != 3 or not code.isalpha():
print 'invalid code'
continue
#do something with the code
</code></pre>
| 1 | 2013-10-16T02:05:11Z | [
"python",
"raw-input"
] |
How to load DLL using ctypes in Python? | 1,781,531 | <p>Please provide me a sample explaining how to load & call a functions in c++ dll using Python?</p>
<p>I found some articles saying we can use "ctypes" to load and call a function in DLL using Python. But i am not able to find a working sample?</p>
<p>It would be great if anyone provide me an sample of how to do... | 4 | 2009-11-23T07:08:36Z | 1,781,552 | <p>Here is some <em>actual</em> code I used in a project to load a DLL, lookup a function and set up and call that function.</p>
<pre class="lang-py prettyprint-override"><code>import ctypes
# Load DLL into memory.
hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")
# Set up prototype and parameters for the desired ... | 3 | 2009-11-23T07:16:38Z | [
"python"
] |
regular expression matching everything except a given regular expression | 1,781,554 | <p>I am trying to figure out a regular expression which matches any string which doesn't start with mpeg. A generalization of this is matching any string which doesn't start with a given regular expression.</p>
<p>I tried something like as follows:</p>
<pre><code>[^m][^p][^e][^g].*
</code></pre>
<p>The problem with ... | 5 | 2009-11-23T07:17:03Z | 1,781,604 | <p>Try a <a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow">look-ahead assertion</a>:</p>
<pre><code>(?!mpeg)^.*
</code></pre>
<p>Or if you want to use negated classes only:</p>
<pre><code>^(.{0,3}$|[^m]|m([^p]|p([^e]|e([^g])))).*$
</code></pre>
| 2 | 2009-11-23T07:31:25Z | [
"python",
"regex"
] |
regular expression matching everything except a given regular expression | 1,781,554 | <p>I am trying to figure out a regular expression which matches any string which doesn't start with mpeg. A generalization of this is matching any string which doesn't start with a given regular expression.</p>
<p>I tried something like as follows:</p>
<pre><code>[^m][^p][^e][^g].*
</code></pre>
<p>The problem with ... | 5 | 2009-11-23T07:17:03Z | 1,781,605 | <pre><code>^(?!mpeg).*
</code></pre>
<p>This uses a negative lookahead to only match a string where the beginning doesn't match <code>mpeg</code>. Essentially, it requires that "the position at the beginning of the string cannot be a position where if we started matching the regex <code>mpeg</code>, we could successfu... | 19 | 2009-11-23T07:31:56Z | [
"python",
"regex"
] |
regular expression matching everything except a given regular expression | 1,781,554 | <p>I am trying to figure out a regular expression which matches any string which doesn't start with mpeg. A generalization of this is matching any string which doesn't start with a given regular expression.</p>
<p>I tried something like as follows:</p>
<pre><code>[^m][^p][^e][^g].*
</code></pre>
<p>The problem with ... | 5 | 2009-11-23T07:17:03Z | 1,781,620 | <p>don't lose your mind with regex. </p>
<pre><code>if len(mystring) >=4 and mystring[:4]=="mpeg":
print "do something"
</code></pre>
<p>or use startswith() with "not" keyword</p>
<pre><code>if len(mystring)>=4 and not mystring.startswith("mpeg")
</code></pre>
| 8 | 2009-11-23T07:35:27Z | [
"python",
"regex"
] |
regular expression matching everything except a given regular expression | 1,781,554 | <p>I am trying to figure out a regular expression which matches any string which doesn't start with mpeg. A generalization of this is matching any string which doesn't start with a given regular expression.</p>
<p>I tried something like as follows:</p>
<pre><code>[^m][^p][^e][^g].*
</code></pre>
<p>The problem with ... | 5 | 2009-11-23T07:17:03Z | 1,781,651 | <p>Your regexp wouldn't match "npeg", I think you would need come up with
<code>^($|[^m]|m($|[^p]|p($|[^e]|e($|[^g]))))</code>, which is quite horrible.
Another alternative would be <code>^(.{0,3}$|[^m]|.[^p]|..[^e]|...[^g])</code>
which is only slightly better.</p>
<p>So I think you should really use a look-ahead ass... | 0 | 2009-11-23T07:46:21Z | [
"python",
"regex"
] |
To understand: From PHP Array to Python? | 1,781,617 | <p>This is Common task In PHP and other programming languages.I moved from PHP developer.
I want to make sure with this collections.
Anyone have who good in python please help me to understand clearly .
This is my collections from PHP code.</p>
<pre><code><?php
$php = array(1,2,3,4,5,6,7,8,9,10);
for ($i = 0; $i &l... | 7 | 2009-11-23T07:34:21Z | 1,781,645 | <p>You can read an introduction to loops in <a href="http://docs.python.org/tutorial/datastructures.html#looping-techniques" rel="nofollow">the Python tutorial</a>. </p>
| 3 | 2009-11-23T07:42:40Z | [
"php",
"python",
"arrays",
"loops"
] |
To understand: From PHP Array to Python? | 1,781,617 | <p>This is Common task In PHP and other programming languages.I moved from PHP developer.
I want to make sure with this collections.
Anyone have who good in python please help me to understand clearly .
This is my collections from PHP code.</p>
<pre><code><?php
$php = array(1,2,3,4,5,6,7,8,9,10);
for ($i = 0; $i &l... | 7 | 2009-11-23T07:34:21Z | 1,781,649 | <p>All of these are quite obvious really. I'm only listing the <em>Pythonic</em> ways to do these things</p>
<h3>Example 1</h3>
<p>PHP</p>
<pre><code>$php = array(1,2,3,4,5,6,7,8,9,10);
for ($i = 0; $i < 10 ; $i ++)
echo $php[$i]."<br>";
</code></pre>
<p>Python (generally you <em>iterate</em> over lists in... | 21 | 2009-11-23T07:44:59Z | [
"php",
"python",
"arrays",
"loops"
] |
To understand: From PHP Array to Python? | 1,781,617 | <p>This is Common task In PHP and other programming languages.I moved from PHP developer.
I want to make sure with this collections.
Anyone have who good in python please help me to understand clearly .
This is my collections from PHP code.</p>
<pre><code><?php
$php = array(1,2,3,4,5,6,7,8,9,10);
for ($i = 0; $i &l... | 7 | 2009-11-23T07:34:21Z | 1,781,694 | <p>"What is in Python?", quite a philosophical question, always a great way to start a day. I think what <em>is in</em> Python can best be answered by the Zen of Python (type <code>import this</code> in an interactive shell):</p>
<ul>
<li>Beautiful is better than ugly.</li>
<li>Explicit is better than implicit.</li>
<... | 10 | 2009-11-23T08:00:12Z | [
"php",
"python",
"arrays",
"loops"
] |
To understand: From PHP Array to Python? | 1,781,617 | <p>This is Common task In PHP and other programming languages.I moved from PHP developer.
I want to make sure with this collections.
Anyone have who good in python please help me to understand clearly .
This is my collections from PHP code.</p>
<pre><code><?php
$php = array(1,2,3,4,5,6,7,8,9,10);
for ($i = 0; $i &l... | 7 | 2009-11-23T07:34:21Z | 1,781,769 | <p>This question reminds me of a wise man who had said, <em>"Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime..."</em></p>
| 2 | 2009-11-23T08:22:53Z | [
"php",
"python",
"arrays",
"loops"
] |
Configure MySQL to work with Django | 1,781,618 | <p>Just installed Django (with easy_install) and created a project, but can't get mysql to work. </p>
<p><code>python manage.py syncdb</code> throws this error:</p>
<pre><code>.....
File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/mysql/base.py", line 13, in <module>
rai... | 0 | 2009-11-23T07:34:50Z | 1,781,653 | <p>you need Python library for MySQL access, MySQLdb:</p>
<p><a href="http://sourceforge.net/projects/mysql-python/" rel="nofollow">http://sourceforge.net/projects/mysql-python/</a></p>
| 3 | 2009-11-23T07:46:42Z | [
"python",
"mysql",
"django",
"configuration",
"installation"
] |
Configure MySQL to work with Django | 1,781,618 | <p>Just installed Django (with easy_install) and created a project, but can't get mysql to work. </p>
<p><code>python manage.py syncdb</code> throws this error:</p>
<pre><code>.....
File "/Library/Python/2.6/site-packages/Django-1.1.1-py2.6.egg/django/db/backends/mysql/base.py", line 13, in <module>
rai... | 0 | 2009-11-23T07:34:50Z | 1,783,284 | <p>The MySQL egg requires a compiler from the dev tools (download XCode from the apple developers site) and a MySQL installation.</p>
<p>If you have installed those, you have set the PATH to include mysql_config.</p>
<pre><code>export PATH=$PATH:/usr/local/mysql-5.1.39-osx10.5-x86_64/bin/
</code></pre>
<p>Check the ... | 0 | 2009-11-23T14:01:25Z | [
"python",
"mysql",
"django",
"configuration",
"installation"
] |
How does the layout of a Python application look? | 1,781,657 | <p>In most programming environments it's clear how the code is distributed into several parts and how everything interacts. In Python I seem to be completely lost.</p>
<ul>
<li><p>How should the layout of a Python application look?</p>
<p>Currently I have:</p>
<pre>
setup.py
application_name/
__main__.py
__i... | 7 | 2009-11-23T07:47:13Z | 1,781,680 | <p>There are several parts to this question so I'll try to answer them in turn:</p>
<p>1: Its really up to you, there are no hard-and-fast rules beyond those for establishing that a directory should be treated as a <a href="http://docs.python.org/tutorial/modules.html#packages" rel="nofollow">package</a> and so on. S... | 5 | 2009-11-23T07:54:48Z | [
"python",
"code-layout"
] |
paste.httpserver and slowdown with HTTP/1.1 Keep-alive; tested with httperf and ab | 1,781,766 | <p>I have a web server based on paste.httpserver as an adapater between HTTP and WSGI. When I do performance measurements with httperf, I can do over 1,000 requests per second if I start a new request each time using --num-conn. If I instead reuse the connection using --num-call then I get about 11 requests per second,... | 3 | 2009-11-23T08:22:12Z | 1,795,352 | <p>After some effort, it seems to be either <a href="http://en.wikipedia.org/wiki/Nagle%27s%5Falgorithm">Nagle's algorithm</a> or the delayed ACK, or the interactions between them. It goes away if I do something like</p>
<pre><code>server.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
</code></pre>
<p>H... | 6 | 2009-11-25T08:00:09Z | [
"python",
"paste",
"keep-alive",
"httpserver",
"httperf"
] |
Writing Sudoku Solver wih Python | 1,781,795 | <p>Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function.</p>
<p>No matter how much time I look over and move the codes around, I seem to have no luck</p>
<p>Can anyone Help me?</p>
<p><hr></p>
<pre><code>import copy
def... | 1 | 2009-11-23T08:31:34Z | 1,781,835 | <p>Solving sudoku need some bruteforcing method, I dont see those in your codes. </p>
<p>I also tried to do before, but finally I saw <a href="http://norvig.com/sudoku.html" rel="nofollow">norvig's codes</a>, its just working perfect.</p>
<p>and ended up with learning his codes finally.</p>
| 0 | 2009-11-23T08:41:48Z | [
"python",
"sudoku"
] |
Writing Sudoku Solver wih Python | 1,781,795 | <p>Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function.</p>
<p>No matter how much time I look over and move the codes around, I seem to have no luck</p>
<p>Can anyone Help me?</p>
<p><hr></p>
<pre><code>import copy
def... | 1 | 2009-11-23T08:31:34Z | 1,781,876 | <p>If you want to stabilize your code, then write small test cases for each function which make sure that they work correctly.</p>
<p>In your case, run a puzzle, and determine which field is wrong. Then guess which function might produce the wrong output. Call it with the input to see what it really does. Repeat for e... | 3 | 2009-11-23T08:55:12Z | [
"python",
"sudoku"
] |
Writing Sudoku Solver wih Python | 1,781,795 | <p>Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function.</p>
<p>No matter how much time I look over and move the codes around, I seem to have no luck</p>
<p>Can anyone Help me?</p>
<p><hr></p>
<pre><code>import copy
def... | 1 | 2009-11-23T08:31:34Z | 1,781,899 | <p>I would avoid things like "move the codes around". This is called <a href="http://blog.giladnaor.com/2008/08/programming-by-coincidence.html" rel="nofollow">"Programming by Coincidence"</a> (see <a href="http://rads.stackoverflow.com/amzn/click/020161622X" rel="nofollow">The Pragmatic Programmer</a>). Programming li... | 3 | 2009-11-23T09:04:21Z | [
"python",
"sudoku"
] |
Writing Sudoku Solver wih Python | 1,781,795 | <p>Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function.</p>
<p>No matter how much time I look over and move the codes around, I seem to have no luck</p>
<p>Can anyone Help me?</p>
<p><hr></p>
<pre><code>import copy
def... | 1 | 2009-11-23T08:31:34Z | 1,782,184 | <p>I'd like to help you in a way that you can write the actual code, so here is some explanation, and some pseudo-code.</p>
<p>Those sudoku solvers that don't mimic human deduction logic are bruteforce-based. Basically, you'll need a backtrack algorithm. You have your has_conflict method, which checks whether the cand... | 2 | 2009-11-23T10:03:06Z | [
"python",
"sudoku"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.