text
stringlengths 0
828
|
---|
.. code-block:: json
|
[
|
{
|
""address"": ""belfast, uk"",
|
""owner"": ""daisy"",
|
""pet"": ""dog""
|
},
|
{
|
""address"": ""the moon"",
|
""owner"": ""john"",
|
""pet"": ""snake""
|
},
|
{
|
""address"": ""larne"",
|
""owner"": ""susan"",
|
""pet"": ""crocodile""
|
}
|
]
|
and to save the json rendering to file:
|
.. code-block:: python
|
dataSet.json(""/path/to/myfile.json"")
|
""""""
|
self.log.debug('starting the ``json`` method')
|
dataCopy = copy.deepcopy(self.listOfDictionaries)
|
for d in dataCopy:
|
for k, v in d.iteritems():
|
if isinstance(v, datetime):
|
d[k] = v.strftime(""%Y%m%dt%H%M%S"")
|
renderedData = json.dumps(
|
dataCopy,
|
separators=(',', ': '),
|
sort_keys=True,
|
indent=4
|
)
|
if filepath and len(self.listOfDictionaries):
|
# RECURSIVELY CREATE MISSING DIRECTORIES
|
if not os.path.exists(os.path.dirname(filepath)):
|
os.makedirs(os.path.dirname(filepath))
|
writeFile = codecs.open(filepath, encoding='utf-8', mode='w')
|
writeFile.write(renderedData)
|
writeFile.close()
|
self.log.debug('completed the ``json`` method')
|
return renderedData"
|
4782,"def yaml(
|
self,
|
filepath=None
|
):
|
""""""*Render the data in yaml format*
|
**Key Arguments:**
|
- ``filepath`` -- path to the file to write the yaml content to. Default *None*
|
**Return:**
|
- ``renderedData`` -- the data rendered as yaml
|
**Usage:**
|
To render the data set as yaml:
|
.. code-block:: python
|
print dataSet.yaml()
|
.. code-block:: yaml
|
- address: belfast, uk
|
owner: daisy
|
pet: dog
|
- address: the moon
|
owner: john
|
pet: snake
|
- address: larne
|
owner: susan
|
pet: crocodile
|
and to save the yaml rendering to file:
|
.. code-block:: python
|
dataSet.json(""/path/to/myfile.yaml"")
|
""""""
|
self.log.debug('starting the ``yaml`` method')
|
dataCopy = []
|
dataCopy[:] = [dict(l) for l in self.listOfDictionaries]
|
renderedData = yaml.dump(dataCopy, default_flow_style=False)
|
if filepath and len(self.listOfDictionaries):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.