Skip to content

Commit 06149e8

Browse files
committed
Simplify a few format calls
1 parent 3231c19 commit 06149e8

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

stagpy/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ def main():
2020
except error.StagpyError as err:
2121
if DEBUG:
2222
raise
23+
errtype = type(err).__name__
2324
print('Oops! StagPy encountered the following problem while '
24-
'processing your request.',
25-
'Please check the path to your simulation and the command line '
26-
'arguments.', '',
27-
'{}: {}'.format(err.__class__.__name__, err),
28-
sep='\n', file=sys.stderr)
25+
'processing your request.', 'Please check the path to your '
26+
'simulation and the command line arguments.', '',
27+
f'{errtype}: {err}', sep='\n', file=sys.stderr)
2928
sys.exit()
3029

3130

stagpy/commands.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ def info_cmd():
2727
lstep = sdat.steps[-1]
2828
print(f'StagYY run in {sdat.path}')
2929
if lsnap.geom.threed:
30-
dimension = '{} x {} x {}'.format(lsnap.geom.nxtot,
31-
lsnap.geom.nytot,
32-
lsnap.geom.nztot)
30+
dimension = '{0.nxtot} x {0.nytot} x {0.nztot}'.format(lsnap.geom)
3331
elif lsnap.geom.twod_xz:
34-
dimension = '{} x {}'.format(lsnap.geom.nxtot,
35-
lsnap.geom.nztot)
32+
dimension = '{0.nxtot} x {0.nztot}'.format(lsnap.geom)
3633
else:
37-
dimension = '{} x {}'.format(lsnap.geom.nytot,
38-
lsnap.geom.nztot)
34+
dimension = '{0.nytot} x {0.nztot}'.format(lsnap.geom)
3935
if lsnap.geom.cartesian:
4036
print('Cartesian', dimension)
4137
elif lsnap.geom.cylindrical:

stagpy/misc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
from . import conf
1111

12-
INT_FMT = '{:05d}'
13-
1412

1513
def out_name(stem, timestep=None):
1614
"""Return StagPy out file name.
@@ -29,7 +27,7 @@ def out_name(stem, timestep=None):
2927
if conf.core.shortname:
3028
return conf.core.outname
3129
if timestep is not None:
32-
stem = (stem + INT_FMT).format(timestep)
30+
stem = f'{stem}{timestep:05d}'
3331
return conf.core.outname + '_' + stem
3432

3533

@@ -45,8 +43,7 @@ def scilabel(value, precision=2):
4543
Returns:
4644
str: the scientific notation the specified value.
4745
"""
48-
fmt = f'{{:.{precision}e}}'
49-
man, exp = fmt.format(value).split('e')
46+
man, exp = f'{value:.{precision}e}'.split('e')
5047
exp = int(exp)
5148
return fr'{man}\times 10^{{{exp}}}'
5249

0 commit comments

Comments
 (0)