python - How do I save the output I have to a new text file? -


so basically, have super long output, , want able save output brand new text file, without changing old file. code far, need know out_file variable.

thanks future help.

txt_list = []  open("x:\- photogrammetry\python correct dxf colors\involvedpontiac.dxf", "r") in_file, open("x:\- photogrammetry\python correct dxf colors\involvedpontiacfixed.txt", "w+") new_file:     line in in_file:         line = line.rstrip()         txt_list.append(line) entity = 0 = 0 while < len(txt_list):     if txt_list[i] == "entities":         entity = 1     if txt_list[i] == " 62" , entity == 1:         txt_list[i+1] = " 256"     += 1   layer = 0 j = 0 while j < len(txt_list):     if txt_list[j] == "layer" , txt_list[j+2] != " 7":         userinput = input("what color layer " +txt_list[j+2] + "? type 0 black, 1 red, 3 green, 4 light blue, 5 blue, 6 magenta, 7 white, 8 dark grey, 9 medium gray, or 30 orange.")         txt_list[j+6] = " " + userinput          print ("the " + txt_list[j+2] + " layer has color code of " + userinput)     j += 1 item in txt_list:     new_file.write(item) print ('\n'.join(txt_list)) 

i'm not sure what's going on in code.

but write variable file, can use

with open('output.txt', 'w+') new_file:     new_file.write(variable) 

note 'w+' create file if doesn't exist, , overwrite if does.

and if it's items in txt_list want write file, don't think i'd join them first. use for loop:

with open('output.txt', 'w+') new_file:     item in txt_list:         new_file.write(item)  

this print every item in list on new line in file.

txt_list = []  open("x:\- photogrammetry\python correct dxf colors\involvedpontiac.dxf", "r") in_file:     line in in_file:         line = line.rstrip()         txt_list.append(line) entity = 0 = 0 while < len(txt_list):     if txt_list[i] == "entities":         entity = 1     if txt_list[i] == " 62" , entity == 1:         txt_list[i+1] = " 256"     += 1   layer = 0 j = 0 while j < len(txt_list):     if txt_list[j] == "layer" , txt_list[j+2] != " 7":         userinput = input("what color layer " +txt_list[j+2] + "? type 0 black, 1 red, 3 green, 4 light blue, 5 blue, 6 magenta, 7 white, 8 dark grey, 9 medium gray, or 30 orange.")         txt_list[j+6] = " " + userinput          print ("the " + txt_list[j+2] + " layer has color code of " + userinput)     j += 1  open('output.txt', 'w+') new_file:     item in txt_list:         new_file.write(item)  print ('\n'.join(txt_list) 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -