我有一个从函数调用的路径pathorganizer,如下所示。
该功能pathorganizer如下所示,
def pathorganizer(raw,output):
for root,sub,file in os.walk(raw):
for folders in sub:
if folders.startswith("raw"):
patient_id_raw = root.split(os.sep)[8]
for outdir,outsub,outfile in os.walk(output):
for folders in outsub:
if folders.startswith("raw"):
patient_id_output = outdir.split(os.sep)[8]
#print(outdir)
if folders.startswith("derived"):
if patient_id_output == patient_id_raw:
path = print(outdir + "/derived/")
#path = str(path)
return(path)
pathorganizer(raw,outdir)
/Users/xyz/temp/pro/data_repo/poc/MAY-M-13/PZT-MAY-2/events/derived/
type(pathorganizer(raw,outdir))
/Users/xyz/temp/pro/data_repo/poc/MAY-M-13/PZT-MAY-2/events/derived/
NoneType
现在我需要将上述路径(字符串)附加到另一个字符串。上面的字符串被检测为 NoneType,而不是字符串。在这种情况下,我无法将它与另一个字符串连接起来。当我尝试连接时,它抛出以下错误,
TypeError: can only concatenate str (not "NoneType") to str
这是我尝试过的,
for sam in list:
file = sam + '.doc'
with open(file, 'w') as my_file:
my_file.write("whatever: " + pathorganizer(raw,outdir) + sam + "\n")
我想知道在这种情况下如何编写或连接我的值。我的目标是.doc写成如下,
whatever: /Users/xyz/temp/pro/data_repo/poc/MAY-M-13/PZT-MAY-2/events/derived/sam
我也试过了str(pathorganizer(raw,outdir)),然后它返回doc
该文件被写为,
whatever: Nonesam
BIG阳
相关分类