summaryrefslogtreecommitdiff
path: root/pypers/marelli/modulo1/try_finally.py
diff options
context:
space:
mode:
authormichele.simionato <devnull@localhost>2007-12-02 11:13:11 +0000
committermichele.simionato <devnull@localhost>2007-12-02 11:13:11 +0000
commit20ce686b0193d67ea56823a30551140f88b3aee1 (patch)
tree76015e7e4dc0b000bd857a2bdba6fb7976ac29a7 /pypers/marelli/modulo1/try_finally.py
parentf08f40335ad7f0ac961f25dabaaed34c4d4bcc44 (diff)
downloadmicheles-20ce686b0193d67ea56823a30551140f88b3aee1.tar.gz
Commited all py papers into Google code
Diffstat (limited to 'pypers/marelli/modulo1/try_finally.py')
-rwxr-xr-xpypers/marelli/modulo1/try_finally.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/pypers/marelli/modulo1/try_finally.py b/pypers/marelli/modulo1/try_finally.py
new file mode 100755
index 0000000..ca512a4
--- /dev/null
+++ b/pypers/marelli/modulo1/try_finally.py
@@ -0,0 +1,17 @@
+"""
+How try .. finally works:
+CTRL-C is caught, CTRL-Break is NOT
+"""
+import time
+F = "x.txt"
+
+f = file(F, "w")
+try:
+ for i in range(10):
+ print >> f, "line %s" % (i + 1)
+ time.sleep(1)
+finally:
+ f.close()
+ print "File %r was closed correctly. Current content:" % F
+ for line in file(F): print line,
+