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 |
|---|---|---|---|---|---|---|---|---|---|
Is there a python equivalent of the prefuse visualization toolkit? | 591,839 | <p>The <a href="http://prefuse.org/" rel="nofollow">prefuse visualization toolkit</a> is pretty nice, but for Java. I was wondering if there was something similar for python. My primary interest is being able to navigate dynamic graphs.</p>
| 10 | 2009-02-26T18:30:45Z | 3,476,644 | <p>This is well after OP, but just in case:</p>
<p><a href="http://dkbza.org/pydot.html" rel="nofollow">pydot</a>. Allows generation & rendering of graphs. If you need graph algorithms (transitive closure etc.) also look at pygraphlib which extends and integrates pydot.</p>
<p>Note that neither allows interactiv... | 1 | 2010-08-13T12:12:14Z | [
"python",
"visualization",
"prefuse"
] |
In Python what is the preferred way to create and manage threads? | 592,143 | <p>Python provides several methods to create threads. Which provides
the best API and the most control?</p>
<p>Thanks.</p>
| 2 | 2009-02-26T19:54:47Z | 592,168 | <p>I believe the <code>threading</code> module is the recommended one. The <code>thread</code> module is being renamed to _thread in Python 3.x, and is meant as a lower-level interface. See the note at the top of this page:</p>
<p><a href="http://docs.python.org/library/thread.html" rel="nofollow">http://docs.python... | 4 | 2009-02-26T20:00:17Z | [
"python",
"multithreading"
] |
In Python what is the preferred way to create and manage threads? | 592,143 | <p>Python provides several methods to create threads. Which provides
the best API and the most control?</p>
<p>Thanks.</p>
| 2 | 2009-02-26T19:54:47Z | 592,170 | <p>When necessary, the <a href="http://docs.python.org/library/threading.html" rel="nofollow">threading</a> module and its high-level interface is preferred. Of course, many people suggest that it's rarely/never necessary, and threads aren't very nice to deal with. The thread module may be necessary for some weird use-... | 8 | 2009-02-26T20:00:54Z | [
"python",
"multithreading"
] |
Fast way to determine if a PID exists on (Windows)? | 592,256 | <p>I realize "fast" is a bit subjective so I'll explain with some context. I'm working on a Python module called <a href="http://code.google.com/p/psutil/" rel="nofollow"><strong>psutil</strong></a> for reading process information in a cross-platform way. One of the functions is a <code>pid_exists(pid)</code> function ... | 8 | 2009-02-26T20:19:23Z | 592,449 | <p>There is an inherent race condition in the use of pid_exists function: by the time the calling program gets to use the answer, the process may have already disappeared, or a new process with the queried id may have been created. I would dare say that any application that uses this function is flawed by design and th... | 4 | 2009-02-26T21:08:02Z | [
"python",
"c",
"winapi",
"pid"
] |
Fast way to determine if a PID exists on (Windows)? | 592,256 | <p>I realize "fast" is a bit subjective so I'll explain with some context. I'm working on a Python module called <a href="http://code.google.com/p/psutil/" rel="nofollow"><strong>psutil</strong></a> for reading process information in a cross-platform way. One of the functions is a <code>pid_exists(pid)</code> function ... | 8 | 2009-02-26T20:19:23Z | 592,788 | <p><a href="http://msdn.microsoft.com/en-us/library/ms684320%28VS.85%29.aspx">OpenProcess</a> could tell you w/o enumerating all. I have no idea how fast.</p>
<p><strong>EDIT</strong>: note that you also need <code>GetExitCodeProcess</code> to verify the state of the process even if you get a handle from <code>OpenPro... | 8 | 2009-02-26T22:41:23Z | [
"python",
"c",
"winapi",
"pid"
] |
Fast way to determine if a PID exists on (Windows)? | 592,256 | <p>I realize "fast" is a bit subjective so I'll explain with some context. I'm working on a Python module called <a href="http://code.google.com/p/psutil/" rel="nofollow"><strong>psutil</strong></a> for reading process information in a cross-platform way. One of the functions is a <code>pid_exists(pid)</code> function ... | 8 | 2009-02-26T20:19:23Z | 600,217 | <p>Turns out that my benchmarks evidently were flawed somehow, as later testing reveals OpenProcess and GetExitCodeProcess are much faster than using EnumProcesses after all. I'm not sure what happened but I did some new tests and verified this is the faster solution: </p>
<pre><code>int pid_is_running(DWORD pid)
{
... | 3 | 2009-03-01T18:18:22Z | [
"python",
"c",
"winapi",
"pid"
] |
Fast way to determine if a PID exists on (Windows)? | 592,256 | <p>I realize "fast" is a bit subjective so I'll explain with some context. I'm working on a Python module called <a href="http://code.google.com/p/psutil/" rel="nofollow"><strong>psutil</strong></a> for reading process information in a cross-platform way. One of the functions is a <code>pid_exists(pid)</code> function ... | 8 | 2009-02-26T20:19:23Z | 609,020 | <p>I'd code Jay's last function this way.</p>
<pre><code>int pid_is_running(DWORD pid){
HANDLE hProcess;
DWORD exitCode;
//Special case for PID 0 System Idle Process
if (pid == 0) {
return 1;
}
//skip testing bogus PIDs
if (pid < 0) {
return 0;
}
hProcess = handle... | 3 | 2009-03-04T02:13:18Z | [
"python",
"c",
"winapi",
"pid"
] |
Any reasons not to use SQLObject over SQLAlchemy? | 592,332 | <p>I don't expect to need much more than basic CRUD type functionality. I know that SQLAlchemy is more flexible, but the syntax etc of sqlobject just seem to be a bit easier to get up and going with.</p>
| 13 | 2009-02-26T20:37:30Z | 592,348 | <p>I think SQLObject is more pythonic/simpler, so if it works for you, then stick with it.<br />
SQLAlchemy takes a little more to learn, but can do more advanced things if you need that.</p>
| 8 | 2009-02-26T20:41:48Z | [
"python",
"orm",
"sqlalchemy",
"sqlobject"
] |
Any reasons not to use SQLObject over SQLAlchemy? | 592,332 | <p>I don't expect to need much more than basic CRUD type functionality. I know that SQLAlchemy is more flexible, but the syntax etc of sqlobject just seem to be a bit easier to get up and going with.</p>
| 13 | 2009-02-26T20:37:30Z | 592,427 | <p>Also, you might wanna take a look at <a href="http://elixir.ematia.de/trac/wiki">elixir</a>, which is a fairly thick wrapper around SQLAlchemy and really makes the basic tasks easy while retaining the power of SQLA.</p>
| 6 | 2009-02-26T21:00:19Z | [
"python",
"orm",
"sqlalchemy",
"sqlobject"
] |
Any reasons not to use SQLObject over SQLAlchemy? | 592,332 | <p>I don't expect to need much more than basic CRUD type functionality. I know that SQLAlchemy is more flexible, but the syntax etc of sqlobject just seem to be a bit easier to get up and going with.</p>
| 13 | 2009-02-26T20:37:30Z | 11,271,218 | <p>Try quick_orm. It is as powerful as SQLAlchemy and simpler than SQLObject. </p>
<p><a href="https://github.com/tylerlong/quick_orm" rel="nofollow">https://github.com/tylerlong/quick_orm</a></p>
| 0 | 2012-06-30T03:41:30Z | [
"python",
"orm",
"sqlalchemy",
"sqlobject"
] |
PyQt4: Databinding? | 592,404 | <p>Coming from the .NET world over to Python and PyQt4. Was wondering if anyone is familiar with any functionality that would allow me to bind data to Qt widgets? For example (using sqlalchemy for data):</p>
<pre><code>gems = session.query(Gem).all()
list = QListWidget()
list.datasource = gems
</code></pre>
<p>Is suc... | 3 | 2009-02-26T20:55:38Z | 592,439 | <p>One option would have a function that returns a list (or tuple) object from a query, and then use that to update the QListWidget. Remember that the QListWidget stores QListStrings. Your update function might look like this:</p>
<pre><code>def updateQListWidget(qlistwidget, values):
""" Updates a QListWidg... | 3 | 2009-02-26T21:03:53Z | [
"python",
"data-binding",
"qt4",
"pyqt4"
] |
PyQt4: Databinding? | 592,404 | <p>Coming from the .NET world over to Python and PyQt4. Was wondering if anyone is familiar with any functionality that would allow me to bind data to Qt widgets? For example (using sqlalchemy for data):</p>
<pre><code>gems = session.query(Gem).all()
list = QListWidget()
list.datasource = gems
</code></pre>
<p>Is suc... | 3 | 2009-02-26T20:55:38Z | 592,785 | <p>Although not a direct replacement, you might find it useful to look at the QDataWidgetMapper class:</p>
<p><a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdatawidgetmapper.html" rel="nofollow">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdatawidgetmapper.html</a></p>
<p>If you'r... | 4 | 2009-02-26T22:40:32Z | [
"python",
"data-binding",
"qt4",
"pyqt4"
] |
Parsing an HTML file with selectorgadget.com | 592,910 | <p>How can I use beautiful soup and <a href="http://selectorgadget.com" rel="nofollow">selectorgadget</a> to scrape a website. For example I have a website - <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16819115017" rel="nofollow">(a newegg product)</a> and I would like my script to return all of the sp... | 3 | 2009-02-26T23:21:39Z | 592,986 | <p>Inspecting the page, I can see that the specifications are placed in a div with the ID pcraSpecs:</p>
<pre><code><div id="pcraSpecs">
<script type="text/javascript">...</script>
<TABLE cellpadding="0" cellspacing="0" class="specification">
<TR>
<TD colspan="2" class="t... | 1 | 2009-02-26T23:40:38Z | [
"python",
"css",
"screen-scraping",
"beautifulsoup",
"html-content-extraction"
] |
Parsing an HTML file with selectorgadget.com | 592,910 | <p>How can I use beautiful soup and <a href="http://selectorgadget.com" rel="nofollow">selectorgadget</a> to scrape a website. For example I have a website - <a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16819115017" rel="nofollow">(a newegg product)</a> and I would like my script to return all of the sp... | 3 | 2009-02-26T23:21:39Z | 593,345 | <p>Have you tried using Feedity - <a href="http://feedity.com" rel="nofollow">http://feedity.com</a> for creating a custom RSS feed from any webpage.</p>
| 0 | 2009-02-27T02:58:36Z | [
"python",
"css",
"screen-scraping",
"beautifulsoup",
"html-content-extraction"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 592,961 | <p>I think most uses of local static variables is to simulate generators, that is, having some function which performs some iteration of a process, returns the result, but mantains the state for the subsequent invocation. Python handles this very elegantly using the <code>yield</code> command, so it seems there is not... | 6 | 2009-02-26T23:35:18Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 592,971 | <p>It's a design choice.</p>
<p>I'm assuming Guido thinks you don't need them very often, and you never <em>really</em> need them: you can always just use a global variable and tell everyone to keep their greasy paws offa' your variable ;-)</p>
| 5 | 2009-02-26T23:37:37Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 593,046 | <p>The idea behind this omission is that static variables are only useful in two situations: when you really should be using a class and when you really should be using a generator.</p>
<p>If you want to attach stateful information to a function, what you need is a class. A trivially simple class, perhaps, but a clas... | 73 | 2009-02-27T00:04:02Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 593,098 | <p>The answer's pretty much the same as why nobody uses static methods (even though they exist). You have a module-level namespace that serves about the same purpose as a class would anyway.</p>
| 0 | 2009-02-27T00:28:54Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 593,154 | <p>For caching or <a href="http://code.activestate.com/recipes/52201/" rel="nofollow">memoization</a> purposes, decorators can be used as an elegant and general solution.</p>
| 4 | 2009-02-27T00:54:15Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 593,226 | <p>One alternative to a class is a function attribute:</p>
<pre><code>def foo(arg):
if not hasattr(foo, 'cache'):
foo.cache = get_data_dict()
return foo.cache[arg]
</code></pre>
<p>While a class is probably cleaner, this technique can be useful and is nicer, in my opinion, then a global. </p>
| 19 | 2009-02-27T01:41:57Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 593,477 | <p>An ill-advised alternative:</p>
<p>You can also use the side-effects of the definition time evaluation of function defaults:</p>
<pre><code>def func(initial=0, my_static=[])
if not my_static:
my_static.append(initial)
my_static[0] += 1
return my_static[0]
print func(0), func(0), func(0)
</code></pre>
... | 0 | 2009-02-27T04:04:02Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 594,760 | <p>From one of your comments: "I'd like to use them to cache things loaded from disk. I think it clutters the instance less, if I could assign them to the function"</p>
<p>Use a caching class then, as a class or instance attribute to your other class. That way, you can use the full feature set of classes without clutt... | -1 | 2009-02-27T13:34:45Z | [
"python"
] |
Why doesn't Python have static variables? | 592,931 | <p>There is a <a href="http://stackoverflow.com/questions/460586/simulating-a-local-static-variable-in-python">questions asking how to simulate static variables in python</a>.</p>
<p>Also, on the web one can find many different solutions to create static variables. (Though I haven't seen one that I like yet.)</p>
<p>... | 42 | 2009-02-26T23:28:09Z | 623,043 | <p>In Python 3, I would use a closure:</p>
<pre><code>def makefoo():
x = 0
def foo():
nonlocal x
x += 1
return x
return foo
foo = makefoo()
print(foo())
print(foo())
</code></pre>
| 8 | 2009-03-08T04:39:27Z | [
"python"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,694 | <p>Do the getting started guide to scipy?</p>
<p><a href="http://www.scipy.org/Getting%5FStarted" rel="nofollow">http://www.scipy.org/Getting_Started</a></p>
| 8 | 2009-02-27T06:13:05Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,705 | <p>Assuming that these students are new to programming (which is quite likely for math students), you'll want to give them a basic introduction to programming (what a function is, what a variable is, how each of these differ from functions and variables in math, etc).</p>
<p>Show them some example programs, with a vie... | 4 | 2009-02-27T06:16:45Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,708 | <p>I'm assuming this is for Freshmen (only because most higher level Math students will likely know how to program)? If so, do something that is fun and relevant. Go through the basics, but maybe walk them through the logic / basic framework for a Game (which are heavily math oriented) or Python-Based Graphing Calcul... | 0 | 2009-02-27T06:20:02Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,711 | <p>Python will work well, but GNU Octave may be better.</p>
| 0 | 2009-02-27T06:21:47Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,833 | <p>Sage: <a href="http://www.sagemath.org/" rel="nofollow">http://www.sagemath.org/</a></p>
| 7 | 2009-02-27T07:22:18Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,900 | <p>What should be content of my presentation ?</p>
<blockquote>
<p>The concept of <strong>functional programming</strong> with Python.
Some introduction to third party modules like <strong>NumPy</strong> and <strong>SciPy</strong>.</p>
</blockquote>
<p>What are good resources available ?</p>
<blockquote>
<p>Ha... | 0 | 2009-02-27T07:54:09Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,932 | <p>You are going to have to decide what you want to show them. If you want to show them how to using a computer can be a useful tool in mathematics show them sage and how you can perform numerical methods with it to get answers to hard questions. Then manipulate some algebraic formulas with it. Maybe show how it can... | 1 | 2009-02-27T08:10:34Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 593,973 | <p>I would recommend solving a few different kinds of problems from Project Euler in Python and having a discussion about the solutions, how they could have been done differently to be more efficient, etc. as part of the seminar. Python is a very elegant language for solving mathematical problems and should be one of t... | 1 | 2009-02-27T08:34:15Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 600,499 | <p><a href="http://www.sagemath.org" rel="nofollow">http://www.sagemath.org</a></p>
<p>In our wiki is a collection of talks, they may help you! <a href="http://wiki.sagemath.org/Talks" rel="nofollow">http://wiki.sagemath.org/Talks</a></p>
<p>Also be aware, that Sage contains NumPy, SciPy and SymPy. Therefore all info... | 0 | 2009-03-01T20:55:49Z | [
"python",
"math"
] |
Python for mathematics students? | 593,685 | <p>I need to deliver one and half hour seminar on programming for students at the department of mathematics. </p>
<p>I have chosen python as language.</p>
<ol>
<li>What should be content of my presentation ?</li>
<li>What are good resources available ?</li>
<li>What is necessity of programming for maths students?</l... | 7 | 2009-02-27T06:10:16Z | 641,395 | <p>I would bring up using Python as a free & open source option to replace/augment expensive packages like Matlab, IDL, etc via:</p>
<ul>
<li>scipy - fft's, </li>
<li>ipython - "shell"/debugger</li>
<li>matplotlib - 2d graphing</li>
<li>MayaVi - 3d graphing/visualization</li>
</ul>
<p><a href="http://www.archive.... | 2 | 2009-03-13T03:43:01Z | [
"python",
"math"
] |
How do I find images with a similar color using Python and PIL? | 593,925 | <p>I have a lot of images in a folder, and I would like to find images with a similar color to a pre chosen image.</p>
<p>I would like to be able to do something like: </p>
<pre><code>python find_similar.py sample.jpg
</code></pre>
<p>and have that return something like:</p>
<pre><code>234324.jpg
55.jpg
9945.jpg
34... | 3 | 2009-02-27T08:07:21Z | 593,936 | <p>The algorithm for finding similar images is discussed in a <a href="http://stackoverflow.com/questions/75891/algorithm-for-finding-similar-images">Question on Stackoverflow</a>, you might want to implement one of those in Python & PIL.</p>
<p>Also, you can straightaway use the <code>ImageChops</code> module fro... | 1 | 2009-02-27T08:13:04Z | [
"python",
"image-processing",
"python-imaging-library"
] |
How do I find images with a similar color using Python and PIL? | 593,925 | <p>I have a lot of images in a folder, and I would like to find images with a similar color to a pre chosen image.</p>
<p>I would like to be able to do something like: </p>
<pre><code>python find_similar.py sample.jpg
</code></pre>
<p>and have that return something like:</p>
<pre><code>234324.jpg
55.jpg
9945.jpg
34... | 3 | 2009-02-27T08:07:21Z | 593,958 | <p>I cannot give you a canned solution, but here's an angle to tackle the problem. It's not PIL-specific, and it might be entirely bogus, since I have no experience in image processing.</p>
<ol>
<li><p>Perform <a href="http://en.wikipedia.org/wiki/Color%5Fquantization" rel="nofollow">color quantization</a> on the imag... | 4 | 2009-02-27T08:23:06Z | [
"python",
"image-processing",
"python-imaging-library"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 594,292 | <p><a href="http://www.sagemath.org/index.html" rel="nofollow">Sage</a> is intended as matlab replacement and in <a href="http://www.sagemath.org/help-video.html" rel="nofollow">intro videos</a> it's demonstrated how similar to yours cases are handled. They seem to be supporting a wide range of approaches. Since the co... | 0 | 2009-02-27T10:50:39Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 594,294 | <pre><code> f = parser.parse('sin(x)*x^2').to_pyfunc()
</code></pre>
<p>Where <code>parser</code> could be defined using PLY, pyparsing, builtin tokenizer, parser, ast.</p>
<p>Don't use <code>eval</code> on user input.</p>
| 9 | 2009-02-27T10:51:37Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 594,360 | <p>Python's own internal compiler can parse this, if you use Python notation.</p>
<p>If your change the notation slightly, you'll be happier.</p>
<pre><code>import compiler
eq= "sin(x)*x**2"
ast= compiler.parse( eq )
</code></pre>
<p>You get an abstract syntax tree that you can work with.</p>
| 37 | 2009-02-27T11:12:34Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 594,457 | <p>To emphasize J.F. Sebastian's advice, 'eval' and even the 'compiler' solutions can be open to subtle security holes. How trustworthy is the input? With 'compiler' you can at least filter out things like getattr lookups from the AST, but I've found it's easier to use PLY or pyparsing for this sort of thing than it is... | 2 | 2009-02-27T11:57:10Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 2,537,560 | <p>In agreement with vartec. I would use SymPy - in particular the lambdify function should do exactly what you want.</p>
<p>See: <a href="http://showmedo.com/videotutorials/video?name=7200080&fromSeriesID=720" rel="nofollow">http://showmedo.com/videotutorials/video?name=7200080&fromSeriesID=720</a></p>
<p>fo... | 0 | 2010-03-29T11:44:17Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 2,537,691 | <p>pyparsing might do what you want (http://pyparsing.wikispaces.com/) especially if the strings are from an untrusted source.</p>
<p>See also <a href="http://pyparsing.wikispaces.com/file/view/fourFn.py">http://pyparsing.wikispaces.com/file/view/fourFn.py</a> for a fairly full-featured calculator built with it.</p>
| 7 | 2010-03-29T12:11:39Z | [
"python",
"parsing",
"equation"
] |
Equation parsing in Python | 594,266 | <p>How can I (easily) take a string such as <code>"sin(x)*x^2"</code> which might be entered by a user at runtime and produce a Python function that could be evaluated for any value of <code>x</code>? </p>
| 26 | 2009-02-27T10:42:07Z | 5,936,822 | <p>You can use Python <code>parser</code>:</p>
<pre><code>import parser
formula = "sin(x)*x**2"
code = parser.expr(formula).compile()
from math import sin
x = 10
print eval(code)
</code></pre>
<p>It performs better than pure <code>eval</code>.</p>
| 18 | 2011-05-09T12:23:11Z | [
"python",
"parsing",
"equation"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,532 | <p>In the first example I would certainly stick with the if-else statement. In fact I don't see a reason not to use if-else unless</p>
<ol>
<li><p>You find (using e.g. the profile module) that the if statement is a bottleneck (very unlikely IMO unless you have a huge number of cases that do very little)</p></li>
<li><... | 8 | 2009-02-27T12:21:10Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,539 | <p>Each of the exposed options fit well some scenarios:</p>
<ol>
<li>if-elif-else: simplicity, clarity</li>
<li>dictionary: useful when you configure it dynamically (imagine that you need a particular functionality to be executed on a branch)</li>
<li>tuple: simplicity over if-else case for multiple choices per branch... | 1 | 2009-02-27T12:23:10Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,547 | <p>I agree with df regarding the second example. The first example I would probably try to rewrite using a dictionary, particularly if all the curve constructors have the same type signature (perhaps using *args and/or **kwargs). Something like</p>
<pre><code>def _setCurrentCurve(self, new_curve):
self.currentCurv... | 1 | 2009-02-27T12:27:03Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,550 | <p>Considering that this is done in response to a user action (pickings something from a menu), and the number of choices you anticipate is very small, I'd definitely go with a simple if-elif-else ladder.</p>
<p>There's no point in optinizing for speed, since it only happens as fast as the user can make the selection ... | 2 | 2009-02-27T12:27:13Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,574 | <p>Regarding your dictionary questions:</p>
<blockquote>
<p>As far as I know, the reasons for choosing a dict is for fast lookup. When is that warranted? when I have 100 cases or more? Is it a good idea to keep building and throwing away a dictionary each time the function is called? If I build a dict for this purpo... | 2 | 2009-02-27T12:35:44Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,622 | <p>Sigh. Too much hand-wringing over the wrong part of the problem. The switch statement is not the issue. There are many ways of expressing "alternative" that don't add <strong>meaning</strong>.</p>
<p>The issue is <strong>meaning</strong> -- not technical statement choices. </p>
<p>There are three common pattern... | 22 | 2009-02-27T12:51:21Z | [
"python",
"switch-statement"
] |
Choosing between different switch-case replacements in Python - dictionary or if-elif-else? | 594,442 | <p>I recently read the questions that recommend against using switch-case statements in languages that do support it. As far as Python goes, I've seen a number of switch case replacements, such as: </p>
<ol>
<li>Using a dictionary (Many variants) </li>
<li>Using a Tuple </li>
<li>Using a function decorator (<a href... | 15 | 2009-02-27T11:47:51Z | 594,707 | <p>In Python, don't event think about how to replace a switch statement.</p>
<p>Use classes and polymorphism instead. Try to keep the information about each availble choice and how to implement it in one place (i.e. the class that implements it).</p>
<p>Otherwise you will end up having lots of places that each contai... | 1 | 2009-02-27T13:23:21Z | [
"python",
"switch-statement"
] |
Email body is a string sometimes and a list sometimes. Why? | 594,545 | <p>My application is written in python. What I am doing is I am running a script on each email received by postfix and do something with the email content. Procmail is responsible for running the script taking the email as input. The problem started when I was converting the input message(may be text) to email_message ... | 7 | 2009-02-27T12:24:39Z | 594,559 | <p>It might be <a href="http://en.wikipedia.org/wiki/MIME#Multipart%5Fmessages" rel="nofollow">MIME multipart</a> </p>
<p>See <a href="http://docs.python.org/library/email.parser.html#additional-notes" rel="nofollow">http://docs.python.org/library/email.parser.html#additional-notes</a></p>
| 0 | 2009-02-27T12:30:42Z | [
"python",
"email",
"message",
"payload"
] |
Email body is a string sometimes and a list sometimes. Why? | 594,545 | <p>My application is written in python. What I am doing is I am running a script on each email received by postfix and do something with the email content. Procmail is responsible for running the script taking the email as input. The problem started when I was converting the input message(may be text) to email_message ... | 7 | 2009-02-27T12:24:39Z | 594,566 | <p>As crazy as it might seem, the reason for the sometimes string, sometimes list-semantics are <a href="http://docs.python.org/library/email.parser.html#email.message%5Ffrom%5Fstring">given in the documentation</a>. Basically, multipart messages are returned as lists.</p>
| 10 | 2009-02-27T12:31:24Z | [
"python",
"email",
"message",
"payload"
] |
Email body is a string sometimes and a list sometimes. Why? | 594,545 | <p>My application is written in python. What I am doing is I am running a script on each email received by postfix and do something with the email content. Procmail is responsible for running the script taking the email as input. The problem started when I was converting the input message(may be text) to email_message ... | 7 | 2009-02-27T12:24:39Z | 594,633 | <p>Well, the answers are correct, you should read the docs, but for an example of a generic way:</p>
<pre><code>def get_first_text_part(msg):
maintype = msg.get_content_maintype()
if maintype == 'multipart':
for part in msg.get_payload():
if part.get_content_maintype() == 'text':
... | 11 | 2009-02-27T12:53:42Z | [
"python",
"email",
"message",
"payload"
] |
Email body is a string sometimes and a list sometimes. Why? | 594,545 | <p>My application is written in python. What I am doing is I am running a script on each email received by postfix and do something with the email content. Procmail is responsible for running the script taking the email as input. The problem started when I was converting the input message(may be text) to email_message ... | 7 | 2009-02-27T12:24:39Z | 3,543,831 | <p>Rather than simply looking for a sub-part, use walk() to iterate through the message contents</p>
<pre><code>def walkMsg(msg):
for part in msg.walk():
if part.get_content_type() == "multipart/alternative":
continue
yield part.get_payload(decode=1)
</code></pre>
<p>The walk() method returns an itera... | 8 | 2010-08-22T23:04:49Z | [
"python",
"email",
"message",
"payload"
] |
Make a python property with the same name as the class member name | 594,856 | <p>Is it possible in python to create a property with the same name as the member variable name of the class. e.g.</p>
<pre><code>Class X:
...
self.i = 10 # marker
...
property(fget = get_i, fset = set_i)
</code></pre>
<p>Please tell me how I can do so. Because if I do so, for the statement at marker ... | 5 | 2009-02-27T13:58:53Z | 594,892 | <blockquote>
<p>Is it possible in python to create a property with the same name as the member variable name</p>
</blockquote>
<p>No. properties, members and methods all share the same namespace.</p>
<blockquote>
<p>the statement at marker I get stack overflow</p>
</blockquote>
<p>Clearly. You try to set i, whic... | 17 | 2009-02-27T14:09:00Z | [
"python"
] |
How to load an RSA key from a PEM file and use it in python-crypto | 595,114 | <p>I have not found a way to load an RSA private key from a PEM file to use it in python-crypto (signature).</p>
<p>python-openssl can load a PEM file but the PKey object can't be used to retrieved key information (p, q, ...) to use with Crypto.PublicKey.construct().</p>
| 8 | 2009-02-27T15:01:59Z | 595,150 | <p>is this (close to) what you tried doing?</p>
<pre><code>public_key_filename = 'public_key.pem'
rsa = M2Crypto.RSA.load_pub_key(pk)
</code></pre>
<p>That should work. The issue might be with openssl too, does it work when you just use openssl (not in Python)?</p>
<p><a href="http://chandlerproject.org/bin/view/Pr... | 5 | 2009-02-27T15:12:02Z | [
"python",
"cryptography"
] |
How to load an RSA key from a PEM file and use it in python-crypto | 595,114 | <p>I have not found a way to load an RSA private key from a PEM file to use it in python-crypto (signature).</p>
<p>python-openssl can load a PEM file but the PKey object can't be used to retrieved key information (p, q, ...) to use with Crypto.PublicKey.construct().</p>
| 8 | 2009-02-27T15:01:59Z | 606,702 | <p>I recommend M2Crypto instead of python-crypto. You will need M2Crypto to parse PEM anyway and its EVP api frees your code from depending on a particular algorithm.</p>
<pre><code>private = """
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBANQNY7RD9BarYRsmMazM1hd7a+u3QeMPFZQ7Ic+BmmeWHvvVP4Yj
yu1t6vAut7mKkaDeKbT3yiGVUg... | 11 | 2009-03-03T14:57:27Z | [
"python",
"cryptography"
] |
Does PyS60 has a reliable garbage collection? | 595,290 | <p>I have heard it many times that garbage collection in PyS60 is not up to to the mark. This imposes a lot of limits on writing cleaner code. Can I at least rely that the non cyclic references are cleaned up after a function exists.</p>
| 3 | 2009-02-27T15:46:32Z | 595,300 | <p>PyS60 as of version 1.9.0 uses Python 2.5.1 core and has no problems with garbage collection.</p>
| 3 | 2009-02-27T15:49:30Z | [
"python",
"symbian",
"nokia",
"s60",
"pys60"
] |
Does PyS60 has a reliable garbage collection? | 595,290 | <p>I have heard it many times that garbage collection in PyS60 is not up to to the mark. This imposes a lot of limits on writing cleaner code. Can I at least rely that the non cyclic references are cleaned up after a function exists.</p>
| 3 | 2009-02-27T15:46:32Z | 915,114 | <p>Mostly you can, but occasionally PyS60 needs a little "help". Unbind keys, always cancel timers, might have to manually delete some classes etc. Nothing too bad.</p>
<p>Btw current 1.9.x branch uses python core 2.5.4. In my opinion 1.9.5 is the first version, which might be better that 1.4.5. Worth taking a look, e... | 0 | 2009-05-27T10:55:12Z | [
"python",
"symbian",
"nokia",
"s60",
"pys60"
] |
Does the stack limit of Symbian also apply to PyS60? | 595,296 | <p>Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?</p>
| 3 | 2009-02-27T15:48:37Z | 595,330 | <p>Yes, PyS60 is based on CPython, thus uses the C stack.</p>
| 3 | 2009-02-27T15:54:53Z | [
"python",
"symbian",
"nokia",
"pys60"
] |
Does the stack limit of Symbian also apply to PyS60? | 595,296 | <p>Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?</p>
| 3 | 2009-02-27T15:48:37Z | 606,180 | <p>Increasing the Symbian stack size is done through a parameter in the mmp file.
This is valid when you create a native application that the toolchain will turn into an exe file.</p>
<p>If you were to upgrade the Python runtime on your phone, with a version you built yourself, you could increase the stack size of the... | 1 | 2009-03-03T12:18:20Z | [
"python",
"symbian",
"nokia",
"pys60"
] |
Does the stack limit of Symbian also apply to PyS60? | 595,296 | <p>Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?</p>
| 3 | 2009-02-27T15:48:37Z | 685,145 | <p>I would assume that PyS60 should be doing the memory management for you, as your program will probably be constrained by the resources of PyS60.</p>
| 0 | 2009-03-26T10:04:26Z | [
"python",
"symbian",
"nokia",
"pys60"
] |
Does the stack limit of Symbian also apply to PyS60? | 595,296 | <p>Symbian has a stack limit of 8kB. Does this also apply to the function calling in PyS60 apps?</p>
| 3 | 2009-02-27T15:48:37Z | 915,134 | <p>There is a difference between python runtime and python apps. Also from PyS60 app developer point of view, it's the heapsize that's more interesting...</p>
<p>Version 1.9.5 comes by default with heapsize 100k min and 4M max. Of course you can define those by yourself when creating the SIS package to release and dis... | 1 | 2009-05-27T11:03:01Z | [
"python",
"symbian",
"nokia",
"pys60"
] |
What's the Python function like sum() but for multiplication? product()? | 595,374 | <p>Python's <a href="http://docs.python.org/library/functions.html#sum"><code>sum()</code></a> function returns the sum of numbers in an iterable.</p>
<pre><code>sum([3,4,5]) == 3 + 4 + 5 == 12
</code></pre>
<p>I'm looking for the function that returns the product instead.</p>
<pre><code>somelib.somefunc([3,4,5]) ==... | 91 | 2009-02-27T16:06:36Z | 595,384 | <pre><code>Numeric.product
</code></pre>
<p>( or </p>
<pre><code>reduce(lambda x,y:x*y,[3,4,5])
</code></pre>
<p>)</p>
| 16 | 2009-02-27T16:09:09Z | [
"python",
"builtin",
"pep"
] |
What's the Python function like sum() but for multiplication? product()? | 595,374 | <p>Python's <a href="http://docs.python.org/library/functions.html#sum"><code>sum()</code></a> function returns the sum of numbers in an iterable.</p>
<pre><code>sum([3,4,5]) == 3 + 4 + 5 == 12
</code></pre>
<p>I'm looking for the function that returns the product instead.</p>
<pre><code>somelib.somefunc([3,4,5]) ==... | 91 | 2009-02-27T16:06:36Z | 595,391 | <p>Use this</p>
<pre><code>def prod( iterable ):
p= 1
for n in iterable:
p *= n
return p
</code></pre>
<p>Since there's no built-in <code>prod</code> function.</p>
| 12 | 2009-02-27T16:10:46Z | [
"python",
"builtin",
"pep"
] |
What's the Python function like sum() but for multiplication? product()? | 595,374 | <p>Python's <a href="http://docs.python.org/library/functions.html#sum"><code>sum()</code></a> function returns the sum of numbers in an iterable.</p>
<pre><code>sum([3,4,5]) == 3 + 4 + 5 == 12
</code></pre>
<p>I'm looking for the function that returns the product instead.</p>
<pre><code>somelib.somefunc([3,4,5]) ==... | 91 | 2009-02-27T16:06:36Z | 595,396 | <p>There isn't one built in, but it's simple to roll your own, as demonstrated <a href="http://stackoverflow.com/questions/493853/which-python-module-is-suitable-for-data-manipulation-in-a-list/494034#494034">here</a>:</p>
<pre><code>import operator
def prod(factors):
return reduce(operator.mul, factors, 1)
</code... | 38 | 2009-02-27T16:11:54Z | [
"python",
"builtin",
"pep"
] |
What's the Python function like sum() but for multiplication? product()? | 595,374 | <p>Python's <a href="http://docs.python.org/library/functions.html#sum"><code>sum()</code></a> function returns the sum of numbers in an iterable.</p>
<pre><code>sum([3,4,5]) == 3 + 4 + 5 == 12
</code></pre>
<p>I'm looking for the function that returns the product instead.</p>
<pre><code>somelib.somefunc([3,4,5]) ==... | 91 | 2009-02-27T16:06:36Z | 595,409 | <p>Actually, Guido vetoed the idea: <a href="http://bugs.python.org/issue1093">http://bugs.python.org/issue1093</a></p>
<p>But, as noted in that issue, you can make one pretty easily:</p>
<pre><code>from functools import reduce # Valid in Python 2.6+, required in Python 3
import operator
reduce(operator.mul, (3, 4, ... | 141 | 2009-02-27T16:13:48Z | [
"python",
"builtin",
"pep"
] |
What's the Python function like sum() but for multiplication? product()? | 595,374 | <p>Python's <a href="http://docs.python.org/library/functions.html#sum"><code>sum()</code></a> function returns the sum of numbers in an iterable.</p>
<pre><code>sum([3,4,5]) == 3 + 4 + 5 == 12
</code></pre>
<p>I'm looking for the function that returns the product instead.</p>
<pre><code>somelib.somefunc([3,4,5]) ==... | 91 | 2009-02-27T16:06:36Z | 6,364,663 | <p>There's a <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.prod.html"><code>prod()</code></a> in numpy that does what you're asking for.</p>
| 20 | 2011-06-15T21:33:14Z | [
"python",
"builtin",
"pep"
] |
wxPython toolbar help | 596,190 | <p>I am new to Python. I am writing an application using wxPython and I currently my code that generates a toolbar looks like this:</p>
<pre><code>class Window(wx.Frame)
def __init__(self, parent, plot):
wx.Frame.__init__(self, parent, wx.ID_ANY, "Name", size =(900, 600))
self.Centre()
self.toolbar = self... | 0 | 2009-02-27T19:13:08Z | 596,340 | <p>Instead of a class that sets up your toolbar, use a function. The function can be a member function of your Window that subclasses wx.Frame. That way, the toolbar will get Created from the correct window, and be attached the way you would expect.</p>
<p>The class that you're writing above would work, if it knew ... | 3 | 2009-02-27T19:52:14Z | [
"python",
"user-interface",
"wxpython",
"toolbars"
] |
wxPython toolbar help | 596,190 | <p>I am new to Python. I am writing an application using wxPython and I currently my code that generates a toolbar looks like this:</p>
<pre><code>class Window(wx.Frame)
def __init__(self, parent, plot):
wx.Frame.__init__(self, parent, wx.ID_ANY, "Name", size =(900, 600))
self.Centre()
self.toolbar = self... | 0 | 2009-02-27T19:13:08Z | 598,126 | <p>Yes. Break your wxpython code into objects like this. It is much easier to maintain if you are going to code your GUI by hand (I do).</p>
<p>You need to subclass <a href="http://wxpython.org/docs/api/wx.ToolBar-class.html" rel="nofollow">wx.ToolBar</a> (which itself is a subclass of <a href="http://wxpython.org/d... | 1 | 2009-02-28T15:04:55Z | [
"python",
"user-interface",
"wxpython",
"toolbars"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,762 | <p>For what it's worth, I wrote my website in mod_python without any intervening framework like Django. I didn't really have any reason to complain. (Well maybe a little, mod_python is kind of quirky in a few ways but not in the common use cases) One thing's for sure, it will definitely let you write Python ;-)</p>
| 3 | 2009-02-27T21:33:33Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,807 | <p>The way to go is <a href="http://wsgi.org">wsgi</a>.</p>
<p>WSGI is the <strong>Web Server Gateway Interface</strong>. It is a specification for web servers and application servers to communicate with web applications (though it can also be used for more than that). <strong>It is a Python standard, described in det... | 36 | 2009-02-27T21:45:58Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,811 | <p>You could also check <a href="http://cherrypy.org" rel="nofollow">cherrypy</a>. The focus of cherrypy is in being a framework that lets you write python. Cherrypy has its own pretty good webserver, but it is wsgi-compatible so you can run cherrypy applications in apache via mod_wsgi. Here is hello world in cherrypy:... | 9 | 2009-02-27T21:46:50Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,845 | <p>What's wrong with Django? It doesn't force you to use it's ORM and controllers are just plain Python functions instead of Rails-like class methods. Also, url routing is done with regular expressions instead of another framework-invented syntax. If django seems like too much for you anyway, i recommend taking a look ... | 0 | 2009-02-27T21:56:26Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,877 | <p>It's hilarious how, even prompted with a question asking how to write without a framework, everyone still piles in to promote their favourite framework. The OP whinges about not wanting a âheavyweight frameworkâ, and the replies mention <em>Twisted</em>, of all things?! Come now, really.</p>
<p>Yes, it <em>is</... | 18 | 2009-02-27T22:11:40Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,884 | <p>I'm pretty fond of Google AppEngine. I use the ORM and templating system, but otherwise follow a REST-patterned design and just implement Python methods for the corresponding HTTP ones. It makes the raw HTTP interaction central, and optionally gives you other things to use. Plus no more configuring and managing y... | 0 | 2009-02-27T22:14:37Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,890 | <p>I've written a few small web applications using mod-python and <a href="http://www.math.temple.edu/doc/packages/apache2-mod_python/doc-html/pyapi-psp.html" rel="nofollow">PSP</a> -- mod-python's equivalent to php.</p>
<p>In one case, I wrote a web page that generates release notes by inspecting our source code repo... | 1 | 2009-02-27T22:16:44Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,910 | <p>+1 to all the answers with WSGI.</p>
<p>Eric Florenzo wrote a great blog post lately you should read: <a href="http://www.eflorenzano.com/blog/post/writing-blazing-fast-infinitely-scalable-pure-wsgi/">Writing Blazing Fast, Infinitely Scalable, Pure-WSGI Utilities</a>. This will give you a better idea of pure WSGI ... | 8 | 2009-02-27T22:23:49Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 596,988 | <p>I think it depends on the definition of what a framework is and what it should do for you.</p>
<p>As pointed out, a very minimal "framework" would be WSGI as it only defines one small interface for interfacing with a web server. But it's a powerful approach because of the middleware you can put between your app and... | 1 | 2009-02-27T22:53:00Z | [
"python",
"performance",
"web.py"
] |
How do I use python for web development without relying on a framework? | 596,729 | <p>I know the various frameworks have their benefits, but I personally want my web development in python to be as straight-forward as possible: less writing to the framework, more writing <em>python</em>.</p>
<p>The only thing I have found so far that lets me do this in the most obvious way possible is <a href="http:/... | 28 | 2009-02-27T21:20:50Z | 7,968,503 | <p>Why do you have concerns about web.py's performance? As I mentioned <a href="http://stackoverflow.com/questions/7788149/web-py-deployment-for-ios-app-backend/7853705#7853705">here</a>, we use <a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> (the web server "built into" web.py) behind <a href="http://ng... | 2 | 2011-11-01T15:09:09Z | [
"python",
"performance",
"web.py"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 596,899 | <p>Your file is <code>jargon</code>, not <code>jargonFile</code> (a string). That's probably what's causing your error message. You'll also need a second loop to read each line of the file from the beginning until you find the word you're looking for. Your code currently stops searching if the word is not found in t... | 1 | 2009-02-27T22:20:13Z | [
"python",
"file",
"readline"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 596,901 | <p>First you open the file and read it into a string with readline(). Later on you try to readline() from the string you obtained in the first step.</p>
<p>You need to take care what object (thing) you're handling: open() gave you a file "jargon", readline on jargon gave you the string "jargonFile".</p>
<p>So jargonF... | 3 | 2009-02-27T22:21:22Z | [
"python",
"file",
"readline"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 596,927 | <p>Everytime you enter a search phrase, it looks for it on the <strong>next</strong> line, not the first one. You need to re-open the file for every search phrase, if you want it behave like you describe. </p>
| 1 | 2009-02-27T22:31:55Z | [
"python",
"file",
"readline"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 596,932 | <p>Take a look at the documentation for File objects:</p>
<p><a href="http://docs.python.org/library/stdtypes.html#file-objects" rel="nofollow">http://docs.python.org/library/stdtypes.html#file-objects</a></p>
<p>You might be interested in the <code>readlines</code> method. For a simple case where your file is not e... | 1 | 2009-02-27T22:33:56Z | [
"python",
"file",
"readline"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 597,178 | <p>Hmm, I don't know anything at all about Python, but it looks to me like you are not iterating through all the lines of the file for the search string entered.</p>
<p>Typically, you need to do something like this:</p>
<pre><code>enter search string
open file
if file has data
start loop
get next line of file... | 2 | 2009-02-28T00:21:41Z | [
"python",
"file",
"readline"
] |
AttributeError: 'str' object has no attribute 'readline' | 596,886 | <p><strong>Update: My current question is how can I get my code to read to the EOF starting from the beginning with each new search phrase.</strong></p>
<p>This is an assignment I am doing and currently stuck on. Mind you this is a beginner's programming class using Python.</p>
<pre><code>jargon = open("jargonFile.tx... | 4 | 2009-02-27T22:15:25Z | 598,010 | <p>you shouldn't try to re-invent the wheel. just use the
<a href="http://docs.python.org/3.0/library/re.html?highlight=findall#re.findall" rel="nofollow">re module functions</a>.
your program could work better if you used:
result = jargon.read() .
instead of:
result = jargon.readline() .
then you could use the re.find... | 2 | 2009-02-28T13:14:32Z | [
"python",
"file",
"readline"
] |
xml.dom.minidom: Getting CDATA values | 597,058 | <p>I'm able to get the value in the image tag (see XML below), but not the Category tag. The difference is one is a CDATA section and the other is just a string. Any help would be appreciated.</p>
<pre><code>from xml.dom import minidom
xml = """<?xml version="1.0" ?>
<ProductData>
<ITEM Id="047119... | 10 | 2009-02-27T23:20:56Z | 597,107 | <blockquote>
<p>p.getElementsByTagName('Category')[0].firstChild</p>
</blockquote>
<p>minidom does not flatten away <![CDATA[ sections to plain text, it leaves them as DOM CDATASection nodes. (Arguably it should, at least optionally. DOM Level 3 LS defaults to flattening them, for what it's worth, but minidom is ... | 21 | 2009-02-27T23:40:50Z | [
"python",
"xml"
] |
xml.dom.minidom: Getting CDATA values | 597,058 | <p>I'm able to get the value in the image tag (see XML below), but not the Category tag. The difference is one is a CDATA section and the other is just a string. Any help would be appreciated.</p>
<pre><code>from xml.dom import minidom
xml = """<?xml version="1.0" ?>
<ProductData>
<ITEM Id="047119... | 10 | 2009-02-27T23:20:56Z | 597,111 | <p>CDATA is its own node, so the Category elements here actually have three children, a whitespace text node, the CDATA node, and another whitespace node. You're just looking at the wrong one, is all. I don't see any more obvious way to query for the CDATA node, but you can pull it out like this:</p>
<pre><code>[n for... | 6 | 2009-02-27T23:44:06Z | [
"python",
"xml"
] |
xml.dom.minidom: Getting CDATA values | 597,058 | <p>I'm able to get the value in the image tag (see XML below), but not the Category tag. The difference is one is a CDATA section and the other is just a string. Any help would be appreciated.</p>
<pre><code>from xml.dom import minidom
xml = """<?xml version="1.0" ?>
<ProductData>
<ITEM Id="047119... | 10 | 2009-02-27T23:20:56Z | 30,481,821 | <p>I've ran into a similar problem. My solution was similar to what ironfroggy answered, but implemented in a more general fashion:</p>
<pre><code>for node in parentNode.childNodes:
if node.nodeType == 4:
cdataContent = node.data.strip()
</code></pre>
<p>CDATA's node type is 4 (<a href="https://de... | 2 | 2015-05-27T12:00:47Z | [
"python",
"xml"
] |
Converting an object into a subclass in Python? | 597,199 | <p>Lets say I have a library function that I cannot change that produces an object of class A, and I have created a class B that inherits from A. </p>
<p>What is the most straightforward way of using the library function to produce an object of class B?</p>
<p>edit- I was asked in a comment for more detail, so here g... | 14 | 2009-02-28T00:34:11Z | 597,243 | <p>Since the library function returns an A, you can't make it return a B without changing it.</p>
<p>One thing you can do is write a function to take the fields of the A instance and copy them over into a new B instance:</p>
<pre><code>class A: # defined by the library
def __init__(self, field):
self.fiel... | 11 | 2009-02-28T00:57:05Z | [
"python"
] |
Converting an object into a subclass in Python? | 597,199 | <p>Lets say I have a library function that I cannot change that produces an object of class A, and I have created a class B that inherits from A. </p>
<p>What is the most straightforward way of using the library function to produce an object of class B?</p>
<p>edit- I was asked in a comment for more detail, so here g... | 14 | 2009-02-28T00:34:11Z | 597,249 | <p>Monkeypatch the library?</p>
<p>For example,</p>
<pre><code>import other_library
other_library.function_or_class_to_replace = new_function
</code></pre>
<p>Poof, it returns whatever you want it to return.</p>
<p>Monkeypatch A.<strong>new</strong> to return an instance of B?</p>
<p>After you call obj = A(), chan... | 1 | 2009-02-28T00:59:08Z | [
"python"
] |
Converting an object into a subclass in Python? | 597,199 | <p>Lets say I have a library function that I cannot change that produces an object of class A, and I have created a class B that inherits from A. </p>
<p>What is the most straightforward way of using the library function to produce an object of class B?</p>
<p>edit- I was asked in a comment for more detail, so here g... | 14 | 2009-02-28T00:34:11Z | 597,324 | <p>This can be done if the initializer of the subclass can handle it, or you write an explicit upgrader. Here is an example:</p>
<pre><code>class A(object):
def __init__(self):
self.x = 1
class B(A):
def __init__(self):
super(B, self).__init__()
self._init_B()
def _init_B(self):
... | 13 | 2009-02-28T01:40:07Z | [
"python"
] |
Converting an object into a subclass in Python? | 597,199 | <p>Lets say I have a library function that I cannot change that produces an object of class A, and I have created a class B that inherits from A. </p>
<p>What is the most straightforward way of using the library function to produce an object of class B?</p>
<p>edit- I was asked in a comment for more detail, so here g... | 14 | 2009-02-28T00:34:11Z | 29,256,784 | <p>you can actually change the <code>.__class__</code> attribute of the object <em>if you know what you're doing</em>:</p>
<pre class="lang-py prettyprint-override"><code>In [1]: class A(object):
...: def foo(self):
...: return "foo"
...:
In [2]: class B(object):
...: def foo(self):
...... | 2 | 2015-03-25T13:16:41Z | [
"python"
] |
Python: Getting an IPv6 socket to receive packets destined for the Subnet-Routers Anycast address | 597,225 | <p>How do you get a socket to receive packets destined for the IPv6 Subnet-Routers Anycast address?</p>
<p>I haven't been able to find any informationn on how to do this.</p>
<p>In a fit of desparation, I've tried using socket.setsockopt as you would to join a multicast group:</p>
<pre><code># 7 is the interface num... | 5 | 2009-02-28T00:45:31Z | 606,511 | <p>Instead of <code>IPV6_JOIN_GROUP</code>, try passing <code>IPV6_JOIN_ANYCAST</code> to your <code>s.setsockopt()</code> code. Unfortunately the Python <code>socket</code> module doesn't define it but you should be able to pass the integer equivalent instead. In Linux <a href="http://lxr.linux.no/linux%2Bv2.6.28.7/in... | 2 | 2009-03-03T14:11:59Z | [
"python",
"networking",
"ipv6"
] |
Python: Getting an IPv6 socket to receive packets destined for the Subnet-Routers Anycast address | 597,225 | <p>How do you get a socket to receive packets destined for the IPv6 Subnet-Routers Anycast address?</p>
<p>I haven't been able to find any informationn on how to do this.</p>
<p>In a fit of desparation, I've tried using socket.setsockopt as you would to join a multicast group:</p>
<pre><code># 7 is the interface num... | 5 | 2009-02-28T00:45:31Z | 918,381 | <p>The <code>IPV6_JOIN_ANYCAST</code> and <code>IPV6_LEAVE_ANYCAST</code> socket options are non-standard Linux-isms.</p>
<p>If you'd like your code to be <em>portable</em>, then you should probably do it the standard way, i.e. assign the subnet routers anycast address to the appropriate interface, then bind your sock... | 0 | 2009-05-27T23:00:50Z | [
"python",
"networking",
"ipv6"
] |
Python: efficiently join chunks of bytes into one big chunk? | 597,289 | <p>I'm trying to jury-rig the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134" rel="nofollow">Amazon S3 python library</a> to allow chunked handling of large files. Right now it does a "self.body = http_response.read()", so if you have a 3G file you're going to read the entire thing in... | 1 | 2009-02-28T01:18:53Z | 597,296 | <p>In python3, <code>bytes</code> objects are distinct from <code>str</code>, but I don't know any reason why there would be anything wrong with this.</p>
| 0 | 2009-02-28T01:21:23Z | [
"python",
"amazon-s3"
] |
Python: efficiently join chunks of bytes into one big chunk? | 597,289 | <p>I'm trying to jury-rig the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134" rel="nofollow">Amazon S3 python library</a> to allow chunked handling of large files. Right now it does a "self.body = http_response.read()", so if you have a 3G file you're going to read the entire thing in... | 1 | 2009-02-28T01:18:53Z | 597,302 | <p><code>join</code> seems fine if you really do need to put the entire string together, but then you just wind up storing the whole thing in RAM anyway. In a situation like this, I would try to see if there's a way to process each part of the string and then discard the processed part, so you only need to hold a fixed... | 0 | 2009-02-28T01:24:43Z | [
"python",
"amazon-s3"
] |
Python: efficiently join chunks of bytes into one big chunk? | 597,289 | <p>I'm trying to jury-rig the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134" rel="nofollow">Amazon S3 python library</a> to allow chunked handling of large files. Right now it does a "self.body = http_response.read()", so if you have a 3G file you're going to read the entire thing in... | 1 | 2009-02-28T01:18:53Z | 597,304 | <p>''join() is the best method for joining chunks of data. The alternative boils down to repeated concatenation, which is O(n**2) due to the immutability of strings and the need to create more at every concatenation. Given, this repeated concatenation is optimized by recent versions of CPython if used with += to become... | 3 | 2009-02-28T01:24:44Z | [
"python",
"amazon-s3"
] |
Python: efficiently join chunks of bytes into one big chunk? | 597,289 | <p>I'm trying to jury-rig the <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=134" rel="nofollow">Amazon S3 python library</a> to allow chunked handling of large files. Right now it does a "self.body = http_response.read()", so if you have a 3G file you're going to read the entire thing in... | 1 | 2009-02-28T01:18:53Z | 597,338 | <p>hm - what problem are you trying to solve? I suspect the answer depends on what you are trying to do with the data.</p>
<p>Since in general you don't want a whole 3Gb file in memory, I'd not store the chunks in an array, but iterate over the http_response and write it straight to disk, in a temporary or persistent ... | 2 | 2009-02-28T01:52:52Z | [
"python",
"amazon-s3"
] |
FOSS HTML to PDF in Python, .Net or command line? | 597,348 | <p>I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good <strong>html to pdf converter</strong> that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking fo... | 0 | 2009-02-28T01:56:26Z | 597,355 | <p>I've wkhtmltopdf used on a couple of projects. <a href="http://code.google.com/p/wkhtmltopdf/" rel="nofollow">http://code.google.com/p/wkhtmltopdf/</a>. It uses the webkit rendering engine, which powers the Safari browser. You'll get completely up to date rendering just like a web browser with CSS and all.</p>
<p>O... | 5 | 2009-02-28T02:01:12Z | [
"c#",
".net",
"python",
"html-to-pdf"
] |
FOSS HTML to PDF in Python, .Net or command line? | 597,348 | <p>I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good <strong>html to pdf converter</strong> that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking fo... | 0 | 2009-02-28T01:56:26Z | 597,361 | <p>I haven't found a good FOSS solution, but I can say that <a href="http://www.princexml.com/" rel="nofollow">PrinceXML</a> works very well, provides quite a bit of functionality through the command-line and is priced very reasonably. IIRC, the free version appends a cover page to each PDF you produce, which may or m... | 2 | 2009-02-28T02:05:04Z | [
"c#",
".net",
"python",
"html-to-pdf"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.