Skip to content

Instantly share code, notes, and snippets.

@chulman444
Created March 8, 2018 20:35
Show Gist options
  • Save chulman444/62729a74e426fe4e170ff36d4d8cf785 to your computer and use it in GitHub Desktop.
Save chulman444/62729a74e426fe4e170ff36d4d8cf785 to your computer and use it in GitHub Desktop.
import yaml
content = """First line
Second line
Third line"""
print("The following is the content")
print(content)
print("-------------END of content")
print("\nThe following is when you dump it")
print(yaml.dump(content))
print("-------------END of dump")
print("\nThe following is when you load, say, a file with the content")
print(yaml.load(content))
print("-------------END of load")
# OUTPUT:
"""
The following is the content
First line
Second line
Third line
-------------END of content
The following is when you dump it
'First line
Second line
Third line'
-------------END of dump
The following is when you load, say, a file with the content
First line
Second line
Third line
-------------END of load
"""
@chulman444
Copy link
Author

New lines are killing me.

I didn't have to read "JSON reference", but I guess I'll have to give "YAML reference" (here) a try, not knowing understanding the 'reference' could help me out.

@chulman444
Copy link
Author

What I have so far

loaded = yaml.load(file_content)
lines = loaded.split("\n")
fixed_str = ""
for line in lines:
  # Add 2 empty spaces ' ' + ' ' at the beginning of a line
  # Add 3 new lines at the end of a line
  fixed_str = "  " + line + "\n\n\n"
# load AGAIN
fixed_str = yaml.load(fixed_str)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment