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
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
6,784,575
<p>check for scipy.stats module: </p> <pre><code> scipy.stats.scoreatpercentile </code></pre>
6
2011-07-22T00:53:10Z
[ "python", "numpy", "percentile" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
7,464,107
<p>The definition of percentile I usually see expects as a result the value from the supplied list below which P percent of values are found. To get that, you can use a simpler function.</p> <pre><code>def percentile(N, P): """ Find the percentile of a list of values @parameter N - A list of values. N m...
6
2011-09-18T20:05:11Z
[ "python", "numpy", "percentile" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
13,413,196
<p><a href="http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.percentile.html" rel="nofollow">numpy.percentile</a></p> <p>Is there something I am missing?</p>
4
2012-11-16T08:50:02Z
[ "python", "numpy", "percentile" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
15,589,202
<p>Here's how to do it without numpy, using only python to calculate the percentile.</p> <pre><code>import math def percentile(data, percentile): size = len(data) return sorted(data)[int(math.ceil((size * percentile) / 100)) - 1] p5 = percentile(mylist, 5) p25 = percentile(mylist, 25) p50 = percentile(mylist...
2
2013-03-23T16:35:03Z
[ "python", "numpy", "percentile" ]
How do I calculate percentiles with python/numpy?
2,374,640
<p>Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array?</p> <p>I am looking for something similar to Excel's percentile function.</p> <p>I looked in NumPy's statistics reference, and couldn't find this. All I could find is the median (50th percentile), but not something...
100
2010-03-03T20:21:13Z
17,060,201
<pre><code>import numpy as np a = [154, 400, 1124, 82, 94, 108] print np.percentile(a,95) # gives the 95th percentile </code></pre>
21
2013-06-12T07:45:24Z
[ "python", "numpy", "percentile" ]
How does the following code in python work? How to work with struct_time objects
2,375,101
<p>Hi if I do the following I can convert from a time_struct object to a datetime object:</p> <p>mydate = datetime.datetime(*time.localtime()[:6])</p> <p>How does this code work? What do the * and the [:6] mean?</p>
0
2010-03-03T21:26:51Z
2,375,114
<p><code>*time.localtime()</code> means, that the <code>tuple</code> returned from localtime is unpacked (turned into arguments passed to datetime). <code>[:6]</code> means that only a slice of the <code>tuple</code> is used, this operator returns new <code>tuple</code> of first six elements.</p> <p>This code takes <c...
3
2010-03-03T21:28:53Z
[ "python" ]
How does the following code in python work? How to work with struct_time objects
2,375,101
<p>Hi if I do the following I can convert from a time_struct object to a datetime object:</p> <p>mydate = datetime.datetime(*time.localtime()[:6])</p> <p>How does this code work? What do the * and the [:6] mean?</p>
0
2010-03-03T21:26:51Z
2,375,127
<p><code>*</code> is <a href="http://docs.python.org/3.1/tutorial/controlflow.html#unpacking-argument-lists" rel="nofollow">argument unpacking</a>, <code>[:6]</code> is <a href="http://docs.python.org/3.1/library/stdtypes.html#sequence-types-str-bytes-bytearray-list-tuple-range" rel="nofollow">slicing</a>. That is what...
4
2010-03-03T21:30:48Z
[ "python" ]
Generate image for each font on a linux system using Python
2,375,125
<p>I'm looking for a way to list all fonts installed on a linux/Debian system, and then generate images of some strings using these fonts. I'm looking for your advice as I kind of see how to do each part, but not to do both:</p> <ol> <li><p>To list all fonts on a UNIX system, <code>xlsfonts</code> can do the trick:</p...
4
2010-03-03T21:30:43Z
2,375,457
<p>You can do this using pango, through the pygtk package. Pango can list fonts and render them.</p>
1
2010-03-03T22:21:10Z
[ "python", "linux", "fonts", "debian", "python-imaging-library" ]
Generate image for each font on a linux system using Python
2,375,125
<p>I'm looking for a way to list all fonts installed on a linux/Debian system, and then generate images of some strings using these fonts. I'm looking for your advice as I kind of see how to do each part, but not to do both:</p> <ol> <li><p>To list all fonts on a UNIX system, <code>xlsfonts</code> can do the trick:</p...
4
2010-03-03T21:30:43Z
2,375,489
<p>you best bet is to do a <code>find</code> on all the fonts on the system, and then use <code>ImagesFont.load()</code> on the results of that list. I don't know where the fonts are on Debian, but they should be in a well known folder you can just do an <code>os.walk</code> and then feed the filenames in that way.</p>...
1
2010-03-03T22:27:02Z
[ "python", "linux", "fonts", "debian", "python-imaging-library" ]
How to do a dregradê on wx.Panel Background?
2,375,158
<p>I want to color the background (SetBackgroundColour) of a wx.Panel with a blue to black degradê.</p> <p>How can I make it?</p>
1
2010-03-03T21:34:34Z
2,375,535
<p>Adapted from <a href="http://www.daniweb.com/forums/thread128350-6.html#">DaniWeb</a>:</p> <pre><code>import wx class MyFrame(wx.Frame): def __init__(self, parent=None, title=None): wx.Frame.__init__(self, parent, wx.ID_ANY, title) self.panel = wx.Panel(self, size=(350, 450)) # this set...
5
2010-03-03T22:34:53Z
[ "python", "colors", "wxpython", "panel" ]
File Uploads with Turbogears 2
2,375,290
<p>I've been trying to work out the 'best practices' way to manage file uploads with Turbogears 2 and have thus far not really found any examples. I've figured out a way to actually upload the file, but I'm not sure how reliable it us.</p> <p>Also, what would be a good way to get the uploaded files name?</p> <pre><co...
5
2010-03-03T21:54:35Z
2,376,443
<p>I don't know much about Turbogears and whether it can provide anything to avoid the following, but it seems to me that this code is fraught with danger. It may be possible for a malicious user to overwrite (or create) any file that the Turbogears python process has write access to.</p> <p>What if <code>asset_dirnam...
1
2010-03-04T02:04:53Z
[ "python", "turbogears2" ]
File Uploads with Turbogears 2
2,375,290
<p>I've been trying to work out the 'best practices' way to manage file uploads with Turbogears 2 and have thus far not really found any examples. I've figured out a way to actually upload the file, but I'm not sure how reliable it us.</p> <p>Also, what would be a good way to get the uploaded files name?</p> <pre><co...
5
2010-03-03T21:54:35Z
2,377,971
<p>Isn't turbogears just pylons with extras? You could check out the help there:</p> <p><a href="http://wiki.pylonshq.com/display/pylonsdocs/Form+Handling#file-uploads" rel="nofollow">http://wiki.pylonshq.com/display/pylonsdocs/Form+Handling#file-uploads</a></p> <p>However, that still contains the potential security...
0
2010-03-04T09:06:35Z
[ "python", "turbogears2" ]
File Uploads with Turbogears 2
2,375,290
<p>I've been trying to work out the 'best practices' way to manage file uploads with Turbogears 2 and have thus far not really found any examples. I've figured out a way to actually upload the file, but I'm not sure how reliable it us.</p> <p>Also, what would be a good way to get the uploaded files name?</p> <pre><co...
5
2010-03-03T21:54:35Z
2,385,331
<p>@mhawke - you're right you have to handle that - depends on what you are doing with the file, if it doesn't matter if there is a name collision eg you only care for the latest version of some data then theres probably no issue, or if the filename isn't actually important just the file contents, but its still bad pra...
1
2010-03-05T08:07:43Z
[ "python", "turbogears2" ]
File Uploads with Turbogears 2
2,375,290
<p>I've been trying to work out the 'best practices' way to manage file uploads with Turbogears 2 and have thus far not really found any examples. I've figured out a way to actually upload the file, but I'm not sure how reliable it us.</p> <p>Also, what would be a good way to get the uploaded files name?</p> <pre><co...
5
2010-03-03T21:54:35Z
2,400,484
<p>Werkzeug has a very good helper function for securing file names called <a href="http://dev.pocoo.org/projects/werkzeug/browser/werkzeug/utils.py#L249" rel="nofollow">secure_filename</a>. I think you can adopt and use it.</p>
0
2010-03-08T10:05:47Z
[ "python", "turbogears2" ]
File Uploads with Turbogears 2
2,375,290
<p>I've been trying to work out the 'best practices' way to manage file uploads with Turbogears 2 and have thus far not really found any examples. I've figured out a way to actually upload the file, but I'm not sure how reliable it us.</p> <p>Also, what would be a good way to get the uploaded files name?</p> <pre><co...
5
2010-03-03T21:54:35Z
29,744,262
<p>I just want anyone who comes here looking for answers, to know that <a href="https://twitter.com/__amol__" rel="nofollow">Allesandro Molina</a>'s great library <a href="http://depot.readthedocs.org/en/latest/" rel="nofollow">Depot</a> constitutes the best answer to this question.</p> <p>It solves both the naming an...
2
2015-04-20T09:39:58Z
[ "python", "turbogears2" ]
Create a python function procedurally (specifically the arguments)
2,375,316
<h2>Question</h2> <p>How do you procedurally create a function in Python which takes specific named arguments but allow those argument names to be data-driven?</p> <h2>Example</h2> <p>Say, you want to create a class decorator, <code>with_init</code>, which adds an <code>__init__</code> method with specific named arg...
1
2010-03-03T21:58:09Z
2,375,414
<p>Very roughly. This accepts kw args and checks to see that the number of args is correct</p> <pre><code>def __call__(self, cls): def init(cls_self, *args, **kw): if len(args)+len(kw) != len(self.params): raise RuntimeError("Wrong number of arguments") for param, value in zip(self.para...
3
2010-03-03T22:13:42Z
[ "python" ]
Create a python function procedurally (specifically the arguments)
2,375,316
<h2>Question</h2> <p>How do you procedurally create a function in Python which takes specific named arguments but allow those argument names to be data-driven?</p> <h2>Example</h2> <p>Say, you want to create a class decorator, <code>with_init</code>, which adds an <code>__init__</code> method with specific named arg...
1
2010-03-03T21:58:09Z
2,375,567
<p>Here's my namedtuple inspired answer. It's currently open to template injection attacks but you don't have to handle <em>any</em> of the parameter errors yourself.</p> <pre><code>def __call__(self, cls): paramtxt = ', '.join(['self'] + self.params) bodytxt = '\n\t'.join('self.%(param)s = %(param)s' % local...
0
2010-03-03T22:40:07Z
[ "python" ]
Python Type Conversion
2,375,334
<p>Whats the best way to convert int's, long's, double's to strings and vice versa in python.</p> <p>I am looping through a list and passing longs to a dict that should be turned into a unicode string.</p> <p>I do </p> <pre><code>for n in l: {'my_key':n[0],'my_other_key':n[1]} </code></pre> <p>Why are some ...
10
2010-03-03T22:00:59Z
2,375,344
<p>To convert from a numeric type to a string:</p> <pre><code>str(100) </code></pre> <p>To convert from a string to an int:</p> <pre><code>int("100") </code></pre> <p>To convert from a string to a float:</p> <pre><code>float("100") </code></pre>
37
2010-03-03T22:02:57Z
[ "python", "types", "int" ]
Python Type Conversion
2,375,334
<p>Whats the best way to convert int's, long's, double's to strings and vice versa in python.</p> <p>I am looping through a list and passing longs to a dict that should be turned into a unicode string.</p> <p>I do </p> <pre><code>for n in l: {'my_key':n[0],'my_other_key':n[1]} </code></pre> <p>Why are some ...
10
2010-03-03T22:00:59Z
2,375,382
<p>You could do it like this in Python 2.x:</p> <pre><code>&gt;&gt;&gt; l = ((1,2),(3,4)) &gt;&gt;&gt; dict(map(lambda n: (n[0], unicode(n[1])), l)) {1: u'2', 3: u'4'} </code></pre> <p>or in Python 3.x:</p> <pre><code>&gt;&gt;&gt; l = ((1,2),(3,4)) &gt;&gt;&gt; {n[0] : str(n[1]) for n in l} {1: '2', 3: '4'} </code><...
2
2010-03-03T22:09:16Z
[ "python", "types", "int" ]
Python Type Conversion
2,375,334
<p>Whats the best way to convert int's, long's, double's to strings and vice versa in python.</p> <p>I am looping through a list and passing longs to a dict that should be turned into a unicode string.</p> <p>I do </p> <pre><code>for n in l: {'my_key':n[0],'my_other_key':n[1]} </code></pre> <p>Why are some ...
10
2010-03-03T22:00:59Z
2,375,527
<p>You can do it this way</p> <pre><code>for n in l: {'my_key':unicode(n[0]),'my_other_key':unicode(n[1])} </code></pre> <p>Perhaps this is clearer if there are only 2 or 3 keys/values</p> <pre><code>for my_value, my_other_value in l: {'my_key':unicode(my_value),'my_other_key':unicode(my_other_value)} </code...
0
2010-03-03T22:33:16Z
[ "python", "types", "int" ]
In Django, how do I clear a sessionkey?
2,375,335
<p>I set a session like this:</p> <pre><code>request.session['mykey']= 33 </code></pre> <p>How do I clear it? I just want to DELETE it.</p>
16
2010-03-03T22:01:24Z
2,375,362
<pre><code> del request.session['mykey'] </code></pre>
35
2010-03-03T22:06:23Z
[ "python", "django", "session" ]
Help on my django models for my shoe review website
2,375,365
<p>What i'm trying to achieve at this point:</p> <ul> <li>Allow me to add new shoe objects, and shoe review objects. <em>complete</em></li> <li>Allow "Owner Reviews" on each shoe <em>complete</em> (I think, but there might be somewhere in my model I can improve)</li> <li>Allow ratings of attributes defined by me which...
2
2010-03-03T22:06:29Z
2,375,538
<p>Instead of that:</p> <pre><code>ShoeReview.objects.filter(owner_review__ratings__rating_attribute = 'overall').sort_by(owner_review__ratings__rating) </code></pre> <p>you should call:</p> <pre><code>ShoeReview.objects.filter(owner_review__ratings__rating_attribute__attribute = 'overall').order_by(owner_review__ra...
1
2010-03-03T22:35:21Z
[ "python", "django", "database-design", "django-models" ]
Help on my django models for my shoe review website
2,375,365
<p>What i'm trying to achieve at this point:</p> <ul> <li>Allow me to add new shoe objects, and shoe review objects. <em>complete</em></li> <li>Allow "Owner Reviews" on each shoe <em>complete</em> (I think, but there might be somewhere in my model I can improve)</li> <li>Allow ratings of attributes defined by me which...
2
2010-03-03T22:06:29Z
8,602,004
<p>You should do:</p> <pre><code>ShoeReview.objects\ .filter(owner_review__ratings__rating_attribute__attribute='overall')\ .order_by(owner_review__ratings__rating) </code></pre> <p>But actually, you are better off using a manager:</p> <pre><code>class BestShoesReviewManager(models.Manager): ...
1
2011-12-22T09:42:54Z
[ "python", "django", "database-design", "django-models" ]
How does one monkey patch a function in python?
2,375,403
<p>I'm having trouble replacing a function from a different module with another function and it's driving me crazy.</p> <p>Let's say I have a module bar.py that looks like this:</p> <pre><code>from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() </code></pre> <p>And ...
50
2010-03-03T22:11:38Z
2,375,443
<p>It may help to think of how Python namespaces work: they're essentially dictionaries. So when you do this:</p> <pre><code>from a_package.baz import do_something_expensive do_something_expensive = lambda: 'Something really cheap.' </code></pre> <p>think of it like this:</p> <pre><code>do_something_expensive = a_p...
54
2010-03-03T22:19:45Z
[ "python", "monkeypatching" ]
How does one monkey patch a function in python?
2,375,403
<p>I'm having trouble replacing a function from a different module with another function and it's driving me crazy.</p> <p>Let's say I have a module bar.py that looks like this:</p> <pre><code>from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() </code></pre> <p>And ...
50
2010-03-03T22:11:38Z
2,375,450
<p>There's a really elegant decorator for this: <a href="http://mail.python.org/pipermail/python-dev/2008-January/076194.html">Guido van Rossum: Python-Dev list: Monkeypatching Idioms</a>.</p> <p>There's also the <a href="http://pypi.python.org/pypi/dectools/0.1.3">dectools</a> package, which I saw an PyCon 2010, whic...
16
2010-03-03T22:20:30Z
[ "python", "monkeypatching" ]
How does one monkey patch a function in python?
2,375,403
<p>I'm having trouble replacing a function from a different module with another function and it's driving me crazy.</p> <p>Let's say I have a module bar.py that looks like this:</p> <pre><code>from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() </code></pre> <p>And ...
50
2010-03-03T22:11:38Z
2,375,491
<p>In the first snippet, you make <code>bar.do_something_expensive</code> refer to the function object that <code>a_package.baz.do_something_expensive</code> refers to at that moment. To really "monkeypatch" that you would need to change the function itself (you are only changing what names refer to); this is possible,...
4
2010-03-03T22:27:17Z
[ "python", "monkeypatching" ]
How does one monkey patch a function in python?
2,375,403
<p>I'm having trouble replacing a function from a different module with another function and it's driving me crazy.</p> <p>Let's say I have a module bar.py that looks like this:</p> <pre><code>from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() </code></pre> <p>And ...
50
2010-03-03T22:11:38Z
2,379,020
<p><code>do_something_expensive</code> in the <code>a_function()</code> function is just a variable within the namespace of the module pointing to a function object. When you redefine the module you are doing it in a different namespace.</p>
0
2010-03-04T11:56:26Z
[ "python", "monkeypatching" ]
How does one monkey patch a function in python?
2,375,403
<p>I'm having trouble replacing a function from a different module with another function and it's driving me crazy.</p> <p>Let's say I have a module bar.py that looks like this:</p> <pre><code>from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() </code></pre> <p>And ...
50
2010-03-03T22:11:38Z
26,016,216
<p>If you want to only patch it for your call and otherwise leave the original code you can use <a href="https://docs.python.org/3/library/unittest.mock.html#patch" rel="nofollow">https://docs.python.org/3/library/unittest.mock.html#patch</a> (since Python 3.3):</p> <pre><code>with patch('a_package.baz.do_something_ex...
1
2014-09-24T11:51:49Z
[ "python", "monkeypatching" ]
Emacs collaborative buffers open in the wrong mode
2,375,473
<p>I am using Emacs and <a href="http://www.emacswiki.org/emacs/Rudel" rel="nofollow">Rudel</a> to collaborate with a remote programmer. Rudel has a concept of published buffers. When my partner publishes a buffer, I can subscribe to it and the we can both edit it simultaneously.</p> <p>My problem is that when he pu...
4
2010-03-03T22:24:27Z
2,376,009
<p>I don't know Rudel well enough to give a 100% solution, but what you want to do is something like this:</p> <pre><code>(add-hook 'rudel-document-attach-hook 'my-rudel-set-mode-appropriately) (defun my-rudel-set-mode-appropriately (document buffer) "try to set the mode appropriately" (set-buffer buffer) (let (...
3
2010-03-04T00:05:40Z
[ "python", "emacs", "collaboration", "pair-programming" ]
Emacs collaborative buffers open in the wrong mode
2,375,473
<p>I am using Emacs and <a href="http://www.emacswiki.org/emacs/Rudel" rel="nofollow">Rudel</a> to collaborate with a remote programmer. Rudel has a concept of published buffers. When my partner publishes a buffer, I can subscribe to it and the we can both edit it simultaneously.</p> <p>My problem is that when he pu...
4
2010-03-03T22:24:27Z
2,376,238
<p>I know absolutely nothing about how rudel works. However, have you tried explicitly setting the mode in the text file? Try adding something like this to the first line of the file:</p> <pre><code># -*- mode: python; fill-column: 75; comment-column: 50; -*- </code></pre> <p>Putting a line like this first in the fil...
0
2010-03-04T01:09:51Z
[ "python", "emacs", "collaboration", "pair-programming" ]
Python check for blank CSV value not working
2,375,604
<p>I have a CSV file and I am running a script against it to insert into a database. If the value is blank then I don't want to insert it. Here is what I have</p> <pre><code>if attrs[attr] != '' and attrs[attr] != None: log.info('Attriute ID: %s' % attr) log.info('Attriute Value: %s' % attrs[a...
1
2010-03-03T22:47:40Z
2,375,624
<p>It's probably whitespace i.e. a tab or string with spaces try:-</p> <pre><code>attrs[attr].strip() </code></pre>
4
2010-03-03T22:52:30Z
[ "python", "csv", null ]
Python check for blank CSV value not working
2,375,604
<p>I have a CSV file and I am running a script against it to insert into a database. If the value is blank then I don't want to insert it. Here is what I have</p> <pre><code>if attrs[attr] != '' and attrs[attr] != None: log.info('Attriute ID: %s' % attr) log.info('Attriute Value: %s' % attrs[a...
1
2010-03-03T22:47:40Z
2,375,627
<p>Presumably it contains whitespace. You could check this by printing <code>repr(attrs[attr])</code> which will put quotes round it and show tabs at "\t"</p> <p>Change the code to <code>if attrs[attr] is not None and attrs[attr].strip() !="":</code></p>
3
2010-03-03T22:53:30Z
[ "python", "csv", null ]
Python check for blank CSV value not working
2,375,604
<p>I have a CSV file and I am running a script against it to insert into a database. If the value is blank then I don't want to insert it. Here is what I have</p> <pre><code>if attrs[attr] != '' and attrs[attr] != None: log.info('Attriute ID: %s' % attr) log.info('Attriute Value: %s' % attrs[a...
1
2010-03-03T22:47:40Z
2,377,989
<p>You should (almost) always normalise whitespace in any text string that is intended for insertion in a database (or for many other purposes).</p> <p>To normalise whitespace is to (1) strip any leading whitespace (2) strip any trailing whitespace (3) replace any internal runs (length >= 1) of whitespace by exactly 1...
1
2010-03-04T09:10:02Z
[ "python", "csv", null ]
Is it possible to dock wx.auiManager panes onto tops/bottoms of another panes?
2,375,613
<p>with this code:</p> <pre><code>import wx import wx.aui class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='wx.aui Test', pos=wx.DefaultPosition, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) ...
0
2010-03-03T22:49:28Z
2,375,905
<p>Maybe the <a href="http://wiki.wxpython.org/AuiNotebook" rel="nofollow">AuiNotebook</a> wxPython sample works for you?</p> <pre><code>import wx import wx.aui ######################################################################## class TabPanel(wx.Panel): """ This will be the first notebook tab """ ...
1
2010-03-03T23:41:38Z
[ "python", "wxpython", "dock" ]
Getting a Jabber status via Python
2,375,705
<p>I'm developing a website using the Django framework, and I need to retrieve Jabber (okay, Google Talk) statuses for a user. Most of the Jabber python libraries seem like an incredible amount of overkill (and overhead) for a simple task. Is there any simple way to do this? </p> <p>I know very little about XMPP/Jabbe...
1
2010-03-03T23:06:27Z
2,376,412
<p>I recommend checking out Google AppEngine's <a href="http://code.google.com/appengine/docs/python/xmpp/" rel="nofollow">XMPP API</a> (Django runs on AppEngine, too). AFAIK you have to be authorized to check a user's status.</p>
0
2010-03-04T01:53:17Z
[ "python", "django", "xmpp", "google-talk" ]
Getting a Jabber status via Python
2,375,705
<p>I'm developing a website using the Django framework, and I need to retrieve Jabber (okay, Google Talk) statuses for a user. Most of the Jabber python libraries seem like an incredible amount of overkill (and overhead) for a simple task. Is there any simple way to do this? </p> <p>I know very little about XMPP/Jabbe...
1
2010-03-03T23:06:27Z
2,449,028
<blockquote> <p>Do you need to be an authenticated and "friended" user to retrieve another user's status?</p> </blockquote> <p>Yes.</p> <p>To get the status of a given user, you should write a jabber bot and the user should add your bot as a friend. Then you would be able to get the status of that user. <a href...
0
2010-03-15T17:14:50Z
[ "python", "django", "xmpp", "google-talk" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,853
<p>You could do something like this:</p> <pre><code>if (!IsReadOnly) { T newobj = null; try { newobj = DataPortal.Update&lt;T&gt;(this); } catch (DataPortalException) { // TODO: Implement DataPortal.Update&lt;T&gt;() recovery mechanism } if (newobj != null) { ...
0
2010-03-03T23:30:56Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,857
<p>that would be the empty statement like hits</p> <pre><code>try { somethingThatCanThrow(); } catch(Exception ex) { LogException(ex); return; } ContinueFlow(); </code></pre>
0
2010-03-03T23:31:23Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,860
<p>I would prefer to see the rest of the code outside the try/catch so it is clear where the exception you are trying to catch is coming from and that you don't accidentally catch an exception that you weren't trying to catch.</p> <p>I think the closest equivalent to the Python try/catch/else is to use a local boolean...
7
2010-03-03T23:31:40Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,862
<p>C# does not have such a concept, so you are just left with three options, </p> <ul> <li>put the else code inside the try.</li> <li>put the else code outside the try catch block, use a local variable to indicate success or failure, and an if block around your else code.</li> <li>put the else code in the finally bloc...
2
2010-03-03T23:31:49Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,870
<p>Just put your "else" block <em>before</em> the catch. Then, it will only execute if code execution reaches that point:</p> <pre><code>try { fee(); fi(); foe(); fum(); /// put your "else" stuff here. /// It will only be executed if fee-fi-foe-fum did not fail. } catch(Exception e) { // ...
2
2010-03-03T23:33:06Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,375,941
<p>Allow me to repeat an idea from a <a href="http://stackoverflow.com/questions/2359206/access-the-value-returned-by-a-function-in-a-finally-block/2359452#2359452">similar StackOverflow question</a>. You cannot do this directly, but you can write a method that encapsulates the behavior you need. Look at the original q...
2
2010-03-03T23:49:04Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,376,090
<p>Barbaric solution: create an Else class derived from Exception, throw an instance of it at the end of the try block, and use <code>catch (Else) {...}</code> to handle the other stuff.</p> <p>I feel so dirty.</p>
6
2010-03-04T00:30:57Z
[ "c#", "python", "exception", "try-catch" ]
C#: Equivalent of the python try/catch/else block
2,375,794
<p>In Python, there is this useful exception handling code:</p> <pre><code>try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail </code></pre> <p>I think it's useful to be able to separate the code that <em>could</em> raise a...
6
2010-03-03T23:20:46Z
2,376,104
<p>This will might get downvoted but doesn't c# have goto(note I have almost no c# knowledge so I have no idea if this works).</p> <p>what about something like</p> <pre><code>try { ... } catch(Exception ex) { ... goto Jump_past_tryelse } ...//Code to execute if the try block DID NOT fail Jump_past_tryelse: ......
5
2010-03-04T00:34:58Z
[ "c#", "python", "exception", "try-catch" ]
Getting rid of Django IOErrors
2,375,950
<p>I'm running a Django site (via Apache/mod_python) and I use Django's facilities to inform me and other developers about internal server errors. Sometimes errors like those appear:</p> <pre><code>Traceback (most recent call last): File "/opt/webapp/externals/lib/django/core/handlers/base.py", line 92, in get_resp...
6
2010-03-03T23:51:00Z
2,377,051
<p>You should be able to write a Middleware to catch the exception and you can then "silence" those specific exceptions. </p> <p><a href="http://docs.djangoproject.com/en/1.1/topics/http/middleware/#process-exception" rel="nofollow">http://docs.djangoproject.com/en/1.1/topics/http/middleware/#process-exception</a></p>...
2
2010-03-04T05:21:04Z
[ "python", "django", "logging" ]
Getting rid of Django IOErrors
2,375,950
<p>I'm running a Django site (via Apache/mod_python) and I use Django's facilities to inform me and other developers about internal server errors. Sometimes errors like those appear:</p> <pre><code>Traceback (most recent call last): File "/opt/webapp/externals/lib/django/core/handlers/base.py", line 92, in get_resp...
6
2010-03-03T23:51:00Z
9,242,038
<p>In django 1.3 and up, you can use a <a href="https://docs.djangoproject.com/en/dev/topics/logging/#topic-logging-parts-filters" rel="nofollow">logging filter</a> class to suppress the exceptions which you aren't interested in. Here's the logging filter class I'm using to narrowly suppress IOError exceptions raised f...
2
2012-02-11T16:54:25Z
[ "python", "django", "logging" ]
Getting rid of Django IOErrors
2,375,950
<p>I'm running a Django site (via Apache/mod_python) and I use Django's facilities to inform me and other developers about internal server errors. Sometimes errors like those appear:</p> <pre><code>Traceback (most recent call last): File "/opt/webapp/externals/lib/django/core/handlers/base.py", line 92, in get_resp...
6
2010-03-03T23:51:00Z
10,284,097
<p>Extending the solution by @dlowe for Django 1.3, we can write the full working example as:</p> <h1>settings.py</h1> <pre><code>LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'supress_unreadable_post': { '()': 'common.logging.SuppressUnreadablePost', ...
10
2012-04-23T16:05:21Z
[ "python", "django", "logging" ]
wsdl2py requests
2,375,956
<p>I'm trying to get results from a SOAP service called Chrome ADS (for vehicle data). They provided php and Java samples, but I need python (our site is in Django). My question is:</p> <p>What should I be passing as a request to the SOAP service when using wsdl2py-generated classes?</p> <p>Following the examples I'm...
1
2010-03-03T23:51:33Z
2,376,155
<p>You probably need to be instantiating your definition objects and then populating them. Look for type == pyclass_type objects associated with the request you're wanting to make and instantiate them.</p> <p>e.g. (just guessing)</p> <pre><code>&gt;&gt;&gt; versionrequest = getDataVersions() &gt;&gt;&gt; versionreque...
0
2010-03-04T00:46:58Z
[ "python", "soap", "wsdl" ]
wsdl2py requests
2,375,956
<p>I'm trying to get results from a SOAP service called Chrome ADS (for vehicle data). They provided php and Java samples, but I need python (our site is in Django). My question is:</p> <p>What should I be passing as a request to the SOAP service when using wsdl2py-generated classes?</p> <p>Following the examples I'm...
1
2010-03-03T23:51:33Z
2,381,764
<p>It looks like you might be passing a class to service.getDataVersions() the second time instead of an instance (it can't be an instance if it doesn't have _<em>class</em>_).</p> <p>What's happening is isinstance() returns false, and in the process of trying to raise a type error, an attribute error gets raised inst...
1
2010-03-04T18:34:46Z
[ "python", "soap", "wsdl" ]
Debugging Python Crash
2,376,029
<p>I am building Python 2.6 4 from source on a Linux server and am experiencing a Segmentation Fault when running the tests (make test) (test_hashlib.py and test_hmac.py). When I opened the core dump file in gdb, I am told that the error is at <code>0x00002b73379ac446 in ??</code>. I then recompiled python with both ...
2
2010-03-04T00:12:59Z
2,376,048
<p>Typically you need to set <code>CFLAGS</code> <em>before</em> calling <code>./configure</code> - it is usually written to bake a CFLAGS value into the <code>Makefile</code>.</p>
0
2010-03-04T00:17:42Z
[ "python", "linux", "debugging", "gdb" ]
Debugging Python Crash
2,376,029
<p>I am building Python 2.6 4 from source on a Linux server and am experiencing a Segmentation Fault when running the tests (make test) (test_hashlib.py and test_hmac.py). When I opened the core dump file in gdb, I am told that the error is at <code>0x00002b73379ac446 in ??</code>. I then recompiled python with both ...
2
2010-03-04T00:12:59Z
2,379,876
<p>How do you open core dump? I do it like this 'gdb .python core', where 'gdb' is gdb, '.python' is a binary file, that created the core, 'core' is the name of the 'core' file. When I open it like this 'gdb --core=core' I see the same as you, '??' instead of function name.</p>
0
2010-03-04T14:14:52Z
[ "python", "linux", "debugging", "gdb" ]
Regex redefinition error
2,376,049
<p>I am using python, and run into some redefinition error, I know they are redefinition but logically its not possible to reach that since its an or. Is there a way to get around this? I appreciate for any help in advance</p> <p>/python-2.5/lib/python2.5/re.py", line 233, in _compile raise error, v # invalid expr...
2
2010-03-04T00:17:57Z
2,376,063
<p>Regular expression syntax simply does not allow multiple occurrences of identically-named groups -- groups that aren't "reached" are defined to be "empty" (None) on a match.</p> <p>So you have to change those names e.g. to <code>dob0</code>, <code>dob1</code>, <code>dob2</code> and <code>id0</code>, <code>id1</code...
2
2010-03-04T00:24:03Z
[ "python", "regex", "scripting" ]
Regex redefinition error
2,376,049
<p>I am using python, and run into some redefinition error, I know they are redefinition but logically its not possible to reach that since its an or. Is there a way to get around this? I appreciate for any help in advance</p> <p>/python-2.5/lib/python2.5/re.py", line 233, in _compile raise error, v # invalid expr...
2
2010-03-04T00:17:57Z
2,376,288
<p>Perhaps in this case it is better to loop through a list of regular expressions. </p> <pre><code>&gt;&gt;&gt; strs=[ ... "garbage;DOB 10-10-2010;more garbage\nID PARI12345678;more garbage", ... "garbage;ID PARI12345678;more garbage\nDOB 10-10-2010;more garbage", ... "garbage;DOB 10-10-2010", ... "garbage;ID PARI123...
1
2010-03-04T01:24:47Z
[ "python", "regex", "scripting" ]
Regex redefinition error
2,376,049
<p>I am using python, and run into some redefinition error, I know they are redefinition but logically its not possible to reach that since its an or. Is there a way to get around this? I appreciate for any help in advance</p> <p>/python-2.5/lib/python2.5/re.py", line 233, in _compile raise error, v # invalid expr...
2
2010-03-04T00:17:57Z
2,376,409
<p>I was originally going to post a pyparsing example using the Each class (which picks out expressions that can be in any order), but then I saw that there was intermixed garbage, so searching through your string using <code>searchString</code> seemed a better fit. This intrigued me because <code>searchString</code> ...
2
2010-03-04T01:52:55Z
[ "python", "regex", "scripting" ]
Python and a "time value of money" problem
2,376,355
<p><em>(I asked this question earlier today, but I did a poor job of explaining myself. Let me try again)</em></p> <p>I have a client who is an industrial maintenance company. They sell service agreements that are prepaid 20 hour blocks of a technician's time. Some of their larger customers might burn through that ag...
0
2010-03-04T01:40:53Z
2,376,723
<p>If you want to consider the problem in terms of present value of future revenue (that's what "time value of money" implies to me), then you have the following parameters: discount rate D (on a monthly basis for convenience), time T a customer will take to exhaust their prepaid hours, likelihood L that they will rene...
1
2010-03-04T03:41:02Z
[ "python", "math", "finance" ]
Python and a "time value of money" problem
2,376,355
<p><em>(I asked this question earlier today, but I did a poor job of explaining myself. Let me try again)</em></p> <p>I have a client who is an industrial maintenance company. They sell service agreements that are prepaid 20 hour blocks of a technician's time. Some of their larger customers might burn through that ag...
0
2010-03-04T01:40:53Z
2,427,737
<p>Thanks for the assistance even though my requirements were a bit vague. After consulting someone who is extremely versed in financial mathematics, I determined that a simple formula was not an appropriate solution.</p> <p>What I ended up doing is "exploding" the months into the component days using xrange() and it...
0
2010-03-11T18:46:36Z
[ "python", "math", "finance" ]
How do I remove a column from a table in beautifulsoup (Python)
2,376,427
<p>I have an html table, and I would like to remove a column. What is the easiest way to do this with BeautifulSoup or any other python library?</p>
4
2010-03-04T01:57:05Z
2,376,565
<p><a href="http://codespeak.net/lxml/lxmlhtml.html" rel="nofollow">lxml.html</a> is nicer for manipulating HTML, IMO. Here's some code that will remove the second column of an HTML table.</p> <pre><code>from lxml import html text = """ &lt;table&gt; &lt;tr&gt;&lt;th&gt;head 1&lt;/th&gt;&lt;th&gt;head 2&lt;/th&gt;&lt...
2
2010-03-04T02:47:59Z
[ "python", "beautifulsoup", "html-table" ]
TypeError: unsupported operand type(s) for -: 'str' and 'int'
2,376,464
<p>New to python and programing how come I'm getting this error?</p> <pre><code>def cat_n_times(s, n): while s != 0: print(n) s = s - 1 text = input("What would you like the computer to repeat back to you: ") num = input("How many times: ") cat_n_times(num, text) </code></pre>
19
2010-03-04T02:13:23Z
2,376,520
<ol> <li><p>The reason this is failing is because (Python 3) <code>input</code> returns a string. To convert it to an integer, use <code>int(some_string)</code>. </p></li> <li><p>You do not typically keep track of indices manually in Python. A better way to implement such a function would be </p> <pre><code>def cat_n_...
25
2010-03-04T02:31:46Z
[ "python", "python-3.x" ]
TypeError: unsupported operand type(s) for -: 'str' and 'int'
2,376,464
<p>New to python and programing how come I'm getting this error?</p> <pre><code>def cat_n_times(s, n): while s != 0: print(n) s = s - 1 text = input("What would you like the computer to repeat back to you: ") num = input("How many times: ") cat_n_times(num, text) </code></pre>
19
2010-03-04T02:13:23Z
2,376,563
<p>For future reference Python is <a href="http://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language">strongly typed</a>. Unlike other dynamic languages, it will not automagically cast objects from one type or the other (say from <code>str</code> to <code>int<...
17
2010-03-04T02:46:24Z
[ "python", "python-3.x" ]
How do I loop through every 4th pixel in every 4th row, using Python?
2,376,505
<p>Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. <strong>Next , it will loop through every 4th pixel in every 4th row</strong> and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the res...
0
2010-03-04T02:26:22Z
2,376,516
<p>Stepped ranges come to mind <code>range(0, len(), 4)</code> but I don't know the type of your <code>pic</code>.</p>
3
2010-03-04T02:30:12Z
[ "python", "image", "audio" ]
How do I loop through every 4th pixel in every 4th row, using Python?
2,376,505
<p>Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. <strong>Next , it will loop through every 4th pixel in every 4th row</strong> and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the res...
0
2010-03-04T02:26:22Z
2,376,675
<p>I would guess the best way is to calculate the offset of 4 rows, and, when at the end of the row, add it to the current position. So you ave two iterations: one within the row, that skip 3 pixels, and one at the end of each row that skip 3 lines. But, as msw noted, without any information on your pic object, we can'...
0
2010-03-04T03:23:48Z
[ "python", "image", "audio" ]
How do I loop through every 4th pixel in every 4th row, using Python?
2,376,505
<p>Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. <strong>Next , it will loop through every 4th pixel in every 4th row</strong> and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the res...
0
2010-03-04T02:26:22Z
2,377,061
<p>Here's some building blocks you could base your program on:</p> <pre><code>#!/usr/bin/env python import easygui import Image import numpy filename = easygui.fileopenbox() # pick a file im = Image.open(filename) # make picture image_width, image_height = im.size im.show() # show picture ar = numpy.asarray(im) # get...
1
2010-03-04T05:23:06Z
[ "python", "image", "audio" ]
How do I loop through every 4th pixel in every 4th row, using Python?
2,376,505
<p>Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. <strong>Next , it will loop through every 4th pixel in every 4th row</strong> and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the res...
0
2010-03-04T02:26:22Z
2,377,394
<p>You might want to look at <a href="http://stackoverflow.com/questions/2364966/python-jython-playing-notes-from-pixels-in-picture/2365825#2365825">this question</a>. The person who asked that question seems to working on the same project as you.</p>
1
2010-03-04T07:00:45Z
[ "python", "image", "audio" ]
Apache using Python 2.4, Python 2.5 scripts failing
2,376,768
<p>Using CentOS5, I have Apache configured with the following directives.</p> <pre><code>Alias /pscript/ /var/www/pscript/ &lt;Directory "/var/www/pscript/"&gt; Options +ExecCGI DirectoryIndex thetest.py AddHandler cgi-script .py &lt;/Directory&gt; </code></pre> <p>When I call www.domain.com/pscript/ then...
1
2010-03-04T03:55:44Z
2,376,978
<p>Does the Python script have a first line something like:</p> <pre><code>#!/usr/bin/python </code></pre> <p>If so, maybe <code>/usr/bin/python</code> is Python version 2.4, while running <code>python</code> directly from the command line is running a different Python executable (version 2.5) from somewhere else in ...
3
2010-03-04T04:59:39Z
[ "python", "apache" ]
How do I print number of notes to be played?
2,376,788
<p>How do I do the second line in my main argument?</p> <pre><code>def main(): pic= makePicture( pickAFile()) ### It will print the number of notes to be played(which is the number of pixels in the pic divided by 16, why?)### listenToPicture(pic) def listenToPicture(pic): show(pic) w= getWidth...
1
2010-03-04T04:00:55Z
2,377,373
<p>in function <code>listenToPicture()</code>, you have this code:</p> <pre><code>w= getWidth(pic) h= getHeight(pic) for i in range(0, w, 4): for j in range(0, h, 4): .... </code></pre> <p>strangely, <code>i</code> and <code>j</code> are not used in the rest of the code, but seem to explain why the number...
1
2010-03-04T06:53:59Z
[ "python" ]
Django form INSERTs when I want it to UPDATE
2,376,797
<p>I'm new to Django but I seem to have nearly identical code working on another site. I can update a record in the Django shell, but in view.py the same code insists on INSERTing a new record when I run this form.</p> <ul> <li>I have a "DisciplineEvent" object in the model. I let Django create the "id" field for the...
0
2010-03-04T04:02:21Z
2,377,808
<p>What you are trying to do is unconventional and a possible <strong>security hole</strong>.</p> <p>You <strong>should not</strong> get the instance of the object from the hidden id key you populated in the form. Users can easily change this one and get your code to overwrite some other model instance that they may n...
9
2010-03-04T08:32:07Z
[ "python", "django" ]
How to write a python script to search a website html for matching links
2,376,798
<p>I am not too familiar with python and have to write a script to perform a host of functions. Basically the module i still need is how to check a website code for matching links provided beforehand.</p>
3
2010-03-04T04:02:46Z
2,376,812
<p>Generally, you use <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a>, <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a> (htmllib etc) for programming web in Python. you could also use <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mech...
3
2010-03-04T04:08:04Z
[ "python", "scrape" ]
How to write a python script to search a website html for matching links
2,376,798
<p>I am not too familiar with python and have to write a script to perform a host of functions. Basically the module i still need is how to check a website code for matching links provided beforehand.</p>
3
2010-03-04T04:02:46Z
2,376,923
<p>Matching links what? Their HREF attribute? The link display text? Perhaps something like:</p> <pre><code>from BeautifulSoup import BeautifulSoup, SoupStrainer import re import urllib2 doc = urllib2.urlopen("http://somesite.com").read() links = SoupStrainer('a', href=re.compile(r'^test')) soup = [str(elm) for elm i...
5
2010-03-04T04:39:37Z
[ "python", "scrape" ]
How to write a python script to search a website html for matching links
2,376,798
<p>I am not too familiar with python and have to write a script to perform a host of functions. Basically the module i still need is how to check a website code for matching links provided beforehand.</p>
3
2010-03-04T04:02:46Z
24,582,968
<p>try scrapy , the most comprehensive web extraction framework.</p> <p><a href="http://scrapy.org" rel="nofollow">http://scrapy.org</a> </p>
0
2014-07-05T04:27:50Z
[ "python", "scrape" ]
Python: How to refactor this simple list code?
2,376,833
<p>I'm new to Python. Am I doing it right?</p> <p>The goal:</p> <ol> <li><p>Get a bunch of <code>InCart</code> objects from Google App Engine's datastore that corresponds to the current user. Each <code>InCart</code> item has two attributes: <code>InCart.owner</code> and <code>InCart.item</code></p></li> <li><p>Provi...
2
2010-03-04T04:13:55Z
2,376,848
<p>For:</p> <pre><code>items = [] for entry in cartEntries: items.append(entry.item) </code></pre> <p>you could use a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>:</p> <pre><code>items = [entry.item for entry in cartEntries] </code></pre...
7
2010-03-04T04:18:16Z
[ "python", "google-app-engine", "code-review" ]
Python: How to refactor this simple list code?
2,376,833
<p>I'm new to Python. Am I doing it right?</p> <p>The goal:</p> <ol> <li><p>Get a bunch of <code>InCart</code> objects from Google App Engine's datastore that corresponds to the current user. Each <code>InCart</code> item has two attributes: <code>InCart.owner</code> and <code>InCart.item</code></p></li> <li><p>Provi...
2
2010-03-04T04:13:55Z
2,377,178
<p>Definitely use a comprehension as Alok said. I'd be inclined to use the same template for the table and add logic to the template to either render the table or the message, but that depends on the template system you are using.</p> <p>Maybe you are using <code>Views/message.html</code> in a bunch of places so it ma...
0
2010-03-04T05:54:41Z
[ "python", "google-app-engine", "code-review" ]
Python: How to refactor this simple list code?
2,376,833
<p>I'm new to Python. Am I doing it right?</p> <p>The goal:</p> <ol> <li><p>Get a bunch of <code>InCart</code> objects from Google App Engine's datastore that corresponds to the current user. Each <code>InCart</code> item has two attributes: <code>InCart.owner</code> and <code>InCart.item</code></p></li> <li><p>Provi...
2
2010-03-04T04:13:55Z
2,378,739
<p>Iterating over a query causes it to fetch results in batches of 20. This is much less efficient than fetching them all at once. You should call .fetch(), like this:</p> <pre><code>cartEntries = InCart.gql("WHERE owner = :1", self.user).fetch(1000) </code></pre> <p>Where 1000 is the maximum number of results you wa...
1
2010-03-04T11:12:15Z
[ "python", "google-app-engine", "code-review" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,376,875
<p>They all have different features. And don't forget <a href="http://project-voldemort.com/" rel="nofollow">Project Voldemort</a> which is actually used/tested by LinkedIn in their production before each release.</p> <p>It's hard to compare. You have to ask yourself what you need: e.g. do you want partitioning? if so...
7
2010-03-04T04:25:30Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,377,117
<blockquote> <p>Which do you recommend, and why?</p> </blockquote> <p>I recommend Redis. Why? Continue reading!!</p> <blockquote> <p>Which one is the fastest?</p> </blockquote> <p>I can't say whether it's the fastest. But Redis is <a href="http://redis.io/topics/benchmarks">fast</a>. It's fast because it holds a...
26
2010-03-04T05:35:50Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,377,161
<p>I really like <strong>memcached</strong> personally.</p> <p>I use it on a couple of my sites and it's simple, fast, and easy. It really was just incredibly simple to use, the API is easy to use. It doesn't store anything on disk, thus the name memcached, so it's out if you're looking for a persistent storage engine...
3
2010-03-04T05:50:14Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,380,691
<p>At this year's PyCon, Jeremy Edberg of Reddit gave a talk:</p> <p><a href="http://pycon.blip.tv/file/3257303/">http://pycon.blip.tv/file/3257303/</a></p> <p>He said that Reddit uses PostGres as a key-value store, presumably with a simple 2-column table; according to his talk it had benchmarked faster than any othe...
8
2010-03-04T16:00:23Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,380,715
<p>Just to make the list complete: there's Dreamcache, too. It's compatible with Memcached (in terms of protocol, so you can use any client library written for Memcached), it's just faster.</p>
1
2010-03-04T16:03:06Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,380,871
<p>I've been playing with MongoDB and it has one thing that makes it perfect for my application, the ability to store complex Maps/Lists in the database directly. I have a large Map where each value is a list and I don't have to do anything special just to write and retrieve that without knowing all the different keys ...
7
2010-03-04T16:24:34Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,380,915
<p>There is also zodb.</p>
4
2010-03-04T16:32:00Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,381,057
<p>One distinction you have to make is what will you use the DB for? Don't jump on board just because it's trendy. Do you need a key value store? or do you need a document based store? What is your memory footprint requirement? running it on a small VM or a separate one? </p> <p>I recommend listing your requirements f...
6
2010-03-04T16:49:11Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,384,388
<p>I notice how everyone is confusing memcached with memcachedb. They are two different systems. The op asked about memcachedb.</p> <p>memcached is memory storage. memcachedb uses Berkeley DB as its datastore.</p>
6
2010-03-05T03:29:35Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,438,183
<p>I only have experience with Berkeley DB, so I'll mention what I like about it.</p> <ul> <li>It is fast</li> <li>It is very mature and stable</li> <li>It has outstanding documentation</li> <li>It has C,C++,Java &amp; C# bindings out of the box. Other language bindings are available. I believe Python comes with bindi...
5
2010-03-13T11:44:32Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,616,225
<p>You need to understand what modern NoSQL phenomenon is about. <br> It is not about key-value storages. They've been available for decades (BerkeleyDB for example). Why all the fuss now ?</p> <p>It is not about fancy document or object oriented schemas and overcoming "impedance mismatch". Proponents of these feature...
24
2010-04-11T06:22:26Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
2,616,380
<p><a href="http://cassandra.apache.org/" rel="nofollow">Cassandra</a> seems to be popular.</p> <blockquote> <p>Cassandra is in use at Digg, Facebook, Twitter, Reddit, Rackspace, Cloudkick, Cisco, SimpleGeo, Ooyala, OpenX, and more companies that have large, active data sets. The largest production cluster has over ...
2
2010-04-11T08:01:31Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
6,257,091
<blockquote> <p>Which key value store is the most promising/stable?</p> </blockquote> <p><a href="http://forum.gwan.com/index.php?p=/discussion/comment/2253/#Comment_2253" rel="nofollow">G-WAN KV store</a> looks rather <strong>promising</strong>:</p> <pre><code>DB engine Traversal ----------- --...
4
2011-06-06T19:39:48Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
14,586,720
<p>As the others said, it depends always on your needs. I for example prefer whatever suits my applications best.</p> <p>I first used memcached to have fast read/write access. As Java API I´ve used SpyMemcached, what comes with an very easy interface you can use for writing and reading data. Due to memory leaks (no m...
1
2013-01-29T15:45:14Z
[ "python", "ruby", "database", "comparison" ]
Which key/value store is the most promising/stable?
2,376,846
<p>I'm looking to start using a key/value store for some side projects (mostly as a learning experience), but so many have popped up in the recent past that I've got no idea where to begin. Just listing from memory, I can think of:</p> <ol> <li>CouchDB</li> <li>MongoDB</li> <li>Riak</li> <li>Redis</li> <li>Tokyo Cabi...
58
2010-03-04T04:17:12Z
16,867,563
<p>Only have experience with mongoDB, memchache and redis. Here's a <a href="http://db-engines.com/en/system/CouchDB;Memcached;MongoDB;Redis" rel="nofollow">comparison</a> between them and couchDB.</p> <p>Seems mongoDB is most popular. It support sharding and replication, eventually consistent, has good support in rub...
1
2013-05-31T23:46:16Z
[ "python", "ruby", "database", "comparison" ]
wx.TR_HAS_VARIABLE_ROW_HEIGHT has no effect?
2,377,094
<p>I created a TreeListCtrl in wxPython like following.</p> <pre><code>self.tree = wx.gizmos.TreeListCtrl(self, style = wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_HIDE_ROOT | wx.TR_HAS_VARIABLE_ROW_HEIGHT) </code></pre> ...
0
2010-03-04T05:00:01Z
2,377,204
<p><code>wx.TR_HAS_VARIABLE_ROW_HEIGHT</code> applies to wx.TreeCntrl not wx.gizmos.TreeListCtrl, read <a href="http://www.wxpython.org/docs/api/wx.gizmos.TreeListCtrl-class.html" rel="nofollow">http://www.wxpython.org/docs/api/wx.gizmos.TreeListCtrl-class.html</a> to see what that tree cntrl can do</p> <p>If you see ...
0
2010-03-04T06:01:34Z
[ "python", "wxpython" ]
SQLAlchemy - Problem with an association table and dates in primary join
2,377,220
<p>I am working on defining my mapping with SQLAlchemy and I am pretty much done except one thing. I have a 'resource' object and an association table 'relation' with several properties and a relationship between 2 resources. What I have been trying to do almost successfully so far, is to provide on the resource object...
1
2010-03-04T06:08:18Z
2,384,626
<p>I actually have found the reason of my trouble and got it working. <a href="http://stackoverflow.com/questions/2384438/sqlalchemy-can-we-use-date-comparison-in-relation-definition">See here</a></p> <p>Cheers,</p> <p>Richard Lopes</p>
0
2010-03-05T04:47:31Z
[ "python", "database", "orm", "mapping", "sqlalchemy" ]
SQLAlchemy - Problem with an association table and dates in primary join
2,377,220
<p>I am working on defining my mapping with SQLAlchemy and I am pretty much done except one thing. I have a 'resource' object and an association table 'relation' with several properties and a relationship between 2 resources. What I have been trying to do almost successfully so far, is to provide on the resource object...
1
2010-03-04T06:08:18Z
2,384,646
<p>Consider using <code>&gt;=</code> instead of <code>&gt;</code> in date comparison.</p>
0
2010-03-05T04:54:17Z
[ "python", "database", "orm", "mapping", "sqlalchemy" ]
How to write a python script to manipulate google spreadsheet data
2,377,301
<p>I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell. </p> <p>i.e, I am able to get the feed from the worksheet. Now I need to get data(string type?) from each of the cells to make a comparison and for input. </p> <p>How exactly can I do that?</p>
5
2010-03-04T06:32:05Z
2,377,645
<p>Maybe you can use this library <a href="http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html" rel="nofollow">http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html</a> ?</p>
1
2010-03-04T07:57:28Z
[ "python", "google-spreadsheet", "gspread" ]
How to write a python script to manipulate google spreadsheet data
2,377,301
<p>I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell. </p> <p>i.e, I am able to get the feed from the worksheet. Now I need to get data(string type?) from each of the cells to make a comparison and for input. </p> <p>How exactly can I do that?</p>
5
2010-03-04T06:32:05Z
2,377,867
<p>Google data api has a Python binding including for spreadsheets: <a href="http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html" rel="nofollow">http://code.google.com/apis/spreadsheets/data/1.0/developers_guide_python.html</a></p>
3
2010-03-04T08:43:00Z
[ "python", "google-spreadsheet", "gspread" ]
How to write a python script to manipulate google spreadsheet data
2,377,301
<p>I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell. </p> <p>i.e, I am able to get the feed from the worksheet. Now I need to get data(string type?) from each of the cells to make a comparison and for input. </p> <p>How exactly can I do that?</p>
5
2010-03-04T06:32:05Z
8,468,493
<p>There's another <a href="https://github.com/burnash/gspread">spreadsheet library</a> worth to look at: gspread. I've used Google's data libary mentioned above and to me the provided api is weird. You need to extract spreadsheet's key to start working with this spreadsheet.</p> <p>Here it's a way simpler. If you nee...
21
2011-12-11T23:55:10Z
[ "python", "google-spreadsheet", "gspread" ]
How to write a python script to manipulate google spreadsheet data
2,377,301
<p>I am able to get the feed from the spreadsheet and worksheet ID. I want to capture the data from each cell. </p> <p>i.e, I am able to get the feed from the worksheet. Now I need to get data(string type?) from each of the cells to make a comparison and for input. </p> <p>How exactly can I do that?</p>
5
2010-03-04T06:32:05Z
22,048,019
<p>gspread is probably the fastest way to begin this process, however there are some speed limitations on updating data using gspread from your localhost. If you're moving large sets of data with gspread - for instance moving 20 columns of data over a column, you may want to automate the process using a CRON job.</p>
0
2014-02-26T16:54:11Z
[ "python", "google-spreadsheet", "gspread" ]
Sqlalchemy file organization
2,377,549
<p>Does anyone has any insight on organizing sqlalchemy based projects? I have many tables and classes with foreign keys, and relations. What is everyone doing in terms of separating classes, tables, and mappers ? I am relatively new to the framework, so any help would be appreciated.</p> <p>Example:</p> <pre><code>c...
2
2010-03-04T07:36:43Z
2,378,474
<p>Take a look at Pylons project including SA setup.</p> <p><strong>meta.py</strong> includes engine and metadata objects</p> <p><strong>models</strong> package includes declerative classes (no mapper needed). Inside that package, structure your classes by relavance into modules. </p> <p>Maybe a good example would b...
1
2010-03-04T10:31:47Z
[ "python", "sqlalchemy" ]
Sqlalchemy file organization
2,377,549
<p>Does anyone has any insight on organizing sqlalchemy based projects? I have many tables and classes with foreign keys, and relations. What is everyone doing in terms of separating classes, tables, and mappers ? I am relatively new to the framework, so any help would be appreciated.</p> <p>Example:</p> <pre><code>c...
2
2010-03-04T07:36:43Z
2,384,717
<p>There are two features in SQLAlchemy design to avoid cross imports when defining relations:</p> <ol> <li><code>backref</code> argument of <code>relation()</code> allows you to define backward relation.</li> <li>Using strings (model class and their fields names). Unfortunately this works for declarative only, which ...
1
2010-03-05T05:19:15Z
[ "python", "sqlalchemy" ]
deprecation of apply decorator
2,377,573
<p>There was a beautiful way to organize class property in frame of one function, by using the apply decorator. </p> <pre><code>class Example(object): @apply def myattr(): doc = """This is the doc string.""" def fget(self): return self._half * 2 def fset(self, value): ...
7
2010-03-04T07:40:50Z
2,377,586
<p>You can always write your own:</p> <pre><code>def apply(f, a): return f(*a) </code></pre> <p>However, I'm not quite sure I see the benefit of using <code>apply</code> as a decorator in this way. What's the use case?</p>
0
2010-03-04T07:43:19Z
[ "python" ]
deprecation of apply decorator
2,377,573
<p>There was a beautiful way to organize class property in frame of one function, by using the apply decorator. </p> <pre><code>class Example(object): @apply def myattr(): doc = """This is the doc string.""" def fget(self): return self._half * 2 def fset(self, value): ...
7
2010-03-04T07:40:50Z
2,377,950
<p>:) that is a clever user of apply, though i am not sure if there are any pitfalls?</p> <p>anyway you can do this</p> <pre><code>class Example(object): def myattr(): doc = """This is the doc string.""" def fget(self): return self._half * 2 def fset(self, value): ...
2
2010-03-04T09:00:42Z
[ "python" ]
deprecation of apply decorator
2,377,573
<p>There was a beautiful way to organize class property in frame of one function, by using the apply decorator. </p> <pre><code>class Example(object): @apply def myattr(): doc = """This is the doc string.""" def fget(self): return self._half * 2 def fset(self, value): ...
7
2010-03-04T07:40:50Z
2,377,983
<blockquote> <p>Is there any possibility to achieve such simplicity and readability for property</p> </blockquote> <p>The new Python 2.6 way is:</p> <pre><code>@property def myattr(self): """This is the doc string.""" return self._half * 2 @myattr.setter def myattr(self, value): self._half = value / 2 ...
12
2010-03-04T09:09:25Z
[ "python" ]
Django/App Engine/Python 2.5: default __new__ takes no parameters
2,377,627
<p>New to app engine and django. I think this is an issue with my django install, which is 1.1.1, but I've also read that I can just use the django packaged with the app engine SDK.</p> <p>Any help on why I'm getting this error when I test locally would be greatly appreciated.</p> <p><strong>The callback:</strong></...
0
2010-03-04T07:53:27Z
2,380,440
<p>You appear to have subclassed (at least once) a Django's view class with an <code>__init__</code> (but not a <code>__new__</code>) with a non-standard signature. If you click on the triangle towards the beginning of this message (in your own environment -- the click doesn't work on this copy/pasted msg in SO, of co...
2
2010-03-04T15:26:58Z
[ "python", "django", "google-app-engine" ]