title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python C-API Object Allocationâ | 573,275 | <p>I want to use the new and delete operators for creating and destroying my objects.</p>
<p>The problem is python seems to break it into several stages. tp_new, tp_init and tp_alloc for creation and tp_del, tp_free and tp_dealloc for destruction. However c++ just has new which allocates and fully constructs the objec... | 5 | 2009-02-21T16:01:45Z | 573,424 | <p>The documentation for these is at <a href="http://docs.python.org/3.0/c-api/typeobj.html" rel="nofollow">http://docs.python.org/3.0/c-api/typeobj.html</a> and
<a href="http://docs.python.org/3.0/extending/newtypes.html" rel="nofollow">http://docs.python.org/3.0/extending/newtypes.html</a> describes how to make your... | 10 | 2009-02-21T17:25:29Z | [
"c++",
"python",
"c",
"python-3.x",
"python-c-api"
] |
Any way to create a NumPy matrix with C API? | 573,487 | <p>I read the documentation on NumPy C API I could find, but still wasn't able to find out whether there is a possibility to construct a matrix object with C API â not a two-dimensional array. The function is intended for work with math matrices, and I don't want strange results if the user calls matrix multiplicatio... | 2 | 2009-02-21T18:12:07Z | 573,575 | <p><code>numpy.matrix</code> is an ordinary class defined in <a href="http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/core/defmatrix.py#L154" rel="nofollow">numpy/core/defmatrix.py</a>. You can construct it using C API as any other instance of user-defined class in Python.</p>
| 3 | 2009-02-21T19:06:20Z | [
"python",
"numpy",
"python-c-api"
] |
Any way to create a NumPy matrix with C API? | 573,487 | <p>I read the documentation on NumPy C API I could find, but still wasn't able to find out whether there is a possibility to construct a matrix object with C API â not a two-dimensional array. The function is intended for work with math matrices, and I don't want strange results if the user calls matrix multiplicatio... | 2 | 2009-02-21T18:12:07Z | 573,576 | <p>You can call any python callable with the <code>PyObject_Call*</code> functions.</p>
<pre><code>PyObject *numpy = PyImport_ImportModule("numpy");
PyObject *numpy_matrix = PyObject_GetAttrString(numpy, "matrix");
PyObject *my_matrix = PyObject_CallFunction(numpy_matrix, "(s)", "0 0; 0 0");
</code></pre>
<p>This wil... | 6 | 2009-02-21T19:07:29Z | [
"python",
"numpy",
"python-c-api"
] |
Python serialize lexical closures? | 573,569 | <p>Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example:</p>
<pre><code>def foo(bar, baz) :
def closure(wal... | 18 | 2009-02-21T19:03:12Z | 574,789 | <p>If you simply use a class with a <code>__call__</code> method to begin with, it should all work smoothly with <code>pickle</code>.</p>
<pre><code>class foo(object):
def __init__(self, bar, baz):
self.baz = baz
def __call__(self,waldo):
return self.baz * waldo
</code></pre>
<p>On the other h... | 12 | 2009-02-22T11:42:04Z | [
"python",
"serialization",
"closures"
] |
Python serialize lexical closures? | 573,569 | <p>Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example:</p>
<pre><code>def foo(bar, baz) :
def closure(wal... | 18 | 2009-02-21T19:03:12Z | 584,138 | <p><a href="http://code.activestate.com/recipes/500261/" rel="nofollow">Recipe 500261: Named Tuples</a> contains a function that defines a class on-the-fly. And this class supports pickling.</p>
<p>Here's the essence:</p>
<pre><code>result.__module__ = _sys._getframe(1).f_globals.get('__name__', '__main__')
</code></... | 0 | 2009-02-24T23:38:42Z | [
"python",
"serialization",
"closures"
] |
Python serialize lexical closures? | 573,569 | <p>Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example:</p>
<pre><code>def foo(bar, baz) :
def closure(wal... | 18 | 2009-02-21T19:03:12Z | 704,118 | <p>Yes! I got it (at least I think) -- that is, the more generic problem of pickling a function. Python is so wonderful :), I found out most of it though the dir() function and a couple of web searches. Also wonderful to have it [hopefully] solved, I needed it also.</p>
<p>I haven't done a lot of testing on how robust... | 1 | 2009-04-01T05:01:25Z | [
"python",
"serialization",
"closures"
] |
Python serialize lexical closures? | 573,569 | <p>Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example:</p>
<pre><code>def foo(bar, baz) :
def closure(wal... | 18 | 2009-02-21T19:03:12Z | 2,477,448 | <pre><code>#!python
import marshal, pickle, new
def dump_func(f):
if f.func_closure:
closure = tuple(c.cell_contents for c in f.func_closure)
else:
closure = None
return marshal.dumps(f.func_code), f.func_defaults, closure
def load_func(code, defaults, closure, globs):
if closure is ... | 0 | 2010-03-19T13:04:14Z | [
"python",
"serialization",
"closures"
] |
Python serialize lexical closures? | 573,569 | <p>Is there a way to serialize a lexical closure in Python using the standard library? pickle and marshal appear not to work with lexical closures. I don't really care about the details of binary vs. string serialization, etc., it just has to work. For example:</p>
<pre><code>def foo(bar, baz) :
def closure(wal... | 18 | 2009-02-21T19:03:12Z | 4,124,868 | <p>PiCloud has released an open-source (LGPL) pickler which can handle function closure and a whole lot more useful stuff. It can be used independently of their cloud computing infrastructure - it's just a normal pickler. The whole shebang is documented <a href="http://docs.picloud.com/" rel="nofollow">here</a>, and y... | 16 | 2010-11-08T14:46:46Z | [
"python",
"serialization",
"closures"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 573,656 | <p>If you're using a standard POSIX OS, you use <a href="http://linux.die.net/man/8/cron" rel="nofollow">cron</a>.</p>
<p>If you're using Windows, you use <a href="http://technet.microsoft.com/en-us/library/cc755618.aspx" rel="nofollow">at</a>.</p>
<p>Write a Django management command to </p>
<ol>
<li><p>Figure out ... | 24 | 2009-02-21T20:04:40Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 573,659 | <p>One solution that I have employed is to do this:</p>
<p>1) Create a <a href="http://docs.djangoproject.com/en/dev/howto/custom-management-commands/#howto-custom-management-commands">custom management command</a>, e.g. </p>
<pre><code>python manage.py my_cool_command
</code></pre>
<p>2) Use <code>cron</code> (on L... | 219 | 2009-02-21T20:06:38Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 573,685 | <p>Look at Django Poor Man's Cron which is a Django app that makes use of spambots, search engine indexing robots and alike to run scheduled tasks in approximately regular intervals</p>
<p>See: <a href="http://code.google.com/p/django-poormanscron/">http://code.google.com/p/django-poormanscron/</a></p>
| 12 | 2009-02-21T20:29:47Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 574,245 | <p>I personally use cron, but the <a href="http://code.google.com/p/django-command-extensions/wiki/JobsScheduling">Jobs Scheduling</a> parts of <a href="https://github.com/django-extensions/django-extensions">django-extensions</a> looks interesting.</p>
| 8 | 2009-02-22T03:18:07Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 621,538 | <p>Interesting new pluggable Django app: <a href="http://code.google.com/p/django-chronograph/">django-chronograph</a></p>
<p>You only have to add one cron entry which acts as a timer, and you have a very nice Django admin interface into the scripts to run.</p>
| 20 | 2009-03-07T08:32:30Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 1,057,920 | <p><a href="http://celeryproject.org/">Celery</a> is a distributed task queue, built on AMQP (RabbitMQ). It also handles periodic tasks in a cron-like fashion. Depending on your app, it might be worth a gander.</p>
| 92 | 2009-06-29T11:56:47Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 2,024,459 | <p>Put the following at the top of your cron.py file:</p>
<pre><code>#!/usr/bin/python
import os, sys
sys.path.append('/path/to/') # the parent directory of the project
sys.path.append('/path/to/project') # these lines only needed if not on path
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproj.settings'
# imports and c... | 5 | 2010-01-07T23:26:10Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 6,025,832 | <p>after the part of code,I can write anything just like my views.py :)</p>
<pre><code>#######################################
import os,sys
sys.path.append('/home/administrator/development/store')
os.environ['DJANGO_SETTINGS_MODULE']='store.settings'
from django.core.management impor setup_environ
from store import s... | 4 | 2011-05-17T03:09:13Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 7,287,891 | <p>I had something similar with your problem today.</p>
<p>I didn't wanted to have it handled by the server trhough cron (and most of the libs were just cron helpers in the end).</p>
<p>So i've created a scheduling module and attached it to the <strong>init</strong> .</p>
<p>It's not the best approach, but it helps ... | 2 | 2011-09-02T18:41:33Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 7,945,123 | <p>I just thought about this rather simple solution:</p>
<ol>
<li>Define a view function <strong>do_work(req, param)</strong> like you would with any other view, with URL mapping, return a HttpResponse and so on.</li>
<li>Set up a cron job with your timing preferences (or using AT or Scheduled Tasks in Windows) which ... | 4 | 2011-10-30T13:19:58Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 8,575,485 | <p>Brian Neal's suggestion of running management commands via cron works well, but if you're looking for something a little more robust (yet not as elaborate as Celery) I'd look into a library like <a href="https://github.com/jgorset/django-kronos">Kronos</a>:</p>
<pre><code># app/cron.py
import kronos
@kronos.regis... | 7 | 2011-12-20T12:30:42Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 9,071,268 | <p>We've open-sourced what I think is a structured app. that Brian's solution above alludes too. Would love any / all feedback!</p>
<p><a href="https://github.com/tivix/django-cron">https://github.com/tivix/django-cron</a></p>
<p>It comes with one management command:</p>
<pre><code>./manage.py runcrons
</code></pre>... | 26 | 2012-01-30T21:47:06Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 9,995,875 | <p>RabbitMQ and Celery have more features and task handling capabilities than Cron. If task failure isn't an issue, and you think you will handle broken tasks in the next call, then Cron is sufficient.</p>
<p>Celery & <a href="https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol" rel="nofollow">AMQP</a>... | 7 | 2012-04-03T14:54:18Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 22,649,515 | <p>Yes, the method above is so great. And I tried some of them. At last, I found a method like this:</p>
<pre><code> from threading import Timer
def sync():
do something...
sync_timer = Timer(self.interval, sync, ())
sync_timer.start()
</code></pre>
<p>Just like <strong>Recursive</st... | 2 | 2014-03-26T01:04:36Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 32,320,532 | <p>I use celery to create my periodical tasks. First you need to install it as follows:</p>
<pre><code>pip install django-celery
</code></pre>
<p>Don't forget to register <code>django-celery</code> in your settings and then you could do something like this:</p>
<pre><code>from celery import task
from celery.decorato... | 0 | 2015-08-31T21:52:36Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Django - Set Up A Scheduled Job? | 573,618 | <p>I've been working on a web app using Django, and I'm curious if there is a way to schedule a job to run periodically. </p>
<p>Basically I just want to run through the database and make some calculations/updates on an automatic, regular basis, but I can't seem to find any documentation on doing this.</p>
<p>Does an... | 299 | 2009-02-21T19:39:59Z | 38,468,265 | <p>Although not part of Django, <a href="http://airflow.incubator.apache.org/project.html" rel="nofollow">Airflow</a> is a more recent project (as of 2016) that is useful for task management.</p>
<p>Airflow is a workflow automation and scheduling system that can be used to author and manage data pipelines. A web-based... | 0 | 2016-07-19T20:49:43Z | [
"python",
"django",
"web-applications",
"scheduled-tasks"
] |
Using wget in python (Error Code Help me) | 573,914 | <p>Heres my code. </p>
<pre><code>import os, sys
if len(sys.argv) != 2:
sys.exit(1)
h = os.popen("wget -r %s") % sys.argv[1]
fil = open("links.txt","w")
dir = os.listdir("%s") % sys.argv[1]
for file in dir:
print file.replace("@","?")
fil.write("%s/"+file.replace("@","?")) % sys.argv[1]
fil.write... | 0 | 2009-02-21T23:32:24Z | 573,929 | <p>I think you want:</p>
<pre><code>h = os.popen("wget -r %s" % sys.argv[1])
</code></pre>
| 1 | 2009-02-21T23:40:19Z | [
"python"
] |
Using wget in python (Error Code Help me) | 573,914 | <p>Heres my code. </p>
<pre><code>import os, sys
if len(sys.argv) != 2:
sys.exit(1)
h = os.popen("wget -r %s") % sys.argv[1]
fil = open("links.txt","w")
dir = os.listdir("%s") % sys.argv[1]
for file in dir:
print file.replace("@","?")
fil.write("%s/"+file.replace("@","?")) % sys.argv[1]
fil.write... | 0 | 2009-02-21T23:32:24Z | 573,932 | <p>You're putting the <code>%</code> operator in the wrong place: you need to put it directly after the format string:</p>
<pre><code>h = os.popen("wget -r %s" % sys.argv[1])
...
dir = os.listdir("%s" % sys.argv[1])
...
fil.write(("%s/"+file.replace("@","?")) % sys.argv[1])
</code></pre>
<p>Alternatively, since you'r... | 1 | 2009-02-21T23:42:11Z | [
"python"
] |
Using wget in python (Error Code Help me) | 573,914 | <p>Heres my code. </p>
<pre><code>import os, sys
if len(sys.argv) != 2:
sys.exit(1)
h = os.popen("wget -r %s") % sys.argv[1]
fil = open("links.txt","w")
dir = os.listdir("%s") % sys.argv[1]
for file in dir:
print file.replace("@","?")
fil.write("%s/"+file.replace("@","?")) % sys.argv[1]
fil.write... | 0 | 2009-02-21T23:32:24Z | 573,933 | <ol>
<li><p>h = os.popen("wget -r %s" % sys.argv[1])</p></li>
<li><p>use the subprocess module, os.popen is obsolete</p></li>
<li><p>python has urllib, you can consider using that to have pure python code</p></li>
<li><p>there is pycurl</p></li>
</ol>
| 9 | 2009-02-21T23:42:18Z | [
"python"
] |
Docs for the internals of CPython Implementation | 574,004 | <p>I am currently in the process of making an embedded system port of the CPython 3.0 Python interpreter and I'm particularly interested in any references or documentation that provides details about the design and structure of code for Release 3.0 or even about any of the 2.x releases.</p>
<p>One useful document I ha... | 8 | 2009-02-22T00:16:52Z | 574,393 | <p>There's the documentation for the C API, which is essentially the API for the internals of Python. It won't cover porting details, though. The code itself is fairly well documented. You might try reading in and around the area you'll need to modify.</p>
| 8 | 2009-02-22T05:14:50Z | [
"python",
"cpython"
] |
Docs for the internals of CPython Implementation | 574,004 | <p>I am currently in the process of making an embedded system port of the CPython 3.0 Python interpreter and I'm particularly interested in any references or documentation that provides details about the design and structure of code for Release 3.0 or even about any of the 2.x releases.</p>
<p>One useful document I ha... | 8 | 2009-02-22T00:16:52Z | 575,040 | <p>Most of the documentation is stored in the minds of various core developers. :) A good resource for you would be the #python-dev IRC channel on freenode where many of them hang out.</p>
<p>There's also some scattered information on the <a href="http://wiki.python.org/moin/" rel="nofollow">Python wiki</a>.</p>
| 1 | 2009-02-22T15:12:04Z | [
"python",
"cpython"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 574,135 | <p>As always: It depends ;-)</p>
<p>When I don't need any apache features I am going with a pure python webserver like paste etc. Which one exactly depends on your application I guess and can be decided by doing some benchmarks. I always wanted to do some but never came to it. I guess Spawning might have some advantag... | 25 | 2009-02-22T01:39:56Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 575,737 | <p>The absolute easiest thing to deploy is CherryPy. Your web application can also become a standalone webserver. CherryPy is also a fairly fast server considering that it's written in pure Python. With that said, it's not Apache. Thus, I find that CherryPy is a good choice for lower volume webapps.</p>
<p>Other t... | 13 | 2009-02-22T20:36:33Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 581,621 | <p>I'm using Google App Engine for an application I'm developing. It runs WSGI applications.
<a href="http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html" rel="nofollow">Here's a couple bits of info on it.</a> </p>
<p>This is the first web-app I've ever really worked on, so I don't have a basi... | 4 | 2009-02-24T12:47:38Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 612,607 | <p>We are using pure Paste for some of our web services. It is easy to deploy (with our internal deployment mechanism; we're not using Paste Deploy or anything like that) and it is nice to minimize the difference between production systems and what's running on developers' workstations. Caveat: we don't expect low la... | 1 | 2009-03-04T21:48:27Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 612,622 | <p>Apache httpd + mod_fcgid using web.py (which is a wsgi application).</p>
<p>Works like a charm.</p>
| 3 | 2009-03-04T21:53:23Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 616,720 | <p>Apache+mod_wsgi,</p>
<p>Simple, clean. (only four lines of webserver config), easy for other sysadimns to get their head around.</p>
| 1 | 2009-03-05T21:34:32Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 622,597 | <blockquote>
<p>I would absolutely love you to bore me with details about the whats and the whys, application specific stuff, etc</p>
</blockquote>
<p>Ho. Well you asked for it!</p>
<p>Like Daniel I personally use Apache with mod_wsgi. It is still new enough that deploying it in some environments can be a struggle,... | 13 | 2009-03-07T22:15:27Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 629,171 | <h2>TurboGears (2.0)</h2>
<p><a href="http://turbogears.org/2.0/docs/index.html" rel="nofollow">TurboGears 2.0</a> is leaving <em>Beta</em> within the next month (has been in it for plenty of time). 2.0 improves upon 1.0 series and attempts to give you best-of-breed WSGI stack, so it makes some default choices for yo... | 4 | 2009-03-10T07:08:23Z | [
"python",
"deployment",
"wsgi"
] |
How do YOU deploy your WSGI application? (and why it is the best way) | 574,068 | <p>Deploying a WSGI application. There are many ways to skin this cat. I am currently using apache2 with mod-wsgi, but I can see some potential problems with this.</p>
<p>So how can it be done?</p>
<ol>
<li>Apache Mod-wsgi (the other mod-wsgi's seem to not be worth it)</li>
<li>Pure Python web server eg paste, cherry... | 42 | 2009-02-22T00:58:37Z | 635,680 | <p>Nginx reverse proxy and static file sharing + XSendfile + uploadprogress_module. Nothing beats it for the purpose.</p>
<p>On the WSGI side either Apache + mod_wsgi or cherrypy server. I like to use cherrypy wsgi server for applications on servers with less memory and less requests.</p>
<p>Reasoning:</p>
<p>I've d... | 6 | 2009-03-11T18:06:50Z | [
"python",
"deployment",
"wsgi"
] |
One view ( frontpage ) for many controllers (sub views) | 574,140 | <p><em>Notes:</em> Cannot use Javascript or iframes. In fact I can't trust the client browser to do just about anything but the ultra basics.</p>
<p>I'm rebuilding a legacy PHP4 app as a MVC application, with most of my research currently focused with the Pylon's framework.</p>
<p>One of the first weird issues I've r... | 1 | 2009-02-22T01:42:10Z | 649,506 | <p>You could use <a href="http://toscawidgets.org/" rel="nofollow">ToscaWidgets</a> to encapsulate your widgets, along with a stored list of the widgets enabled for each user (in database or other service, as you suggest). Pass a list of the enabled ToscaWidgets to the view and the widgets will render themselves (incl... | 0 | 2009-03-16T07:03:57Z | [
"python",
"model-view-controller",
"pylons",
"cherrypy"
] |
One view ( frontpage ) for many controllers (sub views) | 574,140 | <p><em>Notes:</em> Cannot use Javascript or iframes. In fact I can't trust the client browser to do just about anything but the ultra basics.</p>
<p>I'm rebuilding a legacy PHP4 app as a MVC application, with most of my research currently focused with the Pylon's framework.</p>
<p>One of the first weird issues I've r... | 1 | 2009-02-22T01:42:10Z | 784,476 | <p>While in most cases I'd recommend what you originally stated, using Javascript to load each widget, since that isn't an option I think you'll need to do something a little different.</p>
<p>In addition to using the approach of trying to have a single front controller go through all the widgets needed and building t... | 6 | 2009-04-24T04:08:31Z | [
"python",
"model-view-controller",
"pylons",
"cherrypy"
] |
How to determine number of files on a drive with Python? | 574,236 | <p>I have been trying to figure out how to retrieve (quickly) the number of files on a given HFS+ drive with python.</p>
<p>I have been playing with os.statvfs and such, but can't quite get anything (that seems helpful to me).</p>
<p>Any ideas?</p>
<p><strong>Edit:</strong> Let me be a bit more specific. =]</p>
<p>... | 5 | 2009-02-22T03:12:46Z | 574,270 | <p>The right answer for your purpose is to live without a progress bar once, store the number rsync came up with and assume you have the same number of files as last time for each successive backup.</p>
<p>I didn't believe it, but this seems to work on Linux:</p>
<pre><code>os.statvfs('/').f_files - os.statvfs('/').f... | 7 | 2009-02-22T03:37:47Z | [
"python",
"osx",
"filesystems",
"hard-drive"
] |
How to determine number of files on a drive with Python? | 574,236 | <p>I have been trying to figure out how to retrieve (quickly) the number of files on a given HFS+ drive with python.</p>
<p>I have been playing with os.statvfs and such, but can't quite get anything (that seems helpful to me).</p>
<p>Any ideas?</p>
<p><strong>Edit:</strong> Let me be a bit more specific. =]</p>
<p>... | 5 | 2009-02-22T03:12:46Z | 574,278 | <p>Edit: Spotlight does not track every file, so its metadata will not suffice.</p>
| 0 | 2009-02-22T03:42:55Z | [
"python",
"osx",
"filesystems",
"hard-drive"
] |
How to determine number of files on a drive with Python? | 574,236 | <p>I have been trying to figure out how to retrieve (quickly) the number of files on a given HFS+ drive with python.</p>
<p>I have been playing with os.statvfs and such, but can't quite get anything (that seems helpful to me).</p>
<p>Any ideas?</p>
<p><strong>Edit:</strong> Let me be a bit more specific. =]</p>
<p>... | 5 | 2009-02-22T03:12:46Z | 577,322 | <p>If traversing the directory tree is an option (would be slower than querying the drive directly):</p>
<pre><code>import os
dirs = 0
files = 0
for r, d, f in os.walk('/path/to/drive'):
dirs += len(d)
files += len(f)
</code></pre>
| 1 | 2009-02-23T11:23:55Z | [
"python",
"osx",
"filesystems",
"hard-drive"
] |
How to determine number of files on a drive with Python? | 574,236 | <p>I have been trying to figure out how to retrieve (quickly) the number of files on a given HFS+ drive with python.</p>
<p>I have been playing with os.statvfs and such, but can't quite get anything (that seems helpful to me).</p>
<p>Any ideas?</p>
<p><strong>Edit:</strong> Let me be a bit more specific. =]</p>
<p>... | 5 | 2009-02-22T03:12:46Z | 585,629 | <p>You could use a number from a previous <code>rsync</code> run. It is quick, portable, and for <code>10**6</code> files and any reasonable backup strategy it will give you <code>1%</code> or better precision.</p>
| 2 | 2009-02-25T11:20:23Z | [
"python",
"osx",
"filesystems",
"hard-drive"
] |
Has anyone used SciPy with IronPython? | 574,604 | <p>I've been able to use the standard Python modules from IronPython, but I haven't gotten SciPy to work yet. Has anyone been able to use SciPy from IronPython? What did you have to do to make it work?</p>
<p>Update: See <a href="http://www.johndcook.com/blog/2009/03/19/ironclad-ironpytho/">Numerical computing in Ir... | 16 | 2009-02-22T08:57:53Z | 574,623 | <p>Anything with components written in C (for example NumPy, which is a component of SciPy) will not work on IronPython as the external language interface works differently. Any C language component will probably not work unless it has been explicitly ported to work with IronPython.</p>
<p>You might have to dig into ... | 8 | 2009-02-22T09:13:41Z | [
"python",
"scipy",
"ironpython",
"python.net"
] |
Has anyone used SciPy with IronPython? | 574,604 | <p>I've been able to use the standard Python modules from IronPython, but I haven't gotten SciPy to work yet. Has anyone been able to use SciPy from IronPython? What did you have to do to make it work?</p>
<p>Update: See <a href="http://www.johndcook.com/blog/2009/03/19/ironclad-ironpytho/">Numerical computing in Ir... | 16 | 2009-02-22T08:57:53Z | 574,919 | <p>Some of my workmates are working on <a href="http://code.google.com/p/ironclad/" rel="nofollow">Ironclad</a>, a project that will make extension modules for CPython work in IronPython. It's still in development, but parts of numpy, scipy and some other modules already work. You should try it out to see whether the p... | 12 | 2009-02-22T13:21:58Z | [
"python",
"scipy",
"ironpython",
"python.net"
] |
Include html part in a mail with python libgmail | 574,861 | <p>I've a question about its usage: i need to send an html formatted mail. I prepare my message with </p>
<pre><code>ga = libgmail.GmailAccount(USERNAME,PASSWORD)
msg = MIMEMultipart('alternative')
msg.attach(part1)
msg.attach(part2)
...
ga.sendMessage(msg.as_string())
</code></pre>
<p>This way doesn't works, it see... | 2 | 2009-02-22T12:41:45Z | 574,938 | <p>If you refer to <code>libgmail</code> from sourceforge, you need to compose your messages with the <a href="http://docs.python.org/library/email.html#module-email" rel="nofollow">email module</a>.</p>
<p>Generate the HTML message as a <a href="http://docs.python.org/library/email.generator.html" rel="nofollow">MIME... | 1 | 2009-02-22T13:40:48Z | [
"python",
"html",
"gmail",
"mime",
"libgmail"
] |
How can you extract all 6 letter Latin words to a list? | 574,952 | <p>I need to have all 6 letter <a href="http://www.math.ubc.ca/~cass/frivs/latin/latin-dict-full.html" rel="nofollow">Latin words</a> in a list. </p>
<p>I would also like to have words which follow the pattern Xyzzyx in a list.</p>
<p>I have used little Python.</p>
| 1 | 2009-02-22T13:51:36Z | 574,974 | <p>Regular expressions are your friend, my friend! Is this homework?</p>
<p>Here's an example that's <em>close</em> to what you want:</p>
<pre><code>egrep "^\w{6}$" /usr/share/dict/words | egrep "(.)(.)(.)\3\2\1"
</code></pre>
<p>I'll leave it as an exercise for the reader to create a latin word list and deal with ... | 5 | 2009-02-22T14:10:50Z | [
"python",
"regex",
"data-mining"
] |
How can you extract all 6 letter Latin words to a list? | 574,952 | <p>I need to have all 6 letter <a href="http://www.math.ubc.ca/~cass/frivs/latin/latin-dict-full.html" rel="nofollow">Latin words</a> in a list. </p>
<p>I would also like to have words which follow the pattern Xyzzyx in a list.</p>
<p>I have used little Python.</p>
| 1 | 2009-02-22T13:51:36Z | 575,704 | <p>Note that unless your list contains all of the nouns' declensions and verbs' conjugations, your program won't produce anything like <em>all</em> the six-letter words in Latin.</p>
<p>For instance, your list probably contains only the nominative case of the nouns. First-declension nouns whose nominative case is fiv... | 0 | 2009-02-22T20:20:48Z | [
"python",
"regex",
"data-mining"
] |
Why doesn't Python release file handles after calling file.close()? | 575,081 | <p>I am on windows with Python 2.5. I have an open file for writing. I write some data. Call file close. When I try to delete the file from the folder using Windows Explorer, it errors, saying that a process still holds a handle to the file.</p>
<p>If I shutdown python, and try again, it succeeds.</p>
| 5 | 2009-02-22T15:32:53Z | 575,086 | <p>It does close them.
Are you sure f.close() is getting called?
I just tested the same scenario and windows deletes the file for me.</p>
| 4 | 2009-02-22T15:38:49Z | [
"python"
] |
Why doesn't Python release file handles after calling file.close()? | 575,081 | <p>I am on windows with Python 2.5. I have an open file for writing. I write some data. Call file close. When I try to delete the file from the folder using Windows Explorer, it errors, saying that a process still holds a handle to the file.</p>
<p>If I shutdown python, and try again, it succeeds.</p>
| 5 | 2009-02-22T15:32:53Z | 575,296 | <p>Are you handling any exceptions around the file object? If so, make sure the error handling looks something like this:</p>
<pre><code>f = open("hello.txt")
try:
for line in f:
print line
finally:
f.close()
</code></pre>
<p>In considering why you should do this, consider the following lines of code... | 2 | 2009-02-22T17:35:45Z | [
"python"
] |
Why doesn't Python release file handles after calling file.close()? | 575,081 | <p>I am on windows with Python 2.5. I have an open file for writing. I write some data. Call file close. When I try to delete the file from the folder using Windows Explorer, it errors, saying that a process still holds a handle to the file.</p>
<p>If I shutdown python, and try again, it succeeds.</p>
| 5 | 2009-02-22T15:32:53Z | 8,688,682 | <p>Explained in the tutorial:</p>
<pre><code>with open('/tmp/workfile', 'r') as f:
read_data = f.read()
</code></pre>
<p>It works when you writing or pickling/unpickling, too</p>
<p>It's not really necessary that try finally block: Java way of doing things, not Python</p>
| 3 | 2011-12-31T14:38:44Z | [
"python"
] |
Why doesn't Python release file handles after calling file.close()? | 575,081 | <p>I am on windows with Python 2.5. I have an open file for writing. I write some data. Call file close. When I try to delete the file from the folder using Windows Explorer, it errors, saying that a process still holds a handle to the file.</p>
<p>If I shutdown python, and try again, it succeeds.</p>
| 5 | 2009-02-22T15:32:53Z | 30,957,893 | <p>I was looking for this, because the same thing happened to me. The question didn't help me, but I think I figured out what happened.</p>
<p>In the original version of the script I wrote, I neglected to add in a 'finally' clause to the file in case of an exception.</p>
<p>I was testing the script from the interacti... | 0 | 2015-06-20T19:13:34Z | [
"python"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 575,124 | <p>Yes, there is.</p>
<p>Okay, now you'll want to know why. Why not just constrain it so that z > y? Try </p>
<pre><code>for z in range (y+1, 1000)
</code></pre>
| 1 | 2009-02-22T16:05:11Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 575,134 | <p>You should define x < y < z.</p>
<pre><code>for x in range (1, 1000):
for y in range (x + 1, 1000):
for z in range(y + 1, 1000):
</code></pre>
<p>Another good optimization would be to only use x and y and calculate zsqr = x * x + y * y. If zsqr is a square number (or z = sqrt(zsqr) is a whole... | 12 | 2009-02-22T16:09:18Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 575,199 | <p>I wrote that program in Ruby and it similar to the python implementation. The important line is:</p>
<pre><code>if x*x == y*y + z*z && gcd(y,z) == 1:
</code></pre>
<p>Then you have to implement a method that return the greatest common divisor (gcd) of two given numbers. A very simple example in Ruby again:... | 2 | 2009-02-22T16:44:40Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 575,728 | <pre><code>def pyth_triplets(n=1000):
"Version 1"
for x in xrange(1, n):
x2= x*x # time saver
for y in xrange(x+1, n): # y > x
z2= x2 + y*y
zs= int(z2**.5)
if zs*zs == z2:
yield x, y, zs
>>> print list(pyth_triplets(20))
[(3, 4, 5)... | 4 | 2009-02-22T20:32:06Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 575,849 | <p>Algorithms can be tuned for speed, memory usage, simplicity, and other things.</p>
<p>Here is a <code>pythagore_triplets</code> algorithm tuned for speed, at the cost of memory usage and simplicity. If all you want is speed, this could be the way to go.</p>
<p>Calculation of <code>list(pythagore_triplets(10000))<... | 7 | 2009-02-22T21:31:53Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 576,405 | <p>Pythagorean Triples make a good example for claiming "<strong><code>for</code> loops considered harmful</strong>", because <code>for</code> loops seduce us into thinking about counting, often the most irrelevant part of a task. </p>
<p>(I'm going to stick with pseudo-code to avoid language biases, and to keep the p... | 59 | 2009-02-23T03:00:32Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 577,110 | <p>Version 5 to Joel Neely.</p>
<p>Since X can be max of 'N-2' and Y can be max of 'N-1' for range of 1..N. Since Z max is N and Y max is N-1, X can be max of Sqrt ( N * N - (N-1) * (N-1) ) = Sqrt ( 2 * N - 1 ) and can start from 3.</p>
<pre><code>MaxX = ( 2 * N - 1 ) ** 0.5
for x in 3..MaxX {
y = x+1
z = y+1
... | 0 | 2009-02-23T10:12:40Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 578,789 | <p>The previously listed algorithms for generating <a href="http://en.wikipedia.org/wiki/Pythagorean_triplets">Pythagorean triplets</a> are all modifications of the naive approach derived from the basic relationship <code>a^2 + b^2 = c^2</code> where <code>(a, b, c)</code> is a triplet of positive integers. It turns ou... | 11 | 2009-02-23T18:43:00Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 2,241,194 | <p>Just checking, but I've been using the following code to make pythagorean triples. It's very fast (and I've tried some of the examples here, though I kind of learned them and wrote my own and came back and checked here (2 years ago)). I think this code correctly finds all pythagorean triples up to (name your limit) ... | 0 | 2010-02-10T23:41:16Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 8,263,898 | <p>Substantially faster than any of the solutions so far. Finds triplets via a ternary tree.</p>
<blockquote>
<p><a href="http://mathworld.wolfram.com/PythagoreanTriple.html">Wolfram</a> says:</p>
<p>Hall (1970) and Roberts (1977) prove that is a primitive Pythagorean triple if and only if</p>
<p><code>(a... | 22 | 2011-11-25T00:59:17Z | [
"python",
"math"
] |
Generating unique, ordered Pythagorean triplets | 575,117 | <p>This is a program I wrote to calculate Pythagorean triplets. When I run the program it prints each set of triplets twice because of the if statement. Is there any way I can tell the program to only print a new set of triplets once? Thanks.</p>
<pre><code>import math
def main():
for x in range (1, 1000):
... | 17 | 2009-02-22T16:00:34Z | 21,654,130 | <p>It should be noted that for a, b, and c you don't need to loop all the way to N.</p>
<p>For a, you only have to loop from 1 to <code>int(sqrt(n**2/2))+1</code>, for b, <code>a+1</code> to <code>int(sqrt(n**2-a**2))+1</code>, and for c from <code>int(sqrt(a**2+b**2)</code> to <code>int(sqrt(a**2+b**2)+2</code>.</p>... | 0 | 2014-02-09T01:38:41Z | [
"python",
"math"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 575,183 | <p><a href="http://en.wikipedia.org/wiki/Berkeley_DB" rel="nofollow">BerkleyDB</a></p>
| 4 | 2009-02-22T16:35:08Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 575,184 | <p>BerkeleyDB : (it seems that there is an API binding to python : <a href="http://www.jcea.es/programacion/pybsddb.htm" rel="nofollow">http://www.jcea.es/programacion/pybsddb.htm</a>)</p>
| 2 | 2009-02-22T16:35:12Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 575,193 | <p>Have you looked at <a href="http://couchdb.apache.org/" rel="nofollow">CouchDB</a>? It's non-relational, data can be migrated with relative ease and it has a Python API in the form of <a href="http://code.google.com/p/couchdb-python/" rel="nofollow">couchdb-python</a>. It does have some fairly unusual dependencies i... | 3 | 2009-02-22T16:41:53Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 575,197 | <p>If you're used to thinking a relational database has to be huge and heavy like PostgreSQL or MySQL, then you'll be pleasantly surprised by SQLite.</p>
<p>It is relational, very small, uses a single file, has Python bindings, requires no extra priviledges, and works on Linux, Windows, and many other platforms.</p>
| 3 | 2009-02-22T16:43:43Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 575,307 | <p>Have you looked at <a href="http://wiki.zope.org/ZODB/FrontPage" rel="nofollow">Zope Object Database</a>?</p>
<p>Also, <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a> or <a href="http://docs.djangoproject.com/en/dev/" rel="nofollow">Django's ORM</a> layer makes schema management over SQLite almos... | 0 | 2009-02-22T17:43:29Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 576,408 | <p><a href="http://www.equi4.com/metakit/">Metakit</a> is an interesting non-relational embedded database that supports Python. </p>
<p>Installation requires just copying a single shared library and .py file. It works on Windows, Linux and Mac and is open-source (MIT licensed).</p>
| 5 | 2009-02-23T03:01:27Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 576,473 | <p>If you're only coming and going from Python you might think about using <a href="http://docs.python.org/library/pickle.html" rel="nofollow">Pickle</a> to serialize the objects. Not going to work if you're looking to use other tools to access the same data of course. It's built into python, so you shouldn't have an... | 0 | 2009-02-23T03:52:37Z | [
"python",
"non-relational-database",
"portable-database"
] |
portable non-relational database | 575,172 | <p>I want to experiment/play around with non-relational databases, it'd be best if the solution was:</p>
<ul>
<li>portable, meaning it doesn't require an installation. ideally just copy-pasting the directory to someplace would make it work. I don't mind if it requires editing some configuration files or running a conf... | 1 | 2009-02-22T16:31:16Z | 576,570 | <p>I recommend you consider <a href="http://en.wikipedia.org/wiki/Berkeley_DB">BerkelyDB</a> <strong>with awareness of the licensing issues.</strong> </p>
<p>I am getting very tired of people recommending BerkleyDB without qualification - you can only distribute BDB systems under GPL or some unknown and not publicly v... | 7 | 2009-02-23T04:49:08Z | [
"python",
"non-relational-database",
"portable-database"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,204 | <p><code>f</code> doesn't actually alter the value of <code>x</code> (which is always the same reference to an instance of a list). Rather, it alters the <em>contents</em> of this list.</p>
<p>In both cases, a <em>copy</em> is passed to the function. But since <code>x</code> is a reference to a list instance, only the... | 11 | 2009-02-22T16:47:13Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,254 | <p>It´s because a list is a mutable object. You´re not setting x to the value of [0,1,2,3], you´re defining a label to the object [0,1,2,3].</p>
<p>You should declare your function f() like this:</p>
<pre><code>def f(n, x=None):
if x is None:
x = []
...
</code></pre>
| 2 | 2009-02-22T17:06:01Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,259 | <p>n is an int (immutable), and a copy is passed to the function, so in the function you are changing the copy.</p>
<p>X is a list (mutable), and a copy of <em>the pointer</em> is passed o the function so x.append(4) changes the contents of the list. However, you you said x = [0,1,2,3,4] in your function, you would n... | 2 | 2009-02-22T17:07:59Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,268 | <p>I will rename variables to reduce confusion. <em>n</em> -> <em>nf</em> or <em>nmain</em>. <em>x</em> -> <em>xf</em> or <em>xmain</em>:</p>
<pre><code>def f(nf, xf):
nf = 2
xf.append(4)
print 'In f():', nf, xf
def main():
nmain = 1
xmain = [0,1,2,3]
print 'Before:', nmain, xmain
f(nmai... | 2 | 2009-02-22T17:15:36Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,337 | <p>Some answers contain the word "copy" in a context of a function call. I find it confusing.</p>
<p><strong>Python doesn't copy <em>objects</em> you pass during a function call <em>ever</em>.</strong></p>
<p>Function parameters are <em>names</em>. When you call a function Python binds these parameters to whatever ob... | 109 | 2009-02-22T18:06:13Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 575,887 | <p>You've got a number of answers already, and I broadly agree with J.F. Sebastian, but you might find this useful as a shortcut:</p>
<p>Any time you see <strong><code>varname =</code></strong>, you're creating a <em>new</em> name binding within the function's scope. Whatever value <code>varname</code> was bound to b... | 11 | 2009-02-22T21:52:14Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 4,354,058 | <p>Python is a pure pass-by-value language if you think about it the right way. A python variable stores the location of an object in memory. The Python variable does not store the object itself. When you pass a variable to a function, you are passing a <em>copy</em> of the address of the object being pointed to by ... | 0 | 2010-12-04T14:48:00Z | [
"python"
] |
In Python, why can a function modify some arguments as perceived by the caller, but not others? | 575,196 | <p>I'm new to Python and am trying to understand its approach to variable scope. In this example, why is <code>f()</code> able to alter the value of <code>x</code>, as perceived within <code>main()</code>, but not the value of <code>n</code>?</p>
<pre><code>def f(n, x):
n = 2
x.append(4)
print 'In f():', n... | 77 | 2009-02-22T16:42:51Z | 34,829,285 | <p>Python is copy by value of reference. An object occupies a field in memory, and a reference is associated with that object, but itself occupies a field in memory. And name/value is associated with a reference. In python function, it always copy the value of the reference, so in your code, n is copied to be a new na... | 0 | 2016-01-16T16:30:33Z | [
"python"
] |
How does python close files that have been gc'ed? | 575,278 | <p>I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:</p>
<pre><code>>>> f = open('somefile.txt')
>>> del f
</code></pre>
<p>Just out of sheer curiosity, how does this work? I notic... | 14 | 2009-02-22T17:26:49Z | 575,292 | <p>Hence the <strong>with</strong> statement.</p>
<p>For Python 2.5, use</p>
<pre><code>from __future__ import with_statement
</code></pre>
<p>(For Python 2.6 or 3.x, do nothing)</p>
<pre><code>with open( "someFile", "rU" ) as aFile:
# process the file
pass
# At this point, the file was closed by the with s... | 4 | 2009-02-22T17:35:00Z | [
"python",
"file",
"garbage-collection",
"del"
] |
How does python close files that have been gc'ed? | 575,278 | <p>I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:</p>
<pre><code>>>> f = open('somefile.txt')
>>> del f
</code></pre>
<p>Just out of sheer curiosity, how does this work? I notic... | 14 | 2009-02-22T17:26:49Z | 575,303 | <p>Best guess is that because the file type is a built-in type, the interpreter itself handles closing the file on garbage collection.</p>
<p>Alternatively, you are only checking after the python interpreter has exited, and all "leaked" file handles are closed anyways.</p>
| 0 | 2009-02-22T17:41:07Z | [
"python",
"file",
"garbage-collection",
"del"
] |
How does python close files that have been gc'ed? | 575,278 | <p>I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:</p>
<pre><code>>>> f = open('somefile.txt')
>>> del f
</code></pre>
<p>Just out of sheer curiosity, how does this work? I notic... | 14 | 2009-02-22T17:26:49Z | 575,320 | <p>In CPython, at least, files are closed when the file object is deallocated. See the <code>file_dealloc</code> function in <code>Objects/fileobject.c</code> in the CPython source. Dealloc methods are sort-of like <code>__del__</code> for C types, except without some of the problems inherent to <code>__del__</code>.</... | 19 | 2009-02-22T17:53:46Z | [
"python",
"file",
"garbage-collection",
"del"
] |
How does python close files that have been gc'ed? | 575,278 | <p>I had always assumed that a file would leak if it was opened without being closed, but I just verified that if I enter the following lines of code, the file will close:</p>
<pre><code>>>> f = open('somefile.txt')
>>> del f
</code></pre>
<p>Just out of sheer curiosity, how does this work? I notic... | 14 | 2009-02-22T17:26:49Z | 575,383 | <p>Python uses reference counting and deterministic destruction in addition to garbage collection. When there is no more references to an object, the object is released immediately. Releasing a file closes it.</p>
<p>This is different than e.g. Java where there is only nondeterministic garbage collection. This means y... | 2 | 2009-02-22T18:22:23Z | [
"python",
"file",
"garbage-collection",
"del"
] |
Succesive calls to cProfile/pstats no updating properly | 575,325 | <p>I'm trying to make successive calls of some profiler code however on the second call to the function the update time of the profile file changes but the actual profiler stats stay the same. This isn't the code I'm running but it's as simplified an example I can come up with that shows the same behaviour.</p>
<p>On ... | 1 | 2009-02-22T17:56:42Z | 576,184 | <p>Calling profiler.dump_stats (implemented in cProfile.py) calls profiler.create_stats, which in turns calls profiler.disable().</p>
<p>You need to call profiler.enable() to make it work again. No, this is not documented.</p>
<p>The following seems to do what you want. Note that I got rid of the intermediate data fi... | 1 | 2009-02-23T00:37:41Z | [
"python"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 575,394 | <p>When using pyglet I found that I couldn't use psyco on the entire app without making my app non-functional. I could use it in small sections of math-heavy code, of course, but it wasn't necessary, so I didn't bother.</p>
<p>Also, psyco has done strange things with my profiling results (such as, well, not alter them... | 5 | 2009-02-22T18:26:25Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 575,423 | <p>It also depends where your bottleneck is. I am mostly doing web apps and there the bottlenecks are probably more IO and database. So you should know where to optimize.</p>
<p>Also beware that maybe you first should think about your code instead of directly throwing psyco at it. So I agree with Devin, that algorithm... | 4 | 2009-02-22T18:39:53Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 575,433 | <blockquote>
<p>Psyco currently uses a lot of memory.
It only runs on Intel 386-compatible
processors (under any OS) right now.
There are some subtle semantic
differences (i.e. bugs) with the way
Python works; they should not be
apparent in most programs.</p>
</blockquote>
<p>See also the <a href="http:/... | 6 | 2009-02-22T18:45:14Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 575,829 | <p>Quite simply: "Because the code already runs fast enough".</p>
| 0 | 2009-02-22T21:24:38Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 576,379 | <p>One should never rely on some magic bullet to fix your problems. Using psyco to make a slow program faster is usually not necessary. Bad algorithms can be rewritten, and parts that <em>require</em> speed could be written in another language. Of course, your question asks why we don't use it for the speed boost anywa... | 3 | 2009-02-23T02:43:57Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 620,966 | <p>A couple of other things:</p>
<ol>
<li>It doesn't seem to be very actively maintained.</li>
<li>It can be a memory hog.</li>
</ol>
| 2 | 2009-03-07T00:14:22Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 1,437,939 | <p>1) The memory overhead is the main one, as described in other answers. You also pay the compilation cost, which can be prohibitive if you aren't selective. From the <a href="http://psyco.sourceforge.net/psycoguide/module-psyco.html">user reference</a>:</p>
<blockquote>
<p>Compiling everything is often overkill fo... | 20 | 2009-09-17T10:23:30Z | [
"python",
"optimization",
"psyco"
] |
Why not always use psyco for Python code? | 575,385 | <p><a href="http://psyco.sourceforge.net/">psyco</a> seems to be quite helpful in optimizing Python code, and it does it in a very non-intrusive way. </p>
<p>Therefore, one has to wonder. Assuming you're always on a x86 architecture (which is where most apps run these days), why not just always use <code>psyco</code> ... | 37 | 2009-02-22T18:23:50Z | 12,466,971 | <p>psyco is dead and not longer maintained. It is time to find another </p>
| 2 | 2012-09-17T20:53:44Z | [
"python",
"optimization",
"psyco"
] |
How to obtain the keycodes in Python | 575,650 | <p>I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.</p>
<p>I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in ... | 5 | 2009-02-22T20:01:21Z | 575,656 | <p>Depending on what you are trying to accomplish, perhaps using a library such as <a href="http://pygame.org">pygame</a> would do what you want. Pygame contains more advanced keypress handling than is normally available with Python's standard libraries.</p>
| 8 | 2009-02-22T20:03:45Z | [
"python",
"input",
"keycode"
] |
How to obtain the keycodes in Python | 575,650 | <p>I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.</p>
<p>I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in ... | 5 | 2009-02-22T20:01:21Z | 575,688 | <p>You probably will have to use <a href="http://wiki.python.org/moin/TkInter" rel="nofollow">Tkinter</a>, which is the 'standard' Python gui, and has been included with python for many years. </p>
<p>A command-line solution is probably not available, because of the way data passes into and out of command-line proces... | 2 | 2009-02-22T20:12:31Z | [
"python",
"input",
"keycode"
] |
How to obtain the keycodes in Python | 575,650 | <p>I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.</p>
<p>I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in ... | 5 | 2009-02-22T20:01:21Z | 575,758 | <p>If you need to work in windows only you should try <a href="http://docs.python.org/library/msvcrt.html" rel="nofollow">msvcrt</a>.</p>
| 0 | 2009-02-22T20:50:47Z | [
"python",
"input",
"keycode"
] |
How to obtain the keycodes in Python | 575,650 | <p>I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.</p>
<p>I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in ... | 5 | 2009-02-22T20:01:21Z | 575,781 | <p>See <a href="http://docs.python.org/library/tty.html">tty</a> standard module. It allows switching from default line-oriented (cooked) mode into char-oriented (cbreak) mode with <a href="http://docs.python.org/library/tty.html#tty.setcbreak">tty.setcbreak(sys.stdin)</a>. Reading single char from sys.stdin will resul... | 16 | 2009-02-22T21:02:36Z | [
"python",
"input",
"keycode"
] |
How to obtain the keycodes in Python | 575,650 | <p>I have to know what key is pressed, but not need the code of the Character, i want to know when someone press the 'A' key even if the key obtained is 'a' or 'A', and so with all other keys.</p>
<p>I can't use PyGame or any other library (including Tkinter). Only Python Standard Library. And this have to be done in ... | 5 | 2009-02-22T20:01:21Z | 591,938 | <p>The obvious answer:</p>
<pre><code>someFunction = string.upper
ord('a') != ord('A') # 97 != 65
someFunction('a') == someFunction('A') # a_code == A_code
</code></pre>
<p>or, in other (key)words:</p>
<pre><code>char_from_user = getch().upper() # read a char converting to uppercase
if char ... | 0 | 2009-02-26T18:59:04Z | [
"python",
"input",
"keycode"
] |
How to convert rational and decimal number strings to floats in python? | 575,925 | <p>How can I convert strings which can denote decimal or rational numbers to floats</p>
<pre><code>>>> ["0.1234", "1/2"]
['0.1234', '1/2']
</code></pre>
<p>I'd want [0.1234, 0.5].</p>
<p>eval is what I was thinking but no luck:</p>
<pre><code>>>> eval("1/2")
0
</code></pre>
| 9 | 2009-02-22T22:08:47Z | 575,932 | <p>The <code>/</code> operator does integer division. Try:</p>
<pre><code>>>> eval("1.0*" + "1/2")
0.5
</code></pre>
<p>Because <code>eval()</code> is potentially dangerous, you should always check precisely what you are passing into it:</p>
<pre><code>>>> import re
>>> s = "1/2"
>>&... | 3 | 2009-02-22T22:13:30Z | [
"python",
"rational-numbers"
] |
How to convert rational and decimal number strings to floats in python? | 575,925 | <p>How can I convert strings which can denote decimal or rational numbers to floats</p>
<pre><code>>>> ["0.1234", "1/2"]
['0.1234', '1/2']
</code></pre>
<p>I'd want [0.1234, 0.5].</p>
<p>eval is what I was thinking but no luck:</p>
<pre><code>>>> eval("1/2")
0
</code></pre>
| 9 | 2009-02-22T22:08:47Z | 575,935 | <p>That's because 1 and 2 are interpreted by Python as integers and not floats. It needs to be 1.0/2.0 or some mix of that.</p>
| 0 | 2009-02-22T22:15:39Z | [
"python",
"rational-numbers"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.