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 |
|---|---|---|---|---|---|---|---|---|---|
Applying a common font scheme to multiple objects in wxPython | 171,694 | <p>Many times I will use the same font scheme for static text in a wxPython application. Currently I am making a <strong>SetFont()</strong> call for each static text object but that seems like a lot of unnecessary work. However, the wxPython demo and <em>wxPython In Action</em> book don't discuss this.</p>
<p>Is there... | 3 | 2008-10-05T08:27:57Z | 184,571 | <p>You can do this by calling SetFont on the parent window (Frame, Dialog, etc) before adding any widgets. The child widgets will inherit the font.</p>
| 5 | 2008-10-08T19:55:40Z | [
"python",
"fonts",
"wxpython"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 171,779 | <p>To expand on what Shimi has said, you should only be running your loop from 1 to the square root of n. Then to find the pair, do <code>n / i</code>, and this will cover the whole problem space.</p>
<p>As was also noted, this is a NP, or 'difficult' problem. Exhaustive search, the way you are doing it, is about as g... | 19 | 2008-10-05T10:03:51Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 171,784 | <p>Given your factorGenerator function, here is a divisorGen that should work:</p>
<pre><code>def divisorGen(n):
factors = list(factorGenerator(n))
nfactors = len(factors)
f = [0] * nfactors
while True:
yield reduce(lambda x, y: x*y, [factors[x][0]**f[x] for x in range(nfactors)], 1)
i ... | 62 | 2008-10-05T10:09:20Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 371,129 | <p>I like Greg solution, but I wish it was more python like.
I feel it would be faster and more readable;
so after some time of coding I came out with this.</p>
<p>The first two functions are needed to make the cartesian product of lists.
And can be reused whnever this problem arises.
By the way, I had to program t... | 5 | 2008-12-16T12:17:12Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 15,025,068 | <p>Adapted from <a href="http://codereview.stackexchange.com/a/23015/8431">CodeReview</a>, here is a variant which works with <code>num=1</code> !</p>
<pre><code>from itertools import product
import operator
def prod(ls):
return reduce(operator.mul, ls, 1)
def powered(factors, powers):
return prod(f**p for (f,... | 2 | 2013-02-22T13:11:56Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 18,366,032 | <p>Assuming that the <code>factors</code> function returns the factors of <em>n</em> (for instance, <code>factors(60)</code> returns the list [2, 2, 3, 5]), here is a function to compute the divisors of <em>n</em>:</p>
<pre><code>function divisors(n)
divs := [1]
for fact in factors(n)
temp := []
... | 0 | 2013-08-21T19:29:02Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 23,983,542 | <pre><code>return [x for x in range(n+1) if n/x==int(n/x)]
</code></pre>
| -1 | 2014-06-01T19:20:42Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 25,813,885 | <p>For me this works fine and is also clean (Python 3)</p>
<pre><code>def divisors(number):
n = 1
while(n<number):
if(number%n==0):
print(n)
else:
pass
n += 1
print(number)
</code></pre>
<p>Not very fast but returns divisors line by line as you wanted, al... | -1 | 2014-09-12T17:42:43Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 31,340,346 | <p>Here's my solution. It seems to be dumb but works well...and I was trying to find all proper divisors so the loop started from i = 2. </p>
<pre><code>import math as m
def findfac(n):
faclist = [1]
for i in range(2, int(m.sqrt(n) + 2)):
if n%i == 0:
if i not in faclist:
... | 0 | 2015-07-10T12:05:26Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 36,070,582 | <p>Old question, but here is my take:</p>
<pre><code>def divs(n, m):
if m == 1: return [1]
if n % m == 0: return [m] + divs(n, m - 1)
return divs(n, m - 1)
</code></pre>
<p>You can proxy with:</p>
<pre><code>def divisorGenerator(n):
for x in reversed(divs(n, n)):
yield x
</code></pre>
<p>NOT... | 0 | 2016-03-17T20:01:32Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 36,700,288 | <p>I think you can stop at <code>math.sqrt(n)</code> instead of n/2. </p>
<p>I will give you example so that you can understand it easily. Now the <code>sqrt(28)</code> is <code>5.29</code> so <code>ceil(5.29)</code> will be 6. So I if I will stop at 6 then I will can get all the divisors. How?</p>
<p>First see the c... | 0 | 2016-04-18T17:13:37Z | [
"python",
"algorithm",
"math"
] |
What is the best way to get all the divisors of a number? | 171,765 | <p>Here's the very dumb way:</p>
<pre><code>def divisorGenerator(n):
for i in xrange(1,n/2+1):
if n%i == 0: yield i
yield n
</code></pre>
<p>The result I'd like to get is similar to this one, but I'd like a smarter algorithm (this one it's too much slow and dumb :-)</p>
<p>I can find prime factors an... | 62 | 2008-10-05T09:48:58Z | 37,058,745 | <p>Although there are already many solutions to this, I really have to post this :)</p>
<p>This one is:</p>
<ul>
<li>readable </li>
<li>short</li>
<li>self contained, copy & paste ready</li>
<li>quick (in cases with a lot of prime factors and divisors, > 10 times faster than Greg's solution)</li>
<li>python3, pyt... | 5 | 2016-05-05T19:25:54Z | [
"python",
"algorithm",
"math"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,053 | <p>I'm also looking into this. I too am working on a Django project that might utilize Open Id. For references, check out:</p>
<ul>
<li><a href="http://siege.org/projects/phpMyID/" rel="nofollow">PHPMyId</a></li>
<li><a href="http://openid.net/get/" rel="nofollow">OpenId's page</a></li>
</ul>
<p>Hopefully someone h... | 3 | 2008-10-05T14:20:57Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,058 | <p>I'm using <a href="http://siege.org/projects/phpMyID/" rel="nofollow">phpMyID</a> to authenticate at StackOverflow right now. Generates a standard HTTP auth realm and works perfectly. It should be exactly what you need.</p>
| 3 | 2008-10-05T14:22:37Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,086 | <p>Why not run an OpenID provider from your local machine?</p>
<p>If you are a .Net developer there is an OpenID provider library for .Net at <a href="http://code.google.com/p/dotnetopenid/" rel="nofollow">Google Code</a>. This uses the standard .Net profile provider mechanism and wraps it with an OpenID layer. We are... | 1 | 2008-10-05T14:48:18Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,137 | <p>You could probably use the django OpenID library to write a provider to test against. Have one that always authenticates and one that always fails.</p>
| 3 | 2008-10-05T15:24:31Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,145 | <p>I have no problems testing with <a href="http://myopenid.com" rel="nofollow">myopenid.com</a>. I thought there would be a problem testing on my local machine but it just worked. (I'm using ASP.NET with DotNetOpenId library).</p>
<p>The 'realm' and return url must contain the port number like '<a href="http://localh... | 9 | 2008-10-05T15:29:43Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 172,244 | <p>You shouldn't be having trouble developing against your own machine. What error are you getting?</p>
<p>An OpenID provider will ask you to give your site (in this case <a href="http://localhost:8000" rel="nofollow">http://localhost:8000</a> or similar) access to your identity. If you click ok then it will redirect ... | 1 | 2008-10-05T16:40:16Z | [
"python",
"django",
"openid"
] |
How do you develop against OpenID locally | 172,040 | <p>I'm developing a website (in Django) that uses OpenID to authenticate users. As I'm currently only running on my local machine I can't authenticate using one of the OpenID providers on the web. So I figure I need to run a local OpenID server that simply lets me type in a username and then passes that back to my main... | 34 | 2008-10-05T14:08:42Z | 175,273 | <p>The libraries at <a href="http://openidenabled.com/" rel="nofollow">OpenID Enabled</a> ship with examples that are sufficient to run a local test provider. Look in the examples/djopenid/ directory of the python-openid source distribution. Running that will give you an instance of <a href="http://openidenabled.com/... | 13 | 2008-10-06T17:22:39Z | [
"python",
"django",
"openid"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 172,097 | <p>A <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users">user profile</a> (as returned by <code>django.contrib.auth.models.User.get_profile</code>) doesn't extend the User table - the model you specify as the profile model with the <code>AUTH_PROFILE_MODULE</code> sett... | 7 | 2008-10-05T14:53:46Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 172,099 | <p>From the documentation on <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">django auth</a>, if you want to use the User model, it's mandatory to have a username and password, there are no "anonymous accounts". I guess you could create accounts with a default password and then give the oppor... | 0 | 2008-10-05T14:56:24Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 172,464 | <p>Users that can't login? Just given them a totally random password.</p>
<pre><code>import random
user.set_password( str(random.random()) )
</code></pre>
<p>They'll never be able to log on.</p>
| 2 | 2008-10-05T18:57:26Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 176,472 | <p>Using a <a href="http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users" rel="nofollow">model with a ForeignKey field linking to User</a> might not work as you want because you need anonymous access. I'm not sure if that's going to work, but you might try what happens if you let... | 0 | 2008-10-06T22:31:06Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 176,825 | <p>Supply your own authentication routine, then you can check (or not check) anything you like. We do this so if they fail on normal username, we can also let them in on email/password (although that's not what I'm showing below).</p>
<p>in settings.py:</p>
<pre><code>AUTHENTICATION_BACKENDS = (
'django.contrib.a... | 3 | 2008-10-07T00:40:41Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 177,742 | <p>The django.contrib.auth.models.User exists solely for the purpose of using default authentication backend (database-based). If you write your own backend, you can make some accounts passwordless, while keeping <em>normal</em> accounts with passwords. Django documentation has a <a href="http://docs.djangoproject.com/... | 0 | 2008-10-07T09:23:25Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
Django UserProfile... without a password | 172,066 | <p>I'd like to create a subset of Users that don't have a login... basically as a way to add a photographer field to photos without having a full blown account associated with that person (since in many cases, they'll never actually log in to the site). A caveat is that I'd also like to be able to enable an account for... | 1 | 2008-10-05T14:29:56Z | 180,657 | <p>Another upvote for <a href="http://stackoverflow.com/questions/172066/django-userprofile-without-a-password#172097">insin's answer</a>: handle this through a <code>UserProfile</code>. <a href="http://djangopeople.net/ubernostrum/" rel="nofollow">James Bennett</a> has a <a href="http://www.b-list.org/weblog/2006/jun... | 0 | 2008-10-07T22:09:42Z | [
"python",
"database",
"django",
"django-authentication",
"django-users"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 172,313 | <p>Speaking as a library author:</p>
<p>I'm waiting for the final version to be released. My belief, like that of most of the Python community, is that 2.x will continue to be the dominant version for a period of weeks or months. That's plenty of time to release a nice, polished 3.x release.</p>
<p>I'll be maintainin... | 3 | 2008-10-05T17:14:15Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 172,350 | <p>The main idea of 2.6 is to provide a migration path to 3.0. So you can use <code>from __future__ import X</code> slowly migrating one feature at a time until you get all of them nailed down and can move to 3.0. Many of the 3.0 features will flow into 2.6 as well, so you can make the language gap smaller gradually ra... | 5 | 2008-10-05T17:50:42Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 174,305 | <p>Some of my more complex 2.x code is going to stay at 2.5 or 2.6.
I am moving onto 3.0 for all new development once some of the 3rd party libraries I use often have been updated for 3.</p>
| 0 | 2008-10-06T13:32:52Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 214,601 | <p>Here's the general plan for Twisted. I was originally going to blog this, but then I thought: why blog about it when I could get <em>points</em> for it?</p>
<ol>
<li><p><strong>Wait until somebody cares.</strong></p>
<p>Right now, nobody has Python 3. We're not going to spend a bunch of effort until at least one... | 88 | 2008-10-18T04:59:57Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 2,977,934 | <h2><strong>Support both</strong></h2>
<p>I wanted to make an attempt at converting the BeautifulSoup library to 3x for a project I'm working on but I can see how it would be a pain to maintain two different branches of the code.</p>
<p>The current model to handle this include:</p>
<ol>
<li>make a change to the 2x b... | 3 | 2010-06-04T21:32:10Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 5,324,553 | <p>The Zope Toolkit has been in a slow progress to Python 3 support. Slow mainly because many of these libraries are very complex. </p>
<p>For most libraries I use 2to3. Some libraries make do without it because they are simple or have most of the code in a C-extension. zc.buildout, which is a related package, will ru... | 2 | 2011-03-16T11:22:43Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
How are you planning on handling the migration to Python 3? | 172,306 | <p>I'm sure this is a subject that's on most python developers' minds considering that Python 3 is coming out soon. Some questions to get us going in the right direction:</p>
<ol>
<li><p>Will you have a python 2 and python 3 version to be maintained concurrently or will you simply have a python 3 version once it's fi... | 49 | 2008-10-05T17:08:30Z | 13,095,022 | <p>The Django project uses the library <a href="http://packages.python.org/six"><code>six</code></a> to maintain a codebase that works simultaneously on Python 2 <em>and</em> Python 3 (<a href="https://www.djangoproject.com/weblog/2012/aug/19/experimental-python-3-support/">blog post</a>).</p>
<p><code>six</code> does... | 8 | 2012-10-26T22:00:41Z | [
"python",
"migration",
"python-3.x",
"py2to3"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,398 | <p>I'd probably go for <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard#Implementations" rel="nofollow">AES</a>.</p>
| 1 | 2008-10-05T18:26:22Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,420 | <p>AES 256 is generally the preferred choice, but depending on your location (or your customers' location) you may have legal constraints, and will be forced to use something weaker.</p>
<p>Also note that you should use a random IV for each communication and pass it along with the message (this will also save the need... | 3 | 2008-10-05T18:39:01Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,430 | <p>Asymmetric encryption would work in this scenario as well. Simply have each node publish it's public key. Any node that wants to communicate with that node need only encrypt the message with that node's public key. One advantage of using asymmetric keys is that it becomes easier to change and distribute keys -- s... | 1 | 2008-10-05T18:42:31Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,437 | <p>Assuming the use of symmetric crypto, then AES should be your default choice, unless you have a good very reason to select otherwise. </p>
<p>There was a long, involved competition to select AES, and the winner was carefully chosen. Even Bruce Schneier, crypto god, has said that the AES winner is a better choice th... | 4 | 2008-10-05T18:46:12Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,449 | <p>Why not create a VPN among the nodes that must communicate securely? </p>
<p>Then, you don't have to bother coding up your own security solution, and you're not restricted to a static, shared key (which, if compromised, will allow all captured traffic to be decrypted after the fact).</p>
| 1 | 2008-10-05T18:49:11Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 172,458 | <p>Your first thought should be channel security - either SSL/TLS, or IPSec.<br />
Admittedly, these both have a certain amount of setup overhead, IPSec more than SSL/TLS, especially when it comes to PKI etc. - but it more than pays for itself in simplicity of development, reliability, security, and more. Just make sur... | 7 | 2008-10-05T18:52:23Z | [
"python",
"security",
"encryption"
] |
What symmetric cypher to use for encrypting messages? | 172,392 | <p>I haven't a clue about encryption at all. But I need it. How?</p>
<p>Say you have a system of nodes communicating with each other on a network via asynchronous messages. The nodes do not maintain session information about other nodes (this is a design restriction).</p>
<p>Say you want to make sure only your nodes ... | 5 | 2008-10-05T18:23:19Z | 179,023 | <blockquote>
<p>I haven't a clue about encryption at all. But I need it. How?</p>
</blockquote>
<p><strong>DANGER!</strong> If you don't know much about cryptography, don't try to implement it yourself. Cryptography is <em>hard to get right</em>. There are many, many different ways to break the security of a crypt... | 8 | 2008-10-07T15:24:37Z | [
"python",
"security",
"encryption"
] |
How do I split a multi-line string into multiple lines? | 172,439 | <p>I have a multi-line string literal that I want to do an operation on each line, like so:</p>
<pre><code>inputString = """Line 1
Line 2
Line 3"""
</code></pre>
<p>I want to do something like the following:</p>
<pre><code>for line in inputString:
doStuff()
</code></pre>
| 137 | 2008-10-05T18:46:27Z | 172,454 | <pre><code>inputString.splitlines()
</code></pre>
<p>Will give you a list with each item, the <a href="http://docs.python.org/2/library/stdtypes.html#str.splitlines"><code>splitlines()</code></a> method is designed to split each line into a list element.</p>
| 171 | 2008-10-05T18:50:59Z | [
"python",
"string"
] |
How do I split a multi-line string into multiple lines? | 172,439 | <p>I have a multi-line string literal that I want to do an operation on each line, like so:</p>
<pre><code>inputString = """Line 1
Line 2
Line 3"""
</code></pre>
<p>I want to do something like the following:</p>
<pre><code>for line in inputString:
doStuff()
</code></pre>
| 137 | 2008-10-05T18:46:27Z | 172,468 | <p>Like the others said:</p>
<pre><code>inputString.split('\n') # --> ['Line 1', 'Line 2', 'Line 3']
</code></pre>
<p>This is identical to the above, but the string module's functions are deprecated and should be avoided:</p>
<pre><code>import string
string.split(inputString, '\n') # --> ['Line 1', 'Line 2',... | 154 | 2008-10-05T18:58:44Z | [
"python",
"string"
] |
How do I split a multi-line string into multiple lines? | 172,439 | <p>I have a multi-line string literal that I want to do an operation on each line, like so:</p>
<pre><code>inputString = """Line 1
Line 2
Line 3"""
</code></pre>
<p>I want to do something like the following:</p>
<pre><code>for line in inputString:
doStuff()
</code></pre>
| 137 | 2008-10-05T18:46:27Z | 16,752,366 | <p>Might be overkill in this particular case but another option involves using <code>StringIO</code> to create a file-like object</p>
<pre><code>for line in StringIO.StringIO(inputString):
doStuff()
</code></pre>
| 14 | 2013-05-25T17:54:57Z | [
"python",
"string"
] |
How do I split a multi-line string into multiple lines? | 172,439 | <p>I have a multi-line string literal that I want to do an operation on each line, like so:</p>
<pre><code>inputString = """Line 1
Line 2
Line 3"""
</code></pre>
<p>I want to do something like the following:</p>
<pre><code>for line in inputString:
doStuff()
</code></pre>
| 137 | 2008-10-05T18:46:27Z | 22,233,816 | <p>The best way to do this is to simply use <code>str.splitlines</code>.</p>
<p>Besides the advantage mentioned by @efotinis of optionally including the newline character in the split result when called with a <code>True</code> argument, <code>splitlines()</code> handles newlines properly, unlike <code>split("\n")</co... | 24 | 2014-03-06T19:13:57Z | [
"python",
"string"
] |
How do I split a multi-line string into multiple lines? | 172,439 | <p>I have a multi-line string literal that I want to do an operation on each line, like so:</p>
<pre><code>inputString = """Line 1
Line 2
Line 3"""
</code></pre>
<p>I want to do something like the following:</p>
<pre><code>for line in inputString:
doStuff()
</code></pre>
| 137 | 2008-10-05T18:46:27Z | 30,873,284 | <p>I wish comments had proper code text formatting, because I think @1_CR 's answer needs more bumps, and I would like to augment his answer. Anyway, He led me to the following technique; it will use cStringIO if available (BUT NOTE: cStringIO and StringIO are <strong>not the same</strong>, because you cannot subclass ... | 1 | 2015-06-16T16:34:00Z | [
"python",
"string"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,726 | <p>First thing that comes to mind: <a href="http://psyco.sourceforge.net/" rel="nofollow">psyco</a>. It runs only on x86, for the time being.</p>
<p>Then, <a href="http://code.activestate.com/recipes/277940/" rel="nofollow">constant binding</a>. That is, make all global references (and <em>global.attr</em>, <em>global... | 16 | 2008-10-05T21:51:10Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,734 | <p>This won't necessarily speed up any of your code, but is critical knowledge when programming in Python if you want to avoid slowing your code down. The "Global Interpreter Lock" (GIL), has the potential to drastically reduce the speed of your multi-threaded program if its behavior is not understood (yes, this bit m... | 4 | 2008-10-05T21:59:06Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,737 | <p>Run your app through the Python profiler.
Find a serious bottleneck.
Rewrite that bottleneck in C.
Repeat.</p>
| 4 | 2008-10-05T22:02:52Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,740 | <p>Cython and pyrex can be used to generate c code using a python-like syntax. Psyco is also fantastic for appropriate projects (sometimes you'll not notice much speed boost, sometimes it'll be as much as 50x as fast).
I still reckon the best way is to profile your code (cProfile, etc.) and then just code the bottlenec... | 9 | 2008-10-05T22:03:44Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,744 | <p>The usual suspects -- profile it, find the most expensive line, figure out what it's doing, fix it. If you haven't done much profiling before, there could be some big fat quadratic loops or string duplication hiding behind otherwise innocuous-looking expressions.</p>
<p>In Python, two of the most common causes I've... | 22 | 2008-10-05T22:09:25Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,766 | <p>People have given some good advice, but you have to be aware that when high performance is needed, the python model is: punt to c. Efforts like psyco may in the future help a bit, but python just isn't a fast language, and it isn't designed to be. Very few languages have the ability to do the dynamic stuff really ... | 4 | 2008-10-05T22:27:08Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,782 | <p>Just a note on using psyco: In some cases it can actually produce slower run-times. Especially when trying to use psyco with code that was written in C. I can't remember the the article I read this, but the <code>map()</code> and <code>reduce()</code> functions were mentioned specifically. Luckily you can tell psyc... | 3 | 2008-10-05T22:45:13Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,784 | <p>Regarding "Secondly: When writing a program from scratch in python, what are some good ways to greatly improve performance?"</p>
<p>Remember the Jackson rules of optimization: </p>
<ul>
<li>Rule 1: Don't do it.</li>
<li>Rule 2 (for experts only): Don't do it yet.</li>
</ul>
<p>And the Knuth rule:</p>
<ul>
<li>"P... | 40 | 2008-10-05T22:46:37Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,794 | <p>I'm surprised no one mentioned ShedSkin: <a href="http://code.google.com/p/shedskin/">http://code.google.com/p/shedskin/</a>, it automagically converts your python program to C++ and in some benchmarks yields better improvements than psyco in speed. </p>
<p>Plus anecdotal stories on the simplicity: <a href="http:/... | 7 | 2008-10-05T22:54:57Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 172,991 | <p>This is the procedure that I try to follow:<br></p>
<ul>
<li> import psyco; psyco.full()
<li> If it's not fast enough, run the code through a profiler, see where the bottlenecks are. (DISABLE psyco for this step!)
<li> Try to do things such as other people have mentioned to get the code at those bottlenecks as f... | 3 | 2008-10-06T01:38:57Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 173,055 | <p>Rather than just punting to C, I'd suggest:</p>
<p>Make your code count. Do more with fewer executions of lines:</p>
<ul>
<li>Change the algorithm to a faster one. It doesn't need to be fancy to be faster in many cases.</li>
<li>Use python primitives that happens to be written in C. Some things will force an inter... | 26 | 2008-10-06T02:28:52Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 175,283 | <p>If using psyco, I'd recommend <code>psyco.profile()</code> instead of <code>psyco.full()</code>. For a larger project it will be smarter about the functions that got optimized and use a ton less memory.</p>
<p>I would also recommend looking at iterators and generators. If your application is using large data sets t... | 1 | 2008-10-06T17:24:16Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 247,612 | <p>It's often possible to achieve near-C speeds (close enough for any project using Python in the first place!) by replacing explicit algorithms written out longhand in Python with an implicit algorithm using a built-in Python call. This works because most Python built-ins are written in C anyway. Well, in CPython of ... | 3 | 2008-10-29T17:06:02Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 247,641 | <p>The canonical reference to how to improve Python code is here: <a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips" rel="nofollow">PerformanceTips</a>. I'd recommend against optimizing in C unless you really need to though. For most applications, you can get the performance you need by following the ... | 2 | 2008-10-29T17:16:39Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 364,373 | <p>I hope you've read: <a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips">http://wiki.python.org/moin/PythonSpeed/PerformanceTips</a></p>
<p>Resuming what's already there are usualy 3 principles:</p>
<ul>
<li>write code that gets transformed in better bytecode, like, use locals, avoid unnecessary looku... | 5 | 2008-12-12T22:27:19Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 863,670 | <p>Besides the (great) <a href="http://psyco.sourceforge.net/" rel="nofollow">psyco</a> and the (nice) <a href="http://code.google.com/p/shedskin/" rel="nofollow">shedskin</a>, I'd recommend trying <a href="http://www.cython.org/" rel="nofollow">cython</a> a great fork of <a href="http://www.cosc.canterbury.ac.nz/greg.... | 1 | 2009-05-14T14:32:27Z | [
"python",
"optimization",
"performance"
] |
Speeding Up Python | 172,720 | <p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established python project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</stron... | 39 | 2008-10-05T21:46:00Z | 18,849,701 | <p>A couple of ways to speed up Python code were introduced after this question was asked:</p>
<ul>
<li><strong>Pypy</strong> has a JIT-compiler, which makes it a lot faster for CPU-bound code.</li>
<li>Pypy is written in <a href="https://code.google.com/p/rpython/" rel="nofollow"><strong>Rpython</strong></a>, a subse... | 0 | 2013-09-17T12:20:41Z | [
"python",
"optimization",
"performance"
] |
Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx) | 173,246 | <p>I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.</p>
<p>The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scri... | 12 | 2008-10-06T05:07:19Z | 173,292 | <p>You can probably check the code for <a href="http://www.sphider.eu/" rel="nofollow">Sphider</a>. They docs and pdfs, so I'm sure they can read them. Might also lead you in the right direction for other Office formats.</p>
| 2 | 2008-10-06T05:56:07Z | [
"php",
"python",
"perl",
"parsing",
"office-2007"
] |
Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx) | 173,246 | <p>I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.</p>
<p>The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scri... | 12 | 2008-10-06T05:07:19Z | 173,306 | <p>The Office 2007 file formats are open and <a href="http://msdn.microsoft.com/en-us/library/aa338205.aspx">well documented</a>. Roughly speaking, all of the new file formats ending in "x" are zip compressed XML documents. For example:</p>
<blockquote>
<p>To open a Word 2007 XML file Create a
temporary folder in ... | 16 | 2008-10-06T06:10:41Z | [
"php",
"python",
"perl",
"parsing",
"office-2007"
] |
Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx) | 173,246 | <p>I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.</p>
<p>The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scri... | 12 | 2008-10-06T05:07:19Z | 173,340 | <p>I have successfully used the <a href="http://msdn.microsoft.com/en-us/library/bb448854.aspx" rel="nofollow">OpenXML Format SDK</a> in a project to modify an Excel spreadsheet via code. This would require .NET and I'm not sure about how well it would work under Mono.</p>
| 3 | 2008-10-06T06:30:25Z | [
"php",
"python",
"perl",
"parsing",
"office-2007"
] |
Parsing and generating Microsoft Office 2007 files (.docx, .xlsx, .pptx) | 173,246 | <p>I have a web project where I must import text and images from a user-supplied document, and one of the possible formats is Microsoft Office 2007. There's also a need to generate documents in this format.</p>
<p>The server runs CentOS 5.2 and has PHP/Perl/Python installed. I can execute local binaries and shell scri... | 12 | 2008-10-06T05:07:19Z | 1,979,887 | <p>The python docx module can generate formatted Microsoft office docx files from pure Python. Out of the box, it does headers, paragraphs, tables, and bullets, but the makeelement() module can be extended to do arbitrary elements like images.</p>
<pre><code>from docx import *
document = newdocument()
# This location... | 6 | 2009-12-30T12:13:58Z | [
"php",
"python",
"perl",
"parsing",
"office-2007"
] |
Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught? | 173,278 | <p>The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches SystemExit and prevents the exit. This is normally great, but the specific ... | 33 | 2008-10-06T05:40:13Z | 173,323 | <p>You can call <a href="https://docs.python.org/2/library/os.html#os._exit">os._exit()</a> to directly exit, without throwing an exception:</p>
<pre><code> import os
os._exit(1)
</code></pre>
<p>This bypasses all of the python shutdown logic, such as the atexit module, and will not run through the exception handl... | 45 | 2008-10-06T06:24:53Z | [
"python",
"exception",
"exit",
"systemexit"
] |
Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught? | 173,278 | <p>The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches SystemExit and prevents the exit. This is normally great, but the specific ... | 33 | 2008-10-06T05:40:13Z | 13,723,190 | <p>As Jerub said, <code>os._exit(1)</code> is your answer. But, considering it bypasses <em>all</em> cleanup procedures, including <code>finally:</code> blocks, closing files, etc, and should really be avoided at all costs, may I present a "safer-ish" way of using it?</p>
<p>If you problem is <code>SystemExit</code> b... | 29 | 2012-12-05T12:23:15Z | [
"python",
"exception",
"exit",
"systemexit"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 173,299 | <p>You actually want to do this:</p>
<pre><code>for i, tag in enumerate(tag):
tagDict[tag] = i
</code></pre>
<p>The .update() method is used for updating a dictionary using another dictionary, not for changing a single key/value pair.</p>
| 44 | 2008-10-06T06:05:00Z | [
"python",
"dictionary",
"variables"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 173,300 | <p>I think this is what you want to do:</p>
<pre><code>d = {}
for i, tag in enumerate(ithTag):
d[tag] = i
</code></pre>
| 2 | 2008-10-06T06:05:05Z | [
"python",
"dictionary",
"variables"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 173,301 | <p>Try</p>
<pre><code>tagDict[ithTag] = i
</code></pre>
| 2 | 2008-10-06T06:05:28Z | [
"python",
"dictionary",
"variables"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 173,369 | <p>If you want to be clever:</p>
<pre><code>tagDict.update(map(reversed, enumerate(tag)))
</code></pre>
<p>Thanks to Brian for the update. This is apparently ~5% faster than the iterative version.</p>
<p>(EDIT: Thanks saverio for pointing out my answer was incorrect (now fixed). Probably the most efficient/Pythonic ... | 17 | 2008-10-06T06:41:44Z | [
"python",
"dictionary",
"variables"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 179,005 | <p>It's a one-liner:</p>
<pre><code>tagDict = dict((t, i) for i, t in enumerate(tag))
</code></pre>
| 12 | 2008-10-07T15:22:22Z | [
"python",
"dictionary",
"variables"
] |
python dictionary update method | 173,290 | <p>I have a list string tag.</p>
<p>I am trying to initialize a dictionary with the key as the tag string and values as the array index.</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update(ithTag=i)
</code></pre>
<p>The above returns me {'ithTag': 608} <em>608 is the 608th index</em></p>
<p>My probl... | 17 | 2008-10-06T05:53:32Z | 13,350,988 | <p>I think what you want is this:</p>
<pre><code>for i, ithTag in enumerate(tag):
tagDict.update({ithTag: i})
</code></pre>
| 2 | 2012-11-12T20:24:27Z | [
"python",
"dictionary",
"variables"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 173,774 | <p>Have you checked out the <a href="http://www.mobilepythonbook.com/" rel="nofollow">Mobile Python Book</a>?</p>
<blockquote>
<p>This practical hands-on book effectively teaches how to program your own powerful and fun applications easily on Nokia smartphones based on Symbian OS and the S60 platform.</p>
</blockquo... | 3 | 2008-10-06T10:06:13Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 174,358 | <p>I've just started to look into this myself. I've purchased the Mobile Python book above. It looks good so far. </p>
<p>This site has a few tutorials as well:
<a href="http://croozeus.com/tutorials.htm" rel="nofollow">http://croozeus.com/tutorials.htm</a></p>
<p>I'm using putools to code/sync over bluetooth from li... | 3 | 2008-10-06T13:49:52Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 330,298 | <h2>PyS60 -- its cool :)</h2>
<p>I worked quite a lot on PyS60 ver 1.3 FP2. It is a great language to port your apps on
Symbian Mobiles and Powerful too. I did my Major project in PyS60, which was a <a href="http://sourceforge.net/projects/gsmlocator" rel="nofollow">GSM locator</a>(its not the latest version) app for... | 8 | 2008-12-01T08:50:45Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 489,368 | <p>I've written a calculator, that I'd like to have, and made a simple game.
I wrote it right on the phone. I was writing in text editor then switched to Python and ran a script. It is not very comfortable, but it's ok. Moreover, I was writing all this when I hadn't PC nearby.</p>
<p>It was a great experience!</p>
| 0 | 2009-01-28T21:06:11Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 1,195,831 | <p>I have some J2ME experience and now I decided to write a couple of useful apps for my phone so I decided to use PyS60 to study Python by the way:)</p>
<p>Some things I don't like about the platform are:</p>
<ol>
<li>You can't invoke any graphical functions (module appuifw) from non-main thread.</li>
<li>Python scr... | 0 | 2009-07-28T18:22:38Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 1,201,939 | <p>There is a nice little IDE called <a href="http://code.google.com/p/ped-s60/" rel="nofollow">PED</a> for S60 phones which gives you some extra features and makes it easier to code. It's not really that advanced yet, but it's better than manually switching between text editor and python all the time.</p>
<p>HTH</p>
... | 0 | 2009-07-29T17:49:54Z | [
"python",
"mobile",
"pys60"
] |
Does anyone have experience with PyS60 mobile development | 173,484 | <p>I am in the position of having to make a technology choice early in a project which is targetted at mobile phones. I saw that there is a python derivative for S60 and wondered whether anyone could share experiences, good and bad, and suggest appropriate IDE's and emulators.</p>
<p>Please don't tell me that I shoul... | 10 | 2008-10-06T07:37:30Z | 4,553,278 | <p>I've seen here a mobile IDE for pyS60..</p>
<p><a href="http://circuitdesolator.blogspot.com/2010/12/ped-mobile-phyton-ide-for-pys60.html" rel="nofollow">http://circuitdesolator.blogspot.com/2010/12/ped-mobile-phyton-ide-for-pys60.html</a></p>
<p>It's called PED and i've been using it in the past months..</p>
| 1 | 2010-12-29T10:25:53Z | [
"python",
"mobile",
"pys60"
] |
Is it possible to pass arguments into event bindings? | 173,687 | <p>I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO.</p>
<p>When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way:</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self... | 23 | 2008-10-06T09:31:40Z | 173,694 | <p>You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific.</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, 'somevalue'), b)
def OnClick(self, event, somearg):
self.lo... | 37 | 2008-10-06T09:38:08Z | [
"python",
"events",
"wxpython"
] |
Is it possible to pass arguments into event bindings? | 173,687 | <p>I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO.</p>
<p>When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way:</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self... | 23 | 2008-10-06T09:31:40Z | 173,826 | <p>The nicest way would be to make a generator of event handlers, e.g.:</p>
<pre><code>def getOnClick(self, additionalArgument):
def OnClick(self, event):
self.log.write("Click! (%d), arg: %s\n"
% (event.GetId(), additionalArgument))
return OnClick
</code></pre>
<p>Now you bi... | 11 | 2008-10-06T10:33:33Z | [
"python",
"events",
"wxpython"
] |
How do I blink/control Macbook keyboard LEDs programmatically? | 173,905 | <p>Do you know how I can switch on/off (blink) Macbook keyboard led (caps lock,numlock) under Mac OS X (preferably Tiger)?</p>
<p>I've googled for this, but have got no results, so I am asking for help.</p>
<p>I would like to add this feature as notifications (eg. new message received on Adium, new mail received).</p... | 4 | 2008-10-06T11:11:05Z | 173,914 | <p><a href="http://googlemac.blogspot.com/2008/04/manipulating-keyboard-leds-through.html" rel="nofollow">http://googlemac.blogspot.com/2008/04/manipulating-keyboard-leds-through.html</a></p>
| 5 | 2008-10-06T11:15:02Z | [
"python",
"osx",
"keyboard",
"blink"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 174,184 | <p>Have a look at this question <a href="http://stackoverflow.com/questions/169897/how-to-package-twisted-program-with-py2exe">how-to-package-twisted-program-with-py2exe</a> it seems to be the same problem.</p>
<p>The answer given there is to explicitly include the modules on the command line to py2exe.</p>
| 4 | 2008-10-06T13:05:01Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 174,203 | <p>If you don't have to work with py2exe, bbfreeze works better, and I've tried it with the email module. <a href="http://pypi.python.org/pypi/bbfreeze/0.95.4" rel="nofollow">http://pypi.python.org/pypi/bbfreeze/0.95.4</a></p>
| 1 | 2008-10-06T13:09:26Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 174,769 | <p>Use the "includes" option. See: <a href="http://www.py2exe.org/index.cgi/ListOfOptions" rel="nofollow">http://www.py2exe.org/index.cgi/ListOfOptions</a></p>
| 2 | 2008-10-06T15:31:13Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 176,305 | <p>What version of Python are you using? If you are using 2.5 or 2.6, then you should be doing your import like:</p>
<pre><code>import string,time,sys,os,smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders
</code><... | 4 | 2008-10-06T21:38:17Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 1,194,697 | <p>while porting my app from py24 to 26 I had the same problem.</p>
<p>After reading <a href="http://www.py2exe.org/index.cgi/ExeWithEggs" rel="nofollow">http://www.py2exe.org/index.cgi/ExeWithEggs</a>
if found finaly following solution:</p>
<h2>in my application.py:</h2>
<pre><code>import email
import email.mime.te... | 0 | 2009-07-28T14:56:32Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 18,602,374 | <p>This solve my problem:
in setup.py edit</p>
<pre><code>includes = ["email"]
</code></pre>
| 0 | 2013-09-03T22:16:01Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 25,947,245 | <p>Please try this. This works on my py2exe build. Just replace "project_name.py" with your main script. The EXTRA_INCLUDES are packages that you need to include in your build like email package. I this works with you also. </p>
<pre><code>from distutils.core import setup
import py2exe, sys, os
sys.argv.a... | 0 | 2014-09-20T09:20:36Z | [
"python",
"winapi",
"py2exe"
] |
Python - Py2exe can't build .exe using the 'email' module | 174,170 | <p>py2exe does not work with the standard email module</p>
<p>Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:</p>
<p><hr /></p>
<p>The following modules appear to be missing</p>
<h2>['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.... | 7 | 2008-10-06T13:02:03Z | 31,598,698 | <p>I got it working by explicitly including missing modules in setup.py:</p>
<p>OLD setup.py:</p>
<pre><code>setup(console = ['main.py'])
</code></pre>
<p>New setup.py:</p>
<pre><code>setup(console = ['main.py'],
options={"py2exe":{"includes":["email.mime.multipart","email.mime.text"]}})
</code></pre>
| 1 | 2015-07-23T21:52:10Z | [
"python",
"winapi",
"py2exe"
] |
What is the best way to run multiple subprocesses via fork()? | 174,853 | <p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice.
The parent process goes on processing the rest of the scr... | 8 | 2008-10-06T15:47:59Z | 174,984 | <p>Have you looked at the <a href="http://pyprocessing.berlios.de/" rel="nofollow">pyprocessing</a> module?</p>
| 2 | 2008-10-06T16:16:41Z | [
"python",
"linux"
] |
What is the best way to run multiple subprocesses via fork()? | 174,853 | <p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice.
The parent process goes on processing the rest of the scr... | 8 | 2008-10-06T15:47:59Z | 174,989 | <p>The traditional, UNIX-y way to communicate with sub-processes is to open pipes to their standard input/output, and use the <code>select()</code> system call to multiplex the communications in the parent process (available in Python via... the <code>select</code> module).</p>
<p>If you need to kill a slow-running ch... | 1 | 2008-10-06T16:17:28Z | [
"python",
"linux"
] |
What is the best way to run multiple subprocesses via fork()? | 174,853 | <p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice.
The parent process goes on processing the rest of the scr... | 8 | 2008-10-06T15:47:59Z | 175,038 | <p>Simple example:</p>
<pre><code>import os
chidren = []
for job in jobs:
child = os.fork()
if child:
children.append(child)
else:
pass # really should exec the job
for child in children:
os.waitpid(child, 0)
</code></pre>
<p>Timing out a slow child is a little more work; you can use ... | 10 | 2008-10-06T16:26:25Z | [
"python",
"linux"
] |
What is the best way to run multiple subprocesses via fork()? | 174,853 | <p>A python script need to spawn multiple sub-processes via fork(). All of those child processes should run simultaneously and the parent process should be waiting for all of them to finish. Having an ability to set some timeout on a "slow" child would be nice.
The parent process goes on processing the rest of the scr... | 8 | 2008-10-06T15:47:59Z | 177,237 | <p><em>Ephemient</em>: each child in your code will stay in the for loop after his job ends. He will fork again and again. Moreover, the children that start when children[] is not empty will try to wait for some of their brothers at the end of the loop. Eventually someone will crash. This is a workaround:</p>
<pre><co... | 4 | 2008-10-07T04:31:40Z | [
"python",
"linux"
] |
How to output CDATA using ElementTree | 174,890 | <p>I've discovered that cElementTree is about 30 times faster than <code>xml.dom.minidom</code> and I'm rewriting my XML encoding/decoding code. However, I need to output XML that contains CDATA sections and there doesn't seem to be a way to do that with ElementTree.</p>
<p>Can it be done?</p>
| 26 | 2008-10-06T15:56:07Z | 175,016 | <p>It's not possible AFAIK... which is a pity. Basically, ElementTree modules assume that the reader is 100% XML compliant, so it shouldn't matter if they output a section as CDATA or some other format that generates the equivalent text.</p>
<p>See <a href="https://mail.python.org/pipermail/python-list/2005-June/3046... | 6 | 2008-10-06T16:21:58Z | [
"python",
"xml"
] |
How to output CDATA using ElementTree | 174,890 | <p>I've discovered that cElementTree is about 30 times faster than <code>xml.dom.minidom</code> and I'm rewriting my XML encoding/decoding code. However, I need to output XML that contains CDATA sections and there doesn't seem to be a way to do that with ElementTree.</p>
<p>Can it be done?</p>
| 26 | 2008-10-06T15:56:07Z | 175,101 | <p>After a bit of work, I found the answer myself. Looking at the ElementTree.py source code, I found there was special handling of XML comments and preprocessing instructions. What they do is create a factory function for the special element type that uses a special (non-string) tag value to differentiate it from regu... | 21 | 2008-10-06T16:41:48Z | [
"python",
"xml"
] |
How to output CDATA using ElementTree | 174,890 | <p>I've discovered that cElementTree is about 30 times faster than <code>xml.dom.minidom</code> and I'm rewriting my XML encoding/decoding code. However, I need to output XML that contains CDATA sections and there doesn't seem to be a way to do that with ElementTree.</p>
<p>Can it be done?</p>
| 26 | 2008-10-06T15:56:07Z | 202,122 | <p><a href="http://lxml.de/">lxml</a> has support for <a href="http://lxml.de/api.html#cdata">CDATA</a> and API like ElementTree.</p>
| 10 | 2008-10-14T17:43:57Z | [
"python",
"xml"
] |
How to output CDATA using ElementTree | 174,890 | <p>I've discovered that cElementTree is about 30 times faster than <code>xml.dom.minidom</code> and I'm rewriting my XML encoding/decoding code. However, I need to output XML that contains CDATA sections and there doesn't seem to be a way to do that with ElementTree.</p>
<p>Can it be done?</p>
| 26 | 2008-10-06T15:56:07Z | 320,876 | <p>Actually this code has a bug, since you don't catch <code>]]></code> appearing in the data you are inserting as CDATA</p>
<p>as per <a href="http://stackoverflow.com/questions/223652/is-there-a-way-to-escape-a-cdata-end-token-in-xml">Is there a way to escape a CDATA end token in xml?</a></p>
<p>you should break... | 5 | 2008-11-26T14:28:21Z | [
"python",
"xml"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.