This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Learn Python the Hard Way

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Week 3: Ex 9-12, Due Feb 13

Go back to: General discussion

Questions/comments about 9-12 here, A.K.A. The Boring Exercises.  Don't worry, I read ahead and it gets more interesting!

Red Olaf's picture
Red Olaf
Sat, 2011-02-12 02:51

Yes, I agree, 9-12 were a bit boring. But 13 is fun! I smile every time I type raw_input().

ZM L's picture
ZM L
Sat, 2011-02-12 04:07

I felt the boring exercises are at the later part of the book. When we are told to memorise things for a week :(.

nagarjuna c's picture
nagarjuna c
Mon, 2011-02-14 14:41

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

Red Olaf's picture
Red Olaf
Wed, 2011-02-16 02:33

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?

nagarjuna c's picture
nagarjuna c
Wed, 2011-02-16 07:33

Thank you