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
pycurl request exist in header function?
525,405
<p>in C do return -1 when i want to cancel the download in either the header or the write function. In pycurl i get this error</p> <pre><code>pycurl.error: invalid return value for write callback -1 17 </code></pre> <p>I dont know what the 17 means but what am i not doing correctly?</p>
2
2009-02-08T08:32:58Z
525,481
<p>from pycurl.c: </p> <pre><code>else if (PyInt_Check(result)) { long obj_size = PyInt_AsLong(result); if (obj_size &lt; 0 || obj_size &gt; total_size) { PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size); goto verbose_error; } </...
3
2009-02-08T10:00:13Z
[ "python", "libcurl", "pycurl" ]
pycurl request exist in header function?
525,405
<p>in C do return -1 when i want to cancel the download in either the header or the write function. In pycurl i get this error</p> <pre><code>pycurl.error: invalid return value for write callback -1 17 </code></pre> <p>I dont know what the 17 means but what am i not doing correctly?</p>
2
2009-02-08T08:32:58Z
2,304,840
<pre><code>import pycurl import StringIO c = pycurl.Curl() s = StringIO.StringIO() c.setopt(pycurl.URL, url) c.setopt(pycurl.HEADER, True) c.setopt(pycurl.NOBODY, True) c.setopt(pycurl.WRITEFUNCTION, s.write) c.perform() print(s.getvalue()) </code></pre>
1
2010-02-21T05:05:28Z
[ "python", "libcurl", "pycurl" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,639
<p><code>\b</code> is word boundary, which can be a white space, the beginning of a line or a non-alphanumeric symbol (<code>\bGBP\b</code>).</p>
8
2009-02-08T12:42:22Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,642
<p>Yes, why not?</p> <pre><code>re.sub(u'^\W*GBP... </code></pre> <p>matches the start of the string, 0 or more whitespaces, then GBP...</p> <p><em>edit</em>: Oh, I think you want alternation, use the <code>|</code>:</p> <pre><code>re.sub(u'(^|\W)GBP... </code></pre>
1
2009-02-08T12:43:25Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,645
<p>You can always trim leading and trailing whitespace from the token before you search if it's not a matching/grouping situation that requires the full line.</p>
0
2009-02-08T12:44:29Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,649
<p>This replaces GBP if it's preceded by the start of a string or a <a href="http://www.regular-expressions.info/wordboundaries.html" rel="nofollow">word boundary</a> (which the start of a string already is), and after GBP comes a numeric value or a word boundary: </p> <pre><code>re.sub(u'\bGBP(?=\b|\d)', u'£', text)...
6
2009-02-08T12:46:39Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,650
<p>Use the OR "<code>|</code>" operator:</p> <pre><code>&gt;&gt;&gt; re.sub(r'(^|\W)GBP([\W\d])', u'\g&lt;1&gt;£\g&lt;2&gt;', text) u'\xa3 5 Off when you spend \xa375.00' </code></pre>
30
2009-02-08T12:46:54Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,651
<p>I think you're looking for <code>'(^|\W)GBP([\W\d])'</code></p>
2
2009-02-08T12:47:27Z
[ "python", "regex" ]
Regular expression: match start or whitespace
525,635
<p><strong>Can a regular expression match whitespace <em>or</em> the start of a string?</strong></p> <p>I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.</p> <pre><code>...
25
2009-02-08T12:38:08Z
525,683
<p>It works in Perl:</p> <pre><code>$text = 'GBP 5 off when you spend GBP75'; $text =~ s/(\W|^)GBP([\W\d])/$1\$$2/g; printf "$text\n"; </code></pre> <p>The output is:</p> <pre><code>$ 5 off when you spend $75 </code></pre> <p>Note that I stipulated that the match should be global, to get all occurrences.</p>
0
2009-02-08T13:10:56Z
[ "python", "regex" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
525,781
<p>You might want to look at <a href="http://docs.python.org/library/cookielib.html" rel="nofollow">cookielib</a>.</p>
4
2009-02-08T14:15:20Z
[ "python", "cookies" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
525,966
<p>I believe you mean having a Python script that tries to speak HTTP. I suggest you to use a high-level library that handles cookies automatically. pycurl, mechanize, twill - you choose.</p> <p>For Nikhil Chelliah:</p> <p>I don't see what's not clear here.</p> <p><strong>Accepting</strong> a cookie happens client-s...
1
2009-02-08T16:14:19Z
[ "python", "cookies" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
525,982
<p>There's the cookielib library. You can also implement your own cookie storage and policies, the cookies are found in the set-cookie header of the response (Set-Cookie: name=value), then you send the back to a server in one or more Cookie headers in the request (Cookie: name=value).</p>
0
2009-02-08T16:24:59Z
[ "python", "cookies" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
526,013
<p>It's unclear whether you want a client-side or a server-side solution.</p> <p>For client-side, <a href="http://www.docs.python.org/library/cookielib.html" rel="nofollow">cookielib</a> will work fine. <a href="http://stackoverflow.com/questions/189555/how-to-use-python-to-login-to-a-webpage-and-retrieve-cookies-for...
1
2009-02-08T16:49:40Z
[ "python", "cookies" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
526,695
<p>Try this:</p> <pre><code>import urllib2 import cookielib jar = cookielib.FileCookieJar("cookies") opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) print "Currently have %d cookies" % len(jar) print "Getting page" response = opener.open("http://google.com") print response.headers print "Got page" p...
18
2009-02-08T23:49:44Z
[ "python", "cookies" ]
Accept Cookies in Python
525,773
<p>How can I accept cookies in a python script?</p>
10
2009-02-08T14:09:04Z
13,911,060
<p><strong>The easiest way is to use <a href="http://docs.python-requests.org/" rel="nofollow">requests</a> library.</strong></p> <pre><code>import requests url = 'http://www.google.com/doodles/' r = requests.get(url) print r.cookies </code></pre>
4
2012-12-17T09:02:21Z
[ "python", "cookies" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,262
<p>The simplest thing to do is to use random.choice (which uses a uniform distribution) and vary the frequency of occurrence on the object in the source collection.</p> <pre><code>&gt;&gt;&gt; random.choice([1, 2, 3, 4]) 4 </code></pre> <p>... vs:</p> <pre><code>&gt;&gt;&gt; random.choice([1, 1, 1, 1, 2, 2, 2, 3, 3,...
1
2009-02-08T20:01:37Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,277
<p>You want to give each object a weight. The bigger the weight the more likely it will happen. More precisely probx =weight/sum_all_weights.</p> <p>Then generate a random number in the range 0 to sum_all_weights and map it to each object.</p> <p>This code allows you to generate a random index and it is mapped when t...
2
2009-02-08T20:08:31Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,284
<p>I would use this <a href="http://code.activestate.com/recipes/117241/" rel="nofollow">recipe</a> . You will need to add a weight to your objects, but that is just a simple ratio and put them in a list of tuples (object, conviction/(sum of convictions)). This should be easy to do using a list comprehension.</p>
2
2009-02-08T20:16:43Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,295
<p>I suggest you port <a href="http://w-shadow.com/blog/2008/12/10/fast-weighted-random-choice-in-php/" rel="nofollow">this PHP implementation of weighted random</a> to Python. In particular, the binary-search-based second algorithm helps address your speed concerns.</p>
2
2009-02-08T20:20:31Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,300
<p><a href="http://code.activestate.com/recipes/117241/">This activestate recipe</a> gives an easy-to-follow approach, specifically the version in the comments that doesn't require you to pre-normalize your weights:</p> <pre><code>import random def weighted_choice(items): """items is a list of tuples in the form ...
25
2009-02-08T20:26:28Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,308
<p>Here is a classic way to do it, in pseudocode, where random.random() gives you a random float from 0 to 1.</p> <pre><code>let z = sum of all the convictions let choice = random.random() * z iterate through your objects: choice = choice - the current object's conviction if choice &lt;= 0, return this object...
2
2009-02-08T20:30:14Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,319
<p>A very easy and simple way of doing this is to set weights for each of the values, and it wouldn't require much memory.</p> <p>You could probably use a hash/dictionary to do this.</p> <p>What you'll want to do is to have the random number, <em>x</em>, multiplied and summed over the entire set of things you want se...
1
2009-02-08T20:35:52Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
526,843
<p>In comments on the original post, Nicholas Leonard suggests that both the exchanging and the sampling need to be fast. Here's an idea for that case; I haven't tried it.</p> <p>If only sampling had to be fast, we could use an array of the values together with the running sum of their probabilities, and do a binary s...
6
2009-02-09T01:12:33Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
529,790
<p>Here's a better answer for a special probability distribution, the one <a href="http://stackoverflow.com/questions/526255/probability-distribution-in-python/526585#526585">Rex Logan's answer</a> seems to be geared at. The distribution is like this: each object has an integer weight between 0 and 100, and its probabi...
1
2009-02-09T20:31:49Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
1,053,635
<p>I was needed in faster functions, for non very large numbers. So here it is, in Visual C++:</p> <pre><code>#undef _DEBUG // disable linking with python25_d.dll #include &lt;Python.h&gt; #include &lt;malloc.h&gt; #include &lt;stdlib.h&gt; static PyObject* dieroll(PyObject *, PyObject *args) { PyObject *list; ...
0
2009-06-27T21:12:33Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
2,051,148
<p>(A year later) <a href="http://code.activestate.com/recipes/576564" rel="nofollow">Walker's alias method for random objects with different probablities</a> is very fast and very simple</p>
1
2010-01-12T17:58:54Z
[ "python", "algorithm", "random", "distribution", "probability" ]
Probability distribution in Python
526,255
<p>I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module th...
17
2009-02-08T19:52:22Z
21,211,673
<p><em><strong>About 3 years later...</em></strong></p> <p>If you use numpy, perhaps the simplest option is to use <a href="http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html" rel="nofollow"><code>np.random.choice</code></a>, which takes a list of possible values, and an optional sequence...
1
2014-01-19T00:25:27Z
[ "python", "algorithm", "random", "distribution", "probability" ]
pycurl cancel a transfer and try & except
526,325
<p>How do i cancel a transfer in pycurl? i use to return -1 in libcurl but pycurl doesnt seem to like that ("pycurl.error: invalid return value for write callback -1 17") return 0 doesnt work either, i get "error: (23, 'Failed writing body')" . Also how do i do a try/except with pycurl? i dont see any examples online n...
1
2009-02-08T20:39:16Z
622,703
<p>Example code would help here. Judging from the error message, and grepping for it in the source code, you've set up a write callback. This is configured, I think, by CURLOPT_WRITEFUNCTION, and the documentation for that says:</p> <blockquote> <p>Return the number of bytes actually taken care of. If that amount ...
3
2009-03-07T23:14:21Z
[ "python", "pycurl" ]
Django form fails validation on a unique field
526,457
<p>I have a simple model that is defined as:</p> <pre><code>class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) </code></pre> <p>and the form:</p> <pre><code>class ArticleForm(ModelForm): class Meta: model = Arti...
16
2009-02-08T21:36:23Z
526,477
<p>All i can guess is that you are getting an object to fill a form, and trying to save it again. </p> <p>Try using a ModelForm, and intantiate it with desired object.</p>
1
2009-02-08T21:47:58Z
[ "python", "django" ]
Django form fails validation on a unique field
526,457
<p>I have a simple model that is defined as:</p> <pre><code>class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) </code></pre> <p>and the form:</p> <pre><code>class ArticleForm(ModelForm): class Meta: model = Arti...
16
2009-02-08T21:36:23Z
526,484
<p>It appears that your SlugField is returning None and because a null/blank slug already exists somewhere in the database, its giving an 'already exists' error. It seems like your slug field isn't saving correctly at all.</p>
1
2009-02-08T21:49:46Z
[ "python", "django" ]
Django form fails validation on a unique field
526,457
<p>I have a simple model that is defined as:</p> <pre><code>class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) </code></pre> <p>and the form:</p> <pre><code>class ArticleForm(ModelForm): class Meta: model = Arti...
16
2009-02-08T21:36:23Z
526,656
<p>I don't think you are actually updating an existing article, but instead creating a new one, presumably with more or less the same content, especially the slug, and thus you will get an error. It is a bit strange that you don't get better error reporting, but also I do not know what the rest of your view looks like....
23
2009-02-08T23:33:29Z
[ "python", "django" ]
Django form fails validation on a unique field
526,457
<p>I have a simple model that is defined as:</p> <pre><code>class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) </code></pre> <p>and the form:</p> <pre><code>class ArticleForm(ModelForm): class Meta: model = Arti...
16
2009-02-08T21:36:23Z
658,765
<p>I was also searching for a way to update an existing record, even tried <code>form.save(force_update=True)</code> but received errors?? Finally by trial &amp; error managed to update existing record. Below codes tested working. Hope this helps...</p> <h1>models.py from djangobook</h1> <pre><code>class Author(model...
4
2009-03-18T15:27:47Z
[ "python", "django" ]
subprocess.Popen error
526,734
<p>I am running an msi installer in silent mode and caching logs in the specific file. The following is the command i need to execute.</p> <p><code>C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log"</code></p> <p>I used:</p> <pre><code>subprocess.Popen(['C:\Program Files\ My Installer\Se...
3
2009-02-09T00:10:49Z
526,771
<p>The problem is that you effectively supply Setup.exe with only one argument. Don't think in terms of the shell, the string you hand over as an argument does not get splitted on spaces anymore, that's your duty!</p> <p>So, if you are absolutely sure that "/qn /lv %TEMP%\log_silent.log" should be one argument, then ...
2
2009-02-09T00:35:39Z
[ "python", "subprocess", "popen" ]
subprocess.Popen error
526,734
<p>I am running an msi installer in silent mode and caching logs in the specific file. The following is the command i need to execute.</p> <p><code>C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log"</code></p> <p>I used:</p> <pre><code>subprocess.Popen(['C:\Program Files\ My Installer\Se...
3
2009-02-09T00:10:49Z
526,775
<p>Try putting each argument in its own string (reformatted for readability):</p> <pre><code>cmd = ['C:\Program Files\ My Installer\Setup.exe', '/s', '/v', '"/qn', '/lv', '%TEMP%\log_silent.log"'] subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] </code></pre> <p>I hav...
0
2009-02-09T00:38:00Z
[ "python", "subprocess", "popen" ]
subprocess.Popen error
526,734
<p>I am running an msi installer in silent mode and caching logs in the specific file. The following is the command i need to execute.</p> <p><code>C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log"</code></p> <p>I used:</p> <pre><code>subprocess.Popen(['C:\Program Files\ My Installer\Se...
3
2009-02-09T00:10:49Z
526,781
<p>The problem is very subtle.</p> <p>You're executing the program directly. It gets:</p> <pre><code>argv[0] = "C:\Program Files\ My Installer\Setup.exe" argv[1] = /s /v "/qn /lv %TEMP%\log_silent.log" </code></pre> <p>Whereas it should be:</p> <pre><code>argv[1] = "/s" argv[2] = "/v" argv[3] = "/qn" argv[4] = "/lv...
8
2009-02-09T00:40:21Z
[ "python", "subprocess", "popen" ]
subprocess.Popen error
526,734
<p>I am running an msi installer in silent mode and caching logs in the specific file. The following is the command i need to execute.</p> <p><code>C:\Program Files\ My Installer\Setup.exe /s /v "/qn /lv %TEMP%\log_silent.log"</code></p> <p>I used:</p> <pre><code>subprocess.Popen(['C:\Program Files\ My Installer\Se...
3
2009-02-09T00:10:49Z
526,830
<p>You said:</p> <pre><code>subprocess.Popen(['C:\Program Files\ My Installer\Setup.exe', '/s /v "/qn /lv %TEMP%\log_silent.log"'],stdout=subprocess.PIPE).communicate()[0] </code></pre> <p>Is the directory name really " My Installer" (with a leading space)?</p> <p>Also, as a general rule, you should use forward slas...
0
2009-02-09T01:03:07Z
[ "python", "subprocess", "popen" ]
How to add custom fields to InlineFormsets?
526,795
<p>I'm trying to add custom fields to an InlineFormset using the following code, but the fields won't show up in the Django Admin. Is the InlineFormset too locked down to allow this? My print "ding" test fires as expected, I can print out the form.fields and see them all there, but the actual fields are never rendere...
6
2009-02-09T00:47:25Z
527,903
<pre><code>model = models.Progress </code></pre> <p>In the admin there will be only the fields defined in this <em>Progress</em> model. You have no fields/fieldsets option overwriting it.</p> <p>If you want to add the new ones, there are two options:</p> <ul> <li>In the model definition, add those new additional fie...
1
2009-02-09T12:12:45Z
[ "python", "django", "field", "formset", "inline-formset" ]
How to add custom fields to InlineFormsets?
526,795
<p>I'm trying to add custom fields to an InlineFormset using the following code, but the fields won't show up in the Django Admin. Is the InlineFormset too locked down to allow this? My print "ding" test fires as expected, I can print out the form.fields and see them all there, but the actual fields are never rendere...
6
2009-02-09T00:47:25Z
2,250,977
<p>I did it another way:</p> <p>forms.py:</p> <pre><code>from django import forms class ItemAddForm(forms.ModelForm): my_new_field = forms.IntegerField(initial=1, label='quantity') class Meta: model = Item </code></pre> <p>admin.py:</p> <pre><code>from django.contrib import admin from forms import *...
4
2010-02-12T10:06:37Z
[ "python", "django", "field", "formset", "inline-formset" ]
How to add custom fields to InlineFormsets?
526,795
<p>I'm trying to add custom fields to an InlineFormset using the following code, but the fields won't show up in the Django Admin. Is the InlineFormset too locked down to allow this? My print "ding" test fires as expected, I can print out the form.fields and see them all there, but the actual fields are never rendere...
6
2009-02-09T00:47:25Z
26,925,774
<p>You can do it by another way (Dynamic forms):</p> <p><strong>admin.py</strong></p> <pre><code>class ProgressInline(admin.TabularInline): model = models.Progress extra = 8 def get_formset(self, request, obj=None, **kwargs): extra_fields = {'my_field': forms.CharField()} kwargs['form'] =...
1
2014-11-14T08:27:09Z
[ "python", "django", "field", "formset", "inline-formset" ]
python console intrupt? and cross platform threads
526,955
<p>I want my app to loop in python but have a way to quit. Is there a way to get input from the console, scan it for letter q and quick when my app is ready to quit? in C i would just create a pthread that waits for cin, scans, locks a global quit var, change, unlock and exit the thread allowing my app to quit when its...
0
2009-02-09T02:07:21Z
527,014
<p>use the threading module to make a thread class.</p> <pre><code>import threading; class foo(threading.Thread): def __init__(self): #initialize anything def run(self): while True: str = raw_input("input something"); class bar: def __init__(self) self.thread = foo(); ...
1
2009-02-09T02:47:34Z
[ "python", "multithreading", "console", "quit" ]
python console intrupt? and cross platform threads
526,955
<p>I want my app to loop in python but have a way to quit. Is there a way to get input from the console, scan it for letter q and quick when my app is ready to quit? in C i would just create a pthread that waits for cin, scans, locks a global quit var, change, unlock and exit the thread allowing my app to quit when its...
0
2009-02-09T02:07:21Z
527,075
<p>Creating a new thread is easy enough – the threading module will help you out. You may want to make it daemonic (if you have other ways of exiting your program). I <em>think</em> you can change a variable without locking, too – python implements its own threads, and I'm fairly sure something like <code>self.ru...
1
2009-02-09T03:43:15Z
[ "python", "multithreading", "console", "quit" ]
Dynamic data in postgresql
527,013
<p>I intend to have a python script do many UPDATEs per second on 2,433,000 rows. I am currently trying to keep the dynamic column in python as a value in a python dict. Yet to keep my python dict synchronized with changes in the other columns is becoming more and more difficult or nonviable.</p> <p>I know I could put...
1
2009-02-09T02:46:33Z
527,220
<p>PostgreSQL supports asynchronous notifications using the <a href="http://www.postgresql.org/docs/8.3/static/sql-listen.html" rel="nofollow">LISTEN</a> and <a href="http://www.postgresql.org/docs/8.1/static/sql-notify.html" rel="nofollow">NOTIFY</a> commands. An application (client) LISTENs for a notification using a...
3
2009-02-09T06:04:10Z
[ "python", "postgresql", "performance", "dynamic-data", "vacuum" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,145
<p><a href="http://en.wikipedia.org/wiki/Mu_(negative" rel="nofollow">Mu</a></p>
3
2009-02-09T04:53:55Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,146
<p>Neither. Try Scheme. Or Haskell. or C. or a book.</p>
7
2009-02-09T04:54:20Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,149
<p>Neither <em>language</em> will expose a student to computer science concepts. That's up to the instructor (or motivated student) – where will they take the learning experience?</p> <p>[I'm assuming here that by "computer science", you mean algorithms and data structures (and related topics); if instead you mean ...
7
2009-02-09T04:55:42Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,152
<p>It's not about the language, it's about what you do with it. You can learn about virtually any CS concept in either Python or Java (or anything else), although there are definitely some concepts that are much better suited for one or another - for example, functional programming (e.g. the <code>map</code> and <code>...
14
2009-02-09T04:57:32Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,161
<p>Computer Science is fairly language agnostic. Both Python and Java support multiple programming paradigms. Python supports object-oriented, imperative, and functional, while Java supports object-oriented, imperative, and structured. Python is dynamically typed while Java is statically typed.</p> <p>I could go on...
4
2009-02-09T05:05:48Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,170
<p>C &lt;-- </p>
2
2009-02-09T05:13:25Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,182
<p><a href="http://www.clojure.org/" rel="nofollow">Clojure</a> or <a href="http://www.haskell.org/" rel="nofollow">Haskell</a></p>
1
2009-02-09T05:23:15Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,235
<p>I learned C++ first and can't think of a better learning tool. If you want to learn CS rewrite the STL.</p>
2
2009-02-09T06:17:34Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
527,783
<p>You have mentioned computer science concepts but that is too vague. IMHO you need to define what concepts you want to learn (say is it algorithms or OO design) and then work with either Java or Python to strengthen those concepts. </p> <p>If you intend to learn design patterns then I would suggest Java (at least f...
1
2009-02-09T11:26:27Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
528,604
<p>Strictly speaking neither language is going to help much with <em>computer science</em> concepts, if by this we mean algorithms, data structures and the like. Such things are largely independent of language However there are some <em>programming</em> concepts which are not language independent. Joel talks a fair bit...
1
2009-02-09T15:26:32Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
528,919
<p>Just pick one language, and start learning by solving a problem most relevant to you. I don't think that a debate is needed in which language should you learn first.</p>
1
2009-02-09T16:46:59Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
871,027
<p>Pick the one you like. The important thing is not stop learning or giving up because every language you learn will make you a better coder. Lots of knowledge are common between them. Of course there are lots of differences, but do not mind them yet. No language is perfect, or no language is the solution for all prob...
0
2009-05-15T21:56:55Z
[ "java", "python", "programming-languages" ]
Python or java which language will exposed a self taught programmer to more computer science concept?
527,134
<p>Of the two which one would exposed someone just learning to program to more computer science concept/problems?</p>
6
2009-02-09T04:48:10Z
15,336,592
<p><a href="http://mitpress.mit.edu/sicp/full-text/book/book.html" rel="nofollow">Scheme</a> This book will teach you all the fundamental concepts of computer programming (I wish I had read this book before :)</p>
1
2013-03-11T10:44:36Z
[ "java", "python", "programming-languages" ]
Intercepting stdout of a subprocess while it is running
527,197
<p>If this is my subprocess:</p> <pre><code>import time, sys for i in range(200): sys.stdout.write( 'reading %i\n'%i ) time.sleep(.02) </code></pre> <p>And this is the script controlling and modifying the output of the subprocess:</p> <pre><code>import subprocess, time, sys print 'starting' proc = subproce...
21
2009-02-09T05:43:35Z
527,202
<p>Process output is buffered. On more UNIXy operating systems (or Cygwin), the <A HREF="http://www.noah.org/wiki/Pexpect">pexpect</A> module is available, which recites all the necessary incantations to avoid buffering-related issues. However, these incantations require a working <A HREF="http://docs.python.org/librar...
6
2009-02-09T05:49:20Z
[ "python", "process", "subprocess", "stdout", "popen" ]
Intercepting stdout of a subprocess while it is running
527,197
<p>If this is my subprocess:</p> <pre><code>import time, sys for i in range(200): sys.stdout.write( 'reading %i\n'%i ) time.sleep(.02) </code></pre> <p>And this is the script controlling and modifying the output of the subprocess:</p> <pre><code>import subprocess, time, sys print 'starting' proc = subproce...
21
2009-02-09T05:43:35Z
527,229
<p>As Charles already mentioned, the problem is buffering. I ran in to a similar problem when writing some modules for SNMPd, and solved it by replacing stdout with an auto-flushing version.</p> <p>I used the following code, inspired by some posts on ActiveState:</p> <pre><code>class FlushFile(object): """Write-o...
14
2009-02-09T06:12:49Z
[ "python", "process", "subprocess", "stdout", "popen" ]
How to debug deadlock with python?
527,296
<p>I am developing a multi-threading application, which is deadlocking. </p> <p>I am using Visual C++ Express 2008 to trace the program. Once the deadlock occurs, I just pause the program and trace. I found that when deadlock occurs, there will be two threads called python from my C++ extension. </p> <p>All of them u...
4
2009-02-09T06:49:07Z
527,354
<p>If you can compile your extension module with gcc (for example, by using <a href="http://cygwin.com/">Cygwin</a>), you could use gdb and the <a href="http://wiki.python.org/moin/DebuggingWithGdb">pystack</a> gdb macro to get Python stacks in that situation. I don't know if it would be possible to do something equiva...
5
2009-02-09T07:33:28Z
[ "python", "multithreading", "debugging", "deadlock" ]
How to modify existing panels in Maya using MEL or Python?
527,314
<p>I've been writing tools in Maya for years using MEL and Python. I'd consider myself an expert in custom window/gui design in Maya except for one area; modifying existing panels and editors.</p> <p>Typically, I'm building tools that need totally custom UIs, so its customary for me to build them from scratch. Howev...
1
2009-02-09T07:05:27Z
551,109
<p>Have you tried searching ui item names in MEL files under maya installation directory? It should be one of the MEL scripts included, and from there you can just modify it.</p>
1
2009-02-15T16:03:11Z
[ "python", "user-interface", "maya", "panels", "mel" ]
How to modify existing panels in Maya using MEL or Python?
527,314
<p>I've been writing tools in Maya for years using MEL and Python. I'd consider myself an expert in custom window/gui design in Maya except for one area; modifying existing panels and editors.</p> <p>Typically, I'm building tools that need totally custom UIs, so its customary for me to build them from scratch. Howev...
1
2009-02-09T07:05:27Z
1,045,794
<p>having just stumbled across your question, have you tried Digital Tutors Artists Guide to MEL? Chapters 19-22 describe step by step how to create your own custom GUI's and windows in Maya, here's the link: <a href="http://www.digitaltutors.com/store/home.php?cat=82" rel="nofollow">http://www.digitaltutors.com/stor...
1
2009-06-25T19:33:59Z
[ "python", "user-interface", "maya", "panels", "mel" ]
How to modify existing panels in Maya using MEL or Python?
527,314
<p>I've been writing tools in Maya for years using MEL and Python. I'd consider myself an expert in custom window/gui design in Maya except for one area; modifying existing panels and editors.</p> <p>Typically, I'm building tools that need totally custom UIs, so its customary for me to build them from scratch. Howev...
1
2009-02-09T07:05:27Z
3,135,835
<p>Old post, but maybe someone still wants to find out. </p> <p>I wrote this script at least 30 years ago: <a href="http://www.creativecrash.com/maya/downloads/scripts-plugins/interface-display/c/guihelper" rel="nofollow">http://www.creativecrash.com/maya/downloads/scripts-plugins/interface-display/c/guihelper</a></p>...
2
2010-06-28T20:18:21Z
[ "python", "user-interface", "maya", "panels", "mel" ]
How to modify existing panels in Maya using MEL or Python?
527,314
<p>I've been writing tools in Maya for years using MEL and Python. I'd consider myself an expert in custom window/gui design in Maya except for one area; modifying existing panels and editors.</p> <p>Typically, I'm building tools that need totally custom UIs, so its customary for me to build them from scratch. Howev...
1
2009-02-09T07:05:27Z
10,439,595
<p>The easy way can modify existing Maya code and put it in you user/script. You can use whatIs to get the script name. Say for eg: </p> <pre><code>whatIs "layerEditor"; </code></pre> <p>Result is <code>./scripts/others/layerEditor.mel //</code> .But now you can use wrapping instance with PyQt also.</p>
3
2012-05-03T21:30:04Z
[ "python", "user-interface", "maya", "panels", "mel" ]
input and thread problem, python
527,420
<p>I am doing something like this in python</p> <pre><code>class MyThread ( threading.Thread ): def run (s): try: s.wantQuit = 0 while(not s.wantQuit): button = raw_input() if button == "q": s.wantQuit=1 except KeyboardInte...
0
2009-02-09T08:34:41Z
527,433
<p>just tried the code to make sure, but this does do what it's supposed to... you can type q and enter in to the console and make the application quit before a=0 (so it says hey less then 5 times)</p> <p>I don't know what you mean by the raw_input dialog, raw_input normally just takes info from stdin</p>
0
2009-02-09T08:49:10Z
[ "python", "multithreading" ]
input and thread problem, python
527,420
<p>I am doing something like this in python</p> <pre><code>class MyThread ( threading.Thread ): def run (s): try: s.wantQuit = 0 while(not s.wantQuit): button = raw_input() if button == "q": s.wantQuit=1 except KeyboardInte...
0
2009-02-09T08:34:41Z
527,437
<p>You mean the while loop runs before the thread? Well, you can't predict this unless you synchronize it. No one guarantees you that the thread will run before or after that while loop. But if it's being blocked for 5 seconds that's akward - the thread should have been pre-empted by then.</p> <p>Also, since you're fi...
1
2009-02-09T08:51:08Z
[ "python", "multithreading" ]
input and thread problem, python
527,420
<p>I am doing something like this in python</p> <pre><code>class MyThread ( threading.Thread ): def run (s): try: s.wantQuit = 0 while(not s.wantQuit): button = raw_input() if button == "q": s.wantQuit=1 except KeyboardInte...
0
2009-02-09T08:34:41Z
527,445
<p>The behaviour here is not what you described. Look at those sample outputs I got:</p> <p>1st: pressing <code>q&lt;ENTER&gt;</code> as fast as possible:</p> <pre><code>hey q </code></pre> <p>2nd: wait a bit before pressing <code>q&lt;ENTER&gt;</code>:</p> <pre><code>hey hey hey q </code></pre> <p>3rd: Don't touc...
1
2009-02-09T08:54:56Z
[ "python", "multithreading" ]
input and thread problem, python
527,420
<p>I am doing something like this in python</p> <pre><code>class MyThread ( threading.Thread ): def run (s): try: s.wantQuit = 0 while(not s.wantQuit): button = raw_input() if button == "q": s.wantQuit=1 except KeyboardInte...
0
2009-02-09T08:34:41Z
528,259
<p>huperboreean has your answer. The thread is still being started when the for loop is executed.</p> <p>You want to check that a thread is started before moving into your loop. You could simplify the thread to monitor raw_input, and return when a 'q' is entered. This will kill the thread.</p> <p>You main for loop c...
0
2009-02-09T14:09:03Z
[ "python", "multithreading" ]
How to deploy a Python application with libraries as source with no further dependencies?
527,510
<p><strong>Background</strong>: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directo...
12
2009-02-09T09:20:17Z
527,531
<p>Just use <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a> - it is a tool to create isolated Python environments. You can create a set-up script and distribute the whole bunch if you want.</p>
9
2009-02-09T09:28:04Z
[ "python", "deployment", "layout", "bootstrapping" ]
How to deploy a Python application with libraries as source with no further dependencies?
527,510
<p><strong>Background</strong>: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directo...
12
2009-02-09T09:20:17Z
527,872
<p>"I dislike the fact that developers (or me starting on a clean new machine) have to jump through the distutils hoops of having to install the libraries locally before they can get started"</p> <p>Why?</p> <p>What -- specifically -- is wrong with this?</p> <p>You did it to create the project. Your project is so p...
8
2009-02-09T12:01:16Z
[ "python", "deployment", "layout", "bootstrapping" ]
How to deploy a Python application with libraries as source with no further dependencies?
527,510
<p><strong>Background</strong>: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directo...
12
2009-02-09T09:20:17Z
527,934
<p>I agree with the answers by Nosklo and S.Lott. (+1 to both)</p> <p>Can I just add that what you want to do is actually a <strong>terrible idea</strong>.</p> <p>If you genuinely want people to hack on your code, they will need some understanding of the libraries involved, how they work, what they are, where they co...
0
2009-02-09T12:24:30Z
[ "python", "deployment", "layout", "bootstrapping" ]
How to deploy a Python application with libraries as source with no further dependencies?
527,510
<p><strong>Background</strong>: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directo...
12
2009-02-09T09:20:17Z
528,064
<p>I sometimes use the approach I describe below, for the exact same reason that @Boris states: I would prefer that the use of some code is as easy as a) svn checkout/update - b) go.</p> <p>But for the record:</p> <ul> <li>I use virtualenv/easy_install most of the time.</li> <li>I agree to a certain extent to the cri...
8
2009-02-09T13:05:46Z
[ "python", "deployment", "layout", "bootstrapping" ]
How to deploy a Python application with libraries as source with no further dependencies?
527,510
<p><strong>Background</strong>: I have a small Python application that makes life for developers releasing software in our company a bit easier. I build an executable for Windows using py2exe. The application as well as the binary are checked into Subversion. Distribution happens by people just checking out the directo...
12
2009-02-09T09:20:17Z
530,727
<p>I'm not suggesting that this is a great idea, but usually what I do in situations like these is that I have a Makefile, checked into subversion, which contains make rules to fetch all the dependent libraries and install them. The makefile can be smart enough to only apply the dependent libraries if they aren't pres...
0
2009-02-10T01:01:51Z
[ "python", "deployment", "layout", "bootstrapping" ]
How to embed p tag inside some text using Beautifulsoup?
527,629
<p>I wanted to embed <code>&lt;p</code>> tag where ever there is a \r\n\r\n.</p> <p>u"Finally Sri Lanka showed up, prevented their first 5-0 series whitewash, and stopped India at nine ODI wins in a row. \r\n\r\nFor 62 balls Yuvraj Singh played a dream knock, keeping India in the game despite wickets falling around h...
1
2009-02-09T10:09:05Z
527,647
<pre><code>''.join('&lt;p&gt;%s&lt;/p&gt;' % line for line in text.split('\r\n\r\n')) # Results: u"&lt;p&gt;Finally Sri Lanka showed up, prevented their first 5-0 series whitewash, and stopped India at nine ODI wins in a row. &lt;/p&gt; &lt;p&gt;For 62 balls Yuvraj Singh played a dream knock, keeping India in the game...
5
2009-02-09T10:15:15Z
[ "python", "beautifulsoup" ]
Can I instantiate a subclass object from the superclass
527,757
<p>I have the following example code:</p> <pre><code>class A(object): def __init__(self, id): self.myid = id def foo(self, x): print 'foo', self.myid*x class B(A): def __init__(self, id): self.myid = id self.mybid = id*2 def bar(self, x): print 'bar', self.myid,...
4
2009-02-09T11:13:30Z
527,789
<p>You should rather implement <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory pattern</a>, and your factory would then build any object you like, depending on provided parameters. That way your code will remain clean and extensible.</p> <p>Any hack you could use to make it directly c...
6
2009-02-09T11:29:00Z
[ "python", "oop" ]
Can I instantiate a subclass object from the superclass
527,757
<p>I have the following example code:</p> <pre><code>class A(object): def __init__(self, id): self.myid = id def foo(self, x): print 'foo', self.myid*x class B(A): def __init__(self, id): self.myid = id self.mybid = id*2 def bar(self, x): print 'bar', self.myid,...
4
2009-02-09T11:13:30Z
527,794
<p>Generally it's not such a good idea when a superclass has any knowledge of the subclasses.</p> <p>Think about what you want to do from an OO point of view.</p> <p>The superclass is providing common behaviour for all objects of that type, e.g. Animal. Then the subclass provides the specialisation of the behaviour, ...
2
2009-02-09T11:31:04Z
[ "python", "oop" ]
Can I instantiate a subclass object from the superclass
527,757
<p>I have the following example code:</p> <pre><code>class A(object): def __init__(self, id): self.myid = id def foo(self, x): print 'foo', self.myid*x class B(A): def __init__(self, id): self.myid = id self.mybid = id*2 def bar(self, x): print 'bar', self.myid,...
4
2009-02-09T11:13:30Z
527,799
<p>I don't think you can change the type of the object, but you can create another class that will work like a factory for the subclasses. Something like this:</p> <pre><code>class LetterFactory(object): @staticmethod def getLetterObject(n): if n == 1: return A(n) elif n == 2: return B(n)...
2
2009-02-09T11:32:35Z
[ "python", "oop" ]
How to properly organize a package/module dependency tree?
527,919
<p>Good morning,</p> <p>I am currently writing a python library. At the moment, modules and classes are deployed in an unorganized way, with no reasoned design. As I approach a more official release, I would like to reorganize classes and modules so that they have a better overall design. I drew a diagram of the impor...
2
2009-02-09T12:19:02Z
527,943
<p>The question is very vague.</p> <p>You can achieve this by having base/core things that import nothing from the remainder of the library, and concrete implementations importing from here. Apart from "don't have two modules importing from each-other at import-time", you should be fine.</p> <p>module1.py:</p> <pre>...
0
2009-02-09T12:27:56Z
[ "python", "design" ]
How to properly organize a package/module dependency tree?
527,919
<p>Good morning,</p> <p>I am currently writing a python library. At the moment, modules and classes are deployed in an unorganized way, with no reasoned design. As I approach a more official release, I would like to reorganize classes and modules so that they have a better overall design. I drew a diagram of the impor...
2
2009-02-09T12:19:02Z
527,964
<p><strong>"I drew a diagram of the import dependencies, and I was planning to aggregate classes by layer level."</strong></p> <p>Python must read like English (or any other natural language.)</p> <p>An import is a first-class statement that should have real meaning. Organizing things by "layer level" (whatever that...
6
2009-02-09T12:34:30Z
[ "python", "design" ]
How to properly organize a package/module dependency tree?
527,919
<p>Good morning,</p> <p>I am currently writing a python library. At the moment, modules and classes are deployed in an unorganized way, with no reasoned design. As I approach a more official release, I would like to reorganize classes and modules so that they have a better overall design. I drew a diagram of the impor...
2
2009-02-09T12:19:02Z
528,339
<p>It depends on the project, right? For example, if you are using a model-view-controller design, then your package would be structured in a way that makes the 3 groups of code independent.</p> <p>If you need some ideas, open up your site-packages directory, and look through some of the code in those modules to see h...
0
2009-02-09T14:30:34Z
[ "python", "design" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
528,134
<ol> <li>Provide some code. </li> <li><p>You probably call some function that should update database, but the function does not return any data (like <code>cursor.execute()</code>). And code: </p> <p>data = cursor.execute()</p> <p>Makes <code>data</code> a <code>None</code> object (of <code>NoneType</code>). But wi...
10
2009-02-09T13:31:20Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
528,137
<p>It means that the object you are trying to iterate is actually None; maybe the query produced no results?<br /> Could you please post a code sample?</p>
6
2009-02-09T13:32:01Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
528,158
<p>The function you used to select all rows returned None. This "probably" (because you did not provide code, I am only assuming) means that the SQL query did not return any values.</p>
5
2009-02-09T13:35:36Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
528,299
<p>Try using the cursor.rowcount variable after you call cursor.execute(). (this code will not work because I don't know what module you are using).</p> <pre><code>db = mysqlmodule.connect("a connection string") curs = dbo.cursor() curs.execute("select top 10 * from tablename where fieldA &gt; 100") for i in range(cur...
0
2009-02-09T14:20:03Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
528,454
<p>This error means that you are attempting to loop over a None object. This is like trying to loop over a Null array in C/C++. As Abgan, orsogufo, Dan mentioned, this is probably because the query did not return anything. I suggest that you check your query/databse connection.</p> <p>A simple code fragment to reprodu...
2
2009-02-09T14:55:27Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
17,230,253
<p>This may occur when I try to let 'usrsor.fetchone' execute twice. Like this:</p> <pre><code>import sqlite3 db_filename = 'test.db' with sqlite3.connect(db_filename) as conn: cursor = conn.cursor() cursor.execute(""" insert into test_table (id, username, password) values ('user_id', 'myname', 'pas...
0
2013-06-21T07:54:29Z
[ "python", "mysql" ]
TypeError: 'NoneType' object is not iterable
528,116
<p>I need to process mysql data one row at a time and i have selected all rows put them in a tuple but i get the error above.</p> <p>what does this mean and how do I go about it?</p>
-2
2009-02-09T13:25:34Z
29,757,361
<p>I know it's an old question but I thought I'd add one more possibility. I was getting this error when calling a stored procedure, and adding SET NOCOUNT ON at the top of the stored procedure solved it. The issue is that earlier selects that are not the final select for the procedure make it look like you've got em...
0
2015-04-20T20:06:04Z
[ "python", "mysql" ]
Is there a better way (besides COM) to remote-control Excel?
528,817
<p>I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:</p> <p>For example, the slightest upset se...
1
2009-02-09T16:21:49Z
528,833
<p>There is no way that completely bypasses COM. You can use VSTO (Visual Studio Tools for Office), which has nice .NET wrappers on the COM objects, but it is still COM underneath. </p>
6
2009-02-09T16:25:35Z
[ "python", ".net", "excel", "com" ]
Is there a better way (besides COM) to remote-control Excel?
528,817
<p>I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:</p> <p>For example, the slightest upset se...
1
2009-02-09T16:21:49Z
528,960
<p>It is also possible to run Excel as a server application and use it as a calculation engine. This allows non IT users to specify business rules within Excel and call them through webservices. I have not worked with this myself, but I know a coworker of mine used this once. <a href="http://msdn.microsoft.com/en-us/li...
1
2009-02-09T16:54:49Z
[ "python", ".net", "excel", "com" ]
Is there a better way (besides COM) to remote-control Excel?
528,817
<p>I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:</p> <p>For example, the slightest upset se...
1
2009-02-09T16:21:49Z
529,039
<p>Have you looked at the <a href="http://pypi.python.org/pypi/xlrd" rel="nofollow">xlrd</a> and <a href="http://pypi.python.org/pypi/xlwt" rel="nofollow">xlwt</a> packages? I'm not in need of them any more, but I had good success with xlrd on my last project. Last I knew, they couldn't process macros, but could do b...
1
2009-02-09T17:16:39Z
[ "python", ".net", "excel", "com" ]
Is there a better way (besides COM) to remote-control Excel?
528,817
<p>I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:</p> <p>For example, the slightest upset se...
1
2009-02-09T16:21:49Z
529,100
<p>You could use Jython with the JExcelApi (<a href="http://jexcelapi.sourceforge.net/" rel="nofollow">http://jexcelapi.sourceforge.net/</a>) to control your Excel application. I've been considering implementing this solution with one of my PyQt projects, but haven't gotten around to trying it yet. I have effectively...
1
2009-02-09T17:34:57Z
[ "python", ".net", "excel", "com" ]
Is there a better way (besides COM) to remote-control Excel?
528,817
<p>I'm working on a regression-testing tool that will validate a very large number of Excel spreadsheets. At the moment I control them via COM from a Python script using the latest version of the pywin32 product. Unfortunately COM seems to have a number of annoying drawbacks:</p> <p>For example, the slightest upset se...
1
2009-02-09T16:21:49Z
546,465
<blockquote> <p>The Excel COM interface will not allow me to safely remote-control two seperate instances of the Excel application operating on the same workbook file, even if they are read-only.</p> </blockquote> <p>This is not a limitation of COM, this is a <a href="http://blogs.msdn.com/excel/archive/2009/01/07/w...
2
2009-02-13T15:57:15Z
[ "python", ".net", "excel", "com" ]
Python: Pass or Sleep for long running processes?
529,034
<p>I am writing an queue processing application which uses threads for waiting on and responding to queue messages to be delivered to the app. For the main part of the application, it just needs to stay active. For a code example like:</p> <pre> while True: pass </pre> <p>or</p> <pre> while True: time.sleep(1)...
19
2009-02-09T17:15:42Z
529,048
<p>I've always seen/heard that using sleep is the better way to do it. Using sleep will keep your Python interpreter's CPU usage from going wild.</p>
4
2009-02-09T17:18:45Z
[ "python" ]
Python: Pass or Sleep for long running processes?
529,034
<p>I am writing an queue processing application which uses threads for waiting on and responding to queue messages to be delivered to the app. For the main part of the application, it just needs to stay active. For a code example like:</p> <pre> while True: pass </pre> <p>or</p> <pre> while True: time.sleep(1)...
19
2009-02-09T17:15:42Z
529,052
<p>I would imagine <em>time.sleep()</em> will have less overhead on the system. Using <em>pass</em> will cause the loop to immediately re-evaluate and peg the CPU, whereas using time.sleep will allow the execution to be temporarily suspended.</p> <p><strong>EDIT</strong>: just to prove the point, if you launch the pyt...
38
2009-02-09T17:20:00Z
[ "python" ]
Python: Pass or Sleep for long running processes?
529,034
<p>I am writing an queue processing application which uses threads for waiting on and responding to queue messages to be delivered to the app. For the main part of the application, it just needs to stay active. For a code example like:</p> <pre> while True: pass </pre> <p>or</p> <pre> while True: time.sleep(1)...
19
2009-02-09T17:15:42Z
529,073
<p>You don't give much context to what you are really doing, but maybe <a href="http://www.python.org/doc/2.5.2/lib/module-Queue.html" rel="nofollow"><code>Queue</code></a> could be used instead of an explicit busy-wait loop? If not, I would assume <code>sleep</code> would be preferable, as I believe it will consume le...
6
2009-02-09T17:27:08Z
[ "python" ]
Python: Pass or Sleep for long running processes?
529,034
<p>I am writing an queue processing application which uses threads for waiting on and responding to queue messages to be delivered to the app. For the main part of the application, it just needs to stay active. For a code example like:</p> <pre> while True: pass </pre> <p>or</p> <pre> while True: time.sleep(1)...
19
2009-02-09T17:15:42Z
529,321
<p>Why sleep? You don't want to sleep, you want to wait for the threads to finish.</p> <p>So</p> <pre><code># store the threads you start in a your_threads list, then for a_thread in your_threads: a_thread.join() </code></pre> <p>See: <a href="http://www.python.org/doc/2.5.2/lib/thread-objects.html#l2h-3460">thr...
21
2009-02-09T18:41:46Z
[ "python" ]
Python Script: Print new line each time to shell rather than update existing line
529,395
<p>I am a noob when it comes to python. I have a python script which gives me output like this:</p> <pre><code>[last] ZVZX-W3vo9I: Downloading video webpage [last] ZVZX-W3vo9I: Extracting video information [download] Destination: myvideo.flv [download] 9.9% of 10.09M at 3.30M/s ETA 00:02 </code></pre> <p>The las...
3
2009-02-09T19:00:14Z
529,415
<p>If I understand your request properly, you should be able to change that function to this:</p> <pre><code>def report_progress(self, percent_str, data_len_str, speed_str, eta_str): """Report download progress.""" print u'[download] %s of %s at %s ETA %s' % (percent_str, data_len_str, speed_str, eta_str) </co...
3
2009-02-09T19:03:10Z
[ "python", "shell" ]
Python Script: Print new line each time to shell rather than update existing line
529,395
<p>I am a noob when it comes to python. I have a python script which gives me output like this:</p> <pre><code>[last] ZVZX-W3vo9I: Downloading video webpage [last] ZVZX-W3vo9I: Extracting video information [download] Destination: myvideo.flv [download] 9.9% of 10.09M at 3.30M/s ETA 00:02 </code></pre> <p>The las...
3
2009-02-09T19:00:14Z
529,417
<p>I'm thinking you may just need to change:</p> <pre><code>skip_eol=True </code></pre> <p>to:</p> <pre><code>skip_eol=False </code></pre> <p>and get rid of the "<code>\r</code>" to see what happens. I think you'll be pleasantly surprised :-)</p>
3
2009-02-09T19:03:25Z
[ "python", "shell" ]
Python Script: Print new line each time to shell rather than update existing line
529,395
<p>I am a noob when it comes to python. I have a python script which gives me output like this:</p> <pre><code>[last] ZVZX-W3vo9I: Downloading video webpage [last] ZVZX-W3vo9I: Extracting video information [download] Destination: myvideo.flv [download] 9.9% of 10.09M at 3.30M/s ETA 00:02 </code></pre> <p>The las...
3
2009-02-09T19:00:14Z
529,420
<p>You can take out the \r, which moves to the cursor back to the beginning of the line and take out the skip_eol=True probably. Perhaps:</p> <pre><code> self.to_stdout(u'[download] %s of %s at %s ETA %s' % (percent_str, data_len_str, speed_str, eta_str)) </code></pre>
0
2009-02-09T19:04:17Z
[ "python", "shell" ]
Python Script: Print new line each time to shell rather than update existing line
529,395
<p>I am a noob when it comes to python. I have a python script which gives me output like this:</p> <pre><code>[last] ZVZX-W3vo9I: Downloading video webpage [last] ZVZX-W3vo9I: Extracting video information [download] Destination: myvideo.flv [download] 9.9% of 10.09M at 3.30M/s ETA 00:02 </code></pre> <p>The las...
3
2009-02-09T19:00:14Z
529,445
<p>The "update" effect is achieved by '\r'.</p> <p>Try this in a Python (2.x) shell:</p> <pre><code>print "00000000\r1111" </code></pre> <p>\r just returns the cursor to the beginning of the line.</p>
0
2009-02-09T19:08:28Z
[ "python", "shell" ]
Traverse a list in reverse order in Python
529,424
<p>So I can start from <code>len(collection)</code> and end in <code>collection[0]</code>.</p> <p>EDIT: Sorry, I forgot to mention I also want to be able to access the loop index.</p>
309
2009-02-09T19:04:58Z
529,427
<p>Use the <code>reversed()</code> built-in function:</p> <pre><code>&gt;&gt;&gt; a = ["foo", "bar", "baz"] &gt;&gt;&gt; for i in reversed(a): ... print i ... baz bar foo </code></pre> <p>To also access the original index:</p> <pre><code>&gt;&gt;&gt; for i, e in reversed(list(enumerate(a))): ... print i, e ...
505
2009-02-09T19:05:54Z
[ "python", "loops" ]
Traverse a list in reverse order in Python
529,424
<p>So I can start from <code>len(collection)</code> and end in <code>collection[0]</code>.</p> <p>EDIT: Sorry, I forgot to mention I also want to be able to access the loop index.</p>
309
2009-02-09T19:04:58Z
529,439
<p>Use <code>list.reverse()</code> and then iterate as you normally would.</p> <p><a href="http://docs.python.org/tutorial/datastructures.html" rel="nofollow">http://docs.python.org/tutorial/datastructures.html</a></p>
2
2009-02-09T19:07:13Z
[ "python", "loops" ]