Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
EnPy /
20121120aExceptions#1Consider the following script, which works similarly to the Unix command #!/usr/bin/env python # mycat.py import sys def cat(fname): f = open(fname, 'r') text = f.read() print '---', fname print text f.close() ##### if __name__ == "__main__": args = sys.argv[1:] for arg in args: cat(arg) Usage: ./mycat.py file1 file2 ... Exercise If we pass a non-existing file as an argument, then catch the exception, print an error message, and continue processing the next argument. |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |