Re: Use cases for del

2005-07-10 Thread Reinhold Birkenfeld
Ron Adam wrote: 'abc' is 'abcd'[:3] False Well of course it will be false... your testing two different strings! And the resulting slice creates a third. Try: ABC = 'abc' value = ABC if value is ABC: # Test if it is the same object pass That's not going to buy you

Re: Use cases for del

2005-07-10 Thread Ron Adam
Reinhold Birkenfeld wrote: Ron Adam wrote: 'abc' is 'abcd'[:3] False Well of course it will be false... your testing two different strings! And the resulting slice creates a third. Try: ABC = 'abc' value = ABC if value is ABC: # Test if it is the same object pass

Re: Use cases for del

2005-07-10 Thread Terry Reedy
Ron Adam [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] To avoid that you either need to define the flag string as a global name or use it strictly in the local scope it's defined in. Python will also sometimes reuse strings as an optimization instead of creating a second string

Re: Use cases for del

2005-07-09 Thread Scott David Daniels
Ron Adam wrote: George Sakkis wrote: I get: None: 0.54952316 String: 0.498000144958 is None: 0.45047684 What do yo get for name is 'string' expressions? 'abc' is 'abcd'[:3] False You need to test for equality (==), not identity (is) when equal things may be

Re: Use cases for del

2005-07-08 Thread Ron Adam
Steven D'Aprano wrote: Ron Adam wrote: def count_records(record_obj, start=0, end=len(record_obj)): That would work really well, except that it doesn't work at all. Yep, and I have to stop trying to post on too little sleep. Ok, how about... ? def count_records(record_obj, start=0,

Re: Use cases for del

2005-07-08 Thread George Sakkis
Ron Adam [EMAIL PROTECTED] wrote: Here's something interesting: import time x = None t = time.time() for i in range(100): if x==None: pass print 'None:',time.time()-t x = 'to-end' t = time.time() for i in range(100): if x=='to-end': pass print

Re: Use cases for del

2005-07-08 Thread Scott David Daniels
Ron Adam wrote: Here's something interesting: import time x = None t = time.time() for i in range(100): if x==None: pass print 'None:',time.time()-t x = 'to-end' t = time.time() for i in range(100): if x=='to-end': pass print

Re: Use cases for del

2005-07-08 Thread Daniel Dittmar
Scott David Daniels wrote: Testing for None should be an is-test (not just for speed). In older pythons the == result wasn't necessarily same as is-test. This made sense to me after figuring out NULL in database stuff. NULL in SQL databases has nothing to do with Python None. I'm quite sure

Re: Use cases for del

2005-07-08 Thread Roy Smith
Daniel Dittmar [EMAIL PROTECTED] wrote: In a SQL database, NULL = NULL will always return NULL, which is prety much the same as FALSE. Except for NOT, AS NOT NULL is NULL. SQL's NULL is very much akin to the IEEE NaN (not quite, but close). --

Re: Use cases for del

2005-07-07 Thread Steven D'Aprano
Ron Adam wrote: Why would you want to use None as an integer value? If a value isn't established yet, then do you need the name defined? Wouldn't it be better to wait until you need the name then give it a value? Er, maybe I'm misunderstanding something here, but surely the most obvious

Re: Use cases for del

2005-07-07 Thread Grant Edwards
On 2005-07-07, Ron Adam [EMAIL PROTECTED] wrote: class demo: def foo(v=None): if v is not None: self.v = v return self.v You are really checking if v exists, so having it undefined in namespace as the default is consistent with what you are

Re: Use cases for del

2005-07-07 Thread Ron Adam
Grant Edwards wrote: On 2005-07-07, Ron Adam [EMAIL PROTECTED] wrote: It would be a way to set an argument as being optional without actually assigning a value to it. So it would still work like you expect even though v is not bound to anything. Like I said the bigger problem is that globals

Re: Use cases for del

2005-07-07 Thread Ron Adam
Steven D'Aprano wrote: Ron Adam wrote: Why would you want to use None as an integer value? If a value isn't established yet, then do you need the name defined? Wouldn't it be better to wait until you need the name then give it a value? Er, maybe I'm misunderstanding something here,

Re: Use cases for del

2005-07-07 Thread Dieter Maurer
Daniel Dittmar [EMAIL PROTECTED] writes on Wed, 06 Jul 2005 16:12:46 +0200: Peter Hansen wrote: Arguing the case for del: how would I, in doing automated testing, ensure that I've returned everything to a clean starting point in all cases if I can't delete variables? Sometimes a global is

Re: Use cases for del

2005-07-07 Thread Peter Hansen
Duncan Booth wrote: Peter Hansen wrote: Tom Anderson wrote: How about just getting rid of del? Arguing the case for del: how would I, in doing automated testing, ensure that I've returned everything to a clean starting point in all cases if I can't delete variables? Sometimes a global is the

Re: Use cases for del

2005-07-07 Thread George Sakkis
Grant Edwards [EMAIL PROTECTED] wrote: On 2005-07-07, George Sakkis [EMAIL PROTECTED] wrote: I guess he means why not define foo as property: class demo(object): foo = property(fget = lambda self: self.v, fset = lambda self,v: setattr(self,'v',v)) d = demo()

Re: Use cases for del

2005-07-07 Thread Steven D'Aprano
Ron Adam wrote: Steven D'Aprano wrote: Er, maybe I'm misunderstanding something here, but surely the most obvious case is for default and special function arguments: def count_records(record_obj, start=0, end=None): if end == None: end = len(record_obj) if start == None:

Re: Use cases for del

2005-07-06 Thread Jp Calderone
On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Tom Anderson wrote: How about just getting rid of del? Removal from collections could be done with a method call, and i'm not convinced that deleting variables is something we really need to be able to do (most other

Re: Use cases for del

2005-07-06 Thread Daniel Dittmar
Peter Hansen wrote: Arguing the case for del: how would I, in doing automated testing, ensure that I've returned everything to a clean starting point in all cases if I can't delete variables? Sometimes a global is the simplest way to do something... how do I delete a global if not with

Re: Use cases for del

2005-07-06 Thread Duncan Booth
Peter Hansen wrote: Tom Anderson wrote: How about just getting rid of del? Removal from collections could be done with a method call, and i'm not convinced that deleting variables is something we really need to be able to do (most other languages manage without it). Arguing the case

Re: Use cases for del

2005-07-06 Thread Steven D'Aprano
On Wed, 06 Jul 2005 10:00:02 -0400, Jp Calderone wrote: On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Tom Anderson wrote: How about just getting rid of del? Removal from collections could be done with a method call, and i'm not convinced that deleting variables is

Re: Use cases for del

2005-07-06 Thread Ron Adam
Steven D'Aprano wrote: On Wed, 06 Jul 2005 10:00:02 -0400, Jp Calderone wrote: On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Tom Anderson wrote: How about just getting rid of del? Removal from collections could be done with a method call, and i'm not convinced

Re: Use cases for del

2005-07-06 Thread Stian Søiland
On 2005-07-06 18:10:16, Ron Adam wrote: But what if assigning a name to None actually unbound it's name? And accessing an undefined name returned None instead of a NameError? Yes, and we can make someunknownlist[] = 2 magically do someunknownlist = list() and append 2. Please. --

Re: Use cases for del

2005-07-06 Thread Benji York
Stian Søiland wrote: Yes, and we can make someunknownlist[] = 2 magically do someunknownlist = list() and append 2. I hope you're being sarcastic. :) If not, why don't you like: some_list = [2] -- Benji York -- http://mail.python.org/mailman/listinfo/python-list

Re: Use cases for del

2005-07-06 Thread Ron Adam
Ron Adam wrote: And accessing an undefined name returned None instead of a NameError? I retract this. ;-) It's not a good idea. But assigning to None as a way to unbind a name may still be an option. -- http://mail.python.org/mailman/listinfo/python-list

Re: Use cases for del

2005-07-06 Thread Reinhold Birkenfeld
Ron Adam wrote: Ron Adam wrote: And accessing an undefined name returned None instead of a NameError? I retract this. ;-) It's not a good idea. But assigning to None as a way to unbind a name may still be an option. IMO, it isn't. This would completely preclude the usage of None as

Re: Use cases for del

2005-07-06 Thread Ron Adam
Reinhold Birkenfeld wrote: Ron Adam wrote: Ron Adam wrote: And accessing an undefined name returned None instead of a NameError? I retract this. ;-) It's not a good idea. But assigning to None as a way to unbind a name may still be an option. IMO, it isn't. This would completely

Re: Use cases for del

2005-07-06 Thread Grant Edwards
On 2005-07-06, Ron Adam [EMAIL PROTECTED] wrote: It would be a way to set an argument as being optional without actually assigning a value to it. The conflict would be if there where a global with the name baz as well. Probably it would be better to use a valid null value for what ever

Re: Use cases for del

2005-07-06 Thread Ron Adam
Grant Edwards wrote: On 2005-07-06, Ron Adam [EMAIL PROTECTED] wrote: It would be a way to set an argument as being optional without actually assigning a value to it. The conflict would be if there where a global with the name baz as well. Probably it would be better to use a valid null

Re: Use cases for del

2005-07-06 Thread Grant Edwards
On 2005-07-07, Ron Adam [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2005-07-06, Ron Adam [EMAIL PROTECTED] wrote: It would be a way to set an argument as being optional without actually assigning a value to it. The conflict would be if there where a global with the name baz as well.

Re: Use cases for del

2005-07-06 Thread Leif K-Brooks
Grant Edwards wrote: 1) So I know whether an parameter was passed in or not. Perhaps it's not considered good Pythonic style, but I like to use a single method for both get and set operations. With no parameters, it's a get. With a parameter, it's a set: class demo: def

Re: Use cases for del

2005-07-06 Thread Grant Edwards
On 2005-07-07, Leif K-Brooks [EMAIL PROTECTED] wrote: Grant Edwards wrote: 1) So I know whether an parameter was passed in or not. Perhaps it's not considered good Pythonic style, but I like to use a single method for both get and set operations. With no parameters, it's a get.

Re: Use cases for del

2005-07-06 Thread George Sakkis
Grant Edwards wrote: In 2005-07-07, Leif K-Brooks [EMAIL PROTECTED] wrote: - Hide quoted text - - Show quoted text - Grant Edwards wrote: 1) So I know whether an parameter was passed in or not. Perhaps it's not considered good Pythonic style, but I like to use a single method

Re: Use cases for del

2005-07-06 Thread Leif K-Brooks
Grant Edwards wrote: On 2005-07-07, Leif K-Brooks [EMAIL PROTECTED] wrote: _NOVALUE = object() class demo: def foo(v=_NOVALUE): if v is _NOVALUE: return self.v else: self.v = v Apart from the change in the logic such that the set operation doesn't

Re: Use cases for del

2005-07-06 Thread Grant Edwards
On 2005-07-07, George Sakkis [EMAIL PROTECTED] wrote: I guess he means why not define foo as property: class demo(object): foo = property(fget = lambda self: self.v, fset = lambda self,v: setattr(self,'v',v)) d = demo() d.foo = 3 print d.foo In some ways that's

Re: Use cases for del

2005-07-06 Thread Grant Edwards
On 2005-07-07, Leif K-Brooks [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2005-07-07, Leif K-Brooks [EMAIL PROTECTED] wrote: _NOVALUE = object() class demo: def foo(v=_NOVALUE): if v is _NOVALUE: return self.v else: self.v = v Apart from the

Re: Use cases for del

2005-07-06 Thread Ron Adam
Grant Edwards wrote: On 2005-07-07, Ron Adam [EMAIL PROTECTED] wrote: Grant Edwards wrote: On 2005-07-06, Ron Adam [EMAIL PROTECTED] wrote: It would be a way to set an argument as being optional without actually assigning a value to it. The conflict would be if there where a global with