By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,713 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,713 IT Pros & Developers. It's quick & easy.

RE: Use of the "is" statement

P: n/a
Maric Michaud wrote:
Le Friday 27 June 2008 18:26:45 Christian Heimes, vous avez écrit*:
>Ask yourself if you are interested if f.tell() returns exactly the
same 0 object ("is") or a number that is equal to 0 ("==").
That said, "f.tell() == 0" and "f.tell() != 0" should be written
"f.tell()" and "not f.tell()" in python.

if not f.tell() :
print 'at the beginning of the file"
No, because semantically you're not using the result of f.tell() as a boolean value. tell() returns a *position*, and he is checking for a particular position.

If he'd instead been testing for f.tell() == 2, would you have advisd that he use "if f.tell()"?

Ignoring the triviality of the below code, would you suggest refactoring:

for i, v in enumerate(iterable):
if i == 0:
doSomethingSpecial()
else:
print i

as:

for i, v in enumerate(iterable):
if not i:
doSomethingSpecial()
else:
print -i

?

Tim Delaney
Jun 30 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.