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 |
|---|---|---|---|---|---|---|---|---|---|
Extending python - to swig, not to swig or Cython | 456,884 | <p>I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.</p>
<p>With the help of swig you almost don't need to care about arguments etc. Everything works fine.</p>
<p>Now my question: swig creates a quite large py-file which does a lot of 'ch... | 55 | 2009-01-19T08:32:06Z | 457,099 | <p>Using <a href="http://cython.org/">Cython</a> is pretty good. You can write your C extension with a Python-like syntax and have it generate C code. Boilerplate included. Since you have the code already in python, you have to do just a few changes to your bottleneck code and C code will be generated from it.</p>
<p>... | 16 | 2009-01-19T10:05:52Z | [
"python",
"c++",
"c",
"swig",
"cython"
] |
Extending python - to swig, not to swig or Cython | 456,884 | <p>I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.</p>
<p>With the help of swig you almost don't need to care about arguments etc. Everything works fine.</p>
<p>Now my question: swig creates a quite large py-file which does a lot of 'ch... | 55 | 2009-01-19T08:32:06Z | 461,364 | <p>There be dragons here. Don't swig, don't boost. For any complicated project the code you have to fill in yourself to make them work becomes unmanageable quickly. If it's a plain C API to your library (no classes), you can just use ctypes. It will be easy and painless, and you won't have to spend hours trawling throu... | 4 | 2009-01-20T13:56:30Z | [
"python",
"c++",
"c",
"swig",
"cython"
] |
Extending python - to swig, not to swig or Cython | 456,884 | <p>I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.</p>
<p>With the help of swig you almost don't need to care about arguments etc. Everything works fine.</p>
<p>Now my question: swig creates a quite large py-file which does a lot of 'ch... | 55 | 2009-01-19T08:32:06Z | 478,892 | <p>Since you are concerned with speed and overhead, I suggest considering <a href="http://code.google.com/p/pybindgen/">PyBindGen </a>. </p>
<p>I have experience using it to wrap a large internal C++ library. After trying SWIG, SIP, and Boost.Python I prefer PyBindGen for the following reasons:</p>
<ol>
<li>A PyBindG... | 5 | 2009-01-26T05:07:53Z | [
"python",
"c++",
"c",
"swig",
"cython"
] |
Extending python - to swig, not to swig or Cython | 456,884 | <p>I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.</p>
<p>With the help of swig you almost don't need to care about arguments etc. Everything works fine.</p>
<p>Now my question: swig creates a quite large py-file which does a lot of 'ch... | 55 | 2009-01-19T08:32:06Z | 3,167,276 | <p>An observation: Based on the benchmarking conducted by the pybindgen developers, there is no significant difference between boost.python and swig. I haven't done my own benchmarking to verify how much of this depends on the proper use of the boost.python functionality. </p>
<p>Note also that there may be a reason t... | 7 | 2010-07-02T15:58:44Z | [
"python",
"c++",
"c",
"swig",
"cython"
] |
Extending python - to swig, not to swig or Cython | 456,884 | <p>I found the bottleneck in my python code, played around with psycho etc. Then decided to write a c/c++ extension for performance.</p>
<p>With the help of swig you almost don't need to care about arguments etc. Everything works fine.</p>
<p>Now my question: swig creates a quite large py-file which does a lot of 'ch... | 55 | 2009-01-19T08:32:06Z | 6,580,735 | <p>SWIG 2.0.4 has introduced a new -builtin option that improves performance.
I did some benchmarking using an example program that does a lot of fast calls to a C++ extension.
I built the extension using boost.python, PyBindGen, SIP and SWIG with and without the -builtin option. Here are the results (average of 100 ru... | 26 | 2011-07-05T09:47:58Z | [
"python",
"c++",
"c",
"swig",
"cython"
] |
Code to utilize memory more than 70% | 456,926 | <p>Please tell me C++/Java code which utilize memory more than 70% .</p>
<p>For Example we have 3 Virtual machine and in memory resources we want to test the<br />
memory utilization as per memory resources allocated by user.</p>
| 1 | 2009-01-19T08:52:11Z | 456,943 | <pre><code>#include malloc.h
#DEFINE MB 512
void main(int argc, char **argv)
{
int i;
for (i = 0; i < MB; i++)
{
malloc(1024* 1024);
}
getchar();
}
</code></pre>
<p>Hit enter to release the memory, set the MB constant to how much memory you want your program to take.</p>
<p>My C is a li... | 3 | 2009-01-19T08:58:28Z | [
"java",
"c++",
"python",
"c"
] |
Code to utilize memory more than 70% | 456,926 | <p>Please tell me C++/Java code which utilize memory more than 70% .</p>
<p>For Example we have 3 Virtual machine and in memory resources we want to test the<br />
memory utilization as per memory resources allocated by user.</p>
| 1 | 2009-01-19T08:52:11Z | 456,948 | <p>Which memory? On a 64 bit platform, a 64 bit process can use far more than 4GB. You'd be filling swap for hours before you hit those limits.</p>
<p>If you want to test "70% of physical RAM", you might discover that you cannot allocate 70% of the 32 bits address space. A significant amount is already claimed by the ... | 4 | 2009-01-19T09:00:13Z | [
"java",
"c++",
"python",
"c"
] |
Code to utilize memory more than 70% | 456,926 | <p>Please tell me C++/Java code which utilize memory more than 70% .</p>
<p>For Example we have 3 Virtual machine and in memory resources we want to test the<br />
memory utilization as per memory resources allocated by user.</p>
| 1 | 2009-01-19T08:52:11Z | 460,265 | <p>I want to test the Memory utilization but after executing the code i am unable to test the same.</p>
<p>As i am new to this so help me more on this.</p>
<p>Let we have 3 Virtual machine V1,V2,V3</p>
<p>For V1 - Set shared resource as High</p>
<p>For V2 - Set shared resources as Normal </p>
<p>For V3 - Set share... | 0 | 2009-01-20T06:24:40Z | [
"java",
"c++",
"python",
"c"
] |
Cropping pages of a .pdf file | 457,207 | <p>I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size.</p>
<p>After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribu... | 9 | 2009-01-19T10:43:23Z | 458,189 | <p>You are probably looking for a free solution, but if you have money to spend, <a href="http://pdflib.com" rel="nofollow">PDFlib</a> is a fabulous library. It has never disappointed me. </p>
| 0 | 2009-01-19T16:24:51Z | [
"python",
"pdf"
] |
Cropping pages of a .pdf file | 457,207 | <p>I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size.</p>
<p>After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribu... | 9 | 2009-01-19T10:43:23Z | 459,523 | <p>You can convert the PDF to Postscript (pstopdf or ps2pdf) and than use text processing on the Postscript file. After that you can convert the output back to PDF.</p>
<p>This works nicely if the PDFs you want to process are all generated by the same application and are somewhat similar. If they come from different s... | 0 | 2009-01-19T22:54:55Z | [
"python",
"pdf"
] |
Cropping pages of a .pdf file | 457,207 | <p>I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size.</p>
<p>After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribu... | 9 | 2009-01-19T10:43:23Z | 459,639 | <p>Acrobat Javascript API has a setPageBoxes method, but Adobe doesn't provide any Python code samples. Only C++, C# and VB.</p>
| 0 | 2009-01-19T23:39:01Z | [
"python",
"pdf"
] |
Cropping pages of a .pdf file | 457,207 | <p>I was wondering if anyone had any experience in working programmatically with .pdf files. I have a .pdf file and I need to crop every page down to a certain size.</p>
<p>After a quick Google search I found the pyPdf library for python but my experiments with it failed. When I changed the cropBox and trimBox attribu... | 9 | 2009-01-19T10:43:23Z | 465,901 | <p>pypdf does what I expect in this area. Using the following script:</p>
<pre><code>#!/usr/bin/python
#
from pyPdf import PdfFileWriter, PdfFileReader
input1 = PdfFileReader(file("in.pdf", "rb"))
output = PdfFileWriter()
numPages = input1.getNumPages()
print "document has %s pages." % numPages
for i in range(num... | 14 | 2009-01-21T16:12:44Z | [
"python",
"pdf"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 457,310 | <p>Maybe <a href="http://code.enthought.com/chaco/" rel="nofollow">Chaco</a>? I don't know if it can do 50 frames per second, but I saw in a demonstration how it did very smooth realtime plotting. It should definitely be faster than matplotlib.</p>
| 1 | 2009-01-19T11:27:17Z | [
"python",
"wxpython",
"wxwidgets"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 457,505 | <p>If you want really something fast with 50 frames per second, I think you need something like PyGame and kind of talk directly to the display, not a plotting module.</p>
<p>Check the related threads:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/434583/what-is-the-fastest-way-to-draw-an-image-from-discre... | 1 | 2009-01-19T12:57:15Z | [
"python",
"wxpython",
"wxwidgets"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 457,524 | <p>Here's a sample of a dynamic plotter with wxPython and matplotlib. While not 50 FPS, it draws smoothly and quickly enough for most real-time data views:</p>
<p><a href="http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/">http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/</a><... | 10 | 2009-01-19T13:04:57Z | [
"python",
"wxpython",
"wxwidgets"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 457,781 | <p>It's not difficult to create a C++ widget that would read from your data source, and truly update at 50 FPS. The beautiful thing about this approach is that very little (if any) Python code would be executing at 50FPS, it would all be in the C++, depending on how you hand your updated data to the widget.</p>
<p>Yo... | 5 | 2009-01-19T14:40:50Z | [
"python",
"wxpython",
"wxwidgets"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 7,605,072 | <p>If you want high performance with a minimal code footprint, look no farther than Python's built-in plotting library tkinter. No need to write special C / C++ code or use a large plotting package to get performance much better than 50 fps.</p>
<p><img src="http://i.stack.imgur.com/CGK8y.png" alt="Screenshot"></p>
... | 8 | 2011-09-30T01:24:00Z | [
"python",
"wxpython",
"wxwidgets"
] |
What is the best real time plotting widget for wxPython? | 457,246 | <p>I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython.
The widget should support both Win32 and Linux platforms.</p>
<p>Any hints are welcome.</p>
<p>Edited to add:</p>
<p>I don't need to update the display at 50 fps, but up need to show up to 50 s... | 12 | 2009-01-19T11:00:38Z | 39,784,200 | <p>I use <a href="http://www.pyqtgraph.org/" rel="nofollow">PyQtGraph</a> for this kind of thing. It is much faster than Matplotlib for realtime plotting and has lots of nice convenience features like a context menu in the plotting canvas with auto-scaling and scrolling without any extra work.</p>
| 0 | 2016-09-30T05:21:06Z | [
"python",
"wxpython",
"wxwidgets"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 457,475 | <p>I would recommend you download <a href="http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103">numpy</a> (to have efficiant matrix in python) and <a href="http://www.scipy.org/">scipy</a> (a Matlab toolbox substitute, which uses numpy). The erf function lies in scipy.</p>
<pre><code>>... | 20 | 2009-01-19T12:47:09Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 457,805 | <p>I recommend SciPy for numerical functions in Python, but if you want something with no dependencies, here is a function with an error error is less than 1.5 * 10<sup>-7</sup> for all inputs.</p>
<pre><code>def erf(x):
# save the sign of x
sign = 1 if x >= 0 else -1
x = abs(x)
# constants
a1 ... | 39 | 2009-01-19T14:46:13Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 458,069 | <p>To answer my own question, I have ended up using the following code, adapted from a Java version I found elsewhere on the web:</p>
<pre><code># from: http://www.cs.princeton.edu/introcs/21function/ErrorFunction.java.html
# Implements the Gauss error function.
# erf(z) = 2 / sqrt(pi) * integral(exp(-t*t), t = 0..z... | 6 | 2009-01-19T15:54:40Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 463,261 | <p>A pure python implementation can be found in the mpmath module (http://code.google.com/p/mpmath/)</p>
<p>From the doc string:</p>
<pre><code>>>> from mpmath import *
>>> mp.dps = 15
>>> print erf(0)
0.0
>>> print erf(1)
0.842700792949715
>>> print erf(-1)
-0.84270079294... | 7 | 2009-01-20T21:44:09Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 4,021,276 | <p>I have a function which does 10^5 erf calls. On my machine...</p>
<p>scipy.special.erf makes it time at 6.1s</p>
<p>erf Handbook of Mathematical Functions takes 8.3s</p>
<p>erf Numerical Recipes 6.2 takes 9.5s</p>
<p>(three-run averages, code taken from above posters).</p>
| 6 | 2010-10-26T06:41:50Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 6,662,057 | <p>Since v.2.7. the standard <em>math</em> module contains <em>erf</em> function. This should be the easiest way.</p>
<p><a href="http://docs.python.org/2/library/math.html#math.erf">http://docs.python.org/2/library/math.html#math.erf</a></p>
| 44 | 2011-07-12T09:31:08Z | [
"python",
"math"
] |
Is there an easily available implementation of erf() for Python? | 457,408 | <p>I can implement the error function, erf, myself, but I'd prefer not to. Is there a python package with no external dependencies that contains an implementation of this function? I have found http://pylab.sourceforge.net/packages/included_functions.html>this but this seems to be part of some much larger package (and ... | 36 | 2009-01-19T12:10:58Z | 20,745,660 | <p>One note for those aiming for higher performance: vectorize, if possible.</p>
<pre><code>import numpy as np
from scipy.special import erf
def vectorized(n):
x = np.random.randn(n)
return erf(x)
def loopstyle(n):
x = np.random.randn(n)
return [erf(v) for v in x]
%timeit vectorized(10e5)
%timeit lo... | 3 | 2013-12-23T14:37:14Z | [
"python",
"math"
] |
How to copy a picture from canvas to clipboard? | 457,514 | <p>I have some Tkinter canvas and some picture of lines and text on it. Is there an easy way to copy it to a clipboard?</p>
| 3 | 2009-01-19T12:59:53Z | 458,236 | <p>To use windows clipboard you must convert the image data to a format accepted by win api. Then, just use this function:</p>
<pre><code>import win32clipboard
def send_to_clibboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type,... | 3 | 2009-01-19T16:38:14Z | [
"python",
"clipboard",
"tkinter"
] |
How to copy a picture from canvas to clipboard? | 457,514 | <p>I have some Tkinter canvas and some picture of lines and text on it. Is there an easy way to copy it to a clipboard?</p>
| 3 | 2009-01-19T12:59:53Z | 488,541 | <p>You could use <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/canvas-methods.html" rel="nofollow"><code>.postscript</code></a> method of the canvas to get an Encapsulated PostScript (EPS) representation of the contents. Then, use `<a href="http://www.imagemagick.org" rel="nofollow">ImageMagick</a>'s Python b... | 4 | 2009-01-28T17:27:01Z | [
"python",
"clipboard",
"tkinter"
] |
What is the correct procedure to store a utf-16 encoded rss stream into sqlite3 using python | 457,641 | <p>I have a python sgi script that attempts to extract an rss items that is posted to it and store the rss in a sqlite3 db. I am using flup as the WSGIServer.<br>
To obtain the posted content:
postData = environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"]))</p>
<p>To attempt to store in the db:</p>
<pre><co... | 1 | 2009-01-19T13:57:37Z | 457,663 | <p>Regarding the insertion encoding - in any decent database API, you should insert <code>unicode</code> strings and <code>unicode</code> strings only.</p>
<p>For the reading and parsing bit, I'd recommend Mark Pilgrim's <a href="http://www.feedparser.org/" rel="nofollow">Feed Parser</a>. It properly handles BOM, and... | 1 | 2009-01-19T14:04:45Z | [
"python",
"sqlite",
"wsgi"
] |
What is the correct procedure to store a utf-16 encoded rss stream into sqlite3 using python | 457,641 | <p>I have a python sgi script that attempts to extract an rss items that is posted to it and store the rss in a sqlite3 db. I am using flup as the WSGIServer.<br>
To obtain the posted content:
postData = environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"]))</p>
<p>To attempt to store in the db:</p>
<pre><co... | 1 | 2009-01-19T13:57:37Z | 457,769 | <p>Before the SQL insertion you should to convert the string to unicode compatible strings. If you raise an UnicodeError exception, then encode the string.encode("utf-8").</p>
<p>Or , you can autodetect encoding and encode it , on his encode schema. <a href="http://code.activestate.com/recipes/52257" rel="nofollow">A... | 0 | 2009-01-19T14:36:03Z | [
"python",
"sqlite",
"wsgi"
] |
What is the correct procedure to store a utf-16 encoded rss stream into sqlite3 using python | 457,641 | <p>I have a python sgi script that attempts to extract an rss items that is posted to it and store the rss in a sqlite3 db. I am using flup as the WSGIServer.<br>
To obtain the posted content:
postData = environ["wsgi.input"].read(int(environ["CONTENT_LENGTH"]))</p>
<p>To attempt to store in the db:</p>
<pre><co... | 1 | 2009-01-19T13:57:37Z | 458,637 | <p>Are you sure your incoming data are encoded as UTF-16 (otherwise known as UCS-2)?</p>
<p>UTF-16 encoded unicode strings typically include lots of NUL characters (surely for all characters existing in ASCII too), so UTF-16 data hardly can be stored in environment variables (env vars in POSIX are NUL terminated).</p>... | 1 | 2009-01-19T18:34:14Z | [
"python",
"sqlite",
"wsgi"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 458,246 | <p>It is better to always check with the library you are using if it supports usage in a <strong>non-blocking</strong> way.</p>
<p>But if you want a more generic solution, or if there is no other way, you can run anything that blocks in a separated process by using the <a href="http://docs.python.org/library/multiproc... | 19 | 2009-01-19T16:40:24Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 458,295 | <p>Use <code>matplotlib</code>'s calls that won't block:</p>
<p>Using <code>draw()</code>:</p>
<pre><code>from matplotlib.pyplot import plot, draw, show
plot([1,2,3])
draw()
print 'continue computation'
# at the end call show to ensure window won't close.
show()
</code></pre>
<p>Using interactive mode:</p>
<pre><c... | 112 | 2009-01-19T16:52:17Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 458,321 | <p>You may want to read this document in <code>matplotlib</code>'s documentation, titled:</p>
<p><a href="http://matplotlib.sourceforge.net/users/shell.html#using-matplotlib-in-a-python-shell">Using matplotlib in a python shell</a></p>
| 8 | 2009-01-19T17:00:04Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 465,439 | <p>In my case, I wanted to have several windows pop up as they are being computed. For reference, this is the way:</p>
<pre><code>from matplotlib.pyplot import draw, figure, show
f1, f2 = figure(), figure()
af1 = f1.add_subplot(111)
af2 = f2.add_subplot(111)
af1.plot([1,2,3])
af2.plot([6,5,4])
draw()
print 'continuin... | 6 | 2009-01-21T14:05:30Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 4,149,491 | <p>Well, I had great trouble figuring out the non-blocking commands... But finally, I managed to rework the "<a href="http://www.scipy.org/Cookbook/Matplotlib/Animations#head-3d51654b8306b1585664e7fe060a60fc76e5aa08" rel="nofollow">Cookbook/Matplotlib/Animations - Animating selected plot elements</a>" example, so it wo... | 4 | 2010-11-10T21:55:48Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 5,335,087 | <p>On my system show() does not block, although I wanted the script to wait for the user to interact with the graph (and collect data using 'pick_event' callbacks) before continuing.</p>
<p>In order to block execution until the plot window is closed, I used the following:</p>
<pre><code>fig = plt.figure()
ax = fig.ad... | 2 | 2011-03-17T05:06:56Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 10,731,085 | <p>If I understand the question properly, using Ipython (or Ipython QT or Ipython notebook)
would allow you to work interactively with the chart while calculations go one in the background. <a href="http://ipython.org/" rel="nofollow">http://ipython.org/</a></p>
| 0 | 2012-05-24T04:18:42Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 13,361,748 | <p>Use the keyword 'block' to override the blocking behavior, e.g. </p>
<pre><code>from matplotlib.pyplot import show, plot
plot(1)
show(block=False)
# your code
</code></pre>
<p>to continue your code.</p>
| 67 | 2012-11-13T13:40:54Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 14,398,396 | <p>Try</p>
<pre class="lang-py prettyprint-override"><code>from matplotlib.pyplot import *
plot([1,2,3])
show(block=False)
# other code
# [...]
# Put
show()
# at the very end of your script
# to make sure Python doesn't bail out
# before you finished examining.
</code></pre>
<p>The <a href="http://matplotlib.org/api... | 13 | 2013-01-18T11:53:33Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 20,665,576 | <p>In many cases it is <strong>more convenient til save the image</strong> as a .png file on the hard drive. Here is why:</p>
<p><strong>Advantages:</strong></p>
<ul>
<li>You can open it, have a look at it and close it down any time in the process. This is particularly convenient when your application is running for ... | 2 | 2013-12-18T18:21:54Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 26,734,905 | <p>I also wanted my plots to display run the rest of the code (and then keep on displaying) even if there is an error (I sometimes use plots for debugging). I coded up this little hack so that any plots inside this <code>with</code> statement behave as such.</p>
<p>This is probably a bit too non-standard and not advis... | 2 | 2014-11-04T12:14:28Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 34,478,093 | <p>In my opinion, the answers in this thread provide methods which don't work for every systems and in more complex situations like animations. I suggest to have a look at the answer of MikeTex in the following thread, where a robust method has been found:
<a href="http://stackoverflow.com/questions/34432353/how-to-wa... | 0 | 2015-12-27T06:17:15Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 34,853,314 | <p>If you are working in console, i.e. <code>IPython</code> you could use <code>plt.show(block=False)</code> as pointed out in the other answers. But if you're lazy you could just type:</p>
<pre><code>plt.show(0)
</code></pre>
<p>Which will be the same.</p>
| 2 | 2016-01-18T11:11:44Z | [
"python",
"matplotlib",
"plot"
] |
Is there a way to detach matplotlib plots so that the computation can continue? | 458,209 | <p>After these instructions in the Python interpreter one gets a window with a plot:</p>
<pre><code>from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
</code></pre>
<p>Unfortunately, I don't know how to continue to interactively explore the figure created by <code>show()</code> while the program does f... | 122 | 2009-01-19T16:30:57Z | 39,534,832 | <p>If you want to open multiple figures, while keeping them all opened, this code worked for me:</p>
<pre><code>show(block=False)
draw()
</code></pre>
| -1 | 2016-09-16T15:11:08Z | [
"python",
"matplotlib",
"plot"
] |
How do I install an .egg file without easy_install in Windows? | 458,311 | <p>I have Python 2.6 and I want to install easy _ install module. The problem is that the only available installation package of easy _ install for Python 2.6 is an .egg file! What should I do?</p>
| 14 | 2009-01-19T16:58:10Z | 458,339 | <p>You could try <a href="http://peak.telecommunity.com/dist/ez_setup.py" rel="nofollow">this script</a>.</p>
<pre><code>#!python
"""Bootstrap setuptools installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setu... | 12 | 2009-01-19T17:05:36Z | [
"python",
"easy-install",
"egg"
] |
How do I install an .egg file without easy_install in Windows? | 458,311 | <p>I have Python 2.6 and I want to install easy _ install module. The problem is that the only available installation package of easy _ install for Python 2.6 is an .egg file! What should I do?</p>
| 14 | 2009-01-19T16:58:10Z | 458,342 | <p>Maybe you need to bootstrap setup tools like it's shown here:</p>
<p><a href="http://www.ibm.com/developerworks/library/l-cppeak3.html" rel="nofollow">http://www.ibm.com/developerworks/library/l-cppeak3.html</a></p>
| 2 | 2009-01-19T17:06:09Z | [
"python",
"easy-install",
"egg"
] |
How do I install an .egg file without easy_install in Windows? | 458,311 | <p>I have Python 2.6 and I want to install easy _ install module. The problem is that the only available installation package of easy _ install for Python 2.6 is an .egg file! What should I do?</p>
| 14 | 2009-01-19T16:58:10Z | 1,878,505 | <p>sh setuptools-0.6c9-py2.5.egg</p>
| 5 | 2009-12-10T03:43:06Z | [
"python",
"easy-install",
"egg"
] |
How do I install an .egg file without easy_install in Windows? | 458,311 | <p>I have Python 2.6 and I want to install easy _ install module. The problem is that the only available installation package of easy _ install for Python 2.6 is an .egg file! What should I do?</p>
| 14 | 2009-01-19T16:58:10Z | 10,000,462 | <p>MS Windows installer (.exe) <a href="http://pypi.python.org/pypi/setuptools#files" rel="nofollow">http://pypi.python.org/pypi/setuptools#files</a></p>
| 2 | 2012-04-03T20:01:06Z | [
"python",
"easy-install",
"egg"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 458,478 | <p>after adding some imports your code runs fine for me, how do you call the script, maybe you could tell us the folder structure of the '..\packed\bin' directory. </p>
<p>I called your code with the following arguments:</p>
<pre><code>planName='test.zip'
files=['z.py',]
folders=['c:\\temp']
(success,filename)=create... | 2 | 2009-01-19T17:47:34Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 459,242 | <p>A zip file has no directory structure, it just has a bunch of pathnames and their contents. These pathnames should be relative to an imaginary root folder (the ZIP file itself). "../" prefixes have no defined meaning in a zip file.</p>
<p>Consider you have a file, <code>a</code> and you want to store it in a "folde... | 10 | 2009-01-19T21:34:13Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 459,419 | <p>Ok, after i understood what you want, it is as simple as using the second argument of <code>zipfile.write</code>, where you can use whatever you want:</p>
<pre><code>import zipfile
myZipFile = zipfile.ZipFile("zip.zip", "w" )
myZipFile.write("test.py", "dir\\test.py", zipfile.ZIP_DEFLATED )
</code></pre>
<p>create... | 30 | 2009-01-19T22:21:46Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 459,430 | <p>Heres the edited code I ran. Its based on the code above, taken from the mailing list. I added the imports and made a main routine. I also cut out the fiddling with the output filename to make the code shorter.</p>
<pre><code>#!/usr/bin/env python
import os, zipfile, glob, sys
def addFolderToZip(myZipFile,folder)... | 0 | 2009-01-19T22:26:04Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 670,635 | <pre><code>import zipfile
import os
class ZipUtilities:
def toZip(self, file, filename):
zip_file = zipfile.ZipFile(filename, 'w')
if os.path.isfile(file):
zip_file.write(file)
else:
self.addFolderToZip(zip_file, file)
zip_file.close()
... | 4 | 2009-03-22T07:03:11Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 676,492 | <p>When you wanna create an empty folder, you can do it like this: </p>
<pre><code> storage = api.Storage.open("empty_folder.zip","w")
res = storage.open_resource("hannu//","w")
storage.close()
</code></pre>
<p>Folder not showe in winextractor, but when you extract it it is showed.</p>
| -2 | 2009-03-24T08:06:09Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 792,199 | <p>Below is some code for zipping an entire directory into a zipfile.</p>
<p>This seems to work OK creating zip files on both windows and linux. The output
files seem to extract properly on windows (built-in Compressed Folders feature,
WinZip, and 7-Zip) and linux. However, empty directories in a zip file appear
to be... | 4 | 2009-04-27T03:53:45Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 1,544,983 | <p>here is my function i use to zip a folder:</p>
<pre><code>import os
import os.path
import zipfile
def zip_dir(dirpath, zippath):
fzip = zipfile.ZipFile(zippath, 'w', zipfile.ZIP_DEFLATED)
basedir = os.path.dirname(dirpath) + '/'
for root, dirs, files in os.walk(dirpath):
if os.path.basename(ro... | 2 | 2009-10-09T17:04:44Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 1,906,438 | <p>Thank you wery much for this useful function! I found it very useful as I was also searching for help. However, maybe it would be useful to change it a little bit so that </p>
<pre><code>basedir = os.path.dirname(dirpath) + '/'
</code></pre>
<p>would be </p>
<pre><code>basedir = os.path.dirname(dirpath + '/')
</c... | 0 | 2009-12-15T10:17:30Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 6,511,788 | <p>You can also use shutil</p>
<pre><code>import shutil
shutil.make_archive("desired_zipfile_name_no", "zip", "name_of_the_folder_you_want_to_zip")
</code></pre>
<p>This will put the whole folder in the zip.</p>
| 44 | 2011-06-28T19:05:19Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 18,295,769 | <p>If you look at a zip file created with Info-ZIP, you'll see that directories are indeed listed:</p>
<pre><code>$ zip foo.zip -r foo
adding: foo/ (stored 0%)
adding: foo/foo.jpg (deflated 84%)
$ less foo.zip
Archive: foo.zip
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ----... | 1 | 2013-08-18T04:41:39Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Adding folders to a zip file using python | 458,436 | <p>I want to create a zip file. Add a folder to the zip file and then add a bunch of files to that folder.</p>
<p>So I want to end up with a zip file with a single folder with files in.</p>
<p>I dont know if its bad practice to have folders in zip files or something but google gives me nothing on the subject.</p>
<... | 31 | 2009-01-19T17:33:17Z | 25,898,859 | <pre><code>import os
import zipfile
zf = zipfile.ZipFile("file.zip", "w")
for file in os.listdir(os.curdir):
if not file.endswith('.zip') and os.path.isfile(os.curdir+'/'+file):
print file
zf.write(file)
elif os.path.isdir(os.curdir+'/'+file):
print f
for f in os.listdir(os.curd... | 0 | 2014-09-17T19:32:24Z | [
"python",
"file",
"zip",
"folder",
"zipfile"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 458,658 | <p>For what it's worth, if you're using NumPy distutils, <code>numpy.distutils.misc_util.Configuration</code> has a <a href="http://docs.scipy.org/doc/numpy/reference/distutils.html#numpy.distutils.misc_util.Configuration.make_svn_version_py" rel="nofollow"><code>make_svn_version_py()</code></a> method that embeds the ... | 0 | 2009-01-19T18:42:23Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 458,684 | <p>There doesn't seem to be a standard way to embed a version string in a python package. Most packages I've seen use some variant of your solution, i.e. eitner</p>
<ol>
<li><p>Embed the version in <code>setup.py</code> and have <code>setup.py</code> generate a module (e.g. <code>version.py</code>) containing only ver... | 5 | 2009-01-19T18:49:58Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 459,185 | <p>Not directly an answer to your question, but you should consider naming it <code>__version__</code>, not <code>version</code>.</p>
<p>This is almost a quasi-standard. Many modules in the standard library use <code>__version__</code>, and this is also used in <a href="http://www.google.com/codesearch?as_q=__version_... | 64 | 2009-01-19T21:13:57Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 466,694 | <p>Also worth noting is that as well as <code>__version__</code> being a semi-std. in python so is <code>__version_info__</code> which is a tuple, in the simple cases you can just do something like:</p>
<pre><code>__version__ = '1.2.3'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
</code></pr... | 3 | 2009-01-21T19:44:24Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 1,131,751 | <p>Though this is probably far too late, there is a slightly simpler alternative to the previous answer:</p>
<pre><code>__version_info__ = ('1', '2', '3')
__version__ = '.'.join(__version_info__)
</code></pre>
<p>(And it would be fairly simple to convert auto-incrementing portions of version numbers to a string using... | 17 | 2009-07-15T14:29:04Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 1,551,226 | <p>I also saw another style:</p>
<pre><code>>>> django.VERSION
(1, 1, 0, 'final', 0)
</code></pre>
| 5 | 2009-10-11T17:32:47Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 7,071,358 | <p>Here is how I do this. Advantages of the following method:</p>
<ol>
<li><p>It provides a <code>__version__</code> attribute.</p></li>
<li><p>It provides the standard metadata version. Therefore it will be detected by <code>pkg_resources</code> or other tools that parse the package metadata (EGG-INFO and/or PKG-INFO... | 67 | 2011-08-15T22:04:35Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 15,952,533 | <p>Many of the existing answers argue that "There doesn't seem to be a standard way" or that a style "is almost a quasi-standard."</p>
<p>In fact <em>there is a standard way</em> to do this<sup>*</sup>:</p>
<ul>
<li><strong><a href="http://www.python.org/dev/peps/pep-0396/">PEP 396</a>: Module Version Numbers</strong... | 19 | 2013-04-11T15:16:03Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 16,084,844 | <p>Here is the best solution I've seen so far and it also explains why:</p>
<p>Inside <code>yourpackage/version.py</code>:</p>
<pre><code># Store the version here so:
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your modu... | 44 | 2013-04-18T13:50:57Z | [
"python",
"string",
"package"
] |
Standard way to embed version into python package? | 458,550 | <p>Is there a standard way to associate version string with a python package in such way that I could do the following?</p>
<pre><code>import foo
print foo.version
</code></pre>
<p>I would imagine there's some way to retrieve that data without any extra hardcoding, since minor/major strings are specified in <code>set... | 126 | 2009-01-19T18:05:54Z | 21,356,350 | <p>I use a JSON file in the package dir. This fits Zooko's requirements.</p>
<p>Inside <code>pkg_dir/pkg_info.json</code>:</p>
<pre><code>{"version": "0.1.0"}
</code></pre>
<p>Inside <code>setup.py</code>:</p>
<pre><code>from distutils.core import setup
import json
with open('pkg_dir/pkg_info.json') as fp:
_in... | 6 | 2014-01-25T21:15:36Z | [
"python",
"string",
"package"
] |
wxPython is not throwing exceptions when it should, instead giving raw error messages | 458,943 | <p>I'm coding the menu for an application I'm writing in python, using wxPython libraries for the user interface, and I'm attempting to add icons to some of the menu items. Because I'm trying to be conscientious about it, I'm trying to limit the damage done if one of the image files referenced doesn't exist, and the m... | 3 | 2009-01-19T19:56:09Z | 459,013 | <p>That is a known issue. <a href="http://alldunn.com/robin/" rel="nofollow">Robin Dunn</a> answered it a couple of times: just create your Logging method eg.:</p>
<pre><code>dummy_log=wx.LogNull()
</code></pre>
<p>when the variable <code>dummy_log</code> runs out of scope, normal logging is enabled again.</p>
| 3 | 2009-01-19T20:13:41Z | [
"python",
"exception",
"wxpython"
] |
How do you run your own code alongside Tkinter's event loop? | 459,083 | <p>My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, but the birds need to move <em>every moment</em>.</p>
<p>Tkinter, however, hogs the time for its own event loop, an... | 64 | 2009-01-19T20:40:39Z | 459,131 | <p>Use the <code>after</code> method on the <code>Tk</code> object:</p>
<pre><code>from tkinter import *
root = Tk()
def task():
print("hello")
root.after(2000, task) # reschedule event in 2 seconds
root.after(2000, task)
root.mainloop()
</code></pre>
<p>Here's the declaration and documentation for the <c... | 79 | 2009-01-19T20:55:36Z | [
"python",
"events",
"tkinter"
] |
How do you run your own code alongside Tkinter's event loop? | 459,083 | <p>My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, but the birds need to move <em>every moment</em>.</p>
<p>Tkinter, however, hogs the time for its own event loop, an... | 64 | 2009-01-19T20:40:39Z | 538,559 | <p>Another option is to let tkinter execute on a separate thread. One way of doing it is like this:</p>
<pre><code>import Tkinter
import threading
class MyTkApp(threading.Thread):
def __init__(self):
self.root=Tkinter.Tk()
self.s = Tkinter.StringVar()
self.s.set('Foo')
l = Tkinter.... | 0 | 2009-02-11T20:14:55Z | [
"python",
"events",
"tkinter"
] |
How do you run your own code alongside Tkinter's event loop? | 459,083 | <p>My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, but the birds need to move <em>every moment</em>.</p>
<p>Tkinter, however, hogs the time for its own event loop, an... | 64 | 2009-01-19T20:40:39Z | 1,835,036 | <p>The solution posted by Bjorn results in a "RuntimeError: Calling
Tcl from different appartment" message on my computer (RedHat Enterprise 5, python 2.6.1). Bjorn might not have gotten this message, since, according to <a href="http://www.mail-archive.com/tkinter-discuss@python.org/msg01808.html">one place I checked... | 26 | 2009-12-02T18:55:46Z | [
"python",
"events",
"tkinter"
] |
How do you run your own code alongside Tkinter's event loop? | 459,083 | <p>My little brother is just getting into programming, and for his Science Fair project, he's doing a simulation of a flock of birds in the sky. He's gotten most of his code written, and it works nicely, but the birds need to move <em>every moment</em>.</p>
<p>Tkinter, however, hogs the time for its own event loop, an... | 64 | 2009-01-19T20:40:39Z | 4,836,121 | <p>When writing your own loop, as in the simulation (I assume), you need to call the <code>update</code> function which does what the <code>mainloop</code> does: updates the window with your changes, but you do it in your loop.</p>
<pre><code>def task():
# do something
root.update()
while 1:
task()
</code>... | 8 | 2011-01-29T09:35:20Z | [
"python",
"events",
"tkinter"
] |
Filtering by relation count in SQLAlchemy | 459,125 | <p>I'm using the SQLAlchemy Python ORM in a Pylons project. I have a class "Project" which has a one to many relationship with another class "Entry". I want to do a query in SQLAlchemy that gives me all of the projects which have one or more entries associated with them. At the moment I'm doing:</p>
<pre><code>[projec... | 6 | 2009-01-19T20:53:54Z | 459,313 | <p>Project.entries.any() should work.</p>
| 11 | 2009-01-19T21:48:24Z | [
"python",
"sql",
"database",
"sqlalchemy",
"pylons"
] |
BeautifulSoup 3.1 parser breaks far too easily | 459,552 | <p><em>I was having trouble parsing some dodgy HTML with BeautifulSoup. Turns out that the HTMLParser used in newer versions is less tolerant than the SGMLParser used previously.</em></p>
<p><hr /></p>
<p>Does BeautifulSoup have some kind of debug mode? I'm trying to figure out how to stop it borking on some nasty HT... | 3 | 2009-01-19T23:07:02Z | 459,642 | <p>Your problem must be something else; it works fine for me: </p>
<pre><code>In [1]: import BeautifulSoup
In [2]: c = """<HTML>
...: <HEAD>
...: <TITLE>Title</TITLE>
...: <HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
...: </HEAD>
...: <BODY... | 2 | 2009-01-19T23:40:08Z | [
"python",
"html",
"parsing",
"beautifulsoup"
] |
BeautifulSoup 3.1 parser breaks far too easily | 459,552 | <p><em>I was having trouble parsing some dodgy HTML with BeautifulSoup. Turns out that the HTMLParser used in newer versions is less tolerant than the SGMLParser used previously.</em></p>
<p><hr /></p>
<p>Does BeautifulSoup have some kind of debug mode? I'm trying to figure out how to stop it borking on some nasty HT... | 3 | 2009-01-19T23:07:02Z | 638,597 | <p><a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html" rel="nofollow">Having problems with Beautiful Soup 3.1.0?</a> recommends to use <a href="http://code.google.com/p/html5lib/" rel="nofollow">html5lib</a>'s parser as one of workarounds.</p>
<pre><code>#!/usr/bin/env python
from html5lib import ... | 6 | 2009-03-12T13:20:25Z | [
"python",
"html",
"parsing",
"beautifulsoup"
] |
BeautifulSoup 3.1 parser breaks far too easily | 459,552 | <p><em>I was having trouble parsing some dodgy HTML with BeautifulSoup. Turns out that the HTMLParser used in newer versions is less tolerant than the SGMLParser used previously.</em></p>
<p><hr /></p>
<p>Does BeautifulSoup have some kind of debug mode? I'm trying to figure out how to stop it borking on some nasty HT... | 3 | 2009-01-19T23:07:02Z | 1,223,045 | <p>Try <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> (and its html module). Despite its name, it is also for parsing and scraping HTML. It's much, much faster than BeautifulSoup, and it even handles "broken" HTML better than BeautifulSoup. It has a compatibility API for BeautifulSoup too if you don't wan... | 3 | 2009-08-03T15:40:41Z | [
"python",
"html",
"parsing",
"beautifulsoup"
] |
Thread specific data with webpy | 459,608 | <p>I'm writing a little web app with webpy, and I'm wondering if anyone has any information on a little problem I'm having.</p>
<p>I've written a little ORM system, and it seems to be working pretty well. Ideally I'd like to stitch it in with webpy, but it appears that just using it as is causes thread issues (DB conn... | 2 | 2009-01-19T23:26:18Z | 460,713 | <p>I'll give this one a try. Disclaimer: I have no experience with the web.py framework.</p>
<p>I suggest you try the following:</p>
<p>(1) Create a global threading.local instance to keep track of your thread local objects (in your case, it will keep track of only one object, a database session).</p>
<pre><code>imp... | 2 | 2009-01-20T10:17:25Z | [
"python",
"database",
"multithreading",
"web.py"
] |
Thread specific data with webpy | 459,608 | <p>I'm writing a little web app with webpy, and I'm wondering if anyone has any information on a little problem I'm having.</p>
<p>I've written a little ORM system, and it seems to be working pretty well. Ideally I'd like to stitch it in with webpy, but it appears that just using it as is causes thread issues (DB conn... | 2 | 2009-01-19T23:26:18Z | 519,493 | <p>We use SQLAlchemy with web.py and use hooks to create and close db connections per request. SQLAlchemy handles pooling, so not every connection is a tcp connection.</p>
<p>The thread local storage you want to use is web.ctx ie. any time you access web.ctx you only see properties set by that thread.</p>
<p>Our cod... | 4 | 2009-02-06T07:59:19Z | [
"python",
"database",
"multithreading",
"web.py"
] |
BeautifulSoup - modifying all links in a piece of HTML? | 459,981 | <p>I need to be able to modify every single link in an HTML document. I know that I need to use the <code>SoupStrainer</code> but I'm not 100% positive on how to implement it. If someone could direct me to a good resource or provide a code example, it'd be very much appreciated.</p>
<p>Thanks.</p>
| 13 | 2009-01-20T02:52:19Z | 459,991 | <p>Maybe something like this would work? (I don't have a Python interpreter in front of me, unfortunately)</p>
<pre><code>from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup('<p>Blah blah blah <a href="http://google.com">Google</a></p>')
for a in soup.findAll('a'):
a['href'] = a['hre... | 29 | 2009-01-20T03:02:34Z | [
"python",
"beautifulsoup"
] |
BeautifulSoup - modifying all links in a piece of HTML? | 459,981 | <p>I need to be able to modify every single link in an HTML document. I know that I need to use the <code>SoupStrainer</code> but I'm not 100% positive on how to implement it. If someone could direct me to a good resource or provide a code example, it'd be very much appreciated.</p>
<p>Thanks.</p>
| 13 | 2009-01-20T02:52:19Z | 460,002 | <pre><code>from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup('<p>Blah blah blah <a href="http://google.com">Google</a></p>')
for a in soup.findAll('a'):
a['href'] = a['href'].replace("google", "mysite")
print str(soup)
</code></pre>
<p>This is Lusid's solution, but since he didn'... | 22 | 2009-01-20T03:09:49Z | [
"python",
"beautifulsoup"
] |
BeautifulSoup - modifying all links in a piece of HTML? | 459,981 | <p>I need to be able to modify every single link in an HTML document. I know that I need to use the <code>SoupStrainer</code> but I'm not 100% positive on how to implement it. If someone could direct me to a good resource or provide a code example, it'd be very much appreciated.</p>
<p>Thanks.</p>
| 13 | 2009-01-20T02:52:19Z | 22,571,633 | <p>I tried this and it worked, it's easier to avoid using regexp for matching each <code>'href'</code>:</p>
<pre><code>from bs4 import BeautifulSoup as bs
soup = bs(htmltext)
for a in soup.findAll('a'):
a['href'] = "mysite"
</code></pre>
<p>Check it out, on <a href="http://beautiful-soup-4.readthedocs.org/en/late... | 1 | 2014-03-22T00:03:17Z | [
"python",
"beautifulsoup"
] |
Python/Twisted - Sending to a specific socket object? | 460,068 | <p>I have a "manager" process on a node, and several worker processes. The manager is the actual server who holds all of the connections to the clients. The manager accepts all incoming packets and puts them into a queue, and then the worker processes pull the packets out of the queue, process them, and generate a resu... | 1 | 2009-01-20T03:43:14Z | 460,245 | <p>It sounds like you might need to keep a reference to the transport (or protocol) along with the bytes the just came in on that protocol in your 'event' object. That way responses that came in on a connection go out on the same connection. </p>
<p>If things don't need to be processed serially perhaps you should thi... | 3 | 2009-01-20T06:00:42Z | [
"python",
"sockets",
"twisted",
"multiprocess"
] |
Python/Twisted - TCP packet fragmentation? | 460,144 | <p>In Twisted when implementing the dataReceived method, there doesn't seem to be any examples which refer to packets being fragmented. In every other language this is something you manually implement, so I was just wondering if this is done for you in twisted already or what? If so, do I need to prefix my packets with... | 5 | 2009-01-20T04:38:17Z | 460,224 | <p>In the dataReceived method you get back the data as a string of indeterminate length meaning that it may be a whole message in your protocol or it may only be part of the message that some 'client' sent to you. You will have to inspect the data to see if it comprises a whole message in your protocol.</p>
<p>I'm cu... | 6 | 2009-01-20T05:47:42Z | [
"python",
"tcp",
"twisted",
"packet"
] |
Python/Twisted - TCP packet fragmentation? | 460,144 | <p>In Twisted when implementing the dataReceived method, there doesn't seem to be any examples which refer to packets being fragmented. In every other language this is something you manually implement, so I was just wondering if this is done for you in twisted already or what? If so, do I need to prefix my packets with... | 5 | 2009-01-20T04:38:17Z | 461,477 | <p>When dealing with TCP, you should really forget all notion of 'packets'. TCP is a stream protocol - you stream data in and data streams out the other side. Once the data is sent, it is allowed to arrive in as many or as few blocks as it wants, as long as the data all arrives in the right order. You'll have to manual... | 5 | 2009-01-20T14:20:12Z | [
"python",
"tcp",
"twisted",
"packet"
] |
Python/Twisted - TCP packet fragmentation? | 460,144 | <p>In Twisted when implementing the dataReceived method, there doesn't seem to be any examples which refer to packets being fragmented. In every other language this is something you manually implement, so I was just wondering if this is done for you in twisted already or what? If so, do I need to prefix my packets with... | 5 | 2009-01-20T04:38:17Z | 817,378 | <p>You can also use a LineReceiver protocol</p>
| 1 | 2009-05-03T16:01:47Z | [
"python",
"tcp",
"twisted",
"packet"
] |
Algorithm to generate spanning set | 460,479 | <p>Given this input: [1,2,3,4]</p>
<p>I'd like to generate the set of spanning sets:</p>
<pre><code>[1] [2] [3] [4]
[1] [2] [3,4]
[1] [2,3] [4]
[1] [3] [2,4]
[1,2] [3] [4]
[1,3] [2] [4]
[1,4] [2] [3]
[1,2] [3,4]
[1,3] [2,4]
[1,4] [2,3]
[1,2,3] [4]
[1,2,4] [3]
[1,3,4] [2]
[2,3,4] [1]
[1,2,3,4]
</code></pre>
<p>Every ... | 10 | 2009-01-20T08:38:46Z | 460,514 | <p>What about this? I haven't tested it yet, but I'll try it laterâ¦</p>
<p>I think this technique is called Dynamic Programming:</p>
<ol>
<li><p>Take the first element <code>[1]</code><br />
What can you create with it? Only <code>[1]</code></p></li>
<li><p>Take the second one <code>[2]</code><br />
Now you've got ... | 6 | 2009-01-20T08:55:20Z | [
"python",
"algorithm"
] |
Algorithm to generate spanning set | 460,479 | <p>Given this input: [1,2,3,4]</p>
<p>I'd like to generate the set of spanning sets:</p>
<pre><code>[1] [2] [3] [4]
[1] [2] [3,4]
[1] [2,3] [4]
[1] [3] [2,4]
[1,2] [3] [4]
[1,3] [2] [4]
[1,4] [2] [3]
[1,2] [3,4]
[1,3] [2,4]
[1,4] [2,3]
[1,2,3] [4]
[1,2,4] [3]
[1,3,4] [2]
[2,3,4] [1]
[1,2,3,4]
</code></pre>
<p>Every ... | 10 | 2009-01-20T08:38:46Z | 460,529 | <p>This should work, though I haven't tested it enough.</p>
<pre><code>def spanningsets(items):
if not items: return
if len(items) == 1:
yield [[items[-1]]]
else:
for cc in spanningsets(items[:-1]):
yield cc + [[items[-1]]]
for i in range(len(cc)):
yi... | 11 | 2009-01-20T09:02:54Z | [
"python",
"algorithm"
] |
Algorithm to generate spanning set | 460,479 | <p>Given this input: [1,2,3,4]</p>
<p>I'd like to generate the set of spanning sets:</p>
<pre><code>[1] [2] [3] [4]
[1] [2] [3,4]
[1] [2,3] [4]
[1] [3] [2,4]
[1,2] [3] [4]
[1,3] [2] [4]
[1,4] [2] [3]
[1,2] [3,4]
[1,3] [2,4]
[1,4] [2,3]
[1,2,3] [4]
[1,2,4] [3]
[1,3,4] [2]
[2,3,4] [1]
[1,2,3,4]
</code></pre>
<p>Every ... | 10 | 2009-01-20T08:38:46Z | 460,565 | <p>Here's <a href="http://www.cs.sunysb.edu/~algorith/files/generating-subsets.shtml" rel="nofollow">The SUNY algorithm repository</a> page on the problem. Maybe you can translate one of the code references to python.</p>
<p>Edit: This was a similar problem. <a href="http://www.cs.sunysb.edu/~algorith/files/generating... | 0 | 2009-01-20T09:23:06Z | [
"python",
"algorithm"
] |
Algorithm to generate spanning set | 460,479 | <p>Given this input: [1,2,3,4]</p>
<p>I'd like to generate the set of spanning sets:</p>
<pre><code>[1] [2] [3] [4]
[1] [2] [3,4]
[1] [2,3] [4]
[1] [3] [2,4]
[1,2] [3] [4]
[1,3] [2] [4]
[1,4] [2] [3]
[1,2] [3,4]
[1,3] [2,4]
[1,4] [2,3]
[1,2,3] [4]
[1,2,4] [3]
[1,3,4] [2]
[2,3,4] [1]
[1,2,3,4]
</code></pre>
<p>Every ... | 10 | 2009-01-20T08:38:46Z | 461,219 | <p>The result sets together with the empty set {} looks like the results of the <a href="http://en.wikipedia.org/wiki/Power_set" rel="nofollow">powerset</a> (or power set), but it is not the same thing.</p>
<p>I started a post about a similar problem which has a few implementations (although in C#) and geared more for... | -1 | 2009-01-20T13:03:18Z | [
"python",
"algorithm"
] |
Algorithm to generate spanning set | 460,479 | <p>Given this input: [1,2,3,4]</p>
<p>I'd like to generate the set of spanning sets:</p>
<pre><code>[1] [2] [3] [4]
[1] [2] [3,4]
[1] [2,3] [4]
[1] [3] [2,4]
[1,2] [3] [4]
[1,3] [2] [4]
[1,4] [2] [3]
[1,2] [3,4]
[1,3] [2,4]
[1,4] [2,3]
[1,2,3] [4]
[1,2,4] [3]
[1,3,4] [2]
[2,3,4] [1]
[1,2,3,4]
</code></pre>
<p>Every ... | 10 | 2009-01-20T08:38:46Z | 463,586 | <p>I think the following method is the best way to generate them for the euler problem, as you can replace the return value with the number of prime spanning subsets, and it will be trivial to do the multiplication (especially with memoization):</p>
<pre><code>GenerateSubsets(list)
partitions = { x | x is subset o... | 0 | 2009-01-20T23:46:59Z | [
"python",
"algorithm"
] |
Simulating a 'local static' variable in python | 460,586 | <p>Consider the following code: </p>
<pre><code>def CalcSomething(a):
if CalcSomething._cache.has_key(a):
return CalcSomething._cache[a]
CalcSomething._cache[a] = ReallyCalc(a)
return CalcSomething._cache[a]
CalcSomething._cache = { }
</code></pre>
<p>This is the easiest way I can think of for si... | 23 | 2009-01-20T09:32:42Z | 460,601 | <p>Turn it into a decorator.</p>
<pre><code>def static_var(var_name, initial_value):
def _set_var(obj):
setattr(obj, var_name, initial_value)
return obj
return _set_var
@static_var("_cache", {})
def CalcSomething(a):
...
</code></pre>
| 15 | 2009-01-20T09:39:21Z | [
"python"
] |
Simulating a 'local static' variable in python | 460,586 | <p>Consider the following code: </p>
<pre><code>def CalcSomething(a):
if CalcSomething._cache.has_key(a):
return CalcSomething._cache[a]
CalcSomething._cache[a] = ReallyCalc(a)
return CalcSomething._cache[a]
CalcSomething._cache = { }
</code></pre>
<p>This is the easiest way I can think of for si... | 23 | 2009-01-20T09:32:42Z | 460,691 | <p>Consider writing decorator that will maintain cache and your function won't be contaminated by caching code:</p>
<pre><code>def cacheResults(aFunc):
'''This decorator funcion binds a map between the tuple of arguments
and results computed by aFunc for those arguments'''
def cachedFunc(*args):
... | 10 | 2009-01-20T10:10:57Z | [
"python"
] |
Simulating a 'local static' variable in python | 460,586 | <p>Consider the following code: </p>
<pre><code>def CalcSomething(a):
if CalcSomething._cache.has_key(a):
return CalcSomething._cache[a]
CalcSomething._cache[a] = ReallyCalc(a)
return CalcSomething._cache[a]
CalcSomething._cache = { }
</code></pre>
<p>This is the easiest way I can think of for si... | 23 | 2009-01-20T09:32:42Z | 460,811 | <p>Turn it into a callable object (since that's what it really is.)</p>
<pre><code>class CalcSomething(object):
def __init__(self):
self._cache = {}
def __call__(self, a):
if a not in self._cache:
self._cache[a] = self.reallyCalc(a)
return self._cache[a]
def reallyCalc(... | 44 | 2009-01-20T10:57:30Z | [
"python"
] |
Simulating a 'local static' variable in python | 460,586 | <p>Consider the following code: </p>
<pre><code>def CalcSomething(a):
if CalcSomething._cache.has_key(a):
return CalcSomething._cache[a]
CalcSomething._cache[a] = ReallyCalc(a)
return CalcSomething._cache[a]
CalcSomething._cache = { }
</code></pre>
<p>This is the easiest way I can think of for si... | 23 | 2009-01-20T09:32:42Z | 460,924 | <p>One option is to abuse default parameters. ie:</p>
<pre><code>def CalcSomething(a, _cache={}):
if _cache.has_key(a):
</code></pre>
<p>This has the advantage that you don't need to qualify the name, and will get fast local access to the variables rather than doing two slow dict lookups. However it still has t... | 3 | 2009-01-20T11:34:50Z | [
"python"
] |
Simulating a 'local static' variable in python | 460,586 | <p>Consider the following code: </p>
<pre><code>def CalcSomething(a):
if CalcSomething._cache.has_key(a):
return CalcSomething._cache[a]
CalcSomething._cache[a] = ReallyCalc(a)
return CalcSomething._cache[a]
CalcSomething._cache = { }
</code></pre>
<p>This is the easiest way I can think of for si... | 23 | 2009-01-20T09:32:42Z | 461,557 | <p>The solution proposed by S.Lott is the solution I would propose too.</p>
<p>There are useful "memoize" decorators around, too, like:</p>
<ul>
<li><a href="http://code.activestate.com/recipes/496879/" rel="nofollow">Memoize decorator function with cache size limit</a></li>
<li><a href="http://code.activestate.com/r... | 4 | 2009-01-20T14:37:35Z | [
"python"
] |
XML-RPC and Continuum from Python / Perl | 462,038 | <p>Has anyone had any success with getting data via Xml-rpc using Python or Perl...?</p>
<p>I'm using the continuum.py library:</p>
<pre><code>#!/usr/bin/env python
from continuum import *
c = Continuum( "http://localhost:8080/continuum/xmlrpc" )
</code></pre>
<p>or:</p>
<pre><code>#!/usr/bin/perl
use Frontier::... | 2 | 2009-01-20T16:27:39Z | 464,646 | <p>Yes... with Perl. </p>
<p>I've used <a href="http://search.cpan.org/dist/XML-RPC/" rel="nofollow">XML::RPC</a>. In fact I wrote the CPAN module <a href="http://search.cpan.org/dist/WWW-FreshMeat-API/" rel="nofollow">WWW::FreshMeat::API</a> using it to access Freshmeats XML-RPC API so I know it does work well!</p... | 1 | 2009-01-21T09:59:57Z | [
"python",
"perl",
"xml-rpc",
"continuum"
] |
XML-RPC and Continuum from Python / Perl | 462,038 | <p>Has anyone had any success with getting data via Xml-rpc using Python or Perl...?</p>
<p>I'm using the continuum.py library:</p>
<pre><code>#!/usr/bin/env python
from continuum import *
c = Continuum( "http://localhost:8080/continuum/xmlrpc" )
</code></pre>
<p>or:</p>
<pre><code>#!/usr/bin/perl
use Frontier::... | 2 | 2009-01-20T16:27:39Z | 498,602 | <p>What you describe is not part of the client-side library-- it's a matter of whether the server implements these methods.</p>
<p>I'm the author of the <a href="http://search.cpan.org/dist/RPC-XML" rel="nofollow">RPC::XML</a> Perl module, and in the server class I provide I also provide implementation of the basic "i... | 1 | 2009-01-31T10:11:11Z | [
"python",
"perl",
"xml-rpc",
"continuum"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.