Re: Strange behavior in string interpolation of constants

2017-10-16 Thread Ned Batchelder
On 10/16/17 7:39 PM, מיקי מונין wrote: Hello, I am working on an article on python string formatting. As a part of the article I am researching the different forms of python string formatting. While researching string interpolation(i.e. the % operator) I noticed something weird with string lengt

Re: Strange behavior

2016-01-14 Thread Chris Angelico
On Thu, Jan 14, 2016 at 3:03 PM, Michal Nalevanko wrote: > I've just installed Python 3.5.1 on my computer and came across somewhat > strange behavior. > > This is a snapshot of a short code that I wrote: https://goo.gl/izYbD0 > > Quite simple, you might say. Obviously, the program should create a

Re: Strange Behavior

2014-06-03 Thread Steven D'Aprano
On Tue, 03 Jun 2014 10:01:26 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: >> >>> I invoked the wrong bug.py :/ , works fine now (this happens to me >>> when im a bit tired sometimes...). >> >> Clarity in naming is an excellent thin

Re: Strange Behavior

2014-06-03 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > >> I invoked the wrong bug.py :/ , works fine now (this happens to me when >> im a bit tired sometimes...). > > Clarity in naming is an excellent thing. If you have two files called > "bug.py", that's two too many.

Re: Strange Behavior

2014-06-02 Thread Igor Korot
On Mon, Jun 2, 2014 at 5:30 PM, Chris Angelico wrote: > On Tue, Jun 3, 2014 at 10:22 AM, Steven D'Aprano > wrote: >> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: >> >>> I invoked the wrong bug.py :/ , works fine now (this happens to me when >>> im a bit tired sometimes...). >> >> Clarity

Re: Strange Behavior

2014-06-02 Thread Chris Angelico
On Tue, Jun 3, 2014 at 10:22 AM, Steven D'Aprano wrote: > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > >> I invoked the wrong bug.py :/ , works fine now (this happens to me when >> im a bit tired sometimes...). > > Clarity in naming is an excellent thing. If you have two files called > "

Re: Strange Behavior

2014-06-02 Thread Steven D'Aprano
On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > I invoked the wrong bug.py :/ , works fine now (this happens to me when > im a bit tired sometimes...). Clarity in naming is an excellent thing. If you have two files called "bug.py", that's two too many. Imagine having fifty files called "

Re: Strange Behavior

2014-06-02 Thread robertw89
I invoked the wrong bug.py :/ , works fine now (this happens to me when im a bit tired sometimes...). Im unsure about the "real" bugreport, will investigate if I find some time and motivation. -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior

2014-06-02 Thread Peter Otten
robert...@googlemail.com wrote: > Hello folks, > > I am not sure if it is only on my system the case that the code in > http://pastebin.com/WETvqMJN misbehaves in the stated way. > Can anybody reproduce it? > > I thought it could be that the tabs/spaces do influence it, but it doesn't > care. >

Re: Strange Behavior

2014-06-02 Thread Mark Lawrence
On 02/06/2014 17:35, robert...@googlemail.com wrote: Hello folks, I am not sure if it is only on my system the case that the code in http://pastebin.com/WETvqMJN misbehaves in the stated way. Can anybody reproduce it? I thought it could be that the tabs/spaces do influence it, but it doesn't ca

Re: Strange behavior with sort()

2014-02-26 Thread Larry Hudson
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx sort() sorts the sequence in pla

Re: Strange behavior with sort()

2014-02-26 Thread Gary Herron
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: Most such questions can be answered by printing out the values in question and observi

Re: Strange behavior with sort()

2014-02-26 Thread ast
Thanks for the very clear explanation -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with sort()

2014-02-26 Thread Marko Rauhamaa
"ast" : > if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? The list.sort() method returns None. The builtin sorted() function returns a list: if sorted(box) == [1, 2, 3]: would work. Note that the list.sort() method is often preferred because

Re: Strange behavior with sort()

2014-02-26 Thread Lele Gaifax
"ast" writes: > If I write: > >box.sort() >if box == [1, 2, 3]: > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? Because very often methods **dont't** return the object they are applied (self that is).

Re: Strange behavior with sort()

2014-02-26 Thread Eduardo A . Bustamante López
On Thu, Feb 27, 2014 at 07:24:24AM +0100, ast wrote: > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Wh

Re: Strange behavior with sort()

2014-02-26 Thread Frank Millman
"ast" wrote in message news:530eda1d$0$2061$426a7...@news.free.fr... > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test alwa

Re: Strange behavior for a 2D list

2013-04-18 Thread Wim R. Cardoen
Thank you all for your replies. I had the matrix concept in mind such as explained in the numpy example. Rob On Thu, Apr 18, 2013 at 3:19 PM, Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > Robrecht W. Uyttenhove gmail.com> writes: > > > > > Hello, > > I tried out the follo

Re: Strange behavior for a 2D list

2013-04-18 Thread Wolfgang Maier
Robrecht W. Uyttenhove gmail.com> writes: > > Hello, > I tried out the following code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y[[0, 1, 2, 3, 4, 5, 6],  [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20],  [21, 22, 23, 24, 25, 26, 27],  [28, >

Re: Strange behavior for a 2D list

2013-04-18 Thread John Gordon
In "Robrecht W. Uyttenhove" writes: > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 33,

Re: Strange behavior for a 2D list

2013-04-18 Thread Peter Otten
Robrecht W. Uyttenhove wrote: > Hello, > > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 3

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
On 16-Aug-2012 19:40, Steven D'Aprano wrote: On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: On 15-Aug-2012 02:19, Steven D'Aprano wrote: On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: You might find the following useful: def testFunc(startingList): xOnlyList = [];

Re: Strange behavior

2012-08-16 Thread Steven D'Aprano
On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: > On 15-Aug-2012 02:19, Steven D'Aprano wrote: >> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: >> >>> You might find the following useful: >>> >>> def testFunc(startingList): >>> xOnlyList = []; j = -1 >>> for xl in s

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
x27;'' Purpose: Time four different algorithms for the same task Author: V. Stokes (v...@it.uu.se, 2012-08-16 (15:46), 2012-08-16) Refs: python-list@python.org list * Strange behavior, 14-Aug-2012 17:38, light1qu...@gmail.com * Re: Strange behavior, 14-Aug-2012 21:40, Stok

Re: Strange behavior

2012-08-16 Thread Peter Otten
Virgil Stokes wrote: >>> def testFunc(startingList): >>>xOnlyList = []; j = -1 >>>for xl in startingList: >>>if (xl[0] == 'x'): >> That's going to fail in the starting list contains an empty string. Use >> xl.startswith('x') instead. > Yes, but this was by design (tacitly assumed that startingList

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
code is actually irrelevant for the original "Strange behavior" post. Have a good day! ''' Purpose: Time three different algorithms for the same task Author: V. Stokes (v...@it.uu.se, 2012-08-16) Refs: python-list@python.org list * Strange behavior, 14-Aug-2

Re: Strange behavior

2012-08-15 Thread Alain Ketterlin
light1qu...@gmail.com writes: > I got my answer by reading your posts and referring to: > http://docs.python.org/reference/compound_stmts.html#the-for-statement > (particularly the shaded grey box) Not that the problem is not specific to python (if you erase the current element when traversing a

Re: Strange behavior

2012-08-15 Thread Alain Ketterlin
Chris Angelico writes: > Other people have explained the problem with your code. I'll take this > example as a way of introducing you to one of Python's handy features > - it's an idea borrowed from functional languages, and is extremely > handy. It's called the "list comprehension", and can be l

Re: Strange behavior

2012-08-14 Thread Steven D'Aprano
On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: > You might find the following useful: > > def testFunc(startingList): > xOnlyList = []; j = -1 > for xl in startingList: > if (xl[0] == 'x'): That's going to fail in the starting list contains an empty string. Use xl.s

Re: Strange behavior

2012-08-14 Thread Chris Angelico
On Wed, Aug 15, 2012 at 1:38 AM, wrote: > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remo

Fwd: Re: Strange behavior

2012-08-14 Thread Virgil Stokes
Original Message Subject:Re: Strange behavior Date: Tue, 14 Aug 2012 21:32:16 +0200 From: Virgil Stokes To: light1qu...@gmail.com On 2012-08-14 17:38, light1qu...@gmail.com wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am

Re: Strange behavior

2012-08-14 Thread Virgil Stokes
On 2012-08-14 17:38, light1qu...@gmail.com wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run

Re: Strange behavior

2012-08-14 Thread Terry Reedy
On 8/14/2012 11:59 AM, Alain Ketterlin wrote: light1qu...@gmail.com writes: However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. def testFunc(startingList): xOnlyList = []; for str in startingList:

Re: Strange behavior

2012-08-14 Thread Alain Ketterlin
light1qu...@gmail.com writes: > However if you run the code you will notice only one of the strings > beginning with 'x' is removed from the startingList. > > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): >

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Waylan Limberg
On Mon, Feb 13, 2012 at 3:16 PM, Arnaud Delobelle wrote: >> Strangely it was working fine the other day. Then while debugging a >> script it suddenly started do this and now does this for every script > > How were you debugging? I think I may have been attempting to use pipes to redirect stdin an

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Arnaud Delobelle
On 13 February 2012 19:50, waylan wrote: > When I try running any Python Script on the command line with Python > 3.2 I get this weird behavior. The cursor dances around the command > line window and nothing ever happens. Pressing Ctr+C does nothing. > When I close the window (mouse click on X in

Re: strange behavior from recursive generator

2011-09-23 Thread Phillip Feldman
I don't know how many times I stared at that code without seeing the error. Thanks so much! Phillip On Fri, Sep 23, 2011 at 1:26 PM, Arnaud Delobelle wrote: > On 23 September 2011 21:09, Dr. Phillip M. Feldman > wrote: > > > > A few weeks ago, I wrote a class that creates an iterator for solv

Re: strange behavior from recursive generator

2011-09-23 Thread Arnaud Delobelle
On 23 September 2011 21:09, Dr. Phillip M. Feldman wrote: > > A few weeks ago, I wrote a class that creates an iterator for solving the > general unlabeled-balls-in-labeled boxes occupancy problem. Chris Rebert > converted my code to a generator, which made the code cleaner, and I > subsequently s

Re: Strange behavior related to value / reference

2009-10-30 Thread Aahz
In article <626f24e5-4d8e-416c-b3ed-dc56a88dc...@s21g2000prm.googlegroups.com>, Lambda wrote: > >def matrix_power(m, n): > result = m[:] > print result is m Use copy.deepcopy() -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "You could make Eskimos emigrate t

Re: Strange behavior related to value / reference

2009-10-28 Thread Dave Angel
Mark Dickinson wrote: On Oct 28, 8:24 am, Lambda wrote: Thank you! Following is my final code: Looks good, but are you sure about that word 'final'? ;-) def matrix_power(m, n): """ Raise 2x2 matrix m to nth power. """ if n =0: return [[1, 0], [0, 1]] x =atrix_power(m,

Re: Strange behavior related to value / reference

2009-10-28 Thread Peter Otten
Lambda wrote: > I defined a function to raise a 2x2 matrix to nth power: > BTW, numpy has such a function, but it doesn't support really large > number. > Does numpy has some functions that support arbitrarily large number? You can tell it to use Python instead of C integers: >>> import numpy >

Re: Strange behavior related to value / reference

2009-10-28 Thread Mark Dickinson
On Oct 28, 8:24 am, Lambda wrote: > Thank you! > Following is my final code: Looks good, but are you sure about that word 'final'? ;-) > > def matrix_power(m, n): >   """ >   Raise 2x2 matrix m to nth power. >   """ >   if n == 0: return [[1, 0], [0, 1]] > >   x = matrix_power(m, n / 2) I sugg

Re: Strange behavior related to value / reference

2009-10-28 Thread Lambda
On Oct 28, 10:40 am, Chris Rebert wrote: > On Tue, Oct 27, 2009 at 7:15 PM, Lambda wrote: > > I defined a function to raise a 2x2 matrix to nth power: > > > def matrix_power(m, n): > >  result = m[:] > > Note that this only copies the *outer* list. It does NOT copy any of > the inner, nested list

Re: Strange behavior related to value / reference

2009-10-27 Thread Terry Reedy
Lambda wrote: I defined a function to raise a 2x2 matrix to nth power: There is a much faster way to raise x to a count power n than the definitional but naive method of multipling 1 by x n times. It is based on the binary representation of n. Example: x**29 = x**(16+8+4+1) = x**16 * x**8 *

Re: Strange behavior related to value / reference

2009-10-27 Thread Chris Rebert
On Tue, Oct 27, 2009 at 7:15 PM, Lambda wrote: > I defined a function to raise a 2x2 matrix to nth power: > > def matrix_power(m, n): >  result = m[:] Note that this only copies the *outer* list. It does NOT copy any of the inner, nested lists, it just makes fresh *references* to them, which is w

Re: strange behavior with os.system

2009-06-17 Thread kmw
That's it. I am calling my own program and not coreutils' sort, what explains the unrequested output. Many thanks. Cheers, Kay On 16 Jun., 22:16, Piet van Oostrum wrote: > > kmw (k) wrote: > >k> Hi, > >k> I wanted to write a simple script (in 5 minutes or so) which replaces > >k> the option

Re: strange behavior with os.system

2009-06-16 Thread Piet van Oostrum
> kmw (k) wrote: >k> Hi, >k> I wanted to write a simple script (in 5 minutes or so) which replaces >k> the option '+1' given to the command 'sort' by '-k 2' and than runs >k> 'sort' with the modified argument list. After two hours I am giving up >k> and ask you for help. This is what I tried

Re: strange behavior with os.system

2009-06-16 Thread MRAB
kmw wrote: Hi, I wanted to write a simple script (in 5 minutes or so) which replaces the option '+1' given to the command 'sort' by '-k 2' and than runs 'sort' with the modified argument list. After two hours I am giving up and ask you for help. This is what I tried (please excuse the verbose co

Re: strange behavior of math.sqrt() in new 3.0 version

2009-01-03 Thread Eric Kemp
Tim Roberts wrote: Scott David Daniels wrote: I avoid using single-letter variables except where I know the types from the name (so I use i, j, k, l, m, n as integers, s as string, and w, x, y, and z I am a little looser with (but usually float or complex). It's amazing to me that Fortran con

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-28 Thread Steve Holden
Tim Roberts wrote: > Scott David Daniels wrote: >> I avoid using single-letter variables except where I know the types >>from the name (so I use i, j, k, l, m, n as integers, s as string, >> and w, x, y, and z I am a little looser with (but usually float or >> complex). > > It's amazing to me tha

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-27 Thread Tim Roberts
Scott David Daniels wrote: > >I avoid using single-letter variables except where I know the types >from the name (so I use i, j, k, l, m, n as integers, s as string, >and w, x, y, and z I am a little looser with (but usually float or >complex). It's amazing to me that Fortran continues to live on

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread John Machin
On Dec 27, 8:52 am, David Lemper wrote: > I'm a newbee trying 3.0   Please help with  math.sqrt() math.sqrt() is not the problem. > At the command line this function works correctly >       >>> import math >               n = input("enter a number > ") >               s = math.sqrt(n) >      An e

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Gabriel Genellina
En Fri, 26 Dec 2008 19:52:24 -0200, escribió: I'm a newbee trying 3.0 Please help with math.sqrt() At the command line this function works correctly >>> import math n = input("enter a number > ") s = math.sqrt(n) An entry of 9 or 9.0 will yield 3.0 Y

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Chris Rebert
On Fri, Dec 26, 2008 at 1:52 PM, wrote: > I'm a newbee trying 3.0 Please help with math.sqrt() > > At the command line this function works correctly > >>> import math > n = input("enter a number > ") raw_input() was renamed input() in Python 3.0, and it returns a *string*, n

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Scott David Daniels
David Lemper wrote: I'm a newbee trying 3.0 Please help with math.sqrt() At the command line this function works correctly >>> import math n = input("enter a number > ") s = math.sqrt(n) An entry of 9 or 9.0 will yield 3.0 Yet the same code in a sc

Re: Strange behavior of the Eclipse embedded console

2008-03-20 Thread Preston Landers
On Mar 20, 9:09 am, hellt <[EMAIL PROTECTED]> wrote: > "The eclipse console is not an exact copy of a shell... one of the > changes is that when you press in a shell, it may give you a > \r, \n or \r\n as an end-line char, depending on your platform. Python > does not expect this -- from the docs

Re: Strange behavior of the Eclipse embedded console

2008-03-20 Thread hellt
On 20 мар, 14:31, hellt <[EMAIL PROTECTED]> wrote: > i've faced with some strangeness while executing this sample: > > choice = raw_input("your choice: ") > print len(choice) > > when i run this sample in my eclipse console with CPython and print > Yes, i have this output > 4 #trailing \t is the fo

Re: Strange Behavior: csv module & IDLE

2007-12-28 Thread t_rectenwald
On Dec 28, 9:43 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Dec 29, 1:12 pm, t_rectenwald <[EMAIL PROTECTED]> wrote: > > > I've noticed an oddity when running a program, using the csv module, > > within IDLE.  I'm new to Python so am confused by what is happening. > > Here is what I'm doing: >

Re: Strange Behavior: csv module & IDLE

2007-12-28 Thread John Machin
On Dec 29, 1:12 pm, t_rectenwald <[EMAIL PROTECTED]> wrote: > I've noticed an oddity when running a program, using the csv module, > within IDLE. I'm new to Python so am confused by what is happening. > Here is what I'm doing: > > 1) Open the IDLE Shell. > 2) Select File | Open... > 3) Choose my f

Re: Strange Behavior: csv module & IDLE

2007-12-28 Thread Marc 'BlackJack' Rintsch
On Fri, 28 Dec 2007 18:12:58 -0800, t_rectenwald wrote: > Within the program, the snippet where I use the csv module is below: > > == > csvfile = open('foo.csv', 'w') > writer = csv.writer(csvfile) > > for row in rows: > writer.writerow(row[0:3]) > > csvfile.clos

Re: Strange behavior of __get__ in a descriptor in IPython

2007-11-07 Thread Fernando Perez
Jakub Hegenbart wrote: > Hi, > > I'm studying the descriptor protocol and its usage from the following > document: > > http://users.rcn.com/python/download/Descriptor.htm > > There is some sample code: > > http://users.rcn.com/python/download/Descriptor.htm#descriptor-example > > that behaves

Re: Strange behavior of __get__ in a descriptor in IPython

2007-11-07 Thread Diez B. Roggisch
Jakub Hegenbart wrote: > Hi, > > I'm studying the descriptor protocol and its usage from the following > document: > > http://users.rcn.com/python/download/Descriptor.htm > > There is some sample code: > > http://users.rcn.com/python/download/Descriptor.htm#descriptor-example > > that behaves

Re: Strange behavior in Windows

2007-06-05 Thread Douglas Woodrow
On Mon, 4 Jun 2007 21:34:36, David Stockwell wxp <[EMAIL PROTECTED]> wrote > >in DOS you can try this to see what your path is: > >echo "My path is %PATH%" or more simply: , | C:> path ` -- Doug Woodrow -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior in Windows

2007-06-04 Thread David Stockwell wxp
my guess its your path. I'm not familiar with IDLE but if you try getting the properties of IDLE, chances are its got the patch set up correctly. in DOS you can try this to see what your path is: echo "My path is %PATH%" - Original Message - From: "Jakob Svavar Bjarnason" <[EMAIL PROT

Re: Strange behavior in Windows

2007-06-04 Thread Gabriel Genellina
En Sat, 02 Jun 2007 15:31:40 -0300, Jakob Svavar Bjarnason <[EMAIL PROTECTED]> escribió: > I have been trying to switch to Python from other languages such as Perl > and now I have a newbie question. > > I have been trying to run a setup script to install a python library. To > do that I nee

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Gabriel Genellina
En Thu, 12 Apr 2007 01:23:08 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > On Thu, 12 Apr 2007 00:32:32 -0300, Gabriel Genellina wrote: > >> First I want to say that __getitem__ should raise IndexError, not >> KeyError, to indicate "not found" > > How do you know the Original Poster's c

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Scott David Daniels
Steven D'Aprano wrote: > On Wed, 11 Apr 2007 16:37:35 -0700, rconradharris wrote: > ... > Here are the results under Python 2.5: > tester(10) > Checking index 0... > Checking index 0... > Checking index 0... > Checking index 0... > Checking index 0... > [False, 'KeyError', False, 'KeyError',

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Steven D'Aprano
On Thu, 12 Apr 2007 00:32:32 -0300, Gabriel Genellina wrote: > First I want to say that __getitem__ should raise IndexError, not > KeyError, to indicate "not found" How do you know the Original Poster's class was meant to be a sequence rather than a mapping? -- Steven. -- http://mail.python

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Steven D'Aprano
On Wed, 11 Apr 2007 16:37:35 -0700, rconradharris wrote: > A co-worker of mine came across some interesting behavior in the > Python interpreter today and I'm hoping someone more knowledgeable in > Python internals can explain this to me. > > First, we create an instance of an Old-Style class wit

Re: Strange Behavior with Old-Style classes and implicit __contains__

2007-04-11 Thread Gabriel Genellina
En Wed, 11 Apr 2007 20:37:35 -0300, <[EMAIL PROTECTED]> escribió: > First, we create an instance of an Old-Style class without defining a > __contains__ but instead define a __getitem__ method in which we raise > KeyError. Next we repeatedly use the 'in' operator to test to see > whether something

Re: Strange behavior when printing a returned closure function

2007-03-25 Thread Steven D'Aprano
On Sun, 25 Mar 2007 03:59:52 -0700, dartsch wrote: > I get an output like > > > > > So according to print I get the same function object returned at both > calls. Not the same function object. The first object is printed, then deleted by the garbage collector because it goes out of scope. Th

Re: Strange behavior when printing a returned closure function

2007-03-25 Thread dartsch
On Mar 25, 1:04 pm, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On 25 Mar 2007 03:59:52 -0700, [EMAIL PROTECTED] wrote: > > > > >Hello, > > >when I execute the following code (python 2.5) > > >def f(x): > >def g(): > >return x > >return g > > >print f(1) > >print f(2) > > >I ge

Re: Strange behavior when printing a returned closure function

2007-03-25 Thread Jean-Paul Calderone
On 25 Mar 2007 03:59:52 -0700, [EMAIL PROTECTED] wrote: >Hello, > >when I execute the following code (python 2.5) > >def f(x): >def g(): >return x >return g > >print f(1) >print f(2) > >I get an output like > > > > >So according to print I get the same function object returned at

Re: Strange Behavior

2006-10-16 Thread Fredrik Lundh
Carsten Haese wrote: > I think this statement needs to be clarified. The binding of "data" to > the empty list *does* happen at runtime, not at compile time. However, > the binding happens only once, when the "def" statement is executed, as > opposed to every time the __init__ function is called.

Re: Strange Behavior

2006-10-16 Thread Carsten Haese
On Mon, 2006-10-16 at 10:51, Steven D'Aprano wrote: > On Mon, 16 Oct 2006 07:26:05 -0700, abcd wrote: > > > class Foo: > > def __init__(self, name, data=[]): > > The binding of the name "data" to the empty list happens at compile time, > not runtime. I think this statement needs to be clarif

Re: Strange Behavior

2006-10-16 Thread Diez B. Roggisch
abcd wrote: > Rob Williscroft wrote: >> http://docs.python.org/ref/function.html#l2h-619 > > > thanks. weird that it works that way since they even state "This is > generally not what was intended." The "not intended" refers to the programmer making the mistake of creating a shared instance -

Re: Strange Behavior

2006-10-16 Thread Fredrik Lundh
Steven D'Aprano wrote: > It isn't a bug in Python. At worst, it is a "gotcha", but it is a > deliberate design decision, and quite useful. For example, this is good > for caching complicated calculations: it's also used to pass in *objects* instead of names into an inner scope. -- http://mail

Re: Strange Behavior

2006-10-16 Thread Neil Cerutti
On 2006-10-16, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Well, it's a bug in your code :) > > It isn't a bug in Python. At worst, it is a "gotcha", but it is > a deliberate design decision, and quite useful. For example, > this is good for caching complicated calculations: I'd say the feature i

Re: Strange Behavior

2006-10-16 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > It isn't a bug in Python. At worst, it is a "gotcha", but it is a > deliberate design decision, and quite useful. For example, this is good > for caching complicated calculations: > > def function(x, _cache={}): > # _cache is initialised to an empt

Re: Strange Behavior

2006-10-16 Thread Steven D'Aprano
On Mon, 16 Oct 2006 07:26:05 -0700, abcd wrote: > class Foo: > def __init__(self, name, data=[]): The binding of the name "data" to the empty list happens at compile time, not runtime. > self.name = name > self.data = data > > def addData(self, val): > self.data.

Re: Strange Behavior

2006-10-16 Thread abcd
Rob Williscroft wrote: > http://docs.python.org/ref/function.html#l2h-619 thanks. weird that it works that way since they even state "This is generally not what was intended." oh well. -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior

2006-10-16 Thread Rob Williscroft
abcd wrote in news:[EMAIL PROTECTED] in comp.lang.python: > class Foo: > def __init__(self, name, data=[]): http://docs.python.org/ref/function.html#l2h-619 Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with iterables - is this a bug?

2006-05-31 Thread [EMAIL PROTECTED]
My original concern and reason for goint the iterator/generator route was exactly for large large lists :) Unnecessary in this example, but exactly what I was exploring. I wouldn't be using list comprehension for generating the permutiations. Where all this came from was creating a generator/ite

Re: Strange behavior with iterables - is this a bug?

2006-05-31 Thread Gary Herron
[EMAIL PROTECTED] wrote: >Gary Herron wrote: > > >>List comprehension is a great shortcut, but when the shortcut starts >>causing trouble, better to go with the old ways. You need to reopen each >>file each time you want to iterate through it. You should be able to >>understand the difference be

Re: Strange behavior with iterables - is this a bug?

2006-05-31 Thread [EMAIL PROTECTED]
Gary Herron wrote: > List comprehension is a great shortcut, but when the shortcut starts > causing trouble, better to go with the old ways. You need to reopen each > file each time you want to iterate through it. You should be able to > understand the difference between these two bits of code. >

Re: Strange behavior with iterables - is this a bug?

2006-05-30 Thread [EMAIL PROTECTED]
DOH!! thanks a lot. had to be something stupid on my part. Now I get it :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with iterables - is this a bug?

2006-05-30 Thread Gary Herron
[EMAIL PROTECTED] wrote: >Ok, I am confused about this one. I'm not sure if it's a bug or a >feature.. but > > List comprehension is a great shortcut, but when the shortcut starts causing trouble, better to go with the old ways. You need to reopen each file each time you want to iterate throu

Re: Strange behavior with iterables - is this a bug?

2006-05-30 Thread Inyeol Lee
On Tue, May 30, 2006 at 01:11:26PM -0700, [EMAIL PROTECTED] wrote: [...] > >>> RESTART > >>> f1 = open('word1.txt') > >>> f2 = open('word2.txt') > >>> f3 = open('word3.txt') > >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in f1 for i2 in f2 for > >>> i3 in

Re: Strange behavior with iterables - is this a bug?

2006-05-30 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ok, I am confused about this one. I'm not sure if it's a bug or a > feature.. but > RESTART f1 = open('word1.txt') f2 = open('word2.txt') f3 = open('word3.txt') print [(i1.stri

Re: Strange behavior with os call in cgi script

2006-02-08 Thread Rene Pijlman
Vinay Sajip: >Rene Pijlman: >> It struck me as somewhat complicated as well. >You should look at later versions of Python - your points above about >easier configuration have already been addressed: here's a link from >the current (2.4) docs: > >http://docs.python.org/lib/minimal-example.html Yes

Re: Strange behavior with os call in cgi script

2006-02-07 Thread Vinay Sajip
Rene Pijlman wrote: > It struck me as somewhat complicated as well. > > Looking at the basic example: > http://www.python.org/doc/2.3.5/lib/node304.html > > ... the things that first-time users shouldn't be bothered with IMO are: > > 1. Getting a logger by name from a hierarchical namespace. There

Re: Strange behavior with os call in cgi script

2006-02-07 Thread Jim
> But I do think that adding logging to a cgi script is a sensible thing to > do for a beginner. Let me second that. I happen to write a lot of CGI, and ISTM that while you can do it without logging, you are condemming yourself to a lot of staring at the screen, head-scratching, and saying ``Now w

Re: Strange behavior with os call in cgi script

2006-02-06 Thread Fredrik Lundh
Rene Pijlman wrote: > But I do think that adding logging to a cgi script is a sensible thing to > do for a beginner. Getting that to run in a debugger is probably way more > complicated. on the other hand, adding if 1: # set to 0 when deploying print "" print cgi.escape(repr(

Re: Strange behavior with os call in cgi script

2006-02-06 Thread Rene Pijlman
Steve Holden: >Rene Pijlman: >> Add logging to your program: >> http://www.python.org/doc/2.3.5/lib/module-logging.html >> >Probably oiverkill, particularly for a beginner (is it only me that >thinks the logging module is either way over-complicated or way >under-documented?). It struck me as s

Re: Strange behavior with os call in cgi script

2006-02-06 Thread Duncan Booth
Steve Holden wrote: >> Add logging to your program: >> http://www.python.org/doc/2.3.5/lib/module-logging.html >> > Probably oiverkill, particularly for a beginner (is it only me that > thinks the logging module is either way over-complicated or way > under-documented?). No, I would agree with

Re: Strange behavior with os call in cgi script

2006-02-05 Thread Steve Holden
Rene Pijlman wrote: > sophie_newbie: > >>OK, interesting, but just how dow I print he environment in the >>program?? > > > Add logging to your program: > http://www.python.org/doc/2.3.5/lib/module-logging.html > Probably oiverkill, particularly for a beginner (is it only me that thinks the log

Re: Strange behavior with os call in cgi script

2006-02-05 Thread Rene Pijlman
sophie_newbie: >OK, interesting, but just how dow I print he environment in the >program?? Add logging to your program: http://www.python.org/doc/2.3.5/lib/module-logging.html And log the environment: http://www.python.org/dev/doc/newstyle/lib/os-procinfo.html -- René Pijlman -- http://mail.py

Re: Strange behavior with os call in cgi script

2006-02-05 Thread sophie_newbie
OK, interesting, but just how dow I print he environment in the program?? -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with os call in cgi script

2006-02-05 Thread Dennis Benzinger
sophie_newbie schrieb: > I have written a cgi script that seems to run perfectly from the > command line when I simulate some cgi input using > os.environ['QUERY_STRING']. > > The thing is that when I run it from the browser, one of my os.system > calls, which gets excecuted fine when running the

Re: Strange behavior of int()

2006-01-29 Thread Dan Bishop
Brian wrote: > Hello, > > Can someone tell me what I am doing wrong in this code. > > If I create a file change.py with the following contents: > > def intTest(M, c): > r = M > for k in c: > print 'int(r/k) = ', int(r/k), 'r =', r, 'k =', k, 'r/k > =', r/k >

  1   2   >