I tried to make a download list by reading a txt file. The python script can generation a list below. I don't know how to fix the problem that it printed one item in 3 lines. I want one item in one line. Please advice. Thanks a lot.
srr.txt
SRR3468015
SRR3468016
SRR3468017
python lines
f=open("srr.txt")
line=f.readline()
while line:
print "ftp://ftp.sra.ebi.ac.uk/vol1/fastq/"+line[0:6]+"/00"+line[9:]+"/"+line+"/"+line+"_1.fastq.gz"
line=f.readline()
f.close()
actual result
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/005
/SRR3468015
/SRR3468015
_1.fastq.gz
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/006
/SRR3468016
/SRR3468016
_1.fastq.gz
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/007
/SRR3468017
/SRR3468017
_1.fastq.gz
the result I want
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/005/SRR3468015/SRR3468015_1.fastq.gz
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/006/SRR3468016/SRR3468016_1.fastq.gz
ftp://ftp.sra.ebi.ac.uk/vol1/fastq/SRR346/007/SRR3468017/SRR3468017_1.fastq.gz
1 answer
When you copy either the end of your input or the full input, you're also copying the newline character. Before printing your string, apply rstrip(). That should fix it.
Log in to answer this question.