•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 425,924 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,697 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 698 | Replies: 3
![]() |
•
•
Join Date: Jul 2006
Posts: 562
Reputation:
Rep Power: 4
Solved Threads: 72
A friend of mine just introduced me to the Eclipse IDE, which may or may not end up replacing IDLE for me.
Anyway, one of the features of Eclipse is error warnings as the code is *displayed*, rather than waiting for errors to pop up at runtime.
This code got flagged:
the line marked <----- got flagged as "unnecessary else", since the return "" technically prevents the code from getting to 'elif self.tag == "_text":' unless the if falls through.
Stylistically, what is your opinion? Would you write the code like that, or like this:
Anyway, one of the features of Eclipse is error warnings as the code is *displayed*, rather than waiting for errors to pop up at runtime.
This code got flagged:
if self.tag == None:
return ""
elif self.tag == "_text": <-----
return "\t"*tablvl + self.value
elif self.tag == "_toplevel":
s = ""
for i in self.children:
s = s + "\n" + i.__str__(0)
return sthe line marked <----- got flagged as "unnecessary else", since the return "" technically prevents the code from getting to 'elif self.tag == "_text":' unless the if falls through.
Stylistically, what is your opinion? Would you write the code like that, or like this:
if self.tag == None:
return ""
if self.tag == "_text": <-----
return "\t"*tablvl + self.value
if self.tag == "_toplevel":
s = ""
for i in self.children:
s = s + "\n" + i.__str__(0)
return s
Lint Filters give warnings that are not always sensible. Using elif instead of all if is faster, since Python has to evaluate all the if, but stops at the first true elif condition.
In your case it doesn't make much difference since you have a return statement, which will stop Python from going through the rest of the if conditionals. So 'if' is less to type than 'elif'.
In your case it doesn't make much difference since you have a return statement, which will stop Python from going through the rest of the if conditionals. So 'if' is less to type than 'elif'.
Last edited by Ene Uran : Sep 4th, 2006 at 1:56 pm.
drink her pretty
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Background question (JavaScript / DHTML / AJAX)
- Function Style: writeLog(...) (Software Developers' Lounge)
- How do you grab a value from a stylesheet? (JavaScript / DHTML / AJAX)
- Style properties are ignored by Mozilla browser... (ASP.NET)
- array question (C++)
Other Threads in the Python Forum
- Previous Thread: raise in Text()
- Next Thread: Trying to save the info in the student library.



Linear Mode