Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dict iteration in Python 3 #29

Closed
wants to merge 3 commits into from
Closed

Fix dict iteration in Python 3 #29

wants to merge 3 commits into from

Conversation

sandrinr
Copy link
Contributor

@sandrinr sandrinr commented Jan 7, 2015

The custom code in "swigify_ib.i" makes use of "list.iteritems()". That method was renamed to "list.items()" in Python 3. To ensure the custom code works in Python 2.7 and 3.x I added the "six" library as a dependency. It enables us to iterate over lists in Python 2.7 and Python 3.x.

Make use of 'six' library to enable iteritems() in Python 2 and Python 3.
@sandrinr
Copy link
Contributor Author

sandrinr commented Jan 7, 2015

BTW: This should solve issue #25.

@Komnomnomnom
Copy link
Owner

Thanks @sandrinr appreciate you taking the time to put together the pull request.

I'd rather not add a dependency on six though. Just the changing the two affected lines to items() should do fine.

@Komnomnomnom
Copy link
Owner

Closed by c142d2f

@sandrinr
Copy link
Contributor Author

sandrinr commented Jan 8, 2015

As far as I understand it swigibpy will not be able to run on Python-2.7 anymore if you just take over the change to list.items(). Since I am not using Python-2 anymore this is acceptable for me.

EDIT: My commend above is actually wrong. list.items() exists also in Python-2.7 but it just has a different memory behaviour than list.iteritems(). So with the patch applied as it is now it should not be a problem.

@Komnomnomnom
Copy link
Owner

Yep in Python 2 items() returns a list and iteritems() returns an iterator. In Python 3 items() and many other methods (e.g. range) were changed to return iterators and their iterator equivalents were removed. Changes these two lines to use items() has negligible overhead in Python 2.

@sandrinr sandrinr deleted the fix-py3-iteration branch January 8, 2015 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants