Re: semantics of ** (unexpected/inconsistent?)

2009-12-07 Thread Albert van der Horst
In article <87eingrbh9@benfinney.id.au>, Ben Finney wrote: >Lie Ryan writes: > >> I generally do not expect operator precedence to be reliable at all > >Have another read of the thread. The OP's confusion was not over >operator precedence, but over how names resolve to values in >expressions

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
On Mon, Nov 30, 2009 at 2:05 PM, Lie Ryan wrote: > On 12/1/2009 5:58 AM, inhahe wrote: >> >> i wasn't suggesting it as a feature for python, just pointing out why >> it might seem counterintuitive. > > I'm interested, what do YOU (inhahe) think the result should be? Should both > become -9 or both

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Brian J Mingus
On Sun, Nov 29, 2009 at 5:58 PM, Esmail wrote: > Brian J Mingus wrote: > >> >> >> >> I think you answered your own question. 3**2 comes first in the order of >> operations, followed by the negation. >> > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem i

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Lie Ryan
On 12/1/2009 5:58 AM, inhahe wrote: i wasn't suggesting it as a feature for python, just pointing out why it might seem counterintuitive. I'm interested, what do YOU (inhahe) think the result should be? Should both become -9 or both become 9. What was your expectation when you wrote that post

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
On Mon, Nov 30, 2009 at 1:53 PM, Chris Rebert wrote: >> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing >> wrote: >>> Esmail wrote: >>> Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it s

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Chris Rebert
> On Mon, Nov 30, 2009 at 3:46 AM, Gregory Ewing > wrote: >> Esmail wrote: >> >>> Wow .. never heard of Concatenative_languages languages before or the >>> distinction you make. Your distinction explains the behavior, but I >>> find it somewhat counter-intuitive. >> >> You shouldn't find it any mo

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread MRAB
Lie Ryan wrote: On 11/30/2009 12:38 PM, Esmail wrote: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops, n

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread inhahe
one point of confusion could be the use of ** instead of superscript. it might make things a little bit more counterintuitive-looking than with superscripts, since the issue with would only apply to exponents, as -5*4 and a = -5 a*4 return the same answer, and superscripts make it a little eas

Re: semantics of ** (unexpected/inconsistent?)

2009-11-30 Thread Gregory Ewing
Esmail wrote: Wow .. never heard of Concatenative_languages languages before or the distinction you make. Your distinction explains the behavior, but I find it somewhat counter-intuitive. You shouldn't find it any more surprising than the fact that a = 2 + 3 print a * 5 gives a different

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread inhahe
On Sun, Nov 29, 2009 at 8:04 PM, Esmail wrote: > Chris Rebert wrote: > Wow .. never heard of Concatenative_languages languages before or the > distinction you make. Your distinction explains the behavior, but I > find it somewhat counter-intuitive. (I use the Python interpreter frequently > for sm

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Ben Finney
Lie Ryan writes: > I generally do not expect operator precedence to be reliable at all Have another read of the thread. The OP's confusion was not over operator precedence, but over how names resolve to values in expressions. -- \ “Life does not cease to be funny when people die any more

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Lie Ryan
On 11/30/2009 12:38 PM, Esmail wrote: Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. I generally do not expect operator precedence to be reliable at all except for: + - (binary ops, not the unary) * /

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Thanks all!! I get it now :-) It helped to have a number of different explanations, thanks for taking the time to post. Much appreciated. Cheers, Esmail -- http://mail.python.org/mailman/listinfo/python-list

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Mel
Esmail wrote: > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> > > I would have expected the same result in both cases. > > In

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Alf P. Steinbach
* Esmail: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -3**2 -9 >>> x = -3 >>> x**2 9 >>> I would have expected the same result in both cases. Init

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Ben Finney
Esmail writes: > Brian J Mingus wrote: > > > > > > > > I think you answered your own question. 3**2 comes first in the > > order of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same resul

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread The Music Guy
It's just like in algebra. You evaluate exponents before the - which, after all, is just another way to write -1, or times-negative-one. However, a variable with a negative value is not the same as a value that is being multiplied by a negative. -3 ** 2 = (-1)(3)^(2) in algebraic terms. Expon

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Martin v. Löwis
>> I think you answered your own question. 3**2 comes first in the order >> of operations, followed by the negation. > > No, that's not the problem, I'm ok with the operator precedence of - vs ** > > My problem is why I don't get the same result if I use the literal -3 or > a variable that contai

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Colin W.
On 29-Nov-09 19:50 PM, Chris Rebert wrote: On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: Ok, this is somewhat unexpected: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. -3**2 -9 x = -3

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Chris Rebert wrote: _No_, because using the variable evaluates "-3" as a unit separately by itself, before the exponentiation ever occurs; it's the same as the difference between (-3)**2 and -3**2. Python is not a concatenative programming language[*]; you can't directly textually replace a vari

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Esmail
Brian J Mingus wrote: I think you answered your own question. 3**2 comes first in the order of operations, followed by the negation. No, that's not the problem, I'm ok with the operator precedence of - vs ** My problem is why I don't get the same result if I use the literal -3 or a variabl

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Chris Rebert
On Sun, Nov 29, 2009 at 4:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > -3**2 > -9 > x = -3 > x**2 > 9 > > I

Re: semantics of ** (unexpected/inconsistent?)

2009-11-29 Thread Brian J Mingus
On Sun, Nov 29, 2009 at 5:39 PM, Esmail wrote: > Ok, this is somewhat unexpected: > > Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) > [GCC 4.3.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > > > >>> -3**2 > -9 > > >>> x = -3 > > >>> x**2 > 9 > >>> >

Re: semantics of [:]

2009-11-20 Thread Esmail
Diez B. Roggisch wrote: Esmail schrieb: None of your operations changes a. But I talked about the lists you bound b and c to before. Those aren't changed as well - they simply are not pointed to anymore. In your example, that means the will be garbage-collected, in other scenarios, such as th

Re: semantics of [:]

2009-11-20 Thread Diez B. Roggisch
Esmail schrieb: Diez B. Roggisch wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > # The following two are equivalent ###

Re: semantics of [:]

2009-11-20 Thread Ethan Furman
Dave Angel wrote: Esmail wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent Semi-aside, if I wanted to make local copy of a li

Re: semantics of [:]

2009-11-20 Thread Esmail
Thank you all for your posts - this was very enlightening and I printed this thread off for future reference. -- http://mail.python.org/mailman/listinfo/python-list

Re: semantics of [:]

2009-11-20 Thread Duncan Booth
Dave Angel wrote: > > > Esmail wrote: >> Diez B. >> Roggisch wrote: >>> Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but

Re: semantics of [:]

2009-11-20 Thread Dave Angel
Esmail wrote: Diez B. Roggisch wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > Semi-aside, if I wanted to make loc

Re: semantics of [:]

2009-11-20 Thread Stephen Hansen
> > The original list 'a', isn't changed in any of these cases right? And > modifying b, c or d would not change 'a' either - or am I not understanding > this correctly? > > ## 1 ## > > creates a new list and copies all elements from a to b > > Yes. > ## 2 ## > > take an already existing list (em

Re: semantics of [:]

2009-11-20 Thread Luis Zarrabeitia
On Friday 20 November 2009 11:15:55 am Esmail wrote: > Could someone help confirm/clarify the semantics of the [:] operator > in Python? In short, a[:], when "a" is a list, returns a slice ("sublist") of "a" that happens to contain all the elemnts of "a". In general, a[low:upper:step] will give

Re: semantics of [:]

2009-11-20 Thread Esmail
Diez B. Roggisch wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > # The following two are equivalent # 2

Re: semantics of [:]

2009-11-20 Thread Dave Angel
Diez B. Roggisch wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > # The following two are equivalent # 2 #

Re: semantics of [:]

2009-11-20 Thread Tim Chase
Diez B. Roggisch wrote: Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > # The following two are equivalent # 2 #

Re: semantics of [:]

2009-11-20 Thread Diez B. Roggisch
Esmail schrieb: Could someone help confirm/clarify the semantics of the [:] operator in Python? a = range(51,55) # 1 ## b = a[:] # b receives a copy of a, but they are independent > # The following two are equivalent # 2 ## c = [] c =

Re: semantics of the |= operator

2008-08-24 Thread akva
thanks everybody. -- http://mail.python.org/mailman/listinfo/python-list

Re: semantics of the |= operator

2008-08-22 Thread Peter Pearson
On Fri, 22 Aug 2008 00:35:31 -0700 (PDT), akva <[EMAIL PROTECTED]> wrote: > > well, frankly I expected a |= b to mean exactly the same as a = a | b > regardless of the object type. So did I. I'm glad your post called this to my attention; I recently told my kid exactly that wrong thing. -- To

Re: semantics of the |= operator

2008-08-22 Thread Fredrik Lundh
akva wrote: could you please refer me a link where this is specified? I couldn't find it in python documentation http://docs.python.org/ref/augassign.html "An augmented assignment expression like x += 1 can be rewritten as x = x + 1 to achieve a similar, but not exactly equal effect. In the

Re: semantics of the |= operator

2008-08-22 Thread akva
thanks all, >Yes. That's the exact purpose of the in-place operators when they deal with >mutable objects. What else did you expect? well, frankly I expected a |= b to mean exactly the same as a = a | b regardless of the object type. > The manual explicitly specifies that mutable objects may imp

Re: semantics of the |= operator

2008-08-21 Thread Terry Reedy
akva wrote: Hi All, what's the exact semantics of the |= operator in python? It seems that a |= d is not always equivalent to a = a | d The manual explicitly specifies that mutable objects may implement the operation part of operation-assignments by updating in place -- so that the object

Re: semantics of the |= operator

2008-08-21 Thread Diez B. Roggisch
akva wrote: > Hi All, > > what's the exact semantics of the |= operator in python? > It seems that a |= d is not always equivalent to a = a | d > > For example let's consider the following code: > > def foo(s): >s = s | set([10]) > > def bar(s): >s |= set([10]) > > s = set([1,2]) > >

Re: Semantics of thread.error

2007-08-05 Thread Martin v. Löwis
Paul Miller schrieb: > In the language documentation, all that is said about thread.error is > that it's raised "on thread-specific errors." Is there anywhere a > list of conditions which will cause thread.error to be raised? I don't think so. However, it is fairly easy to extract such a list fr

Re: Semantics of file.close()

2007-07-18 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: >> But the writes are buffered, and close causes the buffer to be >> flushed. file.close can throw an exception just like fclose, but >> it will still ensure that the file is closed. > > Is this buffering being done by Python or the kernel? It is done i

Re: Semantics of file.close()

2007-07-17 Thread Paul Rubin
"Evan Klitzke" <[EMAIL PROTECTED]> writes: > Is this buffering being done by Python or the kernel? I think this refers to buffering done in the C stdio library, which Python uses. -- http://mail.python.org/mailman/listinfo/python-list

Re: Semantics of file.close()

2007-07-17 Thread Evan Klitzke
On 7/17/07, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Evan Klitzke" <[EMAIL PROTECTED]> writes: > > > You should take a look at the man pages for close(2) and write(2) (not > > fclose). Generally you will only get an error in C if you try to close > > a file that isn't open. In Python you don't e

Re: Semantics of file.close()

2007-07-17 Thread Matthew Woodcraft
Donn Cave <[EMAIL PROTECTED]> wrote: > I don't think there's any remedy for it, other than the obvious - > either always flush, or wrap an explicit close in its own exception > handler. Even if you have flushed, close() can give an error with some filesystems. -M- -- http://mail.python.org/mai

Re: Semantics of file.close()

2007-07-17 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: > You should take a look at the man pages for close(2) and write(2) (not > fclose). Generally you will only get an error in C if you try to close > a file that isn't open. In Python you don't even have to worry about > that -- if you close a regular file

Re: Semantics of file.close()

2007-07-17 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Evan Klitzke" <[EMAIL PROTECTED]> wrote: ... > > How do I ensure that the close() methods in my finally clause do not > > throw an exception? > You should take a look at the man pages for close(2) and write(2) (not > fclose). Generally you will only get an error

Re: Semantics of file.close()

2007-07-17 Thread Evan Klitzke
On 7/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > I'm a Python beginner and I'm trying to open, write and close a file > in a > correct manner. I've RTFM, RTFS, and I've read this thread: > http://groups.google.ca/group/comp.lang.python/browse_thread/thread/73bbda2c920521c/98c73

Re: Semantics of file.close()

2007-07-16 Thread Matimus
> How do I ensure that the close() methods in my finally clause do not > throw an exception? You have no choice. If close is going to fail, it will fail. Fortunately you can catch the exception and continue on. try: try: file1.write(somestuff) finally: file1.close() except

Re: Semantics of file.close()

2007-07-16 Thread Dan Bishop
On Jul 16, 6:35 pm, [EMAIL PROTECTED] wrote: > Hello, > > I'm a Python beginner and I'm trying to open, write and close a file > in a > correct manner. I've RTFM, RTFS, and I've read this > thread:http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7... > > I still cannot figure ou

Re: Semantics of file.close()

2007-07-16 Thread seerdecker
Sorry for the bad formatting; I've had to post this through the google groups. -- http://mail.python.org/mailman/listinfo/python-list

Re: Semantics of propagated exceptions

2006-08-01 Thread Thomas Lotze
Sorry for not answering such a long time. It's because my question originated from a discussion within our company which moved out of focus shortly after I posted, and over waiting for some response from them before replying here, I forgot about it. Steve Holden wrote: >> - f might catch E excep

Re: Semantics of propagated exceptions

2006-07-21 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, Thomas Lotze <[EMAIL PROTECTED]> wrote: > Suppose you have a function f which, as part of its protocol, raises some > standard exception E under certain, well-defined circumstances. Suppose > further that f calls other functions which may also raise E. How to best

Re: Semantics of propagated exceptions

2006-07-21 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Thomas Lotze wrote: > I wonder how to solve the following problem the most pythonic way: > > Suppose you have a function f which, as part of its protocol, raises some > standard exception E under certain, well-defined circumstances. Suppose > further that f calls other fun

Re: Semantics of propagated exceptions

2006-07-21 Thread Steve Holden
Thomas Lotze wrote: > Hi, > > I wonder how to solve the following problem the most pythonic way: > > Suppose you have a function f which, as part of its protocol, raises some > standard exception E under certain, well-defined circumstances. Suppose > further that f calls other functions which may

Re: Semantics of propagated exceptions

2006-07-21 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Thomas Lotze wrote: > Suppose you have a function f which, as part of its protocol, raises some > standard exception E under certain, well-defined circumstances. Suppose > further that f calls other functions which may also raise E. How to best > distinguish whether