Writing a text file using python -
how can write test below using python text file? required when have write several text files different parameters.
my_file = e:\test.jpg band_subset = ( 1 0 0 ) spatial_subset1 = ( 25.0 50.0 ) spatial_subset2 = ( 25.0 50.0 ) para1 = ( 0.0 0.0 0.0 0.0 0.0 0.0 ) end = end
with open('filename', 'w') f: f.write(yourstring)
where
>>> yourstring = """my_file = e:\test.jpg band_subset = ( 1 0 0 ) spatial_subset1 = ( 25.0 50.0 ) spatial_subset2 = ( 25.0 50.0 ) para1 = ( 0.0 0.0 0.0 0.0 0.0 0.0 ) end = end"""
you replace values using following code.
with open('filename', 'w') f: f.write(yourstring.format(band_subset, spatial_subset_1, spatial_subset_2, para1))
where
yourstring = """my_file = e:\test.jpg band_subset = {} spatial_subset1 = {} spatial_subset2 = {} para1 = {} end = end"""
always use help
function or consult python docs.
write(...) write(str) -> none. write string str file.
Comments
Post a Comment