Re: Why re.match()?

2009-07-06 Thread kj
In a...@pythoncraft.com (Aahz) writes: >In article , kj wrote: >You may find this enlightening: >http://www.python.org/doc/1.4/lib/node52.html Indeed. Thank you. kj -- http://mail.python.org/mailman/listinfo/python-list

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Martin Vilcans
On Fri, Jul 3, 2009 at 4:05 PM, kj wrote: > I'm will be teaching a programming class to novices, and I've run > into a clear conflict between two of the principles I'd like to > teach: code clarity vs. code reuse.  I'd love your opinion about > it. In general, code clarity is more important than r

Re: A Bug By Any Other Name ...

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 03:33:36 -0300, Gary Herron escribió: Gabriel Genellina wrote: En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano escribió: On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: I wonder how many people have been tripped up by the fact that ++n and

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Andre Engels
On Mon, Jul 6, 2009 at 9:44 AM, Martin Vilcans wrote: > On Fri, Jul 3, 2009 at 4:05 PM, kj wrote: >> I'm will be teaching a programming class to novices, and I've run >> into a clear conflict between two of the principles I'd like to >> teach: code clarity vs. code reuse.  I'd love your opinion abo

Re: A Bug By Any Other Name ...

2009-07-06 Thread Tim Golden
Gabriel Genellina wrote: [... re confusion over ++n etc ...] In this case, a note in the documentation warning about the potential confusion would be fine. The difficulty here is knowing where to put such a warning. You obviously can't put it against the "++" operator as such because... there

Re: Python and webcam capture delay?

2009-07-06 Thread Stef Mientki
jack catcher (nick) wrote: Hi, I'm thinking of using Python for capturing and showing live webcam stream simultaneously between two computers via local area network. Operating system is Windows. I'm going to begin with VideoCapture extension, no ideas about other implementation yet. Do you ha

Re: generation of keyboard events

2009-07-06 Thread RAM
On 5 July, 17:12, Tim Harig wrote: > On 2009-07-05, RAM wrote: > > > I need to start an external program and pass the keyboard events like > > F1,Right arrow key etc to the program..I am trying to use the > > subprocess module to invoke the external program. I am able to invoke > > but not able t

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

2009-07-06 Thread David M . Cooke
Martin v. Löwis v.loewis.de> writes: > > This is a good test for Python implementation bottlenecks. Run > > that tokenizer on HTML, and see where the time goes. > > I looked at it with cProfile, and the top function that comes up > for a larger document (52k) is > ...validator.HTMLConformanceCh

Re: A Bug By Any Other Name ...

2009-07-06 Thread Lawrence D'Oliveiro
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 an epiphenomenon. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: A Bug By Any Other Name ...

2009-07-06 Thread Chris Rebert
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 an epiphenomenon. :) Well, l

Re: A Bug By Any Other Name ...

2009-07-06 Thread alex23
On Jul 6, 5:56 pm, Tim Golden wrote: > Gabriel Genellina wrote: > > In this case, a note in the documentation warning about the potential > > confusion would be fine. > > The difficulty here is knowing where to put such a warning. > You obviously can't put it against the "++" operator as such > be

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

2009-07-06 Thread Lawrence D'Oliveiro
In message <4a4f91f9$0$1587$742ec...@news.sonic.net>, John Nagle wrote: > ("It should be written in C" is not an acceptable answer.) I don't see why not. State machines that have to process input byte by byte are well known to be impossible to implement efficiently in high-level languages. That

Re: generation of keyboard events

2009-07-06 Thread Simon Brunning
2009/7/6 RAM : > I am trying to do this on windows. My program(executable) has been > written in VC++ and when I run this program, I need to click on one > button on the program GUI i,e just I am entering "Enter key" on the > key board. But this needs manual process. So i need to write a python >

Re: A Bug By Any Other Name ...

2009-07-06 Thread John Machin
On Jul 6, 12:32 pm, Lawrence D'Oliveiro wrote: > I wonder how many people have been tripped up by the fact that > >     ++n > > and > >     --n > > fail silently for numeric-valued n. What fail? In Python, ++n and --n are fatuous expressions which SUCCEED silently except for rare circiumstances e

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

2009-07-06 Thread Vilya Harvey
2009/7/6 Xavier Ho : > Why is version B of the code faster than version A? (Only three lines > different) Here's a guess: As the number you're testing gets larger, version A is creating very big list. I'm not sure exactly how much overhead each list entry has in python, but I guess it's at least

Re: A Bug By Any Other Name ...

2009-07-06 Thread Terry Reedy
Gabriel Genellina wrote: In this case, a note in the documentation warning about the potential confusion would be fine. How would that help someone who does not read the doc? -- http://mail.python.org/mailman/listinfo/python-list

Tree structure consuming lot of memory

2009-07-06 Thread mayank gupta
Hi, I am creating a tree data-structure in python; with nodes of the tree created by a simple class : class Node : def __init__(self , other attributes): # initialise the attributes here!! But the problem is I am working with a huge tree (millions of nodes); and each no

Re: A Bug By Any Other Name ...

2009-07-06 Thread Steven D'Aprano
On Mon, 06 Jul 2009 02:19:51 -0300, Gabriel Genellina wrote: > En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano > escribió: >> On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: >> >>> I wonder how many people have been tripped up by the fact that >>> >>> ++n >>> >>> and >>> >>

Re: Tree structure consuming lot of memory

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 2:55 AM, mayank gupta wrote: > Hi, > > I am creating a tree data-structure in python; with nodes of the tree > created by a simple class : > > class Node : >    def __init__(self , other attributes): >   # initialise the attributes here!! > > But the prob

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

2009-07-06 Thread Dave Angel
Xavier Ho wrote: (Here's a short version of the long version below if you don't want to read:) Why is version B of the code faster than version A? (Only three lines different) Version A: http://pastebin.com/f14561243 Version B: http://pastebin.com/f1f657afc

Re: Tree structure consuming lot of memory

2009-07-06 Thread mayank gupta
Thanks for the other possibilites. I would consider option (2) and (3) to improve my code. But out of curiosity, I would still like to know why does an object of a Python-class consume "so" much of memory (1.4 kb), and this memory usage has nothing to do with its attributes. Thanks Regards. On

Opening a SQLite database in readonly mode

2009-07-06 Thread Paul Moore
The SQLite documentation mentions a flag, SQLITE_OPEN_READONLY, to open a database read only. I can't find any equivalent documented in the Python standard library documentation for the sqlite3 module (or, for that matter, on the pysqlite library's website). Is it possible to open a sqlite databas

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

2009-07-06 Thread Xavier Ho
Thanks for the response all, I finally got my 'net working on the mountains, and I think your reasons are quite sound. I'll keep that in mind for the future. Best regards, Ching-Yun "Xavier" Ho, Technical Artist Contact Information Mobile: (+61) 04 3335 4748 Skype ID: SpaXe85 Email: cont...@xavi

Re: A Bug By Any Other Name ...

2009-07-06 Thread Hendrik van Rooyen
"Terry Reedy" wrote: > Gabriel Genellina wrote: > > > > In this case, a note in the documentation warning about the potential > > confusion would be fine. > > How would that help someone who does not read the doc? It obviously won't. All it will do, is that it will enable people on this group

Re: How Python Implements "long integer"?

2009-07-06 Thread Pedram
OK, fine, I read longobject.c at last! :) I found that longobject is a structure like this: struct _longobject { struct _object *_ob_next; struct _object *_ob_prev; Py_ssize_t ob_refcnt; struct _typeobject *ob_type; digit ob_digit[1]; } And a digit is a 15-item array of C's un

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Scott David Daniels
Andre Engels wrote: On Mon, Jul 6, 2009 at 9:44 AM, Martin Vilcans wrote: On Fri, Jul 3, 2009 at 4:05 PM, kj wrote: I'm will be teaching a programming class to novices, and I've run into a clear conflict between two of the principles I'd like to teach: code clarity vs. code reuse. I'd love you

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Jean-Michel Pichavant
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 before, unlike other languages, sense in english does **not** mean direction. You should rewrite th

Re: Creating alot of class instances?

2009-07-06 Thread Scott David Daniels
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 example, using hammers to drive screws for temporary strong holds led to making

VirtualEnv

2009-07-06 Thread Ronn Ross
I'm attempting to write a bootstrap script for virtualenv. I just want to do a couple of easy_install's after the environment is created. It was fairly easy to create the script, but I can't figure out how to implement it. The documentation was not of much help. Can someone please point me in the r

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

2009-07-06 Thread Jean-Michel Pichavant
protocol = {"start":initialiser,"hunt":hunter,"classify":classifier,other states} def state_machine(): next_step = protocol["start"]() while True: next_step = protocol[next_step]() Woot ! I'll keep this one in my mind, while I may not be that concerned by speed unlike t

Re: A Bug By Any Other Name ...

2009-07-06 Thread pdpi
On Jul 6, 1:12 pm, "Hendrik van Rooyen" wrote: > "Terry Reedy" wrote: > > Gabriel Genellina wrote: > > > > In this case, a note in the documentation warning about the potential > > > confusion would be fine. > > > How would that help someone who does not read the doc? > > It obviously won't. > >

Re: How Python Implements "long integer"?

2009-07-06 Thread Mark Dickinson
On Jul 6, 1:24 pm, Pedram wrote: > OK, fine, I read longobject.c at last! :) > I found that longobject is a structure like this: > > struct _longobject { >     struct _object *_ob_next; >     struct _object *_ob_prev; For current CPython, these two fields are only present in debug builds; for a

How to map size_t using ctypes?

2009-07-06 Thread Philip Semanchuk
Hi all, I can't figure out how to map a C variable of size_t via Python's ctypes module. Let's say I have a C function like this: void populate_big_array(double *the_array, size_t element_count) {...} How would I pass parameter 2? A long (or ulong) will (probably) work (on most platforms),

Re: finding most common elements between thousands of multiple arrays.

2009-07-06 Thread Scott David Daniels
Peter Otten wrote: Scott David Daniels wrote: Scott David Daniels wrote: t = timeit.Timer('sum(part[:-1]==part[1:])', 'from __main__ import part') What happens if you calculate the sum in numpy? Try t = timeit.Timer('(part[:-1]==part[1:]).sum()',

Re: A Bug By Any Other Name ...

2009-07-06 Thread Mark Dickinson
On Jul 6, 3:32 am, Lawrence D'Oliveiro wrote: > I wonder how many people have been tripped up by the fact that > >     ++n > > and > >     --n > > fail silently for numeric-valued n. Recent python-ideas discussion on this subject: http://mail.python.org/pipermail/python-ideas/2009-March/003741.h

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

2009-07-06 Thread Hendrik van Rooyen
"Jean-Michel Pichavant" wrote: > Woot ! I'll keep this one in my mind, while I may not be that concerned > by speed unlike the OP, I still find this way of doing very simple and > so intuitive (one will successfully argue how I was not figuring this > out by myself if it was so intuitive). > A

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

2009-07-06 Thread MRAB
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 least constrain yourself to odd numbers (after the initial case of 2).

Help to find a regular expression to parse po file

2009-07-06 Thread gialloporpora
Hi all, I would like to extract string from a PO file. To do this I have created a little python function to parse po file and extract string: import re regex=re.compile("msgid (.*)\\nmsgstr (.*)\\n\\n") m=r.findall(s) where s is a po file like this: msgctxt "write ubiquity commands.descripti

ANN: GMPY 1.10 alpha with support for Python 3

2009-07-06 Thread casevh
An alpha release of GMPY that supports Python 2 and 3 is available. GMPY is a wrapper for the GMP multiple-precision arithmetic library. The MPIR multiple-precision arithmetic library is also supported. GMPY is available for download from http://code.google.com/p/gmpy/ Support for Python 3 require

Re: A Bug By Any Other Name ...

2009-07-06 Thread Rhodri James
On Mon, 06 Jul 2009 10:58:21 +0100, Steven D'Aprano wrote: On Mon, 06 Jul 2009 02:19:51 -0300, Gabriel Genellina wrote: En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano escribió: On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: I wonder how many people have been tripped

Re: Help to find a regular expression to parse po file

2009-07-06 Thread Hallvard B Furuseth
gialloporpora writes: > I would like to extract string from a PO file. To do this I have created > a little python function to parse po file and extract string: > > import re > regex=re.compile("msgid (.*)\\nmsgstr (.*)\\n\\n") > m=r.findall(s) I don't know the syntax of a po file, but this works

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

2009-07-06 Thread J Kenneth King
a...@pythoncraft.com (Aahz) writes: > In article , > Hendrik van Rooyen wrote: >> >>But wait - maybe if he passes an iterator around - the equivalent of >>for char in input_stream... Still no good though, unless the next call >>to the iterator is faster than an ordinary python call. > > Calls to

Re: Help to find a regular expression to parse po file

2009-07-06 Thread MRAB
gialloporpora wrote: Hi all, I would like to extract string from a PO file. To do this I have created a little python function to parse po file and extract string: import re regex=re.compile("msgid (.*)\\nmsgstr (.*)\\n\\n") m=r.findall(s) where s is a po file like this: msgctxt "write ubiqu

Re: How Python Implements "long integer"?

2009-07-06 Thread Pedram
Hello Mr. Dickinson. Glad to see you again :) On Jul 6, 5:46 pm, Mark Dickinson wrote: > On Jul 6, 1:24 pm, Pedram wrote: > > > OK, fine, I read longobject.c at last! :) > > I found that longobject is a structure like this: > > > struct _longobject { > >     struct _object *_ob_next; > >     str

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> It would probably save some time to not bother storing the zeroes in the >DA> list at all. And it should help if you were to step through a list of >DA> primes, rather than trying every possible int. Or at least constrain >DA> yourself to odd numbers (after the

Re: Python and webcam capture delay?

2009-07-06 Thread Rhodri James
On Mon, 06 Jul 2009 07:10:38 +0100, jack catcher (nick) wrote: Tim Roberts kirjoitti: "jack catcher (nick)" wrote: I'm thinking of using Python for capturing and showing live webcam stream simultaneously between two computers via local area network. Operating system is Windows. I'm goin

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

2009-07-06 Thread Jean-Michel Pichavant
Hendrik van Rooyen wrote: "Jean-Michel Pichavant" wrote: Woot ! I'll keep this one in my mind, while I may not be that concerned by speed unlike the OP, I still find this way of doing very simple and so intuitive (one will successfully argue how I was not figuring this out by myself if it

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Tim Rowe
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.e. they are checks against the module writer's > programming

try -> except -> else -> except?

2009-07-06 Thread David House
Hi all, I'm looking for some structure advice. I'm writing something that currently looks like the following: try: except KeyError: else: This is working fine. However, I now want to add a call to a function in the `else' part that may raise an exception, say a ValueError. So I wa

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

2009-07-06 Thread Piet van Oostrum
Sorry, there was an error in the sieve in my last example. Here is a corrected version: D = {9: 6} # contains composite numbers Dlist = [2, 3] # list of already generated primes def sieve(): '''generator that yields all prime numbers''' global D global Dlist for q in Dlist:

Re: try -> except -> else -> except?

2009-07-06 Thread Piet van Oostrum
> David House (DH) wrote: >DH> Hi all, >DH> I'm looking for some structure advice. I'm writing something that >DH> currently looks like the following: >DH> try: >DH> >DH> except KeyError: >DH> >DH> else: >DH> >DH> This is working fine. However, I now want to add a call to a f

Re: How to map size_t using ctypes?

2009-07-06 Thread Diez B. Roggisch
Philip Semanchuk wrote: > Hi all, > I can't figure out how to map a C variable of size_t via Python's > ctypes module. Let's say I have a C function like this: > > void populate_big_array(double *the_array, size_t element_count) {...} > > How would I pass parameter 2? A long (or ulong) will (pro

Python-URL! - weekly Python news and links (Jul 6)

2009-07-06 Thread Gabriel Genellina
QOTW: "Simulating a shell with hooks on its I/O should be so complicated that a 'script kiddie' has trouble writing a Trojan." - Scott David Daniels http://groups.google.com/group/comp.lang.python/msg/1c0f70d5fc69b5aa Python 3.1 final was released last week - congratulations!

Re: try -> except -> else -> except?

2009-07-06 Thread David House
2009/7/6 Python : > as far as I know try has no 'else' It does: http://docs.python.org/reference/compound_stmts.html#the-try-statement > it's 'finally' There is a `finally', too, but they are semantically different. See the above link. -- -David -- http://mail.python.org/mailman/listinfo/pyth

Re: try -> except -> else -> except?

2009-07-06 Thread Python
On 6 jul 2009, at 18:14, David House wrote: 2009/7/6 Python : as far as I know try has no 'else' It does: http://docs.python.org/reference/compound_stmts.html#the-try-statement it's 'finally' There is a `finally', too, but they are semantically different. See the above link. -- -David

Re: How to map size_t using ctypes?

2009-07-06 Thread Philip Semanchuk
On Jul 6, 2009, at 12:10 PM, Diez B. Roggisch wrote: Philip Semanchuk wrote: Hi all, I can't figure out how to map a C variable of size_t via Python's ctypes module. Let's say I have a C function like this: void populate_big_array(double *the_array, size_t element_count) {...} How would

Re: generation of keyboard events

2009-07-06 Thread Tim Harig
On 2009-07-06, RAM wrote: > I am trying to do this on windows. My program(executable) has been > written in VC++ and when I run this program, I need to click on one > button on the program GUI i,e just I am entering "Enter key" on the > key board. But this needs manual process. So i need to write

Re: Help to find a regular expression to parse po file

2009-07-06 Thread gialloporpora
Risposta al messaggio di Hallvard B Furuseth : I don't know the syntax of a po file, but this works for the snippet you posted: arg_re = r'"[^\\\"]*(?:\\.[^\\\"]*)*"' arg_re = '%s(?:\s+%s)*' % (arg_re, arg_re) find_re = re.compile( r'^msgid\s+(' + arg_re + ')\s*\nmsgstr\s+(' + arg_re + '

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

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

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

2009-07-06 Thread Dave Angel
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 least constrain yourself to odd numbers (after the initial

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

2009-07-06 Thread Dave Angel
Rhodri James wrote: On Mon, 06 Jul 2009 10:58:21 +0100, Steven D'Aprano wrote: On Mon, 06 Jul 2009 02:19:51 -0300, Gabriel Genellina wrote: En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano escribió: On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: I wonder how many peo

Re: try -> except -> else -> except?

2009-07-06 Thread Python
On 6 jul 2009, at 17:46, David House wrote: Hi all, I'm looking for some structure advice. I'm writing something that currently looks like the following: try: except KeyError: else: This is working fine. However, I now want to add a call to a function in the `else' part that may

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

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

Re: Tree structure consuming lot of memory

2009-07-06 Thread Simon Forman
On Mon, Jul 6, 2009 at 6:12 AM, mayank gupta wrote: > Thanks for the other possibilites. I would consider option (2) and (3) to > improve my code. > > But out of curiosity, I would still like to know why does an object of a > Python-class consume "so" much of memory (1.4 kb), and this memory usage

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

2009-07-06 Thread MRAB
Dave Angel wrote: 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 least constrain yourself to odd numbers

updating, adding new pages to confluence remotely, using python

2009-07-06 Thread pescadero10
Hello, I am new to python and have been trying to figure out how to remotely add new pages to my confluence wiki space. I'm running my python script from a linux rhel4 machine and using confluence version 2.10. As a test I tried to read from stdin and write a page but it fails- that is, the script

Re: Python and webcam capture delay?

2009-07-06 Thread jack catcher (nick)
Rhodri James kirjoitti: On Mon, 06 Jul 2009 07:10:38 +0100, jack catcher (nick) wrote: Tim Roberts kirjoitti: "jack catcher (nick)" wrote: I'm thinking of using Python for capturing and showing live webcam stream simultaneously between two computers via local area network. Operating syste

Re: Help to find a regular expression to parse po file

2009-07-06 Thread gialloporpora
Risposta al messaggio di MRAB : gialloporpora wrote: Hi all, I would like to extract string from a PO file. To do this I have created a little python function to parse po file and extract string: import re regex=re.compile("msgid (.*)\\nmsgstr (.*)\\n\\n") m=r.findall(s) where s is a po file

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

2009-07-06 Thread Dave Angel
MRAB wrote: Dave Angel wrote: 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 least constrain yourself t

Re: Clarity vs. code reuse/generality

2009-07-06 Thread David Niergarth
I remember in college taking an intro programming class (C++) where the professor started us off writing a program to factor polynomials; he probably also incorporated binary search into an assignment. But people don't generally use Python to implement binary search or factor polynomials so maybe y

Re: A Bug By Any Other Name ...

2009-07-06 Thread Pablo Torres N.
On Mon, Jul 6, 2009 at 07:12, Hendrik van Rooyen wrote: > "Terry Reedy" wrote: > >> Gabriel Genellina wrote: >> > >> > In this case, a note in the documentation warning about the potential >> > confusion would be fine. >> >> How would that help someone who does not read the doc? > > It obviously w

Ctypes to wrap libusb-1.0

2009-07-06 Thread Scott Sibley
I have been having issues trying to wrap libusb-1.0 with ctypes. Actually, there's not much of an issue if I keep everything synchronous, but I need this to be asynchronous and that is where my problem arises. Please refer to the following link on Stackoverflow for a full overview of the issue. h

Re: Python and webcam capture delay?

2009-07-06 Thread Nobody
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 >> depends a

Re: try -> except -> else -> except?

2009-07-06 Thread Bruno Desthuilliers
David House a écrit : Hi all, I'm looking for some structure advice. I'm writing something that currently looks like the following: try: except KeyError: else: This is working fine. However, I now want to add a call to a function in the `else' part that may raise an exception, s

Re: try -> except -> else -> except?

2009-07-06 Thread Bruno Desthuilliers
Python a écrit : (snip whole OP) as far as I know try has no 'else' Then you may want to RTFM. -- http://mail.python.org/mailman/listinfo/python-list

Re: How Python Implements "long integer"?

2009-07-06 Thread Bruno Desthuilliers
Mark Dickinson a écrit : On Jul 5, 1:09 pm, Pedram wrote: Thanks for reply, Sorry I can't explain too clear! I'm not English ;) That's shocking. Everyone should be English. :-) Mark, tu sors ! -- http://mail.python.org/mailman/listinfo/python-list

Re: A Bug By Any Other Name ...

2009-07-06 Thread Terry Reedy
Mark Dickinson wrote: On Jul 6, 3:32 am, Lawrence D'Oliveiro wrote: I wonder how many people have been tripped up by the fact that ++n and --n fail silently for numeric-valued n. Rather few, it seems. Recent python-ideas discussion on this subject: http://mail.python.org/piperm

Re: Tree structure consuming lot of memory

2009-07-06 Thread Antoine Pitrou
mayank gupta gmail.com> writes: > > After a little analysis, I found out that in general it uses about > 1.4 kb of memory for each node!! How did you measure memory use? Python objects are not very compact, but 1.4KB per object seems a bit too much (I would expect more about 150-200 bytes/object

Re: updating, adding new pages to confluence remotely, using python

2009-07-06 Thread Terry Reedy
pescadero10 wrote: I am new to python and have been trying to figure out how to remotely add new pages to my confluence wiki space. I'm running my python script from a linux rhel4 machine and using confluence version 2.10. As a test I tried to read from stdin and write a page but it fails- that

Re: regex question on .findall and \b

2009-07-06 Thread Ethan Furman
Many thanks to all who replied! And, yes, I will *definitely* use raw strings from now on. :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Cleaning up after failing to contructing objects

2009-07-06 Thread brasse
Hello! 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. The following is an example of one possible way to do it: class Foo(object): def __init__(self, name, f

Re: Why re.match()?

2009-07-06 Thread kj
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 pretention to minimalism. Assuming that you me

Re: Opening a SQLite database in readonly mode

2009-07-06 Thread Joshua Kugler
Paul Moore wrote: > The SQLite documentation mentions a flag, SQLITE_OPEN_READONLY, to > open a database read only. I can't find any equivalent documented in > the Python standard library documentation for the sqlite3 module (or, > for that matter, on the pysqlite library's website). > > Is it pos

Re: Tree structure consuming lot of memory

2009-07-06 Thread mayank gupta
I worked out a small code which initializes about 1,000,000 nodes with some attributes, and saw the memory usage on my linux machine (using 'top' command). Then just later I averaged out the memory usage per node. I know this is not the most accurate way but just for estimated value. The kind of N

Re: Tree structure consuming lot of memory

2009-07-06 Thread Chris Rebert
> On Tue, Jul 7, 2009 at 1:28 AM, Antoine Pitrou wrote: >> >> mayank gupta gmail.com> writes: >> > >> > After a little analysis, I found out that in general it uses about >> > 1.4 kb of memory for each node!! >> >> How did you measure memory use? Python objects are not very compact, but >> 1.4KB

Re: Cleaning up after failing to contructing objects

2009-07-06 Thread Scott David Daniels
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 is less than straight forward. Is there some kind > of best practice tha

Re: Why re.match()?

2009-07-06 Thread Diez B. Roggisch
kj schrieb: 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 pretention to minimalism. Assuming that

Catching control-C

2009-07-06 Thread Michael Mossey
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. Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list

getting text from webpage that has embedded flash

2009-07-06 Thread Oisin
HI, Im trying to parse a bands myspace page and get the total number of plays for their songs. e.g. http://www.myspace.com/mybloodyvalentine The problem is that I cannot use urllib2 as the "Total plays" string does not appear in the page source. Any idea of ways around this? Thanks, O -- http:

Re: Catching control-C

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 2: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. try: #code that reads input except KeyboardInterrupt: #Ctrl-C was pressed Cheers, Chris -- http://bl

Re: Catching control-C

2009-07-06 Thread Philip Semanchuk
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. You can use a try/except to catch a KeyboardInterrupt exception, or you can trap it using the signal module:

Re: Catching control-C

2009-07-06 Thread Michael Mossey
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 Linux. > > You can use a try/except to catch a KeyboardInterrupt

Semi-Newbie needs a little help

2009-07-06 Thread Nile
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 dictionary. Each time a date is returned I want to increment the value associated with that date. The

Re: Catching control-C

2009-07-06 Thread Philip Semanchuk
On Jul 6, 2009, at 6:02 PM, 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 Linux. You can use a tr

Re: Semi-Newbie needs a little help

2009-07-06 Thread Chris Rebert
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 > dictionary. Each time a date is returned I want t

Re: Semi-Newbie needs a little help

2009-07-06 Thread Pablo Torres N.
On Mon, Jul 6, 2009 at 17:02, Nile wrote: > Code > >    for x in range(len(file_list)): >    d = open(file_list[x] , "r") >    data = d.readlines() >    k = above_or_below(data)                                # This > function seems to work correctly >    print "here is the value that was returned

Re: Catching control-C

2009-07-06 Thread Ben Charrow
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 Linux. >> You can use a try/except to catc

Re: Semi-Newbie needs a little help

2009-07-06 Thread MRAB
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 dictionary. Each time a date is re

Re: Opening a SQLite database in readonly mode

2009-07-06 Thread Paul Moore
2009/7/6 Joshua Kugler : > Paul Moore wrote: >> The SQLite documentation mentions a flag, SQLITE_OPEN_READONLY, to >> open a database read only. I can't find any equivalent documented in >> the Python standard library documentation for the sqlite3 module (or, >> for that matter, on the pysqlite lib

Re: Semi-Newbie needs a little help

2009-07-06 Thread Nile
On Jul 6, 5:30 pm, "Pablo Torres N." wrote: > On Mon, Jul 6, 2009 at 17:02, Nile wrote: > > Code > > >    for x in range(len(file_list)): > >    d = open(file_list[x] , "r") > >    data = d.readlines() > >    k = above_or_below(data)                                # This > > function seems to work

  1   2   >