Skip to content

Commit

Permalink
Merge pull request #34 from lazywei/master
Browse files Browse the repository at this point in the history
Rewind _current_line; expose encoding nominal
  • Loading branch information
mfeurer committed Apr 30, 2015
2 parents c2d88e7 + 8c34644 commit dcc20e6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions arff.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ def _decode_data(self, s):
def _decode(self, s, encode_nominal=False):
'''Do the job the ``encode``.'''

# Make sure this method is idempotent
self._current_line = 0

# If string, convert to a list of lines
if isinstance(s, basestring):
s = s.strip('\r\n ').replace('\r\n', '\n').split('\n')
Expand Down Expand Up @@ -714,25 +717,25 @@ def iter_encode(self, obj):
# =============================================================================

# BASIC INTERFACE =============================================================
def load(fp):
def load(fp, encode_nominal=False):
'''Load a file-like object containing the ARFF document and convert it into
a Python object.
:param fp: a file-like object.
:return: a dictionary.
'''
decoder = ArffDecoder()
return decoder.decode(fp)
return decoder.decode(fp, encode_nominal=encode_nominal)

def loads(s):
def loads(s, encode_nominal=False):
'''Convert a string instance containing the ARFF document into a Python
object.
:param s: a string object.
:return: a dictionary.
'''
decoder = ArffDecoder()
return decoder.decode(s)
return decoder.decode(s, encode_nominal=encode_nominal)

def dump(obj, fp):
'''Serialize an object representing the ARFF document to a given file-like
Expand Down

0 comments on commit dcc20e6

Please sign in to comment.