title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Are there any good 3rd party GUI products for Python?
449,168
<p>In .Net you have companies like DevEpxress, and Infragistics that offer a range of GUI widgets. Is there any market like that for Python GUI widgets? I'm thinking specifically about widgets like the DevExpress xtraGrid Suite.</p> <p>Edit 01-16-09: For Example:</p> <p><a href="http://www.devexpress.com/Downloads...
5
2009-01-16T01:11:49Z
23,121,183
<p>I don't see any commercial packages for GUI in Python but as I know Kivy is a good option for creating fast and beautiful GUI <a href="https://github.com/kivy/kivy" rel="nofollow">https://github.com/kivy/kivy</a></p>
0
2014-04-16T22:20:01Z
[ "python", "user-interface" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
449,707
<p>First: an answer.</p> <pre><code>import sys try: print sys.getsizeof(object) except AttributeError: print "sys.getsizeof exists in Python ≥2.6" </code></pre> <p>Discussion:<br /> In Python, you cannot ever access "direct" memory addresses. Why, then, would you need or want to know how many such addresses a...
2
2009-01-16T06:58:40Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
450,034
<p>Just use the <a href="http://docs.python.org/library/sys.html#sys.getsizeof">sys.getsizeof</a> function defined in the <code>sys</code> module.</p> <blockquote> <p><code>sys.getsizeof(object[, default])</code>:</p> <p>Return the size of an object in bytes. The object can be any type of object. All built-...
316
2009-01-16T10:42:37Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
450,351
<p>This can be more complicated than it looks depending on how you want to count things. For instance, if you have a list of ints, do you want the size of the list containing the <em>references</em> to the ints? (ie. list only, not what is contained in it), or do you want to include the actual data pointed to, in whic...
11
2009-01-16T13:00:14Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
3,373,511
<p>For numpy arrays, <code>getsizeof</code> doesn't work - for me it always returns 40 for some reason:</p> <pre><code>from pylab import * from sys import getsizeof A = rand(10) B = rand(10000) </code></pre> <p>Then (in ipython):</p> <pre><code>In [64]: getsizeof(A) Out[64]: 40 In [65]: getsizeof(B) Out[65]: 40 </c...
60
2010-07-30T16:33:00Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
15,207,478
<p>Here is a quick script I wrote based on the previous answers to list sizes of all variables</p> <pre><code>for i in dir(): try: print (i, eval(i).nbytes ) except: print (i, sys.getsizeof(eval(i)) ) </code></pre>
4
2013-03-04T17:34:04Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
30,316,760
<blockquote> <h1>How do I determine the size of an object in Python?</h1> </blockquote> <p>The answer, "Just use sys.getsizeof" is not a complete answer. </p> <p>That answer <em>does</em> work for builtin objects directly, but it does not account for what those objects may contain, specifically, what types, such as...
88
2015-05-19T04:26:33Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
31,388,142
<p>In case anyone comes across this question and needs a more "bulletproof" solution than sys.getsizeof or the procedure provided by Aaron Hall, there is a recipe <a href="http://code.activestate.com/recipes/546530-size-of-python-objects-revised/" rel="nofollow">here</a> that attempts to deal with issues such as classe...
3
2015-07-13T16:02:05Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
33,631,772
<p>There is a module called <a href="https://pypi.python.org/pypi/Pympler" rel="nofollow">Pympler</a> which contains the <code>asizeof</code> module.</p> <p>Use as follows:</p> <pre><code>from pympler import asizeof asizeof.asizeof(my_object) </code></pre> <p>Unlike <code>sys.getsizeof</code>, it <strong>works for y...
4
2015-11-10T14:01:35Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
How do I determine the size of an object in Python?
449,560
<p>In C, we can find the size of an <code>int</code>, <code>char</code>, etc. I want to know how to get size of objects like a string, integer, etc. in Python.</p> <p>Related question: <a href="http://stackoverflow.com/questions/135664/how-many-bytes-per-element-are-there-in-a-python-list-tuple">How many bytes per ele...
271
2009-01-16T05:07:12Z
38,515,297
<p>Having run into this problem many times myself, I wrote up a small function (inspired by @aaron-hall's answer) &amp; tests that does what I would have expected sys.getsizeof to do:</p> <p><a href="https://github.com/bosswissam/pysize" rel="nofollow">https://github.com/bosswissam/pysize</a></p> <p>If you're interes...
3
2016-07-21T22:21:07Z
[ "python", "object", "memory", "memory-management", "sizeof" ]
Is there a tool for converting VB to a scripting language, e.g. Python or Ruby?
449,734
<p>I've discovered <a href="http://vb2py.sourceforge.net/" rel="nofollow">VB2Py</a>, but it's been silent for almost 5 years. Are there any other tools out there which could be used to convert VB6 projects to Python, Ruby, Tcl, whatever?</p>
2
2009-01-16T07:09:38Z
449,779
<p>I doubt there would be a good solution for that since VB6 relies too much on the windows API and VBRun libraries though you could translate code that does something else besides GUI operations</p> <p>Is there something special you need to do with that code? You could compile your VB6 functionality and expose it as ...
3
2009-01-16T07:47:53Z
[ "python", "vb6" ]
Is there a tool for converting VB to a scripting language, e.g. Python or Ruby?
449,734
<p>I've discovered <a href="http://vb2py.sourceforge.net/" rel="nofollow">VB2Py</a>, but it's been silent for almost 5 years. Are there any other tools out there which could be used to convert VB6 projects to Python, Ruby, Tcl, whatever?</p>
2
2009-01-16T07:09:38Z
449,789
<p>Compile the VB code either into a normal DLL or a COM DLL. All Pythons on Windows, including the vanilla ActivePython distribution (IronPython isn't required) can connect to both types of DLLs.</p> <p>I think this is your best option. As Gustavo said, finding something that will compile arbitrary VB6 code into Pyt...
3
2009-01-16T07:56:30Z
[ "python", "vb6" ]
Is there a tool for converting VB to a scripting language, e.g. Python or Ruby?
449,734
<p>I've discovered <a href="http://vb2py.sourceforge.net/" rel="nofollow">VB2Py</a>, but it's been silent for almost 5 years. Are there any other tools out there which could be used to convert VB6 projects to Python, Ruby, Tcl, whatever?</p>
2
2009-01-16T07:09:38Z
450,198
<p>Generally, Python is much, much more expressive than VB. Things which took many lines of code in VB can be represented more simply in Python.</p> <p>If the VB is truly epic in scale, a manual rewrite may be hard. But maintaining VB6 may be just as hard. </p> <p>If the VB is intimately tied to Windows GUI presen...
1
2009-01-16T11:57:25Z
[ "python", "vb6" ]
How can I split a url string up into separate parts in Python?
449,775
<p>I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:</p> <p><a href="http://example.com/random/folder/path.html">http://example.com/...
9
2009-01-16T07:43:22Z
449,782
<p>I have no experience with python, but I found the urlparse module, which should do the job:</p> <p><a href="http://docs.python.org/library/urlparse.html">http://docs.python.org/library/urlparse.html</a></p>
8
2009-01-16T07:49:55Z
[ "python", "url", "parsing" ]
How can I split a url string up into separate parts in Python?
449,775
<p>I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:</p> <p><a href="http://example.com/random/folder/path.html">http://example.com/...
9
2009-01-16T07:43:22Z
449,800
<p>In Python a lot of operations are done using lists. The urlparse module mentioned by Sebasian Dietz may well solve your specific problem, but if you're generally interested in Pythonic ways to find slashes in strings, for example, try something like this:</p> <pre><code>url = 'http://example.com/random/folder/path...
5
2009-01-16T08:08:32Z
[ "python", "url", "parsing" ]
How can I split a url string up into separate parts in Python?
449,775
<p>I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:</p> <p><a href="http://example.com/random/folder/path.html">http://example.com/...
9
2009-01-16T07:43:22Z
449,805
<p>If this is the extent of your URL parsing, Python's inbuilt rpartition will do the job:</p> <pre><code>&gt;&gt;&gt; URL = "http://example.com/random/folder/path.html" &gt;&gt;&gt; Segments = URL.rpartition('/') &gt;&gt;&gt; Segments[0] 'http://example.com/random/folder' &gt;&gt;&gt; Segments[2] 'path.html' </code><...
8
2009-01-16T08:11:11Z
[ "python", "url", "parsing" ]
How can I split a url string up into separate parts in Python?
449,775
<p>I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:</p> <p><a href="http://example.com/random/folder/path.html">http://example.com/...
9
2009-01-16T07:43:22Z
449,811
<p>The urlparse module in python 2.x (or urllib.parse in python 3.x) would be the way to do it.</p> <pre><code>&gt;&gt;&gt; from urllib.parse import urlparse &gt;&gt;&gt; url = 'http://example.com/random/folder/path.html' &gt;&gt;&gt; parse_object = urlparse(url) &gt;&gt;&gt; parse_object.netloc 'example.com' &gt;&gt;...
36
2009-01-16T08:14:36Z
[ "python", "url", "parsing" ]
How can I split a url string up into separate parts in Python?
449,775
<p>I decided that I'll learn python tonight :) I know C pretty well (wrote an OS in it) so I'm not a noob in programming so everything in python seems pretty easy, but I don't know how to solve this problem : let's say I have this address:</p> <p><a href="http://example.com/random/folder/path.html">http://example.com/...
9
2009-01-16T07:43:22Z
14,722,294
<p>Thank you very much to the other answerers here, who pointed me in the right direction via the answers they have given!</p> <p>It seems like the posixpath module mentioned by <code>sykora</code>'s answer is not available in my Python setup (python 2.7.3).</p> <p>As per <a href="http://www.doughellmann.com/PyMOTW/u...
2
2013-02-06T05:35:32Z
[ "python", "url", "parsing" ]
How to check if a file can be created inside given directory on MS XP/Vista?
450,210
<p>I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.</p> <p>I have created directory for test purposes, let's call it <code>C:\foo</code>. </p> <p>I have following permissions to <code>C:\foo</code>: </p> <ul> <li>Tra...
5
2009-01-16T12:01:24Z
450,259
<p>I wouldn't waste time and LOCs on checking for permissions. Ultimate test of file creation in Windows is the creation itself. Other factors may come into play (such as existing files (or worse, folders) with the same name, disk space, background processes. These conditions can even change between the time you make t...
3
2009-01-16T12:18:28Z
[ "python", "windows", "winapi", "windows-vista", "permissions" ]
How to check if a file can be created inside given directory on MS XP/Vista?
450,210
<p>I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.</p> <p>I have created directory for test purposes, let's call it <code>C:\foo</code>. </p> <p>I have following permissions to <code>C:\foo</code>: </p> <ul> <li>Tra...
5
2009-01-16T12:01:24Z
450,297
<p>I recently wrote a App to pass a set of test to obtain the ISV status from Microsoft and I also add that condition. The way I understood it was that if the user is Least Priveledge then he won't have permission to write in the system folders. So I approached the problem the the way Ishmaeel described. I try to creat...
3
2009-01-16T12:36:05Z
[ "python", "windows", "winapi", "windows-vista", "permissions" ]
How to check if a file can be created inside given directory on MS XP/Vista?
450,210
<p>I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.</p> <p>I have created directory for test purposes, let's call it <code>C:\foo</code>. </p> <p>I have following permissions to <code>C:\foo</code>: </p> <ul> <li>Tra...
5
2009-01-16T12:01:24Z
450,344
<p>I agree with the other answers that the way to do this is to try to create the file and catch the exception. </p> <p><em>However</em>, on Vista beware of UAC! See for example <a href="http://stackoverflow.com/questions/370837/why-does-my-application-allow-me-to-save-files-to-the-windows-and-system32-folder">"Why do...
2
2009-01-16T12:56:30Z
[ "python", "windows", "winapi", "windows-vista", "permissions" ]
How to check if a file can be created inside given directory on MS XP/Vista?
450,210
<p>I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it.</p> <p>I have created directory for test purposes, let's call it <code>C:\foo</code>. </p> <p>I have following permissions to <code>C:\foo</code>: </p> <ul> <li>Tra...
5
2009-01-16T12:01:24Z
451,131
<pre><code>import os import tempfile def can_create_file(folder_path): try: tempfile.TemporaryFile(dir=folder_path) return True except OSError: return False def can_create_folder(folder_path): try: name = tempfile.mkdtemp(dir=folder_path) os.rmdir(name) retu...
1
2009-01-16T16:52:23Z
[ "python", "windows", "winapi", "windows-vista", "permissions" ]
Python Path
450,290
<p>I am installing active python, django. I really dont know how to set the python path in vista environment system. first of all will it work in vista.</p>
1
2009-01-16T12:33:20Z
450,304
<p>Perhaps this helps: It's a <a href="http://www.neuralwiki.org/index.php?title=Guide_to_installing_Python_in_Windows_Vista" rel="nofollow">Guide to installing Python in Windows Vista</a>.</p>
1
2009-01-16T12:37:56Z
[ "python" ]
Python Path
450,290
<p>I am installing active python, django. I really dont know how to set the python path in vista environment system. first of all will it work in vista.</p>
1
2009-01-16T12:33:20Z
450,545
<p>Remember that in addition to setting <code>PYTHONPATH</code> in your system environment, you'll also want to assign <code>DJANGO_SETTINGS_MODULE</code>.</p>
0
2009-01-16T14:28:41Z
[ "python" ]
Python Path
450,290
<p>I am installing active python, django. I really dont know how to set the python path in vista environment system. first of all will it work in vista.</p>
1
2009-01-16T12:33:20Z
10,585,779
<h1>Temporary Change</h1> <p>To change the python path temporarily (i.e., for one interactive session), just append to <code>sys.path</code> like this:</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.path ['', 'C:\\Program Files\\PyScripter\\Lib\\rpyc.zip', 'C:\\Windows\\system32\\python27.zip', 'C:\\Pytho...
2
2012-05-14T14:54:43Z
[ "python" ]
Deleting lines from wx.TextCtrl
450,306
<p>I am using a wx.TextCtrl to output text from a network daemon.<br /> As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)<br /> I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines(...
2
2009-01-16T12:38:18Z
450,315
<p>How about the Remove method of wx.TextCtrl?</p> <p>Whenever you're about to add new text, you can check if the current text appears too long and remove some from the start.</p>
0
2009-01-16T12:43:31Z
[ "python", "wxpython", "wx.textctrl" ]
Deleting lines from wx.TextCtrl
450,306
<p>I am using a wx.TextCtrl to output text from a network daemon.<br /> As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)<br /> I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines(...
2
2009-01-16T12:38:18Z
450,317
<p>The <a href="http://docs.wxwidgets.org/2.6/wx_wxtextctrl.html#wxtextctrlsetmaxlength" rel="nofollow">SetMaxLength reference</a> says that the limitation depends on the underlying native text control,but should be 32KB at least.</p> <p>About deleting the top N lines, you could try to call <a href="http://docs.wxwidg...
1
2009-01-16T12:44:11Z
[ "python", "wxpython", "wx.textctrl" ]
Deleting lines from wx.TextCtrl
450,306
<p>I am using a wx.TextCtrl to output text from a network daemon.<br /> As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)<br /> I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines(...
2
2009-01-16T12:38:18Z
450,324
<p>Remove() should do the trick.</p> <p>TextCtrl without wx.TE_RICH flag can't have more than 64 KB on Windows.</p>
0
2009-01-16T12:46:25Z
[ "python", "wxpython", "wx.textctrl" ]
Deleting lines from wx.TextCtrl
450,306
<p>I am using a wx.TextCtrl to output text from a network daemon.<br /> As the output is quite verbose, the size of text in the TextCtrl can become huge (BTW is there any limitation on the size of the contents of a TextCtrl?)<br /> I would like to delete the top N lines from the TextCtrl when TextCtrl.GetNumberOfLines(...
2
2009-01-16T12:38:18Z
38,823,051
<p>You should be able to use <a href="https://wxpython.org/Phoenix/docs/html/wx.TextCtrl.html#wx.TextCtrl.PositionToXY" rel="nofollow"><code>wx.TextCtrl.PositionToXY()</code></a> and <a href="https://wxpython.org/Phoenix/docs/html/wx.TextCtrl.html#wx.TextCtrl.XYToPosition" rel="nofollow"><code>wx.TextCtrl.XYToPosition(...
0
2016-08-08T07:02:59Z
[ "python", "wxpython", "wx.textctrl" ]
Cookie Problem in Python
450,787
<p>I'm working on a simple HTML scraper for Hulu in python 2.6 and am having problems with logging on to my account. Here's my code so far:</p> <pre><code>import urllib import urllib2 from cookielib import CookieJar #make a cookie and redirect handlers cookies = CookieJar() cookie_handler= urllib2.HTTPCookieProcesso...
2
2009-01-16T15:39:35Z
451,306
<p>What you're seeing is a ajax return. It is probably using javascript to set the cookie, and screwing up your attempts to authenticate.</p>
4
2009-01-16T17:33:52Z
[ "python", "cookies", "urllib2" ]
Cookie Problem in Python
450,787
<p>I'm working on a simple HTML scraper for Hulu in python 2.6 and am having problems with logging on to my account. Here's my code so far:</p> <pre><code>import urllib import urllib2 from cookielib import CookieJar #make a cookie and redirect handlers cookies = CookieJar() cookie_handler= urllib2.HTTPCookieProcesso...
2
2009-01-16T15:39:35Z
451,605
<p>The error message you are getting back could be misleading. For example the server might be looking at <em>user-agent</em> and seeing that say it's not one of the supported browsers, or looking at <i>HTTP_REFERER</i> expecting it to be coming from hulu domain. My point is there are two many variables coming in the r...
2
2009-01-16T19:21:48Z
[ "python", "cookies", "urllib2" ]
ImportError when using Google App Engine
450,883
<p>When I add the following line to Google's helloworld example:</p> <pre><code> from reportlab.pdfgen import canvas </code></pre> <p>I get the following error:</p> <pre><code> &lt;type 'exceptions.ImportError'&gt;: No module named reportlab.pdfgen </code></pre> <p>I can get at the reportlab.pdfgen library from t...
0
2009-01-16T15:59:54Z
450,944
<p>Copying the module locally worked.</p> <p>From </p> <pre><code>Python\Lib\site-packages\reportlab </code></pre> <p>to </p> <pre><code>helloworld\reportlab </code></pre>
3
2009-01-16T16:12:15Z
[ "python", "google-app-engine", "import" ]
ImportError when using Google App Engine
450,883
<p>When I add the following line to Google's helloworld example:</p> <pre><code> from reportlab.pdfgen import canvas </code></pre> <p>I get the following error:</p> <pre><code> &lt;type 'exceptions.ImportError'&gt;: No module named reportlab.pdfgen </code></pre> <p>I can get at the reportlab.pdfgen library from t...
0
2009-01-16T15:59:54Z
450,951
<p>I believe the google app engine does not include all the standard python modules. I know that anything that works with sockes is disabled, such as urllib.urlopen().</p>
0
2009-01-16T16:12:56Z
[ "python", "google-app-engine", "import" ]
What's the most efficient way to access sibling dictionary value in a Python dict?
451,690
<p>In Python, I've got a list of dictionaries that looks like this:</p> <pre><code>matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] </code></pre> <p>and, I have a variable:</p> <pre><code>the_id ...
3
2009-01-16T19:45:51Z
451,700
<p>You can use a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p> <pre><code>domains = [matching['domain'] for matching in matchings if matching['id'] == the_id] </code></pre> <p>Which follows the format standard format of:</p> <pre><code>re...
5
2009-01-16T19:47:57Z
[ "python", "loops", "dictionary", "list-comprehension" ]
What's the most efficient way to access sibling dictionary value in a Python dict?
451,690
<p>In Python, I've got a list of dictionaries that looks like this:</p> <pre><code>matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] </code></pre> <p>and, I have a variable:</p> <pre><code>the_id ...
3
2009-01-16T19:45:51Z
451,710
<p>The fact that there are dictionaries in the list doesn't really matter - the problem reduces to finding an item in a list where some property is true. To that end, some variation on @<a href="#451700" rel="nofollow">Soviut</a>'s answer is the way to go: loop or list comprehension, examining each of the items until a...
0
2009-01-16T19:49:47Z
[ "python", "loops", "dictionary", "list-comprehension" ]
What's the most efficient way to access sibling dictionary value in a Python dict?
451,690
<p>In Python, I've got a list of dictionaries that looks like this:</p> <pre><code>matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] </code></pre> <p>and, I have a variable:</p> <pre><code>the_id ...
3
2009-01-16T19:45:51Z
451,722
<p>The best I can figure is to do an explicit search. This is one area where I get disappointed in Python is that it doesn't give you a strong set of decoupled building blocks like in the C++ STL algorithms</p> <pre><code>[d["domain"] for d in matchings if d["id"] == "someid3"] </code></pre>
1
2009-01-16T19:52:12Z
[ "python", "loops", "dictionary", "list-comprehension" ]
What's the most efficient way to access sibling dictionary value in a Python dict?
451,690
<p>In Python, I've got a list of dictionaries that looks like this:</p> <pre><code>matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] </code></pre> <p>and, I have a variable:</p> <pre><code>the_id ...
3
2009-01-16T19:45:51Z
451,819
<p>I'd restructure <code>matchings</code>.</p> <pre><code>from collections import defaultdict matchings_ix= defaultdict(list) for m in matchings: matchings_ix[m['id']].append( m ) </code></pre> <p>Now the most efficient lookup is</p> <pre><code>matchings_ix[ d ] </code></pre>
2
2009-01-16T20:16:04Z
[ "python", "loops", "dictionary", "list-comprehension" ]
What's the most efficient way to access sibling dictionary value in a Python dict?
451,690
<p>In Python, I've got a list of dictionaries that looks like this:</p> <pre><code>matchings = [ {'id': 'someid1', 'domain': 'somedomain1.com'}, {'id': 'someid2', 'domain': 'somedomain2.com'}, {'id': 'someid3', 'domain': 'somedomain3.com'} ] </code></pre> <p>and, I have a variable:</p> <pre><code>the_id ...
3
2009-01-16T19:45:51Z
5,503,404
<p>I really like to use <a href="http://docs.python.org/library/functions.html#filter" rel="nofollow">filter</a> in this sort of situation. It takes a function and an iterable and returns the list of elements where the function returns True (in Python 3.x it returns an iterator).</p> <pre><code>&gt;&gt;&gt; filter(lam...
0
2011-03-31T16:52:26Z
[ "python", "loops", "dictionary", "list-comprehension" ]
What is the correct way to backup ZODB blobs?
451,952
<p>I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.</p> <p>I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply poin...
6
2009-01-16T20:51:01Z
453,942
<p>Backing up "blobstorage" will do it. No need for a special order or anything else, it's very simple.</p> <p>All operations in Plone are fully transactional, so hitting the backup in the middle of a transaction should work just fine. This is why you can do live backups of the ZODB. Without knowing what file system y...
3
2009-01-17T20:16:28Z
[ "python", "plone", "zope", "zodb", "blobstorage" ]
What is the correct way to backup ZODB blobs?
451,952
<p>I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.</p> <p>I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply poin...
6
2009-01-16T20:51:01Z
676,364
<p>Your backup strategy for the FileStorage is fine. However, making a backup of any database that stores data in multiple files never is easy as your copy has to happen with no writes to the various files. For the FileStorage a blind stupid copy is fine as it's just a single file. (Using repozo is even better.)</p> <...
1
2009-03-24T06:51:57Z
[ "python", "plone", "zope", "zodb", "blobstorage" ]
What is the correct way to backup ZODB blobs?
451,952
<p>I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.</p> <p>I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply poin...
6
2009-01-16T20:51:01Z
2,664,479
<p>It should be safe to do a repozo backup of the Data.fs followed by an rsync of the blobstorage directory, as long as the database doesn't get packed while those two operations are happening.</p> <p>This is because, at least when using blobs with FileStorage, modifications to a blob always results in the creation of...
12
2010-04-18T23:51:13Z
[ "python", "plone", "zope", "zodb", "blobstorage" ]
What is the correct way to backup ZODB blobs?
451,952
<p>I am using plone.app.blob to store large ZODB objects in a blobstorage directory. This reduces size pressure on Data.fs but I have not been able to find any advice on backing up this data.</p> <p>I am already backing up Data.fs by pointing a network backup tool at a directory of repozo backups. Should I simply poin...
6
2009-01-16T20:51:01Z
5,263,021
<p>I have an script that copies for a month the blobs using hard links ( so you have and historial of the blobs as the Data.fs ):</p> <p>backup.sh </p> <pre><code>#!/bin/sh # per a fer un full : ./cron_nocturn.sh full ZEO_FOLDER=/var/plone/ZEO # Zeo port ZEO_PORT = 8023 # Name of the DB ZEO_DB = zodb1 BACKUP_FOL...
2
2011-03-10T16:54:01Z
[ "python", "plone", "zope", "zodb", "blobstorage" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
451,969
<p>To make a method sort of private, you can name-mangle a method like so:</p> <pre><code>class Foo: def __blah(): pass class Bar(Foo): def callBlah(): self.__blah() # will throw an exception </code></pre> <p>But subclasses can still find your methods through introspection if they really want...
5
2009-01-16T20:56:31Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
452,023
<p>There's no way to truly do this in Python. Rather unpythonic, it is. </p> <p>As Guido would say, we're all consenting adults here.</p> <p>Here's a good <a href="http://mail.python.org/pipermail/tutor/2003-October/025932.html">summary of the philosophy behind everything in Python being public</a>.</p>
26
2009-01-16T21:09:56Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
452,028
<p>Python is distributed as source. The very idea of a private method makes very little sense.</p> <p>The programmer who wants to extend <code>B</code>, frustrated by a privacy issue, looks at the source for <code>B</code>, copies and pastes the source code for <code>method</code> into the subclass <code>C</code>. <...
15
2009-01-16T21:11:46Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
452,049
<p>This may be a fair approximation. Lexical scoping to the "rescue":</p> <pre><code>#!/usr/bin/env python class Foo(object): def __init__(self, name): self.name = name self.bar() def bar(self): def baz(): print "I'm private" print self.name def quux()...
7
2009-01-16T21:16:58Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
452,240
<p>I am surprised that no one has mentioned this, but prefixing the method name with a single underscore is the correct way of labelling it as "private". It's not really <em>private</em> of course, (as explained in other answers), but there you go.</p> <pre><code>def _i_am_private(self): """If you call me from a s...
11
2009-01-16T22:09:27Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
452,316
<p>You can prefix methods and members with a single or double underscore. A single underscore implies "please don't use me, I'm supposed to be used only by this class", and a double underscore instructs the Python compiler to mangle the method/member name with the class name; as long as the class and its subclasses don...
12
2009-01-16T22:42:42Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
453,521
<p>Changing an inherited method from public to private <em>breaks inheritance</em>. Specifically, it breaks the is-a relationship.</p> <p>Imagine a Restaurant class with a open-doors public method (i.e. it's dinnertime and we want to flip the front door sign from closed to open). Now we want a Catering class that woul...
5
2009-01-17T16:19:59Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
458,101
<p>"Everything must be public" proponents think the author is trying to hide a useful API from the users. This guy doesn't want to violate an unquestionable law of Python. He wants to use some methods to define a useful API, and he wants to use other methods to organize the implementation of that API. If there's no sep...
7
2009-01-19T16:03:19Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
5,851,875
<p>Contrary to popular fashion on this subject, there <strong>are</strong> legitimate reasons to have a distinction between public, private, and protected members, whether you work in Python or a more traditional OOP environment. Many times, it comes to be that you develop auxiliary methods for a particularly long-wind...
27
2011-05-01T22:26:19Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
9,198,380
<p>Even among consenting adults, there are reasons why you do not want to expose methods to a derived class. The question is, can I have a hierarchy like Parent > Child, where a user can derive from either Parent or Child but not be exposed any private or protected methods. In the following example, Child explicitly ...
1
2012-02-08T17:27:58Z
[ "python", "oop", "inheritance" ]
Making a method private in a python subclass
451,963
<p>Is it possible to make a public method private in a subclass ? I don't want other classes extending this one to be able to call some of the methods . Here is an example :</p> <pre><code>class A: def __init__(self): #do something here def method(self): #some code here class B(A): def __...
24
2009-01-16T20:53:50Z
19,740,244
<pre><code>class MyClass(object): def _prtectedfunc(self): pass # with one undersocre def __privatefunc(self): pass # with two undersocre </code></pre> <p><a href="http://linuxwell.com/2011/07/21/private-protected-and-public-in-python/" rel="nofollow">http://linuxwell.com/2011/07/21/private-p...
0
2013-11-02T08:32:17Z
[ "python", "oop", "inheritance" ]
Python and Bluetooth/OBEX
452,018
<p>Is there any Python libraries that will let me send files with OBEX (OBject EXchange) and that works cross-platform (Windows, OS X, Linux)? I have found Lightblue, which works for Linux and OS X, but not for Windows.</p> <p>If none such lib exists, are there any decent ones that only works in Windows?</p>
2
2009-01-16T21:08:16Z
473,676
<p><a href="http://org.csail.mit.edu/pybluez/" rel="nofollow">PyBluez - Windows</a> </p>
1
2009-01-23T16:59:45Z
[ "python", "bluetooth" ]
Python and Bluetooth/OBEX
452,018
<p>Is there any Python libraries that will let me send files with OBEX (OBject EXchange) and that works cross-platform (Windows, OS X, Linux)? I have found Lightblue, which works for Linux and OS X, but not for Windows.</p> <p>If none such lib exists, are there any decent ones that only works in Windows?</p>
2
2009-01-16T21:08:16Z
499,460
<p>PyOBEX might work, but it has only been tested with a Linux Bluetooth stack:</p> <p><a href="http://pypi.python.org/pypi/PyOBEX/0.10" rel="nofollow">http://pypi.python.org/pypi/PyOBEX/0.10</a></p> <p>It would be good to know if it works correctly on Windows and Mac OS X.</p>
2
2009-01-31T20:12:45Z
[ "python", "bluetooth" ]
Python and Bluetooth/OBEX
452,018
<p>Is there any Python libraries that will let me send files with OBEX (OBject EXchange) and that works cross-platform (Windows, OS X, Linux)? I have found Lightblue, which works for Linux and OS X, but not for Windows.</p> <p>If none such lib exists, are there any decent ones that only works in Windows?</p>
2
2009-01-16T21:08:16Z
1,701,376
<p>pyobex on xp have problem with import MSG_WAITALL from socket</p>
0
2009-11-09T14:37:20Z
[ "python", "bluetooth" ]
Creating a gradient fill in a PDF file using reportlab
452,074
<p>Is it possible to create a gradient fill in a PDF using <a href="http://www.reportlab.org/">ReportLab</a> (python)?</p>
10
2009-01-16T21:24:12Z
2,799,222
<p><strong>[My answer is no longer correct, gradients are now available in Reportlab, see the other answer on this page for details.]</strong></p> <p>Sorry to ressurect this question, but I stumbled across it and it hadn't been correctly answered.</p> <p>The answer is no, as of today, the current version of ReportLab...
3
2010-05-09T21:21:49Z
[ "python", "pdf", "gradient", "reportlab" ]
Creating a gradient fill in a PDF file using reportlab
452,074
<p>Is it possible to create a gradient fill in a PDF using <a href="http://www.reportlab.org/">ReportLab</a> (python)?</p>
10
2009-01-16T21:24:12Z
15,988,441
<p>ReportLab now supports PDF gradients.</p> <p>A patch for gradient support was <a href="http://two.pairlist.net/pipermail/reportlab-users/2012-August/010465.html">posted to the ReportLab mailing list</a> by Peter Johnson on 6 August 2012 and was <a href="https://bitbucket.org/rptlab/reportlab/commits/494980a689ff55a...
5
2013-04-13T13:43:04Z
[ "python", "pdf", "gradient", "reportlab" ]
Creating a gradient fill in a PDF file using reportlab
452,074
<p>Is it possible to create a gradient fill in a PDF using <a href="http://www.reportlab.org/">ReportLab</a> (python)?</p>
10
2009-01-16T21:24:12Z
20,546,843
<p>You want to fill a rectangle (or other path) with a gradient instead of a solid color?</p> <p>No problem. Use clipping to bound/limit the gradient to a path. Just remember to set the clip path <em>before</em> setting the gradient. (And wrap it inside <code>saveState()</code>/<code>restoreState()</code> to reset the...
0
2013-12-12T14:58:32Z
[ "python", "pdf", "gradient", "reportlab" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
452,116
<p>Regular Expressions are compiled before being used when using the second version. If you are going to executing it many times it is definatly better to compile it first. If not compiling every time you match for one off's is fine.</p>
0
2009-01-16T21:36:28Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
452,126
<p>My understanding is that those two examples are effectively equivalent. The only difference is that in the first, you can reuse the compiled regular expression elsewhere without causing it to be compiled again.</p> <p>Here's a reference for you: <a href="http://diveintopython3.ep.io/refactoring.html" rel="nofollow"...
-2
2009-01-16T21:38:12Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
452,142
<p>FWIW:</p> <pre><code>$ python -m timeit -s "import re" "re.match('hello', 'hello world')" 100000 loops, best of 3: 3.82 usec per loop $ python -m timeit -s "import re; h=re.compile('hello')" "h.match('hello world')" 1000000 loops, best of 3: 1.26 usec per loop </code></pre> <p>so, if you're going to be using the...
34
2009-01-16T21:42:37Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
452,143
<p>I've had a lot of experience running a compiled regex 1000s of times versus compiling on-the-fly, and have not noticed any perceivable difference. Obviously, this is anecdotal, and certainly not a great argument <em>against</em> compiling, but I've found the difference to be negligible.</p> <p>EDIT: After a quick ...
258
2009-01-16T21:42:57Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
452,153
<p>This is a good question. You often see people use re.compile without reason. It lessens readability. But sure there are lots of times when pre-compiling the expression is called for. Like when you use it repeated times in a loop or some such.</p> <p>It's like everything about programming (everything in life actuall...
1
2009-01-16T21:44:59Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
453,568
<p>For me, the biggest benefit to <code>re.compile</code> isn't any kind of premature optimization (which is the <a href="http://programmers.stackexchange.com/questions/39/whats-your-favourite-quote-about-programming/816#816">root of all evil</a>, <a href="http://en.wikipedia.org/wiki/Optimization_%28computer_science%2...
71
2009-01-17T16:49:07Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
462,399
<p>Interestingly, compiling does prove more efficient for me (Python 2.5.2 on Win XP):</p> <pre><code>import re import time rgx = re.compile('(\w+)\s+[0-9_]?\s+\w*') str = "average 2 never" a = 0 t = time.time() for i in xrange(1000000): if re.match('(\w+)\s+[0-9_]?\s+\w*', str): #~ if rgx.match(str): ...
2
2009-01-20T18:06:57Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
660,315
<p>In general, I find it is easier to use flags (at least easier to remember how), like <code>re.I</code> when compiling patterns than to use flags inline.</p> <pre><code>&gt;&gt;&gt; foo_pat = re.compile('foo',re.I) &gt;&gt;&gt; foo_pat.findall('some string FoO bar') ['FoO'] </code></pre> <p>vs </p> <pre><code>&gt;...
4
2009-03-18T22:13:45Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
1,086,330
<p>(months later) it's easy to add your own cache around re.match, or anything else for that matter --</p> <pre><code>""" Re.py: Re.match = re.match + cache efficiency: re.py does this already (but what's _MAXCACHE ?) readability, inline / separate: matter of taste """ import re cache = {} _re_type = type(...
0
2009-07-06T10:13:44Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
2,082,709
<p>I ran this test before stumbling upon the discussion here. However, having run it I thought I'd at least post my results.</p> <p>I stole and bastardized the example in Jeff Friedl's "Mastering Regular Expressions". This is on a macbook running OSX 10.6 (2Ghz intel core 2 duo, 4GB ram). Python version is 2.6.1.</...
2
2010-01-17T21:22:18Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
2,634,933
<p>I just tried this myself. For the simple case of parsing a number out of a string and summing it, using a compiled regular expression object is about twice as fast as using the <code>re</code> methods.</p> <p>As others have pointed out, the <code>re</code> methods (including <code>re.compile</code>) look up the reg...
6
2010-04-14T04:40:24Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
4,114,923
<p>i'd like to motivate that pre-compiling is both conceptually and 'literately' (as in 'literate programming') advantageous. have a look at this code snippet:</p> <pre><code>from re import compile as _Re class TYPO: def text_has_foobar( self, text ): return self._text_has_foobar_re_search( text ) is not None ...
0
2010-11-06T20:03:49Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
13,640,709
<p>Here's a simple test case:</p> <pre><code>~$ for x in 1 10 100 1000 10000 100000 1000000; do python -m timeit -n $x -s 'import re' 're.match("[0-9]{3}-[0-9]{3}-[0-9]{4}", "123-123-1234")'; done 1 loops, best of 3: 3.1 usec per loop 10 loops, best of 3: 2.41 usec per loop 100 loops, best of 3: 2.24 usec per loop 100...
27
2012-11-30T07:24:30Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
15,328,835
<p>Using the given examples:</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>The <em>match</em> method in the example above is not the same as the one used below:</p> <pre><code>re.match('hello', 'hello world') </code></pre> <p><a href="http://docs.python.org/3.3/library/re.html?highl...
2
2013-03-10T23:03:59Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
17,598,179
<p>Performance difference aside, using re.compile and using the compiled regular expression object to do match (whatever regular expression related operations) makes the semantics clearer to Python run-time.</p> <p>I had some painful experience of debugging some simple code:</p> <pre><code>compare = lambda s, p: re.m...
1
2013-07-11T16:00:03Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
25,020,854
<p>I agree with Honest Abe that the <code>match(...)</code> in the given examples are different. They are not a one-to-one comparisons and thus, outcomes are vary. To simplify my reply, I use A, B, C, D for those functions in question. Oh yes, we are dealing with 4 functions in <code>re.py</code> instead of 3.</p> ...
5
2014-07-29T16:55:09Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
29,159,014
<p>There is one addition perk of using re.compile(), in the form of adding comments to my regex patterns using re.VERBOSE</p> <pre><code>pattern = ''' hello[ ]world # Some info on my pattern logic. [ ] to recognize space ''' re.search(pattern, 'hello world', re.VERBOSE) </code></pre> <p>Although this does not aff...
2
2015-03-20T03:39:09Z
[ "python", "regex" ]
Is it worth using Python's re.compile?
452,104
<p>Is there any benefit in using compile for regular expressions in Python?</p> <pre><code>h = re.compile('hello') h.match('hello world') </code></pre> <p>vs</p> <pre><code>re.match('hello', 'hello world') </code></pre>
238
2009-01-16T21:31:57Z
39,446,619
<p>This answer might be arriving late but is an interesting find. Using compile can really save you time if you are planning on using the regex multiple times (this is also mentioned in the docs). Below you can see that using a compiled regex is the fastest when the match method is directly called on it. passing a comp...
0
2016-09-12T08:57:31Z
[ "python", "regex" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
452,302
<p>The "normal" way is to:</p> <ul> <li>Go to the Beautiful Soup web site, <a href="http://www.crummy.com/software/BeautifulSoup/">http://www.crummy.com/software/BeautifulSoup/</a></li> <li>Download the package</li> <li>Unpack it</li> <li>In a Terminal window, <code>cd</code> to the resulting directory</li> <li>Type <...
69
2009-01-16T22:37:30Z
[ "python", "osx", "module", "installation" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
452,311
<p>Brian beat me too it, but since I already have the transcript:</p> <p><a href="http://peak.telecommunity.com/DevCenter/EasyInstall">easy_install</a></p> <pre><code>aaron@ares ~$ sudo easy_install BeautifulSoup Searching for BeautifulSoup Best match: BeautifulSoup 3.0.7a Processing BeautifulSoup-3.0.7a-py2.5.egg Be...
14
2009-01-16T22:41:46Z
[ "python", "osx", "module", "installation" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
6,045,148
<p>Download the package and unpack it. In Terminal, go to the package's directory and type</p> <pre><code>python setup.py install </code></pre>
2
2011-05-18T13:05:00Z
[ "python", "osx", "module", "installation" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
15,520,403
<pre><code>sudo yum remove python-beautifulsoup </code></pre> <p>OR</p> <pre><code>sudo easy_install -m BeautifulSoup </code></pre> <p>can remove old version 3</p>
0
2013-03-20T10:02:07Z
[ "python", "osx", "module", "installation" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
19,257,356
<p>On advice from <a href="http://for-ref-only.blogspot.de/2012/08/installing-beautifulsoup-for-python-3.html" rel="nofollow">http://for-ref-only.blogspot.de/2012/08/installing-beautifulsoup-for-python-3.html</a>, I used the Windows command prompt with:</p> <pre><code>C:\Python\Scripts\easy_install c:\Python\Beautiful...
0
2013-10-08T20:09:28Z
[ "python", "osx", "module", "installation" ]
How can I install the Beautiful Soup module on the Mac?
452,283
<p>I read this without finding the solution: <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a></p>
38
2009-01-16T22:26:45Z
24,178,431
<p>I think the current right way to do this is by <code>pip</code> like Pramod comments</p> <pre><code>pip install beautifulsoup4 </code></pre> <p>because of last changes in Python, see discussion <a href="http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install">here</a>. This was not so in the past....
12
2014-06-12T07:08:25Z
[ "python", "osx", "module", "installation" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
452,310
<pre><code>&gt;&gt;&gt; from datetime import date &gt;&gt;&gt; &gt;&gt;&gt; repr(date.today()) # calls date.today().__repr__() 'datetime.date(2009, 1, 16)' &gt;&gt;&gt; eval(_) # _ is the output of the last command datetime.date(2009, 1, 16) </code></pre> <p>The output is a string that can be ...
54
2009-01-16T22:41:37Z
[ "python" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
452,312
<p>It should be a Python expression that, when eval'd, creates an object with the exact same properties as this one. For example, if you have a <code>Fraction</code> class that contains two integers, a numerator and denominator, your <code>__repr__()</code> method would look like this:</p> <pre><code># in the definiti...
24
2009-01-16T22:42:22Z
[ "python" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
452,733
<p>"but does that mean it should just be an example of the sort of expression you could use, or should it be an actual expression, that can be executed (eval etc..) to recreate the object? Or... should it be just a rehasing of the actual expression which was used, for pure information purposes?"</p> <p>Wow, that's a l...
3
2009-01-17T03:16:28Z
[ "python" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
453,381
<p><strong>Guideline:</strong> If you can succinctly provide an <em>exact representation</em>, <strong>format it as a Python expression</strong> (which implies that it can be both eval'd and copied directly into source code, in the right context). If providing an <em>inexact representation</em>, <strong>use <code>&lt;....
9
2009-01-17T14:42:03Z
[ "python" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
28,759,968
<p>Peace :),</p> <p>This might be useful: <a href="http://www.rafekettler.com/magicmethods.html" rel="nofollow">http://www.rafekettler.com/magicmethods.html</a></p>
0
2015-02-27T07:48:14Z
[ "python" ]
Python object.__repr__(self) should be an expression?
452,300
<p>I was looking at the builtin object methods in the <a href="http://docs.python.org/reference/datamodel.html#objects-values-and-types">Python documentation</a>, and I was interested in the documentation for <code>object.__repr__(self)</code>. Here's what it says:</p> <blockquote> <p>Called by the repr() built-in f...
51
2009-01-16T22:37:18Z
31,559,519
<p>I think the confusion over here roots from the english. I mean <code>__repr__()</code>; short for 'representation' of the value I'm guessing, like @S.Lott said </p> <blockquote> <p>"What is the difference between "an actual expression, that can ... recreate the object" and "a rehasing of the actual expression whi...
0
2015-07-22T09:44:21Z
[ "python" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,317
<p>Certainly one successful use of Python on the web is <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a>. Site authors write code in (a slightly restricted subset of) Python, which is then executed by the App Engine servers in a distributed and scalable manner.</p>
5
2009-01-16T22:42:54Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,324
<p><a href="http://www.djangoproject.com/">Django</a> is, IMHO, one of the major benefits of using Python. Model your domain, code your classes, and voila, your ORM is done, and you can focus on the UI. Add in the ease of templating with the built-in templating language (or one of many others you can use as well), and ...
13
2009-01-16T22:45:56Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,328
<p><a href="http://trac.edgewall.org/" rel="nofollow">trac</a>(bug tracker) and <a href="http://moinmo.in/" rel="nofollow">moinmoin</a>(wiki) are too web based python tools that I find invaluable.</p>
1
2009-01-16T22:47:28Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,352
<p>Dynamic languages are in general good for web apps because the speed of development. Python in particular has two advantages over most of them:</p> <ul> <li>"batteries included" means <em>lots</em> of available libraries</li> <li>Django. For me this is the only reason why i use Python instead of Lua (which i like a...
0
2009-01-16T22:59:19Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,356
<p>GNU Mailman is another project written in python that is widely successful.</p>
1
2009-01-16T22:59:52Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,384
<p>Besides the frameworks...</p> <ul> <li>Python's pervasive support for Unicode should make i18n much smoother.</li> <li>A sane namespace system makes debugging much nicer, because it's typically easier to find where things are defined.</li> <li>Python's inability to function as a standalone templating language shoul...
0
2009-01-16T23:16:55Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,392
<p>Other examples of Python sites are Reddit and YouTube.</p>
0
2009-01-16T23:22:47Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,403
<p><a href="http://www.python.org/about/quotes/">Quotes about Python</a>:</p> <blockquote> <p>"Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers," said Cuong Do, Software Architect, <a href="http://youtube.com">YouTube.com</a>.</p>...
5
2009-01-16T23:26:08Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,462
<p>Short anwser: the diversity of tools readily available and freedom of choice.</p> <p>This sounds like a simple question but which it really isn't. While Python is very good for web development and this has been shown by the, oh so famous, <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine<...
2
2009-01-16T23:52:11Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
452,600
<p>As many have pointed out, Django is a great reason to use Python...so in order to figure out why Python is great for web development, the best bet is to look at why it is a good language to build a framework like Django.</p> <p>IMHO Python combines the cleanest, or at least one of the cleanest, metaprogramming mode...
1
2009-01-17T01:12:28Z
[ "python", "programming-languages" ]
What are the benefits of using Python for web programming?
452,305
<p>What makes Python stand out for use in web development? What are some examples of highly successful uses of Python on the web?</p>
9
2009-01-16T22:38:56Z
453,371
<p>YouTube uses a lot of Python and is probably the best example of a Python success story.</p> <p>A great example of a Django success story is the Washington Post, who recently shared a big list of applications they have developed:</p> <p><a href="http://push.cx/2009/washington-post-update" rel="nofollow">http://pus...
3
2009-01-17T14:35:02Z
[ "python", "programming-languages" ]