So I have this program. Basically I get 7 coordinates and I sent back 1 coordinate. (Cant really explain)
from sys import stdin ,stdout
test=int(stdin.readline().strip("\n")) #It got stripped the new line
for z in range(test):
c=stdin.readline().strip("\n").split(" ")# Here also!
x=[0,0,0,0,0,0,0,0]
y=[0,0,0,0,0,0,0,0]
letter="abcdefgh"
for k in range(7):
x[letter.index(c[k][0])]=1
y[int(c[k][1])-1]=1
stdout.write(letter[x.index(0)]+str(y.index(0)+1)+"\n") #This is the main bits
Here's the thing.
This program respond is caught by another program and written in a file. When I use stdout.write(+"\n")
or print
, my program outputs something like
h4
g2
h4
...
But when I just use plain stdout.write()
h4g2h4...
How do I make my program outputs something like this:
h4
g2
h5
...
The program who records my program uses this:
result=open("txt.txt","w")
process=subprocess.Popen([sys.executable,"work.py"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
res=process.communicate(a)
result.write(res[0])
As far as I concern, print
adds 1 line, not 2 lines. That's where I got lost.
My input does have new line, but it got stripped, as you can see in line 2.