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
listlengths
1
5
Compiled Python CGI
895,163
<p>Assuming the webserver is configured to handle <strong><em>.exe</em></strong>, Can i compile a python CGI file into an exe for speed. What would some pros and cons be to such a desession?</p>
0
2009-05-21T21:06:11Z
895,181
<p>Since the RDBMS and the network are the bottlenecks, I see no value in fussing around creating an EXE. </p> <p>On average, most of a web site's transfers are static content (images, .CSS, .JS, etc.) which is best handled by Apache without any Python in the loop. This has huge impact.</p> <p>Reserve Python for th...
0
2009-05-21T21:10:56Z
[ "python" ]
Compiled Python CGI
895,163
<p>Assuming the webserver is configured to handle <strong><em>.exe</em></strong>, Can i compile a python CGI file into an exe for speed. What would some pros and cons be to such a desession?</p>
0
2009-05-21T21:06:11Z
895,211
<p>You probably don't want to run Python as a CGI if you want it fast. Look at proxies, mod_python, WSGI or FastCGI, as those techinques avoid re-loading python runtime and your app on each request.</p>
1
2009-05-21T21:15:14Z
[ "python" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,405
<p>This is what happens when you use variable name of negative meaning, you need to invert their values. The following would be easier to understand:</p> <pre><code>sorted = False while not sorted: ... </code></pre> <p>On the other hand, the logic of the algorithm is a little bit off. You need to check whether ...
9
2009-05-21T21:54:22Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,410
<p>Your use of the Unsorted variable is wrong; you want to have a variable that tells you if you have swapped two elements; if you have done that, you can exit your loop, otherwise, you need to loop again. To fix what you've got here, just put the "unsorted = false" in the body of your if case; remove your else case; ...
8
2009-05-21T21:55:33Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,477
<p>You've got a couple of errors in there. The first is in length, and the second is in your use of unsorted (as stated by McWafflestix). You probably also want to return the list if you're going to print it:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 2 unsorted...
2
2009-05-21T22:08:14Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,733
<p>Answers provided by the-fury and Martin Cote fixed the problem of the infinite loop, but my code would still not work correctly (for a larger list, it would not sort correctly.). I ended up ditching the <code>unsorted</code> variable and used a counter instead.</p> <pre><code>def bubble(badList): length = len(b...
0
2009-05-21T23:12:40Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,748
<pre><code>def bubble_sort(l): for passes_left in range(len(l)-1, 0, -1): for index in range(passes_left): if l[index] &lt; l[index + 1]: l[index], l[index + 1] = l[index + 1], l[index] return l </code></pre>
3
2009-05-21T23:17:22Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
895,755
<p>The goal of bubble sort is to move the <em>heavier</em> items at the bottom in each round, while moving the <em>lighter</em> items up. In the inner loop, where you compare the elements, <strong>you don't have to iterate the whole list in each turn</strong>. The <em>heaviest</em> is already placed last. The <em>swapp...
11
2009-05-21T23:18:39Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
902,736
<p>To explain why your script isn't working right now, I'll rename the variable <code>unsorted</code> to <code>sorted</code>.</p> <p>At first, your list isn't yet sorted. Of course, we set <code>sorted</code> to <code>False</code>.</p> <p>As soon as we start the <code>while</code> loop, we assume that the list is alr...
106
2009-05-23T23:49:07Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
16,005,368
<p>#A very simple function, can be optimized (obviously) by decreasing the problem space of the 2nd array. But same O(n^2) complexity.</p> <pre><code>def bubble(arr): l = len(arr) for a in range(l): for b in range(l-1): if (arr[a] &lt; arr[b]): arr[a], arr[b] = arr[b], a...
1
2013-04-14T23:01:18Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
21,217,166
<p>I am a fresh fresh beginner, started to read about Python yesterday. Inspired by your example I created something maybe more in the 80-ties style, but nevertheless it kinda works</p> <pre><code>lista1 = [12, 5, 13, 8, 9, 65] i=0 while i &lt; len(lista1)-1: if lista1[i] &gt; lista1[i+1]: x = lista1[i] ...
0
2014-01-19T13:09:36Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
21,298,077
<p>The problem with the original algorithm is that if you had a lower number further in the list, it would not bring it to the correct sorted position. The program needs to go back the the beginning each time to ensure that the numbers sort all the way through.</p> <p>I simplified the code and it will now work for an...
1
2014-01-23T02:16:20Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
24,583,756
<pre><code>def bubble_sort(l): exchanged = True iteration = 0 n = len(l) while(exchanged): iteration += 1 exchanged = False # Move the largest element to the end of the list for i in range(n-1): if l[i] &gt; l[i+1]: exchanged = True ...
1
2014-07-05T06:41:12Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
28,551,860
<pre><code>def bubbleSort(alist): if len(alist) &lt;= 1: return alist for i in range(0,len(alist)): print "i is :%d",i for j in range(0,i): print "j is:%d",j print "alist[i] is :%d, alist[j] is :%d"%(alist[i],alist[j]) if alist[i] &gt; alist[j]: alist[i],alist[j] = alist[j],alist[i]...
1
2015-02-16T23:02:43Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
29,086,629
<pre><code>def bubble_sort(a): t = 0 sorted = False # sorted = False because we have not began to sort while not sorted: sorted = True # Assume sorted = True first, it will switch only there is any change for key in range(1,len(a)): if a[key-1] &gt; a[key]: sorted = F...
0
2015-03-16T20:47:13Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
32,392,195
<p>A simpler example:</p> <pre><code>a = len(alist)-1 while a &gt; 0: for b in range(0,a): #compare with the adjacent element if alist[b]&gt;=alist[b+1]: #swap both elements alist[b], alist[b+1] = alist[b+1], alist[b] a-=1 </code></pre> <p>This simply takes the elements...
1
2015-09-04T07:13:41Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
Bubble Sort Homework
895,371
<p>In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them.</p> <p>This is my attempt in Python:</p> <pre><code>mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 ...
113
2009-05-21T21:47:24Z
37,822,474
<pre><code>def bubble_sort(li): l = len(li) tmp = None sorted_l = sorted(li) while (li != sorted_l): for ele in range(0,l-1): if li[ele] &gt; li[ele+1]: tmp = li[ele+1] li[ele+1] = li [ele] li[ele] = tmp return li </code></pre>
0
2016-06-14T21:30:58Z
[ "python", "algorithm", "sorting", "bubble-sort" ]
What if I want to store a None value in the memcache?
895,386
<p>This is specifically related to the Google App Engine Memcache API, but I'm sure it also applies to other Memcache tools.</p> <p>The dictionary .get() method allows you to specify a default value, such as dict.get('key', 'defaultval')</p> <p>This can be useful if it's possible you might want to store None as a val...
10
2009-05-21T21:50:03Z
895,579
<p>A possible way to do this is to create new class that defines <code>None</code> for this purpose, and assign instances of this to the cache (unfortunately you cannot extend <code>None</code>). Alternatively, you could use the empty string "", or avoid storing None/null values altogether (absence of the key implies N...
7
2009-05-21T22:29:26Z
[ "python", "google-app-engine", "memcached" ]
What if I want to store a None value in the memcache?
895,386
<p>This is specifically related to the Google App Engine Memcache API, but I'm sure it also applies to other Memcache tools.</p> <p>The dictionary .get() method allows you to specify a default value, such as dict.get('key', 'defaultval')</p> <p>This can be useful if it's possible you might want to store None as a val...
10
2009-05-21T21:50:03Z
896,359
<p>Not really.</p> <p>You could store a None value as an empty string, but there isn't really a way to store special data in a memcache.</p> <p>What's the difference between the cache key not existing and the cache value being None? It's probably better to unify these two situations.</p>
0
2009-05-22T04:33:50Z
[ "python", "google-app-engine", "memcached" ]
What if I want to store a None value in the memcache?
895,386
<p>This is specifically related to the Google App Engine Memcache API, but I'm sure it also applies to other Memcache tools.</p> <p>The dictionary .get() method allows you to specify a default value, such as dict.get('key', 'defaultval')</p> <p>This can be useful if it's possible you might want to store None as a val...
10
2009-05-21T21:50:03Z
921,038
<p>You could do something like what Haskell and Scala does and store an Option dictionary. The dictionary contains two keys: one key to indicate that it is valid and one key that is used to hold the data. Something like this:</p> <pre><code>{valid: true, data: whatyouwanttostore} </code></pre> <p>Then if <code>get</c...
2
2009-05-28T14:10:46Z
[ "python", "google-app-engine", "memcached" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,439
<p>Lookup Django.</p>
0
2009-05-21T22:02:33Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,456
<p>Python can be used for web development, but there isn't a special language extension or anything in the language that will handle all the HTML generation or that works like PHP.</p> <p>It's pretty much run through some sort of interpreter on a web server (CGI, mod_python, etc.).</p> <p>I would recommend looking in...
0
2009-05-21T22:05:45Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,466
<p><a href="http://wiki.python.org/moin/WebFrameworks" rel="nofollow">Python Wiki: Web Frameworks for Python</a></p> <p>If you decide to use <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>, <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/" rel="nofollow">the official tutorial</a> is an...
2
2009-05-21T22:06:48Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,472
<p>There are <a href="http://en.wikipedia.org/wiki/Comparison%5Fof%5Fweb%5Fapplication%5Fframeworks" rel="nofollow">quite a few</a> web frameworks for python out there, but the only one I've used is <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>, and I really like it.</p> <p>If you've got a few hour...
0
2009-05-21T22:07:25Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,473
<p><strong>Edited 3 years later</strong>: Don't use mod_python, use mod_wsgi. Flask and Werkzeug are good frameworks too. Needing to know what's going on is useful, but it isn't a requirement. That would be stupid. </p> <p>Don't lookup Django until you have a good grasp of what Django is doing on your behalf. for you....
4
2009-05-21T22:07:28Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
895,533
<p>As others have mentioned, one of the more prominent python "offshoots" as you call them would be <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>. It is a rather powerful framework that allows you to quickly and securely build web applications. The first place to look would be <a href="http://docs...
0
2009-05-21T22:19:28Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
897,015
<p>If you really don't want to delve into the frameworks - and you should, I heartily recommend Django or Pylons - there's still need to go down the road of CGI. This is a totally out-of-date technology, not to mention slow and inefficient.</p> <p>There <em>is</em> a standard way of building Python web applications, a...
3
2009-05-22T09:14:49Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
897,434
<p>Now that everyone has said <a href="http://docs.djangoproject.com/en/dev/intro/tutorial01/">Django</a>, I can add my two cents: I would argue that you might learn more by looking at the different components first, before using Django. For web development with Python, you often want 3 components:</p> <ol> <li><p>Som...
21
2009-05-22T11:35:19Z
[ "python" ]
Using python to develop web application
895,420
<p>I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?</p> <p>Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?</p>
16
2009-05-21T21:58:58Z
908,362
<p>There are a couple of choices for web development. From my experience, your choice will again be dependent on your application. I used <a href="http://djangoproject.com" rel="nofollow">django</a> and <a href="http://webpy.org/" rel="nofollow">web.py</a> in production and I am about to deploy an app based on <a href=...
1
2009-05-25T23:25:10Z
[ "python" ]
Django App Dependency Cycle
895,454
<p>I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.)</p> <p>I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am havi...
19
2009-05-21T22:05:33Z
895,984
<p>Normally I advocate for splitting functionality into smaller apps, but a circular dependence between models reflects such a tight integration that you're probably not gaining much from the split and might just consider merging the apps. If that results in an app that feels too large, there may be a way to make the ...
1
2009-05-22T00:56:03Z
[ "python", "django", "dependencies" ]
Django App Dependency Cycle
895,454
<p>I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.)</p> <p>I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am havi...
19
2009-05-21T22:05:33Z
896,090
<p>If you're seeing circular model dependency I'm guessing that one of three things is happening:</p> <ul> <li>You've defined an inverse relationship to one that's already defined (for instance both course has many lectures and lecture has one course) which is redundant in django</li> <li>You have a model method in th...
2
2009-05-22T01:58:07Z
[ "python", "django", "dependencies" ]
Django App Dependency Cycle
895,454
<p>I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.)</p> <p>I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am havi...
19
2009-05-21T22:05:33Z
896,995
<p>If your dependency is with foreign keys referencing models in other applications, you <em>don't</em> need to import the other model. You can use a string in your ForeignKey definition:</p> <pre><code>class MyModel(models.Model): myfield = models.ForeignKey('myotherapp.MyOtherModel') </code></pre> <p>This way t...
48
2009-05-22T09:08:17Z
[ "python", "django", "dependencies" ]
Django App Dependency Cycle
895,454
<p>I am in the middle of developing a Django application, which has quite complicated models (it models a university - courses, modules, lectures, students etc.)</p> <p>I have separated the project into apps, to make the whole thing more organised (apps are courses, schools, people, modules and timeperiods). I am havi...
19
2009-05-21T22:05:33Z
7,874,086
<p>This may not be well-suited to your situation, but ignoring the Django aspect to your question, the general technique for breaking circular dependencies is to break out one of the cross-referenced items into a new module. For example:</p> <pre><code>moduleA: class1, class2 | ^ v ...
3
2011-10-24T10:12:36Z
[ "python", "django", "dependencies" ]
Can reading a list from a disk be better than loading a dictionary?
895,500
<p>I am building an application where I am trying to allow users to submit a list of company and date pairs and find out whether or not there was a news event on that date. The news events are stored in a dictionary with a company identifier and a date as a key. </p> <pre><code>newsDict('identifier','MM/DD/YYYY')=[...
2
2009-05-21T22:12:17Z
895,528
<p>With such a large amount of data, you should be using a database. This would be far better than looking at a list, and would be the most appropriate way of storing your data anyway. If you're using Python, it has SQLite built in I believe.</p>
5
2009-05-21T22:18:34Z
[ "python", "list", "dictionary", "performance" ]
Can reading a list from a disk be better than loading a dictionary?
895,500
<p>I am building an application where I am trying to allow users to submit a list of company and date pairs and find out whether or not there was a news event on that date. The news events are stored in a dictionary with a company identifier and a date as a key. </p> <pre><code>newsDict('identifier','MM/DD/YYYY')=[...
2
2009-05-21T22:12:17Z
896,125
<p>The dictionary will take more memory because it is effectively a hash.</p> <p>You don't have to go so far as using a database, since your lookup requirements are so simple. Just use the file system.</p> <p>Create a directory structure based on the company name (or ticker), with subdirectories for each date. To f...
1
2009-05-22T02:15:54Z
[ "python", "list", "dictionary", "performance" ]
Looking for help, just started with Python today. (3.0)
895,637
<p>I am just trying to get into python, but I've found it very difficult to find any resource that is Python 3. All I've got so far is diveintopython3.org, and its limited. Anyways, I was just trying to get a feel for the language by doing some very basic stuff, but I can't figure out why this little program won't do w...
1
2009-05-21T22:45:27Z
895,657
<p><a href="http://www.swaroopch.com/notes/Python%5Fen:Table%5Fof%5FContents" rel="nofollow">A Byte of Python</a> covers Python 3 in detail. There's also a 2.X version of the book, which can help compare and contrast the differences in the languages.</p> <p>To fix your problem, you need to convert the input taken int...
7
2009-05-21T22:50:00Z
[ "python", "python-3.x" ]
Looking for help, just started with Python today. (3.0)
895,637
<p>I am just trying to get into python, but I've found it very difficult to find any resource that is Python 3. All I've got so far is diveintopython3.org, and its limited. Anyways, I was just trying to get a feel for the language by doing some very basic stuff, but I can't figure out why this little program won't do w...
1
2009-05-21T22:45:27Z
895,673
<p>You didn't say what you <em>do</em> get - I'm guessing <code>num</code> and <code>num2</code> concatenated, as the <a href="http://docs.python.org/3.0/library/functions.html#input" rel="nofollow"><code>input</code></a> returns a string. Adding two strings just concatenates them. If you expect <code>num</code> and <c...
3
2009-05-21T22:53:31Z
[ "python", "python-3.x" ]
Looking for help, just started with Python today. (3.0)
895,637
<p>I am just trying to get into python, but I've found it very difficult to find any resource that is Python 3. All I've got so far is diveintopython3.org, and its limited. Anyways, I was just trying to get a feel for the language by doing some very basic stuff, but I can't figure out why this little program won't do w...
1
2009-05-21T22:45:27Z
895,677
<p>There's an Addison-Wesley book by Mark Summerfield called "Programming in Python 3", and I have found it to be the best Python book I've read. One nice thing for you, I would imagine, is that Summerfield does not bring up differences between 2.X and 3.x, so someone just picking up Python gets an uninterrupted view ...
0
2009-05-21T22:54:11Z
[ "python", "python-3.x" ]
Looking for help, just started with Python today. (3.0)
895,637
<p>I am just trying to get into python, but I've found it very difficult to find any resource that is Python 3. All I've got so far is diveintopython3.org, and its limited. Anyways, I was just trying to get a feel for the language by doing some very basic stuff, but I can't figure out why this little program won't do w...
1
2009-05-21T22:45:27Z
895,699
<p>Interesting, 3 answers, and none of them address your problem correctly.</p> <p>All you have to do is this:</p> <pre><code>def add(num=0,num2=0): sumEm = (int(num)+int(num2)) # may need the int() because in python 3.0 the manual says it only returns strings return sumEm # use return here not print </code><...
1
2009-05-21T22:59:46Z
[ "python", "python-3.x" ]
How can I start an interactive program(like gdb) from python?
896,031
<p>I am going to start up gdb from python.</p> <p>For example:</p> <pre><code>prog.shell.py: #do lots of things # # p.subprocess.Popen("gdb --args myprog", shell=True, stdin=sys.stdin, stdout=sys.stdout) </code></pre> <p>But the gdb is not invoked as I expected, the interaction with gdb is broken. I ...
1
2009-05-22T01:21:59Z
896,037
<p>I think you meant</p> <pre><code>p = subprocess.Popen(...) </code></pre> <p>You probably need to wait for p to finish:</p> <pre><code>p.wait() </code></pre>
3
2009-05-22T01:27:21Z
[ "python", "gdb" ]
Can't create games with pygame
896,062
<p>I make a game with python 2.5 and pygame.</p> <p>but,I can't complete make. because this errors occured.</p> <pre><code>C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd Traceback (most recent call last): File "Main.py", line 8, in &lt;module&gt;...
0
2009-05-22T01:42:01Z
896,080
<p>It looks like you don't have the <code>freesansbold.ttf</code> file on your computer in an accessible fonts folder. This font should have come with Pygame in the <code>lib</code> directory.</p> <p>Check the installation folder for your copy of Pygame, and if it's there, modify your Python installation's font path t...
1
2009-05-22T01:49:52Z
[ "python", "fonts", "pygame" ]
Can't create games with pygame
896,062
<p>I make a game with python 2.5 and pygame.</p> <p>but,I can't complete make. because this errors occured.</p> <pre><code>C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd Traceback (most recent call last): File "Main.py", line 8, in &lt;module&gt;...
0
2009-05-22T01:42:01Z
1,250,718
<p>A simple solution would be to simply load the font directly instead of using sysfont. Just use the pygame.font.Font class and directly load a ttf file. This will also make it easier to use py2exe, and you can choose exactly the font you want.</p>
2
2009-08-09T05:17:25Z
[ "python", "fonts", "pygame" ]
Can't create games with pygame
896,062
<p>I make a game with python 2.5 and pygame.</p> <p>but,I can't complete make. because this errors occured.</p> <pre><code>C:\Python26\TypeType\src\dist\Main.exe:8: RuntimeWarning: use font: MemoryLoadLibrary failed loading pygame\font.pyd Traceback (most recent call last): File "Main.py", line 8, in &lt;module&gt;...
0
2009-05-22T01:42:01Z
31,501,648
<p>You probably found a solution but i want to give one for other. Create you game with pygame. Then, unzip the librairy file. Go to </p> <blockquote> <p>PythonX.X\Lib\site-packages\pygame and copy freesansbold.ttf</p> </blockquote> <p>Back to your library file that you unzipped and go to </p> <blockquote> <p>li...
0
2015-07-19T13:20:55Z
[ "python", "fonts", "pygame" ]
Properly importing modules in Python
896,112
<p>How do I set up module imports so that each module can access the objects of all the others?</p> <p>I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to <code>sys.path</code> and imports a group of modules, using <code>impo...
9
2009-05-22T02:09:07Z
896,128
<p>You won't get recursion on imports because Python caches each module and won't reload one it already has.</p>
3
2009-05-22T02:17:58Z
[ "python", "python-import" ]
Properly importing modules in Python
896,112
<p>How do I set up module imports so that each module can access the objects of all the others?</p> <p>I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to <code>sys.path</code> and imports a group of modules, using <code>impo...
9
2009-05-22T02:09:07Z
896,137
<p>Few pointers</p> <ol> <li><p>You may have already split functionality in various module. If correctly done most of the time you will not fall into circular import problems (e.g. if module a depends on b and b on a you can make a third module c to remove such circular dependency). As last resort, in a import b but ...
5
2009-05-22T02:20:43Z
[ "python", "python-import" ]
Properly importing modules in Python
896,112
<p>How do I set up module imports so that each module can access the objects of all the others?</p> <p>I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to <code>sys.path</code> and imports a group of modules, using <code>impo...
9
2009-05-22T02:09:07Z
897,001
<p>The way to do this is to avoid magic. In other words, if your module requires something from another module, it should import it explicitly. You shouldn't rely on things being imported automatically.</p> <p>As the Zen of Python (<code>import this</code>) has it, explicit is better than implicit.</p>
4
2009-05-22T09:10:17Z
[ "python", "python-import" ]
Properly importing modules in Python
896,112
<p>How do I set up module imports so that each module can access the objects of all the others?</p> <p>I have a medium size Python application with modules files in various subdirectories. I have created modules that append these subdirectories to <code>sys.path</code> and imports a group of modules, using <code>impo...
9
2009-05-22T02:09:07Z
897,186
<p><strong>"I have a medium size Python application with modules files in various subdirectories."</strong></p> <p>Good. Make absolutely sure that each directory include a <code>__init__.py</code> file, so that it's a package.</p> <p><strong>"I have created modules that append these subdirectories to <code>sys.path<...
19
2009-05-22T10:05:51Z
[ "python", "python-import" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
898,557
<p>It's very easy to move indented blocks when you have <code>set foldmethod=indent</code>. For example, if you're on the <code>def main():</code> line in the following snippet:</p> <pre><code>def main(): +-- 35 lines: gps.init()----------------------------------------------------- if __name__ == "__main__": main() <...
6
2009-05-22T15:45:11Z
[ "python", "vim", "editing" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
1,315,239
<p>More information on the Vim script refred to above:</p> <p><a href="http://www.vim.org/scripts/script.php?script_id=386">http://www.vim.org/scripts/script.php?script_id=386</a></p> <p>python_match.vim : Extend the % motion and define g%, [%, and ]% motions for Python files</p> <p>description This script redefines...
11
2009-08-22T05:44:32Z
[ "python", "vim", "editing" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
1,394,173
<p>Here is a VIM script <a href="http://www.vim.org/scripts/script.php?script_id=30">http://www.vim.org/scripts/script.php?script_id=30</a></p> <p>which makes it much easier to navigate around python code blocks.</p> <p>Shortcuts:</p> <ul> <li>]t -- Jump to beginning of block</li> <li>]e -- Jump to end of ...
16
2009-09-08T13:56:12Z
[ "python", "vim", "editing" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
28,284,564
<h1><a href="https://github.com/klen/python-mode" rel="nofollow">python-mode</a></h1> <p>This vim plugin provides motions similar to built-in ones:</p> <pre class="lang-none prettyprint-override"><code>2.4 Vim motion ~ *pymode-motion* Support Vim motion...
5
2015-02-02T18:44:46Z
[ "python", "vim", "editing" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
32,072,543
<p>To address your final paragraph, the following script defines a new "indent" text-object that you can perform actions on. For instance, <kbd>d</kbd><kbd>i</kbd><kbd>i</kbd> deletes everything indented at the same level as the line the cursor is on.</p> <p>See the plugin's documentation for more info: <a href="http...
0
2015-08-18T12:32:14Z
[ "python", "vim", "editing" ]
More efficient movements editing python files in vim
896,145
<p>Given a python file with the following repeated endlessly:</p> <pre><code>def myFunction(a, b, c): if a: print b elif c: print 'hello' </code></pre> <p>I'd like to move around and edit this file using familiar vim movements. For instance, using (, ), [[, ]], {, } or deleting/yanking/changi...
36
2009-05-22T02:25:37Z
34,286,586
<h2><a href="https://github.com/alfredodeza/chapa.vim" rel="nofollow">chapa.vim</a></h2> <p>A multi-language vim plugin to move (or visually select) the next/previous class, method or function; out of the box support for python and javascript.</p> <pre class="lang-none prettyprint-override"><code>" Function Movement ...
0
2015-12-15T10:21:42Z
[ "python", "vim", "editing" ]
How to show hidden autofield in django formset
896,153
<p>A Django autofield when displayed using a formset is hidden by default. What would be the best way to show it?</p> <p>At the moment, the model is declared as,</p> <pre><code>class MyModel: locid = models.AutoField(primary_key=True) ... </code></pre> <p>When this is rendered using Django formsets, </p> <pre...
2
2009-05-22T02:29:31Z
896,160
<p>Try changing the default field type:</p> <pre><code>from django import forms class MyModelForm(ModelForm): locid = forms.IntegerField(min_value=1, required=True) class Meta: model = MyModel fields = ('locid', 'name') </code></pre> <p><strong>EDIT:</strong> Tested and works...</p>
2
2009-05-22T02:34:17Z
[ "python", "django", "formset" ]
How to show hidden autofield in django formset
896,153
<p>A Django autofield when displayed using a formset is hidden by default. What would be the best way to show it?</p> <p>At the moment, the model is declared as,</p> <pre><code>class MyModel: locid = models.AutoField(primary_key=True) ... </code></pre> <p>When this is rendered using Django formsets, </p> <pre...
2
2009-05-22T02:29:31Z
896,973
<p>As you say, you are not using the custom form you have defined. This is because you aren't passing it in anywhere, so Django can't know about it.</p> <p>The solution is simple - just pass the custom form class into modelformset_factory:</p> <pre><code>LocFormSet = modelformset_factory(MyModel, form=MyModelForm) </...
1
2009-05-22T08:59:29Z
[ "python", "django", "formset" ]
How to show hidden autofield in django formset
896,153
<p>A Django autofield when displayed using a formset is hidden by default. What would be the best way to show it?</p> <p>At the moment, the model is declared as,</p> <pre><code>class MyModel: locid = models.AutoField(primary_key=True) ... </code></pre> <p>When this is rendered using Django formsets, </p> <pre...
2
2009-05-22T02:29:31Z
902,854
<p>Okay, none of the approaches above worked for me. I solved this issue from the template side, finally.</p> <ul> <li><p>There is a ticket filed (<a href="http://code.djangoproject.com/ticket/10427" rel="nofollow">http://code.djangoproject.com/ticket/10427</a>), which adds a "value" option to a template variable for ...
0
2009-05-24T01:25:51Z
[ "python", "django", "formset" ]
How to show hidden autofield in django formset
896,153
<p>A Django autofield when displayed using a formset is hidden by default. What would be the best way to show it?</p> <p>At the moment, the model is declared as,</p> <pre><code>class MyModel: locid = models.AutoField(primary_key=True) ... </code></pre> <p>When this is rendered using Django formsets, </p> <pre...
2
2009-05-22T02:29:31Z
1,266,682
<p>The reason that the autofield is hidden, is that both BaseModelFormSet and BaseInlineFormSet override that field in add_field. The way to fix it is to create your own formset and override add_field without calling super. Also you don't have to explicitly define the primary key.</p> <p>you have to pass the formset t...
0
2009-08-12T14:51:02Z
[ "python", "django", "formset" ]
Django -- how to use templatetags filter with multiple arguments
896,166
<p>I have a few values that I would like to pass into a filter and get a URL out of it.</p> <p>In my template I have:</p> <pre><code>{% if names %} {% for name in names %} &lt;a href='{{name|slugify|add_args:"custid=name.id, sortid=2"}}'&gt;{{name}}&lt;/a&gt; {%if not forloop.last %} | {% endif %} {% endf...
2
2009-05-22T02:37:17Z
896,301
<p>You're calling <code>argz.join</code> a couple times and never assigning the results to anything: maybe you're operating under the misconception that the <code>join</code> method of a string has some mysterious side effect, but it doesn't -- it just returns a new string, and if you don't do anything with that new st...
3
2009-05-22T04:08:59Z
[ "python", "django", "filter", "django-templates", "tags" ]
Django -- how to use templatetags filter with multiple arguments
896,166
<p>I have a few values that I would like to pass into a filter and get a URL out of it.</p> <p>In my template I have:</p> <pre><code>{% if names %} {% for name in names %} &lt;a href='{{name|slugify|add_args:"custid=name.id, sortid=2"}}'&gt;{{name}}&lt;/a&gt; {%if not forloop.last %} | {% endif %} {% endf...
2
2009-05-22T02:37:17Z
896,755
<p>You can't pass <code>name.id</code> to your filter. Filter arguments can be asingle value or a single literal. Python/Django doesn't attempt any "smart" variable replacement like PHP.</p> <p>I suggest you to create a tag for this task:</p> <pre><code>&lt;a href='{% add_args "custid" name.id "sortid" "2" %}{{name|s...
4
2009-05-22T07:47:51Z
[ "python", "django", "filter", "django-templates", "tags" ]
Django -- how to use templatetags filter with multiple arguments
896,166
<p>I have a few values that I would like to pass into a filter and get a URL out of it.</p> <p>In my template I have:</p> <pre><code>{% if names %} {% for name in names %} &lt;a href='{{name|slugify|add_args:"custid=name.id, sortid=2"}}'&gt;{{name}}&lt;/a&gt; {%if not forloop.last %} | {% endif %} {% endf...
2
2009-05-22T02:37:17Z
911,750
<p>This "smart" stuff logic should not be in the template. Build your end-of-urls in your view and then pass them to template:</p> <pre><code>def the_view(request): url_stuff = "custid=%s, sortid, ...." % (name.id, 2 ...) return render_to_response('template.html', {'url_stuff':url_stuff,}, context_instanc...
6
2009-05-26T17:08:24Z
[ "python", "django", "filter", "django-templates", "tags" ]
Any python library to access quickbooks?
896,193
<p>I want to integrate my mobile POS system with quickbooks (I need customers, sellers, inventory &amp; post orders &amp; invoices).</p> <p>I have not not been able to find a python library for this.</p>
5
2009-05-22T02:53:52Z
34,371,049
<p>I think it might be useful to someone</p> <p>First, you have to automize a POS</p> <p><a href="https://github.com/maxolasersquad/orthosie" rel="nofollow">Orthosie Point of sale system written in Python</a></p> <p><a href="https://code.google.com/p/wxpos/" rel="nofollow">Wxpos Python cross platform point of sale s...
0
2015-12-19T12:58:53Z
[ "python", "api", "quickbooks" ]
How to change default django User model to fit my needs?
896,421
<p>The default Django's <code>User</code> model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. </p> <p>I also don't like default characte...
10
2009-05-22T05:01:09Z
896,788
<p>The Django User model is structured very sensibly. You really don't want to allow arbitrary characters in a username, for instance, and there are ways to achieve <a href="http://www.djangosnippets.org/snippets/74/" rel="nofollow">email address login</a>, without hacking changes to the base model.</p> <p>To simply ...
7
2009-05-22T07:59:39Z
[ "python", "django", "django-models", "user" ]
How to change default django User model to fit my needs?
896,421
<p>The default Django's <code>User</code> model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. </p> <p>I also don't like default characte...
10
2009-05-22T05:01:09Z
897,928
<p><strong>I misread the question. Hope this post is helpful to anyone else.</strong></p> <pre><code>#in models.py from django.db.models.signals import post_save class UserProfile(models.Model): user = models.ForeignKey(User) #other fields here def __str__(self): return "%s's profile" %...
7
2009-05-22T13:47:00Z
[ "python", "django", "django-models", "user" ]
How to change default django User model to fit my needs?
896,421
<p>The default Django's <code>User</code> model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. </p> <p>I also don't like default characte...
10
2009-05-22T05:01:09Z
898,052
<p>You face a bit of a dilemma which really has two solutions if you're committed to avoiding the profile-based customization already pointed out.</p> <ol> <li>Change the <code>User</code> model itself, per Daniel's suggestions</li> <li>Write a <code>CustomUser</code> class, subclassing <code>User</code> or copying it...
0
2009-05-22T14:09:53Z
[ "python", "django", "django-models", "user" ]
How to change default django User model to fit my needs?
896,421
<p>The default Django's <code>User</code> model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. </p> <p>I also don't like default characte...
10
2009-05-22T05:01:09Z
898,313
<p>Rather than modify the User class directly or do subclassing, you can also just repurpose the existing fields. </p> <p>For one site I used the "first_name" field as the "publicly displayed name" of a user and stuff a slugified version of that into the "username" field (for use in URLs). I wrote a custom auth back...
8
2009-05-22T14:59:04Z
[ "python", "django", "django-models", "user" ]
How to change default django User model to fit my needs?
896,421
<p>The default Django's <code>User</code> model has some fields, and validation rules, that I don't really need. I want to make registration as simple as possible, i.e. require either email or username, or phone number - all those being unique, hence good as user identifiers. </p> <p>I also don't like default characte...
10
2009-05-22T05:01:09Z
3,902,915
<p>There are anumber of ways to do this, but here's what I'd do: I'd allow a user to enter an email, username (which must contain at least one letter and no <code>@</code> symbols) or mobile number. Then, when I validate it:</p> <ol> <li>Check for the presence of <code>@</code>. If so, set it as the user's email, hash...
0
2010-10-11T00:58:28Z
[ "python", "django", "django-models", "user" ]
Passing Variables to Django Comment Views
896,532
<p>Alright, I know I've asked similar questions, but I feel this is hopefully a bit different. I'm integrating django.comments into my application, and the more I play with it, the more I realize it may not even be worth my while at the end of the day. That aside, I've managed to add Captcha to my comments, and I've le...
-3
2009-05-22T05:57:04Z
896,983
<p>Dynamic data in sidebars is what template tags are for.</p> <p>There's absolutely no need to muck around with the built-in views - just define the tags add them to your templates.</p>
3
2009-05-22T09:02:29Z
[ "python", "django", "django-comments" ]
Passing Variables to Django Comment Views
896,532
<p>Alright, I know I've asked similar questions, but I feel this is hopefully a bit different. I'm integrating django.comments into my application, and the more I play with it, the more I realize it may not even be worth my while at the end of the day. That aside, I've managed to add Captcha to my comments, and I've le...
-3
2009-05-22T05:57:04Z
900,503
<p>I user template tags as well. Templates in Django are truly for displaying data only. I think Django believes in separation between the Designers and the Developers. So, they are enforcing the idea of templates should be simple enough for web designer to work with. (the photoshop guys)</p> <p>So, as long as you don...
0
2009-05-23T00:13:38Z
[ "python", "django", "django-comments" ]
How to convert a Pyglet image to a PIL image?
896,548
<p>i want to convert a Pyglet.AbstractImage object to an PIL image for further manipulation here are my codes</p> <pre><code>from pyglet import image from PIL import Image pic = image.load('pic.jpg') data = pic.get_data('RGB', pic.pitch) im = Image.fromstring('RGB', (pic.width, pic.height), data) im.show() </code></pr...
1
2009-05-22T06:07:26Z
896,554
<p>This is an open <a href="http://code.google.com/p/pyglet/wiki/ReleaseSchedule" rel="nofollow">wishlist</a> item:</p> <blockquote> <p>AbstractImage to/from PIL image. </p> </blockquote>
0
2009-05-22T06:10:05Z
[ "python", "image", "python-imaging-library", "pyglet" ]
How to convert a Pyglet image to a PIL image?
896,548
<p>i want to convert a Pyglet.AbstractImage object to an PIL image for further manipulation here are my codes</p> <pre><code>from pyglet import image from PIL import Image pic = image.load('pic.jpg') data = pic.get_data('RGB', pic.pitch) im = Image.fromstring('RGB', (pic.width, pic.height), data) im.show() </code></pr...
1
2009-05-22T06:07:26Z
896,756
<p>I think I find the solution</p> <p>the pitch in Pyglet.AbstractImage instance is not compatible with PIL I found in pyglet 1.1 there is a codec function to encode the Pyglet image to PIL here is the <a href="http://pyglet.googlecode.com/svn/trunk/pyglet/image/codecs/pil.py" rel="nofollow">link</a> to the source</p>...
2
2009-05-22T07:47:56Z
[ "python", "image", "python-imaging-library", "pyglet" ]
Display all file names from a specific folder
896,595
<p>Like there is a folder say XYZ , whcih contain files with diffrent diffrent format let say .txt file, excel file, .py file etc. i want to display in the output all file name using Python programming</p>
0
2009-05-22T06:32:42Z
896,613
<pre><code>import glob glob.glob('XYZ/*') </code></pre> <p><a href="http://docs.python.org/library/glob.html" rel="nofollow">See the documentation for more</a></p>
3
2009-05-22T06:37:44Z
[ "python", "directory", "ls" ]
Display all file names from a specific folder
896,595
<p>Like there is a folder say XYZ , whcih contain files with diffrent diffrent format let say .txt file, excel file, .py file etc. i want to display in the output all file name using Python programming</p>
0
2009-05-22T06:32:42Z
896,802
<p>Here is an example that might also help show some of the handy basics of python -- dicts <code>{}</code> , lists <code>[]</code> , little string techniques (<code>split</code>), a module like <code>os</code>, etc.:</p> <pre><code>bvm@bvm:~/example$ ls deal.xls five.xls france.py guido.py make.py thing....
2
2009-05-22T08:05:53Z
[ "python", "directory", "ls" ]
Display all file names from a specific folder
896,595
<p>Like there is a folder say XYZ , whcih contain files with diffrent diffrent format let say .txt file, excel file, .py file etc. i want to display in the output all file name using Python programming</p>
0
2009-05-22T06:32:42Z
897,024
<pre><code>import os XYZ = '.' for item in enumerate(sorted(os.listdir(XYZ))): print item </code></pre>
1
2009-05-22T09:17:06Z
[ "python", "directory", "ls" ]
Checking folder/file ntfs permissions using python
896,638
<p>As the question title might suggest, I would very much like to know of the way to check the ntfs permissions of the given file or folder (hint: those are the ones you see in the "security" tab). Basically, what I need is to take a path to a file or directory (on a local machine, or, preferrably, on a share on a remo...
6
2009-05-22T06:48:03Z
897,963
<p>Unless you fancy rolling your own, win32security is the way to go. There's the beginnings of an example here:</p> <p><a href="http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html">http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html</a></p> <p>If you want to live slightly ...
11
2009-05-22T13:56:50Z
[ "python", "winapi", "permissions", "acl", "ntfs" ]
Creating modelformset from a modelform
896,848
<p>I have a model MyModel which contains a PK - locid, that is an AutoField.</p> <p>I want to construct a model formset from this, with some caveats:</p> <ul> <li>The queryset for the formset should be a custom one (say, order_by('field')) rather than all()</li> <li>Since locid for MyModel is an AutoField and thus hi...
0
2009-05-22T08:22:12Z
897,383
<p>It makes no sense to show an autofield to the user, as it's an autoincremented primary key -- the user can not change it and it will not be available before saving the record to the database (where the DBMS selectes the next available id).</p> <p>This is how you set a custom queryset for a formset:</p> <pre><code>...
2
2009-05-22T11:16:38Z
[ "python", "django", "formset", "modelform" ]
Creating modelformset from a modelform
896,848
<p>I have a model MyModel which contains a PK - locid, that is an AutoField.</p> <p>I want to construct a model formset from this, with some caveats:</p> <ul> <li>The queryset for the formset should be a custom one (say, order_by('field')) rather than all()</li> <li>Since locid for MyModel is an AutoField and thus hi...
0
2009-05-22T08:22:12Z
902,872
<p>If you like cheap workarounds, why not mangle the <code>locid</code> into the <code>__unicode__</code> method? The user is guaranteed to see it, and no special knowledge of django-admin is required.</p> <p>But, to be fair, all my answers to django-admin related questions tend along the lines of "don't strain to ha...
0
2009-05-24T01:38:21Z
[ "python", "django", "formset", "modelform" ]
Creating modelformset from a modelform
896,848
<p>I have a model MyModel which contains a PK - locid, that is an AutoField.</p> <p>I want to construct a model formset from this, with some caveats:</p> <ul> <li>The queryset for the formset should be a custom one (say, order_by('field')) rather than all()</li> <li>Since locid for MyModel is an AutoField and thus hi...
0
2009-05-22T08:22:12Z
912,892
<p>I ended up using a template side variable to do this, as I mentioned here:</p> <p><a href="http://stackoverflow.com/questions/896153/how-to-show-hidden-autofield-in-django-formset">http://stackoverflow.com/questions/896153/how-to-show-hidden-autofield-in-django-formset</a></p>
1
2009-05-26T21:35:34Z
[ "python", "django", "formset", "modelform" ]
Running multiple processes and capturing the output in python with pygtk
896,874
<p>I'd like to write a simple application that runs multiple programs and displays their output in multiple terminal (style) windows. In addition, I want to be able to read the stdout/stderr of these processes and search for keywords in the output.</p> <p>I've tried implementing this two ways in python, the first usi...
1
2009-05-22T08:29:23Z
897,075
<p>I did something similar to this using the <a href="http://docs.python.org/library/subprocess.html#popen-objects" rel="nofollow">subprocess.Popen</a>. For each process I actually ended up redirecting the stdout and stderr to a temporary file, then periodically checking the file for updates and dumping the output into...
1
2009-05-22T09:33:18Z
[ "python" ]
Running multiple processes and capturing the output in python with pygtk
896,874
<p>I'd like to write a simple application that runs multiple programs and displays their output in multiple terminal (style) windows. In addition, I want to be able to read the stdout/stderr of these processes and search for keywords in the output.</p> <p>I've tried implementing this two ways in python, the first usi...
1
2009-05-22T08:29:23Z
897,094
<p>If you go with igkuk's suggestion, I got <a href="http://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes-using-python">some good advice on watching files for changes</a> in a related question. That worked pretty well for me (I was watching a log file for changes).</p>
1
2009-05-22T09:39:28Z
[ "python" ]
Running multiple processes and capturing the output in python with pygtk
896,874
<p>I'd like to write a simple application that runs multiple programs and displays their output in multiple terminal (style) windows. In addition, I want to be able to read the stdout/stderr of these processes and search for keywords in the output.</p> <p>I've tried implementing this two ways in python, the first usi...
1
2009-05-22T08:29:23Z
897,209
<p>You want to use <a href="http://docs.python.org/library/select.html" rel="nofollow">select</a> to monitor the pipes from your subprocesses. It's better than polling.</p>
0
2009-05-22T10:15:39Z
[ "python" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
897,061
<p>If it's part of a Database query you should be able to use a <a href="http://python.projects.postgresql.org/docs/0.8/driver.html#parameterized-statements">Parameterized SQL Statement</a>.</p> <p>As well as escaping your quotes, this will deal with all special characters and will protect you from <a href="http://sta...
23
2009-05-22T09:30:32Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
2,429,209
<p>For a solution to a more generic problem, I have a program where I needed to store <em>any</em> set of characters in a flat file, tab delimited. Obviously, having tabs in the 'set' was causing problems.</p> <p>Instead of output_f.write(str), I used output_f.write(repr(str)), which solved my problem. It is slower to...
0
2010-03-11T22:28:36Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
2,429,285
<p>If you're using psycopg2 that has a method for escaping strings: <strong><code>psycopg2.extensions.adapt()</code></strong> See <a href="http://stackoverflow.com/questions/309945/how-to-quote-a-string-value-explicitly-python-db-api-psycopg2">http://stackoverflow.com/questions/309945/how-to-quote-a-string-value-explic...
2
2010-03-11T22:40:43Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
9,028,006
<p>Triple-double quotes are best for escaping:</p> <pre>string = """This will span across 'single quotes', "double quotes", and literal EOLs all in the same string."""</pre>
1
2012-01-27T01:44:37Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
13,676,745
<p>The easy and standard way to escape strings, and convert other objects to programmatic form, is to use the build in repr() function. It converts an object into the representation you would need to enter it with manual code.</p> <p>E.g.:</p> <pre><code>s = "I'm happy I am \"here\" now" print repr(s) &gt;&gt; 'I\'...
5
2012-12-03T03:27:26Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
14,930,615
<p>Use <code>json.dumps</code>.</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; print json.dumps('a"bc') "a\"bc" </code></pre>
19
2013-02-18T06:25:16Z
[ "python", "database", "escaping", "sql-injection" ]
A good way to escape quotes in a database query string?
897,020
<p>I've tried all manner of Python modules and they either escape too much or in the wrong way. What's the best way you've found to escape quotes (", ') in Python?</p>
25
2009-05-22T09:16:28Z
37,897,034
<p>Reply for old thread, but the best way still missing here..</p> <p>If using psycopg2, it's execute -method has buildin escaping.</p> <pre><code>cursor.execute("SELECT column FROM table WHERE column=%s AND column2=%s", (value1, value2)) </code></pre> <p>Note, that you are giving two arguments to execute method (st...
1
2016-06-18T12:36:48Z
[ "python", "database", "escaping", "sql-injection" ]
Python cgi FieldStorage slow, alternatives?
897,206
<p>I have a python cgi script that receives files uploaded via a http post. The files can be large (300+ Mb). The thing is, cgi.FieldStorage() is incredibly slow for getting the file (a 300Mb file took 6 minutes to be "received"). Doing the same by just reading the stdin took around 15 seconds. The problem with the lat...
3
2009-05-22T10:15:13Z
897,218
<p>"[I] would have to parse the data myself"</p> <p>Why? CGI has a <a href="http://docs.python.org/library/cgi.html#cgi.parse" rel="nofollow">parser</a> you can call explicitly.</p> <p>Read the uploaded stream and save it in a local disk file. </p> <p>For blazing speed, use a StringIO in-memory file. Just be awa...
2
2009-05-22T10:20:42Z
[ "python", "cgi" ]
What is the idiomatic way of invoking a list of functions in Python?
897,362
<p>I have a list of callback functions that I need to invoke when an event is fired. Is this idiomatic python? </p> <pre><code>def first_callback(m): print 'first ' + m def second_callback(m): print 'second ' + m lst = [first_callback, second_callback] map(lambda x: x("event_info"),lst) #is this how you do it? ...
4
2009-05-22T11:09:53Z
897,373
<p>Use <code>map</code> only for functions without side effects (like <code>print</code>). That is, use it only for functions that just return something. In this case a regular loop is more idiomatic:</p> <pre><code>for f in lst: f("event_info") </code></pre> <p><strong>Edit</strong>: also, as of Python 3.0, <a h...
17
2009-05-22T11:14:00Z
[ "python" ]
What is the idiomatic way of invoking a list of functions in Python?
897,362
<p>I have a list of callback functions that I need to invoke when an event is fired. Is this idiomatic python? </p> <pre><code>def first_callback(m): print 'first ' + m def second_callback(m): print 'second ' + m lst = [first_callback, second_callback] map(lambda x: x("event_info"),lst) #is this how you do it? ...
4
2009-05-22T11:09:53Z
897,379
<p>You could also write a list comprehension:</p> <pre><code>[f("event_info") for f in lst] </code></pre> <p>However, it does have the side-effect of returning a list of results.</p>
3
2009-05-22T11:15:11Z
[ "python" ]
What is the idiomatic way of invoking a list of functions in Python?
897,362
<p>I have a list of callback functions that I need to invoke when an event is fired. Is this idiomatic python? </p> <pre><code>def first_callback(m): print 'first ' + m def second_callback(m): print 'second ' + m lst = [first_callback, second_callback] map(lambda x: x("event_info"),lst) #is this how you do it? ...
4
2009-05-22T11:09:53Z
1,813,292
<p>If you have dynamically created list of functions simple for is good:</p> <p>for function in list_of_functions: function(your_argument_here)</p> <p>But if you use OOP and some classes should know that some event happens (generally changes) consider introducing Observer design pattern: <a href="http://en.wikipe...
0
2009-11-28T18:26:31Z
[ "python" ]
What is the idiomatic way of invoking a list of functions in Python?
897,362
<p>I have a list of callback functions that I need to invoke when an event is fired. Is this idiomatic python? </p> <pre><code>def first_callback(m): print 'first ' + m def second_callback(m): print 'second ' + m lst = [first_callback, second_callback] map(lambda x: x("event_info"),lst) #is this how you do it? ...
4
2009-05-22T11:09:53Z
1,814,326
<p>I have to ask if this is truly the OP's intent. When I hear "invoke a list of functions", I assume that just looping over the list of functions and calling each one is so obvious, that there must be more to the question. For instance, given these two string manipulators:</p> <pre><code>def reverse(s): return ...
0
2009-11-29T01:10:55Z
[ "python" ]
Regular Expression Sub Problems
897,480
<p>Okay so i have a semi weridish problem with re.sub.</p> <p>Take the following code:</p> <pre><code>import re str_to_be_subbed = r'somefile.exe -i &lt;INPUT&gt;' some_str = r'C:\foobar' s = re.sub(r'\&lt;INPUT\&gt;', some_str, str_to_be_subbed) print s </code></pre> <p>I would think it would give me:</p> <pre><co...
3
2009-05-22T11:53:15Z
897,492
<p><code>\f</code> is the <em>form feed</em> character. Escape it and it works:</p> <pre><code>some_str = r'C:\\foobar' </code></pre> <p>Another solution:</p> <pre><code>s = re.sub(r'&lt;INPUT&gt;', some_str.encode("string_escape"), str_to_be_subbed) </code></pre>
3
2009-05-22T11:58:35Z
[ "python", "regex" ]
Regular Expression Sub Problems
897,480
<p>Okay so i have a semi weridish problem with re.sub.</p> <p>Take the following code:</p> <pre><code>import re str_to_be_subbed = r'somefile.exe -i &lt;INPUT&gt;' some_str = r'C:\foobar' s = re.sub(r'\&lt;INPUT\&gt;', some_str, str_to_be_subbed) print s </code></pre> <p>I would think it would give me:</p> <pre><co...
3
2009-05-22T11:53:15Z
897,496
<p>Don't use regular expressions:</p> <pre><code>print str_to_be_subbed.replace("&lt;INPUT&gt;",some_str) </code></pre> <p>As the <a href="http://docs.python.org/library/re.html#re.sub" rel="nofollow">documentation</a> says:</p> <blockquote> <p>repl can be a string or a function; if it is a string, any backslash...
3
2009-05-22T11:58:57Z
[ "python", "regex" ]
Regular Expression Sub Problems
897,480
<p>Okay so i have a semi weridish problem with re.sub.</p> <p>Take the following code:</p> <pre><code>import re str_to_be_subbed = r'somefile.exe -i &lt;INPUT&gt;' some_str = r'C:\foobar' s = re.sub(r'\&lt;INPUT\&gt;', some_str, str_to_be_subbed) print s </code></pre> <p>I would think it would give me:</p> <pre><co...
3
2009-05-22T11:53:15Z
897,513
<p>Your example doesn't need regexps, use <a href="http://docs.python.org/library/stdtypes.html#str.replace" rel="nofollow"><code>str.replace()</code></a>:</p> <pre><code>&gt;&gt;&gt; str_to_be_subbed.replace('&lt;INPUT&gt;',some_str) 'somefile.exe -i C:\\foobar' &gt;&gt;&gt; </code></pre>
0
2009-05-22T12:03:14Z
[ "python", "regex" ]
Regular Expression Sub Problems
897,480
<p>Okay so i have a semi weridish problem with re.sub.</p> <p>Take the following code:</p> <pre><code>import re str_to_be_subbed = r'somefile.exe -i &lt;INPUT&gt;' some_str = r'C:\foobar' s = re.sub(r'\&lt;INPUT\&gt;', some_str, str_to_be_subbed) print s </code></pre> <p>I would think it would give me:</p> <pre><co...
3
2009-05-22T11:53:15Z
14,576,905
<p>Python docs saying...</p> <p>re.sub(pattern, repl, string, count=0, flags=0) Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern isn’t found, string is returned unchanged. repl can be a string or a function; if it is a strin...
2
2013-01-29T06:27:07Z
[ "python", "regex" ]
How do I refer to a class method outside a function body in Python?
897,739
<p>I want to do a one time callback registration within Observer. I don't want to do the registration inside init or other function. I don't know if there is a class level equivalent for init</p> <pre><code> class Observer: @classmethod def on_new_user_registration(new_user): #body of h...
1
2009-05-22T13:06:20Z
897,830
<p>I've come to accept that python isn't very intuitive when it comes to functional programming within class definitions. See <a href="http://stackoverflow.com/questions/707090/decorators-and-in-class">this question</a>. The problem with the first method is that Observer doesn't exist as a namespace until the class h...
1
2009-05-22T13:23:50Z
[ "python" ]
How do I refer to a class method outside a function body in Python?
897,739
<p>I want to do a one time callback registration within Observer. I don't want to do the registration inside init or other function. I don't know if there is a class level equivalent for init</p> <pre><code> class Observer: @classmethod def on_new_user_registration(new_user): #body of h...
1
2009-05-22T13:06:20Z
897,840
<p>oops. sorry about that. All I had to do was to move the subscription outside the class definition</p> <pre><code>class Observer: @classmethod def on_new_user_registration(new_user): #body of handler... #after end of class NewUserRegistered().subscribe(Observer.on_new_user_registration...
0
2009-05-22T13:25:06Z
[ "python" ]
How do I refer to a class method outside a function body in Python?
897,739
<p>I want to do a one time callback registration within Observer. I don't want to do the registration inside init or other function. I don't know if there is a class level equivalent for init</p> <pre><code> class Observer: @classmethod def on_new_user_registration(new_user): #body of h...
1
2009-05-22T13:06:20Z
897,852
<p>What you're doing should work:</p> <pre><code>&gt;&gt;&gt; class foo: ... @classmethod ... def func(cls): ... print 'func called!' ... &gt;&gt;&gt; foo.func() func called! &gt;&gt;&gt; class foo: ... @classmethod ... def func(cls): ... print 'func called!' ... foo.func() ...
0
2009-05-22T13:27:09Z
[ "python" ]
How do I refer to a class method outside a function body in Python?
897,739
<p>I want to do a one time callback registration within Observer. I don't want to do the registration inside init or other function. I don't know if there is a class level equivalent for init</p> <pre><code> class Observer: @classmethod def on_new_user_registration(new_user): #body of h...
1
2009-05-22T13:06:20Z
898,517
<p>I suggest to cut down on the number of classes -- remember that Python isn't Java. Every time you use <code>@classmethod</code> or <code>@staticmethod</code> you should stop and think about it since these keywords are quite rare in Python.</p> <p>Doing it like this works:</p> <pre><code>class BaseEvent(object): ...
2
2009-05-22T15:36:08Z
[ "python" ]