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 |
|---|---|---|---|---|---|---|---|---|---|
Get stacktrace from stuck python process | 1,781,935 | <p>I have to run a legacy Zope2 website and have some grievance with it. The biggest issue is that, occasionally, it just locks up, running at 100% CPU load and not answering to requests anymore. While the problem isn't reproducible on a regular basis, one page containing 3 dynamic graphs triggers it sometimes, so I su... | 5 | 2009-11-23T09:14:29Z | 1,781,955 | <p>You could try to attach a debugger to the running process. See also <a href="http://stackoverflow.com/questions/47701/is-there-a-way-to-attach-a-debugger-to-a-multi-threaded-python-process">this question</a>.</p>
| 1 | 2009-11-23T09:17:42Z | [
"python",
"debugging",
"infinite-loop",
"zope"
] |
Get stacktrace from stuck python process | 1,781,935 | <p>I have to run a legacy Zope2 website and have some grievance with it. The biggest issue is that, occasionally, it just locks up, running at 100% CPU load and not answering to requests anymore. While the problem isn't reproducible on a regular basis, one page containing 3 dynamic graphs triggers it sometimes, so I su... | 5 | 2009-11-23T09:14:29Z | 1,781,977 | <p>If the process is stuck in a way that no other signal gets through, you might want to consider running it from a debugger, instead of trying to attach to it at runtime.</p>
<p>Also, it might be useful to other debugging tactics, like turning off certain parts of the code to find out the minimal case in which it is ... | 0 | 2009-11-23T09:21:07Z | [
"python",
"debugging",
"infinite-loop",
"zope"
] |
Get stacktrace from stuck python process | 1,781,935 | <p>I have to run a legacy Zope2 website and have some grievance with it. The biggest issue is that, occasionally, it just locks up, running at 100% CPU load and not answering to requests anymore. While the problem isn't reproducible on a regular basis, one page containing 3 dynamic graphs triggers it sometimes, so I su... | 5 | 2009-11-23T09:14:29Z | 1,783,841 | <p>See my answer to <a href="http://stackoverflow.com/questions/1032813/dump-stacktraces-of-all-active-threads/1038671#1038671" title="Dump stacktraces of all active Threads">this SO question</a>, use <a href="http://pypi.python.org/pypi/Products.signalstack" rel="nofollow">Products.signalstack</a>. It registers the sa... | 2 | 2009-11-23T15:26:46Z | [
"python",
"debugging",
"infinite-loop",
"zope"
] |
Get stacktrace from stuck python process | 1,781,935 | <p>I have to run a legacy Zope2 website and have some grievance with it. The biggest issue is that, occasionally, it just locks up, running at 100% CPU load and not answering to requests anymore. While the problem isn't reproducible on a regular basis, one page containing 3 dynamic graphs triggers it sometimes, so I su... | 5 | 2009-11-23T09:14:29Z | 39,713,320 | <p>after running around the internet in circles for a while I finally ended up here: <a href="http://podoliaka.org/2016/04/10/debugging-cpython-gdb/" rel="nofollow">http://podoliaka.org/2016/04/10/debugging-cpython-gdb/</a> - describes in detail how all the pieces fit together. the money quote for me was 'gdb <strong>/... | 0 | 2016-09-26T22:21:43Z | [
"python",
"debugging",
"infinite-loop",
"zope"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,781,987 | <p>Might be a nicer way, but this should work</p>
<pre><code>tuple([10*x for x in img.size])
</code></pre>
| 20 | 2009-11-23T09:22:41Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,781,991 | <p>You can try something like this:</p>
<pre><code>print [10 * s for s in img.size]
</code></pre>
<p>It will give you a new list with all the elements you have in the tuple multiplied by 10</p>
| 1 | 2009-11-23T09:24:01Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,781,995 | <p>The <strong>pythonic</strong> way would be using a list comprehension:</p>
<pre><code>y = tuple([z * 10 for z in img.size])
</code></pre>
<p>Another way could be:</p>
<pre><code>y = tuple(map((10).__mul__, img.size))
</code></pre>
| 10 | 2009-11-23T09:24:29Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,782,003 | <pre><code>img.size = tuple(i * 10 for i in img.size)
</code></pre>
| 18 | 2009-11-23T09:25:30Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,782,006 | <p>There is probably a simpler way than this, but</p>
<pre><code>print map(lambda x: 10*x, img.size)
</code></pre>
<p>Will do nearly what you want, although it prints as a list rather than a tuple. Wrap the <code>map</code> call inside <code>tuple(map...)</code> if you want it to print as a tuple (parentheses rather ... | 3 | 2009-11-23T09:25:52Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 1,782,085 | <p>If you have this problem more often and with larger tuples or lists then you might want to use the <a href="http://www.numpy.org/" rel="nofollow">numpy</a> library, which allows you to do all kinds of mathematical operations on arrays. However, in this simple situation this would be complete overkill.</p>
| 2 | 2009-11-23T09:40:59Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 17,874,936 | <p>adding nothing but variety..</p>
<pre><code>import operator
img_size = (70, 70)
map(operator.mul, img_size, len(img_size)*(10,))
</code></pre>
| 0 | 2013-07-26T07:02:43Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 24,527,626 | <p>Solution:</p>
<pre><code>set1=(70, 70)
tuple(2*array(set1))
</code></pre>
<p>Explanation: <code>arrays</code> make direct scalar multiplication possible. Hence the <code>tuple</code> called <code>set1</code> here is converted to an <code>array</code>. I assume you wish to keep using the <code>tuple</code>, hence w... | 4 | 2014-07-02T09:33:52Z | [
"python",
"python-imaging-library"
] |
Multiplying a tuple by a scalar | 1,781,970 | <p>I have the following code:</p>
<pre><code>print img.size
print 10 * img.size
</code></pre>
<p>this will print</p>
<pre><code>(70, 70)
(70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70)
</code></pre>
<p>while I'd like it to print</p>
<pre><code>(700, 700)
</code></pre>
<p>Is any wa... | 18 | 2009-11-23T09:19:40Z | 35,268,472 | <p>In line with the previous answers but using numpy:</p>
<pre><code>import numpy as np
result = tuple(10*np.array(img.size))
</code></pre>
| 0 | 2016-02-08T11:23:44Z | [
"python",
"python-imaging-library"
] |
Convert Perl script to Python: dedupe 2 files based on hash keys | 1,782,033 | <p>I am new to Python and would like to know if someone would kindly convert an example of a fairly simple Perl script to Python? </p>
<p>The script takes 2 files and outputs only unique lines from the second file by comparing hash keys. It also outputs duplicate lines to a file. I have found that this method of dedup... | 1 | 2009-11-23T09:31:19Z | 1,782,076 | <p>You can use sets in Python if you don't care about order:</p>
<pre><code>file1=set(open("file1").readlines())
file2=set(open("file2").readlines())
intersection = file1 & file2 #common lines
non_intersection = file2 - file1 #uncommon lines (in file2 but not file1)
for items in intersection:
print items
for ... | 7 | 2009-11-23T09:39:28Z | [
"python",
"perl",
"hash"
] |
Convert Perl script to Python: dedupe 2 files based on hash keys | 1,782,033 | <p>I am new to Python and would like to know if someone would kindly convert an example of a fairly simple Perl script to Python? </p>
<p>The script takes 2 files and outputs only unique lines from the second file by comparing hash keys. It also outputs duplicate lines to a file. I have found that this method of dedup... | 1 | 2009-11-23T09:31:19Z | 1,782,223 | <p>Here's a slightly different solution that's a little more memory friendly, should the files be very large. This only creates a set for the original file (as there doesn't seem to be a need to have all of file2 in memory at once):</p>
<pre><code>with open("file1.txt", "r") as file1:
file1set = set(line.rstrip()... | 3 | 2009-11-23T10:15:35Z | [
"python",
"perl",
"hash"
] |
Convert Perl script to Python: dedupe 2 files based on hash keys | 1,782,033 | <p>I am new to Python and would like to know if someone would kindly convert an example of a fairly simple Perl script to Python? </p>
<p>The script takes 2 files and outputs only unique lines from the second file by comparing hash keys. It also outputs duplicate lines to a file. I have found that this method of dedup... | 1 | 2009-11-23T09:31:19Z | 1,782,802 | <p>Yet another variant (merely syntaxic changes from other proposals, there is also more than one way to do it using python).</p>
<pre><code>file1set = set([line for line in file("file1.txt")])
file2set = set([line for line in file("file2.txt")])
for name, results in [
("duplicate.txt", file1set.intersection(file... | 4 | 2009-11-23T12:15:53Z | [
"python",
"perl",
"hash"
] |
Why don't these two math functions return the same result? | 1,782,114 | <p>I'm trying to use fancy indexing instead of looping to speed up a function in Numpy. To the best of my knowledge, I've implemented the fancy indexing version correctly. The problem is that the two functions (loop and fancy-indexed) do not return the same result. I'm not sure why. It's worth pointing out that the fun... | 0 | 2009-11-23T09:47:32Z | 1,782,332 | <p>First, in fancy your signal is now 2D if I understand correctly - so I think it would be clearer to index it explicitly (eg amp_a = mean(signal[t-window_size:t,:], axis=0). Similarly with alen(signal) - this should just be samples in both cases so I think it would be clearer to use that.</p>
<p>It is wrong whenever... | 0 | 2009-11-23T10:44:09Z | [
"python",
"numpy",
"scipy"
] |
Why don't these two math functions return the same result? | 1,782,114 | <p>I'm trying to use fancy indexing instead of looping to speed up a function in Numpy. To the best of my knowledge, I've implemented the fancy indexing version correctly. The problem is that the two functions (loop and fancy-indexed) do not return the same result. I'm not sure why. It's worth pointing out that the fun... | 0 | 2009-11-23T09:47:32Z | 1,783,227 | <p>The problem is this line:</p>
<pre><code>maxdiff[the_diff > maxdiff] = the_diff
</code></pre>
<p>The left side selects only some elements of maxdiff, but the right side contains all elements of the_diff. This should work instead:</p>
<pre><code>replaceElements = the_diff > maxdiff
maxdiff[replaceElements] =... | 3 | 2009-11-23T13:47:47Z | [
"python",
"numpy",
"scipy"
] |
How do I order this list in Python? | 1,782,253 | <pre><code>[(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
</code></pre>
<p>I want to order this alphabetically, by "PRP, VBD, PRP, and VBP"
It's not the traditional sort, right?</p>
| 1 | 2009-11-23T10:24:34Z | 1,782,274 | <p>Use itemgetter:</p>
<pre><code>>>> a = [(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
>>> import operator
>>> a.sort(key = operator.itemgetter(1))
>>> a
[(u'.', '.'), (u'we', 'PRP'), (u'you', 'PRP'), (u'saw', 'VBD'), (u'bruh', 'VBP')]
</code></p... | 15 | 2009-11-23T10:31:20Z | [
"python",
"list",
"sorting"
] |
How do I order this list in Python? | 1,782,253 | <pre><code>[(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
</code></pre>
<p>I want to order this alphabetically, by "PRP, VBD, PRP, and VBP"
It's not the traditional sort, right?</p>
| 1 | 2009-11-23T10:24:34Z | 1,782,284 | <p>You can pass a comparison function in the <code>sort</code> method. </p>
<p>Example:</p>
<pre><code>l = [(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
l.sort(lambda x, y: cmp(x[1], y[1])) # compare tuple's 2nd elements
</code></pre>
<p>Output:</p>
<pre><code>>>> l
[(u... | 1 | 2009-11-23T10:33:56Z | [
"python",
"list",
"sorting"
] |
How do I order this list in Python? | 1,782,253 | <pre><code>[(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
</code></pre>
<p>I want to order this alphabetically, by "PRP, VBD, PRP, and VBP"
It's not the traditional sort, right?</p>
| 1 | 2009-11-23T10:24:34Z | 1,782,354 | <p>The <a href="http://docs.python.org/library/stdtypes.html#mutable-sequence-types" rel="nofollow"><code>sort</code> method</a> takes a <code>key</code> argument to extract a comparison key from each argument, i.e. <code>key</code> is a function which transforms the list item into the value you wish to sort on.</p>
<... | 7 | 2009-11-23T10:48:45Z | [
"python",
"list",
"sorting"
] |
How do I order this list in Python? | 1,782,253 | <pre><code>[(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
</code></pre>
<p>I want to order this alphabetically, by "PRP, VBD, PRP, and VBP"
It's not the traditional sort, right?</p>
| 1 | 2009-11-23T10:24:34Z | 1,782,364 | <p>Or use the Built-in Function sorted (similar to Nick_D's answer):</p>
<pre><code>ls = [(u'we', 'PRP'), (u'saw', 'VBD'), (u'you', 'PRP'), (u'bruh', 'VBP'), (u'.', '.')]
sorted(ls, cmp=lambda t1, t2: cmp(t1[1], t2[1]))
</code></pre>
| 0 | 2009-11-23T10:50:18Z | [
"python",
"list",
"sorting"
] |
app engine: string to datetime? | 1,782,255 | <p>i have string </p>
<pre><code>date = "11/28/2009"
hour = "23"
minutes = "59"
seconds = "00"
</code></pre>
<p>how can i convert to datetime object and store it in datastore?</p>
| 6 | 2009-11-23T10:24:45Z | 1,782,287 | <p>I apologize if this isn't what you want, but at least for the first part of the question you could probably do it like so?</p>
<pre><code>>>> import datetime
>>> datetime.datetime.strptime(date + ' ' + hour + ':' + minutes + ':' + seconds, '%m/%d/%Y %H:%M:%S')
datetime.datetime(2009, 11, 28, 23, 5... | 11 | 2009-11-23T10:34:56Z | [
"python",
"datetime"
] |
Is it possible to hook up a more robust HTML parser to Python mechanize? | 1,782,368 | <p>I am trying to parse and submit a form on a website using mechanize, but it appears that the built-in form parser cannot detect the form and its elements. I suspect that it is choking on poorly formed HTML, and I'd like to try pre-parsing it with a parser better designed to handle bad HTML (say lxml or BeautifulSoup... | 9 | 2009-11-23T10:50:44Z | 1,783,735 | <p>reading from the big example on the first page of the <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize website</a>:</p>
<pre><code># Sometimes it's useful to process bad headers or bad HTML:
response = br.response() # this is a copy of response
headers = response.info() # currently, ... | 3 | 2009-11-23T15:13:27Z | [
"python",
"mechanize"
] |
Is it possible to hook up a more robust HTML parser to Python mechanize? | 1,782,368 | <p>I am trying to parse and submit a form on a website using mechanize, but it appears that the built-in form parser cannot detect the form and its elements. I suspect that it is choking on poorly formed HTML, and I'd like to try pre-parsing it with a parser better designed to handle bad HTML (say lxml or BeautifulSoup... | 9 | 2009-11-23T10:50:44Z | 1,783,742 | <p>What you're looking for can be done with <code>lxml.etree</code> which is the <code>xml.etree.ElementTree</code> emulator (and replacement) provided by <code>lxml</code>:</p>
<p>First we take bad mal-formed HTML:</p>
<pre><code>% cat bad.html
<html>
<HEAD>
<TITLE>this HTML is awful</title&... | 1 | 2009-11-23T15:14:38Z | [
"python",
"mechanize"
] |
Is it possible to hook up a more robust HTML parser to Python mechanize? | 1,782,368 | <p>I am trying to parse and submit a form on a website using mechanize, but it appears that the built-in form parser cannot detect the form and its elements. I suspect that it is choking on poorly formed HTML, and I'd like to try pre-parsing it with a parser better designed to handle bad HTML (say lxml or BeautifulSoup... | 9 | 2009-11-23T10:50:44Z | 1,783,758 | <p>Check out <a href="http://twill.idyll.org/" rel="nofollow">twill</a>.</p>
| 1 | 2009-11-23T15:16:48Z | [
"python",
"mechanize"
] |
Is it possible to hook up a more robust HTML parser to Python mechanize? | 1,782,368 | <p>I am trying to parse and submit a form on a website using mechanize, but it appears that the built-in form parser cannot detect the form and its elements. I suspect that it is choking on poorly formed HTML, and I'd like to try pre-parsing it with a parser better designed to handle bad HTML (say lxml or BeautifulSoup... | 9 | 2009-11-23T10:50:44Z | 5,039,584 | <p>I had a problem where a form field was missing from a form, I couldn't find any malformed html but I figured that was the cause so I used BeautifulSoup's prettify function to parse it and it worked.</p>
<pre><code>resp = br.open(url)
soup = BeautifulSoup(resp.get_data())
resp.set_data(soup.prettify())
br.set_respon... | 10 | 2011-02-18T09:27:11Z | [
"python",
"mechanize"
] |
How to change firefox proxy from webdriver? | 1,782,375 | <p>how can I access Firefox proxy settings from Python Webdriver and change them to make Firefox use modified proxy settings <em>without needing to restart it</em>?</p>
| 1 | 2009-11-23T10:52:41Z | 1,782,487 | <p>I don't think that is possible from the outside of Firefox. Have a look at <a href="https://addons.mozilla.org/de/firefox/addon/2464" rel="nofollow">FoxyProxy</a>. It allows you to define a proxy per URL pattern.</p>
| 0 | 2009-11-23T11:13:38Z | [
"python",
"firefox",
"proxy",
"webdriver"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,599 | <p>If you're just searching for a particular substring, use <a href="http://docs.python.org/library/stdtypes.html#str.find" rel="nofollow"><code>str.find()</code></a> instead.</p>
| 0 | 2009-11-23T11:35:38Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,600 | <p>Depending on what you're doing it might be better to use a tokenizer and loop through the tokens to find matches.</p>
<p>However, when it comes to short pieces of text regexes have incredibly good performance. Personally I remember only coming into problems when text sizes became ridiculous like 100k words or somet... | 0 | 2009-11-23T11:35:52Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,608 | <p>in general case, you can use "in" keyword</p>
<pre><code>for line in open("file"):
if "word" in line:
print line.rstrip()
</code></pre>
<p>regex is usually not needed when you use Python :)</p>
| 0 | 2009-11-23T11:37:36Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,614 | <p>If speed is of the essence, you are better off running some tests before you decide how to code your production application.</p>
<p>First of all, you said that you are searching for words which suggests that you may be able to do this using split() to break up the string on whitespace. And then use simple string co... | 5 | 2009-11-23T11:38:30Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,626 | <p>When you compile the regexp, it is converted into a state machine representation. Provided the regexp is efficiently expressed, it should still be very fast to match. Compiling the regexp can be expensive though, so you will want to do that up front, and as infrequently as possible. Ultimately though, only you can a... | 1 | 2009-11-23T11:41:08Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,712 | <p>You should try to compile all your regexps into a single one using the <code>|</code> operator. That way, the regexp engine will do most of the optimizations for you. Use the grouping operator <code>()</code> to determine which regexp matched.</p>
| 4 | 2009-11-23T11:59:46Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,782,806 | <p>If you like to know how does it fast during compiling regex patterns, you need to benchmark it.</p>
<p>Here is how I do that. Its compile 1 Million time each patterns.</p>
<pre><code>import time,re
def taken(f):
def wrap(*arg):
t1,r,t2=time.time(),f(*arg),time.time()
print t2-t1,"s taken"
return r
return ... | 2 | 2009-11-23T12:16:27Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,783,030 | <p>Your requirement appears to be searching a text for the first occurrence of any one of a collection of strings. Presumably you then wish to restart the search to find the next occurrence, and so on until the searched string is exhausted. Only plain old string comparison is involved.</p>
<p>The classic algorithm for... | 3 | 2009-11-23T13:01:45Z | [
"python",
"regex",
"performance"
] |
Speed of many regular expressions in python | 1,782,586 | <p>I'm writing a python program that deals with a fair amount of strings/files. My problem is that I'm going to be presented with a fairly short piece of text, and I'm going to need to search it for instances of a fairly broad range of words/phrases.</p>
<p>I'm thinking I'll need to compile regular expressions as a wa... | 4 | 2009-11-23T11:32:22Z | 1,785,029 | <p>This is a question that can readily be answered by just trying it.</p>
<pre><code>>>> import re
>>> import timeit
>>> find = ['foo', 'bar', 'baz']
>>> pattern = re.compile("|".join(find))
>>> with open('c:\\temp\\words.txt', 'r') as f:
words = f.readlines()
>... | 1 | 2009-11-23T18:23:11Z | [
"python",
"regex",
"performance"
] |
Distribute a Python program with a minimal environment | 1,782,680 | <p>I want to distribute a Python application to windows users who don't have Python or the correct Python version.</p>
<p>I have tried py2exe conversion but my Python program is really complex and involve code import on the fly by xmlrpc process so it is not suitable for py2exe.</p>
<p>The complete Python folder take... | 7 | 2009-11-23T11:52:41Z | 1,782,726 | <p>Have a look at <a href="http://www.portablepython.com/" rel="nofollow">Portable Python</a>. This will install a Python programming environment in a local folder. I am sure that you could strip many unwanted things off.</p>
<p>I recommend however that you give py2exe another chance.</p>
| 3 | 2009-11-23T12:02:08Z | [
"python",
"windows",
"installer"
] |
Distribute a Python program with a minimal environment | 1,782,680 | <p>I want to distribute a Python application to windows users who don't have Python or the correct Python version.</p>
<p>I have tried py2exe conversion but my Python program is really complex and involve code import on the fly by xmlrpc process so it is not suitable for py2exe.</p>
<p>The complete Python folder take... | 7 | 2009-11-23T11:52:41Z | 1,784,515 | <p><a href="http://www.google.com/search?client=safari&rls=en&q=pyinstaller&ie=UTF-8&oe=UTF-8" rel="nofollow">PyInstaller</a> is a py2exe "competitor" that has many extras (such as being cross-platform, supporting popular third party packages "out of the box", and explicitly supporting advanced importin... | 4 | 2009-11-23T17:00:53Z | [
"python",
"windows",
"installer"
] |
Distribute a Python program with a minimal environment | 1,782,680 | <p>I want to distribute a Python application to windows users who don't have Python or the correct Python version.</p>
<p>I have tried py2exe conversion but my Python program is really complex and involve code import on the fly by xmlrpc process so it is not suitable for py2exe.</p>
<p>The complete Python folder take... | 7 | 2009-11-23T11:52:41Z | 3,212,744 | <blockquote>
<blockquote>
<p>..involve code import on the fly by xmlrpc process so it is not suitable for py2exe</p>
</blockquote>
</blockquote>
<p>Py2exe can deal with situations like this. You just have to tell it which modules are being imported at runtime, so that it includes them in the distribution. Your... | 1 | 2010-07-09T12:56:40Z | [
"python",
"windows",
"installer"
] |
Django passing a model instance to slightly different model | 1,782,815 | <p>I'm writing an django app for a project where everybody can change articles but the changes that users commit have to be viewed by someone before they go online. So you see it is a bit like the system used by wikipedia.</p>
<pre><code>class Content(models.Model):
tp = models.DateTimeField(auto_now_add=True)
... | 1 | 2009-11-23T12:19:24Z | 1,784,214 | <p>The way you have your models coded, I don't think it's going to work like you're expecting. In this case ChangeSet inherits from Content. The way Django implements this is by create a OneToOneField that connects ChangeSet with Content. This means 2 things for your application:</p>
<ol>
<li>Having the ForeignKey ... | 1 | 2009-11-23T16:19:18Z | [
"python",
"django"
] |
Python decorator handling docstrings | 1,782,843 | <p>I have a problem using docstrings with decorators. Given the following example:</p>
<pre><code>def decorator(f):
def _decorator():
print 'decorator active'
f()
return _decorator
@decorator
def foo():
'''the magic foo function'''
print 'this is function foo'
help(foo)
</code></pre>
... | 34 | 2009-11-23T12:24:39Z | 1,782,881 | <p>I found a solution, but don't know if it's really nice:</p>
<pre><code>def decorator(f):
def _decorator():
print 'decorator active'
f()
_decorator.__name__=f.__name__
_decorator.__doc__=f.__doc__
return _decorator
</code></pre>
<p>The part with <code>_decorator.__name__=f.__name__</... | 12 | 2009-11-23T12:31:32Z | [
"python",
"decorator",
"docstring"
] |
Python decorator handling docstrings | 1,782,843 | <p>I have a problem using docstrings with decorators. Given the following example:</p>
<pre><code>def decorator(f):
def _decorator():
print 'decorator active'
f()
return _decorator
@decorator
def foo():
'''the magic foo function'''
print 'this is function foo'
help(foo)
</code></pre>
... | 34 | 2009-11-23T12:24:39Z | 1,782,888 | <p>Use <code>functools.wraps()</code> to update the attributes of the decorator:</p>
<pre><code>from functools import wraps
def decorator(f):
@wraps(f)
def _decorator():
print 'decorator active'
f()
return _decorator
@decorator
def foo():
'''the magic foo function'''
print 'this i... | 48 | 2009-11-23T12:33:04Z | [
"python",
"decorator",
"docstring"
] |
Python decorator handling docstrings | 1,782,843 | <p>I have a problem using docstrings with decorators. Given the following example:</p>
<pre><code>def decorator(f):
def _decorator():
print 'decorator active'
f()
return _decorator
@decorator
def foo():
'''the magic foo function'''
print 'this is function foo'
help(foo)
</code></pre>
... | 34 | 2009-11-23T12:24:39Z | 1,782,903 | <p>Take a look at <code>functools.wraps</code>: <a href="http://docs.python.org/library/functools.html" rel="nofollow">http://docs.python.org/library/functools.html</a></p>
| 1 | 2009-11-23T12:34:52Z | [
"python",
"decorator",
"docstring"
] |
Python decorator handling docstrings | 1,782,843 | <p>I have a problem using docstrings with decorators. Given the following example:</p>
<pre><code>def decorator(f):
def _decorator():
print 'decorator active'
f()
return _decorator
@decorator
def foo():
'''the magic foo function'''
print 'this is function foo'
help(foo)
</code></pre>
... | 34 | 2009-11-23T12:24:39Z | 10,999,330 | <p>It's probably a bit old now but this is how you do it. Just make sure that <code>@decorator</code> is indented on the same line as <code>def decorator(f)</code>:</p>
<pre><code>from functools import wraps
def decorator(f):
@wraps(f)
def _decorator():
print 'decorator active'
return f()
... | -4 | 2012-06-12T15:00:34Z | [
"python",
"decorator",
"docstring"
] |
Openlayers + Mapnik + Tilecache configuration problem | 1,783,081 | <p>I am trying to setup Mapnik + tilecache but can't see any tiles in the browser when I set bbox parameters in both Tilecache.cfg and Openlayers but when I don't specify the bbox everything works fine and I can see actual map tiles.</p>
<p>I was wondering if anyone can point out the problem in the code. I think I hav... | 1 | 2009-11-23T13:18:11Z | 1,806,721 | <p>Looking at your code I think you are asking for the region bounded by 50 and 54 degrees east, and 2 degrees north and south. Is this correct?</p>
<p>If it is, then I think your bounds are the wrong way around. -2 degrees (south) should be at the bottom, and 2 degrees (north) should be at the top. So the bbox should... | 1 | 2009-11-27T04:28:37Z | [
"python",
"maps",
"openlayers",
"proj4js",
"tilecache"
] |
Openlayers + Mapnik + Tilecache configuration problem | 1,783,081 | <p>I am trying to setup Mapnik + tilecache but can't see any tiles in the browser when I set bbox parameters in both Tilecache.cfg and Openlayers but when I don't specify the bbox everything works fine and I can see actual map tiles.</p>
<p>I was wondering if anyone can point out the problem in the code. I think I hav... | 1 | 2009-11-23T13:18:11Z | 1,806,817 | <p>The OpenLayers.Bounds constructor parameters are in the order left, bottom, right top. Taking the bounds that you're using change your JavaScript to be:</p>
<pre><code> var options = {
numZoomLevels:20,
maxResolution: 360/512,
projection: "EPSG:4326",
... | 3 | 2009-11-27T04:54:51Z | [
"python",
"maps",
"openlayers",
"proj4js",
"tilecache"
] |
Where in a virtualenv does *my* code go? | 1,783,146 | <p>What sort of directory structure should one follow when using <code>virtualenv</code>? For instance, if I were building a WSGI application and created a virtualenv called <code>foobar</code> I would start with a directory structure like:</p>
<pre><code>/foobar
/bin
{activate, activate.py, easy_install, python... | 64 | 2009-11-23T13:31:01Z | 1,783,482 | <p>If you only have a few projects every so often, nothing stops you from creating a new virtualenv for each one, and putting your packages right inside:</p>
<pre><code>/foobar
/bin
{activate, activate.py, easy_install, python}
/include
{python2.6/...}
/lib
{python2.6/...}
/mypackage1
__init__.... | 38 | 2009-11-23T14:33:35Z | [
"python",
"project",
"virtualenv"
] |
Where in a virtualenv does *my* code go? | 1,783,146 | <p>What sort of directory structure should one follow when using <code>virtualenv</code>? For instance, if I were building a WSGI application and created a virtualenv called <code>foobar</code> I would start with a directory structure like:</p>
<pre><code>/foobar
/bin
{activate, activate.py, easy_install, python... | 64 | 2009-11-23T13:31:01Z | 1,784,135 | <p>If you give your project a <code>setup.py</code>, pip can import it from version control directly. </p>
<p>Do something like this:</p>
<pre><code>$ virtualenv --no-site-packages myproject
$ . myproject/bin/activate
$ easy_install pip
$ pip install -e hg+http://bitbucket.org/owner/myproject#egg=proj
</code></pre>
... | 2 | 2009-11-23T16:07:43Z | [
"python",
"project",
"virtualenv"
] |
Where in a virtualenv does *my* code go? | 1,783,146 | <p>What sort of directory structure should one follow when using <code>virtualenv</code>? For instance, if I were building a WSGI application and created a virtualenv called <code>foobar</code> I would start with a directory structure like:</p>
<pre><code>/foobar
/bin
{activate, activate.py, easy_install, python... | 64 | 2009-11-23T13:31:01Z | 1,785,127 | <p><code>virtualenv</code> provides a python interpreter instance, not an application instance. You wouldn't normally create your application files within the directories containing a system's default python, likewise there's no requirement to locate your application within a virtualenv directory. For example, you mi... | 51 | 2009-11-23T18:44:16Z | [
"python",
"project",
"virtualenv"
] |
Where in a virtualenv does *my* code go? | 1,783,146 | <p>What sort of directory structure should one follow when using <code>virtualenv</code>? For instance, if I were building a WSGI application and created a virtualenv called <code>foobar</code> I would start with a directory structure like:</p>
<pre><code>/foobar
/bin
{activate, activate.py, easy_install, python... | 64 | 2009-11-23T13:31:01Z | 1,785,770 | <p>Because virtualenvs are not relocatable, in my opinion it is bad practice to place your project files inside a virtualenv directory. The virtualenv itself is a generated development/deployment artifact (sort of like a .pyc file), not part of the project; it should be easy to blow it away and recreate it anytime, or ... | 17 | 2009-11-23T20:35:28Z | [
"python",
"project",
"virtualenv"
] |
Growing matrices columnwise in NumPy | 1,783,251 | <p>In pure Python you can grow matrices column by column pretty easily:</p>
<pre><code>data = []
for i in something:
newColumn = getColumnDataAsList(i)
data.append(newColumn)
</code></pre>
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a>'s array doesn't have the append function. The <code>hstack</cod... | 15 | 2009-11-23T13:54:00Z | 1,783,277 | <p>Generally it is expensive to keep reallocating the NumPy array - so your third solution is really the best performance wise. </p>
<p>However I think <code>hstack</code> will do what you want - the cue is in the error message, </p>
<blockquote>
<h1>ValueError: arrays must have same number of dimensions`</h1>
</bl... | 1 | 2009-11-23T14:00:03Z | [
"python",
"arrays",
"numpy"
] |
Growing matrices columnwise in NumPy | 1,783,251 | <p>In pure Python you can grow matrices column by column pretty easily:</p>
<pre><code>data = []
for i in something:
newColumn = getColumnDataAsList(i)
data.append(newColumn)
</code></pre>
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a>'s array doesn't have the append function. The <code>hstack</cod... | 15 | 2009-11-23T13:54:00Z | 1,784,129 | <p>Usually you don't keep resizing a NumPy array when you create it. What don't you like about your third solution? If it's a very large matrix/array, then it might be worth allocating the array before you start assigning its values:</p>
<pre><code>x = len(something)
y = getColumnDataAsNumpyArray.someLengthProperty
... | 4 | 2009-11-23T16:07:23Z | [
"python",
"arrays",
"numpy"
] |
Growing matrices columnwise in NumPy | 1,783,251 | <p>In pure Python you can grow matrices column by column pretty easily:</p>
<pre><code>data = []
for i in something:
newColumn = getColumnDataAsList(i)
data.append(newColumn)
</code></pre>
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a>'s array doesn't have the append function. The <code>hstack</cod... | 15 | 2009-11-23T13:54:00Z | 1,790,187 | <p>NumPy actually does have an <em>append</em> function, which it seems might do what you want, e.g.,</p>
<pre><code>import numpy as NP
my_data = NP.random.random_integers(0, 9, 9).reshape(3, 3)
new_col = NP.array((5, 5, 5)).reshape(3, 1)
res = NP.append(my_data, new_col, axis=1)
</code></pre>
<p>your second snippet ... | 18 | 2009-11-24T13:50:48Z | [
"python",
"arrays",
"numpy"
] |
Growing matrices columnwise in NumPy | 1,783,251 | <p>In pure Python you can grow matrices column by column pretty easily:</p>
<pre><code>data = []
for i in something:
newColumn = getColumnDataAsList(i)
data.append(newColumn)
</code></pre>
<p><a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a>'s array doesn't have the append function. The <code>hstack</cod... | 15 | 2009-11-23T13:54:00Z | 9,043,975 | <p>The hstack can work on zero sized arrays:</p>
<pre><code>import numpy as np
N = 5
M = 15
a = np.ndarray(shape = (N, 0))
for i in range(M):
b = np.random.rand(N, 1)
a = np.hstack((a, b))
</code></pre>
| 3 | 2012-01-28T08:40:42Z | [
"python",
"arrays",
"numpy"
] |
String preallocation in numpy.arrays | 1,783,369 | <pre><code>>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'])
>>> a[1] = 'thirteen'
>>> print a
['zero' 'thirt' 'two' 'three']
>>>
</code></pre>
<p>As you can see, the second element has been truncated to the maximum number of characters in the origina... | 2 | 2009-11-23T14:16:14Z | 1,783,602 | <p>Use the <code>dtype</code> argument in <code>numpy.array</code>, e.g.:</p>
<pre><code>>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'], dtype='S8')
>>> a[1] = 'thirteen'
>>> print(a)
['zero' 'thirteen' 'two' 'three']
</code></pre>
| 2 | 2009-11-23T14:52:51Z | [
"python",
"numpy"
] |
String preallocation in numpy.arrays | 1,783,369 | <pre><code>>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'])
>>> a[1] = 'thirteen'
>>> print a
['zero' 'thirt' 'two' 'three']
>>>
</code></pre>
<p>As you can see, the second element has been truncated to the maximum number of characters in the origina... | 2 | 2009-11-23T14:16:14Z | 1,783,979 | <p>If you don't know the maximum length element, then you can use dtype=object</p>
<pre><code>>>> import numpy as np
>>> a = np.array(['zero', 'one', 'two', 'three'], dtype=object)
>>> a[1] = 'thirteen'
>>> print a
['zero' 'thirteen' 'two' 'three']
>>>
</code></pre>
| 5 | 2009-11-23T15:45:39Z | [
"python",
"numpy"
] |
How do I copy wsgi.input if I want to process POST data more than once? | 1,783,383 | <p>In WSGI, post data is consumed by reading the file-like object <code>environ['wsgi.input']</code>. If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read.</p>
<p>How should I copy the POST data so it can be processed multiple times?</p>
| 7 | 2009-11-23T14:18:41Z | 1,783,464 | <p>If you're gonna read it in one fell swoop, you could always read it in, create a CStringIO file-like object of the stuff you've read and then assign it back, like this:</p>
<pre><code>import cStringIO
import copy
lines = []
for line in environ['wsgi.input']:
lines.append(line)
newlines = copy.copy(lines)
enviro... | 1 | 2009-11-23T14:31:32Z | [
"python",
"wsgi"
] |
How do I copy wsgi.input if I want to process POST data more than once? | 1,783,383 | <p>In WSGI, post data is consumed by reading the file-like object <code>environ['wsgi.input']</code>. If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read.</p>
<p>How should I copy the POST data so it can be processed multiple times?</p>
| 7 | 2009-11-23T14:18:41Z | 1,783,469 | <p>You could try putting a file-like replica of the stream back in the environment:</p>
<pre><code>from cStringIO import StringIO
length = int(environ.get('CONTENT_LENGTH', '0'))
body = StringIO(environ['wsgi.input'].read(length))
environ['wsgi.input'] = body
</code></pre>
<p>Needing to do this is a bit of a smell, ... | 10 | 2009-11-23T14:32:05Z | [
"python",
"wsgi"
] |
How do I copy wsgi.input if I want to process POST data more than once? | 1,783,383 | <p>In WSGI, post data is consumed by reading the file-like object <code>environ['wsgi.input']</code>. If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read.</p>
<p>How should I copy the POST data so it can be processed multiple times?</p>
| 7 | 2009-11-23T14:18:41Z | 1,786,453 | <p>Go have a look at <a href="http://pythonpaste.org/webob/">WebOb</a> package. It provides functionality that allows one to designate that wsgi.input should be made seekable. This has the effect of allowing you to rewind the input stream such that content can be replayed through different handler. Even if you don't us... | 7 | 2009-11-23T22:18:43Z | [
"python",
"wsgi"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,783,473 | <p>With disk space at the current price, size shouldn't matter. Give both a try and figure out which will be easier for you to learn and maintain. Despite the fact that people believe that when you know one language, you know all, that's only true as long as you write code on the "hello world" level.</p>
| 3 | 2009-11-23T14:32:33Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,783,478 | <p>I personally prefer Python/django. Size is small given u have necessary things installed. </p>
| 4 | 2009-11-23T14:33:22Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,783,693 | <p>If you are experienced with Java and concerned about deploying Django and Rails apps, I'd recommend you give <a href="http://jruby.org/" rel="nofollow">JRuby</a> a try. This will give you several benefits from a Java-perpective:</p>
<ol>
<li>You can call Java-classes and components from your Ruby/Rails app</li>
<li... | 0 | 2009-11-23T15:07:38Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,783,732 | <p>One option with Ruby on Rails is to go with a JRuby deployment which would allow you to pack it all into a single .war file. This would require the person deploying the web application to have a java web application server (Jetty is probably the smallest and easiest to bundle).</p>
<p>With Rails, you are generally ... | 1 | 2009-11-23T15:12:58Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,784,061 | <p>With the cheeseshop, any python application can be made installable with a single command. I'm a big fan of Django, but it will require you to hook into an external webserver, as the built in server is for development only. You might look for something that has a more robust builtin web server if you want somethin... | 0 | 2009-11-23T15:57:30Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,785,692 | <p>I just used <a href="http://heroku.com" rel="nofollow">heroku</a> to deploy a blog written in Rails, and it was a fantastically easy experience. If you're interested in simplicity, it's probably the most simple deploy I've ever experienced.</p>
| 1 | 2009-11-23T20:21:41Z | [
"python",
"ruby-on-rails",
"django"
] |
Python Vs Ruby On Rails : on Size | 1,783,431 | <p>I am planning to do a small web application that will be distributed as a single installable. I have plans to develop this application in either Python/Django or Ruby On Rails. (I am a Java/C++ programmer, hence both these languages are new to me). </p>
<p>My main concern is about the size and simplicity of final i... | 3 | 2009-11-23T14:26:31Z | 1,786,648 | <p>I don't think you can get them both. I'm sorry to say this but you have to choose which one is more important to you. </p>
<ul>
<li>Django application is smaller in size because many things is already provided out of the box, but deployment is not as easy.</li>
<li>On the other hand, RoR apps deployment is easier (... | 1 | 2009-11-23T22:56:50Z | [
"python",
"ruby-on-rails",
"django"
] |
Possible to use Mathematica from other programming languages (python/C#)? | 1,783,564 | <p>Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program.</p>
<p>Is it possible?</p>
| 5 | 2009-11-23T14:45:33Z | 1,783,595 | <p>I haven't used it, but <a href="http://www.wolfram.com/solutions/mathlink/netlink/" rel="nofollow">this looks interesting</a>. Looks like you can call Mathematica code directly from your C# app using .NET/Link (a product by Wolfram).</p>
| 1 | 2009-11-23T14:52:03Z | [
"c#",
"python",
"wolfram-mathematica",
"mathlink"
] |
Possible to use Mathematica from other programming languages (python/C#)? | 1,783,564 | <p>Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program.</p>
<p>Is it possible?</p>
| 5 | 2009-11-23T14:45:33Z | 1,783,601 | <p>Looks like there is a MathLink API you can use from C#, c or Java, have you checked this out?</p>
<p><a href="http://reference.wolfram.com/mathematica/guide/MathLinkAPI.html" rel="nofollow">http://reference.wolfram.com/mathematica/guide/MathLinkAPI.html</a></p>
| 5 | 2009-11-23T14:52:36Z | [
"c#",
"python",
"wolfram-mathematica",
"mathlink"
] |
Possible to use Mathematica from other programming languages (python/C#)? | 1,783,564 | <p>Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program.</p>
<p>Is it possible?</p>
| 5 | 2009-11-23T14:45:33Z | 1,783,604 | <p>To links about usage of <a href="http://library.wolfram.com/infocenter/MathSource/585/" rel="nofollow">python</a> and <a href="http://reference.wolfram.com/mathematica/NETLink/tutorial/CallingMathematicaFromNET.html" rel="nofollow">.Net (for C#)</a></p>
| 4 | 2009-11-23T14:53:02Z | [
"c#",
"python",
"wolfram-mathematica",
"mathlink"
] |
Possible to use Mathematica from other programming languages (python/C#)? | 1,783,564 | <p>Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program.</p>
<p>Is it possible?</p>
| 5 | 2009-11-23T14:45:33Z | 1,788,415 | <p>Perhaps the easiest way is to make the Mathematica program its own self-contained script and just call it as a system call or pipe stuff to/from it via stdin/stdout. Here's how to do that:</p>
<p><a href="http://stackoverflow.com/questions/148057/calling-a-mathematica-program">http://stackoverflow.com/questions/14... | 4 | 2009-11-24T07:21:48Z | [
"c#",
"python",
"wolfram-mathematica",
"mathlink"
] |
Possible to use Mathematica from other programming languages (python/C#)? | 1,783,564 | <p>Is it possible to use Mathematica's computing capabilities from other languages? I need to do some complex operations (not necessarily symbolic, btw), and it'd be pretty sweet to be able to just call Mathematica's functions or running Mathematica's code right from my python/c#'s program.</p>
<p>Is it possible?</p>
| 5 | 2009-11-23T14:45:33Z | 2,261,790 | <p>Yes but there are some subtleties. I covered Mathematica .NET interoperability in my book <a href="http://www.ffconsultancy.com/products/fsharp_for_scientists/" rel="nofollow">F# for Scientists</a> but dropped the subject for its successor <a href="http://www.ffconsultancy.com/products/fsharp_for_technical_computing... | 1 | 2010-02-14T16:32:28Z | [
"c#",
"python",
"wolfram-mathematica",
"mathlink"
] |
Any python Support Vector Machine library around that allows online learning? | 1,783,669 | <p>I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once).</p>
<p>Are there any?</p>
| 10 | 2009-11-23T15:03:29Z | 1,784,156 | <p><a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/">LibSVM</a> includes a python wrapper that works via SWIG.</p>
<p>Example svm-test.py from their distribution:</p>
<pre><code>#!/usr/bin/env python
from svm import *
# a three-class problem
labels = [0, 1, 1, 2]
samples = [[0, 0], [0, 1], [1, 0], [1, 1]]
problem... | 8 | 2009-11-23T16:09:44Z | [
"python",
"artificial-intelligence",
"machine-learning",
"svm"
] |
Any python Support Vector Machine library around that allows online learning? | 1,783,669 | <p>I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once).</p>
<p>Are there any?</p>
| 10 | 2009-11-23T15:03:29Z | 1,784,199 | <p>Haven't heard of one. But do you really need online learning? I'm using SVMs for quite some time and never encountered a problem where i had to use online learning. Usually i set a threshold on the number of changes of training examples (maybe 100 or 1000) and then just batch-retrain all.</p>
<p>If your problem is ... | 4 | 2009-11-23T16:17:21Z | [
"python",
"artificial-intelligence",
"machine-learning",
"svm"
] |
Any python Support Vector Machine library around that allows online learning? | 1,783,669 | <p>I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once).</p>
<p>Are there any?</p>
| 10 | 2009-11-23T15:03:29Z | 1,816,714 | <p>Why would you want to train it online? Adding trainings instances would usually require to re-solve the quadratic programming problem associated with the SVM.</p>
<p>A way to handle this is to train a SVM in batch mode, and when new data is available, check if these data points are in the [-1, +1] margin of the hyp... | 0 | 2009-11-29T20:45:17Z | [
"python",
"artificial-intelligence",
"machine-learning",
"svm"
] |
Any python Support Vector Machine library around that allows online learning? | 1,783,669 | <p>I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once).</p>
<p>Are there any?</p>
| 10 | 2009-11-23T15:03:29Z | 4,615,636 | <p>While there are no python bindings there, the algorithm described at
<a href="http://leon.bottou.org/projects/sgd" rel="nofollow">http://leon.bottou.org/projects/sgd</a> is trained in an online fashion and is easily reimplemented using e.g. numpy.</p>
| 1 | 2011-01-06T13:57:47Z | [
"python",
"artificial-intelligence",
"machine-learning",
"svm"
] |
Any python Support Vector Machine library around that allows online learning? | 1,783,669 | <p>I do know there are some libraries that allow to use Support vector Machines from python code, but I am looking specifically for libraries that allow one to teach it online (this is, without having to give it all the data at once).</p>
<p>Are there any?</p>
| 10 | 2009-11-23T15:03:29Z | 10,645,842 | <p><a href="http://eprints.pascal-network.org/archive/00004062/01/ShalevSiSr07.pdf" rel="nofollow">Pegasos</a> is an online SVM algorithm that performs quite nicely. It's also fairly easy to implement, even without a specific Python binding. There is a <a href="http://www.cs.huji.ac.il/~shais/code/index.html" rel="no... | 1 | 2012-05-18T02:05:53Z | [
"python",
"artificial-intelligence",
"machine-learning",
"svm"
] |
What is the most efficent way to implement concurrency in Python? | 1,783,714 | <p>In a cluster environment using Python what is the least expensive way to develop a concurrent application or what is the pro / con of the various options?</p>
| 0 | 2009-11-23T15:10:29Z | 1,783,750 | <p>I would say Google app engine is the easiest option since you don't have to worry about all this things. But if it's a big project, it might not be the cheapest solution. </p>
<p>Again, it really depends on the size of your project and what you really want to do.</p>
<p>You need to give more details if you want to... | 1 | 2009-11-23T15:15:39Z | [
"python",
"concurrency",
"multithreading",
"process"
] |
Python - Most useful lists-comprehension construction | 1,783,974 | <p>What Python's user-made list-comprehension construction is the most useful? </p>
<p>I have created the following two quantifiers, which I use to do different verification operations:</p>
<pre><code>def every(f, L): return not (False in [f(x) for x in L])
def some(f, L): return True in [f(x) for x in L]
</code></pr... | -1 | 2009-11-23T15:44:23Z | 1,783,995 | <p><code>any</code>and <code>all</code> are part of standard Python from 2.5. There's no need to make your own versions of these. Also the official version of <code>any</code> and <code>all</code> short-circuit the evaluation if possible, giving a performance improvement. Your versions always iterate over the entire li... | 13 | 2009-11-23T15:48:23Z | [
"python",
"list",
"list-comprehension"
] |
Python - Most useful lists-comprehension construction | 1,783,974 | <p>What Python's user-made list-comprehension construction is the most useful? </p>
<p>I have created the following two quantifiers, which I use to do different verification operations:</p>
<pre><code>def every(f, L): return not (False in [f(x) for x in L])
def some(f, L): return True in [f(x) for x in L]
</code></pr... | -1 | 2009-11-23T15:44:23Z | 1,784,123 | <p>This solution shadows builtins which is generally a <strong>bad</strong> idea. However the usage feels fairly pythonic, and it preserves the original functionality. </p>
<p>Note there are several ways to potentially optimize this based on testing, including, moving the imports out into the module level and changin... | 4 | 2009-11-23T16:06:35Z | [
"python",
"list",
"list-comprehension"
] |
Python - Most useful lists-comprehension construction | 1,783,974 | <p>What Python's user-made list-comprehension construction is the most useful? </p>
<p>I have created the following two quantifiers, which I use to do different verification operations:</p>
<pre><code>def every(f, L): return not (False in [f(x) for x in L])
def some(f, L): return True in [f(x) for x in L]
</code></pr... | -1 | 2009-11-23T15:44:23Z | 1,784,346 | <p>There aren't all that many cases where a list comprehension (LC for short) will be substantially more useful than the equivalent generator expression (GE for short, i.e., using round parentheses instead of square brackets, to generate one item at a time rather than "all in bulk at the start").</p>
<p>Sometimes you ... | 5 | 2009-11-23T16:38:34Z | [
"python",
"list",
"list-comprehension"
] |
Python - Most useful lists-comprehension construction | 1,783,974 | <p>What Python's user-made list-comprehension construction is the most useful? </p>
<p>I have created the following two quantifiers, which I use to do different verification operations:</p>
<pre><code>def every(f, L): return not (False in [f(x) for x in L])
def some(f, L): return True in [f(x) for x in L]
</code></pr... | -1 | 2009-11-23T15:44:23Z | 1,784,402 | <p>for your information, the documentation for module <code>itertools</code> in python 3.x list some pretty nice generator functions.</p>
| 2 | 2009-11-23T16:44:59Z | [
"python",
"list",
"list-comprehension"
] |
Python - Strip all drive letters from csv file and replace with Z: | 1,783,994 | <p>Here is the code example. Basically output.csv needs to remove any drive letter A:-Y: and replace it with Z: I tried to do this with a list (not complete yet) but it generates the error: <em>TypeError: expected a character buffer object</em></p>
<pre><code>#!/usr/bin/python
import os.path
import os
import shutil
im... | 1 | 2009-11-23T15:48:07Z | 1,784,032 | <p>It seems like the problem is in the loop at the bottom of your code. The string's <code>replace</code> method doesn't receive a list as its first arguments, but another string. You need to loop through your <code>removeDrives</code> list and call <code>line.remove</code> with every item in that list.</p>
| 1 | 2009-11-23T15:53:58Z | [
"python"
] |
Python - Strip all drive letters from csv file and replace with Z: | 1,783,994 | <p>Here is the code example. Basically output.csv needs to remove any drive letter A:-Y: and replace it with Z: I tried to do this with a list (not complete yet) but it generates the error: <em>TypeError: expected a character buffer object</em></p>
<pre><code>#!/usr/bin/python
import os.path
import os
import shutil
im... | 1 | 2009-11-23T15:48:07Z | 1,784,038 | <p>You could use</p>
<pre><code>for driveletter in removedrives:
line = line.replace(driveletter, 'Z:')
</code></pre>
<p>thereby iterating over your list and replacing one of the possible drive letters after the other. As abyx wrote, <code>replace</code> expects a string, not a list, so you need this extra step. ... | 0 | 2009-11-23T15:54:51Z | [
"python"
] |
Python - Strip all drive letters from csv file and replace with Z: | 1,783,994 | <p>Here is the code example. Basically output.csv needs to remove any drive letter A:-Y: and replace it with Z: I tried to do this with a list (not complete yet) but it generates the error: <em>TypeError: expected a character buffer object</em></p>
<pre><code>#!/usr/bin/python
import os.path
import os
import shutil
im... | 1 | 2009-11-23T15:48:07Z | 1,784,420 | <p>I can see you use some pythonic snippets, with smart uses of path.join and a commented code. This can get even better, let's rewrite a few things so we can solve your drive letters issue, and gain a more pythonic code on the way :</p>
<pre><code>#!/usr/bin/env python
# -*- coding= UTF-8 -*-
# Firstly, modules can ... | 1 | 2009-11-23T16:47:33Z | [
"python"
] |
import from {in,out}side of a packages | 1,783,996 | <p>I have a project I build on a library I'm building in parallel. The structure is the following :</p>
<pre><code>project/
main.py
MyLibrary/
__init__.py --> empty
Module1.py --> contain the class Class1
Module2.py --> contain the class Class2
Module3.py --> contain the class Cla... | 0 | 2009-11-23T15:48:28Z | 1,827,408 | <p>The behavior you're experiencing (where imports work normally on one machine and not another) often happens because you've got multiple packages named MyLibrary on one system and your PYTHONPATH doesn't list '.' first.</p>
<p>To test if this is the problem, in the project directory, run Python and do</p>
<pre><cod... | 1 | 2009-12-01T16:41:56Z | [
"python",
"import"
] |
wxPython. Create a panel with four static sized boxes | 1,784,026 | <p>I'm trying to create a panel, with four boxes containing some data. These four boxes should have a predefined static size. What I have so far is four boxes that is overlapping to some extent. </p>
<p>Any ideas?</p>
<p>Code:</p>
<pre><code>import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
... | 1 | 2009-11-23T15:53:21Z | 1,784,781 | <p>I'll just answer my own question.</p>
<p>The solution is to add a wx.Sizer.SetMinSize() to each wx.StaticBoxSizer() like this.</p>
<pre><code>sb = wx.StaticBox(self.pl, -1, 'BOX0')
sat = wx.CheckBox(self.pl, -1, 'Satellite')
gsm = wx.CheckBox(self.pl, -1, 'GSM')
wlan = wx.CheckBox(self.pl, -1, 'WLAN')
box = wx.St... | 1 | 2009-11-23T17:44:50Z | [
"python",
"wxpython"
] |
How do I unit test Django views on the Google App Engine? | 1,784,076 | <p>I am struggling to run unit tests using the Django <em>Client</em> class on the Google App Engine. I downloaded GAEUnit (v2.0a for Django) and I am trying to use that as my testing framework (maybe I should rather be using something else?)</p>
<p>I copy all the GAEUnit files into my project root as instructed, and ... | 2 | 2009-11-23T15:59:07Z | 1,784,146 | <p>I managed to figure out what was wrong here. I made two mistakes:</p>
<ol>
<li>In <em>app.yaml</em>, url: /test.* had to be <strong>before</strong> url:/.* (otherwise the /test URL would be matched to /.* before getting to the /test.* handler)</li>
<li><strong>Beware</strong> of copying all the files from the GAE... | 0 | 2009-11-23T16:08:37Z | [
"python",
"django",
"google-app-engine"
] |
Function not being called in Python, why? and how can I solve it? | 1,784,197 | <p>I am currently working on python/django site, at the moment I have a template that looks like this</p>
<pre><code> {% extends "shopbase.html" %}
{% block pageid %}products{% endblock %}
{% block right-content %}
<img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/... | 0 | 2009-11-23T16:16:47Z | 1,784,268 | <p>Your template has <code>{{download.mini.thumbnail}}</code> instead of <code>{{download.mini_thumbnail}}</code></p>
| 2 | 2009-11-23T16:27:58Z | [
"python",
"django",
"python-imaging-library"
] |
Function not being called in Python, why? and how can I solve it? | 1,784,197 | <p>I am currently working on python/django site, at the moment I have a template that looks like this</p>
<pre><code> {% extends "shopbase.html" %}
{% block pageid %}products{% endblock %}
{% block right-content %}
<img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/... | 0 | 2009-11-23T16:16:47Z | 1,785,242 | <p>As with many things in Django... someone has already solved this problem and come up with a clean, flexible solution for generating/storing thumbnails of different sizes etc. I'd strongly suggest looking at the sorl-thumbnail project.</p>
<p>Docs here: <a href="http://thumbnail.sorl.net/docs/" rel="nofollow">http:/... | 5 | 2009-11-23T18:59:06Z | [
"python",
"django",
"python-imaging-library"
] |
Create a new Tuple with one element modified | 1,784,478 | <p>(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations)</p>
<p>I am trying to scrape out some tables from a number of Word documents. For each table,
I have an iterator t... | 3 | 2009-11-23T16:56:01Z | 1,784,549 | <p>If every tuple contains 4 elements, then, frankly, I think you'd be better off assigning them to individual variables, manipulating those, and then building your tuple:</p>
<pre><code>for row in rows:
t1, t2, t3, t4 = tuple([c.InnerText for c in row.Descendants[TableCell]()])
t1 = ...
t = (t1, t2, t3, t... | 1 | 2009-11-23T17:06:39Z | [
"python",
"iterator",
"ironpython",
"generator"
] |
Create a new Tuple with one element modified | 1,784,478 | <p>(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations)</p>
<p>I am trying to scrape out some tables from a number of Word documents. For each table,
I have an iterator t... | 3 | 2009-11-23T16:56:01Z | 1,784,592 | <pre><code>def item(i, v):
if i != 1: return v
return strangestuff(v)
for row in rows:
t = tuple(item(i, c.InnerText)
for i, c in enumerate(row.Descendants[TableCell]())
)
</code></pre>
| 6 | 2009-11-23T17:12:21Z | [
"python",
"iterator",
"ironpython",
"generator"
] |
Create a new Tuple with one element modified | 1,784,478 | <p>(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations)</p>
<p>I am trying to scrape out some tables from a number of Word documents. For each table,
I have an iterator t... | 3 | 2009-11-23T16:56:01Z | 1,784,849 | <p>I would do this:</p>
<pre><code>temp_list = [c.InnerText for c in row.Descendants[TableCell]()]
temp_list[2] = "Something different"
t = tuple(temp_list)
</code></pre>
<p>It would work like this:</p>
<pre><code>>>> temp_list = [i for i in range(4)]
>>> temp_list[2] = "Something different"
>&g... | 2 | 2009-11-23T17:55:22Z | [
"python",
"iterator",
"ironpython",
"generator"
] |
Create a new Tuple with one element modified | 1,784,478 | <p>(I am working interactively with a WordprocessingDocument object in IronPython using the OpenXML SDK, but this is really a general Python question that should be applicable across all implementations)</p>
<p>I am trying to scrape out some tables from a number of Word documents. For each table,
I have an iterator t... | 3 | 2009-11-23T16:56:01Z | 2,022,755 | <p>What i've generally done, but am not a fan of:</p>
<p>l = list(oldtuple)
l[2] = foo
t = tuple(l)</p>
<p>I kind of want something like update() for dicts </p>
<p>newtuple = update(oldtuple, (None, None, val, None))</p>
<p>Or perhaps the right structure is a zip</p>
<p>newtuple = update(oldtuple, ((2, val), (3, v... | 0 | 2010-01-07T18:45:59Z | [
"python",
"iterator",
"ironpython",
"generator"
] |
Python 3 - pull down a file object from a web server over a proxy (no-auth) | 1,784,483 | <p>I have a very simple problem and I am absolutely amazed that I haven't seen anything on this specifically. I am attempting to follow best practices for copying a file that is hosted on a webserver going through a proxy server (which does not require auth) using python3.</p>
<p>i have done similar things using pyth... | -1 | 2009-11-23T16:56:44Z | 1,785,566 | <p>here is an function to retrieve a file through an http proxy:</p>
<pre><code>import urllib.request
def retrieve( url, filename ):
proxy = urllib.request.ProxyHandler( {'http': '127.0.0.1'} )
opener = urllib.request.build_opener( proxy )
remote = opener.open( url )
local = open( filename, 'wb' )
... | 1 | 2009-11-23T19:59:32Z | [
"python",
"http",
"proxy",
"tunnel"
] |
Designing a multi-process spider in Python | 1,784,632 | <p>I'm working on a multi-process spider in Python. It should start scraping one page for links and work from there. Specifically, the top-level page contains a list of categories, the second-level pages events in those categories, and the final, third-level pages participants in the events. I can't predict how many ca... | 3 | 2009-11-23T17:20:13Z | 1,784,649 | <p>I presume you are putting items to visit in a <a href="http://docs.python.org/library/queue.html" rel="nofollow">queue</a>, exhausting the queue with workers, and the workers find new items to visit and add them to the queue. </p>
<p>It's finished when all the workers are idle, and the queue of items to visit is em... | 1 | 2009-11-23T17:22:53Z | [
"python",
"multithreading",
"design",
"web-crawler"
] |
Designing a multi-process spider in Python | 1,784,632 | <p>I'm working on a multi-process spider in Python. It should start scraping one page for links and work from there. Specifically, the top-level page contains a list of categories, the second-level pages events in those categories, and the final, third-level pages participants in the events. I can't predict how many ca... | 3 | 2009-11-23T17:20:13Z | 1,784,889 | <p>You might want to look into <a href="http://scrapy.org/" rel="nofollow">Scrapy</a>, an asynchronous (based on <a href="http://twistedmatrix.com/trac/" rel="nofollow">Twisted</a>) web-scraper. It looks like for your task, the XPath description for the spider would be pretty easy to define! </p>
<p>Good luck!</p>
... | 2 | 2009-11-23T18:01:00Z | [
"python",
"multithreading",
"design",
"web-crawler"
] |
How get hours:minutes | 1,784,952 | <p>I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in <strong>minutes:seconds</strong></p>
<p>I want to have that in <strong>hours:minutes</strong></p>
<p>What changes do I have to make?</p>
<p>This is the peace of script concerned:</p>
<pre><code>i... | 1 | 2009-11-23T18:11:07Z | 1,784,984 | <pre><code>hours = secs / 3600
minutes = secs / 60 - hours * 60
len = "%d:%02d" % (hours, minutes)
</code></pre>
<p>Or, for more recent versions of Python:</p>
<pre><code>hours = secs // 3600
minutes = secs // 60 - hours * 60
len = "%d:%02d" % (hours, minutes)
</code></pre>
| 7 | 2009-11-23T18:15:56Z | [
"python",
"time",
"formatting"
] |
How get hours:minutes | 1,784,952 | <p>I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in <strong>minutes:seconds</strong></p>
<p>I want to have that in <strong>hours:minutes</strong></p>
<p>What changes do I have to make?</p>
<p>This is the peace of script concerned:</p>
<pre><code>i... | 1 | 2009-11-23T18:11:07Z | 1,785,761 | <p>So len the number of seconds in the movie? That's a bad name. Python already uses the word len for something else. Change it. </p>
<pre><code>def display_movie_length(seconds):
# the // ensures you are using integer division
# You can also use / in python 2.x
hours = seconds // 3600
# You ne... | 0 | 2009-11-23T20:34:36Z | [
"python",
"time",
"formatting"
] |
How get hours:minutes | 1,784,952 | <p>I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in <strong>minutes:seconds</strong></p>
<p>I want to have that in <strong>hours:minutes</strong></p>
<p>What changes do I have to make?</p>
<p>This is the peace of script concerned:</p>
<pre><code>i... | 1 | 2009-11-23T18:11:07Z | 25,422,864 | <p>There is a nice answer to this here <a href="http://stackoverflow.com/a/20291909/202168">http://stackoverflow.com/a/20291909/202168</a> (a later duplicate of this question)</p>
<p>However if you are dealing with timezone offsets in a datetime string then you need to also handle negative hours, in which case the zer... | 0 | 2014-08-21T09:30:57Z | [
"python",
"time",
"formatting"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.