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 |
|---|---|---|---|---|---|---|---|---|---|
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 3,431,104 | <p>Finally found a good solution to this on <a href="http://groups.google.com/group/django-developers/browse_thread/thread/44cd834438cfda77/557f53697658ab04?lnk=gst&q=template%20model#557f53697658ab04">the dev mailing list</a>:</p>
<p>In the view add:</p>
<pre><code>from django.forms.models import model_to_dict
... | 56 | 2010-08-07T16:13:17Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 5,658,690 | <p>I'm using this, <a href="https://github.com/miracle2k/django-tables" rel="nofollow">https://github.com/miracle2k/django-tables</a>.</p>
<pre><code><table>
<tr>
{% for column in table.columns %}
<th><a href="?sort={{ column.name_toggled }}">{{ column }}</a></th>
{% end... | 2 | 2011-04-14T04:49:13Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 7,154,321 | <p>Instead of editing every model I would recommend to write <strong>one template tag</strong> which will return all field of <strong>any model</strong> given. <br>
Every object has list of fields <code>._meta.fields</code>.<br>
Every field object has attribute <code>name</code> that will return it's name and method <... | 4 | 2011-08-22T22:25:33Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 7,769,930 | <p>There should really be a built-in way to do this. I wrote this utility <code>build_pretty_data_view</code> that takes a model object and form instance (a form based on your model) and returns a <code>SortedDict</code>.</p>
<p>Benefits to this solution include:</p>
<ul>
<li>It preserves order using Django's built-... | 7 | 2011-10-14T15:29:09Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 9,942,455 | <p>Ok, I know this is a bit late, but since I stumbled upon this before finding the correct answer so might someone else.</p>
<p>From the <a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.values">django docs</a>:</p>
<pre><code># This list contains a Blog object.
>... | 9 | 2012-03-30T11:55:40Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 10,325,754 | <p>Below is mine, inspired by <em>shacker's</em> <code>get_all_fields</code>.
It gets a dict of one model instance, if encounter relation field, then asign the field value a dict recursively.</p>
<pre><code>def to_dict(obj, exclude=[]):
"""çæä¸ä¸ª dict, éå½å
å«ä¸ä¸ª model instance æ°æ®.
"""
tr... | 5 | 2012-04-26T00:37:56Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 13,075,271 | <p>This approach shows how to use a class like django's ModelForm and a template tag like {{ form.as_table }}, but have all the table look like data output, not a form.</p>
<p>The first step was to subclass django's TextInput widget:</p>
<pre><code>from django import forms
from django.utils.safestring import mark_saf... | 2 | 2012-10-25T18:52:02Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 14,625,776 | <p>I used <a href="http://stackoverflow.com/a/3431104/2022534">http://stackoverflow.com/a/3431104/2022534</a> but replaced Django's model_to_dict() with this to be able to handle ForeignKey:</p>
<pre><code>def model_to_dict(instance):
data = {}
for field in instance._meta.fields:
data[field.name] = fie... | 5 | 2013-01-31T12:26:44Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 14,667,584 | <p>You can have a form do the work for you.</p>
<pre><code>def my_model_view(request, mymodel_id):
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
model = get_object_or_404(MyModel, pk=mymodel_id)
form = MyModelForm(instance=model)
return render(request, 'model.html... | 6 | 2013-02-02T23:15:59Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 26,508,233 | <p>Take a look at <a href="https://pypi.python.org/pypi/django-etc" rel="nofollow">django-etc</a> application. It has <code>model_field_verbose_name</code> template tag to get field verbose name from templates: <a href="http://django-etc.rtfd.org/en/latest/models.html#model-field-template-tags" rel="nofollow">http://dj... | 0 | 2014-10-22T13:11:02Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 27,872,439 | <p>Django 1.7 solution for me:</p>
<p>There variables are exact to the question, but you should definitely be able to dissect this example</p>
<p>The key here is to pretty much use the <code>.__dict__</code> of the model<br>
<strong>views.py</strong>:</p>
<pre><code>def display_specific(request, key):
context = {
... | 3 | 2015-01-10T03:01:07Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 30,278,233 | <p>In light of Django 1.8's release (and the formalization of the <a href="https://docs.djangoproject.com/en/1.8/ref/models/meta/" rel="nofollow">Model _meta API</a>, I figured I would update this with a more recent answer.</p>
<p>Assuming the same model:</p>
<pre><code>class Client(Model):
name = CharField(max_l... | 15 | 2015-05-16T16:41:36Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 36,880,596 | <p>You can use the <code>values()</code> method of a <code>queryset</code>, which returns a dictionary. Further, this method accepts a list of fields to subset on. The <code>values()</code> method will not work with <code>get()</code>, so you must use <code>filter()</code> (refer to the <a href="https://docs.djangoproj... | 3 | 2016-04-27T04:52:44Z | [
"python",
"django",
"django-templates"
] |
Iterate over model instance field names and values in template | 2,170,228 | <p>I'm trying to create a basic template to display the selected instance's field values, along with their names. Think of it as just a standard output of the values of that instance in table format, with the field name (verbose_name specifically if specified on the field) in the first column and the value of that fie... | 123 | 2010-01-31T01:48:11Z | 39,384,659 | <p>Just an edit of @wonder</p>
<p><code>def to_dict(obj, exclude=[]):
tree = {}
for field in obj._meta.fields + obj._meta.many_to_many:
if field.name in exclude or \
'%s.%s' % (type(obj).__name__, field.name) in exclude:
continue
try :
value = getattr(obj, fie... | 1 | 2016-09-08T07:13:14Z | [
"python",
"django",
"django-templates"
] |
Can existing virtualenv be upgraded gracefully? | 2,170,252 | <p>I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6. </p>
<p>Here is how it was originally set up: </p>
<pre><code>virtualenv --no-site-packages -p python2.5 myenv
</code></pre>
<p>I now run virtualenv in the same directory to upgrade: </p>
<pre><code>virtualenv --no-site-packages -... | 53 | 2010-01-31T01:58:45Z | 2,170,343 | <p>You should create a new <code>virtualenv</code> using <code>python2.6</code> and then, after activating the new env, use its <code>python2.6</code> and its <code>easy_install</code> to install new versions of any site packages you need. Beware that the path name to the <code>virtualenv</code> is hardwired into vari... | 4 | 2010-01-31T02:38:53Z | [
"python",
"virtualenv"
] |
Can existing virtualenv be upgraded gracefully? | 2,170,252 | <p>I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6. </p>
<p>Here is how it was originally set up: </p>
<pre><code>virtualenv --no-site-packages -p python2.5 myenv
</code></pre>
<p>I now run virtualenv in the same directory to upgrade: </p>
<pre><code>virtualenv --no-site-packages -... | 53 | 2010-01-31T01:58:45Z | 2,171,079 | <p>You can use the Python 2.6 virtualenv to "revirtual" the existing directory. You will have to reinstall all the modules you installed though. I often have a virtual directory for developing a module, and virtualenv the same directory with many versions of Python, and it works just fine. :)</p>
| 38 | 2010-01-31T08:48:00Z | [
"python",
"virtualenv"
] |
Can existing virtualenv be upgraded gracefully? | 2,170,252 | <p>I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6. </p>
<p>Here is how it was originally set up: </p>
<pre><code>virtualenv --no-site-packages -p python2.5 myenv
</code></pre>
<p>I now run virtualenv in the same directory to upgrade: </p>
<pre><code>virtualenv --no-site-packages -... | 53 | 2010-01-31T01:58:45Z | 21,637,195 | <p>Install a second Python on CentOS</p>
<ol>
<li>download python</li>
<li><p>install to diff local</p>
<pre><code>configure --prefix=/opt/virtualenv/python
make && make install
</code></pre></li>
<li><p>create virtual env using new python</p>
<pre><code>virtualenv /opt/virtualenv --python=/opt/python276/bi... | 2 | 2014-02-07T20:30:30Z | [
"python",
"virtualenv"
] |
Can existing virtualenv be upgraded gracefully? | 2,170,252 | <p>I have a virtualenv created for Python 2.5 and want to "upgrade" it to Python 2.6. </p>
<p>Here is how it was originally set up: </p>
<pre><code>virtualenv --no-site-packages -p python2.5 myenv
</code></pre>
<p>I now run virtualenv in the same directory to upgrade: </p>
<pre><code>virtualenv --no-site-packages -... | 53 | 2010-01-31T01:58:45Z | 27,436,646 | <p>If you're using OS X, try <a href="http://stackoverflow.com/a/24724360/2293304">this</a> if you want to upgrade Python to a minor-increased version (e.g. 2.7.6 to 2.7.8) while keeping third-party libraries work.</p>
<p>It work for me on 5 different virtual environments with Django installed.</p>
| 0 | 2014-12-12T04:03:27Z | [
"python",
"virtualenv"
] |
Django and NoneType object is not callable | 2,170,303 | <p>I have such model:</p>
<pre><code>class Body(models.Model):
point = models.TextField()
description = models.TextField(blank = True)
order = models.IntegerField(default = 0, blank = True)
</code></pre>
<p>When I am adding in django admin interface a new record I am getting </p>
<p>'NoneType' object is ... | 0 | 2010-01-31T02:22:51Z | 2,171,238 | <p>I've found that </p>
<pre><code>order = models.IntegerField(default = 0, blank = True)
</code></pre>
<p>was the reason of my problem. When I've changed 'order' name to something else I've got my problem fixed. :)</p>
| 1 | 2010-01-31T09:54:24Z | [
"python",
"django"
] |
wx 'easy gui' library; how do I keep this code from crashing IDLE & Other python IDEs? | 2,170,389 | <p>When I run this code in IDLE, it crashes. However, if I run it outside of IDLE it works just fine.</p>
<p>There are a couple of Python IDEs that are written in python that suffer the same problem, but if I use an IDE/editor that's not based on it, those run fine as well.</p>
<p>Is there any way of modifying this ... | 0 | 2010-01-31T02:53:00Z | 9,868,195 | <p>The most recent version of IDLE (2.7.2) with wx 2.8.11.0 on Ubuntu does not crash IDLE.</p>
| 0 | 2012-03-26T07:29:35Z | [
"python",
"python-idle",
"wx"
] |
Using Python Reg Exp to read data from file | 2,170,461 | <p>I'm having trouble using python reg exp to read data from a file.</p>
<p>The file has data I want and some info I'm not interested in. An example of the info I'm interested in is below. The number of rows will vary</p>
<pre><code>FREQ VM(VOUT)
1.000E+00 4.760E+01
1.002E+00 4.749E+01
Y
</code></pre>
... | 4 | 2010-01-31T03:31:35Z | 2,170,481 | <p>I think this will get you what you want. As long as the file is consistent.</p>
<pre><code>from csv import reader
with open('file') as f:
listoftuples = [(float(row[0]), float(row[1]))
for row in reader(f, delimiter=' ')
if row and row[0] != 'FREQ']
</code></pre>
<p>If you ... | 3 | 2010-01-31T03:44:49Z | [
"python",
"regex"
] |
Using Python Reg Exp to read data from file | 2,170,461 | <p>I'm having trouble using python reg exp to read data from a file.</p>
<p>The file has data I want and some info I'm not interested in. An example of the info I'm interested in is below. The number of rows will vary</p>
<pre><code>FREQ VM(VOUT)
1.000E+00 4.760E+01
1.002E+00 4.749E+01
Y
</code></pre>
... | 4 | 2010-01-31T03:31:35Z | 2,170,662 | <p>Not nearly as elegant as <a href="http://stackoverflow.com/questions/2170461/using-python-reg-exp-to-read-data-from-file/2170481#2170481">Tor's answer</a>. No regexps either. Bring on the downvotes!</p>
<pre><code>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import decimal
import os
def main():
we_care = F... | 0 | 2010-01-31T05:26:39Z | [
"python",
"regex"
] |
Using Python Reg Exp to read data from file | 2,170,461 | <p>I'm having trouble using python reg exp to read data from a file.</p>
<p>The file has data I want and some info I'm not interested in. An example of the info I'm interested in is below. The number of rows will vary</p>
<pre><code>FREQ VM(VOUT)
1.000E+00 4.760E+01
1.002E+00 4.749E+01
Y
</code></pre>
... | 4 | 2010-01-31T03:31:35Z | 2,171,090 | <pre><code>import decimal
flag=0
result=[]
for line in open("file"):
line=line.rstrip()
if line == "Y": flag=0
if line.startswith("FREQ VM"):
flag=1
continue
if flag and line:
result.append(map(decimal.Decimal,line.split()))
print result
</code></pre>
| 1 | 2010-01-31T08:51:09Z | [
"python",
"regex"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 2,170,994 | <p>There's no direct support in the form of a <code>parent</code> attribute, but you can perhaps use the patterns described <a href="http://effbot.org/zone/element.htm#accessing-parents">here</a> to achieve the desired effect. The following one-liner is suggested (from the linked-to post) to create a child-to-parent ma... | 24 | 2010-01-31T08:04:25Z | [
"python",
"elementtree"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 20,132,342 | <p><a href="http://stackoverflow.com/a/2170994/1556416">Vinay's answer</a> should still work, but for Python 2.7+ and 3.2+ the following is recommended:</p>
<pre><code>parent_map = {c:p for p in tree.iter() for c in p}
</code></pre>
<p><code>getiterator()</code> is deprecated in favor of <code>iter()</code>, and it's... | 11 | 2013-11-21T21:31:37Z | [
"python",
"elementtree"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 21,963,494 | <p>Another way if just want a single subElement's parent and also known the subElement's xpath.</p>
<pre><code>parentElement = subElement.find(xpath+"/..")
</code></pre>
| 2 | 2014-02-23T02:41:36Z | [
"python",
"elementtree"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 27,286,097 | <p>If you are using lxml, I was able to get the parent element with the following:</p>
<pre><code>parent_node = next(child_node.iterancestors())
</code></pre>
| 2 | 2014-12-04T04:04:37Z | [
"python",
"elementtree"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 33,280,875 | <p>You can use xpath <code>...</code> notation in ElementTree.</p>
<pre><code><parent>
<child id="123">data1</child>
</parent>
xml.findall('.//child[@id="123"]...')
>> [<Element 'parent'>]
</code></pre>
| 2 | 2015-10-22T12:18:20Z | [
"python",
"elementtree"
] |
access ElementTree node parent node | 2,170,610 | <p>I am using the builtin Python ElementTree module. It is straightforward to access children, but what about parent nor sibling nodes? - can this be done efficiently without traversing the entire tree?</p>
| 32 | 2010-01-31T05:02:47Z | 33,904,949 | <p>As mentioned in <a href="http://stackoverflow.com/questions/24239435/get-parent-element-after-using-find-method-xml-etree-elementtree">Get parent element after using find method (xml.etree.ElementTree)</a> you would have to do an indirect search for parent.
Having xml:</p>
<pre><code><a>
<b>
<c>... | 2 | 2015-11-24T22:19:25Z | [
"python",
"elementtree"
] |
Using a python module's C API in my own C module | 2,170,625 | <p>This seems to be sort of what I want, except I want to make an instance of a C PyObject in another C module.</p>
<p><a href="http://stackoverflow.com/questions/1147452/create-instance-of-a-python-class-declared-in-python-with-c-api">Create instance of a python class , declared in python, with C API</a></p>
<p>But ... | 3 | 2010-01-31T05:10:43Z | 2,170,718 | <p>The trick is to write the normal Python routine, but in C. Use <a href="http://docs.python.org/c-api/import.html#PyImport_ImportModule" rel="nofollow"><code>PyImport_ImportModule()</code></a>, <a href="http://docs.python.org/c-api/object.html#PyObject_GetAttr" rel="nofollow"><code>PyObject_GetAttr()</code></a>, and ... | 1 | 2010-01-31T05:51:18Z | [
"python",
"module",
"linker",
"pygame"
] |
Using a python module's C API in my own C module | 2,170,625 | <p>This seems to be sort of what I want, except I want to make an instance of a C PyObject in another C module.</p>
<p><a href="http://stackoverflow.com/questions/1147452/create-instance-of-a-python-class-declared-in-python-with-c-api">Create instance of a python class , declared in python, with C API</a></p>
<p>But ... | 3 | 2010-01-31T05:10:43Z | 2,170,778 | <p>I googled it in a single <a href="http://www.python.org/doc/2.5.2/ext/embedding.html" rel="nofollow">"I'm feeling lucky."</a></p>
| 0 | 2010-01-31T06:12:19Z | [
"python",
"module",
"linker",
"pygame"
] |
Using a python module's C API in my own C module | 2,170,625 | <p>This seems to be sort of what I want, except I want to make an instance of a C PyObject in another C module.</p>
<p><a href="http://stackoverflow.com/questions/1147452/create-instance-of-a-python-class-declared-in-python-with-c-api">Create instance of a python class , declared in python, with C API</a></p>
<p>But ... | 3 | 2010-01-31T05:10:43Z | 5,773,766 | <p>You <em>can</em> use the pygame C-API, even though it is probably not meant to be used in that way (which then again begs the question why the pygame headers are installed with the pygame package).</p>
<p>An extension built against such an "internal" API is likely to break when the next version/build of pygame come... | 0 | 2011-04-24T22:49:05Z | [
"python",
"module",
"linker",
"pygame"
] |
Why (dictionary.keys()).sort() is not working in python? | 2,170,632 | <p>I'm new to Python and can't understand why a thing like this does not work.
I can't find the issue raised elsewhere either.</p>
<pre><code>toto = {'a':1, 'c':2 , 'b':3}
toto.keys().sort() #does not work (yields none)
(toto.keys()).sort() #does not work (yields none)
eval('toto.keys()').sort() #d... | 2 | 2010-01-31T05:13:49Z | 2,170,638 | <p><code>sort()</code> sorts the list <em>in place</em>. It returns <code>None</code> to prevent you from thinking that it's leaving the original list alone and returning a sorted copy of it.</p>
| 7 | 2010-01-31T05:16:37Z | [
"python",
"sorting"
] |
Why (dictionary.keys()).sort() is not working in python? | 2,170,632 | <p>I'm new to Python and can't understand why a thing like this does not work.
I can't find the issue raised elsewhere either.</p>
<pre><code>toto = {'a':1, 'c':2 , 'b':3}
toto.keys().sort() #does not work (yields none)
(toto.keys()).sort() #does not work (yields none)
eval('toto.keys()').sort() #d... | 2 | 2010-01-31T05:13:49Z | 2,170,643 | <pre><code>sorted(toto.keys())
</code></pre>
<p>Should do what you want. The sort method you're using sorts in place and returns None.</p>
| 7 | 2010-01-31T05:18:09Z | [
"python",
"sorting"
] |
Why (dictionary.keys()).sort() is not working in python? | 2,170,632 | <p>I'm new to Python and can't understand why a thing like this does not work.
I can't find the issue raised elsewhere either.</p>
<pre><code>toto = {'a':1, 'c':2 , 'b':3}
toto.keys().sort() #does not work (yields none)
(toto.keys()).sort() #does not work (yields none)
eval('toto.keys()').sort() #d... | 2 | 2010-01-31T05:13:49Z | 2,170,647 | <p><code>sort()</code> method sort in place, returning <code>none</code>. You have to use <code>sorted(toto.keys())</code> which returns a new iterable, sorted.</p>
| 1 | 2010-01-31T05:18:54Z | [
"python",
"sorting"
] |
Python __init__ argument problem | 2,170,684 | <p>I have some trouble understanding what happens with class init arguments that are lists<br>
like:</p>
<pre><code>class A(object):
def __init__(self, argument=[]):
self.argument = argument[:]
</code></pre>
<p>or:</p>
<pre><code>def __init__(self,argument=None):
self.arguments = arguments or [... | 2 | 2010-01-31T05:39:31Z | 2,170,699 | <p>The list is created when the definition is run, not when the method is executed.</p>
| 4 | 2010-01-31T05:45:02Z | [
"python",
"class",
"list",
"identity",
"equality"
] |
Python __init__ argument problem | 2,170,684 | <p>I have some trouble understanding what happens with class init arguments that are lists<br>
like:</p>
<pre><code>class A(object):
def __init__(self, argument=[]):
self.argument = argument[:]
</code></pre>
<p>or:</p>
<pre><code>def __init__(self,argument=None):
self.arguments = arguments or [... | 2 | 2010-01-31T05:39:31Z | 2,170,715 | <p>I think the question is somewhat unclear, but what I understand from it is that you are wondering how passing a class init a list doesn't make the internal object the same one you pass it, but rather a copy. If this is not the question, tell me, and I'll delete this answer.</p>
<p>Briefly, here's how it works: noth... | 1 | 2010-01-31T05:49:51Z | [
"python",
"class",
"list",
"identity",
"equality"
] |
Python __init__ argument problem | 2,170,684 | <p>I have some trouble understanding what happens with class init arguments that are lists<br>
like:</p>
<pre><code>class A(object):
def __init__(self, argument=[]):
self.argument = argument[:]
</code></pre>
<p>or:</p>
<pre><code>def __init__(self,argument=None):
self.arguments = arguments or [... | 2 | 2010-01-31T05:39:31Z | 2,170,754 | <p>This is a well known <a href="http://zephyrfalcon.org/labs/python_pitfalls.html#5" rel="nofollow" title="5 - Mutable default arguments">python</a> <a href="http://www.ferg.org/projects/python_gotchas.html#contents_item_6" rel="nofollow" title="6 - Mutable defaults for function/method arguments">gotcha</a>.</p>
<p>B... | 4 | 2010-01-31T06:04:18Z | [
"python",
"class",
"list",
"identity",
"equality"
] |
how to wait for a pause in user input in a gtk.TextBuffer? | 2,170,851 | <p>I'm trying to write a simple gui-based application in pygtk which provides 'live' previewing of text-based markup. The markup processing, however, can be quite computationally expensive and slow to run, so updating the preview on every keystroke is not really viable. Instead I'd like to have the update run only wh... | 1 | 2010-01-31T06:58:37Z | 2,171,118 | <p>So i did not have pygtk, so i mimiced your problem using termios and a home made loop for the text input. But the part about the timer should work in gtk too. Please note that the access to the self.timer is not thread safe if you use an object of class example within more than one thread at the time you must lock s... | 0 | 2010-01-31T09:03:25Z | [
"python",
"gtk",
"pygtk"
] |
how to wait for a pause in user input in a gtk.TextBuffer? | 2,170,851 | <p>I'm trying to write a simple gui-based application in pygtk which provides 'live' previewing of text-based markup. The markup processing, however, can be quite computationally expensive and slow to run, so updating the preview on every keystroke is not really viable. Instead I'd like to have the update run only wh... | 1 | 2010-01-31T06:58:37Z | 2,171,634 | <p>so I think I found a solution using <code>glib.timeout_add()</code> instead of <code>threading.Timer</code>:</p>
<pre><code>import gtk, glib
class example:
def __init__(self):
window = gtk.Window()
window.set_title("example")
window.resize(600,400)
box = gtk.HBox(homogeneous = T... | 1 | 2010-01-31T12:26:47Z | [
"python",
"gtk",
"pygtk"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 2,170,915 | <p>A non-slicky method:</p>
<pre><code>def index_containing_substring(the_list, substring):
for i, s in enumerate(the_list):
if substring in s:
return i
return -1
</code></pre>
| 18 | 2010-01-31T07:29:09Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 2,170,921 | <pre><code>def find(l, s):
for i in range(len(l)):
if l[i].find(s)!=-1:
return i
return None # Or -1
</code></pre>
| 2 | 2010-01-31T07:31:11Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 2,170,932 | <p>This is quite slick and fairly efficient.</p>
<pre><code>>>> def find(lst, predicate):
... return (i for i, j in enumerate(lst) if predicate(j)).next()
...
>>> l = ['the cat ate the mouse','the tiger ate the chicken','the horse ate the straw']
>>> find(l, lambda x: 'tiger' in x)
1
</... | 2 | 2010-01-31T07:34:49Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 2,170,939 | <pre><code>def first_substring(strings, substring):
return min(i for i, string in enumerate(strings) if substring in string)
</code></pre>
<p>Note: This will raise <code>ValueError</code> in case no match is found, which is better in my opinion.</p>
| 1 | 2010-01-31T07:36:31Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 2,171,094 | <p>Variation of abyx solution (optimised to stop when the match is found)</p>
<pre><code>def first_substring(strings, substring):
return next(i for i, string in enumerate(strings) if substring in string)
</code></pre>
<p>If you are pre 2.6 you'll need to put the <code>next()</code> at the end</p>
<pre><code>def ... | 3 | 2010-01-31T08:53:05Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 16,200,817 | <pre><code> >>> li = ['my','array','with','words']
>>> reduce(lambda tup, word: (tup[0], True) if not tup[1] and word == 'my' else (tup[0]+1 if not tup[1] else tup[0], tup[1]), li, (0, False))[0]
0
>>> reduce(lambda tup, word: (tup[0], True) if not tup[1] and word == 'words' else (tu... | 1 | 2013-04-24T19:43:54Z | [
"python",
"list"
] |
Get first list index containing sub string in Python | 2,170,900 | <p>For lists, the method list.index(x) returns the index in the list of the first item whose value is x. But if I want to look inside the list items, and not just at the whole items, how do I make the most Pythoninc method for this?</p>
<p>For example, with</p>
<pre><code>l = ['the cat ate the mouse','the tiger ate t... | 13 | 2010-01-31T07:23:13Z | 38,303,263 | <p>If you do not strictly need a function, you could also use this one-liner:</p>
<pre><code>index = [idx for idx, s in enumerate(l) if 'tiger' in s][0]
</code></pre>
| 0 | 2016-07-11T09:16:59Z | [
"python",
"list"
] |
How to check if a user is logged on in mediawiki in a different app? | 2,170,990 | <p>Here is the situation:</p>
<p>I have a mediawiki installation, and a few additional server-side scripts that require more resources and were already written in a different language (python). The python code will be very loosely coupled with the mediawiki code (only called by clicking on a link here or there)</p>
<... | 4 | 2010-01-31T08:01:53Z | 2,179,077 | <p>You can use the <a href="http://www.mediawiki.org/wiki/API%3aQuery_-_Meta#userinfo_.2F_ui" rel="nofollow">MediaWiki API</a> to get the userinfo and parse that in XML. </p>
| 1 | 2010-02-01T18:31:44Z | [
"python",
"authentication",
"mediawiki"
] |
How to check if a user is logged on in mediawiki in a different app? | 2,170,990 | <p>Here is the situation:</p>
<p>I have a mediawiki installation, and a few additional server-side scripts that require more resources and were already written in a different language (python). The python code will be very loosely coupled with the mediawiki code (only called by clicking on a link here or there)</p>
<... | 4 | 2010-01-31T08:01:53Z | 2,456,365 | <blockquote>
<p>All you need to do is essentially forward the session, cookies and all, to the API as if it's the user querying.</p>
</blockquote>
<p>How would one go about doing that? I can access the API directly and see my login info, but if I access it via PHP, it shows me as not being logged in (anonymous user ... | 0 | 2010-03-16T16:51:41Z | [
"python",
"authentication",
"mediawiki"
] |
How to check if a user is logged on in mediawiki in a different app? | 2,170,990 | <p>Here is the situation:</p>
<p>I have a mediawiki installation, and a few additional server-side scripts that require more resources and were already written in a different language (python). The python code will be very loosely coupled with the mediawiki code (only called by clicking on a link here or there)</p>
<... | 4 | 2010-01-31T08:01:53Z | 4,447,649 | <p>I can't comment on Jon's post due to lack of privileges, so I'm posting a new answer to elaborate on his about using MediaWiki API and passing cookies. Hopefully this helps someone.</p>
<p>You can use PHP's cURL library to pass the session cookie value as a cookie to the api.php page in your wiki (you need to creat... | 1 | 2010-12-15T07:27:38Z | [
"python",
"authentication",
"mediawiki"
] |
How to check if a user is logged on in mediawiki in a different app? | 2,170,990 | <p>Here is the situation:</p>
<p>I have a mediawiki installation, and a few additional server-side scripts that require more resources and were already written in a different language (python). The python code will be very loosely coupled with the mediawiki code (only called by clicking on a link here or there)</p>
<... | 4 | 2010-01-31T08:01:53Z | 5,477,091 | <p>mediawiki check if logged in:</p>
<pre><code><?php
global $wgUser;
require_once('StubObject.php');
if( StubObject::isRealObject( $wgUser ) && $wgUser->isLoggedIn())
{
// code or HTML
}
?>
</code></pre>
<p>I have also seen the following for skins (i.e. MonoBook.php), but I have not tested:</p>
... | 0 | 2011-03-29T18:21:44Z | [
"python",
"authentication",
"mediawiki"
] |
Trouble with MySQL UPDATE syntax with the module mysqldb in Python | 2,171,072 | <p>I am attempting to execute the following query via the mysqldb module in python:</p>
<p>for i in self.p.parameter_type:
cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = %s""" % (i,
float(getattr(self.p, i)), self.list_box_parameter.GetStringSelection()))</p>
<p>I keep g... | 0 | 2010-01-31T08:45:44Z | 2,171,104 | <p>It looks like query is formed with wrong syntax.
Could you display string parameter of cursor.execute?</p>
| 0 | 2010-01-31T08:57:49Z | [
"python",
"mysql"
] |
Trouble with MySQL UPDATE syntax with the module mysqldb in Python | 2,171,072 | <p>I am attempting to execute the following query via the mysqldb module in python:</p>
<p>for i in self.p.parameter_type:
cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = %s""" % (i,
float(getattr(self.p, i)), self.list_box_parameter.GetStringSelection()))</p>
<p>I keep g... | 0 | 2010-01-31T08:45:44Z | 2,171,112 | <p>i see now, i think you need to enclose parameter_set_name = %s in quotes such as:</p>
<pre><code>parameter_set_name = "%s"
</code></pre>
<p>otherwise it's trying to acces column M1</p>
<p>so:</p>
<pre><code>cursor.execute("""UPDATE parameters SET %s = %s WHERE parameter_set_name = \"%s\" """ % (i, float(getattr(... | 1 | 2010-01-31T09:00:50Z | [
"python",
"mysql"
] |
no module names _mysql; where is _mysql | 2,171,078 | <pre><code>import MySQLdb
</code></pre>
<p>and </p>
<p>traceback:</p>
<pre><code>Traceback (most recent call last):
File "D:\zjm_code\sphinx_test\a.py", line 1, in <module>
import MySQLdb
File "D:\zjm_code\sphinx_test\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: No mo... | 0 | 2010-01-31T08:47:18Z | 2,171,142 | <p>You need to install MySQLdb correctly. It consists of the python module and platform-dependent library (<code>_mysql.dll</code> in your case). Use the win32 installer from the project page instead of installing just by unpacking sources.</p>
| 3 | 2010-01-31T09:15:09Z | [
"python",
"mysql"
] |
Python - Display string containing entity references as normal text | 2,171,084 | <p>I have a Python string <code>"&#039;&#039;Grassmere&#039;&#039;"</code>
as retrieved from a website.</p>
<p>I would like to have the <code>&#039;</code> displayed as the correct ascii symbol (<code>'</code>) but for some reason python insists on just printing the ascii code.</p>
| 2 | 2010-01-31T08:49:47Z | 2,171,206 | <p>Batteries are included for this one</p>
<pre><code>>>> import xmllib
>>> X=xmllib.XMLParser()
>>> X.translate_references("&#039;&#039;Grassmere&#039;&#039;")
"''Grassmere''"
</code></pre>
| 3 | 2010-01-31T09:40:32Z | [
"python"
] |
Python - Display string containing entity references as normal text | 2,171,084 | <p>I have a Python string <code>"&#039;&#039;Grassmere&#039;&#039;"</code>
as retrieved from a website.</p>
<p>I would like to have the <code>&#039;</code> displayed as the correct ascii symbol (<code>'</code>) but for some reason python insists on just printing the ascii code.</p>
| 2 | 2010-01-31T08:49:47Z | 2,171,219 | <p>Or without additional modules:</p>
<pre><code>re.sub("&#(\d+);", lambda m: chr(int(m.group(1))), "&#039;&#039;Grassmere&#039;&#039;")
</code></pre>
| 1 | 2010-01-31T09:46:30Z | [
"python"
] |
Python - efficient method to remove all non-letters and replace them with underscores | 2,171,095 | <pre><code>def format_title(title):
''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip()))
</code></pre>
<p>Anything faster?</p>
| 10 | 2010-01-31T08:53:09Z | 2,171,100 | <pre><code>import re
title = re.sub("[\W\d]", "_", title.strip())
</code></pre>
<p>should be faster.</p>
<p>If you want to replace a succession of adjacent non-letters with a single underscore, use</p>
<pre><code>title = re.sub("[\W\d]+", "_", title.strip())
</code></pre>
<p>instead which is even faster.</p>
<p>I ... | 16 | 2010-01-31T08:56:24Z | [
"python",
"string",
"performance"
] |
Python - efficient method to remove all non-letters and replace them with underscores | 2,171,095 | <pre><code>def format_title(title):
''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip()))
</code></pre>
<p>Anything faster?</p>
| 10 | 2010-01-31T08:53:09Z | 2,171,119 | <p>The faster way to do it is to use <code>str.translate()</code>
This is ~50 times faster than your way</p>
<pre><code># You only need to do this once
>>> title_trans=''.join(chr(c) if chr(c).isupper() or chr(c).islower() else '_' for c in range(256))
>>> "abcde1234!@%^".translate(title_trans)
'abc... | 20 | 2010-01-31T09:03:27Z | [
"python",
"string",
"performance"
] |
Python - efficient method to remove all non-letters and replace them with underscores | 2,171,095 | <pre><code>def format_title(title):
''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip()))
</code></pre>
<p>Anything faster?</p>
| 10 | 2010-01-31T08:53:09Z | 2,171,126 | <p>Instead of <code>(x.isupper() or x.islower())</code> you should be able to use <a href="http://docs.python.org/library/stdtypes.html#str.isalpha" rel="nofollow"><code>x.isalpha()</code></a>. The <code>isalpha()</code> method might return <code>True</code> for <code>'_'</code> (I don't remember if it does or not) but... | 2 | 2010-01-31T09:06:55Z | [
"python",
"string",
"performance"
] |
Python - efficient method to remove all non-letters and replace them with underscores | 2,171,095 | <pre><code>def format_title(title):
''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip()))
</code></pre>
<p>Anything faster?</p>
| 10 | 2010-01-31T08:53:09Z | 2,171,274 | <p>Curious about this for my own reasons I wrote a quick script to test the different approaches listed here along with just removing the lambda which I expected (incorrectly) would speed up the original solution.</p>
<p>The short version is that the str.translate approach blows the other ones away. As an aside the r... | 1 | 2010-01-31T10:12:21Z | [
"python",
"string",
"performance"
] |
Python - efficient method to remove all non-letters and replace them with underscores | 2,171,095 | <pre><code>def format_title(title):
''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip()))
</code></pre>
<p>Anything faster?</p>
| 10 | 2010-01-31T08:53:09Z | 2,171,546 | <pre><code>import string,sys
letters=string.letters
mystring = list("abc134#$@e##$%%$*&(()#def")
for n,c in enumerate(mystring):
if not c in letters:
mystring[n]="_"
print ''.join(mystring)
</code></pre>
| 0 | 2010-01-31T11:54:02Z | [
"python",
"string",
"performance"
] |
Installing mypysql | 2,171,120 | <p>In the readme file for <a href="http://sourceforge.net/projects/mypysql/" rel="nofollow" title="mysql">mypysql</a>, under the Installation section, all that is written is the following:</p>
<pre><code>$ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql
$ cd mypysql
$ make compile
$ sudo make ins... | 0 | 2010-01-31T09:03:34Z | 2,171,121 | <p>At a shell prompt.</p>
| 1 | 2010-01-31T09:05:42Z | [
"python",
"mysql"
] |
Installing mypysql | 2,171,120 | <p>In the readme file for <a href="http://sourceforge.net/projects/mypysql/" rel="nofollow" title="mysql">mypysql</a>, under the Installation section, all that is written is the following:</p>
<pre><code>$ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql
$ cd mypysql
$ make compile
$ sudo make ins... | 0 | 2010-01-31T09:03:34Z | 2,172,703 | <p>What OS are you using? Maybe this helps: <a href="http://www.aboutdebian.com/compile.htm" rel="nofollow">Compiling Software With Debian Linux</a></p>
| 0 | 2010-01-31T18:05:26Z | [
"python",
"mysql"
] |
Installing mypysql | 2,171,120 | <p>In the readme file for <a href="http://sourceforge.net/projects/mypysql/" rel="nofollow" title="mysql">mypysql</a>, under the Installation section, all that is written is the following:</p>
<pre><code>$ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql
$ cd mypysql
$ make compile
$ sudo make ins... | 0 | 2010-01-31T09:03:34Z | 2,538,683 | <p>I have compile mypysql-0.5 for window using vc2005. The project src at <a href="http://211.147.215.55/down/mypysql-0.5-win.zip" rel="nofollow">mypysql-0.5-win.zip</a></p>
| 0 | 2010-03-29T14:32:33Z | [
"python",
"mysql"
] |
Installing mypysql | 2,171,120 | <p>In the readme file for <a href="http://sourceforge.net/projects/mypysql/" rel="nofollow" title="mysql">mypysql</a>, under the Installation section, all that is written is the following:</p>
<pre><code>$ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql
$ cd mypysql
$ make compile
$ sudo make ins... | 0 | 2010-01-31T09:03:34Z | 7,530,439 | <p>You're not installing it, you're compiling it. To install it you just need to copy mypysql.pyd and libmysql.dll to [your python folder]/DLLs/</p>
<p>You'll need to get libmysql.dll from your mysql folder or download it from the mysql website.</p>
| 0 | 2011-09-23T14:18:07Z | [
"python",
"mysql"
] |
Installing mypysql | 2,171,120 | <p>In the readme file for <a href="http://sourceforge.net/projects/mypysql/" rel="nofollow" title="mysql">mypysql</a>, under the Installation section, all that is written is the following:</p>
<pre><code>$ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql
$ cd mypysql
$ make compile
$ sudo make ins... | 0 | 2010-01-31T09:03:34Z | 17,394,223 | <p>Execute the above code at the command prompt.</p>
<p>If you are using Windows OS then execute it at C:\</p>
<p>If you are using Mac/Unix/Linux like OS, start the terminal and execute it there - []$</p>
<p>You will need to have the administrator privileges to do this.</p>
| 0 | 2013-06-30T19:46:53Z | [
"python",
"mysql"
] |
python-tz am I wrong or it's a bug | 2,171,189 | <p>It's a bit weird it seems that when I want to get a timezone for Europe/Paris with pytz it gets me to the PMT timezone instead of GMT+1 when it seems to work for Europe/Berlin.</p>
<p>Not clear ? Well look at this snippet :</p>
<pre><code>#!/usr/bin/python
import os
import datetime
from pytz.tzfile import build_tz... | 4 | 2010-01-31T09:34:23Z | 2,171,624 | <p><a href="http://pytz.sourceforge.net/">The docs</a> say you can't use <code>datetime.datetime(..., tzinfo)</code> like you're doing:</p>
<blockquote>
<p>Unfortunately using the tzinfo argument of the standard datetime constructors <em>does not work</em> with pytz for many timezones.</p>
</blockquote>
<p>And curi... | 6 | 2010-01-31T12:17:18Z | [
"python",
"timezone"
] |
What Is The Best Way To Play Audio Through Qt? | 2,171,232 | <p>I am building an application in pyQt4 and I want it to be able to play audio files. I was considering doing this through <a href="http://pymedia.org/" rel="nofollow">pyMedia</a> as I could not get anywhere with the documentation, although the QAudio classes did initially look promising. It is important that the solu... | 2 | 2010-01-31T09:52:24Z | 2,171,287 | <p>Use Phonon ( <a href="http://phonon.kde.org/" rel="nofollow">http://phonon.kde.org/</a> ). I used it from Java with success, so I expect it will work even better in Python/Linux.</p>
<p>This might also help:</p>
<p><a href="http://0pointer.de/blog/projects/guide-to-sound-apis.html" rel="nofollow">http://0pointer.d... | 1 | 2010-01-31T10:18:42Z | [
"python",
"audio",
"pyqt4"
] |
What Is The Best Way To Play Audio Through Qt? | 2,171,232 | <p>I am building an application in pyQt4 and I want it to be able to play audio files. I was considering doing this through <a href="http://pymedia.org/" rel="nofollow">pyMedia</a> as I could not get anywhere with the documentation, although the QAudio classes did initially look promising. It is important that the solu... | 2 | 2010-01-31T09:52:24Z | 2,171,346 | <p>As alex said, Phonon looks like your best bet because you <em>can</em> use it with Pyqt. You can find lots of examples of using phonon using google. This one, <a href="http://forum.kde.org/viewtopic.php?f=14&t=84275" rel="nofollow">http://forum.kde.org/viewtopic.php?f=14&t=84275</a>, for example is a command... | 2 | 2010-01-31T10:39:09Z | [
"python",
"audio",
"pyqt4"
] |
where is SeparatedValuesField in my code, i used sphinx | 2,171,314 | <pre><code>from django.db import models
from djangosphinx import SphinxSearch
# A sample model from iBegin
class City(models.Model):
name = models.CharField(max_length=32)
aliases = SeparatedValuesField(blank=True, null=True)#<-------this
slug = models.SlugField(blank=True)... | 1 | 2010-01-31T10:26:02Z | 2,171,327 | <p>Google finds <a href="http://www.davidcramer.net/code/181/custom-fields-in-django.html" rel="nofollow">this page</a>, from the same (non-responsive here) blog.</p>
| 0 | 2010-01-31T10:29:45Z | [
"python",
"django",
"django-sphinx"
] |
where is SeparatedValuesField in my code, i used sphinx | 2,171,314 | <pre><code>from django.db import models
from djangosphinx import SphinxSearch
# A sample model from iBegin
class City(models.Model):
name = models.CharField(max_length=32)
aliases = SeparatedValuesField(blank=True, null=True)#<-------this
slug = models.SlugField(blank=True)... | 1 | 2010-01-31T10:26:02Z | 2,171,330 | <p>It seems to be a user-defined custom form field, one possible definition is on Django Snippets: <a href="http://www.djangosnippets.org/snippets/497/" rel="nofollow">http://www.djangosnippets.org/snippets/497/</a></p>
<p>The blog doesn't seem to be available right now, but perhaps the author has mentioned or used th... | 0 | 2010-01-31T10:30:43Z | [
"python",
"django",
"django-sphinx"
] |
Can Large Python Scripts Drain DiskSpace? | 2,171,395 | <p><em><strong>UPDATE:</em></strong> <em><strong>Interestingly, after almost 15min, I seem to have AUTOMATICALLY restored about 500MB. Hows this happening?</em></strong></p>
<p>I'm on Mac OSX 10.5.6(Leopard). I wrote a python script for a Project-Euler problem. My script had a loop which iterated for an enormous count... | 0 | 2010-01-31T10:59:23Z | 2,171,409 | <p>The only way your script can fill up your disk is if it creates large/many temporary files and doesn't clean up. Just running a Python program cannot itself fill up your disk.</p>
<p>To recover the disk space, you need to figure out where the space is spent and remove the temporary files. Not sure how to do that o... | 2 | 2010-01-31T11:03:28Z | [
"python",
"osx",
"memory",
"caching",
"loops"
] |
Can Large Python Scripts Drain DiskSpace? | 2,171,395 | <p><em><strong>UPDATE:</em></strong> <em><strong>Interestingly, after almost 15min, I seem to have AUTOMATICALLY restored about 500MB. Hows this happening?</em></strong></p>
<p>I'm on Mac OSX 10.5.6(Leopard). I wrote a python script for a Project-Euler problem. My script had a loop which iterated for an enormous count... | 0 | 2010-01-31T10:59:23Z | 2,171,491 | <p>What I first though was that your program used a lot of memory which caused the swap file to grow. However, from the code I can see that it does not consume much memory. Therefore this script is not the cause of the lost space.</p>
| 0 | 2010-01-31T11:33:08Z | [
"python",
"osx",
"memory",
"caching",
"loops"
] |
Can Large Python Scripts Drain DiskSpace? | 2,171,395 | <p><em><strong>UPDATE:</em></strong> <em><strong>Interestingly, after almost 15min, I seem to have AUTOMATICALLY restored about 500MB. Hows this happening?</em></strong></p>
<p>I'm on Mac OSX 10.5.6(Leopard). I wrote a python script for a Project-Euler problem. My script had a loop which iterated for an enormous count... | 0 | 2010-01-31T10:59:23Z | 2,171,550 | <p>That's not python, that's something else on your system using memory... probably your browser.</p>
<p>1GB is not nearly enough free space on a Mac... you need at least 10GB free, so it's time to clean up.</p>
| 0 | 2010-01-31T11:54:47Z | [
"python",
"osx",
"memory",
"caching",
"loops"
] |
Redirect calls to a member of a class in python | 2,171,396 | <p>I was trying to 'extend' a closed class</p>
<pre><code>collections.defaultdict(lambda: 1)
</code></pre>
<p>by addint it 2 methods, called 'vocabulary', and 'wordcount'
apparently it's impossible to setattr method to builin types, nor can I inherit from defaultdic, so I decided to write a class and redirect calls t... | 0 | 2010-01-31T11:00:18Z | 2,171,418 | <p>Either copy from class to class, not instance to instance, or just have <a href="http://docs.python.org/reference/datamodel.html#object.__getattr__" rel="nofollow"><code>.__getattr__()</code></a> delegate to the encapsulated object.</p>
| 3 | 2010-01-31T11:05:09Z | [
"python",
"metaprogramming",
"functional-programming"
] |
Redirect calls to a member of a class in python | 2,171,396 | <p>I was trying to 'extend' a closed class</p>
<pre><code>collections.defaultdict(lambda: 1)
</code></pre>
<p>by addint it 2 methods, called 'vocabulary', and 'wordcount'
apparently it's impossible to setattr method to builin types, nor can I inherit from defaultdic, so I decided to write a class and redirect calls t... | 0 | 2010-01-31T11:00:18Z | 2,171,610 | <p>What do you mean with "cannot inherit from defaultdict"? It works for me (not a very good example, but I'm not sure what you're trying to accomplish, so...):</p>
<pre><code>#!/usr/bin/env python
from collections import defaultdict
import operator
class DD(defaultdict):
def vocabulary(self):
return s... | 1 | 2010-01-31T12:14:48Z | [
"python",
"metaprogramming",
"functional-programming"
] |
How to change caps lock status without key press | 2,171,408 | <p>I am using a python program that is activate when pressing Caps Lock key and I want to be able to turn on/off the caps lock status when the program is active.</p>
<p>I tried to send keys with virtkey but it obviously don't work since the keys just activate the app and don't change the caps lock status. So what is t... | 12 | 2010-01-31T11:03:17Z | 2,171,443 | <p>Use <a href="http://stackoverflow.com/questions/854393/change-keyboard-locks-in-python"><code>sendkeys</code></a> to change the status and <a href="http://pypi.python.org/pypi/python-keyboardleds/0.1" rel="nofollow"><code>keyboardleds</code></a> to change the LED indicators.</p>
<h3>sendkeys:</h3>
<p>From <a href=... | 1 | 2010-01-31T11:13:06Z | [
"python",
"keyboard",
"capslock"
] |
How to change caps lock status without key press | 2,171,408 | <p>I am using a python program that is activate when pressing Caps Lock key and I want to be able to turn on/off the caps lock status when the program is active.</p>
<p>I tried to send keys with virtkey but it obviously don't work since the keys just activate the app and don't change the caps lock status. So what is t... | 12 | 2010-01-31T11:03:17Z | 2,171,452 | <p><strong>On Linux:</strong></p>
<pre><code>import fcntl
import os
KDSETLED = 0x4B32
console_fd = os.open('/dev/console', os.O_NOCTTY)
# Turn on caps lock
fcntl.ioctl(console_fd, KDSETLED, 0x04)
# Turn off caps lock
fcntl.ioctl(console_fd, KDSETLED, 0)
</code></pre>
<p>Source: <a href="http://stackoverflow.com/q... | 5 | 2010-01-31T11:17:41Z | [
"python",
"keyboard",
"capslock"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,558 | <p>If you want to append to a list, use mylist.append(item) instead.</p>
<p>Also, if you iterate a fixed number of times it's better to use a for loop:</p>
<pre><code>for i in range(no_of_runs):
# do stuff
</code></pre>
<p>The idea is, that <code>range(no_of_runs)</code> generates the list <code>[0, 1, 2, ..., 10]... | 0 | 2010-01-31T11:58:19Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,565 | <p>You need to rebind <code>cumulative_nodes_found_list</code> at the beginning of the loop, instead of just clearing it.</p>
| 6 | 2010-01-31T12:00:03Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,571 | <p>You are adding a reference to <code>cumulative_nodes_found_list</code> to the <code>cumulative_nodes_found_total_list</code>, but it's the same reference each time. Move this line into the loop body:</p>
<pre><code>cumulative_nodes_found_list = []
</code></pre>
| 1 | 2010-01-31T12:02:24Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,573 | <p>Lists are mutable objects. You're mutating <code>cumulative_nodes_found_list</code> inside your code, so the object added to your total list in the previous run is also mutated, because they are the same object.</p>
<p>Either make a copy to insert in the total:</p>
<pre><code>for count in xrange(no_of_runs):
# ... | 1 | 2010-01-31T12:02:37Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,579 | <p>I believe the problem is in the rest of your program code.
The items in <code>cummulative_nodes_found_list</code> is being replaced in-place each time through the loop.</p>
<p>I assume you're doing something like this:</p>
<pre><code>while count < no_of_runs:
cummulative_nodes_found_list.clear()
#fill u... | 1 | 2010-01-31T12:03:41Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,582 | <p>This is psychic debugging at its best, since you're effectively asking "what is wrong with my code, which I'm not going to show to you".</p>
<p>All I can do is assume.</p>
<p>I'm assuming you're re-using the array objects in memory.</p>
<p>In other words, you do something like this:</p>
<pre><code>list1.insert(0... | 2 | 2010-01-31T12:04:14Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 2,171,590 | <p>My guess is that you are not assigning the <code>cumulative_nodes_found_list</code> to be a new list each time, but updating its contents instead. So each time around the loop you are adding the same list reference to the total list. Since the reference within the totals list is the same object, when you update this... | 1 | 2010-01-31T12:06:45Z | [
"python"
] |
Python: problem with list append | 2,171,551 | <p>Here is my code - </p>
<pre><code>cumulative_nodes_found_list = []
cumulative_nodes_found_total_list = []
no_of_runs = 10
count = 0
while count < no_of_runs:
#My program code
print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list)
cumulative_nodes_found_total_list.insert(count,cumulativ... | 2 | 2010-01-31T11:55:27Z | 22,220,746 | <blockquote>
<p>"Assignment statements in Python do not copy objects, they create
bindings between a target and an object."</p>
</blockquote>
<p>Use deepcopy (or copy)</p>
| -1 | 2014-03-06T09:52:23Z | [
"python"
] |
How to solve an LCP (linear complementarity problem) in python? | 2,171,704 | <p>Is there a good library to numericly solve an <a href="http://en.wikipedia.org/wiki/Linear_complementarity_problem" rel="nofollow">LCP</a> in python ?</p>
<p><strong>Edit:</strong> I need a working python code example because most libraries seem to only solve quadratic problems and i have problems converting an LCP... | 4 | 2010-01-31T12:50:20Z | 2,268,359 | <p>Take a look at the scikit <a href="http://openopt.org/Welcome" rel="nofollow">OpenOpt</a>. It has an example of doing <a href="http://projects.scipy.org/scikits/browser/trunk/openopt/scikits/openopt/examples/qp_1.py" rel="nofollow">quadratic programming</a> and I believe that it goes beyond SciPy's optimization rout... | 2 | 2010-02-15T19:21:07Z | [
"python"
] |
How to solve an LCP (linear complementarity problem) in python? | 2,171,704 | <p>Is there a good library to numericly solve an <a href="http://en.wikipedia.org/wiki/Linear_complementarity_problem" rel="nofollow">LCP</a> in python ?</p>
<p><strong>Edit:</strong> I need a working python code example because most libraries seem to only solve quadratic problems and i have problems converting an LCP... | 4 | 2010-01-31T12:50:20Z | 2,271,832 | <p>For quadratic programming with Python, I use the <a href="http://abel.ee.ucla.edu/cvxopt/userguide/coneprog.html#quadratic-programming" rel="nofollow"><code>qp</code></a>-solver from <a href="http://abel.ee.ucla.edu/cvxopt/" rel="nofollow"><code>cvxopt</code></a>. Using this, it is straightforward to translate the L... | 3 | 2010-02-16T09:44:53Z | [
"python"
] |
How to solve an LCP (linear complementarity problem) in python? | 2,171,704 | <p>Is there a good library to numericly solve an <a href="http://en.wikipedia.org/wiki/Linear_complementarity_problem" rel="nofollow">LCP</a> in python ?</p>
<p><strong>Edit:</strong> I need a working python code example because most libraries seem to only solve quadratic problems and i have problems converting an LCP... | 4 | 2010-01-31T12:50:20Z | 10,337,009 | <p>OpenOpt has a free LCP solver written in Python + NumPy see <a href="http://openopt.org/LCP" rel="nofollow">http://openopt.org/LCP</a></p>
| 1 | 2012-04-26T15:55:18Z | [
"python"
] |
problem with breadth first tree generation | 2,171,733 | <p>i have a problem with breadth first algorithm, my script generates curves in maya, position them, rotate and scale them so they give me the tree shape,
i have these variables</p>
<p>cs=current State,</p>
<p>p=parent,</p>
<p>nodes=non visited node List</p>
<p>lvl=current depth</p>
<p>maxlvl= max depth</p>
<p>th... | 1 | 2010-01-31T13:00:31Z | 2,172,224 | <p>You need to associate the depth with each node. Either put it as a member in the node class, or have your queue entries store both depth and node like this:</p>
<pre><code>nodes.append((1, firstNode))
while nodes and lvl<5:
lvl, p = nodes.pop(0)
For each child:
#...create child
nodes.app... | 4 | 2010-01-31T15:34:38Z | [
"python",
"tree",
"breadth-first-search"
] |
Integrating pygame with a C module | 2,171,746 | <p>In my Python2_6/include directory is a folder with pygame headers. I assumed that my python C module can access pygame stuff directly in C. Is this the case? How do I integrate a C module that wants to use pygame, with a python script using pygame? Right now my brain sees:</p>
<p>pygame <-- MyCModule <-- MySc... | 1 | 2010-01-31T13:07:07Z | 2,176,010 | <blockquote>
<p>I assumed that my python C module can
access pygame stuff directly in C. Is
this the case?</p>
</blockquote>
<p>No, that stuff is most likely just there because it was necessary to compile the pygame Python extension.</p>
<p>I don't understand what you mean when you say you see 2 pygame instance... | 0 | 2010-02-01T10:37:30Z | [
"python",
"module",
"pygame"
] |
Integrating pygame with a C module | 2,171,746 | <p>In my Python2_6/include directory is a folder with pygame headers. I assumed that my python C module can access pygame stuff directly in C. Is this the case? How do I integrate a C module that wants to use pygame, with a python script using pygame? Right now my brain sees:</p>
<p>pygame <-- MyCModule <-- MySc... | 1 | 2010-01-31T13:07:07Z | 2,307,803 | <p>See <a href="http://stackoverflow.com/questions/1583077/making-a-c-extension-to-python-that-requires-another-extension">this question</a>. The code given in the accepted answer checks whether Pygame was already loaded, so you won't end up with two sets of Pygame stuff.</p>
<p>Also, those headers aren't for custom C... | 0 | 2010-02-21T22:57:26Z | [
"python",
"module",
"pygame"
] |
How to implement a client admin in Django? | 2,171,820 | <p>I'm building a simple app, a sort of project/tasks manager where I can have several projects and several tasks that are assigned to one project.</p>
<p>I enabled Django admin for all this sort of tasks and it's working like a charm. Also, I have some users that have projects assigned to them. So what I want now is ... | 3 | 2010-01-31T13:32:52Z | 2,171,917 | <p>+1 for custom app, hacking admin can take more time than just putting together your own admin from generic views.</p>
| 3 | 2010-01-31T14:02:43Z | [
"python",
"django",
"django-admin"
] |
How to implement a client admin in Django? | 2,171,820 | <p>I'm building a simple app, a sort of project/tasks manager where I can have several projects and several tasks that are assigned to one project.</p>
<p>I enabled Django admin for all this sort of tasks and it's working like a charm. Also, I have some users that have projects assigned to them. So what I want now is ... | 3 | 2010-01-31T13:32:52Z | 2,171,929 | <p>I think that the best way to do this, either way, would be to somehow implement row-level permissions.<br>
At the moment, the best solution for this is probably using the <a href="http://code.google.com/p/django-granular-permissions/" rel="nofollow">django-granular-permissions</a>.</p>
<p>Like Dmitry I'm also for t... | 2 | 2010-01-31T14:06:47Z | [
"python",
"django",
"django-admin"
] |
draw hebrew text to an image using Image module (python) | 2,171,910 | <p>Hi
I am trying to use Image module in order to make bitmaps with hebrew lettering in it.
when printing from the shell (idle) I managed to print hebrew, but when trying to draw text to a bitmap it draws some ascii lettering.</p>
<p>this is the code:</p>
<pre><code>import Image
import ImageDraw
a = "×ר×××" #... | 3 | 2010-01-31T14:01:38Z | 2,172,065 | <p>Try <code>a = u"×ר×××"</code>.</p>
<p>Failing that, try <a href="http://cairographics.org/documentation/pycairo/" rel="nofollow">PyCairo</a>. It has advanced typography handling that may work better.</p>
| 1 | 2010-01-31T14:42:19Z | [
"python",
"image",
"draw"
] |
draw hebrew text to an image using Image module (python) | 2,171,910 | <p>Hi
I am trying to use Image module in order to make bitmaps with hebrew lettering in it.
when printing from the shell (idle) I managed to print hebrew, but when trying to draw text to a bitmap it draws some ascii lettering.</p>
<p>this is the code:</p>
<pre><code>import Image
import ImageDraw
a = "×ר×××" #... | 3 | 2010-01-31T14:01:38Z | 2,172,091 | <p><a href="http://blog.wensheng.com/2006/03/how-to-create-images-from-chinese-text.html" rel="nofollow">This site</a> mentions that to draw Chinese text, they had to specify that the string was unicode, so you should do the same, e.g.</p>
<pre><code>a = u"×ר×××" #like this
a = unicode("×ר×××", "UTF-8") #or ... | 1 | 2010-01-31T14:54:20Z | [
"python",
"image",
"draw"
] |
How does len work? | 2,171,960 | <p>How does len work on Python?</p>
<p>Look at this example:</p>
<pre><code>class INT(int):
pass
class STR(str):
def __len__(self):
return INT(42)
q = STR('how').__len__()
print q, type(q)
q = len(STR('how'))
print q, type(q)
</code></pre>
<p>The output is:</p>
<pre><code>42 <class '__main__.I... | 3 | 2010-01-31T14:16:11Z | 2,171,983 | <p>I don't think you can, unless you write your own len.
The builtin len always return an int.</p>
| 3 | 2010-01-31T14:20:12Z | [
"python"
] |
How does len work? | 2,171,960 | <p>How does len work on Python?</p>
<p>Look at this example:</p>
<pre><code>class INT(int):
pass
class STR(str):
def __len__(self):
return INT(42)
q = STR('how').__len__()
print q, type(q)
q = len(STR('how'))
print q, type(q)
</code></pre>
<p>The output is:</p>
<pre><code>42 <class '__main__.I... | 3 | 2010-01-31T14:16:11Z | 2,171,986 | <p>You won't be able to. At least if you want it to work with the rest of python. See the <a href="http://docs.python.org/reference/datamodel.html#object.__len__" rel="nofollow">definition of <strong>len</strong></a></p>
<blockquote>
<p>Called to implement the built-in
function len(). Should return the
length of... | 2 | 2010-01-31T14:20:59Z | [
"python"
] |
How does len work? | 2,171,960 | <p>How does len work on Python?</p>
<p>Look at this example:</p>
<pre><code>class INT(int):
pass
class STR(str):
def __len__(self):
return INT(42)
q = STR('how').__len__()
print q, type(q)
q = len(STR('how'))
print q, type(q)
</code></pre>
<p>The output is:</p>
<pre><code>42 <class '__main__.I... | 3 | 2010-01-31T14:16:11Z | 2,172,149 | <p>Do not do this. You need to learn when the best answer really is not to do what you are trying to do at all. This is one of those times.</p>
| 3 | 2010-01-31T15:11:33Z | [
"python"
] |
How does len work? | 2,171,960 | <p>How does len work on Python?</p>
<p>Look at this example:</p>
<pre><code>class INT(int):
pass
class STR(str):
def __len__(self):
return INT(42)
q = STR('how').__len__()
print q, type(q)
q = len(STR('how'))
print q, type(q)
</code></pre>
<p>The output is:</p>
<pre><code>42 <class '__main__.I... | 3 | 2010-01-31T14:16:11Z | 2,172,284 | <p>As others say, don't do this. Consider how usage of this class would look:</p>
<pre><code>length = len(s) # the reader assumes `q` is an int.
length.in_yards() # the reader is going WTF?!
</code></pre>
<p>Instead of violating the reader's expectations, why don't you just add a different method:</p>
<pre><c... | 2 | 2010-01-31T15:53:05Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.