title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Dynamically attaching a method to an existing Python object generated with swig? | 1,382,871 | <p>I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as <strong><code>__str__</code></strong>) to the objects created from that class without modifying the class declaration?</p>
<p>EDIT:
Thank you for all your answers. I tried them all but they... | 7 | 2009-09-05T09:30:59Z | 1,382,965 | <p>Create a subclass. Example:</p>
<pre><code>>>> import datetime
>>> t = datetime.datetime.now()
>>> datetime.datetime.__str__ = lambda self: 'spam'
...
TypeError: cant set attributes of built-in/extension type 'datetime.datetime'
>>> t.__str__ = lambda self: 'spam'
...
AttributeEr... | 3 | 2009-09-05T10:22:01Z | [
"python",
"class",
"dynamic",
"methods"
] |
Dynamically attaching a method to an existing Python object generated with swig? | 1,382,871 | <p>I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as <strong><code>__str__</code></strong>) to the objects created from that class without modifying the class declaration?</p>
<p>EDIT:
Thank you for all your answers. I tried them all but they... | 7 | 2009-09-05T09:30:59Z | 1,382,968 | <p>This is my answer from <a href="http://stackoverflow.com/questions/357997/does-python-have-something-like-anonymous-inner-classes-of-java/358055#358055">another question</a>:</p>
<pre><code>import types
class someclass(object):
val = "Value"
def some_method(self):
print self.val
def some_method_upp... | 2 | 2009-09-05T10:23:31Z | [
"python",
"class",
"dynamic",
"methods"
] |
Dynamically attaching a method to an existing Python object generated with swig? | 1,382,871 | <p>I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as <strong><code>__str__</code></strong>) to the objects created from that class without modifying the class declaration?</p>
<p>EDIT:
Thank you for all your answers. I tried them all but they... | 7 | 2009-09-05T09:30:59Z | 1,383,071 | <p>Note that using Alex's subclass idea, you can help yourself a little bit more using "<code>from</code> ... <code>import</code> ... <code>as</code>":</p>
<pre><code>from datetime import datetime as datetime_original
class datetime(datetime_original):
def __str__(self):
return 'spam'
</code></pre>
<p>so no... | 1 | 2009-09-05T11:13:10Z | [
"python",
"class",
"dynamic",
"methods"
] |
Dynamically attaching a method to an existing Python object generated with swig? | 1,382,871 | <p>I am working with a Python class, and I don't have write access to its declaration.
How can I attach a custom method (such as <strong><code>__str__</code></strong>) to the objects created from that class without modifying the class declaration?</p>
<p>EDIT:
Thank you for all your answers. I tried them all but they... | 7 | 2009-09-05T09:30:59Z | 1,383,646 | <p>If you create a wrapper class, this will work with any other class, either built-in or not. This is called "containment and delegation", and it is a common alternative to inheritance:</p>
<pre><code>class SuperDuperWrapper(object):
def __init__(self, origobj):
self.myobj = origobj
def __str__(self)... | 19 | 2009-09-05T15:51:30Z | [
"python",
"class",
"dynamic",
"methods"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 1,383,009 | <p><code>--no-site-packages</code> should, as the name suggests, remove the standard site-packages directory from sys.path. Anything else that lives in the standard Python path will remain there.</p>
| 11 | 2009-09-05T10:47:29Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 1,402,050 | <p>Eventually I found that, for whatever reason, pip -E was not working. However, if I actually activate the virtualenv, and use easy_install provided by virtualenv to install pip, then use pip directly from within, it seems to work as expected and only show the packages in the virtualenv</p>
| 21 | 2009-09-09T20:57:04Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 15,178,877 | <p>I know this is a very old question but for those arriving here looking for a solution:</p>
<p>Don't forget to <strong>activate the virtualenv</strong> (<code>source bin/activate</code>) before running <code>pip freeze</code>. Otherwise you'll get a list of all global packages.</p>
| 10 | 2013-03-02T20:06:48Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 15,887,589 | <p>I had a problem like this, until I realized that (long before I had discovered virtualenv), I had gone adding directories to the PYTHONPATH in my .bashrc file. As it had been over a year beforehand, I didn't think of that straight away. </p>
| 60 | 2013-04-08T19:46:09Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 19,555,526 | <p>A similar problem can occur on Windows if you call scripts directly as <code>script.py</code> which then uses the Windows default opener and opens Python outside the virtual environment. Calling it with <code>python script.py</code> will use Python with the virtual environment.</p>
| 3 | 2013-10-24T01:55:56Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 30,939,505 | <p>This also seems to happen when you move the virtualenv directory to another directory (on linux), or rename a parent directory.</p>
| 2 | 2015-06-19T13:33:11Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 33,244,110 | <p>Here's the list of all the pip install <a href="http://pip.readthedocs.org/en/stable/reference/pip_install/#options" rel="nofollow">options</a> - I didn't find any '<code>-E</code>' option, may be older version had it. Below I am sharing a plain english usage and working of <code>virtualenv</code> for the upcoming S... | 0 | 2015-10-20T18:26:34Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 33,366,748 | <p>You have to make sure you are running the <code>pip</code> binary in the virtual environment you created, not the global one.</p>
<pre><code>env/bin/pip freeze
</code></pre>
<hr>
<p>See a test:</p>
<p>We create the virtualenv with the <code>--no-site-packages</code> option:</p>
<pre><code>$ virtualenv --no-site... | 7 | 2015-10-27T11:25:36Z | [
"python",
"virtualenv",
"pip"
] |
virtualenv --no-site-packages and pip still finding global packages? | 1,382,925 | <p>I was under the impression that virtualenv --no-site-packages would create a completely separate and isolated Python environment, but it doesn't seem to.</p>
<p>For example, I have python-django installed globally, but wish to create a virtualenv with a different Django version.</p>
<pre><code>$ virtualenv --no-si... | 78 | 2009-09-05T09:59:17Z | 33,851,358 | <p>I was having this same problem. The issue for me (on Ubuntu) was that my path name contained <code>$</code>. When I created a virtualenv outside of the $ dir, it worked fine.</p>
<p>Weird.</p>
| 0 | 2015-11-22T03:42:06Z | [
"python",
"virtualenv",
"pip"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 1,383,014 | <p>Without measuring, I would expect that the .translate method of Unicode strings is the fastest solution. You should definitely make your own measurements, though.</p>
| 0 | 2009-09-05T10:49:24Z | [
"python",
"unicode"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 1,383,019 | <p><a href="http://docs.python.org/library/string.html#string.maketrans" rel="nofollow">Maketrans</a> (and translate) then convert to ascii:</p>
<pre><code>intab = u'áéÃ' # extend as needed
outtab = u'aei' # as well as this one
table = maketrans(intab, outtab)
text = translate(u"Wikipédia, le projet dâencyclop... | 1 | 2009-09-05T10:51:27Z | [
"python",
"unicode"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 1,383,056 | <p>The "correct" way to do this is to register your own error handler for unicode encoding/decoding, and in that error handler provide the replacements from è to e and ö to o, etc.</p>
<p>Like so:</p>
<pre><code># -*- coding: UTF-8 -*-
import codecs
map = {u'é': u'e',
u'â': u"'",
# ETC
}
d... | 8 | 2009-09-05T11:06:43Z | [
"python",
"unicode"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 1,383,721 | <p>So here are three approaches, more or less as given or suggested in other answers:</p>
<pre><code># -*- coding: utf-8 -*-
import codecs
import unicodedata
x = u"Wikipédia, le projet dâencyclopédie"
xtd = {ord(u'â'): u"'", ord(u'é'): u'e', }
def asciify(error):
return xtd[ord(error.object[error.start])... | 15 | 2009-09-05T16:34:29Z | [
"python",
"unicode"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 11,955,764 | <p>The awesome <a href="http://pypi.python.org/pypi/Unidecode/">unidecode</a> module does this for you:</p>
<pre><code>>>> import unidecode
>>> n = unicode('Wikipédia, le projet dâencyclopédie','utf-8')
>>> unidecode.unidecode(n)
"Wikipedia, le projet d'encyclopedie"
</code></pre>
| 6 | 2012-08-14T15:29:59Z | [
"python",
"unicode"
] |
latin-1 to ascii | 1,382,998 | <p>I have a unicode string with accented latin chars e.g.</p>
<pre><code>n=unicode('Wikipédia, le projet dâencyclopédie','utf-8')
</code></pre>
<p>I want to convert it to plain ascii i.e. 'Wikipedia, le projet dencyclopedie', so all acute/accent,cedilla etc should get removed</p>
<p>What is the fastest way to do... | 13 | 2009-09-05T10:44:40Z | 30,650,136 | <p>Package <a href="https://pypi.python.org/pypi/Unihandecode" rel="nofollow"><code>unihandecode</code></a> is</p>
<blockquote>
<p>US-ASCII transliterations of Unicode text.<br/>
an improved version of Python unidecode, that is Python port of Text::Unidecode Perl module by Sean M. Burke .</p>
</blockquote>
<pre><... | 0 | 2015-06-04T17:13:43Z | [
"python",
"unicode"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 1,383,149 | <p>Although you installed it, Python can apparently not find the module psycopg2. This is usually due to the module not being in Python's path. See if you can find a folder named psycopg2 in <code>/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages</code>. If it's not there, did MacPorts tell ... | 3 | 2009-09-05T11:49:09Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 1,383,153 | <p>There seems to be a problem with your <code>psycopg2</code> installation â Python does not find it. This is a Python installation problem, not a Django issue.</p>
<p>You can try to load it manually using the Python interpreter and see if it works:</p>
<pre><code>$ python
>>> import psycopg2
</code></pre... | 24 | 2009-09-05T11:51:18Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 5,148,709 | <p>For the record I got the same error for a different reason:</p>
<p>I had put</p>
<pre><code>'ENGINE': 'django.db.backends.postgresql'
</code></pre>
<p>instead of</p>
<pre><code>'ENGINE': 'django.db.backends.postgresql_psycopg2'
</code></pre>
<p>in <code>settings.py</code></p>
| 10 | 2011-02-28T23:14:05Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 5,170,613 | <p>Tim's answer worked for me too.
By default, settings.py shows options like 'postgresql_psycopg2', 'mysql', etc, without a package name. Prefixing with 'django.db.backends.' worked for me (for postgresql_psycopg2, at least).</p>
| 0 | 2011-03-02T16:45:34Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 6,420,799 | <p>Yes Tim's answer works for me too.It works without prefix 'django.db.backends.' also. But remember to create database or schema you mentioned in settings.py:</p>
<pre><code>DATABASE_NAME = 'your_db_name'
</code></pre>
<p>manually using your database client so when you run 'python manage.py syncdb' you don't get t... | 1 | 2011-06-21T05:37:51Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 6,648,494 | <p>I got the same error, but it was because I was using <code>python26 ./manage.py runserver</code> when my virtualenv only had <code>python</code> and <code>python2.6</code> executables (thus the system <code>python26</code> was being used, which didn't have <code>psycopg2</code> installed</p>
| 1 | 2011-07-11T09:59:46Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 9,498,200 | <p>Here's the solution: <a href="http://initd.org/psycopg/install/" rel="nofollow">http://initd.org/psycopg/install/</a>
You've to install python-dev and libpq-dev libraries before executing "easy_install psycopg2"</p>
| 2 | 2012-02-29T11:24:07Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 10,399,009 | <p>If you have <code>pip</code> installed, simply install the missing extension by running:</p>
<pre><code>$ pip install psycopg2
</code></pre>
| 14 | 2012-05-01T14:18:47Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 11,973,485 | <p>I realized I didn't have psycopg2 installed</p>
<pre><code>aptitude install python-psycopg2
</code></pre>
<p>Worked like a charm</p>
| 3 | 2012-08-15T16:46:49Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 27,580,910 | <p>For me, psycopg2 was indeed installed, but not into the virtualenv in which Django was running. These two steps fixed it:</p>
<pre><code>sudo apt-get build-dep python-psycopg2
sudo /opt/myenv/bin/pip install psycopg2
</code></pre>
| 0 | 2014-12-20T13:59:41Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 31,955,669 | <p>I had this issue recently after updating homebrew on OSX.
psycopg2 was already listed in my virtualenv
I just reinstalled psycopg2 and it worked again</p>
<p><code>pip install --forece-reinstall psycopg2</code></p>
| 0 | 2015-08-12T03:47:32Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 32,443,055 | <p>I'm on Windows and had installed psycopg2, but the 64 bit version. So my fix was to download the 32 bit one from <a href="http://www.stickpeople.com/projects/python/win-psycopg/" rel="nofollow">here</a> then in PowerShell with my virtual environment activated, my fix was: </p>
<pre><code>pip uninstall psycopg2
easy... | 0 | 2015-09-07T16:43:39Z | [
"python",
"django",
"django-syncdb"
] |
Django/Python Beginner: Error when executing python manage.py syncdb - psycopg2 not found | 1,383,126 | <p>I have Pythong2.6, psycopg2 and pgAdmin3 installed using Macports. My settings.py is:</p>
<pre><code>DATABASE_ENGINE = 'postgresql_psycopg2' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'mysite' # Or path to database file if using sqlite3.
DATABASE_USE... | 21 | 2009-09-05T11:40:31Z | 32,607,270 | <p>THIS HAS HELPED ME:</p>
<p>I just added PostgreSQL bin path to ENV and it was able to fine the needed dll:
C:\Program Files (x86)\PostgreSQL\9.4\bin</p>
<p><a href="https://groups.google.com/forum/#!topic/robotframework-users/qLq9KvHe1wE" rel="nofollow">https://groups.google.com/forum/#!topic/robotframework-users/... | 0 | 2015-09-16T11:26:06Z | [
"python",
"django",
"django-syncdb"
] |
Can I use __init__.py to define global variables? | 1,383,239 | <p>I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the <code>__init__.py</code> file of the root package. But I don't know how to do this. Suppose I have a few subpackages and each with several modules. How can I access that var... | 46 | 2009-09-05T12:33:03Z | 1,383,248 | <p>You cannot do that. You will have to explicitely import your constants into each individual module's namespace. The best way to achieve this is to define your constants in a "config" module and import it everywhere you require it:</p>
<pre><code># mypackage/config.py
MY_CONST = 17
# mypackage/main.py
from mypackag... | 25 | 2009-09-05T12:38:56Z | [
"python",
"global-variables",
"module",
"packages",
"init"
] |
Can I use __init__.py to define global variables? | 1,383,239 | <p>I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the <code>__init__.py</code> file of the root package. But I don't know how to do this. Suppose I have a few subpackages and each with several modules. How can I access that var... | 46 | 2009-09-05T12:33:03Z | 1,383,281 | <p>You should be able to put them in __init__.py. This is done all the time.</p>
<p>mypackage/__init__.py:</p>
<pre><code>MY_CONSTANT = 42
</code></pre>
<p>mypackage/mymodule.py:</p>
<pre><code>from mypackage import MY_CONSTANT
print "my constant is", MY_CONSTANT
</code></pre>
<p>Then, import mymodule:</p>
<pre>... | 75 | 2009-09-05T12:57:05Z | [
"python",
"global-variables",
"module",
"packages",
"init"
] |
Can I use __init__.py to define global variables? | 1,383,239 | <p>I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the <code>__init__.py</code> file of the root package. But I don't know how to do this. Suppose I have a few subpackages and each with several modules. How can I access that var... | 46 | 2009-09-05T12:33:03Z | 1,383,549 | <p>You can define global variables from anywhere, but it is a really bad idea. import the <code>__builtin__</code> module and modify or add attributes to this modules, and suddenly you have new builtin constants or functions. In fact, when my application installs gettext, I get the _() function in all my modules, witho... | 2 | 2009-09-05T15:09:14Z | [
"python",
"global-variables",
"module",
"packages",
"init"
] |
Can I use __init__.py to define global variables? | 1,383,239 | <p>I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the <code>__init__.py</code> file of the root package. But I don't know how to do this. Suppose I have a few subpackages and each with several modules. How can I access that var... | 46 | 2009-09-05T12:33:03Z | 38,275,781 | <p>Just wanted to add that constants can be employed using a config.ini file and parsed in the script using the configparser library. This way you could have constants for multiple circumstances. For instance if you had parameter constants for two separate url requests just label them like so:</p>
<pre><code>mymodule/... | 0 | 2016-07-08T21:41:23Z | [
"python",
"global-variables",
"module",
"packages",
"init"
] |
Logging, StreamHandler and standard streams | 1,383,254 | <p>I can't figure out how to log info-level messages to stdout, but everything else to stderr. I already read this <a href="http://docs.python.org/library/logging.html">http://docs.python.org/library/logging.html</a>. Any suggestion?</p>
| 37 | 2009-09-05T12:45:17Z | 1,383,365 | <p>The following script, <code>log1.py</code>:</p>
<pre><code>import logging, sys
class SingleLevelFilter(logging.Filter):
def __init__(self, passlevel, reject):
self.passlevel = passlevel
self.reject = reject
def filter(self, record):
if self.reject:
return (record.leveln... | 60 | 2009-09-05T13:46:23Z | [
"python",
"logging"
] |
Logging, StreamHandler and standard streams | 1,383,254 | <p>I can't figure out how to log info-level messages to stdout, but everything else to stderr. I already read this <a href="http://docs.python.org/library/logging.html">http://docs.python.org/library/logging.html</a>. Any suggestion?</p>
| 37 | 2009-09-05T12:45:17Z | 24,956,305 | <p>Generally, I think it makes sense to <strong>redirect messages lower than <code>WARNING</code> to <em>stdout</em>, instead of only <code>INFO</code> messages</strong>.</p>
<p>Based on <em>Vinay Sajip</em>'s excellent answer, I came up with this:</p>
<pre><code>class MaxLevelFilter(Filter):
'''Filters (lets thr... | 9 | 2014-07-25T12:56:45Z | [
"python",
"logging"
] |
Logging, StreamHandler and standard streams | 1,383,254 | <p>I can't figure out how to log info-level messages to stdout, but everything else to stderr. I already read this <a href="http://docs.python.org/library/logging.html">http://docs.python.org/library/logging.html</a>. Any suggestion?</p>
| 37 | 2009-09-05T12:45:17Z | 28,743,317 | <p>Since my edit was rejected, here's my answer. @goncalopp's answer is good but doesn't stand alone or work out of the box. Here's my improved version:</p>
<pre><code>import sys, logging
class LogFilter(logging.Filter):
"""Filters (lets through) all messages with level < LEVEL"""
# http://stackoverflow.c... | 3 | 2015-02-26T13:07:25Z | [
"python",
"logging"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 1,383,601 | <p>I would just prepend the names with an underscore <code>_</code>, to show that the reader shouldn't bother about them.
It's conventionally the same thing as private members in other languages.</p>
| 0 | 2009-09-05T15:31:54Z | [
"python",
"code-organization"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 1,383,607 | <p>If the method is relevant to the Path - no matter how obscure - I think it should reside within the class itself.</p>
<p>If you have multiple places where you have path-related functionality, it leads to problems. For example, if you want to check if some functionality already exists, how will a new programmer know... | 4 | 2009-09-05T15:33:41Z | [
"python",
"code-organization"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 1,383,613 | <p>Put them in the Path class, and document that they are "obscure" either with comments or docstrings. Separate them at the end if you like.</p>
| 0 | 2009-09-05T15:36:20Z | [
"python",
"code-organization"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 1,383,623 | <p>If you're keen to put those methods in a different source file at any cost, AND keen to have them at methods at any cost, you can achieve both goals by using the different source file to define a mixin class and having your Path class import that method and multiply-inherit from that mixin. So, technically, it's qui... | 2 | 2009-09-05T15:39:15Z | [
"python",
"code-organization"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 1,383,639 | <p>Oh wait, I thought of something -- I can just define them in the <code>Path.py</code> module, where every obscure method will be a one-liner that will call the function from the separate module that currently exists. With this compromise, the obscure methods will comprise of maybe 10 lines in the end of the file ins... | 0 | 2009-09-05T15:45:08Z | [
"python",
"code-organization"
] |
Code organization in Python: Where is a good place to put obscure methods? | 1,383,590 | <p>I have a class called <code>Path</code> for which there are defined about 10 methods, in a dedicated module <code>Path.py</code>. Recently I had a need to write 5 more methods for <code>Path</code>, however these new methods are quite obscure and technical and 90% of the time they are irrelevant.</p>
<p>Where would... | 2 | 2009-09-05T15:25:58Z | 8,028,755 | <p>I suggest making them accessible from a property of the Path class called something like "Utilties". For example: <code>Path.Utilities.RazzleDazzle</code>. This will help with auto-completion tools and general maintenance.</p>
| 0 | 2011-11-06T17:09:05Z | [
"python",
"code-organization"
] |
You don't have permission to access /index.py on this server | 1,383,632 | <p>I am setting up a simple test page in Python. I only have two files: .htaccess and index.py. I get a 403 Forbidden error when trying to view the page - how can I fix this?</p>
<p>.htaccess:</p>
<pre><code>RewriteEngine On
AddHandler application/x-httpd-cgi .py
DirectoryIndex index.py
</code></pre>
<p>index.py:</p... | 1 | 2009-09-05T15:41:05Z | 1,383,637 | <p>What permissions have you set on <code>index.py</code> (e.g. what does <code>ls -l index.py</code> say, if in Linux or other Unix variants)?</p>
| 2 | 2009-09-05T15:44:14Z | [
"python",
".htaccess"
] |
remove inner border on gtk.Button | 1,383,663 | <p>I would like to remove border on a gtk.Button and also set its size fixed. How can I accomplish that?
My button looks like that:</p>
<pre>
b = gtk.Button()
b.set_relief(gtk.RELIEF_NONE)
</pre>
<p>Thanks!
p.d: I'm using pygtk</p>
| 0 | 2009-09-05T16:01:42Z | 1,383,706 | <p>You can use <a href="http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#method-gtkwidget--set-size-request" rel="nofollow">gtk.Widget.set_size_request</a> to set a fixed size for the widget. Note that this is generally a bad idea, since the user may want a larger font size than you had planned for, etc.</p>
<p>As... | 2 | 2009-09-05T16:23:23Z | [
"python",
"gtk",
"pygtk"
] |
remove inner border on gtk.Button | 1,383,663 | <p>I would like to remove border on a gtk.Button and also set its size fixed. How can I accomplish that?
My button looks like that:</p>
<pre>
b = gtk.Button()
b.set_relief(gtk.RELIEF_NONE)
</pre>
<p>Thanks!
p.d: I'm using pygtk</p>
| 0 | 2009-09-05T16:01:42Z | 1,507,847 | <p>I don't think the EventBox can send button events like "activated" and "clicked".</p>
| -1 | 2009-10-02T05:22:31Z | [
"python",
"gtk",
"pygtk"
] |
Python data structure for a collection of objects with random access based on an attribute | 1,383,693 | <p>I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of what I have now:</p>
<pre><code>class Item():
def __init__(self, uniq_key, title=None):
... | 3 | 2009-09-05T16:15:07Z | 1,383,738 | <p>Well, dict really is what you want. What may be cumbersome is not the dict itself, but the way you are building it. Here is a slight enhancement to your example, showing how to use a list expression and the dict constructor to easily create your lookup dict. This also shows how to create a multimap kind of dict, ... | 0 | 2009-09-05T16:41:32Z | [
"python"
] |
Python data structure for a collection of objects with random access based on an attribute | 1,383,693 | <p>I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of what I have now:</p>
<pre><code>class Item():
def __init__(self, uniq_key, title=None):
... | 3 | 2009-09-05T16:15:07Z | 1,383,743 | <p>There is actually no duplication of information as you fear: the dict's key, and the object's <code>.key</code> attribute, are just two references to exactly the same object.</p>
<p>The only real problem is "what if the <code>.key</code> gets reassigned". Well then, clearly you must use a property that updates all ... | 4 | 2009-09-05T16:44:02Z | [
"python"
] |
Python data structure for a collection of objects with random access based on an attribute | 1,383,693 | <p>I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of what I have now:</p>
<pre><code>class Item():
def __init__(self, uniq_key, title=None):
... | 3 | 2009-09-05T16:15:07Z | 1,383,744 | <p>There are a number of great things you can do here. One example would be to let the class keep track of everything:</p>
<pre><code>class Item():
_member_dict = {}
@classmethod
def get_by_key(cls,key):
return cls._member_dict[key]
def __init__(self, uniq_key, title=None):
self.key = ... | 2 | 2009-09-05T16:44:19Z | [
"python"
] |
Python data structure for a collection of objects with random access based on an attribute | 1,383,693 | <p>I need a collection of objects which can be looked up by a certain (unique) attribute common to each of the objects. Right now I am using a dicitionary assigning the dictionary key to the attribute.
Here is an example of what I have now:</p>
<pre><code>class Item():
def __init__(self, uniq_key, title=None):
... | 3 | 2009-09-05T16:15:07Z | 1,383,798 | <p>Editing to correct the problem I had - which was due to my "collection = dict()" default parameter <code>(*bonk*).</code> Now, each call to the function will return a class with its own collection as intended - this for convenience in case more than one such collection should be needed. Also am putting the collect... | 0 | 2009-09-05T17:08:05Z | [
"python"
] |
OS X - multiple python versions, PATH and /usr/local | 1,383,863 | <p>If you install multiple versions of python (I currently have the default 2.5, installed 3.0.1 and now installed 2.6.2), it automatically puts stuff in <code>/usr/local</code>, and it also adjusts the path to include the <code>/Library/Frameworks/Python/Versions/theVersion/bin</code>, but whats the point of that when... | 5 | 2009-09-05T17:40:24Z | 1,383,891 | <p>There's no a priori guarantee that /usr/local/bin will stay on the PATH (especially it will not necessarily stay "in front of" /usr/bin!-), so it's perfectly reasonable for an installer to ensure the specifically needed /Library/.../bin directory does get on the PATH. Plus, it may be the case that the /Library/.../... | 5 | 2009-09-05T17:53:27Z | [
"python",
"osx",
"path",
"multiple-versions"
] |
OS X - multiple python versions, PATH and /usr/local | 1,383,863 | <p>If you install multiple versions of python (I currently have the default 2.5, installed 3.0.1 and now installed 2.6.2), it automatically puts stuff in <code>/usr/local</code>, and it also adjusts the path to include the <code>/Library/Frameworks/Python/Versions/theVersion/bin</code>, but whats the point of that when... | 5 | 2009-09-05T17:40:24Z | 1,384,223 | <p>I just noticed/encountered this issue on my Mac. I have Python 2.5.4, 2.6.2, and 3.1.1 on my machine, and was looking for a way to easily change between them at will. That is when I noticed all the symlinks for the executables, which I found in both '/usr/bin' and '/usr/local/bin'. I ripped all the non-version speci... | 0 | 2009-09-05T20:41:25Z | [
"python",
"osx",
"path",
"multiple-versions"
] |
(re)Using dictionaries in django views | 1,384,246 | <p>I have this dictionary in my apps model file:</p>
<pre><code>TYPE_DICT = (
("1", "Shopping list"),
("2", "Gift Wishlist"),
("3", "test list type"),
)
</code></pre>
<p>model, which uses this dict is this:</p>
<pre><code>class List(models.Model):
user = models.ForeignKey(User)
name = models.... | 1 | 2009-09-05T20:55:39Z | 1,384,258 | <p>Your <code>TYPE_DICT</code> in your models file isn't a dictionary: it's a tuple of tuples.</p>
<p>You can easily make a dictionary from it though if you want:</p>
<pre><code>TYPE_DICT_DICT = dict(TYPE_DICT)
</code></pre>
<p>then you can use <code>TYPE_DICT_DICT</code> as a real dictionary.</p>
| 6 | 2009-09-05T21:02:22Z | [
"python",
"django",
"list",
"dictionary",
"tuples"
] |
(re)Using dictionaries in django views | 1,384,246 | <p>I have this dictionary in my apps model file:</p>
<pre><code>TYPE_DICT = (
("1", "Shopping list"),
("2", "Gift Wishlist"),
("3", "test list type"),
)
</code></pre>
<p>model, which uses this dict is this:</p>
<pre><code>class List(models.Model):
user = models.ForeignKey(User)
name = models.... | 1 | 2009-09-05T20:55:39Z | 1,384,262 | <p>You're creating a tuple, not a dict.</p>
<pre><code>TYPE_DICT = {
1: "Shopping list",
2: "Gift Wishlist",
3: "test list type",
}
</code></pre>
<p>is a dict (but that's not what choices wants).</p>
| -1 | 2009-09-05T21:03:35Z | [
"python",
"django",
"list",
"dictionary",
"tuples"
] |
(re)Using dictionaries in django views | 1,384,246 | <p>I have this dictionary in my apps model file:</p>
<pre><code>TYPE_DICT = (
("1", "Shopping list"),
("2", "Gift Wishlist"),
("3", "test list type"),
)
</code></pre>
<p>model, which uses this dict is this:</p>
<pre><code>class List(models.Model):
user = models.ForeignKey(User)
name = models.... | 1 | 2009-09-05T20:55:39Z | 1,384,777 | <p>firstly, modify your tuple to dictionary format..
then, when accessing in django template you need to assume the key of that dictionary as an attribute...let say this is the dictionary</p>
<pre><code>TYPE_DICT = {
1: 'Shopping list',
2: 'Gift Wishlist',
3: 'test list type',
}
</code></pre>
<p>when acce... | 0 | 2009-09-06T03:04:33Z | [
"python",
"django",
"list",
"dictionary",
"tuples"
] |
(re)Using dictionaries in django views | 1,384,246 | <p>I have this dictionary in my apps model file:</p>
<pre><code>TYPE_DICT = (
("1", "Shopping list"),
("2", "Gift Wishlist"),
("3", "test list type"),
)
</code></pre>
<p>model, which uses this dict is this:</p>
<pre><code>class List(models.Model):
user = models.ForeignKey(User)
name = models.... | 1 | 2009-09-05T20:55:39Z | 8,796,869 | <p>Hello I was trying to do this since yesterday and today I realized your can <a href="https://docs.djangoproject.com/en/dev/howto/custom-template-tags/" rel="nofollow">make your own filter</a> so that you can pass the dictionary key (that is stored in the database).</p>
<p>I was trying to get this to work with state... | 0 | 2012-01-09T23:57:46Z | [
"python",
"django",
"list",
"dictionary",
"tuples"
] |
python variable scope issue | 1,384,301 | <p>i am stuck at scope resolution in python.
let me explain a code first:</p>
<pre><code>class serv_db:
def __init__(self, db):
self.db = db
self.dbc = self.db.cursor()
def menudisp (self):
print"Welcome to Tata Motors"
print"Please select one of the options to continue:"
print"1. Insert Car Info"
print"2. Dis... | -1 | 2009-09-05T21:28:01Z | 1,384,304 | <p>It's a mistake to explicitly pass self when calling a method on your class. It's another mistake comparing ch to integers, when raw_input returns a string</p>
<p>Try</p>
<pre><code>elif ch=='2': self.adnewcar(reg)
</code></pre>
<p>instead</p>
<p>You also have a print misindented in adnewcar.</p>
<p>But even the... | 2 | 2009-09-05T21:31:52Z | [
"python"
] |
python variable scope issue | 1,384,301 | <p>i am stuck at scope resolution in python.
let me explain a code first:</p>
<pre><code>class serv_db:
def __init__(self, db):
self.db = db
self.dbc = self.db.cursor()
def menudisp (self):
print"Welcome to Tata Motors"
print"Please select one of the options to continue:"
print"1. Insert Car Info"
print"2. Dis... | -1 | 2009-09-05T21:28:01Z | 1,384,378 | <p>You need all these three:</p>
<pre><code>if menu_choice==1: self.additem() # 1: self.
elif ch=='2': self.adnewcar(reg) # 2: self. instead of (self, reg)
print "adding info to database: car" # 3: indented.
</code></pre>
<p>Always remember to keep indents consistent throughout a .py, otherwise the interpreter w... | 0 | 2009-09-05T22:11:13Z | [
"python"
] |
python variable scope issue | 1,384,301 | <p>i am stuck at scope resolution in python.
let me explain a code first:</p>
<pre><code>class serv_db:
def __init__(self, db):
self.db = db
self.dbc = self.db.cursor()
def menudisp (self):
print"Welcome to Tata Motors"
print"Please select one of the options to continue:"
print"1. Insert Car Info"
print"2. Dis... | -1 | 2009-09-05T21:28:01Z | 1,384,379 | <p>is it a copy error or do you have your indentation wrong? The (I suppose) methods align with the class definition instead of being indented one level. </p>
<p>Perhaps you are mixing tabs and spaces?</p>
<p>btw if you define your class correctly you should be calling <em>self.additem()</em> instead of <em>additem()... | 0 | 2009-09-05T22:11:21Z | [
"python"
] |
Serving file download with python | 1,384,320 | <p>Hey gang, I'm trying to convert a legacy php script over to python and not having much luck. </p>
<p>The intent of the script is to serve up a file while concealing it's origin. Here's what's working in php:</p>
<pre><code><?php
$filepath = "foo.mp3";
$filesize = filesize($filepath);
header("Pragma: no-cache"... | 1 | 2009-09-05T21:38:18Z | 1,384,328 | <p>Well, maybe it's just me missing something, but... You are actually not writing the contents of the file to stdout. You are just reading it into memory, so it will never show up on the other side of the TCP connection...</p>
<p>Try:</p>
<pre><code>sys.stdout.write(open(filepath,"rb").read())
sys.stdout.flush()
</c... | 5 | 2009-09-05T21:43:43Z | [
"php",
"python",
"binary"
] |
Serving file download with python | 1,384,320 | <p>Hey gang, I'm trying to convert a legacy php script over to python and not having much luck. </p>
<p>The intent of the script is to serve up a file while concealing it's origin. Here's what's working in php:</p>
<pre><code><?php
$filepath = "foo.mp3";
$filesize = filesize($filepath);
header("Pragma: no-cache"... | 1 | 2009-09-05T21:38:18Z | 1,384,329 | <p>You should check out <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a> to set and work with headers. <a href="http://vsbabu.org/mt/archives/2003/05/27/urllib2%5Fsetting%5Fhttp%5Fheaders.html" rel="nofollow">Here's a small example</a> that does this.</p>
| -1 | 2009-09-05T21:43:51Z | [
"php",
"python",
"binary"
] |
Serving file download with python | 1,384,320 | <p>Hey gang, I'm trying to convert a legacy php script over to python and not having much luck. </p>
<p>The intent of the script is to serve up a file while concealing it's origin. Here's what's working in php:</p>
<pre><code><?php
$filepath = "foo.mp3";
$filesize = filesize($filepath);
header("Pragma: no-cache"... | 1 | 2009-09-05T21:38:18Z | 1,384,330 | <p>I don't know if this is the only issue but the python print statement terminates lines with "\n" whereas HTTP headers need to be terminated with "\r\n"</p>
| 1 | 2009-09-05T21:44:29Z | [
"php",
"python",
"binary"
] |
lxml equivalent to BeautifulSoup "OR" syntax? | 1,384,470 | <p>I'm converting some html parsing code from BeautifulSoup to lxml. I'm trying to figure out the lxml equivalent syntax for the following BeautifullSoup statement:</p>
<pre><code>soup.find('a', {'class': ['current zzt', 'zzt']})
</code></pre>
<p>Basically I want to find all of the "a" tags in the document that have... | 5 | 2009-09-05T23:04:18Z | 1,429,316 | <p>No, lxml does not provide the "find first or return None" method you're looking for. Just use <code>(select(soup) or [None])[0]</code> if you need that, or write a function to do it for you.</p>
<pre><code>#!/usr/bin/python
import lxml.html
import lxml.cssselect
soup = lxml.html.fromstring("""
<html>
... | 3 | 2009-09-15T19:57:42Z | [
"python",
"beautifulsoup",
"lxml"
] |
python smtp gmail authentication error (sending email through gmail smtp server) | 1,384,535 | <p>I have the following code </p>
<pre><code>import smtplib
from email.mime.text import MIMEText
smtpserver = 'smtp.gmail.com'
AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1
smtpuser = 'admin@myhost.com' # for SMTP AUTH, set SMTP username here
smtppass = '123456' # for SMTP AUTH, set SMTP password here
... | 2 | 2009-09-05T23:52:31Z | 1,384,583 | <p>Port 587 obviously needs to be open, but it probably is (or you wouldn't have gotten the detailed error msg in question). Python 2.5 vs 2.6 should make no difference. I think the issue has to do with "solving a captcha" once on the computer for which logins are currently getting rejected; follow the detailed instruc... | 6 | 2009-09-06T00:27:50Z | [
"python",
"smtp",
"gmail",
"smtplib"
] |
python smtp gmail authentication error (sending email through gmail smtp server) | 1,384,535 | <p>I have the following code </p>
<pre><code>import smtplib
from email.mime.text import MIMEText
smtpserver = 'smtp.gmail.com'
AUTHREQUIRED = 1 # if you need to use SMTP AUTH set to 1
smtpuser = 'admin@myhost.com' # for SMTP AUTH, set SMTP username here
smtppass = '123456' # for SMTP AUTH, set SMTP password here
... | 2 | 2009-09-05T23:52:31Z | 5,673,945 | <pre><code>import random,time
for i in range(1,100):
y=random.randint(30,300)
time.sleep(y)
print ("Mailing for fun, Mail No: " + str(i))
msg = MIMEText('Testing mailing \n Mail No:' + str(i))
msg['Subject'] = 'Mail Number: ' + str(i)
</code></pre>
<p>Randomizing the mail interval to check smtp beh... | 2 | 2011-04-15T08:02:04Z | [
"python",
"smtp",
"gmail",
"smtplib"
] |
Python : Revert to base __str__ behavior | 1,384,542 | <p>How can I revert back to the default function that python uses if there is no <code>__str__</code> method?</p>
<pre><code>class A :
def __str__(self) :
return "Something useless"
class B(A) :
def __str__(self) :
return some_magic_base_function(self)
</code></pre>
| 6 | 2009-09-06T00:00:39Z | 1,384,559 | <p>You can use <code>object.__str__()</code>:</p>
<pre><code>class A:
def __str__(self):
return "Something useless"
class B(A):
def __str__(self):
return object.__str__(self)
</code></pre>
<p>This gives you the default output for instances of <code>B</code>:</p>
<pre><code>>>> b = B()
>... | 12 | 2009-09-06T00:06:42Z | [
"python",
"string"
] |
Python : Revert to base __str__ behavior | 1,384,542 | <p>How can I revert back to the default function that python uses if there is no <code>__str__</code> method?</p>
<pre><code>class A :
def __str__(self) :
return "Something useless"
class B(A) :
def __str__(self) :
return some_magic_base_function(self)
</code></pre>
| 6 | 2009-09-06T00:00:39Z | 1,384,569 | <p>"the default function that python uses if there is no <code>__str__</code> method" is <code>repr</code>, so:</p>
<pre><code>class B(A) :
def __str__(self) :
return repr(self)
</code></pre>
<p>This holds whether <code>__repr__</code> has been overridden in the inheritance chain or not. IOW, if you ALSO nee... | 2 | 2009-09-06T00:16:30Z | [
"python",
"string"
] |
How to "slow down" a MIDI file (ideally in Python)? | 1,384,588 | <p>I have background music for some songs available in both .MID and .KAR formats, but in each case it's being played somewhat faster than I'd like. What's the simplest way to create either .MID or .KAR files with the same content but at a slower tempo -- say, one slowed down by 20% or so, another by 15%, a third by 25... | 14 | 2009-09-06T00:35:53Z | 1,384,611 | <p>You could edit the file, as per <a href="http://www.sonicspot.com/guide/midifiles.html" rel="nofollow">http://www.sonicspot.com/guide/midifiles.html</a></p>
<p>Although there probably is a MIDI reading/writing library already. In fact, it was a matter of seeing the related questions: <a href="http://stackoverflow.c... | 9 | 2009-09-06T00:47:20Z | [
"python",
"midi"
] |
How to "slow down" a MIDI file (ideally in Python)? | 1,384,588 | <p>I have background music for some songs available in both .MID and .KAR formats, but in each case it's being played somewhat faster than I'd like. What's the simplest way to create either .MID or .KAR files with the same content but at a slower tempo -- say, one slowed down by 20% or so, another by 15%, a third by 25... | 14 | 2009-09-06T00:35:53Z | 1,449,597 | <p>As Vinko says, you can edit the midifile, but since it's a binary format, squeezed into the least number of bits possible, it helps to have help.</p>
<p>This is a midi-to-text converter (and vice-versa):<br />
<a href="http://midicomp.opensrc.org/">http://midicomp.opensrc.org/</a><br />
I've been using it quite a b... | 13 | 2009-09-19T21:34:34Z | [
"python",
"midi"
] |
How to "slow down" a MIDI file (ideally in Python)? | 1,384,588 | <p>I have background music for some songs available in both .MID and .KAR formats, but in each case it's being played somewhat faster than I'd like. What's the simplest way to create either .MID or .KAR files with the same content but at a slower tempo -- say, one slowed down by 20% or so, another by 15%, a third by 25... | 14 | 2009-09-06T00:35:53Z | 20,596,154 | <p>I have a similar interest as your post. I just came across this library which looks very promising:</p>
<p><a href="http://web.mit.edu/music21/" rel="nofollow">http://web.mit.edu/music21/</a></p>
| 1 | 2013-12-15T15:27:14Z | [
"python",
"midi"
] |
Should I use Mako for Templating? | 1,384,634 | <p>I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako.</p>
<p>I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe?</p>
<p... | 7 | 2009-09-06T01:11:38Z | 1,384,671 | <p>This seems to be a bit of a religious issue. Django templates take a hard line: no code in templates. They do this because of their history as a system used in shops where there's a clear separation between those who write code and those who create pages. Others (perhaps you) don't make such a clear distinction, ... | 2 | 2009-09-06T01:36:52Z | [
"python",
"template-engine",
"mako",
"genshi"
] |
Should I use Mako for Templating? | 1,384,634 | <p>I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako.</p>
<p>I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe?</p>
<p... | 7 | 2009-09-06T01:11:38Z | 1,384,699 | <p>As the mako <a href="http://www.makotemplates.org/">homepage</a> points out, Mako's advantages are pretty clear: insanely fast, instantly familiar to anyone who's handy with Python in terms of both syntax and features.</p>
<p>Genshi chooses "interpretation" instead of ahead-of-time Python code generation (according... | 18 | 2009-09-06T01:54:26Z | [
"python",
"template-engine",
"mako",
"genshi"
] |
Should I use Mako for Templating? | 1,384,634 | <p>I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako.</p>
<p>I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe?</p>
<p... | 7 | 2009-09-06T01:11:38Z | 1,384,847 | <p>You could discipline yourself to not inject any Python code within the template unless it's really the last resort to get the job done. I have faced a similar issue with Django's template where I have to do some serious CSS gymnastics to display my content. If I could have used some Python code in the template, it ... | 0 | 2009-09-06T04:15:18Z | [
"python",
"template-engine",
"mako",
"genshi"
] |
Should I use Mako for Templating? | 1,384,634 | <p>I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako.</p>
<p>I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe?</p>
<p... | 7 | 2009-09-06T01:11:38Z | 1,386,193 | <p>Genshi is conceived (read: biased, optimized) for generation of xml docs (even if it does offer support for generating any kind of text document). Mako and Django templates are conceived as <em>generic text</em> templating system. <a href="http://evoque.gizmojo.org/" rel="nofollow">Evoque</a> also, but with one fund... | 2 | 2009-09-06T17:30:33Z | [
"python",
"template-engine",
"mako",
"genshi"
] |
Should I use Mako for Templating? | 1,384,634 | <p>I've been considering a templating solution, although my choices are between Mako and Genshi. I find templating in Genshi a bit ugly, so I'm shifting more towards Mako.</p>
<p>I've gone to wonder: what is so good about the fact that Mako allows embedded Python code? How is it convenient for the average joe?</p>
<p... | 7 | 2009-09-06T01:11:38Z | 1,391,510 | <blockquote>
<p>Wouldn't templating JUST suffice without having embedded Python code?</p>
</blockquote>
<p>Only if your templating language has enough logical functionality that it is essentially a scripting language in itself. At which point, you might just as well have used Python.</p>
<p>More involved sites ofte... | 15 | 2009-09-08T01:16:12Z | [
"python",
"template-engine",
"mako",
"genshi"
] |
Is concurrent computing important for web development? | 1,384,715 | <p>Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is pro... | 4 | 2009-09-06T02:10:03Z | 1,384,724 | <p>Not anytime soon in my estimation. The lifespan of most single web requests are well under a second. In light of this it makes little sense to split up the web request task itself and rather distribute the web request tasks across the cores. Something web servers are capable of and most already do. </p>
| 4 | 2009-09-06T02:15:49Z | [
"python",
"web-applications",
"concurrency"
] |
Is concurrent computing important for web development? | 1,384,715 | <p>Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is pro... | 4 | 2009-09-06T02:10:03Z | 1,384,736 | <p>In the hypothetical circumstances you design, with about 10 requests "in play" per core, as long as the request-to-core assignment is handled sensibly (probably even the simplest round-robin load balancing will do), it's just fine if each request lives throughout its lifetime on a single core.</p>
<p>Point is, that... | 5 | 2009-09-06T02:24:47Z | [
"python",
"web-applications",
"concurrency"
] |
Is concurrent computing important for web development? | 1,384,715 | <p>Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is pro... | 4 | 2009-09-06T02:10:03Z | 1,384,753 | <p>Caveat: I've only skimmed the "Concurrency" section, which seems to be what you're referring to.The issue seems to be (and this isn't new, of course):</p>
<ul>
<li>Python threads don't run in parallel due to the GIL.</li>
<li>A system with many cores will need as many backends (in practice, you probably want at lea... | 1 | 2009-09-06T02:48:51Z | [
"python",
"web-applications",
"concurrency"
] |
Is concurrent computing important for web development? | 1,384,715 | <p>Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is pro... | 4 | 2009-09-06T02:10:03Z | 1,384,774 | <p>In the article, he seems to single out the GIL as the cause of holding back concurrent processing in web applications in Python, which I simply don't understand. As you get larger, eventually you're going to have another server, and, GIL or not GIL, it won't matter - you have multiple machines.</p>
<p>If he's talk... | 0 | 2009-09-06T03:01:17Z | [
"python",
"web-applications",
"concurrency"
] |
Is concurrent computing important for web development? | 1,384,715 | <p>Let's say I have a web application running on S servers with an average of C cores each. My application is processing an average of R requests at any instant. Assuming R is around 10 times larger than S * C, won't benefits from spreading the work of a request across multiple cores be minimal since each core is pro... | 4 | 2009-09-06T02:10:03Z | 1,384,855 | <p>One thing you're omitting is that a web request isn't a single sequential series of instructions that involve only the CPU.</p>
<p>A typical web request handler might need to do some computation with the CPU, then read some config data off the disk, then ask the database server for some records that have to get tra... | 1 | 2009-09-06T04:23:01Z | [
"python",
"web-applications",
"concurrency"
] |
Python egg found interactively but not in fastcgi | 1,384,717 | <p>In agreement to <a href="http://stackoverflow.com/questions/531224/setting-up-django-on-an-internal-server-os-environ-not-working-as-expected">this question, and its answer</a>. I added the path of the egg and it worked. However, when I run python interactively and I import flup, it works without any problem or addi... | 1 | 2009-09-06T02:10:28Z | 1,384,729 | <p>Programs run by or code run in a web server has a restricted environment compared with what you use interactively. Most likely, the difference stems from the difference between your interactive environment and the FastCGI environment. What I can't tell you is which difference is critical in this context.</p>
| 0 | 2009-09-06T02:20:09Z | [
"python",
"fastcgi",
"egg"
] |
Python egg found interactively but not in fastcgi | 1,384,717 | <p>In agreement to <a href="http://stackoverflow.com/questions/531224/setting-up-django-on-an-internal-server-os-environ-not-working-as-expected">this question, and its answer</a>. I added the path of the egg and it worked. However, when I run python interactively and I import flup, it works without any problem or addi... | 1 | 2009-09-06T02:10:28Z | 1,384,775 | <p>I've encountered a similar issue when running my Python applications under IIS (Windows). I've found that when running under ISAPI, eggs aren't readable because setuptools munges the permissions on zipped eggs, and because the ISAPI application runs under a limited privilege account.</p>
<p>You may be experiencing... | 0 | 2009-09-06T03:01:20Z | [
"python",
"fastcgi",
"egg"
] |
Python egg found interactively but not in fastcgi | 1,384,717 | <p>In agreement to <a href="http://stackoverflow.com/questions/531224/setting-up-django-on-an-internal-server-os-environ-not-working-as-expected">this question, and its answer</a>. I added the path of the egg and it worked. However, when I run python interactively and I import flup, it works without any problem or addi... | 1 | 2009-09-06T02:10:28Z | 1,386,226 | <p>After some more thorough analysis, I think I understand what's going on here.</p>
<p>When Python starts up, it sets up the sys.path (all as part of initializing the interpreter).</p>
<p>At this time, the environment is used to determine where to find .pth files. If no PYTHONPATH is defined at this time, then it w... | 2 | 2009-09-06T17:42:41Z | [
"python",
"fastcgi",
"egg"
] |
Python egg found interactively but not in fastcgi | 1,384,717 | <p>In agreement to <a href="http://stackoverflow.com/questions/531224/setting-up-django-on-an-internal-server-os-environ-not-working-as-expected">this question, and its answer</a>. I added the path of the egg and it worked. However, when I run python interactively and I import flup, it works without any problem or addi... | 1 | 2009-09-06T02:10:28Z | 3,748,247 | <p>I concur that even with the PYTHONPATH environment variable defined the .pth files do not get interpreted when python starts up in the FastCGI environment. I do not now why this is so, but I do have a suggestion for a workaround.</p>
<p>Use site.addsitedir. It will interpret the .pth files allowing you to then impo... | 0 | 2010-09-20T01:43:10Z | [
"python",
"fastcgi",
"egg"
] |
Where should one place the code to autoincrement a sharded counter on Google App Engine/Django when one creates a new model? | 1,384,932 | <p>I've a model MyModel (extending Google's db.Model), and I want to keep track of the number of Models that have been created.</p>
<p>I think the code at from Google's I/O talk on <a href="http://code.google.com/appengine/articles/sharding_counters.html" rel="nofollow">Sharding Counters</a> is quite good, so I'm usin... | 3 | 2009-09-06T05:26:18Z | 1,386,885 | <p>I suggest the approach (curiously close to "aspect oriented programming") suggested by "App Engine Fan" <a href="http://blog.appenginefan.com/2009/01/hacking-google-app-engine-part-1.html" rel="nofollow">here</a> (essentially "setting the scene") and especially <a href="http://blog.appenginefan.com/2009/01/hacking-g... | 2 | 2009-09-06T22:25:53Z | [
"python",
"django",
"google-app-engine",
"auto-increment",
"sharding"
] |
Django admin and showing thumbnail images | 1,385,094 | <p>I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong.</p>
<p>Server media URL:</p>
<pre><code>from django.conf import settings
(r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': set... | 44 | 2009-09-06T07:15:35Z | 1,385,145 | <p>This is in the source for <a href="http://code.google.com/p/django-photologue/">photologue</a> (see <code>models.py</code>, slightly adapted to remove irrelevant stuff):</p>
<pre><code>def admin_thumbnail(self):
return u'<img src="%s" />' % (self.image.url)
admin_thumbnail.short_description = 'Thumbnail'
... | 64 | 2009-09-06T07:43:07Z | [
"python",
"django",
"django-admin"
] |
Django admin and showing thumbnail images | 1,385,094 | <p>I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong.</p>
<p>Server media URL:</p>
<pre><code>from django.conf import settings
(r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': set... | 44 | 2009-09-06T07:15:35Z | 11,475,926 | <p>Adding on to @dominic, I wanted to use this in multiple models, so I created a function that I could call in each model, inputing the image to be displayed.</p>
<p>For instance in one app I have:</p>
<pre><code>from django.contrib import admin
from .models import Frontpage
from ..admin import image_file
class F... | 6 | 2012-07-13T18:06:17Z | [
"python",
"django",
"django-admin"
] |
Django admin and showing thumbnail images | 1,385,094 | <p>I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong.</p>
<p>Server media URL:</p>
<pre><code>from django.conf import settings
(r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': set... | 44 | 2009-09-06T07:15:35Z | 21,449,282 | <p>Add a method in your model (<code>models.py</code>):</p>
<pre><code>def image_tag(self):
return u'<img src="%s" />' % <URL to the image>
image_tag.short_description = 'Image'
image_tag.allow_tags = True
</code></pre>
<p>and in your ModelAdmin (<code>admin.py</code>) add:</p>
<pre><code>readonly_fi... | 6 | 2014-01-30T06:24:23Z | [
"python",
"django",
"django-admin"
] |
Django admin and showing thumbnail images | 1,385,094 | <p>I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong.</p>
<p>Server media URL:</p>
<pre><code>from django.conf import settings
(r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': set... | 44 | 2009-09-06T07:15:35Z | 37,965,195 | <h1>Update v. 1.9</h1>
<p>Note that in Django v.1.9 <strike></p>
<pre><code>image_tag.allow_tags = True
</code></pre>
<p></strike></p>
<blockquote>
<p><a href="https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display" rel="nofollow">is depricated and you should use for... | 3 | 2016-06-22T10:23:21Z | [
"python",
"django",
"django-admin"
] |
Django admin and showing thumbnail images | 1,385,094 | <p>I'm trying to show thumbnail images in Django admin, but I can only see the path to the images, but not the rendered images. I don't know what I'm doing wrong.</p>
<p>Server media URL:</p>
<pre><code>from django.conf import settings
(r'^public/(?P<path>.*)$', 'django.views.static.serve',{'document_root': set... | 44 | 2009-09-06T07:15:35Z | 38,718,178 | <p>With <a href="https://github.com/matthewwithanm/django-imagekit" rel="nofollow">django-imagekit</a> you can add any image like this:</p>
<pre><code>from imagekit.admin import AdminThumbnail
@register(Fancy)
class FancyAdmin(ModelAdmin):
list_display = ['name', 'image_display']
image_display = AdminThumbnai... | 1 | 2016-08-02T10:39:14Z | [
"python",
"django",
"django-admin"
] |
Unpickling classes from Python 3 in Python 2 | 1,385,096 | <p>If a Python 3 class is pickled using protocol 2, it is supposed to work in Python 2, but unfortunately, this fails because the names of some classes have changed.</p>
<p>Assume we have code called as follows.</p>
<p>Sender</p>
<pre><code>pickle.dumps(obj,2)
</code></pre>
<p>Receiver</p>
<pre><code>pickle.loads(... | 5 | 2009-09-06T07:15:54Z | 1,385,100 | <p>This problem is <a href="http://bugs.python.org/issue3675" rel="nofollow">Python issue 3675</a>. This bug is actually fixed in Python 3.11.</p>
<p>If we import:</p>
<pre><code>from lib2to3.fixes.fix_imports import MAPPING
</code></pre>
<p>MAPPING maps Python 2 names to Python 3 names. We want this in reverse.</p>... | 11 | 2009-09-06T07:18:45Z | [
"python",
"python-3.x",
"pickle"
] |
Edit python31 file and it opens notepad and starts python26 | 1,385,280 | <p>I am in python31, </p>
<p>then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31</p>
<p>The moment it opens the notepad, it starts python26</p>
<p>I thought it has something to open with, and I have changed that to python31
And it still opens python26</p>
<p>EDIT:</p... | -1 | 2009-09-06T09:27:10Z | 1,385,322 | <p>I am guessing here, the question it not very clear. </p>
<p>It sounds like the .py extension in Windows is associated with the Python 2.6 runtime. (This normally get setup this way during installation of Python on Windows). You can change this by updating the associated file extensions and programs in Windows.</p>
... | 0 | 2009-09-06T10:01:35Z | [
"python",
"windows",
"python-3.x"
] |
Edit python31 file and it opens notepad and starts python26 | 1,385,280 | <p>I am in python31, </p>
<p>then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31</p>
<p>The moment it opens the notepad, it starts python26</p>
<p>I thought it has something to open with, and I have changed that to python31
And it still opens python26</p>
<p>EDIT:</p... | -1 | 2009-09-06T09:27:10Z | 1,385,779 | <p>I had similar problems, and right clicking and changing edit options didn't solve it. You can try repairing python31 installation with running the msi installer and selecting it as the default python</p>
| 0 | 2009-09-06T14:18:41Z | [
"python",
"windows",
"python-3.x"
] |
Calling non-static method from static one in Python | 1,385,546 | <p>I can't find if it's possible to call a non-static method from a static one in Python.</p>
<p>Thanks</p>
<p>EDIT:
Ok. And what about static from static? Can I do this:</p>
<pre><code>class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd)... | 3 | 2009-09-06T12:20:29Z | 1,385,553 | <p>When in a static method, you don't have a self instance: what object are you calling the non-static methods on? Certainly if you have an instance lying around, you can call methods on it.</p>
| 2 | 2009-09-06T12:22:45Z | [
"python",
"oop"
] |
Calling non-static method from static one in Python | 1,385,546 | <p>I can't find if it's possible to call a non-static method from a static one in Python.</p>
<p>Thanks</p>
<p>EDIT:
Ok. And what about static from static? Can I do this:</p>
<pre><code>class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd)... | 3 | 2009-09-06T12:20:29Z | 1,385,563 | <p>It's not possible withotut the instance of the class. You could add a param to your method <code>f(x, y, ..., me)</code> and use <code>me</code> as the object to call the non-static methods on.</p>
| 0 | 2009-09-06T12:28:24Z | [
"python",
"oop"
] |
Calling non-static method from static one in Python | 1,385,546 | <p>I can't find if it's possible to call a non-static method from a static one in Python.</p>
<p>Thanks</p>
<p>EDIT:
Ok. And what about static from static? Can I do this:</p>
<pre><code>class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd)... | 3 | 2009-09-06T12:20:29Z | 1,385,611 | <p>After the other answers and your follow-up question - regarding static method from static method: Yes you can:</p>
<pre><code>>>> class MyClass(object):
@staticmethod
def static_method_one(x):
return MyClass.static_method_two(x)
@staticmethod
def static_method_two(x):
return 2 * x... | 2 | 2009-09-06T12:57:05Z | [
"python",
"oop"
] |
Calling non-static method from static one in Python | 1,385,546 | <p>I can't find if it's possible to call a non-static method from a static one in Python.</p>
<p>Thanks</p>
<p>EDIT:
Ok. And what about static from static? Can I do this:</p>
<pre><code>class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd)... | 3 | 2009-09-06T12:20:29Z | 1,385,633 | <p>Use class methods, not static methods. Why else put it inside a class?</p>
<pre><code>class MyClass(object):
@classmethod
def static_method_one(cls, cmd):
...
@classmethod
def static_method_two(cls, cmd):
cls.static_method_one(cmd)
</code></pre>
| 3 | 2009-09-06T13:06:04Z | [
"python",
"oop"
] |
Calling non-static method from static one in Python | 1,385,546 | <p>I can't find if it's possible to call a non-static method from a static one in Python.</p>
<p>Thanks</p>
<p>EDIT:
Ok. And what about static from static? Can I do this:</p>
<pre><code>class MyClass(object):
@staticmethod
def static_method_one(cmd):
...
@staticmethod
def static_method_two(cmd)... | 3 | 2009-09-06T12:20:29Z | 1,385,650 | <p>It's perfectly possible, but not very meaningful. Ponder the following class:</p>
<pre><code>class MyClass:
# Normal method:
def normal_method(self, data):
print "Normal method called with instance %s and data %s" % (self, data)
@classmethod
def class_method(cls, data):
print "Class... | 7 | 2009-09-06T13:13:35Z | [
"python",
"oop"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.