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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Python most common element in a list | 1,518,522 | <p>What is an efficient way to find the most common element in a Python list?</p>
<p>My list items may not be hashable so can't use a dictionary.
Also in case of draws the item with the lowest index should be returned. Example:</p>
<pre><code>>>> most_common(['duck', 'duck', 'goose'])
'duck'
>>> most_common(['goose', 'duck', 'duck', 'goose'])
'goose'
</code></pre>
| 63 | 2009-10-05T06:35:44Z | 20,872,750 | <p>Borrowing from <a href="http://stackoverflow.com/questions/10797819/finding-the-mode-of-a-list-in-python">here</a>, this can be used with Python 2.7:</p>
<pre><code>from collections import Counter
def Most_Common(lst):
data = Counter(lst)
return data.most_common(1)[0][0]
</code></pre>
<p>Works around 4-6 times faster than Alex's solutions, and is 50 times faster than the one-liner proposed by newacct.</p>
| 45 | 2014-01-01T20:10:48Z | [
"python",
"list"
] |
Python most common element in a list | 1,518,522 | <p>What is an efficient way to find the most common element in a Python list?</p>
<p>My list items may not be hashable so can't use a dictionary.
Also in case of draws the item with the lowest index should be returned. Example:</p>
<pre><code>>>> most_common(['duck', 'duck', 'goose'])
'duck'
>>> most_common(['goose', 'duck', 'duck', 'goose'])
'goose'
</code></pre>
| 63 | 2009-10-05T06:35:44Z | 36,478,038 | <p>What you want is known in statistics as mode, and Python of course has a built-in function to do exactly that for you:</p>
<pre><code>>>> from statistics import mode
>>> mode([1, 2, 2, 3, 3, 3, 3, 3, 4, 5, 6, 6, 6])
3
</code></pre>
| 3 | 2016-04-07T13:43:14Z | [
"python",
"list"
] |
Python most common element in a list | 1,518,522 | <p>What is an efficient way to find the most common element in a Python list?</p>
<p>My list items may not be hashable so can't use a dictionary.
Also in case of draws the item with the lowest index should be returned. Example:</p>
<pre><code>>>> most_common(['duck', 'duck', 'goose'])
'duck'
>>> most_common(['goose', 'duck', 'duck', 'goose'])
'goose'
</code></pre>
| 63 | 2009-10-05T06:35:44Z | 38,442,481 | <pre><code>def popular(L):
C={}
for a in L:
C[a]=L.count(a)
for b in C.keys():
if C[b]==max(C.values()):
return b
L=[2,3,5,3,6,3,6,3,6,3,7,467,4,7,4]
print popular(L)
</code></pre>
| -1 | 2016-07-18T17:15:15Z | [
"python",
"list"
] |
Snow Leopard Python 2.6 problems getting PIL to work | 1,518,573 | <p>I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error:</p>
<p><strong>ImportError: The _imaging C module is not installed</strong></p>
<p>Any help much appreciated!</p>
<p>I tried to import _imaging w/ Python interpreter to see what's wrong and got this:</p>
<pre><code> >>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: dynamic lookup
</code></pre>
| 2 | 2009-10-05T06:59:33Z | 1,518,583 | <p>Edit: Thanks for the added error message. This is apparently a problem with the jpeglib on Snow Leopard. Have you tried this?</p>
<p><a href="http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/" rel="nofollow">http://jetfar.com/libjpeg-and-python-imaging-pil-on-snow-leopard/</a></p>
| 2 | 2009-10-05T07:02:46Z | [
"python",
"image-manipulation",
"osx-snow-leopard",
"pylons",
"python-imaging-library"
] |
Snow Leopard Python 2.6 problems getting PIL to work | 1,518,573 | <p>I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error:</p>
<p><strong>ImportError: The _imaging C module is not installed</strong></p>
<p>Any help much appreciated!</p>
<p>I tried to import _imaging w/ Python interpreter to see what's wrong and got this:</p>
<pre><code> >>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: dynamic lookup
</code></pre>
| 2 | 2009-10-05T06:59:33Z | 1,582,363 | <p>I kept having this problem as well. It turned out to be related to a change I made to my .bash_profile (forcing the usage of ggc-4.0) when trying to fix a MySQLdb installation problem.</p>
<p><a href="http://www.brambraakman.com/blog/comments/installing%5Fpil%5Fin%5Fsnow%5Fleopard%5Fjpeg%5Fresync%5Fto%5Frestart%5Ferror/" rel="nofollow">http://www.brambraakman.com/blog/comments/installing%5Fpil%5Fin%5Fsnow%5Fleopard%5Fjpeg%5Fresync%5Fto%5Frestart%5Ferror/</a></p>
| 1 | 2009-10-17T14:51:13Z | [
"python",
"image-manipulation",
"osx-snow-leopard",
"pylons",
"python-imaging-library"
] |
Snow Leopard Python 2.6 problems getting PIL to work | 1,518,573 | <p>I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error:</p>
<p><strong>ImportError: The _imaging C module is not installed</strong></p>
<p>Any help much appreciated!</p>
<p>I tried to import _imaging w/ Python interpreter to see what's wrong and got this:</p>
<pre><code> >>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: dynamic lookup
</code></pre>
| 2 | 2009-10-05T06:59:33Z | 1,676,682 | <p>I just hit this as well on SL, and the problem is likely your libjpeg was built without a matching architecture. Assuming you're using MacPorts, run <code>file /opt/local/lib/libjpeg.dylib</code>. The right way is to build everything with MacPorts as <code>+universal</code>, see
<a href="http://rcaguilar.wordpress.com/2009/11/04/universal-binaries-in-macports/" rel="nofollow">Universal Binaries in MacPorts</a> as it relates to PIL dependencies.</p>
| 4 | 2009-11-04T21:15:43Z | [
"python",
"image-manipulation",
"osx-snow-leopard",
"pylons",
"python-imaging-library"
] |
Snow Leopard Python 2.6 problems getting PIL to work | 1,518,573 | <p>I installed libjpeg and PIL, but when I try to save a JPG image, I always get this error:</p>
<p><strong>ImportError: The _imaging C module is not installed</strong></p>
<p>Any help much appreciated!</p>
<p>I tried to import _imaging w/ Python interpreter to see what's wrong and got this:</p>
<pre><code> >>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: dynamic lookup
</code></pre>
| 2 | 2009-10-05T06:59:33Z | 2,871,841 | <p>A lot of these errors happen when compiling from source when you've previously installed python tools from fink or ports. For example the <code>_jpeg_resync_to_restart</code> error can happen when you've got leftover libjpeg files in <code>/opt/local/lib</code>. Try this:</p>
<pre><code>cd /opt/local/lib
sudo rm *jpeg*
</code></pre>
<p>Then recompile libjpeg (starting with <code>make clean</code>), then recompile PIL (starting with <code>rm -Rf build</code>).</p>
<p>After that, <code>import _imaging</code> should work. Did for me anyway.</p>
| 4 | 2010-05-20T07:44:51Z | [
"python",
"image-manipulation",
"osx-snow-leopard",
"pylons",
"python-imaging-library"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,665 | <p>You have an empty def</p>
<pre><code>def timer():
</code></pre>
<p>use</p>
<pre><code>def timer():
pass
</code></pre>
<p>instead.</p>
| 11 | 2009-10-05T07:24:39Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,666 | <p>try deindent main() and add pass to timer and define an init method:</p>
<pre><code>class Alarm():
def __init__(self):
print ("Timer has Started")
<shell>$ Alarm()
</code></pre>
| 1 | 2009-10-05T07:25:00Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,669 | <p>Your timer function is not defined. (And your space/tab indentation may be mixed)</p>
<p>See the tutorial (<a href="http://docs.python.org/tutorial/classes.html#class-objects" rel="nofollow">classes</a>) for more details on classes.</p>
<pre><code>class Alarm:
def timer(self):
pass
def main(self):
print ("Timer has Started")
if __name__ == '__main__':
class_inst = Alarm()
class_inst.main()
</code></pre>
<p>If you getting into python read <a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP8</a>.<br />
Also, using <a href="http://www.logilab.org/857" rel="nofollow">pylint</a> helps, it will point out indentation and many other errors you'll run across before you 'execute' your code.</p>
| 1 | 2009-10-05T07:26:52Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,670 | <p>Learn about the <a href="http://docs.python.org/reference/simple%5Fstmts.html#the-pass-statement" rel="nofollow"><code>pass</code> statement</a>, <code>main</code> is usually not part of the class.</p>
<p>A global (module level) <code>main()</code> function is simpler than an <code>Alarm.main()</code> class method. Usually, <code>main()</code> functions come at module level.</p>
<pre><code>class Alarm:
def timer():
pass
def main():
print ("Timer has Started")
main()
</code></pre>
| 3 | 2009-10-05T07:27:16Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,678 | <p>I think you want to use <code>__init__</code> though, which is the constructor...</p>
<pre><code>class Alarm:
def timer(self):
print('timer has started')
def __init__(self):
print('constructor')
self.timer()
x = Alarm()
</code></pre>
<blockquote>
<p>constructor</p>
<p>timer has started</p>
</blockquote>
<p>My example differs from the others in that I'm actually instantiating a new object.</p>
<p>Notes:</p>
<ul>
<li>specify <code>self</code> as the first argument to any method defined in the class</li>
<li><code>__init__</code> is the method to define for the constructor</li>
<li>invoke the class by doing variableName = className() like you would invoke a function, no <code>new</code> keyword</li>
<li>if you have an empty function, use the <code>pass</code> keyword like <code>def foo(self): pass</code></li>
</ul>
| 1 | 2009-10-05T07:32:15Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,714 | <p>Invoking main() will give an <em>undefined function error</em>, as it is a Alarm method.</p>
<p>IMHO the right form you should use is the following:</p>
<pre><code>class Alarm:
def timer():
pass
@staticmethod
def main():
print ("Timer has Started")
if __name__ == "__main__" :
Alarm.main()
</code></pre>
| 1 | 2009-10-05T07:47:53Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,735 | <p>As others have pointed out, you have a syntax error because timer() has no body.</p>
<p>You don't need to use main() in python at all. Usually people use it to indicate that the file is the top level program and not a module to be imported, but it is just by convention</p>
<p>You may also see this idiom</p>
<pre><code>def main():
blah blah
if __name__ == "__main__":
main()
</code></pre>
<p>Here <code>__name__</code> is a special variable. If the file has been imported it will contain the module name, so the comparison fails and main does not run.</p>
<p>For the top level program <code>__name__</code> contains "<code>__main__</code>" so the main() function will be run.</p>
<p>This is useful because sometimes your module might run tests when it is loaded as a program but you don't want those test to run if you are importing it into a larger program</p>
| 0 | 2009-10-05T07:54:04Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,518,903 | <p>In Python, you don't need to define everything as a class. There's nothing to encapsulate in this code, so there's no reason to define an Alarm class. Just have the functions in a module.</p>
| 0 | 2009-10-05T08:53:39Z | [
"python"
] |
Python and indentation, having touble getting started | 1,518,659 | <p>I have just started learning python and am getting caught up. I come from mostly C background. </p>
<pre><code>class Alarm:
def timer():
def main():
print ("Timer has Started")
main()
</code></pre>
<p>I always get a silly error when I try to run this code::</p>
<pre><code>alarm > python alarm.py
File "alarm.py", line 5
def main():
^
IndentationError: expected an indented block
</code></pre>
<p>What am I doing wrong?</p>
| 2 | 2009-10-05T07:22:33Z | 1,521,982 | <p>Thanks for all the help everybody. I was making a little alarm/timer to remind me to get up and take a walk every now and then. I got most of it working, and it works great. Checked it against a stop watch and it works great. </p>
<pre><code>import time
def timer(num):
seconds = num*60
print (num , "minutes", seconds , "seconds")
while (seconds > 0):
print (seconds, "seconds")
time.sleep(1)
seconds = seconds-1
print ("Time to get up and take a WALK!!!!")
main()
def main():
number = input("Input time : ")
int(number)
timer(number)
if __name__ == '__main__':
main()
</code></pre>
| 0 | 2009-10-05T19:39:11Z | [
"python"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 1,518,728 | <p>/proc/partitions shows all the partitions known to the kernel.</p>
| 0 | 2009-10-05T07:52:09Z | [
"python",
"linux"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 1,518,753 | <p>All mayor Linux distros include <a href="http://www.reactivated.net/writing%5Fudev%5Frules.html">udev</a>, that allows you to write custom scripts on hardware events.</p>
| 9 | 2009-10-05T08:02:41Z | [
"python",
"linux"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 1,518,829 | <p>When an USB device is plugged in syslog writes messages concerning this to /var/log/messages. The "dmesg" command shows this log. You can check near the end of the log to see which channel the device was attached to, it is usually /dev/sd(letter)(number) depending on the partitions and number of serial disks plugged into the system.</p>
| 1 | 2009-10-05T08:27:11Z | [
"python",
"linux"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 1,518,879 | <p>You can read <a href="http://lwn.net/Articles/242046/">uevents from kernel</a> via a <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/netlink.7.html">Netlink</a> socket and look for events where <code>"ACTION"</code> is <code>"add"</code> (you can also watch if a partition from a device was mounted or unmounted, or if a device is being removed). That's as close to the source of events as one can get in user space. As far as I know, this is how <code>udev</code> detects inserted removable media.</p>
<p>But probably <a href="http://ubuntuforums.org/archive/index.php/t-904706.html">using D-Bus/HAL API via Python bingings</a> will be much easier (no uevents data parsing, etc). Not sure why you are opposed to this. Since you are using Python, I suspect that resources are not really the issue.</p>
| 6 | 2009-10-05T08:46:12Z | [
"python",
"linux"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 1,519,381 | <p>If you are targetting an embedded device, then you can run <a href="http://wildanm.wordpress.com/2007/08/21/mdev-mini-udev-in-busybox/" rel="nofollow">mdev</a> instead of udev.
Then you can write mdev rules that are quite simple and triggers a script.</p>
<p>Of course you are not directly monitoring from your script, mdev is doing it, but you can launch any command. You can probably do the same thing with udev, but it always looked quite complicated to me.</p>
| 4 | 2009-10-05T10:51:53Z | [
"python",
"linux"
] |
How can I detect when a flash drive is plugged in under Linux? | 1,518,699 | <p>How can I detect when a flash drive is plugged in? I'm using a bare Debian installation, without any GUI and want to be notified in my Python script when a new flash drive appears... I know that D-BUS distributes such information, but i dont want to use D-BUS. Is there a more bare access to that information? Shouldn't that be available under /proc or /sys? How can I "connect" to that source?</p>
<p>Bye
falstaff</p>
| 5 | 2009-10-05T07:40:27Z | 16,370,716 | <p>I did this using zenity in a script and udev with rule on rhel6 with:</p>
<p>KERNEL=="sd[b-d]", DRIVERS=="usb", ACTION=="add", RUN+="/path/to/script"</p>
| 0 | 2013-05-04T04:50:43Z | [
"python",
"linux"
] |
Need help in designing a phone book application on python running on google app engine | 1,518,725 | <p>Hi I want some help in building a Phone book application on python and put it on google app engine. I am running a huge db of 2 million user lists and their contacts in phonebook. I want to upload all that data from my servers directly onto the google servers and then use a UI to retrieve the phone book contacts of each user based on his name.</p>
<p>I am using MS SQL sever 2005 as my DB.</p>
<p>Please help in putting together this application.</p>
<p>Your inputs are much appreciated.</p>
| 0 | 2009-10-05T07:50:45Z | 1,519,020 | <p>I think you're going to need to be more specific as to what problem you're having. As far as bulk loading goes, there's lots of bulkloader documentation around; or are you asking about model design? If so, we need to know more about how you plan to search for users. Do you need partial string matches? Sorting? Fuzzy matching?</p>
| 0 | 2009-10-05T09:24:47Z | [
"python",
"google-app-engine",
"bulk-load"
] |
Need help in designing a phone book application on python running on google app engine | 1,518,725 | <p>Hi I want some help in building a Phone book application on python and put it on google app engine. I am running a huge db of 2 million user lists and their contacts in phonebook. I want to upload all that data from my servers directly onto the google servers and then use a UI to retrieve the phone book contacts of each user based on his name.</p>
<p>I am using MS SQL sever 2005 as my DB.</p>
<p>Please help in putting together this application.</p>
<p>Your inputs are much appreciated.</p>
| 0 | 2009-10-05T07:50:45Z | 1,535,434 | <p>For building your UI, AppEngine has <a href="http://code.google.com/appengine/docs/python/tools/webapp/" rel="nofollow">it's own web framework</a> called webapp that is pretty easy to get working. I've also had a good experience using the <a href="http://jinja.pocoo.org/2/" rel="nofollow">Jinja2 templating engine</a>, which you can include in your source, or <a href="http://code.google.com/appengine/articles/django10%5Fzipimport.html" rel="nofollow">package as a zip file</a> (example shows Django, you can do the same type of thing for Jinja).</p>
<p>As for loading all of your data into the DataStore, you should take a look at the <a href="http://code.google.com/appengine/docs/python/tools/uploadingdata.html#Downloading%5Fand%5FUploading%5FAll%5FData" rel="nofollow">bulk uploader documentation</a>.</p>
| 1 | 2009-10-08T03:15:47Z | [
"python",
"google-app-engine",
"bulk-load"
] |
Combine two lists: aggregate values that have similar keys | 1,518,858 | <p>I have two lists or more than . Some thing like this:</p>
<pre><code>listX = [('A', 1, 10), ('B', 2, 20), ('C', 3, 30), ('D', 4, 30)]
listY = [('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20),
('A', 6, 60), ('D', 7, 70])
</code></pre>
<p>i want to get the result that move the duplicate elements like this:
my result is to get all the list from listX + listY,but in the case there are duplicated
for example
the element <code>('A', 1, 10), ('D', 4, 30)</code> of listX is presented or exitst in listY.so the result so be like this</p>
<pre><code>result = [('A', 7, 70), ('B', 2, 20), ('C', 3, 30), ('D', 11, 100),
('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20)]
</code></pre>
<p><code>(A, 7, 70)</code> is obtained by adding <code>('A', 1, 10)</code> and <code>('A', '6', '60')</code> together</p>
<p>Anybody could me to solve this problem.?
Thanks.</p>
| 0 | 2009-10-05T08:38:15Z | 1,518,882 | <p>This is pretty easy if you use a dictionary.</p>
<pre><code>combined = {}
for item in listX + listY:
key = item[0]
if key in combined:
combined[key][0] += item[1]
combined[key][1] += item[2]
else:
combined[key] = [item[1], item[2]]
result = [(key, value[0], value[1]) for key, value in combined.items()]
</code></pre>
| 8 | 2009-10-05T08:47:21Z | [
"python"
] |
Combine two lists: aggregate values that have similar keys | 1,518,858 | <p>I have two lists or more than . Some thing like this:</p>
<pre><code>listX = [('A', 1, 10), ('B', 2, 20), ('C', 3, 30), ('D', 4, 30)]
listY = [('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20),
('A', 6, 60), ('D', 7, 70])
</code></pre>
<p>i want to get the result that move the duplicate elements like this:
my result is to get all the list from listX + listY,but in the case there are duplicated
for example
the element <code>('A', 1, 10), ('D', 4, 30)</code> of listX is presented or exitst in listY.so the result so be like this</p>
<pre><code>result = [('A', 7, 70), ('B', 2, 20), ('C', 3, 30), ('D', 11, 100),
('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20)]
</code></pre>
<p><code>(A, 7, 70)</code> is obtained by adding <code>('A', 1, 10)</code> and <code>('A', '6', '60')</code> together</p>
<p>Anybody could me to solve this problem.?
Thanks.</p>
| 0 | 2009-10-05T08:38:15Z | 1,518,885 | <p>I'd say use a dictionary:</p>
<pre><code>result = {}
for eachlist in (ListX, ListY,):
for item in eachlist:
if item[0] not in result:
result[item[0]] = item
</code></pre>
<p>It's always tricky do do data manipulation if you have data in a structure that doesn't represent the data well. Consider using better data structures.</p>
| 1 | 2009-10-05T08:47:56Z | [
"python"
] |
Combine two lists: aggregate values that have similar keys | 1,518,858 | <p>I have two lists or more than . Some thing like this:</p>
<pre><code>listX = [('A', 1, 10), ('B', 2, 20), ('C', 3, 30), ('D', 4, 30)]
listY = [('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20),
('A', 6, 60), ('D', 7, 70])
</code></pre>
<p>i want to get the result that move the duplicate elements like this:
my result is to get all the list from listX + listY,but in the case there are duplicated
for example
the element <code>('A', 1, 10), ('D', 4, 30)</code> of listX is presented or exitst in listY.so the result so be like this</p>
<pre><code>result = [('A', 7, 70), ('B', 2, 20), ('C', 3, 30), ('D', 11, 100),
('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20)]
</code></pre>
<p><code>(A, 7, 70)</code> is obtained by adding <code>('A', 1, 10)</code> and <code>('A', '6', '60')</code> together</p>
<p>Anybody could me to solve this problem.?
Thanks.</p>
| 0 | 2009-10-05T08:38:15Z | 1,518,887 | <p>You appear to be using lists like a dictionary. Any reason you're using lists instead of dictionaries?</p>
<p>My understanding of this garbled question, is that you want to add up values in tuples where the first element in the same.</p>
<p>I'd do something like this:</p>
<pre><code>counter = dict(
(a[0], (a[1], a[2]))
for a in listX
)
for key, v1, v2 in listY:
if key not in counter:
counter[key] = (0, 0)
counter[key][0] += v1
counter[key][1] += v2
result = [(key, value[0], value[1]) for key, value in counter.items()]
</code></pre>
| 2 | 2009-10-05T08:48:38Z | [
"python"
] |
Combine two lists: aggregate values that have similar keys | 1,518,858 | <p>I have two lists or more than . Some thing like this:</p>
<pre><code>listX = [('A', 1, 10), ('B', 2, 20), ('C', 3, 30), ('D', 4, 30)]
listY = [('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20),
('A', 6, 60), ('D', 7, 70])
</code></pre>
<p>i want to get the result that move the duplicate elements like this:
my result is to get all the list from listX + listY,but in the case there are duplicated
for example
the element <code>('A', 1, 10), ('D', 4, 30)</code> of listX is presented or exitst in listY.so the result so be like this</p>
<pre><code>result = [('A', 7, 70), ('B', 2, 20), ('C', 3, 30), ('D', 11, 100),
('a', 5, 50), ('b', 4, 40), ('c', 3, 30), ('d', 1, 20)]
</code></pre>
<p><code>(A, 7, 70)</code> is obtained by adding <code>('A', 1, 10)</code> and <code>('A', '6', '60')</code> together</p>
<p>Anybody could me to solve this problem.?
Thanks.</p>
| 0 | 2009-10-05T08:38:15Z | 1,519,108 | <p>Use dictionary and its 'get' method.</p>
<pre><code>d = {}
for x in (listX + listY):
y = d.get(x[0], (0, 0, 0))
d[x[0]] = (x[0], x[1] + y[1], x[2] + y[2])
d.values()
</code></pre>
| 0 | 2009-10-05T09:46:48Z | [
"python"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,518,958 | <ul>
<li>In .NET, elements of an array are certainly contiguous. In Java I'd expect them to be in most implementations, but it appears not to be guaranteed.</li>
<li>I think it's reasonable to <em>assume</em> that the memory used by an instance for fields is in a single block... but don't forget that some of those fields may be references to other objects.</li>
</ul>
<p>For the Java array part, <a href="http://java.sun.com/docs/books/jni/html/objtypes.html" rel="nofollow">Sun's JNI documentation</a> includes this comment, tucked away in a discussion about strings:</p>
<blockquote>
<p>For example, the Java virtual machine may not store arrays contiguously.</p>
</blockquote>
<p>For your last question, if you have two <code>int[]</code> then each of those arrays will be a contiguous block of memory, but they could be very "far apart" in memory. If you have an array of objects with two int fields, then each object could be a long way from each other, but the two integers within each object will be close together. Potentially more importantly, you'll end up taking a <em>lot</em> more memory with the "lots of objects" solution due to the per-object overhead. In .NET you could use a custom <em>struct</em> with two integers instead, and have an array of those - that would keep all the data in one big block.</p>
<p>I believe that in both Java and .NET, if you allocate a lot of smallish objects in quick succession within a single thread then those objects are <em>likely</em> to have good locality of reference. When the GC compacts a heap, this may improve - or it may potentially become worse, if a heap with</p>
<pre><code>A B C D E
</code></pre>
<p>is compacted to</p>
<pre><code>A D E B
</code></pre>
<p>(where C is collected) - suddenly A and B, which may have been "close" before, are far apart. I don't know whether this actually happens in any garbage collector (there are loads around!) but it's possible.</p>
<p>Basically in a managed environment you don't usually have as much control over locality of reference as you do in an unmanaged environment - you have to trust that the managed environment is sufficiently good at managing it, and that you'll have saved enough time by coding to a higher level platform to let you spend time optimising elsewhere.</p>
| 8 | 2009-10-05T09:06:35Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,518,961 | <p>First, your title is implying C#. "Managed code" is a term coined by Microsoft, if I'm not mistaken.</p>
<p>Java primitive arrays are guaranteed to be a continuous block of memory. If you have a </p>
<pre><code>int[] array = new int[4];
</code></pre>
<p>you can from JNI (native C) get a <code>int *p</code> to point to the actual array. I think this goes for the Array* class of containers as well (ArrayList, ArrayBlockingQueue, etc).</p>
<p>Early implementations of the JVM had objects as contiuous struct, I think, but this cannot be assumed with newer JVMs. (JNI abstracts away this).</p>
<p>Two integers in the same object will as you say probably be "closer", but they may not be. This will probably vary even using the same JVM.</p>
<p>An object with two int fields is an object and I don't think any JVM makes any guarantee that the members will be "close". An int-array with two elements will very likely be backed by a 8 byte long array.</p>
| 3 | 2009-10-05T09:07:01Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,518,970 | <p>With regards to arrays here is an excerpt from CLI (Common Language Infrastructure) specification:</p>
<blockquote>
<p>Array elements shall be laid out
within the array object in row-major
order (i.e., the elements associated
with the rightmost array dimension
<strong>shall be laid out contiguously from lowest to highest index</strong>). The
actual storage allocated for each
array element can include
platform-specific padding. (The size
of this storage, in bytes, is returned
by the sizeof instruction when it is
applied to the type of that arrayâs
elements.</p>
</blockquote>
| 2 | 2009-10-05T09:10:16Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,519,011 | <p>Good question! I think I would resort to writing extensions in C++ that handle memory in a more carefully managed way and just exposing enough of an interface to allow the rest of the application to manipulate the objects. If I was that concerned about performance I would probably resort to a C++ extension anyway.</p>
| 2 | 2009-10-05T09:22:51Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,519,069 | <p>If you need to optimise to that level then I suspect a VM based language is not for you ;)</p>
| -3 | 2009-10-05T09:36:57Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
In managed code, how do I achieve good locality of reference? | 1,518,915 | <p>Since RAM seems to be <a href="http://www.infoq.com/news/2008/06/ram-is-disk">the new disk</a>, and since that statement also means that access to memory is now considered slow similarly to how disk access has always been, I do want to maximize locality of reference in memory for high performance applications. For example, in a sorted index, I want adjacent values to be close (unlike say, in a hashtable), and I want the data the index is pointing to close by, too.</p>
<p>In C, I can whip up a data structure with a specialized memory manager, like the developers of the (immensely complex) <a href="http://judy.sourceforge.net/">Judy array</a> did. With direct control over the pointers, they even went so far as to encode additional information in the pointer value itself. When working in Python, Java or C#, I am deliberately one (or more) level(s) of abstraction away from this type of solution and I'm entrusting the JIT compilers and optimizing runtimes with doing clever tricks on the low levels for me.</p>
<p>Still, I guess, even at this high level of abstraction, there are things that can be semantically considered "closer" and therefore are likely to be <em>actually</em> closer at the low levels. For example, I was wondering about the following (my guess in parentheses):</p>
<ul>
<li>Can I expect an array to be an adjacent block of memory (yes)?</li>
<li>Are two integers in the same instance closer than two in different instances of the same class (probably)?</li>
<li>Does an object occupy a contigous region in memory (no)?</li>
<li>What's the difference between an array of objects with only two <code>int</code> fields and a single object with two <code>int[]</code> fields? (this example is probably Java specific)</li>
</ul>
<p>I started wondering about these in a Java context, but my wondering has become more general, so I'd suggest to not treat this as a Java question.</p>
| 9 | 2009-10-05T08:58:36Z | 1,519,671 | <p>I don't think anyone has talked about Python so I'll have a go</p>
<blockquote>
<p>Can I expect an array to be an adjacent block of memory (yes)?</p>
</blockquote>
<p>In python arrays are more like arrays of pointers in C. So the pointers will be adjacent, but the actual objects are unlikely to be.</p>
<blockquote>
<p>Are two integers in the same instance closer than two in different instances of the same class (probably)?</p>
</blockquote>
<p>Probably not for the same reason as above. The instance will only hold pointers to the objects which are the actual integers. Python doesn't have native int (like Java), only boxed Int (in Java-speak).</p>
<blockquote>
<p>Does an object occupy a contigous region in memory (no)?</p>
</blockquote>
<p>Probably not. However if you use the <code>__slots__</code> optimisation then some parts of it will be contiguous!</p>
<blockquote>
<p>What's the difference between an array of objects with only two int fields and a single object with two int[] fields?
(this example is probably Java specific)</p>
</blockquote>
<p>In python, in terms of memory locality, they are both pretty much the same! One will make an array of pointers to objects which will in turn contain two pointers to ints, the other will make two arrays of pointers to integers.</p>
| 2 | 2009-10-05T12:02:46Z | [
"c#",
"java",
"python",
"optimization",
"memory-management"
] |
Learning to write reusable libraries | 1,518,948 | <p>We need to write simple scripts to manipulate the configuration of our load balancers (ie, drain nodes from pools, enabled or disable traffic rules). The load balancers have a SOAP API (defined through a bunch of WSDL files) which is very comprehensive but using it is quite low-level with a lot of manual error checking and list manipulation. It doesn't tend to produce reusable, robust code.</p>
<p>I'd like to write a Python library to handle the nitty-gritty of interacting with the SOAP interface but I don't really know where to start; all of my coding experience is with writing one-off monolithic programs for specific jobs. This is fine for small jobs but it's not helping me or my coworkers -- we're reinventing the wheel with a different number of spokes each time :~)</p>
<p>The API already provides methods like getPoolNames() and getDrainingNodes() but they're a bit awkward to use. Most take a list of nodes and return another list, so (say) working out which virtual servers are enabled involves this sort of thing:</p>
<pre><code>names = conn.getVirtualServerNames()
enabled = conn.getEnabled(names)
for i in range(0, len(names)):
if (enabled[i]):
print names[i]
conn.setEnabled(['www.example.com'], [0])
</code></pre>
<p>Whereas something like this:</p>
<pre><code>lb = LoadBalancer('hostname')
for name in [vs.name for vs in lb.virtualServers() if vs.isEnabled()]:
print name
www = lb.virtualServer('www.example.com').disable()
</code></pre>
<p>is more Pythonic and (IMHO) easier.</p>
<p>There are a lot of things I'm not sure about: how to handle errors, how to deal with 20-odd WSDL files (a SOAPpy/suds instance for each?) and how much boilerplate translation from the API methods to my methods I'll need to do.</p>
<p>This is more an example of a wider problem (how to learn to write libraries instead of one-off scripts) so I don't want answers to these specific questions -- they're there to demonstrate my thinking and illustrate my problem. I recognise a code smell in the way I do things at the moment (one-off, non-reusable code) but I don't know how to fix it. How does one get into the mindset for tackling problems at a more abstract level? How do you 'learn' software design?</p>
| 3 | 2009-10-05T09:03:42Z | 1,518,978 | <p>If you are not afraid of C++, there is an excellent book on the subject called "Large-scale C++ Software Design".</p>
<p>This book will guide you through the steps of designing a library by introducing "physical" and "logical" design.
For instance, you'll learn to flatten your components' hierarchy, to restrict dependency between components, to create levels of abstraction.</p>
<p>The is really "the" book on software design IMHO.</p>
| 0 | 2009-10-05T09:11:41Z | [
"python",
"design"
] |
Learning to write reusable libraries | 1,518,948 | <p>We need to write simple scripts to manipulate the configuration of our load balancers (ie, drain nodes from pools, enabled or disable traffic rules). The load balancers have a SOAP API (defined through a bunch of WSDL files) which is very comprehensive but using it is quite low-level with a lot of manual error checking and list manipulation. It doesn't tend to produce reusable, robust code.</p>
<p>I'd like to write a Python library to handle the nitty-gritty of interacting with the SOAP interface but I don't really know where to start; all of my coding experience is with writing one-off monolithic programs for specific jobs. This is fine for small jobs but it's not helping me or my coworkers -- we're reinventing the wheel with a different number of spokes each time :~)</p>
<p>The API already provides methods like getPoolNames() and getDrainingNodes() but they're a bit awkward to use. Most take a list of nodes and return another list, so (say) working out which virtual servers are enabled involves this sort of thing:</p>
<pre><code>names = conn.getVirtualServerNames()
enabled = conn.getEnabled(names)
for i in range(0, len(names)):
if (enabled[i]):
print names[i]
conn.setEnabled(['www.example.com'], [0])
</code></pre>
<p>Whereas something like this:</p>
<pre><code>lb = LoadBalancer('hostname')
for name in [vs.name for vs in lb.virtualServers() if vs.isEnabled()]:
print name
www = lb.virtualServer('www.example.com').disable()
</code></pre>
<p>is more Pythonic and (IMHO) easier.</p>
<p>There are a lot of things I'm not sure about: how to handle errors, how to deal with 20-odd WSDL files (a SOAPpy/suds instance for each?) and how much boilerplate translation from the API methods to my methods I'll need to do.</p>
<p>This is more an example of a wider problem (how to learn to write libraries instead of one-off scripts) so I don't want answers to these specific questions -- they're there to demonstrate my thinking and illustrate my problem. I recognise a code smell in the way I do things at the moment (one-off, non-reusable code) but I don't know how to fix it. How does one get into the mindset for tackling problems at a more abstract level? How do you 'learn' software design?</p>
| 3 | 2009-10-05T09:03:42Z | 1,519,028 | <p>There's an excellent <a href="http://www.infoq.com/presentations/effective-api-design" rel="nofollow">presentation</a> by Joshua Bloch on API design (and thus leading to library design). It's well worth watching. IIRC it's Java-focused, but the principles will apply to any language.</p>
| 1 | 2009-10-05T09:26:50Z | [
"python",
"design"
] |
Learning to write reusable libraries | 1,518,948 | <p>We need to write simple scripts to manipulate the configuration of our load balancers (ie, drain nodes from pools, enabled or disable traffic rules). The load balancers have a SOAP API (defined through a bunch of WSDL files) which is very comprehensive but using it is quite low-level with a lot of manual error checking and list manipulation. It doesn't tend to produce reusable, robust code.</p>
<p>I'd like to write a Python library to handle the nitty-gritty of interacting with the SOAP interface but I don't really know where to start; all of my coding experience is with writing one-off monolithic programs for specific jobs. This is fine for small jobs but it's not helping me or my coworkers -- we're reinventing the wheel with a different number of spokes each time :~)</p>
<p>The API already provides methods like getPoolNames() and getDrainingNodes() but they're a bit awkward to use. Most take a list of nodes and return another list, so (say) working out which virtual servers are enabled involves this sort of thing:</p>
<pre><code>names = conn.getVirtualServerNames()
enabled = conn.getEnabled(names)
for i in range(0, len(names)):
if (enabled[i]):
print names[i]
conn.setEnabled(['www.example.com'], [0])
</code></pre>
<p>Whereas something like this:</p>
<pre><code>lb = LoadBalancer('hostname')
for name in [vs.name for vs in lb.virtualServers() if vs.isEnabled()]:
print name
www = lb.virtualServer('www.example.com').disable()
</code></pre>
<p>is more Pythonic and (IMHO) easier.</p>
<p>There are a lot of things I'm not sure about: how to handle errors, how to deal with 20-odd WSDL files (a SOAPpy/suds instance for each?) and how much boilerplate translation from the API methods to my methods I'll need to do.</p>
<p>This is more an example of a wider problem (how to learn to write libraries instead of one-off scripts) so I don't want answers to these specific questions -- they're there to demonstrate my thinking and illustrate my problem. I recognise a code smell in the way I do things at the moment (one-off, non-reusable code) but I don't know how to fix it. How does one get into the mindset for tackling problems at a more abstract level? How do you 'learn' software design?</p>
| 3 | 2009-10-05T09:03:42Z | 1,519,142 | <p>"I don't really know where to start"</p>
<p>Clearly false. You provided an excellent example. Just do more of that. It's that simple.</p>
<p>"There are a lot of things I'm not sure about: how to handle errors, how to deal with 20-odd WSDL files (a SOAPpy/suds instance for each?) and how much boilerplate translation from the API methods to my methods I'll need to do."</p>
<ol>
<li><p>Handle errors by raising an exception. That's enough. Remember, you're still going to have high-level scripts using your API library.</p></li>
<li><p>20-odd WSDL files? Just pick something for now. Don't overengineer this. Design the API -- as you did with your example -- for the things you want to do. The WSDL's and the number of instances will become clear as you go. One, Ten, Twenty doesn't really matter to <em>users</em> of your API library. It only matters to you, the maintainer. Focus on the users.</p></li>
<li><p>Boilerplate translation? As little as possible. Focus on what parts of these interfaces you use with your actual scripts. Translate just what you need and nothing more. </p></li>
</ol>
<p>An API is not fixed, cast in concrete, a thing of beauty and a joy forever. It's just a module (in your case a package might be better) that does some useful stuff.</p>
<p>It will undergo constant change and evolution. </p>
<p>Don't overengineer the first release. Build something useful that works for one use case. Then add use cases to it.</p>
<p>"But what if I realize I did something wrong?" That's inevitable, you'll always reach this point. Don't worry about it now. </p>
<p>The most important thing about writing an API library is writing the unit tests that (a) demonstrate <em>how</em> it works and (b) prove that it actually works.</p>
| 4 | 2009-10-05T09:54:58Z | [
"python",
"design"
] |
String manipulation in Python docstrings | 1,519,029 | <p>I've been trying to do the following:</p>
<pre><code>#[...]
def __history_dependent_simulate(self, node, iterations=1,
*args, **kwargs):
"""
For history-dependent simulations only:
""" + self.simulate.__doc___
</code></pre>
<p>What I tried to accomplish here is to have the same documentation for this private method as the documentation of the method <code>simulate</code>, except with a short introduction. This would allow me to avoid copy-pasting, keep a shorter file and not have to update the documentation for two functions every time.</p>
<p>But it doesn't work. Does anyone know of a reason why, or whether there is a solution?</p>
| 8 | 2009-10-05T09:27:01Z | 1,519,088 | <p>A better solution is probably to use a decorator, eg:</p>
<pre><code>def add_docs_for(other_func):
def dec(func):
func.__doc__ = other_func.__doc__ + "\n\n" + func.__doc__
return func
return dec
def foo():
"""documentation for foo"""
pass
@add_docs_for(foo)
def bar():
"""additional notes for bar"""
pass
help(bar) # --> "documentation for foo // additional notes for bar"
</code></pre>
<p>That way you can do arbitrary manipulations of docstrings.</p>
| 9 | 2009-10-05T09:41:11Z | [
"python",
"string",
"documentation"
] |
String manipulation in Python docstrings | 1,519,029 | <p>I've been trying to do the following:</p>
<pre><code>#[...]
def __history_dependent_simulate(self, node, iterations=1,
*args, **kwargs):
"""
For history-dependent simulations only:
""" + self.simulate.__doc___
</code></pre>
<p>What I tried to accomplish here is to have the same documentation for this private method as the documentation of the method <code>simulate</code>, except with a short introduction. This would allow me to avoid copy-pasting, keep a shorter file and not have to update the documentation for two functions every time.</p>
<p>But it doesn't work. Does anyone know of a reason why, or whether there is a solution?</p>
| 8 | 2009-10-05T09:27:01Z | 1,519,090 | <p>I think <a href="http://www.python.org/dev/peps/pep-0257/#what-is-a-docstring" rel="nofollow">this section</a> makes it pretty clear:</p>
<blockquote>
<p><strong>What is a Docstring?</strong></p>
<p>A docstring is a string literal that
occurs as the first statement in a
module, function, class, or method
definition. Such a docstring becomes
the <strong>doc</strong> special attribute of that
object.</p>
</blockquote>
<p>So, it's not an expression that evaluates into a string, it's a <em>string literal</em>.</p>
| 1 | 2009-10-05T09:41:58Z | [
"python",
"string",
"documentation"
] |
Verifying peer in SSL using python | 1,519,074 | <p>I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that the server url </p>
<p>Thanks in advance for any insights.</p>
| 8 | 2009-10-05T09:37:53Z | 1,520,341 | <p>It is impossible to verify a self-signed certificate because of its very nature: it is self-signed. </p>
<p>You have to sign a certificate by some other trusted third party's certificate to be able to verify anything, and after this you can add that third party's certificate to the list of your trusted CAs and then you will be able to verify certificates signed by that certificate/CA.</p>
<p>If you want recommendations about how to do this in Python, you should provide the name of the SSL library you are using, since there is a choice of SSL libraries for Python.</p>
| 0 | 2009-10-05T14:12:31Z | [
"python",
"ssl"
] |
Verifying peer in SSL using python | 1,519,074 | <p>I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that the server url </p>
<p>Thanks in advance for any insights.</p>
| 8 | 2009-10-05T09:37:53Z | 1,520,828 | <p>I assume you use some OpenSSL binding. I see 2 ways to solve your problem.</p>
<ol>
<li>You can add your certificate to openssl directory (run <code>openssl version -d</code> to see it for your system). This will affect all programs using openssl on your machine.</li>
<li>Load certificate and add it run-time (the code sketch below is for PyOpenSSL, but it should be similar for other bindings):</li>
</ol>
<p>.</p>
<pre><code>x509 = OpenSSL.crypto.load_certificate(...)
ctx = OpenSSL.SSL.Context(...)
store = ctx.get_cert_store()
store.add_cert(x509)
ctx.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT, ...)
</code></pre>
| 2 | 2009-10-05T15:38:03Z | [
"python",
"ssl"
] |
Verifying peer in SSL using python | 1,519,074 | <p>I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that the server url </p>
<p>Thanks in advance for any insights.</p>
| 8 | 2009-10-05T09:37:53Z | 1,522,323 | <p>From the comments to my first reply I see that there is a general misunderstanding what does 'verify a certificate mean'. I will try to write a brief explanation here to eliminate some of the illusions.</p>
<p>Certificate verification is about checking a signature on the certificate metadata (i.e. subject, validity period, extensions and such) against some cryptographic signature.</p>
<p>If all you have for the validation is a self-signed certificate you cannot distinguish it from another self-signed certificate with exactly the same metadata, but the different key, unless you know the key certificate's key in advance. And don't forget that you establish all this verification procedure to remove the requirement to have this pre-shared knowledge. With regular certificate verification you cannot completely remove the requirement to have some pre-shared knowlege, which is a set of third-party certificates, also known as 'CA certificates'. Since this knowledge is pre-shared, those certificates may be self-signed, but remember that you have received information about validity of those certificates not from the verification process, but from some outer knowledge.</p>
<p>When you have a set of trusted 'CA certificates' distributed between peers, you can use those to sign other certificates and check signatures against that pre-shared knowledge of trusted CAs. </p>
<p>But if you have no additional knowledge about a self-signed certificate except the certificate itself you can make no assumptions about trust to this particular certificate, because it can be issued by some evil hacker as well as by you trustworthy server.</p>
<p>Please, acquire some knowledge about <a href="http://en.wikipedia.org/wiki/Man-in-the-middle%5Fattack">Man in the middle attack</a>, <a href="http://en.wikipedia.org/wiki/Public%5Fkey%5Finfrastructure">Public key infrastructure</a> and <a href="http://en.wikipedia.org/wiki/Public-key%5Fcryptography">Public key cryptography</a> in general before implementing any kind of certificate verification processes.</p>
<p>Please understand that blind verification of a self-signed certificate will not protect you even from a clever hacker in your own network, not even considering internet security in general.</p>
<p><strong>Edit</strong>: question author clarified that he was actually looking for how to verify a verisign (or other CA) signature on a certificate using M2Crypto bindings. Here are two examples:</p>
<pre><code>from M2Crypto import X509, SSL
# manual validation of a signature on a certificate using a given CA cert:
ca = X509.load_cert('/path/to/ca_cert.pem')
cert = X509.load_cert('certificate_to_validate.pem')
print "Verification results:", cert.verify(ca.get_pubkey())
# adding a given CA cert to the SSL Context for verification
ctx = SSL.Context()
# load a certificate from file
ctx.load_verify_locations(cafile='/path/to/ca_cert.pem')
# or use all certificate in a CA directory
ctx.load_verify_locations(capath='/path/to/ca/dir')
# or you can specify both options at the same time.
</code></pre>
<p>If you are going to use a directory with many CA certificates (which is often more convenient) you must rename each certificate to <code><hash>.0</code> where <code><hash></code> is the hash of the certificate subject (obtained with <code>openssl x509 -noout -hash -in cert.pem</code>).</p>
| 10 | 2009-10-05T20:51:15Z | [
"python",
"ssl"
] |
Is it normal that running python under valgrind shows many errors with memory? | 1,519,276 | <p>I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:</p>
<pre><code>valgrind python -c ""
</code></pre>
<p>Valgrind output full of repeated info like this:</p>
<pre><code>==12317== Invalid read of size 4
==12317== at 0x409CF59: PyObject_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x405C7C7: PyGrammar_RemoveAccelerators (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x410A1EC: Py_Finalize (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4114FD1: Py_Main (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x8048591: main (in /usr/bin/python2.5)
==12317== Address 0x43CD010 is 7,016 bytes inside a block of size 8,208 free'd
==12317== at 0x4022F6C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==12317== by 0x4107ACC: PyArena_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41095D7: PyRun_StringFlags (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40DF262: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4099569: PyCFunction_Call (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E76CC: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E70F3: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E896A: PyEval_EvalCodeEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E8AC2: PyEval_EvalCode (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FD99C: PyImport_ExecCodeModuleEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FFC93: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41002B0: (within /usr/lib/libpython2.5.so.1.0)
</code></pre>
<p>Python 2.5.2 on Slackware 12.2.</p>
<p>Is it normal behavior? If so then valgrind maybe is inappropriate tool for debugging memory errors in Python?</p>
| 13 | 2009-10-05T10:25:48Z | 1,519,508 | <p>Yes, this is typical. Large systems often leave memory un-freed, which is fine so long as it is a constant amount, and not proportional to the running history of the system. The Python interpreter falls into this category.</p>
<p>Perhaps you can filter the valgrind output to focus only on allocations made in your C extension?</p>
| 0 | 2009-10-05T11:23:35Z | [
"python",
"debugging",
"memory-leaks",
"valgrind",
"python-c-extension"
] |
Is it normal that running python under valgrind shows many errors with memory? | 1,519,276 | <p>I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:</p>
<pre><code>valgrind python -c ""
</code></pre>
<p>Valgrind output full of repeated info like this:</p>
<pre><code>==12317== Invalid read of size 4
==12317== at 0x409CF59: PyObject_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x405C7C7: PyGrammar_RemoveAccelerators (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x410A1EC: Py_Finalize (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4114FD1: Py_Main (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x8048591: main (in /usr/bin/python2.5)
==12317== Address 0x43CD010 is 7,016 bytes inside a block of size 8,208 free'd
==12317== at 0x4022F6C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==12317== by 0x4107ACC: PyArena_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41095D7: PyRun_StringFlags (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40DF262: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4099569: PyCFunction_Call (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E76CC: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E70F3: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E896A: PyEval_EvalCodeEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E8AC2: PyEval_EvalCode (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FD99C: PyImport_ExecCodeModuleEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FFC93: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41002B0: (within /usr/lib/libpython2.5.so.1.0)
</code></pre>
<p>Python 2.5.2 on Slackware 12.2.</p>
<p>Is it normal behavior? If so then valgrind maybe is inappropriate tool for debugging memory errors in Python?</p>
| 13 | 2009-10-05T10:25:48Z | 1,519,539 | <p>This is quite common, in any largish system. You can use Valgrind's <a href="http://valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles" rel="nofollow">suppression system</a> to explicitly suppress warnings that you're not interested in.</p>
| 2 | 2009-10-05T11:29:16Z | [
"python",
"debugging",
"memory-leaks",
"valgrind",
"python-c-extension"
] |
Is it normal that running python under valgrind shows many errors with memory? | 1,519,276 | <p>I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:</p>
<pre><code>valgrind python -c ""
</code></pre>
<p>Valgrind output full of repeated info like this:</p>
<pre><code>==12317== Invalid read of size 4
==12317== at 0x409CF59: PyObject_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x405C7C7: PyGrammar_RemoveAccelerators (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x410A1EC: Py_Finalize (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4114FD1: Py_Main (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x8048591: main (in /usr/bin/python2.5)
==12317== Address 0x43CD010 is 7,016 bytes inside a block of size 8,208 free'd
==12317== at 0x4022F6C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==12317== by 0x4107ACC: PyArena_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41095D7: PyRun_StringFlags (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40DF262: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4099569: PyCFunction_Call (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E76CC: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E70F3: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E896A: PyEval_EvalCodeEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E8AC2: PyEval_EvalCode (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FD99C: PyImport_ExecCodeModuleEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FFC93: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41002B0: (within /usr/lib/libpython2.5.so.1.0)
</code></pre>
<p>Python 2.5.2 on Slackware 12.2.</p>
<p>Is it normal behavior? If so then valgrind maybe is inappropriate tool for debugging memory errors in Python?</p>
| 13 | 2009-10-05T10:25:48Z | 1,519,598 | <p>You could try using the <a href="http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp">suppression file</a> that comes with the python source</p>
<p>Reading the <a href="http://svn.python.org/projects/python/trunk/Misc/README.valgrind">Python Valgrind README</a> is a good idea too!</p>
| 22 | 2009-10-05T11:45:32Z | [
"python",
"debugging",
"memory-leaks",
"valgrind",
"python-c-extension"
] |
Is it normal that running python under valgrind shows many errors with memory? | 1,519,276 | <p>I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:</p>
<pre><code>valgrind python -c ""
</code></pre>
<p>Valgrind output full of repeated info like this:</p>
<pre><code>==12317== Invalid read of size 4
==12317== at 0x409CF59: PyObject_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x405C7C7: PyGrammar_RemoveAccelerators (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x410A1EC: Py_Finalize (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4114FD1: Py_Main (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x8048591: main (in /usr/bin/python2.5)
==12317== Address 0x43CD010 is 7,016 bytes inside a block of size 8,208 free'd
==12317== at 0x4022F6C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==12317== by 0x4107ACC: PyArena_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41095D7: PyRun_StringFlags (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40DF262: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4099569: PyCFunction_Call (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E76CC: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E70F3: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E896A: PyEval_EvalCodeEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E8AC2: PyEval_EvalCode (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FD99C: PyImport_ExecCodeModuleEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FFC93: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41002B0: (within /usr/lib/libpython2.5.so.1.0)
</code></pre>
<p>Python 2.5.2 on Slackware 12.2.</p>
<p>Is it normal behavior? If so then valgrind maybe is inappropriate tool for debugging memory errors in Python?</p>
| 13 | 2009-10-05T10:25:48Z | 1,832,581 | <p>There is another option I found. James Henstridge has custom build of python which can detect the fact that python running under valgrind and in this case pymalloc allocator is disabled, with PyObject_Malloc/PyObject_Free passing through to normal malloc/free, which valgrind knows how to track.</p>
<p>Package available here: <a href="https://launchpad.net/~jamesh/+archive/python" rel="nofollow">https://launchpad.net/~jamesh/+archive/python</a></p>
| 0 | 2009-12-02T12:20:27Z | [
"python",
"debugging",
"memory-leaks",
"valgrind",
"python-c-extension"
] |
Is it normal that running python under valgrind shows many errors with memory? | 1,519,276 | <p>I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as:</p>
<pre><code>valgrind python -c ""
</code></pre>
<p>Valgrind output full of repeated info like this:</p>
<pre><code>==12317== Invalid read of size 4
==12317== at 0x409CF59: PyObject_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x405C7C7: PyGrammar_RemoveAccelerators (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x410A1EC: Py_Finalize (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4114FD1: Py_Main (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x8048591: main (in /usr/bin/python2.5)
==12317== Address 0x43CD010 is 7,016 bytes inside a block of size 8,208 free'd
==12317== at 0x4022F6C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==12317== by 0x4107ACC: PyArena_Free (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41095D7: PyRun_StringFlags (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40DF262: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x4099569: PyCFunction_Call (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E76CC: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E70F3: PyEval_EvalFrameEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E896A: PyEval_EvalCodeEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40E8AC2: PyEval_EvalCode (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FD99C: PyImport_ExecCodeModuleEx (in /usr/lib/libpython2.5.so.1.0)
==12317== by 0x40FFC93: (within /usr/lib/libpython2.5.so.1.0)
==12317== by 0x41002B0: (within /usr/lib/libpython2.5.so.1.0)
</code></pre>
<p>Python 2.5.2 on Slackware 12.2.</p>
<p>Is it normal behavior? If so then valgrind maybe is inappropriate tool for debugging memory errors in Python?</p>
| 13 | 2009-10-05T10:25:48Z | 1,927,181 | <p>The most correct option is to tell Valgrind that it should intercept Python's allocation functions.
You should patch valgrind/coregrind/m_replacemalloc/vg_replace_malloc.c adding the new interceptors for PyObject_Malloc, PyObject_Free, PyObject_Realloc, e.g.:</p>
<pre><code>ALLOC_or_NULL(NONE, PyObject_Malloc, malloc);
</code></pre>
<p>(note that the soname for users allocation functions should be <code>NONE</code>)</p>
| 1 | 2009-12-18T09:22:51Z | [
"python",
"debugging",
"memory-leaks",
"valgrind",
"python-c-extension"
] |
How do you host your own egg repository? | 1,519,589 | <p>Say you're on a team that's maintaining a lot of internal python libraries(eggs), and for whatever reason uploading them to pypi is not an option. How could you host the libraries(eggs) so that easy_install can still work for the members of your team?</p>
<p>Basically it would be cool if this worked....</p>
<pre><code>(someproj)uberdev@hackmo:~$ easy_install myproprietary.lib-dev
user: uberdev
password:...
fetching......
Searching for myproprietary.lib-dev
Reading http://dev.mycompany.corp/myproprietary.lib-dev
Reading http://dev.mycompany.corp
Reading http://dev.mycompany.corp/dist
Best match: myproprietary.lib-dev
Downloading http://dev.mycompany.corp/dist/myproprietary.lib-dev
</code></pre>
<p>I suppose there's some sort of servers out there that can be installed but I'd appreciate some guidance from the experts on this matter.</p>
<p>Thanks</p>
| 16 | 2009-10-05T11:43:20Z | 1,519,645 | <p>If your team is distributed -- and on speaking terms -- then a simple subversion repository of source is better than some other kind of server.</p>
<p>Simply create projects and have everyone checkout trunk. When things change, tell them to update.</p>
<p>If your team is co-located -- and on speaking terms -- then a shared drive with the "official" libraries also works well. Simply mount it and include it on your <code>PYTHONPATH</code>. </p>
<p>If you want localized copies, provide the official source in subversion (or a shared drive) with a good <code>setup.py</code> file. They simply CD to the directory and run <code>python setup.py install</code> and everything else happens for them. It's a fraction simpler than <code>easy_install</code> because <code>setup.py</code> is already part of the Python distribution.</p>
<p>Eggs are for people who are not on speaking terms. </p>
<p>Your team members usually are on speaking terms and don't need the added complexity of eggs. The basic <code>setup.py</code> should be sufficient.</p>
| 3 | 2009-10-05T11:57:54Z | [
"python"
] |
How do you host your own egg repository? | 1,519,589 | <p>Say you're on a team that's maintaining a lot of internal python libraries(eggs), and for whatever reason uploading them to pypi is not an option. How could you host the libraries(eggs) so that easy_install can still work for the members of your team?</p>
<p>Basically it would be cool if this worked....</p>
<pre><code>(someproj)uberdev@hackmo:~$ easy_install myproprietary.lib-dev
user: uberdev
password:...
fetching......
Searching for myproprietary.lib-dev
Reading http://dev.mycompany.corp/myproprietary.lib-dev
Reading http://dev.mycompany.corp
Reading http://dev.mycompany.corp/dist
Best match: myproprietary.lib-dev
Downloading http://dev.mycompany.corp/dist/myproprietary.lib-dev
</code></pre>
<p>I suppose there's some sort of servers out there that can be installed but I'd appreciate some guidance from the experts on this matter.</p>
<p>Thanks</p>
| 16 | 2009-10-05T11:43:20Z | 1,519,660 | <p>First of all: If the packages are generic packages should be available publicly, not uploading the packages to PyPI is generally a bad idea, as easy_installing a package that depends on your package means your egg server needs to be up and running, as well as PyPI. For every server involved you get more single-point of failures.</p>
<p>But if it's private packages that should not even be listed on PyPI, or packages only useful as a part of a large system, like Plone, it's another matter. Then you want easy___install and buildout etc's to look for eggs on your server. Doing that is quite straighforward. You just put the eggs directory on a webserver and point to that directory with the -f parameter to easy_install.</p>
<p>Here is an example of such a repository: <a href="http://dist.plone.org/release/3.3.1/" rel="nofollow">http://dist.plone.org/release/3.3.1/</a></p>
| 1 | 2009-10-05T12:00:41Z | [
"python"
] |
How do you host your own egg repository? | 1,519,589 | <p>Say you're on a team that's maintaining a lot of internal python libraries(eggs), and for whatever reason uploading them to pypi is not an option. How could you host the libraries(eggs) so that easy_install can still work for the members of your team?</p>
<p>Basically it would be cool if this worked....</p>
<pre><code>(someproj)uberdev@hackmo:~$ easy_install myproprietary.lib-dev
user: uberdev
password:...
fetching......
Searching for myproprietary.lib-dev
Reading http://dev.mycompany.corp/myproprietary.lib-dev
Reading http://dev.mycompany.corp
Reading http://dev.mycompany.corp/dist
Best match: myproprietary.lib-dev
Downloading http://dev.mycompany.corp/dist/myproprietary.lib-dev
</code></pre>
<p>I suppose there's some sort of servers out there that can be installed but I'd appreciate some guidance from the experts on this matter.</p>
<p>Thanks</p>
| 16 | 2009-10-05T11:43:20Z | 1,519,692 | <p>Deploy all your eggs to a directory all devs. can reach (for instance on a webserver).</p>
<p>To install eggs from that directory, type:</p>
<pre><code>$ easy_install -H None -f http://server/vdir TheEggToInstall
</code></pre>
<p>or.</p>
<pre><code>$ easy_install -H None -f /path/to/directory TheEggToInstall
</code></pre>
<p><code>-H None</code> means do not allow egg download from any host (except the one named in <code>-f</code>).</p>
<p>The directory can be reachable over http or can be a directory you mount (NFS, Windows shares etc.). Perhaps even FTP works?</p>
<p>The easy_install <a href="http://peak.telecommunity.com/DevCenter/EasyInstall">documentation</a> has information on this.</p>
| 8 | 2009-10-05T12:07:02Z | [
"python"
] |
How do you host your own egg repository? | 1,519,589 | <p>Say you're on a team that's maintaining a lot of internal python libraries(eggs), and for whatever reason uploading them to pypi is not an option. How could you host the libraries(eggs) so that easy_install can still work for the members of your team?</p>
<p>Basically it would be cool if this worked....</p>
<pre><code>(someproj)uberdev@hackmo:~$ easy_install myproprietary.lib-dev
user: uberdev
password:...
fetching......
Searching for myproprietary.lib-dev
Reading http://dev.mycompany.corp/myproprietary.lib-dev
Reading http://dev.mycompany.corp
Reading http://dev.mycompany.corp/dist
Best match: myproprietary.lib-dev
Downloading http://dev.mycompany.corp/dist/myproprietary.lib-dev
</code></pre>
<p>I suppose there's some sort of servers out there that can be installed but I'd appreciate some guidance from the experts on this matter.</p>
<p>Thanks</p>
| 16 | 2009-10-05T11:43:20Z | 11,961,259 | <p>I use <a href="http://pypi.python.org/pypi/ClueReleaseManager" rel="nofollow">ClueReleaseManager</a></p>
<blockquote>
<p>ClueReleaseManager is an implementation of the PyPi server backend as
provided by <a href="http://pypi.python.org" rel="nofollow">http://pypi.python.org</a>. It uses SQLAlchemy (on top of
sqlite by default) to store all project metadata and the filesystem
for storing project files.</p>
</blockquote>
| 2 | 2012-08-14T21:45:18Z | [
"python"
] |
Provisioning mercurial server | 1,519,785 | <p>I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: </p>
<pre><code> POST /repos
name=foo
</code></pre>
<p>Creates a repository at <code>/repos/foo</code>, which then works as per hgwebdir.cgi. </p>
<p>Does such software exist? If not, any recommendations about how to go about implementing it (I'm OK with python syntax but relatively clueless about the best way of constructing apps like this).</p>
| 1 | 2009-10-05T12:26:23Z | 1,519,890 | <p><a href="http://mercurial.selenic.com/wiki/HgWebDirStepByStep" rel="nofollow">hgwebdir.cgi</a> can get you halfway there, assuming they are already created this is one way to host them. </p>
| 0 | 2009-10-05T12:47:40Z | [
"python",
"mercurial"
] |
Provisioning mercurial server | 1,519,785 | <p>I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: </p>
<pre><code> POST /repos
name=foo
</code></pre>
<p>Creates a repository at <code>/repos/foo</code>, which then works as per hgwebdir.cgi. </p>
<p>Does such software exist? If not, any recommendations about how to go about implementing it (I'm OK with python syntax but relatively clueless about the best way of constructing apps like this).</p>
| 1 | 2009-10-05T12:26:23Z | 1,519,892 | <p>I am not aware of such software, but it would be pretty trivial to create one yourself if you are familiar with web applications and python. </p>
<pre><code>import os
from mercurial import commands,ui
os.mkdir("/repos/foo")
commands.init(ui.ui(),"/repos/foo")
</code></pre>
<p>should do the trick. Of course you need to wrap it inside a nice WSGI script to have the web interface / API</p>
<p>For further info, consult the <a href="http://mercurial.selenic.com/wiki/MercurialApi" rel="nofollow">Mercurial API documentation</a></p>
| 3 | 2009-10-05T12:48:13Z | [
"python",
"mercurial"
] |
Provisioning mercurial server | 1,519,785 | <p>I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: </p>
<pre><code> POST /repos
name=foo
</code></pre>
<p>Creates a repository at <code>/repos/foo</code>, which then works as per hgwebdir.cgi. </p>
<p>Does such software exist? If not, any recommendations about how to go about implementing it (I'm OK with python syntax but relatively clueless about the best way of constructing apps like this).</p>
| 1 | 2009-10-05T12:26:23Z | 1,523,532 | <p>I wrote a cheesy shell CGI to do exactly this awhile ago. Please head the security warnings:</p>
<pre><code>#!/bin/sh
echo -n -e "Content-Type: text/plain\n\n"
mkdir -p /my/repos/$PATH_INFO
cd /my/repos/$PATH_INFO
hg init
</code></pre>
<p>Please heed the security warnings found with <a href="http://ry4an.org/unblog/UnBlog/2009-09-17" rel="nofollow">the full instructions</a>.</p>
| 1 | 2009-10-06T03:59:01Z | [
"python",
"mercurial"
] |
Provisioning mercurial server | 1,519,785 | <p>I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: </p>
<pre><code> POST /repos
name=foo
</code></pre>
<p>Creates a repository at <code>/repos/foo</code>, which then works as per hgwebdir.cgi. </p>
<p>Does such software exist? If not, any recommendations about how to go about implementing it (I'm OK with python syntax but relatively clueless about the best way of constructing apps like this).</p>
| 1 | 2009-10-05T12:26:23Z | 1,527,135 | <p>For those interested in this, I ended up implementing a python CGI script to do something like this, avoiding some security problems by putting the naming of the repo largely in the hands of the server. The code is at <a href="https://bitbucket.org/jimdowning/lf-hg-server/" rel="nofollow">https://bitbucket.org/jimdowning/lf-hg-server/</a>. The main <code>create.py</code> script looks like this: -</p>
<pre><code>#!/usr/bin/env python
from __future__ import with_statement
import cgi
import ConfigParser
from mercurial import commands, ui
import os
import uuid
import cgitb
cgitb.enable()
def bad_request(reason):
print "Content-type: text/html"
print "Status: 400 ", reason
print
print "<html><body><h1>Bad request</h1><p>", reason, "</p></body></html>"
def abs_url(rel, env):
protocol = env["SERVER_PROTOCOL"].partition("/")[0].lower()
host = env["HTTP_HOST"]
return "%s://%s/%s" % (protocol, host, rel)
if not os.environ["REQUEST_METHOD"] == "POST":
bad_request("Method was not POST")
elif not (form.has_key("user")) :
bad_request("Missing parameter - requires 'user' param")
else :
form = cgi.FieldStorage()
user = form["user"].value
lfDir = os.path.dirname( os.environ["SCRIPT_FILENAME"])
id = str(uuid.uuid1())
userDir = os.path.join(lfDir, "repos", user)
rDir = os.path.join(userDir, id)
relPath = "lf/"+ rDir[len(lfDir)+1:]
os.makedirs(rDir)
commands.init(ui.ui(), rDir)
repoUrl = abs_url(relPath, os.environ)
config = ConfigParser.ConfigParser()
config.add_section("web")
config.set("web", "allow_push", "*")
config.set("web", "push_ssl", "false")
with open(os.path.join(rDir, ".hg", "hgrc"), "w+") as f:
config.write(f)
print "Content-Type: text/html\n"
print "Status: 201\nLocation:"
print
print "<html><body><h1>Repository Created</h1>"
print "<p>Created a repo at <a href=\""+ repoUrl + "\">"
print repoUrl+ "</a></p>"
print "</body></html>"
</code></pre>
<p>I stick this script in the same dir as <code>hgwebdir.cgi</code>. The overall functioning of it was made <em>much</em> simpler with some trickery in <code>hgweb.config</code> :-</p>
<pre><code>[collections]
repos/ = repos/
[web]
style = gitweb
</code></pre>
| 1 | 2009-10-06T18:00:37Z | [
"python",
"mercurial"
] |
Provisioning mercurial server | 1,519,785 | <p>I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: </p>
<pre><code> POST /repos
name=foo
</code></pre>
<p>Creates a repository at <code>/repos/foo</code>, which then works as per hgwebdir.cgi. </p>
<p>Does such software exist? If not, any recommendations about how to go about implementing it (I'm OK with python syntax but relatively clueless about the best way of constructing apps like this).</p>
| 1 | 2009-10-05T12:26:23Z | 4,815,421 | <p>have look at <a href="https://bitbucket.org/sdorra/scm-manager" rel="nofollow">https://bitbucket.org/sdorra/scm-manager</a></p>
| 2 | 2011-01-27T10:56:15Z | [
"python",
"mercurial"
] |
NumPy and memmap: [Errno 24] Too many open files | 1,519,956 | <p>I am working with large matrixes, so I am using NumPy's memmap. However, I am getting an error as apparently the file descriptors used by memmap are not being closed.</p>
<pre><code>import numpy
import tempfile
counter = 0
while True:
temp_fd, temporary_filename = tempfile.mkstemp(suffix='.memmap')
map = numpy.memmap(temporary_filename, dtype=float, mode="w+", shape=1000)
counter += 1
print counter
map.close()
os.remove(temporary_filename)
</code></pre>
<p>From what I understand, the memmap file is closed when the method close() is called. However, the code above cannot loop forever, as it eventually throws the "<strong>[Errno 24] Too many open files</strong>" error:</p>
<pre><code> 1016
1017
1018
1019
Traceback (most recent call last):
File "./memmap_loop.py", line 11, in <module>
File "/usr/lib/python2.5/site-packages/numpy/core/memmap.py", line 226, in __new__
EnvironmentError: [Errno 24] Too many open files
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/apport_python_hook.py", line 38, in apport_excepthook
ImportError: No module named packaging_impl
Original exception was:
Traceback (most recent call last):
File "./memmap_loop.py", line 11, in <module>
File "/usr/lib/python2.5/site-packages/numpy/core/memmap.py", line 226, in __new__
EnvironmentError: [Errno 24] Too many open files
</code></pre>
<p>Does anybody know what I am overlooking?</p>
| 5 | 2009-10-05T13:02:10Z | 1,520,156 | <p>Since the memmap does not take the open file descriptor, but the file name, I suppose you leak the <code>temp_fd</code> file descriptor. Does <code>os.close(temp_fd)</code> help?</p>
<p><hr /></p>
<p>Great that it works.</p>
<p>Since you can pass numpy.memmap a file-like object, you could create one from the file descriptor you already have, <code>temp_fd</code>.</p>
<pre><code>fobj = os.fdopen(temp_fd, "w+")
numpy.memmap(fobj, ...
</code></pre>
| 4 | 2009-10-05T13:42:54Z | [
"python",
"memory-management",
"numpy"
] |
Python SQLAlchemy/Elixer Question | 1,520,031 | <p>I am trying to define a SQLAlchemy/Elixer model that can describe the following relationship. I have an SSP table, which has multiple Foreign Keys to the POC table. I've defined the ManyToOne relationships correctly within the SSP object (allowing me to <code>SSP.get(1).action.first_name</code> correctly). What I would also like to add is the other side of this relationship, where I can perform something like <code>POC.get(1).csa</code> and return a list of SSP objects in which this POC is defined as the idPOCCSA.</p>
<p>I know this would be best for a polymorphic association but I really can not change the DB schema at all (creating a new poc2ssp table with a column for <code>type</code> of association).</p>
<pre><code>class POC(Entity):
using_options(tablename = 'poc', autoload = True)
# These two line visually display my "issue":
# csa = OneToMany('SSP')
# action = OneToMany('SSP')
class SSP(Entity):
'''
Many to One Relationships:
- csa: ssp.idPOCCSA = poc.id
- action: ssp.idPOCAction = poc.id
- super: ssp.idSuper = poc.id
'''
using_options(tablename = 'spp', autoload = True)
csa = ManyToOne('POC', colname = 'idPOCCSA')
action = ManyToOne('POC', colname = 'idPOCAction')
super = ManyToOne('POC', colname = 'idPOCSuper')
</code></pre>
<p>Any ideas to accomplish this? The Elixer FAQ has a good example utilizing the primaryjoin and foreign_keys parameters but I can't find them in the documentation. I was kind of hoping OneToMany() just supported a colname parameter like ManyToOne() does. Something a bit less verbose.</p>
| 0 | 2009-10-05T13:18:04Z | 1,520,627 | <p>Try the following:</p>
<pre><code>class POC(Entity):
# ...
#declare the one-to-many relationships
csas = OneToMany('SSP')
actions = OneToMany('SSP')
# ...
class SSP(Entity):
# ...
#Tell Elixir how to disambiguate POC/SSP relationships by specifying
#the inverse explicitly.
csa = ManyToOne('POC', colname = 'idPOCCSA', inverse='csas')
action = ManyToOne('POC', colname = 'idPOCAction', inverse='actions')
# ...
</code></pre>
| 1 | 2009-10-05T14:59:56Z | [
"python",
"orm",
"sqlalchemy",
"python-elixir"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 1,520,264 | <pre><code>>> import numpy
>> print numpy.__version__
</code></pre>
| 122 | 2009-10-05T14:01:19Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 1,520,275 | <pre><code>import numpy
numpy.version.version
</code></pre>
| 174 | 2009-10-05T14:02:58Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 1,958,122 | <p>from the command line, you can simply issue:</p>
<pre><code>python -c "import numpy; print(numpy.version.version)"
</code></pre>
<p>or</p>
<pre><code>python -c "import numpy; print(numpy.__version__)"
</code></pre>
| 25 | 2009-12-24T12:10:38Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 16,904,549 | <p>You can also check if your version is using MKL with:</p>
<pre><code>import numpy
numpy.show_config()
</code></pre>
| 12 | 2013-06-03T19:40:00Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 18,930,126 | <pre><code>numpy.version.version
</code></pre>
<p>type it.</p>
| -6 | 2013-09-21T07:35:34Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 33,469,668 | <p>We can use pip freeze to get any python package version without opening the python shell.</p>
<p><code>pip freeze | grep 'numpy'</code></p>
| 5 | 2015-11-02T02:06:09Z | [
"python",
"numpy"
] |
How to check which version of Numpy I'm using? | 1,520,234 | <p>How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard.</p>
| 118 | 2009-10-05T13:56:50Z | 33,490,162 | <p>For python 3.X print syntax.</p>
<pre><code>python -c "import numpy; print (numpy.version.version)"
</code></pre>
<p>or</p>
<pre><code>python -c "import numpy; print numpy.__version__"
</code></pre>
| 1 | 2015-11-03T01:51:30Z | [
"python",
"numpy"
] |
How to update Numpy on Mac OS X Snow Leopard? | 1,520,379 | <p>How can I update Numpy into the newest one? Should I download .dmg file from here:</p>
<p><a href="http://sourceforge.net/projects/numpy/files/">http://sourceforge.net/projects/numpy/files/</a></p>
<p>Is this .dmg only for 10.5? I have installed numpy using these instructions:</p>
<p><a href="http://www.scipy.org/Installing_SciPy/Mac_OS_X">http://www.scipy.org/Installing_SciPy/Mac_OS_X</a></p>
<p>My current Numpy is 1.2.1. I'm running on Mac OS X 10.6.1 Snow Leopard. Thanks!</p>
| 11 | 2009-10-05T14:17:39Z | 1,520,680 | <p><code>sudo easy_install -U numpy</code></p>
<p>Installing via setuptools will get the new numpy on the sys.path for non-system utilties (I've been told that some Apple utilities rely on the system-numpy). In general, setuptools will "do the right" thing on OS X.</p>
| 25 | 2009-10-05T15:08:08Z | [
"python",
"osx",
"osx-snow-leopard",
"numpy"
] |
How to update Numpy on Mac OS X Snow Leopard? | 1,520,379 | <p>How can I update Numpy into the newest one? Should I download .dmg file from here:</p>
<p><a href="http://sourceforge.net/projects/numpy/files/">http://sourceforge.net/projects/numpy/files/</a></p>
<p>Is this .dmg only for 10.5? I have installed numpy using these instructions:</p>
<p><a href="http://www.scipy.org/Installing_SciPy/Mac_OS_X">http://www.scipy.org/Installing_SciPy/Mac_OS_X</a></p>
<p>My current Numpy is 1.2.1. I'm running on Mac OS X 10.6.1 Snow Leopard. Thanks!</p>
| 11 | 2009-10-05T14:17:39Z | 1,958,059 | <p>as suggested elsewhere, macports works fine on multiple architecture and versions of MacOsX + allows updates and more:</p>
<pre><code>$ port search numpy
py-numpy @1.3.0 (python)
The core utilities for the scientific library scipy for Python
py25-numpy @1.3.0 (python)
The core utilities for the scientific library scipy for Python
py25-symeig @1.4 (python, science)
Symeig - Symmetrical eigenvalue routines for NumPy.
py26-numpy @1.3.0 (python)
The core utilities for the scientific library scipy for Python
py26-scikits-audiolab @0.10.2 (python, science, audio)
Audiolab is a python toolbox to read/write audio files from numpy arrays
Found 5 ports.
$
</code></pre>
<p>in your case, simply issue :</p>
<pre><code>$ sudo port install py26-numpy
</code></pre>
<p>alternatively, if you want / need to compile yourself, the instructions in <a href="http://blog.hyperjeff.net/?p=160" rel="nofollow">HJBlog</a> are very useful. I tested and could easily compile the 64-bit version of matplotlib.</p>
| 4 | 2009-12-24T11:52:31Z | [
"python",
"osx",
"osx-snow-leopard",
"numpy"
] |
How to update Numpy on Mac OS X Snow Leopard? | 1,520,379 | <p>How can I update Numpy into the newest one? Should I download .dmg file from here:</p>
<p><a href="http://sourceforge.net/projects/numpy/files/">http://sourceforge.net/projects/numpy/files/</a></p>
<p>Is this .dmg only for 10.5? I have installed numpy using these instructions:</p>
<p><a href="http://www.scipy.org/Installing_SciPy/Mac_OS_X">http://www.scipy.org/Installing_SciPy/Mac_OS_X</a></p>
<p>My current Numpy is 1.2.1. I'm running on Mac OS X 10.6.1 Snow Leopard. Thanks!</p>
| 11 | 2009-10-05T14:17:39Z | 2,510,572 | <p>For some reason, easy_install -U numpy didn't work.</p>
<pre><code>print numpy.__version__
</code></pre>
<p>would always give 1.2.1</p>
<p>So, I first removed numpy 1.2.1 by finding it and deleting the entire folder:</p>
<pre><code>import numpy
print numpy.__file__
</code></pre>
<p>I downloaded the GNU Fortran Compiler from:</p>
<p><a href="http://r.research.att.com/gfortran-4.2.3.dmg" rel="nofollow">http://r.research.att.com/gfortran-4.2.3.dmg</a></p>
<p>I used easy_install to install numpy.</p>
<p>In retrospect, easy_install -U numpy might have worked if I had the Fortran compiler installed.</p>
| 0 | 2010-03-24T18:54:04Z | [
"python",
"osx",
"osx-snow-leopard",
"numpy"
] |
How to update Numpy on Mac OS X Snow Leopard? | 1,520,379 | <p>How can I update Numpy into the newest one? Should I download .dmg file from here:</p>
<p><a href="http://sourceforge.net/projects/numpy/files/">http://sourceforge.net/projects/numpy/files/</a></p>
<p>Is this .dmg only for 10.5? I have installed numpy using these instructions:</p>
<p><a href="http://www.scipy.org/Installing_SciPy/Mac_OS_X">http://www.scipy.org/Installing_SciPy/Mac_OS_X</a></p>
<p>My current Numpy is 1.2.1. I'm running on Mac OS X 10.6.1 Snow Leopard. Thanks!</p>
| 11 | 2009-10-05T14:17:39Z | 19,387,974 | <p>Use <code>pip install -U numpy</code> instead, as easy_install is deprecated in favor of <code>pip</code></p>
| 1 | 2013-10-15T18:01:41Z | [
"python",
"osx",
"osx-snow-leopard",
"numpy"
] |
Python: Running command line application to the script. Sending parameters in files | 1,520,442 | <p>I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:</p>
<pre><code>$ application -parameter1 -file1
</code></pre>
<p>Here <code>file1</code> is a file which contains my initial data, and <code>parameter1</code> is an unrelated parameter.</p>
<p>The workflow as I see it now is the following:</p>
<pre><code>initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
</code></pre>
<p>I wonder if it's possible to execute this script (called <code>application</code>) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?</p>
| 1 | 2009-10-05T14:28:14Z | 1,520,468 | <p>This depends entirely on the features of the command line program you're calling. If it requires that you give it a filename as a parameter, you'll have to do just that. It could be, though, that if you give it a filename of "-" it will read from stdin. Some programs work that way. You'll need to read the documentation on that program to learn what options you have available to you.</p>
| 0 | 2009-10-05T14:33:23Z | [
"python"
] |
Python: Running command line application to the script. Sending parameters in files | 1,520,442 | <p>I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:</p>
<pre><code>$ application -parameter1 -file1
</code></pre>
<p>Here <code>file1</code> is a file which contains my initial data, and <code>parameter1</code> is an unrelated parameter.</p>
<p>The workflow as I see it now is the following:</p>
<pre><code>initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
</code></pre>
<p>I wonder if it's possible to execute this script (called <code>application</code>) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?</p>
| 1 | 2009-10-05T14:28:14Z | 1,520,655 | <p>You can use the subprocess modul</p>
<p>something like that: </p>
<pre><code>import subprocess
bufsize =1024
initial_data = get_initial_data_from_db()
p = subprocess.Popen("application -parameter1", shell=True, bufsize=bufsize,
stdin=subprocess.PIPE, close_fds=True)
p.stdin.write(initial_data)
print p.communicate()
</code></pre>
<p>! if your application can read from stdin</p>
<p>Testing with Python as Application (in Eclipse) / after remark from Oleg Tarasenko :</p>
<pre><code>import subprocess
initial_data = """
import sys
print sys.path
"""
for test in [1,2,3] :
p = subprocess.Popen("C:/python26/python", shell=True, bufsize=512,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
p.stdin.write(initial_data)
print p.communicate()
</code></pre>
<p>Output:</p>
<pre><code>("['', 'C:\\\\dev\\\\ide\\\\eclipse\\\\plugins\\\\org.python.pydev_1.5.0.1251989166\\\\PySrc\\\\pydev_sitecustomize', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\jython\\\\jython2.5.0\\\\Lib', 'C:\\\\jython\\\\jython2.5.0\\\\Lib\\\\site-packages', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\rt.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jsse.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jce.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\charsets.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\dnsns.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\localedata.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunjce_provider.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunpkcs11.jar', 'C:\\\\WINDOWS\\\\system32\\\\python26.zip', 'C:\\\\python26\\\\DLLs', 'C:\\\\python26\\\\lib', 'C:\\\\python26\\\\lib\\\\plat-win', 'C:\\\\python26\\\\lib\\\\lib-tk', 'C:\\\\python26']\r\n", "'import site' failed; use -v for traceback\r\n")
("['', 'C:\\\\dev\\\\ide\\\\eclipse\\\\plugins\\\\org.python.pydev_1.5.0.1251989166\\\\PySrc\\\\pydev_sitecustomize', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\jython\\\\jython2.5.0\\\\Lib', 'C:\\\\jython\\\\jython2.5.0\\\\Lib\\\\site-packages', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\rt.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jsse.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jce.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\charsets.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\dnsns.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\localedata.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunjce_provider.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunpkcs11.jar', 'C:\\\\WINDOWS\\\\system32\\\\python26.zip', 'C:\\\\python26\\\\DLLs', 'C:\\\\python26\\\\lib', 'C:\\\\python26\\\\lib\\\\plat-win', 'C:\\\\python26\\\\lib\\\\lib-tk', 'C:\\\\python26']\r\n", "'import site' failed; use -v for traceback\r\n")
("['', 'C:\\\\dev\\\\ide\\\\eclipse\\\\plugins\\\\org.python.pydev_1.5.0.1251989166\\\\PySrc\\\\pydev_sitecustomize', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\libs', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jacob.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jiffie.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\jaxen-1.1.1.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\swt.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\script_jy\\\\jars\\\\mysql-connector-java-3.0.17-ga-bin.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\qpslib.jar', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\nlibs\\\\ifxjdbc.jar', 'C:\\\\server\\\\jboss\\\\client\\\\jbossall-client.jar', 'C:\\\\usr\\\\local\\\\machine', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol\\\\config', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src\\\\build\\\\components\\\\jobcontrol', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\event\\\\src', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\oknos\\\\tickcardimp\\\\bin', 'C:\\\\dev\\\\ws\\\\central\\\\head\\\\common\\\\jar\\\\shared.jar', 'C:\\\\jython\\\\jython2.5.0\\\\Lib', 'C:\\\\jython\\\\jython2.5.0\\\\Lib\\\\site-packages', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\rt.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jsse.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\jce.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\charsets.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\dnsns.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\localedata.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunjce_provider.jar', 'C:\\\\dev\\\\java\\\\jdk1.5.0_17\\\\jre\\\\lib\\\\ext\\\\sunpkcs11.jar', 'C:\\\\WINDOWS\\\\system32\\\\python26.zip', 'C:\\\\python26\\\\DLLs', 'C:\\\\python26\\\\lib', 'C:\\\\python26\\\\lib\\\\plat-win', 'C:\\\\python26\\\\lib\\\\lib-tk', 'C:\\\\python26']\r\n", "'import site' failed; use -v for traceback\r\n")
</code></pre>
| 1 | 2009-10-05T15:04:49Z | [
"python"
] |
Python: Running command line application to the script. Sending parameters in files | 1,520,442 | <p>I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:</p>
<pre><code>$ application -parameter1 -file1
</code></pre>
<p>Here <code>file1</code> is a file which contains my initial data, and <code>parameter1</code> is an unrelated parameter.</p>
<p>The workflow as I see it now is the following:</p>
<pre><code>initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
</code></pre>
<p>I wonder if it's possible to execute this script (called <code>application</code>) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?</p>
| 1 | 2009-10-05T14:28:14Z | 1,520,690 | <p>Bryan Oakley is correct, a lot of this depends on the capabilities of the called application. But if it can't directly take stdin, there might be another way. If you're on a Unix-like system, you might be able to replace the temporary file with a <a href="http://www.linuxjournal.com/article/2156" rel="nofollow">named pipe</a>. <a href="http://en.wikipedia.org/wiki/Named%5Fpipe" rel="nofollow">Wikipedia</a> claims Windows has similar functionality, but I'm not familiar with it. This may require kicking off the application from another Python thread.</p>
| 0 | 2009-10-05T15:09:19Z | [
"python"
] |
Python: Running command line application to the script. Sending parameters in files | 1,520,442 | <p>I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:</p>
<pre><code>$ application -parameter1 -file1
</code></pre>
<p>Here <code>file1</code> is a file which contains my initial data, and <code>parameter1</code> is an unrelated parameter.</p>
<p>The workflow as I see it now is the following:</p>
<pre><code>initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
</code></pre>
<p>I wonder if it's possible to execute this script (called <code>application</code>) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?</p>
| 1 | 2009-10-05T14:28:14Z | 1,520,747 | <p>As an additional idea, you could use the built in <a href="http://docs.python.org/library/tempfile.html" rel="nofollow">temp file that Python has built in</a>. I'm not extremely familiar with Python or this feature but I wanted to share this idea. </p>
<p>You'd still be writing a file out and executing the client program in the same fashion. But, this way, Python manages the clean up for you which might solve your question enough to not need to worry about a more complicated implementation. </p>
| 0 | 2009-10-05T15:23:02Z | [
"python"
] |
Python: Running command line application to the script. Sending parameters in files | 1,520,442 | <p>I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:</p>
<pre><code>$ application -parameter1 -file1
</code></pre>
<p>Here <code>file1</code> is a file which contains my initial data, and <code>parameter1</code> is an unrelated parameter.</p>
<p>The workflow as I see it now is the following:</p>
<pre><code>initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
</code></pre>
<p>I wonder if it's possible to execute this script (called <code>application</code>) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?</p>
| 1 | 2009-10-05T14:28:14Z | 1,524,247 | <p>if you are on linux, you can try passing /dev/stdin as the file which works the same as using "-" but supports programs that don't know about "-"</p>
| 0 | 2009-10-06T08:15:59Z | [
"python"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,520,575 | <p>Maybe I'm missing something obvious but what about this:</p>
<pre><code>def f():
s = """123456"""
return s
</code></pre>
<p>or simply this:</p>
<pre><code>def f():
s = "123456"
return s
</code></pre>
<p>or even simpler:</p>
<pre><code>def f():
return "123456"
</code></pre>
<p>If that doesn't answer your question, then please clarify what the question is about.</p>
| 4 | 2009-10-05T14:52:40Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,520,579 | <pre><code>re.sub('\D+', '', s)
</code></pre>
<p>will return a string, if you want an integer, convert this string with <code>int</code>.</p>
| -1 | 2009-10-05T14:53:07Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,520,580 | <p>Try</p>
<pre><code>import re
</code></pre>
<p>and then</p>
<pre><code> return re.sub("\s+", "", s)
</code></pre>
| -1 | 2009-10-05T14:53:08Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,520,623 | <p>My guess is:</p>
<pre><code>def f():
s = """123
456"""
return u'123456'
</code></pre>
<p>Minimum change and does what is asked for.</p>
| -3 | 2009-10-05T14:59:29Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,520,704 | <pre><code>def f():
s = """123\
456"""
return s
</code></pre>
<p>Don't indent any of the blockquote lines after the first line; end every line except the last with a backslash.</p>
| 13 | 2009-10-05T15:12:28Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,521,159 | <p>Subsequent strings are concatenated, so you can use:</p>
<pre><code>def f():
s = ("123"
"456")
return s
</code></pre>
<p>This will allow you to keep indention as you like.</p>
| 12 | 2009-10-05T16:47:14Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 1,521,440 | <p>Don't use a triple-quoted string when you don't want extra whitespace, tabs and newlines.</p>
<p>Use implicit continuation, it's more elegant:</p>
<pre><code>def f():
s = ('123'
'456')
return s
</code></pre>
| 40 | 2009-10-05T17:46:54Z | [
"python",
"string"
] |
How does Python's triple-quote string work? | 1,520,548 | <p>How should this function be changed to return <code>"123456"</code>?</p>
<pre><code>def f():
s = """123
456"""
return s
</code></pre>
<p>UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the <code>re</code> module.</p>
| 17 | 2009-10-05T14:49:04Z | 6,133,466 | <pre><code>textwrap.dedent("""\
123
456""")
</code></pre>
<p>From the standard library. First "\" is necessary because this function works by removing the common leading whitespace.</p>
| 6 | 2011-05-26T03:50:14Z | [
"python",
"string"
] |
Getting proper code completion for Python on Vim? | 1,520,576 | <p>I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.</p>
<p>I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent. </p>
<p>Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?</p>
| 4 | 2009-10-05T14:52:40Z | 1,520,822 | <p>Try hitting Ctrl-p while typing mid-word. Ctrl-p inserts the most recent word that starts with the prefix you're typing and Ctrl-n inserts the next match. If you have several possibilities, you can hit ctrl-p more than once to substitute each candidate in order.</p>
| 0 | 2009-10-05T15:35:21Z | [
"python",
"vim"
] |
Getting proper code completion for Python on Vim? | 1,520,576 | <p>I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.</p>
<p>I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent. </p>
<p>Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?</p>
| 4 | 2009-10-05T14:52:40Z | 1,520,897 | <p>You may try <a href="http://www.vim.org/scripts/script.php?script%5Fid=850" rel="nofollow">Pydiction</a> (Excerpt below)</p>
<blockquote>
<p><strong>Description</strong> Pydiction allows you to
Tab-complete Python code in Vim,
including: standard, custom and
third-party modules and packages. Plus
keywords, built-ins, and string
literals.</p>
</blockquote>
| 2 | 2009-10-05T15:52:11Z | [
"python",
"vim"
] |
Getting proper code completion for Python on Vim? | 1,520,576 | <p>I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.</p>
<p>I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent. </p>
<p>Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?</p>
| 4 | 2009-10-05T14:52:40Z | 1,523,392 | <p>There's also <code>Ctrl+n</code> in insert mode which will autocomplete based on the words it has seen in any of the open buffers (even in other tabs). </p>
| 4 | 2009-10-06T03:04:59Z | [
"python",
"vim"
] |
Getting proper code completion for Python on Vim? | 1,520,576 | <p>I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again.</p>
<p>I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent. </p>
<p>Can someone post a full, step-by-step tutorial on how to get code completion working properly, for complete Vim newbies (for dummies?)?</p>
| 4 | 2009-10-05T14:52:40Z | 1,558,148 | <p><a href="https://launchpad.net/pyflakes" rel="nofollow">Pyflakes</a> has a <a href="http://www.vim.org/scripts/script.php?script%5Fid=2441" rel="nofollow">vim plugin</a> that does this pretty awesomely. Unlike Pydiction, you don't need to build a dictionary beforehand (so if you're bouncing between different virtualenvs it's a bit less hassle.) I haven't been using it long but it seems very slick.</p>
| 1 | 2009-10-13T04:05:25Z | [
"python",
"vim"
] |
Compile pyme for Python 2.6 | 1,520,646 | <p>Has anyone been able to compile pyme (<a href="http://sourceforge.net/projects/pyme/" rel="nofollow">http://sourceforge.net/projects/pyme/</a>)</p>
<p>I installed mingw32 and I can compile other modules like pycrypto without issues, but pyme is proving to be a real pain in the you know what :-)</p>
| 0 | 2009-10-05T15:02:22Z | 1,522,700 | <p>I also struggled with pyme for a while, then gave up and created <a href="http://code.google.com/p/python-gnupg/" rel="nofollow">python-gnupg</a>. If you don't get any joy with pyme, feel free to take a look at it.</p>
| 0 | 2009-10-05T22:20:35Z | [
"python"
] |
Python Fixed Length Packet | 1,520,765 | <p>I am trying to build a fixed length packet in python for an ATSC PSIP generator. This is probably very simple but so far I can't seem to get it to work. I am trying to build a packet with fields similar to the following:</p>
<pre><code>table_id = 0xCB
syntax = 0b1
reserved = 0b11
table_ext = 0xFF
</code></pre>
<p>the end goal would be the following in binary</p>
<pre><code>'1100101111111111111'
</code></pre>
<p>I have tried a dozen different things and can't get the results I would expect.
I am going to send this via sockets so I believe it needs to end up in a string.</p>
| 2 | 2009-10-05T15:26:34Z | 1,520,795 | <p>You can use the <a href="http://docs.python.org/library/struct.html" rel="nofollow"><code>struct</code> module</a> to build binary strings from arbitrary layouts.</p>
<p>That can only generate byte-aligned structures, but you'll need to be byte aligned to send on the network socket anyway.</p>
<p>EDIT:</p>
<p>So the format you're generating really does have non-aligned bits 8-1-1-2-12-16 etc.</p>
<p>In order to send on a socket you'll need to be byte aligned, but I guess that the protocol handles that some how. (maybe with padding bits somewhere?)</p>
<p>My new suggestion would be to build up a bit string, then chop it up into 8-bit blocks and convert from there:</p>
<pre><code>input_binary_string = "110010111111111111101010" ## must be a multiple of 8
out = []
while len(input_binary_string) >= 8:
byte = input_binary_string[:8]
input_binary_string = input_binary_string[8:]
b = int(byte,2)
c = chr(b)
out.append(c)
## Better not have a bits left over
assert len(input_binary_string) == 0
outString = "".join(out)
print [ ord(c) for c in out ]
</code></pre>
| 4 | 2009-10-05T15:31:43Z | [
"python",
"sockets",
"binary"
] |
Python Fixed Length Packet | 1,520,765 | <p>I am trying to build a fixed length packet in python for an ATSC PSIP generator. This is probably very simple but so far I can't seem to get it to work. I am trying to build a packet with fields similar to the following:</p>
<pre><code>table_id = 0xCB
syntax = 0b1
reserved = 0b11
table_ext = 0xFF
</code></pre>
<p>the end goal would be the following in binary</p>
<pre><code>'1100101111111111111'
</code></pre>
<p>I have tried a dozen different things and can't get the results I would expect.
I am going to send this via sockets so I believe it needs to end up in a string.</p>
| 2 | 2009-10-05T15:26:34Z | 23,330,545 | <p>Construct (<a href="http://construct.readthedocs.org/en/latest/" rel="nofollow">http://construct.readthedocs.org/en/latest/</a>) is a parser and builder for binary data. It does look to be ideal for this application, as you can define things from bits and bytes. It also looks to have useful features like handling conditional situations as well as easily checking for terminators and the like. </p>
<p>I've spent years using a system for complicated packet creation and parsing that didn't have some of the features that Construct has, so unless there's something particularly odd either in the protocol, it looks like Construct will handle it.</p>
| 0 | 2014-04-28T00:02:35Z | [
"python",
"sockets",
"binary"
] |
Basic Comet in Python using just std lib | 1,520,953 | <p>I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet.</p>
<p>Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applications like Jetty or StreamHub.</p>
<p>Without going too much deeper in this, I'd like to know is there's a chance to implement Comet-like communication using just standard lib modules like BaseHTTPServer and keep things as simple as possible as I don't need so much power and efficiency.</p>
<p>Note: Jython is a possibility, but I'd like to keep it with as less requirements as possible.</p>
| 1 | 2009-10-05T16:04:08Z | 1,520,980 | <p>This is possible. Just don't close the connection to the client.</p>
| 0 | 2009-10-05T16:11:22Z | [
"python",
"comet"
] |
Basic Comet in Python using just std lib | 1,520,953 | <p>I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet.</p>
<p>Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applications like Jetty or StreamHub.</p>
<p>Without going too much deeper in this, I'd like to know is there's a chance to implement Comet-like communication using just standard lib modules like BaseHTTPServer and keep things as simple as possible as I don't need so much power and efficiency.</p>
<p>Note: Jython is a possibility, but I'd like to keep it with as less requirements as possible.</p>
| 1 | 2009-10-05T16:04:08Z | 1,521,048 | <p>As gs said, just keep the connection open.</p>
<p>Here's an example WSGI app that sends the current time to the client every second:</p>
<pre><code>import time
def application(environ, start_response):
start_response('200 OK', [('content-type', 'text/plain')])
while True:
time.sleep(1.0)
yield time.ctime() + '\n'
if __name__ == '__main__':
from wsgiref.simple_server import make_server
print "Serving on http://localhost:4000..."
make_server('localhost', 4000, application).serve_forever()
</code></pre>
<p>If I go to the URL in my browser, I see this:</p>
<pre><code>Mon Oct 05 12:21:26 2009
Mon Oct 05 12:21:27 2009
Mon Oct 05 12:21:28 2009
Mon Oct 05 12:21:29 2009
Mon Oct 05 12:21:30 2009
(...a new line appears every second...)
</code></pre>
<p>The problem with this approach is that you can't keep very many connections like this open at the same time. In fact, the <code>wsgiref</code> server is single-threaded, so you can only have one connection open at any time. If this is a problem then you must use a multithreaded (e.g. CherryPy) or non-blocking server (e.g. Twisted, Tornado, etc.).</p>
| 4 | 2009-10-05T16:23:43Z | [
"python",
"comet"
] |
Basic Comet in Python using just std lib | 1,520,953 | <p>I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet.</p>
<p>Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applications like Jetty or StreamHub.</p>
<p>Without going too much deeper in this, I'd like to know is there's a chance to implement Comet-like communication using just standard lib modules like BaseHTTPServer and keep things as simple as possible as I don't need so much power and efficiency.</p>
<p>Note: Jython is a possibility, but I'd like to keep it with as less requirements as possible.</p>
| 1 | 2009-10-05T16:04:08Z | 1,751,708 | <p>Extending what lost-theory has said, if you want to use comet for a passing messages between clients then you need to implement something like pubsub.</p>
<p>Using something like tornado for the pubsub is much simpler than with the single threaded wsgiref servers.</p>
| 0 | 2009-11-17T20:56:36Z | [
"python",
"comet"
] |
Is it possible to reduce an image's depth using PIL? | 1,521,058 | <p>Is it possible to reduce the depth of an image using PIL? Say like going to 4bpp from a regular 8bpp.</p>
| 4 | 2009-10-05T16:26:56Z | 1,521,175 | <p>You can easily convert image modes (just call <code>im.convert(newmode)</code> on an image object <code>im</code>, it will give you a new image of the new required mode), but there's no mode for "4bpp"; the modes supported are listed <a href="http://effbot.org/imagingbook/concepts.htm" rel="nofollow">here</a> in the <a href="http://effbot.org/imagingbook/" rel="nofollow"><em>The Python Imaging Library Handbook</em></a>.</p>
| 6 | 2009-10-05T16:49:27Z | [
"python",
"image-processing",
"python-imaging-library"
] |
Is it possible to reduce an image's depth using PIL? | 1,521,058 | <p>Is it possible to reduce the depth of an image using PIL? Say like going to 4bpp from a regular 8bpp.</p>
| 4 | 2009-10-05T16:26:56Z | 29,192,668 | <p>This can be done using the <strong>changeColorDepth</strong> function in <strong>ufp.image</strong> module.
this function only can reduce color depth(bpp)</p>
<pre><code>import ufp.image
import PIL
im = PIL.Image.open('test.png')
ufp.image.changeColorDepth(im, 16) # change to 4bpp(this function change original PIL.Image object)
im.save('changed.png')
</code></pre>
<p>see example : <a href="http://runnable.com/VQ5o_OpMIyQdA6zE/image-quantize-by-improved-gray-scale-for-python" rel="nofollow"> image quantize by Improved Gray Scale. [Python] </a></p>
| 0 | 2015-03-22T09:11:35Z | [
"python",
"image-processing",
"python-imaging-library"
] |
What is a good size (in bytes) for a log file? | 1,521,082 | <p>I am using the python <a href="http://docs.python.org/library/logging.html#simple-examples">logging</a> modules <a href="http://docs.python.org/library/logging.html#rotatingfilehandler">RotatingFileHandler</a>, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes.</p>
| 13 | 2009-10-05T16:32:49Z | 1,521,108 | <p>It completely depends on the external variables of the system. For instance:</p>
<ul>
<li>Are you running on an embedded device whose only external storage is a 1MB SD card, or do you have full access to a 1TB hard drive?</li>
<li>Are you logging each time you enter/exit a function, or are you only logging one or two caught exceptions throughout the whole system?</li>
<li>Is the purpose of these logs to be sent back to the developer for support? A 1kb log file isn't going to help you much, but you probably don't need 200MB of logs for a single support issue.</li>
</ul>
<p>Without these kinds of details, there is no good answer to your question (and there might not be a good answer even <em>with</em> these details).</p>
| 2 | 2009-10-05T16:36:28Z | [
"python",
"logging"
] |
What is a good size (in bytes) for a log file? | 1,521,082 | <p>I am using the python <a href="http://docs.python.org/library/logging.html#simple-examples">logging</a> modules <a href="http://docs.python.org/library/logging.html#rotatingfilehandler">RotatingFileHandler</a>, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes.</p>
| 13 | 2009-10-05T16:32:49Z | 1,521,111 | <p>Size isn't as important to me as <strong>dividing at sensible chronological points</strong>. I prefer one log file per day, however, if the file won't open with any notepad program you have at your disposal, it is too big and you might want to go with hourly logs.</p>
| 7 | 2009-10-05T16:37:05Z | [
"python",
"logging"
] |
What is a good size (in bytes) for a log file? | 1,521,082 | <p>I am using the python <a href="http://docs.python.org/library/logging.html#simple-examples">logging</a> modules <a href="http://docs.python.org/library/logging.html#rotatingfilehandler">RotatingFileHandler</a>, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes.</p>
| 13 | 2009-10-05T16:32:49Z | 1,521,144 | <p>As the other answers have said, there is a no hard and fast answer. It depends so much on your app and your environment. Here's some guidelines I use.</p>
<p>For a multi-user app on a typical server:
Configure your logging to generate no more than 1 or 2 entries per user action for production, and then rotate it daily. Keep as many days as you have disk space for, or your data retention/privacy policies allow for. If you want auditing, you probably want a separate solution.</p>
<p>For a single-user app:
Try and keep enough information to diagnose anything weird that might happen. No more than 2 or 3 entries per user action though, unless you are doing batch operations. Don't put more than 2MB in a file, so the user can email it you. Don't keep more than 50MB of logs, because it's probably not your space you are wasting here.</p>
| 6 | 2009-10-05T16:43:50Z | [
"python",
"logging"
] |
What is a good size (in bytes) for a log file? | 1,521,082 | <p>I am using the python <a href="http://docs.python.org/library/logging.html#simple-examples">logging</a> modules <a href="http://docs.python.org/library/logging.html#rotatingfilehandler">RotatingFileHandler</a>, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes.</p>
| 13 | 2009-10-05T16:32:49Z | 1,521,531 | <p>My default logging setup:</p>
<pre><code>RotatingFileHandler(filename, maxBytes=10*1024*1024, backupCount=5)
</code></pre>
| 8 | 2009-10-05T18:05:59Z | [
"python",
"logging"
] |
How do you know when two objects can communicate? | 1,521,368 | <pre><code>class GuiMaker(Frame):
#more code
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH) # make frame stretchable
self.start() # for subclass: set menu/toolBar
self.makeMenuBar() # done here: build menu-bar
self.makeToolBar() # done here: build tool-bar
self.makeWidgets() # for subclass: add middle part
#more code
class TextEditor:
#more code
def start(self):
#more code
</code></pre>
<p>How come self.start() will call TextEditor's start if self refers to GuiMaker or else how come self refers to TextEditor?</p>
| 1 | 2009-10-05T17:32:32Z | 1,521,398 | <p>Does <code>GuiMaker</code> inherit from <code>TextEditor</code> somewhere? In other words is Frame a descendant of <code>TextEditor</code>? That would cause <code>TextEditor</code>'s start method to be called.</p>
<p>Other than that, I don't see any way for the code (as written) to have <code>GuiMaker.start</code> call <code>TextEditor.start</code></p>
| 5 | 2009-10-05T17:38:23Z | [
"python",
"class",
"object"
] |
Get Root Domain of Link | 1,521,592 | <p>I have a link such as <a href="http://www.techcrunch.com/">http://www.techcrunch.com/</a> and I would like to get just the techcrunch.com part of the link. How do I go about this in python?</p>
| 10 | 2009-10-05T18:16:12Z | 1,521,695 | <p>Getting the hostname is easy enough using <a href="http://docs.python.org/library/urlparse.html">urlparse</a>:</p>
<pre><code>hostname = urlparse.urlparse("http://www.techcrunch.com/").hostname
</code></pre>
<p>Getting the "root domain", however, is going to be more problematic, because it isn't defined in a syntactic sense. What's the root domain of "www.theregister.co.uk"? How about networks using default domains? "devbox12" could be a valid hostname.</p>
<p>For the most common cases, however, you can probably handle the former specially and ignore the latter, but aware that it won't 100% accurate.</p>
<pre><code>hostname = urlparse.urlparse(url).hostname.split(".")
hostname = ".".join(len(hostname[-2]) < 4 and hostname[-3:] or hostname[-2:])
</code></pre>
<p>This uses the last three parts if the next-to-last part is less than four characters (e.g. ".com.au", ".co.uk") and the last two parts otherwise.</p>
| 20 | 2009-10-05T18:35:45Z | [
"python",
"regex",
"dns",
"root"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.