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

  • Thread starter Íéêüëáïò Êïýñáò
  • Start date
F

Fábio Santos

but if enumerate yields 0 instead of '==========' then elif '=' not in
year of course fails.

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'tknow how.

Well, you could try this:
for i, month in enumerate(months):
if i == 0:
month = ('=' * 10)
print('<option value="%s"> %s </option>' % (i, month) )

No?
 
Î

Îικόλαος ΚοÏÏας

Well, you could try this:


No?

I'am afraid not Fabio, i just tried byt sumbitting only the year, not
name not month

after printign the valeus to see what went wrong, the values look like:

========== 0 2010

instead of:

========== ========== 2010

========== is the value of the month when its not selected by the user,
but even with your suggestions it reurns t0 intead of the equal signs.....
 
F

Fábio Santos

I'am afraid not Fabio, i just tried byt sumbitting only the year, not name not month

after printign the valeus to see what went wrong, the values look like:

========== 0 2010

instead of:

========== ========== 2010

========== is the value of the month when its not selected by the user,
but even with your suggestions it reurns t0 intead of the equal signs.....
Have you tried

i = month = '=' * 10

I had assumed you just wanted those equal signs for the user display.
 
A

Andreas Perstinger

[Please trim your replies to the relevant parts.]

But when it comes to select '==========' from month instead of
'==========' to be submitted a zero gets submitted and i think the
problem is the way i'm filling up months into the drop down menu which is:


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


the if case does not execute because of the way it checks for None entry
which is: elif '=' not in year:

but if enumerate yields 0 instead of '==========' then elif '=' not in
year of course fails.

How often do we need to tell you that you should reread your posts
before sending them?
You start with telling us you have problems with "month" and then show
us code regarding "year"
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 "=========="?

Bye, Andreas
 
Î

Îικόλαος ΚοÏÏας

-------- Original Message --------
Subject: Re: A certainl part of an if() structure never gets executed.
Date: Wed, 12 Jun 2013 10:07:39 +0100
From: Fábio Santos <[email protected]>
To: Îικόλαος ΚοÏÏας <[email protected]>
CC: (e-mail address removed) <[email protected]>
Newsgroups: comp.lang.python
References: <[email protected]>
<[email protected]> <[email protected]>

but if enumerate yields 0 instead of '==========' then elif '=' not in
year of course fails.

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.

Well, you could try this:
for i, month in enumerate(months):
if i == 0:
month = ('=' * 10)
print('<option value="%s"> %s </option>' % (i, month) )

No?

You can see if for yourself if you go to:
http://superhost.gr/?page=pelatologio.py

bottom down where the form drop down menus are:

search will work but f the suer just gives out the year it will never
make it to the specific if() branch.
 
Î

Îικόλαος ΚοÏÏας

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.
 
Î

Îικόλαος ΚοÏÏας

Oh my God!

i just need to do this:

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

feedthetroll

Am Mittwoch, 12. Juni 2013 12:07:54 UTC+2 schrieb Andreas Perstinger:
[Please trim your replies to the relevant parts.]
But when it comes to select '==========' from monthinstead of
'==========' to be submitted a zero gets submitted and i think the
problem is the way i'm filling up months into the drop down menu which is:
for i, month in enumerate(months):
print('<option value="%s"> %s </option>' % (i, month) )

the if case does not execute because of the way it checks for None entry
which is: elif '=' not in year:
but if enumerate yields 0 instead of '==========' then elif '=' not in
year of course fails.

How often do we need to tell you that you should reread your posts
before sending them?
You start with telling us you have problems with "month" and then show
us code regarding "year"
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 "=========="?
To Nikos:
My I elaborate that for you:
Your form contains: <option value="0"> ========== </option>
If you still don't know why you get "0" read:
http://www.w3schools.com/tags/att_option_value.asp (or something in
greek about html forms)
(Sorry, I know, you do not read doks, because they describe what the software
DOES and not what you WANT it to DO)

So this is no python problem, it is a html-problem.
 
Î

Îικόλαος ΚοÏÏας

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 "=========="?

Bye, Andreas

I have corrected the enumerate loop but it seems thet now the year works
and the selected name nad month fail:

if '=' not in ( name and month and year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) =
%s ORDER BY lastvisit ASC''', (name, month, year) )
elif '=' not in ( month and year ):
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER
BY lastvisit ASC''', year )
else:
print( '<h2><font color=red>Πώς να γίνει αναζήτηση Î±Ï†Î¿Ï Î´ÎµÎ½ επέλεξες
οÏτε πελάτη οÏτε μήνα ή τουλάχιστον το έτος?' )
print( '<meta http-equiv="REFRESH"
content="5;/cgi-bin/pelatologio.py">' )
sys.exit(0)


i tried in , not in and all possible combinations. but somehow it
confuses me.

doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year
variables?

i think it does, but why it fails then?
 
F

Fábio Santos

Oh my God!

i just need to do this:


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

Usually what goes in <option value="..."> is an ID of something. You should
keep using (i, month) and then do months[id] to get the month string.

Also, tuples aren't traditionally used for this. Normally you'd use a list.
 
Î

Îικόλαος ΚοÏÏας

Oh my God!

i just need to do this:


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

Usually what goes in <option value="..."> is an ID of something. You
should keep using (i, month) and then do months[id] to get the month string.

Also, tuples aren't traditionally used for this. Normally you'd use a list.

You were right, i counter needed to signify the value: I just made it
work as i wanted to!


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


.....
.....


#
=================================================================================================================
# find & display requested info based on name/month/year criteria
#
=================================================================================================================
if( seek ):
try:
if '=' not in ( name or month or year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) =
%s ORDER BY lastvisit ASC''', (name, month, year) )
elif '=' not in ( month or year ):
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER
BY lastvisit ASC''', year )
 
N

Neil Cerutti

It'd be courteous to acknowledge those who made that
suggestion, most notably alex23 who posted it in almost that
exact form.

Also, I wish he would stop fudging his From info. I've got
something like 8 entries for this ass in my killfile, and it
seems I need a new one every day.
 
M

Mark Lawrence

Also, I wish he would stop fudging his From info. I've got
something like 8 entries for this ass in my killfile, and it
seems I need a new one every day.

An ass eh, when did he get promoted to that position?

--
"Steve is going for the pink ball - and for those of you who are
watching in black and white, the pink is next to the green." Snooker
commentator 'Whispering' Ted Lowe.

Mark Lawrence
 
G

Grant Edwards

???????? ?????? said:
Code:
		if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
		elif not re.search( '=', month ) and not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
		elif not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )[/QUOTE]

There is so much you didn't tell us here, including which database you are
using.[/QUOTE]

Are you guys _still_ on Nikos hook?

[No, I don't really think he's trolling, but it would be really
impressive if he were.]

Anyway, I salute your patience.
 
N

Neil Cerutti

???????? ?????? said:
Code:
		if not re.search( '=', name ) and not re.search( '=', month ) and not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (name, month, year) )
		elif not re.search( '=', month ) and not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
		elif not re.search( '=', year ):
			cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year )[/QUOTE]

There is so much you didn't tell us here, including which database you are
using.[/QUOTE]

Are you guys _still_ on Nikos hook?

[No, I don't really think he's trolling, but it would be really
impressive if he were.][/QUOTE]

He's definitely trolling. I can't think of any other reason to
make it so hard to kill-file himself.
 
Z

Zero Piraeus

:

He's definitely trolling. I can't think of any other reason to
make it so hard to kill-file himself.

He's not a troll, he's a help vampire:

http://slash7.com/2006/12/22/vampires/

.... a particularly extreme example, I'll admit: his lack of
consideration for others apparently knows no bounds. The email thing
is just another aspect of that.

-[]z.
 
M

MRAB

I have corrected the enumerate loop but it seems thet now the year works
and the selected name nad month fail:

if '=' not in ( name and month and year ):
cur.execute( '''SELECT * FROM works WHERE clientsID = (SELECT id FROM
clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) =
%s ORDER BY lastvisit ASC''', (name, month, year) )
elif '=' not in ( month and year ):
cur.execute( '''SELECT * FROM works WHERE MONTH(lastvisit) = %s and
YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', (month, year) )
elif '=' not in year:
cur.execute( '''SELECT * FROM works WHERE YEAR(lastvisit) = %s ORDER
BY lastvisit ASC''', year )
else:
print( '<h2><font color=red>Πώς να γίνει αναζήτηση Î±Ï†Î¿Ï Î´ÎµÎ½ επέλεξες
οÏτε πελάτη οÏτε μήνα ή τουλάχιστον το έτος?' )
print( '<meta http-equiv="REFRESH"
content="5;/cgi-bin/pelatologio.py">' )
sys.exit(0)


i tried in , not in and all possible combinations. but somehow it
confuses me.

doesn't that mean?

if '=' not in ( name and month and year ):

if '=' does not exists as a char inside the name and month and year
variables?

i think it does, but why it fails then?
You think it does, but you're wrong.
 
Î

Îικόλαος ΚοÏÏας

You think it does, but you're wrong.

How would you telll in english word what this is doing?

if '=' not in ( name and month and year ):


and then what this is doing?

if '=' not in ( name or month or year ):

Never before i used not in with soe many variables in parenthesi, up
until now i was specified it as not in var 1 and not in var 2 and not in
var 2 and so on....
 
M

MRAB

How would you telll in english word what this is doing?

if '=' not in ( name and month and year ):
In English, the result of:

x and y

is basically:

if bool(x) is false then the result is x, otherwise the result is y

For example:
'world'


and then what this is doing?

if '=' not in ( name or month or year ):
In English, the result of:

x or y

is basically:

if bool(x) is true then the result is x, otherwise the result is y

For example:
'Hello'

These can be strung together, so that:

x and y and z

is equivalent to:

(x and y) and z

and:

x or y or z

is equivalent to:

(x or y) or z

and so on, however many times you wish to do it.
Never before i used not in with soe many variables in parenthesi, up
until now i was specified it as not in var 1 and not in var 2 and not in
var 2 and so on....
Keep it simple:

if '=' not in name and '=' not in month and '=' not in year:

There may be a shorter way, but you seem confused enough as it is.
 
Î

Îικόλαος ΚοÏÏας

In English, the result of:

x or y

is basically:

if bool(x) is true then the result is x, otherwise the result is y

For example:

'Hello'

These can be strung together, so that:

x and y and z

is equivalent to:

(x and y) and z

and:

x or y or z

is equivalent to:

(x or y) or z

and so on, however many times you wish to do it.

Keep it simple:

if '=' not in name and '=' not in month and '=' not in year:

There may be a shorter way, but you seem confused enough as it is.

Whn i see:

if( x and y ):
i understand: if x expression = True AND ALSO y expression = True then
execute


if( x or y ):
i understand: if x expression = True OR y expression = True then execute


if '=' not in ( name and month and year ):
i understand: if '=' not in name AND '=' not in month AND '=' not in year


if '=' not in ( name or month or year ):
i understand: if '=' not in name OR '=' not in month OR '=' not in year


but i know it does not work like this, but tis is how i understand it.
its like reading an English sentence
 

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top