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 |
|---|---|---|---|---|---|---|---|---|---|
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 1,196,112 | <p>You probably want the answer to <a href="http://stackoverflow.com/questions/89228/how-to-call-external-command-in-python/92395#92395">"How to call an external command in Python"</a>.</p>
<p>The simplest approach is to use the <code>os.system</code> function, e.g.:</p>
<pre><code>import os
os.system("some_command &... | 24 | 2009-07-28T19:02:59Z | [
"python",
"process",
"daemon"
] |
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 1,196,122 | <p><strong>Note</strong>: This answer is less current than it was when posted in 2009. Using the <code>subprocess</code> module shown in other answers is now recommended <a href="https://docs.python.org/2/library/os.html?highlight=os#os.spawnl">in the docs</a></p>
<blockquote>
<p>(Note that the subprocess module pro... | 46 | 2009-07-28T19:05:23Z | [
"python",
"process",
"daemon"
] |
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 1,196,162 | <p>You probably want to start investigating the os module for forking different threads (by opening an interactive session and issuing help(os)). The relevant functions are fork and any of the exec ones. To give you an idea on how to start, put something like this in a function that performs the fork (the function need... | 8 | 2009-07-28T19:12:06Z | [
"python",
"process",
"daemon"
] |
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 7,224,186 | <p>While <a href="http://stackoverflow.com/questions/1196074/starting-a-background-process-in-python/1196122#1196122">jkp</a>'s solution works, the newer way of doing things (and the way the documentation recommends) is to use the <code>subprocess</code> module. For simple commands its equivalent, but it offers more op... | 198 | 2011-08-28T21:47:04Z | [
"python",
"process",
"daemon"
] |
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 13,593,257 | <p>I found this <a href="http://stackoverflow.com/questions/89228/calling-an-external-command-in-python#2251026">here</a>:</p>
<p>On windows (win xp), the parent process will not finish until the <code>longtask.py</code> has finished its work. It is not what you want in CGI-script. The problem is not specific to Pytho... | 10 | 2012-11-27T21:19:09Z | [
"python",
"process",
"daemon"
] |
How to start a background process in Python? | 1,196,074 | <p>I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scripts complete. I am sure it's ... | 135 | 2009-07-28T18:56:50Z | 34,459,371 | <p><a href="https://gist.github.com/yinjimmy/d6ad0742d03d54518e9f" rel="nofollow">https://gist.github.com/yinjimmy/d6ad0742d03d54518e9f</a></p>
<pre>
import os, time, sys, subprocess
if len(sys.argv) == 2:
time.sleep(5)
print 'track end'
if sys.platform == 'darwin':
subprocess.Popen(['say', 'hello... | 1 | 2015-12-25T01:47:55Z | [
"python",
"process",
"daemon"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,196,757 | <p>To import a python item there needs to be a <code>__init__.py</code> file in each of the folder above it to show that it is a valid python package.</p>
<p>The <code>__init__.py</code> files can be empty, they are there just to show structure.</p>
<pre><code>\mtl12366150
__init__.py
\test
__init__.py
... | 0 | 2009-07-28T21:10:12Z | [
"python",
"import",
"folder",
"shared"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,196,801 | <p>Did you forget to use a raw string, or escape the backslashes, in your additional sys.path component? Remember that "\t" is a tab, whereas r"\t" or "\t" are a backslash followed by a tab.</p>
<p>In most applications you are actually better off using forward slashes rather than backslashes even for Windows paths, an... | 1 | 2009-07-28T21:19:49Z | [
"python",
"import",
"folder",
"shared"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,196,815 | <p>"I appended to sys.path ..."</p>
<p>Please don't.</p>
<p>Set the <code>PYTHONPATH</code> environment variable from outside your application.</p>
| -2 | 2009-07-28T21:22:31Z | [
"python",
"import",
"folder",
"shared"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,196,830 | <p>You say os.path.exists() says the path is there, but are you absolutely sure you escaped the \? Try this:</p>
<pre><code>sys.path.append('\\mtl12366150\\tes')
</code></pre>
| 1 | 2009-07-28T21:25:17Z | [
"python",
"import",
"folder",
"shared"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,196,898 | <p>As S.Lott said, the best approach is to set the PYTHONPATH environment variable. I don't have a windows box handy, but it would look something like this from your command prompt:</p>
<pre><code>c:> SET PYTHONPATH=c:\mtl12366150\test
c:> python
>>> import mymodule
>>>
</code></pre>
| -1 | 2009-07-28T21:38:26Z | [
"python",
"import",
"folder",
"shared"
] |
How to import python module in a shared folder? | 1,196,708 | <p>I have some python modules in a shared folder on a Windows machine. </p>
<p>The file is \mtl12366150\test\mymodule.py</p>
<p>os.path.exists tells me this path is valid.</p>
<p>I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid).</p>
<p>When I try to import mymodul... | 0 | 2009-07-28T21:01:47Z | 1,200,216 | <p>I think I found the answer. I was using Python 2.6.1 and with Python 2.6.2 it now works. I had the same faulty behavior with python 2.5.4.</p>
| 0 | 2009-07-29T13:21:13Z | [
"python",
"import",
"folder",
"shared"
] |
Passing a Django model attribute name to a function | 1,197,042 | <p>I'd like to build a function in Django that iterates over a set of objects in a queryset and does something based on the value of an arbitrary attribute. The type of the objects is fixed; let's say they're guaranteed to be from the Comment model, which looks like this:</p>
<pre><code>class Comment(models.Model):
... | 1 | 2009-07-28T22:12:15Z | 1,197,061 | <p>You don't make clear what you want to return from your function, so substitute a suitable <code>return</code> statement. I assume <code>attribute</code> will be set to one of "name", "text" or "email".</p>
<pre><code>def do_something(attribute, objects):
for o in objects:
print getattr(o, attribute)
... | 1 | 2009-07-28T22:16:43Z | [
"python",
"django"
] |
Passing a Django model attribute name to a function | 1,197,042 | <p>I'd like to build a function in Django that iterates over a set of objects in a queryset and does something based on the value of an arbitrary attribute. The type of the objects is fixed; let's say they're guaranteed to be from the Comment model, which looks like this:</p>
<pre><code>class Comment(models.Model):
... | 1 | 2009-07-28T22:12:15Z | 1,197,086 | <pre><code>def do_something(attribute, objects):
results = []
for object in objects:
if hasattr(object, attribute):
results.append(getattr(object, attribute))
return results
</code></pre>
<p>Or, more succinctly,</p>
<pre><code>def do_something(attribute, objects):
return [getattr(o... | 4 | 2009-07-28T22:22:19Z | [
"python",
"django"
] |
Passing a Django model attribute name to a function | 1,197,042 | <p>I'd like to build a function in Django that iterates over a set of objects in a queryset and does something based on the value of an arbitrary attribute. The type of the objects is fixed; let's say they're guaranteed to be from the Comment model, which looks like this:</p>
<pre><code>class Comment(models.Model):
... | 1 | 2009-07-28T22:12:15Z | 1,197,088 | <p>If you're only doing stuff with a single attribute, you can use .values_list(), which is more performant since you're not instantiating whole objects, and you're only pulling the specific value you're using from the database.</p>
<pre><code>>>> def do_something(values):
... for value in values:
... ... | 4 | 2009-07-28T22:22:29Z | [
"python",
"django"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 1,197,292 | <p>You don't mention what environment you're running in, which makes a big difference because there isn't a pure Python web browser that's capable of rendering HTML.</p>
<p>But if you're using a Mac, I've used <a href="http://www.paulhammond.org/webkit2png/" rel="nofollow">webkit2png</a> with great success. If not, a... | 0 | 2009-07-28T23:28:08Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 1,197,604 | <p>On the Mac, there's <a href="http://www.paulhammond.org/webkit2png/">webkit2png</a> and on Linux+KDE, you can use <a href="http://khtml2png.sourceforge.net/">khtml2png</a>. I've tried the former and it works quite well, and heard of the latter being put to use. </p>
<p>I recently came across <a href="http://www.b... | 7 | 2009-07-29T01:12:48Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 1,198,024 | <p>I can't comment on ars's answer, but I actually got <a href="http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/" rel="nofollow">Roland Tapken's code</a> running using QtWebkit and it works quite well. </p>
<p>Just wanted to confirm that what Roland pos... | 5 | 2009-07-29T04:19:46Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 12,031,316 | <p>Here is a simple solution using webkit:
<a href="http://webscraping.com/blog/Webpage-screenshots-with-webkit/">http://webscraping.com/blog/Webpage-screenshots-with-webkit/</a></p>
<pre><code>import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
class Screenshot(QW... | 29 | 2012-08-20T01:21:49Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 18,068,097 | <p>Here is my solution by grabbing help from various sources. It takes full web page screen capture and it crops it (optional) and generates thumbnail from the cropped image also. Following are the requirements:</p>
<p>Requirements:</p>
<ol>
<li>Install NodeJS</li>
<li>Using Node's package manager install phantomjs: ... | 24 | 2013-08-05T21:30:57Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
How can I take a screenshot/image of a website using Python? | 1,197,172 | <p>What I want to achieve is to get a website screenshot from any website in python.</p>
<p>Env: Linux</p>
| 26 | 2009-07-28T22:48:13Z | 20,045,102 | <p>Try this.. </p>
<pre><code>#!/usr/bin/env python
import gtk.gdk
import time
import random
while 1 :
# generate a random time between 120 and 300 sec
random_time = random.randrange(120,300)
# wait between 120 and 300 seconds (or between 2 and 5 minutes)
print "Next picture in: %.2f minutes" % (f... | -1 | 2013-11-18T10:09:39Z | [
"python",
"screenshot",
"webpage",
"backend"
] |
Matching blank lines with regular expressions | 1,197,600 | <p>I've got a string that I'm trying to split into chunks based on blank lines.</p>
<p>Given a string <code>s</code>, I thought I could do this:</p>
<pre><code>re.split('(?m)^\s*$', s)
</code></pre>
<p>This works in some cases:</p>
<pre><code>>>> s = 'foo\nbar\n \nbaz'
>>> re.split('(?m)^\s*$', s)... | 5 | 2009-07-29T01:12:14Z | 1,197,638 | <p>What you're doing wrong is using regular expressions. What is wrong with ('Some\ntext.').split('\n')?</p>
| -1 | 2009-07-29T01:29:14Z | [
"python",
"regex"
] |
Matching blank lines with regular expressions | 1,197,600 | <p>I've got a string that I'm trying to split into chunks based on blank lines.</p>
<p>Given a string <code>s</code>, I thought I could do this:</p>
<pre><code>re.split('(?m)^\s*$', s)
</code></pre>
<p>This works in some cases:</p>
<pre><code>>>> s = 'foo\nbar\n \nbaz'
>>> re.split('(?m)^\s*$', s)... | 5 | 2009-07-29T01:12:14Z | 1,197,642 | <p>Try this instead:</p>
<pre><code>re.split('\n\s*\n', s)
</code></pre>
<p>The problem is that "$ *^" actually only matches "spaces (if any) that are alone on a line"--not the newlines themselves. This leaves the delimiter empty when there's nothing on the line, which doesn't make sense.</p>
<p>This version also g... | 16 | 2009-07-29T01:29:46Z | [
"python",
"regex"
] |
Matching blank lines with regular expressions | 1,197,600 | <p>I've got a string that I'm trying to split into chunks based on blank lines.</p>
<p>Given a string <code>s</code>, I thought I could do this:</p>
<pre><code>re.split('(?m)^\s*$', s)
</code></pre>
<p>This works in some cases:</p>
<pre><code>>>> s = 'foo\nbar\n \nbaz'
>>> re.split('(?m)^\s*$', s)... | 5 | 2009-07-29T01:12:14Z | 1,197,644 | <p>Is this what you want?</p>
<pre><code>>>> s = 'foo\nbar\n\nbaz'
>>> re.split('\n\s*\n',s)
['foo\nbar', 'baz']
>>> s = 'foo\nbar\n \nbaz'
>>> re.split('\n\s*\n',s)
['foo\nbar', 'baz']
>>> s = 'foo\nbar\n\t\nbaz'
>>> re.split('\n\s*\n',s)
['foo\nbar', 'baz']
</c... | 0 | 2009-07-29T01:31:11Z | [
"python",
"regex"
] |
Matching blank lines with regular expressions | 1,197,600 | <p>I've got a string that I'm trying to split into chunks based on blank lines.</p>
<p>Given a string <code>s</code>, I thought I could do this:</p>
<pre><code>re.split('(?m)^\s*$', s)
</code></pre>
<p>This works in some cases:</p>
<pre><code>>>> s = 'foo\nbar\n \nbaz'
>>> re.split('(?m)^\s*$', s)... | 5 | 2009-07-29T01:12:14Z | 15,831,927 | <p>The re library can split on one or more empty lines ! An empty line is a string that consists of zero or more whitespaces, starts at the start of the line and ends at the end of a line. Special character '$' matches the end of the string or just before the newline at the end of the string, and in MULTILINE mode als... | 1 | 2013-04-05T10:46:27Z | [
"python",
"regex"
] |
Matching blank lines with regular expressions | 1,197,600 | <p>I've got a string that I'm trying to split into chunks based on blank lines.</p>
<p>Given a string <code>s</code>, I thought I could do this:</p>
<pre><code>re.split('(?m)^\s*$', s)
</code></pre>
<p>This works in some cases:</p>
<pre><code>>>> s = 'foo\nbar\n \nbaz'
>>> re.split('(?m)^\s*$', s)... | 5 | 2009-07-29T01:12:14Z | 33,071,992 | <p><strong>Try this:</strong></p>
<pre><code>blank=''
with open('fu.txt') as txt:
txt=txt.read().split('\n')
for line in txt:
if line is blank: print('blank')
else: print(line)
</code></pre>
| 0 | 2015-10-12T01:34:08Z | [
"python",
"regex"
] |
CopyBlock tag for Django | 1,197,650 | <p>How can I write a tag "copyblock" for Django templates?</p>
<p>For such a function:</p>
<pre><code><title> {% block title %} some title... {% endblock %} </title>
<h1>{% copyblock title %}</h1>
</code></pre>
| 0 | 2009-07-29T01:32:34Z | 1,197,694 | <p>Take a look at the solutions mentioned in this question:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/511067/how-to-repeat-a-block-in-a-django-template">http://stackoverflow.com/questions/511067/how-to-repeat-a-block-in-a-django-template</a></li>
</ul>
| 1 | 2009-07-29T01:48:15Z | [
"python",
"django",
"templates",
"django-templates"
] |
CopyBlock tag for Django | 1,197,650 | <p>How can I write a tag "copyblock" for Django templates?</p>
<p>For such a function:</p>
<pre><code><title> {% block title %} some title... {% endblock %} </title>
<h1>{% copyblock title %}</h1>
</code></pre>
| 0 | 2009-07-29T01:32:34Z | 1,197,722 | <p>Django's template parser doesn't expose blocks by name. Instead, they are organized into a tree structure in the Django <code>Template</code>'s <code>nodelist</code>, with rendering <code>push</code>ing and <code>pop</code>ping on the stack of template nodes. You'll have a nearly impossible time accessing them in th... | 1 | 2009-07-29T02:02:50Z | [
"python",
"django",
"templates",
"django-templates"
] |
Actions triggered by field change in Django | 1,197,674 | <p>How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model:</p>
<pre><code>class Game(models.Model):
STATE_CHOICES = (
('S', 'Setup'),
('A', 'Active'),
('P', 'Paused'),
('F', 'Finished')
)
name = models.CharF... | 19 | 2009-07-29T01:42:07Z | 1,197,708 | <p>Django has a nifty feature called <a href="http://docs.djangoproject.com/en/dev/topics/signals/">signals</a>, which are effectively triggers that are set off at specific times:</p>
<ul>
<li>Before/after a model's save method is called</li>
<li>Before/after a model's delete method is called</li>
<li>Before/after an ... | 11 | 2009-07-29T01:56:36Z | [
"python",
"django",
"django-models"
] |
Actions triggered by field change in Django | 1,197,674 | <p>How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model:</p>
<pre><code>class Game(models.Model):
STATE_CHOICES = (
('S', 'Setup'),
('A', 'Active'),
('P', 'Paused'),
('F', 'Finished')
)
name = models.CharF... | 19 | 2009-07-29T01:42:07Z | 1,197,738 | <p>Basically, you need to override the <code>save</code> method, check if the <code>state</code> field was changed, set <code>started</code> if needed and then let the model base class finish persisting to the database.</p>
<p>The tricky part is figuring out if the field was changed. Check out the mixins and other so... | 8 | 2009-07-29T02:07:19Z | [
"python",
"django",
"django-models"
] |
Actions triggered by field change in Django | 1,197,674 | <p>How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model:</p>
<pre><code>class Game(models.Model):
STATE_CHOICES = (
('S', 'Setup'),
('A', 'Active'),
('P', 'Paused'),
('F', 'Finished')
)
name = models.CharF... | 19 | 2009-07-29T01:42:07Z | 1,198,061 | <p>One way is to add a setter for the state. It's just a normal method, nothing special.</p>
<pre><code>class Game(models.Model):
# ... other code
def set_state(self, newstate):
if self.state != newstate:
oldstate = self.state
self.state = newstate
if oldstate == 'S'... | 5 | 2009-07-29T04:35:04Z | [
"python",
"django",
"django-models"
] |
Actions triggered by field change in Django | 1,197,674 | <p>How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model:</p>
<pre><code>class Game(models.Model):
STATE_CHOICES = (
('S', 'Setup'),
('A', 'Active'),
('P', 'Paused'),
('F', 'Finished')
)
name = models.CharF... | 19 | 2009-07-29T01:42:07Z | 14,226,105 | <p>@dcramer came up with a more elegant solution (in my opinion) for this issue.</p>
<p><a href="https://gist.github.com/730765" rel="nofollow">https://gist.github.com/730765</a></p>
<pre class="lang-py prettyprint-override"><code>from django.db.models.signals import post_init
def track_data(*fields):
"""
Tr... | 3 | 2013-01-08T23:51:43Z | [
"python",
"django",
"django-models"
] |
Actions triggered by field change in Django | 1,197,674 | <p>How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model:</p>
<pre><code>class Game(models.Model):
STATE_CHOICES = (
('S', 'Setup'),
('A', 'Active'),
('P', 'Paused'),
('F', 'Finished')
)
name = models.CharF... | 19 | 2009-07-29T01:42:07Z | 25,503,326 | <p>It has been answered, but here's an example of using signals, post_init and post_save.</p>
<pre><code>class MyModel(models.Model):
state = models.IntegerField()
previous_state = None
@staticmethod
def post_save(sender, **kwargs):
instance = kwargs.get('instance')
created = kwargs.ge... | 6 | 2014-08-26T10:15:19Z | [
"python",
"django",
"django-models"
] |
Convert html entities to ascii in Python | 1,197,981 | <p>I need to convert any html entity into its ASCII equivalent using Python. My use case is that I am cleaning up some HTML used to build emails to create plaintext emails from the HTML. </p>
<p>Right now, I only really know how to create unicode from these entities when I need ASCII (I think) so that the plaintext em... | 4 | 2009-07-29T04:00:35Z | 1,198,002 | <p>ASCII is the American Standard Code for Information Interchange and does <strong>not</strong> include any accented letters. Your best bet is to get Unicode (as you say you can) and encode it as UTF-8 (maybe ISO-8859-1 or some weird codepage if you're dealing with seriously badly coded user-agents/clients, sigh) -- t... | 2 | 2009-07-29T04:10:44Z | [
"python",
"ascii"
] |
Convert html entities to ascii in Python | 1,197,981 | <p>I need to convert any html entity into its ASCII equivalent using Python. My use case is that I am cleaning up some HTML used to build emails to create plaintext emails from the HTML. </p>
<p>Right now, I only really know how to create unicode from these entities when I need ASCII (I think) so that the plaintext em... | 4 | 2009-07-29T04:00:35Z | 1,198,004 | <p>You can use the <a href="http://docs.python.org/library/htmllib.html#module-htmlentitydefs" rel="nofollow">htmlentitydefs</a> package:</p>
<pre><code>import htmlentitydefs
print htmlentitydefs.entitydefs['aacute']
</code></pre>
<p>Basically, <code>entitydefs</code> is just a dictionary, and you can see this by pri... | 1 | 2009-07-29T04:10:45Z | [
"python",
"ascii"
] |
Convert html entities to ascii in Python | 1,197,981 | <p>I need to convert any html entity into its ASCII equivalent using Python. My use case is that I am cleaning up some HTML used to build emails to create plaintext emails from the HTML. </p>
<p>Right now, I only really know how to create unicode from these entities when I need ASCII (I think) so that the plaintext em... | 4 | 2009-07-29T04:00:35Z | 1,582,036 | <p>Here is a complete implementation that also handles unicode html entities. You might find it useful.</p>
<p>It returns a unicode string that is not ascii, but if you want plain ascii, you can modify the replace operations so that it replaces the entities to empty string.</p>
<pre><code>def convert_html_entities(s)... | 8 | 2009-10-17T11:53:40Z | [
"python",
"ascii"
] |
Convert html entities to ascii in Python | 1,197,981 | <p>I need to convert any html entity into its ASCII equivalent using Python. My use case is that I am cleaning up some HTML used to build emails to create plaintext emails from the HTML. </p>
<p>Right now, I only really know how to create unicode from these entities when I need ASCII (I think) so that the plaintext em... | 4 | 2009-07-29T04:00:35Z | 3,429,309 | <p>We put up a little module with agazso's function:</p>
<p><a href="http://github.com/ARTFL/util/blob/master/ents.py" rel="nofollow">http://github.com/ARTFL/util/blob/master/ents.py</a></p>
<p>We find agazso's function to faster than the alternatives for ent conversion. Thanks for posting it.</p>
| 0 | 2010-08-07T05:56:44Z | [
"python",
"ascii"
] |
Why is wxGridSizer much slower to initialize on a wxDialog then on a wxFrame? | 1,198,067 | <p>It seems that this is specific to windows, here is an example that reproduces the effect:</p>
<pre><code>import wx
def makegrid(window):
grid = wx.GridSizer(24, 10, 1, 1)
window.SetSizer(grid)
for i in xrange(240):
cell = wx.Panel(window)
cell.SetBackgroundColour(wx.Color(i, i, i))
... | 2 | 2009-07-29T04:36:47Z | 1,204,886 | <p>I got a reply on the <a href="http://groups.google.com/group/wxPython-users/browse_thread/thread/66762899a9f3b697#" rel="nofollow">wxPython-users mailing list</a>, the problem can be fixed by calling <code>Layout</code> explicitly before the dialog is shown.</p>
<blockquote>
<p>This is really weird...</p>
<p... | 2 | 2009-07-30T06:58:31Z | [
"python",
"windows",
"wxpython"
] |
Python: How to get rid of circular dependency involving decorator? | 1,198,188 | <p>I had got a following case of circular import (here severly simplified):</p>
<p><code>array2image.py</code> conversion module:</p>
<pre><code>import tuti
@tuti.log_exec_time # can't do that, evaluated at definition time
def convert(arr):
'''Convert array to image.'''
return image.fromarray(arr)
</code></p... | 1 | 2009-07-29T05:31:20Z | 1,198,225 | <p>The answer you came up with is a valid solution. </p>
<p>However, if you were that worried about circular dependencies, I would say that log_exec_time would belong in its own file since its not dependent on anything else in tuti.py.</p>
| 4 | 2009-07-29T05:45:20Z | [
"python",
"import",
"decorator",
"circular"
] |
Tkinter locks python when Icon loaded and tk.mainloop in a thread | 1,198,262 | <p>Here's the test case...</p>
<pre>
import Tkinter as tk
import thread
from time import sleep
if __name__ == '__main__':
t = tk.Tk()
thread.start_new_thread(t.mainloop, ())
# t.iconbitmap('icon.ico')
b = tk.Button(text='test', command=exit)
b.grid(row=0)
while 1:
sleep(1)
</pre>
<p>... | 5 | 2009-07-29T05:57:59Z | 1,198,288 | <p>I believe you should not execute the main loop on a different thread. AFAIK, the main loop should be executed on the same thread that created the widget. </p>
<p>The GUI toolkits that I am familiar with (Tkinter, .NET Windows Forms) are that way: You can manipulate the GUI from one thread only.</p>
<p>On Linux, yo... | 15 | 2009-07-29T06:09:46Z | [
"python",
"winapi",
"tkinter",
"green-threads"
] |
How to set the encoding for the tables' char columns in django? | 1,198,486 | <p>I have a project written in Django. All fields that are supposed to store some strings are supposed to be in UTF-8, however, when I run</p>
<pre><code>manage.py syncdb
</code></pre>
<p>all respective columns are created with cp1252 character set (where did it get that -- I have no idea) and I have to manually upda... | 10 | 2009-07-29T07:07:51Z | 1,198,655 | <p>Djangoâs database backends automatically handles Unicode strings into the appropriate encoding and talk to the database. You donât need to tell Django what encoding your database uses. It handles it well, by using you database's encoding.</p>
<p>I don't see any way you can tell django to create a column, using ... | 4 | 2009-07-29T07:54:10Z | [
"python",
"mysql",
"django"
] |
How to set the encoding for the tables' char columns in django? | 1,198,486 | <p>I have a project written in Django. All fields that are supposed to store some strings are supposed to be in UTF-8, however, when I run</p>
<pre><code>manage.py syncdb
</code></pre>
<p>all respective columns are created with cp1252 character set (where did it get that -- I have no idea) and I have to manually upda... | 10 | 2009-07-29T07:07:51Z | 1,198,663 | <p>What is your MySQL encoding set to?</p>
<p>For example, try the following from the command line:</p>
<pre><code> mysqld --verbose --help | grep character-set
</code></pre>
<p>If it doesn't output utf8, then you'll need to set the output in my.cnf:</p>
<pre><code>[mysqld]
character-set-server=utf8
default-collati... | 2 | 2009-07-29T07:55:56Z | [
"python",
"mysql",
"django"
] |
How to set the encoding for the tables' char columns in django? | 1,198,486 | <p>I have a project written in Django. All fields that are supposed to store some strings are supposed to be in UTF-8, however, when I run</p>
<pre><code>manage.py syncdb
</code></pre>
<p>all respective columns are created with cp1252 character set (where did it get that -- I have no idea) and I have to manually upda... | 10 | 2009-07-29T07:07:51Z | 1,198,675 | <p>Django does not specify charset and collation in <code>CREATE TABLE</code> statements. Everything is determined by database charset. Doing <code>ALTER DATABASE ... CHARACTER SET utf8 COLLATE utf8_general_ci</code> before running <code>syncdb</code> should help.</p>
<p>For connection, Django issues <code>SET NAMES u... | 15 | 2009-07-29T07:59:37Z | [
"python",
"mysql",
"django"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,552 | <p>I would be interested in seeing a more Pythonic way of doing this also. But this is a crappy solution. You would need to add checking for an empry index list.</p>
<p>Something along the lines of:</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
output = []
prev = 0
for index in indexes:
output.append(li... | 5 | 2009-07-29T07:28:04Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,575 | <p>This is all that I could think of</p>
<pre><code>def partition(list_, indexes):
if indexes[0] != 0:
indexes = [0] + indexes
if indexes[-1] != len(list_):
indexes = indexes + [len(list_)]
return [ list_[a:b] for (a,b) in zip(indexes[:-1], indexes[1:])]
</code></pre>
| 0 | 2009-07-29T07:32:07Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,585 | <p>My solution is similar to Il-Bhima's.</p>
<pre><code>>>> def parts(list_, indices):
... indices = [0]+indices+[len(list_)]
... return [list_[v:indices[k+1]] for k, v in enumerate(indices[:-1])]
</code></pre>
<h2>Alternative approach</h2>
<p>If you're willing to slightly change the way you input i... | 6 | 2009-07-29T07:35:18Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,615 | <p>The plural of index is indices. Going for simplicity/readability.</p>
<pre><code>indices = [5, 12, 17]
input = range(20)
output = []
for i in reversed(indices):
output.append(input[i:])
input[i:] = []
output.append(input)
while len(output):
print output.pop()
</code></pre>
| -1 | 2009-07-29T07:43:52Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,739 | <p>Cide's makes three copies of the array: [0]+indices copies, ([0]+indices)+[] copies again, and indices[:-1] will copy a third time. Il-Bhima makes five copies. (I'm not counting the return value, of course.)</p>
<p>Those could be reduced (izip, islice), but here's a zero-copy version:</p>
<pre><code>def iterate_... | 0 | 2009-07-29T08:20:00Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,757 | <pre><code>indices = [5, 12, 17]
input = range(20)
output = []
reduce(lambda x, y: output.append(input[x:y]) or y, indices + [len(input)], 0)
print output
</code></pre>
| 1 | 2009-07-29T08:24:49Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,198,876 | <p>This is the simplest and most pythonic solution I can think of:</p>
<pre><code>def partition(alist, indices):
return [alist[i:j] for i, j in zip([0]+indices, indices+[None])]
</code></pre>
<p>if the inputs are very large, then the iterators solution should be more convenient:</p>
<pre><code>from itertools imp... | 36 | 2009-07-29T08:55:27Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,201,494 | <p>Here's yet another answer.</p>
<pre><code>def partition(l, indexes):
result, indexes = [], indexes+[len(l)]
reduce(lambda x, y: result.append(l[x:y]) or y, indexes, 0)
return result
</code></pre>
<p>It supports negative indexes and such.</p>
<pre><code>>>> partition([1,2,3,4,5], [1, -1])
[[1]... | 0 | 2009-07-29T16:31:57Z | [
"python",
"list"
] |
Split a list into parts based on a set of indexes in Python | 1,198,512 | <p>What is the best way to split a list into parts based on an arbitrary number of indexes? E.g. given the code below</p>
<pre><code>indexes = [5, 12, 17]
list = range(20)
</code></pre>
<p>return something like this</p>
<pre><code>part1 = list[:5]
part2 = list[5:12]
part3 = list[12:17]
part4 = list[17:]
</code></pre... | 33 | 2009-07-29T07:16:24Z | 1,204,323 | <pre><code>>>> def burst_seq(seq, indices):
... startpos = 0
... for index in indices:
... yield seq[startpos:index]
... startpos = index
... yield seq[startpos:]
...
>>> list(burst_seq(range(20), [5, 12, 17]))
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16], [17, ... | 2 | 2009-07-30T03:32:12Z | [
"python",
"list"
] |
django one to many issue at the admin panel | 1,198,589 | <p>Greetings, I have these 2 models:</p>
<pre><code>from django.db import models
class Office(models.Model):
name = models.CharField(max_length=30)
person = models.CharField(max_length=30)
phone = models.CharField(max_length=20)
fax = models.CharField(max_length=20)
address = models.CharField(max_... | -2 | 2009-07-29T07:35:41Z | 1,198,603 | <p>I'm not sure if I'm misunderstanding you, but your models currently say "an office can be associated with many provinces, but each province may only have one office". This contradicts what you want. Use a ManyToMany field instead:</p>
<pre><code>class Province(models.Model):
numberPlate = models.IntegerField(pr... | 2 | 2009-07-29T07:40:54Z | [
"python",
"django",
"django-models",
"django-admin"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 1,198,788 | <p>Gee, I guess I found the anwser: I was not taking care enough about which loop is inner and which is outer. The list comprehension should be like:</p>
<pre><code>[x for b in a for x in b]
</code></pre>
<p>to get the desired result, and yes, one current value can be the iterator for the next loop :-). Sorry for the... | 44 | 2009-07-29T08:34:28Z | [
"python",
"list-comprehension"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 1,198,794 | <p>To answer your question with your own suggestion:</p>
<pre><code>>>> [x for b in a for x in b] # Works fine
</code></pre>
<p>While you asked for list comprehension answers, let me also point out the excellent itertools.chain():</p>
<pre><code>>>> from itertools import chain
>>> list(cha... | 74 | 2009-07-29T08:36:21Z | [
"python",
"list-comprehension"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 26,480,506 | <p>ThomasH has already added a good answer, but I want to show what happens:</p>
<pre><code>>>> a = [[1, 2], [3, 4]]
>>> [x for x in b for b in a]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> [x for b in a for x ... | 10 | 2014-10-21T06:47:04Z | [
"python",
"list-comprehension"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 28,941,994 | <p>I feel this is easier to understand</p>
<pre><code>[row[i] for row in a for i in range(len(a))]
result: [1, 2, 3, 4]
</code></pre>
| 1 | 2015-03-09T12:27:20Z | [
"python",
"list-comprehension"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 36,734,643 | <p>I hope this helps someone else since <code>a,b,x,y</code> don't have much meaning to me! Suppose you have a text full of sentences and you want an array of words.</p>
<pre><code># Without list comprehension
list_of_words = []
for sentence in text:
for word in sentence:
list_of_words.append(word)
return l... | 3 | 2016-04-20T05:34:36Z | [
"python",
"list-comprehension"
] |
Double Iteration in List Comprehension | 1,198,777 | <p>In Python you can have multiple iterators in a list comprehension, like</p>
<pre><code>[(x,y) for x in a for y in b]
</code></pre>
<p>for some suitable sequences a and b. I'm aware of the nested loop semantics of Python's list comprehensions.</p>
<p>My question is: Can one iterator in the comprehension refer to t... | 75 | 2009-07-29T08:30:49Z | 39,870,492 | <p>Order of iterators may seem counter-intuitive.</p>
<p>Take for example: <code>[str(x) for i in range(3) for x in foo(i)]</code></p>
<p>Let's decompose it:</p>
<pre><code>def foo(i):
return i, i + 0.5
[str(x)
for i in range(3)
for x in foo(i)
]
# if same as
for i in range(3):
for x in foo(i):... | 1 | 2016-10-05T09:39:42Z | [
"python",
"list-comprehension"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,199,093 | <p>Try something along the lines of:</p>
<pre><code>d = {(None,100): 0,
(100,200): 1,
...
(1000, None): 5}
value = 300 # example value
for k,v in d.items():
if (k[0] is None or value > k[0]) and (k[1] is None or value <= k[1]):
return v
</code></pre>
| 0 | 2009-07-29T09:42:34Z | [
"python",
"range",
"intervals"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,199,097 | <p>You could try a take on this:</p>
<pre><code>def check_mapping(p):
mapping = [(100, 0), (300, 1), (500, 2)] # Add all your values and returns here
for check, value in mapping:
if p <= check:
return value
print check_mapping(12)
print check_mapping(101)
print check_mapping(303)
</cod... | 3 | 2009-07-29T09:43:35Z | [
"python",
"range",
"intervals"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,199,112 | <pre><code>def which_interval(endpoints, number):
for n, endpoint in enumerate(endpoints):
if number <= endpoint:
return n
previous = endpoint
return n + 1
</code></pre>
<p>Pass your endpoints as a list in <code>endpoints</code>, like this:</p>
<pre><code>which_interval([100, 30... | 0 | 2009-07-29T09:47:46Z | [
"python",
"range",
"intervals"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,199,113 | <pre><code>import bisect
bisect.bisect_left([100,300,500,800,1000], p)
</code></pre>
| 29 | 2009-07-29T09:47:54Z | [
"python",
"range",
"intervals"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,199,299 | <p>Another way ...</p>
<pre><code>def which(lst, p):
return len([1 for el in lst if p > el])
lst = [100, 300, 500, 800, 1000]
which(lst, 2)
which(lst, 101)
which(lst, 1001)
</code></pre>
| 0 | 2009-07-29T10:34:49Z | [
"python",
"range",
"intervals"
] |
Python: Mapping from intervals to values | 1,199,053 | <p>I'm refactoring a function that, given a series of endpoints that implicitly define intervals, checks if a number is included in the interval, and then return a corresponding (not related in any computable way).
The code that is now handling the work is:</p>
<pre><code>if p <= 100:
return 0
elif p > 100 a... | 9 | 2009-07-29T09:33:42Z | 1,200,012 | <p>It is indeed quite horrible. Without a requirement to have no hardcoding, it should have been written like this:</p>
<pre><code>if p <= 100:
return 0
elif p <= 300:
return 1
elif p <= 500:
return 2
elif p <= 800:
return 3
elif p <= 1000:
return 4
else:
return 5
</code></pre>
... | 3 | 2009-07-29T12:48:31Z | [
"python",
"range",
"intervals"
] |
installed module on python editor | 1,199,249 | <p>how can i import modules/packages at python3.0 editor IDLE.
and can we see all the modules contain/included by it.</p>
| 0 | 2009-07-29T10:23:27Z | 1,199,259 | <pre><code>>>> import idle
>>> dir(idle)
</code></pre>
| 1 | 2009-07-29T10:26:43Z | [
"python",
"editor"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,199,371 | <p>Probably either a <code>dict</code> of <code>list</code> or a <code>list</code> of <code>dict</code>. Personally, I'd go with the former. So, parse the heading row of the CSV to get a <code>dict</code> from column heading to column index. Then when you're reading through each row, work out what index you're at, grab... | 0 | 2009-07-29T10:48:21Z | [
"python",
"file",
"csv"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,199,385 | <p>Python's CSV library has a <a href="http://docs.python.org/library/csv.html#csv.DictReader" rel="nofollow">function named DictReader</a> that allow you to view and manipulate the data as a Python dictionary, which allows you to use normal iterative tools.</p>
| 1 | 2009-07-29T10:51:08Z | [
"python",
"file",
"csv"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,199,396 | <p>Go with a list of lists. That is:</p>
<pre><code>[[col1, col2, col3, col4], # Row 1
[col1, col2, col3, col4], # Row 2
[col1, col2, col3, col4], # Row 3
[col1, col2, col3, col4]] # Row 4
</code></pre>
<p>To modify a specific column, you can transform this into a list of columns with a single statement:</p>
<pre... | 2 | 2009-07-29T10:52:56Z | [
"python",
"file",
"csv"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,199,409 | <p>Is SQLite an option for you? I know that you have CSV input and output. However, you can import all the data into the SQLite database. Then do all the necessary processing with the power of SQL. Then you can export the results as CSV. </p>
| 1 | 2009-07-29T10:54:41Z | [
"python",
"file",
"csv"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,199,830 | <p>Good question, I have this problem very frequently.</p>
<p>In general, to handle csv files like that, I prefer to use R which is a data.frame object specifically designed for this.</p>
<p>In python, you can have a look at this library called datamatrix:</p>
<ul>
<li><a href="http://github.com/cswegger/datamatrix/... | 0 | 2009-07-29T12:13:12Z | [
"python",
"file",
"csv"
] |
Whats the best way of putting tabular data into python? | 1,199,350 | <p>I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?</p>
<p>For eg. Assume there is a colu... | 2 | 2009-07-29T10:44:31Z | 1,200,623 | <p>Your situation is kind of vague, but I'll try to answer your question, "How do I remember the column into which a piece of data goes in the text file?"</p>
<p>One way is to store a list of rows as dictionaries. </p>
<p><em>Note: I usually use tab-delimited text files, so forgive me if I'm forgetting something abo... | 0 | 2009-07-29T14:22:31Z | [
"python",
"file",
"csv"
] |
Using Storm: ImportError: No module named local | 1,199,415 | <p>As stated in the Storm documentation, I am doing the following to import the necessary symbols for using Storm:</p>
<pre><code>from storm.locals import *
</code></pre>
<p>I'm using it alongside with Pylons, and storm is indeed installed as an egg in the virtual Python environment which Pylon setup for me, and it a... | 0 | 2009-07-29T10:56:19Z | 1,200,522 | <p>Here's the code that's failing.</p>
<pre><code>File '/home/andy/projects/evecharacters/evecharacters/controllers/characters.py', line 9 in <module>
from storm.local import *
ImportError: No module named local
</code></pre>
<p>You claim your snippet is</p>
<pre><code>from storm.locals import *
</code></pre... | 1 | 2009-07-29T14:08:22Z | [
"python",
"storm-orm"
] |
combine javascript files at deployment in python | 1,199,470 | <p>I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?</p>
| 13 | 2009-07-29T11:06:42Z | 1,199,481 | <p>Here's a Python script I made that I use with all my heavy JavaScript projects. I'm using YUICompressor, but you can change the code to use another compressor.</p>
<pre><code>import os, os.path, shutil
YUI_COMPRESSOR = 'yuicompressor-2.4.2.jar'
def compress(in_files, out_file, in_type='js', verbose=False,
... | 21 | 2009-07-29T11:09:46Z | [
"javascript",
"python",
"deployment",
"buildout",
"jscompress"
] |
combine javascript files at deployment in python | 1,199,470 | <p>I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?</p>
| 13 | 2009-07-29T11:06:42Z | 1,201,475 | <p>The <a href="http://qooxdoo.org" rel="nofollow">qooxdoo</a> project comes with a Javascript compressor written in Python. Although it's tightly integrated with the framework, you should be able to utilize the compressor component. If you get the latest SDK there is a <em>tool/bin/compile.py</em> command line tool yo... | 1 | 2009-07-29T16:29:12Z | [
"javascript",
"python",
"deployment",
"buildout",
"jscompress"
] |
combine javascript files at deployment in python | 1,199,470 | <p>I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?</p>
| 13 | 2009-07-29T11:06:42Z | 1,905,612 | <p>Combining Blixt's solution with JS Min. Here is the code:</p>
<p>Just call the <code>compress(in_files, out_file)</code> method</p>
<pre><code>import os, os.path, shutil
# This code is original from jsmin by Douglas Crockford, it was translated to
# Python by Baruch Even. The original code had the following copyr... | 6 | 2009-12-15T06:46:24Z | [
"javascript",
"python",
"deployment",
"buildout",
"jscompress"
] |
combine javascript files at deployment in python | 1,199,470 | <p>I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?</p>
| 13 | 2009-07-29T11:06:42Z | 5,109,788 | <p>A slightly different take on the solution proposed by Rushabh. Rather than a file based compress function, this is string based and somewhat simpler:</p>
<pre><code>def jsmerge(file_names, debug=False):
"""combines several js files together, with optional minification"""
js = ""
for file_name in file_names:
js ... | 0 | 2011-02-24T20:01:11Z | [
"javascript",
"python",
"deployment",
"buildout",
"jscompress"
] |
combine javascript files at deployment in python | 1,199,470 | <p>I'm trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and compressing scripts with buildout?</p>
| 13 | 2009-07-29T11:06:42Z | 19,655,315 | <p>If you're using WSGI middleware you could also use <a href="http://www.fanstatic.org/en/1.0a3/index.html" rel="nofollow">Fanstatic</a>. It's probably some more work to integrate it into your stack than "simply" changing something in Buildout. The things you get with Fanstatic on the other hand are pretty good. It al... | 1 | 2013-10-29T10:17:26Z | [
"javascript",
"python",
"deployment",
"buildout",
"jscompress"
] |
How to distribute and execute platform-specific unit tests? | 1,199,493 | <p>We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests that should pass on platforms A, B, C and tests that pass on B a... | 5 | 2009-07-29T11:13:10Z | 1,199,671 | <p>Sounds like a handy place for a test loader.</p>
<p>Check out <a href="http://docs.python.org/library/unittest.html#unittest.TestLoader.loadTestsFromName" rel="nofollow">http://docs.python.org/library/unittest.html#unittest.TestLoader.loadTestsFromName</a></p>
<p>If you provide some suitable naming conventions yo... | 0 | 2009-07-29T11:44:31Z | [
"python",
"unit-testing",
"buildbot"
] |
How to distribute and execute platform-specific unit tests? | 1,199,493 | <p>We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests that should pass on platforms A, B, C and tests that pass on B a... | 5 | 2009-07-29T11:13:10Z | 1,199,767 | <p>On a couple of occasions I have used this very simple approach in test modules:</p>
<pre><code>import sys
import unittest
if 'win' in sys.platform:
class TestIt(unittest.TestCase):
...
if 'linux' in sys.platform:
class TestIt(unittest.TestCase):
...
</code></pre>
| 2 | 2009-07-29T12:01:48Z | [
"python",
"unit-testing",
"buildbot"
] |
How to distribute and execute platform-specific unit tests? | 1,199,493 | <p>We have a python project that we want to start testing using buildbot. Its unit tests include tests that should only work on some platforms. So, we've got tests that should pass on all platforms, tests that should only run on 1 specific platform, tests that should pass on platforms A, B, C and tests that pass on B a... | 5 | 2009-07-29T11:13:10Z | 1,371,766 | <p>We've decided to go with decorators that, using platform module and others, check whether the tests should be executed, and if not simply let it pass (though, we saw that python2.7 already has in its trunk a SkipTest exception that could be raised in such cases, to ignore the test).</p>
| 0 | 2009-09-03T06:50:32Z | [
"python",
"unit-testing",
"buildbot"
] |
How do I use Python serverside with shared hosting? | 1,199,703 | <p>I've been told by my hosting company that Python is installed on their servers. How would I go about using it to output a simple HTML page? This is just as a learning exercise at the moment, but one day I'd like to use Python in the same way as I currently use PHP.</p>
| 3 | 2009-07-29T11:49:50Z | 1,199,738 | <p>There are many ways you could do this: assuming the server architecture supports the <a href="http://www.python.org/dev/peps/pep-0333/" rel="nofollow">WSGI</a> standard, then you could do something as simple as plugging in your own handler to generate the HTML (this could just build a string manually if you want to ... | 2 | 2009-07-29T11:57:11Z | [
"python",
"server-side"
] |
How do I use Python serverside with shared hosting? | 1,199,703 | <p>I've been told by my hosting company that Python is installed on their servers. How would I go about using it to output a simple HTML page? This is just as a learning exercise at the moment, but one day I'd like to use Python in the same way as I currently use PHP.</p>
| 3 | 2009-07-29T11:49:50Z | 1,199,744 | <p>If your server is running Apache HTTP server, then you need something like <strong>mod_wsgi</strong> or <strong>mod_python</strong> installed and running as a module (your server signature may tell you this).</p>
<p>Once running, you may need to add a <strong>handler</strong> to your apache config, or a default may... | 2 | 2009-07-29T11:58:08Z | [
"python",
"server-side"
] |
How do I use Python serverside with shared hosting? | 1,199,703 | <p>I've been told by my hosting company that Python is installed on their servers. How would I go about using it to output a simple HTML page? This is just as a learning exercise at the moment, but one day I'd like to use Python in the same way as I currently use PHP.</p>
| 3 | 2009-07-29T11:49:50Z | 1,199,863 | <p>You can't use it "the same way" as PHP. There are however tons of ways of doing it like Python.</p>
<p>Look into the likes of Turbogears or Django. Or BFG of you want something minimalistic, or WSGI (via mod_wsgi) if you want to go directly to the basics.</p>
<p><a href="http://www.djangoproject.com/" rel="nofollo... | 1 | 2009-07-29T12:22:48Z | [
"python",
"server-side"
] |
How do I use Python serverside with shared hosting? | 1,199,703 | <p>I've been told by my hosting company that Python is installed on their servers. How would I go about using it to output a simple HTML page? This is just as a learning exercise at the moment, but one day I'd like to use Python in the same way as I currently use PHP.</p>
| 3 | 2009-07-29T11:49:50Z | 1,199,872 | <p>When I used shared hosting I found that if I renamed the file to .py and prefixed it with a shebang line then it would be executed as Python.</p>
<pre><code>#!/usr/bin/python
</code></pre>
<p>Was probably pretty bad practice, but it did work. Don't expect to be able to spit out any extensive web apps with it thoug... | 3 | 2009-07-29T12:24:50Z | [
"python",
"server-side"
] |
Google app engine - structuring model layout with regards to parents? | 1,199,713 | <p>How does one go about structuring his db.Models effectively?</p>
<p>For instance, lets say I have a model for Countries, with properties like "name, northern_hemisphere(boolean), population, states (list of states), capital(boolean).</p>
<p>And another model called State or county or something with properties "nam... | 1 | 2009-07-29T11:52:42Z | 1,199,742 | <p>If you want to store relational data in the datastore of Google App Engine, this is a great article to start out with: <a href="http://code.google.com/appengine/articles/modeling.html" rel="nofollow">Modeling Entity Relationships</a>.</p>
<p>You use <a href="http://code.google.com/appengine/docs/python/datastore/ty... | 4 | 2009-07-29T11:57:51Z | [
"python",
"google-app-engine",
"django-models"
] |
importing modules with submodules from deep in a library | 1,199,743 | <p>here at office we have a library named after the company name and inside of it sublibraries, per project more or less, and in each sublibrary there might be more modules or libraries. we are using Django and this makes our hierarchy a couple of steps deeper...</p>
<p>I am a bit perplex about the differences among ... | 0 | 2009-07-29T11:58:04Z | 1,199,846 | <p>The three examples above are all equivalent in practice. All of them are weird, though. There is no reason to do </p>
<pre><code>from company.productline import specific
</code></pre>
<p>and</p>
<pre><code>import company.productline.specific.models
</code></pre>
<p>You can (most of the time) just access models b... | 0 | 2009-07-29T12:16:55Z | [
"python",
"coding-style"
] |
importing modules with submodules from deep in a library | 1,199,743 | <p>here at office we have a library named after the company name and inside of it sublibraries, per project more or less, and in each sublibrary there might be more modules or libraries. we are using Django and this makes our hierarchy a couple of steps deeper...</p>
<p>I am a bit perplex about the differences among ... | 0 | 2009-07-29T11:58:04Z | 1,205,070 | <p>so I have looked into it a bit deeper, using this further useless package:</p>
<pre><code>A:(__init__.py: print 'importing A',
B:(__init__.py: print 'importing B',
C1:(__init__.py: print 'importing C1',
D:(__init__.py: print 'importing D'))
C2:(__init__.py: print 'importing C2',
D... | 0 | 2009-07-30T07:55:58Z | [
"python",
"coding-style"
] |
Cython and numpy speed | 1,199,972 | <p>I'm using cython for a correlation calculation in my python program. I have two audio data sets and I need to know the time difference between them. The second set is cut based on onset times and then slid across the first set. There are two for-loops: one slides the set and the inner loop calculates correlation at ... | 13 | 2009-07-29T12:39:52Z | 1,200,064 | <p>The trick with this sort of thing is to find a way to divide and conquer.</p>
<p>Currently, you're sliding to every position and check every point at every position -- effectively an <strong>O</strong>( n ^ 2 ) operation.</p>
<p>You need to reduce the check of <em>every</em> point and the comparison of <em>every</... | 2 | 2009-07-29T12:58:22Z | [
"python",
"numpy",
"cython"
] |
Cython and numpy speed | 1,199,972 | <p>I'm using cython for a correlation calculation in my python program. I have two audio data sets and I need to know the time difference between them. The second set is cut based on onset times and then slid across the first set. There are two for-loops: one slides the set and the inner loop calculates correlation at ... | 13 | 2009-07-29T12:39:52Z | 1,200,096 | <ul>
<li>you can extract range(size2) from the external loop</li>
<li>you can use sum() instead of a loop to compute current_correlation</li>
<li>you can store correlations and delays in a list and then use max() to get the biggest one</li>
</ul>
| 2 | 2009-07-29T13:04:13Z | [
"python",
"numpy",
"cython"
] |
Cython and numpy speed | 1,199,972 | <p>I'm using cython for a correlation calculation in my python program. I have two audio data sets and I need to know the time difference between them. The second set is cut based on onset times and then slid across the first set. There are two for-loops: one slides the set and the inner loop calculates correlation at ... | 13 | 2009-07-29T12:39:52Z | 1,228,914 | <p><strong>Edit:</strong><br>
There's now <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html" rel="nofollow"><code>scipy.signal.fftconvolve</code></a> which would be the preferred approach to doing the FFT based convolution approach that I describe below. I'll leave the original... | 35 | 2009-08-04T17:40:00Z | [
"python",
"numpy",
"cython"
] |
Django CharField limitations | 1,200,046 | <p>how can I specify a blacklist for a CharField. However I want the blacklist to be effective in the Django admin panel aswell...otherwise I would just validate it in the view.</p>
<p>By blacklist I mean values that can't be used. I also set unique for the value but I would like to disable a few strings aswell.</p>
... | 1 | 2009-07-29T12:54:25Z | 1,200,069 | <p>This is not possible out of the box. You would have to write a <a href="http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation" rel="nofollow">custom form field</a> or otherwise add <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get%5Furls" r... | 0 | 2009-07-29T12:59:15Z | [
"python",
"django"
] |
Django CharField limitations | 1,200,046 | <p>how can I specify a blacklist for a CharField. However I want the blacklist to be effective in the Django admin panel aswell...otherwise I would just validate it in the view.</p>
<p>By blacklist I mean values that can't be used. I also set unique for the value but I would like to disable a few strings aswell.</p>
... | 1 | 2009-07-29T12:54:25Z | 1,200,373 | <p>I would override the model's save() method and the to be inserted value against a blacklist before calling the parent class' save() method.</p>
<p>Something like that (simplified):</p>
<pre><code>class BlackListModel(models.Model):
blacklist = ['a', 'b', 'c']
# your model fields definitions...
def sa... | 1 | 2009-07-29T13:42:12Z | [
"python",
"django"
] |
Writing a Template Tag in Django | 1,200,548 | <p>I'm trying to customise a CMS written in Django. The content editors aren't flexible enough so I'm trying to come up with a better solution.</p>
<p>Without over-explaining it, I'd like it to be a bit like <a href="http://bitbucket.org/hakanw/django-better-chunks/wiki/Home" rel="nofollow">django-better-chunks</a> or... | 1 | 2009-07-29T14:12:16Z | 1,828,445 | <p>for this you can create an inclusion tag and use it like:</p>
<pre><code>{% load my_tags %}
{% product bicycle <extra vars ...> %}
</code></pre>
<p>To define the tag, add to your app/templatetags/mytags.py:</p>
<pre><code>@register.inclusion_tag('results.html')
def product(item, *extra):
#maybe repackag... | 2 | 2009-12-01T19:50:52Z | [
"python",
"django",
"django-templates"
] |
Which events can be bound to a Tkinter Frame? | 1,200,592 | <p>I am making a small application with Tkinter. I would like to clean few things in a function called when my window is closed. I am trying to bind the <em>close event</em> of my window with that function. I don't know if it is possible and what is the corresponding sequence.</p>
<p>The Python documentation says: <co... | 1 | 2009-07-29T14:18:04Z | 1,200,907 | <p>I believe <a href="http://tcl.tk/man/tcl8.5/TkCmd/bind.htm" rel="nofollow">this</a> is the bind man page you may have been looking for; I believe the event you're trying to bind is <code>Destroy</code>. <code>__del__</code> is not to be relied on (just too hard to know when a circular reference loop, e.g. parent to ... | 3 | 2009-07-29T14:59:32Z | [
"python",
"python-3.x",
"tkinter"
] |
Which events can be bound to a Tkinter Frame? | 1,200,592 | <p>I am making a small application with Tkinter. I would like to clean few things in a function called when my window is closed. I am trying to bind the <em>close event</em> of my window with that function. I don't know if it is possible and what is the corresponding sequence.</p>
<p>The Python documentation says: <co... | 1 | 2009-07-29T14:18:04Z | 1,200,931 | <p>A more-or-less definitive resource for events is the <a href="http://tcl.tk/man/tcl8.6/TkCmd/bind.htm" rel="nofollow">bind man page for Tk</a>. I'm not exactly clear what you're wanting to do, but binding on <code>"<Destroy>"</code> is probably the event you are looking for. Whether it does what you really ne... | 3 | 2009-07-29T15:02:49Z | [
"python",
"python-3.x",
"tkinter"
] |
Python wx (Python Card) logging subprocess output to window | 1,200,610 | <p>There are <a href="http://stackoverflow.com/questions/531708/logging-output-of-external-program-with-wxpython">similar</a> <a href="http://stackoverflow.com/questions/865082/python-plugging-wx-py-shell-shell-into-a-separate-process">questions</a> to this one, but I'd like to see a clarified answer. I'm building a si... | 1 | 2009-07-29T14:20:31Z | 1,200,684 | <p>Just about every subprocess you can wrap will buffer its output unless you manage to fool it into believing it's actually connected to a terminal -- and subprocess can't do that. Rather, look into <a href="http://pexpect.sourceforge.net/pexpect.html" rel="nofollow">pexpect</a> (runs well on every platform that lets ... | 1 | 2009-07-29T14:29:38Z | [
"python",
"wxpython",
"pythoncard"
] |
Python wx (Python Card) logging subprocess output to window | 1,200,610 | <p>There are <a href="http://stackoverflow.com/questions/531708/logging-output-of-external-program-with-wxpython">similar</a> <a href="http://stackoverflow.com/questions/865082/python-plugging-wx-py-shell-shell-into-a-separate-process">questions</a> to this one, but I'd like to see a clarified answer. I'm building a si... | 1 | 2009-07-29T14:20:31Z | 1,811,747 | <p>I was searching for a solution for this too. It turns out the solution is remarkably simple:
<p>
proc = subprocess.Popen("whatever program", cwd="startup dir", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
<br>
while True:
<br>
txt = proc.stdout.readline()
<br>
if not txt: break
<br>
... | 1 | 2009-11-28T06:09:12Z | [
"python",
"wxpython",
"pythoncard"
] |
python interpolation | 1,200,644 | <p>I have a set of data's as,</p>
<pre><code>Table-1
X1 | Y1
------+--------
0.1 | 0.52147
0.02 | 0.8879
0.08 | 0.901
0.11 | 1.55
0.15 | 1.82
0.152 | 1.95
Table-2
X2 | Y2
-----+------
0.2 | 0.11
0.21 | 0.112
0.34 | 0.120
0.33 | 1.121
</code></pr... | 17 | 2009-07-29T14:25:01Z | 1,200,722 | <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html">numpy.interp</a> seems to be the function you want: pass your X1 as the first argument x, your X2 as the second argument xp, your Y2 as the third argument fp, and you'll get the Y values corresponding to the X1 coordinates (looks like yo... | 25 | 2009-07-29T14:35:04Z | [
"python",
"numpy"
] |
How to get lxml working under IronPython? | 1,200,726 | <p>I need to port some code that relies heavily on lxml from a CPython application to IronPython.</p>
<p>lxml is very Pythonic and I would like to keep using it under IronPython, but it depends on libxslt and libxml2, which are C extensions.</p>
<p>Does anyone know of a workaround to allow lxml under IronPython or a ... | 6 | 2009-07-29T14:36:12Z | 1,211,395 | <p>Something which you might have already considered: </p>
<p>An alternative is to first port the lxml library to IPy and then your code (depending on the code size). You might have to write some C# wrappers for the native C calls to the C extensions -- I'm not sure what issues, if any, are involved in this with regar... | 1 | 2009-07-31T08:54:27Z | [
".net",
"xml",
"ironpython",
"python",
"lxml"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.