PyCon India 2009

2009-07-06 Thread Senthil Kumaran
PyCon India 2009, first Python Conference in India, is being organized by the Python user and developer community in India. The conference will consist of a number of full length presentations, lightning talks, sprints and BoFs. Venue: Indian Institute of Science, Bangalore Dates: 26th and 27th

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

Re: Does cProfile include IO wait time?

2009-07-06 Thread Gabriel Genellina
En Sat, 04 Jul 2009 21:03:38 -0300, Matthew Wilson m...@tplus1.com escribió: I expected to see a bunch of my IO file-reading code in there, but I don't. So this makes me think that the profiler uses CPU time, not clock-on-the-wall time. I'm not an expert on python profiling, and the docs

Re: Help with Sockets.

2009-07-06 Thread Gabriel Genellina
En Sun, 05 Jul 2009 23:06:30 -0300, tanner barnes tanner...@hotmail.com escribió: I am writing a program and in one section there is going to be a lobby with (for testing purposes) about 4 people in it. in the lobby there are two txtctrl's the first for entering your message and the second

Re: Python and webcam capture delay?

2009-07-06 Thread jack catcher (nick)
Tim Roberts kirjoitti: jack catcher (nick) nom...@thank.you 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 going to begin with VideoCapture extension, no ideas about

Re: A Bug By Any Other Name ...

2009-07-06 Thread Gary Herron
Gabriel Genellina wrote: En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano st...@remove-this-cybersource.com.au 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 --n fail silently for

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

2009-07-06 Thread Peter Otten
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()', 'from __main__

Re: Method to separate unit-test methods and data?

2009-07-06 Thread Gabriel Genellina
En Sun, 05 Jul 2009 15:48:06 -0300, Nick Daly nick.m.d...@gmail.com escribió: [test_Midpoint_mid] none_values = ((-1, None),               (None, -12.8)) What I haven't yet figured out how to do though, is properly override the default class member values with values from the config file.  

Re: multiprocessing and freezing on Windows

2009-07-06 Thread Gabriel Genellina
En Sat, 04 Jul 2009 22:15:43 -0300, SK s...@objexx.com escribió: To add a bit more information, I found that I needed to patch get_command_line in multiprocessing/forking.py [...] Is packaging with multiprocessing supposed to be this hard? If so, some documentation is needed. Shouldn't be so

Re: Why re.match()?

2009-07-06 Thread kj
In h2l4o8$sn...@panix3.panix.com a...@pythoncraft.com (Aahz) writes: In article h2l1kc$2t...@reader1.panix.com, kj no.em...@please.post wrote: You may find this enlightening: http://www.python.org/doc/1.4/lib/node52.html Indeed. Thank you. kj --

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Martin Vilcans
On Fri, Jul 3, 2009 at 4:05 PM, kjno.em...@please.post 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

Re: A Bug By Any Other Name ...

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 03:33:36 -0300, Gary Herron gher...@islandtraining.com escribió: Gabriel Genellina wrote: En Mon, 06 Jul 2009 00:28:43 -0300, Steven D'Aprano st...@remove-this-cybersource.com.au escribió: On Mon, 06 Jul 2009 14:32:46 +1200, Lawrence D'Oliveiro wrote: I wonder how many

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Andre Engels
On Mon, Jul 6, 2009 at 9:44 AM, Martin Vilcansmar...@librador.com wrote: On Fri, Jul 3, 2009 at 4:05 PM, kjno.em...@please.post 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

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

Re: generation of keyboard events

2009-07-06 Thread RAM
On 5 July, 17:12, Tim Harig user...@ilthio.net wrote: On 2009-07-05, RAM serverin2...@yahoo.com 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

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 martin at 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

Re: A Bug By Any Other Name ...

2009-07-06 Thread Lawrence D'Oliveiro
In message mailman.2674.1246866966.8015.python-l...@python.org, 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. :) --

Re: A Bug By Any Other Name ...

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 1:29 AM, Lawrence D'Oliveirol...@geek-central.gen.new_zealand wrote: In message mailman.2674.1246866966.8015.python-l...@python.org, 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

Re: A Bug By Any Other Name ...

2009-07-06 Thread alex23
On Jul 6, 5:56 pm, Tim Golden m...@timgolden.me.uk 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

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's

Re: generation of keyboard events

2009-07-06 Thread Simon Brunning
2009/7/6 RAM serverin2...@yahoo.com: 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

Re: A Bug By Any Other Name ...

2009-07-06 Thread John Machin
On Jul 6, 12:32 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand 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

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 cont...@xavierho.com: 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

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

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 st...@remove-this-cybersource.com.au 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

Re: Tree structure consuming lot of memory

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 2:55 AM, mayank guptamooni...@gmail.com 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

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

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:

Re: A Bug By Any Other Name ...

2009-07-06 Thread Hendrik van Rooyen
Terry Reedy t@..el.edu 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

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

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 Vilcansmar...@librador.com wrote: On Fri, Jul 3, 2009 at 4:05 PM, kjno.em...@please.post 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:

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

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

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 the OP,

Re: A Bug By Any Other Name ...

2009-07-06 Thread pdpi
On Jul 6, 1:12 pm, Hendrik van Rooyen m...@microcorp.co.za wrote: Terry Reedy t@..el.edu 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

Re: How Python Implements long integer?

2009-07-06 Thread Mark Dickinson
On Jul 6, 1:24 pm, Pedram pm567...@gmail.com 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

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 l...@geek- central.gen.new_zealand 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:

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

2009-07-06 Thread Hendrik van Rooyen
Jean-Michel Pichavant jeanmic...@sns.com 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

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.description

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

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 st...@remove-this-cybersource.com.au 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 st...@remove-this-cybersource.com.au escribió: On Mon, 06 Jul 2009 14:32:46

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 for the

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 mailman.2639.1246802753.8015.python-l...@python.org, Hendrik van Rooyen m...@microcorp.co.za 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

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

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 dicki...@gmail.com wrote: On Jul 6, 1:24 pm, Pedram pm567...@gmail.com wrote: OK, fine, I read longobject.c at last! :) I found that longobject is a structure like this: struct _longobject {     struct

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...@dejaviewphoto.com (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

Re: Python and webcam capture delay?

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

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 jeanmic...@sns.com 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

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Tim Rowe
2009/7/4 kj no.em...@please.post: 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

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: short amount of code that may raise a KeyError except KeyError: error handler else: nontrivial amount of code This is working fine. However, I now want to add a call to

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 dmho...@gmail.com (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 short amount of code that may raise a KeyError DH except KeyError: DH error handler DH else: DH nontrivial

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 (probably)

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 pyt...@rgbaz.eu: 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: try - except - else - except?

2009-07-06 Thread Python
On 6 jul 2009, at 18:14, David House wrote: 2009/7/6 Python pyt...@rgbaz.eu: 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

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 serverin2...@yahoo.com 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

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...@dejaviewphoto.com (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

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: div class=moz-text-flowed style=font-family: -moz-fixedDave 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

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

2009-07-06 Thread Dave Angel
Rhodri James wrote: div class=moz-text-flowed style=font-family: -moz-fixedOn Mon, 06 Jul 2009 10:58:21 +0100, Steven D'Aprano st...@remove-this-cybersource.com.au 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

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: short amount of code that may raise a KeyError except KeyError: error handler else: nontrivial amount of code This is

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: div class=moz-text-flowed style=font-family: -moz-fixedPiet van Oostrum wrote: Dave Angel da...@dejaviewphoto.com (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

Re: Tree structure consuming lot of memory

2009-07-06 Thread Simon Forman
On Mon, Jul 6, 2009 at 6:12 AM, mayank guptamooni...@gmail.com 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

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: div class=moz-text-flowed style=font-family: -moz-fixedDave 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

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

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) nom...@thank.you wrote: Tim Roberts kirjoitti: jack catcher (nick) nom...@thank.you wrote: I'm thinking of using Python for capturing and showing live webcam stream simultaneously between two computers via local

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: div class=moz-text-flowed style=font-family: -moz-fixedDave Angel wrote: MRAB wrote: div class=moz-text-flowed style=font-family: -moz-fixedDave 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

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

Re: A Bug By Any Other Name ...

2009-07-06 Thread Pablo Torres N.
On Mon, Jul 6, 2009 at 07:12, Hendrik van Rooyenm...@microcorp.co.za wrote: Terry Reedy t@..el.edu 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?

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.

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 bit on

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: short amount of code that may raise a KeyError except KeyError: error handler else: nontrivial amount of code This is working fine. However, I

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 pm567...@gmail.com 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 l...@geek- central.gen.new_zealand 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

Re: Tree structure consuming lot of memory

2009-07-06 Thread Antoine Pitrou
mayank gupta mooniitk at 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

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,

Re: Why re.match()?

2009-07-06 Thread kj
In 4a4e2227$0$7801$426a7...@news.free.fr Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 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

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 possible

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

Re: Tree structure consuming lot of memory

2009-07-06 Thread Chris Rebert
On Tue, Jul 7, 2009 at 1:28 AM, Antoine Pitrou solip...@pitrou.net wrote: mayank gupta mooniitk at 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,

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 that

Re: Why re.match()?

2009-07-06 Thread Diez B. Roggisch
kj schrieb: In 4a4e2227$0$7801$426a7...@news.free.fr Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid 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

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 --

Re: Catching control-C

2009-07-06 Thread Chris Rebert
On Mon, Jul 6, 2009 at 2:37 PM, Michael Mosseymichaelmos...@gmail.com 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

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:

  1   2   3   >