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

Change Python2 Strings to Python3 Strings #1492

Closed
erichlf opened this issue May 8, 2017 · 7 comments
Closed

Change Python2 Strings to Python3 Strings #1492

erichlf opened this issue May 8, 2017 · 7 comments

Comments

@erichlf
Copy link

erichlf commented May 8, 2017

For future compatibility we should switch strings from python2, e.g. '%s' % var, to python3 strings, e.g. '{}'.format(var). The strength of this approach becomes obvious when we look at something like the following:

"%s 1 OR %s 2 OR %s 3" % ((var, ) * 3)

vs

{0} 1 or {0} 2 or {0} 3".format(var)
@erichlf erichlf self-assigned this May 8, 2017
@erichlf
Copy link
Author

erichlf commented May 8, 2017

One can even do the following:

"{var3} {var1} {var2}".format(var1=var1, var2=var2, var3=var3)

@rljacob
Copy link
Member

rljacob commented May 8, 2017

Are we sure these 3.0 features are backwards-compatible with any unix-distro's or HPC vendors version of python 2.7 - 2.9?

@rljacob
Copy link
Member

rljacob commented May 8, 2017

Related to #1488

@mfdeakin-sandia
Copy link
Contributor

str.format was introduced in Python 2.6, so this should be backwards compatible with any version of Python 2.7

@mfdeakin-sandia
Copy link
Contributor

Also, what is Python 2.9? Unless someone's distributing their own Python, 2.8+ doesn't exist?

@rljacob
Copy link
Member

rljacob commented May 8, 2017

Sorry. That was me assuming there's something between 2.7 and 3.0.

@erichlf
Copy link
Author

erichlf commented May 9, 2017

Here is a nice cheat sheet for many of the ways to keep things compatible with both:
http://python-future.org/compatible_idioms.html

@jgfouca jgfouca added the ready label May 10, 2017
@erichlf erichlf added in progress and removed ready labels May 24, 2017
jgfouca added a commit that referenced this issue May 26, 2017
Python2 Strings to Python3 Strings

This PR changes all python2 style strings to python3 style strings. It does not change the scripts_regression_tests.py script nor the code_checker script.

Test suite: code_checker and scripts_regression_tests.py
Test baseline:
Test namelist changes:
Test status: bit for bit

Fixes #1492

User interface changes?:

Code review: @jgfouca @jedwards4b
@ghost ghost removed the in progress label May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants