I'm having trouble writing .txt with python. So i first read one .txt file, then split it, and rearrange then write it out to another .txt file.
Here's my code
# Read objects
objectit = open('objects.txt', 'r')
Lines = objectit.readlines()
# SpawnObjects writing
count = 0
objectit = open('SpawnObject.txt', 'w')
for line in Lines:
test = line.split('|', 3)
objline = ("SpawnObject( ", "\"",test[0],"\"", ", " , "\"",test[1],"\"", ", " , "\"",test[2],"\"" , ");\n")
print("SpawnObject( ", "\"",test[0],"\"", ", " , "\"",test[1],"\"", ", " , "\"",test[2],"\"" , ");\n")
objectit.writelines(objline)
objectit.close()
Input data looks like this:
bldr_Game_wall_5m|13751.722656 46.671505 2962.292480|-155.094345 0.000000 -2.000000
Barrier_4m|13783.922852 41.197544 2915.867920|134.620407 0.000000 2.000000
randomObject|13793.672852 40.633644 2912.021484|136.797043 0.000000 3.000002
And this is what i get when i run this through script.
SpawnObject( "bldr_Game_wall_5m", "13751.722656 46.671505 2962.292480", "-155.094345 0.000000 -2.000000
");
SpawnObject( "Barrier_4m", "13783.922852 41.197544 2915.867920", "134.620407 0.000000 2.000000
");
SpawnObject( "randomObject", "13793.672852 40.633644 2912.021484", "136.797043 0.000000 3.000002
");
I don't know why ");"
is going to another row. But i've tried multiple things to fix this. Whole point was to automate this step, and currently i still have to do manual labor
To be clear, below is the example of data i'd like to get.
SpawnObject( "randomObject", "13793.672852 40.633644 2912.021484", "136.797043 0.000000 3.000002");
SpawnObject( "Barrier_4m", "13783.922852 41.197544 2915.867920", "134.620407 0.000000 2.000000");
SpawnObject( "randomObject", "13793.672852 40.633644 2912.021484", "136.797043 0.000000 3.000002");