TraitError Reorient2StdInputSpec

I use glob.glob to find the full name of my nifti file.

from nipype.interfaces.fsl import utils
reorient = utils.Reorient2Std()
reorient.inputs.in_file = glob.glob(*2021*.nii.gz)

I get this error:
TraitError: The ‘in_file’ trait of a Reorient2StdInputSpec instance must be a pathlike object or string representing an existing file, but a value of “[<MY_FILE_NAME.nii.gz>]” <class ‘str’> was specified.

When I set reorient.inputs.in_file to the file full name, it does work.
How should I replace glob.glob?

Hi @tali.weiss,

glob.glob will return a list, and based on the nipype example, it seems that reorient.inputs.in_file needs to a string of the path to the file. So in your example, assuming that glob.glob(*2021*.nii.gz) returns a list length of 1, you could do glob.glob(*2021*.nii.gz)[0]. If however, the list length is greater than 1, you’d need to run that line in a loop.

Hope this helps a bit.