Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Times from YML file printing wrong

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading