If - Or statements

O

Ognjen Bezanov

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

Patrick Down

What about:

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

tiissa

Patrick said:
What about:

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

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

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top