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
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
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
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
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,
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
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
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
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).
--
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
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
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
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,
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
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
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()
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:
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
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
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
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
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
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.
--
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
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
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
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
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
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
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.
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
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.
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
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
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
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
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
37 matches
Mail list logo