473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

FOR LOOPS

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.filenam e)]

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

Aug 1 '06 #1
2 1245
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.filenam e)]

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?

Aug 1 '06 #2

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.filenam e)]

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

Aug 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Dr. David Kirkby | last post by:
I have a program that loops through and changes all the elements on an array n times, so my code looks like this: for (n=1; n < n_max; ++n) for(i=imax; i >= 0; --i) { for(j=0 ; j < jmax; ++j) {...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.