Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
> Scott David Daniels (SDD) wrote: >SDD> # No need for global declarations, we alter, not replace Yes, I know, but I find it neater to do the global declarations, if only for documentation. And they don't affect the run time, only the compile time. -- Piet van Oostrum URL: http://pie

Python Error from Apress book

2009-07-06 Thread matt0177
http://www.nabble.com/file/p24364269/simple_markup2.py simple_markup2.py http://www.nabble.com/file/p24364269/util2.py util2.py The two above files are from chapter 20 of the Apress book "Beginning Python >From Novice to Professional". When I try to run the command as outlined in the book "simp

Write matrix to text file

2009-07-06 Thread Hanna Michelsen
Hi, I'm working with both python and matlab at the moment and I was wondering if there is an efficient way to take a 2-D array (of 1s and 0s) in python and write it to a text file such that matlab will be able to create a sparse matrix from it later. Thanks! -- http://mail.python.org/mailman/lis

Re: Why is my code faster with append() in a loop than with a large list?

2009-07-06 Thread Piet van Oostrum
> Dave Angel (DA) wrote: >DA> MRAB wrote: >>> Dave Angel >>> wrote: >>> [snip] It would probably save some time to not bother storing the zeroes in the list at all. And it should help if you were to step through a list of primes, rather than trying every possible int. Or at l

Re: Python and webcam capture delay?

2009-07-06 Thread Rhodri James
On Mon, 06 Jul 2009 18:41:03 +0100, jack catcher (nick) wrote: Rhodri James kirjoitti: Does the webcam just deliver frames, or are you getting frames out of a decoder layer? If it's the latter, you want to distribute the encoded video, which should be much lower bandwidth. Exactly how you

Re: Catching control-C

2009-07-06 Thread Piet van Oostrum
> Philip Semanchuk (PS) wrote: >PS> On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote: >>> What is required in a python program to make sure it catches a control- >>> c on the command-line? Do some i/o? The OS here is Linux. >PS> You can use a try/except to catch a KeyboardInterrupt excepti

Newbie needs help

2009-07-06 Thread nacim_bravo
Dear Python gurus, If I'd like to set dielectric constant for the certain material, is it possible to do such in Python environment? If yes, how to do or what syntax can be used? Also, I'd like to get a simulation result, like voltage, is it possible to get this value in Python environment? P

Re: Why re.match()?

2009-07-06 Thread Rhodri James
On Mon, 06 Jul 2009 21:40:49 +0100, kj wrote: In <4a4e2227$0$7801$426a7...@news.free.fr> Bruno Desthuilliers writes: kj a écrit : (snipo To have a special-case re.match() method in addition to a general re.search() method is antithetical to language minimalism, FWIW, Python has no pret

Re: Newbie needs help

2009-07-06 Thread Rhodri James
On Tue, 07 Jul 2009 00:00:39 +0100, wrote: Dear Python gurus, If I'd like to set dielectric constant for the certain material, is it possible to do such in Python environment? If yes, how to do or what syntax can be used? Also, I'd like to get a simulation result, like voltage, is it pos

Re: Re: A Bug By Any Other Name ...

2009-07-06 Thread Rhodri James
On Mon, 06 Jul 2009 17:54:35 +0100, Dave Angel wrote: Rhodri James wrote: Indeed, arguably it's a bug for C compilers to fail to find the valid parsing of "++5" as "+(+5)". All I can say is that I've never even accidentally typed that in twenty years of C programming. But the C language spec

Re: Semi-Newbie needs a little help

2009-07-06 Thread Nile
On Jul 6, 5:22 pm, Chris Rebert wrote: > On Mon, Jul 6, 2009 at 3:02 PM, Nile wrote: > > I am trying to write a simple little program to do some elementary > > stock market analysis.  I read lines, send each line to a function and > > then the function returns a date which serves as a key to a > >

Re: Semi-Newbie needs a little help

2009-07-06 Thread MRAB
Nile wrote: [snip] I initialized the dictionary earlier in the program like this - hashtable = {} I changed the "dict" to hashtable but I still get the same result I will try to learn about the defaultdict but I'm just trying to keep it as simple as I can for now Revised code for x in range

Re: Cleaning up after failing to contructing objects

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 18:15:44 -0300, Scott David Daniels escribió: brasse wrote: I have been thinking about how write exception safe constructors in Python. By exception safe I mean a constructor that does not leak resources when an exception is raised within it. ... > As you can see this i

parsing times like "5 minutes ago"?

2009-07-06 Thread mh
I'm looking for something like Tcl's [clock scan] command which parses human-readable time strings such as: % clock scan "5 minutes ago" 1246925569 % clock scan "tomorrow 12:00" 1246993200 % clock scan "today + 1 fortnight" 1248135628 Does any such package exist for Python

Re: parsing times like "5 minutes ago"?

2009-07-06 Thread Carl Banks
On Jul 6, 5:21 pm, m...@pixar.com wrote: > I'm looking for something like Tcl's [clock scan] command which parses > human-readable time strings such as: > >     % clock scan "5 minutes ago" >     1246925569 >     % clock scan "tomorrow 12:00" >     1246993200 >     % clock scan "today + 1 fortnight

Re: Semi-Newbie needs a little help

2009-07-06 Thread Rhodri James
On Tue, 07 Jul 2009 00:29:36 +0100, Nile wrote: Revised code for x in range(len(file_list)): d = open(file_list[x] , "r") data = d.readlines() k = 0 k = above_or_below(data) print "here is the value that was returned ",k hashtable[k] = hashtable.

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 14:32:10 +0200, Jean-Michel Pichavant wrote: > kj wrote: >> I've rewritten it like this: >> >> sense = cmp(func(hi), func(lo)) >> assert sense != 0, "func is not strictly monotonic in [lo, hi]" >> >> Thanks for your feedback! >> >> kj >> >> > As already said befo

Re: Creating alot of class instances?

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 05:47:18 -0700, Scott David Daniels wrote: > Steven D'Aprano wrote: >> ... That's the Wrong Way to do it -- >> you're using a screwdriver to hammer a nail > > Don't knock tool abuse (though I agree with you here). Sometimes tool > abuse can produce good results. For examp

Re: Where does setuptools live?

2009-07-06 Thread Chris Withers
Floris Bruynooghe wrote: It is, see http://mail.python.org/pipermail/distutils-sig/2009-July/012374.html It's seen no changes in 9 months. It's setuptools... I'm sure you can find many flamefests on distutils- sig about this. Yeah, distutils-sig is the right place to discuss. I wonder ho

Re: Semi-Newbie needs a little help

2009-07-06 Thread Dave Angel
MRAB wrote: Nile wrote: [snip] I initialized the dictionary earlier in the program like this - hashtable = {} I changed the "dict" to hashtable but I still get the same result I will try to learn about the defaultdict but I'm just trying to keep it as simple as I can for now Revised code f

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 16:43:43 +0100, Tim Rowe wrote: > 2009/7/4 kj : > >> Precisely.  As I've stated elsewhere, this is an internal helper >> function, to be called only a few times under very well-specified >> conditions.  The assert statements checks that these conditions are as >> intended.  I.

Re: Newbie needs help

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 17:00:39 -0600, nacim_bravo wrote: > Dear Python gurus, > > If I'd like to set dielectric constant for the certain material, is it > possible to do such in Python environment? If yes, how to do or what > syntax can be used? certain_material.dielectric_constant = 1.234 > Als

Looking for a slick way to classify relationship between two numbers, without tons of if/else

2009-07-06 Thread palewire
In my application, I'd like to have a function that compares two values, either of which may be null, and then classify the result depending on whether one is higher or lower than the other. I find myself writing something clunky like this, and I'm curious whether anyone might know a more elegan

Re: Newbie needs help

2009-07-06 Thread Gary Herron
nacim_br...@agilent.com wrote: Dear Python gurus, If I'd like to set dielectric constant for the certain material, is it possible to do such in Python environment? If yes, how to do or what syntax can be used? Also, I'd like to get a simulation result, like voltage, is it possible to get this

Re: A Bug By Any Other Name ...

2009-07-06 Thread Lawrence D'Oliveiro
In message , Terry Reedy wrote: > ... it is C, not Python, that is out of step with standard usage in math > and most languages ... And it is C that introduced "==" for equality, versus "=" for assignment, which Python slavishly followed instead of keeping "=" with its mathematical meaning and

Re: Where does setuptools live?

2009-07-06 Thread David Lyon
On Tue, 07 Jul 2009 02:09:41 +0100, Chris Withers wrote: > I wonder how close setuptools is to being forked because of Phil Eby's > unwillingness to apply patches and/or clean up the horrible setuptools > code? setuptools... as far as I can see isn't actually installed until you install easyinst

Re: Looking for a slick way to classify relationship between two numbers, without tons of if/else

2009-07-06 Thread Rhodri James
On Tue, 07 Jul 2009 02:25:13 +0100, palewire wrote: In my application, I'd like to have a function that compares two values, either of which may be null, and then classify the result depending on whether one is higher or lower than the other. I find myself writing something clunky like this, a

Re: Python Error from Apress book

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 19:56:40 -0300, matt0177 escribió: When I try to run the command as outlined in the book "simple_markup2.py < test_input.txt > test_output.html i get the following error every time. IOError: [Errno 9] Bad file descriptor That's a Windows problem. When you execute the scri

Re: A Bug By Any Other Name ...

2009-07-06 Thread Daniel Fetchinson
I wonder how many people have been tripped up by the fact that ++n and --n fail silently for numeric-valued n. >>> >>> What do you mean, "fail silently"? They do exactly what you should >>> expect: >> ++5 # positive of a positive number is p

copytree with timeout in windows

2009-07-06 Thread Astan Chee
Hi, I'm trying to modify the copytree function in shutil so that any file being copied does not take more than 5 minutes (if it does, skip to the next one). This is what I have so far: import shutil import signal, os def handler(signum, frame): print 'Signal handler called with signal', si

module name versus function name resolution conflict.

2009-07-06 Thread rocky
Someone recently reported a problem in pydb where a function defined in his program was conflicting with a module name that pydb uses. I think I understand what's wrong, but I don't have any elegant solutions to the problem. Suggestions would be appreciated. In a nutshell, here's the problem: In

Re: Looking for a slick way to classify relationship between two numbers, without tons of if/else

2009-07-06 Thread Dave Angel
palewire wrote: In my application, I'd like to have a function that compares two values, either of which may be null, and then classify the result depending on whether one is higher or lower than the other. I find myself writing something clunky like this, and I'm curious whether anyone might kn

Re: parsing times like "5 minutes ago"?

2009-07-06 Thread selasley
On Jul 6, 8:43 pm, Carl Banks wrote: > On Jul 6, 5:21 pm, m...@pixar.com wrote: > > > I'm looking for something like Tcl's [clock scan] command which parses > > human-readable time strings such as: > > >     % clock scan "5 minutes ago" > >     1246925569 > >     % clock scan "tomorrow 12:00" > >

Re: Why re.match()?

2009-07-06 Thread Terry Reedy
kj wrote: "There is real value in having a small language." Guido van Rossum, 2007.07.03 http://mail.python.org/pipermail/python-3000/2007-July/008663.html So there. small != minimal BTW, that's just one example. I've seen similar sentimen

Re: Semi-Newbie needs a little help

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 19:49:41 -0300, MRAB escribió: Chris Rebert wrote: from collections import defaultdict counts = defaultdict(lambda: 0) Better is: counts = defaultdict(int) For speed? This is even faster: zerogen = itertools.repeat(0).next counts = defaultdict(zerogen) -- Gabriel Ge

Re: How to map size_t using ctypes?

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 13:29:21 -0300, Philip Semanchuk escribió: On Jul 6, 2009, at 12:10 PM, Diez B. Roggisch wrote: Philip Semanchuk wrote: I can't figure out how to map a C variable of size_t via Python's ctypes module. from ctypes import c_size_t D'oh! [slaps forehead] That will teach

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Aahz
In article <006e795f$0$9711$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: >On Mon, 06 Jul 2009 14:32:10 +0200, Jean-Michel Pichavant wrote: >> kj wrote: >>> >>> sense = cmp(func(hi), func(lo)) >>> assert sense != 0, "func is not strictly monotonic in [lo, hi]" >> >> As already said b

Re: copytree with timeout in windows

2009-07-06 Thread Tim Golden
Astan Chee wrote: Hi, I'm trying to modify the copytree function in shutil so that any file being copied does not take more than 5 minutes (if it does, skip to the next one). One suggestion is to use the CopyFileEx API exposed in the win32file module from pywin32. That allows for a callback

Re: a little wsgi framework

2009-07-06 Thread Hao Lian
timmyt wrote: i'm interested in getting opinions on a small wsgi framework i assembled from webob, sqlalchemy, genshi, and various code fragments i found on the inter-tubes here is the interesting glue - any comments / suggestions would be much appreciated Fun! Since you're already using WebOb

Re: A Bug By Any Other Name ...

2009-07-06 Thread Lie Ryan
Chris Rebert wrote: > On Mon, Jul 6, 2009 at 1:29 AM, Lawrence > D'Oliveiro wrote: >> In message , Tim Golden >> wrote: >> >>> The difficulty here is knowing where to put such a warning. >>> You obviously can't put it against the "++" operator as such >>> because... there isn't one. >> This bug is

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 21:02:19 -0700, Aahz wrote: > In article <006e795f$0$9711$c3e8...@news.astraweb.com>, Steven D'Aprano > wrote: >>On Mon, 06 Jul 2009 14:32:10 +0200, Jean-Michel Pichavant wrote: >>> kj wrote: sense = cmp(func(hi), func(lo)) assert sense != 0, "func is n

Re: Catching control-C

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 15:02:26 -0700, Michael Mossey wrote: > On Jul 6, 2:47 pm, Philip Semanchuk wrote: >> On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote: >> >> > What is required in a python program to make sure it catches a >> > control- >> > c on the command-line? Do some i/o? The OS here is

Re: A Bug By Any Other Name ...

2009-07-06 Thread Steven D'Aprano
On Tue, 07 Jul 2009 04:51:51 +, Lie Ryan wrote: > Chris Rebert wrote: >> On Mon, Jul 6, 2009 at 1:29 AM, Lawrence >> D'Oliveiro wrote: >>> In message , Tim >>> Golden wrote: >>> The difficulty here is knowing where to put such a warning. You obviously can't put it against the "++" op

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Lie Ryan
Aahz wrote: > In article <006e795f$0$9711$c3e8...@news.astraweb.com>, > Steven D'Aprano wrote: >> On Mon, 06 Jul 2009 14:32:10 +0200, Jean-Michel Pichavant wrote: >>> kj wrote: sense = cmp(func(hi), func(lo)) assert sense != 0, "func is not strictly monotonic in [lo, hi]" >>> As

Re: ANN: GMPY 1.10 alpha with support for Python 3

2009-07-06 Thread casevh
I discovered a serious bug with comparisons and have posted alpha2 which fixes that bug and adds Unicode support for Python 2.x casevh -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: GMPY 1.10 alpha with support for Python 3

2009-07-06 Thread Mensanator
On Jul 7, 12:16�am, casevh wrote: > I discovered a serious bug with comparisons and have posted alpha2 > which fixes that bug and adds Unicode support for Python 2.x > > casevh Damn! I was just congatulating myself for pulling off a hat trick (there had been no point in downloading 3.x without gm

Re: A Bug By Any Other Name ...

2009-07-06 Thread Daniel Fetchinson
>> Yes, there are plenty of languages other than Java and C, but the >> influence of C is admittedly huge in Python. Why do you think loops >> are called "for", conditionals "if" or "while", functions return via >> "return", loops terminate via "break" and keep going via "continue" >> and why is co

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Steven D'Aprano
On Tue, 07 Jul 2009 05:13:28 +, Lie Ryan wrote: > When people are fighting over things like `sense`, although sense may > not be strictly wrong dictionary-wise, it smells of something burning... That would be my patience. I can't believe the direction this discussion has taken. Anybody sensi

Re: Python and webcam capture delay?

2009-07-06 Thread jack catcher (nick)
Nobody kirjoitti: On Mon, 06 Jul 2009 20:41:03 +0300, jack catcher (nick) wrote: Does the webcam just deliver frames, or are you getting frames out of a decoder layer? If it's the latter, you want to distribute the encoded video, which should be much lower bandwidth. Exactly how you do that d

Re: parsing times like "5 minutes ago"?

2009-07-06 Thread Paul McGuire
On Jul 6, 7:21 pm, m...@pixar.com wrote: > I'm looking for something like Tcl's [clock scan] command which parses > human-readable time strings such as: > >     % clock scan "5 minutes ago" >     1246925569 >     % clock scan "tomorrow 12:00" >     1246993200 >     % clock scan "today + 1 fortnight

Re: why PyObject_VAR_HEAD?

2009-07-06 Thread Eric Wong
kio wrote: > Hi, > > I'm studying the CPython source code. I don’t quite understand why > they’re using PyObject_VAR_HEAD to define struct like PyListObject. To > define such kind of struct, could I use _PyObject_HEAD_EXTRA as a > header and add "items" pointer and "allocated" count explicity? I

Re: A Bug By Any Other Name ...

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 10:13 PM, Steven D'Aprano wrote: > On Tue, 07 Jul 2009 04:51:51 +, Lie Ryan wrote: > >> Chris Rebert wrote: >>> On Mon, Jul 6, 2009 at 1:29 AM, Lawrence >>> D'Oliveiro wrote: In message , Tim Golden wrote: > The difficulty here is knowing where to put s

Re: Opening a SQLite database in readonly mode

2009-07-06 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Joshua Kugler wrote: > BTW, APSW is written by the same author as pysqlite. Not even remotely true :-) pysqlite was written by various people, with the maintainer of the last several years being Gerhard Häring. I am the (sole) author of APSW and hav

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-06 Thread John Nagle
Steven D'Aprano wrote: On Sun, 05 Jul 2009 01:58:13 -0700, Paul Rubin wrote: Steven D'Aprano writes: Okay, we get it. Parsing HTML 5 is a bitch. What's your point? I don't see how a case statement would help you here: you're not dispatching on a value, but running through a series of tests un

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-06 Thread John Nagle
Steven D'Aprano wrote: On Sun, 05 Jul 2009 10:12:54 +0200, Hendrik van Rooyen wrote: Python is not C. John Nagle is an old hand at Python. He's perfectly aware of this, and I'm sure he's not trying to program C in Python. I'm not entirely sure *what* he is doing, and hopefully he'll speak

Re: module name versus function name resolution conflict.

2009-07-06 Thread Peter Otten
rocky wrote: > Someone recently reported a problem in pydb where a function defined > in his program was conflicting with a module name that pydb uses. I > think I understand what's wrong, but I don't have any elegant > solutions to the problem. Suggestions would be appreciated. > > In a nutshell

Re: copytree with timeout in windows

2009-07-06 Thread Astan Chee
Tim Golden wrote: Astan Chee wrote: Hi, I'm trying to modify the copytree function in shutil so that any file being copied does not take more than 5 minutes (if it does, skip to the next one). One suggestion is to use the CopyFileEx API exposed in the win32file module from pywin32.

<    1   2