1- # coding: utf-8
1+ # !/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+ """Find out more at https://github.com/AUSSDA/pyDataverse."""
24from __future__ import absolute_import
3-
4- import csv
55import json
66
77
@@ -14,12 +14,12 @@ def json_to_dict(data):
1414 Parameters
1515 ----------
1616 data : string
17- `data` as JSON -formatted string.
17+ Data as a json -formatted string.
1818
1919 Returns
2020 -------
2121 dict
22- `data` represented as dict() .
22+ Data as Python Dictionary .
2323
2424 """
2525 try :
@@ -37,12 +37,12 @@ def dict_to_json(data):
3737 Parameters
3838 ----------
3939 data : dict
40- `data` represented as dict() .
40+ Data as Python Dictionary .
4141
4242 Returns
4343 -------
4444 string
45- `data` as JSON -formatted string
45+ Data as a json -formatted string.
4646
4747 """
4848 try :
@@ -52,20 +52,20 @@ def dict_to_json(data):
5252
5353
5454def read_file (filename , mode = 'r' ):
55- """Read in data from a file.
55+ """Read in a file.
5656
5757 Parameters
5858 ----------
59- filename : type
60- Description of parameter `filename` .
59+ filename : string
60+ Filename with full path .
6161 mode : string
62- Read mode of file. Default is `r`. See more at
62+ Read mode of file. Defaults to `r`. See more at
6363 https://docs.python.org/3.5/library/functions.html#open
6464
6565 Returns
6666 -------
6767 string
68- Returns the whole content as string.
68+ Returns data as string.
6969
7070 """
7171 try :
@@ -78,44 +78,44 @@ def read_file(filename, mode='r'):
7878 raise e
7979
8080
81- def write_file (filename , string , mode = 'w' ):
81+ def write_file (filename , data , mode = 'w' ):
8282 """Write data in a file.
8383
8484 Parameters
8585 ----------
8686 filename : string
87- Full filename with path of file .
88- string : string
89- String of data to be written .
87+ Filename with full path .
88+ data : string
89+ Data to be stored .
9090 mode : string
91- Read mode of file. Default is `w`. See more at
91+ Read mode of file. Defaults to `w`. See more at
9292 https://docs.python.org/3.5/library/functions.html#open
9393
9494 """
9595 try :
9696 with open (filename , mode ) as f :
97- f .write (string )
97+ f .write (data )
9898 except IOError :
9999 print ('An error occured trying to write the file {}.' .format (filename ))
100100 except Exception as e :
101101 raise e
102102
103103
104104def read_file_json (filename ):
105- """Read in JSON file.
105+ """Read in a json file.
106106
107107 See more about the json module at
108108 https://docs.python.org/3.5/library/json.html
109109
110110 Parameters
111111 ----------
112112 filename : string
113- Full filename with path of file .
113+ Filename with full path .
114114
115115 Returns
116116 -------
117117 dict
118- Data represented as a dict() .
118+ Data as a json-formatted string .
119119
120120 """
121121 try :
@@ -125,42 +125,17 @@ def read_file_json(filename):
125125
126126
127127def write_file_json (filename , data , mode = 'w' ):
128- """Write dict() in a JSON file.
128+ """Write data to a json file.
129129
130130 Parameters
131131 ----------
132132 filename : string
133- Full filename with path of file .
133+ Filename with full path .
134134 data : dict
135- Data to be written in the JSON file.
135+ Data to be written in the json file.
136136 mode : string
137- Write mode of file. Default is `w`. See more at
137+ Write mode of file. Defaults to `w`. See more at
138138 https://docs.python.org/3/library/functions.html#open
139139
140140 """
141141 write_file (filename , dict_to_json (data ), mode )
142-
143-
144- def read_file_csv (filename ):
145- """Read in CSV file.
146-
147- See more about csv.reader() at https://docs.python.org/3.5/library/csv.html
148-
149- Parameters
150- ----------
151- filename : string
152- Full filename with path of file.
153-
154- Returns
155- -------
156- reader
157- Reader object, which can be iterated over.
158-
159- """
160- try :
161- with open (filename , newline = '' ) as csvfile :
162- return csv .reader (csvfile , delimiter = ',' , quotechar = '"' )
163- except Exception as e :
164- raise e
165- finally :
166- csvfile .close ()
0 commit comments