paramak icon indicating copy to clipboard operation
paramak copied to clipboard

Consider using .format() in string compositions

Open GregVernon opened this issue 5 years ago • 1 comments

I've found that Cubit commands are often a little easier to read / more maintainable using the .format() method.

For instance, turn this: https://github.com/ukaea/paramak/blob/7924ab0b20e53b0122f56789734bfb795cd73d38/paramak/parametric_neutronics/make_faceteted_neutronics_model.py#L79-L83

into:

cubit.cmd("unite vol {} with vol {}".format(new_vols, new_vols))

or a three-line statement (still fewer lines than the original):

command = "unite vol {} with vol {}"
command.format(new_vols, new_vols)
cubit.cmd(command)

GregVernon avatar Feb 04 '21 03:02 GregVernon

Thanks Greg this is a nice suggestion, thanks for taking the time to help out. We certainly appreciate it.

I has make a PR for this improvement, it will be a bit slower to merge than our usual PRs as to test this we need to connect to our Trelis license server and perform local tests.

I'm keen to update this script from its python 2 origins and also keen to run it using the system python instead of that os.system call that I current use which is a bit of a mess

https://github.com/ukaea/paramak/blob/8188fb5683b56ac75562f98c409d4da9696becc5/paramak/parametric_neutronics/neutronics_model.py#L366-L367

shimwell avatar Feb 04 '21 12:02 shimwell