I have an .yml file which is my config. In this file I have defined two times which look like this:
my-times:
earliest_time: 17:00 #PM
latest_time: 19:00 #PM
My code looks like this:
conf: object = yaml.safe_load(open('myconfig.yml'))
earliest_time = str(conf['my-times']['earliest_time'])
latest_time = str(conf['my-times']['latest_time'])
print(earliest_time)
print(latest_time)
But when I’m in this time window and I want to print or use them in an if-statement, I got the following output:
0:00
1080
How do I print the second time in the code above normally, like how it is in the .yml file?
>Solution :
You can change your yaml file:
my-times:
earliest_time: "17:00" #PM
latest_time: "19:00" #PM
This tells YAML that it is a literal string, and inhibits attempts to treat it as a numeric value.
Look at this post for more info:
https://stackoverflow.com/a/28835540/8961170