FOR LOOPS

O

OriginalBrownster

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.

Any ideas why this is happening?? perhaps someone could shoe me how to
make a proper list for this if this is incorrect.

Thank you
 
D

danielx

OriginalBrownster said:
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.

Any ideas why this is happening?? perhaps someone could shoe me how to
make a proper list for this if this is incorrect.

Thank you

I'm not really familiar with SQLObject, but are you sure file_path is
not empty?

Also, a few small comments:

1. zip is a builtin function. I would choose a different name, even
though this is not strictly necessary.

2. You can accomplish what you seem to be intending with your loop
using list.extend.

3. That's an interesting thing to put in an else case. Why did you do
it that way instead of just leaving it out?
 
I

Iain King

OriginalBrownster said:
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
 

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

Similar Threads


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