title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
73,050
<p>It may look cleaner using a key instead a cmp:</p> <pre class="lang-py prettyprint-override"><code>newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) </code></pre> <p>or as J.F.Sebastian and others suggested,</p> <pre class="lang-py prettyprint-override"><code>from operator import itemgetter newlist = ...
1,147
2008-09-16T14:39:44Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
73,098
<pre><code>import operator a_list_of_dicts.sort(key=operator.itemgetter('name')) </code></pre> <p>'key' is used to sort by an arbitrary value and 'itemgetter' sets that value to each item's 'name' attribute.</p>
13
2008-09-16T14:43:51Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
73,186
<p>You could use a custom comparison function, or you could pass in a function that calculates a custom sort key. That's usually more efficient as the key is only calculated once per item, while the comparison function would be called many more times.</p> <p>You could do it this way:</p> <pre><code>def mykey(adict): ...
8
2008-09-16T14:52:14Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
73,465
<pre><code>import operator </code></pre> <p>To sort the list of dictionaries by key='name':</p> <pre><code>list_of_dicts.sort(key=operator.itemgetter('name')) </code></pre> <p>To sort the list of dictionaries by key='age':</p> <pre><code>list_of_dicts.sort(key=operator.itemgetter('age')) </code></pre>
68
2008-09-16T15:18:14Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
1,144,907
<p>Here is <a href="http://stackoverflow.com/questions/1143671/python-sorting-list-of-dictionaries-by-multiple-keys/1144405">my answer to a related question on sorting by multiple columns</a>. It also works for the degenerate case where the number of columns is only one.</p>
1
2009-07-17T18:22:08Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
2,858,683
<p>If you want to sort the list by multiple keys you can do the following:</p> <pre><code>my_list = [{'name':'Homer', 'age':39}, {'name':'Milhouse', 'age':10}, {'name':'Bart', 'age':10} ] sortedlist = sorted(my_list , key=lambda elem: "%02d %s" % (elem['age'], elem['name'])) </code></pre> <p>It is rather hackish, sin...
24
2010-05-18T15:28:11Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
12,420,427
<p>I tried something like this:</p> <pre><code>my_list.sort(key=lambda x: x['name']) </code></pre> <p>It worked for integers as well.</p>
2
2012-09-14T08:05:47Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
16,772,049
<p>Using Schwartzian transform from Perl,</p> <pre><code>py = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>do</p> <pre><code>sort_on = "name" decorated = [(dict_[sort_on], dict_) for dict_ in py] decorated.sort() result = [dict_ for (key, dict_) in decorated] </code></pre> <p>gives</p> ...
8
2013-05-27T11:21:03Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
23,102,554
<p>Lets Say I h'v a Dictionary D with elements below. To sort just use key argument in sorted to pass custom function as below</p> <pre><code>D = {'eggs': 3, 'ham': 1, 'spam': 2} def get_count(tuple): return tuple[1] sorted(D.items(), key = get_count, reverse=True) or sorted(D.items(), key = lambda x: x[1], reve...
0
2014-04-16T07:18:21Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
28,094,888
<p>Here is the alternative general solution - it sorts elements of dict by keys and values. The advantage of it - no need to specify keys, and it would still work if some keys are missing in some of dictionaries.</p> <pre><code>def sort_key_func(item): """ helper function used to sort list of dicts :param ite...
3
2015-01-22T17:21:17Z
[ "python", "list", "sorting", "dictionary" ]
How do I sort a list of dictionaries by values of the dictionary in Python?
72,899
<p>I got a list of dictionaries and want that to be sorted by a value of that dictionary.</p> <p>This</p> <pre><code>[{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] </code></pre> <p>sorted by name, should become</p> <pre><code>[{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] </code></pre>
822
2008-09-16T14:27:47Z
39,281,050
<p>Using the pandas package is a fairly lightweight and quick method:</p> <pre><code>import pandas as pd listOfDicts = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] df = pd.DataFrame(listOfDicts) df = df.sort_values('name') sorted_listOfDicts = df.T.to_dict().values() </code></pre> <p>Here are some benchma...
0
2016-09-01T21:21:11Z
[ "python", "list", "sorting", "dictionary" ]
How to create a triple-join table with Django
72,945
<p>Using Django's built in models, how would one create a triple-join between three models.</p> <p>For example:</p> <ul> <li>Users, Roles, and Events are the models.</li> <li>Users have many Roles, and Roles many Users. (ManyToMany)</li> <li>Events have many Users, and Users many Events. (ManyToMany)</li> <li>But fo...
9
2008-09-16T14:31:21Z
73,153
<p>I'd recommend just creating an entirely separate model for this.</p> <pre><code>class Assignment(Model): user = ForeignKey(User) role = ForeignKey(Role) event = ForeignKey(Event) </code></pre> <p>This lets you do all the usual model stuff, such as</p> <pre><code>user.assignment_set.filter(role__name="...
3
2008-09-16T14:49:20Z
[ "python", "django", "model-view-controller", "model" ]
How to create a triple-join table with Django
72,945
<p>Using Django's built in models, how would one create a triple-join between three models.</p> <p>For example:</p> <ul> <li>Users, Roles, and Events are the models.</li> <li>Users have many Roles, and Roles many Users. (ManyToMany)</li> <li>Events have many Users, and Users many Events. (ManyToMany)</li> <li>But fo...
9
2008-09-16T14:31:21Z
76,221
<p>I'd model Role as an association class between Users and Roles, thus,</p> <pre><code>class User(models.Model): ... class Event(models.Model): ... class Role(models.Model): user = models.ForeignKey(User) event = models.ForeignKey(Event) </code></pre> <p>And enforce the one role per user per ev...
0
2008-09-16T19:51:09Z
[ "python", "django", "model-view-controller", "model" ]
How to create a triple-join table with Django
72,945
<p>Using Django's built in models, how would one create a triple-join between three models.</p> <p>For example:</p> <ul> <li>Users, Roles, and Events are the models.</li> <li>Users have many Roles, and Roles many Users. (ManyToMany)</li> <li>Events have many Users, and Users many Events. (ManyToMany)</li> <li>But fo...
9
2008-09-16T14:31:21Z
77,898
<p><strong>zacherates</strong> writes:</p> <blockquote> <p>I'd model Role as an association class between Users and Roles (...)</p> </blockquote> <p>I'd also reccomed this solution, but you can also make use of some syntactical sugar provided by Django: <a href="http://docs.djangoproject.com/en/dev/topics/db/models...
8
2008-09-16T22:22:52Z
[ "python", "django", "model-view-controller", "model" ]
How to create a triple-join table with Django
72,945
<p>Using Django's built in models, how would one create a triple-join between three models.</p> <p>For example:</p> <ul> <li>Users, Roles, and Events are the models.</li> <li>Users have many Roles, and Roles many Users. (ManyToMany)</li> <li>Events have many Users, and Users many Events. (ManyToMany)</li> <li>But fo...
9
2008-09-16T14:31:21Z
16,290,256
<p>While trying to find a faster three-table join for my own Django models, I came across this question. By default, Django 1.1 uses INNER JOINs which can be slow on InnoDB. For a query like:</p> <pre><code>def event_users(event_name): return User.objects.filter(roles__events__name=event_name) </code></pre> <p>...
0
2013-04-30T00:11:45Z
[ "python", "django", "model-view-controller", "model" ]
Is there a python package to interface with MS Cluster?
73,439
<p>I need to write a couple of python scripts to automate the installation of Microsoft Cluster Ressources. </p> <p>More specifically, I'll need to query MS Cluster to be able to get a list of ressources with their parameters. And I also need to be able to create resources and set their parameters. </p> <p>Is someone...
1
2008-09-16T15:16:19Z
73,594
<p>You can accomplish this using Microsoft COM objects. You can take a look at <a href="http://www.boddie.org.uk/python/COM.html" rel="nofollow">here</a> on how to start using them.</p>
1
2008-09-16T15:29:37Z
[ "python", "windows", "cluster-computing", "pywin32" ]
Is there a python package to interface with MS Cluster?
73,439
<p>I need to write a couple of python scripts to automate the installation of Microsoft Cluster Ressources. </p> <p>More specifically, I'll need to query MS Cluster to be able to get a list of ressources with their parameters. And I also need to be able to create resources and set their parameters. </p> <p>Is someone...
1
2008-09-16T15:16:19Z
187,067
<p>Ok, I tried it this way.</p> <p>Via pythonwin, I used the <em>COM Makepy</em> utility. I generated a python interface for MSCluster.Cluster (in order to have a nice introspection in ipython). </p> <p>Then, localy on my server I do the following:</p> <pre><code>import win32.client mscluster = win32.client.Disptach...
0
2008-10-09T12:39:48Z
[ "python", "windows", "cluster-computing", "pywin32" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
73,673
<pre><code>import sys sys.exit() </code></pre> <p>details from the <a href="https://docs.python.org/2/library/constants.html#exit"><code>sys</code> module documentation</a>:</p> <blockquote> <p><code>sys.<strong>exit</strong>([<em>arg</em>])</code></p> <blockquote> <p>Exit from Python. This is implemented ...
644
2008-09-16T15:36:36Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
73,680
<p>Another way is:</p> <pre><code>raise SystemExit </code></pre>
72
2008-09-16T15:37:13Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
73,695
<pre><code>from sys import exit exit() </code></pre> <p>As a parameter you can pass an exit code, which will be returned to OS. Default is 0.</p>
16
2008-09-16T15:38:28Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
76,374
<p>While you should generally prefer <code>sys.exit</code> because it is more "friendly" to other code, all it actually does is raise an exception.</p> <p>If you are sure that you need to exit a process immediately, and you might be inside of some exception handler which would catch <code>SystemExit</code>, there is a...
48
2008-09-16T20:08:04Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
14,836,329
<p>A simple way to terminate a Python script early is to use the built-in function quit(). There is no need to import any library, and it is efficient and simple.</p> <p>Example:</p> <pre><code>#do stuff if this == that: quit() </code></pre>
89
2013-02-12T15:50:06Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
16,150,238
<p>You can also use simply <code>exit()</code>.</p> <p>Keep in mind that <code>sys.exit()</code>, <code>exit()</code>, <code>quit()</code>, and <code>os._exit(0)</code> <strong>kill</strong> the Python interpreter. Therefore, if it appears in a script called from another script by <code>execfile()</code>, it stops exe...
30
2013-04-22T14:57:00Z
[ "python", "termination" ]
Terminating a Python script
73,663
<p>I am aware of the <code>die()</code> command in PHP which stops a script early.</p> <p>How can I do this in Python?</p>
469
2008-09-16T15:35:55Z
22,504,027
<p>I'm a total novice but surely this is cleaner and more controlled</p> <pre><code>def main(): try: Answer = 1/0 print Answer except: print 'Program terminated' return print 'You wont see this' if __name__ == '__main__': main() </code></pre> <p>...</p> <blockquote>...
8
2014-03-19T11:13:22Z
[ "python", "termination" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
73,807
<p>It's quite common to just use the sendmail command from Python using os.popen</p> <p>Personally, for scripts i didn't write myself, I think just using the SMTP-protocol is better, since it wouldn't require installing say an sendmail clone to run on windows.</p> <p><a href="https://docs.python.org/library/smtplib.h...
3
2008-09-16T15:49:06Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
73,811
<p>The easiest answer is the smtplib, you can find docs on it <a href="http://docs.python.org/lib/SMTP-example.html" rel="nofollow">here</a>. </p> <p>All you need to do is configure your local sendmail to accept connection from localhost, which it probably already does by default. Sure, you're still using SMTP for th...
-4
2008-09-16T15:49:21Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
73,844
<p>This is a simple python function that uses the unix sendmail to deliver a mail.</p> <pre><code>def sendMail(): sendmail_location = "/usr/sbin/sendmail" # sendmail location p = os.popen("%s -t" % sendmail_location, "w") p.write("From: %s\n" % "from@somewhere.com") p.write("To: %s\n" % "to@somewhereel...
24
2008-09-16T15:51:40Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
74,084
<p>Header injection isn't a factor in how you send the mail, it's a factor in how you construct the mail. Check the <a href="https://docs.python.org/2/library/email.html">email</a> package, construct the mail with that, serialise it, and send it to <code>/usr/sbin/sendmail</code> using the <a href="https://docs.python...
79
2008-09-16T16:12:37Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
5,545,462
<p>This question is very old, but it's worthwhile to note that there is a message construction and e-mail delivery system called <a href="http://www.python-turbomail.org/" rel="nofollow">TurboMail</a> which has been available since before this message was asked.</p> <p>It's now being ported to support Python 3 and upd...
3
2011-04-04T23:24:04Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
17,345,007
<p>I was just searching around for the same thing and found a good example on the Python website: <a href="http://docs.python.org/2/library/email-examples.html" rel="nofollow">http://docs.python.org/2/library/email-examples.html</a></p> <p>From the site mentioned:</p> <pre><code># Import smtplib for the actual sendin...
-2
2013-06-27T13:49:32Z
[ "python", "email", "sendmail" ]
Sending mail via sendmail from python
73,781
<p>If I want to send mail not via SMTP, but rather via sendmail, is there a library for python that encapsulates this process?</p> <p>Better yet, is there a good library that abstracts the whole 'sendmail -versus- smtp' choice?</p> <p>I'll be running this script on a bunch of unix hosts, only some of which are listen...
47
2008-09-16T15:46:43Z
32,673,496
<p>Jim's answer did not work for me in Python 3.4. I had to add an additional <code>universal_newlines=True</code> argument to <code>subrocess.Popen()</code></p> <pre><code>from email.mime.text import MIMEText from subprocess import Popen, PIPE msg = MIMEText("Here is the body of my message") msg["From"] = "me@exampl...
3
2015-09-19T21:38:31Z
[ "python", "email", "sendmail" ]
Is there a common way to check in Python if an object is any function type?
74,092
<p>I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so ...
6
2008-09-16T16:13:09Z
74,138
<pre><code>if hasattr(obj, '__call__'): pass </code></pre> <p>This also fits in better with Python's "duck typing" philosophy, because you don't really care <em>what</em> it is, so long as you can call it.</p> <p>It's worth noting that <code>callable()</code> is being removed from Python and is not present in 3.0.</p...
2
2008-09-16T16:18:26Z
[ "python", "types" ]
Is there a common way to check in Python if an object is any function type?
74,092
<p>I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so ...
6
2008-09-16T16:13:09Z
74,295
<p>If you want to exclude classes and other random objects that may have a <code>__call__</code> method, and only check for functions and methods, these three functions in the <a href="http://docs.python.org/lib/module-inspect.html"><code>inspect</code> module</a></p> <pre><code>inspect.isfunction(obj) inspect.isbuilt...
5
2008-09-16T16:35:51Z
[ "python", "types" ]
Is there a common way to check in Python if an object is any function type?
74,092
<p>I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so ...
6
2008-09-16T16:13:09Z
75,370
<p>Depending on what you mean by 'class':</p> <pre><code>callable( obj ) and not inspect.isclass( obj ) </code></pre> <p>or:</p> <pre><code>callable( obj ) and not isinstance( obj, types.ClassType ) </code></pre> <p>For example, results are different for 'dict':</p> <pre><code>&gt;&gt;&gt; callable( dict ) and not...
1
2008-09-16T18:20:47Z
[ "python", "types" ]
Is there a common way to check in Python if an object is any function type?
74,092
<p>I have a function in Python which is iterating over the attributes returned from dir(obj), and I want to check to see if any of the objects contained within is a function, method, built-in function, etc. Normally you could use callable() for this, but I don't want to include classes. The best I've come up with so ...
6
2008-09-16T16:13:09Z
75,507
<p>The inspect module has exactly what you want:</p> <pre><code>inspect.isroutine( obj ) </code></pre> <p>FYI, the code is:</p> <pre><code>def isroutine(object): """Return true if the object is any kind of function or method.""" return (isbuiltin(object) or isfunction(object) or ismet...
13
2008-09-16T18:34:03Z
[ "python", "types" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
74,445
<p>I think you need to give some more information. It's not really possible to answer why it's not working based on the information in the question. The basic documentation for random is at: <a href="https://docs.python.org/library/random.html" rel="nofollow">https://docs.python.org/library/random.html</a></p> <p>Y...
2
2008-09-16T16:51:27Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
74,459
<p>Can you post an example of what you're trying to do? It's not clear from your question what the actual problem is.</p> <p>Here's an example of how to use the random module:</p> <pre><code>import random print random.randint(0,10) </code></pre>
0
2008-09-16T16:52:11Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
74,476
<pre><code>Python 2.5.2 (r252:60911, Jun 16 2008, 18:27:58) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import random &gt;&gt;&gt; random.seed() &gt;&gt;&gt; dir(random) ['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCO...
1
2008-09-16T16:53:00Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
74,485
<p>Seems to work fine for me. Check out the methods in the <a href="http://docs.python.org/lib/module-random.html" rel="nofollow">official python documentation</a> for random:</p> <pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; random.random() 0.69130806168332215 &gt;&gt;&gt; random.uniform(1, 10) 8.838417091743629...
0
2008-09-16T16:53:43Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
75,360
<p>Works for me:</p> <pre><code>Python 2.5.1 (r251:54863, Jun 15 2008, 18:24:51) [GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import random &gt;&gt;&gt; brothers = ['larry', 'curly', 'moe'] &gt;&gt;&gt; random.choice(brothers) 'mo...
0
2008-09-16T18:19:19Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
75,427
<p>You probably have a file named random.py or random.pyc in your working directory. That's shadowing the built-in random module. You need to rename random.py to something like my_random.py and/or remove the random.pyc file.</p> <p>To tell for sure what's going on, do this:</p> <pre><code>&gt;&gt;&gt; import random...
34
2008-09-16T18:26:02Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
76,404
<p>Is it possible that the script you run is called random.py itself?</p>
1
2008-09-16T20:11:09Z
[ "python" ]
Random in python 2.5 not working?
74,430
<p>I am trying to use the <code>import random</code> statement in python, but it doesn't appear to have any methods in it to use.</p> <p>Am I missing something?</p>
8
2008-09-16T16:49:33Z
78,304
<p>This is happening because you have a random.py file in the python search path, most likely the current directory.</p> <p>Python is searching for modules using sys.path, which normally includes the current directory before the standard site-packages, which contains the expected random.py.</p> <p>This is expected to...
3
2008-09-16T23:22:30Z
[ "python" ]
How do I get the name of a python class as a string?
75,440
<p>What method do I call to get the name of a class?</p>
30
2008-09-16T18:26:47Z
75,456
<p>It's not a method, it's a field. The field is called <code>__name__</code>. <code>class.__name__</code> will give the name of the class as a string. <code>object.__class__.__name__</code> will give the name of the class of an object.</p>
28
2008-09-16T18:27:58Z
[ "python" ]
How do I get the name of a python class as a string?
75,440
<p>What method do I call to get the name of a class?</p>
30
2008-09-16T18:26:47Z
75,467
<pre><code>In [1]: class test(object): ...: pass ...: In [2]: test.__name__ Out[2]: 'test' </code></pre>
33
2008-09-16T18:28:51Z
[ "python" ]
How do I get the name of a python class as a string?
75,440
<p>What method do I call to get the name of a class?</p>
30
2008-09-16T18:26:47Z
77,222
<p>In [8]: <code>str('2'.__class__)</code><br /> Out[8]: <code>"&lt;type 'str'&gt;"</code><br /></p> <p>In [9]: <code>str(len.__class__)</code><br /> Out[9]: <code>"&lt;type 'builtin_function_or_method'&gt;"</code><br /></p> <p>In [10]: <code>str(4.6.__class__)</code><br /> Out[10]: <code>"&lt;type 'float'&gt;"</code...
1
2008-09-16T21:16:24Z
[ "python" ]
How do I get the name of a python class as a string?
75,440
<p>What method do I call to get the name of a class?</p>
30
2008-09-16T18:26:47Z
83,155
<p>I agree with Mr.Shark, but if you have an instance of a class, you'll need to use its <code>__class__</code> member:</p> <pre><code>&gt;&gt;&gt; class test(): ... pass ... &gt;&gt;&gt; a_test = test() &gt;&gt;&gt; &gt;&gt;&gt; a_test.__name__ Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in...
6
2008-09-17T13:26:31Z
[ "python" ]
How to use form values from an unbound form
75,621
<p>I have a web report that uses a Django form (new forms) for fields that control the query used to generate the report (start date, end date, ...). The issue I'm having is that the page should work using the form's initial values (unbound), but I can't access the cleaned_data field unless I call is_valid(). But is_va...
7
2008-09-16T18:45:34Z
75,815
<p>You can pass a dictionary of initial values to your form:</p> <pre><code>if request.method == "GET": # calculate my_start_date and my_end_date here... form = MyForm( { 'start_date': my_start_date, 'end_date': my_end_date} ) ... </code></pre> <p>See the <a href="http://docs.djangoproject.com/en/dev/ref/form...
0
2008-09-16T19:07:39Z
[ "python", "django" ]
How to use form values from an unbound form
75,621
<p>I have a web report that uses a Django form (new forms) for fields that control the query used to generate the report (start date, end date, ...). The issue I'm having is that the page should work using the form's initial values (unbound), but I can't access the cleaned_data field unless I call is_valid(). But is_va...
7
2008-09-16T18:45:34Z
75,923
<p>If you add this method to your form class:</p> <pre><code>def get_cleaned_or_initial(self, fieldname): if hasattr(self, 'cleaned_data'): return self.cleaned_data.get(fieldname) else: return self[fieldname].field.initial </code></pre> <p>you could then re-write your code as:<...
4
2008-09-16T19:18:57Z
[ "python", "django" ]
How to use form values from an unbound form
75,621
<p>I have a web report that uses a Django form (new forms) for fields that control the query used to generate the report (start date, end date, ...). The issue I'm having is that the page should work using the form's initial values (unbound), but I can't access the cleaned_data field unless I call is_valid(). But is_va...
7
2008-09-16T18:45:34Z
81,301
<p><em>Unbound</em> means there is no data associated with form (either initial or provided later), so the validation may fail. As mentioned in other answers (and in your own conclusion), you have to provide initial values and check for both bound data and initial values.</p> <p>The use case for forms is form processi...
1
2008-09-17T09:02:07Z
[ "python", "django" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
76,198
<p>cakephp.org</p> <p>Cakephp is really good, really close to ruby on rails (1.2). It is in php, works very well on shared hosts and is easy to implement. </p> <p>The only downside is that the documentation is somewhat lacking, but you quickly get it and quickly start doing cool stuff.</p> <p>I totally recommend ca...
1
2008-09-16T19:49:26Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
77,693
<blockquote> <p>However it's written in Python which means there's little real support in the way of deployment/packaging, debugging, profilers and other tools that make building and maintaining applications much easier.</p> </blockquote> <p>Python has:</p> <ol> <li>a <a href="http://docs.python.org/lib/m...
9
2008-09-16T22:02:55Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
78,424
<p>I have two friends who originally started writing an application using Ruby on Rails, but ran into a number of issues and limitations. After about 8 weeks of working on it, they decided to investigate other alternatives.</p> <p>They settled on the <a href="http://www.catalystframework.org" rel="nofollow">Catalyst ...
3
2008-09-16T23:45:56Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
81,699
<p>Personally I made some rather big projects with Django, but I can compare only with said "montrosities" (Spring, EJB) and really low-level stuff like Twisted.</p> <p>Web frameworks using interpreted languages are mostly in its infancy and all of them (actively maintained, that is) are getting better with every day....
1
2008-09-17T10:12:02Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
83,075
<p>By "good deployment" are you comparing it with Java's EAR files, which allow you to deploy web applications by uploading a single file to a J2EE server? (And, to a lesser extent, WAR files; EAR files can have WAR files for dependent projects)</p> <p>I don't think Django or Rails have gotten quite to that point yet,...
1
2008-09-17T13:19:14Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
97,778
<p>The "good deployment" issue -- for Python -- doesn't have the Deep Significance that it has for Java.</p> <p>Python deployment for Django is basically "move the files". You can run straight out of the subversion trunk directory if you want to.</p> <p>You can, without breaking much of a sweat, using the Python <a ...
3
2008-09-18T22:47:52Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
460,360
<p>Grails.</p> <p>Grails just looks like Rails (Ruby),but it uses groovy which is simpler than java. It uses java technology and you can use any java lib without any trouble.</p> <p>I also choose Grails over simplicity and there are lots of java lib (such as jasper report, jawr etc) and I am glad that now they join ...
9
2009-01-20T07:32:41Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
1,955,727
<p>You asked for someone who used both Grails and Django. I've done work on both for big projects. Here's my Thoughts:</p> <p><strong>IDE's:</strong> Django works really well in Eclipse, Grails works really well in IntelliJ Idea.</p> <p><strong>Debugging:</strong> Practically the same (assuming you use IntelliJ for G...
26
2009-12-23T22:42:54Z
[ "python", "django", "frameworks" ]
Django -vs- Grails -vs-?
75,798
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out ther...
16
2008-09-16T19:05:48Z
1,997,668
<p>The statement that <em>grails deletes the database on start-up</em> is completely wrong. It's behavior on start-up is completely configurable and easy to configure. I generally use create-drop when running an app in dev mode. I use update when I run in test and production.</p> <p>I also love the bootstrap proces...
7
2010-01-04T05:37:55Z
[ "python", "django", "frameworks" ]
Best way to access table instances when using SQLAlchemy's declarative syntax
75,829
<p>All the docs for SQLAlchemy give <code>INSERT</code> and <code>UPDATE</code> examples using the local table instance (e.g. <code>tablename.update()</code>... )</p> <p>Doing this seems difficult with the declarative syntax, I need to reference <code>Base.metadata.tables["tablename"]</code> to get the table reference...
5
2008-09-16T19:08:29Z
77,962
<p>via the <code>__table__</code> attribute on your declarative class</p>
2
2008-09-16T22:30:56Z
[ "python", "sql", "sqlalchemy" ]
Best way to access table instances when using SQLAlchemy's declarative syntax
75,829
<p>All the docs for SQLAlchemy give <code>INSERT</code> and <code>UPDATE</code> examples using the local table instance (e.g. <code>tablename.update()</code>... )</p> <p>Doing this seems difficult with the declarative syntax, I need to reference <code>Base.metadata.tables["tablename"]</code> to get the table reference...
5
2008-09-16T19:08:29Z
156,968
<p>well it works for me:</p> <pre><code>class Users(Base): __tablename__ = 'users' __table_args__ = {'autoload':True} users = Users() print users.__table__.select() </code></pre> <p>...SELECT users.......</p>
7
2008-10-01T10:14:09Z
[ "python", "sql", "sqlalchemy" ]
Best way to access table instances when using SQLAlchemy's declarative syntax
75,829
<p>All the docs for SQLAlchemy give <code>INSERT</code> and <code>UPDATE</code> examples using the local table instance (e.g. <code>tablename.update()</code>... )</p> <p>Doing this seems difficult with the declarative syntax, I need to reference <code>Base.metadata.tables["tablename"]</code> to get the table reference...
5
2008-09-16T19:08:29Z
315,406
<p>There may be some confusion between <strong>table</strong> (the object) and <strong>tablename</strong> (the name of the table, a string). Using the <strong>table</strong> class attribute works fine for me.</p>
0
2008-11-24T20:45:32Z
[ "python", "sql", "sqlalchemy" ]
Undo with GTK TextView
76,096
<p>I'm trying to keep dependencies to a minimum for a program I contribute to, it's a small text editor.</p> <p>GTK Textview doesn't seem to come with a built-in undo function. Is there any reference implementation I've been missing on so far? Is everyone writing their own undo function for their TextView widgets?</p>...
8
2008-09-16T19:38:45Z
76,453
<p>As far as I know, GTK TextView doesn't include an undo function. So while I am not familiar with Python's GTK library, I would think it doesn't have one.</p> <p>The Ruby-GNOME2 project has a <a href="http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+Editor" rel="nofollow">sample text editor</a> that has undo/r...
3
2008-09-16T20:15:54Z
[ "python", "gtk", "text-editor", "undo" ]
Undo with GTK TextView
76,096
<p>I'm trying to keep dependencies to a minimum for a program I contribute to, it's a small text editor.</p> <p>GTK Textview doesn't seem to come with a built-in undo function. Is there any reference implementation I've been missing on so far? Is everyone writing their own undo function for their TextView widgets?</p>...
8
2008-09-16T19:38:45Z
80,992
<p>Depending on just how dependency-averse you are, and what kind of text editor you're building, <a href="http://projects.gnome.org/gtksourceview/" rel="nofollow">GtkSourceView</a> adds undo/redo among many other things. Very worth looking at if you want some of the other <a href="http://projects.gnome.org/gtksourcevi...
3
2008-09-17T08:05:09Z
[ "python", "gtk", "text-editor", "undo" ]
Undo with GTK TextView
76,096
<p>I'm trying to keep dependencies to a minimum for a program I contribute to, it's a small text editor.</p> <p>GTK Textview doesn't seem to come with a built-in undo function. Is there any reference implementation I've been missing on so far? Is everyone writing their own undo function for their TextView widgets?</p>...
8
2008-09-16T19:38:45Z
586,115
<p>as a follwow-up: I ported gtksourceview's undo mechanism to python: <a href="http://bitbucket.org/tiax/gtk-textbuffer-with-undo/" rel="nofollow">http://bitbucket.org/tiax/gtk-textbuffer-with-undo/</a></p> <p>serves as a drop-in replacement for gtksourceview's undo</p> <p>(OP here, but launchpad open-id doesn't wor...
4
2009-02-25T14:09:27Z
[ "python", "gtk", "text-editor", "undo" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,093
<p>If it ain't broke don't fix it.</p> <p>Just write a quick test, but bear in mind that each language will be faster with certain functions then the other.</p>
1
2008-09-16T21:06:27Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,112
<p>The only right answer is "It depends". There's a lot of variables that can affect the performance, and you can optimize many things in either situation.</p>
0
2008-09-16T21:08:06Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,138
<p>Check out the programming languages shootout:</p> <p><a href="http://dada.perl.it/shootout/" rel="nofollow">http://dada.perl.it/shootout/</a></p>
1
2008-09-16T21:09:32Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,166
<p>You need to be able to make a business case for switching, not just that "it's faster". If a site built on technology B costs 20% more in developer time for maintenance over a set period (say, 3 years), it would likely be cheaper to add another webserver to the system running technology A to bridge the performance ...
1
2008-09-16T21:11:49Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,174
<p>It's about the same. The difference shouldn't be large enough to be the reason to pick one or the other. Don't try to compare them by writing your own tiny benchmarks (<code>"hello world"</code>) because you will probably not have results that are representative of a real web site generating a more complex page.</p>...
2
2008-09-16T21:13:00Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,220
<p>PHP and Python are similiar enough to not warrent any kind of switching.</p> <p>Any performance improvement you might get from switching from one language to another would be vastly outgunned by simply not spending the money on converting the code (you don't code for free right?) and just buy more hardware.</p>
2
2008-09-16T21:16:15Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
77,297
<p>There's no point in attempting to convince your employer to port from PHP to Python, especially not for an existing system, which is what I think you implied in your question.</p> <p>The reason for this is that you already have a (presumably) working system, with an existing investment of time and effort (and exper...
27
2008-09-16T21:24:46Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
79,744
<p>It sounds like you don't want to compare the two <strong>languages</strong>, but that you want to compare two <strong>web systems</strong>.</p> <p>This is tricky, because there are many variables involved.</p> <p>For example, Python web applications can take advantage of <a href="http://code.google.com/p/modwsgi/"...
81
2008-09-17T03:44:12Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
510,276
<p>an IS organization would not ponder this unless availability was becoming an issue.</p> <p>if so the case, look into replication, load balancing and lots of ram.</p>
1
2009-02-04T06:28:30Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
2,412,215
<p>I had to come back to web development at my new job, and, if not Pylons/Python, maybe I would have chosen to live in jungle instead :) In my subjective opinion, PHP is for kindergarten, I did it in my 3rd year of uni and, I believe, many self-respecting (or over-estimating) software engineers will not want to be bot...
0
2010-03-09T20:13:47Z
[ "php", "python", "performance", "pylons" ]
Which is faster, python webpages or php webpages?
77,086
<p>Does anyone know how the speed of pylons(or any of the other frameworks) compares to a similar website made with php? I know that serving a python base webpage via cgi is slower than php because of its long start up every time.</p> <p>I enjoy using pylons and I would still use it if it was slower than php. But if ...
27
2008-09-16T21:05:26Z
33,627,050
<p>I would assume that PHP (>5.5) is faster and more reliable for complex web applications because it is optimized for website scripting.</p> <p>Many of the benchmarks you will find at the net are only made to prove that the favoured language is better. But you can not compare 2 languages with a mathematical task runn...
1
2015-11-10T09:47:19Z
[ "php", "python", "performance", "pylons" ]
What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?
77,198
<p>I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc).</p> <p>Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't?</p>
3
2008-09-16T21:15:02Z
77,458
<p>Good question. I'm not a ruby guy (i use java with flex), but what I believe differentiates blazeds vs commercial livecycle ds is</p> <ol> <li>Streaming protocol support (rtmp) - competition for comet and such, delivering video</li> <li>Some advanced stuff for hibernate detached objects and large resultset caching ...
1
2008-09-16T21:42:49Z
[ "python", "ruby-on-rails", "ruby", "flex", "blazeds" ]
What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?
77,198
<p>I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc).</p> <p>Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't?</p>
3
2008-09-16T21:15:02Z
83,014
<p>Adobe has two products: Livecycle Data Services ES (LCDS) and BlazeDS. BlazeDS contains a subset of LCDS features and was made open source. Unfortunately NIO channels (RTMP NIO/HTTP) and the DataManagement features are implemented only in LCDS, not BlazeDS.</p> <p>BlazeDS can be used only to integrate Flex with Jav...
2
2008-09-17T13:13:50Z
[ "python", "ruby-on-rails", "ruby", "flex", "blazeds" ]
What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?
77,198
<p>I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc).</p> <p>Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't?</p>
3
2008-09-16T21:15:02Z
98,180
<p>Other than NIO (RTMP) channels, LCDS include also the "data management" features. </p> <p>Using this feature, you basically implement, in an ActionScript class, a CRUD-like interface defined by LCDS, and you get:</p> <ul> <li>automatic progressive list loading (large lists/datagrids loads while scrolling)</li> <li...
3
2008-09-19T00:02:00Z
[ "python", "ruby-on-rails", "ruby", "flex", "blazeds" ]
What does BlazeDS Livecycle Data Services do, that something like PyAMF or RubyAMF not do?
77,198
<p>I'm doing a tech review and looking at AMF integration with various backends (Rails, Python, Grails etc).</p> <p>Lots of options are out there, question is, what do the Adobe products do (BlazeDS etc) that something like RubyAMF / pyAMF don't?</p>
3
2008-09-16T21:15:02Z
99,603
<p>The data management features for LCDS described here are certainly valid, however I believe they do not let you actually develop a solution faster. A developer still has to write ALL the data access code, query execution, extracting data from datareaders into value objects. ALL of this has been solved a dozen of tim...
3
2008-09-19T04:17:40Z
[ "python", "ruby-on-rails", "ruby", "flex", "blazeds" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
77,563
<p>Because it's the name of a builtin function.</p>
3
2008-09-16T21:52:12Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
77,600
<p>It's bad to name any variable after a built in function. One of the reasons is because it can be confusing to a reader that doesn't know the name is overridden.</p>
3
2008-09-16T21:54:56Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
77,606
<p>'id' is a built-in method in Python. Assigning a value to 'id' will overwrite the method. It is best to use either an identifier before as in "some_id" or use it in a different capitalization method.</p> <p>The built in method takes a single parameter and returns an integer for the memory address of the object that...
1
2008-09-16T21:55:32Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
77,612
<p><code>id()</code> is a fundamental built-in:</p> <blockquote> <p>Help on built-in function <code>id</code> in module <code>__builtin__</code>:</p> <pre class="lang-none prettyprint-override"><code>id(...) id(object) -&gt; integer Return the identity of an object. This is guaranteed to be unique ...
87
2008-09-16T21:55:59Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
77,925
<p>I might say something unpopular here: <code>id()</code> is a rather specialized built-in function that is rarely used in business logic. Therefore I don't see a problem in using it as a variable name in a tight and well-written function, where it's clear that id doesn't mean the built-in function.</p>
30
2008-09-16T22:27:26Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
78,433
<p>Because python is a dynamic language, it's not usually a good idea to give a variable and a function the same name. id() is a function in python, so it's recommend not to use a variable named id. Bearing that in mind, that applies to all functions that you might use... a variable shouldn't have the same name as a ...
-6
2008-09-16T23:47:16Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
79,198
<p><code>id</code> is a built-in function that gives the memory address of an object. If you name one of your functions <code>id</code>, you will have to say <code>__builtins__.id</code> to get the original. Renaming <code>id</code> globally is confusing in anything but a small script. </p> <p>However, reusing built-i...
38
2008-09-17T02:13:34Z
[ "python" ]
'id' is a bad variable name in Python
77,552
<p>Why is it bad to name a variable <code>id</code> in Python?</p>
73
2008-09-16T21:50:58Z
28,091,085
<p>In <strong>PEP 8 - Style Guide for Python Code</strong>, the following guidance appears in the section <a href="https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles">Descriptive: Naming Styles </a>:</p> <blockquote> <ul> <li><p><code>single_trailing_underscore_</code> : used by convention to avoi...
17
2015-01-22T14:24:12Z
[ "python" ]
iBATIS for Python?
77,731
<p>At my current gig, we use iBATIS through Java to CRUD our databases. I like the abstract qualities of the tool, especially when working with legacy databases, as it doesn't impose its own syntax on you.</p> <p><strong>I'm looking for a Python analogue to this library</strong>, since the website only has Java/.NET/...
4
2008-09-16T22:05:58Z
77,859
<p>Perhaps SQLAlchemy SQL Expression support is suitable. See the <a href="http://docs.sqlalchemy.org/en/rel_0_5/sqlexpression.html" rel="nofollow">documentation</a>. </p>
1
2008-09-16T22:17:30Z
[ "python", "orm", "ibatis" ]
iBATIS for Python?
77,731
<p>At my current gig, we use iBATIS through Java to CRUD our databases. I like the abstract qualities of the tool, especially when working with legacy databases, as it doesn't impose its own syntax on you.</p> <p><strong>I'm looking for a Python analogue to this library</strong>, since the website only has Java/.NET/...
4
2008-09-16T22:05:58Z
78,147
<p>iBatis sequesters the SQL DML (or the definitions of the SQL) in an XML file. It specifically focuses on the mapping between the SQL and some object model defined elsewhere.</p> <p>SQL Alchemy can do this -- but it isn't really a very complete solution. Like iBatis, you can merely have SQL table definitions and a...
10
2008-09-16T22:53:33Z
[ "python", "orm", "ibatis" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
77,978
<p>Nope, that is the only formula for the centroid of a collection of points. See Wikipedia: <a href="http://en.wikipedia.org/wiki/Centroid">http://en.wikipedia.org/wiki/Centroid</a></p>
12
2008-09-16T22:33:06Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
77,985
<p>You got it. What you are calculating is the centroid, or the mean vector.</p>
-1
2008-09-16T22:33:34Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
77,997
<p>A "more accurate centroid" I believe centroid is defined the way you calculated it hence there can be no "more accurate centroid".</p>
-1
2008-09-16T22:34:34Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
78,046
<p>you can use increase accuracy summation - Kahan summation - was that what you had in mind? </p>
3
2008-09-16T22:40:36Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
78,058
<p>Yes that is the correct formula.</p> <p>If you have a large number of points you can exploit the symmetry of the problem (be it cylindrical, spherical, mirror). Otherwise, you can borrow from statistics and average a random number of the points and just have a bit of error.</p>
0
2008-09-16T22:42:12Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
85,787
<p>Potentially more efficient: if you're calculating this multiple times, you can speed this up quite a bit by keeping two standing variables </p> <pre><code>N # number of points sums = dict(x=0,y=0,z=0) # sums of the locations for each point </code></pre> <p>then changing N and sums whenever points are created or...
2
2008-09-17T17:48:20Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
88,394
<p>You vaguely mention "a way to get a more accurate centroid". Maybe you're talking about a centroid that isn't affected by outliers. For example, the <i>average</i> household income in the USA is probably very high, because a small number of <i>very</i> rich people skew the average; they are the "outliers". For th...
10
2008-09-17T22:35:44Z
[ "python", "math", "3d", "geometry" ]
What's the best way to calculate a 3D (or n-D) centroid?
77,936
<p>As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of points, as in:</p> <pre><code>centroid = average(x), average(y), average(z) </code></pre> <p>where <code>x</code>, <code>...
10
2008-09-16T22:28:58Z
37,780,869
<p>Contrary to the common refrain here, there are different ways to define (and calculate) a center of a point cloud. The first and most common solution has been suggested by you already and I will <strong>not</strong> argue that there is anything wrong with this:</p> <p><code>centroid = average(x), average(y), averag...
0
2016-06-13T01:56:07Z
[ "python", "math", "3d", "geometry" ]
OPENGL User Interface Programming
78,238
<p>I'm developing a graphical application to present data (not a game but a real workhorse app). It needs to be cross platform, so I have chosen:</p> <ul> <li>python</li> <li>openGL (I need 3D, blending, textures etc)</li> <li>pyopengl</li> <li>wx/pywx - windowing, dialogs etc.</li> </ul> <p>The last component - WX -...
1
2008-09-16T23:11:31Z
78,397
<p>You might want to look at <a href="http://clutter-project.org/" rel="nofollow">Clutter</a>, it looks pretty cool. I haven't used it yet but I intend to in an upcoming personal project.</p>
1
2008-09-16T23:39:31Z
[ "python", "user-interface", "opengl" ]
OPENGL User Interface Programming
78,238
<p>I'm developing a graphical application to present data (not a game but a real workhorse app). It needs to be cross platform, so I have chosen:</p> <ul> <li>python</li> <li>openGL (I need 3D, blending, textures etc)</li> <li>pyopengl</li> <li>wx/pywx - windowing, dialogs etc.</li> </ul> <p>The last component - WX -...
1
2008-09-16T23:11:31Z
78,404
<p>This is not an answer, more of a plea: Please don't do that.</p> <p>Your reimplemented widgets will lack all sorts of functionality that users will miss. Will your text-entry boxes support drag'n'drop? Copy/paste? Right-to-left scripts? Drag-select? Double-click-select? Will all these mechanisms follow the native c...
12
2008-09-16T23:41:09Z
[ "python", "user-interface", "opengl" ]