Skip to content

Commit 437b31e

Browse files
committed
STYLE: Use writelines instead of write in a loop
Use `writelines` instead of `write` in a loop. Fixes: ``` - for val in bvals: - fid.write(f'{val} ') + fid.writelines(f'{val} ' for val in bvals) ``` and other similar errors raised for example in: https://github.com/nipy/nibabel/actions/runs/16092302666/job/45410655457?pr=1422#step:7:23 Documentation: https://docs.astral.sh/ruff/rules/for-loop-writes/
1 parent b5ecf48 commit 437b31e

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

nibabel/cmdline/parrec2nii.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ def proc_file(infile, opts):
358358
)
359359
with open(basefilename + '.bvals', 'w') as fid:
360360
# np.savetxt could do this, but it's just a loop anyway
361-
for val in bvals:
362-
fid.write(f'{val} ')
361+
fid.writelines(f'{val} ' for val in bvals)
363362
fid.write('\n')
364363
else:
365364
verbose('Writing .bvals and .bvecs files')
@@ -374,8 +373,7 @@ def proc_file(infile, opts):
374373
fid.write('\n')
375374
with open(basefilename + '.bvecs', 'w') as fid:
376375
for row in bvecs.T:
377-
for val in row:
378-
fid.write(f'{val} ')
376+
fid.writelines(f'{val} ' for val in row)
379377
fid.write('\n')
380378

381379
# export data labels varying along the 4th dimensions if requested

0 commit comments

Comments
 (0)