0
def uniqfile( title, suffix ):
    print('input: '+title)
    if os.path.isfile(title+suffix):
        title += " "
        uniqfile(title, suffix)
    else:
        return title+suffix

The first print line within it returns the correct output, but when the function is supposed to finally return the properly appended title value, it instead returns None.

How do I get the value returned properly so that I may assign it to a variable to print out and save the file uniquely named?

namepdf = uniqfile(row[0], '.pdf')
afb
  • 1
  • 1
  • 1
    You forgot the return: `return uniqfile(title, suffix)`. Also google "Python recursive None" and the first hit are 5 duplicates on this site. – user2390182 Mar 18 '20 at 17:27

1 Answers1

0

It seems that you forgot to add the return statement. That's why you get None

def uniqfile( title, suffix ):
    print('input: '+title)
    if os.path.isfile(title+suffix):
        title += " "
        # put RETURN here
        return uniqfile(title, suffix)
    else:
        return title
Maxim Krabov
  • 685
  • 5
  • 17