[Tutor] optional parameter in list comprehension
prasad rao
prasadaraon50 at gmail.com
Mon Dec 29 16:40:32 CET 2008
hello! I am a novice looking up to the tutor as my Guide.
I got a problem while using optional parameter.
#! user/bin/env python
import os
def myfiles(directory,extension=None):
for x in [os.path.join(x,i) for x,y,z in os.walk(directory)\
for i in z if i.endswith(extension)]:print x
if __name__=='__main__':
import sys
myfiles(sys.argv[1],sys.argv[2])
>>> myfiles.myfiles('C:\\python26')
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
myfiles.myfiles('C:\\python26')
File "C:\Python26\lib\site-packages\myfiles.py", line 6, in myfiles
for i in z if i.endswith(extension)]:print x
TypeError: expected a character buffer object
>>> myfiles.myfiles('C:\\python26','doc')
C:\python26\Doc\examples.doc
How can I rectify this?
Thanks
Prasad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081229/bfb6ead9/attachment.htm>
More information about the Tutor
mailing list