[Zope] add file to zope filesystem unless it exists

John Hunter jdhunter@ace.bsd.uchicago.edu
Wed, 13 Feb 2002 16:06:56 -0600


>>>>> "John" == John Hunter <jdhunter@ace.bsd.uchicago.edu> writes:

    John> I want to have a user upload a file to the zope filesystem,
    John> but if the file already exists I want to ignore the request

        [snip] 

    John> Without the 'if not hasattr(folder, file_name):' the script
    John> works fine and adds the file to the filesystem and returns
    John> an error if the file already exists there.  Apparently I am
    John> not using the hasattr part correctly.  What is the correct
    John> way in a python script to test for the existence of a file
    John> in a folder object?


Use

if file_name in  folder.objectIds():