Re: If - Or statements

2005-06-11 Thread tiissa
Patrick Down wrote: > 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'. ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: If - Or statements

2005-06-07 Thread Patrick Down
What about: if True in [thefile.endswith(x) for x in ('mp3','mp4','ogg','aac','wma')]: -- http://mail.python.org/mailman/listinfo/python-list

Re: If - Or statements

2005-06-07 Thread bruno modulix
Steven Bethard wrote: > bruno modulix wrote: (snip) >> ext = os.path.splitext(filename) > > Check the docs[1]. This should probably read: > _, ext = os.path.splitext(filename) Of course. Au temps pour moi. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p

Re: If - Or statements

2005-06-06 Thread Steven D'Aprano
On Sun, 05 Jun 2005 13:52:09 -0400, Roy Smith wrote: > One sure sign of somebody trying to write C in Python is when they loop > over a list by doing > > for i in range (len (myList)): >doSomethingWith (myList[i]) I usually do that, and I've never coded a line of C in my life. I can't even

Re: If - Or statements

2005-06-06 Thread Steven Bethard
bruno modulix wrote: > Here's a somewhat more pythonic version: > > filelist = os.listdir(path) > for filename in filelist: > # I assume you want to remember what's the ext is > ext = os.path.splitext(filename) Check the docs[1]. This should probably read: _, ext = os.path.splitext

Re: If - Or statements

2005-06-06 Thread bruno modulix
Ognjen Bezanov wrote: (snip) > filelist = os.listdir('/mnt/cdrom/') #get a list of files from the cdrom > drive Please put long comments on the previous line... And BTW, please avoid useless comments that just paraphrase the code > for thefile in filelist[:]: #for each file in the fi

Re: If - Or statements

2005-06-05 Thread Roy Smith
venkata subramanian <[EMAIL PROTECTED]> wrote: > It just reminds me that the most important thing about learning a > language is also to learn its style and "paradigm" and not just its > syntax and semantics. Or one might end up wrenching in > "C-like-thinking" into a python program where it might

Re: If - Or statements

2005-06-05 Thread venkata subramanian
I'm sorry if this mail (also) sidetracks the primary theme of this thread. But, it was a moment of "shock and awe" seeing the use of list for checking among multiple options ... which is usually done using a name=opt1 or name=op2 etc., I started as a C programmer and hence, that style of thinkin

Re: If - Or statements

2005-06-04 Thread Ognjen Bezanov
Robert Kern wrote: > Ognjen Bezanov wrote: > >> Robert Kern wrote: >> >> >>> Ognjen Bezanov wrote: >>> >>> 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

Re: If - Or statements

2005-06-04 Thread tiissa
Ognjen Bezanov wrote: > ext = thefile.split('.') #get the file extension > ext[1] = ext[1].lower() #convert to lowercase As a side note, ext[1] will be the first extension: >>> 'foo.bar.ogg'.split('.')[1] 'bar' I'd advise ext[-1], the last element of the spli

Re: If - Or statements

2005-06-04 Thread rzed
Ognjen Bezanov <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Robert Kern wrote: > >> Ognjen Bezanov wrote: >> >>> 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

Re: If - Or statements

2005-06-04 Thread Robert Kern
Ognjen Bezanov wrote: > Robert Kern wrote: > > >>Ognjen Bezanov wrote: >> >> >>>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 st

Re: If - Or statements

2005-06-04 Thread Ognjen Bezanov
Robert Kern wrote: > Ognjen Bezanov wrote: > >> 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 f

Re: If - Or statements

2005-06-04 Thread Robert Kern
Ognjen Bezanov wrote: > 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 us