FOR LOOPS

Iain King iainking at gmail.com
Tue Aug 1 04:15:48 EDT 2006


OriginalBrownster wrote:
> I am using a class called UploadedFile.
> I want to create a for loop to itterate through the objects within file
> name
>
> class UploadedFile(SQLObject):
> 	filename = StringCol(alternateID=True)
> 	abspath = StringCol()
> 	uniqueid = IntCol()
>
> I'll show you a snippit of the code I am trying to use it in::
>
>
>         zip= ["zip.txt"]
>         file_path = [myfile.filename for myfile in
> UploadedFile.select(orderBy=UploadedFile.q.filename)]
>
>         if kw:
>             for filename in file_path:
>                 zip.append(filename)
>             flash('Options selected'+ str(kw) + str(zip))
>         else:
>             pass
>
> When i run this the flash displays all the values for kw...however zip
> only shows up as "zip.txt" using the str function. Meaning that the FOR
> LOOP is not working correctly.

After your 'file_path =' line, try adding a 'print file_path', and see
if it's creating it correctly.  Your for loop looks fine, assuming that
file_path is a list of filenames.

Iain




More information about the Python-list mailing list