C:\lphw>python ex16.py nagarjuna
we are going to erase 'nagarjuna'.
if you dont wnat that hit ctrl-c (c).
if do want them hit return.
?Traceback (most recent call last):
File "ex16.py", line 9, in
raw_input("?")
KeyboardInterrupt
Hello, that is not an error when you hit control+c. I think that is what is supposed to happen according to the documentation:
exception KeyboardInterrupt
Raised when the user hits the interrupt key (normally Control-C or Delete). During execution, a check for interrupts is made regularly. Interrupts typed when a built-in function input() or raw_input() is waiting for input also raise this exception. The exception inherits from BaseException so as to not be accidentally caught by code that catches Exception and thus prevent the interpreter from exiting.
Yes, I agree, 9-12 were a bit boring. But 13 is fun! I smile every time I type raw_input().
I felt the boring exercises are at the later part of the book. When we are told to memorise things for a week :(.
i have done ex16 and below my code
from sys import argv
script, filename = argv
print " we are going to erase %r." %filename
print "if you dont wnat that hit ctrl-c (c)."
print "if do want them hit return."
raw_input("?")
print "opening the file.."
target = open(filename, 'w')
print "Truncateing the file. Goodbye!"
target.truncate()
print" now i am going to ask you for three lines"
line1 = raw_input("Line 1:")
line2 = raw_input("line2:")
line3 = raw_input("line3:")
print " I am going to write these lines to file"
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
and i got error when i hot contrl+c
C:\lphw>python ex16.py nagarjuna
we are going to erase 'nagarjuna'.
if you dont wnat that hit ctrl-c (c).
if do want them hit return.
?Traceback (most recent call last):
File "ex16.py", line 9, in
raw_input("?")
KeyboardInterrupt
Please help me
Hello, that is not an error when you hit control+c. I think that is what is supposed to happen according to the documentation:
exception KeyboardInterrupt
Raised when the user hits the interrupt key (normally Control-C or Delete). During execution, a check for interrupts is made regularly. Interrupts typed when a built-in function input() or raw_input() is waiting for input also raise this exception. The exception inherits from BaseException so as to not be accidentally caught by code that catches Exception and thus prevent the interpreter from exiting.
That comes from:
http://docs.python.org/library/exceptions.html
What happened to you also happened to me. When you hit return, did your script work?
Thank you