Connecting Tech Pros Worldwide Forums | Help | Site Map

If - Or statements

Ognjen Bezanov
Guest
 
Posts: n/a
#1: Jul 19 '05
Another newbie-ish question.

I want to create an if statement which will check if a particular
variable matches one of the statements, and willl execute the statement
if the variable matches any of the statements.

I have tried the following (the pass is just used for testing)


if ext[1] == "mp3" or ext[1] == "mp4" or ext[1] == "ogg" or ext[1] ==
"aac" or ext[1] != "wma":
print "we have a valid extension: " + ext[1] #here would go the
code for decoding the above
pass


but it does not work, running the program the if statement is totally
ignored. if the variable (ext[1]) matches it does not execute the
instructions under the if statement, but also does not return anyerrors.

So how do you create proper if statements using the 'or' function (or
something similar).

thx.


P.S Please CC me as i am having email-list troubles.


Patrick Down
Guest
 
Posts: n/a
#2: Jul 19 '05

re: If - Or statements


What about:

if True in [thefile.endswith(x) for x in
('mp3','mp4','ogg','aac','wma')]:

tiissa
Guest
 
Posts: n/a
#3: Jul 19 '05

re: If - Or statements


Patrick Down wrote:[color=blue]
> What about:
>
> if True in [thefile.endswith(x) for x in
> ('mp3','mp4','ogg','aac','wma')]:[/color]

That will catch (widely used) file names such as 'tmp3' or
'i_cant_spell_frogg'. ;)
Closed Thread