use of (a**b) (a*b)

2006-11-07 Thread Santosh Chikkerur
Hi Friends,Let me know the use of ' ** ' operator and ' \\' use.f=(3*s**2) how is it different, if use only single '*' and also the divide operator.Thanks in advance,Santosh -- http://mail.python.org/mailman/listinfo/python-list

Re: use of (a**b) (a*b)

2006-11-07 Thread Rares Vernica
Hi, Check out some examples: In [16]: 9./2 Out[16]: 4.5 In [17]: 9.//2 Out[17]: 4 In [18]: 2*3 Out[18]: 6 In [19]: 2**3 Out[19]: 8 Here is the documentation for these operations: http://docs.python.org/lib/typesnumeric.html Regards, Ray Santosh Chikkerur wrote: > Hi Friends, > Let me know th

a=b change b a==b true??

2007-02-26 Thread rstupplebeen
I do not have a clue what is happening in the code below. >>> a=[[2,4],[9,3]] >>> b=a >>> [map(list.sort,b)] [[None, None]] >>> b [[2, 4], [3, 9]] >>> a [[2, 4], [3, 9]] I want to make a copy of matrix a and then make changes to the matrices separately. I assume that I am missing a fundamental c

Re: a=b change b a==b true??

2007-02-26 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > I do not have a clue what is happening in the code below. > a=[[2,4],[9,3]] b=a [map(list.sort,b)] > [[None, None]] b > [[2, 4], [3, 9]] a > [[2, 4], [3, 9]] > > I want to make a copy of matrix a and then make changes to the > matrices separate

Re: a=b change b a==b true??

2007-02-26 Thread Chris Mellon
name b to the same object that is bound to the name a. If you want a copy, ask for a copy. >>> a = [1,2] >>> import copy >>> b = copy.copy(a) #shallow copy >>> a.append(3) >>> a,b ([1, 2, 3], [1, 2]) >>> You may need to do something else depending on exactly what copy semantics you want, read the docs on the copy module. -- http://mail.python.org/mailman/listinfo/python-list

Re: a=b change b a==b true??

2007-02-26 Thread Philipp Pagel
[EMAIL PROTECTED] wrote: > I do not have a clue what is happening in the code below. > >>> a=[[2,4],[9,3]] > >>> b=a > >>> [map(list.sort,b)] > [[None, None]] > >>> b > [[2, 4], [3, 9]] > >>> a > [[2, 4], [3, 9]] > I want to make a copy of matrix a and then make changes to the > matrices separate

Re: a=b change b a==b true??

2007-02-26 Thread bayer . justin
If you want to copy lists, you do it by using the [:] operator. e.g.: >>> a = [1,2] >>> b = a[:] >>> a [1, 2] >>> b [1, 2] >>> b[0] = 2 >>> a [1, 2] >>> b [2, 2] If you want to copy a list of lists, you can use a list comprehension if you do not want to use the copy module: >>> a = [[1,2],[3,4]]

Re: a=b change b a==b true??

2007-02-26 Thread rstupplebeen
All, It works great now. Thank you for all of your incredibly quick replies. Rob -- http://mail.python.org/mailman/listinfo/python-list

RE: a=b change b a==b true??

2007-02-26 Thread Delaney, Timothy (Tim)
[EMAIL PROTECTED] wrote: > All, > It works great now. Thank you for all of your incredibly quick > replies. > Rob You should have a read of these: http://wiki.python.org/moin/BeginnersGuide http://effbot.org/zone/python-objects.htm Cheers, Tim Delaney -- http://mail.python.org/mailman/listin

Re: a=b change b a==b true??

2007-02-26 Thread Gabriel Genellina
En Mon, 26 Feb 2007 11:26:43 -0300, <[EMAIL PROTECTED]> escribió: > It works great now. Thank you for all of your incredibly quick > replies. Now that you have solved your immediate problem, you could read: http://effbot.org/zone/python-objects.htm -- Gabriel Genellina -- http://mail.python.

Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-02 Thread chirayuk
;].split(os.sep) is wrong on Windows for the case when PATH="c:\\A;B";c:\\D; where there is a ';' embedded in the quoted path. Does anyone know of a simple way (addons ok) which would do it in a cross platform way? If not - I will roll my own. My search has shown that general

def a((b,c,d),e):

2005-04-18 Thread AdSR
Fellow Pythonistas, Please check out http://spyced.blogspot.com/2005/04/how-well-do-you-know-python-part-3.html if you haven't done so yet. It appears that you can specify a function explicitly to take n-tuples as arguments. It actually works, checked this myself. If you read the reference manua

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-02 Thread Michael Spencer
'PATH'].split(os.sep) is wrong on Windows for the case when PATH="c:\\A;B";c:\\D; where there is a ';' embedded in the quoted path. Does anyone know of a simple way (addons ok) which would do it in a cross platform way? If not - I will roll my own. My search has shown

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread chirayuk
%PATH%, etc) but I > > am not able to find a simple function to do so. > > > > os.environ['PATH'].split(os.sep) is wrong on Windows for the case when > > PATH="c:\\A;B";c:\\D; > > where there is a ';' embedded in the quoted path. > >

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Jeff Epler
if your goal is to search for files on a windows-style path environment variable, maybe you don't want to take this approach, but instead wrap and use the _wsearchenv or _searchenv C library functions http://msdn.microsoft.com/library/en-us/vclib/html/_crt__searchenv.2c_._wsearchenv.asp Incid

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Michael Spencer
chirayuk wrote: However, I just realized that the following is also a valid PATH in windows. PATH=c:\A"\B;C"\D;c:\program files\xyz" (The quotes do not need to cover the entire path) Too bad! What a crazy format! So here is my handcrafted solution. def WinPathList_to_PyList (pathL

RE: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Chirayu Krishnappa
exe do was discovered when I tried C:\temp>dir \Pro C:\temp>dir "\Program Files" C:\temp>dir "\Program Files"\vim ...and it worked. That's when I placed something in c:\temp\a;b\c and set path to begin with c:\temp"\a;b"\c;%path% and realized that cmd

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Jeff Epler
The C code that Python uses to find the initial value of sys.path based on PYTHONPATH seems to be simple splitting on the equivalent of os.pathsep. See the source file Python/sysmodule.c, function makepathobject(). for (i = 0; ; i++) { p = strchr(path, delim); // ";" on win

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-03 Thread Chirayu Krishnappa
I do agree that it is a crazy format - and am amazed that it works at the prompt. For the first case - you have a mismatched double quote for test2 at the end of the string. test2 should be r'c:\A"\B;C"\D;c:\program files\xyz' instead. For the 2nd case - my code swallowed the

Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

2005-04-04 Thread Chirayu Krishnappa
Its good to see what cpython did with the PATH. I now feel good about taking the simple approach. It would be crazy if that sort of quoting in the middle becomes something which works with too many applications - and others are expected to keep up with it. I guess I dont need to worry about unix P

Re: Why does min(A, B) not raise an error if A, B actually can't be compared?

2005-08-26 Thread Claudio Grondi
efined__cmp__() PythonObject_classWithDefined__cmp__instanceB = PythonObject_classWithDefined__cmp__() print "min(A,B) is A: " print "in case of classes with defined __cmp__() as parameter: " + str(min(PythonObject_classWithDefined__cmp__instanceA, PythonObject_cla

Re: Why does min(A, B) not raise an error if A, B actually can't be compared?

2005-08-26 Thread Raymond Hettinger
[Claudio Grondi] > The still open question for me then is: > Why does min() not raise an error in case > there is no comparison function definition > for the feeded objects available? Actually, there is a comparison function for class instances. Unfortunately, the default method is not very usefu

Re: def a((b,c,d),e):

2005-04-18 Thread Simon Percivall
You can always unpack a tuple that way, like in: .>>> import sys .>>> for (index, (key, value)) in enumerate(sys.modules.iteritems()): pass -- http://mail.python.org/mailman/listinfo/python-list

Re: def a((b,c,d),e):

2005-04-18 Thread Michael Spencer
s *.py # For def [\w]+\(\( c:\python23\lib\test\test_compile.py(49) def comp_args((a, b)): c:\python23\lib\test\test_compile.py(53) def comp_args((a, b)=(3, 4)): c:\python23\lib\test\test_grammar.py(159) def f5((compound, first), two): pass c:\python23\lib\test\test_scope.py(318)

Re: def a((b,c,d),e):

2005-04-18 Thread Fredrik Lundh
"AdSR" <[EMAIL PROTECTED]> wrote: Small wonder since it looks like one of those language features that make committing atrocities an order of magnitude easier. eh? def f((a, b)): ... is short for def f(tmp): a, b = tmp ... if you think this is an &

Re: def a((b,c,d),e):

2005-04-18 Thread Fredrik Lundh
def f(tmp): a, b = tmp ... back to the original source form def f((a, b)): ... but that has absolutely nothing whatsoever to do with how argument passing works at run time. -- http://mail.python.org/mailman/listinfo/python-list

Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> if you think this is an "atrocity", maybe programming isn't for you. My resume might suggest otherwise but I guess that's not the main topic here. Maybe I got carried away -- this one took me completely by surprise. Anyway, this gets interesting: def z(((a, b), (c,

Re: def a((b,c,d),e):

2005-04-18 Thread Diez B. Roggisch
AdSR wrote: > Fellow Pythonistas, > > Please check out > > http://spyced.blogspot.com/2005/04/how-well-do-you-know-python-part-3.html > > if you haven't done so yet. It appears that you can specify a function > explicitly to take n-tuples as arguments. It actually works, checked > this myself.

Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> Yes, but usually not so much in function arguments but more in > list-comprehensions or other places where unpacking was useful. I love the > feature - I just don't have nested enough data to use it more :) I use tuple unpacking in its typical uses, it's one of the first language features I lear

Re: def a((b,c,d),e):

2005-04-18 Thread François Pinard
[Diez B. Roggisch] > AdSR wrote: > > It appears that you can specify a function explicitly to take > > n-tuples as arguments. [...] Has anyone actually used it in real > > code? I do not use it often in practice, but sometimes, yes. If the feature was not there, it would be easy to do an explici

Re: def a((b,c,d),e):

2005-04-18 Thread John Machin
On 18 Apr 2005 13:05:57 -0700, "AdSR" <[EMAIL PROTECTED]> wrote: >Fellow Pythonistas, > >Please check out > >http://spyced.blogspot.com/2005/04/how-well-do-you-know-python-part-3.html > >if you haven't done so yet. It appears that you can specify a function >explicitly to take n-tuples as argument

Re: def a((b,c,d),e):

2005-04-18 Thread Diez B. Roggisch
hink about it the whole positional argument passing is nothing more than tuple unpacking. Its like having an anonymous variable that gets unpacked: def foo(a,b,c = i_m_so_anonymous): pass So it's just orthogonal to have the full functionality of unpacking available for function arg

Re: def a((b,c,d),e):

2005-04-18 Thread AdSR
> Thanks for pointing this out. However I see no atrocity potential here > -- what did you have in mind? Bad choice of words. I meant obfuscated, something like def z(((a, b), (c, d)), e, f): pass but much worse. But it looks like there is nothing unusual about it after all. Oh

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
François Pinard wrote: > The most useful place for implicit tuple unpacking, in my experience, > is likely at the left of the `in' keyword in `for' statements (and > it is even nicer when one avoids extraneous parentheses). ... and would be nicest (IMO) if default arguments and *varargs were all

Re: def a((b,c,d),e):

2005-04-19 Thread François Pinard
[George Sakkis] > François Pinard wrote: > > The most useful place for implicit tuple unpacking, in my > > experience, is likely at the left of the `in' keyword in `for' > > statements (and it is even nicer when one avoids extraneous > > parentheses). > ... and would be nicest (IMO) if default ar

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
. Let's keep the "should python become lazy ?" question for a future thread :-) Concerning default argument expressions, a neat feature would be to allow an expression to refer to other arguments, as in "def foo(a,b,s=a+b)" instead of the current workaround which goes like

Re: def a((b,c,d),e):

2005-04-19 Thread François Pinard
t not otherwise, and from what I saw so far, less meaningful in other contexts anyway. However, I think laziness is available explicitely if needed (there is library function that returns a "promise" of its argument). > Or for a more exotic use: > def prologLikeSum

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
"François Pinard" wrote: > > > keywords may be abbreviated, and much more hairy, > > > Hmm.. -1 on this. It may save a few keystrokes, but it's not good for > > readability and maintenability. > > That was my first impression too. Yet, interactively, I found that > feature very convenient. Alread

Re: def a((b,c,d),e):

2005-04-19 Thread Bengt Richter
= arg[1] self.y = 'default for non-tuple' else: self.x = arg[1][0] self.y = len(arg[1])==2 and arg[1][1] or 'default' u = property(fset=_fset) def __iter__(self): return iter((self.a, self.x, self.y)) def test(): upk = Tupk

Re: def a((b,c,d),e):

2005-04-19 Thread Greg Ewing
AdSR wrote: if you haven't done so yet. It appears that you can specify a function explicitly to take n-tuples as arguments. Has anyone actually used it in real code? Yes. In PyGUI I have some point and rectangle manipulation utilities that do things like def add_pt((x1, y1), (x2, y2)): retur

Does python support the expression "a = b | 1"???

2005-10-05 Thread Wenhua Zhao
a = b | 1 a = b if b != nil else a =1 Is there such expression in python? Thanks a lot! -- http://mail.python.org/mailman/listinfo/python-list

Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >I believe what Peter Otten was pointing out is that calling __eq__ is >not the same as using ==, presumably because the code for == checks the >types of the two objects and returns False if they're different before >the __eq

Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Steven Bethard
Mel Wilson wrote: In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: I believe what Peter Otten was pointing out is that calling __eq__ is not the same as using ==, presumably because the code for == checks the types of the two objects and returns False if they're different b

Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Steven Bethard
Mel Wilson wrote: In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: I believe what Peter Otten was pointing out is that calling __eq__ is not the same as using ==, presumably because the code for == checks the types of the two objects and returns False if they're different b

Re: assymetry between a == b and a.__eq__(b)

2004-12-03 Thread Nick Coghlan
owing, depending on the operator and the types of A and B: A.__op__(B) B.__op__(A) B.__rop__(A) The latter two get invoked when B is a proper subclass of A (using 'op' for commutative operations, and 'rop' for potentially non-commutative ones). This is so that subclasses

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: >Mel Wilson wrote: >> In article <[EMAIL PROTECTED]>, >> Steven Bethard <[EMAIL PROTECTED]> wrote: >> >>>I believe what Peter Otten was pointing out is that calling __eq__ is >>>not the same as using ==, presumably because th

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Tim Peters
[Mel Wilson] > :) Seems to: > > > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> class Eq(object): > ... def __eq__(self, other): > ... return True > ... > >>> class Neq(Eq

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Peter Otten
Tim Peters wrote: > See the Python (language, not library) reference manual, section 3.3.8 > ("Coercion rules"), bullet point starting with: > > Exception to the previous item: if the left operand is an > instance of a built-in type or a new-style class, and the right > operand is an

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Nick Coghlan
is getting coerced. It's just that "A binop B" gets translated to a method call differently depending on the types of A and B. The options being: A.__binop__(B) # 1 - the usual case B.__binop__(A) # 2.1 - commutative op, and B is a proper subclass of A B.__rbinop__(A) # 2.2 - p

Re: assymetry between a == b and a.__eq__(b)

2004-12-05 Thread Mel Wilson
In article <[EMAIL PROTECTED]>, Peter Otten <[EMAIL PROTECTED]> wrote: >Tim Peters wrote: > >> See the Python (language, not library) reference manual, section 3.3.8 >> ("Coercion rules"), bullet point starting with: >> >> Exception to the previous item: if the left operand is an >> instanc

Re: Does python support the expression "a = b | 1"???

2005-10-05 Thread Diez B. Roggisch
Wenhua Zhao wrote: > a = b | 1 > > a = b if b != nil > else a =1 > > Is there such expression in python? Soon there will be, but currently: no. What you are after is a ternary operator like _?_:_ in C. There have been plenty of discussions about these - search this NG.

Re: Does python support the expression "a = b | 1"???

2005-10-05 Thread François Pinard
[Wenhua Zhao] > a = b | 1 > a = b if b != nil > else a =1 > Is there such expression in python? Hi. Merely write: a = b or 1 In Python, there is no `nil'. `a' will receive 1 instead of the value of `b' only if `b' is either zero, None, False, or empty i

Re: Does python support the expression "a = b | 1"???

2005-10-05 Thread Paul Rubin
Wenhua Zhao <[EMAIL PROTECTED]> writes: > Is there such expression in python? Not in the current version but one is being added. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does python support the expression "a = b | 1"???

2005-10-05 Thread Grant Edwards
On 2005-10-05, Wenhua Zhao <[EMAIL PROTECTED]> wrote: > a = b | 1 Yes, Python supports that expression. > a = b if b != nil > else a =1 But that's not what it means. > Is there such expression in python? >>> b=0 >>> b = 0 >>> a = b | 1 >&

Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an endless loop in a line with: if a==b: print 'OK' I mean, it would be of much

*tuple vs tuple example print os.path.join(os.path.dirname(os.tmpnam()), *("a", "b", "c"))

2005-12-13 Thread Steve
I have been trying to find documentation on the behavior Can anyone tell me why the first example works and the second doesn't and where I can read about it in the language reference? Steve print os.path.join(os.path.dirname(os.tmpnam()),*("a","b","c")) #work

Re: *tuple vs tuple example printos.path.join(os.path.dirname(os.tmpnam()), *("a", "b", "c"))

2005-12-13 Thread Fredrik Lundh
x is path = os.path.join("part1", "part2", "part3") your first example > print os.path.join(os.path.dirname(os.tmpnam()),*("a","b","c")) is equivalent to print os.path.join(os.path.dirname(os.tmpnam()), "a", "b&qu

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fredrik Lundh
Claudio Grondi wrote: > In the process of learning about some deeper details of Python I am > curious if it is possible to write a 'prefix' code assigning to a and b > something special, so, that Python gets trapped in an endless loop in a > line with: > > if a==b: pri

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steve Holden
Claudio Grondi wrote: > In the process of learning about some deeper details of Python I am > curious if it is possible to write a 'prefix' code assigning to a and b > something special, so, that Python gets trapped in an endless loop in a > line with: > > if a==b

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
Steve Holden wrote: > Claudio Grondi wrote: > >> In the process of learning about some deeper details of Python I am >> curious if it is possible to write a 'prefix' code assigning to a and >> b something special, so, that Python gets trapped in an endless loop

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Claudio Grondi wrote: [snip..] > Thanks for the quick reply. > > I see, that I have overseen, that as Fredrik also stated, one can > directly manipulate __eq__() as the easiest way to achieve what I > requested. > > To explain why I am not happy with it, I will try here to give some more > backgro

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steve Holden
hing special, so, that Python gets trapped in an endless loop >>>in a line with: >>> >>>if a==b: print 'OK' >>> >>>I mean, it would be of much help to me on my way to understanding >>>Python to know how such prefix code leading to

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
Fuzzyman wrote: > Claudio Grondi wrote: > [snip..] > >>Thanks for the quick reply. >> >>I see, that I have overseen, that as Fredrik also stated, one can >>directly manipulate __eq__() as the easiest way to achieve what I >>requested. >> >>To explain why I am not happy with it, I will try here to

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
prefix' code assigning to a >>>> and b something special, so, that Python gets trapped in an endless >>>> loop in a line with: >>>> >>>> if a==b: print 'OK' >>>> >>>> I mean, it would be of much help to me on my

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steve Holden
bjects storing the integer value 1, what I mean > can happen when there is enough other code between the Python code lines > assigning the integer value 1 to a list element or any other identifier. Perhaps you could try again in English? :-) Sorry, that's a very complex sentence and it i

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Claudio Grondi wrote: [snip..] > Yes, I know about 'is', > > but I mean, that it is not possible to use 'is' as replacement for '==' > operator to achieve in Python same behaviour as it is the case in C and > Javascript when comparing values with '=='. > 'is' does the C, Javascript job when compar

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Claudio Grondi wrote: > Steve Holden wrote: [snip..] > The problem here is, that I mean, that in Python it makes no sense to > talk about a value of an object, because it leads to weird things when > trying to give a definition what a value of an object is. > You're saying that C and Java get rou

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
t; > > Perhaps you could try again in English? :-) Sorry, that's a very complex > sentence and it isn't clear what yo mean. Here in English ;-) : a=[1] ... many other statements here ... b=[1] a is b # False a == b # True a[0] is b[0] # unpredictable(?) a[0] == b[0] # True

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Claudio Grondi wrote: [snip..]> > Perhaps you could try again in English? :-) Sorry, that's a very complex > > sentence and it isn't clear what yo mean. > Here in English ;-) : > a=[1] > ... many other statements here ... > b=[1] > a is b # False > a ==

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Oops... my misreading, sorry. The reason that, in Python, short ints have the same identity is not fickle - it's just True. Python creates a new reference (pointer) to the same object. You're saying you want one comparison operator that for : > a=[1] > ... many other statements here ... > b=[1]

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steve Holden
hy you say that. > It seems, that in Python there is a lack of operator able to compare > values as it is the case in C and Javascript, simply because in Python > there are no really such things as values, so there is no need to > compare them. > That is simply incorrect. The e

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread bonono
Fuzzyman wrote: > Claudio Grondi wrote: > > Steve Holden wrote: > [snip..] > > The problem here is, that I mean, that in Python it makes no sense to > > talk about a value of an object, because it leads to weird things when > > trying to give a definition what a value of an object is. > > > > You'

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Peter Hansen
Claudio Grondi wrote: > but I mean, that it is not possible to use 'is' as replacement for '==' > operator to achieve in Python same behaviour as it is the case in C and > Javascript when comparing values with '=='. > 'is' does the C, Javascript job when comparing lists, but I mean it > fails to

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
[EMAIL PROTECTED] wrote: > Fuzzyman wrote: > > Claudio Grondi wrote: > > > Steve Holden wrote: > > [snip..] > > > The problem here is, that I mean, that in Python it makes no sense to > > > talk about a value of an object, because it leads to weird things when > > > trying to give a definition wha

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread bonono
Fuzzyman wrote: > The above gentleman is asserting that in *Python* the term value has no > meaning. I don't know what he meant and don't want to get into that value/reference/object thingy discussion as it would be a never ending thing. I just want to say that '==' in C is very clear to me, wheth

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
Script/Javascript being more like Python is. It is _important to distinguish_ between Java as a programming language with its VM and Javascript as an engine working inside dynamic HTML pages (unless one is on Windows and has the JScript engine available for both purposes: inside HTML and stand-alone

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread bonono
Fuzzyman wrote: > Ok... so I'm now assuming that the information about '==' provided by > the above gentleman *and* that I understand it correctly. > > The only confusion in C (which doesn't have classes) is that two list > (like) objects can't be tested by value - only identity. > In C, they are

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Ok... so I'm now assuming that the information about '==' provided by the above gentleman *and* that I understand it correctly. The only confusion in C (which doesn't have classes) is that two list (like) objects can't be tested by value - only identity. In Java, comparing strings using '==' comp

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
are container objects of the same type, with the same contents. That's > very counter intuitive. As also the fact, that when a = [1,2.0,3L] b = [1.0,2,3 ] a==b # gives True even if the objects in the lists are actually different, or when the objects being members of the list redef

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
I'm not familiar with the C basic datatypes - I assume it has an array or list like object. Would it contain a sequence of poitners to the members ? In which case they would only be equal if the pointers are the same. In this case : a = ['some string'] b = ['somestring'

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fredrik Lundh
Claudio Grondi wrote: > As also the fact, that when > a = [1,2.0,3L] > b = [1.0,2,3 ] > a==b # gives True > even if the objects in the lists are actually different, they all compare equal: >>> 1 == 1.0 True >>> 2.0 == 2 True >>> 3L == 3 True >

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread bonono
Claudio Grondi wrote: > As also the fact, that when > a = [1,2.0,3L] > b = [1.0,2,3 ] > a==b # gives True > even if the objects in the lists are actually different, > or when the objects being members of the list redefine __eq__ so, that > no matter how different they

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
gt; > a = ['some string'] > b = ['somestring'] > a == b > False (probably) > Oops... definitely False unless it is corrected to : a = ['some string'] b = ['some string'] a == b False (probably) All the best, Fuzzyman http://www.voidspace.or

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
So you're no longer wanting to test for equality (as Fredrik has pointed out). All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fredrik Lundh
gt; > a = ['some string'] > b = ['somestring'] > a == b > False (probably) the "value" of a C array is the address of its first argument. two separate arrays will never compare equal, no matter what they contain. (C programs tend to use various "cmp&qu

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
Peter Hansen wrote: > Claudio Grondi wrote: > > but I mean, that it is not possible to use 'is' as replacement for '==' > > operator to achieve in Python same behaviour as it is the case in C and > > Javascript when comparing values with '=='. > > 'is' does the C, Javascript job when comparing lis

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread bonono
gt; > a = ['some string'] > b = ['somestring'] > a == b > False (probably) > > Incorrectly using Python syntax for a C example of course :-) > That depends, the C syntax is like this : char *a="hello"; char *b="hello"; assert(a==b); // true,

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fuzzyman
he pointers are the same. > > > > In this case : > > > > a = ['some string'] > > b = ['somestring'] > > a == b > > False (probably) > > the "value" of a C array is the address of its first argument. two separate > ar

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Claudio Grondi
as it is the case in C and Javascript, simply because in Python >> there are no really such things as values, so there is no need to >> compare them. >> > That is simply incorrect. The expression a == b is true under > well-defined circumstances usually referred to as &q

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steve Holden
Claudio Grondi wrote: > > > > Subject: > Re: Can a simple a==b 'hang' in and endless loop? > From: > Claudio Grondi <[EMAIL PROTECTED]> > Date: > Wed, 18 Jan 2006 19:59:12

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Dave Hansen
On Wed, 18 Jan 2006 17:03:23 +0100 in comp.lang.python, Claudio Grondi <[EMAIL PROTECTED]> wrote: [...] > > >>> a = 1L > >>> b = 1L > >>> a is b >False > >Python fails to reuse the long integer object. It would be interesting >to know why, because it seems to be strange, that in case of integers

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Dave Hansen
ch case >> they would only be equal if the pointers are the same. >> >> In this case : >> >> a = ['some string'] >> b = ['somestring'] >> a == b >> False (probably) >> >> Incorrectly using Python syntax for a C examp

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steven D'Aprano
value of that Python object: the int 1 Python object 4.7 The value of that Python object: the float 4.7 Python object "abc" The value of that Python object: a string consisting of characters a, b and c. Python object [1, 4.7, "abc"] The value of that Python object: a list conta

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Donn Cave
In article <[EMAIL PROTECTED]>, Claudio Grondi <[EMAIL PROTECTED]> wrote: ... > It is probably true, that it doesn't much matter when writing Python > code when one do not understand how Python works internally. The rare > practical cases of getting into trouble because of lack of such > unders

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Fredrik Lundh
only be equal if the pointers are the same. > >> > >> In this case : > >> > >> a = ['some string'] > >> b = ['somestring'] > >> a == b > >> False (probably) > >> > >> Incorrectly using Python syntax fo

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-19 Thread Claudio Grondi
ners to the members ? In which case >>>>they would only be equal if the pointers are the same. >>>> >>>>In this case : >>>> >>>>a = ['some string'] >>>>b = ['somestring'] >>>>a == b >

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-19 Thread Steven D'Aprano
possible to say > a[0], but ... if here > if(a==b): > print "True" > _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-19 Thread Claudio Grondi
; data structures which provide strings as arrays where it is possible >> to say a[0], but ... if here >> if(a==b): >> print "True" >> _does not_ print True, the Python engine is definitely broken. > > > > Why are you comparing C behaviour to Py

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-19 Thread Claudio Grondi
ion what a value of an object is. > > > Python object: 1 > The value of that Python object: the int 1 > > Python object 4.7 > The value of that Python object: the float 4.7 > > Python object "abc" > The value of that Python object: a string consisting of ch

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-19 Thread Steve Holden
ly, in terms of C, pointer to Python object >>>data structures which provide strings as arrays where it is possible >>>to say a[0], but ... if here >>>if(a==b): >>> print "True" >>>_does not_ print True, the Python engine is definitely brok

  1   2   >