python - Copying a range of columns from a text file and creating a new file -
I'm new to Python and I'm parsing some data for some sonar files, for which I need to process more information. I have received this code and I am trying to manipulate it to fulfill my goal. I only need the information of the first 53 columns, the previous 100+ column external data is not required. In line for f: if line.strip ():
f = open ("ADV125cm.txt", "r") g = open "ADV125cm_fixed.txt", "w") G.write ("\ t" .joined (line split (0,53) [1:]) + "\ n") F.close () g.close ()
I have received this error code and I do not know what it means:
Type error: Expected one character buffer object
Any help
You get typeError: a character buffer object is expected
/ Code> because string is expected Sorting characters you are going through 0, 53
Maybe you are confused with piece operation If you want to get 53 of the first row columns , then you need the line [: 53]
. To implement this change your for
loop code is created:
for line f: g.write (line.strip () [: 53] + ' \ N ')