out = open ("output.jh")

towrite= a+b
out.write (towrite)

When you want to put an output to a file. instead of the information going right next to eachother how could they go one over the other in the file. This would be for many different outputs.

Recommended Answers

All 4 Replies

over? You mean on a different line??
If so, you should use a line break.

out = open('output.jh')
towrite = a+'\n'+b
out.write(towrite)

over? You mean on a different line??
If so, you should use a line break.

out = open('output.jh')
towrite = a+'\n'+b
out.write(towrite)

where would the line break go

ltwrite = v[6]+ " " + (int (b))
fout.write (ltwrite)

First off, you do not write integers to a file. You convert them to strings first.
Second, the line break is '\n'.
It goes between the values you are trying to separate.

ltwrite = str(v[6])+ "\n" + str(b)
fout.write (ltwrite)

Personally, I like to put the items by appending to a list, then I append the '\n' using join.

ltwrite = []
ltwrite.append(str(v[6]))
ltwrite.append(str(b))
fout.write('\n'.join(ltwrite))
fout.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.