if len(sys.argv) < 2: sys.stderr.write('Usage: sys.argv ') sys.exit(1) if not os.path.exists(sys.argv): sys.stderr.write('ERROR: Database sys.argv was not found!') sys.exit(1)
This is a portion of code I'm working on. The first part I'm trying to say if the user doesn't type
python programname something then it will exit.
The second part I'm trying to see if the database exists. On both places I'm unsure if I have the correct way to write out the sys.argv's by stderr or not.
This question is related to
BTW you can pass the error message directly to sys.exit:
if len(sys.argv) < 2: sys.exit('Usage: %s database-name' % sys.argv) if not os.path.exists(sys.argv): sys.exit('ERROR: Database %s was not found!' % sys.argv)