text
stringlengths 0
828
|
---|
if type(arg) == types.FunctionType:
|
return decorator(arg)
|
else:
|
return decorator"
|
4778,"def recurse_up(directory, filename):
|
""""""
|
Recursive walk a directory up to root until it contains `filename`
|
""""""
|
directory = osp.abspath(directory)
|
while True:
|
searchfile = osp.join(directory, filename)
|
if osp.isfile(searchfile):
|
return directory
|
if directory == '/': break
|
else: directory = osp.dirname(directory)
|
return False"
|
4779,"def etree_to_dict(tree):
|
""""""Translate etree into dictionary.
|
:param tree: etree dictionary object
|
:type tree: <http://lxml.de/api/lxml.etree-module.html>
|
""""""
|
d = {tree.tag.split('}')[1]: map(
|
etree_to_dict, tree.iterchildren()
|
) or tree.text}
|
return d"
|
4780,"def csv(
|
self,
|
filepath=None
|
):
|
""""""*Render the data in CSV format*
|
**Key Arguments:**
|
- ``filepath`` -- path to the file to write the csv content to. Default *None*
|
**Return:**
|
- ``renderedData`` -- the data rendered in csv format
|
**Usage:**
|
To render the data set as csv:
|
.. code-block:: python
|
print dataSet.csv()
|
.. code-block:: text
|
owner,pet,address
|
daisy,dog,""belfast, uk""
|
john,snake,the moon
|
susan,crocodile,larne
|
and to save the csv rendering to file:
|
.. code-block:: python
|
dataSet.csv(""/path/to/myfile.csv"")
|
""""""
|
self.log.debug('starting the ``csv`` method')
|
renderedData = self._list_of_dictionaries_to_csv(""machine"")
|
if filepath and renderedData != ""NO MATCH"":
|
# 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 ``csv`` method')
|
return renderedData"
|
4781,"def json(
|
self,
|
filepath=None
|
):
|
""""""*Render the data in json format*
|
**Key Arguments:**
|
- ``filepath`` -- path to the file to write the json content to. Default *None*
|
**Return:**
|
- ``renderedData`` -- the data rendered as json
|
**Usage:**
|
To render the data set as json:
|
.. code-block:: python
|
print dataSet.json()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.