if..else stmt

Discussion in 'Python' started by bigden007, Oct 22, 2007.

  1. bigden007

    bigden007 Guest

    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.
     
    bigden007, Oct 22, 2007
    #1
    1. Advertising

  2. 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 && && 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
     
    Erik Max Francis, Oct 22, 2007
    #2
    1. Advertising

  3. 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.
    >
    >
     
    J. Cliff Dyer, Oct 22, 2007
    #3
  4. bigden007

    Sander Smits Guest

    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-tf4670106.html#a13340589
    Sent from the Python - python-list mailing list archive at Nabble.com.
     
    Sander Smits, Oct 22, 2007
    #4
  5. 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.

    :)
     
    J. Cliff Dyer, Oct 22, 2007
    #5
  6. 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...).
     
    Bruno Desthuilliers, Oct 22, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric DELAGE
    Replies:
    2
    Views:
    753
  2. Jay
    Replies:
    3
    Views:
    4,674
    William Ryan
    Oct 31, 2003
  3. Art

    eval with print stmt

    Art, Jul 29, 2004, in forum: Python
    Replies:
    1
    Views:
    308
    Mel Wilson
    Jul 29, 2004
  4. Replies:
    2
    Views:
    297
  5. David

    Changing drop down select stmt

    David, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    288
    David
    Oct 20, 2006
Loading...

Share This Page