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 reduce color palette with PIL | 1,065,945 | <p>I'm not sure how I would go about reducing the color palette of a PIL Image. I would like to reduce an image's palette to the 5 prominent colors found in that image. My overall goal is to do some basic color sampling.</p>
| 11 | 2009-06-30T20:43:32Z | 1,067,168 | <p>I assume you want to do something more sophisticated than <a href="http://effbot.org/imagingbook/imageops.htm#tag-ImageOps.posterize" rel="nofollow">posterize</a>. "Sampling" as you say, will take some finesse, as the 5 most common colors in the image are likely to be similar to one another. Maybe take a look at t... | 1 | 2009-07-01T03:38:51Z | [
"python",
"image",
"colors",
"python-imaging-library",
"palette"
] |
How to reduce color palette with PIL | 1,065,945 | <p>I'm not sure how I would go about reducing the color palette of a PIL Image. I would like to reduce an image's palette to the 5 prominent colors found in that image. My overall goal is to do some basic color sampling.</p>
| 11 | 2009-06-30T20:43:32Z | 1,071,275 | <p>The short answer is to use the <code>Image.quantize</code> method. For more info, see: <a href="http://stackoverflow.com/questions/236692/how-do-i-convert-any-image-to-a-4-color-paletted-image-using-the-python-imaging-l">How do I convert any image to a 4-color paletted image using the Python Imaging Library ?</a></p... | 3 | 2009-07-01T20:38:53Z | [
"python",
"image",
"colors",
"python-imaging-library",
"palette"
] |
How to reduce color palette with PIL | 1,065,945 | <p>I'm not sure how I would go about reducing the color palette of a PIL Image. I would like to reduce an image's palette to the 5 prominent colors found in that image. My overall goal is to do some basic color sampling.</p>
| 11 | 2009-06-30T20:43:32Z | 1,074,680 | <p>That's easy, just use the undocumented colors argument:</p>
<pre><code>result = image.convert('P', palette=Image.ADAPTIVE, colors=5)
</code></pre>
<p>I'm using Image.ADAPTIVE to avoid dithering</p>
| 22 | 2009-07-02T14:22:06Z | [
"python",
"image",
"colors",
"python-imaging-library",
"palette"
] |
Unable to understand a statement about customizing Python's Macro Syntax | 1,065,966 | <p><a href="http://stackoverflow.com/questions/454648/pythonic-macro-syntax">Cody</a> has been building a Pythonic Macro Syntax. He says</p>
<blockquote>
<p>These macros allow you to define
completely custom syntax, from new
constructs to new operators. There's
no facility for doing this in Python
as it stan... | 1 | 2009-06-30T20:46:45Z | 1,066,027 | <p>No doubt Cody refers to completely new operators that are not currently in Python, such as (I dunno) <code>^^</code> or <code>++</code> or <code>+*</code> and so on, whatever they might mean. And he's explicitly saying that the macro system lets you define a completely new syntax <em>for Python</em> (his question wa... | 6 | 2009-06-30T20:56:42Z | [
"python",
"syntax",
"macros"
] |
Export set of data in different formats | 1,066,516 | <p>I want to be able to display set of data differently according to url parameters.</p>
<p>My URL looks like /page/{limit}/{offset}/{format}/. </p>
<p>For example:</p>
<pre><code>/page/20/0/xml/ - subset [0:20) in xml
/page/100/20/json/ - subset [20:100) in json
</code></pre>
<p>Also I want to be able to do the sa... | 1 | 2009-06-30T23:02:17Z | 1,066,621 | <p>Yes, that is a correct approach.</p>
| 0 | 2009-06-30T23:30:15Z | [
"python",
"django",
"rendering"
] |
Export set of data in different formats | 1,066,516 | <p>I want to be able to display set of data differently according to url parameters.</p>
<p>My URL looks like /page/{limit}/{offset}/{format}/. </p>
<p>For example:</p>
<pre><code>/page/20/0/xml/ - subset [0:20) in xml
/page/100/20/json/ - subset [20:100) in json
</code></pre>
<p>Also I want to be able to do the sa... | 1 | 2009-06-30T23:02:17Z | 1,066,999 | <p>I suggest having the renderer also know about the mimetype rather than hardcoding the latter in the code that calls the renderer -- better to concentrate format-specific knowledge in one place, so the calling code would be</p>
<pre><code>content, mimetype = renderer().render(data=dataset)
return HttpResponse(conten... | 1 | 2009-07-01T02:12:10Z | [
"python",
"django",
"rendering"
] |
Multiprocessing in python with more then 2 levels | 1,066,710 | <p>I want to do a program and want make a the spawn like this process -> n process -> n process</p>
<p>can the second level spawn process with multiprocessing ? using multiprocessinf module of python 2.6</p>
<p>thnx</p>
| 4 | 2009-07-01T00:01:35Z | 1,066,747 | <p>@<a href="#1066724" rel="nofollow">vilalian</a>'s answer is correct, but terse. Of course, it's hard to supply more information when your original question was vague.</p>
<p>To expand a little, you'd have your original program spawn its <code>n</code> processes, but they'd be slightly different than the original in... | 3 | 2009-07-01T00:14:09Z | [
"python",
"multiprocessing"
] |
Multiprocessing in python with more then 2 levels | 1,066,710 | <p>I want to do a program and want make a the spawn like this process -> n process -> n process</p>
<p>can the second level spawn process with multiprocessing ? using multiprocessinf module of python 2.6</p>
<p>thnx</p>
| 4 | 2009-07-01T00:01:35Z | 1,066,750 | <p>Sure you can. Expecially if you are using fork to spawn child processes, they works as perfectly normal processes (like the father). Thread management is quite different, but you can also use "second level" sub-treading. </p>
<p>Pay attention to not over-complicate your program, as example program with two level th... | 0 | 2009-07-01T00:15:06Z | [
"python",
"multiprocessing"
] |
Multiprocessing in python with more then 2 levels | 1,066,710 | <p>I want to do a program and want make a the spawn like this process -> n process -> n process</p>
<p>can the second level spawn process with multiprocessing ? using multiprocessinf module of python 2.6</p>
<p>thnx</p>
| 4 | 2009-07-01T00:01:35Z | 1,068,763 | <p>You can structure your app as a series of process pools communicating via Queues at any nested depth. Though it can get hairy pretty quick (probably due to the required context switching).</p>
<p>It's not erlang though that's for sure.</p>
<p>The docs on <a href="http://docs.python.org/dev/library/multiprocessing.... | 0 | 2009-07-01T12:00:08Z | [
"python",
"multiprocessing"
] |
Multiprocessing in python with more then 2 levels | 1,066,710 | <p>I want to do a program and want make a the spawn like this process -> n process -> n process</p>
<p>can the second level spawn process with multiprocessing ? using multiprocessinf module of python 2.6</p>
<p>thnx</p>
| 4 | 2009-07-01T00:01:35Z | 1,068,961 | <p>Yes - but, you might run into an issue which would require the fix I committed to python trunk yesterday. See bug <a href="http://bugs.python.org/issue5313" rel="nofollow">http://bugs.python.org/issue5313</a></p>
| 1 | 2009-07-01T12:41:13Z | [
"python",
"multiprocessing"
] |
find length of sequences of identical values in a numpy array | 1,066,758 | <p>In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: <code>d[t]</code> is the <em>distance</em> at time <code>t</code> (and the timespan of my data is <code>len(d)</code> time units).</p>
<p>The events I'm interested in are when the distance i... | 19 | 2009-07-01T00:19:18Z | 1,066,780 | <pre><code>durations = []
counter = 0
for bool in b:
if bool:
counter += 1
elif counter > 0:
durations.append(counter)
counter = 0
if counter > 0:
durations.append(counter)
</code></pre>
| 0 | 2009-07-01T00:31:02Z | [
"python",
"matlab",
"numpy",
"matplotlib"
] |
find length of sequences of identical values in a numpy array | 1,066,758 | <p>In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: <code>d[t]</code> is the <em>distance</em> at time <code>t</code> (and the timespan of my data is <code>len(d)</code> time units).</p>
<p>The events I'm interested in are when the distance i... | 19 | 2009-07-01T00:19:18Z | 1,066,838 | <p>While not <code>numpy</code> primitives, <code>itertools</code> functions are often very fast, so do give this one a try (and measure times for various solutions including this one, of course):</p>
<pre><code>def runs_of_ones(bits):
for bit, group in itertools.groupby(bits):
if bit: yield sum(group)
</code></... | 22 | 2009-07-01T01:04:34Z | [
"python",
"matlab",
"numpy",
"matplotlib"
] |
find length of sequences of identical values in a numpy array | 1,066,758 | <p>In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: <code>d[t]</code> is the <em>distance</em> at time <code>t</code> (and the timespan of my data is <code>len(d)</code> time units).</p>
<p>The events I'm interested in are when the distance i... | 19 | 2009-07-01T00:19:18Z | 1,066,864 | <p>Just in case anyone is curious (and since you mentioned MATLAB in passing), here's one way to solve it in MATLAB:</p>
<pre><code>threshold = 7;
d = 10*rand(1,100000); % Sample data
b = diff([false (d < threshold) false]);
durations = find(b == -1)-find(b == 1);
</code></pre>
<p>I'm not too familiar with Python... | 5 | 2009-07-01T01:15:16Z | [
"python",
"matlab",
"numpy",
"matplotlib"
] |
find length of sequences of identical values in a numpy array | 1,066,758 | <p>In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: <code>d[t]</code> is the <em>distance</em> at time <code>t</code> (and the timespan of my data is <code>len(d)</code> time units).</p>
<p>The events I'm interested in are when the distance i... | 19 | 2009-07-01T00:19:18Z | 1,068,397 | <p>Here is a solution using only arrays: it takes an array containing a sequence of bools and counts the length of the transitions.</p>
<pre><code>>>> from numpy import array, arange
>>> b = array([0,0,0,1,1,1,0,0,0,1,1,1,1,0,0], dtype=bool)
>>> sw = (b[:-1] ^ b[1:]); print sw
[False False ... | 5 | 2009-07-01T10:32:35Z | [
"python",
"matlab",
"numpy",
"matplotlib"
] |
find length of sequences of identical values in a numpy array | 1,066,758 | <p>In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: <code>d[t]</code> is the <em>distance</em> at time <code>t</code> (and the timespan of my data is <code>len(d)</code> time units).</p>
<p>The events I'm interested in are when the distance i... | 19 | 2009-07-01T00:19:18Z | 32,681,075 | <p>Fully numpy vectorized and generic RLE for any array (works with strings, booleans etc too).</p>
<p>Outputs tuple of run lengths, start positions, and values.</p>
<pre><code>import numpy as np
def rle(inarray):
""" run length encoding. Partial credit to R rle function.
Multi datatype arrays c... | 5 | 2015-09-20T15:30:43Z | [
"python",
"matlab",
"numpy",
"matplotlib"
] |
Object Attribute in Random List Not Accessible in Python | 1,066,827 | <p>I'm working on my first object oriented bit of python and I have the following:</p>
<pre><code>#!/usr/bin/python
import random
class triangle:
# Angle A To Angle C Connects Side F
# Angle C to Angle B Connects Side D
# Angle B to Angle A Connects Side E
def __init__(self, a, b, c, d, e, f):
self.a = a... | 1 | 2009-07-01T00:57:37Z | 1,066,871 | <p>To assign to <code>a</code>, <code>b</code>, and <code>c</code>:</p>
<pre><code>myTri.a = random.randint(1, 100)
myTri.b = random.randint(1, 100)
myTri.c = random.randint(1, 100)
</code></pre>
<p>To assign to one random attribute from <code>a</code>-<code>f</code>:</p>
<pre><code>attrs = ['a', 'b', 'c', 'd', 'e',... | 2 | 2009-07-01T01:17:32Z | [
"python",
"random",
"object",
"oop"
] |
Object Attribute in Random List Not Accessible in Python | 1,066,827 | <p>I'm working on my first object oriented bit of python and I have the following:</p>
<pre><code>#!/usr/bin/python
import random
class triangle:
# Angle A To Angle C Connects Side F
# Angle C to Angle B Connects Side D
# Angle B to Angle A Connects Side E
def __init__(self, a, b, c, d, e, f):
self.a = a... | 1 | 2009-07-01T00:57:37Z | 1,066,873 | <p>When you say <code>[myTri.a, myTri.b, ...]</code> you are not getting a list of the variables themselves, or references to them. Instead you are getting just their values. Since you know they were initialized to <code>0</code>, it is as if you had written <code>[0, 0, 0, 0, 0, 0]</code>. There's no difference.</p>
... | 5 | 2009-07-01T01:18:40Z | [
"python",
"random",
"object",
"oop"
] |
Object Attribute in Random List Not Accessible in Python | 1,066,827 | <p>I'm working on my first object oriented bit of python and I have the following:</p>
<pre><code>#!/usr/bin/python
import random
class triangle:
# Angle A To Angle C Connects Side F
# Angle C to Angle B Connects Side D
# Angle B to Angle A Connects Side E
def __init__(self, a, b, c, d, e, f):
self.a = a... | 1 | 2009-07-01T00:57:37Z | 1,066,982 | <p>Alternative to using setattr: do it when you create a Triangle instance.</p>
<pre><code>args = [random.randint(1, 100) for i in xrange(3)] + [0, 0, 0]
random.shuffle(args)
my_tri = Triangle(*args)
</code></pre>
| 0 | 2009-07-01T02:06:44Z | [
"python",
"random",
"object",
"oop"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 1,066,947 | <p>No, there is no "intrinsic" way of knowing that (e.g.) <code>zap.co.it</code> is a subdomain (because Italy's registrar DOES sell domains such as <code>co.it</code>) while <code>zap.co.uk</code> <em>isn't</em> (because the UK's registrar DOESN'T sell domains such as <code>co.uk</code>, but only like <code>zap.co.uk<... | 35 | 2009-07-01T01:48:50Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 1,066,955 | <p>There are many, many TLD's. Here's the list:</p>
<p><a href="http://data.iana.org/TLD/tlds-alpha-by-domain.txt" rel="nofollow">http://data.iana.org/TLD/tlds-alpha-by-domain.txt</a></p>
<p>Here's another list</p>
<p><a href="http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains" rel="nofollow">http://en... | 2 | 2009-07-01T01:51:45Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 1,069,780 | <p>using <a href="http://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1">this file of effective tlds</a> which <a href="http://stackoverflow.com/questions/569137/how-to-get-domain-name-from-url/569176#569176">someone else</a> found on mozzila's website:</p>
<pre><code>from __future__ impo... | 37 | 2009-07-01T15:23:52Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 7,388,904 | <p>Here's a great python module someone wrote to solve this problem after seeing this question:
<a href="https://github.com/john-kurkowski/tldextract">https://github.com/john-kurkowski/tldextract</a></p>
<p>The module looks up TLDs in the <a href="https://www.publicsuffix.org/">Public Suffix List</a>, mantained by Moz... | 33 | 2011-09-12T13:46:06Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 15,508,109 | <p>Here's how I handle it:</p>
<pre><code>if not url.startswith('http'):
url = 'http://'+url
website = urlparse.urlparse(url)[1]
domain = ('.').join(website.split('.')[-2:])
match = re.search(r'((www\.)?([A-Z0-9.-]+\.[A-Z]{2,4}))', domain, re.I)
if not match:
sys.exit(2)
elif not match.group(0):
sys.exit(2... | 0 | 2013-03-19T18:53:47Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 16,580,707 | <p>Using python tld</p>
<p><a href="https://pypi.python.org/pypi/tld">https://pypi.python.org/pypi/tld</a></p>
<p>pip install tld</p>
<pre><code>from tld import get_tld
print get_tld("http://www.google.co.uk")
</code></pre>
<h1>print out: google.co.uk</h1>
| 16 | 2013-05-16T06:46:41Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
How to extract top-level domain name (TLD) from URL | 1,066,933 | <p>how would you extract the domain name from a URL, excluding any subdomains?</p>
<p>My initial simplistic attempt was:</p>
<pre><code>'.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])
</code></pre>
<p>This works for <a href="http://www.foo.com">http://www.foo.com</a>, but not <a href="http://www.foo.com.au">... | 31 | 2009-07-01T01:42:03Z | 29,525,805 | <p>Until get_tld is updated for all the new ones, I pull the tld from the error. Sure it's bad code but it works.</p>
<pre><code>def get_tld():
try:
return get_tld(self.content_url)
except Exception, e:
re_domain = re.compile("Domain ([^ ]+) didn't match any existing TLD name!");
matchObj = re_domain.f... | 0 | 2015-04-08T21:36:29Z | [
"python",
"url",
"parsing",
"dns",
"extract"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,067,145 | <p>Based on <a href="http://docs.python.org/dev/howto/regex.html" rel="nofollow">http://docs.python.org/dev/howto/regex.html</a> ...</p>
<ol>
<li>Replace <code>$line =~ /.*/</code> with <code>re.search(r".*", line)</code>.</li>
<li><code>$line !~ /.*/</code> is just <code>!($line =~ /.*/)</code>.</li>
<li>Replace <cod... | 3 | 2009-07-01T03:22:55Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,067,148 | <p>I am not sure what is so hard to understand about this that it requires a snide remark as in your comment above. Note that <code><></code> is called the diamond operator. <code>s///</code> is the substitution operator and <code>//</code> is the match operator <code>m//</code>.</p>
| 3 | 2009-07-01T03:24:32Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,067,151 | <p>Here's a pretty literal translation with just the minimum of obvious style changes (putting all code into a function, using string rather than re operations where possible).</p>
<pre><code>import re, fileinput
def main():
for line in fileinput.input():
process = False
for nope in ('BEGIN TRANSACTION','CO... | 45 | 2009-07-01T03:25:54Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,067,152 | <p>Shortest? The tilde signifies a regex in perl. "import re" and go from there. The only key differences are that you'll be using \1 and \2 instead of $1 and $2 when you assign values, and you'll be using %s for when you're replacing regexp matches inside strings.</p>
| 1 | 2009-07-01T03:26:16Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,068,921 | <p>Real issue is do you know actually how to migrate the database? What is presented is merely a search and replace loop.</p>
| 1 | 2009-07-01T12:33:18Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 1,070,463 | <p>Here is a slightly better version of the original.</p>
<pre><code>#! /usr/bin/perl
use strict;
use warnings;
use 5.010; # for s/\K//;
while( <> ){
next if m'
BEGIN TRANSACTION |
COMMIT |
sqlite_sequence |
CREATE UNIQUE INDEX
'x;
if( my($name,$sub) = m'CREATE TABLE \"... | 5 | 2009-07-01T17:48:28Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 3,675,869 | <p><a href="http://stackoverflow.com/questions/1067060/translating-perl-to-python/1067151#1067151">Alex Martelli's solution above</a> works good, but needs some fixes and additions:</p>
<p>In the lines using regular expression substitution, the insertion of the matched groups must be double-escaped OR the replacement ... | 10 | 2010-09-09T10:55:41Z | [
"python",
"perl",
"rewrite"
] |
Translating Perl to Python | 1,067,060 | <p>I found this Perl script while <a href="http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql/25860">migrating my SQLite database to mysql</a></p>
<p>I was wondering (since I don't know Perl) how could one rewrite this in Python?</p>
<p>Bonus points for the shortest (code) answer :)</... | 14 | 2009-07-01T02:50:40Z | 6,346,336 | <p>all of scripts on this page can't deal with simple sqlite3:</p>
<pre><code>PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE Filename (
FilenameId INTEGER,
Name TEXT DEFAULT '',
PRIMARY KEY(FilenameId)
);
INSERT INTO "Filename" VALUES(1,'');
INSERT INTO "Filename" VALUES(2,'bigfile1');
INSERT INTO "... | 4 | 2011-06-14T15:48:07Z | [
"python",
"perl",
"rewrite"
] |
Get rid of toplevel tk panewindow while usong tkMessageBox | 1,067,900 | <p><a href="http://stackoverflow.com/questions/1052420/tkkinter-message-box">link text</a></p>
<p>When I do :</p>
<pre><code>tkMessageBox.askquestion(title="Symbol Display",message="Is the symbol visible on the console")
</code></pre>
<p>along with Symbol Display window tk window is also coming. </p>
<p>If i press ... | 4 | 2009-07-01T08:14:21Z | 1,067,995 | <p>The <em>trick</em> is to invoke withdraw on the Tk root top-level:</p>
<pre><code>>>> import tkMessageBox, Tkinter
>>> Tkinter.Tk().withdraw()
>>> tkMessageBox.askquestion(
... title="Symbol Display",
... message="Is the symbol visible on the console")
</code></pre>
| 5 | 2009-07-01T08:37:59Z | [
"python",
"tkinter"
] |
Programmatically detect system-proxy settings on Windows XP with Python | 1,068,212 | <p>I develop a critical application used by a multi-national company. Users in offices all around the globe need to be able to install this application.</p>
<p>The application is actually a plugin to Excel and we have an automatic installer based on Setuptools' easy_install that ensures that all a project's dependanci... | 4 | 2009-07-01T09:33:51Z | 1,068,303 | <p>As far as I know, In a Windows environment, if no proxy environment variables are set, proxy settings are obtained from the registry's Internet Settings section. .
Isn't it enough?</p>
<p>Or u can get something useful info from registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\... | 3 | 2009-07-01T09:59:40Z | [
"python",
"windows",
"networking",
"proxy",
"setuptools"
] |
Programmatically detect system-proxy settings on Windows XP with Python | 1,068,212 | <p>I develop a critical application used by a multi-national company. Users in offices all around the globe need to be able to install this application.</p>
<p>The application is actually a plugin to Excel and we have an automatic installer based on Setuptools' easy_install that ensures that all a project's dependanci... | 4 | 2009-07-01T09:33:51Z | 1,068,484 | <p>Here's a sample that should create a bullet green (proxy enable) or red (proxy disable) in your systray</p>
<p>It shows how to read and write in windows registry</p>
<p>it uses gtk</p>
<pre><code>#!/usr/bin/env python
import gobject
import gtk
from _winreg import *
class ProxyNotifier:
def __init__(self): ... | 4 | 2009-07-01T10:54:28Z | [
"python",
"windows",
"networking",
"proxy",
"setuptools"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 1,068,275 | <p>Look into using a dedicated testrunner, like py.test, nose or possibly even zope.testing. They all have command line options for selecting tests.</p>
<p>Look for example as Nose: <a href="https://pypi.python.org/pypi/nose/1.3.0" rel="nofollow">https://pypi.python.org/pypi/nose/1.3.0</a></p>
| 2 | 2009-07-01T09:51:09Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 1,068,339 | <p>You have basically two ways to do it:</p>
<ol>
<li>Define your own suite of tests for the class</li>
<li>Create mock classes of the cluster connection that will return actual data.</li>
</ol>
<p>I am a strong proponent of he second approach; a unit test <em>should</em> test only a very unit of code, and not comple... | 6 | 2009-07-01T10:12:52Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 1,068,366 | <p>The default <code>unittest.main()</code> uses the default test loader to make a TestSuite out of the module in which main is running.</p>
<p>You don't have to use this default behavior.</p>
<p>You can, for example, make three <a href="http://docs.python.org/library/unittest.html#unittest.TestSuite">unittest.TestSu... | 38 | 2009-07-01T10:23:27Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 12,696,073 | <p>Actually, one can pass the names of the test case as sys.argv and only those cases will be tested.</p>
<p>For instance, suppose you have</p>
<pre><code>class TestAccount(unittest.TestCase):
...
class TestCustomer(unittest.TestCase):
...
class TestShipping(unittest.TestCase):
...
account = TestAccoun... | 8 | 2012-10-02T18:28:18Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 17,097,698 | <p>Or you can make use of the <code>unittest.SkipTest()</code> function. Example, add a <code>skipOrRunTest</code> method to your test class like this:</p>
<pre><code>def skipOrRunTest(self,testType):
#testsToRun = 'ALL'
#testsToRun = 'testType1, testType2, testType3, testType4,...etc'
#testsToRun = 'test... | 0 | 2013-06-13T21:46:36Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 17,817,391 | <p>To run only a single specific test you can use:</p>
<pre><code>$ python -m unittest test_module.TestClass.test_method
</code></pre>
<p>More information <a href="http://pythontesting.net/framework/specify-test-unittest-nosetests-pytest/">here</a></p>
| 59 | 2013-07-23T17:48:07Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 24,427,772 | <p>Since you use <code>unittest.main()</code> you can just run <code>python tests.py --help</code> to get the documentation:</p>
<pre><code>Usage: tests.py [options] [test] [...]
Options:
-h, --help Show this message
-v, --verbose Verbose output
-q, --quiet Minimal output
-f, --failfast Stop o... | 4 | 2014-06-26T10:10:49Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 30,187,488 | <p>I have found another way to select the test_* methods that I only want to run by adding an attribute to them. You basically use a metaclass to decorate the callables inside the TestCase class that have the StepDebug attribute with a unittest.skip decorator. More info on</p>
<p><a href="http://stackoverflow.com/q/30... | 0 | 2015-05-12T09:58:50Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 33,132,449 | <p>Haven't found a nice way to do this before, so sharing here.</p>
<p>Goal: Get a set of test files together so they can be run as a unit,
but we can still select any one of them to run by itself. </p>
<p>Problem: the discover method does not allow easy selection of a single test case to run.</p>
<p>Design: see be... | 0 | 2015-10-14T18:01:27Z | [
"python",
"unit-testing",
"pyunit"
] |
Python unittest: how to run only part of a test file? | 1,068,246 | <p>I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class.</p>
<p>Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn'... | 44 | 2009-07-01T09:40:32Z | 34,146,740 | <p>I tried @slott's answer:</p>
<pre><code>if __name__ == "__main__":
suite = eval(sys.argv[1]) # Be careful with this line!
unittest.TextTestRunner().run(suite)
</code></pre>
<p>But that gave me the following error:</p>
<pre><code>Traceback (most recent call last):
File "functional_tests.py", line 178, i... | 1 | 2015-12-08T02:04:02Z | [
"python",
"unit-testing",
"pyunit"
] |
Using SimpleXMLTreeBuilder in elementtree | 1,068,510 | <p>I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:</p>
<pre><code>"No module named expat; use SimpleXMLTreeBuilder instead"
</code></pre>
... | 4 | 2009-07-01T11:02:51Z | 1,069,424 | <p>Assuming you're now using <code>elementtree.XMLTreeBuilder</code>, just try this instead:</p>
<pre><code>from elementtree import SimpleXMLTreeBuilder as XMLTreeBuilder
</code></pre>
<p>It tries to provide exactly the same functionality but using xmllib instead of expat. If that also fails, BTW, try:</p>
<pre><cod... | 0 | 2009-07-01T14:27:22Z | [
"python",
"django",
"elementtree"
] |
Using SimpleXMLTreeBuilder in elementtree | 1,068,510 | <p>I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:</p>
<pre><code>"No module named expat; use SimpleXMLTreeBuilder instead"
</code></pre>
... | 4 | 2009-07-01T11:02:51Z | 1,070,269 | <blockquote>
<p>from elementtree import SimpleXMLTreeBuilder as XMLTreeBuilder</p>
</blockquote>
<p>Ok, it has slightly changed now:</p>
<pre><code>Traceback (most recent call last):
File "C:\Python26\tests\xml.py", line 12, in <module>
doc = elementtree.ElementTree.parse("foo.xml")
File "C:\Python26\... | 0 | 2009-07-01T17:03:08Z | [
"python",
"django",
"elementtree"
] |
Using SimpleXMLTreeBuilder in elementtree | 1,068,510 | <p>I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:</p>
<pre><code>"No module named expat; use SimpleXMLTreeBuilder instead"
</code></pre>
... | 4 | 2009-07-01T11:02:51Z | 2,067,177 | <p>If you have third party module that wants to use ElementTree (and XMLTreeBuilder by dependency) you can change ElementTree's XMLTreeBuilder definition to the one provided by SimpleXMLTreeBuilder like so:</p>
<pre><code>from xml.etree import ElementTree # part of python distribution
from elementtree import SimpleXML... | 6 | 2010-01-14T19:59:21Z | [
"python",
"django",
"elementtree"
] |
Using SimpleXMLTreeBuilder in elementtree | 1,068,510 | <p>I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:</p>
<pre><code>"No module named expat; use SimpleXMLTreeBuilder instead"
</code></pre>
... | 4 | 2009-07-01T11:02:51Z | 10,235,911 | <p>We ran into this same problem using python version 2.6.4 on CentOS 5.5.</p>
<p>The issue happens when the expat class attempts to load the pyexpat modules, see /usr/lib64/python2.6/xml/parsers/expat.py</p>
<p>Looking inside of /usr/lib64/python2.6/lib-dynload/, I didn't see the "pyexpat.so" shared object. However,... | 1 | 2012-04-19T20:05:48Z | [
"python",
"django",
"elementtree"
] |
Using SimpleXMLTreeBuilder in elementtree | 1,068,510 | <p>I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error:</p>
<pre><code>"No module named expat; use SimpleXMLTreeBuilder instead"
</code></pre>
... | 4 | 2009-07-01T11:02:51Z | 20,462,530 | <p>I have same error as you when I developed on Solaris & python 2.7.2.
I fixed this issue after I installed the python <code>expat</code> package by using pkgin.
See if the solution above can give you any idea.</p>
| 0 | 2013-12-09T03:17:43Z | [
"python",
"django",
"elementtree"
] |
Skip steps on a django FormWizard | 1,068,572 | <p>I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied.</p>
<p>The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want ... | 2 | 2009-07-01T11:21:27Z | 1,079,855 | <p>The hook method <a href="http://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/#django.contrib.formtools.wizard.FormWizard.process%5Fstep">process_step()</a> gives you exactly that opportunity.
After the form is validated you can modify the <strong>self.form_list</strong> variable, and delete the fo... | 5 | 2009-07-03T15:27:33Z | [
"python",
"django",
"formwizard"
] |
Skip steps on a django FormWizard | 1,068,572 | <p>I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied.</p>
<p>The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want ... | 2 | 2009-07-01T11:21:27Z | 1,144,537 | <p>I did it other way, overriding the render_template method. Here my solution. I didn't know about the process_step()...</p>
<pre><code>def render_template(self, request, form, previous_fields, step, context):
if not step == 0:
# A workarround to find the type value!
attr = 'name="0-type" value='... | 0 | 2009-07-17T17:04:43Z | [
"python",
"django",
"formwizard"
] |
Skip steps on a django FormWizard | 1,068,572 | <p>I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied.</p>
<p>The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want ... | 2 | 2009-07-01T11:21:27Z | 23,078,874 | <p>To make certain forms optional you can introduce conditionals in the list of forms you pass to the FormView in your urls.py:</p>
<pre><code>contact_forms = [ContactForm1, ContactForm2]
urlpatterns = patterns('',
(r'^contact/$', ContactWizard.as_view(contact_forms,
condition_dict={'1': show_message_form... | 0 | 2014-04-15T08:54:10Z | [
"python",
"django",
"formwizard"
] |
Django way to do conditional formatting | 1,068,573 | <p>What is the correct way to do conditional formatting in Django?</p>
<p>I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before tod... | 5 | 2009-07-01T11:21:30Z | 1,068,601 | <p>Since you are doing static comparison (no queries needed), you should go for the most DRY and easy to implement option. In this case, I would go for option 4, make a template filter. Then you could do value|filter to get the class you would need to set the background colour. Template filters are actually a bit simpl... | 1 | 2009-07-01T11:27:20Z | [
"python",
"django",
"formatting",
"django-templates"
] |
Django way to do conditional formatting | 1,068,573 | <p>What is the correct way to do conditional formatting in Django?</p>
<p>I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before tod... | 5 | 2009-07-01T11:21:30Z | 1,068,606 | <p>I had a very similar requirement; as this is pretty connected to the business logic, I have added a model method to manage this kind of information, to be used then in the template:</p>
<pre><code>{% if not bug.within_due_date %}bgcolor="OrangeRed"{% endif %}
</code></pre>
<p>It could also be obtained through a te... | 3 | 2009-07-01T11:28:14Z | [
"python",
"django",
"formatting",
"django-templates"
] |
Django way to do conditional formatting | 1,068,573 | <p>What is the correct way to do conditional formatting in Django?</p>
<p>I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before tod... | 5 | 2009-07-01T11:21:30Z | 1,068,616 | <p>I'm a big fan of putting ALL "business" logic in the view function and ALL presentation in the templates/CSS.</p>
<p>Option 1 is ideal. You return a list of pairs: ( date, state ), where the state is the class name ("past", "present", "future").</p>
<p>Your template then uses the state information as the class fo... | 8 | 2009-07-01T11:30:08Z | [
"python",
"django",
"formatting",
"django-templates"
] |
Django way to do conditional formatting | 1,068,573 | <p>What is the correct way to do conditional formatting in Django?</p>
<p>I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before tod... | 5 | 2009-07-01T11:21:30Z | 7,217,889 | <p>you can also take a look at Django's reference for built in Formatting and Filtering tags. It sure has what you are looking for and more and it's a good link to have bookmarked.</p>
<p>You can take a look at it <a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs" rel="nofollow">here<... | 0 | 2011-08-27T22:50:52Z | [
"python",
"django",
"formatting",
"django-templates"
] |
Is there a python module compatible with Google Apps Engine's new "Tasks" | 1,068,690 | <p>I'm writing a Python application, that I want to later migrate to GAE.
The new "Task Queues" API fulfills a requirement of my app, and I want to simulate it locally until I have the time to migrate the whole thing to GAE.</p>
<p>Does anyone know of a compatible module I can run locally?</p>
| 0 | 2009-07-01T11:43:50Z | 1,844,774 | <p>Given the explicitly experimental nature of the thing, there's certainly nothing <em>compatible</em> in existence at this time. And obviously even if there were, Google pretty much says <a href="http://code.google.com/appengine/docs/python/taskqueue/tasks.html" rel="nofollow">"we're going to change the API!"</a> in... | 1 | 2009-12-04T04:04:06Z | [
"python",
"google-app-engine",
"migration",
"task"
] |
Is there a python module compatible with Google Apps Engine's new "Tasks" | 1,068,690 | <p>I'm writing a Python application, that I want to later migrate to GAE.
The new "Task Queues" API fulfills a requirement of my app, and I want to simulate it locally until I have the time to migrate the whole thing to GAE.</p>
<p>Does anyone know of a compatible module I can run locally?</p>
| 0 | 2009-07-01T11:43:50Z | 2,441,810 | <p>Since my original question, I've found two projects that aim to release the vendor-lock-in of GAE:</p>
<ol>
<li>AppScale - <a href="http://code.google.com/p/appscale/" rel="nofollow">http://code.google.com/p/appscale/</a></li>
<li>TyphoonAE - <a href="http://code.google.com/p/typhoonae/" rel="nofollow">http://code.... | 0 | 2010-03-14T10:18:50Z | [
"python",
"google-app-engine",
"migration",
"task"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,068,893 | <p>To help you debug it, try adding:</p>
<pre><code>print repr(cmd)
</code></pre>
<p>It might be that some special characters slipped into the command that normal print is hiding when you copy and paste it.</p>
| 1 | 2009-07-01T12:27:57Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,068,962 | <p>Maybe some indentation problem?</p>
<p>The following works correctly:</p>
<pre><code>import os
def updateExportConfigId(id):
stringId = "%s" % id
cmd= "sed '1,$s/MANAGER_ID=[0-9]*/MANAGER_ID=" + stringId + "/g' test.dat > test.new"
print "command is " + cmd
os.system(cmd)
updateExportConfigId... | 0 | 2009-07-01T12:41:16Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,069,233 | <p>What is wrong is that there is some difference. Yeah, I know that's not helpful, but you need to figure out the difference.</p>
<p>Try running this:</p>
<pre><code>import os
def updateExportConfigId(id):
stringId = "%s" % id
cmd1 = "sed '1,$s/MANAGER_ID=[0-9]*/MANAGER_ID=" + stringId + "/g' path/file.old &... | 1 | 2009-07-01T13:48:47Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,069,409 | <p>Maybe it helps to use only <a href="http://docs.python.org/reference/lexical%5Fanalysis.html#string-literals" rel="nofollow">raw strings</a>.</p>
| 0 | 2009-07-01T14:24:43Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,069,476 | <p>So from previous answers we now know that <code>id</code> is a Unicode string, which makes cmd1 a Unicode string, which os.system() is converting to a byte string for execution in the default encoding.</p>
<p>a) I suggest using subprocess rather than os.system()</p>
<p>b) I suggest not using the name of a built-in... | 1 | 2009-07-01T14:34:59Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,069,587 | <p>Finally, I found a way to run the os.system(cmd)!</p>
<p>Simple trick, to "clean" the cmd string:</p>
<pre><code>os.system(str(cmd))
</code></pre>
<p>Now, I'm able to build the cmd with all arguments I need and at the end I just "clean" it with str() call before run it with os.system() call.</p>
<p>Thanks a lot ... | 0 | 2009-07-01T14:52:34Z | [
"python"
] |
Problem using os.system() with sed command | 1,068,812 | <p>I'm writing a small method to replace some text in a file.
The only argument I need is the new text, as it is always the same file and text to be replaced.</p>
<p>I'm having a problem using the os.system() call, when I try to use the argument of the method</p>
<p>If I use a string like below, everything runs ok:</... | 2 | 2009-07-01T12:11:38Z | 1,072,091 | <p>Obligatory: <strong>don't use <code>os.system</code></strong> - use the <a href="http://docs.python.org/library/subprocess.html"><code>subprocess</code></a> module:</p>
<pre><code>import subprocess
def updateExportConfigId(m_id, source='path/file.old',
destination='path/file.new'):
... | 5 | 2009-07-02T02:07:20Z | [
"python"
] |
Open-Source Forum with API | 1,069,246 | <p>Does anyone have suggestions for a PHP, Python, or J2EE-based web forum that has a good API for programmatically creating users and forum topics?</p>
| 6 | 2009-07-01T13:51:38Z | 1,069,283 | <p><a href="http://www.phpbb.com/" rel="nofollow">phpBB</a> would be the first that comes to mind as open-source, simply because it's free. </p>
<p>In reality almost all forum platforms have some sort of 'api' in that you can do whatever you need programatically, it just may not be as simple as 'add_user(bob)'. A few ... | 3 | 2009-07-01T14:02:49Z | [
"php",
"python",
"website",
"forum"
] |
using profiles in iPython and Django | 1,069,961 | <p>I've got a Django product I'm using iPython to interact with.</p>
<p>I'm trying to have modules automatically loaded when I start a shell:</p>
<p>python manage.py shell</p>
<p>I've copied .ipython/ipythonrc to the root directory of the project and added to the file:</p>
<p>import_some module_name model1 model2... | 3 | 2009-07-01T15:55:13Z | 1,070,222 | <p>I don't know about ipythonrc, but if you only need the models, you could use <a href="http://code.google.com/p/django-command-extensions/" rel="nofollow"><code>django-extensions</code></a>. After you install it, you've got a plethora of new managment commands, including <code>shell_plus</code>, which will open a ipy... | 5 | 2009-07-01T16:53:19Z | [
"python",
"django",
"ipython"
] |
using profiles in iPython and Django | 1,069,961 | <p>I've got a Django product I'm using iPython to interact with.</p>
<p>I'm trying to have modules automatically loaded when I start a shell:</p>
<p>python manage.py shell</p>
<p>I've copied .ipython/ipythonrc to the root directory of the project and added to the file:</p>
<p>import_some module_name model1 model2... | 3 | 2009-07-01T15:55:13Z | 1,303,140 | <p>BryanWheelock Your solution won't work because your shell is the result of the spawn not a direct interatction with it. What you want to do is this - or at least this is what I do.</p>
<p>Within your workspace (the place where you type <code>python manage.py shell</code>) create a ipythonrc file. In it put the fol... | 1 | 2009-08-19T23:19:52Z | [
"python",
"django",
"ipython"
] |
using profiles in iPython and Django | 1,069,961 | <p>I've got a Django product I'm using iPython to interact with.</p>
<p>I'm trying to have modules automatically loaded when I start a shell:</p>
<p>python manage.py shell</p>
<p>I've copied .ipython/ipythonrc to the root directory of the project and added to the file:</p>
<p>import_some module_name model1 model2... | 3 | 2009-07-01T15:55:13Z | 29,457,821 | <p><code>shell_plus</code> command of django-extensions can import the model automatically, but it seems can not load the profile of ipython. I have did some hacky job to make this done. </p>
<p>use <code>start_ipython</code> to launch ipython shell instead of <code>embed</code> and pass some arguments to it.</p>
<p>... | 0 | 2015-04-05T13:32:35Z | [
"python",
"django",
"ipython"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,070,543 | <p>You need this:</p>
<pre><code>os.environ['ORACLE_HOME'] = '/oracledb/10.2.0/'
os.environ['LD_LIBRARY_PATH'] = '/oracledb/10.2.0/lib'
</code></pre>
<p>instead of using <code>os.putenv()</code> because <code>os.putenv()</code> doesn't update <code>os.environ</code>, which <code>cx_Oracle</code> is presumably looking... | 3 | 2009-07-01T18:06:19Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,070,555 | <p>Are your statements out of order?</p>
<pre><code>#!/usr/bin/python
import os
os.putenv('ORACLE_HOME', '/oracledb/10.2.0/')
os.putenv('LD_LIBRARY_PATH', '/oracledb/10.2.0/lib')
import cx_Oracle
import defs as df
con = cx_Oracle.Connection(df.DB_USER, df.DB_PASS, df.DB_SID)
print con
</code></pre>
| 0 | 2009-07-01T18:07:35Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,070,647 | <p>From just a short <a href="http://osdir.com/ml/python.db.cx-oracle/2006-01/msg00007.html" rel="nofollow">google</a> on the problem, it could be that your problem is related to the the ending <code>/</code> in <code>ORACLE_HOME</code>.<br />
Try removing it (and using also suggestion from Richie) and see if it works.... | 1 | 2009-07-01T18:32:57Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,070,694 | <p>You could use a shell script to implement the CGI, set the environment variables in the shell script and call the python script from the shell script.</p>
<p>Setting environment variables from within python seems to be a tricky thing, especially when you are dealing with how libraries are loaded...</p>
| 1 | 2009-07-01T18:42:52Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,078,124 | <p>You can eliminate the problem altogether if you eliminate the need to set the environment variables. Here's a note on how to do this by installing the Oracle Instant Client on your box.</p>
<p><a href="http://stackoverflow.com/questions/764871/installing-oracle-instantclient-on-linux-without-setting-environment-va... | 2 | 2009-07-03T07:10:02Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 1,143,584 | <p>I've managed to solve the problem.</p>
<p>Somehow the user and group that apache was using didn't have access to the environment variables. I solved the problem by changing the user and group that apache was using to a user that I was certain to have access to this variables. </p>
<p>It's strange (and frustrating)... | 1 | 2009-07-17T14:17:25Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 5,394,590 | <p>This is working for me:</p>
<pre><code>os.putenv('ORACLE_HOME', '/oracle/client/v10.2.0.3-64bit')
os.putenv('LD_LIBRARY_PATH', '/oracle/client/v10.2.0.3-64bit/lib')
os.environ['ORACLE_HOME'] = '/oracle/client/v10.2.0.3-64bit'
os.environ['LD_LIBRARY_PATH'] = '/oracle/client/v10.2.0.3-64bit/lib'
</code></pre>
<p>Min... | 5 | 2011-03-22T16:31:57Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 8,331,159 | <p>The actual question why the questioner's code did not work has not yet been answered.</p>
<p>The answer is that the environment variable LD_LIBRARY_PATH is only evaluated when an application is started (in this case the Python interpreter). When Python has started, it is already too late to mess with this variable;... | 0 | 2011-11-30T18:42:25Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
Python + CGI script cannot access environment variables | 1,070,525 | <p>I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache.</p>
<p>For example the following code works perfectly at the command line:</p>
<pre><code>#!/usr/bin/python
import os
import cx_Oracle... | 5 | 2009-07-01T18:03:47Z | 8,986,919 | <p>Don't forget adding <strong>env</strong> module for apache:</p>
<pre><code>a2enmod env
</code></pre>
<p>in .htaccess or apache configuration:</p>
<pre><code>SetEnv LD_LIBRARY_PATH /oracle_lib_path
</code></pre>
<p>in /etc/apache2/envvars doesn't work</p>
| 2 | 2012-01-24T12:37:19Z | [
"python",
"apache",
"cgi",
"cx-oracle"
] |
How to create "virtual root" with Python's ElementTree? | 1,070,772 | <p>I am trying to use Python's ElementTree to generate an XHTML file.</p>
<p>However, the ElementTree.Element() just lets me create a single tag (e.g., HTML).
I need to create some sort of a virtual root or whatever it is called so that I can put the various , DOCTYPES, etc.</p>
<p>How do I do that?
Thanks</p>
| 5 | 2009-07-01T19:02:08Z | 1,070,796 | <p>I don't know if there's a better way but I've seen this done:</p>
<p>Create the base document as a string:</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html></html>
</code></pre>
<p>Then parse that strin... | 7 | 2009-07-01T19:07:24Z | [
"python",
"elementtree"
] |
How to create "virtual root" with Python's ElementTree? | 1,070,772 | <p>I am trying to use Python's ElementTree to generate an XHTML file.</p>
<p>However, the ElementTree.Element() just lets me create a single tag (e.g., HTML).
I need to create some sort of a virtual root or whatever it is called so that I can put the various , DOCTYPES, etc.</p>
<p>How do I do that?
Thanks</p>
| 5 | 2009-07-01T19:02:08Z | 2,177,037 | <p>I have/had the same problem. when i parse a document and write it back again the doctype defenition is not there anymore. but i found a solution browsing the documentation:</p>
<p><a href="http://effbot.org/zone/element-tidylib.htm" rel="nofollow">link text</a></p>
<p>Saving HTML Files #</p>
<p>To save a plain HT... | 0 | 2010-02-01T13:45:18Z | [
"python",
"elementtree"
] |
Equivalent for inject() in Python? | 1,070,926 | <p>In Ruby, I'm used to using Enumerable#inject for going through a list or other structure and coming back with some conclusion about it. For example,</p>
<pre><code>[1,3,5,7].inject(true) {|allOdd, n| allOdd && n % 2 == 1}
</code></pre>
<p>to determine if every element in the array is odd. What would be the... | 8 | 2009-07-01T19:36:42Z | 1,070,946 | <p>Sounds like <code>reduce</code> in Python or <code>fold(r|l)'?'</code> from Haskell.</p>
<pre><code>reduce(lambda x, y: x and y % == 1, [1, 3, 5])
</code></pre>
| 4 | 2009-07-01T19:41:04Z | [
"python",
"functional-programming"
] |
Equivalent for inject() in Python? | 1,070,926 | <p>In Ruby, I'm used to using Enumerable#inject for going through a list or other structure and coming back with some conclusion about it. For example,</p>
<pre><code>[1,3,5,7].inject(true) {|allOdd, n| allOdd && n % 2 == 1}
</code></pre>
<p>to determine if every element in the array is odd. What would be the... | 8 | 2009-07-01T19:36:42Z | 1,070,965 | <p>To determine if every element is odd, I'd use <a href="http://docs.python.org/library/functions.html#all"><code>all()</code></a></p>
<pre><code>def is_odd(x):
return x%2==1
result = all(is_odd(x) for x in [1,3,5,7])
</code></pre>
<p>In general, however, Ruby's <code>inject</code> is most like Python's <a hre... | 19 | 2009-07-01T19:45:01Z | [
"python",
"functional-programming"
] |
Equivalent for inject() in Python? | 1,070,926 | <p>In Ruby, I'm used to using Enumerable#inject for going through a list or other structure and coming back with some conclusion about it. For example,</p>
<pre><code>[1,3,5,7].inject(true) {|allOdd, n| allOdd && n % 2 == 1}
</code></pre>
<p>to determine if every element in the array is odd. What would be the... | 8 | 2009-07-01T19:36:42Z | 1,071,028 | <p>I think you probably want to use <code>all</code>, which is less general than <code>inject</code>. <code>reduce</code> is the Python equivalent of <code>inject</code>, though.</p>
<pre><code>all(n % 2 == 1 for n in [1, 3, 5, 7])
</code></pre>
| 3 | 2009-07-01T19:57:41Z | [
"python",
"functional-programming"
] |
How To: View MFC Doc File in Python | 1,070,932 | <p>I want to use Python to access MFC document files generically? Can CArchive be used to query a file and view the structure, or does Python, in opening the document, need to know more about the document structure in order to view the contents?</p>
| 1 | 2009-07-01T19:37:12Z | 1,071,011 | <p>I think that the Python code needs to know the document structure. </p>
<p>Maybe you should make a python wrapper of your c++ code. </p>
<p>In this case, I would recommend to use http://sourceforge.net/projects/pycpp/>pycpp which is my opinion a great library for making python extensions in c++.</p>
| 0 | 2009-07-01T19:53:10Z | [
"python",
"windows",
"mfc",
"file"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,015 | <p>As far as full frameworks go I believe Django is relatively small.</p>
<p>If you <em>really</em> want lightweight, though, check out <a href="http://webpy.org/">web.py</a>, <a href="http://www.cherrypy.org/">CherryPy</a>, <a href="http://pylonshq.com/">Pylons</a> and <a href="http://www.web2py.com/">web2py</a>.</p>... | 11 | 2009-07-01T19:54:00Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,040 | <p>There are a couple of web frameworks available in python, that will relieve you from most of the work</p>
<ol>
<li><a href="http://docs.djangoproject.com/en/dev/" rel="nofollow">Django</a></li>
<li><a href="http://pylonshq.com/" rel="nofollow">Pylons</a> (and the new TurboGears, based on it).</li>
<li><a href="http... | 8 | 2009-07-01T19:59:03Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,048 | <p>I really love django and it doesn't seem to me that is huge. It is very powerful but not huge.</p>
<p>If you want to start playing with http and python, the simplest thing is the BaseHttpServer provided in the standard library. see <a href="http://docs.python.org/library/basehttpserver.html" rel="nofollow">http://d... | 0 | 2009-07-01T20:00:28Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,058 | <p>I agree with Paolo - Django is pretty small and the way to go - but if you are not down with that I would add to <a href="http://turbogears.org/" rel="nofollow">TurboGears</a> to the list</p>
| 0 | 2009-07-01T20:01:24Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,128 | <p>If you are looking for a framework take a look at this list: <a href="http://wiki.python.org/moin/WebFrameworks" rel="nofollow">Python Web Frameworks</a></p>
<p>If you need small script(-s) or one time job script, might be plain CGI module is going to be enough - <a href="http://wiki.python.org/moin/CgiScripts" rel... | 0 | 2009-07-01T20:14:25Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,129 | <p>Your question was about basic CGI scripting, looking at your example, but it seems like everyone has chosen to answer it with "use my favorite framework". Let's try a different approach.</p>
<p>If you're looking for a direct replacement for what you wrote above (ie. CGI scripting), then you're probably looking for ... | 24 | 2009-07-01T20:14:25Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,255 | <p>What is "huge" is a matter of taste, but Django is a "full stack" framework, that includes everything from an ORM, to templates to well, loads of things. So it's not small (although smaller than Grok and Zope3, other full-stack python web frameworks).</p>
<p>But there are also plenty of really small and minimalisti... | 0 | 2009-07-01T20:34:22Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,071,260 | <p>In Python, the way to produce a website is to use a framework. Most of the popular (and actively maintained/supported) frameworks have already been mentioned. </p>
<p>In general, I do not view Djano or Turbogears as "huge", I view them as "complete." Each will let you build a database backed, dynamic website. T... | 2 | 2009-07-01T20:36:01Z | [
"python"
] |
Writing a website in Python | 1,070,999 | <p>I'm pretty proficient in PHP, but want to try something new.</p>
<p>I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation.</p>
<p>I've just written this, which works:</p>
<pre><code>#!/usr/bin/python
def main():
print "Content-type: text/html"
... | 19 | 2009-07-01T19:50:19Z | 1,075,964 | <p>In web2py the previous code would be</p>
<p>in controller <code>default.py</code>:</p>
<pre><code>def main():
return dict(message="Hello World")
</code></pre>
<p>in view <code>default/main.html</code>:</p>
<pre><code><html><head>
<title>Hello World from Python</title>
</head><... | 2 | 2009-07-02T18:30:47Z | [
"python"
] |
Pylons: address already in use when trying to serve | 1,071,071 | <p>I'm running pylons and I did this:
paster server development.ini
It's running on :5000</p>
<p>But when I try to run the command again:
paster serve development.ini</p>
<p>I get this message:
socket.error: [Errno 98] Address already in use</p>
<p>Any ideas?</p>
| 3 | 2009-07-01T20:03:07Z | 1,071,115 | <p>Normally that means it's still running, but that should only happen if it's in daemon mode. After you started it, do you get a command prompt, or do you have to stop it with Ctrl-C?</p>
<p>If you get a command prompt back it's deamon mode and you have to stop it with</p>
<pre><code>paster server development.ini st... | 3 | 2009-07-01T20:12:19Z | [
"python",
"nginx",
"pylons",
"paste",
"paster"
] |
Pylons: address already in use when trying to serve | 1,071,071 | <p>I'm running pylons and I did this:
paster server development.ini
It's running on :5000</p>
<p>But when I try to run the command again:
paster serve development.ini</p>
<p>I get this message:
socket.error: [Errno 98] Address already in use</p>
<p>Any ideas?</p>
| 3 | 2009-07-01T20:03:07Z | 1,071,117 | <p>As I understand your question, you start some application to listen on port 5000. Then without stopping it (?), you try to start another instance to listen on het same port? If so, you won't succeed.</p>
<p>You can always check what application is listening on what port number by using <code>netstat</code> (for bot... | 2 | 2009-07-01T20:12:30Z | [
"python",
"nginx",
"pylons",
"paste",
"paster"
] |
Pylons: address already in use when trying to serve | 1,071,071 | <p>I'm running pylons and I did this:
paster server development.ini
It's running on :5000</p>
<p>But when I try to run the command again:
paster serve development.ini</p>
<p>I get this message:
socket.error: [Errno 98] Address already in use</p>
<p>Any ideas?</p>
| 3 | 2009-07-01T20:03:07Z | 2,933,318 | <p>This has also happened to me when the server died unexpectedly, and didn't close it's socket's properly. Essentially, the socket is still listed as open with the operating system, even though the process has died. I've found if I wait for 30-60 seconds, the OS will realize the associated process has died, and cleanu... | 1 | 2010-05-29T00:52:52Z | [
"python",
"nginx",
"pylons",
"paste",
"paster"
] |
Pylons: address already in use when trying to serve | 1,071,071 | <p>I'm running pylons and I did this:
paster server development.ini
It's running on :5000</p>
<p>But when I try to run the command again:
paster serve development.ini</p>
<p>I get this message:
socket.error: [Errno 98] Address already in use</p>
<p>Any ideas?</p>
| 3 | 2009-07-01T20:03:07Z | 8,516,490 | <p>your default port 8080 is using.
you should add '-p 10000'
after command to take port 10000</p>
| 0 | 2011-12-15T07:27:12Z | [
"python",
"nginx",
"pylons",
"paste",
"paster"
] |
Pylons: address already in use when trying to serve | 1,071,071 | <p>I'm running pylons and I did this:
paster server development.ini
It's running on :5000</p>
<p>But when I try to run the command again:
paster serve development.ini</p>
<p>I get this message:
socket.error: [Errno 98] Address already in use</p>
<p>Any ideas?</p>
| 3 | 2009-07-01T20:03:07Z | 9,109,982 | <p>I've found this trick in a forum:</p>
<p>This will kill all programs listening to port 5000</p>
<pre><code>kill -9 `fuser -n tcp 5000`
</code></pre>
| 15 | 2012-02-02T09:35:17Z | [
"python",
"nginx",
"pylons",
"paste",
"paster"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.