I have this simple program
import yaml
import sys
def main(argv):
#dddd
with open('file_base.yaml') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
#print(data)
#print(type(data))
#Do some transformations to data
#Then we save it to a file called the_new.yaml
with open('the_new.yaml', 'w') as f:
data2 = yaml.dump(data, f)
print(data2)
print(type(data2))
if __name__ == '__main__':
main(sys.argv[1:])
The final objective is to do some transformations of the data, but in this question I want to ask something more basic. In the script above, no transformation is happening.
However, when looking at the output, the data has changed. For example file_base.yaml has
first_data: # Required.
type: ad
class_names: ["hello",
"dog",
"cat",
"lion",
"human"]
but the_new.yaml has
first_data:
class_names:
-"hello"
-"dog"
-"cat"
-"lion"
-"human"
type: ad
As you can see there are two problems:
- The fields are in disorder
- The arrays go from
[ one, two,three]
to using "-"
How can I correct this?