Hi,

I am trying to write elements from a list that I have created to an outfile using a for-loop with this code:

for j in range(int(Allele[i])):
             outfile.write('             allelelocus[j]   *     ')

However when I do this I just get a whole bunch of allelelocus[j] in my out file. I was wondering if there was any way to get my program to write the actual jth element of the list and not just allelelocus[j]. Thanks!

Elise

for j in range(int(Allele[i])):
    outfile.write('             %s   *     ' % allelelocus[j])
for j in range(int(Allele[i])):
    outfile.write('             %s   *     ' % allelelocus[j])

Inserting %s didn't seem to do anything except put %s in my outfile. I think the problem is that the program is writing literally what I put in the command. So I need a way for it not to do that, if that's possible.

Inserting %s didn't seem to do anything except put %s in my outfile. I think the problem is that the program is writing literally what I put in the command. So I need a way for it not to do that, if that's possible.

That means you did something wrong. Look at tonyjv's code again.

This is the newer way to do exactly the same thing:

for j in range(int(Allele[i])):
    outfile.write('             {0}     *     '.format(allelelocus[j]))

Woops! Thanks so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.