A certainl part of an if() structure never gets executed.

Νικόλαος Κούρας support at superhost.gr
Wed Jun 12 06:59:08 EDT 2013


On 12/6/2013 1:07 μμ, Andreas Perstinger wrote:

>> So, i must tell:
>>
>> for i, month in enumerate(months):
>>       print('<option value="%s"> %s </option>' % (i, month) )
>>
>> to somehow return '==========' instead of 0 but don't know how.
>
> As with most of your problems you are barking up the wrong tree.
> Why not use the actual value you get from the form to check whether you
> have a valid month?
> Do you understand why "0" is submitted instead of "=========="?

No, this is exactly what i do not understand.

months = ( '==========', 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 
'Απρίλιος', 'Μάϊος', 'Ιούνιος',
            'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 
'Νοέμβριος', 'Δεκέμβριος' )

This is a tuple containign months. Then we have this:

for i, month in enumerate(months):
       print('<option value="%s"> %s </option>' % (i, month) )

i is assiciated to month in similar fashion as a dic's key to it's value

i = the increasing counter after each iteration in the loop
month = just the displayed month.

when iteration happens we get this:

value 0 for month '=========='
value 1 for month 'Ιανουάριος'
.....
.....
value 12 for month 'Δεκέμβριος'

So when '==========' is being selected as month from the user value 0 is 
beign returned, but what i need is the string '==========' itself, not 
the value.

the year var have no prblem, is the month that always fails the if() 
condition branch.



More information about the Python-list mailing list