Encapsulating conditional execution based on list membership - how do you do it?
metaperl
metaperl at gmail.com
Mon Dec 11 10:23:22 EST 2006
I have a series of scripts which retrieve files. None of these scripts
should continue if the file to be retrieved already exists in the
archive. Here is the code:
if f in path(self.storage.archive).files('*'):
print f, "exists in archive. Not continuing"
sys.exit()
self.storage is a class which gives me object-oriented access to the
filesystem directories that will be manipulated by the script. E.g.
self.storage.archive is a string which refers to a certain directory.
Initializing this object initializes all the members (input, archive,
output, workfiles) and makes all the correct directories.
ok, so I'm thinking of adding a method to the storage class so I can do
this:
self.storage.archive_has(f, print_msg=True) and sys.exit()
but really there is no need to hardcode which storage directory. So I'm
thinking:
self.storage.memberof('archive', f, print_msg=Tree) and sys.exit()
Is that the best solution you can think of?
More information about the Python-list
mailing list