judy2k / stupid-python-tricks

Stupid Python tricks.
The Unlicense
145 stars 27 forks source link

Added Python3 support for ish module #3

Closed snoack closed 9 years ago

snoack commented 9 years ago

It's a shame that I cannot use the awesome ish library in Python 3. Fortunately, it turned out that porting it were trivial. While doing so I'll also fixed following issues, while touching that lines anyway:

judy2k commented 9 years ago

I really appreciate this PR, but I'd rather it continued to work in Python 2 as well as Python 3. I'm prepared to accept a dependency on six or future if necessary.

snoack commented 9 years ago

This does work on Python 2.7 (maybe even 2.6) as well as on Python 3. That is because bytes has been added as alias for str on Python 2 in order to make supporting Python 2 and 3 with the same code easier.

judy2k commented 9 years ago

Yes, but the print function won't work unless you add from __future__ import print_function at the top of the file ;-)

Maybe a tox config script would be a useful thing - I had planned to add one ;-)

snoack commented 9 years ago

print(<expr>) works even in Python 2.3. ;) That is because it's not interpreted as function call, but the parenthesis merely group the expression provided to the print statement, while the same code is interpreted as function call in Python 3. You only need from __future__ import print_function if you want to use the additional/optional arguments of the print function.

judy2k commented 9 years ago

Much as I like evil, that seems like the wrong kind of evil ;-)

snoack commented 9 years ago

Not sure, if I agree. But here comes a new patch using from __future__ import print_function. I also rebased.