Home > OS >  In Python, how can i write multiple times to a file and keep everything on 1 long line line? (40k pl
In Python, how can i write multiple times to a file and keep everything on 1 long line line? (40k pl

Time:01-25

Working on a data transfer program, to move data from an oracle database to another application that I cant see or change. I have to create several text files described below and drop them off on sftp site.

I am converting from a 20 year old SQR report. (yes SQR) :(

I have to create text files that have a format as such an_alpa_code:2343,34533,4442,333335,.....can be thousands or numbers separated by comma.

The file may have only 1 line, but the file might be 48k in size.

There is no choice on the file format, it is required this way.

Tried using Oracle UTL_FILE, but that cannot deal with a line over 32k in length, so looking for an alterative. Python is a language my company has approved for use, so I am hoping it could do this

CodePudding user response:

I too once [was forced] to use SQR many years ago, and so you have my sympathy.

python can definitely do this. If you set the end argument of the print command to an empty string, then you can ensure that no new line is output:

print("Hello world",end='')

perl could also be a good candidate language.

print("Hello world");

Both python and perl have Oracle client libraries.

CodePudding user response:

This gave me one long line file_obj = open("writing.txt", "w")

for i in range(0,10000): file_obj.write("mystuff" str(i) ",") # file_obj.write('\n')

file_obj.close()

  • Related