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

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

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

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

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

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

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

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: 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)]

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

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

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

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

<    1   2