Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

* Scripting Languages
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* aktuális (2023/24/2)
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Scala


[ edit | logout ]
[ sandbox | passwd ]

20121120a

Exceptions#1

Consider the following script, which works similarly to the Unix command cat:

#!/usr/bin/env python3

# 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.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2017 August 03, 23:54