diff --git a/README.md b/README.md index e032a87..89e59be 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,15 @@ for a in [False, True]: for c in [1, 2, 3]: .... ``` + +Additionally, an option loop (or combination thereof) can be reset using the copy +interface: + +```python +d1 = {'lang' : ['c'], 'doThingX' : [True, False]} +oploop1 = optionloop(d1) + +# iterate through 1 + +oploop2 = oploop1.copy() +``` \ No newline at end of file diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 1baa4b9..65d35b5 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -15,6 +15,7 @@ requirements: build: - python >=2.7,<3|>=3.5,{{PY_VER}}* - setuptools + - six run: - python {{PY_VER}}* diff --git a/optionloop/_version.py b/optionloop/_version.py index 36be4dc..1deade3 100644 --- a/optionloop/_version.py +++ b/optionloop/_version.py @@ -1,4 +1,4 @@ -__version_info__ = (1, 0, 5, '') +__version_info__ = (1, 0, 6, '') __version__ = '.'.join(map(str, __version_info__[:3])) if len(__version_info__) == 4: __version__ += __version_info__[-1] diff --git a/optionloop/optionloop.py b/optionloop/optionloop.py index 14326b4..a47b264 100644 --- a/optionloop/optionloop.py +++ b/optionloop/optionloop.py @@ -81,6 +81,7 @@ """ from collections import defaultdict +import six class OptionLoop(object): @@ -149,7 +150,7 @@ def __init__(self, initializing_dictionary, default_dict_factory=None): self.mydict = initializing_dictionary.copy() self.index = 0 self.end_index = None - for key, value in self.mydict.iteritems(): + for key, value in six.iteritems(self.mydict): if isinstance(value, (str, bytes)): self.mydict[key] = [value] size = 1 @@ -178,9 +179,9 @@ def __next__(self): else: value_list = {} startlen = 1 - if self.index < self.end_index: - for key, value in self.mydict.iteritems(): - value_list[key] = value[(self.index / startlen) % len(value)] + if self.end_index is not None and self.index < self.end_index: + for key, value in six.iteritems(self.mydict): + value_list[key] = value[int(self.index / startlen) % len(value)] startlen *= len(value) self.index += 1 diff --git a/setup.py b/setup.py index cd5652d..3aaee9b 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,10 @@ print('Warning: pypandoc module not found, could not convert Markdown to RST') long_description = desc +install_requires = [ + 'six' +] + tests_require = [ 'nose', ] @@ -37,6 +41,7 @@ packages=['optionloop', 'optionloop.tests'], zip_safe=True, test_suite='nose.collector', + install_requires=install_requires, tests_require=tests_require, classifiers=[ 'Development Status :: 5 - Production/Stable',