Initial RSON prototype parser in subversion

2010-03-05 Thread Patrick Maupin
I have not yet added indentation sensitivity to the parser (although the tokenizer saves the indentation information for the parser), but the initial prototype parses all of JSON plus a lot of syntax enhancements (comments, hex/binary/octal numbers, relaxed quoting requirements for strings, trailin

Re: My four-yorkshireprogrammers contribution

2010-03-05 Thread D'Arcy J.M. Cain
On Sat, 06 Mar 2010 14:19:03 +1300 Gregory Ewing wrote: > MRAB wrote: > > By the standards of just a few years later, that's not so much a > > microcomputer as a nanocomputer! > > Although not quite as nano as another design published > in EA a couple of years earlier, the EDUC-8: Byte Magazine

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 6:26 pm, MRAB wrote: > Pete Emerson wrote: > > I've been wrestling with dicts. I hope at the very least what I > > discovered helps someone else out, but I'm interested in hearing from > > more learned python users. > > > I found out that adding a two dimensional element without defining

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 8:24 pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > > Why isn't the behavior of collections.defaultdict the default for a > > dict? > > Why would it be? > > If you look up a key in a dict: > > addressbook['Barney Rubble'] > > and you don't actually

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 17:22:14 -0800, Pete Emerson wrote: > Why isn't the behavior of collections.defaultdict the default for a > dict? Why would it be? If you look up a key in a dict: addressbook['Barney Rubble'] and you don't actually have Barney's address, should Python guess and make someth

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Paul Rubin
Pete Emerson writes: > I found out that adding a two dimensional element without defining > first dimension existing doesn't work: > data = {} data['one']['two'] = 'three' You can use a tuple as a subscript if you want: data = {} data['one','two'] = 'three' -- http://mail.pyth

Re: Slicing [N::-1]

2010-03-05 Thread Gary Herron
Mensanator wrote: On Mar 5, 6:34 pm, Gary Herron wrote: Mensanator wrote: On Mar 5, 3:42 pm, Gary Herron wrote: Mensanator wrote: The only way to get a 0 from a reverse range() is to have a bound of -1. Not quite. An empty second bound goes all the way t

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Robert Kern: On 2010-03-03 09:39 AM, Mike Kent wrote: What's the compelling use case for this vs. a simple try/finally? original_dir = os.getcwd() try: os.chdir(somewhere) # Do other stuff finally: os.chdir(original_dir) # Do other cleanup A custo

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
On Mar 5, 6:10 pm, Andreas Waldenburger wrote: > On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson > > > > > > wrote: > > [snip] > > >>> data['one'] = {} > > >>> data['one']['two'] = 'three' > > >>> print data > > {'one': {'two': 'three'}} > > > And through some research, I discovered collecti

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread MRAB
Pete Emerson wrote: I've been wrestling with dicts. I hope at the very least what I discovered helps someone else out, but I'm interested in hearing from more learned python users. I found out that adding a two dimensional element without defining first dimension existing doesn't work: data =

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Chris Kaynor
On Fri, Mar 5, 2010 at 5:22 PM, Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without defining > first

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 6:34 pm, Gary Herron wrote: > Mensanator wrote: > > On Mar 5, 3:42 pm, Gary Herron wrote: > > >> Mensanator wrote: > > >>> The only way to get a 0 from a reverse range() is to have a bound of > >>> -1. > > >> Not quite.  An empty second bound goes all the way to the zero index: > > > No

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Andreas Waldenburger
On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > [snip] > >>> data['one'] = {} > >>> data['one']['two'] = 'three' > >>> print data > {'one': {'two': 'three'}} > > And through some research, I discovered collections.defaultdict (new > in Python 2.5, FWIW): > > >>> import collections

Re: best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Andreas Waldenburger
On Fri, 5 Mar 2010 17:22:14 -0800 (PST) Pete Emerson wrote: > I've been wrestling with dicts. I hope at the very least what I > discovered helps someone else out, but I'm interested in hearing from > more learned python users. > > I found out that adding a two dimensional element without definin

Re: Generic singleton

2010-03-05 Thread Gregory Ewing
Steven D'Aprano wrote: While Doubleton or even Tripleton sound cute, once you get to large counts it all starts getting ugly and horrible. "Polyton"? Blah. Tupleton? -- Greg -- http://mail.python.org/mailman/listinfo/python-list

best practices: is collections.defaultdict my friend or not?

2010-03-05 Thread Pete Emerson
I've been wrestling with dicts. I hope at the very least what I discovered helps someone else out, but I'm interested in hearing from more learned python users. I found out that adding a two dimensional element without defining first dimension existing doesn't work: >>> data = {} >>> data['one'][

Re: Generic singleton

2010-03-05 Thread Gregory Ewing
I think the important difference between None and booleans wrt singleton behaviour is that things are often compared with None using "is", so it's quite important that there only be one instance of NoneType around, and it makes sense not to give people the false impression that they can create ano

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Paul Rubin
Robert Kern writes: >> Markdown, Textile, or possibly Creole;... > I believe ReST predates all of those mentioned. Texinfo and POD are certainly older than ReST. I'm not sure about MediaWiki markup, but it's gotten so much traction that Markdown should probably be abandoned in its favor even if

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Robert Kern
On 2010-03-05 17:59 PM, Chris Rebert wrote: On Fri, Mar 5, 2010 at 2:45 PM, Aahz mailto:a...@pythoncraft.com>> wrote: > In article <7xwrxv4vv7@ruckus.brouhaha.com >, > Paul Rubin wrote: >> >>ReST is another abomination that should never have got

Re: My four-yorkshireprogrammers contribution

2010-03-05 Thread Gregory Ewing
MRAB wrote: By the standards of just a few years later, that's not so much a microcomputer as a nanocomputer! Although not quite as nano as another design published in EA a couple of years earlier, the EDUC-8: http://www.sworld.com.au/steven/educ-8/ It had a *maximum* of 256 bytes -- due t

Re: isinstance(False, int)

2010-03-05 Thread Robert Kern
On 2010-03-05 17:48 PM, Jack Diederich wrote: On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: So, the pythonic way to check for True/False should be: 1 is True False Why do you need to check for True/False? You should n

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Gregory Ewing
Steven D'Aprano wrote: I use footnotes all the time[1] in plain text documents and emails. I don't think there's anything bizarre about it at all. It's not the use of footnotes I'm talking about, it's the cryptic character sequences used to mark them up in ReST. Nobody would come up with them

Re: Slicing [N::-1]

2010-03-05 Thread Gary Herron
Mensanator wrote: On Mar 5, 3:42 pm, Gary Herron wrote: Mensanator wrote: The only way to get a 0 from a reverse range() is to have a bound of -1. Not quite. An empty second bound goes all the way to the zero index: Not the same thing. You're using the bounds of the sl

Re: isinstance(False, int)

2010-03-05 Thread Chris Rebert
On Fri, Mar 5, 2010 at 1:51 PM, Terry Reedy wrote: > On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: >> Steven D'Aprano wrote: > >> Despite there are good reasons for bool to be int, the newcomer 'wtf' >> reaction at first glance is legitimate. >> Starting python from scratch, booleans would hav

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 3:42 pm, Gary Herron wrote: > Mensanator wrote: > > > The only way to get a 0 from a reverse range() is to have a bound of > > -1. > > Not quite.  An empty second bound goes all the way to the zero index: Not the same thing. You're using the bounds of the slice index. I was refering to

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Chris Rebert
On Fri, Mar 5, 2010 at 2:45 PM, Aahz wrote: > In article <7xwrxv4vv7@ruckus.brouhaha.com>, > Paul Rubin wrote: >> >>ReST is another abomination that should never have gotten off the >>ground. It is one of the reasons I react so negatively to your >>config format proposal. It just sounds li

Re: isinstance(False, int)

2010-03-05 Thread Jack Diederich
On Fri, Mar 5, 2010 at 6:09 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: > So, the pythonic way to check for True/False should be: >>> 1 is True False >>> >>> Why do you need to check for True/False? >>> >>> >> You should never check for

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 15:58:01 -0500, Jack Diederich wrote: >>> So, the pythonic way to check for True/False should be: >>> >> 1 is True >>> False >> >> Why do you need to check for True/False? >> >> > You should never check for "is" False/True but always check for > equality. The reason is tha

Re: Generic singleton

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 16:25:46 -0500, Terry Reedy wrote: > On 3/5/2010 1:01 PM, Steven D'Aprano wrote: >> On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: >> >>> On 3/4/2010 10:32 PM, Steven D'Aprano wrote: >>> Python does have it's own singletons, like None, True and False. >>> >>> True

Re: Draft PEP on RSON configuration file format

2010-03-05 Thread Aahz
In article <7xwrxv4vv7@ruckus.brouhaha.com>, Paul Rubin wrote: > >ReST is another abomination that should never have gotten off the >ground. It is one of the reasons I react so negatively to your >config format proposal. It just sounds like more of the same. Really? What should we use ins

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Terry Reedy
On 3/5/2010 4:29 PM, Pete Emerson wrote: On Mar 5, 1:14 pm, Chris Rebert wrote: I want to write other modules, and my thinking is that it makes sense for those modules to use the "logger" module to do the logging, if and only if the parent using the other modules is also using the logger modu

Re: Slicing [N::-1]

2010-03-05 Thread Robert Kern
On 2010-03-05 13:10 PM, Robert Kern wrote: On 2010-03-05 12:28 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)] [7, 6, 5, 4, 3, 2, 1, 0]

Re: isinstance(False, int)

2010-03-05 Thread Robert Kern
On 2010-03-05 14:58 PM, Jack Diederich wrote: On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: Arnaud Delobelle wrote: 1 == True True 0 == False True So what's you

Re: imap vs map

2010-03-05 Thread Arnaud Delobelle
mk writes: > Hello everyone, > > I re-wrote more "slowly" an example at the end of > http://wordaligned.org/articles/essential-python-reading-list > > > This example finds anagrams in the text file. > > > from itertools import groupby, imap > from operator import itemgetter > > from string i

Re: isinstance(False, int)

2010-03-05 Thread Terry Reedy
On 3/5/2010 1:54 PM, Jean-Michel Pichavant wrote: Steven D'Aprano wrote: Despite there are good reasons for bool to be int, the newcomer 'wtf' reaction at first glance is legitimate. Starting python from scratch, booleans would have not been a subclass of int (just guessing though), 'cause it

Re: Passing FILE * types using ctypes

2010-03-05 Thread Neil Hodgson
Zeeshan Quireshi: > Hello, I'm using ctypes to wrap a library i wrote. I am trying to pass > it a FILE *pointer, how do i open a file in Python and convert it to a > FILE *pointer. For this to work, your library should have been compiled with the same compiler as Python and possibly the same c

Re: Slicing [N::-1]

2010-03-05 Thread Terry Reedy
On 3/5/2010 2:10 PM, Robert Kern wrote: Rather, they have 0 and len(seq), respectively, when the step is positive, and len(seq)-1 and -1 when the step is negative. I don't believe the actual behaviour is documented anywhere. True, I don't think it is. There are at least two open issues.

Re: Slicing [N::-1]

2010-03-05 Thread Gary Herron
Mensanator wrote: On Mar 5, 12:28 pm, Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)]

How to send utf-8 mail in Python 3?

2010-03-05 Thread Peter Kleiweg
I try to send e-mail from Python 3.1.1 Encoding as iso-8859-1 goes fine. But encoding as utf-8 doesn't work. What am I doing wrong? Python 3.1.1 (r311:74480, Oct 2 2009, 11:50:52) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" fo

Re: isinstance(False, int)

2010-03-05 Thread Terry Reedy
On 3/5/2010 1:30 PM, MRAB wrote: mk wrote: >>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Python didn't have Booleans originally, 0 and 1 were used instead. When bool was introduced it was made a subclass of int so that exist

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 1:14 pm, Chris Rebert wrote: > On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > >> On 3/5/10, Pete Emerson wrote: > >>> In a module, how do I create a conditional that will do something > >>> based on whether or not anothe

Re: Generic singleton

2010-03-05 Thread Terry Reedy
On 3/5/2010 1:01 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: On 3/4/2010 10:32 PM, Steven D'Aprano wrote: Python does have it's own singletons, like None, True and False. True and False are not singletons. Duotons? Doubletons? The latter is what I u

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Chris Rebert
On Fri, Mar 5, 2010 at 12:25 PM, Pete Emerson wrote: > On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: >> On 3/5/10, Pete Emerson wrote: >>> In a module, how do I create a conditional that will do something >>> based on whether or not another module has been loaded? >>> If someone is using

ANN: Wing IDE 3.2.5 Released

2010-03-05 Thread Wingware
Hi, Wingware has released version 3.2.5 of Wing IDE, an integrated development environment designed specifically for the Python programming language. Wing IDE provides a professional code editor with vi, emacs, and other configurable key bindings, auto-completion, call tips, a powerful graphical

Re: isinstance(False, int)

2010-03-05 Thread Jack Diederich
On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > >> On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >>> Arnaud Delobelle wrote: >>> >>> 1 == True True >>> >>> 0 == False True So wha

Re: start function in new process

2010-03-05 Thread Robert Kern
On 2010-03-05 14:09 PM, wongjoek...@yahoo.com wrote: I can't use multiprocessing module since it comes only with python 2.6 and I am bound to python2.4. It is available as a third party package for Python 2.4: http://pypi.python.org/pypi/multiprocessing -- Robert Kern "I have come to believ

Re: start function in new process

2010-03-05 Thread Martin P. Hellwig
On 03/05/10 20:09, wongjoek...@yahoo.com wrote: On 5 mrt, 21:02, "Martin P. Hellwig" wrote: On 03/05/10 19:45, wongjoek...@yahoo.com wrote: On 5 mrt, 20:40, "Martin P. Hellwig" wrote: On 03/05/10 19:21, wongjoek...@yahoo.com wrote: Any specific reason why threading.Thread or multiprocessin

Re: start function in new process

2010-03-05 Thread Jonathan Gardner
You're really close. See inline comment below. On Fri, Mar 5, 2010 at 11:21 AM, wongjoek...@yahoo.com wrote: > > def c(): >    print "function c" > > def f(a,b, d): >    # function I want to run in a new child process >    print a, b >    d() > > def g(): >    pidID = os.fork() >    if pidID == 0

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 11:57 am, MRAB wrote: > Pete Emerson wrote: > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > Suppose I have the following: > > > import foo > > import foobar > > > print foo() > > print foobar() > > >

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 12:06 pm, "Martin P. Hellwig" wrote: > On 03/05/10 19:24, Pete Emerson wrote: > > > In a module, how do I create a conditional that will do something > > based on whether or not another module has been loaded? > > > > If someone is using foo module, I want to take advantage of its > > fe

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Fri, Mar 5, 2010 at 12:17 PM, Chris Rebert wrote: > On 3/5/10, Pete Emerson wrote: >> In a module, how do I create a conditional that will do something >> based on whether or not another module has been loaded? >> >> Suppose I have the following: >> >> import foo >> import foobar >> >> print f

Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account

2010-03-05 Thread Google Adsense
Buy Genuine Google Adsense Account only for Rs.200/- for indian people. For more details visit http://www.buygoogleadsense.tk/ We also provide procedure for creating unlimited google adsense account trick . -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Chris Rebert
On 3/5/10, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo: >retu

Re: start function in new process

2010-03-05 Thread wongjoek...@yahoo.com
On 5 mrt, 21:02, "Martin P. Hellwig" wrote: > On 03/05/10 19:45, wongjoek...@yahoo.com wrote: > > > > > On 5 mrt, 20:40, "Martin P. Hellwig" > > wrote: > >> On 03/05/10 19:21, wongjoek...@yahoo.com wrote: > >> > >> Any specific reason why threading.Thread or multiprocessing is not > >> suitable t

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Martin P. Hellwig
On 03/05/10 19:24, Pete Emerson wrote: In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? > If someone is using foo module, I want to take advantage of its features and use it in foobar, otherwise, I want to do something els

Re: start function in new process

2010-03-05 Thread Martin P. Hellwig
On 03/05/10 19:45, wongjoek...@yahoo.com wrote: On 5 mrt, 20:40, "Martin P. Hellwig" wrote: On 03/05/10 19:21, wongjoek...@yahoo.com wrote: Any specific reason why threading.Thread or multiprocessing is not suitable to solve your problem? -- mph Because I got a memory leak in my function f()

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread MRAB
Pete Emerson wrote: In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ### foo.py def foo: return 'foo' ### foobar.py d

imap vs map

2010-03-05 Thread mk
Hello everyone, I re-wrote more "slowly" an example at the end of http://wordaligned.org/articles/essential-python-reading-list This example finds anagrams in the text file. from itertools import groupby, imap from operator import itemgetter from string import ascii_lowercase, ascii_up

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Steve Holden
Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > By the way, the above statements are never going

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote: > On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: >> Arnaud Delobelle wrote: >> >> 1 == True >>> >>> True >> >> 0 == False >>> >>> True >>> >>> So what's your question? >> >> Well nothing I'm just kind of bewildered: I'd

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 11:24:44 -0800, Pete Emerson wrote: > In a module, how do I create a conditional that will do something based > on whether or not another module has been loaded? try: import foo except ImportError: foo = None def function(): if foo: return foo.func() e

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Steve Holden
Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo: > return 'foo

Re: start function in new process

2010-03-05 Thread wongjoek...@yahoo.com
On 5 mrt, 20:40, "Martin P. Hellwig" wrote: > On 03/05/10 19:21, wongjoek...@yahoo.com wrote: > > Any specific reason why threading.Thread or multiprocessing is not > suitable to solve your problem? > > -- > mph Because I got a memory leak in my function f(). It uses scipy, numpy, pylab, and I a

Re: isinstance(False, int)

2010-03-05 Thread mk
Rolando Espinoza La Fuente wrote: Doesn't have side effects not knowing that False/True are ints? It does, in fact I was wondering why my iterator didn't work until I figured issubclass(bool, int) is true. Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: start function in new process

2010-03-05 Thread Martin P. Hellwig
On 03/05/10 19:21, wongjoek...@yahoo.com wrote: Any specific reason why threading.Thread or multiprocessing is not suitable to solve your problem? -- mph -- http://mail.python.org/mailman/listinfo/python-list

Re: Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
On Mar 5, 11:24 am, Pete Emerson wrote: > In a module, how do I create a conditional that will do something > based on whether or not another module has been loaded? > > Suppose I have the following: > > import foo > import foobar > > print foo() > print foobar() > > ### foo.py > def foo:

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Steve Howell: On Mar 3, 7:10 am, "Alf P. Steinbach" wrote: For C++ Petru Marginean once invented the "scope guard" technique (elaborated on by Andrei Alexandrescu, they published an article about it in DDJ) where all you need to do to ensure some desired cleanup at the end of a scope, even wh

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 12:28 pm, Steven D'Aprano wrote: > On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: > l = range(10) > l > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > l[7::-1] > > [7, 6, 5, 4, 3, 2, 1, 0] > [l[i] for i in range(7, -1, -1)] > > [7, 6, 5, 4, 3, 2, 1, 0] > > Where does

Conditional based on whether or not a module is being used

2010-03-05 Thread Pete Emerson
In a module, how do I create a conditional that will do something based on whether or not another module has been loaded? Suppose I have the following: import foo import foobar print foo() print foobar() ### foo.py def foo: return 'foo' ### foobar.py def foobar: if foo.

start function in new process

2010-03-05 Thread wongjoek...@yahoo.com
Hello all, I would like to run a python function completely in a new process. For example I have a parent process. That parent process needs to start a child process in which the function is called. After the child process is finished however I want that the child process should stop and then only

Re: A "scopeguard" for Python

2010-03-05 Thread Alf P. Steinbach
* Mike Kent: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. This raises the exception insid

Re: Slicing [N::-1]

2010-03-05 Thread Robert Kern
On 2010-03-05 12:28 PM, Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)] [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
On Fri, Mar 5, 2010 at 2:32 PM, mk wrote: > Arnaud Delobelle wrote: > > 1 == True >> >> True > > 0 == False >> >> True >> >> So what's your question? > > Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, > but not in Python.. Although I can understand the rat

Re: Evaluate my first python script, please

2010-03-05 Thread Pete Emerson
On Mar 5, 10:19 am, "sjdevn...@yahoo.com" wrote: > On Mar 5, 10:53 am, Pete Emerson wrote: > > > > > > > Thanks for your response, further questions inline. > > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > > I am looking for advice

Re: isinstance(False, int)

2010-03-05 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? Yes. Do you have an actual question? >>> issubclass(bool, int) True Huh?! Exactly. Bools are a late-comer to Python.

Re: Slicing [N::-1]

2010-03-05 Thread Mensanator
On Mar 5, 12:01 pm, Joan Miller wrote: > What does a slice as [N::-1] ? Starts at position N and returns all items to the start of the list in reverse order. > > It looks that in the first it reverses the slice and then it shows > only N items, right? Wrong. It shows N+1 items. Remember, counti

Re: Slicing [N::-1]

2010-03-05 Thread Shashwat Anand
On Fri, Mar 5, 2010 at 11:42 PM, Arnaud Delobelle wrote: > Joan Miller writes: > > > What does a slice as [N::-1] ? > > > > It looks that in the first it reverses the slice and then it shows > > only N items, right? > > > > Could you add an example to get the same result without use `::` to > > s

Re: isinstance(False, int)

2010-03-05 Thread mk
Arnaud Delobelle wrote: 1 == True True 0 == False True So what's your question? Well nothing I'm just kind of bewildered: I'd expect smth like that in Perl, but not in Python.. Although I can understand the rationale after skimming PEP 285, I still don't like it very much. Regards, mk

Re: isinstance(False, int)

2010-03-05 Thread MRAB
mk wrote: >>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Python didn't have Booleans originally, 0 and 1 were used instead. When bool was introduced it was made a subclass of int so that existing code wouldn't break. -- h

Re: Slicing [N::-1]

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 18:12:05 +, Arnaud Delobelle wrote: l = range(10) l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] Where does the first -1 come from? Slices are supposed to have default

Re: isinstance(False, int)

2010-03-05 Thread Rolando Espinoza La Fuente
On Fri, Mar 5, 2010 at 2:00 PM, Steve Holden wrote: [...] > > Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it > would be a good ideal for Booleans to be a subclass of integers. > I would never figured out >>> bool.__bases__ (,) Doesn't have side effects not knowing tha

Re: Slicing [N::-1]

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 10:01:40 -0800, Joan Miller wrote: > What does a slice as [N::-1] ? Why don't you try it? >>> s = "abcdefgh" >>> s[4::-1] 'edcba' The rules for extended slicing are not explained very well in the docs, and can be confusing. In my experience, apart from [::-1] it is best to

Re: Evaluate my first python script, please

2010-03-05 Thread sjdevn...@yahoo.com
On Mar 5, 10:53 am, Pete Emerson wrote: > Thanks for your response, further questions inline. > > On Mar 4, 11:07 am, Tim Wintle wrote: > > > On Thu, 2010-03-04 at 10:39 -0800, Pete Emerson wrote: > > > I am looking for advice along the lines of "an easier way to do this" > > > or "a more python

Re: Slicing [N::-1]

2010-03-05 Thread Arnaud Delobelle
Joan Miller writes: > What does a slice as [N::-1] ? > > It looks that in the first it reverses the slice and then it shows > only N items, right? > > Could you add an example to get the same result without use `::` to > see it more clear? > > Thanks in advance >>> l = range(10) >>> l [0, 1, 2,

Re: Escaping variable names

2010-03-05 Thread Jean-Michel Pichavant
Kamil Wasilewski wrote: Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl"; server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country

Re: isinstance(False, int)

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 18:14:16 +0100, mk wrote: isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? Yes. Do you have an actual question? > >>> issubclass(bool, int) > True > > Huh?! Exactly. Bools are a late-comer to Python. For historical and implementatio

Re: isinstance(False, int)

2010-03-05 Thread Stephen Hansen
On Fri, Mar 5, 2010 at 9:14 AM, mk wrote: > >>> isinstance(False, int) > True > >>> > >>> isinstance(True, int) > True > > Huh? > > >>> > >>> issubclass(bool, int) > True > > Huh?! > Huh, what? http://www.python.org/dev/peps/pep-0285/ --S -- http://mail.python.org/mailman/listinfo/python-list

Re: isinstance(False, int)

2010-03-05 Thread Arnaud Delobelle
mk writes: isinstance(False, int) > True isinstance(True, int) > True > > Huh? > issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + False 1 In fact: >>> 1 == True True >>> 0 == False True So what's your question? -- Arnaud -- http://mail

Slicing [N::-1]

2010-03-05 Thread Joan Miller
What does a slice as [N::-1] ? It looks that in the first it reverses the slice and then it shows only N items, right? Could you add an example to get the same result without use `::` to see it more clear? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list

Re: Generic singleton

2010-03-05 Thread Steven D'Aprano
On Fri, 05 Mar 2010 11:57:13 -0500, Terry Reedy wrote: > On 3/4/2010 10:32 PM, Steven D'Aprano wrote: > >> Python does have it's own singletons, like None, True and False. > > True and False are not singletons. Duotons? Doubletons? >>> t1 = bool(1) >>> t2 = bool(1) >>> t1 is t2 True >>> t1 is

Re: isinstance(False, int)

2010-03-05 Thread Steve Holden
mk wrote: isinstance(False, int) > True isinstance(True, int) > True > > Huh? > issubclass(bool, int) > True > > Huh?! > >>> 3+True 4 >>> 3+False 3 >>> Just a brainfart from the BDFL - he decided (around 2.2.3, IIRC) that it would be a good ideal for Booleans to be a s

Escaping variable names

2010-03-05 Thread Kamil Wasilewski
Hi, Ive got an issue where a variable name needs to have a minus sign (-) in it. #Python 2.6 from SOAPpy import WSDL wsdlFile = "http://webapi.allegro.pl/uploader.php?wsdl"; server = WSDL.Proxy(wsdlFile) server.soapproxy.config.argsOrdering = {'doGetCountries': ['country-code', 'webapi-key'] } s

Re: ImportError: No module named glib

2010-03-05 Thread Terry Reedy
On 3/5/2010 3:30 AM, Michael Joachimiak wrote: I am too new to python. If anybody has an idea what to do please help. when I use import glib in my code I get this: import glib Traceback (most recent call last): File "", line 1, in ImportError: No module named glib glib is not in Python'

Re: loop over list and process into groups

2010-03-05 Thread mk
lbolla wrote: It looks like Perl ;-) A positive proof that you can write perl code in Python. I, for instance, have had my brain warped by C and tend to write C-like code in Python. That's only half a joke, sadly. I'm trying to change my habits but it's hard. Regards, mk -- http://mail.p

Re: comparing two lists

2010-03-05 Thread Terry Reedy
On 3/5/2010 3:05 AM, jimgardener wrote: hi I have two lists of names.I need to find the difference between these two lists.I tried to do it using sets.But I am wondering if there is a better way to do it.Please tell me if there is a more elegant way. thanks, jim my code snippet follows.. oldlst

isinstance(False, int)

2010-03-05 Thread mk
>>> isinstance(False, int) True >>> >>> isinstance(True, int) True Huh? >>> >>> issubclass(bool, int) True Huh?! Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread mk
nn wrote: Oh my! You could have at least used some "if else" to make it a little bit easier on the eyes :-) That's my entry into """'Obfuscated' "Python" '"''code''"' '"contest"'""" and I'm proud of it. ;-) Regards, mk -- http://mail.python.org/mailman/listinfo/python-list

Re: loop over list and process into groups

2010-03-05 Thread lbolla
On Mar 5, 1:26 pm, mk wrote: > Sneaky Wombat wrote: > > [ 'VLAN4065', > >  'Interface', > >  'Gi9/6', > >  'Po2', > >  'Po3', > >  'Po306', > >  'VLAN4068', > >  'Interface', > >  'Gi9/6', > >  'VLAN4069', > >  'Interface', > >  'Gi9/6',] > > Hey, I just invented a cute ;-) two-liner using list co

Re: A "scopeguard" for Python

2010-03-05 Thread Robert Kern
On 2010-03-05 10:29 AM, Mike Kent wrote: On Mar 4, 8:04 pm, Robert Kern wrote: No, the try: finally: is not implicit. See the source for contextlib.GeneratorContextManager. When __exit__() gets an exception from the with: block, it will push it into the generator using its .throw() method. Thi

Re: Generic singleton

2010-03-05 Thread Terry Reedy
On 3/4/2010 10:32 PM, Steven D'Aprano wrote: Python does have it's own singletons, like None, True and False. True and False are not singletons. > For some reason, they behave quite differently: Because they are quite different. > NoneType fails if you try to instantiate it again, Because

  1   2   >