if..else stmt

B

bigden007

Hi,
I have a if..else statement in my script. The statements all execute
fine, but the problem is , even if the IF part of the statement is
true, the else part executes as well. The verion of pythin i use 2.5
Any help is appreciatiated.

Regards

Big Den.
 
E

Erik Max Francis

bigden007 said:
I have a if..else statement in my script. The statements all execute
fine, but the problem is , even if the IF part of the statement is
true, the else part executes as well. The verion of pythin i use 2.5
Any help is appreciatiated.

You're doing something wrong. Without seeing actual code, it's
impossible to say what.
 
J

J. Cliff Dyer

Your else statement is incorrectly indented. The interpreter treats it
as part of the for-loop construct inside the if statement rather than as
part of the if statement itself. See the recent thread about for-else
constructs for more details.

If your problem is not obvious yet, make sure you aren't mixing spaces
and tabs.

:)
 
S

Sander Smits

Works as expected here, the 'else' part is not executed if the 'if' part is
true.

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information..... print "tr func"
.... return "Sander"
.... .... print "fa func"
.... return "Harry"
.... tr func
fa func
Can you show your code?
 
J

J. Cliff Dyer

bigden007 said:
Hi,
I have a if..else statement in my script. The statements all execute
fine, but the problem is , even if the IF part of the statement is
true, the else part executes as well. The verion of pythin i use 2.5
Any help is appreciatiated.

Regards

Big Den.
Your else statement is incorrectly indented. The interpreter treats it
as part of the for-loop construct inside the if statement rather than as
part of the if statement itself. See the recent thread about for-else
constructs for more details.

If your problem is not obvious yet, make sure you aren't mixing spaces
and tabs.

:)
 
B

Bruno Desthuilliers

bigden007 a écrit :
Hi,
I have a if..else statement in my script. The statements all execute
fine, but the problem is , even if the IF part of the statement is
true, the else part executes as well. The verion of pythin i use 2.5
Any help is appreciatiated.

My crystal ball tells me the problem is on line 42 !-)


And if you expect any useful help, please post the minimal working code
reproducing the problem (chances are you'll find the problem by yourself
doing so...).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top