text - Python: Searching for exact filename -
in searching html within current directory, if name contains substring assume file exists , continue operation instead of saying file doesn't exist. have file "protocolhttp.html" - in testing make sure "protocol.html" throws error, doesn't. continues operation of program.
i make sure filename matches exactly. here's have:
for file in glob.glob('*.html'): if protocolfile in file: open(file) f: contents = f.read() else: print "could not locate '" + protocolfile + ".html'" sys.exit(1)
any ideas or further steps check validate this?
i think code same thing as:
if os.path.isfile(filename): open(filename) f: contents = f.read() else: print 'could not locate {0}'.format(filename) sys.exit(1)
Comments
Post a Comment