Hi see if this help you.
>>> str_input = '''AATTCCGGTTT
CCTTAACCCCC'''
>>> str_input
'AATTCCGGTTT\nCCTTAACCCCC'
>>> x = str_input.replace ('\n', '')
>>> x
'AATTCCGGTTTCCTTAACCCCC'
>>>
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
Somthing like this.
readlines() return a list,so we just use join().
Something with a for loop should also be possibly.
See if this solve it.
>>> my_file = open('test.txt', 'r')
>>> x = my_file.readlines()
>>> x
['AATTCCGGTTT\n', 'CCTTAACCCCC']
>>> y = ''.join(x)
>>> y
'AATTCCGGTTT\nCCTTAACCCCC'
>>> finish = y.replace('\n', '')
>>> finish
'AATTCCGGTTTCCTTAACCCCC'
>>>
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294
If you want to concatenate (join) every two lines in your file, then you can use something simple like this ...
names = """\
Valerie
Vanessa
Velvet
Venice
Venus
Verena
"""
# create a test file
filename = "mynames.txt"
fout = open(filename, "w")
fout.write(names)
fout.close()
mod_list = []
count = 1
for line in file(filename):
# strip ending whitespaces including newline char
line = line.rstrip()
# concatenate every two lines
if count % 2 == 0:
mod_list.append(old_line+line)
else:
old_line = line
count += 1
print(mod_list)
"""
my result -->
['ValerieVanessa', 'VelvetVenice', 'VenusVerena']
"""
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417