I asked a question about this earlier but noone could answer me - I have this code and want what is defined as e to be written into a new ASCII file in one line. I was suggested to use the tuple function which didn't work since it only takes on argument but I have two (a and b). So now I just tried the join function. The code is below
we=open('new.txt','w')
with open('read.txt') as f:
for line in f:
#read a line
a,b=line.split('\t')
#get two values as string
c=2*int(a)
d=3*int(b)
#calculate the other two values
### edited
e = ''.join(("(",str(a),",",str(b),")"))
However, when I print e the last bracket will be moved to a new line:
print(e)
will yield
(1,2
)
(3,4
)
but I want
(1,2)
(3,4)
Thanks for your help!
line = line.replace("\n", "")before further processing the line.