return statement in functions
hokieghal99
hokiegal99 at hotmail.com
Tue Dec 23 11:44:39 EST 2003
Irmen de Jong wrote:
> hokieghal99 wrote:
>
>> Here's how I call the report function:
>>
>> report(fs_object_count,clean_dir_names,etc., etc.)
>>
>
> You're forgetting to actually *call* the other functions too,
> (you just pass the functions themselves, as you see in your output,
> Python prints the function objects that you pass to the report
> function).
> So try this:
>
> report(fs_object_count(),clean_dir_names(),...)
>
> these you forgot: ^^ ^^
>
>
> --Irmen
That works, but it only returns the first item in the list. The
functions are returning a list of paths or of files/dirs. For example,
the function 'clean_dir_names' should return a complete list of
directory names that it has removed bad characters from.
def clean_dir_names(path):
for root, dirs, files in os.walk(path, topdown=False):
for dname in dirs:
new_dname = re.sub(bad,'-' ,dname)
if new_dname != dname:
newpath = os.path.join(root, new_dname)
oldpath = os.path.join(root, dname)
os.renames(oldpath, newpath)
return new_dname
How do I make the report function see all of the contents of the list
and not just the first item of the list?
>
More information about the Python-list
mailing list