None in string formatting
Was doing some string formatting, noticed the following: >>> x = None >>> "%s" % x 'None' Is there a reason it maps to 'None'? I had expected ''. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to turn a variable name into a string?
> c = None (result of an assignment after the os.environ.get() returned a KeyError). Why not trap the KeyError? -- http://mail.python.org/mailman/listinfo/python-list
python.exe on Mac OS X!?
I did a source code build of Python 2.4.1 on OS X (10.3.8) and the executable produced was 'python.exe'. Can someone tell me whether this is a bug, feature, or UserError? % ./configure % make % ./python.exe Python 2.4.1 (#1, Apr 17 2005, 12:14:12) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: python.exe on Mac OS X!?
>> executable produced was 'python.exe'. Can someone tell me whether this >> is a bug, feature, or UserError? > I'm not sure. Why don't you grab the binary? > http://www.python.org/ftp/python/2.4.1/MacPython-OSX-2.4.1-1 .dmg Because I need to keep multiple versions of Python on this machine, and as far as I can tell the binary installer overwrites the default installed version. I could be wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: python.exe on Mac OS X!?
> The default file system on MacOSX is case insensitive. As a result the .exe > extension is required to disambiguate the generated executable from the > Python directory in the source distro. OK. I got it. -- http://mail.python.org/mailman/listinfo/python-list
Why is 'None' not assignable but 'True'/'False' are?
In Python 2.4.1: >>> None = 99 SyntaxError: assignment to None >>> True = 99 >>> False = 99 >>> True == False True --- So why is 'None' special? -- http://mail.python.org/mailman/listinfo/python-list
Extended slicing and Ellipsis - where are they used?
The following are apparently legal Python syntactically: L[1:3, 8:10] L[1, ..., 5:-2] But they don't seem to work on lists: >>> l = [0,1,2,3] >>> l[0:2,3] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers >>> l[...] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers So where is this extended slicing used? -- Rodney -- http://mail.python.org/mailman/listinfo/python-list
Re: Extended slicing and Ellipsis - where are they used?
On Sep 13, 5:50 pm, James Stroud <[EMAIL PROTECTED]> wrote: > Rodney Maxwell wrote: > > The following are apparently legal Python syntactically: > >L[1:3, 8:10] > >L[1, ..., 5:-2] > > > But they don't seem to work on lists: > >>>> l = [0,1,2,3] > >>>> l[0:2,3] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: list indices must be integers > >>>> l[...] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: list indices must be integers > > > So where is this extended slicing used? > > AFAICT this syntax is not used in the standard library. However, the > mega-beauty of it is that you can make use of it in your own classes: > > py> class Bob(list): > ... def __getitem__(self, i): > ... try: > ... return [list.__getitem__(self, j) for j in i] > ... except TypeError: > ... return list.__getitem__(self, i) > ... > py> b = Bob(xrange(15, 30)) > py> b[3, 5, 7, 13] > [18, 20, 22, 28] > > James Or >>> b[0:3, 5, 9] [[15, 16, 17], 20, 24] which is what I was looking for in the first place. Thanks, Rodney -- http://mail.python.org/mailman/listinfo/python-list
Re: Extended slicing and Ellipsis - where are they used?
On Sep 13, 5:50 pm, James Stroud <[EMAIL PROTECTED]> wrote: > Rodney Maxwell wrote: > > The following are apparently legal Python syntactically: > >L[1:3, 8:10] > >L[1, ..., 5:-2] > > > But they don't seem to work on lists: > >>>> l = [0,1,2,3] > >>>> l[0:2,3] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: list indices must be integers > >>>> l[...] > > Traceback (most recent call last): > > File "", line 1, in > > TypeError: list indices must be integers > > > So where is this extended slicing used? > > AFAICT this syntax is not used in the standard library. However, the > mega-beauty of it is that you can make use of it in your own classes: > > py> class Bob(list): > ... def __getitem__(self, i): > ... try: > ... return [list.__getitem__(self, j) for j in i] > ... except TypeError: > ... return list.__getitem__(self, i) > ... > py> b = Bob(xrange(15, 30)) > py> b[3, 5, 7, 13] > [18, 20, 22, 28] > > James Or >>> b[0:3, 5, 9] [[15, 16, 17], 20, 24] which is what I was looking for in the first place. Thanks, Rodney -- http://mail.python.org/mailman/listinfo/python-list