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 |
|---|---|---|---|---|---|---|---|---|---|
Asynchronous File Upload to Amazon S3 with Django | 670,442 | <p>I am using this file storage engine to store files to Amazon S3 when they are uploaded:</p>
<p><a href="http://code.welldev.org/django-storages/wiki/Home">http://code.welldev.org/django-storages/wiki/Home</a></p>
<p>It takes quite a long time to upload because the file must first be uploaded from client to web ser... | 32 | 2009-03-22T02:29:32Z | 848,251 | <p>It's possible to have your users upload files directly to S3 from their browser using a special form (with an encrypted policy document in a hidden field). They will be redirected back to your application once the upload completes.</p>
<p>More information here: <a href="http://developer.amazonwebservices.com/connec... | 22 | 2009-05-11T14:01:49Z | [
"python",
"django",
"amazon-s3"
] |
Asynchronous File Upload to Amazon S3 with Django | 670,442 | <p>I am using this file storage engine to store files to Amazon S3 when they are uploaded:</p>
<p><a href="http://code.welldev.org/django-storages/wiki/Home">http://code.welldev.org/django-storages/wiki/Home</a></p>
<p>It takes quite a long time to upload because the file must first be uploaded from client to web ser... | 32 | 2009-03-22T02:29:32Z | 5,684,245 | <p>You can directly upload media to the s3 server without using your web application server. </p>
<p>See the following references: </p>
<p>Amazon API Reference : <a href="http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?UsingHTTPPOST.html" rel="nofollow">http://docs.amazonwebservices.com/AmazonS3/late... | 3 | 2011-04-16T03:11:57Z | [
"python",
"django",
"amazon-s3"
] |
Asynchronous File Upload to Amazon S3 with Django | 670,442 | <p>I am using this file storage engine to store files to Amazon S3 when they are uploaded:</p>
<p><a href="http://code.welldev.org/django-storages/wiki/Home">http://code.welldev.org/django-storages/wiki/Home</a></p>
<p>It takes quite a long time to upload because the file must first be uploaded from client to web ser... | 32 | 2009-03-22T02:29:32Z | 7,305,558 | <p>As some of the answers here suggest uploading directly to S3, here's a Django S3 Mixin using plupload:
<a href="https://github.com/burgalon/plupload-s3mixin" rel="nofollow">https://github.com/burgalon/plupload-s3mixin</a></p>
| 0 | 2011-09-05T08:28:12Z | [
"python",
"django",
"amazon-s3"
] |
Asynchronous File Upload to Amazon S3 with Django | 670,442 | <p>I am using this file storage engine to store files to Amazon S3 when they are uploaded:</p>
<p><a href="http://code.welldev.org/django-storages/wiki/Home">http://code.welldev.org/django-storages/wiki/Home</a></p>
<p>It takes quite a long time to upload because the file must first be uploaded from client to web ser... | 32 | 2009-03-22T02:29:32Z | 9,799,520 | <p>There is an app for that :-)</p>
<p><a href="https://github.com/jezdez/django-queued-storage">https://github.com/jezdez/django-queued-storage</a></p>
<p>It does exactly what you need - and much more, because you can set any "local" storage and any "remote" storage. This app will store your file in fast "local" sto... | 18 | 2012-03-21T06:18:09Z | [
"python",
"django",
"amazon-s3"
] |
Asynchronous File Upload to Amazon S3 with Django | 670,442 | <p>I am using this file storage engine to store files to Amazon S3 when they are uploaded:</p>
<p><a href="http://code.welldev.org/django-storages/wiki/Home">http://code.welldev.org/django-storages/wiki/Home</a></p>
<p>It takes quite a long time to upload because the file must first be uploaded from client to web ser... | 32 | 2009-03-22T02:29:32Z | 14,830,782 | <p>I encountered the same issue with uploaded images. You cannot pass along files to a Celery worker because Celery needs to be able to pickle the arguments to a task. My solution was to deconstruct the image data into a string and get all other info from the file, passing this data and info to the task, where I recons... | 0 | 2013-02-12T10:50:19Z | [
"python",
"django",
"amazon-s3"
] |
Line-wrapping problems with IPython shell | 670,764 | <p>If I have run a long line in IPython, and try and recall it (using the up-arrow) or backspace beyond the start of the current line, it displays incorrectly (all smushed into one line)</p>
<p>For example, in the following session I wrote a long line <code>[1]</code>, entered a somewhat-blank line <code>[2]</code>, t... | 10 | 2009-03-22T09:40:21Z | 671,274 | <p>I can't reproduce it:</p>
<p><img src="http://i403.photobucket.com/albums/pp111/uber%5Fulrich/misc/so-misc.png" alt="up-arrow works for long lines in ipython" title="ipython up-arrow long line" /></p>
| 1 | 2009-03-22T16:49:32Z | [
"python",
"terminal",
"ipython"
] |
Line-wrapping problems with IPython shell | 670,764 | <p>If I have run a long line in IPython, and try and recall it (using the up-arrow) or backspace beyond the start of the current line, it displays incorrectly (all smushed into one line)</p>
<p>For example, in the following session I wrote a long line <code>[1]</code>, entered a somewhat-blank line <code>[2]</code>, t... | 10 | 2009-03-22T09:40:21Z | 672,755 | <p>Aha! I had an old version of the Python readline module - installing the latest from <a href="http://ipython.scipy.org/dist/">http://ipython.scipy.org/dist/</a> and it works perfectly!</p>
<pre><code>sudo easy_install http://ipython.scipy.org/dist/readline-2.5.1-py2.5-macosx-10.5-i386.egg
</code></pre>
| 9 | 2009-03-23T09:52:26Z | [
"python",
"terminal",
"ipython"
] |
Line-wrapping problems with IPython shell | 670,764 | <p>If I have run a long line in IPython, and try and recall it (using the up-arrow) or backspace beyond the start of the current line, it displays incorrectly (all smushed into one line)</p>
<p>For example, in the following session I wrote a long line <code>[1]</code>, entered a somewhat-blank line <code>[2]</code>, t... | 10 | 2009-03-22T09:40:21Z | 3,373,928 | <p>Got this problem on Snow Leopard. Installing a new version of readline from <a href="http://pypi.python.org/pypi/readline/" rel="nofollow">http://pypi.python.org/pypi/readline/</a> fixes it:</p>
<pre><code>sudo easy_install http://pypi.python.org/packages/2.6/r/readline/readline-2.6.4-py2.6-macosx-10.6-universal.eg... | 2 | 2010-07-30T17:25:41Z | [
"python",
"terminal",
"ipython"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,334 | <p>There's an HTML parser that comes standard in Python. Checkout <code>htmllib</code>.</p>
| 4 | 2009-03-22T17:28:39Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,349 | <p><a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful Soup</a> can do this almost trivially:</p>
<pre><code>from BeautifulSoup import BeautifulSoup as soup
html = soup('<body><a href="123">qwe</a><a href="456">asd</a></body>')
print [tag.attrMap['href'] for tag in ht... | 11 | 2009-03-22T17:43:14Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,365 | <p>Don't divide the html content into lines, as there maybe multiple matches in a single line. Also don't assume there is always quotes around the url. </p>
<p>Do something like this:</p>
<pre><code>links = re.finditer(' href="?([^\s^"]+)', content)
for link in links:
print link
</code></pre>
| 1 | 2009-03-22T17:57:58Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,372 | <p>Another alternative to BeautifulSoup is lxml (<a href="http://lxml.de/" rel="nofollow">http://lxml.de/</a>);</p>
<pre><code>import lxml.html
links = lxml.html.parse("http://stackoverflow.com/").xpath("//a/@href")
for link in links:
print link
</code></pre>
| 8 | 2009-03-22T18:00:18Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,410 | <p>What others haven't told you is that using regular expressions for this is not a reliable solution.<br />
Using regular expression will give you wrong results on many situations: if there are <A> tags that are commented out, or if there are text in the page which include the string "href=", or if there are <te... | 3 | 2009-03-22T18:31:56Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 671,866 | <p>As previously mentioned: regex does not have the power to parse HTML. Do not use regex for parsing HTML. Do not pass Go. Do not collect £200.</p>
<p>Use an HTML parser.</p>
<p>But for completeness, the primary problem is:</p>
<pre><code>re.match ('/href="(.*)"/iU', line)
</code></pre>
<p>You don't use the â/.... | 3 | 2009-03-23T00:14:53Z | [
"python",
"html",
"regex",
"parsing"
] |
Getting the value of href attributes in all <a> tags on a html file with Python | 671,323 | <p>I'm building an app in python, and I need to get the URL of all links in one webpage. I already have a function that uses urllib to download the html file from the web, and transform it to a list of strings with readlines().</p>
<p>Currently I have this code that uses regex (I'm not very good at it) to search for l... | 1 | 2009-03-22T17:22:34Z | 672,508 | <p>Well, just for completeness I will add here what I found to be the best answer, and I found it on the book Dive Into Python, from Mark Pilgrim.</p>
<p>Here follows the code to list all URL's from a webpage:</p>
<pre><code>from sgmllib import SGMLParser
class URLLister(SGMLParser):
def reset(self): ... | 1 | 2009-03-23T07:54:07Z | [
"python",
"html",
"regex",
"parsing"
] |
QSortFilterProxyModel.mapToSource crashes. No info why | 671,340 | <p>I have the following code:</p>
<pre><code>proxy_index = self.log_list.filter_proxy_model.createIndex(index, COL_REV)
model_index = self.log_list.filter_proxy_model.mapToSource(proxy_index)
revno = self.log_list.model.data(model_index,QtCore.Qt.DisplayRole)
self.setEditText(revno.toString())
</code></pre>
<p>The co... | 1 | 2009-03-22T17:33:05Z | 671,884 | <p>It may be that you're using the proxy model's createIndex() method incorrectly. Usually, the createIndex() method is called as part of a model's index() method implementation.</p>
<p>Have you tried calling the proxy model's index() method to get a proxy index then mapping that to the source?</p>
<p>Perhaps you cou... | 1 | 2009-03-23T00:22:32Z | [
"python",
"qt",
"qt4",
"pyqt",
"pyqt4"
] |
QSortFilterProxyModel.mapToSource crashes. No info why | 671,340 | <p>I have the following code:</p>
<pre><code>proxy_index = self.log_list.filter_proxy_model.createIndex(index, COL_REV)
model_index = self.log_list.filter_proxy_model.mapToSource(proxy_index)
revno = self.log_list.model.data(model_index,QtCore.Qt.DisplayRole)
self.setEditText(revno.toString())
</code></pre>
<p>The co... | 1 | 2009-03-22T17:33:05Z | 1,332,267 | <p>I've run into the same problem, but fortunately using the index () method instead of createIndex () as David recommends does the magic.
In general it's a bad idea to mess around with the internal pointer of QModelIndex outside the index () method. Even when using your own Model messing around the internal pointer le... | 0 | 2009-08-26T04:05:42Z | [
"python",
"qt",
"qt4",
"pyqt",
"pyqt4"
] |
unsubscriptable object | 671,363 | <pre><code> im = Image.open(teh_file)
if im:
colors = im.resize( (1,1), Image.ANTIALIAS).getpixel((0,0)) # simple way to get average color
red = colors[0] # and so on, some operations on color data
</code></pre>
<p>The problem is, on a few (very few, particulary don't know why those exactly, sim... | 1 | 2009-03-22T17:57:45Z | 671,373 | <p>From the PIL docs:</p>
<pre><code>getpixel
im.getpixel(xy) => value or tuple
Returns the pixel at the given position. If the image is a multi-layer image, this method returns a tuple.
</code></pre>
<p>So it seems that some of your images are multilayer, and some are single-layer.</p>
| 4 | 2009-03-22T18:00:57Z | [
"python",
"image",
"image-processing",
"colors",
"python-imaging-library"
] |
unsubscriptable object | 671,363 | <pre><code> im = Image.open(teh_file)
if im:
colors = im.resize( (1,1), Image.ANTIALIAS).getpixel((0,0)) # simple way to get average color
red = colors[0] # and so on, some operations on color data
</code></pre>
<p>The problem is, on a few (very few, particulary don't know why those exactly, sim... | 1 | 2009-03-22T17:57:45Z | 671,377 | <p>As noted in another answer, <code>getpixel</code> returns either a single value, or a tuple. You could check the type and do the appropriate action in the following ways:</p>
<pre><code>if isinstance(colors, tuple):
color = colors[0]
else:
color = colors
# Do other stuff
</code></pre>
<p>or:</p>
<pre><cod... | 2 | 2009-03-22T18:06:25Z | [
"python",
"image",
"image-processing",
"colors",
"python-imaging-library"
] |
unsubscriptable object | 671,363 | <pre><code> im = Image.open(teh_file)
if im:
colors = im.resize( (1,1), Image.ANTIALIAS).getpixel((0,0)) # simple way to get average color
red = colors[0] # and so on, some operations on color data
</code></pre>
<p>The problem is, on a few (very few, particulary don't know why those exactly, sim... | 1 | 2009-03-22T17:57:45Z | 671,523 | <p>Ok the case was, that when B&W images have no RGB band (L band), it returns an integer with the pixel color single value, not a list of rgb values. The solution is to check bands</p>
<pre><code>im.getbands()
</code></pre>
<p>or the simpler for my needs was:</p>
<pre><code> if isinstance(colors, tuple):... | 2 | 2009-03-22T19:43:35Z | [
"python",
"image",
"image-processing",
"colors",
"python-imaging-library"
] |
Django: specifying a base template by directory | 671,369 | <p>I'm working on a Django site that has multiple sections and subsections. I'd like to have several depths of template inheritance: a base template for the whole site, one base template for each section that inherits from the root base template, and so on. Here's a simplified version of my desired directory structure:... | 10 | 2009-03-22T17:59:50Z | 671,378 | <p>May be I oversee something, but all you want can be accomplished with the django template system. All extends calls are relative to template directories.</p>
<ol>
<li><p>In order for all base.html files in subdirectories to extend base.html, you just have to put a <code>{% extends "base.html" %}</code> into the fil... | 17 | 2009-03-22T18:07:15Z | [
"python",
"django",
"django-templates"
] |
Django: specifying a base template by directory | 671,369 | <p>I'm working on a Django site that has multiple sections and subsections. I'd like to have several depths of template inheritance: a base template for the whole site, one base template for each section that inherits from the root base template, and so on. Here's a simplified version of my desired directory structure:... | 10 | 2009-03-22T17:59:50Z | 672,282 | <p>The accepted answer will work, but I do recommend using variable names to keep track of section structure. My personal preference would be a <a href="http://docs.djangoproject.com/en/dev/ref/templates/api/?from=olddocs#writing-your-own-context-processors">context processor</a>. If, for example, your site's section... | 5 | 2009-03-23T05:00:58Z | [
"python",
"django",
"django-templates"
] |
Django: specifying a base template by directory | 671,369 | <p>I'm working on a Django site that has multiple sections and subsections. I'd like to have several depths of template inheritance: a base template for the whole site, one base template for each section that inherits from the root base template, and so on. Here's a simplified version of my desired directory structure:... | 10 | 2009-03-22T17:59:50Z | 36,059,204 | <p>You can use this library: <a href="https://github.com/vb64/django.templates.relative.path" rel="nofollow">https://github.com/vb64/django.templates.relative.path</a></p>
<p>Just write in your templates as follows:</p>
<p>{% load relative_path %}
{% extends ".base.html" %}</p>
<p>this will extend template "base.htm... | 0 | 2016-03-17T11:27:47Z | [
"python",
"django",
"django-templates"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,454 | <p>Often times, dictionaries of dictionaries are useful for other than performance reasons. ie, they allow you to store context information about the data without having extra fields on the objects themselves, and make querying subsets of the data faster.</p>
<p>In terms of memory usage, it would stand to reason that... | 1 | 2009-03-22T19:03:03Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,463 | <p>If you're using Python, you really shouldn't be worrying about this sort of thing in the first place. Just build your data structure the way it best suits <em>your</em> needs, not the computer's.</p>
<p>This smacks of premature optimization, not performance improvement. Profile your code if something is actually ... | 13 | 2009-03-22T19:12:25Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,474 | <p>"Simple" is generally better than "clever", especially if you have no tested reason to go beyond "simple". And anyway "Memory efficient" is an ambiguous term, and there are tradeoffs, when you consider persisting, serializing, cacheing, swapping, and a whole bunch of other stuff that someone else has already thought... | 6 | 2009-03-22T19:19:15Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,476 | <p>Honestly, you won't be able to tell the difference either way, in terms of either performance or memory usage. Unless you're dealing with tens of millions of items or more, the performance or memory impact is just noise.</p>
<p>From the way you worded your second sentence, it sounds like the one big dictionary is ... | 1 | 2009-03-22T19:19:59Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,502 | <p>Premature optimization bla bla, don't do it bla bla.</p>
<p>I think you're mistaken about the <em>power</em> of two extra allocation does. I think its just a <em>multiplier</em> of two. x*2, not x^2.</p>
<p>I've seen this question a few times on various python mailing lists.</p>
<p>With regards to memory, here'... | 3 | 2009-03-22T19:36:51Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 671,522 | <p>Three suggestions:</p>
<ol>
<li><p><strong>Use one dictionary.</strong><br>
It's easier, it's more straightforward, and someone else has already optimized this problem for you. Until you've actually measured your code and traced a performance problem to this part of it, you have no reason not to do the simple, str... | 59 | 2009-03-22T19:43:19Z | [
"python",
"memory",
"dictionary",
"performance"
] |
Memory efficiency: One large dictionary or a dictionary of smaller dictionaries? | 671,403 | <p>I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store.</p>
<p>I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference t... | 25 | 2009-03-22T18:27:48Z | 801,780 | <p>If your dictionary is so big that it does not fit into memory, you might want to have a look at <a href="http://www.ibm.com/developerworks/aix/library/au-zodb/" rel="nofollow">ZODB</a>, a very mature object database for Python.</p>
<p>The 'root' of the db has the same interface as a dictionary, and you don't need t... | 4 | 2009-04-29T10:37:13Z | [
"python",
"memory",
"dictionary",
"performance"
] |
How to do "performance-based" (benchmark) unit testing in Python | 671,503 | <p>Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.)</p>
<p>Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by... | 7 | 2009-03-22T19:36:55Z | 671,517 | <p>You will want to do performance testing at a system level if possible - test your application as a whole, in context, with data and behaviour as close to production use as possible.</p>
<p>This is not easy, and it will be even harder to automate it and get consistent results.</p>
<p>Moreover, you can't use a VM fo... | 7 | 2009-03-22T19:40:24Z | [
"python",
"linux",
"unit-testing",
"benchmarking"
] |
How to do "performance-based" (benchmark) unit testing in Python | 671,503 | <p>Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.)</p>
<p>Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by... | 7 | 2009-03-22T19:36:55Z | 671,524 | <p>MarkR is right... doing real-world performance testing is key, and may be somewhat dodgey in unit tests. Having said that, have a look at the <code>cProfile</code> module in the standard library. It will at least be useful for giving you a relative sense from commit-to-commit of how fast things are running, and you ... | 2 | 2009-03-22T19:44:06Z | [
"python",
"linux",
"unit-testing",
"benchmarking"
] |
How to do "performance-based" (benchmark) unit testing in Python | 671,503 | <p>Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.)</p>
<p>Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by... | 7 | 2009-03-22T19:36:55Z | 671,921 | <p>When I do performance testing, I generally have a test suite of data inputs, and measure how long it takes the program to process each one.</p>
<p>You can log the performance on a daily or weekly basis, but I don't find it particularly useful to worry about performance until all the functionality is implemented.</p... | 2 | 2009-03-23T00:46:55Z | [
"python",
"linux",
"unit-testing",
"benchmarking"
] |
How to do "performance-based" (benchmark) unit testing in Python | 671,503 | <p>Let's say that I've got my code base to as high a degree of unit test coverage as makes sense. (Beyond a certain point, increasing coverage doesn't have a good ROI.)</p>
<p>Next I want to test performance. To benchmark code to make sure that new commits aren't slowing things down needlessly. I was very intrigued by... | 7 | 2009-03-22T19:36:55Z | 2,209,270 | <p>While I agree that testing performance at a system level is ultimately more relevant, if you'd like to do UnitTest style load testing for Python, FunkLoad <a href="http://funkload.nuxeo.org/" rel="nofollow">http://funkload.nuxeo.org/</a> does exactly that.</p>
<p>Micro benchmarks have their place when you're trying... | 4 | 2010-02-05T18:03:46Z | [
"python",
"linux",
"unit-testing",
"benchmarking"
] |
Do you have a copy of Unipath-0.2.0.tar.gz? | 671,542 | <p>I need a copy of this library installed on my system because my software depends on this library.</p>
<p>Unfortunately, at the moment, it's impossible install it trough easy_install:</p>
<pre><code>andrea@puzzle:~$ sudo easy_install Unipath
[sudo] password for andrea:
Searching for Unipath
Reading http://pypi.pyt... | 0 | 2009-03-22T20:07:01Z | 671,630 | <p>I found <a href="http://groups.google.com/group/python-file-system-discuss/browse%5Fthread/thread/a421d749eff8a230/4eacafbf70b6c04b?hl=en&q=unipath%2Bpython#4eacafbf70b6c04b" rel="nofollow">this</a> newsgroup post written my Mike Orr (the creator of Unipath). In the last sentence he says that he's moving the pro... | 0 | 2009-03-22T21:19:08Z | [
"python"
] |
Do you have a copy of Unipath-0.2.0.tar.gz? | 671,542 | <p>I need a copy of this library installed on my system because my software depends on this library.</p>
<p>Unfortunately, at the moment, it's impossible install it trough easy_install:</p>
<pre><code>andrea@puzzle:~$ sudo easy_install Unipath
[sudo] password for andrea:
Searching for Unipath
Reading http://pypi.pyt... | 0 | 2009-03-22T20:07:01Z | 694,714 | <p>I contacted the original author who confirmed me that there was a problem with the DNS entry and he's going to solve it.</p>
<p>He also uploaded the latest tarball to pypi, so now you can install it with <code>easy_install Unipath</code>.</p>
| 0 | 2009-03-29T14:37:52Z | [
"python"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 671,595 | <p>Perl's CGI module has support for something like this.</p>
<pre><code>use CGI ':standard';
use Lisp::Fmt
print header();
print table( { -border => 1, -cellpading => 4},
loop({ below => 25, by=> 5}, sub {
my $i = shift;
tr( {-align => 'right'} ,
loop({ from => $i,... | 5 | 2009-03-22T20:51:03Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 671,722 | <p>Perl's standard <a href="http://search.cpan.org/dist/CGI.pm/CGI.pm" rel="nofollow">CGI</a> module can do something similar:</p>
<pre><code>#!/usr/bin/perl
use strict;
use warnings;
use CGI qw/:standard/;
print
start_html("An example"),
h1(
{
-align => "left",
-class => "headerinfo"... | 3 | 2009-03-22T22:35:54Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 671,836 | <p>There is <a href="http://www.kieranholland.com/code/documentation/nevow-stan/" rel="nofollow">stan</a>: <em>An s-expression-like syntax for expressing xml in pure python</em>, from <a href="http://divmod.org/trac/wiki/DivmodNevow" rel="nofollow">Divmod's Nevow</a>. I think it's kind of what you want. An example from... | 4 | 2009-03-22T23:57:23Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 672,064 | <p>One of <a href="http://www.perlfoundation.org/" rel="nofollow">The Perl Foundation</a>'s current grant-sponsored projects (a <a href="http://www.perlfoundation.org/ilya%5Fcarl%5Fand%5Fstephen%5Fa%5Flightweight%5Fweb%5Fframework%5Ffor%5Fperl%5F6" rel="nofollow">lightweight web framework for Perl 6</a>) has working Pe... | 6 | 2009-03-23T02:28:38Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 672,665 | <p>For <a href="http://search.cpan.org" rel="nofollow">CPAN</a> offerings have a look at the following (in alphabetical order)...</p>
<ul>
<li><a href="http://search.cpan.org/dist/Builder/" rel="nofollow">Builder</a></li>
<li><a href="http://search.cpan.org/dist/HTML-Tree/lib/HTML/AsSubs.pm" rel="nofollow">HTML::AsSub... | 11 | 2009-03-23T09:21:02Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 693,058 | <p><a href="http://elzr.com/posts/hyperscript" rel="nofollow">Here</a> is such thing for JavaScript. It looks like the following:</p>
<pre><code>T.div({ className: "content"},
T.p("Some ", T.u("paragraph")),
T.p("Another paragraph"))
</code></pre>
| 1 | 2009-03-28T16:32:44Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 693,552 | <h2>Clojure</h2>
<p>There are a bunch of CL-WHO-inspired HTML-generating libraries available in Clojure (as one would expect, Clojure being a Lisp). Here's how you could do it using the HTML library that comes with <a href="http://github.com/weavejester/compojure/tree/master" rel="nofollow">Compojure</a>, and <a href... | 3 | 2009-03-28T21:23:22Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 3,313,597 | <h2>Haskell</h2>
<p>Haskell has an HTML combinator library that is not all that different from CL-WHO. The lazy functional approach to programming, though, does result in a much different idiomatic iteration structure than the loop facilities in Common Lisp:</p>
<pre><code>import Data.Char
import Data.List
import Tex... | 1 | 2010-07-22T21:20:44Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
CL-WHO-like HTML templating for other languages? | 671,572 | <p>Common Lisp guys have their <a href="http://www.weitz.de/cl-who/" rel="nofollow">CL-WHO</a>, which makes HTML templating integrated with the "main" language thus making the task easier. For those who don't know CL-WHO, it looks like this (example from CL-WHO's webpage):</p>
<pre><code>(with-html-output (*http-strea... | 10 | 2009-03-22T20:31:07Z | 6,444,393 | <p>There's <a href="http://wiki.call-cc.org/egg/html-tags" rel="nofollow">html-tags</a>, a <a href="http://call-cc.org" rel="nofollow">Chicken Scheme</a> extension. html-tags generates either [X]HTML or SXML.</p>
<p>Here's an example (using the loop extension and considering string output):</p>
<pre><code>(<table&... | 1 | 2011-06-22T18:02:55Z | [
"python",
"html",
"perl",
"common-lisp",
"templating"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 671,752 | <p>PyQt and its models can automate some of these tasks for you (to some amount off course, e.g. filling widgets with data from a database and handling most of the widgets behaviour, buffering etc.).</p>
<p>If you want a more object-oriented approach to handling SQL you could look into an ORM-oriented solution (for ex... | 4 | 2009-03-22T22:58:54Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 671,849 | <p><a href="http://en.wikipedia.org/wiki/WxGlade" rel="nofollow">wxGlade</a> may help, although I haven't used it myself so I don't speak from experience.</p>
<p><a href="http://en.wikipedia.org/wiki/Boa%5Fconstructor" rel="nofollow">Boa Constructor</a> apparently has a wxPython GUI builder in it, and there is also <a... | 1 | 2009-03-23T00:04:16Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 671,911 | <p><a href="http://dabodev.com/" rel="nofollow">Dabo</a> is built on top of wxPython, so you may not prefer it, but it's designed to make it easy to tie a GUI to a database, so I'd recommend you check it out if you haven't already. In particular, it's got good facilities for tying widgets to data, and handling a lot of... | 4 | 2009-03-23T00:37:12Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 672,093 | <p>Besides the ones already mentioned I can add:</p>
<ul>
<li><a href="http://www.async.com.br/projects/kiwi/api/kiwi.html" rel="nofollow">Kiwi</a></li>
<li><a href="http://www.uxpython.com/" rel="nofollow">uxpython</a></li>
<li><a href="http://www.pygtk.org/" rel="nofollow">pygtk</a></li>
<li><a href="http://code.goo... | 5 | 2009-03-23T02:53:13Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 677,952 | <p>Traits might be a good option for you.
<a href="http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html" rel="nofollow">http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html</a></p>
<p>AS simple as it is to map a UI to an object, it doesn't seem too far fetched to incorporate SQLAlchemy ... | 1 | 2009-03-24T15:34:32Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 678,000 | <p>I had lots of success with wxPython, but that was some years ago now and there may be better new solutions...</p>
| 0 | 2009-03-24T15:43:44Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 691,567 | <p>There is a good book on wxPython, "wxPython in Action", which can't be said for some of the other solutions. No knock on the others. I've had success developing with wxPython in the past and it comes with a great set of demo applications with source code from which you can borrow liberally.</p>
<p>The best UI des... | 1 | 2009-03-27T21:41:51Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Is there a Python library that allows to build user interfaces without writing much code? | 671,741 | <p>I am writing editing front ends in Python since several years now, and I am fed up with micromanaging every UI detail of a window or dialog every single time.</p>
<p>Is there a technology that allows me to, say, specify the relations between a GTK+ Glade-designed interface and the tables and records of an SQLite da... | 7 | 2009-03-22T22:49:11Z | 765,138 | <p>Ok this is an unconventional solution but write yourself a code generator. I have done this several times using <a href="http://www.makotemplates.org/" rel="nofollow">Mako</a>. So in my case I auto inspect a table which columns it contains and types and generate classes from that. It's more work upfront but does exa... | 0 | 2009-04-19T09:39:09Z | [
"python",
"user-interface",
"sqlite",
"gtk",
"glade"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,176 | <p>Would this do it?</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest2(bar):
print bar
def maptest(foo):
print foo
map(maptest2, bars)
map(maptest, foos)
</code></pre>
| 0 | 2009-03-23T03:51:03Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,197 | <p>Here's the solution you're looking for:</p>
<pre><code>>>> foos = [1.0, 2.0, 3.0, 4.0, 5.0]
>>> bars = [1, 2, 3]
>>> [(x, bars) for x in foos]
[(1.0, [1, 2, 3]), (2.0, [1, 2, 3]), (3.0, [1, 2, 3]), (4.0, [1, 2, 3]), (5.0, [
1, 2, 3])]
</code></pre>
<p>I'd recommend using a list comprehen... | 30 | 2009-03-23T04:00:28Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,198 | <p>The easiest way would be not to pass <code>bars</code> through the different functions, but to access it directly from <code>maptest</code>:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo):
print foo, bars
map(maptest, foos)
</code></pre>
<p>With your original <code>maptest</code>... | 52 | 2009-03-23T04:00:28Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,216 | <pre><code>import itertools
foos=[1.0, 2.0, 3.0, 4.0, 5.0]
bars=[1, 2, 3]
print zip(foos, itertools.cycle([bars]))
</code></pre>
| 11 | 2009-03-23T04:17:28Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,222 | <pre><code>>>> from itertools import repeat
>>> for foo, bars in zip(foos, repeat(bars)):
... print foo, bars
...
1.0 [1, 2, 3]
2.0 [1, 2, 3]
3.0 [1, 2, 3]
4.0 [1, 2, 3]
5.0 [1, 2, 3]
</code></pre>
| 12 | 2009-03-23T04:21:19Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,230 | <p>Here's an overview of the parameters to the <code>map(function, *sequences)</code> function:</p>
<ul>
<li><code>function</code> is the name of your function.</li>
<li><code>sequences</code> is any number of sequences, which are usually lists or tuples. <code>map</code> will iterate over them <em>simultaneously</em... | 6 | 2009-03-23T04:24:48Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,296 | <p>Are you familiar with other functional languages? i.e. are you trying to learn how python does functional programming, or are you trying to learn about functional programming and using python as the vehicle?</p>
<p>Also, do you understand list comprehensions?</p>
<pre><code>map(f, sequence)
</code></pre>
<p>is di... | 188 | 2009-03-23T05:11:47Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 672,469 | <p>Functional programming is about creating side-effect-free code.</p>
<p>map is a functional list transformation abstraction. You use it to take a sequence of something and turn it into a sequence of something else.</p>
<p>You are trying to use it as an iterator. Don't do that. :)</p>
<p>Here is an example of ho... | 18 | 2009-03-23T07:28:29Z | [
"python",
"dictionary",
"functional-programming"
] |
Using python map and other functional tools | 672,172 | <p>This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, bars)
</code></pre>
<p>produces:</p>
<pre><code>1.0 1
2.0 2
3.0 3
4.0 None
5.0 N... | 119 | 2009-03-23T03:46:29Z | 18,649,750 | <p>How about this:</p>
<pre><code>foos = [1.0,2.0,3.0,4.0,5.0]
bars = [1,2,3]
def maptest(foo, bar):
print foo, bar
map(maptest, foos, [bars]*len(foos))
</code></pre>
| 0 | 2013-09-06T04:11:41Z | [
"python",
"dictionary",
"functional-programming"
] |
Django Custom Queryset filters | 672,182 | <p>Is there, in Django, a standard way to write complex, custom filters for QuerySets?</p>
<p>Just as I can write </p>
<pre><code>MyClass.objects.all().filter(field=val)
</code></pre>
<p>I'd like to do something like this :</p>
<pre><code>MyClass.objects.all().filter(customFilter)
</code></pre>
<p>I could use a ge... | 6 | 2009-03-23T03:53:41Z | 672,193 | <p>I think you may need custom <a href="https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers" rel="nofollow">managers</a>.</p>
| 5 | 2009-03-23T03:58:12Z | [
"python",
"django",
"django-queryset",
"generator-expression"
] |
Django Custom Queryset filters | 672,182 | <p>Is there, in Django, a standard way to write complex, custom filters for QuerySets?</p>
<p>Just as I can write </p>
<pre><code>MyClass.objects.all().filter(field=val)
</code></pre>
<p>I'd like to do something like this :</p>
<pre><code>MyClass.objects.all().filter(customFilter)
</code></pre>
<p>I could use a ge... | 6 | 2009-03-23T03:53:41Z | 673,180 | <p>The recommendation to start using manager methods is a good one, but to answer your question more directly: yes, use <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects">Q objects</a>. For example:</p>
<pre><code>from django.db.models import Q
complexQuery = Q(name__sta... | 12 | 2009-03-23T12:21:14Z | [
"python",
"django",
"django-queryset",
"generator-expression"
] |
How do you send AT GSM commands using python? | 672,366 | <p>How do i send AT GSM commands using python?</p>
<p>Am able to do this quite easily using Delphi and some comport component (TComport), but how do i talk to my modem using python?</p>
<p>Gath</p>
| 9 | 2009-03-23T06:11:02Z | 672,434 | <p>I don't know if there is an AT module, but you can use <a href="http://pyserial.sourceforge.net/" rel="nofollow">pyserial</a> to communicate with a serial port.</p>
| 4 | 2009-03-23T06:59:32Z | [
"python",
"modem"
] |
How do you send AT GSM commands using python? | 672,366 | <p>How do i send AT GSM commands using python?</p>
<p>Am able to do this quite easily using Delphi and some comport component (TComport), but how do i talk to my modem using python?</p>
<p>Gath</p>
| 9 | 2009-03-23T06:11:02Z | 672,448 | <p>I do it like this with pyserial:</p>
<pre><code>import serial
serialPort = serial.Serial(port=1,baudrate=115200,timeout=0,rtscts=0,xonxoff=0)
def sendatcmd(cmd):
serialPort.write('at'+cmd+'\r')
print 'Loading profile...',
sendatcmd('+npsda=0,2')
</code></pre>
<p>Then I listen for an answer...</p>
| 16 | 2009-03-23T07:08:33Z | [
"python",
"modem"
] |
Python Programming - Rules/Advice for developing enterprise-level software in Python? | 672,781 | <p>I'm a somewhat advanced C++/Java Developer who recently became interested in Python and I enjoy its dynamic typing and efficient coding style very much. I currently use it on my small programming needs like solving programming riddles and scripting, but I'm curious if anyone out there has successfully used Python in... | 7 | 2009-03-23T09:59:44Z | 672,806 | <p>I've been using Python as distributed computing framework in one of the worlds largest banks.
It was chosen because:</p>
<ul>
<li>It had to be extremely fast for developing and deploying new functionalities;</li>
<li>It had to be easily integrable with C and C++; </li>
<li>Some parts of the code were to be writt... | 3 | 2009-03-23T10:06:25Z | [
"java",
"python",
"design-patterns",
"programming-languages",
"dynamic-typing"
] |
Python Programming - Rules/Advice for developing enterprise-level software in Python? | 672,781 | <p>I'm a somewhat advanced C++/Java Developer who recently became interested in Python and I enjoy its dynamic typing and efficient coding style very much. I currently use it on my small programming needs like solving programming riddles and scripting, but I'm curious if anyone out there has successfully used Python in... | 7 | 2009-03-23T09:59:44Z | 672,975 | <p>I'm using Python for developing a complex insurance underwriting application.</p>
<p>Our application software essentially repackages our actuarial model in a form that companies can subscribe to it. This business is based on our actuaries and their deep thinking. We're not packaging a clever algorithm that's relat... | 16 | 2009-03-23T11:11:11Z | [
"java",
"python",
"design-patterns",
"programming-languages",
"dynamic-typing"
] |
File dialogs of Tkinter in Python 3? | 673,174 | <p>I want to select a file from a dialog box. <a href="http://www.java2s.com/Code/Python/GUI-Tk/Fileopendialog.htm">Here</a> is code that does all I need, but when I run it: </p>
<p><code>ImportError: No module named 'tkMessageBox'</code> </p>
<p>How can I make this example work with Python 3?</p>
| 13 | 2009-03-23T12:20:01Z | 673,309 | <p>The package <code>Tkinter</code> has been renamed to <code>tkinter</code> in Python 3, as well as other modules related to it. Here are the name changes:</p>
<ul>
<li><code>Tkinter</code> â <code>tkinter</code></li>
<li><code>tkMessageBox</code> â <code>tkinter.messagebox</code></li>
<li><code>tkColorChooser</c... | 36 | 2009-03-23T13:11:44Z | [
"python",
"python-2.7",
"python-3.x",
"tkinter",
"dialog"
] |
How to include page in PDF in PDF document in Python | 673,288 | <p>I am using reportlab toolkit in Python to generate some reports in PDF format. I want to use some predefined parts of documents already published in PDF format to be included in generated PDF file. Is it possible (and how) to accomplish this in reportlab or in python library?</p>
<p>I know I can use some other tool... | 5 | 2009-03-23T13:03:12Z | 673,322 | <p>There is an add-on for ReportLab — <a href="http://www.reportlab.com/docs/PageCatchIntro.pdf" rel="nofollow">PageCatcher</a>. </p>
| 1 | 2009-03-23T13:17:53Z | [
"python",
"pdf",
"pdf-generation",
"reportlab"
] |
How to include page in PDF in PDF document in Python | 673,288 | <p>I am using reportlab toolkit in Python to generate some reports in PDF format. I want to use some predefined parts of documents already published in PDF format to be included in generated PDF file. Is it possible (and how) to accomplish this in reportlab or in python library?</p>
<p>I know I can use some other tool... | 5 | 2009-03-23T13:03:12Z | 673,515 | <p>I'm currently using <a href="http://pybrary.net/pyPdf/">PyPDF</a> to read, write, and combine existing PDF's and ReportLab to generate new content. Using the two package seemed to work better than any single package I was able to find.</p>
| 6 | 2009-03-23T14:10:39Z | [
"python",
"pdf",
"pdf-generation",
"reportlab"
] |
How to include page in PDF in PDF document in Python | 673,288 | <p>I am using reportlab toolkit in Python to generate some reports in PDF format. I want to use some predefined parts of documents already published in PDF format to be included in generated PDF file. Is it possible (and how) to accomplish this in reportlab or in python library?</p>
<p>I know I can use some other tool... | 5 | 2009-03-23T13:03:12Z | 7,154,867 | <p>If you want to place existing PDF pages in your Reportlab documents I recommend <a href="http://code.google.com/p/pdfrw/" rel="nofollow">pdfrw</a>. Unlike PageCatcher it is free.</p>
<p>I've used it for several projects where I need to add barcodes etc to existing documents and it works very well. There are a coupl... | 2 | 2011-08-22T23:46:43Z | [
"python",
"pdf",
"pdf-generation",
"reportlab"
] |
Is there a Python library for easily writing zoomable UI's? | 673,434 | <p>My next work is going to be heavily focused on working with data that is best understood when organized on a two-dimensional zoomable plane or canvas, instead of using lists and property forms.</p>
<p>The library can be based on OpenGL, GTK+ or Cairo. It should allow me to:</p>
<ul>
<li>build widgets out of vector... | 3 | 2009-03-23T13:51:13Z | 673,447 | <p>Qt has this covered... check PyQt</p>
| 3 | 2009-03-23T13:54:34Z | [
"python",
"user-interface",
"opengl",
"gtk",
"cairo"
] |
Is there a Python library for easily writing zoomable UI's? | 673,434 | <p>My next work is going to be heavily focused on working with data that is best understood when organized on a two-dimensional zoomable plane or canvas, instead of using lists and property forms.</p>
<p>The library can be based on OpenGL, GTK+ or Cairo. It should allow me to:</p>
<ul>
<li>build widgets out of vector... | 3 | 2009-03-23T13:51:13Z | 675,971 | <p>I think <a href="http://www.clutter-project.org/" rel="nofollow">Clutter</a> is perfect for you.</p>
<p>From the web site:</p>
<blockquote>
<p>Clutter is an open source software
library for creating fast, visually
rich and animated graphical user
interfaces.</p>
</blockquote>
<p>Clutter is written in C, b... | 2 | 2009-03-24T02:32:42Z | [
"python",
"user-interface",
"opengl",
"gtk",
"cairo"
] |
What signals should I catch for clipboard pasting and character insertion in GTK? | 673,605 | <p>I have a Window with a TextView, and I would like to perform some actions when the user pastes some text. </p>
<p>I would also like to know what signal(s) should I catch in order to perform something when the user presses a key inside the TextView. </p>
<p>Can you tell me what are the signals I must connect?</p>
| 1 | 2009-03-23T14:37:30Z | 673,643 | <p>For paste: Take a look at the <a href="http://library.gnome.org/devel/gtk/stable/GtkTextBuffer.html#GtkTextBuffer-paste-done" rel="nofollow">paste-done</a> signal of the <code><a href="http://library.gnome.org/devel/gtk/stable/GtkTextBuffer.html" rel="nofollow">GtkTextBuffer</a></code> class, it sounds about right.<... | 2 | 2009-03-23T14:44:47Z | [
"python",
"gtk",
"clipboard",
"pygtk",
"signals"
] |
Using PiL to take a screenshot of HTML/CSS | 673,725 | <p>I want to enable a user on a website to upload an image, and write some text over it. Also, they should be able to crop/scale/move the image and text. For that stuff, I can do it in jQuery.</p>
<p>After they've made the image the way they want it, is there a way i can take a screenshot of that image (using PiL) a... | 1 | 2009-03-23T15:00:51Z | 673,958 | <p>I assume you got Python on the server side.</p>
<p>The best way imo is to somehow 'get' all the editing parameters from the client, then re-render it using PIL.</p>
<p>Update: How I will do it
On the server side, you need an url to handle posts.
On the client side, (after each edit, )send a post to that url, with... | 1 | 2009-03-23T15:58:28Z | [
"jquery",
"python",
"css",
"xhtml",
"python-imaging-library"
] |
Using PiL to take a screenshot of HTML/CSS | 673,725 | <p>I want to enable a user on a website to upload an image, and write some text over it. Also, they should be able to crop/scale/move the image and text. For that stuff, I can do it in jQuery.</p>
<p>After they've made the image the way they want it, is there a way i can take a screenshot of that image (using PiL) a... | 1 | 2009-03-23T15:00:51Z | 673,961 | <p>Taking a "screenshot" of the picture is neither the best, nor the proper way to do it. To take a screenshot, you need to execute code on the client machine, which is "not possible" in a website scenario.</p>
<p>Have a look at <a href="http://mine.icanhascheezburger.com/" rel="nofollow">lolcat builder</a> (I can't t... | 2 | 2009-03-23T15:59:10Z | [
"jquery",
"python",
"css",
"xhtml",
"python-imaging-library"
] |
Using PiL to take a screenshot of HTML/CSS | 673,725 | <p>I want to enable a user on a website to upload an image, and write some text over it. Also, they should be able to crop/scale/move the image and text. For that stuff, I can do it in jQuery.</p>
<p>After they've made the image the way they want it, is there a way i can take a screenshot of that image (using PiL) a... | 1 | 2009-03-23T15:00:51Z | 674,221 | <p>PIL isn't available on the client side.. so unless, as Jack Ha suggests, you intend to upload all the instructions of your image editing to the server and re-execute them, it's not an option. I would shy away from this because you'd need to implement the same editing routines on both the client and the server, doub... | 0 | 2009-03-23T16:55:34Z | [
"jquery",
"python",
"css",
"xhtml",
"python-imaging-library"
] |
Using PiL to take a screenshot of HTML/CSS | 673,725 | <p>I want to enable a user on a website to upload an image, and write some text over it. Also, they should be able to crop/scale/move the image and text. For that stuff, I can do it in jQuery.</p>
<p>After they've made the image the way they want it, is there a way i can take a screenshot of that image (using PiL) a... | 1 | 2009-03-23T15:00:51Z | 674,283 | <p>Well, even if others are trying to discourage you from doing this, it would probably not be that hard.</p>
<p>On the client-side, you, you define a div that is floated/resizable over the image, with transparency, that can be scaled for the crop.</p>
<p>Move, I assume it applies only to the text, so you dynamically... | 0 | 2009-03-23T17:08:06Z | [
"jquery",
"python",
"css",
"xhtml",
"python-imaging-library"
] |
How to read from an os.pipe() without getting blocked? | 673,844 | <p>I'm trying to read from an open <code>os.pipe()</code> to see if it's empty at the moment of the reading. The problem is that calling <code>read()</code> causes the program to block there until there is actually something to read there however there won't be any, if the test I'm doing succeeded. </p>
<p>I know I ca... | 7 | 2009-03-23T15:27:53Z | 674,508 | <p>You might try this. </p>
<pre><code>import os, fcntl
fcntl.fcntl(thePipe, fcntl.F_SETFL, os.O_NONBLOCK)
</code></pre>
<p>With this <code>thePipe.read()</code> should be non-blocking. </p>
<p>From <a href="http://man7.org/linux/man-pages/man7/pipe.7.html">pipe(7)</a> man page:</p>
<blockquote>
<p>If a process ... | 13 | 2009-03-23T17:54:55Z | [
"python",
"file",
"pipe"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,882 | <p>Python's dict is a hashmap, so it has no order. But you can sort the keys separately, extracting them from the dictionary with <a href="http://docs.python.org/library/stdtypes.html#dict.keys" rel="nofollow">keys()</a> method.</p>
<p><a href="http://docs.python.org/library/functions.html#sorted" rel="nofollow"><code... | 1 | 2009-03-23T15:37:47Z | [
"python",
"order"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,888 | <p>You can't sort a dictionary; a dictionary is a mapping and a mapping has no ordering.</p>
<p>You could extract the keys and sort those, however:</p>
<pre><code>keys = myDict.keys()
sorted_keys = sorted(keys, myCompare)
</code></pre>
| 1 | 2009-03-23T15:39:42Z | [
"python",
"order"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,890 | <p>A dict is not ordered. You will need to keep a list of keys.</p>
<p>You can pass your own comparison function to list.sort() or sorted().</p>
<p>If you need to sort on multiple keys, just concatenate them in a tuple, and sort on the tuple.</p>
| 0 | 2009-03-23T15:39:58Z | [
"python",
"order"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,892 | <p>Use the <code>key</code> named keyword argument of <code>sorted()</code>.</p>
<pre><code>#set up the order you want the keys to appear here
order = ["banana", "carrot", "apple"]
# this uses the order list to sort the actual keys.
sorted(keys, key=order.index)
</code></pre>
<p>For higher performance than <code>lis... | 13 | 2009-03-23T15:40:10Z | [
"python",
"order"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,897 | <p>There will be <code>OrderedDict</code> in new Python versions: <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">http://www.python.org/dev/peps/pep-0372/</a>.</p>
<p>Meanwhile, you can try one of the alternative implementations: <a href="http://code.activestate.com/recipes/496761/" rel="nofollow">ht... | 1 | 2009-03-23T15:41:25Z | [
"python",
"order"
] |
python: arbitrary order by | 673,867 | <p>In Oracle sql there is a feature to order as follow:</p>
<pre><code>order by decode("carrot" = 2
,"banana" = 1
,"apple" = 3)
</code></pre>
<p>What will be the best way to implement this in python?</p>
<p>I want to be able to order a dict on its keys. And that order isn't alphabetical... | 3 | 2009-03-23T15:33:24Z | 673,910 | <p>You can't order a dict per se, but you can convert it to a list of (key, value) tuples, and you can sort that.</p>
<p>You use the .items() method to do that. For example,</p>
<pre><code>>>> {'a': 1, 'b': 2}
{'a': 1, 'b': 2}
>>> {'a': 1, 'b': 2}.items()
[('a', 1), ('b', 2)]
</code></pre>
<p>Most ... | 4 | 2009-03-23T15:47:08Z | [
"python",
"order"
] |
Error while deploying Django on Apache | 673,936 | <p>I have a small Django website which I am trying to run on an Apache 2.2 HTTP-Server.
The application is running fine using "python manage.py runserver".</p>
<p>Django Version: 1.0.2 final <br />
Python: 2.5<br />
OS: Windows 2000<br /></p>
<p>I wen't through the steps described in the <a href="http://docs.djangop... | 1 | 2009-03-23T15:52:46Z | 674,237 | <p>Have you installed gettext? Or a maybe different version of it...</p>
| 0 | 2009-03-23T17:00:04Z | [
"python",
"windows",
"django",
"apache",
"mod-python"
] |
Error while deploying Django on Apache | 673,936 | <p>I have a small Django website which I am trying to run on an Apache 2.2 HTTP-Server.
The application is running fine using "python manage.py runserver".</p>
<p>Django Version: 1.0.2 final <br />
Python: 2.5<br />
OS: Windows 2000<br /></p>
<p>I wen't through the steps described in the <a href="http://docs.djangop... | 1 | 2009-03-23T15:52:46Z | 675,981 | <p>The problem is that you are importing your app ("main") as if it lives directly on the Python path, and your URLconf ("therap.urls") as if it lives within a "therap" module on the Python path. This can only work if both "D:/therap" and "D:/therap/therap" are BOTH on the Python path (which runserver does for you aut... | 3 | 2009-03-24T02:38:00Z | [
"python",
"windows",
"django",
"apache",
"mod-python"
] |
How can I make the Django contrib Admin change list for a particular model class editable with drop downs for related items displayed in the listing? | 673,970 | <p>Basically I want to have an editable form for related entries instead of a static listing. </p>
| 1 | 2009-03-23T16:00:39Z | 680,830 | <p>Try Django 1.1 beta. It's got the option to make items in the changelist editable (as well as incorporating the django-batchadmin project) </p>
| 1 | 2009-03-25T09:24:43Z | [
"python",
"django",
"django-admin",
"django-templates",
"django-forms"
] |
Django syncdb locking up on table creation | 674,030 | <p>I've added new models and pushed to our staging server, run syncdb to create their tables, and it locks up. It gets as far as 'Create table photos_photousertag' and postgres output shows the notice for creation of 'photos_photousertag_id_seq', but otherwise i get nothing on either said. I can't ctrl+c the syncdb pro... | 3 | 2009-03-23T16:16:18Z | 674,105 | <p>We use postgres, and while we've not run into this particular issue, there are some steps you may find helpful in debugging:</p>
<p>a. What version of postgres and psycopg2 are you using? For that matter, what version of django?</p>
<p>b. Try running the syncdb command with the "--verbosity=2" option to show all o... | 1 | 2009-03-23T16:30:12Z | [
"python",
"django",
"django-syncdb"
] |
Django syncdb locking up on table creation | 674,030 | <p>I've added new models and pushed to our staging server, run syncdb to create their tables, and it locks up. It gets as far as 'Create table photos_photousertag' and postgres output shows the notice for creation of 'photos_photousertag_id_seq', but otherwise i get nothing on either said. I can't ctrl+c the syncdb pro... | 3 | 2009-03-23T16:16:18Z | 10,438,955 | <p>I just experienced this as well, and it turned out to just be a plain old lock on that particular table, unrelated to Django. Once that cleared the sync went through just fine.</p>
<p>Try querying the table that the sync is getting stuck on and make sure that's working correctly first.</p>
| 1 | 2012-05-03T20:35:57Z | [
"python",
"django",
"django-syncdb"
] |
Django syncdb locking up on table creation | 674,030 | <p>I've added new models and pushed to our staging server, run syncdb to create their tables, and it locks up. It gets as far as 'Create table photos_photousertag' and postgres output shows the notice for creation of 'photos_photousertag_id_seq', but otherwise i get nothing on either said. I can't ctrl+c the syncdb pro... | 3 | 2009-03-23T16:16:18Z | 21,254,637 | <p>Strange here too, but <strong>simply restarting the PostgreSQL service (or server)</strong> solved it. I'd tried manually pasting the table creation code in psql too, but that wasn't solving it either (well, no way it could if it was a lock thing) - so I just used the restart:</p>
<blockquote>
<p>systemctl restar... | 0 | 2014-01-21T09:53:51Z | [
"python",
"django",
"django-syncdb"
] |
How to display errors to the user while still logging it? | 674,067 | <p>I'm using a PyQt4 user interface. I've redirected stderr to a log file for easy debugging and trouble-shooting, but now I need to display error messages to the user when an error occurs.</p>
<p>My issue is that I need to catch an exception when it happens and let the user know that it happened, but still let the t... | 2 | 2009-03-23T16:22:51Z | 674,073 | <p>Exactly, but you can just</p>
<pre><code>raise
</code></pre>
<p>which will re-raise the currently handled exception.</p>
| 3 | 2009-03-23T16:24:38Z | [
"python",
"exception-handling",
"error-handling",
"pyqt4",
"error-logging"
] |
How to display errors to the user while still logging it? | 674,067 | <p>I'm using a PyQt4 user interface. I've redirected stderr to a log file for easy debugging and trouble-shooting, but now I need to display error messages to the user when an error occurs.</p>
<p>My issue is that I need to catch an exception when it happens and let the user know that it happened, but still let the t... | 2 | 2009-03-23T16:22:51Z | 674,149 | <p>I think you are thinking about this in the wrong way. You shouldn't be re-raising the error simply to log it further down the line. The cannonical way of doing this in Python is to use the logging module. Adapted from the docs:</p>
<pre><code>import logging
LOG_FILENAME = '/tmp/logging_example.out'
logging.basicCon... | 6 | 2009-03-23T16:41:55Z | [
"python",
"exception-handling",
"error-handling",
"pyqt4",
"error-logging"
] |
How to display errors to the user while still logging it? | 674,067 | <p>I'm using a PyQt4 user interface. I've redirected stderr to a log file for easy debugging and trouble-shooting, but now I need to display error messages to the user when an error occurs.</p>
<p>My issue is that I need to catch an exception when it happens and let the user know that it happened, but still let the t... | 2 | 2009-03-23T16:22:51Z | 674,884 | <p>Some additional information:</p>
<p>(With PyQt4) you will also need to rebind sys.excepthook to your own function to catch all <em>uncaught</em> exceptions. Otherwise PyQt will just print them to the console, which may not be what you need...</p>
<pre><code>import sys
def excepthook(exc_type, exc_val, tracebackob... | 1 | 2009-03-23T19:27:35Z | [
"python",
"exception-handling",
"error-handling",
"pyqt4",
"error-logging"
] |
Python list.index throws exception when index not found | 674,229 | <p>Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this?</p>
<p>To me it looks cleaner to deal with special values, etc than exceptions.</p>
<p>EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None?</p>
| 9 | 2009-03-23T16:58:07Z | 674,250 | <p>Because <code>-1</code> is itself a valid index. It could use a different value, such as <code>None</code>, but that wouldn't be useful, which <code>-1</code> can be in other situations (thus <code>str.find()</code>), and would amount simply to error-checking, which is exactly what exceptions are for.</p>
| 10 | 2009-03-23T17:02:18Z | [
"python",
"indexing",
"list"
] |
Python list.index throws exception when index not found | 674,229 | <p>Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this?</p>
<p>To me it looks cleaner to deal with special values, etc than exceptions.</p>
<p>EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None?</p>
| 9 | 2009-03-23T16:58:07Z | 674,258 | <p>In Python, -1 is a valid index, meaning a number from the end of the list (instead of the beginning), so if you were to do</p>
<pre><code>idx = mylist.index(someval)
nextval = mylist[idx+1]
</code></pre>
<p>then you would get the first value of the array, instead of realising there was an error. This way you can c... | 3 | 2009-03-23T17:04:00Z | [
"python",
"indexing",
"list"
] |
Python list.index throws exception when index not found | 674,229 | <p>Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this?</p>
<p>To me it looks cleaner to deal with special values, etc than exceptions.</p>
<p>EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None?</p>
| 9 | 2009-03-23T16:58:07Z | 674,259 | <p>Well, the special value would actually have to be <strong><code>None</code></strong>, because -1 is a valid index (meaning the last element of a list). </p>
<p>You can emulate this behavior by:</p>
<pre><code>idx = l.index(x) if x in l else None
</code></pre>
| 5 | 2009-03-23T17:04:10Z | [
"python",
"indexing",
"list"
] |
Python list.index throws exception when index not found | 674,229 | <p>Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this?</p>
<p>To me it looks cleaner to deal with special values, etc than exceptions.</p>
<p>EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None?</p>
| 9 | 2009-03-23T16:58:07Z | 674,262 | <p>One simple idea: <code>-1</code> is perfectly usable as an index (as are other negative values).</p>
| 1 | 2009-03-23T17:04:17Z | [
"python",
"indexing",
"list"
] |
Python list.index throws exception when index not found | 674,229 | <p>Why does list.index throws an exception instead of returning a value like say -1? What's the idea behind this?</p>
<p>To me it looks cleaner to deal with special values, etc than exceptions.</p>
<p>EDIT: I didn't realize -1 to be usable, but in that case, how about a value of None?</p>
| 9 | 2009-03-23T16:58:07Z | 674,268 | <p>To add to Devin's response: This is an old debate between special return values versus exceptions. Many programming gurus prefer an exception because on an exception, I get to see the whole stacktrace and immediate infer what is wrong. </p>
| 7 | 2009-03-23T17:05:02Z | [
"python",
"indexing",
"list"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.