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
Python asynchronous callbacks and generators
1,805,958
<p>I'm trying to convert a synchronous library to use an internal asynchronous IO framework. I have several methods that look like this:</p> <pre><code>def foo: .... sync_call_1() # synchronous blocking call .... sync_call_2() # synchronous blocking call .... return bar </code></pre> <p>For each of th...
10
2009-11-26T22:32:10Z
1,807,674
<p>There are several way for multiplexing tasks. We can't say what is the best for your case without deeper knowledge on what you are doing. Probably the most easiest/universal way is to use threads. Take a look at <a href="http://stackoverflow.com/questions/1696152/easy-python-async-precompiler">this question</a> for ...
2
2009-11-27T09:33:23Z
[ "python", "asynchronous", "generator" ]
Python asynchronous callbacks and generators
1,805,958
<p>I'm trying to convert a synchronous library to use an internal asynchronous IO framework. I have several methods that look like this:</p> <pre><code>def foo: .... sync_call_1() # synchronous blocking call .... sync_call_2() # synchronous blocking call .... return bar </code></pre> <p>For each of th...
10
2009-11-26T22:32:10Z
1,985,400
<p><strong>UPDATE</strong>: take this with a grain of salt, as I'm out of touch with modern python async developments, including <a href="http://www.gevent.org/" rel="nofollow">gevent</a> and <a href="https://www.python.org/dev/peps/pep-3156/" rel="nofollow">asyncio</a> and don't actually have serious experience with a...
10
2009-12-31T13:27:09Z
[ "python", "asynchronous", "generator" ]
Python asynchronous callbacks and generators
1,805,958
<p>I'm trying to convert a synchronous library to use an internal asynchronous IO framework. I have several methods that look like this:</p> <pre><code>def foo: .... sync_call_1() # synchronous blocking call .... sync_call_2() # synchronous blocking call .... return bar </code></pre> <p>For each of th...
10
2009-11-26T22:32:10Z
1,985,597
<p>You need to make function <code>foo</code> also async. How about this approach?</p> <pre><code>@make_async def foo(somearg, callback): # This function is now async. Expect a callback argument. ... # change # x = sync_call1(somearg, some_other_arg) # to the following: x = yield async_...
2
2009-12-31T14:22:06Z
[ "python", "asynchronous", "generator" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,805,998
<p>Take a look at <a href="http://en.wikipedia.org/wiki/Hamming%5Fdistance" rel="nofollow">Hamming Distance</a></p>
2
2009-11-26T22:44:21Z
[ "python", "list", "text", "vector" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,806,010
<p>You could use the <a href="http://www.sgi.com/tech/stl/set%5Fintersection.html" rel="nofollow">set_intersection</a> algorithm. The 2 vectors must be sorted first (use sort call), then pass in 4 iterators and you'll get a collection back with the common elements inserted into it. There are a few others that operate s...
-1
2009-11-26T22:48:09Z
[ "python", "list", "text", "vector" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,806,012
<p>I would suggest you a book called <a href="http://oreilly.com/catalog/9780596529321" rel="nofollow">Programming Collective Intelligence</a>.<br/> It's a very nice book on how you can retrieve information from simple data like this one. There are code examples included (in Python :)</p> <p><strong>Edit:</strong> Jus...
3
2009-11-26T22:48:30Z
[ "python", "list", "text", "vector" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,806,034
<p>As mbg mentioned, the hamming distance is a good start. It's basically assigning a bitmask for every possible item whether it is contained in the companies value. </p> <p>Eg. toothpaste is 1 for company A, but 0 for company B. You then count the bits which differ between the companies. The Jaccard coefficient is re...
0
2009-11-26T22:59:01Z
[ "python", "list", "text", "vector" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,806,244
<p>Is position is very important, as you emphasize, then the crucial metric will be based on the difference of positions between the same items in the different vectors (you can, for example, sum the absolute values of the differences, or their squares). The big issue that needs to be solved is -- how much to weigh an...
3
2009-11-27T00:18:47Z
[ "python", "list", "text", "vector" ]
Suppose I have 2 vectors. What algorithms can I use to compare them?
1,805,987
<p>Company 1 has this vector:</p> <pre><code>['books','video','photography','food','toothpaste','burgers'] ... ... </code></pre> <p>Company 2 has this vector:</p> <pre><code>['video','processor','photography','LCD','power supply', 'books'] ... ... </code></pre> <p>Suppose this is a frequency distribution (I could m...
1
2009-11-26T22:39:54Z
1,806,269
<p>pick the rank of each entry (higher rank is better) and make sum of geometric means between matches</p> <p>for two vectors</p> <pre><code>sum(sqrt(vector_multiply(x,y))) //multiply matches </code></pre> <p>Sum of ranks for each value over vector should be same for each vector (preferrebly 1) That way you can ma...
0
2009-11-27T00:32:07Z
[ "python", "list", "text", "vector" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,166
<p>Why not do it randomly. For each transaction, pick a random number between 0 and 100. If that number is less than your "percent", then audit the transaction. If the number is greater than your "percent", then don't. I don't know if this satisfies your requirements, but over an extended period of time, you will h...
17
2009-11-26T23:50:21Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,169
<p>Try this:</p> <p>1) Keep your audit percentage as a decimal.<br> 2) For every transaction, associate a random number (between 0 and 1) with it<br> 3) If the random number is less than the percentage, audit the transaction.</p>
3
2009-11-26T23:50:49Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,173
<p>If you need to audit these transactions in real time (as they are received) perhaps you could use a random number generator to check if you need to audit the transaction.</p> <p>So if for example you want to audit 50% of transactions, for every transaction received you would generate a random number between 0 and 1...
1
2009-11-26T23:51:26Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,206
<p>For a high throughput system the random method is best, but if you don't want randomness, the this algorithm will do the job. Don't forget to test it in a unit test!</p> <pre><code>// setup int transactionCount = 0; int auditCount = 0; double targetAuditRatio = auditPercent/100.0; // start of processing transacti...
1
2009-11-27T00:03:41Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,208
<p>You can constantly "query" each audit using counter. For example</p> <pre><code>ctr = 0; percent = 50 while(1) { ctr += percent; if (ctr &gt;= 100) { audit; ctr = ctr - 100; } else skip } </code></pre> <p>You can use floats (however this will bring some unpredictability) or multiply 100 ...
0
2009-11-27T00:04:32Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,223
<pre><code> if percent &gt; random.randint(1,100): print("audit") else: print("skip") </code></pre>
2
2009-11-27T00:10:27Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,231
<p>To follow your own algorithm: just keep adding that 1.333333 (or other quotient) to a counter.</p> <p>Have two counters: an integer one and a real one. If the truncated part of the real counter = the integer counter, the audit is carried out, otherwise it isn't, like this:</p> <pre><code>Integer counter Real cou...
2
2009-11-27T00:13:00Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Calculate percent at runtime
1,806,143
<p>I have this problem where I have to "audit" a percent of my transtactions.</p> <p>If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. </p> <p>The problem ( or the opportunity ) is that I have to perform the check at runtime. </p> <p>What I tried wa...
6
2009-11-26T23:40:58Z
1,806,241
<p>Not tested, but in the <code>random</code> module there is a function <code>sample</code>. If <code>transactions</code> was a list of transactions, you would do something like:</p> <pre><code>import random to_be_audited = random.sample(transactions,len(transactions*100/percentage)) </code></pre> <p>This would ge...
0
2009-11-27T00:17:42Z
[ "c#", "java", "python", "algorithm", "language-agnostic" ]
Scrapy BaseSpider: How does it work?
1,806,235
<p>This is the BaseSpider example from the Scrapy tutorial:</p> <pre><code>from scrapy.spider import BaseSpider from scrapy.selector import HtmlXPathSelector from dmoz.items import DmozItem class DmozSpider(BaseSpider): domain_name = "dmoz.org" start_urls = [ "http://www.dmoz.org/Computers/Programming/L...
5
2009-11-27T00:15:37Z
1,807,439
<p>Probably you meant <code>item = FirmItem()</code> instead of <code>item = FirmItem</code>?</p>
16
2009-11-27T08:35:34Z
[ "python", "web-crawler", "scrapy" ]
mechanize python click a button
1,806,238
<p>I have a form with <code>&lt;input type="button" name="submit" /&gt;</code> button and would like to be able to click it. </p> <p>I have tried <code>mech.form.click("submit")</code> but that gives the following error:</p> <p><code>ControlNotFoundError: no control matching kind 'clickable', id 'submit'</code></p> ...
12
2009-11-27T00:16:30Z
1,806,266
<p>clicking a <code>type="button"</code> in a <strong>pure html</strong> form does nothing. For it to do anything, there must be <em>javascript</em> involved.</p> <p>And <code>mechanize</code> doesn't run <em>javascript</em>.</p> <p>So your options are:</p> <ul> <li>Read the javascript yourself and simulate with <co...
21
2009-11-27T00:30:53Z
[ "python", "button", "mechanize" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,288
<p>That might be a dirty workaround, but you could convert spaces to a <code>+</code> sign to solve the 3rd case (or to a <code>-</code> if your fraction is negative).</p>
2
2009-11-27T00:39:43Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,290
<p>Depending on what syntax you want to support for your fractions, <code>eval('+'.join(s.split()))</code> (with true division in place -- i.e., Python 3 or <code>from __future__ import division</code> in Python 2 -- might work. It would cover all the cases you mention, in particular.</p>
0
2009-11-27T00:40:28Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,302
<p>Though you should stear clear of eval completely. Perhaps some more refined version of:</p> <pre><code>num,den = s.split( '/' ) wh, num = num.split() result = wh + (float(num)/float(den)) </code></pre> <p>Sorry, meant to be num.split not s.split, and casts. Edited.</p>
3
2009-11-27T00:44:56Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,309
<p>maybe something like this (2.6+)</p> <pre><code>from fractions import Fraction float(sum(Fraction(s) for s in '1 2/3'.split())) </code></pre>
21
2009-11-27T00:50:46Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,375
<p>This implementation avoids using eval and works on pre-2.6 versions of Python.</p> <pre><code># matches a string consting of an integer followed by either a divisor # ("/" and an integer) or some spaces and a simple fraction (two integers # separated by "/") FRACTION_REGEX = re.compile(r'^(\d+)(?:(?:\s+(\d+))?/(\d+...
1
2009-11-27T01:20:54Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
1,806,409
<pre><code>&gt;&gt;&gt; s="1/2" &gt;&gt;&gt; eval('/'.join(map(str,map(float,s.split("/"))))) 0.5 &gt;&gt;&gt; s="3/5" &gt;&gt;&gt; eval('/'.join(map(str,map(float,s.split("/"))))) 0.59999999999999998 </code></pre>
0
2009-11-27T01:33:07Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
19,073,403
<p>I see there are already several good answers here, but I've had good luck with this. It also has the benefit that it will tolerate non-fraction strings if you're parsing mixed sets of data, so there's no need to check if it's a fraction string or not upfront.</p> <pre><code>def convert_to_float(frac_str): try:...
2
2013-09-29T01:05:39Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
26,020,082
<pre><code>def fractionToFloat(fraction): num = 0 mult = 1 if fraction[:1] == "-": fraction = fraction[1:] mult = -1 if " " in fraction: a = fraction.split(" ") num = float(a[0]) toSplit = a[1] else: toSplit = fraction frac = toSplit.split...
2
2014-09-24T14:54:20Z
[ "python", "parsing" ]
Convert fraction to float?
1,806,278
<p>Kind of <a href="http://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions">like this question</a>, but in reverse.</p> <p>Given a string like <code>1</code>, <code>1/2</code>, or <code>1 2/3</code>, what's the best way to convert it into a float? I'm thinking about using regexes on...
10
2009-11-27T00:36:10Z
30,629,776
<p>I tweaked <a href="http://stackoverflow.com/a/19073403/65387">James' answer</a> a bit.</p> <pre><code>def convert_to_float(frac_str): try: return float(frac_str) except ValueError: num, denom = frac_str.split('/') try: leading, num = num.split(' ') whole = flo...
2
2015-06-03T20:13:45Z
[ "python", "parsing" ]
"Permission Denied" in Django template using Djapian
1,806,449
<p>I've followed the Djapian tutorial and setup everything "by the book" so that the indexshell commandline supplied by Djapian shows successful queries.</p> <p>However, when integrating the sample search from the Djapian tutorial I get this nonsense error:</p> <blockquote> <p>TemplateSyntaxError at /search/</p> ...
0
2009-11-27T01:56:18Z
1,806,773
<p>Please figure out what is the exact file path involved in this error. I guess it involves a write operation to some template cache, but you should make sure.</p> <p>Then you just need to check the UNIX permissions on the file accessed or on the directory for that file in the case of a newly created file.</p> <p>An...
2
2009-11-27T04:42:52Z
[ "python", "django", "search", "django-templates", "xapian" ]
Navigation menu using Django templates
1,806,472
<p>Trying to work with a trivial navigation menu using django templates, I'm having trouble setting the current class on a particular menu item. Here's my base template:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html ...
5
2009-11-27T02:11:22Z
1,806,532
<p>I don't think you can replace a block from an included template. My suggestion is that you need to rethink the logic of your templates. IMHO it should be something like this: </p> <p>base.html</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-s...
7
2009-11-27T02:43:48Z
[ "python", "django" ]
Navigation menu using Django templates
1,806,472
<p>Trying to work with a trivial navigation menu using django templates, I'm having trouble setting the current class on a particular menu item. Here's my base template:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html ...
5
2009-11-27T02:11:22Z
1,806,999
<p>The other way people handle this is to just use the body.class in the CSS file...</p> <p><strong>nav.html</strong></p> <pre><code> &lt;ul id="top"&gt; &lt;li&gt;&lt;a class="home" href="/"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="myaccount" href="/profile/"&gt;My Account&lt;/a&gt;&lt;/li&gt; {%...
2
2009-11-27T05:53:52Z
[ "python", "django" ]
Navigation menu using Django templates
1,806,472
<p>Trying to work with a trivial navigation menu using django templates, I'm having trouble setting the current class on a particular menu item. Here's my base template:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html ...
5
2009-11-27T02:11:22Z
9,801,377
<p>You can solve the duplication problem using DRY menu custom template tag. It solves the problem of active/inactive menu class too. See the description below, please. The source code: <a href="http://djangosnippets.org/snippets/2722/" rel="nofollow">http://djangosnippets.org/snippets/2722/</a></p> <p>Description of ...
1
2012-03-21T08:59:16Z
[ "python", "django" ]
Alternatives to FontForge
1,806,583
<p>I use python bindings for FontForge under Ubuntu. It constantly runs into crash without any clues about the reason, e.g. segmentation fault, memory mapping errors, etc.</p> <p>All what I need is to read font file's (.ttf and .otf) meta data (font name, family name, version, unique id, copyright, license, designer, ...
2
2009-11-27T03:14:13Z
1,806,646
<p>I had some issue with fontforge at my ubuntu x64 before too.</p> <p>I am using it for adding opentype rules, but error sometimes happen, when I try to modify those metadata.</p> <p>Latest svn is a lot better, I mean least crashing, I use following guide to install from svn.</p> <p><a href="http://openfontlibrary....
3
2009-11-27T03:53:35Z
[ "python", "fonts", "fontforge" ]
Alternatives to FontForge
1,806,583
<p>I use python bindings for FontForge under Ubuntu. It constantly runs into crash without any clues about the reason, e.g. segmentation fault, memory mapping errors, etc.</p> <p>All what I need is to read font file's (.ttf and .otf) meta data (font name, family name, version, unique id, copyright, license, designer, ...
2
2009-11-27T03:14:13Z
18,878,345
<blockquote> <p>All what I need is to read font file's (.ttf and .otf) meta data (font name, family name, version, unique id, copyright, license, designer, designer url, etc) and count the glyphs it has</p> </blockquote> <p><a href="https://github.com/davelab6/pyfontaine/" rel="nofollow">https://github.com/davelab6/...
0
2013-09-18T17:13:12Z
[ "python", "fonts", "fontforge" ]
python: how can i avoid " list index out of range" in this simple while loop
1,806,608
<p>my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03</p> <p>my code works, but gives an error at the end because the last count is out of range. i understand why it breaks, but dont know how to fix it. thanks</p> <pre><code>count = 1 while L1: print "%.2f" %L1[count] co...
0
2009-11-27T03:30:12Z
1,806,612
<p>If you want to print all numbers in <code>L1</code>, use:</p> <pre><code>for x in L1: print '%.2f' % x </code></pre> <p>If you want to skip the first one, <code>for x in L1[1:]:</code> will work.</p> <p><strong>Edit</strong>: the OP mentions in a comment (!) that their desire is actually to "create a new array" (...
9
2009-11-27T03:32:39Z
[ "python", "loops", "while-loop" ]
python: how can i avoid " list index out of range" in this simple while loop
1,806,608
<p>my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03</p> <p>my code works, but gives an error at the end because the last count is out of range. i understand why it breaks, but dont know how to fix it. thanks</p> <pre><code>count = 1 while L1: print "%.2f" %L1[count] co...
0
2009-11-27T03:30:12Z
1,806,613
<p>Why don't you just loop through the <code>L1</code> list instead of doing a while loop?</p> <pre><code>for i in L1: print "%.2f" % i </code></pre> <p>Keep it simple :)</p>
2
2009-11-27T03:33:32Z
[ "python", "loops", "while-loop" ]
python: how can i avoid " list index out of range" in this simple while loop
1,806,608
<p>my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03</p> <p>my code works, but gives an error at the end because the last count is out of range. i understand why it breaks, but dont know how to fix it. thanks</p> <pre><code>count = 1 while L1: print "%.2f" %L1[count] co...
0
2009-11-27T03:30:12Z
1,807,000
<pre><code>L2=["%.2f" %i for i in L1] </code></pre>
0
2009-11-27T05:53:58Z
[ "python", "loops", "while-loop" ]
python: how can i avoid " list index out of range" in this simple while loop
1,806,608
<p>my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03</p> <p>my code works, but gives an error at the end because the last count is out of range. i understand why it breaks, but dont know how to fix it. thanks</p> <pre><code>count = 1 while L1: print "%.2f" %L1[count] co...
0
2009-11-27T03:30:12Z
1,808,858
<p>2 problems:</p> <ol> <li>Your loop never ends (while L1)</li> <li>You start indexing with 1 (count = 1 in initialisation)</li> </ol> <p>Better is, like the others said:</p> <pre><code>for i in L1: print "%.2f" % i </code></pre> <p>and if you also need the index (count):</p> <pre><code>for (index, item) in e...
0
2009-11-27T13:42:45Z
[ "python", "loops", "while-loop" ]
GUI designer for managing Django models
1,806,681
<p>Is there a GUI tool using which I can design new Django models graphically? For example, drawing lines between fields in different models to indicate a foreign key.</p> <p>Modifying existing models graphically would also be nice.</p>
4
2009-11-27T04:11:59Z
1,806,951
<p><a href="http://code.google.com/p/uml-to-django/" rel="nofollow">uml-to-django</a> might be of interest to you, though I can't personally vouch for it.</p>
1
2009-11-27T05:40:11Z
[ "python", "django", "django-models", "gui-designer" ]
GUI designer for managing Django models
1,806,681
<p>Is there a GUI tool using which I can design new Django models graphically? For example, drawing lines between fields in different models to indicate a foreign key.</p> <p>Modifying existing models graphically would also be nice.</p>
4
2009-11-27T04:11:59Z
33,948,061
<p>You can import django models on <a href="http://dbpatterns.com" rel="nofollow">dbpatterns</a>.</p>
0
2015-11-26T22:50:07Z
[ "python", "django", "django-models", "gui-designer" ]
Grouping by Nested Object Keys in MongoDB
1,806,705
<p>Is it possible to group results by a key found in an array of objects in a list?</p> <p>For example, lets say I have a table of survey responses (<code>survey_responses</code>), and each entry represents a single response. One or more of the questions in the survey is a multiple choice, so the answers stored could ...
0
2009-11-27T04:22:36Z
1,806,742
<p>It seems that your only option is to do this in your own Python code:</p> <pre><code>song_points = {} for response in survey_responses.find(): for song in response['favorite_songs_of_2009']: title = song['title'] song_points[title] = song_points.get(title, 0) + song['points'] </code></pre> <p>Y...
0
2009-11-27T04:35:40Z
[ "python", "mongodb" ]
Python: urllib2 multipart/form-data and proxies
1,806,729
<p><strong>The Objective</strong>: A script which cycles through a list of proxies and sends a post request, containing a file to a PHP page on my server, which then calculates delivery time. It's a pretty useless script, but I am using it to teach myself about urllib2.</p> <p><strong>The Problem</strong>: So far I ha...
2
2009-11-27T04:31:34Z
1,806,916
<p>you could add proxy installer like this, before requesting the page. </p> <pre><code>from urllib2 import ProxyHandler,build_opener,install_opener PROXY="http://USERNAME:PASSWD@ADDRESS:PORT" opener = build_opener(ProxyHandler({"http" : PROXY})) install_opener(opener) </code></pre>
5
2009-11-27T05:30:01Z
[ "python", "proxy", "urllib2", "multipartform-data", "poster" ]
Read from source.sql write to destiantion.sql with python script?
1,806,761
<p>I Have a file source.sql</p> <pre><code>INSERT INTO `Tbl_ABC` VALUES (1, 0, 'MMB', '2 MB INTERNATIONAL', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 12, '3D STRUCTURES', '3D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 0, '2 STRUCTURES', '2D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALU...
1
2009-11-27T04:39:18Z
1,806,801
<p>You can read line by line and check if it is ends with 0) and match with regex for the other one.</p> <pre><code>import re dest=open("destination.sql","w+") for line in open("source.sql","r"): if line.strip().endswith("0)") and re.search("\(\d+, 0,",line): dest.write(line) </code></pre>
1
2009-11-27T04:50:02Z
[ "python" ]
Read from source.sql write to destiantion.sql with python script?
1,806,761
<p>I Have a file source.sql</p> <pre><code>INSERT INTO `Tbl_ABC` VALUES (1, 0, 'MMB', '2 MB INTERNATIONAL', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 12, '3D STRUCTURES', '3D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 0, '2 STRUCTURES', '2D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALU...
1
2009-11-27T04:39:18Z
1,806,814
<p>Something like this:</p> <pre><code>import re RX = re.compile(r'^.*?\(\d+,\s0,.*\s0\)\s*$') outfile = open('destination.sql', 'w') for ln in open('source.sql', 'r').xreadlines(): if RX.match(ln): outfile.write(ln) </code></pre>
1
2009-11-27T04:53:58Z
[ "python" ]
Read from source.sql write to destiantion.sql with python script?
1,806,761
<p>I Have a file source.sql</p> <pre><code>INSERT INTO `Tbl_ABC` VALUES (1, 0, 'MMB', '2 MB INTERNATIONAL', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 12, '3D STRUCTURES', '3D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALUES (2, 0, '2 STRUCTURES', '2D STRUCTURES', NULL, NULL, 0) INSERT INTO `Tbl_ABC` VALU...
1
2009-11-27T04:39:18Z
1,807,361
<blockquote> <p>My sql may loger than this.but positon is keep in general. In this case the first number 0 at position[1] and the second 0 at the position[6] (start count from 0)</p> </blockquote> <p>to S.Mark, fviktor I have tried like this </p> <p>import re</p> <pre><code>RX = re.compile(r'^.*?\(\d+,\s0,.*\s0\)\...
0
2009-11-27T08:12:45Z
[ "python" ]
How to find out the nested class hierarchy?
1,806,812
<p>I have a python code like this.</p> <p>File named mymodule.py</p> <pre><code>class MyBase(object): pass </code></pre> <p>File named data.py</p> <pre><code>from mymodule import MyBase class A: class NestA(MyBase): pass class NestB(MyBase): pass class B: class NestA(MyBase): ...
4
2009-11-27T04:53:20Z
1,807,175
<p>You can do something like this with metaclass programming.</p> <pre><code>class SetOuterClassType(type): def __init__(cls, name, bases, attrs): for attrname, attrvalue in attrs.iteritems(): if getattr(attrvalue, '__set_outerclass__', False): attrvalue.__outerclass__ = cls cl...
0
2009-11-27T06:58:08Z
[ "python" ]
How to find out the nested class hierarchy?
1,806,812
<p>I have a python code like this.</p> <p>File named mymodule.py</p> <pre><code>class MyBase(object): pass </code></pre> <p>File named data.py</p> <pre><code>from mymodule import MyBase class A: class NestA(MyBase): pass class NestB(MyBase): pass class B: class NestA(MyBase): ...
4
2009-11-27T04:53:20Z
1,807,263
<p>What you are asking for is a result of bad design. My advise to you is to redefine your solution.</p>
0
2009-11-27T07:34:04Z
[ "python" ]
How to find out the nested class hierarchy?
1,806,812
<p>I have a python code like this.</p> <p>File named mymodule.py</p> <pre><code>class MyBase(object): pass </code></pre> <p>File named data.py</p> <pre><code>from mymodule import MyBase class A: class NestA(MyBase): pass class NestB(MyBase): pass class B: class NestA(MyBase): ...
4
2009-11-27T04:53:20Z
1,807,275
<p>You can do this with the inspect module:</p> <pre><code>import inspect a = A.NestA print a in [x[1] for x in inspect.getmembers(A, inspect.isclass)] print a in [x[1] for x in inspect.getmembers(B, inspect.isclass)] </code></pre> <p>Result:</p> <pre><code>True False </code></pre> <p><strong>Addendum:</strong></...
1
2009-11-27T07:37:57Z
[ "python" ]
Why do I need to save this model before adding it to another one?
1,806,937
<p>In django, I'm trying to do something like this:</p> <pre><code># if form is valid ... article = form.save(commit=False) article.author = req.user product_name = form.cleaned_data['product_name'] try: article.product = Component.objects.get(name=product_name) except: article.product = Component(name=product_name...
0
2009-11-27T05:34:57Z
1,806,971
<p>The way the Django ManyToManyField works is that it creates an extra table. So say you have two models, ModelA and ModelB. If you did...</p> <pre><code>ModelA.model_b = models.ManyToManyField(ModelB) </code></pre> <p>What Django actually does behind the scenes is it creates a table... <code>app_modela_modelb</co...
4
2009-11-27T05:45:32Z
[ "python", "django", "models" ]
Why do I need to save this model before adding it to another one?
1,806,937
<p>In django, I'm trying to do something like this:</p> <pre><code># if form is valid ... article = form.save(commit=False) article.author = req.user product_name = form.cleaned_data['product_name'] try: article.product = Component.objects.get(name=product_name) except: article.product = Component(name=product_name...
0
2009-11-27T05:34:57Z
1,808,066
<p>You could get around this by using :</p> <pre><code>target_product, created_flag = Component.objects.get_or_create(name=product_name) article.product = target_product </code></pre> <p>as I'm pretty sure <code>get_or_create()</code> will set the id of an object, if it has to create one.</p> <p>Alternatively, if yo...
1
2009-11-27T10:54:18Z
[ "python", "django", "models" ]
Why do I need to save this model before adding it to another one?
1,806,937
<p>In django, I'm trying to do something like this:</p> <pre><code># if form is valid ... article = form.save(commit=False) article.author = req.user product_name = form.cleaned_data['product_name'] try: article.product = Component.objects.get(name=product_name) except: article.product = Component(name=product_name...
0
2009-11-27T05:34:57Z
1,808,090
<p>There's little value in including a code snippet on transactions, as you should read <a href="http://docs.djangoproject.com/en/dev/topics/db/transactions/" rel="nofollow">the Django documentation</a> to gain a good understanding.</p>
1
2009-11-27T10:58:51Z
[ "python", "django", "models" ]
Scrapy spider is not working
1,806,990
<p>Since nothing so far is working I started a new project with </p> <pre><code>python scrapy-ctl.py startproject Nu </code></pre> <p>I followed the tutorial exactly, and created the folders, and a new spider</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml ...
-1
2009-11-27T05:51:29Z
1,809,105
<p>Have you included the spider in <code>SPIDER_MODULES</code> list in your scrapy_settings.py?</p> <p>It's not written in the tutorial anywhere that you should to this, but you do have to.</p>
2
2009-11-27T14:30:49Z
[ "python", "scrapy" ]
Scrapy spider is not working
1,806,990
<p>Since nothing so far is working I started a new project with </p> <pre><code>python scrapy-ctl.py startproject Nu </code></pre> <p>I followed the tutorial exactly, and created the folders, and a new spider</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml ...
-1
2009-11-27T05:51:29Z
2,886,787
<p>I believe you have syntax errors there. The <code>name = hxs...</code> will not work because you don't get defined before the <code>hxs</code> object.</p> <p>Try running <code>python yourproject/spiders/domain.py</code> to get syntax errors.</p>
2
2010-05-22T03:03:19Z
[ "python", "scrapy" ]
Scrapy spider is not working
1,806,990
<p>Since nothing so far is working I started a new project with </p> <pre><code>python scrapy-ctl.py startproject Nu </code></pre> <p>I followed the tutorial exactly, and created the folders, and a new spider</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml ...
-1
2009-11-27T05:51:29Z
3,276,879
<p>These two lines look like they're causing trouble:</p> <pre><code>u = names.pop() rules = (Rule(SgmlLinkExtractor(allow=(u, )), callback='parse_item'),) </code></pre> <ul> <li>Only one rule will be followed each time the script is run. Consider creating a rule for each URL.</li> <li>You haven't created a <code>pa...
3
2010-07-18T19:17:06Z
[ "python", "scrapy" ]
Scrapy spider is not working
1,806,990
<p>Since nothing so far is working I started a new project with </p> <pre><code>python scrapy-ctl.py startproject Nu </code></pre> <p>I followed the tutorial exactly, and created the folders, and a new spider</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml ...
-1
2009-11-27T05:51:29Z
4,541,529
<p>Please also check the version of scrapy. The latest version uses "name" instead of "domain_name" attribute to uniquely identify a spider.</p>
6
2010-12-27T20:19:01Z
[ "python", "scrapy" ]
Scrapy spider is not working
1,806,990
<p>Since nothing so far is working I started a new project with </p> <pre><code>python scrapy-ctl.py startproject Nu </code></pre> <p>I followed the tutorial exactly, and created the folders, and a new spider</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml ...
-1
2009-11-27T05:51:29Z
7,744,661
<p>You are overriding the <code>parse</code> method, instead of implementing a new <code>parse_item</code> method.</p>
2
2011-10-12T18:21:58Z
[ "python", "scrapy" ]
Initialize a list of objects in Python
1,807,026
<p>I'm a looking to initialize an array/list of objects that are not empty -- the class constructor generates data. In C++ and Java I would do something like this:</p> <pre><code>Object lst = new Object[100]; </code></pre> <p>I've dug around, but is there a Pythonic way to get this done?</p> <p>This doesn't work li...
7
2009-11-27T06:05:17Z
1,807,043
<p>There isn't a way to implicitly call an <code>Object()</code> constructor for each element of an array like there is in C++ (recall that in Java, each element of a new array is initialised to <code>null</code> for reference types).</p> <p>I would say that your list comprehension method is the most Pythonic:</p> <p...
18
2009-11-27T06:10:10Z
[ "python", "arrays", "list", "initialization" ]
Initialize a list of objects in Python
1,807,026
<p>I'm a looking to initialize an array/list of objects that are not empty -- the class constructor generates data. In C++ and Java I would do something like this:</p> <pre><code>Object lst = new Object[100]; </code></pre> <p>I've dug around, but is there a Pythonic way to get this done?</p> <p>This doesn't work li...
7
2009-11-27T06:05:17Z
1,807,049
<pre><code>lst = [Object() for i in range(100)] </code></pre> <p>Since an array is it's own first class object in python I think this is the only way to get what you're looking for. * does something crazy.</p>
0
2009-11-27T06:11:47Z
[ "python", "arrays", "list", "initialization" ]
Initialize a list of objects in Python
1,807,026
<p>I'm a looking to initialize an array/list of objects that are not empty -- the class constructor generates data. In C++ and Java I would do something like this:</p> <pre><code>Object lst = new Object[100]; </code></pre> <p>I've dug around, but is there a Pythonic way to get this done?</p> <p>This doesn't work li...
7
2009-11-27T06:05:17Z
1,807,132
<p>I think the list comprehension is the simplest way, but, if you don't like it, it's obviously not the only way to obtain what you desire -- calling a given callable 100 times with no arguments to form the 100 items of a new list. For example, <code>itertools</code> can obviously do it:</p> <pre><code>&gt;&gt;&gt; ...
2
2009-11-27T06:43:28Z
[ "python", "arrays", "list", "initialization" ]
Initialize a list of objects in Python
1,807,026
<p>I'm a looking to initialize an array/list of objects that are not empty -- the class constructor generates data. In C++ and Java I would do something like this:</p> <pre><code>Object lst = new Object[100]; </code></pre> <p>I've dug around, but is there a Pythonic way to get this done?</p> <p>This doesn't work li...
7
2009-11-27T06:05:17Z
1,807,374
<p>You should note that Python's equvalent for Java code (creating array of 100 <strong>null</strong> references to Object):</p> <pre><code>Object arr = new Object[100]; </code></pre> <p>or C++ code:</p> <pre><code>Object **arr = new Object*[100]; </code></pre> <p>is:</p> <pre><code>arr = [None]*100 </code></pre> ...
9
2009-11-27T08:15:59Z
[ "python", "arrays", "list", "initialization" ]
Extract files with invalid characters in filename with Python
1,807,063
<p>I use python's zipfile module to extract a .zip archive (Let's take this file at <a href="http://img.dafont.com/dl/?f=akvaleir" rel="nofollow">http://img.dafont.com/dl/?f=akvaleir</a> for example.)</p> <pre><code>f = zipfile.ZipFile('akvaleir.zip', 'r') for fileinfo in f.infolist(): print fileinfo.filename ...
2
2009-11-27T06:15:06Z
1,807,107
<p>Instead of the <code>extract</code> method, use the <a href="http://docs.python.org/library/zipfile.html?highlight=zipfile%20extract#zipfile.ZipFile.open"><code>open</code></a> method and save the resulting pseudofile to disk under whatever name you wish, for example with <a href="http://docs.python.org/library/shut...
5
2009-11-27T06:33:02Z
[ "python", "unicode", "encoding", "filenames", "zipfile" ]
Extract files with invalid characters in filename with Python
1,807,063
<p>I use python's zipfile module to extract a .zip archive (Let's take this file at <a href="http://img.dafont.com/dl/?f=akvaleir" rel="nofollow">http://img.dafont.com/dl/?f=akvaleir</a> for example.)</p> <pre><code>f = zipfile.ZipFile('akvaleir.zip', 'r') for fileinfo in f.infolist(): print fileinfo.filename ...
2
2009-11-27T06:15:06Z
1,807,754
<p>It took some time but I think I found the answer.</p> <p>I assumed the word was supposed to be Akvaléir. I found a page description about that, in French. When I used your code snippet I had a string like</p> <pre><code>&gt;&gt;&gt; fileinfo.filename 'Akval\x82ir, La police - The Font - Fr - En.pdf' &gt;&gt;&gt; ...
5
2009-11-27T09:49:45Z
[ "python", "unicode", "encoding", "filenames", "zipfile" ]
How to wait for messages on multiple queues using py-amqplib
1,807,113
<p>I'm using <strong>py-amqplib</strong> to access RabbitMQ in Python. The application receives requests to listen on certain MQ topics from time to time.</p> <p>The first time it receives such a request it creates an AMQP connection and a channel and starts a new thread to listen for messages:</p> <pre><code> con...
3
2009-11-27T06:34:39Z
2,019,486
<p>If you want more than one comsumer per channel just attach another one using <strong>basic_consume()</strong> and use <strong>channel.wait()</strong> after. It will listen to all queues attached via <strong>basic_consume()</strong>. Make sure you define different consumer tags for each <strong>basic_consume()</stron...
1
2010-01-07T10:10:47Z
[ "python", "message-queue", "rabbitmq", "amqp", "py-amqplib" ]
Open a second window in PyQt
1,807,299
<p>I'm trying to use pyqt to show a custom QDialog window when a button on a QMainWindow is clicked. I keep getting the following error: </p> <pre><code>$ python main.py DEBUG: Launch edit window Traceback (most recent call last): File "/home/james/Dropbox/Database/qt/ui_med.py", line 23, in launchEditWindow di...
6
2009-11-27T07:50:08Z
1,813,463
<pre><code>class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) </code></pre> <p>Why <code>QtGui.QWidget.__init___</code> ??? Use insted:</p> <pre><code>class StartQT4(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__i...
1
2009-11-28T19:12:35Z
[ "python", "dialog", "pyqt" ]
Open a second window in PyQt
1,807,299
<p>I'm trying to use pyqt to show a custom QDialog window when a button on a QMainWindow is clicked. I keep getting the following error: </p> <pre><code>$ python main.py DEBUG: Launch edit window Traceback (most recent call last): File "/home/james/Dropbox/Database/qt/ui_med.py", line 23, in launchEditWindow di...
6
2009-11-27T07:50:08Z
2,041,487
<p>Ui_Dialog should inherent from QtGui.QDialog, not object.</p> <pre><code>class Ui_Dialog(QtGui.QDialog): def __init__(self, dbConnection): QtGui.QDialog.__init__(self) global c c = dbConnection </code></pre>
3
2010-01-11T11:30:20Z
[ "python", "dialog", "pyqt" ]
Open a second window in PyQt
1,807,299
<p>I'm trying to use pyqt to show a custom QDialog window when a button on a QMainWindow is clicked. I keep getting the following error: </p> <pre><code>$ python main.py DEBUG: Launch edit window Traceback (most recent call last): File "/home/james/Dropbox/Database/qt/ui_med.py", line 23, in launchEditWindow di...
6
2009-11-27T07:50:08Z
2,371,959
<p>I've done like this in the past, and i can tell it works. assuming your button is called "Button"</p> <pre><code>class Main(QtGui.QMainWindow): ''' some stuff ''' def on_Button_clicked(self, checked=None): if checked==None: return dialog = QDialog() dialog.ui = Ui_MyDialog() ...
12
2010-03-03T14:18:07Z
[ "python", "dialog", "pyqt" ]
Running twistd as root, modules aren't found
1,807,484
<p>I have a simple web server written in Twisted, and I'm trying to start it up daemonized with <strong>twistd</strong>. Everything works fine with <code>reactor.run()</code> but when I use <code>twistd -y</code> (as root), none of my packages which are in direct child directories get found. I'm running twistd as root,...
4
2009-11-27T08:45:17Z
1,810,060
<p>General UNIX wisdom is that searching the working directory for things to execute when root is a bad idea. The argument goes that it opens the door to trojans. In not going out of its way to add the working directory to the Python module import search path when running as root, twistd is basically trying to follow...
7
2009-11-27T18:14:54Z
[ "python", "twisted" ]
Python/OpenCV: Converting images taken from capture
1,807,528
<p>I'm trying to convert images taken from a capture (webcam) and do some processing on them with OpenCV, but I'm having a difficult time..</p> <p>When trying to convert the image to grayscale, the program crashes. (Python.exe has stopped working)</p> <p>Here is the main snippet of my code:</p> <pre><code>newFrameIm...
3
2009-11-27T08:54:31Z
1,809,249
<p>There is a common mistake here:</p> <p>You're creating a single image in the <code>newFrameImageGS</code> variable <strong>before</strong> the loop, then overwrite its contents in the loop, which is then appended to a list. The result will not be what you would expect. The list will contain five references to the s...
1
2009-11-27T15:01:50Z
[ "python", "opencv", "iplimage" ]
Python/OpenCV: Converting images taken from capture
1,807,528
<p>I'm trying to convert images taken from a capture (webcam) and do some processing on them with OpenCV, but I'm having a difficult time..</p> <p>When trying to convert the image to grayscale, the program crashes. (Python.exe has stopped working)</p> <p>Here is the main snippet of my code:</p> <pre><code>newFrameIm...
3
2009-11-27T08:54:31Z
1,810,815
<p>For some reason, CvtColor caused the program to crash when the image depths where 8 bit. When I converted them to 32 bit, the program no longer crashed and everything seemed to work OK. I have no idea why this is, but at least it works now.</p> <pre><code>newFrameImage = cv.QueryFrame(ps3eye) newFrameImage32F = cv...
4
2009-11-27T22:20:27Z
[ "python", "opencv", "iplimage" ]
App Engine model filtering with Django
1,807,545
<p>hi i am using django app engine patch i have set up a simple model as follows</p> <pre><code>class Intake(db.Model): intake=db.StringProperty(multiline=False, required=True) #@permerlink def get_absolute_url(self): return "/timekeeper/%s/" % self.intake class Meta: db_table = "Intake"...
1
2009-11-27T08:58:53Z
1,807,898
<p>You need to insert a space between the field name and the operator in your filter arguments - eg, use <code>.filter('intake =')</code> instead of <code>.filter('intake=')</code>. With an equality filter, you can also leave it out entirely, as in <code>.filter('intake')</code>. Without the space, the equals sign is t...
2
2009-11-27T10:18:37Z
[ "python", "django", "google-app-engine", "django-models" ]
how pylons decorator works
1,807,760
<pre><code>from decorator import decorator from pylons.decorators.util import get_pylons def allowed_roles(roles): def wrapper(func, *args, **kwargs): session = get_pylons(args).session # edit pylons session here. return func(*args, **kwargs) return decorator(wrapper) </code></pre> <p>...
1
2009-11-27T09:50:53Z
1,808,391
<p>Like any other decorator works - </p> <p>A decorator is a function which receives a function as an argument, and returns another function. The returned function will "take the place" from the original function.</p> <p>Since the desired effect with a decoratos is usually to be able to run some code before and afte...
2
2009-11-27T12:09:30Z
[ "python", "pylons" ]
How to efficiently use MySQLDB SScursor?
1,808,150
<p>I have to deal with a large result set (could be hundreds thousands of rows, sometimes more).<br> They unfortunately need to be retrieved all at once (on start up). </p> <p>I'm trying to do that by using as less memory as possible.<br> By looking on SO I've found that using <code>SSCursor</code> might be what I'm l...
21
2009-11-27T11:12:38Z
1,808,309
<p>Definitely use the SSCursor when fetching big result sets. It made a huge difference for me when I had a similar problem. You can use it like this:</p> <pre><code>import MySQLdb import MySQLdb.cursors connection = MySQLdb.connect( host=host, port=port, user=username, passwd=password, db=database, ...
6
2009-11-27T11:52:28Z
[ "python", "mysql", "optimization", "cursor" ]
How to efficiently use MySQLDB SScursor?
1,808,150
<p>I have to deal with a large result set (could be hundreds thousands of rows, sometimes more).<br> They unfortunately need to be retrieved all at once (on start up). </p> <p>I'm trying to do that by using as less memory as possible.<br> By looking on SO I've found that using <code>SSCursor</code> might be what I'm l...
21
2009-11-27T11:12:38Z
1,808,414
<p>I am in agreement with Otto Allmendinger's answer, but to make explicit Denis Otkidach's comment, here is how you can iterate over the results without using Otto's fetch() function:</p> <pre><code>import MySQLdb.cursors connection=MySQLdb.connect( host="thehost",user="theuser", passwd="thepassword",db="thed...
23
2009-11-27T12:13:11Z
[ "python", "mysql", "optimization", "cursor" ]
Split UTF-8 encoded string got from unichr
1,808,223
<p>I have a set of unicode numbers , I need to convert them to UTF-8 and print the result in to split them in to hex values.</p> <p>eg: Unicode 0x80 should be converted to UTF-8 and printed as (0xc2,0x80)</p> <p>I tried following</p> <pre><code>str(unichr(0x80).encode('utf-8')).split(r'\x')[0] </code></pre> <p>But ...
0
2009-11-27T11:32:31Z
1,808,256
<p>You want like this? could be done with list comprehensions.</p> <pre><code>&gt;&gt;&gt; ["%x"%ord(x) for x in unichr(0x80).encode('utf-8')] ['c2', '80'] </code></pre>
2
2009-11-27T11:41:40Z
[ "python" ]
Split UTF-8 encoded string got from unichr
1,808,223
<p>I have a set of unicode numbers , I need to convert them to UTF-8 and print the result in to split them in to hex values.</p> <p>eg: Unicode 0x80 should be converted to UTF-8 and printed as (0xc2,0x80)</p> <p>I tried following</p> <pre><code>str(unichr(0x80).encode('utf-8')).split(r'\x')[0] </code></pre> <p>But ...
0
2009-11-27T11:32:31Z
1,808,261
<p>You try to split with <code>\x</code>, but <code>\x</code> doesn't exist in the string. <code>\xc2\x80</code> are just the escape codes (like <code>\n</code> for newline) on your screen, I think what you want is this:</p> <pre><code>print hex(ord(unichr(0x80).encode('utf-8')[0])) </code></pre>
1
2009-11-27T11:42:21Z
[ "python" ]
Split UTF-8 encoded string got from unichr
1,808,223
<p>I have a set of unicode numbers , I need to convert them to UTF-8 and print the result in to split them in to hex values.</p> <p>eg: Unicode 0x80 should be converted to UTF-8 and printed as (0xc2,0x80)</p> <p>I tried following</p> <pre><code>str(unichr(0x80).encode('utf-8')).split(r'\x')[0] </code></pre> <p>But ...
0
2009-11-27T11:32:31Z
1,808,266
<p>To generate a list of the hexadecimal values of the characters in your UTF8-encoded string, use the following:</p> <pre><code>&gt;&gt;&gt; [hex(ord(x)) for x in unichr(0x80).encode('utf-8')] ['0xc2', '0x80'] </code></pre>
2
2009-11-27T11:43:05Z
[ "python" ]
Getting error when INSERT into MySQL
1,808,455
<pre><code>_mysql_exceptions.Warning: Incorrect string value: '\xE7\xB9\x81\xE9\xAB\x94...' for column 'html' at row 1 def getSource(theurl, moved = 0): if moved == 1: theurl = urllib2.urlopen(theurl).geturl() urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) ...
3
2009-11-27T12:21:54Z
1,808,503
<p>You basically need to ensure proper a string encoding. E.g. the string you provide to django is not UTF-8 encoded and therefore some characters can't be resolved.</p> <p>Some helpful advice on how to find the encoding of the requested page can be found here: <a href="http://stackoverflow.com/questions/1020892/pytho...
3
2009-11-27T12:32:22Z
[ "python", "mysql", "html", "database", "django" ]
Getting error when INSERT into MySQL
1,808,455
<pre><code>_mysql_exceptions.Warning: Incorrect string value: '\xE7\xB9\x81\xE9\xAB\x94...' for column 'html' at row 1 def getSource(theurl, moved = 0): if moved == 1: theurl = urllib2.urlopen(theurl).geturl() urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) ...
3
2009-11-27T12:21:54Z
1,808,791
<p>There are 2 ways to go if you want to alter the character set in MySQL. First is the default of the database, see <a href="http://dev.mysql.com/doc/refman/5.0/en/alter-database.html" rel="nofollow">MySQL Alter database</a>, and the second is per-table: <a href="http://dev.mysql.com/doc/refman/5.0/en/charset-table.ht...
0
2009-11-27T13:31:03Z
[ "python", "mysql", "html", "database", "django" ]
Masquerading real module of a class
1,808,522
<p>Suppose you have the following layout for a python package</p> <pre><code>./a ./a/__init__.py ./a/_b.py </code></pre> <p>inside <code>__init__.py</code> you have</p> <pre><code>from _b import * </code></pre> <p>and inside _b.py you have</p> <pre><code>class B(object): pass </code></pre> <p>If you import from i...
3
2009-11-27T12:35:28Z
1,808,569
<p>try:</p> <pre><code>B.__module__= 'a' </code></pre> <p>Incidentally you probably want an absolute import:</p> <pre><code>from a._b import * </code></pre> <p>as relative imports without the new explicit dot syntax are going away (<a href="http://www.python.org/dev/peps/pep-0328/" rel="nofollow">see PEP 328</a>).<...
5
2009-11-27T12:45:04Z
[ "python" ]
Masquerading real module of a class
1,808,522
<p>Suppose you have the following layout for a python package</p> <pre><code>./a ./a/__init__.py ./a/_b.py </code></pre> <p>inside <code>__init__.py</code> you have</p> <pre><code>from _b import * </code></pre> <p>and inside _b.py you have</p> <pre><code>class B(object): pass </code></pre> <p>If you import from i...
3
2009-11-27T12:35:28Z
1,808,587
<p>You could set the <code>__module__</code> variable for <code>Class B</code></p> <pre><code>class B(object): pass B.__module__ = 'a' </code></pre> <blockquote> <p>For classes, functions, and methods, this attribute contains the name of the module in which the object was defined.</p> </blockquote> <p>Or define it...
2
2009-11-27T12:48:06Z
[ "python" ]
What is the default content-type/charset?
1,808,567
<p>According to this answer: <a href="http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode">urllib2 read to Unicode</a></p> <p>I have to get the content-type in order to change to unicode. However, some websites don't have a "charset". </p> <p>For example, the ['content-type'] for <a href="http:...
4
2009-11-27T12:44:51Z
1,808,607
<p><code>htmlSource=htmlSource.decode("utf8")</code> should work for most cases, except you are crawling non-english encoding sites.</p> <p>or you could write force decode function like this</p> <pre><code>def forcedecode(text): for x in ["utf8","sjis","cp1252","utf16"]: try:return text.decode(x) except...
0
2009-11-27T12:54:00Z
[ "python", "html", "unicode", "encoding" ]
What is the default content-type/charset?
1,808,567
<p>According to this answer: <a href="http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode">urllib2 read to Unicode</a></p> <p>I have to get the content-type in order to change to unicode. However, some websites don't have a "charset". </p> <p>For example, the ['content-type'] for <a href="http:...
4
2009-11-27T12:44:51Z
1,808,617
<p><em>In theory</em>, the default charset is <a href="http://www.w3.org/International/O-HTTP-charset" rel="nofollow">ISO-8859-1</a>. But often, this cannot be relied on. Websites which don’t send an explicit charset deserve to be reprimanded. Care to send off an angry email to the webmaster of Endgadget?</p>
2
2009-11-27T12:55:18Z
[ "python", "html", "unicode", "encoding" ]
What is the default content-type/charset?
1,808,567
<p>According to this answer: <a href="http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode">urllib2 read to Unicode</a></p> <p>I have to get the content-type in order to change to unicode. However, some websites don't have a "charset". </p> <p>For example, the ['content-type'] for <a href="http:...
4
2009-11-27T12:44:51Z
1,808,720
<blockquote> <p>Is there a default "encoding" (English, of course)...so that if nothing is found, I can just use that? </p> </blockquote> <p>No, there isn't. You must guess.</p> <p>Trivial approach: try and decode as <code>UTF-8</code>. If it works, great, it's probably UTF-8. If it doesn't, choose a most-likely en...
2
2009-11-27T13:15:59Z
[ "python", "html", "unicode", "encoding" ]
What is the default content-type/charset?
1,808,567
<p>According to this answer: <a href="http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode">urllib2 read to Unicode</a></p> <p>I have to get the content-type in order to change to unicode. However, some websites don't have a "charset". </p> <p>For example, the ['content-type'] for <a href="http:...
4
2009-11-27T12:44:51Z
1,808,810
<p>If there's no explicit content type, it should be ISO-8859-1 as stated earlier in the answers. Unfortunately that's not always the case, which is why browser developers spent some time on getting algorithms going that try to guess the content type based on the content of your page.</p> <p>Luckily for you, Mark Pilg...
0
2009-11-27T13:34:43Z
[ "python", "html", "unicode", "encoding" ]
What is the default content-type/charset?
1,808,567
<p>According to this answer: <a href="http://stackoverflow.com/questions/1020892/python-urllib2-read-to-unicode">urllib2 read to Unicode</a></p> <p>I have to get the content-type in order to change to unicode. However, some websites don't have a "charset". </p> <p>For example, the ['content-type'] for <a href="http:...
4
2009-11-27T12:44:51Z
1,808,854
<p>Well I just browsed the given URL, which redirects to</p> <pre><code>http://www.engadget.com/2009/11/23/apple-hits-back-at-verizon-in-new-iphone-ads-video </code></pre> <p>then hit Crtl-U (view source) in FireFox and it shows</p> <pre><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&g...
3
2009-11-27T13:42:05Z
[ "python", "html", "unicode", "encoding" ]
I just want to download this URL...but it is giving me an error! ...unicode.. (Python)
1,808,612
<pre><code>theurl = 'http://bit.ly/6IcCtf/' urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) urlResponse = urllib2.urlopen(urlReq) htmlSource = urlResponse.read() if unicode == 1: #print urlResponse.headers['content-type'] #encoding=urlResponse.headers['content-type'].split...
1
2009-11-27T12:54:28Z
1,808,642
<p>Not decode? <code>htmlSource = htmlSource.decode('utf8')</code></p> <p>decode mean "decode htmlSource from utf8 encoding"</p> <p>encode mean "encode htmlSource to utf8 encoding"</p> <p>since you are extracting the existing data (crawling from website), you need to decode it, and when you insert to mysql, you may...
3
2009-11-27T12:59:42Z
[ "python", "http", "unicode", "urllib2", "encode" ]
I just want to download this URL...but it is giving me an error! ...unicode.. (Python)
1,808,612
<pre><code>theurl = 'http://bit.ly/6IcCtf/' urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) urlResponse = urllib2.urlopen(urlReq) htmlSource = urlResponse.read() if unicode == 1: #print urlResponse.headers['content-type'] #encoding=urlResponse.headers['content-type'].split...
1
2009-11-27T12:54:28Z
1,808,644
<p>Probably you want to <em>decode</em> Utf8, not <em>encode</em> it:</p> <pre><code>htmlSource = htmlSource.decode('utf8') </code></pre>
1
2009-11-27T12:59:51Z
[ "python", "http", "unicode", "urllib2", "encode" ]
I just want to download this URL...but it is giving me an error! ...unicode.. (Python)
1,808,612
<pre><code>theurl = 'http://bit.ly/6IcCtf/' urlReq = urllib2.Request(theurl) urlReq.add_header('User-Agent',random.choice(agents)) urlResponse = urllib2.urlopen(urlReq) htmlSource = urlResponse.read() if unicode == 1: #print urlResponse.headers['content-type'] #encoding=urlResponse.headers['content-type'].split...
1
2009-11-27T12:54:28Z
1,808,688
<p>Your html data is a string that comes from the internet <strong>already encoded</strong> with some encoding. Before encoding it to <code>utf-8</code>, you <strong>must decode it first</strong>.</p> <p>Python is <strong><em>implicity</em></strong> trying to decode it (That's why you get a <code>UnicodeDecodeError</c...
5
2009-11-27T13:10:08Z
[ "python", "http", "unicode", "urllib2", "encode" ]
How can I conditionally execute code in a "with" block?
1,808,675
<p>I guess this is kinda abusing the feature, but I'm still curious whether it could be done - I want to do something like:</p> <pre><code>with conditional(a): print 1 </code></pre> <p>so that the <code>print 1</code> part is executed only if a==True. Is this possible?</p> <p>EDIT: Like people state below, this ...
0
2009-11-27T13:07:46Z
1,808,685
<pre><code>if a is True: print 1 </code></pre> <p><a href="http://docs.python.org/reference/compound%5Fstmts.html#the-with-statement" rel="nofollow"><code>with</code> statement</a> is intended to provide a reliable enter-exit context.</p>
4
2009-11-27T13:09:17Z
[ "python", "with-statement" ]
How can I conditionally execute code in a "with" block?
1,808,675
<p>I guess this is kinda abusing the feature, but I'm still curious whether it could be done - I want to do something like:</p> <pre><code>with conditional(a): print 1 </code></pre> <p>so that the <code>print 1</code> part is executed only if a==True. Is this possible?</p> <p>EDIT: Like people state below, this ...
0
2009-11-27T13:07:46Z
1,808,726
<p>The only way I see is to raise an exception in <code>conditional</code> if its argument is false. The <code>with</code> body will not be executed, but neither will any of the code that follows - until an <code>except</code> or <code>finally</code> clause, of course.</p>
2
2009-11-27T13:17:53Z
[ "python", "with-statement" ]
How can I conditionally execute code in a "with" block?
1,808,675
<p>I guess this is kinda abusing the feature, but I'm still curious whether it could be done - I want to do something like:</p> <pre><code>with conditional(a): print 1 </code></pre> <p>so that the <code>print 1</code> part is executed only if a==True. Is this possible?</p> <p>EDIT: Like people state below, this ...
0
2009-11-27T13:07:46Z
1,808,750
<p>There's no real reason to do that, since conditionals are already supplied using the <code>if</code> statement:</p> <pre><code>if a == True: print 1 </code></pre> <p>But, if you're just asking for <strong>fun</strong>, the answer is <strong>you can't</strong> really. To stop the <code>with</code> content from ...
8
2009-11-27T13:22:39Z
[ "python", "with-statement" ]
How can I conditionally execute code in a "with" block?
1,808,675
<p>I guess this is kinda abusing the feature, but I'm still curious whether it could be done - I want to do something like:</p> <pre><code>with conditional(a): print 1 </code></pre> <p>so that the <code>print 1</code> part is executed only if a==True. Is this possible?</p> <p>EDIT: Like people state below, this ...
0
2009-11-27T13:07:46Z
1,808,907
<p>Let's say I have class A with an __enter__ and an __exit__ function:</p> <pre><code>class A: def __init__(self, i): self.b = i def __exit__(*args, **kwargs): print "exit" def __enter__(*args, **kwargs): print "enter" </code></pre> <p>And a function B that will check if b in object c equa...
0
2009-11-27T13:52:31Z
[ "python", "with-statement" ]
Is it possible to script for data entry with Drupal?
1,808,721
<p>I'm planning on putting a store's inventory on a Drupal site and I'm wondering if it's possible to create a script (maybe in python/php?) to enter the data automatically to Drupal with CCK? Thanks in advance!</p>
3
2009-11-27T13:16:23Z
1,808,788
<p>CCK or otherwise, it's just a wellformed POST query (presumably), so sure, go for it.</p>
0
2009-11-27T13:30:20Z
[ "php", "python", "drupal", "data-entry" ]
Is it possible to script for data entry with Drupal?
1,808,721
<p>I'm planning on putting a store's inventory on a Drupal site and I'm wondering if it's possible to create a script (maybe in python/php?) to enter the data automatically to Drupal with CCK? Thanks in advance!</p>
3
2009-11-27T13:16:23Z
1,808,833
<p>The fastest and easiest thing would be to do the stuff with a little Drupal module you make for the case, instead of having to send lots of posts to the server and spend resources on node loads and what not.</p> <p>Anyways, what you need for this is quite similar to what mac answers <a href="http://stackoverflow.co...
2
2009-11-27T13:39:13Z
[ "php", "python", "drupal", "data-entry" ]
Is it possible to script for data entry with Drupal?
1,808,721
<p>I'm planning on putting a store's inventory on a Drupal site and I'm wondering if it's possible to create a script (maybe in python/php?) to enter the data automatically to Drupal with CCK? Thanks in advance!</p>
3
2009-11-27T13:16:23Z
1,808,844
<p>There are a couple of Drupal modules dedicated to different scenarios of external (mass) imports - check <a href="http://groups.drupal.org/node/21338" rel="nofollow">this overview</a> for a options/comparisons.</p> <p>If you have very specific needs, you could write your own module, using the existing ones and the ...
2
2009-11-27T13:40:21Z
[ "php", "python", "drupal", "data-entry" ]
Is it possible to script for data entry with Drupal?
1,808,721
<p>I'm planning on putting a store's inventory on a Drupal site and I'm wondering if it's possible to create a script (maybe in python/php?) to enter the data automatically to Drupal with CCK? Thanks in advance!</p>
3
2009-11-27T13:16:23Z
1,809,464
<p>Lots of good suggestions have been done by Henrik and Googletorp already.</p> <p>A few additional elements to consider to design your strategy:</p> <ol> <li>Are you going to do a full-fledged e-store (presumably realised with <a href="http://drupal.org/project/ubercart" rel="nofollow">ubercart</a>) or are you simp...
2
2009-11-27T15:50:56Z
[ "php", "python", "drupal", "data-entry" ]
Is it possible to script for data entry with Drupal?
1,808,721
<p>I'm planning on putting a store's inventory on a Drupal site and I'm wondering if it's possible to create a script (maybe in python/php?) to enter the data automatically to Drupal with CCK? Thanks in advance!</p>
3
2009-11-27T13:16:23Z
1,809,648
<p>If your source data is in MySQL I would be looking at the <a href="https://www.drupal.org/project/migrate" rel="nofollow">Migrate</a> module to create content. Here is an excerpt from its project page:</p> <blockquote> <p>... provides a flexible framework for migrating content into Drupal from other sources (e.g....
0
2009-11-27T16:31:12Z
[ "php", "python", "drupal", "data-entry" ]
Algorithm should I create a new thread?
1,808,806
<p>Is there an algorithm that checks whether creating a new thread pays off performance wise? I'll set a maximum of threads that can be created anyway but if I add just one task it wouldn't be an advantage to start a new thread for that. The programming language I use is python.</p> <h2>Edit 1#</h2> <p>Can this quest...
0
2009-11-27T13:33:46Z
1,808,813
<p>Testing will tell you.</p> <p>Basicly try, and benchmark. </p>
0
2009-11-27T13:35:11Z
[ "python", "math", "multithreading" ]
Algorithm should I create a new thread?
1,808,806
<p>Is there an algorithm that checks whether creating a new thread pays off performance wise? I'll set a maximum of threads that can be created anyway but if I add just one task it wouldn't be an advantage to start a new thread for that. The programming language I use is python.</p> <h2>Edit 1#</h2> <p>Can this quest...
0
2009-11-27T13:33:46Z
1,808,851
<p>Rule of thumb: if a thread is going to do input/output, it may be worth separating it. </p> <p>If it's doing number-crunching then optimum number of threads is number of CPUs.</p>
3
2009-11-27T13:41:52Z
[ "python", "math", "multithreading" ]
Algorithm should I create a new thread?
1,808,806
<p>Is there an algorithm that checks whether creating a new thread pays off performance wise? I'll set a maximum of threads that can be created anyway but if I add just one task it wouldn't be an advantage to start a new thread for that. The programming language I use is python.</p> <h2>Edit 1#</h2> <p>Can this quest...
0
2009-11-27T13:33:46Z
1,808,864
<p>There is no general answer for this ... yet. But there is a trend. Since computers get more and more CPU cores (try to buy a new single CPU PC ...), using threads becomes the de-facto standard.</p> <p>So if you have some work which can be parallelized, then by all means use the threading module and create a pool of...
0
2009-11-27T13:44:45Z
[ "python", "math", "multithreading" ]