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

Use print() function in both Python 2 and Python 3 #925

Closed

Conversation

cclauss
Copy link

@cclauss cclauss commented Aug 19, 2019

Legacy print statements are syntax errors in Python 3 but print() function works as expected n both Python 2 and Python 3.

Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
@astrelsky
Copy link
Contributor

Just slightly confused here. There is no python3 for Jython. The latest version of Jython is 2.7.1. It would surely be reasonable if there were to be python3 support for Jython, but I thought I had read somewhere that there wouldn't be.

@cclauss
Copy link
Author

cclauss commented Aug 28, 2019

@astrelsky
Copy link
Contributor

astrelsky commented Aug 28, 2019

Last commit by jeff5 about 2 years ago.
Jython3 issue 36

@ryanmkurtz
Copy link
Collaborator

Note that print() is a defined method in GhidraScript, so when you call it from a PythonScript, it's actually calling our defined Java method.

@cclauss
Copy link
Author

cclauss commented Aug 29, 2019

Does that redirect happen even when from __future__ import print_function is used?

@ryanmkurtz
Copy link
Collaborator

I just tested this out and I was wrong, GhidraScript's print() method is not actually callable from our Jython environment, which was unexpected. And it looks like you don't need to import anything to use the built-in print() function...Jython 2.7.1 already knows about it somehow.

@cclauss
Copy link
Author

cclauss commented Aug 29, 2019

Try print("A", "B") on Jython with and without the import as discussed at jython/book#6 (comment)

@ryanmkurtz
Copy link
Collaborator

The import has no effect on print("A", "B") in our scripting environment. It's just prints ('A', 'B') in both cases.

@cclauss
Copy link
Author

cclauss commented Aug 29, 2019

Known bug https://bugs.jython.org/issue2007

@cclauss
Copy link
Author

cclauss commented Aug 29, 2019

Closing... With 125 days left until Python 2 end of life, it is clear that an upgrade is not possible.

@cclauss cclauss closed this Aug 29, 2019
@cclauss cclauss deleted the modernize-Python-2-codes branch August 29, 2019 13:15
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.

3 participants