Setting file path location in yaml

Viewed 16533

I have three directories which are in the root directory of my machine: yaml, data and json.

Within my yaml directory I have a configuration yaml file which points to the json directory. Now I want to be able to get out of the yaml directory and then in to the json directory in order to point the json_location to this.

So far I have the following in my yaml file, but it is an absolute path. If someone else was to use my code, they would need to change the file path to meet their User profile name.

# configuration
config:
  json_location: /Users/jaymiee/Desktop/json/
2 Answers

I was using yaml for serverless deployment of functions, and they use variables to make it dynamic, it involves using "$" but other systems use different notation, what uses your yaml?

Option 1. Get the user's home path as a variable and store that into your config

Option 2. let your app code handle directory changes. In Python, you could do something like:

from pathlib import Path
home = str(Path.home())       # python 3.5+
yaml_location = os.path.join(home, "yaml")

Related