0

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

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by echellwig
0
for j in range(int(Allele[i])):
    outfile.write('             %s   *     ' % allelelocus[j])

Edited by pyTony: n/a

0
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.

0

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]))

Edited by jcao219: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.