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 |
|---|---|---|---|---|---|---|---|---|---|
Is there a way to check whether function output is assigned to a variable in Python? | 813,882 | <p>In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just</p>
<pre><code>check_status()
</code></pre>
<p>I would like t... | 2 | 2009-05-02T01:08:18Z | 814,177 | <p>Even if there is a way to do this, it's a bad idea. Imagine trying to debug something that behaves differently depending on the context it's called from. Now try to imagine that it's six months from now and this is buried in part of some system that's too big to keep in your head all at once.</p>
<p>Keep it simple.... | 1 | 2009-05-02T05:01:11Z | [
"python",
"functional-programming",
"bytecode"
] |
If I want to use a pylons app with Apache, should I use mod_wsgi or proxy to paste? | 813,943 | <p>Or should I be using a totally different server?</p>
| 4 | 2009-05-02T01:37:39Z | 814,005 | <p>Nginx with mod_wsgi requires the use of a non-blocking asynchronous framework and setup and isn't likely to work out of box with Pylons.</p>
<p>I usually go with the proxy route to a stand-alone Pylons process using the PasteScript#cherrypy WSGI server (as its higher performing than the Paste#http one, though it wo... | 8 | 2009-05-02T02:26:56Z | [
"python",
"apache2",
"pylons",
"mod-wsgi"
] |
If I want to use a pylons app with Apache, should I use mod_wsgi or proxy to paste? | 813,943 | <p>Or should I be using a totally different server?</p>
| 4 | 2009-05-02T01:37:39Z | 817,350 | <p>I've also used mod_fastcgi + flup to great success several times now. There are a couple of recipes floating around for setting this up, but unfortunately it will probably still require some tweaking on your part to get everything working:</p>
<p><a href="http://wiki.pylonshq.com/display/pylonscookbook/Production+... | 0 | 2009-05-03T15:47:43Z | [
"python",
"apache2",
"pylons",
"mod-wsgi"
] |
How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard? | 814,041 | <p>Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:</p>
<pre><code>noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsd... | 4 | 2009-05-02T03:08:07Z | 814,105 | <p>Follow the instructions at <a href="http://marc-abramowitz.com/archives/2007/11/28/hacking-os-xs-python-dbhash-and-bsddb-modules-to-work/">http://marc-abramowitz.com/archives/2007/11/28/hacking-os-xs-python-dbhash-and-bsddb-modules-to-work/</a> .</p>
| 6 | 2009-05-02T03:59:58Z | [
"python",
"osx",
"osx-leopard",
"berkeley-db",
"bsddb"
] |
How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard? | 814,041 | <p>Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:</p>
<pre><code>noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsd... | 4 | 2009-05-02T03:08:07Z | 5,687,452 | <p>A solution I found was to install ActivePython, dig into its library (located in /Library/Frameworks/Python.framework/Versions/....your version here..../lib) and copy and paste the <strong>_bsddb.so</strong> file into my OS X 10.6 native python 2.6 install directory (/System/Library/Frameworks/Python.framework/Versi... | 1 | 2011-04-16T15:18:45Z | [
"python",
"osx",
"osx-leopard",
"berkeley-db",
"bsddb"
] |
How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard? | 814,041 | <p>Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:</p>
<pre><code>noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsd... | 4 | 2009-05-02T03:08:07Z | 17,073,693 | <p>The error I had was "No module named _bsddb". It turn out I didn't need to upgrade my bsddb. I wasusing the .pkl file created in windows. After renaming the pkl file to get it out the way Mac OSX Python recreated a new .pkl.db file and now it works perfectly.</p>
| 0 | 2013-06-12T19:28:54Z | [
"python",
"osx",
"osx-leopard",
"berkeley-db",
"bsddb"
] |
How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard? | 814,041 | <p>Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:</p>
<pre><code>noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsd... | 4 | 2009-05-02T03:08:07Z | 24,358,389 | <p>The patch did not work for me and I had to replace the bsddb folder in
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7</p>
<p>with the bsddb3 in:</p>
<p>/usr/local/lib/python2.7/site-packages/bsddb3</p>
<p>Make sure you backup the bsddb folder just in case.</p>
| 1 | 2014-06-23T04:28:28Z | [
"python",
"osx",
"osx-leopard",
"berkeley-db",
"bsddb"
] |
How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard? | 814,041 | <p>Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:</p>
<pre><code>noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsd... | 4 | 2009-05-02T03:08:07Z | 25,348,662 | <p>This pain persists on OSX 10.8. I could not install bsddb3 using macports py-bsddb3 into a virtualenv. What was very simple and did work is:</p>
<ul>
<li>install db53 from macports</li>
<li>download and unpack bsddb3 source (<a href="https://pypi.python.org/pypi/bsddb3/6.1.0" rel="nofollow">https://pypi.python.org/... | 2 | 2014-08-17T11:10:12Z | [
"python",
"osx",
"osx-leopard",
"berkeley-db",
"bsddb"
] |
PY2EXE: How to output "*_D.PYD" file (debug) and use MSVCR80D.DLL? | 814,078 | <p>The debug configuration of my app is built against:</p>
<pre><code> PYTHON25_D.DLL
MSVCR80D.DLL
</code></pre>
<p>We use Python .PYD files in our application. Some of these .PYD are .PY converted by PY2EXE to .PYD.</p>
<p>When I run PY2EXE on MYSCRIPT.PY, I get the following .PYD and dependencies:</p>
<pre><co... | 0 | 2009-05-02T03:40:31Z | 814,189 | <p>it won't work, beacuse MSVCR80D is a side by side runtime</p>
<p>You will need to either tell user to directly install MS runtime or manually also copy the manifest files.
Also the MSVCR71.DLL is not selected for you. It's for Python, so you may still need to keep it.</p>
| 0 | 2009-05-02T05:12:00Z | [
"python",
"windows",
"py2exe"
] |
PY2EXE: How to output "*_D.PYD" file (debug) and use MSVCR80D.DLL? | 814,078 | <p>The debug configuration of my app is built against:</p>
<pre><code> PYTHON25_D.DLL
MSVCR80D.DLL
</code></pre>
<p>We use Python .PYD files in our application. Some of these .PYD are .PY converted by PY2EXE to .PYD.</p>
<p>When I run PY2EXE on MYSCRIPT.PY, I get the following .PYD and dependencies:</p>
<pre><co... | 0 | 2009-05-02T03:40:31Z | 814,473 | <p>Note that the MS debug dlls are nondistributable - you must not give them avay. However, py2exe will collect the debug versions of all dlls correctly if you run a debug version of Python, and a debug compiled version of py2exe.</p>
| 0 | 2009-05-02T09:09:38Z | [
"python",
"windows",
"py2exe"
] |
Easiest way to rm -rf in Python | 814,167 | <p>What is the easiest way to do the equivalent of <code>rm -rf</code> in Python?</p>
| 42 | 2009-05-02T04:52:24Z | 814,170 | <pre><code>import shutil
shutil.rmtree("dir-you-want-to-remove")
</code></pre>
| 51 | 2009-05-02T04:54:34Z | [
"python"
] |
Easiest way to rm -rf in Python | 814,167 | <p>What is the easiest way to do the equivalent of <code>rm -rf</code> in Python?</p>
| 42 | 2009-05-02T04:52:24Z | 814,535 | <p>shutil.rmtree() is right answer, but just look at another useful function - os.walk()</p>
| 1 | 2009-05-02T09:38:05Z | [
"python"
] |
Easiest way to rm -rf in Python | 814,167 | <p>What is the easiest way to do the equivalent of <code>rm -rf</code> in Python?</p>
| 42 | 2009-05-02T04:52:24Z | 9,559,881 | <p>While useful, rmtree isn't equivalent: it errors out if you try to remove a single file, which <code>rm -f</code> does not (see example below).</p>
<p>To get around this, you'll need to check whether your path is a file or a directory, and act accordingly. Something like this should do the trick:</p>
<pre><code>im... | 24 | 2012-03-04T23:28:12Z | [
"python"
] |
Easiest way to rm -rf in Python | 814,167 | <p>What is the easiest way to do the equivalent of <code>rm -rf</code> in Python?</p>
| 42 | 2009-05-02T04:52:24Z | 32,881,474 | <pre><code>import os
import shutil
def rm_r(path):
if not os.path.exists(path):
return
if os.path.isfile(path) or os.path.islink(path):
os.unlink(path)
else:
shutil.rmtree(path)
</code></pre>
<p>Slightly improved Gabriel Grant's version. This works also on symlinks to directories.
... | 1 | 2015-10-01T07:11:52Z | [
"python"
] |
Easiest way to rm -rf in Python | 814,167 | <p>What is the easiest way to do the equivalent of <code>rm -rf</code> in Python?</p>
| 42 | 2009-05-02T04:52:24Z | 33,421,144 | <p>Just do this:</p>
<pre><code>import os
dirname = "path_to_directory_to_remove"
os.system("rm -rf %s" % dirname)
</code></pre>
| -5 | 2015-10-29T17:42:14Z | [
"python"
] |
Python lxml screen scraping? | 814,227 | <p>I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave m... | 1 | 2009-05-02T05:44:05Z | 814,233 | <p>No screen-scraping library I know "does well with Javascript" -- it's just too hard to anticipate all ways in which JS could alter the HTML DOM dynamically, conditionally &c.</p>
| 4 | 2009-05-02T05:47:06Z | [
"python",
"html",
"parsing",
"screen-scraping",
"lxml"
] |
Python lxml screen scraping? | 814,227 | <p>I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave m... | 1 | 2009-05-02T05:44:05Z | 814,430 | <p>BeautifulSoup (<a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">http://www.crummy.com/software/BeautifulSoup/</a>) is often the right answer to python html scraping questions.</p>
| 0 | 2009-05-02T08:33:29Z | [
"python",
"html",
"parsing",
"screen-scraping",
"lxml"
] |
Python lxml screen scraping? | 814,227 | <p>I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave m... | 1 | 2009-05-02T05:44:05Z | 814,538 | <p>I know of no Python HTML parsing libraries that handle running javascript in the page being parsed. It's not "simple enough" for the reasons given by Alex Martelli and more.</p>
<p>For this task you may need to think about going to a higher level than just parsing HTML and look at web application testing framework... | 0 | 2009-05-02T09:40:04Z | [
"python",
"html",
"parsing",
"screen-scraping",
"lxml"
] |
Python lxml screen scraping? | 814,227 | <p>I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave m... | 1 | 2009-05-02T05:44:05Z | 1,383,491 | <p>Your code is smart and very flexible to extent, I think.</p>
<p>How about simply adding handle_starttag() and handle_endtag() to supress the <script> blocks?</p>
<pre><code>class HTML2Text(HTMLParser.HTMLParser):
def __init__(self):
HTMLParser.HTMLParser.__init__(self)
self.output = cStri... | 0 | 2009-09-05T14:47:08Z | [
"python",
"html",
"parsing",
"screen-scraping",
"lxml"
] |
Python lxml screen scraping? | 814,227 | <p>I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave m... | 1 | 2009-05-02T05:44:05Z | 2,603,442 | <p><a href="http://zesty.ca/scrape/" rel="nofollow">scrape.py</a> can do this for you.</p>
<p>It's as simple as:</p>
<pre><code>import scrape
s = scrape.Session()
s.go('yoursite.com')
print s.doc.text
</code></pre>
<p>Jump to about 2:40 in this video for an awesome overview from the creator of scrape.py:
<a href="ht... | 2 | 2010-04-08T21:02:24Z | [
"python",
"html",
"parsing",
"screen-scraping",
"lxml"
] |
Python regex parsing | 814,786 | <p>I have an array of strings in python which each string in the array looking something like this:</p>
<pre><code><r n="Foo Bar" t="5" s="10" l="25"/>
</code></pre>
<p>I have been searching around for a while and the best thing I could find is attempting to modify a HTML hyperlink regex into something that wil... | 2 | 2009-05-02T12:28:13Z | 814,797 | <p>This will get you most of the way there:</p>
<pre><code>>>> print re.findall(r'(\w+)="(.*?)"', string)
[('n', 'Foo Bar'), ('t', '5'), ('s', '10'), ('l', '25')]
</code></pre>
<p><a href="http://docs.python.org/library/re.html#re.split" rel="nofollow">re.split</a> and <a href="http://docs.python.org/library... | 7 | 2009-05-02T12:34:08Z | [
"python",
"regex"
] |
Python regex parsing | 814,786 | <p>I have an array of strings in python which each string in the array looking something like this:</p>
<pre><code><r n="Foo Bar" t="5" s="10" l="25"/>
</code></pre>
<p>I have been searching around for a while and the best thing I could find is attempting to modify a HTML hyperlink regex into something that wil... | 2 | 2009-05-02T12:28:13Z | 814,872 | <blockquote>
<pre><code><r n="Foo Bar" t="5" s="10" l="25"/>
</code></pre>
</blockquote>
<p>That source looks like XML, so the "the best way" would be to use an XML parsing module.. If it's not exactly XML, BeautifulSoup (or rather, the <code>BeautifulSoup.BeautifulStoneSoup</code> module) may work best, as it's... | 6 | 2009-05-02T13:32:54Z | [
"python",
"regex"
] |
google app engine - design considerations about cron tasks | 814,896 | <p>I'm developing software using the google app engine. </p>
<p>I have some considerations about the optimal design regarding the following issue: I need to create and save snapshots of some entities at regular intervals.</p>
<p>in the conventional relational db world, I would create db jobs which would insert new su... | 1 | 2009-05-02T13:54:04Z | 814,932 | <p>Have you considered using the <a href="http://code.google.com/appengine/articles/remote%5Fapi.html" rel="nofollow">remote api</a> instead? This way you could get a shell to your datastore and avoid the timeouts. The Mapper class they demonstrate in that link is quite useful and I've used it successfully to do batch ... | 2 | 2009-05-02T14:23:21Z | [
"python",
"database",
"design",
"google-app-engine",
"cron"
] |
google app engine - design considerations about cron tasks | 814,896 | <p>I'm developing software using the google app engine. </p>
<p>I have some considerations about the optimal design regarding the following issue: I need to create and save snapshots of some entities at regular intervals.</p>
<p>in the conventional relational db world, I would create db jobs which would insert new su... | 1 | 2009-05-02T13:54:04Z | 815,113 | <p>I think you'll find that snapshotting every user's state every hour isn't something that will scale well no matter what your framework. A more ordinary environment will disguise this by letting you have longer running tasks, but you'll still reach the point where it's not practical to take a snapshot of every user's... | 3 | 2009-05-02T16:17:30Z | [
"python",
"database",
"design",
"google-app-engine",
"cron"
] |
google app engine - design considerations about cron tasks | 814,896 | <p>I'm developing software using the google app engine. </p>
<p>I have some considerations about the optimal design regarding the following issue: I need to create and save snapshots of some entities at regular intervals.</p>
<p>in the conventional relational db world, I would create db jobs which would insert new su... | 1 | 2009-05-02T13:54:04Z | 1,758,489 | <p>I would use a combination of Cron jobs and a looping url fetch method detailed here: <a href="http://stage.vambenepe.com/archives/549" rel="nofollow">http://stage.vambenepe.com/archives/549</a>. In this way you can catch your timeouts and begin another request.</p>
<p>To summarize the article, the cron job calls y... | 0 | 2009-11-18T19:35:02Z | [
"python",
"database",
"design",
"google-app-engine",
"cron"
] |
python regular exp. with a unicode char | 814,933 | <p>I need a reg exp that will parse something like-</p>
<pre><code>"2 * 240pin"
</code></pre>
<p>where the * can be either the regular star or unicode char \u00d7 or just an x. This is what I have but its not working:</p>
<pre><code>multiple= r'^(\d+)\s?x|*|\\u00d7\s?(\d+)(\w{2,4})$'
multiplepat= re.compile(multiple... | 3 | 2009-05-02T14:26:05Z | 814,947 | <pre><code>multiple= r'^(\d+)\s[xX\*\\u00d7]\s?(\d+)(\w{2,4})$'
</code></pre>
| 2 | 2009-05-02T14:39:06Z | [
"python",
"regex"
] |
python regular exp. with a unicode char | 814,933 | <p>I need a reg exp that will parse something like-</p>
<pre><code>"2 * 240pin"
</code></pre>
<p>where the * can be either the regular star or unicode char \u00d7 or just an x. This is what I have but its not working:</p>
<pre><code>multiple= r'^(\d+)\s?x|*|\\u00d7\s?(\d+)(\w{2,4})$'
multiplepat= re.compile(multiple... | 3 | 2009-05-02T14:26:05Z | 814,950 | <p>You need to escape the <code>*</code> as it is a quantifier in the context you use it. But you could also use a character class. So try this: </p>
<pre><code>ur'^(\d+)\s?[x*\u00d7]\s?(\d+)(\w{2,4})$'
</code></pre>
| 2 | 2009-05-02T14:41:06Z | [
"python",
"regex"
] |
python regular exp. with a unicode char | 814,933 | <p>I need a reg exp that will parse something like-</p>
<pre><code>"2 * 240pin"
</code></pre>
<p>where the * can be either the regular star or unicode char \u00d7 or just an x. This is what I have but its not working:</p>
<pre><code>multiple= r'^(\d+)\s?x|*|\\u00d7\s?(\d+)(\w{2,4})$'
multiplepat= re.compile(multiple... | 3 | 2009-05-02T14:26:05Z | 814,957 | <p>Use <a href="http://docs.python.org/library/re.html#regular-expression-syntax" rel="nofollow">character sets (<code>[]</code>)</a> :</p>
<blockquote>
<p>[]</p>
<p>Used to indicate a set of characters. Characters can be listed individually, or a range of characters can be indicated by giving two characters an... | 2 | 2009-05-02T14:44:35Z | [
"python",
"regex"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 815,160 | <p>It sounds like you're <strong>not</strong> asking for a general-purpose memoization decorator (i.e., you're not interested in the general case where you want to cache return values for different argument values). That is, you'd like to have this:</p>
<pre><code>x = obj.name # expensive
y = obj.name # cheap
</cod... | 22 | 2009-05-02T16:42:33Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 816,245 | <p>Ah, just needed to find the right name for this: "<a href="http://code.activestate.com/recipes/363602/" rel="nofollow">Lazy property evaluation</a>".</p>
<p>I do this a lot too; maybe I'll use that recipe in my code sometime.</p>
| 4 | 2009-05-03T03:25:54Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 2,061,438 | <p>There is yet another example of a <em>memoize</em> decorator at Python Wiki:</p>
<p><a href="http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize" rel="nofollow">http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize</a></p>
<p>That example is a bit smart, because it won't cache the results if the parame... | 3 | 2010-01-14T00:40:44Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 5,295,190 | <p>Werkzeug has a <code>cached_property</code> decorator (<a href="http://werkzeug.pocoo.org/docs/utils/#werkzeug.utils.cached_property">docs</a>, <a href="https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/utils.py">source</a>)</p>
| 8 | 2011-03-14T05:48:16Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 9,674,327 | <p>Starting from Python 3.2 there is a built-in decorator:</p>
<p><a href="http://docs.python.org/dev/library/functools.html#functools.lru_cache"><code>@functools.lru_cache(maxsize=100, typed=False)</code></a></p>
<blockquote>
Decorator to wrap a function with a memoizing callable that saves up to the maxsize most re... | 81 | 2012-03-12T20:28:46Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 16,459,127 | <p>If you are using Django Framework, it has such a property to cache a view or response of API's
using @cache_page(time) and there can be other options as well.</p>
<pre><code>@cache_page(60 * 15, cache="special_cache")
def my_view(request):
...
</code></pre>
<p>More details can be found <a href="https://docs.dj... | 2 | 2013-05-09T10:00:02Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 18,774,264 | <p>I implemented something like this, using pickle for persistance and using sha1 for short almost-certainly-unique IDs. Basically the cache hashed the code of the function and the hist of arguments to get a sha1 then looked for a file with that sha1 in the name. If it existed, it opened it and returned the result; if ... | 1 | 2013-09-12T21:01:43Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 22,552,713 | <pre><code>class memorize(dict):
def __init__(self, func):
self.func = func
def __call__(self, *args):
return self[args]
def __missing__(self, key):
result = self[key] = self.func(*key)
return result
</code></pre>
<p>Sample uses:</p>
<pre><code>>>> @memorize
... ... | 11 | 2014-03-21T07:27:09Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 29,891,043 | <p><strong>DISCLAIMER:</strong> I'm the author of <a href="https://github.com/0k/kids.cache" rel="nofollow">kids.cache</a>.</p>
<p>You should check <code>kids.cache</code>, it provides a <code>@cache</code> decorator that works on python 2 and python 3. No dependencies, ~100 lines of code. It's very straightforward to... | 3 | 2015-04-27T08:46:35Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 30,698,822 | <p>I coded this simple decorator class to cache function responses. I find it VERY useful for my projects:</p>
<pre><code>from datetime import datetime, timedelta
class cached(object):
def __init__(self, *args, **kwargs):
self.cached_function_responses = {}
self.default_max_age = kwargs.get("defa... | 6 | 2015-06-07T21:53:33Z | [
"python",
"caching",
"decorator"
] |
Is there a decorator to simply cache function return values? | 815,110 | <p>Consider the following:</p>
<pre><code>@property
def name(self):
if not hasattr(self, '_name'):
# expensive calculation
self._name = 1 + 1
return self._name
</code></pre>
<p>I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;)</p>
<p>PS th... | 67 | 2009-05-02T16:15:40Z | 36,857,036 | <p>Along with the <a href="http://wiki.python.org/moin/PythonDecoratorLibrary#Memoize" rel="nofollow">Memoize Example</a> I found the following python packages:</p>
<ul>
<li><a href="https://pypi.python.org/pypi/cachepy/" rel="nofollow">cachepy</a>; It allows to set up ttl and\or the number of calls for cached functio... | 0 | 2016-04-26T06:36:31Z | [
"python",
"caching",
"decorator"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,320 | <pre><code>raise ValueError('invalid gender %r' % gender)
</code></pre>
| 23 | 2009-05-02T18:22:36Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,324 | <p>This depends on how sure you are of the gender being either <code>'m'</code> or <code>'f'</code>.</p>
<p>If you're absolutely certain, use <code>if...else</code> instead of <code>if...elif...else</code>. Just makes it easier for everyone.</p>
<p>If there's any chance of malformed data, however, you should probably... | 7 | 2009-05-02T18:23:00Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,327 | <p>You could raise an exception:</p>
<pre><code>raise ValueError("Unexpected gender; expected 'm' or 'f', got %s" % gender)
</code></pre>
<p>or use an assert False if you expect the database to return only 'm' or 'f':</p>
<pre><code>assert False, "Unexpected gender; expected 'm' or 'f', got %s" % gender
</code></pre... | 7 | 2009-05-02T18:24:22Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,518 | <p>I actually think that there's a place for this.</p>
<pre><code>class SeriousDesignError( Exception ):
pass
</code></pre>
<p>So you can do this</p>
<pre><code>if number % 2 == 0:
result = "Even"
elif number % 2 == 1:
result = "Odd"
else:
raise SeriousDesignError()
</code></pre>
<p>I think this is ... | 4 | 2009-05-02T20:11:43Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,886 | <p>I sometimes do:</p>
<pre><code>if gender == 'm':
greeting = 'Mr.'
else:
assert gender == 'f'
greeting = 'Ms.'
</code></pre>
<p>I think this does a good job of telling a reader of the code that there are only (in this case) two possibilities, and what they are. Although you could make a case for raisin... | 2 | 2009-05-02T23:26:18Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 815,935 | <p>It depends exactly what you want the error to signal, but I would use a dictionary in this case:</p>
<pre><code>greetings={'m':'Mr.', 'f':'Ms.'}
gender = readFromDB(...) # either 'm' or 'f'
greeting=greetings[gender]
</code></pre>
<p>If gender is neither m nor f, this will raise a KeyError containing the unexpecte... | 3 | 2009-05-02T23:51:45Z | [
"python"
] |
How to designate unreachable python code | 815,310 | <p>What's the pythonic way to designate unreachable code in python as in:</p>
<pre><code>gender = readFromDB(...) # either 'm' or 'f'
if gender == 'm':
greeting = 'Mr.'
elif gender == 'f':
greeting = 'Ms.'
else:
# What should this line say?
</code></pre>
| 8 | 2009-05-02T18:16:06Z | 10,038,699 | <p>Until now, I've usually used a variation on John Fouhy's answer -- but this is not exactly correct, as Ethan points out:</p>
<pre><code>assert gender in ('m', 'f')
if gender == 'm':
greeting = 'Mr.'
else:
greeting = 'Ms.'
</code></pre>
<p>The main problem with using an assert is that if anyone runs your co... | 3 | 2012-04-06T03:11:54Z | [
"python"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 815,315 | <p>Python's shelve module? <a href="http://docs.python.org/library/shelve.html" rel="nofollow">http://docs.python.org/library/shelve.html</a></p>
| 0 | 2009-05-02T18:20:51Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 815,317 | <p>Do you really need to hash at all? Twitter messages are short enough (and disk space cheap enough) that it may be better to just store the whole message, rather than eating up clock cycles to hash it.</p>
| 6 | 2009-05-02T18:21:12Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 815,321 | <p>Well, tweets are only 140 characters long, so you could even store the entire tweet in the database...</p>
<p>but if you really want to "hash" them somehow, a simple way would be to just take the sum of the ASCII values of all the characters in the tweet:</p>
<pre><code>sum(ord(c) for c in tweet)
</code></pre>
<p... | 1 | 2009-05-02T18:22:41Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 815,381 | <p>I echo Chris' comment about not using a hash at all (your database engine can hopefully index 140-character fields efficiently).</p>
<p>If you did want to use a hash, MD5 would be my first choice as well (16 bytes), followed by SHA-1 (20 bytes).</p>
<p>Whatever you do, don't use sum-of-characters. I can't immedia... | 2 | 2009-05-02T18:52:58Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 815,390 | <p>I am not familiar with Python (sorry, Ruby guy typing here) however you could try a few things. </p>
<p><strong>Assumptions:</strong>
You will likely be storing hundreds of thousands of Tweets over time, so comparing one hash against "every record" in the table will be inefficient. Also, RTs are not always carbon ... | 4 | 2009-05-02T18:57:56Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 817,731 | <p>You are trying to hash a string right? Builtin types can be hashed right away, just do <code>hash("some string")</code> and you get some int. Its the same function python uses for dictonarys, so it is probably the best choice.</p>
| 0 | 2009-05-03T18:59:30Z | [
"python",
"hash",
"twitter",
"md5"
] |
Detecting Retweets using computationally inexpensive Python hashing algorithms | 815,313 | <p>In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database.</p>
<p>What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way.... | 2 | 2009-05-02T18:17:58Z | 1,139,680 | <p>There are a few issues here. First, RT's are not always identical. Some people add a comment. Others change the URL for tracking. Others add in the person that they are RT'ing (which may or may not be the originator).</p>
<p>So if you are going to hash the tweet, you need to boil it down to the meat of the twee... | 2 | 2009-07-16T19:07:47Z | [
"python",
"hash",
"twitter",
"md5"
] |
Python imports from crossreferencing packages | 815,367 | <p>Currently I'm trying to write my first Python library and I've encountered the following problem:</p>
<p>I have the following import in my package myapp.factories:</p>
<pre><code>from myapp.models import *
</code></pre>
<p>And the following in my package myapp.models:</p>
<pre><code>from myapp.factories import *... | 0 | 2009-05-02T18:46:15Z | 815,374 | <p>"inside one model I also need one of the factories" - just import that factory where you need it:</p>
<pre><code>class SomeModel:
def some_method(self):
from myapp.factories import SomeFactory
SomeFactory().do_something()
</code></pre>
| 5 | 2009-05-02T18:49:18Z | [
"python"
] |
C# Web Server: Implementing a Dynamic Language | 815,446 | <p>I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following:</p>
<ul>
<li>ASP.NET</li>
<li>PHP</li>
<li>Python</li>
</ul>
<p>I'd pref... | 0 | 2009-05-02T19:25:41Z | 815,449 | <p>ASP.NET will surely be the easiest as you can use all the built in classes. Essentially you don't need to build it, you just hook it up to the Web server (I don't know if we can count it as <em>writing</em> ASP.NET though ;) )</p>
<p>You might want to look at <a href="http://blogs.msdn.com/dmitryr/archive/2006/03/0... | 1 | 2009-05-02T19:26:54Z | [
"php",
"asp.net",
"python",
"webserver"
] |
C# Web Server: Implementing a Dynamic Language | 815,446 | <p>I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following:</p>
<ul>
<li>ASP.NET</li>
<li>PHP</li>
<li>Python</li>
</ul>
<p>I'd pref... | 0 | 2009-05-02T19:25:41Z | 815,457 | <p>Have you considered boo? It has a very configurable compiler and there are some good OSS examples out there (for example the brail view engine for Monorail & ASP.NET MVC).</p>
| 1 | 2009-05-02T19:31:51Z | [
"php",
"asp.net",
"python",
"webserver"
] |
C# Web Server: Implementing a Dynamic Language | 815,446 | <p>I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following:</p>
<ul>
<li>ASP.NET</li>
<li>PHP</li>
<li>Python</li>
</ul>
<p>I'd pref... | 0 | 2009-05-02T19:25:41Z | 815,491 | <p>Perhaps you should take a look at <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython" rel="nofollow">IronPython</a>.</p>
| 0 | 2009-05-02T19:56:27Z | [
"php",
"asp.net",
"python",
"webserver"
] |
C# Web Server: Implementing a Dynamic Language | 815,446 | <p>I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following:</p>
<ul>
<li>ASP.NET</li>
<li>PHP</li>
<li>Python</li>
</ul>
<p>I'd pref... | 0 | 2009-05-02T19:25:41Z | 815,511 | <p>Well it would appear you are doing this as a learning experience, after all Microsoft already provides a web server for Windows (IIS).</p>
<p>Similary PHP has already been ported to <a href="http://www.php.net/downloads.php" rel="nofollow">Windows</a>, you could use that port directly. SImilary you could use it as ... | 0 | 2009-05-02T20:09:30Z | [
"php",
"asp.net",
"python",
"webserver"
] |
C# Web Server: Implementing a Dynamic Language | 815,446 | <p>I've just finished writing a web server in C#. Its pretty basic and only serves static content like html, xml, and images at the moment. I would like to implement a dynamic language, however. I'm trying to choose between one of the following:</p>
<ul>
<li>ASP.NET</li>
<li>PHP</li>
<li>Python</li>
</ul>
<p>I'd pref... | 0 | 2009-05-02T19:25:41Z | 815,550 | <p>If you implement a cgi interface, you could use any kind of backend language. If you want to get fancy, you could consider looking into fastcgi.</p>
| 1 | 2009-05-02T20:28:46Z | [
"php",
"asp.net",
"python",
"webserver"
] |
How to use subversion Ctypes Python Bindings? | 815,530 | <p>Subversion 1.6 introduce something that is called 'Ctypes Python Binding', but it is not documented. Is it any information available what this bindings are and how to use it? For example, i have a fresh windows XP and want to control SVN repository using subversiion 1.6 and this mysterious python bindings. What exac... | 4 | 2009-05-02T20:18:33Z | 815,568 | <p>The whole point of ctypes is that you shouldn't need to have to compile anything anywhere. That said, the readme for the bindings mentions some dependencies and a build step.</p>
<p>The bindings can be found in the Subversion source distribution at least, in <code>subversion/bindings/ctypes-python/</code>, with a d... | 0 | 2009-05-02T20:41:22Z | [
"python",
"svn"
] |
How to use subversion Ctypes Python Bindings? | 815,530 | <p>Subversion 1.6 introduce something that is called 'Ctypes Python Binding', but it is not documented. Is it any information available what this bindings are and how to use it? For example, i have a fresh windows XP and want to control SVN repository using subversiion 1.6 and this mysterious python bindings. What exac... | 4 | 2009-05-02T20:18:33Z | 815,711 | <p>I looked into the python binding for subversion, but in the end I found it to be simpler to just invoke svn.exe like this:</p>
<pre><code>(stdout, stderr, err) = execute('svn export "%s" "%s"' \
% (exportURL, workingCopyFolder))
</code></pre>
<p>where <code>execute</code> is a function like this:</p>
<pre><cod... | -1 | 2009-05-02T21:54:00Z | [
"python",
"svn"
] |
How to use subversion Ctypes Python Bindings? | 815,530 | <p>Subversion 1.6 introduce something that is called 'Ctypes Python Binding', but it is not documented. Is it any information available what this bindings are and how to use it? For example, i have a fresh windows XP and want to control SVN repository using subversiion 1.6 and this mysterious python bindings. What exac... | 4 | 2009-05-02T20:18:33Z | 841,995 | <p>You need the Subversion source distribution, Python (>= 2.5), and <a href="http://code.google.com/p/ctypesgen/" rel="nofollow">ctypesgen</a>.</p>
<p>Instructions for building the ctypes bindings are <a href="http://svn.apache.org/repos/asf/subversion/trunk/subversion/bindings/ctypes-python/README" rel="nofollow">he... | 1 | 2009-05-08T21:54:54Z | [
"python",
"svn"
] |
How do you remove html tags using Universal Feed Parser? | 815,606 | <p>The documentation lists the tags that are allowed/removed by default:</p>
<p><a href="http://www.feedparser.org/docs/html-sanitization.html" rel="nofollow">http://www.feedparser.org/docs/html-sanitization.html</a></p>
<p>But it doesn't say anything about how you can specify which additional tags you want removed.<... | 3 | 2009-05-02T21:01:15Z | 815,681 | <p>i took a quick look over the code and i don't think there is a way to overwrite them directly. But you can overwrite <code>feedparser._HTMLSanitizer.acceptable_elements</code>, the list of tags that wont get removed before doing <code>feedparser.parse</code></p>
| 5 | 2009-05-02T21:34:41Z | [
"python",
"django",
"feeds",
"parsing"
] |
callable as instancemethod? | 815,947 | <p>Let's say we've got a metaclass <code>CallableWrappingMeta</code> which walks the body of a new class, wrapping its methods with a class, <code>InstanceMethodWrapper</code>:</p>
<pre><code>import types
class CallableWrappingMeta(type):
def __new__(mcls, name, bases, cls_dict):
for k, v in cls_dict.iter... | 2 | 2009-05-02T23:58:32Z | 815,982 | <p><strong>Edit</strong>: I lie yet again. The <code>__?attr__</code> attributes on functions are readonly, but apparently do not always throw an <code>AttributeException</code> exception when you assign? I dunno. Back to square one!</p>
<p><strong>Edit</strong>: This doesn't actually solve the problem, as the wrappin... | 0 | 2009-05-03T00:26:02Z | [
"python",
"metaclass"
] |
callable as instancemethod? | 815,947 | <p>Let's say we've got a metaclass <code>CallableWrappingMeta</code> which walks the body of a new class, wrapping its methods with a class, <code>InstanceMethodWrapper</code>:</p>
<pre><code>import types
class CallableWrappingMeta(type):
def __new__(mcls, name, bases, cls_dict):
for k, v in cls_dict.iter... | 2 | 2009-05-02T23:58:32Z | 816,072 | <p>I'm guessing you are trying to make a metaclass that wraps every method in the class with a custom function.</p>
<p>Here is my version which I think is a little bit less oblique.</p>
<pre><code>import types
class CallableWrappingMeta(type):
def __new__(mcls, name, bases, cls_dict):
instance = type.__n... | 0 | 2009-05-03T01:41:18Z | [
"python",
"metaclass"
] |
callable as instancemethod? | 815,947 | <p>Let's say we've got a metaclass <code>CallableWrappingMeta</code> which walks the body of a new class, wrapping its methods with a class, <code>InstanceMethodWrapper</code>:</p>
<pre><code>import types
class CallableWrappingMeta(type):
def __new__(mcls, name, bases, cls_dict):
for k, v in cls_dict.iter... | 2 | 2009-05-02T23:58:32Z | 817,108 | <p>I think you need to be more specific about your problem. The original question talks about wrapping a function, but your subsequent answer seems to talk about preserving function attributes, which seems to be a new factor. If you spelled out your design goals more clearly, it might be easier to answer your questio... | 0 | 2009-05-03T13:53:23Z | [
"python",
"metaclass"
] |
callable as instancemethod? | 815,947 | <p>Let's say we've got a metaclass <code>CallableWrappingMeta</code> which walks the body of a new class, wrapping its methods with a class, <code>InstanceMethodWrapper</code>:</p>
<pre><code>import types
class CallableWrappingMeta(type):
def __new__(mcls, name, bases, cls_dict):
for k, v in cls_dict.iter... | 2 | 2009-05-02T23:58:32Z | 817,815 | <p>Just enrich you <code>InstanceMethodWrapper</code> class with a <code>__get__</code> (which can perfectly well just <code>return self</code>) -- that is, make that class into a <em>descriptor</em> type, so that its instances are descriptor objects. See <a href="http://users.rcn.com/python/download/Descriptor.htm" r... | 3 | 2009-05-03T19:37:57Z | [
"python",
"metaclass"
] |
Python, SimPy: How to generate a value from a triangular probability distribution? | 815,969 | <p>I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this t... | 6 | 2009-05-03T00:14:53Z | 815,994 | <p>If you download the NumPy package, it has a function numpy.random.triangular(left, mode, right[, size]) that does exactly what you are looking for.</p>
| 6 | 2009-05-03T00:30:52Z | [
"python",
"distribution",
"probability",
"simpy"
] |
Python, SimPy: How to generate a value from a triangular probability distribution? | 815,969 | <p>I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this t... | 6 | 2009-05-03T00:14:53Z | 816,185 | <p>Since, I was checking random's documentation from Python 2.4 I missed this:</p>
<p><strong><em>random.triangular(low, high, mode)</strong>¶
Return a random floating point number N such that low <= N <= high and with the specified mode between those bounds. The low and high bounds default to zero and one.... | 3 | 2009-05-03T02:55:44Z | [
"python",
"distribution",
"probability",
"simpy"
] |
Python, SimPy: How to generate a value from a triangular probability distribution? | 815,969 | <p>I want to run a simulation that uses as parameter a value generated from a triangular probability distribution with lower limit A, mode B and and upper limit C. How can I generate this value in Python? Is there something as simple as expovariate(lambda) (from random) for this distribution or do I have to code this t... | 6 | 2009-05-03T00:14:53Z | 923,105 | <p>Let's say that your distribution wasn't handled by NumPy or the Python Standard Library.</p>
<p>In situations where performance is not very important, rejection sampling is a useful hack for getting draws from a distribution you don't have using one you do have.</p>
<p>For your triangular distribution, you could d... | 2 | 2009-05-28T20:49:34Z | [
"python",
"distribution",
"probability",
"simpy"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 816,115 | <p>get <a href="http://matplotlib.sourceforge.net" rel="nofollow">matplotlib</a></p>
| 16 | 2009-05-03T02:14:07Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 816,325 | <p>I have had reasonable success with Python applications generating SVG with animation features embedded, but this was with a smaller set of elements than what you probably have. For example, if your data is about a seismic event, show a circle that shows up when the event happened and grows in size matching the magn... | 0 | 2009-05-03T04:23:53Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 816,381 | <p>You might want to look at <a href="http://pyqwt.sourceforge.net/" rel="nofollow">PyQwt</a>. It's a plotting library which works with Qt/PyQt. </p>
<p>Several of the PyQwt examples (in the qt4examples directory) show how to create "moving" / dynamically changing plots -- look at <code>CPUplot.py</code>, <code>MapDem... | 0 | 2009-05-03T05:06:05Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 817,418 | <p>I'd try rpy. All the power of R, from within python.
<a href="http://rpy.sourceforge.net/" rel="nofollow">http://rpy.sourceforge.net/</a></p>
<p>rpy is awesome.</p>
<p>Check out the CRAN library for animations,
<a href="http://cran.r-project.org/web/packages/animation/index.html" rel="nofollow">http://cran.r-proje... | 4 | 2009-05-03T16:18:16Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 817,465 | <p>Enthought's <a href="http://code.enthought.com/chaco/" rel="nofollow">Chaco</a> is designed for interactive/updating plots. the api and such takes a little while to get use to, but once you're there it's a fantastic framework to work with.</p>
| 2 | 2009-05-03T16:46:34Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 936,193 | <p>If you are interested in scientific plotting using Python then have a look at Mlab: <a href="http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html" rel="nofollow">http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html</a></p>
<p>It allows you to plot 2d / 3d and ... | 3 | 2009-06-01T18:56:25Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
Scientific Plotting in Python | 816,086 | <p>I have a large data set of tuples containing (time of event, latitude, longitude) that I need to visualize. I was hoping to generate a 'movie'-like xy-plot, but was wondering if anyone has a better idea or if there is an easy way to do this in Python?</p>
<p>Thanks in advance for the help,
--Leo</p>
| 8 | 2009-05-03T01:53:32Z | 936,552 | <p>The easiest option is matplotlib. Two particular solutions that might work for you are:</p>
<p>1) You can generate a series of plots, each a snapshot at a given time. These can either be displayed as a dynamic plot in matplotlib, where the axes stay the same and the data moves around; or you can save the series o... | 8 | 2009-06-01T20:17:06Z | [
"python",
"visualization",
"plot",
"scientific-computing"
] |
What's a good way to mix RSS feeds using Python? | 816,118 | <p>SimplePie lets you merge feeds together:</p>
<p><a href="http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date" rel="nofollow">http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date</a></p>
<p>Is there anything like this in the Python world? The Universal Feed Parser documentatio... | 1 | 2009-05-03T02:15:47Z | 816,216 | <p><a href="http://github.com/dustin/snippets/blob/master/python/net/http/combiner.py" rel="nofollow">This</a> may be a good start for you. I wrote it a long time ago for one very specific combination, but I don't think I wrote it <em>too</em> specifically for my needs.</p>
| 2 | 2009-05-03T03:12:42Z | [
"python",
"django",
"rss",
"feeds",
"parsing"
] |
What's a good way to mix RSS feeds using Python? | 816,118 | <p>SimplePie lets you merge feeds together:</p>
<p><a href="http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date" rel="nofollow">http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date</a></p>
<p>Is there anything like this in the Python world? The Universal Feed Parser documentatio... | 1 | 2009-05-03T02:15:47Z | 816,268 | <p> <a href="http://www.planetplanet.org/" rel="nofollow">Planet is a feed aggregator written in Python. Its development is basically dead, but the code lives on in several forks, including Planet Venus</a>.</p>
| 1 | 2009-05-03T03:34:07Z | [
"python",
"django",
"rss",
"feeds",
"parsing"
] |
What's a good way to mix RSS feeds using Python? | 816,118 | <p>SimplePie lets you merge feeds together:</p>
<p><a href="http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date" rel="nofollow">http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date</a></p>
<p>Is there anything like this in the Python world? The Universal Feed Parser documentatio... | 1 | 2009-05-03T02:15:47Z | 816,553 | <p>I'm using Yahoo pipes for that task. It's a set a very powerful tools. I havo pipes join feeds based on certain criteria, and have it generate a compliant rss feed that i then process with universal feed parser.</p>
| 0 | 2009-05-03T08:04:19Z | [
"python",
"django",
"rss",
"feeds",
"parsing"
] |
What's a good way to mix RSS feeds using Python? | 816,118 | <p>SimplePie lets you merge feeds together:</p>
<p><a href="http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date" rel="nofollow">http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date</a></p>
<p>Is there anything like this in the Python world? The Universal Feed Parser documentatio... | 1 | 2009-05-03T02:15:47Z | 817,637 | <p><strong><a href="http://atomisator.ziade.org/" rel="nofollow">Atomisator</a></strong> is a data aggregator framework. Its purpose is to provide an engine to build any kind of data by merging several sources of data. It was developed as an example application in the book Expert Python Programming. You can use differe... | 1 | 2009-05-03T18:08:20Z | [
"python",
"django",
"rss",
"feeds",
"parsing"
] |
What is wrong with this SimPy installation? | 816,156 | <p>Alright, I have tried a bunch of times the </p>
<pre><code>python setup.py install
</code></pre>
<p>command from my command prompt, and this is what I'm getting:</p>
<p><a href="http://yfrog.com/5ofallasimpyp" rel="nofollow">SCREEN</a></p>
<p>And when trying this:</p>
<pre><code>from SimPy.Simulation import *
<... | 0 | 2009-05-03T02:36:53Z | 816,167 | <p>Not every module supports python 3 - in fact, 90% or more of the modules are for 2.x now.</p>
<p>you should use 2.5 or 2.6 for this module, or find a simpy that is compatible with 3.0.</p>
<p>you can also run the 2->3 upgrade script to modify your simpy source, but I don't suggest doing that.</p>
| 2 | 2009-05-03T02:41:19Z | [
"python",
"windows",
"installation",
"simpy"
] |
What is wrong with this SimPy installation? | 816,156 | <p>Alright, I have tried a bunch of times the </p>
<pre><code>python setup.py install
</code></pre>
<p>command from my command prompt, and this is what I'm getting:</p>
<p><a href="http://yfrog.com/5ofallasimpyp" rel="nofollow">SCREEN</a></p>
<p>And when trying this:</p>
<pre><code>from SimPy.Simulation import *
<... | 0 | 2009-05-03T02:36:53Z | 2,946,419 | <p>I have a similar error, and I Installed python 2.6.4, so I don't think you can solve your problem using an older version of python.</p>
<pre><code>alumno@ubuntu:/usr/local/SimPy/SimPy$ python carro.py
Traceback (most recent call last):
File "carro.py", line 2, in <module>
from SimPy.Simulation import *
... | 0 | 2010-05-31T23:18:22Z | [
"python",
"windows",
"installation",
"simpy"
] |
What is wrong with this SimPy installation? | 816,156 | <p>Alright, I have tried a bunch of times the </p>
<pre><code>python setup.py install
</code></pre>
<p>command from my command prompt, and this is what I'm getting:</p>
<p><a href="http://yfrog.com/5ofallasimpyp" rel="nofollow">SCREEN</a></p>
<p>And when trying this:</p>
<pre><code>from SimPy.Simulation import *
<... | 0 | 2009-05-03T02:36:53Z | 22,529,526 | <p>Refer point 4 of:
<a href="http://pythonhosted.org/SimPy/Manuals/INSTALLATION.html" rel="nofollow">http://pythonhosted.org/SimPy/Manuals/INSTALLATION.html</a>
for a workaround. It worked for me.</p>
<p>simpy package does not seem to have same classes as SimPy by using pip install SimPy command, simpy gets installe... | 0 | 2014-03-20T10:07:02Z | [
"python",
"windows",
"installation",
"simpy"
] |
What is wrong with this SimPy installation? | 816,156 | <p>Alright, I have tried a bunch of times the </p>
<pre><code>python setup.py install
</code></pre>
<p>command from my command prompt, and this is what I'm getting:</p>
<p><a href="http://yfrog.com/5ofallasimpyp" rel="nofollow">SCREEN</a></p>
<p>And when trying this:</p>
<pre><code>from SimPy.Simulation import *
<... | 0 | 2009-05-03T02:36:53Z | 25,465,903 | <p>There is nothing wrong with your Python installation. SimPy 1 and SimPy 2 use remarkably different syntax from SimPy 3, which is the version that you have installed - and the one which is widely available. The old tutorials are all written in view of the old SimPy versions. Checkout this page...</p>
<p><a href="htt... | 0 | 2014-08-23T20:07:07Z | [
"python",
"windows",
"installation",
"simpy"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,217 | <p>I suspect the basic reason is a combination of security and reliability. You don't want someone to be easily able to hack the phone, and you want to have some control over what's being installed.</p>
| 0 | 2009-05-03T03:13:13Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,219 | <p>Jailbroken iPhones can have python installed, and I actually use python very frequently on mine. </p>
| 1 | 2009-05-03T03:15:14Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,225 | <p>I think that performance concerns may be part of, but not all of, the reason. Mobile devices do not have very powerful hardware to work with.</p>
<p>I am partly unsure about this, though.</p>
| 1 | 2009-05-03T03:17:37Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,228 | <p>Memory is also a significant factor. It's easy to eat memory in Python, unfortunately.</p>
| 0 | 2009-05-03T03:20:08Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,233 | <p>One of the most pressing matters is garbage collection. Garbage collection often times introduce unpredictable pauses in embedded machines which sometimes need real time performance.</p>
<p>This is why there is a Java Micro Edition which has a different garbage collector which reduces pauses in exchange for a slowe... | 1 | 2009-05-03T03:21:07Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,248 | <p>In general it's all of these things. Memory, speed, and probably most importantly programmer familiarity. Apple has a huge investment in Objective C, Java is known by basically everyone, and C# is very popular as well. If you're trying for mass programmer appeal it makes sense to start with something popular, even i... | 13 | 2009-05-03T03:26:56Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 816,266 | <p>There are many reasons. Among them:</p>
<ul>
<li>business reasons, such as software lock-in strategies,</li>
<li>efficiency: dynamic languages are usually perceived to be slower (and in some cases really are slower, or at least provide a limit to the amount of optimsation you can do. On a mobile device, optimising ... | 0 | 2009-05-03T03:33:22Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 817,365 | <p>Contrary to the premise of the question: One of the first mainstream mobile devices was the <a href="http://en.wikipedia.org/wiki/Apple%5FNewton" rel="nofollow">Newton</a>, which was designed to use a specialized dynamic language called <a href="http://en.wikipedia.org/wiki/NewtonScript" rel="nofollow">NewtonScript<... | 2 | 2009-05-03T15:54:28Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 817,560 | <p>webOS -- the new OS from Palm, which will debut on the Pre -- has you write apps against a webkit runtime in JavaScript. Time will tell how successful it is, but I suspect it will not be the first to go down this path. As mobile devices become more powerful, you'll see dynamic languages become more prevalent.</p>
| 0 | 2009-05-03T17:35:38Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 817,612 | <p>The situation for multiple languages on mobile devices is better than the question implies. Java (in its J2ME incarnation) is available these days even in fairly cheap phones. Symbian S60 officially supports <a href="http://opensource.nokia.com/projects/pythonfors60/" rel="nofollow">Python</a>, and <a href="http:/... | 2 | 2009-05-03T17:59:39Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 1,077,282 | <p>My Palm has a <a href="http://en.wikipedia.org/wiki/Plua" rel="nofollow">Lua implementation</a> that allows you to do reasonable GUIs, a fairly useless old Python 1.5, a <a href="http://www.quartus.net/products/forth/" rel="nofollow">superb Forth</a> (which allows you to produce compiled apps) and a <a href="http://... | 0 | 2009-07-02T23:59:40Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 1,077,315 | <p>There is a linux distribution for OpenMoko Freerunner called SHR. Most of its settings and framework code is written in python and... well, it isn't very fast. It is bearable, but it was planned from the beginning to rewrite it in Vala.</p>
<p>On the other side, my few smallish apps work fast enough (with the only ... | 0 | 2009-07-03T00:12:49Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
Python/Ruby as mobile OS | 816,212 | <p>I was wondering why smartphone/mobile device OSs are not written to allow dynamic languages as the language of choice? iPhone uses Objective-C, Google Android uses Java, Windows Mobile uses any manner of .NET language.</p>
<p>What would be the reasoning behind a mobile OS being written in Python, Ruby, or any othe... | 10 | 2009-05-03T03:09:58Z | 1,512,031 | <p>Rhomobile's open source <a href="http://rhomobile.com/products/rhodes" rel="nofollow">Rhodes</a> framework offers this today. The world's first Ruby implementations for all smartphones.</p>
| 0 | 2009-10-02T22:08:35Z | [
"python",
"ruby",
"mobile",
"operating-system",
"dynamic-languages"
] |
How to unescape apostrophes and such in Python? | 816,272 | <p>I have a string with symbols like this:</p>
<pre><code>&#39;
</code></pre>
<p>That's an apostrophe apparently.</p>
<p>I tried saxutils.unescape() without any luck and tried urllib.unquote()</p>
<p>How can I decode this? Thanks!</p>
| 7 | 2009-05-03T03:37:49Z | 816,281 | <p>I am not sure about the & or the #, but here is some code for decoding:</p>
<pre><code>>>>chr(39)
"'"
>>>ord("'")
39
</code></pre>
| -2 | 2009-05-03T03:45:19Z | [
"python",
"html",
"django",
"html-entities"
] |
How to unescape apostrophes and such in Python? | 816,272 | <p>I have a string with symbols like this:</p>
<pre><code>&#39;
</code></pre>
<p>That's an apostrophe apparently.</p>
<p>I tried saxutils.unescape() without any luck and tried urllib.unquote()</p>
<p>How can I decode this? Thanks!</p>
| 7 | 2009-05-03T03:37:49Z | 816,297 | <p>Check out <a href="http://stackoverflow.com/questions/275174/">this question</a>. What you're looking for is "html entity decoding". Typically, you'll find a function named something like "htmldecode" that will do what you want. Both Django and Cheetah provide such functions as does BeautifulSoup.</p>
<p>The other ... | 2 | 2009-05-03T03:54:01Z | [
"python",
"html",
"django",
"html-entities"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.