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 |
|---|---|---|---|---|---|---|---|---|---|
Organising my Python project | 391,879 | <p>I'm starting a Python project and expect to have 20 or more classes in it. As is good practice I want to put them in a separate file each. However, the project directory quickly becomes swamped with files (or will when I do this).</p>
<p>If I put a file to import in a folder I can no longer import it. How do I impo... | 45 | 2008-12-24T17:23:14Z | 391,916 | <p>"As is good practice I want to put them in a separate file each. "</p>
<p>This is not actually a very good practice. You should design modules that contain closely-related classes.</p>
<p>As a practical matter, no class actually stands completely alone. Generally classes come in clusters or groups that are logic... | 22 | 2008-12-24T17:42:54Z | [
"python",
"project-organization"
] |
Python Optparse list | 392,041 | <p>I'm using the python optparse module in my program, and I'm having trouble finding an easy way to parse an option that contains a list of values.</p>
<p>For example:</p>
<pre><code>--groups one,two,three.
</code></pre>
<p>I'd like to be able to access these values in a list format as <code>options.groups[]</code... | 33 | 2008-12-24T18:54:52Z | 392,061 | <p>Look at <a href="http://docs.python.org/2/library/optparse#option-callbacks" rel="nofollow">option callbacks</a>. Your callback function can parse the value into a list using a basic <code>optarg.split(',')</code></p>
| 35 | 2008-12-24T19:03:51Z | [
"python",
"optparse"
] |
Python Optparse list | 392,041 | <p>I'm using the python optparse module in my program, and I'm having trouble finding an easy way to parse an option that contains a list of values.</p>
<p>For example:</p>
<pre><code>--groups one,two,three.
</code></pre>
<p>I'd like to be able to access these values in a list format as <code>options.groups[]</code... | 33 | 2008-12-24T18:54:52Z | 392,258 | <p>S.Lott's answer has already been accepted, but here's a code sample for the archives:</p>
<pre><code>def foo_callback(option, opt, value, parser):
setattr(parser.values, option.dest, value.split(','))
parser = OptionParser()
parser.add_option('-f', '--foo',
type='string',
acti... | 73 | 2008-12-24T21:50:34Z | [
"python",
"optparse"
] |
Python Optparse list | 392,041 | <p>I'm using the python optparse module in my program, and I'm having trouble finding an easy way to parse an option that contains a list of values.</p>
<p>For example:</p>
<pre><code>--groups one,two,three.
</code></pre>
<p>I'd like to be able to access these values in a list format as <code>options.groups[]</code... | 33 | 2008-12-24T18:54:52Z | 29,301,200 | <p>Again, just for the sake of archive completeness, expanding the example above:</p>
<ul>
<li>You can still use "dest" to specify the option name for later access</li>
<li>Default values cannot be used in such cases (see explanation in <a href="http://stackoverflow.com/questions/14568141/triggering-callback-on-defaul... | 7 | 2015-03-27T12:53:43Z | [
"python",
"optparse"
] |
wxPython and sharing objects between windows | 392,100 | <p>I've been working with python for a while now and am just starting to learn wxPython. After creating a few little programs, I'm having difficulty understanding how to create objects that can be shared between dialogs.</p>
<p>Here's some code as an example (apologies for the length - I've tried to trim):</p>
<pre>... | 2 | 2008-12-24T19:30:01Z | 392,125 | <p>You can pass a gamePlayer object to <code>__init__</code> as another argument.</p>
<pre><code>def __init__(self, parent, id, title, gamePlayer ):
...etc...
</code></pre>
<p>In the long run, this isn't ideal. </p>
<p>You should separate building an empty panel from loading that panel with data. The empty pan... | 3 | 2008-12-24T19:42:02Z | [
"python",
"wxpython"
] |
wxPython and sharing objects between windows | 392,100 | <p>I've been working with python for a while now and am just starting to learn wxPython. After creating a few little programs, I'm having difficulty understanding how to create objects that can be shared between dialogs.</p>
<p>Here's some code as an example (apologies for the length - I've tried to trim):</p>
<pre>... | 2 | 2008-12-24T19:30:01Z | 20,334,493 | <p>A Model-View-Controller (MVC) framework allows you to access common data (Model) and display it in your GUI (Views) through a Controller. A good explanation is found here:</p>
<p><a href="http://wiki.wxpython.org/ModelViewController" rel="nofollow">MVC Framework for wxPython</a></p>
<p>Basically, you avoid tangled... | 1 | 2013-12-02T17:42:28Z | [
"python",
"wxpython"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,230 | <p>You never absolutely <em>need</em> to use a metaclass, since you can always construct a class that does what you want using inheritance or aggregation of the class you want to modify.</p>
<p>That said, it can be very handy in Smalltalk and Ruby to be able to modify an existing class, but Python doesn't like to do t... | 4 | 2008-12-24T21:17:25Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,232 | <p>The only time I used metaclasses in Python was when writing a wrapper for the Flickr API. </p>
<p>My goal was to scrape <a href="http://www.flickr.com/services/api/" rel="nofollow">flickr's api site</a> and dynamically generate a complete class hierarchy to allow API access using Python objects:</p>
<pre><code># B... | 4 | 2008-12-24T21:19:39Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,255 | <p>The purpose of metaclasses isn't to replace the class/object distinction with metaclass/class - it's to change the behaviour of class definitions (and thus their instances) in some way. Effectively it's to alter the behaviour of the class statement in ways that may be more useful for your particular domain than the... | 27 | 2008-12-24T21:43:05Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,278 | <p>Metaclasses aren't replacing programming! They're just a trick which can automate or make more elegant some tasks. A good example of this is <a href="http://pygments.org/" rel="nofollow">Pygments</a> syntax highlighting library. It has a class called <code>RegexLexer</code> which lets the user define a set of lexing... | 3 | 2008-12-24T22:15:22Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,308 | <p>Metaclasses can be handy for construction of Domain Specific Languages in Python. Concrete examples are Django, SQLObject 's declarative syntax of database schemata. </p>
<p>A basic example from <a href="http://blog.ianbicking.org/a-conservative-metaclass.html" rel="nofollow">A Conservative Metaclass</a> by Ian Bic... | 6 | 2008-12-24T22:54:53Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,442 | <p>Let's start with Tim Peter's classic quote:</p>
<blockquote>
<p>Metaclasses are deeper magic than 99%
of users should ever worry about. If
you wonder whether you need them, you
don't (the people who actually need
them know with certainty that they
need them, and don't need an
explanation about why). T... | 12 | 2008-12-25T02:23:47Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 392,767 | <p>The way I used metaclasses was to provide some attributes to classes. Take for example:</p>
<pre><code>class NameClass(type):
def __init__(cls, *args, **kwargs):
type.__init__(cls, *args, **kwargs)
cls.name = cls.__name__
</code></pre>
<p>will put the <em>name</em> attribute on every class that w... | 3 | 2008-12-25T11:47:43Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 393,368 | <p>I have a class that handles non-interactive plotting, as a frontend to Matplotlib. However, on occasion one wants to do interactive plotting. With only a couple functions I found that I was able to increment the figure count, call draw manually, etc, but I needed to do these before and after every plotting call. ... | 10 | 2008-12-26T01:35:56Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 395,751 | <p>I was thinking the same thing just yesterday and completely agree. The complications in the code caused by attempts to make it more declarative generally make the codebase harder to maintain, harder to read and less pythonic in my opinion.
It also normally requires a lot of copy.copy()ing (to maintain inheritance... | 5 | 2008-12-28T03:20:15Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 5,330,521 | <p>The only legitimate use-case of a metaclass is to keep other nosy developers from touching your code. Once a nosy developer masters metaclasses and starts poking around with yours, throw in another level or two to keep them out. If that doesn't work, start using type.<strong>new</strong> or perhaps some scheme using... | 2 | 2011-03-16T19:13:50Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 7,057,480 | <p>A reasonable pattern of metaclass use is doing something once when a class is defined rather than repeatedly whenever the same class is instantiated. </p>
<p>When multiple classes share the same special behaviour, repeating <strong>__metaclass__=X</strong> is obviously better than repeating the special purpose code... | 4 | 2011-08-14T14:49:02Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 7,058,179 | <p>This is a minor use, but... one thing I've found metaclasses useful for is to invoke a function whenever a subclass is created. I codified this into a metaclass which looks for an <code>__initsubclass__</code> attribute: whenever a subclass is created, all parent classes which define that method are invoked with <c... | 2 | 2011-08-14T16:44:08Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 16,925,938 | <p>Some GUI libraries have trouble when multiple threads try to interact with them. <code>tkinter</code> is one such example; and while one can explicitly handle the problem with events and queues, it can be far simpler to use the library in a manner that ignores the problem altogether. Behold -- the magic of metaclass... | 3 | 2013-06-04T19:29:42Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 19,865,575 | <p>I recently had to use a metaclass to help declaratively define an SQLAlchemy model around a database table populated with U.S. Census data from <a href="http://census.ire.org/data/bulkdata.html" rel="nofollow">http://census.ire.org/data/bulkdata.html</a></p>
<p>IRE provides <a href="https://github.com/ireapps/censu... | 1 | 2013-11-08T17:59:56Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 23,853,525 | <p>There seems to be a legitimate use described <a href="http://www.jesshamrick.com/2013/04/17/rewriting-python-docstrings-with-a-metaclass/" rel="nofollow">here</a> - Rewriting Python Docstrings with a Metaclass.</p>
| 1 | 2014-05-25T08:44:58Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 31,061,875 | <p>I was asked the same question recently, and came up with several answers. I hope it's OK to revive this thread, as I wanted to elaborate on a few of the use cases mentioned, and add a few new ones.</p>
<p>Most metaclasses I've seen do one of two things:</p>
<ol>
<li><p>Registration (adding a class to a data struct... | 13 | 2015-06-25T22:26:32Z | [
"python",
"metaclass"
] |
What are your (concrete) use-cases for metaclasses in Python? | 392,160 | <p>I have a friend who likes to use metaclasses, and regularly offers them as a solution.</p>
<p>I am of the mind that you almost never need to use metaclasses. Why? because I figure if you are doing something like that to a class, you should probably be doing it to an object. And a small redesign/refactor is in order... | 51 | 2008-12-24T20:13:06Z | 39,292,817 | <p>I had to use them once for a binary parser to make it easier to use. You define a message class with attributes of the fields present on the wire.
They needed to be ordered in the way they were declared to construct the final wire format from it. You can do that with metaclasses, if you use an ordered namespace dict... | 0 | 2016-09-02T12:47:37Z | [
"python",
"metaclass"
] |
Is there a Ruby/Python HTML reflow/layout library? | 392,217 | <p>I'm looking for a library in Ruby or Python that would take some HTML and CSS as the input and return data that contains the positions and sizes of the elements. If it helps, I don't need the info for all the elements but just the major divs of the page.</p>
| 3 | 2008-12-24T21:05:12Z | 392,243 | <p>Scriptor, I think what you likely are looking for might be something in JavaScript more then Ruby or Python. I mean - the positions and sizes are essentially going to be determined by the rendering engine (the browser). You might consider using something like jQuery to loop through all of your desired objects - outp... | 3 | 2008-12-24T21:29:45Z | [
"python",
"html",
"ruby",
"layout"
] |
Is there a Ruby/Python HTML reflow/layout library? | 392,217 | <p>I'm looking for a library in Ruby or Python that would take some HTML and CSS as the input and return data that contains the positions and sizes of the elements. If it helps, I don't need the info for all the elements but just the major divs of the page.</p>
| 3 | 2008-12-24T21:05:12Z | 392,412 | <p>Both Ruby and Python have a Regex library. Why not search for things like /width=\"(\d+)px\"/ and /height:(\d+)px/. Use $1 to find the value in the group. I'm not a regex expert and I'm doing this from memory, so refer to any of the tutorials on the net for the correct syntax and variable usage, but that's where ... | -1 | 2008-12-25T01:23:46Z | [
"python",
"html",
"ruby",
"layout"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 392,360 | <p>Why not make var_a and var_b arguments of the function foo?</p>
<pre><code>def foo(var_a = 2, var_b = 3):
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo() # uses default arguments 2, 3
print localClosure(1) # 2 + 3 + 1 = 6
localClosure = foo(0, 3)
print localClosure(1... | 0 | 2008-12-24T23:53:01Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 392,366 | <p>I don't think there is any way to do that in Python. When the closure is defined, the current state of variables in the enclosing scope is captured and no longer has a directly referenceable name (from outside the closure). If you were to call <code>foo()</code> again, the new closure would have a different set of v... | 17 | 2008-12-24T23:58:23Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 392,372 | <p>I've found an alternate answer answer to Greg's, slightly less verbose because it uses Python 2.1's custom function attributes (which conveniently enough can be accessed from inside their own function).</p>
<pre><code>def foo():
var_b = 3
def _closure(x):
return _closure.var_a + var_b + x
_closure.func_dict[... | 8 | 2008-12-25T00:08:52Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 392,468 | <p>It is quite possible in python 3 thanks to the magic of <a href="http://jeremyhylton.blogspot.com/2007/02/nonlocal-implemented.html">nonlocal</a>.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x, magic = None):
nonlocal var_a
if magic is not None... | 19 | 2008-12-25T03:13:56Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 3,399,159 | <p>We've done the following. I think it's simpler than other solutions here.</p>
<pre><code>class State:
pass
def foo():
st = State()
st.var_a = 2
st.var_b = 3
def _closure(x):
return st.var_a + st.var_b + x
def _set_a(a):
st.var_a = a
return _closure, _set_a
localClos... | 6 | 2010-08-03T17:44:46Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 4,576,305 | <p>I worked around a similar limitation by using one-item lists instead of a plain variable. It's ugly but it works because modifying a list item doesn't get treated as a binding operation by the interpreter. </p>
<p>For example:</p>
<pre><code>def my_function()
max_value = [0]
def callback (data)
... | 3 | 2011-01-01T23:31:30Z | [
"python",
"functional-programming",
"closures"
] |
Modify bound variables of a closure in Python | 392,349 | <p>Is there any way to modify the bound value of one of the variables inside a closure? Look at the example to understand it better.</p>
<pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
localClosure = foo()
# Local closure is now "return 2 + 3 + x"
a = loca... | 22 | 2008-12-24T23:38:30Z | 8,792,493 | <pre><code>def foo():
var_a = 2
var_b = 3
def _closure(x):
return var_a + var_b + x
return _closure
def bar():
var_a = [2]
var_b = [3]
def _closure(x):
return var_a[0] + var_b[0] + x
def _magic(y):
var_a[0] = y
return... | 0 | 2012-01-09T17:25:59Z | [
"python",
"functional-programming",
"closures"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,627 | <p>I hate to say it, and I know I'm risking a down mod here, but it doesn't sound like there's a language out there for you. All programming languages have their quirks and programmers simply have to adapt to them. It's completely possible to write a working server in Python without classes (eliminating the "self" vari... | 19 | 2008-12-25T08:30:16Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,645 | <p>It may depend a lot on what language your "game logic" (you may know this term as "business logic") is best expressed in. For example, if the game logic is best expressed in Python (or any other particular language) it might be best to just write it in Python and deal with the performance issues the hard way with ei... | 1 | 2008-12-25T08:50:13Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,650 | <p>What kind of performance do you need?</p>
<p>twisted is great for servers that need lots of concurrency, as is erlang. Either supports massive concurrency easily and has facilities for distributed computing.</p>
<p>If you want to span more than one core in a python app, do the same thing you'd do if you wanted to... | 7 | 2008-12-25T08:55:56Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,672 | <p>Speaking of pure performance, if you can run Java 6 you get about 1:1 performance when compared to optimized C++ (special cases notwithstanding, sometimes Java is faster, sometimes C++), the only problem you will have is of course stuff like database libraries, interconnectivity, scalability and such. I believe ther... | 7 | 2008-12-25T09:23:36Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,739 | <p>You could also look at <a href="http://jruby.codehaus.org/" rel="nofollow">jRuby</a>. It comes with lots of the benefits of Java and lots of the benefits of Ruby in one neat package. You'll have access to huge libraries from both languages.</p>
| 0 | 2008-12-25T11:07:24Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,764 | <p>You could as well use Java and compile the code using GCC to a native executable.</p>
<p>That way you don't get the performance hit of the bytecode engine (Yes, I know - Java out of the box is as fast as C++. It must be just me who always measures a factor 5 performance difference). The drawback is that the GCC Jav... | 2 | 2008-12-25T11:44:26Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,814 | <p>Erlang is a language which is designed around concurrency and distribution over several servers, which is perfect for server software. Some links about Erlang and game-servers:</p>
<p><a href="http://www.devmaster.net/articles/mmo-scalable-server/">http://www.devmaster.net/articles/mmo-scalable-server/</a></p>
<p>... | 16 | 2008-12-25T13:50:59Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,831 | <p>More details about this game server might help folks better answer your question. Is this a game server in the sense of something like a Counter Strike dedicated server which sits in the background and hosts multiplayer interactions or are you writing something which will be hosted on an HTTP webserver?</p>
<p>Per... | 3 | 2008-12-25T14:13:45Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,844 | <p>The obvious candidates are Java and Erlang:</p>
<p>Pro Java:</p>
<ul>
<li>ease of development</li>
<li>good development environments</li>
<li>stability, good stack traces</li>
<li>well-known (easy to find experienced programmers, lots of libraries, books, ...)</li>
<li>quite fast, mature VM</li>
</ul>
<p>Pro Erla... | 2 | 2008-12-25T14:34:43Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,874 | <p>What are your objectives? Not the creation of the game itself, but why are you creating it?</p>
<p>If you're doing it to learn a new language, then pick the one that seems the most interesting to you (i.e., the one you most want to learn).</p>
<p>If it is for any other reason, then the best language will be the o... | 0 | 2008-12-25T15:16:55Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,907 | <p>You could take a look at <a href="http://www.stackless.com/" rel="nofollow">Stackless Python</a>. It's an alternative Python interpreter that provides greater support for concurrency. Both EVE Online's server and client software use Stackless Python.</p>
<p>Disclaimer: I haven't used Stackless Python extensively my... | 0 | 2008-12-25T15:54:34Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 392,911 | <p>I might be going slightly off-topic here, but the topic interests me as I have (hobby-wise) worked on quite a few game servers (MMORPG servers) - on others' code as well as mine. There is literature out there that will be of interest to you, drop me a note if you want some references.</p>
<p>One thing that strikes ... | 13 | 2008-12-25T15:57:19Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 393,963 | <p>C++ and Java are quite slow compared to C. The language should be a tool but not a crutch.</p>
| -1 | 2008-12-26T16:40:00Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 397,103 | <p>There is a pretty cool framework in development that addresses all your needs:</p>
<p><a href="http://www.projectdarkstar.com" rel="nofollow" title="Project Darkstar">Project Darkstar</a> from Sun. So I'd say Java seems to be a good language for game server development :-)</p>
| 0 | 2008-12-29T03:56:17Z | [
"c#",
"java",
"python",
"networking"
] |
Good language to develop a game server in? | 392,624 | <p>I was just wondering what language would be a good choice for developing a game server to support a large (thousands) number of users? I dabbled in python, but realized that it would just be too much trouble since it doesn't spawn threads across cores (meaning an 8 core server=1 core server). I also didn't really li... | 11 | 2008-12-25T08:25:54Z | 2,130,979 | <p>I know facebook uses a combination of Erlang and C++ for their chat engine. </p>
<p>Whatever you decide, if you choose a combination of languages, check out facebook's thrift framework for cross language services deployment. They open sourced it about a year+ back:</p>
<p><a href="http://incubator.apache.org/thr... | 0 | 2010-01-25T08:17:18Z | [
"c#",
"java",
"python",
"networking"
] |
How to make a color from a number | 392,728 | <p>I have a function that returns a float from 0 to 255. I would like to make a gradient in red color from this, but I need a string in "#FFFFFF" format. Is there a function for that?</p>
| 4 | 2008-12-25T10:56:00Z | 392,732 | <p>You could use:</p>
<pre><code>"#%02X0000" % x
</code></pre>
| 10 | 2008-12-25T10:58:37Z | [
"python",
"colors"
] |
How to make a color from a number | 392,728 | <p>I have a function that returns a float from 0 to 255. I would like to make a gradient in red color from this, but I need a string in "#FFFFFF" format. Is there a function for that?</p>
| 4 | 2008-12-25T10:56:00Z | 392,976 | <pre><code>def rgbtohex(r,g,b):
return "#%02X%02X%02X" % (r,g,b)
</code></pre>
| 3 | 2008-12-25T17:11:00Z | [
"python",
"colors"
] |
How to process two forms in one view? | 392,784 | <p>I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views?<br /><br />
regards<br />
chriss</p>
| 4 | 2008-12-25T12:40:27Z | 392,801 | <p>Personally, I'd use one view to handle each form's POST.</p>
<p>On the other hand, you could use a hidden input element that indicate which form was used</p>
<pre><code><form action="/blog/" method="POST">
{{ blog_form.as_p }}
<input type="hidden" name="form-type" value"blog-form" /> <!-- se... | 5 | 2008-12-25T13:23:25Z | [
"python",
"django",
"django-forms",
"django-templates"
] |
How to process two forms in one view? | 392,784 | <p>I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views?<br /><br />
regards<br />
chriss</p>
| 4 | 2008-12-25T12:40:27Z | 392,849 | <p>If the two forms are completely different, it will certainly not hurt to have them be handled by two different views. Otherwise, you may use the 'hidden input element' trick <em>zacherates</em> has touched upon. Or, you could always give each <code>submit</code> element a <strong>unique</strong> name, and differenti... | 0 | 2008-12-25T14:42:22Z | [
"python",
"django",
"django-forms",
"django-templates"
] |
How to process two forms in one view? | 392,784 | <p>I have two completely different forms in one template. How to process them in one view? How can I distinguish which of the forms was submitted? How can I use prefix to acomplish that? Or maybe it's better to write separate views?<br /><br />
regards<br />
chriss</p>
| 4 | 2008-12-25T12:40:27Z | 393,567 | <p>like ayaz said, you should give unique name to form submit button</p>
<pre><code><form action="." method="post">
......
<input type="submit" name="form1">
</form>
<form action="." method="post">
......
<input type="submit" name="form2">
</form>
#view
if "form1" in request.PO... | 3 | 2008-12-26T07:02:48Z | [
"python",
"django",
"django-forms",
"django-templates"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 393,059 | <p>There isn't one because you can't do it in the general case - what if you have a lazy infinite generator? For example:</p>
<pre><code>def fib():
a, b = 0, 1
while True:
a, b = b, a + b
yield a
</code></pre>
<p>This never terminates but will generate the Fibonacci numbers. You can get as m... | 26 | 2008-12-25T18:53:39Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 393,134 | <p>You can use enumerate() to loop through the generated data stream, then return the last number -- the number of items.</p>
<p>I tried to use itertools.count() with itertools.izip() but no luck. This is the best/shortest answer I've come up with:</p>
<pre><code>#!/usr/bin/python
import itertools
def func():
f... | 7 | 2008-12-25T19:55:48Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 7,223,557 | <p>The easiest way is probably just <code>sum(1 for _ in gen)</code> where gen is your generator. </p>
| 161 | 2011-08-28T20:04:50Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 11,464,079 | <pre><code>def count(iter):
return sum(1 for _ in iter)
</code></pre>
<p>Or better yet:</p>
<pre><code>def count(iter):
try:
return len(iter)
except TypeError:
return sum(1 for _ in iter)
</code></pre>
<p>If it's not iterable, it will throw a <code>TypeError</code>.</p>
<p>Or, if you wan... | 6 | 2012-07-13T04:22:31Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 15,690,900 | <p>By definition, only a subset of generators will return after a certain number of arguments (have a pre-defined length), and even then, only a subset of these finite generators have a predictable end (accessing the generator can have side-effects which could stop the generator earlier).</p>
<p>If you wish to impleme... | 1 | 2013-03-28T19:51:29Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 18,630,336 | <p>Use <a href="http://docs.python.org/2/library/functions.html#reduce" rel="nofollow">reduce(function, iterable[, initializer])</a> for a memory efficient purely functional solution:</p>
<pre><code>>>> iter = "This string has 30 characters."
>>> reduce(lambda acc, e: acc + 1, iter, 0)
30
</code></pr... | 3 | 2013-09-05T07:32:31Z | [
"python",
"generator",
"iterable"
] |
Length of generator output | 393,053 | <p>Python provides a nice method for getting length of an eager iterable, <code>len(x)</code> that is. But I couldn't find anything similar for lazy iterables represented by generator comprehensions and functions. Of course, it is not hard to write something like:</p>
<pre><code>def iterlen(x):
n = 0
try:
whil... | 81 | 2008-12-25T18:50:18Z | 35,995,169 | <p>This is a hack, but if you really want to have <code>len</code> work on a general iterable (consuming it in the way), you can create your own version of <code>len</code>.</p>
<p>The <code>len</code> function is essentially equivalent to the following (though implementations usually provide some optimizations to avo... | 1 | 2016-03-14T18:24:23Z | [
"python",
"generator",
"iterable"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 393,576 | <p>You can use consumer-producer pattern. For example you can create queue that is shared between threads. First thread that fetches data from the web enqueues this data in the shared queue. Another thread that owns database connection dequeues data from the queue and passes it to the database. </p>
| 34 | 2008-12-26T07:10:39Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 393,737 | <p>I like Evgeny's answer - Queues are generally the best way to implement inter-thread communication. For completeness, here are some other options:</p>
<ul>
<li>Close the DB connection when the spawned threads have finished using it. This would fix your <code>OperationalError</code>, but opening and closing connecti... | 0 | 2008-12-26T12:51:53Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 393,984 | <p>Switch to <a href="http://docs.python.org/library/multiprocessing.html" rel="nofollow">multiprocessing</a>. It is much better, scales well, can go beyond the use of multiple cores by using multiple CPUs, and the interface is the same as using python threading module.</p>
<p>Or, as Ali suggested, just use <a href="h... | 10 | 2008-12-26T16:51:24Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 394,109 | <p>Or if you are lazy, like me, you can use <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>. It will handle the threading for you, (<a href="http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/pooling.html#sqlalchemy.pool.SingletonThreadPool">using thread local, and some connection pooling</a>) and the way it do... | 6 | 2008-12-26T18:31:37Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 394,165 | <p>You need to design the concurrency for your program. SQLite has clear limitations and you need to obey them, see the <a href="http://sqlite.org/faq.html#q5" rel="nofollow">FAQ</a> (also the following question).</p>
| 0 | 2008-12-26T19:32:37Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 394,331 | <p>You shouldn't be using threads at all for this. This is a trivial task for <a href="http://twistedmatrix.com/">twisted</a> and that would likely take you significantly further anyway.</p>
<p>Use only one thread, and have the completion of the request trigger an event to do the write.</p>
<p>twisted will take care... | 13 | 2008-12-26T21:59:14Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 395,897 | <p><a href="http://dev.scrapy.org/" rel="nofollow">Scrapy</a> seems like a potential answer to my question. Its home page describes my exact task. (Though I'm not sure how stable the code is yet.)</p>
| 0 | 2008-12-28T05:55:27Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 1,813,731 | <p>I would take a look at the y_serial Python module for data persistence: <a href="http://yserial.sourceforge.net" rel="nofollow">http://yserial.sourceforge.net</a> </p>
<p>which handles deadlock issues surrounding a single SQLite database. If demand on concurrency gets heavy one can easily set up the class Farm of m... | 0 | 2009-11-28T20:39:23Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 2,578,401 | <p>The following found on <a href="http://mail.python.org/pipermail/python-list/2010-March/1239789.html">mail.python.org.pipermail.1239789</a>
<br/><br/>
I have found the solution. I don't know why python documentation has not a single word about this option. So we have to add a new keyword argument to connection func... | 12 | 2010-04-05T12:41:29Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 2,894,830 | <p>Contrary to popular belief, newer versions of sqlite3 <strong>do</strong> support access from multiple threads.</p>
<p>This can be enabled via optional keyword argument <code>check_same_thread</code>:</p>
<pre><code>sqlite.connect(":memory:", check_same_thread=False)
</code></pre>
| 115 | 2010-05-24T05:03:46Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 3,525,147 | <p>Use <a href="http://docs.python.org/library/threading.html#lock-objects" rel="nofollow">threading.Lock()</a></p>
| 0 | 2010-08-19T18:49:37Z | [
"python",
"sqlite"
] |
Python sqlite3 and concurrency | 393,554 | <p>I have a Python program that uses the "threading" module. Once every second, my program starts a new thread that fetches some data from the web, and stores this data to my hard drive. I would like to use sqlite3 to store these results, but I can't get it to work. The issue seems to be about the following line:</p>
... | 54 | 2008-12-26T06:51:54Z | 19,860,325 | <p>The most likely reason you get errors with locked databases is that you must issue</p>
<pre><code>conn.commit()
</code></pre>
<p>after finishing a database operation. If you do not, your database will be write-locked and stay that way. The other threads that are waiting to write will time-out after a time (default... | -1 | 2013-11-08T13:33:32Z | [
"python",
"sqlite"
] |
What values to use for FastCGI maxrequests, maxspare, minspare, maxchildren? | 393,629 | <p>I'm running a Django app using FastCGI and lighttpd.</p>
<p>Can somebody explain me what I should consider when deciding what value to use for maxrequests, maxspare, minspare, maxchildren?</p>
<p>These options are not too well documented, but seem quite important.</p>
<p>Don't just tell me what they do; I want to... | 5 | 2008-12-26T08:49:51Z | 393,636 | <p>Let's start with the definition</p>
<pre>
maxrequests: How many requests does a child server before being killed
and a new one forked
maxspare : Maximum number of spare processes to keep running
minspare : Minimum number of spare processes to prefork
maxchildren: Hard limit num... | 13 | 2008-12-26T09:00:13Z | [
"python",
"django",
"fastcgi"
] |
What values to use for FastCGI maxrequests, maxspare, minspare, maxchildren? | 393,629 | <p>I'm running a Django app using FastCGI and lighttpd.</p>
<p>Can somebody explain me what I should consider when deciding what value to use for maxrequests, maxspare, minspare, maxchildren?</p>
<p>These options are not too well documented, but seem quite important.</p>
<p>Don't just tell me what they do; I want to... | 5 | 2008-12-26T08:49:51Z | 393,649 | <p>Don't forget to coordinate your fcgi settings with your apache worker settings. I usually keep more apache workers around than fcgi workers... they are lighter weight and will wait for an available fcgi worker to free up to process the request if the concurrency reaches higher than my maxspare.</p>
| -1 | 2008-12-26T09:34:20Z | [
"python",
"django",
"fastcgi"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 393,656 | <p>In the switch, did you change PostgreSQL client/server versions?</p>
<p>I have seen similar problems with php+mysql, and the culprit was an incompatibility between the client/server versions (even though they had the same major version!)</p>
| 0 | 2008-12-26T09:43:27Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 394,025 | <p>Smells like a possible threading problem. Django is <em>not</em> guaranteed thread-safe although the in-file docs seem to indicate that Django/FCGI can be run that way. Try running with prefork and then beat the crap out of the server. If the problem goes away ...</p>
| 0 | 2008-12-26T17:29:32Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 546,865 | <p>Maybe the PYTHONPATH and PATH environment variable is different for both setups (Apache+mod_python and lighttpd + FastCGI).</p>
| 0 | 2009-02-13T17:29:29Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 601,989 | <p>In the end I switched back to Apache + mod_python (I was having other random errors with fcgi, besides this one) and everything is good and stable now.</p>
<p>The question still remains open. In case anybody has this problem in the future and solves it they can record the solution here for future reference. :)</p>
| 0 | 2009-03-02T11:23:49Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 645,020 | <p>I fixed a similar issue when using a geodjango model that was not using the default ORM for one of its functions. When I added a line to manually close the connection the error went away.</p>
<p><a href="http://code.djangoproject.com/ticket/9437" rel="nofollow">http://code.djangoproject.com/ticket/9437</a></p>
<p>... | 0 | 2009-03-13T23:56:27Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 803,664 | <p>Have you considered downgrading to Python 2.5.x (2.5.4 specifically)? I don't think Django would be considered mature on Python 2.6 since there are some backwards incompatible changes. However, I doubt this will fix your problem.</p>
<p>Also, Django 1.0.2 fixed some nefarious little bugs so make sure you're runni... | -1 | 2009-04-29T18:35:06Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 1,053,436 | <p>I went through the same problem recently (lighttpd, fastcgi & postgre). Searched for a solution for days without success, and as a last resort switched to mysql. The problem is gone.</p>
| 0 | 2009-06-27T19:17:03Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 1,691,350 | <p>Why not storing session in cache?
Set</p>
<pre><code>SESSION_ENGINE = "django.contrib.sessions.backends.cache"
</code></pre>
<p>Also you can try use postgres with <em>pgbouncer</em> (postgres - prefork server and don't like many connects/disconnects per time), but firstly check your postgresql.log.</p>
<p>Another... | 0 | 2009-11-07T00:07:35Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 1,744,068 | <p>The problem could be mainly with Imports. Atleast thats what happened to me.
I wrote my own solution after finding nothing from the web. Please check my blogpost here: <a href="http://nandakishore.posterous.com/simple-djangopython-utility-to-check-all-the" rel="nofollow">Simple Python Utility to check all Imports in... | 0 | 2009-11-16T18:46:07Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 2,390,581 | <p>Change from method=prefork to method=threaded solved the problem for me.</p>
| 0 | 2010-03-05T23:06:49Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 2,503,925 | <p>Possible solution: <a href="http://groups.google.com/group/django-users/browse_thread/thread/2c7421cdb9b99e48" rel="nofollow">http://groups.google.com/group/django-users/browse_thread/thread/2c7421cdb9b99e48</a></p>
<blockquote>
<p>Until recently I was curious to test
this on Django 1.1.1. Will this
exceptio... | 3 | 2010-03-23T21:57:07Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Django + FastCGI - randomly raising OperationalError | 393,637 | <p>I'm running a Django application. Had it under Apache + mod_python before, and it was all OK. Switched to Lighttpd + FastCGI. Now I randomly get the following exception (neither the place nor the time where it appears seem to be predictable). Since it's random, and it appears only after switching to FastCGI, I assum... | 8 | 2008-12-26T09:04:03Z | 33,128,806 | <p>I try to give an answer to this even if I'am not using django but pyramid as the framework. I was running into this problem since a long time. Problem was, that it was really difficult to produce this error for tests... Anyway. Finally I solved it by digging through the whole stuff of sessions, scoped sessions, inst... | 0 | 2015-10-14T14:57:08Z | [
"python",
"django",
"exception",
"fastcgi",
"lighttpd"
] |
Programmatic Form Submit | 393,738 | <p>I want to scrape the contents of a webpage. The contents are produced after a form on that site has been filled in and submitted. </p>
<p>I've read on how to scrape the end result content/webpage - but how to I programmatically submit the form? </p>
<p>I'm using python and have read that I might need to get the or... | 2 | 2008-12-26T12:54:27Z | 393,749 | <p>You can do it with javascript. If the form is something like:</p>
<pre><code><form name='myform' ...
</code></pre>
<p>Then you can do this in javascript:</p>
<pre><code><script language="JavaScript">
function submitform()
{
document.myform.submit();
}
</script>
</code></pre>
<p>You can use the "on... | -1 | 2008-12-26T13:10:50Z | [
"python",
"forms",
"screen-scraping",
"submit"
] |
Programmatic Form Submit | 393,738 | <p>I want to scrape the contents of a webpage. The contents are produced after a form on that site has been filled in and submitted. </p>
<p>I've read on how to scrape the end result content/webpage - but how to I programmatically submit the form? </p>
<p>I'm using python and have read that I might need to get the or... | 2 | 2008-12-26T12:54:27Z | 393,760 | <p>you'll need to generate a HTTP request containing the data for the form. </p>
<p>The form will look something like:</p>
<pre><code><form action="submit.php" method="POST"> ... </form>
</code></pre>
<p>This tells you the url to request is www.example.com/submit.php and your request should be a POST.</... | 2 | 2008-12-26T13:25:55Z | [
"python",
"forms",
"screen-scraping",
"submit"
] |
Programmatic Form Submit | 393,738 | <p>I want to scrape the contents of a webpage. The contents are produced after a form on that site has been filled in and submitted. </p>
<p>I've read on how to scrape the end result content/webpage - but how to I programmatically submit the form? </p>
<p>I'm using python and have read that I might need to get the or... | 2 | 2008-12-26T12:54:27Z | 393,763 | <p>Using python, I think it takes the following steps:</p>
<ol>
<li>parse the web page that contains the form, find out the form submit address, and the submit method ("post" or "get").</li>
</ol>
<p><a href="http://www.w3.org/TR/html401/interact/forms.html" rel="nofollow">this explains form elements in html file</a>... | 2 | 2008-12-26T13:29:29Z | [
"python",
"forms",
"screen-scraping",
"submit"
] |
Programmatic Form Submit | 393,738 | <p>I want to scrape the contents of a webpage. The contents are produced after a form on that site has been filled in and submitted. </p>
<p>I've read on how to scrape the end result content/webpage - but how to I programmatically submit the form? </p>
<p>I'm using python and have read that I might need to get the or... | 2 | 2008-12-26T12:54:27Z | 393,777 | <p>From a similar question - <a href="http://stackoverflow.com/questions/2861/options-for-html-scraping">options-for-html-scraping</a> - you can learn that with Python you can use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a>.</p>
<blockquote>
<p>Beautiful Soup is a Python... | 2 | 2008-12-26T13:45:29Z | [
"python",
"forms",
"screen-scraping",
"submit"
] |
python and regular expression with unicode | 393,843 | <p>I need to delete some unicode symbols from the string 'Ø¨ÙØ³ÙÙ
٠اÙÙÙÙÙÙ Ø§ÙØ±ÙÙØÙÙ
ÙÙ°ÙÙ Ø§ÙØ±ÙÙØÙÙÙ
Ù'</p>
<p>I know they exist here for sure. I try:</p>
<pre><code>re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', 'Ø¨ÙØ³ÙÙ
٠اÙÙÙÙÙÙ Ø§ÙØ±ÙÙØÙÙ
ÙÙ°ÙÙ Ø§ÙØ... | 57 | 2008-12-26T14:40:04Z | 393,856 | <p>Are you using python 2.x or 3.0?</p>
<p>If you're using 2.x, try making the regex string a unicode-escape string, with 'u'. Since it's regex it's good practice to make your regex string a raw string, with 'r'. Also, putting your entire pattern in parentheses is superfluous.</p>
<pre><code>re.sub(ur'[\u064B-\u0652\... | 75 | 2008-12-26T14:57:57Z | [
"python",
"regex",
"character-properties"
] |
python and regular expression with unicode | 393,843 | <p>I need to delete some unicode symbols from the string 'Ø¨ÙØ³ÙÙ
٠اÙÙÙÙÙÙ Ø§ÙØ±ÙÙØÙÙ
ÙÙ°ÙÙ Ø§ÙØ±ÙÙØÙÙÙ
Ù'</p>
<p>I know they exist here for sure. I try:</p>
<pre><code>re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', 'Ø¨ÙØ³ÙÙ
٠اÙÙÙÙÙÙ Ø§ÙØ±ÙÙØÙÙ
ÙÙ°ÙÙ Ø§ÙØ... | 57 | 2008-12-26T14:40:04Z | 393,915 | <p>Use <a href="http://www.amk.ca/python/howto/unicode">unicode</a> strings. Use the <a href="http://docs.python.org/library/re.html#re.UNICODE">re.UNICODE</a> flag.</p>
<pre><code>>>> myre = re.compile(ur'[\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+',
re.UNICODE)
>>> myre
&... | 44 | 2008-12-26T15:55:11Z | [
"python",
"regex",
"character-properties"
] |
Scripting inside a Python application | 393,871 | <p><br/>
I'd like to include <strong>Python scripting</strong> in one of my applications, that is written in Python itself. </p>
<p>My application must be able to call external Python functions (written by the user) as <strong>callbacks</strong>. There must be some control on code execution; for example, if the user p... | 4 | 2008-12-26T15:12:10Z | 393,893 | <p><a href="http://pypi.python.org/pypi/RestrictedPython" rel="nofollow">RestrictedPython</a> provides a restricted execution environment for Python, e.g. for running untrusted code.</p>
| 4 | 2008-12-26T15:34:26Z | [
"python",
"scripting"
] |
Scripting inside a Python application | 393,871 | <p><br/>
I'd like to include <strong>Python scripting</strong> in one of my applications, that is written in Python itself. </p>
<p>My application must be able to call external Python functions (written by the user) as <strong>callbacks</strong>. There must be some control on code execution; for example, if the user p... | 4 | 2008-12-26T15:12:10Z | 393,897 | <p>Use <code>__import__</code> to import the files provided by the user. This function will return a module. Use that to call the functions from the imported file.</p>
<p>Use <code>try..except</code> both on <code>__import__</code> and on the actual call to catch errors.</p>
<p>Example:</p>
<pre><code>m = None
try:
... | 8 | 2008-12-26T15:36:49Z | [
"python",
"scripting"
] |
Scripting inside a Python application | 393,871 | <p><br/>
I'd like to include <strong>Python scripting</strong> in one of my applications, that is written in Python itself. </p>
<p>My application must be able to call external Python functions (written by the user) as <strong>callbacks</strong>. There must be some control on code execution; for example, if the user p... | 4 | 2008-12-26T15:12:10Z | 393,921 | <p>If you'd like the user to interactively enter commands, I can highly recommend the <a href="http://docs.python.org/library/code.html">code</a> module, part of the standard library. The InteractiveConsole and InteractiveInterpreter objects allow for easy entry and evaluation of user input, and errors are handled very... | 7 | 2008-12-26T16:01:20Z | [
"python",
"scripting"
] |
Scripting inside a Python application | 393,871 | <p><br/>
I'd like to include <strong>Python scripting</strong> in one of my applications, that is written in Python itself. </p>
<p>My application must be able to call external Python functions (written by the user) as <strong>callbacks</strong>. There must be some control on code execution; for example, if the user p... | 4 | 2008-12-26T15:12:10Z | 394,205 | <p>"My application must be able to call external Python functions (written by the user) as callbacks".</p>
<p>There's an alternative that's often simpler.</p>
<p>Define classes which call method functions at specific points. You provide a default implementation.</p>
<p>Your user can then extended the classes and pr... | 0 | 2008-12-26T20:00:14Z | [
"python",
"scripting"
] |
python introspection not showing functions for Lock | 394,300 | <p>When I try to use introspection to look at what methods are available on threading.Lock I don't see what I would expect.</p>
<p>Specifically I don't see acquire, release or locked. Why is this?</p>
<p>Here's what I do see:</p>
<pre><code>>>> dir (threading.Lock)
['__call__', '__class__', '__cmp__', '__d... | 1 | 2008-12-26T21:34:05Z | 394,307 | <p>You're doing it wrong. <code>threading.Lock</code> is not an object.</p>
<pre><code>>>> import threading
>>> threading.Lock
<built-in function allocate_lock>
>>> type(threading.Lock)
<type 'builtin_function_or_method'>
>>> x=threading.Lock()
>>> type(x)
<... | 5 | 2008-12-26T21:42:07Z | [
"python"
] |
Finding when the ActiveApplication changes in OSX through Python | 394,372 | <p>Is there a way to find when the activeApplication changes in OSX through Python and AppKit? I know how to find out launchedApplication and activeApplication ( please refer to my other question here: <a href="http://stackoverflow.com/questions/373020/finding-the-current-active-window-in-mac-os-x-using-python">http://... | 0 | 2008-12-26T22:24:43Z | 394,410 | <p>I've got <a href="http://github.com/dustin/app-hider" rel="nofollow">an OS X app</a> that does this by <a href="http://github.com/dustin/app-hider/tree/master/AppTracker.m#L212" rel="nofollow">polling with an NSTimer</a>. I tried searching for distributed notifications to see if I could find a better way to do it, ... | 1 | 2008-12-26T22:50:24Z | [
"python",
"cocoa-touch",
"osx"
] |
Finding when the ActiveApplication changes in OSX through Python | 394,372 | <p>Is there a way to find when the activeApplication changes in OSX through Python and AppKit? I know how to find out launchedApplication and activeApplication ( please refer to my other question here: <a href="http://stackoverflow.com/questions/373020/finding-the-current-active-window-in-mac-os-x-using-python">http://... | 0 | 2008-12-26T22:24:43Z | 394,416 | <p>I'm not aware of an 'official'/good way to do this, but one hackish way to go about this is to listen for any distributed notifications and see which ones are always fired when the frontmost app changes, so you can listen for that one:</p>
<p>You can set something like this up:</p>
<pre><code>def awakeFromNib(self... | 0 | 2008-12-26T22:52:05Z | [
"python",
"cocoa-touch",
"osx"
] |
Python: Lock directory access under windows | 394,439 | <p>I'd like to be able to lock directory access under windows.
The following code work greatly with file or directory under POSIX system:</p>
<pre><code>def flock(fd, blocking=False, exclusive=False):
if exclusive:
flags = fcntl.LOCK_EX
else:
flags = fcntl.LOCK_SH
if not blocking:
... | 3 | 2008-12-26T23:16:23Z | 394,464 | <p>You probably can do something like this to indirectly lock a directory with the latter flock function.</p>
<pre><code>for file in os.listdir(dir):
f = open(file)
flock(f)
</code></pre>
<p>This is a limited version, since the user will be able to create new files in the directory.</p>
| 0 | 2008-12-26T23:33:21Z | [
"python",
"windows",
"directory",
"locking"
] |
Python: Lock directory access under windows | 394,439 | <p>I'd like to be able to lock directory access under windows.
The following code work greatly with file or directory under POSIX system:</p>
<pre><code>def flock(fd, blocking=False, exclusive=False):
if exclusive:
flags = fcntl.LOCK_EX
else:
flags = fcntl.LOCK_SH
if not blocking:
... | 3 | 2008-12-26T23:16:23Z | 394,813 | <p>Yep you are right, at least I can try to lock every file of the directory but it can be painful because I need to walk into all the subdirectories of my directory.
In POSIX system it's easy because directories are seen like files so, no problem with that. But in Windows when I try to open a directory, it doesn't rea... | 0 | 2008-12-27T08:41:06Z | [
"python",
"windows",
"directory",
"locking"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.