I have this yaml im trying to load into python with yaml.safe_load(file) and everytime im getting
yaml.parser.ParserError: while parsing a block mapping in "../fdlmyamls/testHolder/myfile.yaml", line 12, column 9 expected, but found '-' in "../fdlmyamls/testHolder/myfile.yaml", line 13, column 9
The file im trying to load is
myList:
- Name: MyName
Attributes:
- Name: myInnerName
- Context: some_context
Description: ""
Value:
Trial:
Description: some description
ID: myId
User: myUser
Options:
- Label: label1
Value: 1
Weight: 0.25
- Label: label2
Value: 0
Weight: 0.75
but on the line starting with context im getting errors on the load. the pyyaml library returns this what i posted earlier, where as some other online validators gave me this:
A block sequence may not be used as an implicit map key at line 13, column 1 Implicit keys need to be on a single line at line 13, column 9 Implicit map keys need to be followed by map values at line 13, column 9
There are a lot of Syntax Errors in your yaml. I would suggest you to use JSON (.json files) instead, since it is easier to write and read manually but contains exactly the same data.
Import json like this: import json
You can load a json file to python like this:
filepath = 'myfile.json'
with open(filepath, 'r') as f:
data = json.load(f)
You can save Json to a file like this:
filepath = 'myfile.json'
with open(filepath, 'w') as f:
data = json.dump(f)
Python to Json datatypes:
Python -> JSON
dict Object
list Array
tuple Array
str String
int Number
float Number
True true
False false
None null
More about Json:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.