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>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
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 ...
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>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
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>&gt;&gt;&gt; from statistics import mode &gt;&gt;&gt; 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>&gt;&gt;&gt; most_common(['duck', 'duck', 'goose']) 'duck' &gt;&gt;&gt; mos...
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> &gt;...
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> &gt;...
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%5Fe...
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> &gt;...
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.wordpres...
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> &gt;...
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 *j...
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 &gt; python al...
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 &gt; python al...
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") &lt;shell&gt;$ 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 &gt; python al...
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):...
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 &gt; python al...
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....
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 &gt; python al...
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>t...
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 &gt; python al...
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.ma...
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 &gt; python al...
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>...
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 &gt; python al...
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 &gt; python al...
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 , "mi...
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...
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...
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...
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 plugge...
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...
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 ...
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...
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 scrip...
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...
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 ...
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...
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 ...
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...
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 lik...
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, v...
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 lik...
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. Cons...
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 lik...
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[...
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 lik...
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 e...
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 fiel...
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 e...
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 poi...
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 e...
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 l...
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 e...
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.</...
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 e...
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 e...
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> <blockq...
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 check...
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 dep...
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 check...
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 check...
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 transla...
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 accompl...
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(): """ad...
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 accompl...
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...
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...
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 c...
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...
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>==12...
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...
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>==12...
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>==12...
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>==12...
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 avail...
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>==12...
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, PyOb...
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><...
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 -- the...
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><...
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...
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><...
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 </c...
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><...
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 s...
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....
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....
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 nee...
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....
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/un...
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....
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/jimdo...
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....
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 = n...
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...
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 wo...
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', ...
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>&gt;&gt; import numpy &gt;&gt; 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...
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...
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 ...
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...
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 ...
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...
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 fi...
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 documentat...
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 fi...
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...
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 fi...
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">na...
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 fi...
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 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 fi...
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'...
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 c...
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 c...
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...
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 c...
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 c...
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 virtua...
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> <...
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 ...
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> <...
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 co...
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 the...
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 the...
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) y...
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 the...
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...
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....
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 giv...
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 ...
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 giv...
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 giv...
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 d...
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 giv...
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() ...
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...
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 synta...
20
2009-10-05T18:35:45Z
[ "python", "regex", "dns", "root" ]