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
Django user impersonation by admin
2,242,909
<p>I have a Django app. When logged in as an admin user, I want to be able to pass a secret parameter in the URL and have the whole site behave as if I were another user.</p> <p>Let's say I have the URL <code>/my-profile/</code> which shows the currently logged in user's profile. I want to be able to do something like...
17
2010-02-11T07:35:59Z
28,763,695
<p>It looks like quite a few other people have had this problem and have written re-usable apps to do this and at least some are listed on the <a href="https://www.djangopackages.com/grids/g/user-switching/" rel="nofollow">django packages page for user switching</a>. The most active at time of writing appear to be:</p>...
4
2015-02-27T11:10:46Z
[ "python", "django", "impersonation" ]
Django: "TypeError: [] is not JSON serializable" Why?
2,243,002
<p>How can this be that this error was raised? I entered this:</p> <pre><code>def json(self): return json.dumps( { 'items': self.items } ) </code></pre> <p>and got that error (because self.items was an empty queryset (Django)</p> <p>but then,</p> <pre><code>def json(self): re...
33
2010-02-11T07:58:32Z
2,243,652
<p>Querysets are not serializable out-of-the-box. If you try <code>list(self.items)</code> instead of just <code>self.items</code>, that should work as long as the items themselves are JSON-serializable.</p> <p><strong>Update:</strong> It will raise an exception even if it isn't empty. I don't think it'll be accepted ...
52
2010-02-11T10:05:59Z
[ "python", "django", "json" ]
Django: "TypeError: [] is not JSON serializable" Why?
2,243,002
<p>How can this be that this error was raised? I entered this:</p> <pre><code>def json(self): return json.dumps( { 'items': self.items } ) </code></pre> <p>and got that error (because self.items was an empty queryset (Django)</p> <p>but then,</p> <pre><code>def json(self): re...
33
2010-02-11T07:58:32Z
9,746,559
<p>This is very frustrating. Django's serialization complains about everything that isn't a query set and json.dumps complains about objects from Django's ORM support.</p> <pre><code>&gt;&gt;&gt; from cluster.models import Account &gt;&gt;&gt; import json &gt;&gt;&gt; json.dumps(Account.objects.all()[0]) Traceback (m...
5
2012-03-17T01:49:26Z
[ "python", "django", "json" ]
Django: "TypeError: [] is not JSON serializable" Why?
2,243,002
<p>How can this be that this error was raised? I entered this:</p> <pre><code>def json(self): return json.dumps( { 'items': self.items } ) </code></pre> <p>and got that error (because self.items was an empty queryset (Django)</p> <p>but then,</p> <pre><code>def json(self): re...
33
2010-02-11T07:58:32Z
14,653,384
<p>As Vinay pointed out, even if you cast to a list, serialization often still fails. For me, serialization fails on DateTimeField elements (<code>datetime.datetime</code> objects), even if I ask for a <code>ValuesQuerySet</code> (list-like) with <code>.values()</code>. The solution for me was a simple comprehension.</...
4
2013-02-01T19:10:43Z
[ "python", "django", "json" ]
(python) docstring is causing indentation error
2,243,009
<pre><code>def getText(nodelist): """Extracts the text between XML tags I took this directly from http://docs.python.org/library/xml.dom.minidom.html. For example, if I have a tag &lt;Tag&gt;525&lt;/Tag&gt; this method returns me '525' """ rc = "" for node in nodelist: if node.nodeType ...
7
2010-02-11T08:01:03Z
2,243,025
<p>Make sure you are not mixing spaces and tabs for your indentation</p>
2
2010-02-11T08:04:00Z
[ "python", "indentation" ]
(python) docstring is causing indentation error
2,243,009
<pre><code>def getText(nodelist): """Extracts the text between XML tags I took this directly from http://docs.python.org/library/xml.dom.minidom.html. For example, if I have a tag &lt;Tag&gt;525&lt;/Tag&gt; this method returns me '525' """ rc = "" for node in nodelist: if node.nodeType ...
7
2010-02-11T08:01:03Z
2,243,027
<p>Your docstring starts with tabs. Make your code only use spaces for indentation (or only tabs), including the indentation for the docstrings.</p>
9
2010-02-11T08:04:19Z
[ "python", "indentation" ]
Getting certain attribute value using XPath
2,243,131
<p>From the following HTML snippet:</p> <pre><code>&lt;link rel="index" href="/index.php" /&gt; &lt;link rel="contents" href="/getdata.php" /&gt; &lt;link rel="copyright" href="/blabla.php" /&gt; &lt;link rel="shortcut icon" href="/img/all/favicon.ico" /&gt; </code></pre> <p>I'm trying to get the <code>href</code> va...
6
2010-02-11T08:29:34Z
2,243,186
<p>Like this:</p> <pre><code>data = """&lt;link rel="index" href="/index.php" /&gt; &lt;link rel="contents" href="/getdata.php" /&gt; &lt;link rel="copyright" href="/blabla.php" /&gt; &lt;link rel="shortcut icon" href="/img/all/favicon.ico" /&gt; """ from lxml import etree d = etree.HTML(data) d.xpath('//link[@rel=...
9
2010-02-11T08:42:18Z
[ "python", "xpath" ]
Threads in twisted... how to use them properly?
2,243,266
<p>I need to write a simple app that runs two threads: - thread 1: runs at timed periods, let's say every 1 minute - thread 2: just a 'normal' while True loop that does 'stuff'</p> <p>if not the requirement to run at timed interval I would have not looked at twisted at all, but simple sleep(60) is not good enough and ...
9
2010-02-11T08:58:03Z
2,243,406
<p>Assuming that your main is relatively non-blocking:</p> <pre><code>import random from twisted.internet import task class MyProcess: def __init__(self): self.stats = [] self.lp = None def myloopingCall(self): print "I have %s stats" % len(self.stats) def myMainFunction(self,reactor): self.stat...
2
2010-02-11T09:21:53Z
[ "python", "multithreading", "twisted", "timedelay" ]
Threads in twisted... how to use them properly?
2,243,266
<p>I need to write a simple app that runs two threads: - thread 1: runs at timed periods, let's say every 1 minute - thread 2: just a 'normal' while True loop that does 'stuff'</p> <p>if not the requirement to run at timed interval I would have not looked at twisted at all, but simple sleep(60) is not good enough and ...
9
2010-02-11T08:58:03Z
2,244,899
<p>You didn't explain why you actually need threads here. If you had, I might have been able to explain why you <em>don't</em> need them. ;)</p> <p>That aside, I can confirm that your basic understanding of things is correct. One possible misunderstanding I can clear up, though, is the notion that "python threads" a...
5
2010-02-11T14:08:01Z
[ "python", "multithreading", "twisted", "timedelay" ]
Disable cache in Pylons app under development mode
2,243,470
<p>I'm using <code>@beaker_cache()</code> decorator in my Pylons application. How can I disable the cache under development mode?</p>
0
2010-02-11T09:32:51Z
2,258,420
<p>You could write your own decorator which looks at pylons.config["debug"], and depending on that either returns function unchanged or decorated with beaker_cache. Something along these lines (completely untested!):</p> <pre><code>from pylons import config def my_cache(*args, **kwargs): if config["debug"]: ...
1
2010-02-13T17:34:01Z
[ "python", "pylons" ]
how to efficiently get the k bigger elements of a list in python
2,243,542
<p>What´s the most efficient, elegant and pythonic way of solving this problem?</p> <p>Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume <code>k&lt;n/2</code> without loss of generality, I guess) For example, if the list were:</p> <pre><code>l = [9,1,6,4,2,8,3,7,5] ...
14
2010-02-11T09:47:17Z
2,243,558
<pre><code>l = [9,1,6,4,2,8,3,7,5] sorted(l)[-k:] </code></pre>
6
2010-02-11T09:50:14Z
[ "algorithm", "sorting", "performance", "python" ]
how to efficiently get the k bigger elements of a list in python
2,243,542
<p>What´s the most efficient, elegant and pythonic way of solving this problem?</p> <p>Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume <code>k&lt;n/2</code> without loss of generality, I guess) For example, if the list were:</p> <pre><code>l = [9,1,6,4,2,8,3,7,5] ...
14
2010-02-11T09:47:17Z
2,243,562
<p>Use nlargest from heapq module</p> <pre><code>from heapq import nlargest lst = [9,1,6,4,2,8,3,7,5] nlargest(3, lst) # Gives [9,8,7] </code></pre> <p>You can also give a key to nlargest in case you wanna change your criteria:</p> <pre><code>from heapq import nlargest tags = [ ("python", 30), ("ruby", 25), ("c++", ...
28
2010-02-11T09:50:45Z
[ "algorithm", "sorting", "performance", "python" ]
how to efficiently get the k bigger elements of a list in python
2,243,542
<p>What´s the most efficient, elegant and pythonic way of solving this problem?</p> <p>Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume <code>k&lt;n/2</code> without loss of generality, I guess) For example, if the list were:</p> <pre><code>l = [9,1,6,4,2,8,3,7,5] ...
14
2010-02-11T09:47:17Z
2,243,563
<p>You can use the <code>heapq</code> module.</p> <pre><code>&gt;&gt;&gt; from heapq import heapify, nlargest &gt;&gt;&gt; l = [9,1,6,4,2,8,3,7,5] &gt;&gt;&gt; heapify(l) &gt;&gt;&gt; nlargest(3, l) [9, 8, 7] &gt;&gt;&gt; </code></pre>
3
2010-02-11T09:50:47Z
[ "algorithm", "sorting", "performance", "python" ]
how to efficiently get the k bigger elements of a list in python
2,243,542
<p>What´s the most efficient, elegant and pythonic way of solving this problem?</p> <p>Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume <code>k&lt;n/2</code> without loss of generality, I guess) For example, if the list were:</p> <pre><code>l = [9,1,6,4,2,8,3,7,5] ...
14
2010-02-11T09:47:17Z
2,243,574
<pre><code>sorted(l, reverse=True)[:k] </code></pre>
3
2010-02-11T09:52:31Z
[ "algorithm", "sorting", "performance", "python" ]
how to efficiently get the k bigger elements of a list in python
2,243,542
<p>What´s the most efficient, elegant and pythonic way of solving this problem?</p> <p>Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You can assume <code>k&lt;n/2</code> without loss of generality, I guess) For example, if the list were:</p> <pre><code>l = [9,1,6,4,2,8,3,7,5] ...
14
2010-02-11T09:47:17Z
2,243,598
<p>The simple, O(n log n) way is to sort the list then get the last <em>k</em> elements.</p> <p>The proper way is to use a <a href="http://en.wikipedia.org/wiki/Selection_algorithm#Selecting_k_smallest_or_largest_elements" rel="nofollow">selection algorithm</a>, which runs in O(n + k log k) time.</p> <p>Also, <code>h...
5
2010-02-11T09:56:12Z
[ "algorithm", "sorting", "performance", "python" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,243,747
<p>not really sure what you mean, but you can always check for existence with if</p> <pre><code>&gt;&gt;&gt; reader = csv.reader("file") &gt;&gt;&gt; for r in reader: ... if r: print r ... </code></pre> <p>if this is not what you want, you should describe your problem more clearly by showing examples of things tha...
0
2010-02-11T10:19:15Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,243,848
<p>The Django community has addressed Python CSV import issues, so it might be worth <a href="http://groups.google.co.uk/group/django-users/search?group=django-users&amp;q=csv+import&amp;qt_g=Search+this+group" rel="nofollow">searching for CSV import</a> there, or posting a question. Also, you could edit the offending ...
1
2010-02-11T10:38:25Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,244,051
<p>Maybe you could catch the exception raised by the CSV reader. Something like this:</p> <pre><code>filename = "my.csv" reader = csv.reader(open(filename)) try: for row in reader: print 'Row read with success!', row except csv.Error, e: sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))...
12
2010-02-11T11:22:54Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,244,202
<p>If your problem is specific to the last line being empty, you can use numpy.genfromtxt (or the old matplotlib.mlab.csv2rec)</p> <pre><code>$: cat &gt;csv_file.txt foo,bar,baz yes,no,0 x,y,z $: $: ipython &gt;&gt;&gt; from numpy import genfromtxt &gt;&gt;&gt; genfromtxt("csv_file.txt", dtype=None, delimiter=',') ...
1
2010-02-11T11:55:54Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,244,373
<p>You need (always) to say EXACTLY what is the error message that you got. Please edit your question.</p> <p>Probably this:</p> <pre><code>&gt;&gt;&gt; import csv; csv.reader("\x00").next() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; _csv.Error: line contains NULL byte &gt;&g...
3
2010-02-11T12:30:55Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,244,379
<p>I don't have an answer, but I can confirm the problem, and that most answers posted don't work. You cannot catch this exception. You cannot test for <code>if line</code>. Maybe you could check for the NULL byte directly, but I'm not swift enough to do that... If it is always on the last line, you could of course...
0
2010-02-11T12:32:14Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
2,450,431
<p>You could try cleaning the file as you read it:</p> <pre><code>def nonull(stream): for line in stream: yield line.replace('\x00', '') f = open(filename) reader = csv.reader(nonull(f)) </code></pre> <p>Assuming, of course, that simply ignoring NULL characters will work for you!</p>
1
2010-03-15T20:58:00Z
[ "python", "csv" ]
reading csv file without for
2,243,655
<p>I need to read a CSV file in python.</p> <p>Since for last row I receive a 'NULL byte' error I would like to avoid using for keyword but the while.</p> <p>Do you know how to do that?</p> <pre> reader = csv.reader( file ) for row in reader # I have an error at this line # do whatever with row </...
7
2010-02-11T10:06:50Z
14,355,781
<p>Process the initial <code>csv</code> file and replace the <code>Nul '\0'</code> with blank, and then you can read it. The actual code looks like this:</p> <pre><code>data_initial = open(csv_file, "rU") reader = csv.reader((line.replace('\0','') for line in data_initial)) </code></pre> <p>It works for me.</p> <p>A...
0
2013-01-16T10:06:47Z
[ "python", "csv" ]
Simulate a device driver crash in linux. Have python reload it
2,243,674
<p>I have a web camera running in Linux using the uvcvideo module. And I'm using a python application to access the web camera and display the image.</p> <p>I want the python program to handle it if the web camera for some reason don't work anymore. Have tested with just unloading the module. Works fine if i just unlo...
2
2010-02-11T10:09:47Z
2,243,839
<p>Linux really doesn't like it when you try to remove a kernel driver while any processes are using it. I'm not convinced there's any good way for your userland application to do this (and having your app try to run 'sudo modprobe uvcvideo' is scary enough already).</p>
1
2010-02-11T10:36:37Z
[ "python", "linux" ]
Simulate a device driver crash in linux. Have python reload it
2,243,674
<p>I have a web camera running in Linux using the uvcvideo module. And I'm using a python application to access the web camera and display the image.</p> <p>I want the python program to handle it if the web camera for some reason don't work anymore. Have tested with just unloading the module. Works fine if i just unlo...
2
2010-02-11T10:09:47Z
2,243,849
<p>Do you mean USB camera ? I don't know about forced unloading while module is in use, but this won't happen and is not a good simulation of camera not working anymore. Try to handle camera disconnection /reconnection gracefully first.</p> <p>I don't know what you are trying to achieve when simulating driver crash, b...
4
2010-02-11T10:38:27Z
[ "python", "linux" ]
Simulate a device driver crash in linux. Have python reload it
2,243,674
<p>I have a web camera running in Linux using the uvcvideo module. And I'm using a python application to access the web camera and display the image.</p> <p>I want the python program to handle it if the web camera for some reason don't work anymore. Have tested with just unloading the module. Works fine if i just unlo...
2
2010-02-11T10:09:47Z
2,248,683
<p>The reason your code now is crashing is because when the driver crashes, the device special files representing your hardware disappear. Your code still has open file handles to those devices. Depending on what exactly your code is doing behind the scenes, it is likely trying to issue an IOCTL to a now-invalid file...
2
2010-02-11T23:54:41Z
[ "python", "linux" ]
Venn Diagram up to 4 lists - outputting the intersections and unique sets
2,243,690
<p>in my work I use a lot of Venn diagrams, and so far I've been relying on the web-based "<a href="http://bioinfogp.cnb.csic.es/tools/venny/index.html" rel="nofollow">Venny</a>". This offers the nice option to export the various intersections (i.e., the elements belonging only to that specific intersection). Also, it ...
3
2010-02-11T10:10:59Z
2,243,990
<p>Assuming you have python 2.6 or better:</p> <pre><code>&gt;&gt;&gt; from itertools import combinations &gt;&gt;&gt; &gt;&gt;&gt; data = dict( ... list1 = set(list("alphabet")), ... list2 = set(list("fiddlesticks")), ... list3 = set(list("geography")), ... list4 = set(list("bovinespongiformencephalopathy")),...
6
2010-02-11T11:09:15Z
[ "python", "list", "venn-diagram" ]
Location to put user configuration files in windows
2,243,895
<p>I'm writing a python library that has a per-user configuration file that can be edited by the user of the library. The library also generates logging files. On *nix, the standard seems to be to dump them in $HOME/.library_name.</p> <p>However, I am not sure what to do with Windows users. I've used windows for y...
5
2010-02-11T10:48:37Z
2,243,910
<p>%APPDATA% is the right place for these (probably in a subdirectory for your library). Unfortunately a fair number of *nix apps ported to Windows <em>don't</em> respect that and I end up with .gem, .ssh, .VirtualBox, etc., folders cluttering up my home directory and not hidden by default as on *nix.</p> <p>You can m...
9
2010-02-11T10:52:01Z
[ "python", "windows", "configuration", "configuration-files" ]
Location to put user configuration files in windows
2,243,895
<p>I'm writing a python library that has a per-user configuration file that can be edited by the user of the library. The library also generates logging files. On *nix, the standard seems to be to dump them in $HOME/.library_name.</p> <p>However, I am not sure what to do with Windows users. I've used windows for y...
5
2010-02-11T10:48:37Z
2,243,919
<p>On windows the user is not expected to configure an application using editable config files so there is no standard.<br> The standard for configuration which is editable using a GUI is the registry.</p> <p>If you're using QT (or PyQT?) then you can use <code>QSettings</code> which provide an abstraction layer. On L...
1
2010-02-11T10:53:55Z
[ "python", "windows", "configuration", "configuration-files" ]
Location to put user configuration files in windows
2,243,895
<p>I'm writing a python library that has a per-user configuration file that can be edited by the user of the library. The library also generates logging files. On *nix, the standard seems to be to dump them in $HOME/.library_name.</p> <p>However, I am not sure what to do with Windows users. I've used windows for y...
5
2010-02-11T10:48:37Z
13,427,129
<p>The python <a href="http://pypi.python.org/pypi/appdirs/1.2.0">appdirs</a> package does a nice job of finding the standard place for application data on various platforms. E.g. for Windows it uses the English XP location:</p> <pre><code>C:\Documents and Settings\&lt;User&gt;\Application Data\Local Settings\&lt;App...
6
2012-11-17T02:37:59Z
[ "python", "windows", "configuration", "configuration-files" ]
How to log python program activity in Mac OS X
2,244,153
<p>I'm pretty new to Python programming so I have this question:</p> <p>How can I log a Python application activity into /var/log with Mac OS X?</p> <p>I tried using syslog module, but it does not seem to write anything. I tried also with the logging module, but I always run into a permission error.</p> <p>How can I...
9
2010-02-11T11:45:47Z
2,244,347
<p>the problem is that the account you are running the script as does not have write permission to <code>/var/log</code></p> <p>I do not know about OS X specifics, but I guess that <code>syslog.syslog("message")</code> should print something like (if it acts the way it does in Linux) <code>Feb 11 14:27:47 hostname pyt...
-1
2010-02-11T12:27:18Z
[ "python", "osx", "logging" ]
How to log python program activity in Mac OS X
2,244,153
<p>I'm pretty new to Python programming so I have this question:</p> <p>How can I log a Python application activity into /var/log with Mac OS X?</p> <p>I tried using syslog module, but it does not seem to write anything. I tried also with the logging module, but I always run into a permission error.</p> <p>How can I...
9
2010-02-11T11:45:47Z
2,244,619
<p>I found the solution. It seems that Mac OS X does not record any log activity lower than LOG_ALERT, so this does the trick</p> <pre><code>import syslog # Define identifier syslog.openlog("Python") # Record a message syslog.syslog(syslog.LOG_ALERT, "Example message") </code></pre> <p>This message is recorded on /va...
20
2010-02-11T13:15:31Z
[ "python", "osx", "logging" ]
How to log python program activity in Mac OS X
2,244,153
<p>I'm pretty new to Python programming so I have this question:</p> <p>How can I log a Python application activity into /var/log with Mac OS X?</p> <p>I tried using syslog module, but it does not seem to write anything. I tried also with the logging module, but I always run into a permission error.</p> <p>How can I...
9
2010-02-11T11:45:47Z
7,375,189
<p>You can use the command line tool "syslog" on os x, to get all syslog events.</p>
1
2011-09-10T22:49:07Z
[ "python", "osx", "logging" ]
How to log python program activity in Mac OS X
2,244,153
<p>I'm pretty new to Python programming so I have this question:</p> <p>How can I log a Python application activity into /var/log with Mac OS X?</p> <p>I tried using syslog module, but it does not seem to write anything. I tried also with the logging module, but I always run into a permission error.</p> <p>How can I...
9
2010-02-11T11:45:47Z
19,168,224
<p>Here's a guide with about 5 steps you need to complete - they're straightforward, and it worked for me:</p> <p><a href="http://vastdevblog.vast.com/blog/2012/04/18/using-syslogappender-on-os-x/" rel="nofollow">http://vastdevblog.vast.com/blog/2012/04/18/using-syslogappender-on-os-x/</a></p> <p>Pay close attention ...
1
2013-10-03T20:02:52Z
[ "python", "osx", "logging" ]
WSGI/Django: pass username back to Apache for access log
2,244,244
<p>My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful.</p> <p>Is there a way to pass the username back through the WSGI wrapper to Apache after han...
8
2010-02-11T12:03:10Z
2,244,295
<p>This probably isn't what you're expecting, but you could use the username in your URL scheme. That way the user will be in the path section of your apache logs.</p> <p>You'd need to modify your authentication so that auth-required responses are obvious in the apache logs, otherwise when viewing the logs you may att...
1
2010-02-11T12:17:06Z
[ "python", "django", "apache", "authentication", "mod-wsgi" ]
WSGI/Django: pass username back to Apache for access log
2,244,244
<p>My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful.</p> <p>Is there a way to pass the username back through the WSGI wrapper to Apache after han...
8
2010-02-11T12:03:10Z
2,248,201
<p>You can only do it if using embedded mode and only if you use a separate package called apswigpy, which provides a Python binding for original Apache request object. The mod_wsgi package provides an optional mechanism for allowing original Apache request object to be passed as Python CObject reference in WSGI enviro...
4
2010-02-11T22:21:04Z
[ "python", "django", "apache", "authentication", "mod-wsgi" ]
WSGI/Django: pass username back to Apache for access log
2,244,244
<p>My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful.</p> <p>Is there a way to pass the username back through the WSGI wrapper to Apache after han...
8
2010-02-11T12:03:10Z
2,248,265
<p>You could use <a href="http://www.openfusion.com.au/labs/mod_auth_tkt/" rel="nofollow">mod_auth_tkt</a>. An <code>auth_tkt</code> is a signed cookie with the user id that Apache can understand. Your web application would have to <a href="http://pythonpaste.org/modules/auth.auth_tkt.html#paste.auth.auth_tkt.AuthTicke...
3
2010-02-11T22:30:16Z
[ "python", "django", "apache", "authentication", "mod-wsgi" ]
WSGI/Django: pass username back to Apache for access log
2,244,244
<p>My Django app, deployed in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates users via form login on the Django side. So to Apache, the user is anonymous. This makes the Apache access log less useful.</p> <p>Is there a way to pass the username back through the WSGI wrapper to Apache after han...
8
2010-02-11T12:03:10Z
10,406,967
<p>Correct me if I'm wrong, but what's stopping you from creating some custom middleware that sets a cookie equal to the display name of the current user logged in. This middleware will run on every view, so even though technically the user could spoof his username to display whatever he wants it to display, it'll just...
1
2012-05-02T02:32:26Z
[ "python", "django", "apache", "authentication", "mod-wsgi" ]
How to replace launchd scheduling with a Python program
2,244,261
<p>The Mac OS X system startup program <a href="http://17.254.2.129/macosx/launchd.html" rel="nofollow"><em>launchd</em></a> enables job scheduling (similar to <em>cron</em>.) By creating a <em>launchd</em> agent, one can trigger programs through one of the following events:</p> <ul> <li>an interval of time has elapse...
0
2010-02-11T12:07:37Z
2,244,403
<p>For the filesystem-monitoring problem, perhaps you are looking for <a href="http://pypi.python.org/pypi/pyfsevents/0.2b1" rel="nofollow">pyfsevents</a>. According to <a href="http://www.mac-forums.com/forums/os-x-darwin-development/107170-inotify-mac.html" rel="nofollow">this post</a>,</p> <blockquote> <p>FSEvent...
1
2010-02-11T12:36:59Z
[ "python", "osx", "launchd" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,287
<p>Modern Python exceptions are classes; by using <code>raise 'incorrect'</code>, you are using a deprecated language feature called string exceptions. The <a href="http://docs.python.org/tutorial/errors.html" rel="nofollow">Errors and Exceptions</a> section of the Python tutorial would be a good place to start with ba...
4
2010-02-11T12:13:58Z
[ "python", "exception-handling", "loops", "try-catch" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,290
<p>Your approach seems to be a very long-winded way to accomplish something fairly simple:</p> <pre><code>def Release() : while True : print 'Please select one of the following?\nCompletion = 0\nRelease ID = 1\nVersion ID = 2\nBuild ID = 3\n' a = int(input("Please select the type of release require...
4
2010-02-11T12:14:42Z
[ "python", "exception-handling", "loops", "try-catch" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,294
<p>You are both throwing and catching the exception in the same simple block of code - this is not really what exception handling is about. You can do it better either by breaking out of a loop or by keeping a condition. E.g.:</p> <pre><code>def isNumberCorrect(x): return x in range(4) def Release(): num = Non...
2
2010-02-11T12:17:02Z
[ "python", "exception-handling", "loops", "try-catch" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,302
<p>Instead of using exceptions you could do something like this:</p> <pre><code>... a = raw_input("Please select the type of release required:") while a not in ['0','1','2','3']: a = raw_input("Try again: ") files(int(a)) ... </code></pre>
2
2010-02-11T12:19:20Z
[ "python", "exception-handling", "loops", "try-catch" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,307
<pre><code>def files(a): pass while True: try: i = int(input('Select: ')) if i in range(4): files(i) break except: pass print '\nIncorrect input, try again' </code></pre>
23
2010-02-11T12:19:48Z
[ "python", "exception-handling", "loops", "try-catch" ]
Get a Try statement to loop around until correct value obtained
2,244,270
<p>I am trying to get a user to enter a number between 1 and 4. I have code to check if the number is correct but I want the code to loop around several times until the numbers is correct. Does anyone know how to do this? The code is below:</p> <pre><code>def Release(): try: print 'Please select one of t...
10
2010-02-11T12:09:44Z
2,244,395
<pre><code>def Release(): while 1: print """Please select one of the following? Completion = 0 Release ID = 1 Version ID = 2 Build ID = 3 Exit = 4 """ try: a = int(raw_input("Please select t...
1
2010-02-11T12:35:14Z
[ "python", "exception-handling", "loops", "try-catch" ]
Python Virtualbox API
2,244,368
<p>I have made a command-line interface for virtualbox such that the virtualbox can be controlled from a remote machine. now I am trying to implement the commmand-line interface using python virtualbox api. For that I have downloaded the pyvb package (python api documentation shows functions that can be used for imple...
1
2010-02-11T12:30:33Z
2,244,465
<p><a href="http://enomalism.com/api/pyvb/pyvb.vb.VB-class.html#startVM" rel="nofollow"><code>startVM</code></a> is in <code>pyvb.vb.VB</code> class. Also, it's not <code>'name of vm'</code>, as docs explain <code>startVM</code> should be called with <a href="http://enomalism.com/api/pyvb/pyvb.vm.vbVM-class.html" rel="...
3
2010-02-11T12:49:29Z
[ "python", "api", "virtualbox" ]
Python: How to find the slope of a graph drawn using matplotlib?
2,244,386
<p>Here is my code:</p> <pre><code>import matplotlib.pyplot as plt plt.loglog(length,time,'--') </code></pre> <p>where length and time are lists.</p> <p>How do I find the slope of this graph?</p>
9
2010-02-11T12:33:32Z
2,244,447
<p>If you have matplotlib then you must also have numpy installed since it is a dependency. Therefore, you could use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html#numpy.polyfit" rel="nofollow">numpy.polyfit</a> to find the slope:</p> <pre><code>import matplotlib.pyplot as plt import n...
14
2010-02-11T12:46:03Z
[ "python" ]
Comparing list item values to other items in other list in Python
2,244,443
<p>I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e.</p> <pre><code>list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] </code></pre> <p>would return 'three' and 'five'.</p> <p>I have only a little e...
3
2010-02-11T12:44:57Z
2,244,457
<p>Use sets to get the difference between the lists:</p> <pre><code>&gt;&gt;&gt; list1 = ['one','two','three','four','five'] &gt;&gt;&gt; list2 = ['one','two','four'] &gt;&gt;&gt; set(list1) - set(list2) set(['five', 'three']) </code></pre>
6
2010-02-11T12:48:07Z
[ "python", "plone", "zope" ]
Comparing list item values to other items in other list in Python
2,244,443
<p>I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e.</p> <pre><code>list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] </code></pre> <p>would return 'three' and 'five'.</p> <p>I have only a little e...
3
2010-02-11T12:44:57Z
2,244,459
<p><code>set(list1).difference(set(list2))</code></p>
8
2010-02-11T12:48:17Z
[ "python", "plone", "zope" ]
Comparing list item values to other items in other list in Python
2,244,443
<p>I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e.</p> <pre><code>list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] </code></pre> <p>would return 'three' and 'five'.</p> <p>I have only a little e...
3
2010-02-11T12:44:57Z
2,244,469
<p>You can do it with sets or a list comprehension:</p> <pre><code>unused = [i for i in list1 if i not in list2] </code></pre>
0
2010-02-11T12:49:59Z
[ "python", "plone", "zope" ]
Comparing list item values to other items in other list in Python
2,244,443
<p>I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e.</p> <pre><code>list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] </code></pre> <p>would return 'three' and 'five'.</p> <p>I have only a little e...
3
2010-02-11T12:44:57Z
2,244,487
<p>with <a href="http://docs.python.org/library/stdtypes.html#set.difference" rel="nofollow"><code>set.difference</code></a>:</p> <pre><code>&gt;&gt;&gt; list1 = ['one','two','three','four','five'] &gt;&gt;&gt; list2 = ['one','two','four'] &gt;&gt;&gt; set(list1).difference(list2) {'five', 'three'} </code></pre> <p>y...
1
2010-02-11T12:52:55Z
[ "python", "plone", "zope" ]
Comparing list item values to other items in other list in Python
2,244,443
<p>I want to compare the values in one list to the values in a second list and return all those that are in the first list but not in the second i.e.</p> <pre><code>list1 = ['one','two','three','four','five'] list2 = ['one','two','four'] </code></pre> <p>would return 'three' and 'five'.</p> <p>I have only a little e...
3
2010-02-11T12:44:57Z
2,244,540
<p>All the answers here are correct. I would use list comprehension if the lists are short; sets will be more efficient. In exploring why your code doesn't work, I don't get the error. (It doesn't work, but that's a different issue).</p> <pre><code>&gt;&gt;&gt; list1 = ['a','b','c'] &gt;&gt;&gt; list2 = ['a','b','...
0
2010-02-11T13:01:28Z
[ "python", "plone", "zope" ]
Using Djangos ImageField to upload an image, rename it to a random filename and create thumbnail
2,244,537
<p>Hay guys, I've wrote a simple upload method for my pictures</p> <pre><code>class Picture(models.Model): path = models.CharField(max_length=200) filename = models.CharField(max_length=200) car = models.ForeignKey('Car') thumb_path = models.CharField(max_length=200) created_on = models.DateField(a...
0
2010-02-11T13:01:11Z
2,244,663
<p>You could use an adapted version of:</p> <p><a href="http://www.djangosnippets.org/snippets/1100/" rel="nofollow">http://www.djangosnippets.org/snippets/1100/</a></p> <p>Or depending on what exactly you need to do you can consider a template filter based approach something like this:</p> <p><a href="http://www.dj...
1
2010-02-11T13:25:00Z
[ "python", "django", "file", "upload" ]
OAuth with Twitter script in Python is not working
2,244,608
<p>I'm writing a script of OAuth in Python.</p> <p>For testing this, I use Twitter API. But it is not working well.</p> <pre><code>def test(): params = { "oauth_consumer_key": TWITTER_OAUTH_CONSUMER_KEY, "oauth_nonce": "".join(random.choice(string.digits + string.letters) for i in xrange(7...
4
2010-02-11T13:13:13Z
2,249,604
<p>The easiest way to fix this is to add <code>status = urllib.quote(status)</code> after <code>status = {"status": u"Always_look_on_the_bright_side_of_life".encode("UTF-8")}</code>. This will escape the spaces and other special characters as required.</p>
0
2010-02-12T04:05:27Z
[ "python", "oauth", "twitter" ]
OAuth with Twitter script in Python is not working
2,244,608
<p>I'm writing a script of OAuth in Python.</p> <p>For testing this, I use Twitter API. But it is not working well.</p> <pre><code>def test(): params = { "oauth_consumer_key": TWITTER_OAUTH_CONSUMER_KEY, "oauth_nonce": "".join(random.choice(string.digits + string.letters) for i in xrange(7...
4
2010-02-11T13:13:13Z
2,264,068
<p>I got the same problem in OAuth with FaceBook a while ago. The problem is that the signature validation on server side fails. See your signature generation code here:</p> <pre><code>msg = "&amp;".join(["POST", urllib.quote(url,""), urllib.quote("&amp;".join([k+"="+params[k] for k in sorted(params)])...
1
2010-02-15T04:45:33Z
[ "python", "oauth", "twitter" ]
getting specific xml nodes attributes
2,244,629
<p>This might be a newbie question :) but it's irritating me since I'm new to XML. I have the following xml file:</p> <pre><code>&lt;assetsMain&gt; &lt;assetParent type='character' shortName='char'&gt; &lt;asset&gt; pub &lt;/asset&gt; &lt;asset&gt; car &lt;/asset&gt; &lt;/assetParent&gt...
1
2010-02-11T13:17:10Z
2,244,668
<p>An answer using lxml.etree. Xpath would probably be reusable in another capable library:</p> <pre><code>&gt;&gt;&gt; from lxml import etree &gt;&gt;&gt; data = """&lt;assetsMain&gt; ... &lt;assetParent type='character' shortName='char'&gt; ... &lt;asset&gt;pub&lt;/asset&gt; ... &lt;asset&gt;car&lt;/asset&gt; ... &l...
3
2010-02-11T13:25:54Z
[ "python", "xml" ]
getting specific xml nodes attributes
2,244,629
<p>This might be a newbie question :) but it's irritating me since I'm new to XML. I have the following xml file:</p> <pre><code>&lt;assetsMain&gt; &lt;assetParent type='character' shortName='char'&gt; &lt;asset&gt; pub &lt;/asset&gt; &lt;asset&gt; car &lt;/asset&gt; &lt;/assetParent&gt...
1
2010-02-11T13:17:10Z
2,244,821
<p>This code gives the output you want:</p> <pre><code>from xml.dom.minidom import parseString document = """\ &lt;assetsMain&gt; &lt;assetParent type='character' shortName='char'&gt; &lt;asset&gt; pub &lt;/asset&gt; &lt;asset&gt; car &lt;/asset&gt; &lt;/assetParent&gt; &lt;assetPare...
0
2010-02-11T13:54:13Z
[ "python", "xml" ]
fabric python install problem
2,244,749
<p>Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here:</p> <pre><code>Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.p...
2
2010-02-11T13:40:29Z
2,245,393
<p>Looks like you have different versions of Fabric on those servers, they changed the module structure recently.</p>
1
2010-02-11T15:18:03Z
[ "python", "django", "fabric" ]
fabric python install problem
2,244,749
<p>Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here:</p> <pre><code>Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.p...
2
2010-02-11T13:40:29Z
2,426,806
<p>I just got this message on my Ubuntu 9.10 machine; Ubuntu ships with an old version of fabric (0.1.1). The latest release version is 0.9.0.</p> <pre><code>sudo easy_install fabric </code></pre> <p>should get you the latest released version.</p>
0
2010-03-11T16:35:32Z
[ "python", "django", "fabric" ]
fabric python install problem
2,244,749
<p>Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here:</p> <pre><code>Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.p...
2
2010-02-11T13:40:29Z
2,912,775
<p>I had this problem when I installed fabric using disutils on OS X. So I removed it and reinstalled with pip. works fine.</p> <p>To remove: Delete the Fabric egg in site-packages directory.</p> <p>then install using pip</p> <pre><code>sudo pip install fabric </code></pre>
0
2010-05-26T12:12:17Z
[ "python", "django", "fabric" ]
fabric python install problem
2,244,749
<p>Just installed fabric, trying to use to same fabfile that works on a different server, getting this error here:</p> <pre><code>Traceback (most recent call last): File "/var/lib/python-support/python2.6/fabric.py", line 1211, in main load(fabfile, fail='warn') File "/var/lib/python-support/python2.6/fabric.p...
2
2010-02-11T13:40:29Z
14,308,904
<p>Your problem is that you named a file fabric.py somewhere in your python path. (probably in your current working directory) Rename it to something else and then it will not have any issues. I accidentally do this all the time and it is annoying.</p>
3
2013-01-13T22:25:25Z
[ "python", "django", "fabric" ]
Python - Check network map
2,244,767
<p>I'm looking for some help on logic, the code is not very Pythonic I'm still learning. We map the Z: drive to different locations all the time. Here is what I'm trying to accomplish</p> <p>1: Check for an old map on Z: say \192.168.1.100\old <br> 2: Map the new location to Z: say \192.168.1.200\new<br> 3: Make sure ...
4
2010-02-11T13:43:23Z
2,245,661
<p>I've put together a script based on the one you laid out which I believe accomplishes what you have described.</p> <p>I've tried to do it in a way that's both Pythonic and follows good programming principles.</p> <p>In particular, I've done the following:</p> <ul> <li>modularize much of the functionality into reu...
3
2010-02-11T15:53:55Z
[ "python" ]
How to extract unique values from nested dictionary with Python?
2,244,795
<p>I like to make a function that puts out a list of all values that are in a dictionary. The list must not contain any double items. The list also has to be in alphabetical order. I'm kind of new to Python, I can't come any further than printing all the values of the dictionary with the <code>iteritems()</code> functi...
2
2010-02-11T13:49:36Z
2,244,803
<p>the simplest way would be:</p> <pre><code>&gt;&gt;&gt; d = {1: 'sadf', 2: 'sadf', 3: 'asdf'} &gt;&gt;&gt; sorted(set(d.itervalues())) ['asdf', 'sadf'] </code></pre> <p>print it as you like.</p> <p>For your update question answer would be:</p> <pre><code>&gt;&gt;&gt; films = set() &gt;&gt;&gt; _ = [films.update(d...
4
2010-02-11T13:50:53Z
[ "python", "dictionary" ]
How to extract unique values from nested dictionary with Python?
2,244,795
<p>I like to make a function that puts out a list of all values that are in a dictionary. The list must not contain any double items. The list also has to be in alphabetical order. I'm kind of new to Python, I can't come any further than printing all the values of the dictionary with the <code>iteritems()</code> functi...
2
2010-02-11T13:49:36Z
2,244,919
<p>Another solution:</p> <pre><code>&gt;&gt;&gt; reduce(lambda x,y: set(x) | set(y),[ y.keys() for y in critics.values() ]) set(['Lady in the Water', 'Snakes on a Plane', 'You, Me and Dupree', 'Just My Luck', 'Superman Returns', 'The Night Listener']) </code></pre>
0
2010-02-11T14:10:40Z
[ "python", "dictionary" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,244,847
<p><a href="http://www.feedparser.org/" rel="nofollow">http://www.feedparser.org/</a></p> <p>First hit on G.</p>
2
2010-02-11T13:59:22Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,245,273
<p>In answer to your followup. You could use BeautifulSoup - but feedparser is much better geared towards RSS handing. </p> <p>Not to snark - but have you read feedparsers <a href="http://www.feedparser.org/docs/" rel="nofollow">documentation</a>? I don't know how it could be simpler to use. </p>
1
2010-02-11T15:00:50Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,245,280
<p>If you want an alternative, try xml.dom.minidom. Like "Django is Python", "RSS is XML".</p>
0
2010-02-11T15:01:32Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,245,384
<p><strong>Feedparser is very powerful, configurable and sooo easy to use. A very friendly learning curve, if at all.</strong></p> <p><strong>Example</strong></p> <p>Programatically determine how many answers your question has:</p> <pre><code>easy_install feedparser python -c 'import feedparser; print len(feedparser...
10
2010-02-11T15:16:48Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,245,392
<p>Using feedparser is a much better option than rolling your own with minidom or BeautifulSoup.</p> <ul> <li>It normalizes the differences between all versions of RSS and Atom so you don't have to have different code for each type.</li> <li>It's good about detecting different date formats and other variations in feed...
47
2010-02-11T15:18:02Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
2,245,462
<p>I Strongly recommend feedparser.</p>
0
2010-02-11T15:26:30Z
[ "python", "rss", "feedparser" ]
RSS feed parser library in Python
2,244,836
<p>I am looking for a good library in python that will help me parse RSS feeds. Has anyone used feedparser? Any feedback?</p>
32
2010-02-11T13:57:29Z
25,318,203
<p>I know this is a very old topic, but for what it worth, I was using feedparser (Universal feed parser) version 5.1.3 and I recently swiched to <a href="https://github.com/jmoiron/speedparser" rel="nofollow">speedparser</a> (0.1.8) for performance reasons. It has pretty much the same interfaces, but run faster.</p> ...
1
2014-08-14T21:56:54Z
[ "python", "rss", "feedparser" ]
How to count both sides of many-to-many relationship in Google App Engine
2,244,850
<p>Consider a GAE (python) app that lets users comment on songs. The expected number of users is 1,000,000+. The expected number of songs is 5,000.</p> <p>The app must be able to:</p> <ul> <li>Give the number of songs a user has commented on</li> <li>Give the number of users who have commented on a song</li> </ul> ...
3
2010-02-11T13:59:27Z
2,245,128
<p>You really shouldn't have to worry about handling the user's count of songs on which they have commented inside a transaction because it seems unlikely that a User would be able to comment on more than one song at a time, right?</p> <p>Now, it is definitely the case that many users could be commenting on the same s...
1
2010-02-11T14:39:59Z
[ "python", "google-app-engine", "data-modeling", "python-datamodel" ]
Spawning WSGI example (practical approach to WSGI)
2,244,897
<p>I'm trying to understand how WSGI works. I know I could read the specs, but I'd still want to know how do I create a <a href="http://pypi.python.org/pypi/Spawning" rel="nofollow">spawning</a> application? A complete "hello world".</p> <p>Could someone show me an example? With everything, file naming, creating the m...
3
2010-02-11T14:07:45Z
2,244,972
<p>From what I can see in the documentation, Spawning just runs stock WSGI apps, which means that you just write a <a href="http://ivory.idyll.org/articles/wsgi-intro/what-is-wsgi.html" rel="nofollow">WSGI script</a> and then invoke Spawning against it:</p> <pre><code>spawn helloworld.simple_app spawn helloworld.simpl...
3
2010-02-11T14:16:48Z
[ "python", "wsgi", "wsgiserver" ]
how to measure execution time of functions (automatically) in Python
2,245,161
<p>I need to have a <em>base class</em> which I will use to inherit other classes which I would like to measure execution time of its functions.</p> <p>So <strong>intead of</strong> having something like this:</p> <pre><code>class Worker(): def doSomething(self): start = time.time() ... do somethi...
21
2010-02-11T14:44:40Z
2,245,224
<p>Have you checked the <strong><a href="http://effbot.org/librarybook/profile.htm">"profile" module</a></strong>?</p> <p>I.e. are you sure you need to implement your own custom framework instead of using the default profiling mechanism for the language?</p> <p>You could also google for "python hotshot" for a similar...
8
2010-02-11T14:53:27Z
[ "python", "oop" ]
how to measure execution time of functions (automatically) in Python
2,245,161
<p>I need to have a <em>base class</em> which I will use to inherit other classes which I would like to measure execution time of its functions.</p> <p>So <strong>intead of</strong> having something like this:</p> <pre><code>class Worker(): def doSomething(self): start = time.time() ... do somethi...
21
2010-02-11T14:44:40Z
2,245,290
<p>One way to do this would be with a decorator <a href="http://www.python.org/dev/peps/pep-0318/">(PEP for decorators)</a> <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=240808">(first of a series of tutorial articles on decorators)</a>. Here's an example that does what you want.</p> <pre><code>from funct...
38
2010-02-11T15:02:49Z
[ "python", "oop" ]
how to measure execution time of functions (automatically) in Python
2,245,161
<p>I need to have a <em>base class</em> which I will use to inherit other classes which I would like to measure execution time of its functions.</p> <p>So <strong>intead of</strong> having something like this:</p> <pre><code>class Worker(): def doSomething(self): start = time.time() ... do somethi...
21
2010-02-11T14:44:40Z
2,245,317
<p>There is also <a href="http://docs.python.org/library/timeit.html" rel="nofollow">timeit</a>, which is part of the standard library, and is really easy to use. Remember: don't reinvent the wheel!</p>
4
2010-02-11T15:07:09Z
[ "python", "oop" ]
Uncatchable exception in Python
2,245,243
<p>The issue came up in this <a href="http://stackoverflow.com/questions/2243655">question</a>, which I'll recapitulate in this code:</p> <pre><code>import csv FH = open('data.csv','wb') line1 = [97,44,98,44,99,10] line2 = [100,44,101,44,102,10] for n in line1 + line2: FH.write(chr(n)) FH.write(chr(0)) FH.close() ...
1
2010-02-11T14:56:09Z
2,245,257
<p>You are not putting the "try" block at the right place to catch this exception. In other words, this exception is "catchable", just revisit the question you have referenced.</p> <p>The traceback clearly states that the problem is on the line with the "for" statement.</p>
7
2010-02-11T14:58:43Z
[ "python", "exception" ]
Uncatchable exception in Python
2,245,243
<p>The issue came up in this <a href="http://stackoverflow.com/questions/2243655">question</a>, which I'll recapitulate in this code:</p> <pre><code>import csv FH = open('data.csv','wb') line1 = [97,44,98,44,99,10] line2 = [100,44,101,44,102,10] for n in line1 + line2: FH.write(chr(n)) FH.write(chr(0)) FH.close() ...
1
2010-02-11T14:56:09Z
2,245,266
<p>The code that's throwing the exception isn't inside a try/except.</p> <pre><code>Traceback (most recent call last): File "test.py", line 14, in &lt;module&gt; for line in reader: </code></pre> <p>Just like the traceback shows, retrieving the next line from reader is what's causing the exception. You need to...
0
2010-02-11T14:59:54Z
[ "python", "exception" ]
Uncatchable exception in Python
2,245,243
<p>The issue came up in this <a href="http://stackoverflow.com/questions/2243655">question</a>, which I'll recapitulate in this code:</p> <pre><code>import csv FH = open('data.csv','wb') line1 = [97,44,98,44,99,10] line2 = [100,44,101,44,102,10] for n in line1 + line2: FH.write(chr(n)) FH.write(chr(0)) FH.close() ...
1
2010-02-11T14:56:09Z
2,245,272
<p>Try this :</p> <pre><code>FH = open('data.csv') try: reader = csv.reader(FH) for line in reader: if '\0' in line: continue if not line: continue print line except _csv.Error: print 'error' </code></pre>
0
2010-02-11T15:00:48Z
[ "python", "exception" ]
Uncatchable exception in Python
2,245,243
<p>The issue came up in this <a href="http://stackoverflow.com/questions/2243655">question</a>, which I'll recapitulate in this code:</p> <pre><code>import csv FH = open('data.csv','wb') line1 = [97,44,98,44,99,10] line2 = [100,44,101,44,102,10] for n in line1 + line2: FH.write(chr(n)) FH.write(chr(0)) FH.close() ...
1
2010-02-11T14:56:09Z
2,245,274
<p>It's not uncatchable, you're just trying to catch it in the wrong place. The error is occurring in the line:</p> <pre><code>for line in reader: </code></pre> <p>and you are putting your try block around:</p> <pre><code>print line </code></pre> <p>The exception has already been raised at this point.</p> <p>You ...
4
2010-02-11T15:00:55Z
[ "python", "exception" ]
How does one run Spawning with Django within a virtualenv?
2,245,430
<p>Because of the way Eventlet, which Spawning depends on, installs itself, it can't be installed into a virtualenv. The following error (wrapped for readability) illustrates:</p> <pre><code>Running eventlet-0.9.4/setup.py -q bdist_egg --dist-dir \ /tmp/easy_install-m_s75o/eventlet-0.9.4/egg-dist-tmp-fAZK_u error: S...
0
2010-02-11T15:22:53Z
2,247,113
<p>The following five commands worked without any problems. How are you installing spawning?</p> <pre><code>virtualenv test cd test/ . bin/activate easy_install spawning python -c 'import spawning' </code></pre>
3
2010-02-11T19:27:30Z
[ "python", "django", "wsgi", "virtualenv", "spawning" ]
Group form fields in django?
2,245,612
<p>Is there a way in Django to group some fields from a ModelForm? For example, if there's a model with fields like: age, gender, dob, q1, q2, q3 and a form is created based in such Model, can I group the fields like: info_fields = (age, gender, dob) and response_fields = (q1, q2, q3). This would be helpful to display ...
1
2010-02-11T15:47:43Z
2,246,299
<p>See this post, I believe your hinting at using fieldsets in a ModelForm. <a href="http://stackoverflow.com/questions/518966/django-and-fieldsets-on-modelform">http://stackoverflow.com/questions/518966/django-and-fieldsets-on-modelform</a></p>
1
2010-02-11T17:34:41Z
[ "python", "django", "django-templates", "django-forms" ]
Group form fields in django?
2,245,612
<p>Is there a way in Django to group some fields from a ModelForm? For example, if there's a model with fields like: age, gender, dob, q1, q2, q3 and a form is created based in such Model, can I group the fields like: info_fields = (age, gender, dob) and response_fields = (q1, q2, q3). This would be helpful to display ...
1
2010-02-11T15:47:43Z
21,591,414
<p>Don't know if people find this useful after 2 years but I use jQuery to divide fields amongst fieldsets</p> <pre><code>function splitFields(){ var set0 = $('fieldset').first(); var set1 = $('&lt;fieldset id="set1"&gt;&lt;/fieldset&gt;').insertAfter(set0); //the fields var fields = $('div.form-row',...
0
2014-02-06T00:09:37Z
[ "python", "django", "django-templates", "django-forms" ]
Python: Read configuration file with multiple lines per key
2,245,761
<p>I am writing a small DB test suite, which reads configuration files with queries and expected results, e.g.:</p> <pre><code>query = "SELECT * from cities WHERE name='Unknown';" count = 0 level = 1 name = "Check for cities whose name should be null" suggested_fix = "UPDATE cities SET...
8
2010-02-11T16:06:43Z
2,245,770
<p><a href="http://docs.python.org/library/configparser.html" rel="nofollow"><code>configparser</code></a></p>
5
2010-02-11T16:08:49Z
[ "python", "configuration-files", "text-parsing", "sql" ]
Python: Read configuration file with multiple lines per key
2,245,761
<p>I am writing a small DB test suite, which reads configuration files with queries and expected results, e.g.:</p> <pre><code>query = "SELECT * from cities WHERE name='Unknown';" count = 0 level = 1 name = "Check for cities whose name should be null" suggested_fix = "UPDATE cities SET...
8
2010-02-11T16:06:43Z
2,246,344
<p>The Python standard library module <strong><a href="http://docs.python.org/library/configparser.html">ConfigParser</a></strong> supports this by default. The configuration file has to be in a standard format:</p> <pre><code>[Long Section] short: this is a normal line long: this value continues in the next line </co...
9
2010-02-11T17:41:21Z
[ "python", "configuration-files", "text-parsing", "sql" ]
Python: Read configuration file with multiple lines per key
2,245,761
<p>I am writing a small DB test suite, which reads configuration files with queries and expected results, e.g.:</p> <pre><code>query = "SELECT * from cities WHERE name='Unknown';" count = 0 level = 1 name = "Check for cities whose name should be null" suggested_fix = "UPDATE cities SET...
8
2010-02-11T16:06:43Z
2,247,038
<p>I would you suggest to use a regular expression... The code might look like this to give you are start:</p> <pre><code>import re test="""query = "select * from cities;" count = 0 multine_query = "select * from cities where name='unknown';" """ re_config = re.compile(r'^(\w+)\s*=\s*((?:".[^"]*")|(?:\d+))$', r...
1
2010-02-11T19:16:24Z
[ "python", "configuration-files", "text-parsing", "sql" ]
Python: Read configuration file with multiple lines per key
2,245,761
<p>I am writing a small DB test suite, which reads configuration files with queries and expected results, e.g.:</p> <pre><code>query = "SELECT * from cities WHERE name='Unknown';" count = 0 level = 1 name = "Check for cities whose name should be null" suggested_fix = "UPDATE cities SET...
8
2010-02-11T16:06:43Z
2,251,072
<p>This is almost exactly the use-case that made us switch to <a href="http://www.yaml.org/">YAML</a> (<a href="http://en.wikipedia.org/wiki/YAML">Wikipedia</a>, <a href="http://pyyaml.org/">python implementation</a>, <a href="http://pyyaml.org/wiki/PyYAMLDocumentation">documentation</a>; you might want to look at <a h...
7
2010-02-12T10:25:21Z
[ "python", "configuration-files", "text-parsing", "sql" ]
is there a simple to get group names of a user in django
2,245,895
<p>I tried following Code with the help of the <strong>django.contrib.auth.User</strong> and <strong>django.contrib.auth.Group</strong></p> <pre><code>for g in request.user.groups: l.append(g.name) </code></pre> <p>But that failed and I received following <strong>Error</strong>:</p> <pre><code>TypeError at / 'Ma...
17
2010-02-11T16:29:31Z
2,245,908
<pre><code>for g in request.user.groups.all(): l.append(g.name) </code></pre> <p>or with recent django</p> <pre><code>l = request.user.groups.values_list('name',flat=True) </code></pre>
37
2010-02-11T16:31:39Z
[ "python", "django", "django-admin" ]
is there a simple to get group names of a user in django
2,245,895
<p>I tried following Code with the help of the <strong>django.contrib.auth.User</strong> and <strong>django.contrib.auth.Group</strong></p> <pre><code>for g in request.user.groups: l.append(g.name) </code></pre> <p>But that failed and I received following <strong>Error</strong>:</p> <pre><code>TypeError at / 'Ma...
17
2010-02-11T16:29:31Z
17,086,967
<pre><code>user.groups.all()[0].name == "groupname" </code></pre>
3
2013-06-13T12:21:30Z
[ "python", "django", "django-admin" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,245,915
<pre><code>set([letter.lower() for letter in words if letter != ' ']) </code></pre> <p><strong>Edit</strong>: I just tried it and found this will also work (maybe this is what SilentGhost was referring to):</p> <pre><code>set(letter.lower() for letter in words if letter != ' ') </code></pre> <p>And if you need to ha...
3
2010-02-11T16:31:51Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,245,917
<p>Make <code>ltr</code> a set and change your loop body a little:</p> <pre><code>ltr = set() for word in word_list: for c in word: ltr.add(c) </code></pre> <p>Or using a list comprehension:</p> <pre><code>ltr = set([c for word in word_list for c in word]) </code></pre>
3
2010-02-11T16:32:04Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,245,939
<pre><code>set(l for w in word_list for l in w) </code></pre>
0
2010-02-11T16:35:07Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,245,994
<pre> >>> set('She sells seashells by the seashore'.replace(' ', '').lower()) set(['a', 'b', 'e', 'h', 'l', 'o', 's', 'r', 't', 'y']) >>> set(c.lower() for c in 'She sells seashells by the seashore' if not c.isspace()) set(['a', 'b', 'e', 'h', 'l', 'o', 's', 'r', 't', 'y']) >>> from itertools import chain >>> set(chain...
2
2010-02-11T16:43:37Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,246,003
<p>here are some timings made with py3k:</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; def t(): # mine (see history) a = {i.lower() for i in words} a.discard(' ') return a &gt;&gt;&gt; timeit.timeit(t) 7.993071812372081 &gt;&gt;&gt; def b(): # danben retu...
2
2010-02-11T16:44:23Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,246,067
<p>Sets provide a simple, efficient solution.</p> <pre><code>words = 'She sells seashells by the seashore' unique_letters = set(words.lower()) unique_letters.discard(' ') # If there was a space, remove it. </code></pre>
13
2010-02-11T16:53:04Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
How to go from list of words to a list of distinct letters in Python
2,245,903
<p>Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.</p> <p>Here's my current code:</p> <pre><code>words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lowe...
3
2010-02-11T16:30:14Z
2,246,115
<pre><code>words = 'She sells seashells by the seashore' ltr = list(set(list(words.lower()))) ltr.remove(' ') print ltr </code></pre>
0
2010-02-11T17:01:01Z
[ "python", "filter", "distinct", "list-comprehension", "letters" ]
Python Fabric: How to answer to keyboard input?
2,246,256
<p>I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.</p> <p>For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet'...
21
2010-02-11T17:26:14Z
2,246,395
<p>Why can't you just use <a href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">pipes</a>?</p> <p>For example, for an automated auto accept, just use <a href="http://en.wikipedia.org/wiki/Yes_%28Unix%29"><code>yes</code></a>, that just outputs a neverending stream of <code>y</code>.</p> <pre><code>yes | rm *.txt...
12
2010-02-11T17:47:37Z
[ "python", "automation", "fabric" ]
Python Fabric: How to answer to keyboard input?
2,246,256
<p>I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.</p> <p>For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet'...
21
2010-02-11T17:26:14Z
2,246,416
<p>If you are looking for a user to confirm an operation, use the confrim method.</p> <pre><code>if fabric.contrib.console.confirm("You tests failed do you want to continue?"): #continue processing </code></pre> <p>Or if you are looking for a way to get input from the user, use the prompt method.</p> <pre><code>pa...
31
2010-02-11T17:50:29Z
[ "python", "automation", "fabric" ]
Python Fabric: How to answer to keyboard input?
2,246,256
<p>I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.</p> <p>For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet'...
21
2010-02-11T17:26:14Z
2,246,509
<p>Those both methods are valid and works.</p> <p>I choose the first one, because I didn't want to have any interaction with my deployment system.</p> <p>So here is the solution I used:</p> <p><code> % yes | ./manage.py rebuild_index </p> <p>WARNING: This will irreparably remove EVERYTHING from your search index. Y...
0
2010-02-11T18:03:55Z
[ "python", "automation", "fabric" ]
Python Fabric: How to answer to keyboard input?
2,246,256
<p>I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.</p> <p>For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet'...
21
2010-02-11T17:26:14Z
5,002,203
<p>The development version of Fabric (1.0a) now supports interaction with remote programs. <a href="http://docs.fabfile.org/1.0a/usage/interactivity.html" rel="nofollow">http://docs.fabfile.org/1.0a/usage/interactivity.html</a></p>
1
2011-02-15T10:05:00Z
[ "python", "automation", "fabric" ]