473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

if..else stmt

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.

Oct 22 '07 #1
5 1655
bigden007 wrote:
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.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
So little time, so little to do.
-- Oscar Levant
Oct 22 '07 #2
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.

:)

bigden007 wrote:
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.

Oct 22 '07 #3

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.
>>def tr():
.... print "tr func"
.... return "Sander"
....
>>def fa():
.... print "fa func"
.... return "Harry"
....
>>s = "yes" if tr() == "Sander" else fa()
tr func
>>s
'yes'
>>s = "yes" if tr() == "San" else fa()
tr func
fa func
>>s
'Harry'
>>>
Can you show your code?
bigden007 wrote:
>
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.

--
http://mail.python.org/mailman/listinfo/python-list

--
View this message in context: http://www.nabble.com/if..else-stmt-...html#a13340589
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 22 '07 #4
bigden007 wrote:
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.

:)

Oct 22 '07 #5
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...).
Oct 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Hi all, I am doing the change from having worked in Oracle for a long time to MS SQL server and am frustrated with a couple of simple SQL stmt's. Or at least they have always been easy. The...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1 below the call to that stored procedure does not...
4
by: don.fleming | last post by:
Hi folks: Am doing a VBA SQL Select stmt with multiple rows found and not getting RecordCount > 1. I've verified there are multiple rows found by copying my SQL stmt from Debug window and pasting...
1
by: Uzytkownik | last post by:
I've some function: function show($id) { $title = $text = $date = $nick = NULL; $stmt = $this->base->stmt_init(); $stmt->prepare("SELECT title,text,datetime,nick FROM posts LEFT JOIN authors ON...
4
seshu
by: seshu | last post by:
Hi everybody Presently Iam write three select statements with diff where and limt conditions but the select stmt in them is same insted of that can i write only one direct stmt...
1
by: jesmi | last post by:
hi all i have a problem with my code.following is my code: Connection con = null; PreparedStatement stmt = null;
1
by: Kingsly | last post by:
How to read "stmt" column of "sysibm.syspackstmt" table in a readable format? select stmt from sysibm.syspackstmt where name like 'MYPROC1'; I was expecting the stored procedure statements as...
2
by: pankaj17 | last post by:
hello everyone, MYSQL query ............ how to set prepare stmt result in variable i have written prepare stmt in store procedure and i want to set result of prepare stmt in variable ...
0
by: pankaj17 | last post by:
hello everyone, MYSQL query ............ how to set prepare stmt result in variable i have written prepare stmt in store procedure and i want to set result of prepare stmt in variable ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.